]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Allow additional function calls to be allocated using the arguments from another...
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 1 Dec 2021 14:34:04 +0000 (08:34 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 1 Dec 2021 20:06:45 +0000 (14:06 -0600)
This enables redundant to work correctly

src/lib/unlang/xlat.h
src/lib/unlang/xlat_tokenize.c

index 8793150f2c98aa8b9558aef10f74dc4b6626a19f..810319e9db2e32aac34b790d8b0d819497f06d50 100644 (file)
@@ -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);
index 8b369b3fdfc6d18673f4c6e27e08a4e03c536c48..85c2f030c0001f63f2e8e8e348f5c7cd3afebe45 100644 (file)
@@ -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.