groupdav_delete.c

00001 /*
00002  * $Id: groupdav_delete.c 5147 2007-05-08 15:36:22Z ajc $
00003  *
00004  * Handles GroupDAV DELETE requests.
00005  *
00006  */
00007 
00008 #include "webcit.h"
00009 #include "webserver.h"
00010 #include "groupdav.h"
00011 
00012 
00013 /*
00014  * The pathname is always going to be /groupdav/room_name/euid
00015  */
00016 void groupdav_delete(char *dav_pathname, char *dav_ifmatch) {
00017         char dav_roomname[SIZ];
00018         char dav_uid[SIZ];
00019         long dav_msgnum = (-1);
00020         char buf[SIZ];
00021         int n = 0;
00022 
00023         /* First, break off the "/groupdav/" prefix */
00024         remove_token(dav_pathname, 0, '/');
00025         remove_token(dav_pathname, 0, '/');
00026 
00027         /* Now extract the message euid */
00028         n = num_tokens(dav_pathname, '/');
00029         extract_token(dav_uid, dav_pathname, n-1, '/', sizeof dav_uid);
00030         remove_token(dav_pathname, n-1, '/');
00031 
00032         /* What's left is the room name.  Remove trailing slashes. */
00033         if (dav_pathname[strlen(dav_pathname)-1] == '/') {
00034                 dav_pathname[strlen(dav_pathname)-1] = 0;
00035         }
00036         strcpy(dav_roomname, dav_pathname);
00037 
00038         /* Go to the correct room. */
00039         if (strcasecmp(WC->wc_roomname, dav_roomname)) {
00040                 gotoroom(dav_roomname);
00041         }
00042         if (strcasecmp(WC->wc_roomname, dav_roomname)) {
00043                 wprintf("HTTP/1.1 404 not found\r\n");
00044                 groupdav_common_headers();
00045                 wprintf("Content-Length: 0\r\n\r\n");
00046                 return;
00047         }
00048 
00049         dav_msgnum = locate_message_by_uid(dav_uid);
00050 
00051         /*
00052          * If no item exists with the requested uid ... simple error.
00053          */
00054         if (dav_msgnum < 0L) {
00055                 wprintf("HTTP/1.1 404 Not Found\r\n");
00056                 groupdav_common_headers();
00057                 wprintf("Content-Length: 0\r\n\r\n");
00058                 return;
00059         }
00060 
00061         /*
00062          * It's there ... check the ETag and make sure it matches
00063          * the message number.
00064          */
00065         if (strlen(dav_ifmatch) > 0) {
00066                 if (atol(dav_ifmatch) != dav_msgnum) {
00067                         wprintf("HTTP/1.1 412 Precondition Failed\r\n");
00068                         groupdav_common_headers();
00069                         wprintf("Content-Length: 0\r\n\r\n");
00070                         return;
00071                 }
00072         }
00073 
00074         /*
00075          * Ok, attempt to delete the item.
00076          */
00077         serv_printf("DELE %ld", dav_msgnum);
00078         serv_getln(buf, sizeof buf);
00079         if (buf[0] == '2') {
00080                 wprintf("HTTP/1.1 204 No Content\r\n"); /* success */
00081                 groupdav_common_headers();
00082                 wprintf("Content-Length: 0\r\n\r\n");
00083         }
00084         else {
00085                 wprintf("HTTP/1.1 403 Forbidden\r\n");  /* access denied */
00086                 groupdav_common_headers();
00087                 wprintf("Content-Length: 0\r\n\r\n");
00088         }
00089         return;
00090 }

Generated on Wed Jun 20 23:13:08 2007 for webcit by  doxygen 1.5.2