]> code.citadel.org Git - citadel.git/commitdiff
groupdav_propfind.c: continued fleshing out the DAV features
authorArt Cancro <ajc@citadel.org>
Wed, 1 Mar 2006 04:40:39 +0000 (04:40 +0000)
committerArt Cancro <ajc@citadel.org>
Wed, 1 Mar 2006 04:40:39 +0000 (04:40 +0000)
of this interface so that it can do more than just GroupDAV.  It
now has basic read-only WebDAV browse/fetch support (tested with
cadaver and with konqueror).

webcit/groupdav.h
webcit/groupdav_main.c
webcit/groupdav_options.c
webcit/groupdav_propfind.c
webcit/webserver.c

index 947b9877b74f2774d916e93c6b3a9589a107e403..63652208a49be98d0260812be74c3e58a734355f 100644 (file)
@@ -5,7 +5,7 @@ void groupdav_main(struct httprequest *, char *, int, char *);
 void groupdav_get(char *);
 void groupdav_put(char *, char *, char *, char *);
 void groupdav_delete(char *, char *);
-void groupdav_propfind(char *, char *, char *, char *);
+void groupdav_propfind(char *, int, char *, char *);
 void groupdav_options(char *);
 long locate_message_by_uid(char *);
 void groupdav_folder_list(void);
index 28608cfa43c7c7224eb750f50da30c769eb53a30..80b8be640fe69968c6b650d292debbeb7b6413a5 100644 (file)
@@ -107,15 +107,14 @@ void groupdav_main(struct httprequest *req,
        char dav_method[256];
        char dav_pathname[256];
        char dav_ifmatch[256];
-       char dav_depth[256];
-       char buf[256];
+       int dav_depth;
        char *ds;
        int i;
 
        strcpy(dav_method, "");
        strcpy(dav_pathname, "");
        strcpy(dav_ifmatch, "");
-       strcpy(dav_depth, "");
+       dav_depth = 0;
 
        for (rptr=req; rptr!=NULL; rptr=rptr->next) {
                if (!strncasecmp(rptr->line, "Host: ", 6)) {
@@ -129,8 +128,15 @@ void groupdav_main(struct httprequest *req,
                                sizeof dav_ifmatch);
                 }
                if (!strncasecmp(rptr->line, "Depth: ", 7)) {
-                        safestrncpy(dav_depth, &rptr->line[7],
-                               sizeof dav_depth);
+                       if (!strcasecmp(&rptr->line[7], "infinity")) {
+                               dav_depth = 32767;
+                       }
+                       else if (!strcmp(&rptr->line[7], "0")) {
+                               dav_depth = 0;
+                       }
+                       else if (!strcmp(&rptr->line[7], "1")) {
+                               dav_depth = 1;
+                       }
                 }
        }
 
@@ -150,11 +156,16 @@ void groupdav_main(struct httprequest *req,
        /* If the request does not begin with "/groupdav", prepend it.  If
         * we happen to introduce a double-slash, that's ok; we'll strip it
         * in the next step.
-        */
+        * 
+        * (THIS IS DISABLED BECAUSE WE ARE NOW TRYING TO DO REAL DAV.)
+        *
        if (strncasecmp(dav_pathname, "/groupdav", 9)) {
+               char buf[512];
                snprintf(buf, sizeof buf, "/groupdav/%s", dav_pathname);
                safestrncpy(dav_pathname, buf, sizeof dav_pathname);
        }
+        *
+        */
        
        /* Remove any stray double-slashes in pathname */
        while (ds=strstr(dav_pathname, "//"), ds != NULL) {
index 929a9c843ef0064d6fa49f68970f4a3e48a82630..6de58256bc81e2cab7766d5a6938793d4534079e 100644 (file)
@@ -41,6 +41,7 @@ void groupdav_options(char *dav_pathname) {
        if (strcasecmp(WC->wc_roomname, dav_roomname)) {
                gotoroom(dav_roomname);
        }
+
        if (strcasecmp(WC->wc_roomname, dav_roomname)) {
                wprintf("HTTP/1.1 404 not found\r\n");
                groupdav_common_headers();
@@ -81,7 +82,6 @@ void groupdav_options(char *dav_pathname) {
                return;
        }
 
-
        /*
         * We got to this point, which means that the client is requesting
         * an OPTIONS on the room itself.
index c8e32052a5947db228e565b89404e61baa83f2c4..8e6154d611e18f032f714ad6e2d182bd6a4a5479 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,27 +53,43 @@ 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(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.
         */
@@ -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(char *dav_pathname, int dav_depth, char *dav_content_type, char *dav_content) {
        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();
+               groupdav_collection_list(dav_pathname, dav_depth);
                return;
        }
 
@@ -214,8 +275,7 @@ void groupdav_propfind(char *dav_pathname, char *dav_depth, char *dav_content_ty
 
        /* 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) {
 
@@ -290,6 +350,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")) {
@@ -310,17 +412,19 @@ void groupdav_propfind(char *dav_pathname, char *dav_depth, char *dav_content_ty
 
                if (strlen(uid) > 0) {
                        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>");
+                               wprintf("<propstat>");
+                                       wprintf("<status>HTTP/1.1 200 OK</status>");
+                                       wprintf("<prop>");
+                                               wprintf("<getetag>\"%ld\"</getetag>", msgs[i]);
+                                       wprintf("</prop>");
+                               wprintf("</propstat>");
                        wprintf("</response>");
                }
        }
index 2caf9fcd8baa86f7cf599b4893d547c1376231da..985add616d9d749a43a02dead9a935b4ea1e5959 100644 (file)
@@ -400,13 +400,12 @@ int client_getln(int sock, char *buf, int bufsiz)
                if (retval != 1 || buf[i] == '\n' || i == (bufsiz-1))
                        break;
                if ( (!isspace(buf[i])) && (!isprint(buf[i])) ) {
-                       lprintf(2, "Non printable character recieved from client\n");
+                       /** Non printable character recieved from client */
                        return(-1);
                }
        }
 
-
-       /** If we got a long line, discard characters until the newline.         */
+       /** If we got a long line, discard characters until the newline. */
        if (i == (bufsiz-1))
                while (buf[i] != '\n' && retval == 1)
                        retval = client_read(sock, &buf[i], 1);
@@ -423,8 +422,9 @@ int client_getln(int sock, char *buf, int bufsiz)
 
 
 /**
- * \brief Start running as a daemon.  
- * param do_close_stdio Only close stdio if set.
+ * \brief      Start running as a daemon.  
+ *
+ * param       do_close_stdio          Only close stdio if set.
  */
 void start_daemon(int do_close_stdio)
 {
@@ -436,10 +436,14 @@ void start_daemon(int do_close_stdio)
        signal(SIGHUP, SIG_IGN);
        signal(SIGINT, SIG_IGN);
        signal(SIGQUIT, SIG_IGN);
-       if (fork() != 0)
+       if (fork() != 0) {
                exit(0);
+       }
 }
 
+/**
+ * \brief      Spawn an additional worker thread into the pool.
+ */
 void spawn_another_worker_thread()
 {
        pthread_t SessThread;   /**< Thread descriptor */