Back to index

webcit  8.12-dfsg
dav_delete.c
Go to the documentation of this file.
00001 /*
00002  * Handles GroupDAV DELETE requests.
00003  *
00004  * Copyright (c) 2005-2012 by the citadel.org team
00005  *
00006  * This program is open source software.  You can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License, version 3.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  */
00014 
00015 #include "webcit.h"
00016 #include "webserver.h"
00017 #include "dav.h"
00018 
00019 
00020 /*
00021  * The pathname is always going to be /groupdav/room_name/euid
00022  */
00023 void dav_delete(void) 
00024 {
00025        wcsession *WCC = WC;
00026        char dav_uid[SIZ];
00027        long dav_msgnum = (-1);
00028        char buf[SIZ];
00029        int n = 0;
00030        StrBuf *dav_roomname = NewStrBuf();
00031        
00032        /* Now extract the message euid */
00033        n = StrBufNum_tokens(WCC->Hdr->HR.ReqLine, '/');
00034        extract_token(dav_uid, ChrPtr(WCC->Hdr->HR.ReqLine), n-1, '/', sizeof dav_uid);
00035        StrBufExtract_token(dav_roomname, WCC->Hdr->HR.ReqLine, 0, '/');
00036 
00038        //len = StrLength(WCC->Hdr->HR.ReqLine);
00039        //if ((len > 0) && (ChrPtr(WCC->Hdr->HR.ReqLinee)[len-1] == '/')) {
00040        //     StrBufCutRight(WCC->Hdr->HR.ReqLine, 1);
00041        //}
00042        //StrBufCutLeft(WCC->Hdr->HR.ReqLine, 1);
00043 
00044        /* Go to the correct room. */
00045        if (strcasecmp(ChrPtr(WC->CurRoom.name), ChrPtr(dav_roomname))) {
00046               gotoroom(dav_roomname);
00047        }
00048        if (strcasecmp(ChrPtr(WC->CurRoom.name), ChrPtr(dav_roomname))) {
00049               hprintf("HTTP/1.1 404 not found\r\n");
00050               dav_common_headers();
00051               hprintf("Content-Length: 0\r\n\r\n");
00052               begin_burst();
00053               end_burst();
00054               FreeStrBuf(&dav_roomname);
00055               return;
00056        }
00057 
00058        dav_msgnum = locate_message_by_uid(dav_uid);
00059 
00060        /*
00061         * If no item exists with the requested uid ... simple error.
00062         */
00063        if (dav_msgnum < 0L) {
00064               hprintf("HTTP/1.1 404 Not Found\r\n");
00065               dav_common_headers();
00066               hprintf("Content-Length: 0\r\n\r\n");
00067               begin_burst();
00068               end_burst();
00069               FreeStrBuf(&dav_roomname);
00070               return;
00071        }
00072 
00073        /*
00074         * It's there ... check the ETag and make sure it matches
00075         * the message number.
00076         */
00077        if (StrLength(WCC->Hdr->HR.dav_ifmatch) > 0) {
00078               if (StrTol(WCC->Hdr->HR.dav_ifmatch) != dav_msgnum) {
00079                      hprintf("HTTP/1.1 412 Precondition Failed\r\n");
00080                      dav_common_headers();
00081                      hprintf("Content-Length: 0\r\n\r\n");
00082                      begin_burst();
00083                      end_burst();
00084                      FreeStrBuf(&dav_roomname);
00085                      return;
00086               }
00087        }
00088 
00089        /*
00090         * Ok, attempt to delete the item.
00091         */
00092        serv_printf("DELE %ld", dav_msgnum);
00093        serv_getln(buf, sizeof buf);
00094        if (buf[0] == '2') {
00095               hprintf("HTTP/1.1 204 No Content\r\n");   /* success */
00096               dav_common_headers();
00097               hprintf("Content-Length: 0\r\n\r\n");
00098               begin_burst();
00099               end_burst();
00100        }
00101        else {
00102               hprintf("HTTP/1.1 403 Forbidden\r\n");    /* access denied */
00103               dav_common_headers();
00104               hprintf("Content-Length: 0\r\n\r\n");
00105               begin_burst();
00106               end_burst();
00107        }
00108        FreeStrBuf(&dav_roomname);
00109        return;
00110 }