4 * Entry point for GroupDAV functions
14 * Output HTTP headers which are common to all requests.
16 * Please observe that we don't use the usual output_headers()
17 * and wDumpContent() functions in the GroupDAV subsystem, so we
18 * do our own header stuff here.
21 void groupdav_common_headers(void) {
24 "Connection: close\r\n",
25 PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software)
32 * string conversion function
34 void euid_escapize(char *target, const char *source) {
36 int target_length = 0;
40 for (i=0; i<len; ++i) {
41 if ( (isalnum(source[i])) || (source[i]=='-') || (source[i]=='_') ) {
42 target[target_length] = source[i];
43 target[++target_length] = 0;
46 sprintf(&target[target_length], "=%02X", (0xFF & source[i]));
53 * string conversion function
55 void euid_unescapize(char *target, const char *source) {
58 int target_length = 0;
63 for (a = 0; a < len; ++a) {
64 if (source[a] == '=') {
65 hex[0] = source[a + 1];
66 hex[1] = source[a + 2];
70 target[target_length] = b;
71 target[++target_length] = 0;
75 target[target_length] = source[a];
76 target[++target_length] = 0;
85 * Main entry point for GroupDAV requests
87 void groupdav_main(void)
92 StrBufUnescape(WCC->Hdr->HR.ReqLine, 0);
94 StrBufStripSlashes(WCC->Hdr->HR.ReqLine, 0);
97 * If there's an If-Match: header, strip out the quotes if present, and
98 * then if all that's left is an asterisk, make it go away entirely.
100 len = StrLength(WCC->Hdr->HR.dav_ifmatch);
102 StrBufTrim(WCC->Hdr->HR.dav_ifmatch);
103 if (ChrPtr(WCC->Hdr->HR.dav_ifmatch)[0] == '\"') {
104 StrBufCutLeft(WCC->Hdr->HR.dav_ifmatch, 1);
106 for (i=0; i<len; ++i) {
107 if (ChrPtr(WCC->Hdr->HR.dav_ifmatch)[i] == '\"') {
108 StrBufCutAt(WCC->Hdr->HR.dav_ifmatch, i, NULL);
109 len = StrLength(WCC->Hdr->HR.dav_ifmatch);
113 if (!strcmp(ChrPtr(WCC->Hdr->HR.dav_ifmatch), "*")) {
114 FlushStrBuf(WCC->Hdr->HR.dav_ifmatch);
118 switch (WCC->Hdr->HR.eReqType)
121 * The OPTIONS method is not required by GroupDAV. This is an
122 * experiment to determine what might be involved in supporting
123 * other variants of DAV in the future.
131 * The PROPFIND method is basically used to list all objects in a
132 * room, or to list all relevant rooms on the server.
139 * The GET method is used for fetching individual items.
146 * The PUT method is used to add or modify items.
153 * The DELETE method kills, maims, and destroys.
161 * Couldn't find what we were looking for. Die in a car fire.
163 hprintf("HTTP/1.1 501 Method not implemented\r\n");
164 groupdav_common_headers();
165 hprintf("Content-Type: text/plain\r\n");
166 wprintf("GroupDAV method \"%s\" is not implemented.\r\n",
167 ReqStrs[WCC->Hdr->HR.eReqType]);
174 * Output our host prefix for globally absolute URL's.
176 void groupdav_identify_host(void) {
179 if (StrLength(WCC->Hdr->HR.http_host)!=0) {
181 (is_https ? "https" : "http"),
182 ChrPtr(WCC->Hdr->HR.http_host));
187 void Header_HandleIfMatch(StrBuf *Line, ParsedHttpHdrs *hdr)
189 hdr->HR.dav_ifmatch = Line;
192 void Header_HandleDepth(StrBuf *Line, ParsedHttpHdrs *hdr)
194 if (!strcasecmp(ChrPtr(Line), "infinity")) {
195 hdr->HR.dav_depth = 32767;
197 else if (strcmp(ChrPtr(Line), "0") == 0) {
198 hdr->HR.dav_depth = 0;
200 else if (strcmp(ChrPtr(Line), "1") == 0) {
201 hdr->HR.dav_depth = 1;
209 WebcitAddUrlHandler(HKEY("groupdav"), groupdav_main, XHTTP_COMMANDS|COOKIEUNNEEDED|FORCE_SESSIONCLOSE);
210 RegisterHeaderHandler(HKEY("IF-MATCH"), Header_HandleIfMatch);
211 RegisterHeaderHandler(HKEY("DEPTH"), Header_HandleDepth);