3 * Handles DAV OPTIONS requests (experimental -- not required by GroupDAV)
5 * Copyright (c) 2005-2012 by the citadel.org team
7 * This program is open source software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License, version 3.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
17 #include "webserver.h"
21 * The pathname is always going to be /groupdav/room_name/msg_num
23 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);
68 hprintf("Content-Type: text/plain\r\n");
70 wc_printf("There is no folder called \"%s\" on this server.\r\n", ChrPtr(dav_roomname)
73 FreeStrBuf(&dav_roomname);
78 /* If dav_uid is non-empty, client is requesting an OPTIONS on
79 * a specific item in the room.
81 if (StrLength(dav_uid) != 0) {
82 syslog(LOG_DEBUG, "\033[36mOPTIONS requested for specific item\033[0m");
83 dav_msgnum = locate_message_by_uid(ChrPtr(dav_uid));
85 hprintf("HTTP/1.1 404 not found\r\n");
87 hprintf("Content-Type: text/plain\r\n");
89 wc_printf("Object \"%s\" was not found in the \"%s\" folder.\r\n", ChrPtr(dav_uid), ChrPtr(dav_roomname)
91 FreeStrBuf(&dav_roomname);
97 hprintf("HTTP/1.1 200 OK\r\n");
99 hprintf("Date: %s\r\n", datestring);
100 hprintf("DAV: 1\r\n");
101 hprintf("Allow: OPTIONS, PROPFIND, GET, PUT, DELETE\r\n");
105 FreeStrBuf(&dav_roomname);
106 FreeStrBuf(&dav_uid);
110 FreeStrBuf(&dav_roomname);
111 FreeStrBuf(&dav_uid);
114 * We got to this point, which means that the client is requesting
115 * an OPTIONS on the room itself.
117 syslog(LOG_DEBUG, "\033[36mOPTIONS requested for room '%s' (%slogged in)\033[0m",
118 ChrPtr(WC->CurRoom.name), ((WC->logged_in) ? "" : "not ")
120 hprintf("HTTP/1.1 200 OK\r\n");
121 dav_common_headers();
122 hprintf("Date: %s\r\n", datestring);
125 * Offer CalDAV (RFC 4791) if this is a calendar room
127 if ((WC->CurRoom.view == VIEW_CALENDAR) || (WC->CurRoom.view == VIEW_CALBRIEF)) {
128 hprintf("DAV: 1, calendar-access\r\n");
129 syslog(LOG_DEBUG, "\033[36mDAV: 1, calendar-access\033[0m");
132 hprintf("DAV: 1\r\n");
133 syslog(LOG_DEBUG, "\033[36mDAV: 1\033[0m");
136 hprintf("Allow: OPTIONS, PROPFIND, GET, PUT, REPORT\r\n");