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(StrBuf *dav_content, int offset)
23 * Tell the server that when we save a calendar event, we
24 * do *not* want the server to generate invitations.
26 serv_puts("ICAL sgi|0");
27 serv_getln(buf, sizeof buf);
29 serv_puts("ICAL putics");
30 serv_getln(buf, sizeof buf);
32 hprintf("HTTP/1.1 502 Bad Gateway\r\n");
33 groupdav_common_headers();
34 hprintf("Content-type: text/plain\r\n");
35 wprintf("%s\r\n", &buf[4]);
40 serv_write(ChrPtr(dav_content) + offset, StrLength(dav_content) - offset);
43 /* Report success and not much else. */
44 hprintf("HTTP/1.1 204 No Content\r\n");
45 lprintf(9, "HTTP/1.1 204 No Content\r\n");
46 groupdav_common_headers();
47 hprintf("Content-Length: 0\r\n");
53 * The pathname is always going to take one of two formats:
54 * /groupdav/room_name/euid (GroupDAV)
55 * /groupdav/room_name (webcal)
57 void groupdav_put(const char *dav_pathname, char *dav_ifmatch,
58 const char *dav_content_type, StrBuf *dav_content,
61 char dav_roomname[1024];
63 long new_msgnum = (-2L);
64 long old_msgnum = (-1L);
68 if (num_tokens(dav_pathname, '/') < 3) {
69 hprintf("HTTP/1.1 404 not found\r\n");
70 groupdav_common_headers();
71 hprintf("Content-Type: text/plain\r\n");
72 wprintf("The object you requested was not found.\r\n");
77 extract_token(dav_roomname, dav_pathname, 2, '/', sizeof dav_roomname);
78 extract_token(dav_uid, dav_pathname, 3, '/', sizeof dav_uid);
79 if ((!strcasecmp(dav_uid, "ics")) || (!strcasecmp(dav_uid, "calendar.ics"))) {
83 /* Go to the correct room. */
84 if (strcasecmp(WC->wc_roomname, dav_roomname)) {
85 gotoroom(dav_roomname);
87 if (strcasecmp(WC->wc_roomname, dav_roomname)) {
88 hprintf("HTTP/1.1 404 not found\r\n");
89 groupdav_common_headers();
90 hprintf("Content-Type: text/plain\r\n");
91 wprintf("There is no folder called \"%s\" on this server.\r\n",
98 * If an HTTP If-Match: header is present, the client is attempting
99 * to replace an existing item. We have to check to see if the
100 * message number associated with the supplied uid matches what the
101 * client is expecting. If not, the server probably contains a newer
102 * version, so we fail...
104 if (!IsEmptyStr(dav_ifmatch)) {
105 lprintf(9, "dav_ifmatch: %s\n", dav_ifmatch);
106 old_msgnum = locate_message_by_uid(dav_uid);
107 lprintf(9, "old_msgnum: %ld\n", old_msgnum);
108 if (atol(dav_ifmatch) != old_msgnum) {
109 hprintf("HTTP/1.1 412 Precondition Failed\r\n");
110 lprintf(9, "HTTP/1.1 412 Precondition Failed (ifmatch=%ld, old_msgnum=%ld)\r\n",
111 atol(dav_ifmatch), old_msgnum);
112 groupdav_common_headers();
113 hprintf("Content-Length: 0\r\n");
119 /** PUT on the collection itself uploads an ICS of the entire collection.
121 if (!strcasecmp(dav_uid, "")) {
122 groupdav_put_bigics(dav_content, offset);
127 * We are cleared for upload! We use the new calling syntax for ENT0
128 * which allows a confirmation to be sent back to us. That's how we
129 * extract the message ID.
131 serv_puts("ENT0 1|||4|||1|");
132 serv_getln(buf, sizeof buf);
134 hprintf("HTTP/1.1 502 Bad Gateway\r\n");
135 groupdav_common_headers();
136 hprintf("Content-type: text/plain\r\n");
138 wprintf("%s\r\n", &buf[4]);
143 /* Send the content to the Citadel server */
144 serv_printf("Content-type: %s\n\n", dav_content_type);
145 serv_puts(ChrPtr(dav_content) + offset);
148 /* Fetch the reply from the Citadel server */
151 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
153 case 0: new_msgnum = atol(buf);
155 case 1: lprintf(9, "new_msgnum=%ld (%s)\n", new_msgnum, buf);
157 case 2: strcpy(dav_uid, buf);
164 /* Tell the client what happened. */
166 /* Citadel failed in some way? */
167 if (new_msgnum < 0L) {
168 hprintf("HTTP/1.1 502 Bad Gateway\r\n");
169 groupdav_common_headers();
170 hprintf("Content-type: text/plain\r\n");
171 wprintf("new_msgnum is %ld\r\n"
177 /* We created this item for the first time. */
178 if (old_msgnum < 0L) {
179 hprintf("HTTP/1.1 201 Created\r\n");
180 lprintf(9, "HTTP/1.1 201 Created\r\n");
181 groupdav_common_headers();
182 hprintf("etag: \"%ld\"\r\n", new_msgnum);
183 hprintf("Location: ");
184 groupdav_identify_host();
185 hprintf("/groupdav/");/////TODO
186 hurlescputs(dav_roomname);
187 char escaped_uid[1024];
188 euid_escapize(escaped_uid, dav_uid);
189 hprintf("/%s\r\n", escaped_uid);
194 /* We modified an existing item. */
195 hprintf("HTTP/1.1 204 No Content\r\n");
196 lprintf(9, "HTTP/1.1 204 No Content\r\n");
197 groupdav_common_headers();
198 hprintf("etag: \"%ld\"\r\n", new_msgnum);
199 hprintf("Content-Length: 0\r\n");
201 /* The item we replaced has probably already been deleted by
202 * the Citadel server, but we'll do this anyway, just in case.
204 serv_printf("DELE %ld", old_msgnum);
205 serv_getln(buf, sizeof buf);