* added some missing license declarations
[citadel.git] / webcit / groupdav_delete.c
1 /*
2  * $Id$
3  *
4  * Handles GroupDAV DELETE requests.
5  *
6  * Copyright (c) 2005-2010 by the citadel.org team
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #include "webcit.h"
24 #include "webserver.h"
25 #include "groupdav.h"
26
27
28 /*
29  * The pathname is always going to be /groupdav/room_name/euid
30  */
31 void groupdav_delete(void) 
32 {
33         wcsession *WCC = WC;
34         char dav_uid[SIZ];
35         long dav_msgnum = (-1);
36         char buf[SIZ];
37         int n = 0;
38         StrBuf *dav_roomname = NewStrBuf();
39         
40         /* Now extract the message euid */
41         n = StrBufNum_tokens(WCC->Hdr->HR.ReqLine, '/');
42         extract_token(dav_uid, ChrPtr(WCC->Hdr->HR.ReqLine), n-1, '/', sizeof dav_uid);
43         StrBufExtract_token(dav_roomname, WCC->Hdr->HR.ReqLine, 0, '/');
44
45         ///* What's left is the room name.  Remove trailing slashes. */
46         //len = StrLength(WCC->Hdr->HR.ReqLine);
47         //if ((len > 0) && (ChrPtr(WCC->Hdr->HR.ReqLinee)[len-1] == '/')) {
48         //      StrBufCutRight(WCC->Hdr->HR.ReqLine, 1);
49         //}
50         //StrBufCutLeft(WCC->Hdr->HR.ReqLine, 1);
51
52         /* Go to the correct room. */
53         if (strcasecmp(ChrPtr(WC->CurRoom.name), ChrPtr(dav_roomname))) {
54                 gotoroom(dav_roomname);
55         }
56         if (strcasecmp(ChrPtr(WC->CurRoom.name), ChrPtr(dav_roomname))) {
57                 hprintf("HTTP/1.1 404 not found\r\n");
58                 groupdav_common_headers();
59                 hprintf("Content-Length: 0\r\n\r\n");
60                 begin_burst();
61                 end_burst();
62                 FreeStrBuf(&dav_roomname);
63                 return;
64         }
65
66         dav_msgnum = locate_message_by_uid(dav_uid);
67
68         /*
69          * If no item exists with the requested uid ... simple error.
70          */
71         if (dav_msgnum < 0L) {
72                 hprintf("HTTP/1.1 404 Not Found\r\n");
73                 groupdav_common_headers();
74                 hprintf("Content-Length: 0\r\n\r\n");
75                 begin_burst();
76                 end_burst();
77                 FreeStrBuf(&dav_roomname);
78                 return;
79         }
80
81         /*
82          * It's there ... check the ETag and make sure it matches
83          * the message number.
84          */
85         if (StrLength(WCC->Hdr->HR.dav_ifmatch) > 0) {
86                 if (StrTol(WCC->Hdr->HR.dav_ifmatch) != dav_msgnum) {
87                         hprintf("HTTP/1.1 412 Precondition Failed\r\n");
88                         groupdav_common_headers();
89                         hprintf("Content-Length: 0\r\n\r\n");
90                         begin_burst();
91                         end_burst();
92                         FreeStrBuf(&dav_roomname);
93                         return;
94                 }
95         }
96
97         /*
98          * Ok, attempt to delete the item.
99          */
100         serv_printf("DELE %ld", dav_msgnum);
101         serv_getln(buf, sizeof buf);
102         if (buf[0] == '2') {
103                 hprintf("HTTP/1.1 204 No Content\r\n"); /* success */
104                 groupdav_common_headers();
105                 hprintf("Content-Length: 0\r\n\r\n");
106                 begin_burst();
107                 end_burst();
108         }
109         else {
110                 hprintf("HTTP/1.1 403 Forbidden\r\n");  /* access denied */
111                 groupdav_common_headers();
112                 hprintf("Content-Length: 0\r\n\r\n");
113                 begin_burst();
114                 end_burst();
115         }
116         FreeStrBuf(&dav_roomname);
117         return;
118 }