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
42 * Main entry point for GroupDAV requests
44 void groupdav_main(struct httprequest *req) {
46 struct httprequest *rptr;
48 char dav_pathname[SIZ];
49 char dav_ifmatch[SIZ];
51 strcpy(dav_method, "");
52 strcpy(dav_pathname, "");
53 strcpy(dav_ifmatch, "");
55 for (rptr=req; rptr!=NULL; rptr=rptr->next) {
56 lprintf(9, "> %s\n", rptr->line); /* FIXME we can eventually remove this trace */
57 if (!strncasecmp(rptr->line, "Host: ", 6)) {
58 safestrncpy(WC->http_host, &rptr->line[6], sizeof WC->http_host);
60 if (!strncasecmp(rptr->line, "If-Match: ", 10)) {
61 safestrncpy(dav_ifmatch, &rptr->line[10], sizeof dav_ifmatch);
67 wprintf("HTTP/1.1 401 Unauthorized\n");
68 groupdav_common_headers();
69 wprintf("WWW-Authenticate: Basic realm=\"%s\"\n", serv_info.serv_humannode);
70 wprintf("Content-Type: text/plain\n");
72 wprintf("GroupDAV sessions require HTTP authentication.\n");
76 extract_token(dav_method, req->line, 0, ' ');
77 extract_token(dav_pathname, req->line, 1, ' ');
78 unescape_input(dav_pathname);
81 * If there's an If-Match: header, strip out the quotes if present, and
82 * then if all that's left is an asterisk, make it go away entirely.
84 if (strlen(dav_ifmatch) > 0) {
85 if (dav_ifmatch[0] == '\"') {
86 strcpy(dav_ifmatch, &dav_ifmatch[1]);
87 if (strtok(dav_ifmatch, "\"") != NULL) {
88 strcpy(strtok(dav_ifmatch, "\""), "");
91 if (!strcmp(dav_ifmatch, "*")) {
92 strcpy(dav_ifmatch, "");
97 * The PROPFIND method is basically used to list all objects in a room.
99 if (!strcasecmp(dav_method, "PROPFIND")) {
100 groupdav_propfind(dav_pathname);
105 * We like the GET method ... it's nice and simple.
107 if (!strcasecmp(dav_method, "GET")) {
108 groupdav_get(dav_pathname);
113 * The DELETE method kills, maims, and destroys.
115 if (!strcasecmp(dav_method, "DELETE")) {
116 groupdav_delete(dav_pathname, dav_ifmatch);
121 * Couldn't find what we were looking for. Die in a car fire.
123 wprintf("HTTP/1.1 501 Method not implemented\n");
124 groupdav_common_headers();
125 wprintf("Content-Type: text/plain\n"
127 "GroupDAV method \"%s\" is not implemented.\n",