5 * \defgroup GroupdavMain Entry point for GroupDAV functions
10 #include "webserver.h"
15 * \brief Output HTTP headers which are common to all requests.
17 * Please observe that we don't use the usual output_headers()
18 * and wDumpContent() functions in the GroupDAV subsystem, so we
19 * do our own header stuff here.
22 void groupdav_common_headers(void) {
25 "Connection: close\r\n",
26 SERVER, serv_info.serv_software
33 * \brief string conversion function
34 * \param target output string
35 * \param source string to process
37 void euid_escapize(char *target, char *source) {
39 int target_length = 0;
42 for (i=0; i<strlen(source); ++i) {
43 if (isalnum(source[i])) {
44 target[target_length] = source[i];
45 target[++target_length] = 0;
47 else if (source[i] == ' ') {
48 target[target_length] = '_';
49 target[++target_length] = 0;
51 else if (source[i] == '-') {
52 target[target_length] = '-';
53 target[++target_length] = 0;
56 sprintf(&target[target_length], "%%%02X", source[i]);
63 * \brief string conversion function
64 * \param target output string
65 * \param source string to process
67 void euid_unescapize(char *target, char *source) {
70 int target_length = 0;
74 for (a = 0; a < strlen(source); ++a) {
75 if (source[a] == '%') {
76 hex[0] = source[a + 1];
77 hex[1] = source[a + 2];
80 sscanf(hex, "%02x", &b);
81 target[target_length] = b;
82 target[++target_length] = 0;
85 else if (source[a] == '_') {
86 target[target_length] = ' ';
87 target[++target_length] = 0;
89 else if (source[a] == '-') {
90 target[target_length] = '-';
91 target[++target_length] = 0;
94 target[target_length] = source[a];
95 target[++target_length] = 0;
104 * \brief Main entry point for GroupDAV requests
105 * \param req Request header
106 * \param dav_content_type the kind of dav elemet to represent??
107 * \param dav_content_length the length of our response
108 * \param dav_content the actual content to give back
110 void groupdav_main(struct httprequest *req,
111 char *dav_content_type,
112 int dav_content_length,
115 struct httprequest *rptr;
116 char dav_method[256];
117 char dav_pathname[256];
118 char dav_ifmatch[256];
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, ' ', sizeof dav_method);
149 extract_token(dav_pathname, req->line, 1, ' ', sizeof dav_pathname);
150 unescape_input(dav_pathname);
153 * If the request does not begin with "/groupdav", prepend it. If
154 * we happen to introduce a double-slash, that's ok; we'll strip it
157 if (strncasecmp(dav_pathname, "/groupdav", 9)) {
158 snprintf(buf, sizeof buf, "/groupdav/%s", dav_pathname);
159 safestrncpy(dav_pathname, buf, sizeof dav_pathname);
162 /** Remove any stray double-slashes in pathname */
163 while (ds=strstr(dav_pathname, "//"), ds != NULL) {
168 * If there's an If-Match: header, strip out the quotes if present, and
169 * then if all that's left is an asterisk, make it go away entirely.
171 if (strlen(dav_ifmatch) > 0) {
172 striplt(dav_ifmatch);
173 if (dav_ifmatch[0] == '\"') {
174 strcpy(dav_ifmatch, &dav_ifmatch[1]);
175 for (i=0; i<strlen(dav_ifmatch); ++i) {
176 if (dav_ifmatch[i] == '\"') {
181 if (!strcmp(dav_ifmatch, "*")) {
182 strcpy(dav_ifmatch, "");
187 * The OPTIONS method is not required by GroupDAV. This is an
188 * experiment to determine what might be involved in supporting
189 * other variants of DAV in the future.
191 if (!strcasecmp(dav_method, "OPTIONS")) {
192 groupdav_options(dav_pathname);
197 * The PROPFIND method is basically used to list all objects in a
198 * room, or to list all relevant rooms on the server.
200 if (!strcasecmp(dav_method, "PROPFIND")) {
201 groupdav_propfind(dav_pathname);
206 * The GET method is used for fetching individual items.
208 if (!strcasecmp(dav_method, "GET")) {
209 groupdav_get(dav_pathname);
214 * The PUT method is used to add or modify items.
216 if (!strcasecmp(dav_method, "PUT")) {
217 groupdav_put(dav_pathname, dav_ifmatch,
218 dav_content_type, dav_content);
223 * The DELETE method kills, maims, and destroys.
225 if (!strcasecmp(dav_method, "DELETE")) {
226 groupdav_delete(dav_pathname, dav_ifmatch);
231 * Couldn't find what we were looking for. Die in a car fire.
233 wprintf("HTTP/1.1 501 Method not implemented\r\n");
234 groupdav_common_headers();
235 wprintf("Content-Type: text/plain\r\n"
237 "GroupDAV method \"%s\" is not implemented.\r\n",