]> code.citadel.org Git - citadel.git/blobdiff - webcit/groupdav_propfind.c
* do linebuffered/non-blocking reads from http requests
[citadel.git] / webcit / groupdav_propfind.c
index c8e32052a5947db228e565b89404e61baa83f2c4..6da1f0e851585a1ddd0905b95098ccc1223ac4af 100644 (file)
 #include "webserver.h"
 #include "groupdav.h"
 
-
 /*
  * Given an encoded UID, translate that to an unencoded Citadel EUID and
  * then search for it in the current room.  Return a message number or -1
  * if not found.
  *
- * FIXME there's an indexing facility for this in Citadel.  Use it!!!!
  */
 long locate_message_by_uid(char *uid) {
        char buf[256];
@@ -55,35 +53,51 @@ long locate_message_by_uid(char *uid) {
        }
  ***************************************************/
 
-
        return(retval);
 }
 
 
+
 /*
  * List rooms (or "collections" in DAV terminology) which contain
  * interesting groupware objects.
  */
-void groupdav_collection_list(void) {
+void groupdav_collection_list(const char *dav_pathname, int dav_depth)
+{
        char buf[256];
        char roomname[256];
        int view;
        char datestring[256];
        time_t now;
+       time_t mtime;
        int is_groupware_collection = 0;
+       int starting_point = 1;         /**< 0 for /, 1 for /groupdav/ */
+
+       if (!strcmp(dav_pathname, "/")) {
+               starting_point = 0;
+       }
+       else if (!strcasecmp(dav_pathname, "/groupdav")) {
+               starting_point = 1;
+       }
+       else if (!strcasecmp(dav_pathname, "/groupdav/")) {
+               starting_point = 1;
+       }
+       else if ( (!strncasecmp(dav_pathname, "/groupdav/", 10)) && (strlen(dav_pathname) > 10) ) {
+               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.
         */
-       wprintf("HTTP/1.0 207 Multi-Status\r\n");
+       hprintf("HTTP/1.0 207 Multi-Status\r\n");
        groupdav_common_headers();
-       wprintf("Date: %s\r\n", datestring);
-       wprintf("Content-type: text/xml\r\n");
-       wprintf("Content-encoding: identity\r\n");
+       hprintf("Date: %s\r\n", datestring);
+       hprintf("Content-type: text/xml\r\n");
+       hprintf("Content-encoding: identity\r\n");
 
        begin_burst();
 
@@ -91,12 +105,61 @@ void groupdav_collection_list(void) {
                "<multistatus xmlns=\"DAV:\" xmlns:G=\"http://groupdav.org/\">"
        );
 
+       /**
+        *      If the client is requesting the root, show a root node.
+        */
+       if (starting_point == 0) {
+               wprintf("<response>");
+                       wprintf("<href>");
+                               groupdav_identify_host();
+                               wprintf("/");
+                       wprintf("</href>");
+                       wprintf("<propstat>");
+                               wprintf("<status>HTTP/1.1 200 OK</status>");
+                               wprintf("<prop>");
+                                       wprintf("<displayname>/</displayname>");
+                                       wprintf("<resourcetype><collection/></resourcetype>");
+                                       wprintf("<getlastmodified>");
+                                               escputs(datestring);
+                                       wprintf("</getlastmodified>");
+                               wprintf("</prop>");
+                       wprintf("</propstat>");
+               wprintf("</response>");
+       }
+
+       /**
+        *      If the client is requesting "/groupdav", show a /groupdav subdirectory.
+        */
+       if ((starting_point + dav_depth) >= 1) {
+               wprintf("<response>");
+                       wprintf("<href>");
+                               groupdav_identify_host();
+                               wprintf("/groupdav");
+                       wprintf("</href>");
+                       wprintf("<propstat>");
+                               wprintf("<status>HTTP/1.1 200 OK</status>");
+                               wprintf("<prop>");
+                                       wprintf("<displayname>GroupDAV</displayname>");
+                                       wprintf("<resourcetype><collection/></resourcetype>");
+                                       wprintf("<getlastmodified>");
+                                               escputs(datestring);
+                                       wprintf("</getlastmodified>");
+                               wprintf("</prop>");
+                       wprintf("</propstat>");
+               wprintf("</response>");
+       }
+
+       /**
+        *      Now go through the list and make it look like a DAV collection
+        */
        serv_puts("LKRA");
        serv_getln(buf, sizeof buf);
        if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
 
                extract_token(roomname, buf, 0, '|', sizeof roomname);
                view = extract_int(buf, 7);
+               mtime = extract_long(buf, 8);
+               http_datestring(datestring, sizeof datestring, mtime);
 
                /*
                 * For now, only list rooms that we know a GroupDAV client
@@ -116,7 +179,7 @@ void groupdav_collection_list(void) {
                        is_groupware_collection = 0;
                }
 
-               if (is_groupware_collection) {
+               if ( (is_groupware_collection) && ((starting_point + dav_depth) >= 2) ) {
                        wprintf("<response>");
 
                        wprintf("<href>");
@@ -146,6 +209,9 @@ void groupdav_collection_list(void) {
                        }
 
                        wprintf("</resourcetype>");
+                       wprintf("<getlastmodified>");
+                               escputs(datestring);
+                       wprintf("</getlastmodified>");
                        wprintf("</prop>");
                        wprintf("</propstat>");
                        wprintf("</response>");
@@ -161,7 +227,7 @@ void groupdav_collection_list(void) {
 /*
  * The pathname is always going to be /groupdav/room_name/msg_num
  */
-void groupdav_propfind(char *dav_pathname, char *dav_depth, char *dav_content_type, char *dav_content) {
+void groupdav_propfind(const char *dav_pathname, int dav_depth, StrBuf *dav_content_type, StrBuf *dav_content, int offset) {
        char dav_roomname[256];
        char dav_uid[256];
        char msgnum[256];
@@ -181,17 +247,12 @@ void groupdav_propfind(char *dav_pathname, char *dav_depth, char *dav_content_ty
        extract_token(dav_roomname, dav_pathname, 2, '/', sizeof dav_roomname);
        extract_token(dav_uid, dav_pathname, 3, '/', sizeof dav_uid);
 
-       lprintf(9, "dav_pathname: %s\n", dav_pathname);
-       lprintf(9, "dav_roomname: %s\n", dav_roomname);
-       lprintf(9, "     dav_uid: %s\n", dav_uid);
-       lprintf(9, "   dav_depth: %s\n", dav_depth);
-
        /*
         * If the room name is blank, the client is requesting a
         * folder list.
         */
-       if (strlen(dav_roomname) == 0) {
-               groupdav_collection_list();
+       if (IsEmptyStr(dav_roomname)) {
+               groupdav_collection_list(dav_pathname, dav_depth);
                return;
        }
 
@@ -200,36 +261,33 @@ void groupdav_propfind(char *dav_pathname, char *dav_depth, char *dav_content_ty
                gotoroom(dav_roomname);
        }
        if (strcasecmp(WC->wc_roomname, dav_roomname)) {
-               wprintf("HTTP/1.1 404 not found\r\n");
+               hprintf("HTTP/1.1 404 not found\r\n");
                groupdav_common_headers();
-               wprintf("Date: %s\r\n", datestring);
-               wprintf(
-                       "Content-Type: text/plain\r\n"
-                       "\r\n"
-                       "There is no folder called \"%s\" on this server.\r\n",
+               hprintf("Date: %s\r\n", datestring);
+               hprintf("Content-Type: text/plain\r\n");
+               wprintf("There is no folder called \"%s\" on this server.\r\n",
                        dav_roomname
                );
+               end_burst();
                return;
        }
 
        /* If dav_uid is non-empty, client is requesting a PROPFIND on
         * a specific item in the room.  This is not valid GroupDAV, but
-        * we try to honor it anyway because some clients are expecting
-        * it to work...
+        * it is valid WebDAV.
         */
-       if (strlen(dav_uid) > 0) {
+       if (!IsEmptyStr(dav_uid)) {
 
                dav_msgnum = locate_message_by_uid(dav_uid);
                if (dav_msgnum < 0) {
-                       wprintf("HTTP/1.1 404 not found\r\n");
+                       hprintf("HTTP/1.1 404 not found\r\n");
                        groupdav_common_headers();
-                       wprintf(
-                               "Content-Type: text/plain\r\n"
-                               "\r\n"
-                               "Object \"%s\" was not found in the \"%s\" folder.\r\n",
+                       hprintf("Content-Type: text/plain\r\n");
+                       wprintf("Object \"%s\" was not found in the \"%s\" folder.\r\n",
                                dav_uid,
                                dav_roomname
                        );
+                       end_burst();
                        return;
                }
 
@@ -237,11 +295,11 @@ void groupdav_propfind(char *dav_pathname, char *dav_depth, char *dav_content_ty
                 * everything we know about (which is going to simply be the ETag and
                 * nothing else).  Let the client-side parser sort it out.
                 */
-               wprintf("HTTP/1.0 207 Multi-Status\r\n");
+               hprintf("HTTP/1.0 207 Multi-Status\r\n");
                groupdav_common_headers();
-               wprintf("Date: %s\r\n", datestring);
-               wprintf("Content-type: text/xml\r\n");
-               wprintf("Content-encoding: identity\r\n");
+               hprintf("Date: %s\r\n", datestring);
+               hprintf("Content-type: text/xml\r\n");
+               hprintf("Content-encoding: identity\r\n");
        
                begin_burst();
        
@@ -250,7 +308,7 @@ void groupdav_propfind(char *dav_pathname, char *dav_depth, char *dav_content_ty
                );
 
                wprintf("<response>");
-
+               
                wprintf("<href>");
                groupdav_identify_host();
                wprintf("/groupdav/");
@@ -278,11 +336,11 @@ void groupdav_propfind(char *dav_pathname, char *dav_depth, char *dav_content_ty
         * everything we know about (which is going to simply be the ETag and
         * nothing else).  Let the client-side parser sort it out.
         */
-       wprintf("HTTP/1.0 207 Multi-Status\r\n");
+       hprintf("HTTP/1.0 207 Multi-Status\r\n");
        groupdav_common_headers();
-       wprintf("Date: %s\r\n", datestring);
-       wprintf("Content-type: text/xml\r\n");
-       wprintf("Content-encoding: identity\r\n");
+       hprintf("Date: %s\r\n", datestring);
+       hprintf("Content-type: text/xml\r\n");
+       hprintf("Content-encoding: identity\r\n");
 
        begin_burst();
 
@@ -290,6 +348,48 @@ void groupdav_propfind(char *dav_pathname, char *dav_depth, char *dav_content_ty
                "<multistatus xmlns=\"DAV:\" xmlns:G=\"http://groupdav.org/\">"
        );
 
+
+       /** Transmit the collection resource (FIXME check depth and starting point) */
+       wprintf("<response>");
+
+       wprintf("<href>");
+               groupdav_identify_host();
+               wprintf("/groupdav/");
+               urlescputs(WC->wc_roomname);
+       wprintf("</href>");
+
+       wprintf("<propstat>");
+       wprintf("<status>HTTP/1.1 200 OK</status>");
+       wprintf("<prop>");
+       wprintf("<displayname>");
+       escputs(WC->wc_roomname);
+       wprintf("</displayname>");
+       wprintf("<resourcetype><collection/>");
+
+       switch(WC->wc_default_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;
+       }
+
+       wprintf("</resourcetype>");
+       /* FIXME get the mtime
+       wprintf("<getlastmodified>");
+               escputs(datestring);
+       wprintf("</getlastmodified>");
+       */
+       wprintf("</prop>");
+       wprintf("</propstat>");
+       wprintf("</response>");
+
+       /** Transmit the collection listing (FIXME check depth and starting point) */
+
        serv_puts("MSGS ALL");
        serv_getln(buf, sizeof buf);
        if (buf[0] == '1') while (serv_getln(msgnum, sizeof msgnum), strcmp(msgnum, "000")) {
@@ -308,19 +408,32 @@ void groupdav_propfind(char *dav_pathname, char *dav_depth, char *dav_content_ty
                        }
                }
 
-               if (strlen(uid) > 0) {
+               if (!IsEmptyStr(uid)) {
                        wprintf("<response>");
-                       wprintf("<href>");
-                       groupdav_identify_host();
-                       wprintf("/groupdav/");
-                       urlescputs(WC->wc_roomname);
-                       euid_escapize(encoded_uid, uid);
-                       wprintf("/%s", encoded_uid);
-                       wprintf("</href>");
-                       wprintf("<propstat>");
-                       wprintf("<status>HTTP/1.1 200 OK</status>");
-                       wprintf("<prop><getetag>\"%ld\"</getetag></prop>", msgs[i]);
-                       wprintf("</propstat>");
+                               wprintf("<href>");
+                                       groupdav_identify_host();
+                                       wprintf("/groupdav/");
+                                       urlescputs(WC->wc_roomname);
+                                       euid_escapize(encoded_uid, uid);
+                                       wprintf("/%s", encoded_uid);
+                               wprintf("</href>");
+                               switch(WC->wc_default_view) {
+                               case VIEW_CALENDAR:
+                                       wprintf("<getcontenttype>text/x-ical</getcontenttype>");
+                                       break;
+                               case VIEW_TASKS:
+                                       wprintf("<getcontenttype>text/x-ical</getcontenttype>");
+                                       break;
+                               case VIEW_ADDRESSBOOK:
+                                       wprintf("<getcontenttype>text/x-vcard</getcontenttype>");
+                                       break;
+                               }
+                               wprintf("<propstat>");
+                                       wprintf("<status>HTTP/1.1 200 OK</status>");
+                                       wprintf("<prop>");
+                                               wprintf("<getetag>\"%ld\"</getetag>", msgs[i]);
+                                       wprintf("</prop>");
+                               wprintf("</propstat>");
                        wprintf("</response>");
                }
        }