4 * Handles GroupDAV DELETE requests.
14 #include <sys/types.h>
16 #include <sys/socket.h>
25 #include "webserver.h"
30 * The pathname is always going to be /groupdav/room_name/euid
32 void groupdav_delete(char *dav_pathname, char *dav_ifmatch) {
33 char dav_roomname[SIZ];
35 long dav_msgnum = (-1);
39 /* First, break off the "/groupdav/" prefix */
40 remove_token(dav_pathname, 0, '/');
41 remove_token(dav_pathname, 0, '/');
43 /* Now extract the message euid */
44 n = num_tokens(dav_pathname, '/');
45 extract_token(dav_uid, dav_pathname, n-1, '/');
46 remove_token(dav_pathname, n-1, '/');
48 /* What's left is the room name. Remove trailing slashes. */
49 if (dav_pathname[strlen(dav_pathname)-1] == '/') {
50 dav_pathname[strlen(dav_pathname)-1] = 0;
52 strcpy(dav_roomname, dav_pathname);
54 /* Go to the correct room. */
55 if (strcasecmp(WC->wc_roomname, dav_roomname)) {
56 gotoroom(dav_roomname);
58 if (strcasecmp(WC->wc_roomname, dav_roomname)) {
59 wprintf("HTTP/1.1 404 not found\r\n");
60 groupdav_common_headers();
61 wprintf("Content-Length: 0\r\n\r\n");
65 dav_msgnum = locate_message_by_uid(dav_uid);
68 * If no item exists with the requested uid ... simple error.
70 if (dav_msgnum < 0L) {
71 wprintf("HTTP/1.1 404 Not Found\r\n");
72 groupdav_common_headers();
73 wprintf("Content-Length: 0\r\n\r\n");
78 * It's there ... check the ETag and make sure it matches
81 if (strlen(dav_ifmatch) > 0) {
82 if (atol(dav_ifmatch) != dav_msgnum) {
83 wprintf("HTTP/1.1 412 Precondition Failed\r\n");
84 groupdav_common_headers();
85 wprintf("Content-Length: 0\r\n\r\n");
91 * Ok, attempt to delete the item.
93 serv_printf("DELE %ld", dav_msgnum);
96 wprintf("HTTP/1.1 204 No Content\r\n"); /* success */
97 groupdav_common_headers();
98 wprintf("Content-Length: 0\r\n\r\n");
101 wprintf("HTTP/1.1 403 Forbidden\r\n"); /* access denied */
102 groupdav_common_headers();
103 wprintf("Content-Length: 0\r\n\r\n");