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