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);
37 int found_content_type = 0;
40 /* First, break off the "/groupdav/" prefix */
41 remove_token(dav_pathname, 0, '/');
42 remove_token(dav_pathname, 0, '/');
44 /* Now extract the message euid */
45 n = num_tokens(dav_pathname, '/');
46 extract_token(dav_uid, dav_pathname, n-1, '/');
47 remove_token(dav_pathname, n-1, '/');
49 /* What's left is the room name. Remove trailing slashes. */
50 if (dav_pathname[strlen(dav_pathname)-1] == '/') {
51 dav_pathname[strlen(dav_pathname)-1] = 0;
53 strcpy(dav_roomname, dav_pathname);
55 /* Go to the correct room. */
56 if (strcasecmp(WC->wc_roomname, dav_roomname)) {
57 gotoroom(dav_roomname);
59 if (strcasecmp(WC->wc_roomname, dav_roomname)) {
60 wprintf("HTTP/1.1 404 not found\n");
61 groupdav_common_headers();
62 wprintf("Content-Length: 0\n\n");
66 dav_msgnum = locate_message_by_uid(dav_uid);
69 * If no item exists with the requested uid ... simple error.
71 if (dav_msgnum < 0L) {
72 wprintf("HTTP/1.1 404 Not Found\n");
73 groupdav_common_headers();
74 wprintf("Content-Length: 0\n\n");
79 * It's there ... check the ETag and make sure it matches
82 if (strlen(dav_ifmatch) > 0) {
83 if (atol(dav_ifmatch) != dav_msgnum) {
84 wprintf("HTTP/1.1 412 Precondition Failed\n");
85 groupdav_common_headers();
86 wprintf("Content-Length: 0\n\n");
92 * Ok, attempt to delete the item.
94 serv_printf("DELE %ld", dav_msgnum);
97 wprintf("HTTP/1.1 204 No Content\n"); /* success */
98 groupdav_common_headers();
99 wprintf("Content-Length: 0\n\n");
102 wprintf("HTTP/1.1 403 Forbidden\n"); /* access denied */
103 groupdav_common_headers();
104 wprintf("Content-Length: 0\n\n");