upload DELETE method
authorArt Cancro <ajc@citadel.org>
Fri, 6 Oct 2023 03:20:27 +0000 (23:20 -0400)
committerArt Cancro <ajc@citadel.org>
Fri, 6 Oct 2023 03:20:27 +0000 (23:20 -0400)
webcit-ng/server/messages.c
webcit-ng/server/upload.c

index 81896c7b594edf88505143f7e060e1de4383ac93..4152413684128738dcec1b63557d651dc650f713 100644 (file)
@@ -40,8 +40,7 @@ long locate_message_by_uid(struct ctdlsession *c, char *uid) {
 // DAV delete an object in a room.
 void dav_delete_message(struct http_transaction *h, struct ctdlsession *c, long msgnum) {
        ctdl_delete_msgs(c, &msgnum, 1);
-       h->response_code = 204;
-       h->response_string = strdup("no content");
+       do_204(h);
 }
 
 
index 711bbf3523af9f7c6d7d41aa7c5f70740b014d4a..17d96a9a31f1314ded2605e019a9f1ee2bfe5448 100644 (file)
@@ -106,6 +106,26 @@ void ctdl_p_base(struct http_transaction *h, struct ctdlsession *c) {
 }
 
 
+// DAV delete an uploaded item
+void dav_delete_upload(struct http_transaction *h, struct ctdlsession *c, struct uploaded_file this_one) {
+       int i;
+       struct uploaded_file *u;
+
+       pthread_mutex_lock(&upload_list_mutex);
+       for (i=0; i<array_len(upload_list); ++i) {
+               u = (struct uploaded_file *) array_get_element_at(upload_list, i), sizeof(struct uploaded_file);
+               if (!strcmp(u->id, this_one.id)) {
+                       fclose(u->fp);                          // this deletes the file because it has 0 links
+                       array_delete_element_at(upload_list, i);
+                       i = array_len(upload_list) + 1;         // Go out of scope; we're done here
+               }
+       }
+       pthread_mutex_unlock(&upload_list_mutex);
+
+       do_204(h);
+}
+
+
 // Handle operations on a specific upload
 void specific_upload(struct http_transaction *h, struct ctdlsession *c, char *name) {
        int i;
@@ -137,7 +157,7 @@ void specific_upload(struct http_transaction *h, struct ctdlsession *c, char *na
                do_405(h);
        }
        else if (!strcasecmp(h->method, "DELETE")) {            // delete the item
-               do_405(h);
+               dav_delete_upload(h, c, this_one);
        }
        else {                                                  // unsupported method
                do_405(h);