4 * Handles GroupDAV PROPFIND requests.
14 #include <sys/types.h>
16 #include <sys/socket.h>
25 #include "webserver.h"
30 * Given an encoded UID, translate that to an unencoded Citadel EUID and
31 * then search for it in the current room. Return a message number or -1
34 * NOTE: this function relies on the Citadel server's brute-force search.
35 * There's got to be a way to optimize this better.
37 long locate_message_by_uid(char *uid) {
39 char decoded_uid[SIZ];
43 euid_unescapize(decoded_uid, uid);
45 serv_puts("MSGS ALL|0|1");
48 serv_printf("exti|%s", decoded_uid);
50 while (serv_gets(buf), strcmp(buf, "000")) {
59 * List folders containing interesting groupware objects
61 void groupdav_folder_list(void) {
69 http_datestring(datestring, sizeof datestring, now);
72 * Be rude. Completely ignore the XML request and simply send them
73 * everything we know about. Let the client sort it out.
75 wprintf("HTTP/1.0 207 Multi-Status\r\n");
76 groupdav_common_headers();
77 wprintf("Date: %s\r\n", datestring);
78 wprintf("Content-type: text/xml\r\n");
79 wprintf("Content-encoding: identity\r\n");
83 wprintf("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
84 "<D:multistatus xmlns:D=\"DAV:\">\n"
89 if (buf[0] == '1') while (serv_gets(buf), strcmp(buf, "000")) {
91 extract(roomname, buf, 0);
92 view = extract_int(buf, 6);
95 * For now, only list rooms that we know a GroupDAV client
96 * might be interested in. In the future we may add
99 if ((view == VIEW_CALENDAR) || (view == VIEW_TASKS) || (view == VIEW_ADDRESSBOOK) ) {
101 wprintf(" <D:response>\n");
103 wprintf(" <D:href>");
104 if (strlen(WC->http_host) > 0) {
106 (is_https ? "https" : "http"),
109 wprintf("/groupdav/");
110 urlescputs(roomname);
111 wprintf("/</D:href>\n");
113 wprintf(" <D:propstat>\n");
114 wprintf(" <D:status>HTTP/1.1 200 OK</D:status>\n");
115 wprintf(" <D:prop>\n");
116 wprintf(" <D:displayname>");
118 wprintf( "</D:displayname>\n");
119 wprintf(" <D:resourcetype><D:collection/>");
123 wprintf(" <G:vevent-collection />\n");
126 wprintf(" <G:vtodo-collection />\n");
128 case VIEW_ADDRESSBOOK:
129 wprintf(" <G:vcard-collection />\n");
133 wprintf( "</D:resourcetype>\n");
134 wprintf(" </D:prop>\n");
135 wprintf(" </D:propstat>\n");
136 wprintf(" </D:response>\n");
139 wprintf("</D:multistatus>\n\n\n");
147 * The pathname is always going to be /groupdav/room_name/msg_num
149 void groupdav_propfind(char *dav_pathname) {
150 char dav_roomname[SIZ];
154 char encoded_uid[SIZ];
158 char datestring[SIZ];
162 http_datestring(datestring, sizeof datestring, now);
165 /* First, break off the "/groupdav/" prefix */
166 remove_token(dav_pathname, 0, '/');
167 remove_token(dav_pathname, 0, '/');
169 /* What's left is the room name. Remove trailing slashes. */
170 if (dav_pathname[strlen(dav_pathname)-1] == '/') {
171 dav_pathname[strlen(dav_pathname)-1] = 0;
173 strcpy(dav_roomname, dav_pathname);
177 * If the room name is blank, the client is requesting a
180 if (strlen(dav_roomname) == 0) {
181 groupdav_folder_list();
185 /* Go to the correct room. */
186 if (strcasecmp(WC->wc_roomname, dav_roomname)) {
187 gotoroom(dav_roomname);
189 if (strcasecmp(WC->wc_roomname, dav_roomname)) {
190 wprintf("HTTP/1.1 404 not found\r\n");
191 groupdav_common_headers();
192 wprintf("Date: %s\r\n", datestring);
194 "Content-Type: text/plain\r\n"
196 "There is no folder called \"%s\" on this server.\r\n",
203 * Be rude. Completely ignore the XML request and simply send them
204 * everything we know about (which is going to simply be the ETag and
205 * nothing else). Let the client-side parser sort it out.
207 wprintf("HTTP/1.0 207 Multi-Status\r\n");
208 groupdav_common_headers();
209 wprintf("Date: %s\r\n", datestring);
210 wprintf("Content-type: text/xml\r\n");
211 wprintf("Content-encoding: identity\r\n");
215 wprintf("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
216 "<D:multistatus xmlns:D=\"DAV:\">\n"
219 serv_puts("MSGS ALL");
221 if (buf[0] == '1') while (serv_gets(msgnum), strcmp(msgnum, "000")) {
222 msgs = realloc(msgs, ++num_msgs * sizeof(long));
223 msgs[num_msgs-1] = atol(msgnum);
226 if (num_msgs > 0) for (i=0; i<num_msgs; ++i) {
229 serv_printf("MSG0 %ld|3", msgs[i]);
231 if (buf[0] == '1') while (serv_gets(buf), strcmp(buf, "000")) {
232 if (!strncasecmp(buf, "exti=", 5)) {
233 strcpy(uid, &buf[5]);
237 if (strlen(uid) > 0) {
238 wprintf(" <D:response>\n");
239 wprintf(" <D:href>");
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, uid);
248 wprintf("/%s", encoded_uid);
249 wprintf("</D:href>\n");
250 wprintf(" <D:propstat>\n");
251 wprintf(" <D:status>HTTP/1.1 200 OK</D:status>\n");
252 wprintf(" <D:prop><D:getetag>\"%ld\"</D:getetag></D:prop>\n", msgs[i]);
253 wprintf(" </D:propstat>\n");
254 wprintf(" </D:response>\n");
258 wprintf("</D:multistatus>\n\n\n");