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