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")) {
70 * The pathname is always going to be /groupdav/room_name/msg_num
72 void groupdav_propfind(char *dav_pathname) {
73 char dav_roomname[SIZ];
81 /* First, break off the "/groupdav/" prefix */
82 remove_token(dav_pathname, 0, '/');
83 remove_token(dav_pathname, 0, '/');
85 /* What's left is the room name. Remove trailing slashes. */
86 if (dav_pathname[strlen(dav_pathname)-1] == '/') {
87 dav_pathname[strlen(dav_pathname)-1] = 0;
89 strcpy(dav_roomname, dav_pathname);
91 /* Go to the correct room. */
92 if (strcasecmp(WC->wc_roomname, dav_roomname)) {
93 gotoroom(dav_roomname);
95 if (strcasecmp(WC->wc_roomname, dav_roomname)) {
96 wprintf("HTTP/1.1 404 not found\n");
97 groupdav_common_headers();
99 "Content-Type: text/plain\n"
101 "There is no folder called \"%s\" on this server.\n",
108 * Be rude. Completely ignore the XML request and simply send them
109 * everything we know about (which is going to simply be the ETag and
110 * nothing else). Let the client-side parser sort it out.
112 wprintf("HTTP/1.0 207 Multi-Status\n");
113 groupdav_common_headers();
114 wprintf("Content-type: text/xml\n"
116 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
117 "<D:multistatus xmlns:D=\"DAV:\">\n"
120 serv_puts("MSGS ALL");
122 if (buf[0] == '1') while (serv_gets(msgnum), strcmp(msgnum, "000")) {
123 msgs = realloc(msgs, ++num_msgs * sizeof(long));
124 msgs[num_msgs-1] = atol(msgnum);
127 if (num_msgs > 0) for (i=0; i<num_msgs; ++i) {
130 serv_printf("MSG0 %ld|3", msgs[i]);
132 if (buf[0] == '1') while (serv_gets(buf), strcmp(buf, "000")) {
133 if (!strncasecmp(buf, "exti=", 5)) {
134 strcpy(uid, &buf[5]);
138 if (strlen(uid) > 0) {
139 wprintf(" <D:response>\n");
140 wprintf(" <D:href>");
141 if (strlen(WC->http_host) > 0) {
143 (is_https ? "https" : "http"),
146 wprintf("/groupdav/Calendar/");
147 for (j=0; j<strlen(uid); ++j) {
148 wprintf("%02X", uid[j]);
150 wprintf("</D:href>\n");
151 wprintf(" <D:propstat>\n");
152 wprintf(" <D:status>HTTP/1.1 200 OK</D:status>\n");
153 wprintf(" <D:prop><D:getetag>\"%ld\"</D:getetag></D:prop>\n", msgs[i]);
154 wprintf(" </D:propstat>\n");
155 wprintf(" </D:response>\n");
159 wprintf("</D:multistatus>\n");