5 * \defgroup GroupdavPropfind Handles GroupDAV PROPFIND requests.
7 * A few notes about our XML output:
9 * --> Yes, we are spewing tags directly instead of using an XML library.
10 * If you would like to rewrite this using libxml2, code it up and submit
11 * a patch. Whining will be summarily ignored.
13 * --> XML is deliberately output with no whitespace/newlines between tags.
14 * This makes it difficult to read, but we have discovered clients which
15 * crash when you try to pretty it up.
20 #include "webserver.h"
25 * \brief get all messages of this user
26 * Given an encoded UID, translate that to an unencoded Citadel EUID and
27 * then search for it in the current room. Return a message number or -1
30 * NOTE: this function relies on the Citadel server's brute-force search.
31 * There's got to be a way to optimize this better.
32 * \param uid the user to get the data for...
34 long locate_message_by_uid(char *uid) {
36 char decoded_uid[SIZ];
40 euid_unescapize(decoded_uid, uid);
42 serv_printf("EUID %s", decoded_uid);
43 serv_getln(buf, sizeof buf);
45 retval = extract_long(&buf[4], 0);
52 * \brief List folders containing interesting groupware objects
54 void groupdav_folder_list(void) {
62 http_datestring(datestring, sizeof datestring, now);
65 * Be rude. Completely ignore the XML request and simply send them
66 * everything we know about. Let the client sort it out.
68 wprintf("HTTP/1.1 207 Multi-Status\r\n");
69 groupdav_common_headers();
70 wprintf("Date: %s\r\n", datestring);
71 wprintf("Content-type: text/xml\r\n");
72 wprintf("Content-encoding: identity\r\n");
76 wprintf("<?xml version=\"1.0\" encoding=\"utf-8\"?>"
77 "<D:multistatus xmlns:D=\"DAV:\" xmlns:G=\"http://groupdav.org/\">"
81 serv_getln(buf, sizeof buf);
82 if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
84 extract_token(roomname, buf, 0, '|', sizeof roomname);
85 view = extract_int(buf, 6);
88 * For now, only list rooms that we know a GroupDAV client
89 * might be interested in. In the future we may add
92 if ((view == VIEW_CALENDAR)
93 || (view == VIEW_TASKS)
94 || (view == VIEW_ADDRESSBOOK) ) {
96 wprintf("<D:response>");
99 if (strlen(WC->http_host) > 0) {
101 (is_https ? "https" : "http"),
104 wprintf("/groupdav/");
105 urlescputs(roomname);
106 wprintf("/</D:href>");
108 wprintf("<D:propstat>");
109 wprintf("<D:status>HTTP/1.1 200 OK</D:status>");
111 wprintf("<D:fullname>");
113 wprintf("</D:fullname>");
114 wprintf("<D:resourcetype><D:collection/>");
118 wprintf("<G:vevent-collection />");
121 wprintf("<G:vtodo-collection />");
123 case VIEW_ADDRESSBOOK:
124 wprintf("<G:vcard-collection />");
128 wprintf("</D:resourcetype>");
129 wprintf("</D:prop>");
130 wprintf("</D:propstat>");
131 wprintf("</D:response>");
134 wprintf("</D:multistatus>\n");
142 * \brief Search though a davname
143 * \param dav_pathname The pathname is always going to be /groupdav/room_name/msg_num
145 void groupdav_propfind(char *dav_pathname) {
146 char dav_roomname[256];
149 long dav_msgnum = (-1);
152 char encoded_uid[256];
156 char datestring[256];
160 http_datestring(datestring, sizeof datestring, now);
162 extract_token(dav_roomname, dav_pathname, 2, '/', sizeof dav_roomname);
163 extract_token(dav_uid, dav_pathname, 3, '/', sizeof dav_uid);
166 lprintf(9, "dav_pathname: %s\n", dav_pathname);
167 lprintf(9, "dav_roomname: %s\n", dav_roomname);
168 lprintf(9, " dav_uid: %s\n", dav_uid);
172 * If the room name is blank, the client is requesting a
175 if (strlen(dav_roomname) == 0) {
176 groupdav_folder_list();
180 /* Go to the correct room. */
181 if (strcasecmp(WC->wc_roomname, dav_roomname)) {
182 gotoroom(dav_roomname);
184 if (strcasecmp(WC->wc_roomname, dav_roomname)) {
185 wprintf("HTTP/1.1 404 not found\r\n");
186 groupdav_common_headers();
187 wprintf("Date: %s\r\n", datestring);
189 "Content-Type: text/plain\r\n"
191 "There is no folder called \"%s\" on this server.\r\n",
198 * If dav_uid is non-empty, client is requesting a PROPFIND on
199 * a specific item in the room. This is not valid GroupDAV, but
200 * we try to honor it anyway because some clients are expecting
203 if (strlen(dav_uid) > 0) {
205 dav_msgnum = locate_message_by_uid(dav_uid);
206 if (dav_msgnum < 0) {
207 wprintf("HTTP/1.1 404 not found\r\n");
208 groupdav_common_headers();
210 "Content-Type: text/plain\r\n"
212 "Object \"%s\" was not found in the \"%s\" folder.\r\n",
220 * Be rude. Completely ignore the XML request and simply send them
221 * everything we know about (which is going to simply be the ETag and
222 * nothing else). Let the client-side parser sort it out.
224 wprintf("HTTP/1.1 207 Multi-Status\r\n");
225 groupdav_common_headers();
226 wprintf("Date: %s\r\n", datestring);
227 wprintf("Content-type: text/xml\r\n");
228 wprintf("Content-encoding: identity\r\n");
232 wprintf("<?xml version=\"1.0\" encoding=\"utf-8\"?>"
233 "<D:multistatus xmlns:D=\"DAV:\" xmlns:G=\"http://groupdav.org/\">"
236 wprintf("<D:response>");
239 if (strlen(WC->http_host) > 0) {
241 (is_https ? "https" : "http"),
244 wprintf("/groupdav/");
245 urlescputs(WC->wc_roomname);
246 euid_escapize(encoded_uid, dav_uid);
247 wprintf("/%s", encoded_uid);
248 wprintf("</D:href>");
249 wprintf("<D:propstat>");
250 wprintf("<D:status>HTTP/1.1 200 OK</D:status>");
251 wprintf("<D:prop><D:getetag>\"%ld\"</D:getetag></D:prop>", dav_msgnum);
252 wprintf("</D:propstat>");
254 wprintf("</D:response>\n");
255 wprintf("</D:multistatus>\n");
262 * We got to this point, which means that the client is requesting
263 * a 'collection' (i.e. a list of all items in the room).
265 * Be rude. Completely ignore the XML request and simply send them
266 * everything we know about (which is going to simply be the ETag and
267 * nothing else). Let the client-side parser sort it out.
269 wprintf("HTTP/1.1 207 Multi-Status\r\n");
270 groupdav_common_headers();
271 wprintf("Date: %s\r\n", datestring);
272 wprintf("Content-type: text/xml\r\n");
273 wprintf("Content-encoding: identity\r\n");
277 wprintf("<?xml version=\"1.0\" encoding=\"utf-8\"?>"
278 "<D:multistatus xmlns:D=\"DAV:\" xmlns:G=\"http://groupdav.org/\">"
281 serv_puts("MSGS ALL");
282 serv_getln(buf, sizeof buf);
283 if (buf[0] == '1') while (serv_getln(msgnum, sizeof msgnum), strcmp(msgnum, "000")) {
284 msgs = realloc(msgs, ++num_msgs * sizeof(long));
285 msgs[num_msgs-1] = atol(msgnum);
288 if (num_msgs > 0) for (i=0; i<num_msgs; ++i) {
291 serv_printf("MSG0 %ld|3", msgs[i]);
292 serv_getln(buf, sizeof buf);
293 if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
294 if (!strncasecmp(buf, "exti=", 5)) {
295 strcpy(uid, &buf[5]);
299 if (strlen(uid) > 0) {
300 wprintf("<D:response>");
302 if (strlen(WC->http_host) > 0) {
304 (is_https ? "https" : "http"),
307 wprintf("/groupdav/");
308 urlescputs(WC->wc_roomname);
309 euid_escapize(encoded_uid, uid);
310 wprintf("/%s", encoded_uid);
311 wprintf("</D:href>");
312 wprintf("<D:propstat>");
313 wprintf("<D:status>HTTP/1.1 200 OK</D:status>");
314 wprintf("<D:prop><D:getetag>\"%ld\"</D:getetag></D:prop>", msgs[i]);
315 wprintf("</D:propstat>");
316 wprintf("</D:response>");
320 wprintf("</D:multistatus>\n");