From: Arran Cudbard-Bell Date: Thu, 30 Mar 2023 03:31:06 +0000 (-0600) Subject: xlat: Move function setting overrides into xlat_func.c X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0aec7e2bff3a0efa1695275af058a5a5aa7af7db;p=thirdparty%2Ffreeradius-server.git xlat: Move function setting overrides into xlat_func.c --- diff --git a/src/lib/unlang/xlat_expr.c b/src/lib/unlang/xlat_expr.c index 0a78c4845e..97732cbdcf 100644 --- a/src/lib/unlang/xlat_expr.c +++ b/src/lib/unlang/xlat_expr.c @@ -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 diff --git a/src/lib/unlang/xlat_func.c b/src/lib/unlang/xlat_func.c index bee545a047..fb90b8aff3 100644 --- a/src/lib/unlang/xlat_func.c +++ b/src/lib/unlang/xlat_func.c @@ -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. diff --git a/src/lib/unlang/xlat_func.h b/src/lib/unlang/xlat_func.h index 75faaab4a9..e4146ec3fd 100644 --- a/src/lib/unlang/xlat_func.h +++ b/src/lib/unlang/xlat_func.h @@ -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). diff --git a/src/lib/unlang/xlat_priv.h b/src/lib/unlang/xlat_priv.h index 8e68832685..01118271a7 100644 --- a/src/lib/unlang/xlat_priv.h +++ b/src/lib/unlang/xlat_priv.h @@ -32,6 +32,7 @@ extern "C" { #include #include +#include #include #include #include @@ -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 */