5 * \defgroup GroupdavMain Entry point for GroupDAV functions
6 * \ingroup WebcitHttpServerGDav
11 #include "webserver.h"
16 * \brief Output HTTP headers which are common to all requests.
18 * Please observe that we don't use the usual output_headers()
19 * and wDumpContent() functions in the GroupDAV subsystem, so we
20 * do our own header stuff here.
23 void groupdav_common_headers(void) {
26 "Connection: close\r\n",
27 SERVER, serv_info.serv_software
34 * \brief string conversion function
35 * \param target output string
36 * \param source string to process
38 void euid_escapize(char *target, char *source) {
40 int target_length = 0;
43 for (i=0; i<strlen(source); ++i) {
44 if (isalnum(source[i])) {
45 target[target_length] = source[i];
46 target[++target_length] = 0;
48 else if (source[i] == ' ') {
49 target[target_length] = '_';
50 target[++target_length] = 0;
52 else if (source[i] == '-') {
53 target[target_length] = '-';
54 target[++target_length] = 0;
57 sprintf(&target[target_length], "%%%02X", source[i]);
64 * \brief string conversion function
65 * \param target output string
66 * \param source string to process
68 void euid_unescapize(char *target, char *source) {
71 int target_length = 0;
75 for (a = 0; a < strlen(source); ++a) {
76 if (source[a] == '%') {
77 hex[0] = source[a + 1];
78 hex[1] = source[a + 2];
81 sscanf(hex, "%02x", &b);
82 target[target_length] = b;
83 target[++target_length] = 0;
86 else if (source[a] == '_') {
87 target[target_length] = ' ';
88 target[++target_length] = 0;
90 else if (source[a] == '-') {
91 target[target_length] = '-';
92 target[++target_length] = 0;
95 target[target_length] = source[a];
96 target[++target_length] = 0;
105 * \brief Main entry point for GroupDAV requests
106 * \param req Request header
107 * \param dav_content_type the kind of dav elemet to represent??
108 * \param dav_content_length the length of our response
109 * \param dav_content the actual content to give back
111 void groupdav_main(struct httprequest *req,
112 char *dav_content_type,
113 int dav_content_length,
116 struct httprequest *rptr;
117 char dav_method[256];
118 char dav_pathname[256];
119 char dav_ifmatch[256];
124 strcpy(dav_method, "");
125 strcpy(dav_pathname, "");
126 strcpy(dav_ifmatch, "");
128 for (rptr=req; rptr!=NULL; rptr=rptr->next) {
129 /* lprintf(9, "< %s\n", rptr->line); */
132 * We don't appear to need this; it was already done in webcit.c
133 if (!strncasecmp(rptr->line, "Host: ", 6)) {
134 safestrncpy(WC->http_host, &rptr->line[6],
135 sizeof WC->http_host);
139 if (!strncasecmp(rptr->line, "If-Match: ", 10)) {
140 safestrncpy(dav_ifmatch, &rptr->line[10],
145 if (!WC->logged_in) {
146 wprintf("HTTP/1.1 401 Unauthorized\r\n");
147 groupdav_common_headers();
148 wprintf("WWW-Authenticate: Basic realm=\"%s\"\r\n",
149 serv_info.serv_humannode);
150 wprintf("Content-Length: 0\r\n\r\n");
154 extract_token(dav_method, req->line, 0, ' ', sizeof dav_method);
155 extract_token(dav_pathname, req->line, 1, ' ', sizeof dav_pathname);
156 unescape_input(dav_pathname);
159 * If the request does not begin with "/groupdav", prepend it. If
160 * we happen to introduce a double-slash, that's ok; we'll strip it
163 if (strncasecmp(dav_pathname, "/groupdav", 9)) {
164 snprintf(buf, sizeof buf, "/groupdav/%s", dav_pathname);
165 safestrncpy(dav_pathname, buf, sizeof dav_pathname);
168 /** Remove any stray double-slashes in pathname */
169 while (ds=strstr(dav_pathname, "//"), ds != NULL) {
174 * If there's an If-Match: header, strip out the quotes if present, and
175 * then if all that's left is an asterisk, make it go away entirely.
177 if (strlen(dav_ifmatch) > 0) {
178 striplt(dav_ifmatch);
179 if (dav_ifmatch[0] == '\"') {
180 strcpy(dav_ifmatch, &dav_ifmatch[1]);
181 for (i=0; i<strlen(dav_ifmatch); ++i) {
182 if (dav_ifmatch[i] == '\"') {
187 if (!strcmp(dav_ifmatch, "*")) {
188 strcpy(dav_ifmatch, "");
193 * The OPTIONS method is not required by GroupDAV. This is an
194 * experiment to determine what might be involved in supporting
195 * other variants of DAV in the future.
197 if (!strcasecmp(dav_method, "OPTIONS")) {
198 groupdav_options(dav_pathname);
203 * The PROPFIND method is basically used to list all objects in a
204 * room, or to list all relevant rooms on the server.
206 if (!strcasecmp(dav_method, "PROPFIND")) {
207 groupdav_propfind(dav_pathname);
212 * The GET method is used for fetching individual items.
214 if (!strcasecmp(dav_method, "GET")) {
215 groupdav_get(dav_pathname);
220 * The PUT method is used to add or modify items.
222 if (!strcasecmp(dav_method, "PUT")) {
223 groupdav_put(dav_pathname, dav_ifmatch,
224 dav_content_type, dav_content);
229 * The DELETE method kills, maims, and destroys.
231 if (!strcasecmp(dav_method, "DELETE")) {
232 groupdav_delete(dav_pathname, dav_ifmatch);
237 * Couldn't find what we were looking for. Die in a car fire.
239 wprintf("HTTP/1.1 501 Method not implemented\r\n");
240 groupdav_common_headers();
241 wprintf("Content-Type: text/plain\r\n"
243 "GroupDAV method \"%s\" is not implemented.\r\n",