Began refactoring CALDAV REPORT flow of control.
authorArt Cancro <ajc@citadel.org>
Wed, 24 Jan 2024 20:19:57 +0000 (10:19 -1000)
committerArt Cancro <ajc@citadel.org>
Wed, 24 Jan 2024 20:19:57 +0000 (10:19 -1000)
Removed calendar_functions.c and brought some of its code over
to caldav_reports.c so that we can use the same code path for all
three types of REPORTs.

This is motivated by an idea that perhaps the user interface can
use CalDAV as its REST API instead of inventing something new.  If
that doesn't work, we needed to finish CalDAV eventually anyway.

webcit-ng/api.txt
webcit-ng/server/caldav_reports.c
webcit-ng/server/calendar_functions.c [deleted file]
webcit-ng/server/room_functions.c
webcit-ng/server/webcit.h

index cf0652af0bca1a2220bb501b0814c9da7f236207..8660c8f2ca7d20f17fc0a243d90e3247993fb963 100644 (file)
@@ -16,12 +16,6 @@ GET             /ctdl/r/<roomname>/stat            JSON dictionary of the server
 GET             /ctdl/r/<roomname>/<msgnum>        Retrieve the content of an individual message
 GET             /ctdl/r/<roomname>/<msgnum>/json   Retrieve an individual message in a room, encapsulated in JSON
 GET             /ctdl/r/<roomname>/<msgnum>/<part> Retrieve a MIME component of a message, specified by partnum
-
-GET             /ctdl/r/<roomname>/calendar:<from>:<to>
-                                                   Retrieve calendar items in the current room.
-                                                   "from" and "to" comprise a range expressed in unix timestamps.
-                                                   You can omit either or both timestamps but not the colons.
-
 DELETE          /ctdl/r/<roomname>/<msgnum>        Delete a message from a room
 MOVE            /ctdl/r/<roomname>/<msgnum>        Move a message to another room (requires Destination)
 
index 70a4e8095722d8312f763319bdf07a72f6ad97f5..edd0b4558cffc0742568fe82bf73885cca4b9c80 100644 (file)
@@ -1,7 +1,7 @@
 // This file contains functions which handle all of the CalDAV "REPORT" queries
 // specified in RFC4791 section 7.
 //
-// Copyright (c) 2023 by the citadel.org team
+// Copyright (c) 2023-2024 by the citadel.org team
 //
 // This program is open source software.  Use, duplication, or
 // disclosure is subject to the GNU General Public License v3.
@@ -39,14 +39,17 @@ void caldav_xml_start(void *data, const char *el, const char **attr) {
                syslog(LOG_DEBUG, "                    Attribute '%s' = '%s'", attr[i], attr[i + 1]);
        }
 
