4 * Entry point for GroupDAV functions
12 extern HashList *HandlerHash;
14 HashList *DavNamespaces = NULL;
17 * Output HTTP headers which are common to all requests.
19 * Please observe that we don't use the usual output_headers()
20 * and wDumpContent() functions in the GroupDAV subsystem, so we
21 * do our own header stuff here.
24 void groupdav_common_headers(void) {
27 "Connection: close\r\n",
28 PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software)
35 * string conversion function
37 void euid_escapize(char *target, const char *source) {
39 int target_length = 0;
43 for (i=0; i<len; ++i) {
44 if ( (isalnum(source[i])) || (source[i]=='-') || (source[i]=='_') ) {
45 target[target_length] = source[i];
46 target[++target_length] = 0;
49 sprintf(&target[target_length], "=%02X", (0xFF & source[i]));
56 * string conversion function
58 void euid_unescapize(char *target, const char *source) {
61 int target_length = 0;
66 for (a = 0; a < len; ++a) {
67 if (source[a] == '=') {
68 hex[0] = source[a + 1];
69 hex[1] = source[a + 2];
73 target[target_length] = b;
74 target[++target_length] = 0;
78 target[target_length] = source[a];
79 target[++target_length] = 0;
88 * Main entry point for GroupDAV requests
90 void groupdav_main(void)
95 StrBufUnescape(WCC->Hdr->HR.ReqLine, 0);
97 StrBufStripSlashes(WCC->Hdr->HR.ReqLine, 0);
100 * If there's an If-Match: header, strip out the quotes if present, and
101 * then if all that's left is an asterisk, make it go away entirely.
103 len = StrLength(WCC->Hdr->HR.dav_ifmatch);
105 StrBufTrim(WCC->Hdr->HR.dav_ifmatch);
106 if (ChrPtr(WCC->Hdr->HR.dav_ifmatch)[0] == '\"') {
107 StrBufCutLeft(WCC->Hdr->HR.dav_ifmatch, 1);
109 for (i=0; i<len; ++i) {
110 if (ChrPtr(WCC->Hdr->HR.dav_ifmatch)[i] == '\"') {
111 StrBufCutAt(WCC->Hdr->HR.dav_ifmatch, i, NULL);
112 len = StrLength(WCC->Hdr->HR.dav_ifmatch);
116 if (!strcmp(ChrPtr(WCC->Hdr->HR.dav_ifmatch), "*")) {
117 FlushStrBuf(WCC->Hdr->HR.dav_ifmatch);
121 switch (WCC->Hdr->HR.eReqType)
124 * The OPTIONS method is not required by GroupDAV. This is an
125 * experiment to determine what might be involved in supporting
126 * other variants of DAV in the future.
134 * The PROPFIND method is basically used to list all objects in a
135 * room, or to list all relevant rooms on the server.
142 * The GET method is used for fetching individual items.
149 * The PUT method is used to add or modify items.
156 * The DELETE method kills, maims, and destroys.
164 * Couldn't find what we were looking for. Die in a car fire.
166 hprintf("HTTP/1.1 501 Method not implemented\r\n");
167 groupdav_common_headers();
168 hprintf("Content-Type: text/plain\r\n");
169 wc_printf("GroupDAV method \"%s\" is not implemented.\r\n",
170 ReqStrs[WCC->Hdr->HR.eReqType]);
177 * Output our host prefix for globally absolute URL's.
179 void groupdav_identify_host(void) {
182 if (StrLength(WCC->Hdr->HR.http_host)!=0) {
184 (is_https ? "https" : "http"),
185 ChrPtr(WCC->Hdr->HR.http_host));
190 void tmplput_GROUPDAV_HOSTNAME(StrBuf *Target, WCTemplputParams *TP)
194 if (StrLength(WCC->Hdr->HR.http_host)!=0) {
195 StrBufAppendPrintf(Target,
197 (is_https ? "https" : "http"),
198 ChrPtr(WCC->Hdr->HR.http_host));
203 * Output our host prefix for globally absolute URL's.
205 void groupdav_identify_hosthdr(void) {
208 if (StrLength(WCC->Hdr->HR.http_host)!=0) {
210 (is_https ? "https" : "http"),
211 ChrPtr(WCC->Hdr->HR.http_host));
216 void Header_HandleIfMatch(StrBuf *Line, ParsedHttpHdrs *hdr)
218 hdr->HR.dav_ifmatch = Line;
221 void Header_HandleDepth(StrBuf *Line, ParsedHttpHdrs *hdr)
223 if (!strcasecmp(ChrPtr(Line), "infinity")) {
224 hdr->HR.dav_depth = 32767;
226 else if (strcmp(ChrPtr(Line), "0") == 0) {
227 hdr->HR.dav_depth = 0;
229 else if (strcmp(ChrPtr(Line), "1") == 0) {
230 hdr->HR.dav_depth = 1;
233 int Conditional_DAV_DEPTH(StrBuf *Target, WCTemplputParams *TP)
235 return WC->Hdr->HR.dav_depth == GetTemplateTokenNumber(Target, TP, 2, 0);
239 void RegisterDAVNamespace(const char * UrlString,
241 const char *DisplayName,
244 WebcitRESTDispatchID RID,
249 /* first put it in... */
250 WebcitAddUrlHandler(UrlString, UrlSLen, DisplayName, dslen, F, Flags|PARSE_REST_URL);
251 /* get it out again... */
252 GetHash(HandlerHash, UrlString, UrlSLen, &vHandler);
253 ((WebcitHandler*)vHandler)->RID = RID;
254 /* and keep a copy of it, so we can compare it later */
255 Put(DavNamespaces, UrlString, UrlSLen, vHandler, reference_free_handler);
258 int Conditional_DAV_NS(StrBuf *Target, WCTemplputParams *TP)
265 GetTemplateTokenString(NULL, TP, 2, &NS, &NSLen);
266 GetHash(HandlerHash, NS, NSLen, &vHandler);
267 return WCC->Hdr->HR.Handler == vHandler;
271 int Conditional_DAV_NSCURRENT(StrBuf *Target, WCTemplputParams *TP)
277 return WCC->Hdr->HR.Handler == vHandler;
280 void tmplput_DAV_NAMESPACE(StrBuf *Target, WCTemplputParams *TP)
284 if (TP->Filter.ContextType == CTX_DAVNS) {
286 H = (WebcitHandler*) CTX;
287 StrBufAppendTemplate(Target, TP, H->Name, 0);
289 else if (WCC->Hdr->HR.Handler != NULL) {
290 StrBufAppendTemplate(Target, TP, WCC->Hdr->HR.Handler->Name, 0);
294 int GroupdavDispatchREST(RESTDispatchID WhichAction, int IgnoreFloor)
301 GetHash(WCC->Directory, IKEY(WCC->ThisRoom->nRoomNameParts + 1), &vDir);
302 return locate_message_by_uid(ChrPtr((StrBuf*)vDir)) != -1;
303 /* TODO: remember euid */
315 ServerStartModule_DAV
319 DavNamespaces = NewHash(1, NULL);
324 ServerShutdownModule_DAV
327 DeleteHash(&DavNamespaces);
337 // WebcitAddUrlHandler(HKEY("groupdav"), "", 0, groupdav_main, XHTTP_COMMANDS|COOKIEUNNEEDED|FORCE_SESSIONCLOSE);
338 RegisterDAVNamespace(HKEY("groupdav"), HKEY("GroupDAV"),
339 groupdav_main, GroupdavDispatchREST,
340 XHTTP_COMMANDS|COOKIEUNNEEDED|FORCE_SESSIONCLOSE);
342 RegisterNamespace("DAV:HOSTNAME", 0, 0, tmplput_GROUPDAV_HOSTNAME, NULL, CTX_NONE);
344 RegisterConditional(HKEY("COND:DAV:NS"), 0, Conditional_DAV_NS, CTX_NONE);
346 RegisterIterator("DAV:NS", 0, DavNamespaces, NULL,
347 NULL, NULL, CTX_DAVNS, CTX_NONE, IT_NOFLAG);
350 RegisterConditional(HKEY("COND:DAV:NSCURRENT"), 0, Conditional_DAV_NSCURRENT, CTX_DAVNS);
351 RegisterNamespace("DAV:NAMESPACE", 0, 1, tmplput_DAV_NAMESPACE, NULL, CTX_NONE);
353 RegisterHeaderHandler(HKEY("IF-MATCH"), Header_HandleIfMatch);
354 RegisterHeaderHandler(HKEY("DEPTH"), Header_HandleDepth);
355 RegisterConditional(HKEY("COND:DAV:DEPTH"), 1, Conditional_DAV_DEPTH, CTX_NONE);