* Initial implementation of GroupDAV PROPFIND
authorArt Cancro <ajc@citadel.org>
Wed, 26 Jan 2005 18:02:23 +0000 (18:02 +0000)
committerArt Cancro <ajc@citadel.org>
Wed, 26 Jan 2005 18:02:23 +0000 (18:02 +0000)
webcit/ChangeLog
webcit/Makefile.in
webcit/context_loop.c
webcit/groupdav.h
webcit/groupdav_main.c
webcit/groupdav_propfind.c [new file with mode: 0644]
webcit/webcit.c

index ee48e47d9137acca0283cd1274a8acd7db7b058b..ee8dcf4e3975b40b84a029f4047062d04c95f10c 100644 (file)
@@ -1,4 +1,7 @@
 $Log$
+Revision 528.22  2005/01/26 18:02:22  ajc
+* Initial implementation of GroupDAV PROPFIND
+
 Revision 528.21  2005/01/26 16:28:23  ajc
 * Output ETags in double quotes to conform with the new GroupDAV draft.
 * Output HTTP Server: header in GroupDAV transactions
@@ -2233,4 +2236,3 @@ Sun Dec  6 19:50:55 EST 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
 
 1998-12-03 Nathan Bryant <bryant@cs.usm.maine.edu>
        * webserver.c: warning fix
-
index 1a0de31e5e70c2988fc2706655028298cfb06111..212ae266d07047a93399c0008a8b60bd656ae278 100644 (file)
@@ -37,7 +37,7 @@ webserver: webserver.o context_loop.o tools.o ical_dezonify.o \
        mime_parser.o graphics.o netconf.o siteconfig.o subst.o \
        calendar.o calendar_tools.o calendar_view.o event.o \
        availability.o iconbar.o crypto.o inetconf.o notes.o \
-       groupdav_main.o groupdav_get.o \
+       groupdav_main.o groupdav_get.o groupdav_propfind.o \
        $(LIBOBJS)
        $(CC) webserver.o context_loop.o tools.o cookie_conversion.o \
        webcit.o auth.o tcp_sockets.o mainmenu.o serv_func.o who.o listsub.o \
@@ -46,7 +46,7 @@ webserver: webserver.o context_loop.o tools.o ical_dezonify.o \
        mime_parser.o graphics.o netconf.o preferences.o html2html.o \
        summary.o calendar.o calendar_tools.o calendar_view.o event.o \
        availability.o ical_dezonify.o iconbar.o crypto.o inetconf.o notes.o \
-       groupdav_main.o groupdav_get.o \
+       groupdav_main.o groupdav_get.o groupdav_propfind.o \
        $(LIBOBJS) $(LIBS) $(LDFLAGS) -o webserver
 
 .c.o:
index f0c8e553ba6bc82c674f62f113da6e59ee8b1361..f4bd27372292839ce03a41b755a219d8d0f1ffb2 100644 (file)
@@ -323,9 +323,7 @@ void context_loop(int sock)
         * set.  If there isn't, the client browser has cookies turned off
         * (or doesn't support them) and we have to barf & bail.
         */
-       if (!strncasecmp(buf, "GET ", 4)) strcpy(buf, &buf[4]);
-       else if (!strncasecmp(buf, "HEAD ", 5)) strcpy(buf, &buf[5]);
-       else if (!strncasecmp(buf, "POST ", 5)) strcpy(buf, &buf[5]);
+       remove_token(buf, 0, ' ');
        if (buf[1]==' ') buf[1]=0;
 
        /*
index 6fcc96ffaf86f3de33d677d8f1d334b0e5c7680b..4a71cd306a525bb625e17feee89e68f62eed39d9 100644 (file)
@@ -3,3 +3,4 @@
 void groupdav_common_headers(void);
 void groupdav_main(struct httprequest *);
 void groupdav_get(char *);
+void groupdav_propfind(char *);
index 44701d0ad053d713fbb7acaef443e9116da9c93c..6dca61e589e7b1cbc04593608412cf185c5297f9 100644 (file)
@@ -47,6 +47,10 @@ void groupdav_main(struct httprequest *req) {
        char dav_method[SIZ];
        char dav_pathname[SIZ];
 
+       for (rptr=req; rptr!=NULL; rptr=rptr->next) {
+               lprintf(9, "> %s\n", rptr->line);
+       }
+
        if (!WC->logged_in) {
                wprintf("HTTP/1.1 401 Unauthorized\n");
                groupdav_common_headers();
@@ -69,6 +73,14 @@ void groupdav_main(struct httprequest *req) {
                return;
        }
 
+       /*
+        * The PROPFIND method is basically used to list all objects in a room.
+        */
+       if (!strcasecmp(dav_method, "PROPFIND")) {
+               groupdav_propfind(dav_pathname);
+               return;
+       }
+
        /*
         * Couldn't find what we were looking for.  Die in a car fire.
         */
@@ -79,16 +91,4 @@ void groupdav_main(struct httprequest *req) {
                "GroupDAV method \"%s\" is not implemented.\n",
                dav_method
        );
-
-       /*
-        * FIXME ... after development is finished, get rid of all this
-        */
-       wprintf("\n\n\n ** DEBUGGING INFO FOLLOWS ** \n\n");
-       wprintf("WC->httpauth_user = %s\n", WC->httpauth_user);
-       wprintf("WC->httpauth_pass = (%d characters)\n", strlen(WC->httpauth_pass));
-       wprintf("WC->wc_session    = %d\n", WC->wc_session);
-       
-       for (rptr=req; rptr!=NULL; rptr=rptr->next) {
-               wprintf("> %s\n", rptr->line);
-       }
 }
