Skip to content

Commit

Permalink
just move everything to xlat_bootstrap()
Browse files Browse the repository at this point in the history
  • Loading branch information
alandekok committed Oct 8, 2023
1 parent 3fc2ef4 commit 7cff2ec
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/lib/server/tmpl_tokenize.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
8 changes: 6 additions & 2 deletions src/lib/server/trigger.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 1 addition & 5 deletions src/lib/unlang/xlat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion src/lib/unlang/xlat_expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
32 changes: 10 additions & 22 deletions src/lib/unlang/xlat_inst.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ RCSID("$Id$")
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/heap.h>

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;
Expand Down Expand Up @@ -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
Expand All @@ -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;

Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/lib/unlang/xlat_redundant.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/unlang/xlat_tokenize.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 7cff2ec

Please sign in to comment.