From: Art Cancro Date: Thu, 27 Jan 2022 23:41:18 +0000 (-0500) Subject: /ctdl/r//info.txt now fetches the room info banner X-Git-Tag: v950~30 X-Git-Url: https://code.citadel.org/?a=commitdiff_plain;h=8c84e52d8bccbca567938548ea8e1be9a10ec4e1;p=citadel.git /ctdl/r//info.txt now fetches the room info banner --- diff --git a/webcit-ng/README.txt b/webcit-ng/README.txt index 3d8f60355..56b320021 100644 --- a/webcit-ng/README.txt +++ b/webcit-ng/README.txt @@ -4,8 +4,7 @@ This is WebCit-NG, a complete refactoring of the WebCit server that will focus on "REST first" and build around that. The code will be well layered with as little spaghetti as possible. -Please don't mess with this yet. I'm only pushing it upstream so it gets -backed up. +Please don't mess with this yet. I'm only pushing it upstream so it gets backed up. DESIGN GOALS: @@ -16,6 +15,7 @@ DESIGN GOALS: * Require NO cleanup. Killing the process lets the OS reclaim all resources. * As much as possible, resources should be freed by just coming back down the stack. + Avoid global variables and thread-local variables as much as possible. * Readability of the code is more important than shaving off a few CPU cycles. diff --git a/webcit-ng/api.txt b/webcit-ng/api.txt index e2cab0b5e..ca344ff52 100644 --- a/webcit-ng/api.txt +++ b/webcit-ng/api.txt @@ -13,6 +13,7 @@ GET /ctdl/r/ROOMNAME/MSGNUM Retrieve the content of an individual message (Should we output RFC822 fields as HTTP headers? Decide soon...) PUT /ctdl/r/ROOMNAME/xxx DAV operation to insert a new message into a room (The returned ETag will be the new message number) +GET /ctdl/r/ROOMNAME/info.txt Returns the room info banner for this room GET /ctdl/r/ROOMNAME/MSGNUM/json Retrieve an individual message in a room, encapsulated in JSON GET /ctdl/c/info Returns a JSON representation of the output of an INFO server command POST /ctdl/a/login Send it a your credentials and it will log you in diff --git a/webcit-ng/room_functions.c b/webcit-ng/room_functions.c index 26f35ef5e..14fc60413 100644 --- a/webcit-ng/room_functions.c +++ b/webcit-ng/room_functions.c @@ -106,6 +106,30 @@ void json_msglist(struct http_transaction *h, struct ctdlsession *c, char *which } +// Client is requesting the room info banner +void read_room_info_banner(struct http_transaction *h, struct ctdlsession *c) { + char buf[1024]; + + ctdl_printf(c, "RINF"); + ctdl_readline(c, buf, sizeof(buf)); + if (buf[0] == '1') { + StrBuf *info = NewStrBuf(); + while (ctdl_readline(c, buf, sizeof(buf)), (strcmp(buf, "000"))){ + StrBufAppendPrintf(info, "%s\n", buf); + } + add_response_header(h, strdup("Content-type"), strdup("text/plain")); + h->response_code = 200; + h->response_string = strdup("OK"); + h->response_body_length = StrLength(info); + h->response_body = SmashStrBuf(&info); + return; + } + else { + do_404(h); + } +} + + // Client requested an object in a room. void object_in_room(struct http_transaction *h, struct ctdlsession *c) { char buf[1024]; @@ -114,32 +138,28 @@ void object_in_room(struct http_transaction *h, struct ctdlsession *c) { extract_token(buf, h->url, 4, '/', sizeof buf); - if (!strncasecmp(buf, "msgs.", 5)) { // Client is requesting a list of message numbers + if (!strncasecmp(buf, "msgs.", 5)) { // Client is requesting a list of message numbers unescape_input(&buf[5]); json_msglist(h, c, &buf[5]); return; } -#if 0 - if (!strncasecmp(buf, "threads", 5)) { // Client is requesting a threaded view (still kind of fuzzy here) - threaded_view(h, c, &buf[5]); - return; - } - if (!strncasecmp(buf, "flat", 5)) { // Client is requesting a flat view (still kind of fuzzy here) - flat_view(h, c, &buf[5]); + if (!strcasecmp(buf, "info.txt")) { // Client is requesting the room info banner + read_room_info_banner(h, c); return; } -#endif + + // If we get to this point, the client is requesting a specific object *in* the room. if ((c->room_default_view == VIEW_CALENDAR) // room types where objects are referenced by EUID - || (c->room_default_view == VIEW_TASKS) - || (c->room_default_view == VIEW_ADDRESSBOOK) - ) { + || (c->room_default_view == VIEW_TASKS) + || (c->room_default_view == VIEW_ADDRESSBOOK) + ) { safestrncpy(unescaped_euid, buf, sizeof unescaped_euid); unescape_input(unescaped_euid); msgnum = locate_message_by_uid(c, unescaped_euid); } - else { + else { // otherwise the object is being referenced by message number msgnum = atol(buf); } @@ -474,6 +494,7 @@ void room_list(struct http_transaction *h, struct ctdlsession *c) { JsonObjectAppend(jr, NewJsonNumber(HKEY("current_view"), extract_int(buf, 6))); JsonObjectAppend(jr, NewJsonNumber(HKEY("default_view"), extract_int(buf, 7))); + JsonObjectAppend(jr, NewJsonNumber(HKEY("mtime"), extract_int(buf, 8))); JsonArrayAppend(j, jr); // add the room to the array } @@ -532,8 +553,7 @@ void ctdl_r(struct http_transaction *h, struct ctdlsession *c) { } // At this point our Citadel client session is "in" the specified room. - if (num_tokens(h->url, '/') == 4) // /ctdl/r/roomname - { + if (num_tokens(h->url, '/') == 4) { // /ctdl/r/roomname the_room_itself(h, c); return; }