diff --git a/webcit/groupdav_propfind.c b/webcit/groupdav_propfind.c
new file mode 100644 (file)
index 0000000..171de41
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * $Id$
+ *
+ * Handles GroupDAV PROPFIND requests.
+ *
+ */
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/socket.h>
+#include <limits.h>
+#include <string.h>
+#include <pwd.h>
+#include <errno.h>
+#include <stdarg.h>
+#include <time.h>
+#include <pthread.h>
+#include "webcit.h"
+#include "webserver.h"
+#include "groupdav.h"
+
+
+/*
+ * The pathname is always going to be /groupdav/room_name/msg_num
+ */
+void groupdav_propfind(char *dav_pathname) {
+       char dav_roomname[SIZ];
+       char buf[SIZ];
+
+       /* First, break off the "/groupdav/" prefix */
+       remove_token(dav_pathname, 0, '/');
+       remove_token(dav_pathname, 0, '/');
+
+       /* What's left is the room name.  Remove trailing slashes. */
+       if (dav_pathname[strlen(dav_pathname)-1] == '/') {
+               dav_pathname[strlen(dav_pathname)-1] = 0;
+       }
+       strcpy(dav_roomname, dav_pathname);
+
+       /* Go to the correct room. */
+       if (strcasecmp(WC->wc_roomname, dav_roomname)) {
+               gotoroom(dav_roomname);
+       }
+       if (strcasecmp(WC->wc_roomname, dav_roomname)) {
+               wprintf("HTTP/1.1 404 not found\n");
+               groupdav_common_headers();
+               wprintf(
+                       "Content-Type: text/plain\n"
+                       "\n"
+                       "There is no folder called \"%s\" on this server.\n",
+                       dav_roomname
+               );
+               return;
+       }
+
+       /*
+        * Be rude.  Completely ignore the XML request and simply send them
+        * 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\n");
+       groupdav_common_headers();
+       wprintf("Content-type: text/xml\n"
+               "\n"
+               "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+               "<D:multistatus xmlns:D=\"DAV:\">\n"
+       );
+
+       serv_puts("MSGS ALL");
+       serv_gets(buf);
+       if (buf[0] == '1') while (serv_gets(buf), strcmp(buf, "000")) {
+               wprintf(" <D:response>\n");
+               wprintf("  <D:href>%s/groupdav/Calendar/%s</D:href>\n", WC->http_host, buf);
+               wprintf("   <D:propstat>\n");
+               wprintf("    <D:status>HTTP/1.1 200 OK</D:status>\n");
+               wprintf("    <D:prop><D:getetag>\"%s\"</D:getetag></D:prop>\n", buf);
+               wprintf("   </D:propstat>\n");
+               wprintf(" </D:response>\n");
+       }
+
+       wprintf("</D:multistatus>\n");
+}
index e34d0d405abbd07212fdef4313f831166a0ab926..b873635d1675779be711d4c5db671aa29c7b1c85 100644 (file)
@@ -745,13 +745,17 @@ void extract_action(char *actbuf, char *cmdbuf)
        int i;
 
        strcpy(actbuf, cmdbuf);
-       if (!strncasecmp(actbuf, "GET /", 5))
-               strcpy(actbuf, &actbuf[5]);
-       if (!strncasecmp(actbuf, "PUT /", 5))
-               strcpy(actbuf, &actbuf[5]);
-       if (!strncasecmp(actbuf, "POST /", 6))
-               strcpy(actbuf, &actbuf[6]);
 
+       /*
+        * First strip out the http method
+        */
+       remove_token(actbuf, 0, ' ');
+       if (actbuf[0] == ' ') strcpy(actbuf, &actbuf[1]);
+       if (actbuf[0] == '/') strcpy(actbuf, &actbuf[1]);
+
+       /*
+        * Now kill invalid (for webcit) characters
+        */
        for (i = 0; i < strlen(actbuf); ++i) {
                if (actbuf[i] == ' ') {
                        actbuf[i] = 0;