]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
move XLAT_ALTERNATE children to type-specific fields
authorAlan T. DeKok <aland@freeradius.org>
Wed, 20 Apr 2022 14:47:22 +0000 (10:47 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 20 Apr 2022 14:51:12 +0000 (10:51 -0400)
src/lib/unlang/xlat_eval.c
src/lib/unlang/xlat_priv.h
src/lib/unlang/xlat_tokenize.c

index 2ccd2fc09d6e392897e21dc3c408755129ec9804..650c4812abdd1a8547c178e6c97ba5f0e278e108 100644 (file)
@@ -174,8 +174,8 @@ static char *xlat_fmt_aprint(TALLOC_CTX *ctx, xlat_exp_t const *node)
        {
                char *first, *second, *result;
 
-               first = xlat_fmt_aprint(NULL, node->child);
-               second = xlat_fmt_aprint(NULL, node->alternate);
+               first = xlat_fmt_aprint(NULL, node->alternate[0]);
+               second = xlat_fmt_aprint(NULL, node->alternate[1]);
                result = talloc_asprintf(ctx, "%%{%s:-%s}", first, second);
                talloc_free(first);
                talloc_free(second);
@@ -1106,8 +1106,8 @@ xlat_action_t xlat_frame_eval_repeat(TALLOC_CTX *ctx, fr_dcursor_t *out,
                        }
 
                        XLAT_DEBUG("** [%i] %s(alt-first) - string empty, evaluating alternate: %s",
-                                  unlang_interpret_stack_depth(request), __FUNCTION__, (*in)->alternate->fmt);
-                       *child = (*in)->alternate;
+                                  unlang_interpret_stack_depth(request), __FUNCTION__, (*in)->alternate[1]->fmt);
+                       *child = (*in)->alternate[1];
                        *alternate = true;
 
                        return XLAT_ACTION_PUSH_CHILD;
@@ -1328,11 +1328,12 @@ xlat_action_t xlat_frame_eval(TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_exp_t con
 
                case XLAT_ALTERNATE:
                        XLAT_DEBUG("** [%i] %s(alternate) - %%{%%{%s}:-%%{%s}}", unlang_interpret_stack_depth(request),
-                                  __FUNCTION__, node->child->fmt, node->alternate->fmt);
-                       fr_assert(node->child != NULL);
-                       fr_assert(node->alternate != NULL);
+                                  __FUNCTION__, node->alternate[0]->fmt, node->alternate[1]->fmt);
+                       fr_assert(node->child == NULL);
+                       fr_assert(node->alternate[0] != NULL);
+                       fr_assert(node->alternate[1] != NULL);
 
-                       *child = node->child;
+                       *child = node->alternate[0];
                        xa = XLAT_ACTION_PUSH_CHILD;
                        goto finish;
 
@@ -1721,13 +1722,13 @@ int xlat_eval_walk(xlat_exp_t *exp, xlat_walker_t walker, xlat_type_t type, void
                        /*
                         *      Evaluate the first child
                         */
-                       ret = xlat_eval_walk(node->child, walker, type, uctx);
+                       ret = xlat_eval_walk(node->alternate[0], walker, type, uctx);
                        if (ret < 0) return ret;
 
                        /*
                         *      Evaluate the alternate expansion path
                         */
-                       ret = xlat_eval_walk(node->alternate, walker, type, uctx);
+                       ret = xlat_eval_walk(node->alternate[1], walker, type, uctx);
                        if (ret < 0) return ret;
                        break;
 
index 467a3f244e2baf99b775a624212c24502a9f5c34..4268ec6c46c83ceb85be1b8c7bd5f95f79fe9a83 100644 (file)
@@ -124,7 +124,7 @@ struct xlat_exp {
        xlat_exp_t      *child;         //!< Nested expansion, i.e. arguments for an xlat function.
 
        union {
-               xlat_exp_t      *alternate;     //!< Alternative expansion if this expansion produced no values.
+               xlat_exp_t      *alternate[2];  //!< alternate expansions
 
                /** An tmpl_t reference
                 *
index 08efe6be74cdaf5d64c1547fb1c5d3f483be1d3b..74c5bd542ed2f59ea0182b25b405bffb148cdf65 100644 (file)
@@ -183,14 +183,14 @@ static inline int xlat_tokenize_alternation(TALLOC_CTX *ctx, xlat_exp_t **head,
        xlat_exp_set_type(node, XLAT_ALTERNATE);
 
        if (func_args) {
-               if (xlat_tokenize_function_args(node, &node->child, &node->flags, in, t_rules) < 0) {
+               if (xlat_tokenize_function_args(node, &node->alternate[0], &node->flags, in, t_rules) < 0) {
                error:
                        *head = NULL;
                        talloc_free(node);
                        return -1;
                }
        } else {
-               if (xlat_tokenize_expansion(node, &node->child, &node->flags, in, t_rules) < 0) goto error;
+               if (xlat_tokenize_expansion(node, &node->alternate[0], &node->flags, in, t_rules) < 0) goto error;
        }
 
        if (!fr_sbuff_adv_past_str_literal(in, ":-")) {
@@ -202,8 +202,8 @@ static inline int xlat_tokenize_alternation(TALLOC_CTX *ctx, xlat_exp_t **head,
         *      Allow the RHS to be empty as a special case.
         */
        if (fr_sbuff_next_if_char(in, '}')) {
-               node->alternate = xlat_exp_alloc(node, XLAT_BOX, "", 0);
-               xlat_flags_merge(&node->flags, &node->child->flags);
+               node->alternate[1] = xlat_exp_alloc(node, XLAT_BOX, "", 0);
+               xlat_flags_merge(&node->flags, &node->alternate[1]->flags);
                *head = node;
                return 0;
        }
@@ -211,10 +211,10 @@ static inline int xlat_tokenize_alternation(TALLOC_CTX *ctx, xlat_exp_t **head,
        /*
         *      Parse the alternate expansion.
         */
-       if (xlat_tokenize_string(node, &node->alternate, &node->flags, in,
+       if (xlat_tokenize_string(node, &node->alternate[1], &node->flags, in,
                                  true, &xlat_expansion_rules, t_rules) < 0) goto error;
 
-       if (!node->alternate) {
+       if (!node->alternate[1]) {
                talloc_free(node);
                fr_strerror_const("Empty expansion is invalid");
                goto error;
@@ -1119,11 +1119,12 @@ static void _xlat_debug(xlat_exp_t const *node, int depth)
 #endif
 
                case XLAT_ALTERNATE:
+                       fr_assert(node->child == NULL);
                        DEBUG("XLAT-IF {");
-                       _xlat_debug(node->child, depth + 1);
+                       _xlat_debug(node->alternate[0], depth + 1);
                        DEBUG("}");
                        DEBUG("XLAT-ELSE {");
-                       _xlat_debug(node->alternate, depth + 1);
+                       _xlat_debug(node->alternate[1], depth + 1);
                        DEBUG("}");
                        break;
 
@@ -1259,11 +1260,11 @@ ssize_t xlat_print_node(fr_sbuff_t *out, xlat_exp_t const *head, fr_sbuff_escape
                break;
 
        case XLAT_ALTERNATE:
-               slen = xlat_print(out, node->child, &xlat_escape);
+               slen = xlat_print(out, node->alternate[0], &xlat_escape);
                if (slen < 0) goto error;
 
                FR_SBUFF_IN_STRCPY_LITERAL_RETURN(out, ":-");
-               slen = xlat_print(out, node->alternate, &xlat_escape);
+               slen = xlat_print(out, node->alternate[1], &xlat_escape);
                if (slen < 0) goto error;
                break;
 
@@ -1687,8 +1688,8 @@ int xlat_resolve(xlat_exp_t **head, xlat_flags_t *flags, xlat_res_rules_t const
                {
                        xlat_flags_t    child_flags = node->flags, alt_flags = node->flags;
 
-                       if ((xlat_resolve(&node->child, &child_flags, xr_rules) < 0) ||
-                           (xlat_resolve(&node->alternate, &alt_flags, xr_rules) < 0)) return -1;
+                       if ((xlat_resolve(&node->alternate[0], &child_flags, xr_rules) < 0) ||
+                           (xlat_resolve(&node->alternate[1], &alt_flags, xr_rules) < 0)) return -1;
 
                        xlat_flags_merge(&child_flags, &alt_flags);
                        node->flags = child_flags;
@@ -2007,7 +2008,8 @@ int xlat_copy(TALLOC_CTX *ctx, xlat_exp_t **out, xlat_exp_t const *in)
 #endif
 
                case XLAT_ALTERNATE:
-                       if (unlikely(xlat_copy(node, &node->alternate, p->alternate) < 0)) goto error;
+                       if (unlikely(xlat_copy(node, &node->alternate[0], p->alternate[0]) < 0)) goto error;
+                       if (unlikely(xlat_copy(node, &node->alternate[1], p->alternate[1]) < 0)) goto error;
                        break;
 
                case XLAT_GROUP: