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(HashList *HTTPHeaders,
89 StrBuf *dav_content_type,
90 int dav_content_length,
96 char dav_ifmatch[256];
101 strcpy(dav_ifmatch, "");
104 if ((StrLength(WCC->Hdr->http_host) == 0) &&
105 GetHash(HTTPHeaders, HKEY("HOST"), &vLine) &&
107 WCC->Hdr->http_host = (StrBuf*)vLine;
109 if (GetHash(HTTPHeaders, HKEY("IF-MATCH"), &vLine) &&
111 safestrncpy(dav_ifmatch, ChrPtr((StrBuf*)vLine),
114 if (GetHash(HTTPHeaders, HKEY("DEPTH"), &vLine) &&
116 if (!strcasecmp(ChrPtr((StrBuf*)vLine), "infinity")) {
119 else if (strcmp(ChrPtr((StrBuf*)vLine), "0") == 0) {
122 else if (strcmp(ChrPtr((StrBuf*)vLine), "1") == 0) {
127 if (!WC->logged_in) {
128 hprintf("HTTP/1.1 401 Unauthorized\r\n");
129 groupdav_common_headers();
130 hprintf("WWW-Authenticate: Basic realm=\"%s\"\r\n",
131 ChrPtr(WCC->serv_info->serv_humannode));
132 hprintf("Content-Length: 0\r\n");
137 StrBufUnescape(DavPathname, 0);
139 /* Remove any stray double-slashes in pathname */
140 while (ds=strstr(ChrPtr(DavPathname), "//"), ds != NULL) {
145 * If there's an If-Match: header, strip out the quotes if present, and
146 * then if all that's left is an asterisk, make it go away entirely.
148 len = strlen(dav_ifmatch);
150 stripltlen(dav_ifmatch, &len);
151 if (dav_ifmatch[0] == '\"') {
152 memmove (dav_ifmatch, &dav_ifmatch[1], len);
154 for (i=0; i<len; ++i) {
155 if (dav_ifmatch[i] == '\"') {
161 if (!strcmp(dav_ifmatch, "*")) {
162 strcpy(dav_ifmatch, "");
166 switch (WCC->Hdr->eReqType)
169 * The OPTIONS method is not required by GroupDAV. This is an
170 * experiment to determine what might be involved in supporting
171 * other variants of DAV in the future.
174 groupdav_options(DavPathname);
179 * The PROPFIND method is basically used to list all objects in a
180 * room, or to list all relevant rooms on the server.
183 groupdav_propfind(DavPathname, dav_depth,
184 dav_content_type, dav_content,
189 * The GET method is used for fetching individual items.
192 groupdav_get(DavPathname);
196 * The PUT method is used to add or modify items.
199 groupdav_put(DavPathname, dav_ifmatch,
200 ChrPtr(dav_content_type), dav_content,
205 * The DELETE method kills, maims, and destroys.
208 groupdav_delete(DavPathname, dav_ifmatch);
213 * Couldn't find what we were looking for. Die in a car fire.
215 hprintf("HTTP/1.1 501 Method not implemented\r\n");
216 groupdav_common_headers();
217 hprintf("Content-Type: text/plain\r\n");
218 wprintf("GroupDAV method \"%s\" is not implemented.\r\n",
219 ReqStrs[WCC->Hdr->eReqType]);
226 * Output our host prefix for globally absolute URL's.
228 void groupdav_identify_host(void) {
231 if (StrLength(WCC->Hdr->http_host)!=0) {
233 (is_https ? "https" : "http"),
234 ChrPtr(WCC->Hdr->http_host));
244 WebcitAddUrlHandler(HKEY("groupdav"), do_logout, XHTTP_COMMANDS|COOKIEUNNEEDED|FORCE_SESSIONCLOSE);