Wed, 10 Aug 2022 20:56:24 +0200
add support for named dav repositories in nametrans safs
--- a/src/server/safs/nametrans.c Wed Aug 10 20:32:49 2022 +0200 +++ b/src/server/safs/nametrans.c Wed Aug 10 20:56:24 2022 +0200 @@ -34,8 +34,57 @@ #include "../util/util.h" #include "../public/webdav.h" +#include "../daemon/session.h" +#include "../daemon/config.h" + #include "../public/vfs.h" +static int initialize_dav_repo(pblock *pb, Session *sn, Request *rq, WebdavRepository *repo) { + if(repo->vfs) { + VFS *vfs = repo->vfs->create(sn, rq, pb, repo->vfsInitData); + if(!vfs) { + return REQ_ABORTED; + } + rq->vfs = vfs; + } + + WebdavBackend *backend_first = NULL; + WebdavBackend *backend_last = NULL; + UCX_FOREACH(elm, repo->davBackends) { + WebdavBackendInitData *davInit = elm->data; + WebdavBackend *backend = davInit->davType->create(sn, rq, pb, davInit->davInitData); + if(!backend) { + return REQ_ABORTED; + } + + if(backend_last) { + backend_last->next = backend; + backend_last = backend; + } else { + backend_first = backend; + backend_last = backend; + } + } + rq->davCollection = backend_first; + + return 0; +} + +static int nametrans_set_dav_repository(pblock *pb, Session *sn, Request *rq) { + char *dav = pblock_findkeyval(pb_key_dav, pb); + if(!dav) return 0; + + ServerConfiguration *config = session_get_config(sn); + WebdavRepository *repo = ucx_map_cstr_get(config->dav, dav); + + if(!repo) { + log_ereport(LOG_MISCONFIG, "nametrans: unknown dav repository '%s'", dav); + return REQ_ABORTED; + } + + return initialize_dav_repo(pb, sn, rq, repo); +} + static int nametrans_set_vfs(pblock *pb, Session *sn, Request *rq) { char *vfsclass = pblock_findkeyval(pb_key_vfsclass, pb); if(!vfsclass) return 0; @@ -92,10 +141,18 @@ } } + if(nametrans_set_dav_repository(pb, sn, rq)) { + log_ereport(LOG_FAILURE, "assign-name: cannot create dav repository: name=%s from=%s", name, from); + return REQ_ABORTED; + } if(nametrans_set_vfs(pb, sn, rq)) { log_ereport(LOG_FAILURE, "assign-name: cannot create VFS: name=%s from=%s", name, from); return REQ_ABORTED; } + if(nametrans_set_dav(pb, sn, rq)) { + log_ereport(LOG_FAILURE, "assign-name: cannot create Webdav Backend: name=%s from=%s", name, from); + return REQ_ABORTED; + } // add object to rq->vars pblock_kvinsert(pb_key_name, name, strlen(name), rq->vars); @@ -141,6 +198,7 @@ * from prefix * dir file system directory * name (optional) object name + * dav (optional) dav repository name * vfsclass (optional) vfs name * davclass (optional) dav backend * @@ -184,6 +242,10 @@ uri++; } + if(nametrans_set_dav_repository(pb, sn, rq)) { + log_ereport(LOG_FAILURE, "pfx2dir: cannot create dav repository: from=%s dir=%s name=%s", from, dir, name); + return REQ_ABORTED; + } if(nametrans_set_vfs(pb, sn, rq)) { log_ereport(LOG_FAILURE, "pfx2dir: cannot create VFS: from=%s dir=%s name=%s", from, dir, name); return REQ_ABORTED;
--- a/src/server/util/pblock.cpp Wed Aug 10 20:32:49 2022 +0200 +++ b/src/server/util/pblock.cpp Wed Aug 10 20:56:24 2022 +0200 @@ -327,6 +327,7 @@ const pb_key *const pb_key_depth = _create_key("depth"); const pb_key *const pb_key_if = _create_key("if"); const pb_key *const pb_key_vfs = _create_key("vfs"); +const pb_key *const pb_key_dav = _create_key("dav"); const pb_key *const pb_key_vfsclass = _create_key("vfsclass"); const pb_key *const pb_key_davclass = _create_key("davclass");
--- a/src/server/util/pblock.h Wed Aug 10 20:32:49 2022 +0200 +++ b/src/server/util/pblock.h Wed Aug 10 20:56:24 2022 +0200 @@ -304,6 +304,7 @@ extern const pb_key *const pb_key_depth; extern const pb_key *const pb_key_if; extern const pb_key *const pb_key_vfs; +extern const pb_key *const pb_key_dav; extern const pb_key *const pb_key_vfsclass; extern const pb_key *const pb_key_davclass;