-       if (!strcasecmp(el, "urn:ietf:params:xml:ns:caldav:calendar-multiget")) {
-               crp->report_type = cr_calendar_multiget;
+       // RFC4791 7.8 "calendar-query" REPORT - Client will send a lot of search criteria.
+       if (!strcasecmp(el, "urn:ietf:params:xml:ns:caldav:calendar-query")) {
+               crp->report_type = cr_calendar_query;
        }
 
-       else if (!strcasecmp(el, "urn:ietf:params:xml:ns:caldav:calendar-query")) {
-               crp->report_type = cr_calendar_query;
+       // RFC4791 7.9 "calendar-multiget" REPORT - Client will supply a list of specific hrefs.
+       else if (!strcasecmp(el, "urn:ietf:params:xml:ns:caldav:calendar-multiget")) {
+               crp->report_type = cr_calendar_multiget;
        }
 
+       // RFC4791 7.10 "free-busy-query" REPORT
        else if (!strcasecmp(el, "urn:ietf:params:xml:ns:caldav:free-busy-query")) {
                crp->report_type = cr_freebusy_query;
        }
@@ -248,7 +251,8 @@ void caldav_report(struct http_transaction *h, struct ctdlsession *c) {
                ">"
        );
 
-       if (crp.Hrefs != NULL) {        // Output all qualifying calendar items!
+       // RFC4791 7.9 "calendar-multiget" REPORT - go get the specific Hrefs the client asked for.
+       if ( (crp.report_type == cr_calendar_multiget) && (crp.Hrefs != NULL) ) {
                StrBuf *ThisHref = NewStrBuf();
                const char *pvset = NULL;
                while (StrBufExtract_NextToken(ThisHref, crp.Hrefs, &pvset, '|') >= 0) {
@@ -267,3 +271,63 @@ void caldav_report(struct http_transaction *h, struct ctdlsession *c) {
        h->response_body_length = StrLength(ReportOut);
        h->response_body = SmashStrBuf(&ReportOut);
 }
+
+
+
+
+
+// Client is requesting a message list (make this code work for calendar-query REPORT)
+void XXXXXXXXXXXXXX(struct http_transaction *h, struct ctdlsession *c, char *range) {
+       char buf[SIZ];
+
+       // Determine the date/time range requested by the client
+       time_t lo = atol(range);
+       char *colon = strchr(range, ':');
+       time_t hi = colon ? atol(++colon) : LONG_MAX;
+
+       // Rule out impossible ranges
+       if (hi < lo) {
+               do_404(h);
+               return;
+       }
+
+       // Begin by requesting all messages in the room
+       int i = 0;
+       Array *msglist = get_msglist(c, "ALL");
+       if (msglist == NULL) {
+               do_404(h);
+               return;
+       }
+
+       // We're going to make a lot of MSG4 calls, and the preferred MIME type we want is "text/calendar".
+       // The iCalendar standard is mature now, and we are no longer interested in text/x-vcal or application/ics.
+       ctdl_printf(c, "MSGP text/calendar");
+       ctdl_readline(c, buf, sizeof buf);
+
+       // Iterate through our message list.
+       for (i = 0; i < array_len(msglist); ++i) {
+               long m;
+               memcpy(&m, array_get_element_at(msglist, i), sizeof(long));
+               syslog(LOG_DEBUG, "FIXME %ld", m);
+
+               // now we have to:
+               // 1. fetch the message from citadel server
+               // 2. parse the ical
+               // 3. figure out range
+               // we should steal code from webcit-classic for this
+
+               StrBuf *one_item;
+               one_item = fetch_ical(c, m);
+               syslog(LOG_DEBUG, "calendar item:\n---\n\033[33m%s\n---\033[0m", ChrPtr(one_item));
+               FreeStrBuf(&one_item);
+
+       }
+       array_free(msglist);
+
+       // FIXME we still fail because we aren't finished yet
+       add_response_header(h, strdup("Content-type"), strdup("application/json"));
+       h->response_code = 200;
+       h->response_string = strdup("OK");
+       h->response_body = "{ \"one\":111 , \"two\":222 , \"three\":333 }";
+       h->response_body_length = strlen(h->response_body);
+}
diff --git a/webcit-ng/server/calendar_functions.c b/webcit-ng/server/calendar_functions.c
deleted file mode 100644 (file)
index 47e2bff..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-// Calendar functions
-//
-// Copyright (c) 1996-2023 by the citadel.org team
-//
-// This program is open source software.  Use, duplication, or
-// disclosure is subject to the GNU General Public License v3.
-
-#include "webcit.h"
-
-
-// Client is requesting a message list
-void calendar_msglist(struct http_transaction *h, struct ctdlsession *c, char *range) {
-       char buf[SIZ];
-
-       // Determine the date/time range requested by the client
-       time_t lo = atol(range);
-       char *colon = strchr(range, ':');
-       time_t hi = colon ? atol(++colon) : LONG_MAX;
-
-       // Rule out impossible ranges
-       if (hi < lo) {
-               do_404(h);
-               return;
-       }
-
-       // Begin by requesting all messages in the room
-       int i = 0;
-       Array *msglist = get_msglist(c, "ALL");
-       if (msglist == NULL) {
-               do_404(h);
-               return;
-       }
-
-       // We're going to make a lot of MSG4 calls, and the preferred MIME type we want is "text/calendar".
-       // The iCalendar standard is mature now, and we are no longer interested in text/x-vcal or application/ics.
-       ctdl_printf(c, "MSGP text/calendar");
-       ctdl_readline(c, buf, sizeof buf);
-
-       // Iterate through our message list.
-       for (i = 0; i < array_len(msglist); ++i) {
-               long m;
-               memcpy(&m, array_get_element_at(msglist, i), sizeof(long));
-               syslog(LOG_DEBUG, "FIXME %ld", m);
-
-               // now we have to:
-               // 1. fetch the message from citadel server
-               // 2. parse the ical
-               // 3. figure out range
-               // we should steal code from webcit-classic for this
-
-               StrBuf *one_item;
-               one_item = fetch_ical(c, m);
-               syslog(LOG_DEBUG, "calendar item:\n---\n\033[33m%s\n---\033[0m", ChrPtr(one_item));
-               FreeStrBuf(&one_item);
-
-       }
-       array_free(msglist);
-
-       // FIXME we still fail because we aren't finished yet
-       add_response_header(h, strdup("Content-type"), strdup("application/json"));
-       h->response_code = 200;
-       h->response_string = strdup("OK");
-       h->response_body = "{ \"one\":111 , \"two\":222 , \"three\":333 }";
-       h->response_body_length = strlen(h->response_body);
-}
index 8b3ea950c67ca4e7a541714d6b948b47e0280108..3ab2f5dc103b5b636225b2f0be469a36e83b7ee2 100644 (file)
@@ -1,6 +1,6 @@
 // Room functions
 //
-// Copyright (c) 1996-2023 by the citadel.org team
+// Copyright (c) 1996-2024 by the citadel.org team
 //
 // This program is open source software.  Use, duplication, or
 // disclosure is subject to the GNU General Public License v3.
@@ -226,12 +226,6 @@ void object_in_room(struct http_transaction *h, struct ctdlsession *c) {
                return;
        }
 
-       if (!strncasecmp(buf, "calendar:", 9)) {        // Client is requesting a calendar range
-               unescape_input(&buf[9]);
-               calendar_msglist(h, c, &buf[9]);
-               return;
-       }
-
        if (!strcasecmp(buf, "info.txt")) {             // Client is requesting the room info banner
                read_room_info_banner(h, c);
                return;
index 1a187fef815f03aa7e6c3d2b1aae14fb76c1b00c..70d4c420dfb3b329ded553aeeca1abf4a674db91 100644 (file)
@@ -145,7 +145,6 @@ void caldav_xml_chardata(void *data, const XML_Char *s, int len);
 StrBuf *fetch_ical(struct ctdlsession *c, long msgnum);
 void caldav_response(struct http_transaction *h, struct ctdlsession *c, StrBuf *ReportOut, StrBuf *ThisHref);
 void caldav_report(struct http_transaction *h, struct ctdlsession *c);
-void calendar_msglist(struct http_transaction *h, struct ctdlsession *c, char *range);
 int ctdl_read_binary(struct ctdlsession *ctdl, char *buf, int bytes_requested);
 int ctdl_readline(struct ctdlsession *ctdl, char *buf, int maxbytes);
 StrBuf *ctdl_readtextmsg(struct ctdlsession *ctdl);