* Reduced iconbar button size to 90% because it looked obtuse on a smaller screen
[citadel.git] / webcit / groupdav_delete.c
blobcdc65becb459458d7741335b3255423f09b1641e
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;
22 /* First, break off the "/groupdav/" prefix */
23 StrBufCutLeft(dav_pathname, 9);
25 /* Now extract the message euid */
26 n = StrBufNum_tokens(dav_pathname, '/');
27 extract_token(dav_uid, ChrPtr(dav_pathname), n-1, '/', sizeof dav_uid);
28 StrBufRemove_token(dav_pathname, n-1, '/');
30 /* What's left is the room name. Remove trailing slashes. */
31 //len = StrLength(dav_pathname);
32 //if ((len > 0) && (ChrPtr(dav_pathname)[len-1] == '/')) {
33 // StrBufCutRight(dav_pathname, 1);
34 //}
35 StrBufCutLeft(dav_pathname, 1);
37 /* Go to the correct room. */
38 if (strcasecmp(ChrPtr(WC->wc_roomname), ChrPtr(dav_pathname))) {
39 gotoroom(dav_pathname);
41 if (strcasecmp(ChrPtr(WC->wc_roomname), ChrPtr(dav_pathname))) {
42 hprintf("HTTP/1.1 404 not found\r\n");
43 groupdav_common_headers();
44 hprintf("Content-Length: 0\r\n\r\n");
45 return;
48 dav_msgnum = locate_message_by_uid(dav_uid);
51 * If no item exists with the requested uid ... simple error.
53 if (dav_msgnum < 0L) {
54 hprintf("HTTP/1.1 404 Not Found\r\n");
55 groupdav_common_headers();
56 hprintf("Content-Length: 0\r\n\r\n");
57 return;
61 * It's there ... check the ETag and make sure it matches
62 * the message number.
64 if (!IsEmptyStr(dav_ifmatch)) {
65 if (atol(dav_ifmatch) != dav_msgnum) {
66 hprintf("HTTP/1.1 412 Precondition Failed\r\n");
67 groupdav_common_headers();
68 hprintf("Content-Length: 0\r\n\r\n");
69 return;
74 * Ok, attempt to delete the item.
76 serv_printf("DELE %ld", dav_msgnum);
77 serv_getln(buf, sizeof buf);
78 if (buf[0] == '2') {
79 hprintf("HTTP/1.1 204 No Content\r\n"); /* success */
80 groupdav_common_headers();
81 hprintf("Content-Length: 0\r\n\r\n");
83 else {
84 hprintf("HTTP/1.1 403 Forbidden\r\n"); /* access denied */
85 groupdav_common_headers();
86 hprintf("Content-Length: 0\r\n\r\n");
88 return;