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