Skip/Goto are functionally complete.
[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 is setting the "Last Read Pointer" (marking all messages as "seen" up to this message)
133 void set_last_read_pointer(struct http_transaction *h, struct ctdlsession *c) {
134         char cbuf[1024];
135         ctdl_printf(c, "SLRP %d", atoi(get_url_param(h, "last")));
136         ctdl_readline(c, cbuf, sizeof(cbuf));
137         if (cbuf[0] == '2') {
138                 do_204(h);
139         }
140         else {
141                 do_404(h);
142         }
143 }
144
145
146 // Client requested an object in a room.
147 void object_in_room(struct http_transaction *h, struct ctdlsession *c) {
148         char buf[1024];
149         long msgnum = (-1);
150         char unescaped_euid[1024];
151
152         extract_token(buf, h->url, 4, '/', sizeof buf);
153
154         if (!strncasecmp(buf, "msgs.", 5)) {            // Client is requesting a list of message numbers
155                 unescape_input(&buf[5]);
156                 json_msglist(h, c, &buf[5]);
157                 return;
158         }
159
160         if (!strcasecmp(buf, "info.txt")) {             // Client is requesting the room info banner
161                 read_room_info_banner(h, c);
162                 return;
163         }
164
165         if (!strcasecmp(buf, "slrp")) {                 // Set the Last Read Pointer
166                 set_last_read_pointer(h, c);
167                 return;
168         }
169
170         // If we get to this point, the client is requesting a specific object *in* the room.
171
172         if ((c->room_default_view == VIEW_CALENDAR)     // room types where objects are referenced by EUID
173            || (c->room_default_view == VIEW_TASKS)
174            || (c->room_default_view == VIEW_ADDRESSBOOK)
175            ) {
176                 safestrncpy(unescaped_euid, buf, sizeof unescaped_euid);
177                 unescape_input(unescaped_euid);
178                 msgnum = locate_message_by_uid(c, unescaped_euid);
179         }
180         else {                                          // otherwise the object is being referenced by message number
181                 msgnum = atol(buf);
182         }
183
184         // All methods except PUT require the message to already exist
185         if ((msgnum <= 0) && (strcasecmp(h->method, "PUT"))) {
186                 do_404(h);
187         }
188
189         // If we get to this point we have a valid message number in an accessible room.
190         syslog(LOG_DEBUG, "msgnum is %ld, method is %s", msgnum, h->method);
191
192         // A sixth component in the URL can be one of two things:
193         // (1) a MIME part specifier, in which case the client wants to download that component within the message
194         // (2) a content-type, in which ase the client wants us to try to render it a certain way
195         if (num_tokens(h->url, '/') == 6) {
196                 extract_token(buf, h->url, 5, '/', sizeof buf);
197                 if (!IsEmptyStr(buf)) {
198                         if (!strcasecmp(buf, "json")) {
199                                 json_render_one_message(h, c, msgnum);
200                         }
201                         else {
202                                 download_mime_component(h, c, msgnum, buf);
203                         }
204                         return;
205                 }
206         }
207
208         // Ok, we want a full message, but first let's check for the if[-none]-match headers.
209         char *if_match = header_val(h, "If-Match");
210         if ((if_match != NULL) && (!match_etags(if_match, msgnum))) {
211                 do_412(h);
212                 return;
213         }
214
215         char *if_none_match = header_val(h, "If-None-Match");
216         if ((if_none_match != NULL) && (match_etags(if_none_match, msgnum))) {
217                 do_412(h);
218                 return;
219         }
220
221         // DOOOOOO ITTTTT!!!
222
223         if (!strcasecmp(h->method, "DELETE")) {
224                 dav_delete_message(h, c, msgnum);
225         }
226         else if (!strcasecmp(h->method, "GET")) {
227                 dav_get_message(h, c, msgnum);
228         }
229         else if (!strcasecmp(h->method, "PUT")) {
230                 dav_put_message(h, c, unescaped_euid, msgnum);
231         }
232         else {
233                 do_404(h);      // Got this far but the method made no sense?  Bummer.
234         }
235
236 }
237
238
239 // Called by the_room_itself() when the HTTP method is REPORT
240 void report_the_room_itself(struct http_transaction *h, struct ctdlsession *c) {
241         if (c->room_default_view == VIEW_CALENDAR) {
242                 caldav_report(h, c);    // CalDAV REPORTs ... fmgwac
243                 return;
244         }
245
246         do_404(h);              // future implementations like CardDAV will require code paths here
247 }
248
249
250 // Called by the_room_itself() when the HTTP method is OPTIONS
251 void options_the_room_itself(struct http_transaction *h, struct ctdlsession *c) {
252         h->response_code = 200;
253         h->response_string = strdup("OK");
254         if (c->room_default_view == VIEW_CALENDAR) {
255                 add_response_header(h, strdup("DAV"), strdup("1, calendar-access"));    // offer CalDAV
256         }
257         else if (c->room_default_view == VIEW_ADDRESSBOOK) {
258                 add_response_header(h, strdup("DAV"), strdup("1, addressbook"));        // offer CardDAV
259         }
260         else {
261                 add_response_header(h, strdup("DAV"), strdup("1"));     // ordinary WebDAV for all other room types
262         }
263         add_response_header(h, strdup("Allow"), strdup("OPTIONS, PROPFIND, GET, PUT, REPORT, DELETE"));
264 }
265
266
267 // Called by the_room_itself() when the HTTP method is PROPFIND
268 void propfind_the_room_itself(struct http_transaction *h, struct ctdlsession *c) {
269         char *e;
270         long timestamp;
271         int dav_depth = (header_val(h, "Depth") ? atoi(header_val(h, "Depth")) : INT_MAX);
272         syslog(LOG_DEBUG, "Client PROPFIND requested depth: %d", dav_depth);
273         StrBuf *Buf = NewStrBuf();
274
275         StrBufAppendPrintf(Buf, "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
276                            "<D:multistatus " "xmlns:D=\"DAV:\" " "xmlns:C=\"urn:ietf:params:xml:ns:caldav\"" ">");
277
278         // Transmit the collection resource
279         StrBufAppendPrintf(Buf, "<D:response>");
280         StrBufAppendPrintf(Buf, "<D:href>");
281         StrBufXMLEscAppend(Buf, NULL, h->site_prefix, strlen(h->site_prefix), 0);
282         StrBufAppendPrintf(Buf, "/ctdl/r/");
283         StrBufXMLEscAppend(Buf, NULL, c->room, strlen(c->room), 0);
284         StrBufAppendPrintf(Buf, "</D:href>");
285
286         StrBufAppendPrintf(Buf, "<D:propstat>");
287         StrBufAppendPrintf(Buf, "<D:status>HTTP/1.1 200 OK</D:status>");
288         StrBufAppendPrintf(Buf, "<D:prop>");
289         StrBufAppendPrintf(Buf, "<D:displayname>");
290         StrBufXMLEscAppend(Buf, NULL, c->room, strlen(c->room), 0);
291         StrBufAppendPrintf(Buf, "</D:displayname>");
292
293         StrBufAppendPrintf(Buf, "<D:owner />"); // empty owner ought to be legal; see rfc3744 section 5.1
294
295         StrBufAppendPrintf(Buf, "<D:resourcetype><D:collection />");
296         switch (c->room_default_view) {
297         case VIEW_CALENDAR:
298                 StrBufAppendPrintf(Buf, "<C:calendar />");      // RFC4791 section 4.2
299                 break;
300         }
301         StrBufAppendPrintf(Buf, "</D:resourcetype>");
302
303         int enumerate_by_euid = 0;      // nonzero if messages will be retrieved by euid instead of msgnum
304         switch (c->room_default_view) {
305         case VIEW_CALENDAR:             // RFC4791 section 5.2
306                 StrBufAppendPrintf(Buf, "<C:supported-calendar-component-set><C:comp name=\"VEVENT\"/></C:supported-calendar-component-set>");
307                 StrBufAppendPrintf(Buf, "<C:supported-calendar-data>");
308                 StrBufAppendPrintf(Buf, "<C:calendar-data content-type=\"text/calendar\" version=\"2.0\"/>");
309                 StrBufAppendPrintf(Buf, "</C:supported-calendar-data>");
310                 enumerate_by_euid = 1;
311                 break;
312         case VIEW_TASKS:                // RFC4791 section 5.2
313                 StrBufAppendPrintf(Buf, "<C:supported-calendar-component-set><C:comp name=\"VTODO\"/></C:supported-calendar-component-set>");
314                 StrBufAppendPrintf(Buf, "<C:supported-calendar-data>");
315                 StrBufAppendPrintf(Buf, "<C:calendar-data content-type=\"text/calendar\" version=\"2.0\"/>");
316                 StrBufAppendPrintf(Buf, "</C:supported-calendar-data>");
317                 enumerate_by_euid = 1;
318                 break;
319         case VIEW_ADDRESSBOOK:          // FIXME put some sort of CardDAV crapola here when we implement it
320                 enumerate_by_euid = 1;
321                 break;
322         case VIEW_WIKI:                 // FIXME invent "WikiDAV" ?
323                 enumerate_by_euid = 1;
324                 break;
325         }
326
327         // FIXME get the mtime
328         // StrBufAppendPrintf(Buf, "<D:getlastmodified>");
329         // escputs(datestring);
330         // StrBufAppendPrintf(Buf, "</D:getlastmodified>");
331
332         StrBufAppendPrintf(Buf, "</D:prop>");
333         StrBufAppendPrintf(Buf, "</D:propstat>");
334         StrBufAppendPrintf(Buf, "</D:response>\n");
335
336         // If a depth greater than zero was specified, transmit the collection listing
337         // BEGIN COLLECTION
338         if (dav_depth > 0) {
339                 long *msglist = get_msglist(c, "ALL");
340                 if (msglist) {
341                         int i;
342                         for (i = 0; (msglist[i] > 0); ++i) {
343                                 if ((i % 10) == 0)
344                                         syslog(LOG_DEBUG, "PROPFIND enumerated %d messages", i);
345                                 e = NULL;       // EUID gets stored here
346                                 timestamp = 0;
347
348                                 char cbuf[1024];
349                                 ctdl_printf(c, "MSG0 %ld|3", msglist[i]);
350                                 ctdl_readline(c, cbuf, sizeof(cbuf));
351                                 if (cbuf[0] == '1')
352                                         while (ctdl_readline(c, cbuf, sizeof(cbuf)), strcmp(cbuf, "000")) {
353                                                 if ((enumerate_by_euid) && (!strncasecmp(cbuf, "exti=", 5))) {
354                                                         // e = strdup(&cbuf[5]);
355                                                         int elen = (2 * strlen(&cbuf[5]));
356                                                         e = malloc(elen);
357                                                         urlesc(e, elen, &cbuf[5]);
358                                                 }
359                                                 if (!strncasecmp(cbuf, "time=", 5)) {
360                                                         timestamp = atol(&cbuf[5]);
361                                                 }
362                                         }
363                                 if (e == NULL) {
364                                         e = malloc(20);
365                                         sprintf(e, "%ld", msglist[i]);
366                                 }
367                                 StrBufAppendPrintf(Buf, "<D:response>");
368
369                                 // Generate the 'href' tag for this message
370                                 StrBufAppendPrintf(Buf, "<D:href>");
371                                 StrBufXMLEscAppend(Buf, NULL, h->site_prefix, strlen(h->site_prefix), 0);
372                                 StrBufAppendPrintf(Buf, "/ctdl/r/");
373                                 StrBufXMLEscAppend(Buf, NULL, c->room, strlen(c->room), 0);
374                                 StrBufAppendPrintf(Buf, "/");
375                                 StrBufXMLEscAppend(Buf, NULL, e, strlen(e), 0);
376                                 StrBufAppendPrintf(Buf, "</D:href>");
377                                 StrBufAppendPrintf(Buf, "<D:propstat>");
378                                 StrBufAppendPrintf(Buf, "<D:status>HTTP/1.1 200 OK</D:status>");
379                                 StrBufAppendPrintf(Buf, "<D:prop>");
380
381                                 switch (c->room_default_view) {
382                                 case VIEW_CALENDAR:
383                                         StrBufAppendPrintf(Buf,
384                                                            "<D:getcontenttype>text/calendar; component=vevent</D:getcontenttype>");
385                                         break;
386                                 case VIEW_TASKS:
387                                         StrBufAppendPrintf(Buf,
388                                                            "<D:getcontenttype>text/calendar; component=vtodo</D:getcontenttype>");
389                                         break;
390                                 case VIEW_ADDRESSBOOK:
391                                         StrBufAppendPrintf(Buf, "<D:getcontenttype>text/x-vcard</D:getcontenttype>");
392                                         break;
393                                 }
394
395                                 if (timestamp > 0) {
396                                         char *datestring = http_datestring(timestamp);
397                                         if (datestring) {
398                                                 StrBufAppendPrintf(Buf, "<D:getlastmodified>");
399                                                 StrBufXMLEscAppend(Buf, NULL, datestring, strlen(datestring), 0);
400                                                 StrBufAppendPrintf(Buf, "</D:getlastmodified>");
401                                                 free(datestring);
402                                         }
403                                         if (enumerate_by_euid) {        // FIXME ajc 2017oct30 should this be inside the timestamp conditional?
404                                                 StrBufAppendPrintf(Buf, "<D:getetag>\"%ld\"</D:getetag>", msglist[i]);
405                                         }
406                                 }
407                                 StrBufAppendPrintf(Buf, "</D:prop></D:propstat></D:response>\n");
408                                 free(e);
409                         }
410                         free(msglist);
411                 };
412         }
413         // END COLLECTION
414
415         StrBufAppendPrintf(Buf, "</D:multistatus>\n");
416
417         add_response_header(h, strdup("Content-type"), strdup("text/xml"));
418         h->response_code = 207;
419         h->response_string = strdup("Multi-Status");
420         h->response_body_length = StrLength(Buf);
421         h->response_body = SmashStrBuf(&Buf);
422 }
423
424 // some good examples here
425 // http://blogs.nologin.es/rickyepoderi/index.php?/archives/14-Introducing-CalDAV-Part-I.html
426
427
428 // Called by the_room_itself() when the HTTP method is PROPFIND
429 void get_the_room_itself(struct http_transaction *h, struct ctdlsession *c) {
430         JsonValue *j = NewJsonObject(HKEY("gotoroom"));
431
432         JsonObjectAppend(j, NewJsonPlainString(HKEY("name"), c->room, -1));
433         JsonObjectAppend(j, NewJsonNumber(HKEY("current_view"), c->room_current_view));
434         JsonObjectAppend(j, NewJsonNumber(HKEY("default_view"), c->room_default_view));
435         JsonObjectAppend(j, NewJsonNumber(HKEY("new_messages"), c->new_messages));
436         JsonObjectAppend(j, NewJsonNumber(HKEY("total_messages"), c->total_messages));
437         JsonObjectAppend(j, NewJsonNumber(HKEY("last_seen"), c->last_seen));
438
439         StrBuf *sj = NewStrBuf();
440         SerializeJson(sj, j, 1);        // '1' == free the source array
441
442         add_response_header(h, strdup("Content-type"), strdup("application/json"));
443         h->response_code = 200;
444         h->response_string = strdup("OK");
445         h->response_body_length = StrLength(sj);
446         h->response_body = SmashStrBuf(&sj);
447         return;
448 }
449
450
451 // Handle REST/DAV requests for the room itself (such as /ctdl/r/roomname
452 // or /ctdl/r/roomname/ but *not* specific objects within the room)
453 void the_room_itself(struct http_transaction *h, struct ctdlsession *c) {
454
455         // OPTIONS method on the room itself usually is a DAV client assessing what's here.
456         if (!strcasecmp(h->method, "OPTIONS")) {
457                 options_the_room_itself(h, c);
458                 return;
459         }
460
461         // PROPFIND method on the room itself could be looking for a directory
462         if (!strcasecmp(h->method, "PROPFIND")) {
463                 propfind_the_room_itself(h, c);
464                 return;
465         }
466
467         // REPORT method on the room itself is probably the dreaded CalDAV tower-of-crapola
468         if (!strcasecmp(h->method, "REPORT")) {
469                 report_the_room_itself(h, c);
470                 return;
471         }
472
473         // GET method on the room itself is an API call, possibly from our JavaScript front end
474         if (!strcasecmp(h->method, "get")) {
475                 get_the_room_itself(h, c);
476                 return;
477         }
478
479         // we probably want a "go to this room" for interactive access
480         do_404(h);
481 }
482
483
484 // Dispatcher for "/ctdl/r" and "/ctdl/r/" for the room list
485 void room_list(struct http_transaction *h, struct ctdlsession *c) {
486         char buf[1024];
487         char roomname[1024];
488
489         ctdl_printf(c, "LKRA");
490         ctdl_readline(c, buf, sizeof(buf));
491         if (buf[0] != '1') {
492                 do_502(h);
493                 return;
494         }
495
496         JsonValue *j = NewJsonArray(HKEY("lkra"));
497         while (ctdl_readline(c, buf, sizeof(buf)), strcmp(buf, "000")) {
498
499                 // 0   |1      |2      |3      |4       |5 |6           |7           |8
500                 // name|QRflags|QRfloor|QRorder|QRflags2|ra|current_view|default_view|mtime
501                 JsonValue *jr = NewJsonObject(HKEY("room"));
502
503                 extract_token(roomname, buf, 0, '|', sizeof roomname);
504                 JsonObjectAppend(jr, NewJsonPlainString(HKEY("name"), roomname, -1));
505
506                 JsonObjectAppend(jr, NewJsonNumber(HKEY("floor"), extract_int(buf, 2)));
507                 JsonObjectAppend(jr, NewJsonNumber(HKEY("rorder"), extract_int(buf, 3)));
508
509                 int ra = extract_int(buf, 5);
510                 JsonObjectAppend(jr, NewJsonBool(HKEY("known"), (ra & UA_KNOWN)));
511                 JsonObjectAppend(jr, NewJsonBool(HKEY("hasnewmsgs"), (ra & UA_HASNEWMSGS)));
512
513                 JsonObjectAppend(jr, NewJsonNumber(HKEY("current_view"), extract_int(buf, 6)));
514                 JsonObjectAppend(jr, NewJsonNumber(HKEY("default_view"), extract_int(buf, 7)));
515                 JsonObjectAppend(jr, NewJsonNumber(HKEY("mtime"), extract_int(buf, 8)));
516
517                 JsonArrayAppend(j, jr); // add the room to the array
518         }
519
520         StrBuf *sj = NewStrBuf();
521         SerializeJson(sj, j, 1);        // '1' == free the source array
522
523         add_response_header(h, strdup("Content-type"), strdup("application/json"));
524         h->response_code = 200;
525         h->response_string = strdup("OK");
526         h->response_body_length = StrLength(sj);
527         h->response_body = SmashStrBuf(&sj);
528 }
529
530
531 // Dispatcher for paths starting with /ctdl/r/
532 void ctdl_r(struct http_transaction *h, struct ctdlsession *c) {
533         char requested_roomname[128];
534         char buf[1024];
535
536         // All room-related functions require being "in" the room specified.  Are we in that room already?
537         extract_token(requested_roomname, h->url, 3, '/', sizeof requested_roomname);
538         unescape_input(requested_roomname);
539
540         if (IsEmptyStr(requested_roomname)) {   //      /ctdl/r/
541                 room_list(h, c);
542                 return;
543         }
544         // If not, try to go there.
545         if (strcasecmp(requested_roomname, c->room)) {
546                 ctdl_printf(c, "GOTO %s", requested_roomname);
547                 ctdl_readline(c, buf, sizeof(buf));
548                 if (buf[0] == '2') {
549                         // buf[3] will indicate whether any instant messages are waiting
550                         extract_token(c->room, &buf[4], 0, '|', sizeof c->room);
551                         c->new_messages = extract_int(&buf[4], 1);
552                         c->total_messages = extract_int(&buf[4], 2);
553                         //      3       (int)info                       Info flag: set to nonzero if the user needs to read this room's info file
554                         //      4       (int)CC->room.QRflags           Various flags associated with this room.
555                         //      5       (long)CC->room.QRhighest        The highest message number present in this room
556                         c->last_seen = extract_long(&buf[4], 6);        // The highest message number the user has read in this room
557                         //      7       (int)rmailflag                  Boolean flag: 1 if this is a Mail> room, 0 otherwise.
558                         //      8       (int)raideflag                  Nonzero if user is either Aide or a Room Aide in this room
559                         //      9       (int)newmailcount               The number of new Mail messages the user has
560                         //      10      (int)CC->room.QRfloor           The floor number this room resides on
561                         c->room_current_view = extract_int(&buf[4], 11);
562                         c->room_default_view = extract_int(&buf[4], 12);
563                         //      13      (int)is_trash                   Boolean flag: 1 if this is the user's Trash folder, 0 otherwise.
564                         //      14      (int)CC->room.QRflags2          More flags associated with this room
565                         //      15      (long)CC->room.QRmtime          Timestamp of the last write activity in this room
566                 }
567                 else {
568                         do_404(h);
569                         return;
570                 }
571         }
572         // At this point our Citadel client session is "in" the specified room.
573
574         if (num_tokens(h->url, '/') == 4) {     //      /ctdl/r/roomname
575                 the_room_itself(h, c);
576                 return;
577         }
578
579         extract_token(buf, h->url, 4, '/', sizeof buf);
580         if (num_tokens(h->url, '/') == 5) {
581                 if (IsEmptyStr(buf)) {
582                         the_room_itself(h, c);  //      /ctdl/r/roomname/       ( same as /ctdl/r/roomname )
583                 }
584                 else {
585                         object_in_room(h, c);   //      /ctdl/r/roomname/object
586                 }
587                 return;
588         }
589         if (num_tokens(h->url, '/') == 6) {
590                 object_in_room(h, c);   //      /ctdl/r/roomname/object/ or possibly /ctdl/r/roomname/object/component
591                 return;
592         }
593         // If we get to this point, the client specified a valid room but requested an action we don't know how to perform.
594         do_404(h);
595 }