# HG changeset patch # User Olaf Wintermann # Date 1577649962 -3600 # Node ID 4a6be4f10d5f50d9313d609da6e6a685185830ff # Parent d7e7ea9c6bc65a9a4261a58915b37e5a122cd6f9 move backend initialization to new function diff -r d7e7ea9c6bc6 -r 4a6be4f10d5f src/server/test/webdav.h --- 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 " \ diff -r d7e7ea9c6bc6 -r 4a6be4f10d5f src/server/webdav/webdav.c --- 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 diff -r d7e7ea9c6bc6 -r 4a6be4f10d5f src/server/webdav/webdav.h --- 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,