groupdav_options.c

00001 /*
00002  * $Id: groupdav_options.c 5147 2007-05-08 15:36:22Z ajc $
00003  *
00004  * Handles DAV OPTIONS requests (experimental -- not required by GroupDAV)
00005  *
00006  */
00007 
00008 #include "webcit.h"
00009 #include "webserver.h"
00010 #include "groupdav.h"
00011 
00012 /*
00013  * The pathname is always going to be /groupdav/room_name/msg_num
00014  */
00015 void groupdav_options(char *dav_pathname) {
00016         char dav_roomname[256];
00017         char dav_uid[256];
00018         long dav_msgnum = (-1);
00019         char datestring[256];
00020         time_t now;
00021 
00022         now = time(NULL);
00023         http_datestring(datestring, sizeof datestring, now);
00024 
00025         extract_token(dav_roomname, dav_pathname, 2, '/', sizeof dav_roomname);
00026         extract_token(dav_uid, dav_pathname, 3, '/', sizeof dav_uid);
00027 
00028         /*
00029          * If the room name is blank, the client is doing a top-level OPTIONS.
00030          */
00031         if (strlen(dav_roomname) == 0) {
00032                 wprintf("HTTP/1.1 200 OK\r\n");
00033                 groupdav_common_headers();
00034                 wprintf("Date: %s\r\n", datestring);
00035                 wprintf("DAV: 1\r\n");
00036                 wprintf("Allow: OPTIONS, PROPFIND\r\n");
00037                 wprintf("\r\n");
00038                 return;
00039         }
00040 
00041         /* Go to the correct room. */
00042         if (strcasecmp(WC->wc_roomname, dav_roomname)) {
00043                 gotoroom(dav_roomname);
00044         }
00045 
00046         if (strcasecmp(WC->wc_roomname, dav_roomname)) {
00047                 wprintf("HTTP/1.1 404 not found\r\n");
00048                 groupdav_common_headers();
00049                 wprintf("Date: %s\r\n", datestring);
00050                 wprintf(
00051                         "Content-Type: text/plain\r\n"
00052                         "\r\n"
00053                         "There is no folder called \"%s\" on this server.\r\n",
00054                         dav_roomname
00055                 );
00056                 return;
00057         }
00058 
00059         /* If dav_uid is non-empty, client is requesting an OPTIONS on
00060          * a specific item in the room.
00061          */
00062         if (strlen(dav_uid) > 0) {
00063 
00064                 dav_msgnum = locate_message_by_uid(dav_uid);
00065                 if (dav_msgnum < 0) {
00066                         wprintf("HTTP/1.1 404 not found\r\n");
00067                         groupdav_common_headers();
00068                         wprintf(
00069                                 "Content-Type: text/plain\r\n"
00070                                 "\r\n"
00071                                 "Object \"%s\" was not found in the \"%s\" folder.\r\n",
00072                                 dav_uid,
00073                                 dav_roomname
00074                         );
00075                         return;
00076                 }
00077 
00078                 wprintf("HTTP/1.1 200 OK\r\n");
00079                 groupdav_common_headers();
00080                 wprintf("Date: %s\r\n", datestring);
00081                 wprintf("DAV: 1\r\n");
00082                 wprintf("Allow: OPTIONS, PROPFIND, GET, PUT, DELETE\r\n");
00083                 wprintf("\r\n");
00084                 return;
00085         }
00086 
00087         /*
00088          * We got to this point, which means that the client is requesting
00089          * an OPTIONS on the room itself.
00090          */
00091         wprintf("HTTP/1.1 200 OK\r\n");
00092         groupdav_common_headers();
00093         wprintf("Date: %s\r\n", datestring);
00094         wprintf("DAV: 1\r\n");
00095         wprintf("Allow: OPTIONS, PROPFIND, GET, PUT\r\n");
00096         wprintf("\r\n");
00097 }

Generated on Wed Jun 20 23:13:08 2007 for webcit by  doxygen 1.5.2