]> code.citadel.org Git - citadel.git/blob - webcit/groupdav_get.c
* Encode GroupDAV uid's using more concise string escaping, because the
[citadel.git] / webcit / groupdav_get.c
1 /*
2  * $Id$
3  *
4  * Handles GroupDAV GET 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/euid
31  */
32 void groupdav_get(char *dav_pathname) {
33         char dav_roomname[SIZ];
34         char dav_uid[SIZ];
35         long dav_msgnum = (-1);
36         char buf[SIZ];
37         int found_content_type = 0;
38         int n = 0;
39
40         /* First, break off the "/groupdav/" prefix */
41         remove_token(dav_pathname, 0, '/');
42         remove_token(dav_pathname, 0, '/');
43
44         /* Now extract the message euid */
45         n = num_tokens(dav_pathname, '/');
46         extract_token(dav_uid, dav_pathname, n-1, '/');
47         remove_token(dav_pathname, n-1, '/');
48
49         /* What's left is the room name.  Remove trailing slashes. */
50         if (dav_pathname[strlen(dav_pathname)-1] == '/') {
51                 dav_pathname[strlen(dav_pathname)-1] = 0;
52         }
53         strcpy(dav_roomname, dav_pathname);
54
55         /* Go to the correct room. */
56         if (strcasecmp(WC->wc_roomname, dav_roomname)) {
57                 gotoroom(dav_roomname);
58         }
59         if (strcasecmp(WC->wc_roomname, dav_roomname)) {
60                 wprintf("HTTP/1.1 404 not found\n");
61                 groupdav_common_headers();
62                 wprintf(
63                         "Content-Type: text/plain\n"
64                         "\n"
65                         "There is no folder called \"%s\" on this server.\n",
66                         dav_roomname
67                 );
68                 return;
69         }
70
71         dav_msgnum = locate_message_by_uid(dav_uid);
72         lprintf(9, "* That maps to msgnum %ld\n", dav_msgnum);
73         serv_printf("MSG2 %ld", dav_msgnum);
74         serv_gets(buf);
75         if (buf[0] != '1') {
76                 lprintf(9, "* and it was not found.\n");
77                 wprintf("HTTP/1.1 404 not found\n");
78                 groupdav_common_headers();
79                 wprintf(
80                         "Content-Type: text/plain\n"
81                         "\n"
82                         "Object \"%s\" was not found in the \"%s\" folder.\n",
83                         dav_uid,
84                         dav_roomname
85                 );
86                 return;
87         }
88
89         lprintf(9, "* and it was retrieved successfully.\n");
90         wprintf("HTTP/1.1 200 OK\n");
91         groupdav_common_headers();
92         wprintf("ETag: \"%ld\"\n", dav_msgnum);
93         while (serv_gets(buf), strcmp(buf, "000")) {
94                 if (!strncasecmp(buf, "Content-type: ", 14)) {
95                         found_content_type = 1;
96                 }
97                 if ((strlen(buf) == 0) && (found_content_type == 0)) {
98                         wprintf("Content-type: text/plain\n");
99                 }
100                 wprintf("%s\n", buf);
101         }
102 }