]> code.citadel.org Git - citadel.git/blobdiff - webcit/groupdav_propfind.c
* Repaired pieces of the wiki engine that have fallen into disrepair.
[citadel.git] / webcit / groupdav_propfind.c
index f225eb8f1732a648804c81d43db82d4fa68c2d3d..2a2821f39938c2240c0afedd4a3a52b44277ca49 100644 (file)
@@ -6,8 +6,7 @@
  * A few notes about our XML output:
  *
  * --> Yes, we are spewing tags directly instead of using an XML library.
- *     If you would like to rewrite this using libxml2, code it up and submit
- *     a patch.  Whining will be summarily ignored.
+ *     Whining about it will be summarily ignored.
  *
  * --> XML is deliberately output with no whitespace/newlines between tags.
  *     This makes it difficult to read, but we have discovered clients which
@@ -49,8 +48,9 @@ long locate_message_by_uid(const char *uid) {
  * List rooms (or "collections" in DAV terminology) which contain
  * interesting groupware objects.
  */
-void groupdav_collection_list(const char *dav_pathname, int dav_depth)
+void groupdav_collection_list(void)
 {
+       wcsession *WCC = WC;
        char buf[256];
        char roomname[256];
        int view;
@@ -60,23 +60,20 @@ void groupdav_collection_list(const char *dav_pathname, int dav_depth)
        int is_groupware_collection = 0;
        int starting_point = 1;         /**< 0 for /, 1 for /groupdav/ */
 
-       if (!strcmp(dav_pathname, "/")) {
+       if (WCC->Hdr->HR.Handler == NULL) {
                starting_point = 0;
        }
-       else if (!strcasecmp(dav_pathname, "/groupdav")) {
+       else if (StrLength(WCC->Hdr->HR.ReqLine) == 0) {
                starting_point = 1;
        }
-       else if (!strcasecmp(dav_pathname, "/groupdav/")) {
-               starting_point = 1;
-       }
-       else if ( (!strncasecmp(dav_pathname, "/groupdav/", 10)) && (strlen(dav_pathname) > 10) ) {
+       else {
                starting_point = 2;
        }
 
        now = time(NULL);
        http_datestring(datestring, sizeof datestring, now);
 
-       /**
+       /*
         * Be rude.  Completely ignore the XML request and simply send them
         * everything we know about.  Let the client sort it out.
         */
@@ -92,8 +89,8 @@ void groupdav_collection_list(const char *dav_pathname, int dav_depth)
                "<multistatus xmlns=\"DAV:\" xmlns:G=\"http://groupdav.org/\">"
        );
 
-       /**
-        *      If the client is requesting the root, show a root node.
+       /*
+        * If the client is requesting the root, show a root node.
         */
        if (starting_point == 0) {
                wprintf("<response>");
@@ -114,10 +111,10 @@ void groupdav_collection_list(const char *dav_pathname, int dav_depth)
                wprintf("</response>");
        }
 
-       /**
-        *      If the client is requesting "/groupdav", show a /groupdav subdirectory.
+       /*
+        * If the client is requesting "/groupdav", show a /groupdav subdirectory.
         */
-       if ((starting_point + dav_depth) >= 1) {
+       if ((starting_point + WCC->Hdr->HR.dav_depth) >= 1) {
                wprintf("<response>");
                        wprintf("<href>");
                                groupdav_identify_host();
@@ -136,8 +133,8 @@ void groupdav_collection_list(const char *dav_pathname, int dav_depth)
                wprintf("</response>");
        }
 
-       /**
-        *      Now go through the list and make it look like a DAV collection
+       /*
+        * Now go through the list and make it look like a DAV collection
         */
        serv_puts("LKRA");
        serv_getln(buf, sizeof buf);
@@ -159,14 +156,20 @@ void groupdav_collection_list(const char *dav_pathname, int dav_depth)
                 * GroupDAV calendar even if the user has switched it to a
                 * Calendar List view.
                 */
-               if ((view == VIEW_CALENDAR) || (view == VIEW_TASKS) || (view == VIEW_ADDRESSBOOK) ) {
+               if (    (view == VIEW_CALENDAR) || 
+                       (view == VIEW_TASKS) || 
+                       (view == VIEW_ADDRESSBOOK) ||
+                       (view == VIEW_NOTES) ||
+                       (view == VIEW_JOURNAL) ||
+                       (view == VIEW_WIKI)
+               ) {
                        is_groupware_collection = 1;
                }
                else {
                        is_groupware_collection = 0;
                }
 
-               if ( (is_groupware_collection) && ((starting_point + dav_depth) >= 2) ) {
+               if ( (is_groupware_collection) && ((starting_point + WCC->Hdr->HR.dav_depth) >= 2) ) {
                        wprintf("<response>");
 
                        wprintf("<href>");
@@ -184,15 +187,24 @@ void groupdav_collection_list(const char *dav_pathname, int dav_depth)
                        wprintf("<resourcetype><collection/>");
 
                        switch(view) {
-                               case VIEW_CALENDAR:
-                                       wprintf("<G:vevent-collection />");
-                                       break;
-                               case VIEW_TASKS:
-                                       wprintf("<G:vtodo-collection />");
-                                       break;
-                               case VIEW_ADDRESSBOOK:
-                                       wprintf("<G:vcard-collection />");
-                                       break;
+                       case VIEW_CALENDAR:
+                               wprintf("<G:vevent-collection />");
+                               break;
+                       case VIEW_TASKS:
+                               wprintf("<G:vtodo-collection />");
+                               break;
+                       case VIEW_ADDRESSBOOK:
+                               wprintf("<G:vcard-collection />");
+                               break;
+                       case VIEW_NOTES:
+                               wprintf("<G:vnotes-collection />");
+                               break;
+                       case VIEW_JOURNAL:
+                               wprintf("<G:vjournal-collection />");
+                               break;
+                       case VIEW_WIKI:
+                               wprintf("<G:wiki-collection />");
+                               break;
                        }
 
                        wprintf("</resourcetype>");
@@ -214,12 +226,14 @@ void groupdav_collection_list(const char *dav_pathname, int dav_depth)
 /*
  * The pathname is always going to be /groupdav/room_name/msg_num
  */
-void groupdav_propfind(StrBuf *dav_pathname, int dav_depth, StrBuf *dav_content_type, StrBuf *dav_content, int offset) {
+void groupdav_propfind(void) 
+{
+       wcsession *WCC = WC;
        StrBuf *dav_roomname;
        StrBuf *dav_uid;
-       char msgnum[256];
+       StrBuf *MsgNum;
+       long BufLen;
        long dav_msgnum = (-1);
-       char buf[256];
        char uid[256];
        char encoded_uid[256];
        long *msgs = NULL;
@@ -233,25 +247,25 @@ void groupdav_propfind(StrBuf *dav_pathname, int dav_depth, StrBuf *dav_content_
 
        dav_roomname = NewStrBuf();
        dav_uid = NewStrBuf();
-       StrBufExtract_token(dav_roomname, dav_pathname, 2, '/');
-       StrBufExtract_token(dav_uid, dav_pathname, 3, '/');
+       StrBufExtract_token(dav_roomname, WCC->Hdr->HR.ReqLine, 0, '/');
+       StrBufExtract_token(dav_uid, WCC->Hdr->HR.ReqLine, 1, '/');
 
        /*
         * If the room name is blank, the client is requesting a
         * folder list.
         */
        if (StrLength(dav_roomname) == 0) {
-               groupdav_collection_list(ChrPtr(dav_pathname), dav_depth);
+               groupdav_collection_list();
                FreeStrBuf(&dav_roomname);
                FreeStrBuf(&dav_uid);
                return;
        }
 
        /* Go to the correct room. */
-       if (strcasecmp(ChrPtr(WC->wc_roomname), ChrPtr(dav_roomname))) {
+       if (strcasecmp(ChrPtr(WCC->wc_roomname), ChrPtr(dav_roomname))) {
                gotoroom(dav_roomname);
        }
-       if (strcasecmp(ChrPtr(WC->wc_roomname), ChrPtr(dav_roomname))) {
+       if (strcasecmp(ChrPtr(WCC->wc_roomname), ChrPtr(dav_roomname))) {
                hprintf("HTTP/1.1 404 not found\r\n");
                groupdav_common_headers();
                hprintf("Date: %s\r\n", datestring);
@@ -307,7 +321,7 @@ void groupdav_propfind(StrBuf *dav_pathname, int dav_depth, StrBuf *dav_content_
                wprintf("<href>");
                groupdav_identify_host();
                wprintf("/groupdav/");
-               urlescputs(ChrPtr(WC->wc_roomname));
+               urlescputs(ChrPtr(WCC->wc_roomname));
                euid_escapize(encoded_uid, ChrPtr(dav_uid));
                wprintf("/%s", encoded_uid);
                wprintf("</href>");
@@ -353,24 +367,24 @@ void groupdav_propfind(StrBuf *dav_pathname, int dav_depth, StrBuf *dav_content_
        );
 
 
-       /** Transmit the collection resource (FIXME check depth and starting point) */
+       /* Transmit the collection resource (FIXME check depth and starting point) */
        wprintf("<response>");
 
        wprintf("<href>");
-               groupdav_identify_host();
-               wprintf("/groupdav/");
-               urlescputs(ChrPtr(WC->wc_roomname));
+       groupdav_identify_host();
+       wprintf("/groupdav/");
+       urlescputs(ChrPtr(WCC->wc_roomname));
        wprintf("</href>");
 
        wprintf("<propstat>");
        wprintf("<status>HTTP/1.1 200 OK</status>");
        wprintf("<prop>");
        wprintf("<displayname>");
-       escputs(ChrPtr(WC->wc_roomname));
+       escputs(ChrPtr(WCC->wc_roomname));
        wprintf("</displayname>");
        wprintf("<resourcetype><collection/>");
 
-       switch(WC->wc_default_view) {
+       switch(WCC->wc_default_view) {
                case VIEW_CALENDAR:
                        wprintf("<G:vevent-collection />");
                        break;
@@ -392,27 +406,32 @@ void groupdav_propfind(StrBuf *dav_pathname, int dav_depth, StrBuf *dav_content_
        wprintf("</propstat>");
        wprintf("</response>");
 
-       /** Transmit the collection listing (FIXME check depth and starting point) */
+       /* Transmit the collection listing (FIXME check depth and starting point) */
 
+       MsgNum = NewStrBuf();
        serv_puts("MSGS ALL");
-       serv_getln(buf, sizeof buf);
-       if (buf[0] == '1') while (serv_getln(msgnum, sizeof msgnum), strcmp(msgnum, "000")) {
-               msgs = realloc(msgs, ++num_msgs * sizeof(long));
-               msgs[num_msgs-1] = atol(msgnum);
-       }
+
+       StrBuf_ServGetln(MsgNum);
+       if (GetServerStatus(MsgNum, NULL) == 1)
+               while (BufLen = StrBuf_ServGetln(MsgNum), strcmp(ChrPtr(MsgNum), "000"))  {
+                       msgs = realloc(msgs, ++num_msgs * sizeof(long));
+                       msgs[num_msgs-1] = StrTol(MsgNum);
+               }
 
        if (num_msgs > 0) for (i=0; i<num_msgs; ++i) {
 
                strcpy(uid, "");
                now = (-1);
                serv_printf("MSG0 %ld|3", msgs[i]);
-               serv_getln(buf, sizeof buf);
-               if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
-                       if (!strncasecmp(buf, "exti=", 5)) {
-                               strcpy(uid, &buf[5]);
-                       }
-                       else if (!strncasecmp(buf, "time=", 5)) {
-                               now = atol(&buf[5]);
+               StrBuf_ServGetln(MsgNum);
+               if (GetServerStatus(MsgNum, NULL) == 1)
+                       while (BufLen = StrBuf_ServGetln(MsgNum), strcmp(ChrPtr(MsgNum), "000")) 
+                       {
+                               if (!strncasecmp(ChrPtr(MsgNum), "exti=", 5)) {
+                                       strcpy(uid, &ChrPtr(MsgNum)[5]);
+                               }
+                               else if (!strncasecmp(ChrPtr(MsgNum), "time=", 5)) {
+                                       now = atol(&ChrPtr(MsgNum)[5]);
                        }
                }
 
@@ -421,11 +440,11 @@ void groupdav_propfind(StrBuf *dav_pathname, int dav_depth, StrBuf *dav_content_
                                wprintf("<href>");
                                        groupdav_identify_host();
                                        wprintf("/groupdav/");
-                                       urlescputs(ChrPtr(WC->wc_roomname));
+                                       urlescputs(ChrPtr(WCC->wc_roomname));
                                        euid_escapize(encoded_uid, uid);
                                        wprintf("/%s", encoded_uid);
                                wprintf("</href>");
-                               switch(WC->wc_default_view) {
+                               switch(WCC->wc_default_view) {
                                case VIEW_CALENDAR:
                                        wprintf("<getcontenttype>text/x-ical</getcontenttype>");
                                        break;
@@ -451,6 +470,7 @@ void groupdav_propfind(StrBuf *dav_pathname, int dav_depth, StrBuf *dav_content_
                        wprintf("</response>");
                }
        }
+       FreeStrBuf(&MsgNum);
 
        wprintf("</multistatus>\n");
        end_burst();