From: Alan T. DeKok Date: Sun, 8 Oct 2023 00:32:42 +0000 (-0400) Subject: just move everything to xlat_bootstrap() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7cff2ec5639120ddfd5e204e8b96873c49ce303a;p=thirdparty%2Ffreeradius-server.git just move everything to xlat_bootstrap() --- diff --git a/src/lib/server/tmpl_tokenize.c b/src/lib/server/tmpl_tokenize.c index df05f6d954..1c6c33aebe 100644 --- a/src/lib/server/tmpl_tokenize.c +++ b/src/lib/server/tmpl_tokenize.c @@ -3278,7 +3278,7 @@ fr_slen_t tmpl_afrom_substr(TALLOC_CTX *ctx, tmpl_t **out, * so that their instance data will be created. */ if (head) { - if (xlat_finalize(head, t_rules) < 0) { + if (xlat_bootstrap(head, t_rules) < 0) { fr_strerror_const("Failed to bootstrap xlat"); FR_SBUFF_ERROR_RETURN(&our_in); } diff --git a/src/lib/server/trigger.c b/src/lib/server/trigger.c index 67d2bc06a5..eb600b3e85 100644 --- a/src/lib/server/trigger.c +++ b/src/lib/server/trigger.c @@ -460,8 +460,12 @@ int trigger_exec(unlang_interpret_t *intp, } } - if (xlat_instantiate_ephemeral(trigger->xlat, - (intp ? unlang_interpret_event_list(request) : main_loop_event_list())) < 0) { + if (xlat_bootstrap(trigger->xlat, &(tmpl_rules_t ) { + .xlat = { + .runtime_el = intp ? unlang_interpret_event_list(request) : main_loop_event_list(), + }, + .at_runtime = true + }) < 0) { fr_strerror_const("Failed performing ephemeral instantiation for xlat"); talloc_free(request); return -1; diff --git a/src/lib/unlang/xlat.h b/src/lib/unlang/xlat.h index d9a39a3cf5..b7775963f6 100644 --- a/src/lib/unlang/xlat.h +++ b/src/lib/unlang/xlat.h @@ -450,8 +450,6 @@ void xlat_exp_head_verify(xlat_exp_head_t const *head); /* * xlat_inst.c */ -int xlat_instantiate_ephemeral(xlat_exp_head_t *head, fr_event_list_t *el) CC_HINT(nonnull(1)); - xlat_thread_inst_t *xlat_thread_instance_find(xlat_exp_t const *node); int xlat_thread_instantiate(TALLOC_CTX *ctx, fr_event_list_t *el); @@ -462,12 +460,10 @@ void xlat_thread_detach(void); int xlat_bootstrap_func(xlat_exp_t *node); -int xlat_bootstrap(xlat_exp_head_t *root); +int xlat_bootstrap(xlat_exp_head_t *root, tmpl_rules_t const *t_rules); void xlat_instances_free(void); -int xlat_finalize(xlat_exp_head_t *head, tmpl_rules_t const *t_rules); /* xlat_bootstrap() or xlat_instantiate_ephemeral() */ - /* * xlat_purify.c */ diff --git a/src/lib/unlang/xlat_expr.c b/src/lib/unlang/xlat_expr.c index 0bbdadc643..3e57b09724 100644 --- a/src/lib/unlang/xlat_expr.c +++ b/src/lib/unlang/xlat_expr.c @@ -2907,7 +2907,7 @@ static fr_slen_t xlat_tokenize_expression_internal(TALLOC_CTX *ctx, xlat_exp_hea * Add nodes that need to be bootstrapped to * the registry. */ - if (xlat_finalize(head, t_rules) < 0) { + if (xlat_bootstrap(head, t_rules) < 0) { talloc_free(head); return -1; } diff --git a/src/lib/unlang/xlat_inst.c b/src/lib/unlang/xlat_inst.c index 4f687ec390..7270ce1671 100644 --- a/src/lib/unlang/xlat_inst.c +++ b/src/lib/unlang/xlat_inst.c @@ -31,6 +31,8 @@ RCSID("$Id$") #include #include +static int xlat_instantiate_ephemeral(xlat_exp_head_t *head, fr_event_list_t *el); + /** Holds instance data created by xlat_instantiate */ static fr_heap_t *xlat_inst_tree; @@ -349,26 +351,6 @@ static int _xlat_instantiate_ephemeral_walker(xlat_exp_t *node, void *uctx) } -/** Bootstrap static xlats, or instantiate ephemeral ones. - * - * @note - this function should be called when we have a - * #tmpl_rules_t. i.e. instead of calling xlat_bootstrap() or - * xlat_instantiate_ephemeral() - * - * @param[in] head of xlat tree to create instance data for. - * @param[in] t_rules parsing rules with #fr_event_list_t - */ -int xlat_finalize(xlat_exp_head_t *head, tmpl_rules_t const *t_rules) -{ - if (!t_rules || !t_rules->xlat.runtime_el) { - fr_assert(!t_rules || !t_rules->at_runtime); - return xlat_bootstrap(head); - } - - fr_assert(t_rules && t_rules->at_runtime); - return xlat_instantiate_ephemeral(head, t_rules->xlat.runtime_el); -} - /** Create instance data for "ephemeral" xlats * * @note This function should only be called from routines which get @@ -377,7 +359,7 @@ int xlat_finalize(xlat_exp_head_t *head, tmpl_rules_t const *t_rules) * @param[in] head of xlat tree to create instance data for. * @param[in] el event list used to run any instantiate data */ -int xlat_instantiate_ephemeral(xlat_exp_head_t *head, fr_event_list_t *el) +static int xlat_instantiate_ephemeral(xlat_exp_head_t *head, fr_event_list_t *el) { int ret; @@ -614,11 +596,17 @@ static int _xlat_bootstrap_walker(xlat_exp_t *node, UNUSED void *uctx) * If the caller has a #tmpl_rules_t, it should call xlat_finalize() instead. * * @param[in] head of xlat tree to create instance data for. + * @param[in] t_rules parsing rules with #fr_event_list_t */ -int xlat_bootstrap(xlat_exp_head_t *head) +int xlat_bootstrap(xlat_exp_head_t *head, tmpl_rules_t const *t_rules) { int ret; + /* + * Runtime xlats get ephemeral instantiation + */ + if (t_rules && t_rules->xlat.runtime_el) return xlat_instantiate_ephemeral(head, t_rules->xlat.runtime_el); + /* * If thread instantiate has been called, it's too late to * bootstrap new xlats. diff --git a/src/lib/unlang/xlat_redundant.c b/src/lib/unlang/xlat_redundant.c index de270b03e2..6168caf953 100644 --- a/src/lib/unlang/xlat_redundant.c +++ b/src/lib/unlang/xlat_redundant.c @@ -321,7 +321,7 @@ static int xlat_redundant_instantiate(xlat_inst_ctx_t const *xctx) * we return. */ head->flags = node->flags; - xlat_bootstrap(head); + xlat_bootstrap(head, NULL); xri->ex[num++] = head; } diff --git a/src/lib/unlang/xlat_tokenize.c b/src/lib/unlang/xlat_tokenize.c index 945dcba9e5..8963bcefc9 100644 --- a/src/lib/unlang/xlat_tokenize.c +++ b/src/lib/unlang/xlat_tokenize.c @@ -1880,7 +1880,7 @@ fr_slen_t xlat_tokenize(TALLOC_CTX *ctx, xlat_exp_head_t **out, fr_sbuff_t *in, * Add nodes that need to be bootstrapped to * the registry. */ - if (xlat_finalize(head, t_rules) < 0) { + if (xlat_bootstrap(head, t_rules) < 0) { talloc_free(head); return 0; }