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) {
67 * Be rude. Completely ignore the XML request and simply send them
68 * everything we know about. Let the client sort it out.
70 wprintf("HTTP/1.0 207 Multi-Status\r\n");
71 groupdav_common_headers();
72 wprintf("Content-type: text/xml\r\n");
76 wprintf("<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n"
77 "<D:multistatus xmlns:D=\"DAV:\">\r\n"
82 if (buf[0] == '1') while (serv_gets(buf), strcmp(buf, "000")) {
84 extract(roomname, buf, 0);
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) || (view == VIEW_TASKS) || (view == VIEW_ADDRESSBOOK) ) {
94 wprintf(" <D:response>\r\n");
97 if (strlen(WC->http_host) > 0) {
99 (is_https ? "https" : "http"),
102 wprintf("/groupdav/");
103 urlescputs(roomname);
104 wprintf("/</D:href>\r\n");
106 wprintf(" <D:propstat>\r\n");
107 wprintf(" <D:status>HTTP/1.1 200 OK</D:status>\r\n");
108 wprintf(" <D:prop>\r\n");
109 wprintf(" <D:displayname>");
111 wprintf( "</D:displayname>\r\n");
112 wprintf(" <D:resourcetype><D:collection/>");
116 wprintf(" <G:vevent-collection />\r\n");
119 wprintf(" <G:vtodo-collection />\r\n");
121 case VIEW_ADDRESSBOOK:
122 wprintf(" <G:vcard-collection />\r\n");
126 wprintf( "</D:resourcetype>\r\n");
127 wprintf(" </D:prop>\r\n");
128 wprintf(" </D:propstat>\r\n");
129 wprintf(" </D:response>\r\n");
132 wprintf("</D:multistatus>\r\n\r\n\r\n");
140 * The pathname is always going to be /groupdav/room_name/msg_num
142 void groupdav_propfind(char *dav_pathname) {
143 char dav_roomname[SIZ];
147 char encoded_uid[SIZ];
152 /* First, break off the "/groupdav/" prefix */
153 remove_token(dav_pathname, 0, '/');
154 remove_token(dav_pathname, 0, '/');
156 /* What's left is the room name. Remove trailing slashes. */
157 if (dav_pathname[strlen(dav_pathname)-1] == '/') {
158 dav_pathname[strlen(dav_pathname)-1] = 0;
160 strcpy(dav_roomname, dav_pathname);
164 * If the room name is blank, the client is requesting a
167 if (strlen(dav_roomname) == 0) {
168 groupdav_folder_list();
172 /* Go to the correct room. */
173 if (strcasecmp(WC->wc_roomname, dav_roomname)) {
174 gotoroom(dav_roomname);
176 if (strcasecmp(WC->wc_roomname, dav_roomname)) {
177 wprintf("HTTP/1.1 404 not found\r\n");
178 groupdav_common_headers();
180 "Content-Type: text/plain\r\n"
182 "There is no folder called \"%s\" on this server.\r\n",
189 * Be rude. Completely ignore the XML request and simply send them
190 * everything we know about (which is going to simply be the ETag and
191 * nothing else). Let the client-side parser sort it out.
193 wprintf("HTTP/1.0 207 Multi-Status\r\n");
194 groupdav_common_headers();
195 wprintf("Content-type: text/xml\r\n");
199 wprintf("<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n"
200 "<D:multistatus xmlns:D=\"DAV:\">\r\n"
203 serv_puts("MSGS ALL");
205 if (buf[0] == '1') while (serv_gets(msgnum), strcmp(msgnum, "000")) {
206 msgs = realloc(msgs, ++num_msgs * sizeof(long));
207 msgs[num_msgs-1] = atol(msgnum);
210 if (num_msgs > 0) for (i=0; i<num_msgs; ++i) {
213 serv_printf("MSG0 %ld|3", msgs[i]);
215 if (buf[0] == '1') while (serv_gets(buf), strcmp(buf, "000")) {
216 if (!strncasecmp(buf, "exti=", 5)) {
217 strcpy(uid, &buf[5]);
221 if (strlen(uid) > 0) {
222 wprintf(" <D:response>\r\n");
223 wprintf(" <D:href>");
224 if (strlen(WC->http_host) > 0) {
226 (is_https ? "https" : "http"),
229 wprintf("/groupdav/");
230 urlescputs(WC->wc_roomname);
231 euid_escapize(encoded_uid, uid);
232 wprintf("/%s", encoded_uid);
233 wprintf("</D:href>\r\n");
234 wprintf(" <D:propstat>\r\n");
235 wprintf(" <D:status>HTTP/1.1 200 OK</D:status>\r\n");
236 wprintf(" <D:prop><D:getetag>\"%ld\"</D:getetag></D:prop>\r\n", msgs[i]);
237 wprintf(" </D:propstat>\r\n");
238 wprintf(" </D:response>\r\n");
242 wprintf("</D:multistatus>\r\n\r\n\r\n");