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 if (strlen(WC->http_host) > 0) {
102 (is_https ? "https" : "http"),
105 wprintf("/groupdav/");
106 urlescputs(roomname);
107 wprintf("/</D:href>");
109 wprintf("<D:propstat>");
110 wprintf("<D:status>HTTP/1.1 200 OK</D:status>");
112 wprintf("<D:fullname>");
114 wprintf("</D:fullname>");
115 wprintf("<D:resourcetype><D:collection/>");
119 wprintf("<G:vevent-collection />");
122 wprintf("<G:vtodo-collection />");
124 case VIEW_ADDRESSBOOK:
125 wprintf("<G:vcard-collection />");
129 wprintf("</D:resourcetype>");
130 wprintf("</D:prop>");
131 wprintf("</D:propstat>");
132 wprintf("</D:response>");
135 wprintf("</D:multistatus>\n");
143 * \brief Search though a davname
144 * \param dav_pathname The pathname is always going to be /groupdav/room_name/msg_num
146 void groupdav_propfind(char *dav_pathname) {
147 char dav_roomname[256];
150 long dav_msgnum = (-1);
153 char encoded_uid[256];
157 char datestring[256];
161 http_datestring(datestring, sizeof datestring, now);
163 extract_token(dav_roomname, dav_pathname, 2, '/', sizeof dav_roomname);
164 extract_token(dav_uid, dav_pathname, 3, '/', sizeof dav_uid);
167 lprintf(9, "dav_pathname: %s\n", dav_pathname);
168 lprintf(9, "dav_roomname: %s\n", dav_roomname);
169 lprintf(9, " dav_uid: %s\n", dav_uid);
173 * If the room name is blank, the client is requesting a
176 if (strlen(dav_roomname) == 0) {
177 groupdav_folder_list();
181 /* Go to the correct room. */
182 if (strcasecmp(WC->wc_roomname, dav_roomname)) {
183 gotoroom(dav_roomname);
185 if (strcasecmp(WC->wc_roomname, dav_roomname)) {
186 wprintf("HTTP/1.1 404 not found\r\n");
187 groupdav_common_headers();
188 wprintf("Date: %s\r\n", datestring);
190 "Content-Type: text/plain\r\n"
192 "There is no folder called \"%s\" on this server.\r\n",
199 * If dav_uid is non-empty, client is requesting a PROPFIND on
200 * a specific item in the room. This is not valid GroupDAV, but
201 * we try to honor it anyway because some clients are expecting
204 if (strlen(dav_uid) > 0) {
206 dav_msgnum = locate_message_by_uid(dav_uid);
207 if (dav_msgnum < 0) {
208 wprintf("HTTP/1.1 404 not found\r\n");
209 groupdav_common_headers();
211 "Content-Type: text/plain\r\n"
213 "Object \"%s\" was not found in the \"%s\" folder.\r\n",
221 * Be rude. Completely ignore the XML request and simply send them
222 * everything we know about (which is going to simply be the ETag and
223 * nothing else). Let the client-side parser sort it out.
225 wprintf("HTTP/1.1 207 Multi-Status\r\n");
226 groupdav_common_headers();
227 wprintf("Date: %s\r\n", datestring);
228 wprintf("Content-type: text/xml\r\n");
229 wprintf("Content-encoding: identity\r\n");
233 wprintf("<?xml version=\"1.0\" encoding=\"utf-8\"?>"
234 "<D:multistatus xmlns:D=\"DAV:\" xmlns:G=\"http://groupdav.org/\">"
237 wprintf("<D:response>");
240 if (strlen(WC->http_host) > 0) {
242 (is_https ? "https" : "http"),
245 wprintf("/groupdav/");
246 urlescputs(WC->wc_roomname);
247 euid_escapize(encoded_uid, dav_uid);
248 wprintf("/%s", encoded_uid);
249 wprintf("</D:href>");
250 wprintf("<D:propstat>");
251 wprintf("<D:status>HTTP/1.1 200 OK</D:status>");
252 wprintf("<D:prop><D:getetag>\"%ld\"</D:getetag></D:prop>", dav_msgnum);
253 wprintf("</D:propstat>");
255 wprintf("</D:response>\n");
256 wprintf("</D:multistatus>\n");
263 * We got to this point, which means that the client is requesting
264 * a 'collection' (i.e. a list of all items in the room).
266 * Be rude. Completely ignore the XML request and simply send them
267 * everything we know about (which is going to simply be the ETag and
268 * nothing else). Let the client-side parser sort it out.
270 wprintf("HTTP/1.1 207 Multi-Status\r\n");
271 groupdav_common_headers();
272 wprintf("Date: %s\r\n", datestring);
273 wprintf("Content-type: text/xml\r\n");
274 wprintf("Content-encoding: identity\r\n");
278 wprintf("<?xml version=\"1.0\" encoding=\"utf-8\"?>"
279 "<D:multistatus xmlns:D=\"DAV:\" xmlns:G=\"http://groupdav.org/\">"
282 serv_puts("MSGS ALL");
283 serv_getln(buf, sizeof buf);
284 if (buf[0] == '1') while (serv_getln(msgnum, sizeof msgnum), strcmp(msgnum, "000")) {
285 msgs = realloc(msgs, ++num_msgs * sizeof(long));
286 msgs[num_msgs-1] = atol(msgnum);
289 if (num_msgs > 0) for (i=0; i<num_msgs; ++i) {
292 serv_printf("MSG0 %ld|3", msgs[i]);
293 serv_getln(buf, sizeof buf);
294 if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
295 if (!strncasecmp(buf, "exti=", 5)) {
296 strcpy(uid, &buf[5]);
300 if (strlen(uid) > 0) {
301 wprintf("<D:response>");
303 if (strlen(WC->http_host) > 0) {
305 (is_https ? "https" : "http"),
308 wprintf("/groupdav/");
309 urlescputs(WC->wc_roomname);
310 euid_escapize(encoded_uid, uid);
311 wprintf("/%s", encoded_uid);
312 wprintf("</D:href>");
313 wprintf("<D:propstat>");
314 wprintf("<D:status>HTTP/1.1 200 OK</D:status>");
315 wprintf("<D:prop><D:getetag>\"%ld\"</D:getetag></D:prop>", msgs[i]);
316 wprintf("</D:propstat>");
317 wprintf("</D:response>");
321 wprintf("</D:multistatus>\n");