4 * Handles GroupDAV PUT requests.
14 #include <sys/types.h>
16 #include <sys/socket.h>
25 #include "webserver.h"
30 * The pathname is always going to be /groupdav/room_name/euid
32 void groupdav_put(char *dav_pathname, char *dav_ifmatch,
33 char *dav_content_type, char *dav_content
35 char dav_roomname[SIZ];
37 long new_msgnum = (-1L);
38 long old_msgnum = (-1L);
42 /* First, break off the "/groupdav/" prefix */
43 remove_token(dav_pathname, 0, '/');
44 remove_token(dav_pathname, 0, '/');
46 /* Now extract the message euid */
47 n = num_tokens(dav_pathname, '/');
48 extract_token(dav_uid, dav_pathname, n-1, '/');
49 remove_token(dav_pathname, n-1, '/');
51 /* What's left is the room name. Remove trailing slashes. */
52 if (dav_pathname[strlen(dav_pathname)-1] == '/') {
53 dav_pathname[strlen(dav_pathname)-1] = 0;
55 strcpy(dav_roomname, dav_pathname);
57 /* Go to the correct room. */
58 if (strcasecmp(WC->wc_roomname, dav_roomname)) {
59 gotoroom(dav_roomname);
61 if (strcasecmp(WC->wc_roomname, dav_roomname)) {
62 wprintf("HTTP/1.1 404 not found\n");
63 groupdav_common_headers();
65 "Content-Type: text/plain\n"
67 "There is no folder called \"%s\" on this server.\n",
74 * If an HTTP If-Match: header is present, the client is attempting
75 * to replace an existing item. We have to check to see if the
76 * message number associated with the supplied uid matches what the
77 * client is expecting. If not, the server probably contains a newer
78 * version, so we fail...
80 if (strlen(dav_ifmatch) > 0) {
81 old_msgnum = locate_message_by_uid(dav_uid);
82 if (atol(dav_ifmatch) != old_msgnum) {
83 wprintf("HTTP/1.1 412 Precondition Failed\n");
84 groupdav_common_headers();
85 wprintf("Content-Length: 0\n\n");
91 * We are cleared for upload! We use the new calling syntax for ENT0
92 * which allows a confirmation to be sent back to us. That's how we
93 * extract the message ID.
95 serv_puts("ENT0 1|||4|||1|");
98 wprintf("HTTP/1.1 502 Bad Gateway\n");
99 groupdav_common_headers();
100 wprintf("Content-type: text/plain\n"
107 /* Send the content to the Citadel server */
108 serv_printf("Content-type: %s\n\n", dav_content_type);
109 serv_puts(dav_content);
110 serv_puts("\n000\n");
112 /* Fetch the reply from the Citadel server */
115 while (serv_gets(buf), strcmp(buf, "000")) {
118 new_msgnum = atol(buf);
121 strcpy(dav_uid, buf);
127 /* Tell the client what happened. */
129 /* Citadel failed in some way? */
130 if (new_msgnum < 0L) {
131 wprintf("HTTP/1.1 502 Bad Gateway\n");
132 groupdav_common_headers();
133 wprintf("Content-length: 0\n\n");
137 /* We created this item for the first time. */
138 if (old_msgnum < 0L) {
139 wprintf("HTTP/1.1 201 Created\n");
140 groupdav_common_headers();
141 wprintf("Content-Length: 0\n");
142 wprintf("Location: ");
143 if (strlen(WC->http_host) > 0) {
145 (is_https ? "https" : "http"),
148 wprintf("/groupdav/");
149 urlescputs(dav_roomname);
150 wprintf("/%s\n", dav_uid);
155 /* We modified an existing item. */
156 wprintf("HTTP/1.1 204 No Content\n");
157 groupdav_common_headers();
158 wprintf("Content-Length: 0\n\n");
160 /* The item we replaced has probably already been deleted by
161 * the Citadel server, but we'll do this anyway, just in case.
163 serv_printf("DELE %ld", old_msgnum);