* fix groupdav handling
[citadel.git] / webcit / groupdav_delete.c
1 /*
2  * $Id$
3  *
4  * Handles GroupDAV DELETE requests.
5  *
6  */
7
8 #include "webcit.h"
9 #include "webserver.h"
10 #include "groupdav.h"
11
12
13 /*
14  * The pathname is always going to be /groupdav/room_name/euid
15  */
16 void groupdav_delete(void) 
17 {
18         wcsession *WCC = WC;
19         char dav_uid[SIZ];
20         long dav_msgnum = (-1);
21         char buf[SIZ];
22         int n = 0;
23
24         /* Now extract the message euid */
25         n = StrBufNum_tokens(WCC->Hdr->HR.ReqLine, '/');
26         extract_token(dav_uid, ChrPtr(WCC->Hdr->HR.ReqLine), n-1, '/', sizeof dav_uid);
27         StrBufRemove_token(WCC->Hdr->HR.ReqLine, n-1, '/');
28
29         /* What's left is the room name.  Remove trailing slashes. */
30         //len = StrLength(WCC->Hdr->HR.ReqLine);
31         //if ((len > 0) && (ChrPtr(WCC->Hdr->HR.ReqLinee)[len-1] == '/')) {
32         //      StrBufCutRight(WCC->Hdr->HR.ReqLine, 1);
33         //}
34         StrBufCutLeft(WCC->Hdr->HR.ReqLine, 1);
35
36         /* Go to the correct room. */
37         if (strcasecmp(ChrPtr(WC->wc_roomname), ChrPtr(WCC->Hdr->HR.ReqLine))) {
38                 gotoroom(WCC->Hdr->HR.ReqLine);
39         }
40         if (strcasecmp(ChrPtr(WC->wc_roomname), ChrPtr(WCC->Hdr->HR.ReqLine))) {
41                 hprintf("HTTP/1.1 404 not found\r\n");
42                 groupdav_common_headers();
43                 hprintf("Content-Length: 0\r\n\r\n");
44                 return;
45         }
46
47         dav_msgnum = locate_message_by_uid(dav_uid);
48
49         /*
50          * If no item exists with the requested uid ... simple error.
51          */
52         if (dav_msgnum < 0L) {
53                 hprintf("HTTP/1.1 404 Not Found\r\n");
54                 groupdav_common_headers();
55                 hprintf("Content-Length: 0\r\n\r\n");
56                 return;
57         }
58
59         /*
60          * It's there ... check the ETag and make sure it matches
61          * the message number.
62          */
63         if (StrLength(WCC->Hdr->HR.dav_ifmatch) > 0) {
64                 if (StrTol(WCC->Hdr->HR.dav_ifmatch) != dav_msgnum) {
65                         hprintf("HTTP/1.1 412 Precondition Failed\r\n");
66                         groupdav_common_headers();
67                         hprintf("Content-Length: 0\r\n\r\n");
68                         return;
69                 }
70         }
71
72         /*
73          * Ok, attempt to delete the item.
74          */
75         serv_printf("DELE %ld", dav_msgnum);
76         serv_getln(buf, sizeof buf);
77         if (buf[0] == '2') {
78                 hprintf("HTTP/1.1 204 No Content\r\n"); /* success */
79                 groupdav_common_headers();
80                 hprintf("Content-Length: 0\r\n\r\n");
81         }
82         else {
83                 hprintf("HTTP/1.1 403 Forbidden\r\n");  /* access denied */
84                 groupdav_common_headers();
85                 hprintf("Content-Length: 0\r\n\r\n");
86         }
87         return;
88 }