The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
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: 5d12174bf46b874c05a0847c1c4ebc065c3e92bc $
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  */
26 RCSIDH(xlat_register_h, "$Id: 5d12174bf46b874c05a0847c1c4ebc065c3e92bc $")
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  */
35 DIAG_OFF(attributes)
36 typedef enum CC_HINT(flag_enum) {
41 DIAG_ON(attributes)
42 
43 /** Custom function to print xlat debug
44  */
45 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);
46 
47 /** Custom function to perform resolution of arguments
48  */
49 typedef int (*xlat_resolve_t)(xlat_exp_t *xlat, void *inst, xlat_res_rules_t const *xr_rules);
50 
51 /** Custom function purify the result of an xlat function
52  */
53 typedef int (*xlat_purify_t)(xlat_exp_t *xlat, void *inst, request_t *request);
54 
55 xlat_t *xlat_func_find_module(module_inst_ctx_t const *mctx, char const *name);
56 
57 xlat_t *xlat_func_register_module(TALLOC_CTX *ctx, module_inst_ctx_t const *mctx,
58  char const *name, xlat_func_t func, fr_type_t return_type) CC_HINT(nonnull(2,4));
59 xlat_t *xlat_func_register(TALLOC_CTX *ctx, char const *name, xlat_func_t func, fr_type_t return_type) CC_HINT(nonnull(2));
60 
61 int xlat_func_args_set(xlat_t *xlat, xlat_arg_parser_t const args[]) CC_HINT(nonnull);
62 
63 int xlat_func_mono_set(xlat_t *xlat, xlat_arg_parser_t const *arg) CC_HINT(nonnull);
64 
65 void xlat_func_call_env_set(xlat_t *x, call_env_method_t const *env) CC_HINT(nonnull);
66 
67 void xlat_func_flags_set(xlat_t *x, xlat_func_flags_t flags) CC_HINT(nonnull);
68 
69 void xlat_func_print_set(xlat_t *xlat, xlat_print_t func);
70 
72 
73 void xlat_purify_func_set(xlat_t *xlat, xlat_purify_t func);
74 
75 /** Set the escaped values for output boxes
76  *
77  * @param[in] _xlat function to set the escaped value for (as returned by xlat_register).
78  * @param[in] _escaped escaped value to write to output boxes.
79  */
80 #define xlat_func_safe_for_set(_xlat, _escaped) _xlat_func_safe_for_set(_xlat, (uintptr_t) (_escaped))
81 void _xlat_func_safe_for_set(xlat_t *xlat, uintptr_t escaped);
82 
83 /** Set a callback for global instantiation of xlat functions
84  *
85  * @param[in] _xlat function to set the callback for (as returned by xlat_register).
86  * @param[in] _instantiate A instantiation callback.
87  * @param[in] _inst_struct The instance struct to pre-allocate.
88  * @param[in] _detach A destructor callback.
89  * @param[in] _uctx to pass to _instantiate and _detach callbacks.
90  */
91 #define xlat_func_instantiate_set(_xlat, _instantiate, _inst_struct, _detach, _uctx) \
92  _xlat_func_instantiate_set(_xlat, _instantiate, #_inst_struct, sizeof(_inst_struct), _detach, _uctx)
93 void _xlat_func_instantiate_set(xlat_t const *xlat,
94  xlat_instantiate_t instantiate, char const *inst_type, size_t inst_size,
95  xlat_detach_t detach,
96  void *uctx);
97 
98 /** Set a callback for thread-specific instantiation of xlat functions
99  *
100  * @param[in] _xlat function to set the callback for (as returned by xlat_register).
101  * @param[in] _instantiate A instantiation callback.
102  * @param[in] _inst_struct The instance struct to pre-allocate.
103  * @param[in] _detach A destructor callback.
104  * @param[in] _uctx to pass to _instantiate and _detach callbacks.
105  */
106 #define xlat_func_thread_instantiate_set(_xlat, _instantiate, _inst_struct, _detach, _uctx) \
107  _xlat_func_thread_instantiate_set(_xlat, _instantiate, #_inst_struct, sizeof(_inst_struct), _detach, _uctx)
110  char const *thread_inst_type, size_t thread_inst_size,
112  void *uctx);
113 
114 void xlat_func_unregister(char const *name);
116 /** @hidecallgraph */
117 
118 int xlat_func_init(void);
119 void xlat_func_free(void);
va_list args
Definition: acutest.h:770
#define DIAG_ON(_x)
Definition: build.h:419
#define RCSIDH(h, id)
Definition: build.h:445
#define DIAG_OFF(_x)
Definition: build.h:418
static fr_slen_t in
Definition: dict.h:645
A module/inst tuple.
Definition: dl_module.h:162
fr_type_t
Definition: merged_model.c:80
ssize_t fr_slen_t
Definition: merged_model.c:35
Temporary structure to hold arguments for instantiation calls.
Definition: module_ctx.h:51
static void thread_detach(UNUSED void *uctx)
Explicitly cleanup module/xlat resources.
Definition: radiusd.c:149
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:132
static char const * name
static int instantiate(module_inst_ctx_t const *mctx)
Definition: rlm_rest.c:1312
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:273
int(* xlat_detach_t)(xlat_inst_ctx_t const *xctx)
xlat detach callback
Definition: xlat.h:258
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:214
int(* xlat_thread_instantiate_t)(xlat_thread_inst_ctx_t const *xctx)
Allocate new thread instance data for an xlat instance.
Definition: xlat.h:244
int(* xlat_instantiate_t)(xlat_inst_ctx_t const *xctx)
Allocate new instance data for an xlat instance.
Definition: xlat.h:235
Definition for a single argument consumend by an xlat function.
Definition: xlat.h:145
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:446
void _xlat_func_safe_for_set(xlat_t *xlat, uintptr_t escaped)
Set the escaped values for output boxes.
Definition: xlat_func.c:456
void xlat_func_free(void)
Definition: xlat_func.c:578
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))
Register an xlat function for a module.
Definition: xlat_func.c:274
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:195
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:415
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:405
void xlat_func_resolve_set(xlat_t *xlat, xlat_resolve_t func)
Set a resolve routine for an xlat function.
Definition: xlat_func.c:436
int xlat_func_mono_set(xlat_t *xlat, xlat_arg_parser_t const *arg)
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:53
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:49
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:45
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_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:360
int xlat_func_init(void)
Definition: xlat_func.c:562
void xlat_func_print_set(xlat_t *xlat, xlat_print_t func)
Set a print routine for an xlat function.
Definition: xlat_func.c:426
void xlat_func_unregister(char const *name)
Unregister an xlat function.
Definition: xlat_func.c:531
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:501
void xlat_func_unregister_module(dl_module_inst_t const *inst)
Definition: xlat_func.c:545
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:473
xlat_t * xlat_func_find_module(module_inst_ctx_t const *mctx, char const *name)
Definition: xlat_func.c:159
An xlat expansion node.
Definition: xlat_priv.h:147