add support for name/value config args webdav

Tue, 09 Aug 2022 19:01:54 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 09 Aug 2022 19:01:54 +0200
branch
webdav
changeset 367
1592224f6059
parent 366
47bc686fafe4
child 368
69dbcc7e7f93

add support for name/value config args

src/server/config/serverconfig.c file | annotate | diff | comparison | revisions
src/server/daemon/config.c file | annotate | diff | comparison | revisions
--- a/src/server/config/serverconfig.c	Sun Aug 07 13:46:43 2022 +0200
+++ b/src/server/config/serverconfig.c	Tue Aug 09 19:01:54 2022 +0200
@@ -156,6 +156,28 @@
 }
 */
 
+static void config_arg_set_value(UcxAllocator *a, ConfigArg *arg, CFGToken token) {
+    scstr_t nv = scstrchr(token.content, '=');
+    if(!nv.ptr) {
+        arg->value = sstrdup_a(a, token.content);
+    } else {
+        intptr_t eq = (intptr_t)(nv.ptr - token.content.ptr);
+        scstr_t name = token.content;
+        name.length = (size_t)eq;
+        
+        scstr_t value = nv;
+        value.ptr++;
+        value.length--;
+        if(value.length > 1 && value.ptr[0] == '"' && value.ptr[value.length-1] == '"') {
+            value.ptr++;
+            value.length -= 2; // remove quote
+        }
+        
+        arg->name = sstrdup_a(a, name);
+        arg->value = sstrdup_a(a, value);
+    }
+}
+
 ServerConfig* serverconfig_parse(scstr_t content) {
     UcxMempool *mp = ucx_mempool_new(512);
     if(!mp) return NULL;
@@ -259,8 +281,7 @@
                         obj = current;
                     } else {
                         ConfigArg *arg = ucx_mempool_calloc(mp, 1, sizeof(ConfigArg));
-                        // TODO: add support for key/value
-                        arg->value = sstrdup_a(a, token.content);
+                        config_arg_set_value(a, arg, token);
                         current->args = ucx_list_append_a(a, current->args, arg);
                     }
                 }
--- a/src/server/daemon/config.c	Sun Aug 07 13:46:43 2022 +0200
+++ b/src/server/daemon/config.c	Tue Aug 09 19:01:54 2022 +0200
@@ -681,6 +681,27 @@
     UcxAllocator a = util_pool_allocator(cfg->pool);
     int init_error;
     
+    // parse args
+    char *uri = NULL;
+    char *ppath = NULL;
+    char *name = NULL;
+    UCX_FOREACH(elm, obj->args) {
+        ConfigArg *arg = elm->data;
+        if(arg->name.ptr == NULL) {
+            // default: uri
+            uri = arg->value.ptr;
+        } else if(!sstrcasecmp(arg->name, SC("uri"))) {
+            uri = arg->value.ptr;
+        } else if(!sstrcasecmp(arg->name, SC("ppath"))) {
+            ppath = arg->value.ptr;
+        } else if(!sstrcasecmp(arg->name, SC("name"))) {
+            name = arg->value.ptr;
+        }
+    }
+    if(!uri && !ppath && !name) {
+        return 1;
+    }
+    
     // get a list of all DavBackends
     UCX_FOREACH(elm, obj->children) {
         ConfigNode *node = elm->data;

mercurial