]> code.citadel.org Git - citadel.git/blob - webcit/groupdav_propfind.c
* Initial implementation of GroupDAV PROPFIND
[citadel.git] / webcit / groupdav_propfind.c
1 /*
2  * $Id$
3  *
4  * Handles GroupDAV PROPFIND requests.
5  *
6  */
7
8 #include <ctype.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <stdio.h>
12 #include <fcntl.h>
13 #include <signal.h>
14 #include <sys/types.h>
15 #include <sys/wait.h>
16 #include <sys/socket.h>
17 #include <limits.h>
18 #include <string.h>
19 #include <pwd.h>
20 #include <errno.h>
21 #include <stdarg.h>
22 #include <time.h>
23 #include <pthread.h>
24 #include "webcit.h"
25 #include "webserver.h"
26 #include "groupdav.h"
27
28
29 /*
30  * The pathname is always going to be /groupdav/room_name/msg_num
31  */
32 void groupdav_propfind(char *dav_pathname) {
33         char dav_roomname[SIZ];
34         char buf[SIZ];
35
36         /* First, break off the "/groupdav/" prefix */
37         remove_token(dav_pathname, 0, '/');
38         remove_token(dav_pathname, 0, '/');
39
40         /* What's left is the room name.  Remove trailing slashes. */
41         if (dav_pathname[strlen(dav_pathname)-1] == '/') {
42                 dav_pathname[strlen(dav_pathname)-1] = 0;
43         }
44         strcpy(dav_roomname, dav_pathname);
45
46         /* Go to the correct room. */
47         if (strcasecmp(WC->wc_roomname, dav_roomname)) {
48                 gotoroom(dav_roomname);
49         }
50         if (strcasecmp(WC->wc_roomname, dav_roomname)) {
51                 wprintf("HTTP/1.1 404 not found\n");
52                 groupdav_common_headers();
53                 wprintf(
54                         "Content-Type: text/plain\n"
55                         "\n"
56                         "There is no folder called \"%s\" on this server.\n",
57                         dav_roomname
58                 );
59                 return;
60         }
61
62         /*
63          * Be rude.  Completely ignore the XML request and simply send them
64          * everything we know about (which is going to simply be the ETag and
65          * nothing else).  Let the client-side parser sort it out.
66          */
67         wprintf("HTTP/1.0 207 Multi-Status\n");
68         groupdav_common_headers();
69         wprintf("Content-type: text/xml\n"
70                 "\n"
71                 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
72                 "<D:multistatus xmlns:D=\"DAV:\">\n"
73         );
74
75         serv_puts("MSGS ALL");
76         serv_gets(buf);
77         if (buf[0] == '1') while (serv_gets(buf), strcmp(buf, "000")) {
78                 wprintf(" <D:response>\n");
79                 wprintf("  <D:href>%s/groupdav/Calendar/%s</D:href>\n", WC->http_host, buf);
80                 wprintf("   <D:propstat>\n");
81                 wprintf("    <D:status>HTTP/1.1 200 OK</D:status>\n");
82                 wprintf("    <D:prop><D:getetag>\"%s\"</D:getetag></D:prop>\n", buf);
83                 wprintf("   </D:propstat>\n");
84                 wprintf(" </D:response>\n");
85         }
86
87         wprintf("</D:multistatus>\n");
88 }