* fix another off by one while retrieving the iterator counter params
[citadel.git] / webcit / groupdav_delete.c
blob20915900f5b4eb742bd7d904e10c0c81a0747f7e
1 /*
2 * $Id$
4 * Handles GroupDAV DELETE requests.
6 */
8 #include "webcit.h"
9 #include "webserver.h"
10 #include "groupdav.h"
14 * The pathname is always going to be /groupdav/room_name/euid
16 void groupdav_delete(StrBuf *dav_pathname, char *dav_ifmatch) {
17 char dav_uid[SIZ];
18 long dav_msgnum = (-1);
19 char buf[SIZ];
20 int n = 0;
21 int len;
23 /* First, break off the "/groupdav/" prefix */
24 StrBufRemove_token(dav_pathname, 0, '/');
25 StrBufRemove_token(dav_pathname, 0, '/');
27 /* Now extract the message euid */
28 n = StrBufNum_tokens(dav_pathname, '/');
29 extract_token(dav_uid, ChrPtr(dav_pathname), n-1, '/', sizeof dav_uid);
30 StrBufRemove_token(dav_pathname, n-1, '/');
32 /* What's left is the room name. Remove trailing slashes. */
33 len = StrLength(dav_pathname);
34 if ((len > 0) && (ChrPtr(dav_pathname)[len-1] == '/')) {
35 StrBufCutRight(dav_pathname, 1);
38 /* Go to the correct room. */
39 if (strcasecmp(ChrPtr(WC->wc_roomname), ChrPtr(dav_pathname))) {
40 gotoroom(dav_pathname);
42 if (strcasecmp(ChrPtr(WC->wc_roomname), ChrPtr(dav_pathname))) {
43 hprintf("HTTP/1.1 404 not found\r\n");
44 groupdav_common_headers();
45 hprintf("Content-Length: 0\r\n\r\n");
46 return;
49 dav_msgnum = locate_message_by_uid(dav_uid);
52 * If no item exists with the requested uid ... simple error.
54 if (dav_msgnum < 0L) {
55 hprintf("HTTP/1.1 404 Not Found\r\n");
56 groupdav_common_headers();
57 hprintf("Content-Length: 0\r\n\r\n");
58 return;
62 * It's there ... check the ETag and make sure it matches
63 * the message number.
65 if (!IsEmptyStr(dav_ifmatch)) {
66 if (atol(dav_ifmatch) != dav_msgnum) {
67 hprintf("HTTP/1.1 412 Precondition Failed\r\n");
68 groupdav_common_headers();
69 hprintf("Content-Length: 0\r\n\r\n");
70 return;
75 * Ok, attempt to delete the item.
77 serv_printf("DELE %ld", dav_msgnum);
78 serv_getln(buf, sizeof buf);
79 if (buf[0] == '2') {
80 hprintf("HTTP/1.1 204 No Content\r\n"); /* success */
81 groupdav_common_headers();
82 hprintf("Content-Length: 0\r\n\r\n");
84 else {
85 hprintf("HTTP/1.1 403 Forbidden\r\n"); /* access denied */
86 groupdav_common_headers();
87 hprintf("Content-Length: 0\r\n\r\n");
89 return;