src/server/config/serverconfig.c

branch
webdav
changeset 367
1592224f6059
parent 366
47bc686fafe4
child 415
d938228c382e
--- 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);
                     }
                 }

mercurial