]> code.citadel.org Git - citadel.git/blob - webcit/groupdav_get.c
* Implemented the Groupdav GET method, more or less in its final form
[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
38         extract_token(dav_roomname, dav_pathname, 2, '/');
39         extract_token(dav_msgnum, dav_pathname, 3, '/');
40
41         /* Go to the correct room. */
42         if (strcasecmp(WC->wc_roomname, dav_roomname)) {
43                 gotoroom(dav_roomname);
44         }
45         if (strcasecmp(WC->wc_roomname, dav_roomname)) {
46                 wprintf(
47                         "HTTP/1.1 404 not found\n"
48                         "Connection: close\n"
49                         "Content-Type: text/plain\n"
50                         "\n"
51                         "There is no folder called \"%s\" on this server.\n",
52                         dav_roomname
53                 );
54                 return;
55         }
56
57         serv_printf("MSG2 %s", dav_msgnum);
58         serv_gets(buf);
59         if (buf[0] != '1') {
60                 wprintf(
61                         "HTTP/1.1 404 not found\n"
62                         "Connection: close\n"
63                         "Content-Type: text/plain\n"
64                         "\n"
65                         "Object \"%s\" was not found in the \"%s\" folder.\n",
66                         dav_msgnum,
67                         dav_roomname
68                 );
69                 return;
70         }
71
72         wprintf("HTTP/1.1 200 OK\n");
73         wprintf("ETag: %s\n", dav_msgnum);
74         while (serv_gets(buf), strcmp(buf, "000")) {
75                 if (!strncasecmp(buf, "Content-type: ", 14)) {
76                         found_content_type = 1;
77                 }
78                 if ((strlen(buf) == 0) && (found_content_type == 0)) {
79                         wprintf("Content-type: text/plain\n");
80                 }
81                 wprintf("%s\n", buf);
82         }
83 }