Remove $Id$ tags from most of webcit
[citadel.git] / webcit / groupdav_put.c
index 512cea0980e79068d52e0fe1cbcbd940c725f201..b63b61935f77bfc63b72e711331d1136b81f6f9a 100644 (file)
@@ -1,8 +1,21 @@
 /*
- * $Id$
- *
  * Handles GroupDAV PUT requests.
  *
+ * Copyright (c) 2005-2010 by the citadel.org team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
 #include "webcit.h"
@@ -15,8 +28,9 @@
  * component.  This would be for webcal:// 'publish' operations, not
  * for GroupDAV.
  */
-void groupdav_put_bigics(StrBuf *dav_content, int offset)
+void groupdav_put_bigics(void)
 {
+       wcsession *WCC = WC;
        char buf[1024];
 
        /*
@@ -32,32 +46,33 @@ void groupdav_put_bigics(StrBuf *dav_content, int offset)
                hprintf("HTTP/1.1 502 Bad Gateway\r\n");
                groupdav_common_headers();
                hprintf("Content-type: text/plain\r\n");
-               wprintf("%s\r\n", &buf[4]);
+               begin_burst();
+               wc_printf("%s\r\n", &buf[4]);
                end_burst();
                return;
        }
 
-       serv_write(ChrPtr(dav_content) + offset, StrLength(dav_content) - offset);
+       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();
-       hprintf("Content-Length: 0\r\n");
+       begin_burst();
+       end_burst();
 }
 
 
 
 /*
  * The pathname is always going to take one of two formats:
- * /groupdav/room_name/euid    (GroupDAV)
- * /groupdav/room_name         (webcal)
+ * [/groupdav/]room_name/euid  (GroupDAV)
+ * [/groupdav/]room_name               (webcal)
  */
-void groupdav_put(StrBuf *dav_pathname, char *dav_ifmatch,
-                 const char *dav_content_type, StrBuf *dav_content,
-                 int offset) 
+void groupdav_put(void) 
 {
+       wcsession *WCC = WC;
        StrBuf *dav_roomname;
        StrBuf *dav_uid;
        long new_msgnum = (-2L);
@@ -65,33 +80,35 @@ void groupdav_put(StrBuf *dav_pathname, char *dav_ifmatch,
        char buf[SIZ];
        int n = 0;
 
-       if (StrBufNum_tokens(dav_pathname, '/') < 3) {
+       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");
-               wprintf("The object you requested was not found.\r\n");
+               begin_burst();
+               wc_printf("The object you requested was not found.\r\n");
                end_burst();
                return;
        }
 
        dav_roomname = NewStrBuf();;
        dav_uid = NewStrBuf();;
-       StrBufExtract_token(dav_roomname, dav_pathname, 2, '/');
-       StrBufExtract_token(dav_uid, dav_pathname, 3, '/');
+       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);
        }
 
        /* Go to the correct room. */
-       if (strcasecmp(ChrPtr(WC->wc_roomname), ChrPtr(dav_roomname))) {
+       if (strcasecmp(ChrPtr(WC->CurRoom.name), ChrPtr(dav_roomname))) {
                gotoroom(dav_roomname);
        }
-       if (strcasecmp(ChrPtr(WC->wc_roomname), ChrPtr(dav_roomname))) {
+       if (strcasecmp(ChrPtr(WC->CurRoom.name), ChrPtr(dav_roomname))) {
                hprintf("HTTP/1.1 404 not found\r\n");
                groupdav_common_headers();
                hprintf("Content-Type: text/plain\r\n");
-               wprintf("There is no folder called \"%s\" on this server.\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);
@@ -106,16 +123,16 @@ void groupdav_put(StrBuf *dav_pathname, char *dav_ifmatch,
         * client is expecting.  If not, the server probably contains a newer
         * version, so we fail...
         */
-       if (!IsEmptyStr(dav_ifmatch)) {
-               lprintf(9, "dav_ifmatch: %s\n", dav_ifmatch);
+       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) {
+               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();
-                       hprintf("Content-Length: 0\r\n");
+                       
                        end_burst();
                        FreeStrBuf(&dav_roomname);
                        FreeStrBuf(&dav_uid);
@@ -125,8 +142,8 @@ void groupdav_put(StrBuf *dav_pathname, char *dav_ifmatch,
 
        /** PUT on the collection itself uploads an ICS of the entire collection.
         */
-       if (StrLength(dav_uid) > 0) {
-               groupdav_put_bigics(dav_content, offset);
+       if (StrLength(dav_uid) == 0) {
+               groupdav_put_bigics();
                FreeStrBuf(&dav_roomname);
                FreeStrBuf(&dav_uid);
                return;
@@ -143,15 +160,15 @@ void groupdav_put(StrBuf *dav_pathname, char *dav_ifmatch,
                hprintf("HTTP/1.1 502 Bad Gateway\r\n");
                groupdav_common_headers();
                hprintf("Content-type: text/plain\r\n");
-
-               wprintf("%s\r\n", &buf[4]);
+               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(ChrPtr(dav_content) + offset);
+       //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 */
@@ -180,7 +197,8 @@ void groupdav_put(StrBuf *dav_pathname, char *dav_ifmatch,
                hprintf("HTTP/1.1 502 Bad Gateway\r\n");
                groupdav_common_headers();
                hprintf("Content-type: text/plain\r\n");
-               wprintf("new_msgnum is %ld\r\n"
+               begin_burst();
+               wc_printf("new_msgnum is %ld\r\n"
                        "\r\n", new_msgnum);
                end_burst();
                FreeStrBuf(&dav_roomname);
@@ -196,7 +214,7 @@ void groupdav_put(StrBuf *dav_pathname, char *dav_ifmatch,
                groupdav_common_headers();
                hprintf("etag: \"%ld\"\r\n", new_msgnum);
                hprintf("Location: ");
-               groupdav_identify_host();
+               groupdav_identify_hosthdr();
                hprintf("/groupdav/");/* TODO */
                hurlescputs(ChrPtr(dav_roomname));
                euid_escapize(escaped_uid, ChrPtr(dav_uid));
@@ -211,14 +229,13 @@ void groupdav_put(StrBuf *dav_pathname, char *dav_ifmatch,
        hprintf("HTTP/1.1 204 No Content\r\n");
        lprintf(9, "HTTP/1.1 204 No Content\r\n");
        groupdav_common_headers();
-       hprintf("etag: \"%ld\"\r\n", new_msgnum);
-       hprintf("Content-Length: 0\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);