4 * Handles GroupDAV PUT requests.
14 * This function is for uploading an ENTIRE calendar, not just one
15 * component. This would be for webcal:// 'publish' operations, not
18 void groupdav_put_bigics(char *dav_content, int dav_content_length)
22 serv_puts("ICAL putics");
23 serv_getln(buf, sizeof buf);
25 wprintf("HTTP/1.1 502 Bad Gateway\r\n");
26 groupdav_common_headers();
27 wprintf("Content-type: text/plain\r\n"
34 serv_write(dav_content, dav_content_length);
37 /* Report success and not much else. */
38 wprintf("HTTP/1.1 204 No Content\r\n");
39 lprintf(9, "HTTP/1.1 204 No Content\r\n");
40 groupdav_common_headers();
41 wprintf("Content-Length: 0\r\n\r\n");
47 * The pathname is always going to take one of two formats:
48 * /groupdav/room_name/euid (GroupDAV)
49 * /groupdav/room_name (webcal)
51 void groupdav_put(char *dav_pathname, char *dav_ifmatch,
52 char *dav_content_type, char *dav_content,
53 int dav_content_length
55 char dav_roomname[1024];
57 long new_msgnum = (-2L);
58 long old_msgnum = (-1L);
62 if (num_tokens(dav_pathname, '/') < 3) {
63 wprintf("HTTP/1.1 404 not found\r\n");
64 groupdav_common_headers();
66 "Content-Type: text/plain\r\n"
68 "The object you requested was not found.\r\n"
73 extract_token(dav_roomname, dav_pathname, 2, '/', sizeof dav_roomname);
74 extract_token(dav_uid, dav_pathname, 3, '/', sizeof dav_uid);
76 /* Go to the correct room. */
77 if (strcasecmp(WC->wc_roomname, dav_roomname)) {
78 gotoroom(dav_roomname);
80 if (strcasecmp(WC->wc_roomname, dav_roomname)) {
81 wprintf("HTTP/1.1 404 not found\r\n");
82 groupdav_common_headers();
84 "Content-Type: text/plain\r\n"
86 "There is no folder called \"%s\" on this server.\r\n",
93 * If an HTTP If-Match: header is present, the client is attempting
94 * to replace an existing item. We have to check to see if the
95 * message number associated with the supplied uid matches what the
96 * client is expecting. If not, the server probably contains a newer
97 * version, so we fail...
99 if (strlen(dav_ifmatch) > 0) {
100 lprintf(9, "dav_ifmatch: %s\n", dav_ifmatch);
101 old_msgnum = locate_message_by_uid(dav_uid);
102 lprintf(9, "old_msgnum: %ld\n", old_msgnum);
103 if (atol(dav_ifmatch) != old_msgnum) {
104 wprintf("HTTP/1.1 412 Precondition Failed\r\n");
105 lprintf(9, "HTTP/1.1 412 Precondition Failed (ifmatch=%ld, old_msgnum=%ld)\r\n",
106 atol(dav_ifmatch), old_msgnum);
107 groupdav_common_headers();
108 wprintf("Content-Length: 0\r\n\r\n");
113 /** PUT on the collection itself uploads an ICS of the entire collection.
115 if (!strcasecmp(dav_uid, "")) {
116 groupdav_put_bigics(dav_content, dav_content_length);
121 * We are cleared for upload! We use the new calling syntax for ENT0
122 * which allows a confirmation to be sent back to us. That's how we
123 * extract the message ID.
125 serv_puts("ENT0 1|||4|||1|");
126 serv_getln(buf, sizeof buf);
128 wprintf("HTTP/1.1 502 Bad Gateway\r\n");
129 groupdav_common_headers();
130 wprintf("Content-type: text/plain\r\n"
137 /* Send the content to the Citadel server */
138 serv_printf("Content-type: %s\n\n", dav_content_type);
139 serv_puts(dav_content);
142 /* Fetch the reply from the Citadel server */
145 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
147 case 0: new_msgnum = atol(buf);
149 case 1: lprintf(9, "new_msgnum=%ld (%s)\n", new_msgnum, buf);
151 case 2: strcpy(dav_uid, buf);
158 /* Tell the client what happened. */
160 /* Citadel failed in some way? */
161 if (new_msgnum < 0L) {
162 wprintf("HTTP/1.1 502 Bad Gateway\r\n");
163 groupdav_common_headers();
164 wprintf("Content-type: text/plain\r\n"
166 "new_msgnum is %ld\r\n"
172 /* We created this item for the first time. */
173 if (old_msgnum < 0L) {
174 wprintf("HTTP/1.1 201 Created\r\n");
175 lprintf(9, "HTTP/1.1 201 Created\r\n");
176 groupdav_common_headers();
177 wprintf("etag: \"%ld\"\r\n", new_msgnum);
178 wprintf("Content-Length: 0\r\n");
179 wprintf("Location: ");
180 groupdav_identify_host();
181 wprintf("/groupdav/");
182 urlescputs(dav_roomname);
183 wprintf("/%s\r\n", dav_uid);
188 /* We modified an existing item. */
189 wprintf("HTTP/1.1 204 No Content\r\n");
190 lprintf(9, "HTTP/1.1 204 No Content\r\n");
191 groupdav_common_headers();
192 wprintf("etag: \"%ld\"\r\n", new_msgnum);
193 wprintf("Content-Length: 0\r\n\r\n");
195 /* The item we replaced has probably already been deleted by
196 * the Citadel server, but we'll do this anyway, just in case.
198 serv_printf("DELE %ld", old_msgnum);
199 serv_getln(buf, sizeof buf);