* Doxygen groups. Sorted the files into groups. so now we have a nice structure
[citadel.git] / webcit / groupdav_get.c
1 /*
2  * $Id$
3  */
4 /**
5  * \defgraup GroupdavGet Handle GroupDAV GET requests.
6  * \ingroup WebcitHttpServerGDav
7  *
8  */
9 /*@{*/
10 #include "webcit.h"
11 #include "webserver.h"
12 #include "groupdav.h"
13
14
15 /**
16  * \brief The pathname is always going to be /groupdav/room_name/euid
17  * \param dav_pathname the pathname to print
18  */
19 void groupdav_get(char *dav_pathname) {
20         char dav_roomname[SIZ];
21         char dav_uid[SIZ];
22         long dav_msgnum = (-1);
23         char buf[SIZ];
24         int n = 0;
25         int in_body = 0;
26         int found_content_type = 0;
27
28         /** First, break off the "/groupdav/" prefix */
29         remove_token(dav_pathname, 0, '/');
30         remove_token(dav_pathname, 0, '/');
31
32         /** Now extract the message euid */
33         n = num_tokens(dav_pathname, '/');
34         extract_token(dav_uid, dav_pathname, n-1, '/', sizeof dav_uid);
35         remove_token(dav_pathname, n-1, '/');
36
37         /** What's left is the room name.  Remove trailing slashes. */
38         if (dav_pathname[strlen(dav_pathname)-1] == '/') {
39                 dav_pathname[strlen(dav_pathname)-1] = 0;
40         }
41         strcpy(dav_roomname, dav_pathname);
42
43         /** Go to the correct room. */
44         if (strcasecmp(WC->wc_roomname, dav_roomname)) {
45                 gotoroom(dav_roomname);
46         }
47         if (strcasecmp(WC->wc_roomname, dav_roomname)) {
48                 wprintf("HTTP/1.1 404 not found\r\n");
49                 groupdav_common_headers();
50                 wprintf(
51                         "Content-Type: text/plain\r\n"
52                         "\r\n"
53                         "There is no folder called \"%s\" on this server.\r\n",
54                         dav_roomname
55                 );
56                 return;
57         }
58
59         dav_msgnum = locate_message_by_uid(dav_uid);
60         serv_printf("MSG2 %ld", dav_msgnum);
61         serv_getln(buf, sizeof buf);
62         if (buf[0] != '1') {
63                 wprintf("HTTP/1.1 404 not found\r\n");
64                 groupdav_common_headers();
65                 wprintf(
66                         "Content-Type: text/plain\r\n"
67                         "\r\n"
68                         "Object \"%s\" was not found in the \"%s\" folder.\r\n",
69                         dav_uid,
70                         dav_roomname
71                 );
72                 return;
73         }
74
75         wprintf("HTTP/1.1 200 OK\r\n");
76         groupdav_common_headers();
77         wprintf("etag: \"%ld\"\r\n", dav_msgnum);
78         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
79                 if (!strncasecmp(buf, "Date: ", 6)) {
80                         wprintf("%s\r\n", buf);
81                 }
82                 if (!strncasecmp(buf, "Content-type: ", 14)) {
83                         wprintf("%s\r\n", buf);
84                         found_content_type = 1;
85                 }
86                 if ((strlen(buf) == 0) && (in_body == 0)) {
87                         if (!found_content_type) {
88                                 wprintf("Content-type: text/plain\r\n");
89                         }
90                         in_body = 1;
91                 }
92                 if (in_body) {
93                         wprintf("%s\r\n", buf);
94                 }
95         }
96 }
97
98
99 /*@}*/