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.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
22 #include "webserver.h"
26 * The pathname is always going to be /groupdav/room_name/msg_num
28 void dav_options(void)
33 long dav_msgnum = (-1);
38 http_datestring(datestring, sizeof datestring, now);
40 dav_roomname = NewStrBuf();
41 dav_uid = NewStrBuf();
42 StrBufExtract_token(dav_roomname, WCC->Hdr->HR.ReqLine, 0, '/');
43 StrBufExtract_token(dav_uid, WCC->Hdr->HR.ReqLine, 1, '/');
45 syslog(LOG_DEBUG, "\033[35m%s (logged_in=%d)\033[0m", ChrPtr(WCC->Hdr->HR.ReqLine), WC->logged_in);
47 * If the room name is blank, the client is doing an OPTIONS on the root.
49 if (StrLength(dav_roomname) == 0) {
50 syslog(LOG_DEBUG, "\033[36mOPTIONS requested for root\033[0m");
51 hprintf("HTTP/1.1 200 OK\r\n");
53 hprintf("Date: %s\r\n", datestring);
54 hprintf("DAV: 1\r\n");
55 hprintf("Allow: OPTIONS, PROPFIND\r\n");
59 FreeStrBuf(&dav_roomname);
64 /* Go to the correct room. */
65 if (strcasecmp(ChrPtr(WC->CurRoom.name), ChrPtr(dav_roomname))) {
66 gotoroom(dav_roomname);
69 if (strcasecmp(ChrPtr(WC->CurRoom.name), ChrPtr(dav_roomname))) {
70 syslog(LOG_DEBUG, "\033[36mOPTIONS requested for invalid item\033[0m");
71 hprintf("HTTP/1.1 404 not found\r\n");
73 hprintf("Date: %s\r\n", datestring);
75 "Content-Type: text/plain\r\n");
78 "There is no folder called \"%s\" on this server.\r\n",
82 FreeStrBuf(&dav_roomname);
87 /* If dav_uid is non-empty, client is requesting an OPTIONS on
88 * a specific item in the room.
90 if (StrLength(dav_uid) != 0) {
91 syslog(LOG_DEBUG, "\033[36mOPTIONS requested for specific item\033[0m");
92 dav_msgnum = locate_message_by_uid(ChrPtr(dav_uid));
94 hprintf("HTTP/1.1 404 not found\r\n");
96 hprintf("Content-Type: text/plain\r\n");
99 "Object \"%s\" was not found in the \"%s\" folder.\r\n",
103 FreeStrBuf(&dav_roomname);
104 FreeStrBuf(&dav_uid);
108 hprintf("HTTP/1.1 200 OK\r\n");
109 dav_common_headers();
110 hprintf("Date: %s\r\n", datestring);
111 hprintf("DAV: 1\r\n");
112 hprintf("Allow: OPTIONS, PROPFIND, GET, PUT, DELETE\r\n");
116 FreeStrBuf(&dav_roomname);
117 FreeStrBuf(&dav_uid);
121 FreeStrBuf(&dav_roomname);
122 FreeStrBuf(&dav_uid);
125 * We got to this point, which means that the client is requesting
126 * an OPTIONS on the room itself.
128 syslog(LOG_DEBUG, "\033[36mOPTIONS requested for room '%s' (%slogged in)\033[0m",
129 ChrPtr(WC->CurRoom.name),
130 ((WC->logged_in) ? "" : "not ")
132 hprintf("HTTP/1.1 200 OK\r\n");
133 dav_common_headers();
134 hprintf("Date: %s\r\n", datestring);
137 * Offer CalDAV (RFC 4791) if this is a calendar room
139 if ( (WC->CurRoom.view == VIEW_CALENDAR) || (WC->CurRoom.view == VIEW_CALBRIEF) ) {
140 hprintf("DAV: 1, calendar-access\r\n");
141 syslog(LOG_DEBUG, "\033[36mDAV: 1, calendar-access\033[0m");
144 hprintf("DAV: 1\r\n");
145 syslog(LOG_DEBUG, "\033[36mDAV: 1\033[0m");
148 hprintf("Allow: OPTIONS, PROPFIND, GET, PUT, REPORT\r\n");