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];
46 for (i=0; i<strlen(uid); i=i+2) {
48 sscanf(&uid[i], "%02x", &ch);
54 serv_puts("MSGS ALL|0|1");
57 serv_printf("exti|%s", decoded_uid);
59 while (serv_gets(buf), strcmp(buf, "000")) {
68 * List folders containing interesting groupware objects
70 void groupdav_folder_list(void) {
76 * Be rude. Completely ignore the XML request and simply send them
77 * everything we know about. Let the client sort it out.
79 wprintf("HTTP/1.0 207 Multi-Status\n");
80 groupdav_common_headers();
81 wprintf("Content-type: text/xml\n"
83 "<?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);
93 if ((view == VIEW_CALENDAR) || (view == VIEW_TASKS) || (view == VIEW_ADDRESSBOOK) ) {
95 wprintf(" <D:response>\n");
96 wprintf(" <D:href>http://splorph.xand.com/groupdav/");
97 urlescputs( roomname);
98 wprintf( "/</D:href>\n");
99 wprintf(" <D:propstat>\n");
100 wprintf(" <D:status>HTTP/1.1 200 OK</D:status>\n");
101 wprintf(" <D:prop>\n");
102 wprintf(" <D:displayname>");
103 urlescputs( roomname);
104 wprintf( "</D:displayname>\n");
105 wprintf(" <resourcetype xmlns=\"DAV:\" xmlns:G=\"http://groupdav.org/\">\n");
106 wprintf(" <collection />\n");
109 wprintf(" <G:vevent-collection />\n");
112 wprintf(" <G:vtodo-collection />\n");
114 case VIEW_ADDRESSBOOK:
115 wprintf(" <G:vcard-collection />\n");
118 wprintf(" <resourcetype>\n");
119 wprintf(" </D:prop>\n");
120 wprintf(" </D:propstat>\n");
121 wprintf(" </D:response>\n");
125 wprintf("</D:multistatus>\n");
132 * The pathname is always going to be /groupdav/room_name/msg_num
134 void groupdav_propfind(char *dav_pathname) {
135 char dav_roomname[SIZ];
143 /* First, break off the "/groupdav/" prefix */
144 remove_token(dav_pathname, 0, '/');
145 remove_token(dav_pathname, 0, '/');
147 /* What's left is the room name. Remove trailing slashes. */
148 if (dav_pathname[strlen(dav_pathname)-1] == '/') {
149 dav_pathname[strlen(dav_pathname)-1] = 0;
151 strcpy(dav_roomname, dav_pathname);
155 * If the room name is blank, the client is requesting a
158 if (strlen(dav_roomname) == 0) {
159 groupdav_folder_list();
163 /* Go to the correct room. */
164 if (strcasecmp(WC->wc_roomname, dav_roomname)) {
165 gotoroom(dav_roomname);
167 if (strcasecmp(WC->wc_roomname, dav_roomname)) {
168 wprintf("HTTP/1.1 404 not found\n");
169 groupdav_common_headers();
171 "Content-Type: text/plain\n"
173 "There is no folder called \"%s\" on this server.\n",
180 * Be rude. Completely ignore the XML request and simply send them
181 * everything we know about (which is going to simply be the ETag and
182 * nothing else). Let the client-side parser sort it out.
184 wprintf("HTTP/1.0 207 Multi-Status\n");
185 groupdav_common_headers();
186 wprintf("Content-type: text/xml\n"
188 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
189 "<D:multistatus xmlns:D=\"DAV:\">\n"
192 serv_puts("MSGS ALL");
194 if (buf[0] == '1') while (serv_gets(msgnum), strcmp(msgnum, "000")) {
195 msgs = realloc(msgs, ++num_msgs * sizeof(long));
196 msgs[num_msgs-1] = atol(msgnum);
199 if (num_msgs > 0) for (i=0; i<num_msgs; ++i) {
202 serv_printf("MSG0 %ld|3", msgs[i]);
204 if (buf[0] == '1') while (serv_gets(buf), strcmp(buf, "000")) {
205 if (!strncasecmp(buf, "exti=", 5)) {
206 strcpy(uid, &buf[5]);
210 if (strlen(uid) > 0) {
211 wprintf(" <D:response>\n");
212 wprintf(" <D:href>");
213 if (strlen(WC->http_host) > 0) {
215 (is_https ? "https" : "http"),
218 wprintf("/groupdav/");
219 urlescputs(WC->wc_roomname);
221 for (j=0; j<strlen(uid); ++j) {
222 wprintf("%02X", uid[j]);
224 wprintf("</D:href>\n");
225 wprintf(" <D:propstat>\n");
226 wprintf(" <D:status>HTTP/1.1 200 OK</D:status>\n");
227 wprintf(" <D:prop><D:getetag>\"%ld\"</D:getetag></D:prop>\n", msgs[i]);
228 wprintf(" </D:propstat>\n");
229 wprintf(" </D:response>\n");
233 wprintf("</D:multistatus>\n");