]> code.citadel.org Git - citadel.git/blobdiff - webcit/groupdav_delete.c
* Created IsEmptyStr define to be used rather then using some weird strlen constructs
[citadel.git] / webcit / groupdav_delete.c
index c75fcd90fa048b9154076f46808ea89abc653297..f731daa5a7cf6878f9b0d4c323a64c0557cab4a4 100644 (file)
@@ -5,22 +5,6 @@
  *
  */
 
-#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"
@@ -34,8 +18,8 @@ void groupdav_delete(char *dav_pathname, char *dav_ifmatch) {
        char dav_uid[SIZ];
        long dav_msgnum = (-1);
        char buf[SIZ];
-       int found_content_type = 0;
        int n = 0;
+       int len;
 
        /* First, break off the "/groupdav/" prefix */
        remove_token(dav_pathname, 0, '/');
@@ -43,12 +27,13 @@ void groupdav_delete(char *dav_pathname, char *dav_ifmatch) {
 
        /* 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. */
-       if (dav_pathname[strlen(dav_pathname)-1] == '/') {
-               dav_pathname[strlen(dav_pathname)-1] = 0;
+       len = strlen(dav_pathname);
+       if (dav_pathname[len-1] == '/') {
+               dav_pathname[len-1] = 0;
        }
        strcpy(dav_roomname, dav_pathname);
 
@@ -57,9 +42,9 @@ void groupdav_delete(char *dav_pathname, char *dav_ifmatch) {
                gotoroom(dav_roomname);
        }
        if (strcasecmp(WC->wc_roomname, dav_roomname)) {
-               wprintf("HTTP/1.1 404 not found\n");
+               wprintf("HTTP/1.1 404 not found\r\n");
                groupdav_common_headers();
-               wprintf("Content-Length: 0\n\n");
+               wprintf("Content-Length: 0\r\n\r\n");
                return;
        }
 
@@ -69,9 +54,9 @@ void groupdav_delete(char *dav_pathname, char *dav_ifmatch) {
         * If no item exists with the requested uid ... simple error.
         */
        if (dav_msgnum < 0L) {
-               wprintf("HTTP/1.1 404 Not Found\n");
+               wprintf("HTTP/1.1 404 Not Found\r\n");
                groupdav_common_headers();
-               wprintf("Content-Length: 0\n\n");
+               wprintf("Content-Length: 0\r\n\r\n");
                return;
        }
 
@@ -79,11 +64,11 @@ void groupdav_delete(char *dav_pathname, char *dav_ifmatch) {
         * It's there ... check the ETag and make sure it matches
         * the message number.
         */
-       if (strlen(dav_ifmatch) > 0) {
+       if (!IsEmptyStr(dav_ifmatch)) {
                if (atol(dav_ifmatch) != dav_msgnum) {
-                       wprintf("HTTP/1.1 412 Precondition Failed\n");
+                       wprintf("HTTP/1.1 412 Precondition Failed\r\n");
                        groupdav_common_headers();
-                       wprintf("Content-Length: 0\n\n");
+                       wprintf("Content-Length: 0\r\n\r\n");
                        return;
                }
        }
@@ -92,16 +77,16 @@ void groupdav_delete(char *dav_pathname, char *dav_ifmatch) {
         * Ok, attempt to delete the item.
         */
        serv_printf("DELE %ld", dav_msgnum);
-       serv_gets(buf);
+       serv_getln(buf, sizeof buf);
        if (buf[0] == '2') {
-               wprintf("HTTP/1.1 204 No Content\n");   /* success */
+               wprintf("HTTP/1.1 204 No Content\r\n"); /* success */
                groupdav_common_headers();
-               wprintf("Content-Length: 0\n\n");
+               wprintf("Content-Length: 0\r\n\r\n");
        }
        else {
-               wprintf("HTTP/1.1 403 Forbidden\n");    /* access denied */
+               wprintf("HTTP/1.1 403 Forbidden\r\n");  /* access denied */
                groupdav_common_headers();
-               wprintf("Content-Length: 0\n\n");
+               wprintf("Content-Length: 0\r\n\r\n");
        }
        return;
 }