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(void)
24 * Tell the server that when we save a calendar event, we
25 * do *not* want the server to generate invitations.
27 serv_puts("ICAL sgi|0");
28 serv_getln(buf, sizeof buf);
30 serv_puts("ICAL putics");
31 serv_getln(buf, sizeof buf);
33 hprintf("HTTP/1.1 502 Bad Gateway\r\n");
34 groupdav_common_headers();
35 hprintf("Content-type: text/plain\r\n");
37 wc_printf("%s\r\n", &buf[4]);
42 serv_putbuf(WCC->upload);
45 /* Report success and not much else. */
46 hprintf("HTTP/1.1 204 No Content\r\n");
47 lprintf(9, "HTTP/1.1 204 No Content\r\n");
48 groupdav_common_headers();
56 * The pathname is always going to take one of two formats:
57 * [/groupdav/]room_name/euid (GroupDAV)
58 * [/groupdav/]room_name (webcal)
60 void groupdav_put(void)
65 long new_msgnum = (-2L);
66 long old_msgnum = (-1L);
70 if (StrBufNum_tokens(WCC->Hdr->HR.ReqLine, '/') < 2) {
71 hprintf("HTTP/1.1 404 not found\r\n");
72 groupdav_common_headers();
73 hprintf("Content-Type: text/plain\r\n");
75 wc_printf("The object you requested was not found.\r\n");
80 dav_roomname = NewStrBuf();;
81 dav_uid = NewStrBuf();;
82 StrBufExtract_token(dav_roomname, WCC->Hdr->HR.ReqLine, 0, '/');
83 StrBufExtract_token(dav_uid, WCC->Hdr->HR.ReqLine, 1, '/');
84 if ((!strcasecmp(ChrPtr(dav_uid), "ics")) ||
85 (!strcasecmp(ChrPtr(dav_uid), "calendar.ics"))) {
89 /* Go to the correct room. */
90 if (strcasecmp(ChrPtr(WC->wc_roomname), ChrPtr(dav_roomname))) {
91 gotoroom(dav_roomname);
93 if (strcasecmp(ChrPtr(WC->wc_roomname), ChrPtr(dav_roomname))) {
94 hprintf("HTTP/1.1 404 not found\r\n");
95 groupdav_common_headers();
96 hprintf("Content-Type: text/plain\r\n");
98 wc_printf("There is no folder called \"%s\" on this server.\r\n",
99 ChrPtr(dav_roomname));
101 FreeStrBuf(&dav_roomname);
102 FreeStrBuf(&dav_uid);
107 * If an HTTP If-Match: header is present, the client is attempting
108 * to replace an existing item. We have to check to see if the
109 * message number associated with the supplied uid matches what the
110 * client is expecting. If not, the server probably contains a newer
111 * version, so we fail...
113 if (StrLength(WCC->Hdr->HR.dav_ifmatch) > 0) {
114 lprintf(9, "dav_ifmatch: %s\n", WCC->Hdr->HR.dav_ifmatch);
115 old_msgnum = locate_message_by_uid(ChrPtr(dav_uid));
116 lprintf(9, "old_msgnum: %ld\n", old_msgnum);
117 if (StrTol(WCC->Hdr->HR.dav_ifmatch) != old_msgnum) {
118 hprintf("HTTP/1.1 412 Precondition Failed\r\n");
119 lprintf(9, "HTTP/1.1 412 Precondition Failed (ifmatch=%ld, old_msgnum=%ld)\r\n",
120 StrTol(WCC->Hdr->HR.dav_ifmatch), old_msgnum);
121 groupdav_common_headers();
124 FreeStrBuf(&dav_roomname);
125 FreeStrBuf(&dav_uid);
130 /** PUT on the collection itself uploads an ICS of the entire collection.
132 if (StrLength(dav_uid) == 0) {
133 groupdav_put_bigics();
134 FreeStrBuf(&dav_roomname);
135 FreeStrBuf(&dav_uid);
140 * We are cleared for upload! We use the new calling syntax for ENT0
141 * which allows a confirmation to be sent back to us. That's how we
142 * extract the message ID.
144 serv_puts("ENT0 1|||4|||1|");
145 serv_getln(buf, sizeof buf);
147 hprintf("HTTP/1.1 502 Bad Gateway\r\n");
148 groupdav_common_headers();
149 hprintf("Content-type: text/plain\r\n");
151 wc_printf("%s\r\n", &buf[4]);
156 /* Send the content to the Citadel server */
157 //serv_printf("Content-type: %s\n\n", WCC->upload_content_type);
158 serv_putbuf(WCC->upload);
161 /* Fetch the reply from the Citadel server */
163 FlushStrBuf(dav_uid);
164 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
167 new_msgnum = atol(buf);
170 lprintf(9, "new_msgnum=%ld (%s)\n", new_msgnum, buf);
173 StrBufAppendBufPlain(dav_uid, buf, -1, 0);
180 /* Tell the client what happened. */
182 /* Citadel failed in some way? */
183 if (new_msgnum < 0L) {
184 hprintf("HTTP/1.1 502 Bad Gateway\r\n");
185 groupdav_common_headers();
186 hprintf("Content-type: text/plain\r\n");
188 wc_printf("new_msgnum is %ld\r\n"
191 FreeStrBuf(&dav_roomname);
192 FreeStrBuf(&dav_uid);
196 /* We created this item for the first time. */
197 if (old_msgnum < 0L) {
198 char escaped_uid[1024];
199 hprintf("HTTP/1.1 201 Created\r\n");
200 lprintf(9, "HTTP/1.1 201 Created\r\n");
201 groupdav_common_headers();
202 hprintf("etag: \"%ld\"\r\n", new_msgnum);
203 hprintf("Location: ");
204 groupdav_identify_hosthdr();
205 hprintf("/groupdav/");/* TODO */
206 hurlescputs(ChrPtr(dav_roomname));
207 euid_escapize(escaped_uid, ChrPtr(dav_uid));
208 hprintf("/%s\r\n", escaped_uid);
210 FreeStrBuf(&dav_roomname);
211 FreeStrBuf(&dav_uid);
215 /* We modified an existing item. */
216 hprintf("HTTP/1.1 204 No Content\r\n");
217 lprintf(9, "HTTP/1.1 204 No Content\r\n");
218 groupdav_common_headers();
219 hprintf("Etag: \"%ld\"\r\n", new_msgnum);
220 /* The item we replaced has probably already been deleted by
221 * the Citadel server, but we'll do this anyway, just in case.
223 serv_printf("DELE %ld", old_msgnum);
224 serv_getln(buf, sizeof buf);
227 FreeStrBuf(&dav_roomname);
228 FreeStrBuf(&dav_uid);