]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
xlat: Move function setting overrides into xlat_func.c
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 30 Mar 2023 03:31:06 +0000 (21:31 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 30 Mar 2023 03:31:06 +0000 (21:31 -0600)
src/lib/unlang/xlat_expr.c
src/lib/unlang/xlat_func.c
src/lib/unlang/xlat_func.h
src/lib/unlang/xlat_priv.h

index 0a78c4845ef1c057f362e08e92d471d8ecb15b81..97732cbdcf298ce991be7cdb8382c782a4d5f39c 100644 (file)
@@ -1630,7 +1630,7 @@ do { \
        if (!(xlat = xlat_func_register(NULL, "op_" STRINGIFY(_name), xlat_func_op_ ## _name, FR_TYPE_VOID))) return -1; \
        xlat_func_args_set(xlat, binary_op_xlat_args); \
        xlat_func_flags_set(xlat, XLAT_FUNC_FLAG_PURE | XLAT_FUNC_FLAG_INTERNAL); \
-       xlat_print_set(xlat, xlat_expr_print_binary); \
+       xlat_func_print_set(xlat, xlat_expr_print_binary); \
        xlat_func_async_instantiate_set(xlat, xlat_function_args_to_tmpl, NULL, NULL, NULL); \
        xlat->token = _op; \
 } while (0)
@@ -1641,8 +1641,8 @@ do { \
        if (!(xlat = xlat_func_register(NULL, "cmp_" STRINGIFY(_name), xlat_func_cmp_ ## _name, FR_TYPE_VOID))) return -1; \
        xlat_func_args_set(xlat, binary_op_xlat_args); \
        xlat_func_flags_set(xlat, XLAT_FUNC_FLAG_PURE | XLAT_FUNC_FLAG_INTERNAL); \
-       xlat_print_set(xlat, xlat_expr_print_binary); \
-       xlat_resolve_set(xlat, xlat_expr_resolve_binary); \
+       xlat_func_print_set(xlat, xlat_expr_print_binary); \
+       xlat_func_resolve_set(xlat, xlat_expr_resolve_binary); \
        xlat->token = _op; \
 } while (0)
 
@@ -1652,8 +1652,8 @@ do { \
        if (!(xlat = xlat_func_register(NULL, STRINGIFY(_name), xlat_func_ ## _func_name, FR_TYPE_VOID))) return -1; \
        xlat_func_async_instantiate_set(xlat, xlat_instantiate_ ## _func_name, xlat_ ## _func_name ## _inst_t, NULL, NULL); \
        xlat_func_flags_set(xlat, XLAT_FUNC_FLAG_PURE | XLAT_FUNC_FLAG_INTERNAL); \
-       xlat_print_set(xlat, xlat_expr_print_ ## _func_name); \
-       xlat_purify_set(xlat, xlat_expr_logical_purify); \
+       xlat_func_print_set(xlat, xlat_expr_print_ ## _func_name); \
+       xlat_purify_func_set(xlat, xlat_expr_logical_purify); \
        xlat->token = _op; \
 } while (0)
 
@@ -1664,7 +1664,7 @@ do { \
        xlat_func_args_set(xlat, regex_op_xlat_args); \
        xlat_func_flags_set(xlat, XLAT_FUNC_FLAG_PURE | XLAT_FUNC_FLAG_INTERNAL); \
        xlat_func_async_instantiate_set(xlat, xlat_instantiate_regex, xlat_regex_inst_t, NULL, NULL); \
-       xlat_print_set(xlat, xlat_expr_print_regex); \
+       xlat_func_print_set(xlat, xlat_expr_print_regex); \
        xlat->token = _op; \
 } while (0)
 
@@ -1680,7 +1680,7 @@ do { \
        if (!(xlat = xlat_func_register(NULL, _xlat, _func, FR_TYPE_VOID))) return -1; \
        xlat_func_args_set(xlat, unary_op_xlat_args); \
        xlat_func_flags_set(xlat, XLAT_FUNC_FLAG_PURE | XLAT_FUNC_FLAG_INTERNAL); \
-       xlat_print_set(xlat, xlat_expr_print_unary); \
+       xlat_func_print_set(xlat, xlat_expr_print_unary); \
        xlat->token = _op; \
 } while (0)
 
@@ -1723,7 +1723,7 @@ int xlat_register_expressions(void)
        XLAT_REGISTER_MONO("rcode", xlat_func_rcode, xlat_func_rcode_arg);
        XLAT_REGISTER_MONO("exists", xlat_func_exists, xlat_func_exists_arg);
        xlat_func_async_instantiate_set(xlat, xlat_instantiate_exists, xlat_exists_inst_t, NULL, NULL);
-       xlat_print_set(xlat, xlat_expr_print_exists);
+       xlat_func_print_set(xlat, xlat_expr_print_exists);
 
        /*
         *      -EXPR
index bee545a0475e8dc1b5f5db72513daddb1bff2a82..fb90b8aff33e7c0d2f47690fee239c6bdafd20bc 100644 (file)
@@ -345,6 +345,36 @@ void xlat_func_flags_set(xlat_t *x, xlat_func_flags_t flags)
        x->internal = flags & XLAT_FUNC_FLAG_INTERNAL;
 }
 
+/** Set a print routine for an xlat function.
+ *
+ * @param[in] xlat to set
+ * @param[in] func for printing
+ */
+void xlat_func_print_set(xlat_t *xlat, xlat_print_t func)
+{
+       xlat->print = func;
+}
+
+/** Set a resolve routine for an xlat function.
+ *
+ * @param[in] xlat to set
+ * @param[in] func to resolve xlat.
+ */
+void xlat_func_resolve_set(xlat_t *xlat, xlat_resolve_t func)
+{
+       xlat->resolve = func;
+}
+
+/** Set a resolve routine for an xlat function.
+ *
+ * @param[in] xlat to set
+ * @param[in] func to purify xlat
+ */
+void xlat_purify_func_set(xlat_t *xlat, xlat_purify_t func)
+{
+       xlat->purify = func;
+}
+
 /** Set global instantiation/detach callbacks
  *
  * @param[in] xlat             to set instantiation callbacks for.
index 75faaab4a97c919150d32c82f528e6bfd1feb5a2..e4146ec3fdf82e9f3089b8dc8eb14d7eb6a28939 100644 (file)
@@ -40,6 +40,18 @@ typedef enum CC_HINT(flag_enum) {
 } xlat_func_flags_t;
 DIAG_ON(attributes)
 
+/** Custom function to print xlat debug
+ */
+typedef        fr_slen_t (*xlat_print_t)(fr_sbuff_t *in, xlat_exp_t const *self, void *inst, fr_sbuff_escape_rules_t const *e_rules);
+
+/** Custom function to perform resolution of arguments
+ */
+typedef        int (*xlat_resolve_t)(xlat_exp_t *xlat, void *inst, xlat_res_rules_t const *xr_rules);
+
+/** Custom function purify the result of an xlat function
+ */
+typedef int (*xlat_purify_t)(xlat_exp_t *xlat, void *inst, request_t *request);
+
 xlat_t         *xlat_func_register_module(TALLOC_CTX *ctx, module_inst_ctx_t const *mctx,
                                           char const *name, xlat_func_t func, fr_type_t return_type);
 xlat_t         *xlat_func_register(TALLOC_CTX *ctx, char const *name, xlat_func_t func, fr_type_t return_type) CC_HINT(nonnull(2));
@@ -50,6 +62,12 @@ int          xlat_func_mono_set(xlat_t *xlat, xlat_arg_parser_t const *arg) CC_HINT(nonn
 
 void           xlat_func_flags_set(xlat_t *x, xlat_func_flags_t flags) CC_HINT(nonnull);
 
+void           xlat_func_print_set(xlat_t *xlat, xlat_print_t func);
+
+void           xlat_func_resolve_set(xlat_t *xlat, xlat_resolve_t func);
+
+void           xlat_purify_func_set(xlat_t *xlat, xlat_purify_t func);
+
 /** Set a callback for global instantiation of xlat functions
  *
  * @param[in] _xlat            function to set the callback for (as returned by xlat_register).
index 8e6883268519a22cc6265e0ed8b127935fd21e87..01118271a7bc39dee036cfa1e38d145719648984 100644 (file)
@@ -32,6 +32,7 @@ extern "C" {
 
 #include <freeradius-devel/unlang/xlat_ctx.h>
 #include <freeradius-devel/unlang/xlat.h>
+#include <freeradius-devel/unlang/xlat_func.h>
 #include <freeradius-devel/io/pair.h>
 #include <freeradius-devel/util/talloc.h>
 #include <freeradius-devel/build.h>
@@ -54,10 +55,6 @@ extern "C" {
 #  define _CONST
 #endif
 
-typedef fr_slen_t (*xlat_print_t)(fr_sbuff_t *in, xlat_exp_t const *self, void *inst, fr_sbuff_escape_rules_t const *e_rules);
-typedef int (*xlat_resolve_t)(xlat_exp_t *self, void *inst, xlat_res_rules_t const *xr_rules);
-typedef int (*xlat_purify_t)(xlat_exp_t *self, void *inst, request_t *request);
-
 typedef struct xlat_s {
        fr_rb_node_t            node;                   //!< Entry in the xlat function tree.
        char const              *name;                  //!< Name of xlat function.
@@ -240,38 +237,6 @@ static inline xlat_exp_t *xlat_exp_next(xlat_exp_head_t const *head, xlat_exp_t
        return fr_dlist_next(&head->dlist, node);
 }
 
-/** Set a print routine for an xlat function.
- *
- * @param[in] xlat to set
- * @param[in] func for printing
- */
-static inline void xlat_print_set(xlat_t *xlat, xlat_print_t func)
-{
-       xlat->print = func;
-}
-
-
-/** Set a resolve routine for an xlat function.
- *
- * @param[in] xlat to set
- * @param[in] func to resolve xlat.
- */
-static inline void xlat_resolve_set(xlat_t *xlat, xlat_resolve_t func)
-{
-       xlat->resolve = func;
-}
-
-
-/** Set a resolve routine for an xlat function.
- *
- * @param[in] xlat to set
- * @param[in] func to purify xlat
- */
-static inline void xlat_purify_set(xlat_t *xlat, xlat_purify_t func)
-{
-       xlat->purify = func;
-}
-
 /*
  *     xlat_purify.c
  */