src/server/daemon/config.c

changeset 423
bb7cff720dd0
parent 422
76f2f5d532d0
child 426
6a2e7a464991
--- a/src/server/daemon/config.c	Wed Nov 09 11:51:19 2022 +0100
+++ b/src/server/daemon/config.c	Sat Nov 12 11:01:11 2022 +0100
@@ -844,18 +844,40 @@
     return 0;
 }
 
-static int set_if_condition(pool_handle_t *pool, ConfigNode *node, Condition *condition) {
-    printf("\n");
+static int set_if_condition(pool_handle_t *pool, ConfigNode *node, Condition *condition) { 
+    // convert to parameters to a list of tokens
+    // usually, one parameter is one token, however the config parser
+    // converts name=value pairs to one ConfigParam
     
-    ConfigParam *token = node->args;
-    while(token) {
-        printf("token: %s  %s\n", token->name.ptr, token->value.ptr);
-        token = token->next;
+    // list of cxmutstr, however the expression parser will use this
+    // as list of cxstring, but that is totally fine
+    CxList *tokens = cxLinkedListCreate(pool_allocator(pool), cx_cmp_ptr, sizeof(cxmutstr));
+    ConfigParam *arg = node->args;
+    while(arg) {
+        if(arg->name.length > 0) {
+            // arg text is name=value, therefore we add 3 tokens
+            // name, "=", value
+            cxListAdd(tokens, &arg->name);
+            cxmutstr op = (cxmutstr){ "=", 1 };
+            cxListAdd(tokens, &op);
+        }
+        if(cxListAdd(tokens, &arg->value)) {
+            cxListDestroy(tokens);
+            return 1; // OOM
+        }
+        arg = arg->next;
     }
-    printf("\n");
-    fflush(stdout);
     
-    return 0;
+    int ret = 0;
+    condition->expression = condition_create(pool, tokens);
+    if(!condition->expression) {
+        ret = 1;
+    }
+    
+    // don't need the token list anymore
+    cxListDestroy(tokens);
+    
+    return ret;
 }
 
 // convert a condition 

mercurial