* so that their instance data will be created.
*/
if (head) {
- int rcode;
-
- if (!t_rules->at_runtime) {
- rcode = xlat_bootstrap(head);
- } else {
- rcode = xlat_instantiate_ephemeral(head, t_rules->xlat.runtime_el);
- }
- if (rcode < 0) {
+ if (xlat_finalize(head, t_rules) < 0) {
fr_strerror_const("Failed to bootstrap xlat");
FR_SBUFF_ERROR_RETURN(&our_in);
}
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
*/
static fr_slen_t xlat_tokenize_expression_internal(TALLOC_CTX *ctx, xlat_exp_head_t **out, fr_sbuff_t *in,
fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules, bool cond)
{
- int rcode;
ssize_t slen;
fr_sbuff_parse_rules_t *bracket_rules = NULL;
fr_sbuff_parse_rules_t *terminal_rules = NULL;
* Add nodes that need to be bootstrapped to
* the registry.
*/
- if (!t_rules || !t_rules->xlat.runtime_el) {
- rcode = xlat_bootstrap(head);
- } else {
- rcode = xlat_instantiate_ephemeral(head, t_rules->xlat.runtime_el);
- }
- if (rcode < 0) {
+ if (xlat_finalize(head, t_rules) < 0) {
talloc_free(head);
return -1;
}
return 0;
}
+
+/** 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->at_runtime);
+ return xlat_bootstrap(head);
+ }
+
+ fr_assert(t_rules->at_runtime);
+ return xlat_instantiate_ephemeral(head, t_rules->xlat.runtime_el);
+}
+
/** Create instance data for "ephemeral" xlats
*
- * @note This must only be used for xlats created at runtime.
+ * @note This function should only be called from routines which get
+ * passed a #request_t.
*
* @param[in] head of xlat tree to create instance data for.
* @param[in] el event list used to run any instantiate data
/** Create instance data for "permanent" xlats
*
- * @note This must only be used for xlats created during startup.
+ * @note This must only be used for xlats which are read from the configuration files.
* IF THIS IS CALLED FOR XLATS TOKENIZED AT RUNTIME YOU WILL LEAK LARGE AMOUNTS OF MEMORY.
- * USE xlat_instantiate_request() INSTEAD.
+ * 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.
*/
fr_slen_t xlat_tokenize(TALLOC_CTX *ctx, xlat_exp_head_t **out, fr_sbuff_t *in,
fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules)
{
- int rcode;
fr_sbuff_t our_in = FR_SBUFF(in);
xlat_exp_head_t *head;
* Add nodes that need to be bootstrapped to
* the registry.
*/
- if (!t_rules || !t_rules->xlat.runtime_el) {
- rcode = xlat_bootstrap(head);
- } else {
- rcode = xlat_instantiate_ephemeral(head, t_rules->xlat.runtime_el);
- }
- if (rcode < 0) {
+ if (xlat_finalize(head, t_rules) < 0) {
talloc_free(head);
return 0;
}