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.
17 * \ingroup WebcitHttpServerGDav
21 #include "webserver.h"
26 * \brief get all messages of this user
27 * Given an encoded UID, translate that to an unencoded Citadel EUID and
28 * then search for it in the current room. Return a message number or -1
31 * NOTE: this function relies on the Citadel server's brute-force search.
32 * There's got to be a way to optimize this better.
33 * \param uid the user to get the data for...
35 long locate_message_by_uid(char *uid) {
37 char decoded_uid[SIZ];
41 euid_unescapize(decoded_uid, uid);
43 serv_printf("EUID %s", decoded_uid);
44 serv_getln(buf, sizeof buf);
46 retval = extract_long(&buf[4], 0);
53 * \brief List folders containing interesting groupware objects
55 void groupdav_folder_list(void) {
63 http_datestring(datestring, sizeof datestring, now);
66 * Be rude. Completely ignore the XML request and simply send them
67 * everything we know about. Let the client sort it out.
69 wprintf("HTTP/1.1 207 Multi-Status\r\n");
70 groupdav_common_headers();
71 wprintf("Date: %s\r\n", datestring);
72 wprintf("Content-type: text/xml\r\n");
73 wprintf("Content-encoding: identity\r\n");
77 wprintf("<?xml version=\"1.0\" encoding=\"utf-8\"?>"
78 "<D:multistatus xmlns:D=\"DAV:\" xmlns:G=\"http://groupdav.org/\">"
82 serv_getln(buf, sizeof buf);
83 if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
85 extract_token(roomname, buf, 0, '|', sizeof roomname);
86 view = extract_int(buf, 6);
89 * For now, only list rooms that we know a GroupDAV client
90 * might be interested in. In the future we may add
93 if ((view == VIEW_CALENDAR)
94 || (view == VIEW_TASKS)
95 || (view == VIEW_ADDRESSBOOK) ) {
97 wprintf("<D:response>");
100 output_host_prefix();
101 wprintf("/groupdav/");
102 urlescputs(roomname);
103 wprintf("/</D:href>");
105 wprintf("<D:propstat>");
106 wprintf("<D:status>HTTP/1.1 200 OK</D:status>");
108 wprintf("<D:fullname>");
110 wprintf("</D:fullname>");
111 wprintf("<D:resourcetype><D:collection/>");
115 wprintf("<G:vevent-collection />");
118 wprintf("<G:vtodo-collection />");
120 case VIEW_ADDRESSBOOK:
121 wprintf("<G:vcard-collection />");
125 wprintf("</D:resourcetype>");
126 wprintf("</D:prop>");
127 wprintf("</D:propstat>");
128 wprintf("</D:response>");
131 wprintf("</D:multistatus>\n");
139 * \brief Search though a davname
140 * \param dav_pathname The pathname is always going to be /groupdav/room_name/msg_num
142 void groupdav_propfind(char *dav_pathname) {
143 char dav_roomname[256];
146 long dav_msgnum = (-1);
149 char encoded_uid[256];
153 char datestring[256];
157 http_datestring(datestring, sizeof datestring, now);
159 extract_token(dav_roomname, dav_pathname, 2, '/', sizeof dav_roomname);
160 extract_token(dav_uid, dav_pathname, 3, '/', sizeof dav_uid);
163 lprintf(9, "dav_pathname: %s\n", dav_pathname);
164 lprintf(9, "dav_roomname: %s\n", dav_roomname);
165 lprintf(9, " dav_uid: %s\n", dav_uid);
169 * If the room name is blank, the client is requesting a
172 if (strlen(dav_roomname) == 0) {
173 groupdav_folder_list();
177 /* Go to the correct room. */
178 if (strcasecmp(WC->wc_roomname, dav_roomname)) {
179 gotoroom(dav_roomname);
181 if (strcasecmp(WC->wc_roomname, dav_roomname)) {
182 wprintf("HTTP/1.1 404 not found\r\n");
183 groupdav_common_headers();
184 wprintf("Date: %s\r\n", datestring);
186 "Content-Type: text/plain\r\n"
188 "There is no folder called \"%s\" on this server.\r\n",
195 * If dav_uid is non-empty, client is requesting a PROPFIND on
196 * a specific item in the room. This is not valid GroupDAV, but
197 * we try to honor it anyway because some clients are expecting
200 if (strlen(dav_uid) > 0) {
202 dav_msgnum = locate_message_by_uid(dav_uid);
203 if (dav_msgnum < 0) {
204 wprintf("HTTP/1.1 404 not found\r\n");
205 groupdav_common_headers();
207 "Content-Type: text/plain\r\n"
209 "Object \"%s\" was not found in the \"%s\" folder.\r\n",
217 * Be rude. Completely ignore the XML request and simply send them
218 * everything we know about (which is going to simply be the ETag and
219 * nothing else). Let the client-side parser sort it out.
221 wprintf("HTTP/1.1 207 Multi-Status\r\n");
222 groupdav_common_headers();
223 wprintf("Date: %s\r\n", datestring);
224 wprintf("Content-type: text/xml\r\n");
225 wprintf("Content-encoding: identity\r\n");
229 wprintf("<?xml version=\"1.0\" encoding=\"utf-8\"?>"
230 "<D:multistatus xmlns:D=\"DAV:\" xmlns:G=\"http://groupdav.org/\">"
233 wprintf("<D:response>");
236 output_host_prefix();
237 wprintf("/groupdav/");
238 urlescputs(WC->wc_roomname);
239 euid_escapize(encoded_uid, dav_uid);
240 wprintf("/%s", encoded_uid);
241 wprintf("</D:href>");
242 wprintf("<D:propstat>");
243 wprintf("<D:status>HTTP/1.1 200 OK</D:status>");
244 wprintf("<D:prop><D:getetag>\"%ld\"</D:getetag></D:prop>", dav_msgnum);
245 wprintf("</D:propstat>");
247 wprintf("</D:response>\n");
248 wprintf("</D:multistatus>\n");
255 * We got to this point, which means that the client is requesting
256 * a 'collection' (i.e. a list of all items in the room).
258 * Be rude. Completely ignore the XML request and simply send them
259 * everything we know about (which is going to simply be the ETag and
260 * nothing else). Let the client-side parser sort it out.
262 wprintf("HTTP/1.1 207 Multi-Status\r\n");
263 groupdav_common_headers();
264 wprintf("Date: %s\r\n", datestring);
265 wprintf("Content-type: text/xml\r\n");
266 wprintf("Content-encoding: identity\r\n");
270 wprintf("<?xml version=\"1.0\" encoding=\"utf-8\"?>"
271 "<D:multistatus xmlns:D=\"DAV:\" xmlns:G=\"http://groupdav.org/\">"
274 serv_puts("MSGS ALL");
275 serv_getln(buf, sizeof buf);
276 if (buf[0] == '1') while (serv_getln(msgnum, sizeof msgnum), strcmp(msgnum, "000")) {
277 msgs = realloc(msgs, ++num_msgs * sizeof(long));
278 msgs[num_msgs-1] = atol(msgnum);
281 if (num_msgs > 0) for (i=0; i<num_msgs; ++i) {
284 serv_printf("MSG0 %ld|3", msgs[i]);
285 serv_getln(buf, sizeof buf);
286 if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
287 if (!strncasecmp(buf, "exti=", 5)) {
288 strcpy(uid, &buf[5]);
292 if (strlen(uid) > 0) {
293 wprintf("<D:response>");
295 output_host_prefix();
296 wprintf("/groupdav/");
297 urlescputs(WC->wc_roomname);
298 euid_escapize(encoded_uid, uid);
299 wprintf("/%s", encoded_uid);
300 wprintf("</D:href>");
301 wprintf("<D:propstat>");
302 wprintf("<D:status>HTTP/1.1 200 OK</D:status>");
303 wprintf("<D:prop><D:getetag>\"%ld\"</D:getetag></D:prop>", msgs[i]);
304 wprintf("</D:propstat>");
305 wprintf("</D:response>");
309 wprintf("</D:multistatus>\n");