There can be only two.
[citadel.git] / webcit-ng / room_functions.c
index 75ef7bcf589edc7720a830b1c1b05fb874238283..5e432db8ec3dd44b8cf4994ba34b8ff84f8d3a54 100644 (file)
@@ -1,16 +1,17 @@
-/*
- * Room functions
- *
- * Copyright (c) 1996-2018 by the citadel.org team
- *
- * This program is open source software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- */
+//
+// Room functions
+//
+// Copyright (c) 1996-2021 by the citadel.org team
+//
+// This program is open source software.  It runs great on the
+// Linux operating system (and probably elsewhere).  You can use,
+// copy, and run it under the terms of the GNU General Public
+// License version 3.  Richard Stallman is an asshole communist.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
 
 #include "webcit.h"
 
@@ -19,8 +20,7 @@
  * Return a "zero-terminated" array of message numbers in the current room.
  * Caller owns the memory and must free it.  Returns NULL if any problems.
  */
-long *get_msglist(struct ctdlsession *c, char *which_msgs)
-{
+long *get_msglist(struct ctdlsession *c, char *which_msgs) {
        char buf[1024];
        long *msglist = NULL;
        int num_msgs = 0;
@@ -52,8 +52,7 @@ long *get_msglist(struct ctdlsession *c, char *which_msgs)
  * a message number (which we always use as the entity tag in Citadel), return nonzero if the
  * message number matches any of the supplied tags in the string.
  */
-int match_etags(char *taglist, long msgnum)
-{
+int match_etags(char *taglist, long msgnum) {
        int num_tags = num_tokens(taglist, ',');
        int i = 0;
        char tag[1024];
@@ -88,8 +87,7 @@ int match_etags(char *taglist, long msgnum)
 /*
  * Client is requesting a message list
  */
-void json_msglist(struct http_transaction *h, struct ctdlsession *c, char *which)
-{
+void json_msglist(struct http_transaction *h, struct ctdlsession *c, char *which) {
        int i = 0;
        long *msglist = get_msglist(c, which);
        JsonValue *j = NewJsonArray(HKEY("msgs"));
@@ -116,8 +114,7 @@ void json_msglist(struct http_transaction *h, struct ctdlsession *c, char *which
 /*
  * Client requested an object in a room.
  */
-void object_in_room(struct http_transaction *h, struct ctdlsession *c)
-{
+void object_in_room(struct http_transaction *h, struct ctdlsession *c) {
        char buf[1024];
        long msgnum = (-1);
        char unescaped_euid[1024];
@@ -204,11 +201,14 @@ void object_in_room(struct http_transaction *h, struct ctdlsession *c)
 
        if (!strcasecmp(h->method, "DELETE")) {
                dav_delete_message(h, c, msgnum);
-       } else if (!strcasecmp(h->method, "GET")) {
+       }
+       else if (!strcasecmp(h->method, "GET")) {
                dav_get_message(h, c, msgnum);
-       } else if (!strcasecmp(h->method, "PUT")) {
+       }
+       else if (!strcasecmp(h->method, "PUT")) {
                dav_put_message(h, c, unescaped_euid, msgnum);
-       } else {
+       }
+       else {
                do_404(h);      // Got this far but the method made no sense?  Bummer.
        }
 
@@ -218,8 +218,7 @@ void object_in_room(struct http_transaction *h, struct ctdlsession *c)
 /*
  * Called by the_room_itself() when the HTTP method is REPORT
  */
-void report_the_room_itself(struct http_transaction *h, struct ctdlsession *c)
-{
+void report_the_room_itself(struct http_transaction *h, struct ctdlsession *c) {
        if (c->room_default_view == VIEW_CALENDAR) {
                caldav_report(h, c);    // CalDAV REPORTs ... fmgwac
                return;
@@ -232,15 +231,16 @@ void report_the_room_itself(struct http_transaction *h, struct ctdlsession *c)
 /*
  * Called by the_room_itself() when the HTTP method is OPTIONS
  */
-void options_the_room_itself(struct http_transaction *h, struct ctdlsession *c)
-{
+void options_the_room_itself(struct http_transaction *h, struct ctdlsession *c) {
        h->response_code = 200;
        h->response_string = strdup("OK");
        if (c->room_default_view == VIEW_CALENDAR) {
                add_response_header(h, strdup("DAV"), strdup("1, calendar-access"));    // offer CalDAV
-       } else if (c->room_default_view == VIEW_ADDRESSBOOK) {
+       }
+       else if (c->room_default_view == VIEW_ADDRESSBOOK) {
                add_response_header(h, strdup("DAV"), strdup("1, addressbook"));        // offer CardDAV
-       } else {
+       }
+       else {
                add_response_header(h, strdup("DAV"), strdup("1"));     // ordinary WebDAV for all other room types
        }
        add_response_header(h, strdup("Allow"), strdup("OPTIONS, PROPFIND, GET, PUT, REPORT, DELETE"));
@@ -250,8 +250,7 @@ void options_the_room_itself(struct http_transaction *h, struct ctdlsession *c)
 /*
  * Called by the_room_itself() when the HTTP method is PROPFIND
  */
-void propfind_the_room_itself(struct http_transaction *h, struct ctdlsession *c)
-{
+void propfind_the_room_itself(struct http_transaction *h, struct ctdlsession *c) {
        char *e;
        long timestamp;
        int dav_depth = (header_val(h, "Depth") ? atoi(header_val(h, "Depth")) : INT_MAX);
@@ -288,31 +287,28 @@ void propfind_the_room_itself(struct http_transaction *h, struct ctdlsession *c)
 
        int enumerate_by_euid = 0;      // nonzero if messages will be retrieved by euid instead of msgnum
        switch (c->room_default_view) {
-       case VIEW_CALENDAR:     // RFC4791 section 5.2
-               StrBufAppendPrintf(Buf,
-                                  "<C:supported-calendar-component-set><C:comp name=\"VEVENT\"/></C:supported-calendar-component-set>");
+       case VIEW_CALENDAR:             // RFC4791 section 5.2
+               StrBufAppendPrintf(Buf, "<C:supported-calendar-component-set><C:comp name=\"VEVENT\"/></C:supported-calendar-component-set>");
                StrBufAppendPrintf(Buf, "<C:supported-calendar-data>");
                StrBufAppendPrintf(Buf, "<C:calendar-data content-type=\"text/calendar\" version=\"2.0\"/>");
                StrBufAppendPrintf(Buf, "</C:supported-calendar-data>");
                enumerate_by_euid = 1;
                break;
-       case VIEW_TASKS:        // RFC4791 section 5.2
-               StrBufAppendPrintf(Buf,
-                                  "<C:supported-calendar-component-set><C:comp name=\"VTODO\"/></C:supported-calendar-component-set>");
+       case VIEW_TASKS:                // RFC4791 section 5.2
+               StrBufAppendPrintf(Buf, "<C:supported-calendar-component-set><C:comp name=\"VTODO\"/></C:supported-calendar-component-set>");
                StrBufAppendPrintf(Buf, "<C:supported-calendar-data>");
                StrBufAppendPrintf(Buf, "<C:calendar-data content-type=\"text/calendar\" version=\"2.0\"/>");
                StrBufAppendPrintf(Buf, "</C:supported-calendar-data>");
                enumerate_by_euid = 1;
                break;
-       case VIEW_ADDRESSBOOK:  // FIXME put some sort of CardDAV crapola here when we implement it
+       case VIEW_ADDRESSBOOK:          // FIXME put some sort of CardDAV crapola here when we implement it
                enumerate_by_euid = 1;
                break;
-       case VIEW_WIKI: // FIXME invent "WikiDAV" ?
+       case VIEW_WIKI:                 // FIXME invent "WikiDAV" ?
                enumerate_by_euid = 1;
                break;
        }
 
-
        /* FIXME get the mtime
           StrBufAppendPrintf(Buf, "<D:getlastmodified>");
           escputs(datestring);
@@ -446,32 +442,32 @@ void get_the_room_itself(struct http_transaction *h, struct ctdlsession *c)
  * Handle REST/DAV requests for the room itself (such as /ctdl/r/roomname
  * or /ctdl/r/roomname/ but *not* specific objects within the room)
  */
-void the_room_itself(struct http_transaction *h, struct ctdlsession *c)
-{
-       // OPTIONS method on the room itself usually is a DAV client assessing what's here.
+void the_room_itself(struct http_transaction *h, struct ctdlsession *c) {
 
+       // OPTIONS method on the room itself usually is a DAV client assessing what's here.
        if (!strcasecmp(h->method, "OPTIONS")) {
                options_the_room_itself(h, c);
                return;
        }
-       // PROPFIND method on the room itself could be looking for a directory
 
+       // PROPFIND method on the room itself could be looking for a directory
        if (!strcasecmp(h->method, "PROPFIND")) {
                propfind_the_room_itself(h, c);
                return;
        }
-       // REPORT method on the room itself is probably the dreaded CalDAV tower-of-crapola
 
+       // REPORT method on the room itself is probably the dreaded CalDAV tower-of-crapola
        if (!strcasecmp(h->method, "REPORT")) {
                report_the_room_itself(h, c);
                return;
        }
-       // GET method on the room itself is an API call, possibly from our JavaScript front end
 
+       // GET method on the room itself is an API call, possibly from our JavaScript front end
        if (!strcasecmp(h->method, "get")) {
                get_the_room_itself(h, c);
                return;
        }
+
        // we probably want a "go to this room" for interactive access
        do_404(h);
 }
@@ -480,8 +476,7 @@ void the_room_itself(struct http_transaction *h, struct ctdlsession *c)
 /*
  * Dispatcher for "/ctdl/r" and "/ctdl/r/" for the room list
  */
-void room_list(struct http_transaction *h, struct ctdlsession *c)
-{
+void room_list(struct http_transaction *h, struct ctdlsession *c) {
        char buf[1024];
        char roomname[1024];
 
@@ -502,8 +497,8 @@ void room_list(struct http_transaction *h, struct ctdlsession *c)
                JsonObjectAppend(jr, NewJsonPlainString(HKEY("name"), roomname, -1));
 
                int ra = extract_int(buf, 5);
-               JsonObjectAppend(jr, NewJsonBool(HKEY("known"), (ra && UA_KNOWN)));
-               JsonObjectAppend(jr, NewJsonBool(HKEY("hasnewmsgs"), (ra && UA_HASNEWMSGS)));
+               JsonObjectAppend(jr, NewJsonBool(HKEY("known"), (ra & UA_KNOWN)));
+               JsonObjectAppend(jr, NewJsonBool(HKEY("hasnewmsgs"), (ra & UA_HASNEWMSGS)));
 
                int floor = extract_int(buf, 2);
                JsonObjectAppend(jr, NewJsonNumber(HKEY("floor"), floor));
@@ -528,8 +523,7 @@ void room_list(struct http_transaction *h, struct ctdlsession *c)
 /*
  * Dispatcher for paths starting with /ctdl/r/
  */
-void ctdl_r(struct http_transaction *h, struct ctdlsession *c)
-{
+void ctdl_r(struct http_transaction *h, struct ctdlsession *c) {
        char requested_roomname[128];
        char buf[1024];