extend serverconfig tokenizer to create separate tokens for brackets

Wed, 09 Nov 2022 11:51:19 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 09 Nov 2022 11:51:19 +0100
changeset 422
76f2f5d532d0
parent 421
437562f5681d
child 423
bb7cff720dd0

extend serverconfig tokenizer to create separate tokens for brackets

src/server/config/serverconfig.c file | annotate | diff | comparison | revisions
src/server/daemon/config.c file | annotate | diff | comparison | revisions
src/server/util/object.h file | annotate | diff | comparison | revisions
--- a/src/server/config/serverconfig.c	Wed Nov 09 10:37:52 2022 +0100
+++ b/src/server/config/serverconfig.c	Wed Nov 09 11:51:19 2022 +0100
@@ -155,6 +155,16 @@
             if(token_begin < 0) {
                 token_begin = i;
             }
+        } else if(c == '(' || c == ')') {
+            if(token_begin >= 0) {
+                token_end = i;
+                i--;
+                break;
+            } else {
+                token_begin = i;
+                token_end = i+1;
+                break;
+            }
         } else if(token_begin < 0) {
             token_begin = i;
         }
--- a/src/server/daemon/config.c	Wed Nov 09 10:37:52 2022 +0100
+++ b/src/server/daemon/config.c	Wed Nov 09 11:51:19 2022 +0100
@@ -840,6 +840,23 @@
 // condition depth limit, evaluated in recursive convert_objconf_directives calls
 #define OBJ_CONF_MAX_CONDITION_DEPTH 500
 
+static int set_client_condition(pool_handle_t *pool, ConfigNode *node, Condition *condition) {
+    return 0;
+}
+
+static int set_if_condition(pool_handle_t *pool, ConfigNode *node, Condition *condition) {
+    printf("\n");
+    
+    ConfigParam *token = node->args;
+    while(token) {
+        printf("token: %s  %s\n", token->name.ptr, token->value.ptr);
+        token = token->next;
+    }
+    printf("\n");
+    fflush(stdout);
+    
+    return 0;
+}
 
 // convert a condition 
 static Condition* convert_objconf_condition(
@@ -859,14 +876,27 @@
     
     // "ElseIf" and "Else" require, that a previous "If" or "ElseIf" node exists
     if((typeindex == 2 || typeindex == 3) && prev_condition == NULL) {
-        return 1;
+        return NULL;
     }
     Condition *condition = pool_malloc(pool, sizeof(Condition));
     ZERO(condition, sizeof(Condition));
     
     condition->index = *condition_index;
     condition->parent = parent_condition;
-    condition->ifnot = prev_condition;
+    
+    if(typeindex == 0) {
+        // "Client"
+        if(set_client_condition(pool, node, condition)) {
+            return NULL;
+        }
+    } else {
+        condition->ifnot = prev_condition;
+        
+        // set expression for "If" or "ElseIf"
+        if(typeindex != 4 && set_if_condition(pool, node, condition)) {
+            return NULL;
+        }
+    }
     
     (*condition_index)++;
     return condition;
@@ -902,9 +932,12 @@
             
             // previous condition is used to link "If" "IfElse" and "Else"
             // if the current node is "Else", the if-else block is complete
-            // and we don't set prev_condition
-            //prev_condition = !strcmp(node->name.ptr, "Else") ? NULL :  condition;
-            prev_condition = condition;
+            // "Client" is unrelated to if-else
+            if(!strcmp(node->name.ptr, "If") || !strcmp(node->name.ptr, "ElseIf")) {
+                prev_condition = condition;
+            } else {
+                prev_condition = NULL;
+            }
         } else if(node->type == CONFIG_NODE_DIRECTIVE) {
             directive *d = pool_malloc(pool, sizeof(directive));
             if(!d) return -1;
--- a/src/server/util/object.h	Wed Nov 09 10:37:52 2022 +0100
+++ b/src/server/util/object.h	Wed Nov 09 11:51:19 2022 +0100
@@ -86,11 +86,11 @@
 };
 
 struct Condition {
-    Condition  *parent;
-    Condition  *ifnot;
-    Expression *expression;
-    int        depth;
-    int        index; // used by NSAPIContext to link expression with result
+    Condition       *parent;
+    Condition       *ifnot;
+    Expression      *expression;
+    int             depth;
+    int             index; // used by NSAPIContext to link expression with result
 };
 
 struct Expression {

mercurial