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\n");
71 groupdav_common_headers();
72 wprintf("Content-type: text/xml\n"
74 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
75 "<D:multistatus xmlns:D=\"DAV:\">\n"
80 if (buf[0] == '1') while (serv_gets(buf), strcmp(buf, "000")) {
82 extract(roomname, buf, 0);
83 view = extract_int(buf, 6);
86 * For now, only list rooms that we know a GroupDAV client
87 * might be interested in. In the future we may add
90 if ((view == VIEW_CALENDAR) || (view == VIEW_TASKS) || (view == VIEW_ADDRESSBOOK) ) {
92 wprintf(" <D:response>\n");
95 if (strlen(WC->http_host) > 0) {
97 (is_https ? "https" : "http"),
100 wprintf("/groupdav/");
101 urlescputs(roomname);
102 wprintf("/</D:href>\n");
104 wprintf(" <D:propstat>\n");
105 wprintf(" <D:status>HTTP/1.1 200 OK</D:status>\n");
106 wprintf(" <D:prop>\n");
107 wprintf(" <D:displayname>");
109 wprintf( "</D:displayname>\n");
110 wprintf(" <D:resourcetype><D:collection/>");
114 wprintf(" <G:vevent-collection />\n");
117 wprintf(" <G:vtodo-collection />\n");
119 case VIEW_ADDRESSBOOK:
120 wprintf(" <G:vcard-collection />\n");
124 wprintf( "</D:resourcetype>\n");
125 wprintf(" </D:prop>\n");
126 wprintf(" </D:propstat>\n");
127 wprintf(" </D:response>\n");
130 wprintf("</D:multistatus>\n");
136 * The pathname is always going to be /groupdav/room_name/msg_num
138 void groupdav_propfind(char *dav_pathname) {
139 char dav_roomname[SIZ];
143 char encoded_uid[SIZ];
148 /* First, break off the "/groupdav/" prefix */
149 remove_token(dav_pathname, 0, '/');
150 remove_token(dav_pathname, 0, '/');
152 /* What's left is the room name. Remove trailing slashes. */
153 if (dav_pathname[strlen(dav_pathname)-1] == '/') {
154 dav_pathname[strlen(dav_pathname)-1] = 0;
156 strcpy(dav_roomname, dav_pathname);
160 * If the room name is blank, the client is requesting a
163 if (strlen(dav_roomname) == 0) {
164 groupdav_folder_list();
168 /* Go to the correct room. */
169 if (strcasecmp(WC->wc_roomname, dav_roomname)) {
170 gotoroom(dav_roomname);
172 if (strcasecmp(WC->wc_roomname, dav_roomname)) {
173 wprintf("HTTP/1.1 404 not found\n");
174 groupdav_common_headers();
176 "Content-Type: text/plain\n"
178 "There is no folder called \"%s\" on this server.\n",
185 * Be rude. Completely ignore the XML request and simply send them
186 * everything we know about (which is going to simply be the ETag and
187 * nothing else). Let the client-side parser sort it out.
189 wprintf("HTTP/1.0 207 Multi-Status\n");
190 groupdav_common_headers();
191 wprintf("Content-type: text/xml\n"
193 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
194 "<D:multistatus xmlns:D=\"DAV:\">\n"
197 serv_puts("MSGS ALL");
199 if (buf[0] == '1') while (serv_gets(msgnum), strcmp(msgnum, "000")) {
200 msgs = realloc(msgs, ++num_msgs * sizeof(long));
201 msgs[num_msgs-1] = atol(msgnum);
204 if (num_msgs > 0) for (i=0; i<num_msgs; ++i) {
207 serv_printf("MSG0 %ld|3", msgs[i]);
209 if (buf[0] == '1') while (serv_gets(buf), strcmp(buf, "000")) {
210 if (!strncasecmp(buf, "exti=", 5)) {
211 strcpy(uid, &buf[5]);
215 if (strlen(uid) > 0) {
216 wprintf(" <D:response>\n");
217 wprintf(" <D:href>");
218 if (strlen(WC->http_host) > 0) {
220 (is_https ? "https" : "http"),
223 wprintf("/groupdav/");
224 urlescputs(WC->wc_roomname);
225 euid_escapize(encoded_uid, uid);
226 wprintf("/%s", encoded_uid);
227 wprintf("</D:href>\n");
228 wprintf(" <D:propstat>\n");
229 wprintf(" <D:status>HTTP/1.1 200 OK</D:status>\n");
230 wprintf(" <D:prop><D:getetag>\"%ld\"</D:getetag></D:prop>\n", msgs[i]);
231 wprintf(" </D:propstat>\n");
232 wprintf(" </D:response>\n");
236 wprintf("</D:multistatus>\n");