]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add and set "constant" flag for xlat
authorAlan T. DeKok <aland@freeradius.org>
Fri, 16 Sep 2022 01:12:34 +0000 (21:12 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 16 Sep 2022 01:33:17 +0000 (21:33 -0400)
so that we can suppress printing xlat expansions for XLAT_BOX
and tmpl_t's which are data.  It's confusing to see

EXPAND 4
  ---> 4

src/lib/unlang/xlat.h
src/lib/unlang/xlat_expr.c
src/lib/unlang/xlat_priv.h
src/lib/unlang/xlat_tokenize.c

index fbfb5a24f4f756ec9ff47c9dccb52ead6643f61b..0d98d6aa5d342f544b9002fea38140046decb5f8 100644 (file)
@@ -108,6 +108,8 @@ typedef struct {
                                                ///< require asynchronous expansion.
        bool                    pure;           //!< has no external side effects, true for BOX, LITERAL, and some functions
        bool                    can_purify;     //!< if the xlat has a pure function with pure arguments.
+
+       bool                    constant;       //!< xlat is just tmpl_data, or XLAT_BOX
 } xlat_flags_t;
 
 /*
index c9d73b58a3e1100a8b4e22ce08194de5268f6012..e69a7eae847368f074a44c5413acaebb28ea12b8 100644 (file)
@@ -299,6 +299,7 @@ static int xlat_expr_resolve_binary(xlat_exp_t *node, UNUSED void *inst, xlat_re
 
                b->flags.needs_resolving = false;
                b->flags.pure = tmpl_is_data(b->vpt);
+               b->flags.constant = b->flags.pure;
                goto flags;
        }
 
@@ -318,7 +319,8 @@ static int xlat_expr_resolve_binary(xlat_exp_t *node, UNUSED void *inst, xlat_re
                if (tmpl_resolve(a->vpt, &my_tr_rules) < 0) return -1;
 
                a->flags.needs_resolving = false;
-               a->flags.pure = tmpl_is_data(b->vpt);
+               a->flags.pure = tmpl_is_data(a->vpt);
+               a->flags.constant = a->flags.pure;
                goto flags;
        }
 
@@ -927,7 +929,7 @@ check:
 
        parent->type = XLAT_BOX;
        fr_value_box_copy(parent, &parent->data, box);
-       parent->flags = (xlat_flags_t) { .pure = true, };
+       parent->flags = (xlat_flags_t) { .pure = true, .constant = true, };
 
        talloc_free_children(parent);
 
@@ -1997,6 +1999,7 @@ static xlat_exp_t *expr_cast_alloc(TALLOC_CTX *ctx, fr_type_t type)
         */
        MEM(node = xlat_exp_alloc_null(cast));
        xlat_exp_set_type(node, XLAT_BOX);
+       node->flags.constant = true;
        xlat_exp_set_name_buffer_shallow(node,
                                         talloc_strdup(node,
                                                       fr_table_str_by_value(fr_type_table,
@@ -2350,6 +2353,7 @@ static fr_slen_t tokenize_field(xlat_exp_head_t *head, xlat_exp_t **out, fr_sbuf
                node->fmt = vpt->name;
 
                node->flags.pure = tmpl_is_data(node->vpt);
+               node->flags.constant = node->flags.pure;
                node->flags.needs_resolving = tmpl_needs_resolving(node->vpt);
        }
 
@@ -2374,6 +2378,8 @@ static fr_slen_t tokenize_field(xlat_exp_head_t *head, xlat_exp_t **out, fr_sbuf
                if ((tmpl_value_type(vpt) == FR_TYPE_BOOL) && !tmpl_value_enumv(vpt)) {
                        tmpl_value_enumv(vpt) = attr_expr_bool_enum;
                }
+
+               node->flags.constant = true;
        }
 
        fr_assert(!tmpl_contains_regex(vpt));
index 8e93ae4d475bfaa8d076a99153cb6666775bb470..717b248accd65faa25c51019b9e93a12d1f34954 100644 (file)
@@ -184,6 +184,7 @@ static inline CC_HINT(nonnull) void xlat_flags_merge(xlat_flags_t *parent, xlat_
        parent->pure &= child->pure; /* purity can only be removed, never added */
        parent->pure &= !parent->needs_async; /* things needing async cannot be pure */
        parent->can_purify |= child->can_purify;
+       parent->constant &= child->constant;
 }
 
 /** Set the type of an xlat node
index d4b67e7a4b08cd78792e68e4e216c24d8f8a45a3..71a8108fce826594034469830fc41cf18cf80224 100644 (file)
@@ -957,6 +957,7 @@ static int xlat_tokenize_string(xlat_exp_head_t *head,
                        xlat_exp_set_type(node, XLAT_BOX);
                        xlat_exp_set_name_buffer_shallow(node, str);
                        fr_value_box_strdup_shallow(&node->data, NULL, str, false);
+                       node->flags.constant = true;
 
                        XLAT_DEBUG("VALUE-BOX (%s)<-- %pV",
                                   escapes ? escapes->name : "(none)",
@@ -1571,6 +1572,7 @@ fr_slen_t xlat_tokenize_argv(TALLOC_CTX *ctx, xlat_exp_head_t **out, fr_sbuff_t
 
                        child = xlat_exp_alloc_null(node->group);
                        xlat_exp_set_type(child, XLAT_BOX);
+                       node->flags.constant = true;
 
                        slen = fr_sbuff_out_aunescape_until(child, &str, &our_in, SIZE_MAX,
                                                            value_parse_rules_single_quoted.terminals,