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