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\r\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];
123 strcpy(dav_method, "");
124 strcpy(dav_pathname, "");
125 strcpy(dav_ifmatch, "");
127 for (rptr=req; rptr!=NULL; rptr=rptr->next) {
128 /* lprintf(9, "< %s\n", rptr->line); */
129 if (!strncasecmp(rptr->line, "Host: ", 6)) {
130 safestrncpy(WC->http_host, &rptr->line[6],
131 sizeof WC->http_host);
133 if (!strncasecmp(rptr->line, "If-Match: ", 10)) {
134 safestrncpy(dav_ifmatch, &rptr->line[10],
139 if (!WC->logged_in) {
140 wprintf("HTTP/1.1 401 Unauthorized\r\n");
141 groupdav_common_headers();
142 wprintf("WWW-Authenticate: Basic realm=\"%s\"\r\n",
143 serv_info.serv_humannode);
144 wprintf("Content-Length: 0\r\n\r\n");
148 extract_token(dav_method, req->line, 0, ' ');
149 extract_token(dav_pathname, req->line, 1, ' ');
150 unescape_input(dav_pathname);
153 * If there's an If-Match: header, strip out the quotes if present, and
154 * then if all that's left is an asterisk, make it go away entirely.
156 if (strlen(dav_ifmatch) > 0) {
157 striplt(dav_ifmatch);
158 if (dav_ifmatch[0] == '\"') {
159 strcpy(dav_ifmatch, &dav_ifmatch[1]);
160 for (i=0; i<strlen(dav_ifmatch); ++i) {
161 if (dav_ifmatch[i] == '\"') {
166 if (!strcmp(dav_ifmatch, "*")) {
167 strcpy(dav_ifmatch, "");
172 * The PROPFIND method is basically used to list all objects in a
173 * room, or to list all relevant rooms on the server.
175 if (!strcasecmp(dav_method, "PROPFIND")) {
176 groupdav_propfind(dav_pathname);
181 * The GET method is used for fetching individual items.
183 if (!strcasecmp(dav_method, "GET")) {
184 groupdav_get(dav_pathname);
189 * The PUT method is used to add or modify items.
191 if (!strcasecmp(dav_method, "PUT")) {
192 groupdav_put(dav_pathname, dav_ifmatch,
193 dav_content_type, dav_content);
198 * The DELETE method kills, maims, and destroys.
200 if (!strcasecmp(dav_method, "DELETE")) {
201 groupdav_delete(dav_pathname, dav_ifmatch);
206 * Couldn't find what we were looking for. Die in a car fire.
208 wprintf("HTTP/1.1 501 Method not implemented\r\n");
209 groupdav_common_headers();
210 wprintf("Content-Type: text/plain\r\n"
212 "GroupDAV method \"%s\" is not implemented.\r\n",