X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fgroupdav_put.c;h=4e924f2aaba776bbc7d292b6d6ecfbc188bb0e99;hb=a3ba94ad306d781296c53012f732f3a910015263;hp=a6ba5ef59ffc64d81e392f73a5d3c54de30bb4f6;hpb=a1ee5a623e30d049419be72cb501e96d4dafd4de;p=citadel.git diff --git a/webcit/groupdav_put.c b/webcit/groupdav_put.c index a6ba5ef59..4e924f2aa 100644 --- a/webcit/groupdav_put.c +++ b/webcit/groupdav_put.c @@ -5,68 +5,101 @@ * */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include "webcit.h" #include "webserver.h" #include "groupdav.h" /* - * The pathname is always going to be /groupdav/room_name/euid + * This function is for uploading an ENTIRE calendar, not just one + * component. This would be for webcal:// 'publish' operations, not + * for GroupDAV. */ -void groupdav_put(char *dav_pathname, char *dav_ifmatch, - char *dav_content_type, char *dav_content -) { - char dav_roomname[SIZ]; - char dav_uid[SIZ]; +void groupdav_put_bigics(void) +{ + wcsession *WCC = WC; + char buf[1024]; + + /* + * Tell the server that when we save a calendar event, we + * do *not* want the server to generate invitations. + */ + serv_puts("ICAL sgi|0"); + serv_getln(buf, sizeof buf); + + serv_puts("ICAL putics"); + serv_getln(buf, sizeof buf); + if (buf[0] != '4') { + hprintf("HTTP/1.1 502 Bad Gateway\r\n"); + groupdav_common_headers(); + hprintf("Content-type: text/plain\r\n"); + begin_burst(); + wc_printf("%s\r\n", &buf[4]); + end_burst(); + return; + } + + serv_putbuf(WCC->upload); + serv_printf("\n000"); + + /* Report success and not much else. */ + hprintf("HTTP/1.1 204 No Content\r\n"); + lprintf(9, "HTTP/1.1 204 No Content\r\n"); + groupdav_common_headers(); + begin_burst(); + end_burst(); +} + + + +/* + * The pathname is always going to take one of two formats: + * [/groupdav/]room_name/euid (GroupDAV) + * [/groupdav/]room_name (webcal) + */ +void groupdav_put(void) +{ + wcsession *WCC = WC; + StrBuf *dav_roomname; + StrBuf *dav_uid; long new_msgnum = (-2L); long old_msgnum = (-1L); char buf[SIZ]; int n = 0; - /* First, break off the "/groupdav/" prefix */ - remove_token(dav_pathname, 0, '/'); - remove_token(dav_pathname, 0, '/'); - - /* Now extract the message euid */ - n = num_tokens(dav_pathname, '/'); - extract_token(dav_uid, dav_pathname, n-1, '/', sizeof dav_uid); - remove_token(dav_pathname, n-1, '/'); + if (StrBufNum_tokens(WCC->Hdr->HR.ReqLine, '/') < 2) { + hprintf("HTTP/1.1 404 not found\r\n"); + groupdav_common_headers(); + hprintf("Content-Type: text/plain\r\n"); + begin_burst(); + wc_printf("The object you requested was not found.\r\n"); + end_burst(); + return; + } - /* What's left is the room name. Remove trailing slashes. */ - if (dav_pathname[strlen(dav_pathname)-1] == '/') { - dav_pathname[strlen(dav_pathname)-1] = 0; + dav_roomname = NewStrBuf();; + dav_uid = NewStrBuf();; + StrBufExtract_token(dav_roomname, WCC->Hdr->HR.ReqLine, 0, '/'); + StrBufExtract_token(dav_uid, WCC->Hdr->HR.ReqLine, 1, '/'); + if ((!strcasecmp(ChrPtr(dav_uid), "ics")) || + (!strcasecmp(ChrPtr(dav_uid), "calendar.ics"))) { + FlushStrBuf(dav_uid); } - strcpy(dav_roomname, dav_pathname); /* Go to the correct room. */ - if (strcasecmp(WC->wc_roomname, dav_roomname)) { + if (strcasecmp(ChrPtr(WC->CurRoom.name), ChrPtr(dav_roomname))) { gotoroom(dav_roomname); } - if (strcasecmp(WC->wc_roomname, dav_roomname)) { - wprintf("HTTP/1.1 404 not found\r\n"); + if (strcasecmp(ChrPtr(WC->CurRoom.name), ChrPtr(dav_roomname))) { + hprintf("HTTP/1.1 404 not found\r\n"); groupdav_common_headers(); - wprintf( - "Content-Type: text/plain\r\n" - "\r\n" - "There is no folder called \"%s\" on this server.\r\n", - dav_roomname - ); + hprintf("Content-Type: text/plain\r\n"); + begin_burst(); + wc_printf("There is no folder called \"%s\" on this server.\r\n", + ChrPtr(dav_roomname)); + end_burst(); + FreeStrBuf(&dav_roomname); + FreeStrBuf(&dav_uid); return; } @@ -77,20 +110,32 @@ void groupdav_put(char *dav_pathname, char *dav_ifmatch, * client is expecting. If not, the server probably contains a newer * version, so we fail... */ - if (strlen(dav_ifmatch) > 0) { - lprintf(9, "dav_ifmatch: %s\n", dav_ifmatch); - old_msgnum = locate_message_by_uid(dav_uid); + if (StrLength(WCC->Hdr->HR.dav_ifmatch) > 0) { + lprintf(9, "dav_ifmatch: %s\n", WCC->Hdr->HR.dav_ifmatch); + old_msgnum = locate_message_by_uid(ChrPtr(dav_uid)); lprintf(9, "old_msgnum: %ld\n", old_msgnum); - if (atol(dav_ifmatch) != old_msgnum) { - wprintf("HTTP/1.1 412 Precondition Failed\r\n"); + if (StrTol(WCC->Hdr->HR.dav_ifmatch) != old_msgnum) { + hprintf("HTTP/1.1 412 Precondition Failed\r\n"); lprintf(9, "HTTP/1.1 412 Precondition Failed (ifmatch=%ld, old_msgnum=%ld)\r\n", - atol(dav_ifmatch), old_msgnum); + StrTol(WCC->Hdr->HR.dav_ifmatch), old_msgnum); groupdav_common_headers(); - wprintf("Content-Length: 0\r\n\r\n"); + + end_burst(); + FreeStrBuf(&dav_roomname); + FreeStrBuf(&dav_uid); return; } } + /** PUT on the collection itself uploads an ICS of the entire collection. + */ + if (StrLength(dav_uid) == 0) { + groupdav_put_bigics(); + FreeStrBuf(&dav_roomname); + FreeStrBuf(&dav_uid); + return; + } + /* * We are cleared for upload! We use the new calling syntax for ENT0 * which allows a confirmation to be sent back to us. That's how we @@ -99,33 +144,36 @@ void groupdav_put(char *dav_pathname, char *dav_ifmatch, serv_puts("ENT0 1|||4|||1|"); serv_getln(buf, sizeof buf); if (buf[0] != '8') { - wprintf("HTTP/1.1 502 Bad Gateway\r\n"); + hprintf("HTTP/1.1 502 Bad Gateway\r\n"); groupdav_common_headers(); - wprintf("Content-type: text/plain\r\n" - "\r\n" - "%s\r\n", &buf[4] - ); + hprintf("Content-type: text/plain\r\n"); + begin_burst(); + wc_printf("%s\r\n", &buf[4]); + end_burst(); return; } /* Send the content to the Citadel server */ - serv_printf("Content-type: %s\n\n", dav_content_type); - serv_puts(dav_content); + //serv_printf("Content-type: %s\n\n", WCC->upload_content_type); + serv_putbuf(WCC->upload); serv_puts("\n000"); /* Fetch the reply from the Citadel server */ n = 0; - strcpy(dav_uid, ""); + FlushStrBuf(dav_uid); while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { switch(n++) { - case 0: new_msgnum = atol(buf); - break; - case 1: lprintf(9, "new_msgnum=%ld (%s)\n", new_msgnum, buf); - break; - case 2: strcpy(dav_uid, buf); - break; - default: - break; + case 0: + new_msgnum = atol(buf); + break; + case 1: + lprintf(9, "new_msgnum=%ld (%s)\n", new_msgnum, buf); + break; + case 2: + StrBufAppendBufPlain(dav_uid, buf, -1, 0); + break; + default: + break; } } @@ -133,48 +181,50 @@ void groupdav_put(char *dav_pathname, char *dav_ifmatch, /* Citadel failed in some way? */ if (new_msgnum < 0L) { - wprintf("HTTP/1.1 502 Bad Gateway\r\n"); + hprintf("HTTP/1.1 502 Bad Gateway\r\n"); groupdav_common_headers(); - wprintf("Content-type: text/plain\r\n" - "\r\n" - "new_msgnum is %ld\r\n" - "\r\n", new_msgnum - ); + hprintf("Content-type: text/plain\r\n"); + begin_burst(); + wc_printf("new_msgnum is %ld\r\n" + "\r\n", new_msgnum); + end_burst(); + FreeStrBuf(&dav_roomname); + FreeStrBuf(&dav_uid); return; } /* We created this item for the first time. */ if (old_msgnum < 0L) { - wprintf("HTTP/1.1 201 Created\r\n"); + char escaped_uid[1024]; + hprintf("HTTP/1.1 201 Created\r\n"); lprintf(9, "HTTP/1.1 201 Created\r\n"); groupdav_common_headers(); - wprintf("etag: \"%ld\"\r\n", new_msgnum); - wprintf("Content-Length: 0\r\n"); - wprintf("Location: "); - if (strlen(WC->http_host) > 0) { - wprintf("%s://%s", - (is_https ? "https" : "http"), - WC->http_host); - } - wprintf("/groupdav/"); - urlescputs(dav_roomname); - wprintf("/%s\r\n", dav_uid); - wprintf("\r\n"); + hprintf("etag: \"%ld\"\r\n", new_msgnum); + hprintf("Location: "); + groupdav_identify_hosthdr(); + hprintf("/groupdav/");/* TODO */ + hurlescputs(ChrPtr(dav_roomname)); + euid_escapize(escaped_uid, ChrPtr(dav_uid)); + hprintf("/%s\r\n", escaped_uid); + end_burst(); + FreeStrBuf(&dav_roomname); + FreeStrBuf(&dav_uid); return; } /* We modified an existing item. */ - wprintf("HTTP/1.1 204 No Content\r\n"); + hprintf("HTTP/1.1 204 No Content\r\n"); lprintf(9, "HTTP/1.1 204 No Content\r\n"); groupdav_common_headers(); - wprintf("etag: \"%ld\"\r\n", new_msgnum); - wprintf("Content-Length: 0\r\n\r\n"); - + hprintf("Etag: \"%ld\"\r\n", new_msgnum); /* The item we replaced has probably already been deleted by * the Citadel server, but we'll do this anyway, just in case. */ serv_printf("DELE %ld", old_msgnum); serv_getln(buf, sizeof buf); - + begin_burst(); + end_burst(); + FreeStrBuf(&dav_roomname); + FreeStrBuf(&dav_uid); return; }