move backend initialization to new function webdav

Sun, 29 Dec 2019 21:06:02 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 29 Dec 2019 21:06:02 +0100
branch
webdav
changeset 213
4a6be4f10d5f
parent 212
d7e7ea9c6bc6
child 214
4d7ac67a1c14

move backend initialization to new function

src/server/test/webdav.h file | annotate | diff | comparison | revisions
src/server/webdav/webdav.c file | annotate | diff | comparison | revisions
src/server/webdav/webdav.h file | annotate | diff | comparison | revisions
--- a/src/server/test/webdav.h	Sun Dec 29 15:09:58 2019 +0100
+++ b/src/server/test/webdav.h	Sun Dec 29 21:06:02 2019 +0100
@@ -46,6 +46,8 @@
 
 UCX_TEST(test_msresponse_addproperty);
 
+UCX_TEST(test_msresponse_addproperty);
+
 /* --------------------------- PROPFIND --------------------------- */
 
 #define TEST_PROPFIND1 "<?xml version=\"1.0\" encoding=\"utf-8\" ?> \
--- a/src/server/webdav/webdav.c	Sun Dec 29 15:09:58 2019 +0100
+++ b/src/server/webdav/webdav.c	Sun Dec 29 21:06:02 2019 +0100
@@ -199,51 +199,15 @@
     // requested uri path
     char *path = pblock_findkeyval(pb_key_path, rq->vars);
     
-    // Initialize WebDAV Backend Chain
-    //
-    // Call propfind_init of each Backend
-    // propfind_init can return a new property list, which
-    // will be passed to the next backend
-    //
     // VFS settings are only taken from the first backend
     uint32_t settings = dav->settings;
     
     // list of individual WebdavPropfindRequest objects for each Backend
-    UcxList *backendPropfind = NULL;
-    
-    // new properties after init, start with clone of original plist
-    WebdavPList *newProp = webdav_plist_clone(sn->pool, propfind->properties);
-    size_t newPropCount = propfind->propcount;
+    UcxList *requestObjects = NULL;
     
-    WebdavBackend *davList = dav;
-    while(davList) {
-        // create WebdavPropfindRequest copy
-        WebdavPropfindRequest *pReq = pool_malloc(
-                sn->pool,
-                sizeof(WebdavPropfindRequest));
-        memcpy(propfind, pReq, sizeof(WebdavPropfindRequest));
-        // use new plist after previous init (or orig. plist in the first run)
-        pReq->properties = newProp;
-        pReq->propcount = newPropCount;
-        
-        // add new WebdavPropfindRequest object to list for later use
-        backendPropfind = ucx_list_append_a(a, backendPropfind, pReq);
-        if(!backendPropfind) {
-            return REQ_ABORTED; // OOM
-        }
-        
-        // create plist copy as out-plist for init
-        newProp = webdav_plist_clone(sn->pool, newProp);
-        
-        // run init: this can generate a new properties list (newProp)
-        //           which will be passed to the next backend
-        if(dav->propfind_init(pReq, path, &newProp)) {
-            return REQ_ABORTED;
-        }
-        
-        newPropCount = webdav_plist_count(newProp);
-        
-        davList = davList->next;
+    // Initialize all Webdav Backends
+    if(webdav_propfind_init(dav, propfind, path, &requestObjects)) {
+        return REQ_ABORTED;
     }
     
     // some Backends can list all children by themselves, but some
@@ -271,7 +235,7 @@
     }
     
     int ret = REQ_ABORTED;
-    if(!webdav_propfind_do(dav, backendPropfind, response, NULL, path, statptr)) {
+    if(!webdav_propfind_do(dav, requestObjects, response, NULL, path, statptr)) {
         // propfind for the requested resource was successful
         
         // usevfsdir is TRUE if
@@ -279,7 +243,7 @@
         //   the file is a directory
         //   depth is not 0
         // in this case we need to execute propfind_do for all children
-        if(usevfs && !propfind_children(dav, backendPropfind, response, vfs, path)) {
+        if(usevfs && !propfind_children(dav, requestObjects, response, vfs, path)) {
             ret = REQ_PROCEED;
         }
     }
@@ -295,6 +259,68 @@
 }
 
 /*
+ * Initializes Backend Chain
+ * 
+ * Calls propfind_init of each Backend and generates a list of custom
+ * WebdavPropfindRequest objects for each backend
+ */
+int webdav_propfind_init(
+        WebdavBackend *dav,
+        WebdavPropfindRequest *propfind,
+        const char *path,
+        UcxList **out_req)
+{   
+    pool_handle_t *pool = propfind->sn->pool;
+    UcxAllocator *a = session_get_allocator(propfind->sn);
+    
+    // list of individual WebdavPropfindRequest objects for each Backend
+    UcxList *requestObjects = NULL;
+    
+    // new properties after init, start with clone of original plist
+    WebdavPList *newProp = webdav_plist_clone(pool, propfind->properties);
+    size_t newPropCount = propfind->propcount;
+    
+    // Call propfind_init for each Backend
+    // propfind_init can return a new property list, which
+    // will be passed to the next backend
+
+    WebdavBackend *davList = dav;
+    while(davList) {
+        // create WebdavPropfindRequest copy
+        WebdavPropfindRequest *pReq = pool_malloc(
+                pool,
+                sizeof(WebdavPropfindRequest));
+        memcpy(propfind, pReq, sizeof(WebdavPropfindRequest));
+        // use new plist after previous init (or orig. plist in the first run)
+        pReq->properties = newProp;
+        pReq->propcount = newPropCount;
+        
+        // add new WebdavPropfindRequest object to list for later use
+        requestObjects = ucx_list_append_a(a, requestObjects, pReq);
+        if(!requestObjects) {
+            return REQ_ABORTED; // OOM
+        }
+        
+        // create plist copy as out-plist for init
+        newProp = webdav_plist_clone(pool, newProp);
+        
+        // run init: this can generate a new properties list (newProp)
+        //           which will be passed to the next backend
+        if(dav->propfind_init(pReq, path, &newProp)) {
+            return REQ_ABORTED;
+        }
+        
+        newPropCount = webdav_plist_count(newProp);
+        
+        davList = davList->next;
+    }
+    
+    *out_req = requestObjects;
+    return REQ_PROCEED;
+}
+
+
+/*
  * Executes propfind_do for each Backend
  * The list requests must contain all WebdavPropfindRequest objects
  * of all backends
--- a/src/server/webdav/webdav.h	Sun Dec 29 15:09:58 2019 +0100
+++ b/src/server/webdav/webdav.h	Sun Dec 29 21:06:02 2019 +0100
@@ -62,6 +62,12 @@
 
 int webdav_propfind(pblock *pb, Session *sn, Request *rq);
 
+int webdav_propfind_init(
+        WebdavBackend *dav,
+        WebdavPropfindRequest *propfind,
+        const char *path,
+        UcxList **out_req);
+
 int webdav_propfind_do(
         WebdavBackend *webdav,
         UcxList *requests,

mercurial