From: Arran Cudbard-Bell Date: Wed, 1 Dec 2021 14:34:04 +0000 (-0600) Subject: Allow additional function calls to be allocated using the arguments from another... X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a38ef0e213f64c3a2edd10c99f02c8875950502b;p=thirdparty%2Ffreeradius-server.git Allow additional function calls to be allocated using the arguments from another xlat call This enables redundant to work correctly --- diff --git a/src/lib/unlang/xlat.h b/src/lib/unlang/xlat.h index 8793150f2c9..810319e9db2 100644 --- a/src/lib/unlang/xlat.h +++ b/src/lib/unlang/xlat.h @@ -425,6 +425,8 @@ void xlat_free(void); /* * xlat_tokenize.c */ +xlat_exp_t *xlat_exp_func_alloc(TALLOC_CTX *ctx, xlat_t *func, xlat_exp_t const *args); + void xlat_exp_free(xlat_exp_t **head); tmpl_t *xlat_to_tmpl_attr(TALLOC_CTX *ctx, xlat_exp_t *xlat); diff --git a/src/lib/unlang/xlat_tokenize.c b/src/lib/unlang/xlat_tokenize.c index 8b369b3fdfc..85c2f030c00 100644 --- a/src/lib/unlang/xlat_tokenize.c +++ b/src/lib/unlang/xlat_tokenize.c @@ -155,6 +155,28 @@ static inline CC_HINT(always_inline) xlat_exp_t *xlat_exp_alloc(TALLOC_CTX *ctx, return node; } +/** Allocate an xlat node to call an xlat function + * + * @param[in] ctx to allocate the new node in. + * @param[in] func to call. + * @param[in] args Arguments to the function. Will be copied, + * and freed when the new xlat node is freed. + */ +xlat_exp_t *xlat_exp_func_alloc(TALLOC_CTX *ctx, xlat_t *func, xlat_exp_t const *args) +{ + xlat_exp_t *node; + + MEM(node = xlat_exp_alloc(ctx, XLAT_FUNC, func->name, strlen(func->name))); + node->call.func = func; + if (unlikely(xlat_copy(node, &node->child, args) < 0)) { + talloc_free(node); + return -1; + } + node->flags = func->flags; + + return node; +} + /** Set the type of an xlat node * * @param[in] node to set type for.