From: Arran Cudbard-Bell Date: Wed, 8 Nov 2023 01:11:56 +0000 (-0600) Subject: Remove dict from xlat_exp_head_t X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=adb48e407e96d1c96282164213f7a2cfacad7b04;p=thirdparty%2Ffreeradius-server.git Remove dict from xlat_exp_head_t It's already in the nodes it needs to be in --- diff --git a/src/lib/unlang/xlat_expr.c b/src/lib/unlang/xlat_expr.c index 57e1a999323..0e5f48eb1c9 100644 --- a/src/lib/unlang/xlat_expr.c +++ b/src/lib/unlang/xlat_expr.c @@ -2958,11 +2958,7 @@ static fr_slen_t xlat_tokenize_expression_internal(TALLOC_CTX *ctx, xlat_exp_hea &bracket_terms)); MEM(head = xlat_exp_head_alloc(ctx)); - if (t_rules) { - head->dict = t_rules->attr.dict_def; - } else { - t_rules = &my_rules; - } + if (!t_rules) t_rules = &my_rules; slen = tokenize_expression(head, &node, in, terminal_rules, t_rules, T_INVALID, bracket_rules, p_rules, cond); talloc_free(bracket_rules); diff --git a/src/lib/unlang/xlat_priv.h b/src/lib/unlang/xlat_priv.h index 53d64fcbc98..ec7c848e46b 100644 --- a/src/lib/unlang/xlat_priv.h +++ b/src/lib/unlang/xlat_priv.h @@ -124,6 +124,12 @@ typedef struct { xlat_t const *func; //!< The xlat expansion to expand format with. xlat_exp_head_t *args; //!< arguments to the function call + fr_dict_t const *dict; //!< Records the namespace this xlat call was created in. + ///< Used by the purify code to run fake requests in + ///< the correct namespace, and accessible to instantiation + ///< functions in case the xlat needs to perform runtime + ///< resolution of attributes (as with %eval()). + xlat_inst_t *inst; //!< Instance data for the #xlat_t. xlat_thread_inst_t *thread_inst; //!< Thread specific instance. ///< ONLY USED FOR EPHEMERAL XLATS. @@ -132,8 +138,6 @@ typedef struct { ///< into the instance tree. xlat_input_type_t input_type; //!< The input type used inferred from the ///< bracketing style. - - fr_dict_t const *dict; //!< Dictionary to use when resolving call env tmpls } xlat_call_t; /** An xlat expansion node @@ -147,7 +151,6 @@ struct xlat_exp_s { fr_token_t quote; //!< Type of quoting around XLAT_GROUP types. xlat_flags_t flags; //!< Flags that control resolution and evaluation. - xlat_type_t _CONST type; //!< type of this expansion. #ifndef NDEBUG @@ -184,11 +187,6 @@ struct xlat_exp_head_s { fr_dlist_head_t dlist; xlat_flags_t flags; //!< Flags that control resolution and evaluation. bool instantiated; //!< temporary flag until we fix more things - fr_dict_t const *dict; //!< Records the namespace this xlat was created in. - ///< Used by the purify code to run fake requests in - ///< the correct namespace, and passed to instantiation - ///< functions in case the xlat needs to perform runtime - ///< resolution of attributes (as with %eval()). #ifndef NDEBUG char const * _CONST file; //!< File where the xlat was allocated. diff --git a/src/lib/unlang/xlat_purify.c b/src/lib/unlang/xlat_purify.c index 1c53dc9573e..085e9c4422e 100644 --- a/src/lib/unlang/xlat_purify.c +++ b/src/lib/unlang/xlat_purify.c @@ -29,6 +29,7 @@ RCSID("$Id$") #include #include #include +#include static void xlat_value_list_to_xlat(xlat_exp_head_t *head, fr_value_box_list_t *list) { @@ -130,8 +131,21 @@ int xlat_purify_list(xlat_exp_head_t *head, request_t *request) */ if (!node->flags.pure) { if (node->call.func->purify) { + fr_dict_t const *dict = request->dict; + + /* + * Swap in the node specific dictionary. + * + * The previous code stored the dictionary in the xlat_exp_head_t, + * and whilst this wasn't wrong, it was duplicative. + * + * This allows future code to create inline definitions of local + * attributes, and have them work correctly, as more deeply nested + * expressions would swap in the correct dictionary. + */ + request->dict = node->call.dict; if (node->call.func->purify(node, node->call.inst->data, request) < 0) return -1; - + request->dict = dict; } else { if (xlat_purify_list(node->call.args, request) < 0) return -1; } @@ -207,7 +221,7 @@ int xlat_purify(xlat_exp_head_t *head, unlang_interpret_t *intp) if (!head->flags.can_purify) return 0; - request = request_alloc_internal(NULL, (&(request_init_args_t){ .namespace = head->dict })); + request = request_alloc_internal(NULL, (&(request_init_args_t){ .namespace = fr_dict_internal() })); if (!request) return -1; if (intp) unlang_interpret_set(request, intp); diff --git a/src/lib/unlang/xlat_tokenize.c b/src/lib/unlang/xlat_tokenize.c index 6e0eaa386d6..3b1fa9803bf 100644 --- a/src/lib/unlang/xlat_tokenize.c +++ b/src/lib/unlang/xlat_tokenize.c @@ -1672,8 +1672,6 @@ fr_slen_t xlat_tokenize_argv(TALLOC_CTX *ctx, xlat_exp_head_t **out, fr_sbuff_t xlat_exp_head_t *head; MEM(head = xlat_exp_head_alloc(ctx)); - if (t_rules) head->dict = t_rules->attr.dict_def; - if (p_rules && p_rules->terminals) { tmp_p_rules = (fr_sbuff_parse_rules_t){ /* Stack allocated due to CL scope */ .terminals = fr_sbuff_terminals_amerge(NULL, p_rules->terminals, @@ -1908,7 +1906,6 @@ fr_slen_t xlat_tokenize(TALLOC_CTX *ctx, xlat_exp_head_t **out, fr_sbuff_t *in, MEM(head = xlat_exp_head_alloc(ctx)); if (t_rules) { - head->dict = t_rules->attr.dict_def; fr_assert(!t_rules->at_runtime || t_rules->xlat.runtime_el); /* if it's at runtime, we need an event list */ }