* Added an experimental OPTIONS method. This is not required by GroupDAV,
authorArt Cancro <ajc@citadel.org>
Wed, 29 Jun 2005 15:25:01 +0000 (15:25 +0000)
committerArt Cancro <ajc@citadel.org>
Wed, 29 Jun 2005 15:25:01 +0000 (15:25 +0000)
  but it is an experiment to see whether we can use the same code framework
  to implement other DAV variants in the future.

webcit/ChangeLog
webcit/Makefile.in
webcit/groupdav_main.c
webcit/groupdav_options.c [new file with mode: 0644]

index 5f06e88961c82d7c01ae784b585cd5d51d80c371..5821c436591299d11771486be487a53007de5303 100644 (file)
@@ -1,4 +1,9 @@
 $Log$
+Revision 619.18  2005/06/29 15:25:00  ajc
+* Added an experimental OPTIONS method.  This is not required by GroupDAV,
+  but it is an experiment to see whether we can use the same code framework
+  to implement other DAV variants in the future.
+
 Revision 619.17  2005/06/29 03:12:28  ajc
 * Bumped internal version number to 6.20
 
@@ -2674,4 +2679,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 0526a1dd0ee18beb21482ff9803413e46a223b3b..c08e53cfc30234fb679610b907521761fccd3843 100644 (file)
@@ -38,6 +38,7 @@ webserver: webserver.o context_loop.o tools.o ical_dezonify.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_propfind.o fmt_date.o \
+       groupdav_options.o \
        groupdav_delete.o groupdav_put.o http_datestring.o setup_wizard.o \
        $(LIBOBJS)
        $(CC) webserver.o context_loop.o tools.o cookie_conversion.o \
@@ -48,6 +49,7 @@ webserver: webserver.o context_loop.o tools.o ical_dezonify.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_propfind.o groupdav_delete.o \
+       groupdav_options.o \
        groupdav_put.o http_datestring.o setup_wizard.o fmt_date.o \
        $(LIBOBJS) $(LIBS) $(LDFLAGS) -o webserver
 
index 8df601a558babc5502a984be4a7cb0aaa5ed77bb..11c874c9dec4b7f91e4090226f43c83eb473d632 100644 (file)
@@ -179,6 +179,16 @@ void groupdav_main(struct httprequest *req,
                }
        }
 
+       /*
+        * The OPTIONS method is not required by GroupDAV.  This is an
+        * experiment to determine what might be involved in supporting
+        * other variants of DAV in the future.
+        */
+       if (!strcasecmp(dav_method, "OPTIONS")) {
+               groupdav_options(dav_pathname);
+               return;
+       }
+
        /*
         * The PROPFIND method is basically used to list all objects in a
         * room, or to list all relevant rooms on the server.
diff --git a/webcit/groupdav_options.c b/webcit/groupdav_options.c
new file mode 100644 (file)
index 0000000..6e7323c
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ * $Id$
+ *
+ * Handles DAV OPTIONS requests (experimental -- not required by GroupDAV)
+ *
+ */
+
+#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_options(char *dav_pathname) {
+       char dav_roomname[256];
+       char dav_uid[256];
+       long dav_msgnum = (-1);
+       char datestring[256];
+       time_t now;
+
+       now = time(NULL);
+       http_datestring(datestring, sizeof datestring, now);
+
+       extract_token(dav_roomname, dav_pathname, 2, '/', sizeof dav_roomname);
+       extract_token(dav_uid, dav_pathname, 3, '/', sizeof dav_uid);
+
+       /*
+        * If the room name is blank, the client is doing a top-level OPTIONS.
+        */
+       if (strlen(dav_roomname) == 0) {
+               wprintf("HTTP/1.1 200 OK\r\n");
+               groupdav_common_headers();
+               wprintf("Date: %s\r\n", datestring);
+               wprintf("Allow: OPTIONS, PROPFIND\r\n");
+               wprintf("\r\n");
+               return;
+       }
+
+       /* 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\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",
+                       dav_roomname
+               );
+               return;
+       }
+
+       /* If dav_uid is non-empty, client is requesting an OPTIONS on
+        * a specific item in the room.
+        */
+       if (strlen(dav_uid) > 0) {
+
+               dav_msgnum = locate_message_by_uid(dav_uid);
+               if (dav_msgnum < 0) {
+                       wprintf("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",
+                               dav_uid,
+                               dav_roomname
+                       );
+                       return;
+               }
+
+               wprintf("HTTP/1.1 200 OK\r\n");
+               groupdav_common_headers();
+               wprintf("Date: %s\r\n", datestring);
+               wprintf("Allow: OPTIONS, PROPFIND, GET, PUT, DELETE\r\n");
+               wprintf("\r\n");
+               return;
+       }
+
+
+       /*
+        * We got to this point, which means that the client is requesting
+        * an OPTIONS on the room itself.
+        */
+       wprintf("HTTP/1.1 200 OK\r\n");
+       groupdav_common_headers();
+       wprintf("Date: %s\r\n", datestring);
+       wprintf("Allow: OPTIONS, PROPFIND, GET, PUT\r\n");
+       wprintf("\r\n");
+}