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);
75 if ((!strcasecmp(dav_uid, "ics")) || (!strcasecmp(dav_uid, "calendar.ics"))) {
79 /* Go to the correct room. */
80 if (strcasecmp(WC->wc_roomname, dav_roomname)) {
81 gotoroom(dav_roomname);
83 if (strcasecmp(WC->wc_roomname, dav_roomname)) {
84 wprintf("HTTP/1.1 404 not found\r\n");
85 groupdav_common_headers();
87 "Content-Type: text/plain\r\n"
89 "There is no folder called \"%s\" on this server.\r\n",
96 * If an HTTP If-Match: header is present, the client is attempting
97 * to replace an existing item. We have to check to see if the
98 * message number associated with the supplied uid matches what the
99 * client is expecting. If not, the server probably contains a newer
100 * version, so we fail...
102 if (strlen(dav_ifmatch) > 0) {
103 lprintf(9, "dav_ifmatch: %s\n", dav_ifmatch);
104 old_msgnum = locate_message_by_uid(dav_uid);
105 lprintf(9, "old_msgnum: %ld\n", old_msgnum);
106 if (atol(dav_ifmatch) != old_msgnum) {
107 wprintf("HTTP/1.1 412 Precondition Failed\r\n");
108 lprintf(9, "HTTP/1.1 412 Precondition Failed (ifmatch=%ld, old_msgnum=%ld)\r\n",
109 atol(dav_ifmatch), old_msgnum);
110 groupdav_common_headers();
111 wprintf("Content-Length: 0\r\n\r\n");
116 /** PUT on the collection itself uploads an ICS of the entire collection.
118 if (!strcasecmp(dav_uid, "")) {
119 groupdav_put_bigics(dav_content, dav_content_length);
124 * We are cleared for upload! We use the new calling syntax for ENT0
125 * which allows a confirmation to be sent back to us. That's how we
126 * extract the message ID.
128 serv_puts("ENT0 1|||4|||1|");
129 serv_getln(buf, sizeof buf);
131 wprintf("HTTP/1.1 502 Bad Gateway\r\n");
132 groupdav_common_headers();
133 wprintf("Content-type: text/plain\r\n"
140 /* Send the content to the Citadel server */
141 serv_printf("Content-type: %s\n\n", dav_content_type);
142 serv_puts(dav_content);
145 /* Fetch the reply from the Citadel server */
148 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
150 case 0: new_msgnum = atol(buf);
152 case 1: lprintf(9, "new_msgnum=%ld (%s)\n", new_msgnum, buf);
154 case 2: strcpy(dav_uid, buf);
161 /* Tell the client what happened. */
163 /* Citadel failed in some way? */
164 if (new_msgnum < 0L) {
165 wprintf("HTTP/1.1 502 Bad Gateway\r\n");
166 groupdav_common_headers();
167 wprintf("Content-type: text/plain\r\n"
169 "new_msgnum is %ld\r\n"
175 /* We created this item for the first time. */
176 if (old_msgnum < 0L) {
177 wprintf("HTTP/1.1 201 Created\r\n");
178 lprintf(9, "HTTP/1.1 201 Created\r\n");
179 groupdav_common_headers();
180 wprintf("etag: \"%ld\"\r\n", new_msgnum);
181 wprintf("Content-Length: 0\r\n");
182 wprintf("Location: ");
183 groupdav_identify_host();
184 wprintf("/groupdav/");
185 urlescputs(dav_roomname);
186 wprintf("/%s\r\n", dav_uid);
191 /* We modified an existing item. */
192 wprintf("HTTP/1.1 204 No Content\r\n");
193 lprintf(9, "HTTP/1.1 204 No Content\r\n");
194 groupdav_common_headers();
195 wprintf("etag: \"%ld\"\r\n", new_msgnum);
196 wprintf("Content-Length: 0\r\n\r\n");
198 /* The item we replaced has probably already been deleted by
199 * the Citadel server, but we'll do this anyway, just in case.
201 serv_printf("DELE %ld", old_msgnum);
202 serv_getln(buf, sizeof buf);