4 * Handles GroupDAV PROPFIND requests.
6 * A few notes about our XML output:
8 * --> Yes, we are spewing tags directly instead of using an XML library.
9 * If you would like to rewrite this using libxml2, code it up and submit
10 * a patch. Whining will be summarily ignored.
12 * --> XML is deliberately output with no whitespace/newlines between tags.
13 * This makes it difficult to read, but we have discovered clients which
14 * crash when you try to pretty it up.
24 #include <sys/types.h>
26 #include <sys/socket.h>
35 #include "webserver.h"
40 * Given an encoded UID, translate that to an unencoded Citadel EUID and
41 * then search for it in the current room. Return a message number or -1
44 * NOTE: this function relies on the Citadel server's brute-force search.
45 * There's got to be a way to optimize this better.
47 long locate_message_by_uid(char *uid) {
49 char decoded_uid[SIZ];
53 euid_unescapize(decoded_uid, uid);
55 serv_puts("MSGS ALL|0|1");
58 serv_printf("exti|%s", decoded_uid);
60 while (serv_gets(buf), strcmp(buf, "000")) {
69 * List folders containing interesting groupware objects
71 void groupdav_folder_list(void) {
79 http_datestring(datestring, sizeof datestring, now);
82 * Be rude. Completely ignore the XML request and simply send them
83 * everything we know about. Let the client sort it out.
85 wprintf("HTTP/1.0 207 Multi-Status\r\n");
86 groupdav_common_headers();
87 wprintf("Date: %s\r\n", datestring);
88 wprintf("Content-type: text/xml\r\n");
89 wprintf("Content-encoding: identity\r\n");
93 wprintf("<?xml version=\"1.0\" encoding=\"utf-8\"?>"
94 "<D:multistatus xmlns:D=\"DAV:\">"
99 if (buf[0] == '1') while (serv_gets(buf), strcmp(buf, "000")) {
101 extract(roomname, buf, 0);
102 view = extract_int(buf, 6);
105 * For now, only list rooms that we know a GroupDAV client
106 * might be interested in. In the future we may add
109 if ((view == VIEW_CALENDAR)
110 || (view == VIEW_TASKS)
111 || (view == VIEW_ADDRESSBOOK) ) {
113 wprintf("<D:response>");
116 if (strlen(WC->http_host) > 0) {
118 (is_https ? "https" : "http"),
121 wprintf("/groupdav/");
122 urlescputs(roomname);
123 wprintf("/</D:href>");
125 wprintf("<D:propstat>");
126 wprintf("<D:status>HTTP/1.1 200 OK</D:status>");
128 wprintf("<D:displayname>");
130 wprintf("</D:displayname>");
131 wprintf("<D:resourcetype><D:collection/>");
135 wprintf("<G:vevent-collection />");
138 wprintf("<G:vtodo-collection />");
140 case VIEW_ADDRESSBOOK:
141 wprintf("<G:vcard-collection />");
145 wprintf("</D:resourcetype>");
146 wprintf("</D:prop>");
147 wprintf("</D:propstat>");
148 wprintf("</D:response>");
151 wprintf("</D:multistatus>\n");
159 * The pathname is always going to be /groupdav/room_name/msg_num
161 void groupdav_propfind(char *dav_pathname) {
162 char dav_roomname[SIZ];
166 char encoded_uid[SIZ];
170 char datestring[SIZ];
174 http_datestring(datestring, sizeof datestring, now);
177 /* First, break off the "/groupdav/" prefix */
178 remove_token(dav_pathname, 0, '/');
179 remove_token(dav_pathname, 0, '/');
181 /* What's left is the room name. Remove trailing slashes. */
182 if (dav_pathname[strlen(dav_pathname)-1] == '/') {
183 dav_pathname[strlen(dav_pathname)-1] = 0;
185 strcpy(dav_roomname, dav_pathname);
189 * If the room name is blank, the client is requesting a
192 if (strlen(dav_roomname) == 0) {
193 groupdav_folder_list();
197 /* Go to the correct room. */
198 if (strcasecmp(WC->wc_roomname, dav_roomname)) {
199 gotoroom(dav_roomname);
201 if (strcasecmp(WC->wc_roomname, dav_roomname)) {
202 wprintf("HTTP/1.1 404 not found\r\n");
203 groupdav_common_headers();
204 wprintf("Date: %s\r\n", datestring);
206 "Content-Type: text/plain\r\n"
208 "There is no folder called \"%s\" on this server.\r\n",
215 * Be rude. Completely ignore the XML request and simply send them
216 * everything we know about (which is going to simply be the ETag and
217 * nothing else). Let the client-side parser sort it out.
219 wprintf("HTTP/1.0 207 Multi-Status\r\n");
220 groupdav_common_headers();
221 wprintf("Date: %s\r\n", datestring);
222 wprintf("Content-type: text/xml\r\n");
223 wprintf("Content-encoding: identity\r\n");
227 wprintf("<?xml version=\"1.0\" encoding=\"utf-8\"?>"
228 "<D:multistatus xmlns:D=\"DAV:\">"
231 serv_puts("MSGS ALL");
233 if (buf[0] == '1') while (serv_gets(msgnum), strcmp(msgnum, "000")) {
234 msgs = realloc(msgs, ++num_msgs * sizeof(long));
235 msgs[num_msgs-1] = atol(msgnum);
238 if (num_msgs > 0) for (i=0; i<num_msgs; ++i) {
241 serv_printf("MSG0 %ld|3", msgs[i]);
243 if (buf[0] == '1') while (serv_gets(buf), strcmp(buf, "000")) {
244 if (!strncasecmp(buf, "exti=", 5)) {
245 strcpy(uid, &buf[5]);
249 if (strlen(uid) > 0) {
250 wprintf("<D:response>");
252 if (strlen(WC->http_host) > 0) {
254 (is_https ? "https" : "http"),
257 wprintf("/groupdav/");
258 urlescputs(WC->wc_roomname);
259 euid_escapize(encoded_uid, uid);
260 wprintf("/%s", encoded_uid);
261 wprintf("</D:href>");
262 wprintf("<D:propstat>");
263 wprintf("<D:status>HTTP/1.1 200 OK</D:status>");
264 wprintf("<D:prop><D:getetag>\"%ld\"</D:getetag></D:prop>", msgs[i]);
265 wprintf("</D:propstat>");
266 wprintf("</D:response>");
270 wprintf("</D:multistatus>\n");