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,
45 char *dav_content_type,
46 int dav_content_length,
49 struct httprequest *rptr;
51 char dav_pathname[SIZ];
52 char dav_ifmatch[SIZ];
54 strcpy(dav_method, "");
55 strcpy(dav_pathname, "");
56 strcpy(dav_ifmatch, "");
58 for (rptr=req; rptr!=NULL; rptr=rptr->next) {
59 if (!strncasecmp(rptr->line, "Host: ", 6)) {
60 safestrncpy(WC->http_host, &rptr->line[6],
61 sizeof WC->http_host);
63 if (!strncasecmp(rptr->line, "If-Match: ", 10)) {
64 safestrncpy(dav_ifmatch, &rptr->line[10],
70 wprintf("HTTP/1.1 401 Unauthorized\n");
71 groupdav_common_headers();
72 wprintf("WWW-Authenticate: Basic realm=\"%s\"\n",
73 serv_info.serv_humannode);
74 wprintf("Content-Type: text/plain\n");
76 wprintf("GroupDAV sessions require HTTP authentication.\n");
80 extract_token(dav_method, req->line, 0, ' ');
81 extract_token(dav_pathname, req->line, 1, ' ');
82 unescape_input(dav_pathname);
85 * If there's an If-Match: header, strip out the quotes if present, and
86 * then if all that's left is an asterisk, make it go away entirely.
88 if (strlen(dav_ifmatch) > 0) {
89 if (dav_ifmatch[0] == '\"') {
90 strcpy(dav_ifmatch, &dav_ifmatch[1]);
91 if (strtok(dav_ifmatch, "\"") != NULL) {
92 strcpy(strtok(dav_ifmatch, "\""), "");
95 if (!strcmp(dav_ifmatch, "*")) {
96 strcpy(dav_ifmatch, "");
101 * The PROPFIND method is basically used to list all objects in a
102 * room, or to list all relevant rooms on the server.
104 if (!strcasecmp(dav_method, "PROPFIND")) {
105 groupdav_propfind(dav_pathname);
110 * The GET method is used for fetching individual items.
112 if (!strcasecmp(dav_method, "GET")) {
113 groupdav_get(dav_pathname);
118 * The PUT method is used to add or modify items.
120 if (!strcasecmp(dav_method, "PUT")) {
121 groupdav_put(dav_pathname, dav_ifmatch,
122 dav_content_type, dav_content);
127 * The DELETE method kills, maims, and destroys.
129 if (!strcasecmp(dav_method, "DELETE")) {
130 groupdav_delete(dav_pathname, dav_ifmatch);
135 * Couldn't find what we were looking for. Die in a car fire.
137 wprintf("HTTP/1.1 501 Method not implemented\n");
138 groupdav_common_headers();
139 wprintf("Content-Type: text/plain\n"
141 "GroupDAV method \"%s\" is not implemented.\n",