838 } |
838 } |
839 |
839 |
840 // condition depth limit, evaluated in recursive convert_objconf_directives calls |
840 // condition depth limit, evaluated in recursive convert_objconf_directives calls |
841 #define OBJ_CONF_MAX_CONDITION_DEPTH 500 |
841 #define OBJ_CONF_MAX_CONDITION_DEPTH 500 |
842 |
842 |
|
843 static int set_client_condition(pool_handle_t *pool, ConfigNode *node, Condition *condition) { |
|
844 return 0; |
|
845 } |
|
846 |
|
847 static int set_if_condition(pool_handle_t *pool, ConfigNode *node, Condition *condition) { |
|
848 printf("\n"); |
|
849 |
|
850 ConfigParam *token = node->args; |
|
851 while(token) { |
|
852 printf("token: %s %s\n", token->name.ptr, token->value.ptr); |
|
853 token = token->next; |
|
854 } |
|
855 printf("\n"); |
|
856 fflush(stdout); |
|
857 |
|
858 return 0; |
|
859 } |
843 |
860 |
844 // convert a condition |
861 // convert a condition |
845 static Condition* convert_objconf_condition( |
862 static Condition* convert_objconf_condition( |
846 pool_handle_t *pool, |
863 pool_handle_t *pool, |
847 ConfigNode *node, |
864 ConfigNode *node, |
857 return NULL; |
874 return NULL; |
858 } |
875 } |
859 |
876 |
860 // "ElseIf" and "Else" require, that a previous "If" or "ElseIf" node exists |
877 // "ElseIf" and "Else" require, that a previous "If" or "ElseIf" node exists |
861 if((typeindex == 2 || typeindex == 3) && prev_condition == NULL) { |
878 if((typeindex == 2 || typeindex == 3) && prev_condition == NULL) { |
862 return 1; |
879 return NULL; |
863 } |
880 } |
864 Condition *condition = pool_malloc(pool, sizeof(Condition)); |
881 Condition *condition = pool_malloc(pool, sizeof(Condition)); |
865 ZERO(condition, sizeof(Condition)); |
882 ZERO(condition, sizeof(Condition)); |
866 |
883 |
867 condition->index = *condition_index; |
884 condition->index = *condition_index; |
868 condition->parent = parent_condition; |
885 condition->parent = parent_condition; |
869 condition->ifnot = prev_condition; |
886 |
|
887 if(typeindex == 0) { |
|
888 // "Client" |
|
889 if(set_client_condition(pool, node, condition)) { |
|
890 return NULL; |
|
891 } |
|
892 } else { |
|
893 condition->ifnot = prev_condition; |
|
894 |
|
895 // set expression for "If" or "ElseIf" |
|
896 if(typeindex != 4 && set_if_condition(pool, node, condition)) { |
|
897 return NULL; |
|
898 } |
|
899 } |
870 |
900 |
871 (*condition_index)++; |
901 (*condition_index)++; |
872 return condition; |
902 return condition; |
873 } |
903 } |
874 |
904 |
900 return 1; |
930 return 1; |
901 } |
931 } |
902 |
932 |
903 // previous condition is used to link "If" "IfElse" and "Else" |
933 // previous condition is used to link "If" "IfElse" and "Else" |
904 // if the current node is "Else", the if-else block is complete |
934 // if the current node is "Else", the if-else block is complete |
905 // and we don't set prev_condition |
935 // "Client" is unrelated to if-else |
906 //prev_condition = !strcmp(node->name.ptr, "Else") ? NULL : condition; |
936 if(!strcmp(node->name.ptr, "If") || !strcmp(node->name.ptr, "ElseIf")) { |
907 prev_condition = condition; |
937 prev_condition = condition; |
|
938 } else { |
|
939 prev_condition = NULL; |
|
940 } |
908 } else if(node->type == CONFIG_NODE_DIRECTIVE) { |
941 } else if(node->type == CONFIG_NODE_DIRECTIVE) { |
909 directive *d = pool_malloc(pool, sizeof(directive)); |
942 directive *d = pool_malloc(pool, sizeof(directive)); |
910 if(!d) return -1; |
943 if(!d) return -1; |
911 d->param = pblock_create_pool(pool, 8); |
944 d->param = pblock_create_pool(pool, 8); |
912 |
945 |