improve propfind error handling

Wed, 02 Nov 2022 19:19:01 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 02 Nov 2022 19:19:01 +0100
changeset 414
99a34860c105
parent 413
6afaebf003ea
child 415
d938228c382e

improve propfind error handling

src/server/webdav/webdav.c file | annotate | diff | comparison | revisions
--- a/src/server/webdav/webdav.c	Wed Nov 02 19:10:10 2022 +0100
+++ b/src/server/webdav/webdav.c	Wed Nov 02 19:19:01 2022 +0100
@@ -232,6 +232,18 @@
     return REQ_ABORTED;
 }
 
+static const char* propfind_error2str(int error) {
+    switch(error) {
+        case PROPFIND_PARSER_OK: return "ok";
+        case PROPFIND_PARSER_NO_PROPFIND: return "invalid xml root element";
+        case PROPFIND_PARSER_NO_PROPERTIES: return "no properties specified";
+        case PROPFIND_PARSER_INVALID_REQUEST: return "invalid propfind request";
+        case PROPFIND_PARSER_OOM: return "OOM";
+        case PROPFIND_PARSER_ERROR: return "error";
+    }
+    return "";
+}
+
 int webdav_propfind(pblock *pb, Session *sn, Request *rq) {
     char *expect = pblock_findkeyval(pb_key_expect, rq->headers);
     if(expect) {
@@ -247,8 +259,6 @@
         return REQ_ABORTED;
     }
     
-    UcxAllocator *a = session_get_allocator(sn);
-    
     int error = 0;
     WebdavPropfindRequest *propfind = propfind_parse(
             sn,
@@ -258,10 +268,8 @@
             &error);
     ucx_buffer_free(reqbody);
     if(!propfind) {
-        switch(error) {
-            // TODO: handle all errors
-            default: return REQ_ABORTED;
-        }
+        log_ereport(LOG_FAILURE, "webdav-propfind: %s", propfind_error2str(error));
+        return REQ_ABORTED;
     }
     
     WebdavBackend *dav =  rq->davCollection ?
@@ -280,15 +288,15 @@
         return REQ_ABORTED;
     }
     
-    
     int ret = webdav_propfind_do(dav, propfind, (WebdavResponse*)ms, NULL, path, uri);
     
     // if propfind was successful, send the result to the client
-    if(ret == REQ_PROCEED && multistatus_send(ms, sn->csd)) {
-        ret = REQ_ABORTED;
-        // TODO: log error
+    if(ret == REQ_PROCEED) {
+        if(multistatus_send(ms, sn->csd)) {
+            ret = REQ_ABORTED;
+        }
     } else {
-        // TODO: error response
+        log_ereport(LOG_FAILURE, "webdav-propfind: operation failed");
     }
     
     // cleanup

mercurial