add function for registering webdav backends webdav

Tue, 19 Apr 2022 19:14:49 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 19 Apr 2022 19:14:49 +0200
branch
webdav
changeset 301
2bc514931612
parent 300
0e3f275b2492
child 302
dfbd3a535eac

add function for registering webdav backends

src/server/public/webdav.h file | annotate | diff | comparison | revisions
src/server/webdav/webdav.c file | annotate | diff | comparison | revisions
--- a/src/server/public/webdav.h	Tue Apr 19 18:34:40 2022 +0200
+++ b/src/server/public/webdav.h	Tue Apr 19 19:14:49 2022 +0200
@@ -92,6 +92,8 @@
 #define WS_WEBDAV_PROPPATCH_USE_VFS   0x02
 
 
+typedef WebdavBackend*(*webdav_create_func)(Session *sn, Request *rq, pblock *pb);
+
 enum WebdavValueType {
     WS_VALUE_NO_TYPE = 0,
     WS_VALUE_XML_NODE,
@@ -383,6 +385,11 @@
 };
 
 /*
+ * register a webdav backend
+ */
+int webdav_register_backend(const char *name, webdav_create_func vfsCreate);
+
+/*
  * gets the requested depth
  * 
  * in case of infinity, -1 is returned
--- a/src/server/webdav/webdav.c	Tue Apr 19 18:34:40 2022 +0200
+++ b/src/server/webdav/webdav.c	Tue Apr 19 19:14:49 2022 +0200
@@ -48,8 +48,20 @@
 #include "../daemon/protocol.h"
 #include "../daemon/vfs.h"
 
+/*
+ * http method fptr mapping
+ * key: http method name (string)
+ * value: SAF fptr
+ */
 static UcxMap *method_handler_map;
 
+/*
+ * webdav backend types
+ * key: backend name (string)
+ * value: WebdavBackend*
+ */
+static UcxMap *webdav_type_map;
+
 static WebdavBackend default_backend;
 
 static WSNamespace dav_namespace;
@@ -73,10 +85,23 @@
     default_backend.instance = NULL;
 }
 
+int webdav_register_backend(const char *name, webdav_create_func webdavCreate) {
+    return ucx_map_cstr_put(webdav_type_map, name, webdavCreate);
+}
+
 int webdav_init(pblock *pb, Session *sn, Request *rq) {
-    init_default_backend();
+    webdav_type_map = ucx_map_new(8);
+    if(!webdav_type_map) {
+        return REQ_ABORTED;
+    }
     
     method_handler_map = ucx_map_new(64);
+    if(!method_handler_map) {
+        return REQ_ABORTED;
+    }
+    
+    init_default_backend();
+    ucx_map_cstr_put(webdav_type_map, "default", &default_backend);
     
     ucx_map_cstr_put(method_handler_map, "OPTIONS", webdav_options);
     ucx_map_cstr_put(method_handler_map, "PROPFIND", webdav_propfind);

mercurial