"Forum list" is now more or less in its final form.
[citadel.git] / webcit-ng / room_functions.c
1 // Room functions
2 //
3 // Copyright (c) 1996-2022 by the citadel.org team
4 //
5 // This program is open source software.  It runs great on the
6 // Linux operating system (and probably elsewhere).  You can use,
7 // copy, and run it under the terms of the GNU General Public
8 // License version 3.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14
15 #include "webcit.h"
16
17
18 // Return a "zero-terminated" array of message numbers in the current room.
19 // Caller owns the memory and must free it.  Returns NULL if any problems.
20 long *get_msglist(struct ctdlsession *c, char *which_msgs) {
21         char buf[1024];
22         long *msglist = NULL;
23         int num_msgs = 0;
24         int num_alloc = 0;
25
26         ctdl_printf(c, "MSGS %s", which_msgs);
27         ctdl_readline(c, buf, sizeof(buf));
28         if (buf[0] == '1') {
29                 do {
30                         if (num_msgs >= num_alloc) {
31                                 if (num_alloc == 0) {
32                                         num_alloc = 1024;
33                                         msglist = malloc(num_alloc * sizeof(long));
34                                 }
35                                 else {
36                                         num_alloc *= 2;
37                                         msglist = realloc(msglist, num_alloc * sizeof(long));
38                                 }
39                         }
40                         ctdl_readline(c, buf, sizeof(buf));
41                         msglist[num_msgs++] = atol(buf);
42                 } while (strcmp(buf, "000"));   // this makes the last element a "0" terminator
43         }
44         return msglist;
45 }
46
47
48 // Supplied with a list of potential matches from an If-Match: or If-None-Match: header, and
49 // a message number (which we always use as the entity tag in Citadel), return nonzero if the
50 // message number matches any of the supplied tags in the string.
51 int match_etags(char *taglist, long msgnum) {
52         int num_tags = num_tokens(taglist, ',');
53         int i = 0;
54         char tag[1024];
55
56         if (msgnum <= 0) {                                      // no msgnum?  no match.
57                 return (0);
58         }
59
60         for (i = 0; i < num_tags; ++i) {
61                 extract_token(tag, taglist, i, ',', sizeof tag);
62                 striplt(tag);
63                 char *lq = (strchr(tag, '"'));
64                 char *rq = (strrchr(tag, '"'));
65                 if (lq < rq) {                                  // has two double quotes
66                         strcpy(rq, "");
67                         strcpy(tag, ++lq);
68                 }
69                 striplt(tag);
70                 if (!strcmp(tag, "*")) {                        // wildcard match
71                         return (1);
72                 }
73                 long tagmsgnum = atol(tag);
74                 if ((tagmsgnum > 0) && (tagmsgnum == msgnum)) { // match
75                         return (1);
76                 }
77         }
78
79         return (0);                                             // no match
80 }
81
82
83 // Client is requesting a message list
84 void json_msglist(struct http_transaction *h, struct ctdlsession *c, char *which) {
85         int i = 0;
86         long *msglist = get_msglist(c, which);
87         JsonValue *j = NewJsonArray(HKEY("msgs"));
88
89         if (msglist != NULL) {
90                 for (i = 0; msglist[i] > 0; ++i) {
91                         JsonArrayAppend(j, NewJsonNumber(HKEY("m"), msglist[i]));
92                 }
93                 free(msglist);
94         }
95
96         StrBuf *sj = NewStrBuf();
97         SerializeJson(sj, j, 1);        // '1' == free the source array
98
99         add_response_header(h, strdup("Content-type"), strdup("application/json"));
100         h->response_code = 200;
101         h->response_string = strdup("OK");
102         h->response_body_length = StrLength(sj);
103         h->response_body = SmashStrBuf(&sj);
104         return;
105 }
106
107
108 // Client is requesting the room info banner
109 void read_room_info_banner(struct http_transaction *h, struct ctdlsession *c) {
110         char buf[1024];
111
112         ctdl_printf(c, "RINF");
113         ctdl_readline(c, buf, sizeof(buf));
114         if (buf[0] == '1') {
115                 StrBuf *info = NewStrBuf();
116                 while (ctdl_readline(c, buf, sizeof(buf)), (strcmp(buf, "000"))){
117                         StrBufAppendPrintf(info, "%s\n", buf);
118                 }
119                 add_response_header(h, strdup("Content-type"), strdup("text/plain"));
120                 h->response_code = 200;
121                 h->response_string = strdup("OK");
122                 h->response_body_length = StrLength(info);
123                 h->response_body = SmashStrBuf(&info);
124                 return;
125         }
126         else {
127                 do_404(h);
128         }
129 }
130
131
132 // Client requested an object in a room.
133 void object_in_room(struct http_transaction *h, struct ctdlsession *c) {
134         char buf[1024];
135         long msgnum = (-1);
136         char unescaped_euid[1024];
137
138         extract_token(buf, h->url, 4, '/', sizeof buf);
139
140         if (!strncasecmp(buf, "msgs.", 5)) {            // Client is requesting a list of message numbers
141                 unescape_input(&buf[5]);
142                 json_msglist(h, c, &buf[5]);
143                 return;
144         }
145
146         if (!strcasecmp(buf, "info.txt")) {             // Client is requesting the room info banner
147                 read_room_info_banner(h, c);
148                 return;
149         }
150
151         // If we get to this point, the client is requesting a specific object *in* the room.
152
153         if ((c->room_default_view == VIEW_CALENDAR)     // room types where objects are referenced by EUID
154            || (c->room_default_view == VIEW_TASKS)
155            || (c->room_default_view == VIEW_ADDRESSBOOK)
156            ) {
157                 safestrncpy(unescaped_euid, buf, sizeof unescaped_euid);
158                 unescape_input(unescaped_euid);
159                 msgnum = locate_message_by_uid(c, unescaped_euid);
160         }
161         else {                                          // otherwise the object is being referenced by message number
162                 msgnum = atol(buf);
163         }
164
165         // All methods except PUT require the message to already exist
166         if ((msgnum <= 0) && (strcasecmp(h->method, "PUT"))) {
167                 do_404(h);
168         }
169
170         // If we get to this point we have a valid message number in an accessible room.
171         syslog(LOG_DEBUG, "msgnum is %ld, method is %s", msgnum, h->method);
172
173         // A sixth component in the URL can be one of two things:
174         // (1) a MIME part specifier, in which case the client wants to download that component within the message
175         // (2) a content-type, in which ase the client wants us to try to render it a certain way
176         if (num_tokens(h->url, '/') == 6) {
177                 extract_token(buf, h->url, 5, '/', sizeof buf);
178                 if (!IsEmptyStr(buf)) {
179                         if (!strcasecmp(buf, "json")) {
180                                 json_render_one_message(h, c, msgnum);
181                         }
182                         else {
183                                 download_mime_component(h, c, msgnum, buf);
184                         }
185                         return;
186                 }
187         }
188
189         // Ok, we want a full message, but first let's check for the if[-none]-match headers.
190         char *if_match = header_val(h, "If-Match");
191         if ((if_match != NULL) && (!match_etags(if_match, msgnum))) {
192                 do_412(h);
193                 return;
194         }
195
196         char *if_none_match = header_val(h, "If-None-Match");
197         if ((if_none_match != NULL) && (match_etags(if_none_match, msgnum))) {
198                 do_412(h);
199                 return;
200         }
201
202         // DOOOOOO ITTTTT!!!
203
204         if (!strcasecmp(h->method, "DELETE")) {
205                 dav_delete_message(h, c, msgnum);
206         }
207         else if (!strcasecmp(h->method, "GET")) {
208                 dav_get_message(h, c, msgnum);
209         }
210         else if (!strcasecmp(h->method, "PUT")) {
211                 dav_put_message(h, c, unescaped_euid, msgnum);
212         }
213         else {
214                 do_404(h);      // Got this far but the method made no sense?  Bummer.
215         }
216
217 }
218
219
220 // Called by the_room_itself() when the HTTP method is REPORT
221 void report_the_room_itself(struct http_transaction *h, struct ctdlsession *c) {
222         if (c->room_default_view == VIEW_CALENDAR) {
223                 caldav_report(h, c);    // CalDAV REPORTs ... fmgwac
224                 return;
225         }
226
227         do_404(h);              // future implementations like CardDAV will require code paths here
228 }
229
230
231 // Called by the_room_itself() when the HTTP method is OPTIONS
232 void options_the_room_itself(struct http_transaction *h, struct ctdlsession *c) {
233         h->response_code = 200;
234         h->response_string = strdup("OK");
235         if (c->room_default_view == VIEW_CALENDAR) {
236                 add_response_header(h, strdup("DAV"), strdup("1, calendar-access"));    // offer CalDAV
237         }
238         else if (c->room_default_view == VIEW_ADDRESSBOOK) {
239                 add_response_header(h, strdup("DAV"), strdup("1, addressbook"));        // offer CardDAV
240         }
241         else {
242                 add_response_header(h, strdup("DAV"), strdup("1"));     // ordinary WebDAV for all other room types
243         }
244         add_response_header(h, strdup("Allow"), strdup("OPTIONS, PROPFIND, GET, PUT, REPORT, DELETE"));
245 }
246
247
248 // Called by the_room_itself() when the HTTP method is PROPFIND
249 void propfind_the_room_itself(struct http_transaction *h, struct ctdlsession *c) {
250         char *e;
251         long timestamp;
252         int dav_depth = (header_val(h, "Depth") ? atoi(header_val(h, "Depth")) : INT_MAX);
253         syslog(LOG_DEBUG, "Client PROPFIND requested depth: %d", dav_depth);
254         StrBuf *Buf = NewStrBuf();
255
256         StrBufAppendPrintf(Buf, "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
257                            "<D:multistatus " "xmlns:D=\"DAV:\" " "xmlns:C=\"urn:ietf:params:xml:ns:caldav\"" ">");
258
259         // Transmit the collection resource
260         StrBufAppendPrintf(Buf, "<D:response>");
261         StrBufAppendPrintf(Buf, "<D:href>");
262         StrBufXMLEscAppend(Buf, NULL, h->site_prefix, strlen(h->site_prefix), 0);
263         StrBufAppendPrintf(Buf, "/ctdl/r/");
264         StrBufXMLEscAppend(Buf, NULL, c->room, strlen(c->room), 0);
265         StrBufAppendPrintf(Buf, "</D:href>");
266
267         StrBufAppendPrintf(Buf, "<D:propstat>");
268         StrBufAppendPrintf(Buf, "<D:status>HTTP/1.1 200 OK</D:status>");
269         StrBufAppendPrintf(Buf, "<D:prop>");
270         StrBufAppendPrintf(Buf, "<D:displayname>");
271         StrBufXMLEscAppend(Buf, NULL, c->room, strlen(c->room), 0);
272         StrBufAppendPrintf(Buf, "</D:displayname>");
273
274         StrBufAppendPrintf(Buf, "<D:owner />"); // empty owner ought to be legal; see rfc3744 section 5.1
275
276         StrBufAppendPrintf(Buf, "<D:resourcetype><D:collection />");
277         switch (c->room_default_view) {
278         case VIEW_CALENDAR:
279                 StrBufAppendPrintf(Buf, "<C:calendar />");      // RFC4791 section 4.2
280                 break;
281         }
282         StrBufAppendPrintf(Buf, "</D:resourcetype>");
283
284         int enumerate_by_euid = 0;      // nonzero if messages will be retrieved by euid instead of msgnum
285         switch (c->room_default_view) {
286         case VIEW_CALENDAR:             // RFC4791 section 5.2
287                 StrBufAppendPrintf(Buf, "<C:supported-calendar-component-set><C:comp name=\"VEVENT\"/></C:supported-calendar-component-set>");
288                 StrBufAppendPrintf(Buf, "<C:supported-calendar-data>");
289                 StrBufAppendPrintf(Buf, "<C:calendar-data content-type=\"text/calendar\" version=\"2.0\"/>");
290                 StrBufAppendPrintf(Buf, "</C:supported-calendar-data>");
291                 enumerate_by_euid = 1;
292                 break;
293         case VIEW_TASKS:                // RFC4791 section 5.2
294                 StrBufAppendPrintf(Buf, "<C:supported-calendar-component-set><C:comp name=\"VTODO\"/></C:supported-calendar-component-set>");
295                 StrBufAppendPrintf(Buf, "<C:supported-calendar-data>");
296                 StrBufAppendPrintf(Buf, "<C:calendar-data content-type=\"text/calendar\" version=\"2.0\"/>");
297                 StrBufAppendPrintf(Buf, "</C:supported-calendar-data>");
298                 enumerate_by_euid = 1;
299                 break;
300         case VIEW_ADDRESSBOOK:          // FIXME put some sort of CardDAV crapola here when we implement it
301                 enumerate_by_euid = 1;
302                 break;
303         case VIEW_WIKI:                 // FIXME invent "WikiDAV" ?
304                 enumerate_by_euid = 1;
305                 break;
306         }
307
308         // FIXME get the mtime
309         // StrBufAppendPrintf(Buf, "<D:getlastmodified>");
310         // escputs(datestring);
311         // StrBufAppendPrintf(Buf, "</D:getlastmodified>");
312
313         StrBufAppendPrintf(Buf, "</D:prop>");
314         StrBufAppendPrintf(Buf, "</D:propstat>");
315         StrBufAppendPrintf(Buf, "</D:response>\n");
316
317         // If a depth greater than zero was specified, transmit the collection listing
318         // BEGIN COLLECTION
319         if (dav_depth > 0) {
320                 long *msglist = get_msglist(c, "ALL");
321                 if (msglist) {
322                         int i;
323                         for (i = 0; (msglist[i] > 0); ++i) {
324                                 if ((i % 10) == 0)
325                                         syslog(LOG_DEBUG, "PROPFIND enumerated %d messages", i);
326                                 e = NULL;       // EUID gets stored here
327                                 timestamp = 0;
328
329                                 char cbuf[1024];
330                                 ctdl_printf(c, "MSG0 %ld|3", msglist[i]);
331                                 ctdl_readline(c, cbuf, sizeof(cbuf));
332                                 if (cbuf[0] == '1')
333                                         while (ctdl_readline(c, cbuf, sizeof(cbuf)), strcmp(cbuf, "000")) {
334                                                 if ((enumerate_by_euid) && (!strncasecmp(cbuf, "exti=", 5))) {
335                                                         // e = strdup(&cbuf[5]);
336                                                         int elen = (2 * strlen(&cbuf[5]));
337                                                         e = malloc(elen);
338                                                         urlesc(e, elen, &cbuf[5]);
339                                                 }
340                                                 if (!strncasecmp(cbuf, "time=", 5)) {
341                                                         timestamp = atol(&cbuf[5]);
342                                                 }
343                                         }
344                                 if (e == NULL) {
345                                         e = malloc(20);
346                                         sprintf(e, "%ld", msglist[i]);
347                                 }
348                                 StrBufAppendPrintf(Buf, "<D:response>");
349
350                                 // Generate the 'href' tag for this message
351                                 StrBufAppendPrintf(Buf, "<D:href>");
352                                 StrBufXMLEscAppend(Buf, NULL, h->site_prefix, strlen(h->site_prefix), 0);
353                                 StrBufAppendPrintf(Buf, "/ctdl/r/");
354                                 StrBufXMLEscAppend(Buf, NULL, c->room, strlen(c->room), 0);
355                                 StrBufAppendPrintf(Buf, "/");
356                                 StrBufXMLEscAppend(Buf, NULL, e, strlen(e), 0);
357                                 StrBufAppendPrintf(Buf, "</D:href>");
358                                 StrBufAppendPrintf(Buf, "<D:propstat>");
359                                 StrBufAppendPrintf(Buf, "<D:status>HTTP/1.1 200 OK</D:status>");
360                                 StrBufAppendPrintf(Buf, "<D:prop>");
361
362                                 switch (c->room_default_view) {
363                                 case VIEW_CALENDAR:
364                                         StrBufAppendPrintf(Buf,
365                                                            "<D:getcontenttype>text/calendar; component=vevent</D:getcontenttype>");
366                                         break;
367                                 case VIEW_TASKS:
368                                         StrBufAppendPrintf(Buf,
369                                                            "<D:getcontenttype>text/calendar; component=vtodo</D:getcontenttype>");
370                                         break;
371                                 case VIEW_ADDRESSBOOK:
372                                         StrBufAppendPrintf(Buf, "<D:getcontenttype>text/x-vcard</D:getcontenttype>");
373                                         break;
374                                 }
375
376                                 if (timestamp > 0) {
377                                         char *datestring = http_datestring(timestamp);
378                                         if (datestring) {
379                                                 StrBufAppendPrintf(Buf, "<D:getlastmodified>");
380                                                 StrBufXMLEscAppend(Buf, NULL, datestring, strlen(datestring), 0);
381                                                 StrBufAppendPrintf(Buf, "</D:getlastmodified>");
382                                                 free(datestring);
383                                         }
384                                         if (enumerate_by_euid) {        // FIXME ajc 2017oct30 should this be inside the timestamp conditional?
385                                                 StrBufAppendPrintf(Buf, "<D:getetag>\"%ld\"</D:getetag>", msglist[i]);
386                                         }
387                                 }
388                                 StrBufAppendPrintf(Buf, "</D:prop></D:propstat></D:response>\n");
389                                 free(e);
390                         }
391                         free(msglist);
392                 };
393         }
394         // END COLLECTION
395
396         StrBufAppendPrintf(Buf, "</D:multistatus>\n");
397
398         add_response_header(h, strdup("Content-type"), strdup("text/xml"));
399         h->response_code = 207;
400         h->response_string = strdup("Multi-Status");
401         h->response_body_length = StrLength(Buf);
402         h->response_body = SmashStrBuf(&Buf);
403 }
404
405 // some good examples here
406 // http://blogs.nologin.es/rickyepoderi/index.php?/archives/14-Introducing-CalDAV-Part-I.html
407
408
409 // Called by the_room_itself() when the HTTP method is PROPFIND
410 void get_the_room_itself(struct http_transaction *h, struct ctdlsession *c) {
411         JsonValue *j = NewJsonObject(HKEY("gotoroom"));
412
413         JsonObjectAppend(j, NewJsonPlainString(HKEY("name"), c->room, -1));
414         JsonObjectAppend(j, NewJsonNumber(HKEY("current_view"), c->room_current_view));
415         JsonObjectAppend(j, NewJsonNumber(HKEY("default_view"), c->room_default_view));
416         JsonObjectAppend(j, NewJsonNumber(HKEY("new_messages"), c->new_messages));
417         JsonObjectAppend(j, NewJsonNumber(HKEY("total_messages"), c->total_messages));
418         JsonObjectAppend(j, NewJsonNumber(HKEY("last_seen"), c->last_seen));
419
420         StrBuf *sj = NewStrBuf();
421         SerializeJson(sj, j, 1);        // '1' == free the source array
422
423         add_response_header(h, strdup("Content-type"), strdup("application/json"));
424         h->response_code = 200;
425         h->response_string = strdup("OK");
426         h->response_body_length = StrLength(sj);
427         h->response_body = SmashStrBuf(&sj);
428         return;
429 }
430
431
432 // Handle REST/DAV requests for the room itself (such as /ctdl/r/roomname
433 // or /ctdl/r/roomname/ but *not* specific objects within the room)
434 void the_room_itself(struct http_transaction *h, struct ctdlsession *c) {
435
436         // OPTIONS method on the room itself usually is a DAV client assessing what's here.
437         if (!strcasecmp(h->method, "OPTIONS")) {
438                 options_the_room_itself(h, c);
439                 return;
440         }
441
442         // PROPFIND method on the room itself could be looking for a directory
443         if (!strcasecmp(h->method, "PROPFIND")) {
444                 propfind_the_room_itself(h, c);
445                 return;
446         }
447
448         // REPORT method on the room itself is probably the dreaded CalDAV tower-of-crapola
449         if (!strcasecmp(h->method, "REPORT")) {
450                 report_the_room_itself(h, c);
451                 return;
452         }
453
454         // GET method on the room itself is an API call, possibly from our JavaScript front end
455         if (!strcasecmp(h->method, "get")) {
456                 get_the_room_itself(h, c);
457                 return;
458         }
459
460         // we probably want a "go to this room" for interactive access
461         do_404(h);
462 }
463
464
465 // Dispatcher for "/ctdl/r" and "/ctdl/r/" for the room list
466 void room_list(struct http_transaction *h, struct ctdlsession *c) {
467         char buf[1024];
468         char roomname[1024];
469
470         ctdl_printf(c, "LKRA");
471         ctdl_readline(c, buf, sizeof(buf));
472         if (buf[0] != '1') {
473                 do_502(h);
474                 return;
475         }
476
477         JsonValue *j = NewJsonArray(HKEY("lkra"));
478         while (ctdl_readline(c, buf, sizeof(buf)), strcmp(buf, "000")) {
479
480                 // 0   |1      |2      |3      |4       |5 |6           |7           |8
481                 // name|QRflags|QRfloor|QRorder|QRflags2|ra|current_view|default_view|mtime
482                 JsonValue *jr = NewJsonObject(HKEY("room"));
483
484                 extract_token(roomname, buf, 0, '|', sizeof roomname);
485                 JsonObjectAppend(jr, NewJsonPlainString(HKEY("name"), roomname, -1));
486
487                 JsonObjectAppend(jr, NewJsonNumber(HKEY("floor"), extract_int(buf, 2)));
488                 JsonObjectAppend(jr, NewJsonNumber(HKEY("rorder"), extract_int(buf, 3)));
489
490                 int ra = extract_int(buf, 5);
491                 JsonObjectAppend(jr, NewJsonBool(HKEY("known"), (ra & UA_KNOWN)));
492                 JsonObjectAppend(jr, NewJsonBool(HKEY("hasnewmsgs"), (ra & UA_HASNEWMSGS)));
493
494                 JsonObjectAppend(jr, NewJsonNumber(HKEY("current_view"), extract_int(buf, 6)));
495                 JsonObjectAppend(jr, NewJsonNumber(HKEY("default_view"), extract_int(buf, 7)));
496                 JsonObjectAppend(jr, NewJsonNumber(HKEY("mtime"), extract_int(buf, 8)));
497
498                 JsonArrayAppend(j, jr); // add the room to the array
499         }
500
501         StrBuf *sj = NewStrBuf();
502         SerializeJson(sj, j, 1);        // '1' == free the source array
503
504         add_response_header(h, strdup("Content-type"), strdup("application/json"));
505         h->response_code = 200;
506         h->response_string = strdup("OK");
507         h->response_body_length = StrLength(sj);
508         h->response_body = SmashStrBuf(&sj);
509 }
510
511
512 // Dispatcher for paths starting with /ctdl/r/
513 void ctdl_r(struct http_transaction *h, struct ctdlsession *c) {
514         char requested_roomname[128];
515         char buf[1024];
516
517         // All room-related functions require being "in" the room specified.  Are we in that room already?
518         extract_token(requested_roomname, h->url, 3, '/', sizeof requested_roomname);
519         unescape_input(requested_roomname);
520
521         if (IsEmptyStr(requested_roomname)) {   //      /ctdl/r/
522                 room_list(h, c);
523                 return;
524         }
525         // If not, try to go there.
526         if (strcasecmp(requested_roomname, c->room)) {
527                 ctdl_printf(c, "GOTO %s", requested_roomname);
528                 ctdl_readline(c, buf, sizeof(buf));
529                 if (buf[0] == '2') {
530                         // buf[3] will indicate whether any instant messages are waiting
531                         extract_token(c->room, &buf[4], 0, '|', sizeof c->room);
532                         c->new_messages = extract_int(&buf[4], 1);
533                         c->total_messages = extract_int(&buf[4], 2);
534                         //      3       (int)info                       Info flag: set to nonzero if the user needs to read this room's info file
535                         //      4       (int)CC->room.QRflags           Various flags associated with this room.
536                         //      5       (long)CC->room.QRhighest        The highest message number present in this room
537                         c->last_seen = extract_long(&buf[4], 6);        // The highest message number the user has read in this room
538                         //      7       (int)rmailflag                  Boolean flag: 1 if this is a Mail> room, 0 otherwise.
539                         //      8       (int)raideflag                  Nonzero if user is either Aide or a Room Aide in this room
540                         //      9       (int)newmailcount               The number of new Mail messages the user has
541                         //      10      (int)CC->room.QRfloor           The floor number this room resides on
542                         c->room_current_view = extract_int(&buf[4], 11);
543                         c->room_default_view = extract_int(&buf[4], 12);
544                         //      13      (int)is_trash                   Boolean flag: 1 if this is the user's Trash folder, 0 otherwise.
545                         //      14      (int)CC->room.QRflags2          More flags associated with this room
546                         //      15      (long)CC->room.QRmtime          Timestamp of the last write activity in this room
547                 }
548                 else {
549                         do_404(h);
550                         return;
551                 }
552         }
553         // At this point our Citadel client session is "in" the specified room.
554
555         if (num_tokens(h->url, '/') == 4) {     //      /ctdl/r/roomname
556                 the_room_itself(h, c);
557                 return;
558         }
559
560         extract_token(buf, h->url, 4, '/', sizeof buf);
561         if (num_tokens(h->url, '/') == 5) {
562                 if (IsEmptyStr(buf)) {
563                         the_room_itself(h, c);  //      /ctdl/r/roomname/       ( same as /ctdl/r/roomname )
564                 }
565                 else {
566                         object_in_room(h, c);   //      /ctdl/r/roomname/object
567                 }
568                 return;
569         }
570         if (num_tokens(h->url, '/') == 6) {
571                 object_in_room(h, c);   //      /ctdl/r/roomname/object/ or possibly /ctdl/r/roomname/object/component
572                 return;
573         }
574         // If we get to this point, the client specified a valid room but requested an action we don't know how to perform.
575         do_404(h);
576 }