Began making changes to do better handling of character sets.
[citadel.git] / webcit / groupdav_options.c
1 /*
2  * $Id$
3  *
4  * Handles DAV OPTIONS requests (experimental -- not required by GroupDAV)
5  *
6  */
7
8 #include "webcit.h"
9 #include "webserver.h"
10 #include "groupdav.h"
11
12 /*
13  * The pathname is always going to be /groupdav/room_name/msg_num
14  */
15 void groupdav_options(char *dav_pathname) {
16         char dav_roomname[256];
17         char dav_uid[256];
18         long dav_msgnum = (-1);
19         char datestring[256];
20         time_t now;
21
22         now = time(NULL);
23         http_datestring(datestring, sizeof datestring, now);
24
25         extract_token(dav_roomname, dav_pathname, 2, '/', sizeof dav_roomname);
26         extract_token(dav_uid, dav_pathname, 3, '/', sizeof dav_uid);
27
28         /*
29          * If the room name is blank, the client is doing a top-level OPTIONS.
30          */
31         if (strlen(dav_roomname) == 0) {
32                 wprintf("HTTP/1.1 200 OK\r\n");
33                 groupdav_common_headers();
34                 wprintf("Date: %s\r\n", datestring);
35                 wprintf("DAV: 1\r\n");
36                 wprintf("Allow: OPTIONS, PROPFIND\r\n");
37                 wprintf("\r\n");
38                 return;
39         }
40
41         /* Go to the correct room. */
42         if (strcasecmp(WC->wc_roomname, dav_roomname)) {
43                 gotoroom(dav_roomname);
44         }
45
46         if (strcasecmp(WC->wc_roomname, dav_roomname)) {
47                 wprintf("HTTP/1.1 404 not found\r\n");
48                 groupdav_common_headers();
49                 wprintf("Date: %s\r\n", datestring);
50                 wprintf(
51                         "Content-Type: text/plain\r\n"
52                         "\r\n"
53                         "There is no folder called \"%s\" on this server.\r\n",
54                         dav_roomname
55                 );
56                 return;
57         }
58
59         /* If dav_uid is non-empty, client is requesting an OPTIONS on
60          * a specific item in the room.
61          */
62         if (strlen(dav_uid) > 0) {
63
64                 dav_msgnum = locate_message_by_uid(dav_uid);
65                 if (dav_msgnum < 0) {
66                         wprintf("HTTP/1.1 404 not found\r\n");
67                         groupdav_common_headers();
68                         wprintf(
69                                 "Content-Type: text/plain\r\n"
70                                 "\r\n"
71                                 "Object \"%s\" was not found in the \"%s\" folder.\r\n",
72                                 dav_uid,
73                                 dav_roomname
74                         );
75                         return;
76                 }
77
78                 wprintf("HTTP/1.1 200 OK\r\n");
79                 groupdav_common_headers();
80                 wprintf("Date: %s\r\n", datestring);
81                 wprintf("DAV: 1\r\n");
82                 wprintf("Allow: OPTIONS, PROPFIND, GET, PUT, DELETE\r\n");
83                 wprintf("\r\n");
84                 return;
85         }
86
87         /*
88          * We got to this point, which means that the client is requesting
89          * an OPTIONS on the room itself.
90          */
91         wprintf("HTTP/1.1 200 OK\r\n");
92         groupdav_common_headers();
93         wprintf("Date: %s\r\n", datestring);
94         wprintf("DAV: 1\r\n");
95         wprintf("Allow: OPTIONS, PROPFIND, GET, PUT\r\n");
96         wprintf("\r\n");
97 }