# HG changeset patch # User Olaf Wintermann # Date 1643382065 -3600 # Node ID 7608af69739f2e74f9503b641bb2cb949af2476c # Parent 0cb4eda146c4564a17f01cb9e9c7b110ba78c548 add support for vfsclass parameter in nametrans safs diff -r 0cb4eda146c4 -r 7608af69739f src/server/daemon/vfs.c --- a/src/server/daemon/vfs.c Fri Jan 28 15:44:30 2022 +0100 +++ b/src/server/daemon/vfs.c Fri Jan 28 16:01:05 2022 +0100 @@ -97,6 +97,17 @@ return ucx_map_cstr_put(vfs_type_map, name, vfsCreate); } + +VFS* vfs_create(Session *sn, Request *rq, const char *vfs_class, pblock *pb) { + vfs_create_func createVFS = ucx_map_cstr_get(vfs_type_map, vfs_class); + if(!createVFS) { + log_ereport(LOG_MISCONFIG, "vfs_create: unkown VFS type %s", vfs_class); + return NULL; + } + + return createVFS(sn, rq, pb); +} + VFSContext* vfs_request_context(Session *sn, Request *rq) { WS_ASSERT(sn); WS_ASSERT(rq); diff -r 0cb4eda146c4 -r 7608af69739f src/server/public/vfs.h --- a/src/server/public/vfs.h Fri Jan 28 15:44:30 2022 +0100 +++ b/src/server/public/vfs.h Fri Jan 28 16:01:05 2022 +0100 @@ -116,6 +116,11 @@ int vfs_register_type(const char *name, vfs_create_func vfsCreate); /* + * Create a new VFS instance + */ +VFS* vfs_create(Session *sn, Request *rq, const char *vfs_class, pblock *pb); + +/* * creates a VFSContext for a Request * vfs calls will do ACL checks */ diff -r 0cb4eda146c4 -r 7608af69739f src/server/safs/nametrans.c --- a/src/server/safs/nametrans.c Fri Jan 28 15:44:30 2022 +0100 +++ b/src/server/safs/nametrans.c Fri Jan 28 16:01:05 2022 +0100 @@ -33,6 +33,20 @@ #include "../util/pblock.h" #include "../util/util.h" +#include "../public/vfs.h" + +static int nametrans_set_vfs(pblock *pb, Session *sn, Request *rq) { + char *vfsclass = pblock_findkeyval(pb_key_vfsclass, pb); + if(!vfsclass) return 0; + + VFS *vfs = vfs_create(sn, rq, vfsclass, pb); + if(!vfs) { + return 1; + } + rq->vfs = vfs; + return 0; +} + /* * assign_name * @@ -66,6 +80,11 @@ i++; } } + + 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; + } // add object to rq->vars pblock_kvinsert(pb_key_name, name, strlen(name), rq->vars); @@ -89,6 +108,11 @@ return REQ_ABORTED; } + if(nametrans_set_vfs(pb, sn, rq)) { + log_ereport(LOG_FAILURE, "document-root: cannot create VFS"); + return REQ_ABORTED; + } + sstr_t root_str = sstr(root); sstr_t uri_str = sstr(pblock_findkeyval(pb_key_uri, rq->reqpb)); @@ -147,6 +171,11 @@ uri++; } + 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; + } + request_set_path(sstr(dir), sstr(uri), rq->vars); if(name) { @@ -192,6 +221,11 @@ return REQ_ABORTED; } + if(nametrans_set_vfs(pb, sn, rq)) { + log_ereport(LOG_FAILURE, "simple-rewrite: cannot create VFS: from=%s root=%s path=%s name=%s", from, root, path, name); + return REQ_ABORTED; + } + char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb); sstr_t u = sstr(uri); sstr_t f = sstr(from); diff -r 0cb4eda146c4 -r 7608af69739f src/server/util/pblock.cpp --- a/src/server/util/pblock.cpp Fri Jan 28 15:44:30 2022 +0100 +++ b/src/server/util/pblock.cpp Fri Jan 28 16:01:05 2022 +0100 @@ -326,6 +326,8 @@ const pb_key *const pb_key_warning = _create_key("warning"); 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_vfsclass = _create_key("vfsclass"); /* ------------------------------ _find_key ------------------------------- */ diff -r 0cb4eda146c4 -r 7608af69739f src/server/util/pblock.h --- a/src/server/util/pblock.h Fri Jan 28 15:44:30 2022 +0100 +++ b/src/server/util/pblock.h Fri Jan 28 16:01:05 2022 +0100 @@ -303,6 +303,8 @@ extern const pb_key *const pb_key_warning; 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_vfsclass; NSAPI_PUBLIC pool_handle_t *pblock_pool(pblock *pb);