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