The FreeRADIUS server $Id: f3670dba8951ca10eb4948feb3dc3db9423a334f $
Loading...
Searching...
No Matches
xlat_func.h
Go to the documentation of this file.
1#pragma once
2/*
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16 */
17
18/**
19 * $Id: 67fc92c84d87728c994417f6cef55d9f192e4c4c $
20 *
21 * @file lib/unlang/xlat_func.h
22 * @brief Registration API for xlat functions.
23 *
24 * @copyright 2023 Arran Cudbard-Bell (a.cudbardb@freeradius.org)
25 */
26RCSIDH(xlat_register_h, "$Id: 67fc92c84d87728c994417f6cef55d9f192e4c4c $")
27
28#include <freeradius-devel/unlang/xlat.h>
29
30/*
31 * GCC doesn't support flag_enum (yet)
32 *
33 * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81665
34 */
35DIAG_OFF(attributes)
42DIAG_ON(attributes)
43
44/** Custom function to print xlat debug
45 */
46typedef 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);
47
48/** Custom function to perform resolution of arguments
49 */
50typedef int (*xlat_resolve_t)(xlat_exp_t *xlat, void *inst, xlat_res_rules_t const *xr_rules);
51
52/** Custom function purify the result of an xlat function
53 */
54typedef int (*xlat_purify_t)(xlat_exp_t *xlat, void *inst, request_t *request);
55
56fr_cmp_ret_t xlat_func_cmp(void const *one, void const *two);
57
58xlat_t *xlat_func_find_module(module_inst_ctx_t const *mctx, char const *name);
59
60xlat_t *xlat_func_register(TALLOC_CTX *ctx, char const *name, xlat_func_t func, fr_type_t return_type) CC_HINT(nonnull(2));
61
62void xlat_mctx_set(xlat_t *x, module_inst_ctx_t const *mctx);
63
64int xlat_func_args_set(xlat_t *xlat, xlat_arg_parser_t const args[]) CC_HINT(nonnull);
65
66void xlat_func_call_env_set(xlat_t *x, call_env_method_t const *env) CC_HINT(nonnull);
67
69
71
73
75
76/** Set the escaped values for output boxes
77 *
78 * Any boxes output by the xlat function will have their values marked as safe for something.
79 *
80 * @param[in] _xlat function to set the escaped value for (as returned by xlat_register).
81 * @param[in] _escaped escaped value to write to output boxes.
82 */
83#define xlat_func_safe_for_set(_xlat, _escaped) _xlat_func_safe_for_set(_xlat, (fr_value_box_safe_for_t) (_escaped))
84void _xlat_func_safe_for_set(xlat_t *xlat, uintptr_t escaped);
85
86/** Set a callback for global instantiation of xlat functions
87 *
88 * @param[in] _xlat function to set the callback for (as returned by xlat_register).
89 * @param[in] _instantiate An instantiation callback.
90 * @param[in] _inst_struct The instance struct to pre-allocate.
91 * @param[in] _detach A destructor callback.
92 * @param[in] _uctx to pass to _instantiate and _detach callbacks.
93 */
94#define xlat_func_instantiate_set(_xlat, _instantiate, _inst_struct, _detach, _uctx) \
95 _xlat_func_instantiate_set(_xlat, _instantiate, #_inst_struct, sizeof(_inst_struct), _detach, _uctx)
96void _xlat_func_instantiate_set(xlat_t const *xlat,
97 xlat_instantiate_t instantiate, char const *inst_type, size_t inst_size,
98 xlat_detach_t detach,
99 void *uctx);
100
101/** Set a callback for thread-specific instantiation of xlat functions
102 *
103 * @param[in] _xlat function to set the callback for (as returned by xlat_register).
104 * @param[in] _instantiate A instantiation callback.
105 * @param[in] _inst_struct The instance struct to pre-allocate.
106 * @param[in] _detach A destructor callback.
107 * @param[in] _uctx to pass to _instantiate and _detach callbacks.
108 */
109#define xlat_func_thread_instantiate_set(_xlat, _instantiate, _inst_struct, _detach, _uctx) \
110 _xlat_func_thread_instantiate_set(_xlat, _instantiate, #_inst_struct, sizeof(_inst_struct), _detach, _uctx)
113 char const *thread_inst_type, size_t thread_inst_size,
115 void *uctx);
116
117void xlat_func_unregister(char const *name);
119/** @hidecallgraph */
120
121int xlat_func_init(void);
122void xlat_func_free(void);
va_list args
Definition acutest.h:770
#define DIAG_ON(_x)
Definition build.h:535
#define RCSIDH(h, id)
Definition build.h:561
#define DIAG_OFF(_x)
Definition build.h:534
static fr_slen_t in
Definition dict.h:882
fr_type_t
ssize_t fr_slen_t
fr_cmp_ret_t
Result of an ordering comparison.
Definition misc.h:50
Temporary structure to hold arguments for instantiation calls.
Definition module_ctx.h:50
static void thread_detach(UNUSED void *uctx)
Explicitly cleanup module/xlat resources.
Definition radiusd.c:139
static int thread_instantiate(TALLOC_CTX *ctx, fr_event_list_t *el, UNUSED void *uctx)
Create module and xlat per-thread instances.
Definition radiusd.c:127
static char const * name
Module instance data.
Definition module.h:287
eap_aka_sim_process_conf_t * inst
int(* xlat_thread_detach_t)(xlat_thread_inst_ctx_t const *xctx)
xlat thread detach callback
Definition xlat.h:292
int(* xlat_detach_t)(xlat_inst_ctx_t const *xctx)
xlat detach callback
Definition xlat.h:277
xlat_action_t(* xlat_func_t)(TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in)
xlat callback function
Definition xlat.h:233
int(* xlat_thread_instantiate_t)(xlat_thread_inst_ctx_t const *xctx)
Allocate new thread instance data for an xlat instance.
Definition xlat.h:263
int(* xlat_instantiate_t)(xlat_inst_ctx_t const *xctx)
Allocate new instance data for an xlat instance.
Definition xlat.h:254
Definition for a single argument consumed by an xlat function.
Definition xlat.h:146
int nonnull(2, 5))
void xlat_purify_func_set(xlat_t *xlat, xlat_purify_t func)
Set a resolve routine for an xlat function.
Definition xlat_func.c:434
void _xlat_func_safe_for_set(xlat_t *xlat, uintptr_t escaped)
Set the escaped values for output boxes.
Definition xlat_func.c:444
void xlat_func_free(void)
Definition xlat_func.c:566
void xlat_func_flags_set(xlat_t *x, xlat_func_flags_t flags)
Specify flags that alter the xlat's behaviour.
Definition xlat_func.c:401
void xlat_func_call_env_set(xlat_t *x, call_env_method_t const *env)
Register call environment of an xlat.
Definition xlat_func.c:391
void xlat_func_resolve_set(xlat_t *xlat, xlat_resolve_t func)
Set a resolve routine for an xlat function.
Definition xlat_func.c:424
fr_cmp_ret_t xlat_func_cmp(void const *one, void const *two)
Compare two xlat_t by the underlying function.
Definition xlat_func.c:67
int(* xlat_purify_t)(xlat_exp_t *xlat, void *inst, request_t *request)
Custom function purify the result of an xlat function.
Definition xlat_func.h:54
int(* xlat_resolve_t)(xlat_exp_t *xlat, void *inst, xlat_res_rules_t const *xr_rules)
Custom function to perform resolution of arguments.
Definition xlat_func.h:50
xlat_t * xlat_func_register(TALLOC_CTX *ctx, char const *name, xlat_func_t func, fr_type_t return_type))
Register an xlat function.
Definition xlat_func.c:225
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 print xlat debug.
Definition xlat_func.h:46
xlat_func_flags_t
Definition xlat_func.h:36
@ XLAT_FUNC_FLAG_NONE
Definition xlat_func.h:37
@ XLAT_FUNC_FLAG_PURE
Definition xlat_func.h:38
@ XLAT_FUNC_FLAG_MODULE_STATUS
Definition xlat_func.h:40
@ XLAT_FUNC_FLAG_INTERNAL
Definition xlat_func.h:39
int xlat_func_args_set(xlat_t *xlat, xlat_arg_parser_t const args[])
Register the arguments of an xlat.
Definition xlat_func.c:374
void xlat_func_unregister_module(module_instance_t const *inst)
Definition xlat_func.c:533
int xlat_func_init(void)
Definition xlat_func.c:550
void xlat_func_print_set(xlat_t *xlat, xlat_print_t func)
Set a print routine for an xlat function.
Definition xlat_func.c:414
void xlat_mctx_set(xlat_t *x, module_inst_ctx_t const *mctx)
Associate a module calling ctx with the xlat.
Definition xlat_func.c:307
void xlat_func_unregister(char const *name)
Unregister an xlat function.
Definition xlat_func.c:519
void _xlat_func_thread_instantiate_set(xlat_t const *xlat, xlat_thread_instantiate_t thread_instantiate, char const *thread_inst_type, size_t thread_inst_size, xlat_thread_detach_t thread_detach, void *uctx)
Register an async xlat.
Definition xlat_func.c:489
xlat_t * xlat_func_find_module(module_inst_ctx_t const *mctx, char const *name)
Definition xlat_func.c:186
void _xlat_func_instantiate_set(xlat_t const *xlat, xlat_instantiate_t instantiate, char const *inst_type, size_t inst_size, xlat_detach_t detach, void *uctx)
Set global instantiation/detach callbacks.
Definition xlat_func.c:461
An xlat expansion node.
Definition xlat_priv.h:148