add davclass parameter to pfx2dir for setting the webdav backend webdav

Mon, 02 May 2022 11:29:15 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 02 May 2022 11:29:15 +0200
branch
webdav
changeset 325
2d14055c3543
parent 324
44cf877b3d9f
child 326
814b94f820db

add davclass parameter to pfx2dir for setting the webdav backend

src/server/plugins/postgresql/init.c file | annotate | diff | comparison | revisions
src/server/plugins/postgresql/init.h file | annotate | diff | comparison | revisions
src/server/public/webdav.h file | annotate | diff | comparison | revisions
src/server/safs/nametrans.c file | annotate | diff | comparison | revisions
src/server/util/pblock.cpp file | annotate | diff | comparison | revisions
src/server/util/pblock.h file | annotate | diff | comparison | revisions
src/server/webdav/webdav.c file | annotate | diff | comparison | revisions
--- a/src/server/plugins/postgresql/init.c	Sun May 01 12:33:48 2022 +0200
+++ b/src/server/plugins/postgresql/init.c	Mon May 02 11:29:15 2022 +0200
@@ -43,6 +43,11 @@
         return REQ_ABORTED;
     }
     
+    if(pg_register_webdav_backend(pb)) {
+        log_ereport(LOG_FAILURE, "pg-init: Cannot register dav type");
+        return REQ_ABORTED;
+    }
+    
     return REQ_PROCEED;
 }
 
--- a/src/server/plugins/postgresql/init.h	Sun May 01 12:33:48 2022 +0200
+++ b/src/server/plugins/postgresql/init.h	Mon May 02 11:29:15 2022 +0200
@@ -41,6 +41,8 @@
 
 int pg_register_vfs(pblock *pb);
 
+int pg_register_webdav_backend(pblock *pb);
+
 
 #ifdef __cplusplus
 }
--- a/src/server/public/webdav.h	Sun May 01 12:33:48 2022 +0200
+++ b/src/server/public/webdav.h	Mon May 02 11:29:15 2022 +0200
@@ -394,6 +394,8 @@
  */
 int webdav_register_backend(const char *name, webdav_create_func vfsCreate);
 
+WebdavBackend* webdav_create(Session *sn, Request *rq, const char *dav_class, pblock *pb);
+
 /*
  * gets the requested depth
  * 
--- a/src/server/safs/nametrans.c	Sun May 01 12:33:48 2022 +0200
+++ b/src/server/safs/nametrans.c	Mon May 02 11:29:15 2022 +0200
@@ -32,6 +32,7 @@
 #include "../daemon/request.h"
 #include "../util/pblock.h"
 #include "../util/util.h"
+#include "../public/webdav.h"
 
 #include "../public/vfs.h"
 
@@ -47,6 +48,16 @@
     return 0;
 }
 
+static int nametrans_set_dav(pblock *pb, Session *sn, Request *rq) {
+    char *davclass = pblock_findkeyval(pb_key_davclass, pb);
+    if(!davclass) return 0;
+    
+    WebdavBackend *dav = webdav_create(sn, rq, davclass, pb);
+    
+    rq->davCollection = dav;
+    return 0;
+}
+
 /*
  * assign_name
  *
@@ -130,6 +141,8 @@
  * from     prefix
  * dir      file system directory
  * name     (optional) object name
+ * vfsclass (optional) vfs name
+ * davclass (optional) dav backend
  * 
  */
 int pfx2dir(pblock *pb, Session *sn, Request *rq) {
@@ -175,6 +188,10 @@
         log_ereport(LOG_FAILURE, "pfx2dir: cannot create VFS: from=%s dir=%s name=%s", from, dir, name);
         return REQ_ABORTED;
     }
+    if(nametrans_set_dav(pb, sn, rq)) {
+        log_ereport(LOG_FAILURE, "pfx2dir: cannot create Webdav Backend: from=%s dir=%s name=%s", from, dir, name);
+        return REQ_ABORTED;
+    }
     
     request_set_path(sstr(dir), sstr(uri), rq->vars);
     
--- a/src/server/util/pblock.cpp	Sun May 01 12:33:48 2022 +0200
+++ b/src/server/util/pblock.cpp	Mon May 02 11:29:15 2022 +0200
@@ -328,6 +328,7 @@
 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");
+const pb_key *const pb_key_davclass = _create_key("davclass");
 
 /* ------------------------------ _find_key ------------------------------- */
 
--- a/src/server/util/pblock.h	Sun May 01 12:33:48 2022 +0200
+++ b/src/server/util/pblock.h	Mon May 02 11:29:15 2022 +0200
@@ -305,6 +305,7 @@
 extern const pb_key *const pb_key_if;
 extern const pb_key *const pb_key_vfs;
 extern const pb_key *const pb_key_vfsclass;
+extern const pb_key *const pb_key_davclass;
 
 NSAPI_PUBLIC pool_handle_t *pblock_pool(pblock *pb);
 
--- a/src/server/webdav/webdav.c	Sun May 01 12:33:48 2022 +0200
+++ b/src/server/webdav/webdav.c	Mon May 02 11:29:15 2022 +0200
@@ -89,6 +89,17 @@
     return ucx_map_cstr_put(webdav_type_map, name, webdavCreate);
 }
 
+
+WebdavBackend* webdav_create(Session *sn, Request *rq, const char *dav_class, pblock *pb) {
+    webdav_create_func createDav = ucx_map_cstr_get(webdav_type_map, dav_class);
+    if(!createDav) {
+        log_ereport(LOG_MISCONFIG, "webdav_create: unkown dav type %s", dav_class);
+        return NULL;
+    }
+    
+    return createDav(sn, rq, pb);
+}
+
 static WSBool webdav_is_initialized = FALSE;
 
 int webdav_init(pblock *pb, Session *sn, Request *rq) {

mercurial