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 void groupdav_common_headers(void) {
35 "Connection: close\n",
36 SERVER, serv_info.serv_software
43 * string conversion function
45 void euid_escapize(char *target, char *source) {
47 int target_length = 0;
50 for (i=0; i<strlen(source); ++i) {
51 if (isalnum(source[i])) {
52 target[target_length] = source[i];
53 target[++target_length] = 0;
56 sprintf(&target[target_length], "_%02X", source[i]);
63 * string conversion function
65 void euid_unescapize(char *target, char *source) {
68 int target_length = 0;
72 for (a = 0; a < strlen(source); ++a) {
73 if (source[a] == '_') {
74 hex[0] = source[a + 1];
75 hex[1] = source[a + 2];
78 sscanf(hex, "%02x", &b);
79 target[target_length] = b;
80 target[++target_length] = 0;
84 target[target_length] = source[a];
85 target[++target_length] = 0;
94 * Main entry point for GroupDAV requests
96 void groupdav_main(struct httprequest *req,
97 char *dav_content_type,
98 int dav_content_length,
101 struct httprequest *rptr;
102 char dav_method[SIZ];
103 char dav_pathname[SIZ];
104 char dav_ifmatch[SIZ];
106 strcpy(dav_method, "");
107 strcpy(dav_pathname, "");
108 strcpy(dav_ifmatch, "");
110 for (rptr=req; rptr!=NULL; rptr=rptr->next) {
111 if (!strncasecmp(rptr->line, "Host: ", 6)) {
112 safestrncpy(WC->http_host, &rptr->line[6],
113 sizeof WC->http_host);
115 if (!strncasecmp(rptr->line, "If-Match: ", 10)) {
116 safestrncpy(dav_ifmatch, &rptr->line[10],
121 if (!WC->logged_in) {
122 wprintf("HTTP/1.1 401 Unauthorized\n");
123 groupdav_common_headers();
124 wprintf("WWW-Authenticate: Basic realm=\"%s\"\n",
125 serv_info.serv_humannode);
126 wprintf("Content-Type: text/plain\n");
128 wprintf("GroupDAV sessions require HTTP authentication.\n");
132 extract_token(dav_method, req->line, 0, ' ');
133 extract_token(dav_pathname, req->line, 1, ' ');
134 unescape_input(dav_pathname);
137 * If there's an If-Match: header, strip out the quotes if present, and
138 * then if all that's left is an asterisk, make it go away entirely.
140 if (strlen(dav_ifmatch) > 0) {
141 if (dav_ifmatch[0] == '\"') {
142 strcpy(dav_ifmatch, &dav_ifmatch[1]);
143 if (strtok(dav_ifmatch, "\"") != NULL) {
144 strcpy(strtok(dav_ifmatch, "\""), "");
147 if (!strcmp(dav_ifmatch, "*")) {
148 strcpy(dav_ifmatch, "");
153 * The PROPFIND method is basically used to list all objects in a
154 * room, or to list all relevant rooms on the server.
156 if (!strcasecmp(dav_method, "PROPFIND")) {
157 groupdav_propfind(dav_pathname);
162 * The GET method is used for fetching individual items.
164 if (!strcasecmp(dav_method, "GET")) {
165 groupdav_get(dav_pathname);
170 * The PUT method is used to add or modify items.
172 if (!strcasecmp(dav_method, "PUT")) {
173 groupdav_put(dav_pathname, dav_ifmatch,
174 dav_content_type, dav_content);
179 * The DELETE method kills, maims, and destroys.
181 if (!strcasecmp(dav_method, "DELETE")) {
182 groupdav_delete(dav_pathname, dav_ifmatch);
187 * Couldn't find what we were looking for. Die in a car fire.
189 wprintf("HTTP/1.1 501 Method not implemented\n");
190 groupdav_common_headers();
191 wprintf("Content-Type: text/plain\n"
193 "GroupDAV method \"%s\" is not implemented.\n",