From: Alan T. DeKok Date: Fri, 16 Sep 2022 01:12:34 +0000 (-0400) Subject: add and set "constant" flag for xlat X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9d3d0335a3395deb2e4e2b755486cf61281310a2;p=thirdparty%2Ffreeradius-server.git add and set "constant" flag for xlat 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 --- diff --git a/src/lib/unlang/xlat.h b/src/lib/unlang/xlat.h index fbfb5a24f4f..0d98d6aa5d3 100644 --- a/src/lib/unlang/xlat.h +++ b/src/lib/unlang/xlat.h @@ -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; /* diff --git a/src/lib/unlang/xlat_expr.c b/src/lib/unlang/xlat_expr.c index c9d73b58a3e..e69a7eae847 100644 --- a/src/lib/unlang/xlat_expr.c +++ b/src/lib/unlang/xlat_expr.c @@ -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)); diff --git a/src/lib/unlang/xlat_priv.h b/src/lib/unlang/xlat_priv.h index 8e93ae4d475..717b248accd 100644 --- a/src/lib/unlang/xlat_priv.h +++ b/src/lib/unlang/xlat_priv.h @@ -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 diff --git a/src/lib/unlang/xlat_tokenize.c b/src/lib/unlang/xlat_tokenize.c index d4b67e7a4b0..71a8108fce8 100644 --- a/src/lib/unlang/xlat_tokenize.c +++ b/src/lib/unlang/xlat_tokenize.c @@ -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,