From: Alan T. DeKok Date: Fri, 19 Nov 2021 14:11:04 +0000 (-0500) Subject: prepare for pure xlats X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a9b17867984d4fa29292fb869f681b013a157999;p=thirdparty%2Ffreeradius-server.git prepare for pure xlats --- diff --git a/src/lib/unlang/xlat.h b/src/lib/unlang/xlat.h index 05313f1a5ef..c90cc18dc47 100644 --- a/src/lib/unlang/xlat.h +++ b/src/lib/unlang/xlat.h @@ -91,6 +91,7 @@ typedef struct { bool needs_resolving; //!< Needs pass2 resolution. bool needs_async; //!< Node and all child nodes are guaranteed to not ///< require asynchronous expansion. + bool pure; //!< has no external side effects } xlat_flags_t; extern fr_table_num_sorted_t const xlat_action_table[]; diff --git a/src/lib/unlang/xlat_tokenize.c b/src/lib/unlang/xlat_tokenize.c index 3385704061f..d17f49f4a69 100644 --- a/src/lib/unlang/xlat_tokenize.c +++ b/src/lib/unlang/xlat_tokenize.c @@ -140,6 +140,8 @@ static inline CC_HINT(always_inline) xlat_exp_t *xlat_exp_alloc(TALLOC_CTX *ctx, node->type = type; if (in) node->fmt = talloc_bstrndup(node, in, inlen); + node->flags.pure = (type == XLAT_LITERAL); + return node; } @@ -151,6 +153,11 @@ static inline CC_HINT(always_inline) xlat_exp_t *xlat_exp_alloc(TALLOC_CTX *ctx, static inline CC_HINT(always_inline) void xlat_exp_set_type(xlat_exp_t *node, xlat_type_t type) { node->type = type; + + if (type == XLAT_LITERAL) { + node->flags.needs_async = false; /* literals are always non-async */ + node->flags.pure = true; /* literals are always pure */ + } } #if 0 @@ -189,6 +196,7 @@ static inline CC_HINT(always_inline) void xlat_flags_merge(xlat_flags_t *parent, { parent->needs_async |= child->needs_async; parent->needs_resolving |= child->needs_resolving; + parent->pure &= child->pure; /* purity can only be removed, never added */ } /** Free a linked list of xlat nodes @@ -947,7 +955,6 @@ static int xlat_tokenize_literal(TALLOC_CTX *ctx, xlat_exp_t **head, xlat_flags_ escapes ? escapes->name : "(none)", fr_box_strvalue_len(str, talloc_array_length(str) - 1)); XLAT_HEXDUMP((uint8_t const *)str, talloc_array_length(str) - 1, " LITERAL "); - node->flags.needs_async = false; /* literals are always true */ fr_cursor_insert(&cursor, node); node = NULL; } @@ -1408,7 +1415,6 @@ ssize_t xlat_tokenize_argv(TALLOC_CTX *ctx, xlat_exp_t **head, xlat_flags_t *fla node->child = xlat_exp_alloc_null(node); xlat_exp_set_type(node->child, XLAT_LITERAL); - node->flags.needs_async = false; /* Literals are always needs_async */ slen = fr_sbuff_out_aunescape_until(node->child, &str, &our_in, SIZE_MAX, value_parse_rules_single_quoted.terminals,