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, serv_info.serv_software
32 * string conversion function
34 void euid_escapize(char *target, 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", source[i]);
53 * string conversion function
55 void euid_unescapize(char *target, 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];
69 sscanf(hex, "%02x", &b);
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(struct httprequest *req,
88 char *dav_content_type,
89 int dav_content_length,
92 struct httprequest *rptr;
94 char dav_pathname[256];
95 char dav_ifmatch[256];
100 strcpy(dav_method, "");
101 strcpy(dav_pathname, "");
102 strcpy(dav_ifmatch, "");
105 for (rptr=req; rptr!=NULL; rptr=rptr->next) {
106 if (!strncasecmp(rptr->line, "Host: ", 6)) {
107 if (IsEmptyStr(WC->http_host)) {
108 safestrncpy(WC->http_host, &rptr->line[6],
109 sizeof WC->http_host);
112 if (!strncasecmp(rptr->line, "If-Match: ", 10)) {
113 safestrncpy(dav_ifmatch, &rptr->line[10],
116 if (!strncasecmp(rptr->line, "Depth: ", 7)) {
117 if (!strcasecmp(&rptr->line[7], "infinity")) {
120 else if (!strcmp(&rptr->line[7], "0")) {
123 else if (!strcmp(&rptr->line[7], "1")) {
129 if (!WC->logged_in) {
130 wprintf("HTTP/1.1 401 Unauthorized\r\n");
131 groupdav_common_headers();
132 wprintf("WWW-Authenticate: Basic realm=\"%s\"\r\n",
133 serv_info.serv_humannode);
134 wprintf("Content-Length: 0\r\n\r\n");
138 extract_token(dav_method, req->line, 0, ' ', sizeof dav_method);
139 extract_token(dav_pathname, req->line, 1, ' ', sizeof dav_pathname);
140 unescape_input(dav_pathname);
142 /* If the request does not begin with "/groupdav", prepend it. If
143 * we happen to introduce a double-slash, that's ok; we'll strip it
146 * (THIS IS DISABLED BECAUSE WE ARE NOW TRYING TO DO REAL DAV.)
148 if (strncasecmp(dav_pathname, "/groupdav", 9)) {
150 snprintf(buf, sizeof buf, "/groupdav/%s", dav_pathname);
151 safestrncpy(dav_pathname, buf, sizeof dav_pathname);
156 /* Remove any stray double-slashes in pathname */
157 while (ds=strstr(dav_pathname, "//"), ds != NULL) {
162 * If there's an If-Match: header, strip out the quotes if present, and
163 * then if all that's left is an asterisk, make it go away entirely.
165 len = strlen(dav_ifmatch);
167 stripltlen(dav_ifmatch, &len);
168 if (dav_ifmatch[0] == '\"') {
169 memmove (dav_ifmatch, &dav_ifmatch[1], len);
171 for (i=0; i<len; ++i) {
172 if (dav_ifmatch[i] == '\"') {
178 if (!strcmp(dav_ifmatch, "*")) {
179 strcpy(dav_ifmatch, "");
184 * The OPTIONS method is not required by GroupDAV. This is an
185 * experiment to determine what might be involved in supporting
186 * other variants of DAV in the future.
188 if (!strcasecmp(dav_method, "OPTIONS")) {
189 groupdav_options(dav_pathname);
194 * The PROPFIND method is basically used to list all objects in a
195 * room, or to list all relevant rooms on the server.
197 if (!strcasecmp(dav_method, "PROPFIND")) {
198 groupdav_propfind(dav_pathname, dav_depth,
199 dav_content_type, dav_content);
204 * The GET method is used for fetching individual items.
206 if (!strcasecmp(dav_method, "GET")) {
207 groupdav_get(dav_pathname);
212 * The PUT method is used to add or modify items.
214 if (!strcasecmp(dav_method, "PUT")) {
215 groupdav_put(dav_pathname, dav_ifmatch,
216 dav_content_type, dav_content,
222 * The DELETE method kills, maims, and destroys.
224 if (!strcasecmp(dav_method, "DELETE")) {
225 groupdav_delete(dav_pathname, dav_ifmatch);
230 * Couldn't find what we were looking for. Die in a car fire.
232 wprintf("HTTP/1.1 501 Method not implemented\r\n");
233 groupdav_common_headers();
234 wprintf("Content-Type: text/plain\r\n"
236 "GroupDAV method \"%s\" is not implemented.\r\n",
243 * Output our host prefix for globally absolute URL's.
245 void groupdav_identify_host(void) {
246 if (!IsEmptyStr(WC->http_host)) {
248 (is_https ? "https" : "http"),