2 * Handles DAV OPTIONS requests (experimental -- not required by GroupDAV)
4 * Copyright (c) 2005-2012 by the citadel.org team
6 * This program is open source software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License, version 3.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
16 #include "webserver.h"
20 * The pathname is always going to be /groupdav/room_name/msg_num
22 void dav_options(void)
27 long dav_msgnum = (-1);
32 http_datestring(datestring, sizeof datestring, now);
34 dav_roomname = NewStrBuf();
35 dav_uid = NewStrBuf();
36 StrBufExtract_token(dav_roomname, WCC->Hdr->HR.ReqLine, 0, '/');
37 StrBufExtract_token(dav_uid, WCC->Hdr->HR.ReqLine, 1, '/');
39 syslog(LOG_DEBUG, "\033[35m%s (logged_in=%d)\033[0m", ChrPtr(WCC->Hdr->HR.ReqLine), WC->logged_in);
41 * If the room name is blank, the client is doing an OPTIONS on the root.
43 if (StrLength(dav_roomname) == 0) {
44 syslog(LOG_DEBUG, "\033[36mOPTIONS requested for root\033[0m");
45 hprintf("HTTP/1.1 200 OK\r\n");
47 hprintf("Date: %s\r\n", datestring);
48 hprintf("DAV: 1\r\n");
49 hprintf("Allow: OPTIONS, PROPFIND\r\n");
53 FreeStrBuf(&dav_roomname);
58 /* Go to the correct room. */
59 if (strcasecmp(ChrPtr(WC->CurRoom.name), ChrPtr(dav_roomname))) {
60 gotoroom(dav_roomname);
63 if (strcasecmp(ChrPtr(WC->CurRoom.name), ChrPtr(dav_roomname))) {
64 syslog(LOG_DEBUG, "\033[36mOPTIONS requested for invalid item\033[0m");
65 hprintf("HTTP/1.1 404 not found\r\n");
67 hprintf("Date: %s\r\n", datestring);
69 "Content-Type: text/plain\r\n");
72 "There is no folder called \"%s\" on this server.\r\n",
76 FreeStrBuf(&dav_roomname);
81 /* If dav_uid is non-empty, client is requesting an OPTIONS on
82 * a specific item in the room.
84 if (StrLength(dav_uid) != 0) {
85 syslog(LOG_DEBUG, "\033[36mOPTIONS requested for specific item\033[0m");
86 dav_msgnum = locate_message_by_uid(ChrPtr(dav_uid));
88 hprintf("HTTP/1.1 404 not found\r\n");
90 hprintf("Content-Type: text/plain\r\n");
93 "Object \"%s\" was not found in the \"%s\" folder.\r\n",
97 FreeStrBuf(&dav_roomname);
102 hprintf("HTTP/1.1 200 OK\r\n");
103 dav_common_headers();
104 hprintf("Date: %s\r\n", datestring);
105 hprintf("DAV: 1\r\n");
106 hprintf("Allow: OPTIONS, PROPFIND, GET, PUT, DELETE\r\n");
110 FreeStrBuf(&dav_roomname);
111 FreeStrBuf(&dav_uid);
115 FreeStrBuf(&dav_roomname);
116 FreeStrBuf(&dav_uid);
119 * We got to this point, which means that the client is requesting
120 * an OPTIONS on the room itself.
122 syslog(LOG_DEBUG, "\033[36mOPTIONS requested for room '%s' (%slogged in)\033[0m",
123 ChrPtr(WC->CurRoom.name),
124 ((WC->logged_in) ? "" : "not ")
126 hprintf("HTTP/1.1 200 OK\r\n");
127 dav_common_headers();
128 hprintf("Date: %s\r\n", datestring);
131 * Offer CalDAV (RFC 4791) if this is a calendar room
133 if ( (WC->CurRoom.view == VIEW_CALENDAR) || (WC->CurRoom.view == VIEW_CALBRIEF) ) {
134 hprintf("DAV: 1, calendar-access\r\n");
135 syslog(LOG_DEBUG, "\033[36mDAV: 1, calendar-access\033[0m");
138 hprintf("DAV: 1\r\n");
139 syslog(LOG_DEBUG, "\033[36mDAV: 1\033[0m");
142 hprintf("Allow: OPTIONS, PROPFIND, GET, PUT, REPORT\r\n");