4 * Entry point for GroupDAV functions
14 #include <sys/types.h>
16 #include <sys/socket.h>
25 #include "webserver.h"
30 * Output HTTP headers which are common to all requests.
32 * Please observe that we don't use the usual output_headers()
33 * and wDumpContent() functions in the GroupDAV subsystem, so we
34 * do our own header stuff here.
37 void groupdav_common_headers(void) {
40 "Connection: close\r\n",
41 SERVER, serv_info.serv_software
48 * string conversion function
50 void euid_escapize(char *target, char *source) {
52 int target_length = 0;
55 for (i=0; i<strlen(source); ++i) {
56 if (isalnum(source[i])) {
57 target[target_length] = source[i];
58 target[++target_length] = 0;
60 else if (source[i] == ' ') {
61 target[target_length] = '_';
62 target[++target_length] = 0;
64 else if (source[i] == '-') {
65 target[target_length] = '-';
66 target[++target_length] = 0;
69 sprintf(&target[target_length], "%%%02X", source[i]);
76 * string conversion function
78 void euid_unescapize(char *target, char *source) {
81 int target_length = 0;
85 for (a = 0; a < strlen(source); ++a) {
86 if (source[a] == '%') {
87 hex[0] = source[a + 1];
88 hex[1] = source[a + 2];
91 sscanf(hex, "%02x", &b);
92 target[target_length] = b;
93 target[++target_length] = 0;
96 else if (source[a] == '_') {
97 target[target_length] = ' ';
98 target[++target_length] = 0;
100 else if (source[a] == '-') {
101 target[target_length] = '-';
102 target[++target_length] = 0;
105 target[target_length] = source[a];
106 target[++target_length] = 0;
115 * Main entry point for GroupDAV requests
117 void groupdav_main(struct httprequest *req,
118 char *dav_content_type,
119 int dav_content_length,
122 struct httprequest *rptr;
123 char dav_method[SIZ];
124 char dav_pathname[SIZ];
125 char dav_ifmatch[SIZ];
129 strcpy(dav_method, "");
130 strcpy(dav_pathname, "");
131 strcpy(dav_ifmatch, "");
133 for (rptr=req; rptr!=NULL; rptr=rptr->next) {
134 /* lprintf(9, "< %s\n", rptr->line); */
135 if (!strncasecmp(rptr->line, "Host: ", 6)) {
136 safestrncpy(WC->http_host, &rptr->line[6],
137 sizeof WC->http_host);
139 if (!strncasecmp(rptr->line, "If-Match: ", 10)) {
140 safestrncpy(dav_ifmatch, &rptr->line[10],
145 if (!WC->logged_in) {
146 wprintf("HTTP/1.1 401 Unauthorized\r\n");
147 groupdav_common_headers();
148 wprintf("WWW-Authenticate: Basic realm=\"%s\"\r\n",
149 serv_info.serv_humannode);
150 wprintf("Content-Length: 0\r\n\r\n");
154 extract_token(dav_method, req->line, 0, ' ', sizeof dav_method);
155 extract_token(dav_pathname, req->line, 1, ' ', sizeof dav_pathname);
156 unescape_input(dav_pathname);
158 /* Remove any stray double-slashes in pathname */
159 while (ds=strstr(dav_pathname, "//"), ds != NULL) {
164 * If there's an If-Match: header, strip out the quotes if present, and
165 * then if all that's left is an asterisk, make it go away entirely.
167 if (strlen(dav_ifmatch) > 0) {
168 striplt(dav_ifmatch);
169 if (dav_ifmatch[0] == '\"') {
170 strcpy(dav_ifmatch, &dav_ifmatch[1]);
171 for (i=0; i<strlen(dav_ifmatch); ++i) {
172 if (dav_ifmatch[i] == '\"') {
177 if (!strcmp(dav_ifmatch, "*")) {
178 strcpy(dav_ifmatch, "");
183 * The PROPFIND method is basically used to list all objects in a
184 * room, or to list all relevant rooms on the server.
186 if (!strcasecmp(dav_method, "PROPFIND")) {
187 groupdav_propfind(dav_pathname);
192 * The GET method is used for fetching individual items.
194 if (!strcasecmp(dav_method, "GET")) {
195 groupdav_get(dav_pathname);
200 * The PUT method is used to add or modify items.
202 if (!strcasecmp(dav_method, "PUT")) {
203 groupdav_put(dav_pathname, dav_ifmatch,
204 dav_content_type, dav_content);
209 * The DELETE method kills, maims, and destroys.
211 if (!strcasecmp(dav_method, "DELETE")) {
212 groupdav_delete(dav_pathname, dav_ifmatch);
217 * Couldn't find what we were looking for. Die in a car fire.
219 wprintf("HTTP/1.1 501 Method not implemented\r\n");
220 groupdav_common_headers();
221 wprintf("Content-Type: text/plain\r\n"
223 "GroupDAV method \"%s\" is not implemented.\r\n",