* do linebuffered/non-blocking reads from http requests
[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(const 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 (IsEmptyStr(dav_roomname)) {
32                 hprintf("HTTP/1.1 200 OK\r\n");
33                 groupdav_common_headers();
34                 hprintf("Date: %s\r\n", datestring);
35                 hprintf("DAV: 1\r\n");
36                 hprintf("Allow: OPTIONS, PROPFIND\r\n");
37                 hprintf("\r\n");
38                 begin_burst();
39                 end_burst();
40                 return;
41         }
42
43         /* Go to the correct room. */
44         if (strcasecmp(WC->wc_roomname, dav_roomname)) {
45                 gotoroom(dav_roomname);
46         }
47
48         if (strcasecmp(WC->wc_roomname, dav_roomname)) {
49                 hprintf("HTTP/1.1 404 not found\r\n");
50                 groupdav_common_headers();
51                 hprintf("Date: %s\r\n", datestring);
52                 hprintf(
53                         "Content-Type: text/plain\r\n"
54                         "\r\n"
55                         "There is no folder called \"%s\" on this server.\r\n",
56                         dav_roomname
57                 );
58                 begin_burst();
59                 end_burst();
60                 return;
61         }
62
63         /* If dav_uid is non-empty, client is requesting an OPTIONS on
64          * a specific item in the room.
65          */
66         if (!IsEmptyStr(dav_uid)) {
67
68                 dav_msgnum = locate_message_by_uid(dav_uid);
69                 if (dav_msgnum < 0) {
70                         hprintf("HTTP/1.1 404 not found\r\n");
71                         groupdav_common_headers();
72                         hprintf(
73                                 "Content-Type: text/plain\r\n"
74                                 "\r\n"
75                                 "Object \"%s\" was not found in the \"%s\" folder.\r\n",
76                                 dav_uid,
77                                 dav_roomname
78                         );
79                         begin_burst();end_burst();return;
80                 }
81
82                 hprintf("HTTP/1.1 200 OK\r\n");
83                 groupdav_common_headers();
84                 hprintf("Date: %s\r\n", datestring);
85                 hprintf("DAV: 1\r\n");
86                 hprintf("Allow: OPTIONS, PROPFIND, GET, PUT, DELETE\r\n");
87                 hprintf("\r\n");
88                 begin_burst();
89                 end_burst();
90                 return;
91         }
92
93         /*
94          * We got to this point, which means that the client is requesting
95          * an OPTIONS on the room itself.
96          */
97         hprintf("HTTP/1.1 200 OK\r\n");
98         groupdav_common_headers();
99         hprintf("Date: %s\r\n", datestring);
100         hprintf("DAV: 1\r\n");
101         hprintf("Allow: OPTIONS, PROPFIND, GET, PUT\r\n");
102         hprintf("\r\n");
103         begin_burst();
104         end_burst();
105 }