* Doxygen groups. Sorted the files into groups. so now we have a nice structure
[citadel.git] / webcit / groupdav_delete.c
1 /*
2  * $Id$
3  */
4 /**
5  * \defgroup GroupdavDel Handle GroupDAV DELETE requests.
6  * \ingroup WebcitHttpServerGDav
7  */
8 /*@{*/
9 #include "webcit.h"
10 #include "webserver.h"
11 #include "groupdav.h"
12
13
14 /**
15  * \brief The pathname is always going to be /groupdav/room_name/euid
16  * \param dav_pathname the groupdav pathname
17  * \param dav_ifmatch item to delete ????
18  */
19 void groupdav_delete(char *dav_pathname, char *dav_ifmatch) {
20         char dav_roomname[SIZ];
21         char dav_uid[SIZ];
22         long dav_msgnum = (-1);
23         char buf[SIZ];
24         int n = 0;
25
26         /** First, break off the "/groupdav/" prefix */
27         remove_token(dav_pathname, 0, '/');
28         remove_token(dav_pathname, 0, '/');
29
30         /** Now extract the message euid */
31         n = num_tokens(dav_pathname, '/');
32         extract_token(dav_uid, dav_pathname, n-1, '/', sizeof dav_uid);
33         remove_token(dav_pathname, n-1, '/');
34
35         /** What's left is the room name.  Remove trailing slashes. */
36         if (dav_pathname[strlen(dav_pathname)-1] == '/') {
37                 dav_pathname[strlen(dav_pathname)-1] = 0;
38         }
39         strcpy(dav_roomname, dav_pathname);
40
41         /** Go to the correct room. */
42         if (strcasecmp(WC->wc_roomname, dav_roomname)) {
43                 gotoroom(dav_roomname);
44         }
45         if (strcasecmp(WC->wc_roomname, dav_roomname)) {
46                 wprintf("HTTP/1.1 404 not found\r\n");
47                 groupdav_common_headers();
48                 wprintf("Content-Length: 0\r\n\r\n");
49                 return;
50         }
51
52         dav_msgnum = locate_message_by_uid(dav_uid);
53
54         /**
55          * If no item exists with the requested uid ... simple error.
56          */
57         if (dav_msgnum < 0L) {
58                 wprintf("HTTP/1.1 404 Not Found\r\n");
59                 groupdav_common_headers();
60                 wprintf("Content-Length: 0\r\n\r\n");
61                 return;
62         }
63
64         /**
65          * It's there ... check the ETag and make sure it matches
66          * the message number.
67          */
68         if (strlen(dav_ifmatch) > 0) {
69                 if (atol(dav_ifmatch) != dav_msgnum) {
70                         wprintf("HTTP/1.1 412 Precondition Failed\r\n");
71                         groupdav_common_headers();
72                         wprintf("Content-Length: 0\r\n\r\n");
73                         return;
74                 }
75         }
76
77         /**
78          * Ok, attempt to delete the item.
79          */
80         serv_printf("DELE %ld", dav_msgnum);
81         serv_getln(buf, sizeof buf);
82         if (buf[0] == '2') {
83                 wprintf("HTTP/1.1 204 No Content\r\n"); /* success */
84                 groupdav_common_headers();
85                 wprintf("Content-Length: 0\r\n\r\n");
86         }
87         else {
88                 wprintf("HTTP/1.1 403 Forbidden\r\n");  /* access denied */
89                 groupdav_common_headers();
90                 wprintf("Content-Length: 0\r\n\r\n");
91         }
92         return;
93 }
94
95
96 /*@}*/