]> code.citadel.org Git - citadel.git/blobdiff - webcit-ng/room_functions.c
Release version 932 generated by do-release.sh
[citadel.git] / webcit-ng / room_functions.c
index 403e83f70c2b1d9d43d462c065ceb1067590e95d..9bf9c58bed956012d31e3e7926e57b6a1ca475a6 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.
+//
+// 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;
@@ -28,7 +28,7 @@ long *get_msglist(struct ctdlsession *c, char *which_msgs)
 
        ctdl_printf(c, "MSGS %s", which_msgs);
        ctdl_readline(c, buf, sizeof(buf));
-       if (buf[0] == '1')
+       if (buf[0] == '1') {
                do {
                        if (num_msgs >= num_alloc) {
                                if (num_alloc == 0) {
@@ -42,6 +42,7 @@ long *get_msglist(struct ctdlsession *c, char *which_msgs)
                        ctdl_readline(c, buf, sizeof(buf));
                        msglist[num_msgs++] = atol(buf);
                } while (strcmp(buf, "000"));   // this makes the last element a "0" terminator
+       }
        return msglist;
 }
 
@@ -51,14 +52,12 @@ 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];
 
-       if (msgnum <= 0)        // no msgnum?  no match.
-       {
+       if (msgnum <= 0) {                                      // no msgnum?  no match.
                return (0);
        }
 
@@ -67,32 +66,28 @@ int match_etags(char *taglist, long msgnum)
                striplt(tag);
                char *lq = (strchr(tag, '"'));
                char *rq = (strrchr(tag, '"'));
-               if (lq < rq)    // has two double quotes
-               {
+               if (lq < rq) {                                  // has two double quotes
                        strcpy(rq, "");
                        strcpy(tag, ++lq);
                }
                striplt(tag);
-               if (!strcmp(tag, "*"))  // wildcard match
-               {
+               if (!strcmp(tag, "*")) {                        // wildcard match
                        return (1);
                }
                long tagmsgnum = atol(tag);
-               if ((tagmsgnum > 0) && (tagmsgnum == msgnum))   // match
-               {
+               if ((tagmsgnum > 0) && (tagmsgnum == msgnum)) { // match
                        return (1);
                }
        }
 
-       return (0);             // no match
+       return (0);                                             // no match
 }
 
 
 /*
  * 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"));
@@ -119,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];
@@ -207,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.
        }
 
@@ -221,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;
@@ -235,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"));
@@ -253,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);
@@ -291,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);
@@ -449,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);
 }
@@ -483,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];
 
@@ -505,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));
@@ -531,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];