]> code.citadel.org Git - citadel.git/blobdiff - webcit/groupdav_options.c
* add logging if auth-basic session connecting fails with weird conditions
[citadel.git] / webcit / groupdav_options.c
index 6e7323c50f10a0c8ffe526c8b30cb7fb54503130..e20d1a07fbda65430a74c207f53979fe27766df5 100644 (file)
@@ -5,22 +5,6 @@
  *
  */
 
-#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];
+void groupdav_options(void)
+{
+       wcsession *WCC = WC;
+       StrBuf *dav_roomname;
+       StrBuf *dav_uid;
        long dav_msgnum = (-1);
        char datestring[256];
        time_t now;
@@ -38,73 +24,97 @@ void groupdav_options(char *dav_pathname) {
        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);
+       dav_roomname = NewStrBuf();
+       dav_uid = NewStrBuf();
+       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 doing a top-level OPTIONS.
         */
-       if (strlen(dav_roomname) == 0) {
-               wprintf("HTTP/1.1 200 OK\r\n");
+       if (StrLength(dav_roomname) == 0) {
+               hprintf("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");
+               hprintf("Date: %s\r\n", datestring);
+               hprintf("DAV: 1\r\n");
+               hprintf("Allow: OPTIONS, PROPFIND\r\n");
+               hprintf("\r\n");
+               begin_burst();
+               end_burst();
+               FreeStrBuf(&dav_roomname);
+               FreeStrBuf(&dav_uid);
                return;
        }
 
        /* Go to the correct room. */
-       if (strcasecmp(WC->wc_roomname, dav_roomname)) {
+       if (strcasecmp(ChrPtr(WC->wc_roomname), ChrPtr(dav_roomname))) {
                gotoroom(dav_roomname);
        }
-       if (strcasecmp(WC->wc_roomname, dav_roomname)) {
-               wprintf("HTTP/1.1 404 not found\r\n");
+
+       if (strcasecmp(ChrPtr(WC->wc_roomname), ChrPtr(dav_roomname))) {
+               hprintf("HTTP/1.1 404 not found\r\n");
                groupdav_common_headers();
-               wprintf("Date: %s\r\n", datestring);
+               hprintf("Date: %s\r\n", datestring);
+               hprintf(
+                       "Content-Type: text/plain\r\n");
+               begin_burst();
                wprintf(
-                       "Content-Type: text/plain\r\n"
-                       "\r\n"
                        "There is no folder called \"%s\" on this server.\r\n",
-                       dav_roomname
+                       ChrPtr(dav_roomname)
                );
+               end_burst();
+               FreeStrBuf(&dav_roomname);
+               FreeStrBuf(&dav_uid);
                return;
        }
 
        /* If dav_uid is non-empty, client is requesting an OPTIONS on
         * a specific item in the room.
         */
-       if (strlen(dav_uid) > 0) {
+       if (StrLength(dav_uid) != 0) {
 
-               dav_msgnum = locate_message_by_uid(dav_uid);
+               dav_msgnum = locate_message_by_uid(ChrPtr(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();
+                       hprintf("Content-Type: text/plain\r\n");
+                       begin_burst();
                        wprintf(
-                               "Content-Type: text/plain\r\n"
-                               "\r\n"
                                "Object \"%s\" was not found in the \"%s\" folder.\r\n",
-                               dav_uid,
-                               dav_roomname
+                               ChrPtr(dav_uid),
+                               ChrPtr(dav_roomname)
                        );
-                       return;
+                       FreeStrBuf(&dav_roomname);
+                       FreeStrBuf(&dav_uid);
+                       end_burst();return;
                }
 
-               wprintf("HTTP/1.1 200 OK\r\n");
+               hprintf("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");
+               hprintf("Date: %s\r\n", datestring);
+               hprintf("DAV: 1\r\n");
+               hprintf("Allow: OPTIONS, PROPFIND, GET, PUT, DELETE\r\n");
+               
+               begin_burst();
+               end_burst();
+               FreeStrBuf(&dav_roomname);
+               FreeStrBuf(&dav_uid);
                return;
        }
 
+       FreeStrBuf(&dav_roomname);
+       FreeStrBuf(&dav_uid);
 
        /*
         * 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");
+       hprintf("HTTP/1.1 200 OK\r\n");
        groupdav_common_headers();
-       wprintf("Date: %s\r\n", datestring);
-       wprintf("Allow: OPTIONS, PROPFIND, GET, PUT\r\n");
+       hprintf("Date: %s\r\n", datestring);
+       hprintf("DAV: 1\r\n");
+       hprintf("Allow: OPTIONS, PROPFIND, GET, PUT\r\n");
+       begin_burst();
        wprintf("\r\n");
+       end_burst();
 }