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;
55 else if (source[i] == ' ') {
56 target[target_length] = '_';
57 target[++target_length] = 0;
59 else if (source[i] == '-') {
60 target[target_length] = '-';
61 target[++target_length] = 0;
64 sprintf(&target[target_length], "$%02X", source[i]);
71 * string conversion function
73 void euid_unescapize(char *target, char *source) {
76 int target_length = 0;
80 for (a = 0; a < strlen(source); ++a) {
81 if (source[a] == '$') {
82 hex[0] = source[a + 1];
83 hex[1] = source[a + 2];
86 sscanf(hex, "%02x", &b);
87 target[target_length] = b;
88 target[++target_length] = 0;
91 else if (source[a] == '_') {
92 target[target_length] = ' ';
93 target[++target_length] = 0;
95 else if (source[a] == '-') {
96 target[target_length] = '-';
97 target[++target_length] = 0;
100 target[target_length] = source[a];
101 target[++target_length] = 0;
110 * Main entry point for GroupDAV requests
112 void groupdav_main(struct httprequest *req,
113 char *dav_content_type,
114 int dav_content_length,
117 struct httprequest *rptr;
118 char dav_method[SIZ];
119 char dav_pathname[SIZ];
120 char dav_ifmatch[SIZ];
122 strcpy(dav_method, "");
123 strcpy(dav_pathname, "");
124 strcpy(dav_ifmatch, "");
126 for (rptr=req; rptr!=NULL; rptr=rptr->next) {
127 /* lprintf(9, "< %s\n", rptr->line); */
128 if (!strncasecmp(rptr->line, "Host: ", 6)) {
129 safestrncpy(WC->http_host, &rptr->line[6],
130 sizeof WC->http_host);
132 if (!strncasecmp(rptr->line, "If-Match: ", 10)) {
133 safestrncpy(dav_ifmatch, &rptr->line[10],
138 if (!WC->logged_in) {
139 wprintf("HTTP/1.1 401 Unauthorized\n");
140 groupdav_common_headers();
141 wprintf("WWW-Authenticate: Basic realm=\"%s\"\n",
142 serv_info.serv_humannode);
143 wprintf("Content-Length: 0\n\n");
147 extract_token(dav_method, req->line, 0, ' ');
148 extract_token(dav_pathname, req->line, 1, ' ');
149 unescape_input(dav_pathname);
152 * If there's an If-Match: header, strip out the quotes if present, and
153 * then if all that's left is an asterisk, make it go away entirely.
155 if (strlen(dav_ifmatch) > 0) {
156 if (dav_ifmatch[0] == '\"') {
157 strcpy(dav_ifmatch, &dav_ifmatch[1]);
158 if (strtok(dav_ifmatch, "\"") != NULL) {
159 strcpy(strtok(dav_ifmatch, "\""), "");
162 if (!strcmp(dav_ifmatch, "*")) {
163 strcpy(dav_ifmatch, "");
168 * The PROPFIND method is basically used to list all objects in a
169 * room, or to list all relevant rooms on the server.
171 if (!strcasecmp(dav_method, "PROPFIND")) {
172 groupdav_propfind(dav_pathname);
177 * The GET method is used for fetching individual items.
179 if (!strcasecmp(dav_method, "GET")) {
180 groupdav_get(dav_pathname);
185 * The PUT method is used to add or modify items.
187 if (!strcasecmp(dav_method, "PUT")) {
188 groupdav_put(dav_pathname, dav_ifmatch,
189 dav_content_type, dav_content);
194 * The DELETE method kills, maims, and destroys.
196 if (!strcasecmp(dav_method, "DELETE")) {
197 groupdav_delete(dav_pathname, dav_ifmatch);
202 * Couldn't find what we were looking for. Die in a car fire.
204 wprintf("HTTP/1.1 501 Method not implemented\n");
205 groupdav_common_headers();
206 wprintf("Content-Type: text/plain\n"
208 "GroupDAV method \"%s\" is not implemented.\n",