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 SERVER, serv_info.serv_software
32 * string conversion function
34 void euid_escapize(char *target, char *source) {
36 int target_length = 0;
39 for (i=0; i<strlen(source); ++i) {
40 if (isalnum(source[i])) {
41 target[target_length] = source[i];
42 target[++target_length] = 0;
44 else if (source[i] == ' ') {
45 target[target_length] = '_';
46 target[++target_length] = 0;
48 else if (source[i] == '-') {
49 target[target_length] = '-';
50 target[++target_length] = 0;
53 sprintf(&target[target_length], "%%%02X", source[i]);
60 * string conversion function
62 void euid_unescapize(char *target, char *source) {
65 int target_length = 0;
69 for (a = 0; a < strlen(source); ++a) {
70 if (source[a] == '%') {
71 hex[0] = source[a + 1];
72 hex[1] = source[a + 2];
75 sscanf(hex, "%02x", &b);
76 target[target_length] = b;
77 target[++target_length] = 0;
80 else if (source[a] == '_') {
81 target[target_length] = ' ';
82 target[++target_length] = 0;
84 else if (source[a] == '-') {
85 target[target_length] = '-';
86 target[++target_length] = 0;
89 target[target_length] = source[a];
90 target[++target_length] = 0;
99 * Main entry point for GroupDAV requests
101 void groupdav_main(struct httprequest *req,
102 char *dav_content_type,
103 int dav_content_length,
106 struct httprequest *rptr;
107 char dav_method[256];
108 char dav_pathname[256];
109 char dav_ifmatch[256];
114 strcpy(dav_method, "");
115 strcpy(dav_pathname, "");
116 strcpy(dav_ifmatch, "");
118 for (rptr=req; rptr!=NULL; rptr=rptr->next) {
119 /* lprintf(9, "< %s\n", rptr->line); */
120 if (!strncasecmp(rptr->line, "Host: ", 6)) {
121 safestrncpy(WC->http_host, &rptr->line[6],
122 sizeof WC->http_host);
124 if (!strncasecmp(rptr->line, "If-Match: ", 10)) {
125 safestrncpy(dav_ifmatch, &rptr->line[10],
130 if (!WC->logged_in) {
131 wprintf("HTTP/1.1 401 Unauthorized\r\n");
132 groupdav_common_headers();
133 wprintf("WWW-Authenticate: Basic realm=\"%s\"\r\n",
134 serv_info.serv_humannode);
135 wprintf("Content-Length: 0\r\n\r\n");
139 extract_token(dav_method, req->line, 0, ' ', sizeof dav_method);
140 extract_token(dav_pathname, req->line, 1, ' ', sizeof dav_pathname);
141 unescape_input(dav_pathname);
143 /* If the request does not begin with "/groupdav", prepend it. If
144 * we happen to introduce a double-slash, that's ok; we'll strip it
147 if (strncasecmp(dav_pathname, "/groupdav", 9)) {
148 snprintf(buf, sizeof buf, "/groupdav/%s", dav_pathname);
149 safestrncpy(dav_pathname, buf, sizeof dav_pathname);
152 /* Remove any stray double-slashes in pathname */
153 while (ds=strstr(dav_pathname, "//"), ds != NULL) {
158 * If there's an If-Match: header, strip out the quotes if present, and
159 * then if all that's left is an asterisk, make it go away entirely.
161 if (strlen(dav_ifmatch) > 0) {
162 striplt(dav_ifmatch);
163 if (dav_ifmatch[0] == '\"') {
164 strcpy(dav_ifmatch, &dav_ifmatch[1]);
165 for (i=0; i<strlen(dav_ifmatch); ++i) {
166 if (dav_ifmatch[i] == '\"') {
171 if (!strcmp(dav_ifmatch, "*")) {
172 strcpy(dav_ifmatch, "");
177 * The OPTIONS method is not required by GroupDAV. This is an
178 * experiment to determine what might be involved in supporting
179 * other variants of DAV in the future.
181 if (!strcasecmp(dav_method, "OPTIONS")) {
182 groupdav_options(dav_pathname);
187 * The PROPFIND method is basically used to list all objects in a
188 * room, or to list all relevant rooms on the server.
190 if (!strcasecmp(dav_method, "PROPFIND")) {
191 groupdav_propfind(dav_pathname);
196 * The GET method is used for fetching individual items.
198 if (!strcasecmp(dav_method, "GET")) {
199 groupdav_get(dav_pathname);
204 * The PUT method is used to add or modify items.
206 if (!strcasecmp(dav_method, "PUT")) {
207 groupdav_put(dav_pathname, dav_ifmatch,
208 dav_content_type, dav_content);
213 * The DELETE method kills, maims, and destroys.
215 if (!strcasecmp(dav_method, "DELETE")) {
216 groupdav_delete(dav_pathname, dav_ifmatch);
221 * Couldn't find what we were looking for. Die in a car fire.
223 wprintf("HTTP/1.1 501 Method not implemented\r\n");
224 groupdav_common_headers();
225 wprintf("Content-Type: text/plain\r\n"
227 "GroupDAV method \"%s\" is not implemented.\r\n",