fix webdav mkcol error status codes

Sun, 09 Jul 2023 15:14:26 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 09 Jul 2023 15:14:26 +0200
changeset 503
aeaf7db26fac
parent 502
11ac3761c0e3
child 504
c094afcdfb27

fix webdav mkcol error status codes

src/server/daemon/event_bsd.c file | annotate | diff | comparison | revisions
src/server/safs/cgi.c file | annotate | diff | comparison | revisions
src/server/webdav/operation.c file | annotate | diff | comparison | revisions
--- a/src/server/daemon/event_bsd.c	Sun Jun 11 15:53:55 2023 +0200
+++ b/src/server/daemon/event_bsd.c	Sun Jul 09 15:14:26 2023 +0200
@@ -157,7 +157,7 @@
     int r1 = kevent(h->kqueue, &kev, 1, NULL, 0, NULL);
     EV_SET(&kev, fd, EVFILT_WRITE, EV_DELETE, 0, 0, NULL);
     int r2 = kevent(h->kqueue, &kev, 1, NULL, 0, NULL);
-    // in caase r1 or r2 was successful, we return 0 (no error)
+    // in case r1 or r2 was successful, we return 0 (no error)
     return r1 != -1 || r2 != -1 ? 0 : 1;
 }
 
--- a/src/server/safs/cgi.c	Sun Jun 11 15:53:55 2023 +0200
+++ b/src/server/safs/cgi.c	Sun Jul 09 15:14:26 2023 +0200
@@ -57,6 +57,8 @@
     char *ctlen = pblock_findkeyval(pb_key_content_length, rq->headers);
     int64_t content_length = 0;
     
+    log_ereport(LOG_DEBUG, "cgi-send: path: %s content-length: %s", path, ctlen);
+    
     if(ctlen) {
         if(!util_strtoint(ctlen, &content_length)) {
             log_ereport(
--- a/src/server/webdav/operation.c	Sun Jun 11 15:53:55 2023 +0200
+++ b/src/server/webdav/operation.c	Sun Jul 09 15:14:26 2023 +0200
@@ -733,6 +733,24 @@
         int r = 0;
         if(type == WEBDAV_VFS_MKDIR) {
             r = vfs_mkdir(op->vfs, op->path);
+            if(r) {
+                // mkcol specific status codes
+                switch(op->vfs->vfs_errno) {
+                    case ENOENT: {
+                        op->rq->status_num = 409;
+                        break;
+                    }
+                    case EEXIST: {
+                        op->rq->status_num = 405;
+                        break;
+                    }
+                    case EACCES: {
+                        op->rq->status_num = 403;
+                        break;
+                    }
+                    default: op->rq->status_num = 500;
+                }
+            }
         } else if(type == WEBDAV_VFS_DELETE) {
             r = webdav_vfs_unlink(op);
         }

mercurial