* Doxygen groups. Sorted the files into groups. so now we have a nice structure
[citadel.git] / webcit / groupdav_put.c
index ad5f6927ee2ae2dc5fa97486a6e389e0c2843b06..d06848ec23ec503f6501b1befa158d84af49966c 100644 (file)
@@ -1,61 +1,50 @@
 /*
  * $Id$
- *
- * Handles GroupDAV PUT requests.
+ */
+/**
+ * \defgroup GroupdavPut Handles GroupDAV PUT requests.
+ * \ingroup WebcitHttpServerGDav
  *
  */
-
-#include <ctype.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <sys/socket.h>
-#include <limits.h>
-#include <string.h>
-#include <pwd.h>
-#include <errno.h>
-#include <stdarg.h>
-#include <time.h>
-#include <pthread.h>
+/*@{*/
 #include "webcit.h"
 #include "webserver.h"
 #include "groupdav.h"
 
 
-/*
- * The pathname is always going to be /groupdav/room_name/euid
+/**
+ * \brief GroupDAV PUT an item to the server
+ * \param dav_pathname The pathname is always going to be /groupdav/room_name/euid
+ * \param dav_ifmatch ETag of the item we think we're replacing
+ * \param dav_content_type the mime type
+ * \param dav_content the actual data
  */
 void groupdav_put(char *dav_pathname, char *dav_ifmatch,
-               char *supplied_content_type, char *dav_content
+               char *dav_content_type, char *dav_content
 ) {
        char dav_roomname[SIZ];
        char dav_uid[SIZ];
-       char dav_content_type[SIZ];
        long new_msgnum = (-2L);
        long old_msgnum = (-1L);
        char buf[SIZ];
        int n = 0;
 
-       /* First, break off the "/groupdav/" prefix */
+       /** First, break off the "/groupdav/" prefix */
        remove_token(dav_pathname, 0, '/');
        remove_token(dav_pathname, 0, '/');
 
-       /* Now extract the message euid */
+       /** Now extract the message euid */
        n = num_tokens(dav_pathname, '/');
-       extract_token(dav_uid, dav_pathname, n-1, '/');
+       extract_token(dav_uid, dav_pathname, n-1, '/', sizeof dav_uid);
        remove_token(dav_pathname, n-1, '/');
 
-       /* What's left is the room name.  Remove trailing slashes. */
+       /** What's left is the room name.  Remove trailing slashes. */
        if (dav_pathname[strlen(dav_pathname)-1] == '/') {
                dav_pathname[strlen(dav_pathname)-1] = 0;
        }
        strcpy(dav_roomname, dav_pathname);
 
-       /* Go to the correct room. */
+       /** Go to the correct room. */
        if (strcasecmp(WC->wc_roomname, dav_roomname)) {
                gotoroom(dav_roomname);
        }
@@ -71,28 +60,7 @@ void groupdav_put(char *dav_pathname, char *dav_ifmatch,
                return;
        }
 
-       /* Ugly hack to mess with the content type.  KOrganizer is either
-        * not supplying one, or supplying the wrong one.
-        * FIXME - remove this after KOrg gets fixed.
-        */
-       strcpy(dav_content_type, supplied_content_type);
-       /* lprintf(9, "Supplied content type: %s\n", dav_content_type); */
-       switch (WC->wc_view) {
-               case VIEW_ADDRESSBOOK:
-                       strcpy(dav_content_type, "text/x-vcard");
-                       break;
-               case VIEW_CALENDAR:
-                       strcpy(dav_content_type, "text/calendar");
-                       break;
-               case VIEW_TASKS:
-                       strcpy(dav_content_type, "text/calendar");
-                       break;
-               default:
-                       break;
-       }
-       /* lprintf(9, "  Forced content type: %s\n", dav_content_type); */
-
-       /*
+       /**
         * If an HTTP If-Match: header is present, the client is attempting
         * to replace an existing item.  We have to check to see if the
         * message number associated with the supplied uid matches what the
@@ -100,25 +68,24 @@ void groupdav_put(char *dav_pathname, char *dav_ifmatch,
         * 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);
-               lprintf(9, "old_msgnum:  %ld\n", old_msgnum);
                if (atol(dav_ifmatch) != old_msgnum) {
                        wprintf("HTTP/1.1 412 Precondition Failed\r\n");
-                       lprintf(9, "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);
                        groupdav_common_headers();
                        wprintf("Content-Length: 0\r\n\r\n");
                        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
         * extract the message ID.
         */
        serv_puts("ENT0 1|||4|||1|");
-       serv_gets(buf);
+       serv_getln(buf, sizeof buf);
        if (buf[0] != '8') {
                wprintf("HTTP/1.1 502 Bad Gateway\r\n");
                groupdav_common_headers();
@@ -129,15 +96,15 @@ void groupdav_put(char *dav_pathname, char *dav_ifmatch,
                return;
        }
 
-       /* Send the content to the Citadel server */
+       /** Send the content to the Citadel server */
        serv_printf("Content-type: %s\n\n", dav_content_type);
        serv_puts(dav_content);
        serv_puts("\n000");
 
-       /* Fetch the reply from the Citadel server */
+       /** Fetch the reply from the Citadel server */
        n = 0;
        strcpy(dav_uid, "");
-       while (serv_gets(buf), strcmp(buf, "000")) {
+       while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
                switch(n++) {
                        case 0: new_msgnum = atol(buf);
                                break;
@@ -150,9 +117,9 @@ void groupdav_put(char *dav_pathname, char *dav_ifmatch,
                }
        }
 
-       /* Tell the client what happened. */
+       /** Tell the client what happened. */
 
-       /* Citadel failed in some way? */
+       /** Citadel failed in some way? */
        if (new_msgnum < 0L) {
                wprintf("HTTP/1.1 502 Bad Gateway\r\n");
                groupdav_common_headers();
@@ -164,11 +131,12 @@ void groupdav_put(char *dav_pathname, char *dav_ifmatch,
                return;
        }
 
-       /* We created this item for the first time. */
+       /** We created this item for the first time. */
        if (old_msgnum < 0L) {
                wprintf("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) {
@@ -183,17 +151,22 @@ void groupdav_put(char *dav_pathname, char *dav_ifmatch,
                return;
        }
 
-       /* We modified an existing item. */
+       /** We modified an existing item. */
        wprintf("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");
 
-       /* The item we replaced has probably already been deleted by
+       /**
+        * 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_gets(buf);
+       serv_getln(buf, sizeof buf);
 
        return;
 }
+
+
+/*@}*/