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: 21c8bf461902ed4037ac984e2a265dd6a556c83c $
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: 21c8bf461902ed4037ac984e2a265dd6a556c83c $")
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)
43DIAG_ON(attributes)
44
45/** Custom function to print xlat debug
46 */
47typedef 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);
48
49/** Custom function to perform resolution of arguments
50 */
51typedef int (*xlat_resolve_t)(xlat_exp_t *xlat, void *inst, xlat_res_rules_t const *xr_rules);
52
53/** Custom function purify the result of an xlat function
54 */
55typedef int (*xlat_purify_t)(xlat_exp_t *xlat, void *inst, request_t *request);
56
57fr_cmp_ret_t xlat_func_cmp(void const *one, void const *two);
58
59xlat_t *xlat_func_find_module(module_inst_ctx_t const *mctx, char const *name);
60
61xlat_t *xlat_func_register(TALLOC_CTX *ctx, char const *name, xlat_func_t func, fr_type_t return_type) CC_HINT(nonnull(2));
62
63void xlat_mctx_set(xlat_t *x, module_inst_ctx_t const *mctx);
64
65int xlat_func_args_set(xlat_t *xlat, xlat_arg_parser_t const args[]) CC_HINT(nonnull);
66
67void xlat_func_call_env_set(xlat_t *x, call_env_method_t const *env) CC_HINT(nonnull);
68
70
72
74
76
77/** Set the escaped values for output boxes
78 *
79 * Any boxes output by the xlat function will have their values marked as safe for something.
80 *
81 * @param[in] _xlat function to set the escaped value for (as returned by xlat_register).
82 * @param[in] _escaped escaped value to write to output boxes.
83 */
84#define xlat_func_safe_for_set(_xlat, _escaped) _xlat_func_safe_for_set(_xlat, (fr_value_box_safe_for_t) (_escaped))
85void _xlat_func_safe_for_set(xlat_t *xlat, uintptr_t escaped);
86
87/** Set a callback for global instantiation of xlat functions
88 *
89 * @param[in] _xlat function to set the callback for (as returned by xlat_register).
90 * @param[in] _instantiate An instantiation callback.
91 * @param[in] _inst_struct The instance struct to pre-allocate.
92 * @param[in] _detach A destructor callback.
93 * @param[in] _uctx to pass to _instantiate and _detach callbacks.
94 */
95#define xlat_func_instantiate_set(_xlat, _instantiate, _inst_struct, _detach, _uctx) \
96 _xlat_func_instantiate_set(_xlat, _instantiate, #_inst_struct, sizeof(_inst_struct), _detach, _uctx)
97void _xlat_func_instantiate_set(xlat_t const *xlat,
98 xlat_instantiate_t instantiate, char const *inst_type, size_t inst_size,
99 xlat_detach_t detach,
100 void *uctx);
101
102/** Set a callback for thread-specific instantiation of xlat functions
103 *
104 * @param[in] _xlat function to set the callback for (as returned by xlat_register).
105 * @param[in] _instantiate A instantiation callback.
106 * @param[in] _inst_struct The instance struct to pre-allocate.
107 * @param[in] _detach A destructor callback.
108 * @param[in] _uctx to pass to _instantiate and _detach callbacks.
109 */
110#define xlat_func_thread_instantiate_set(_xlat, _instantiate, _inst_struct, _detach, _uctx) \
111 _xlat_func_thread_instantiate_set(_xlat, _instantiate, #_inst_struct, sizeof(_inst_struct), _detach, _uctx)
114 char const *thread_inst_type, size_t thread_inst_size,
116 void *uctx);
117
118void xlat_func_unregister(char const *name);
120/** @hidecallgraph */
121
122int xlat_func_init(void);
123void 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:904
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:289
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:281
int(* xlat_detach_t)(xlat_inst_ctx_t const *xctx)
xlat detach callback
Definition xlat.h:266
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:222
int(* xlat_thread_instantiate_t)(xlat_thread_inst_ctx_t const *xctx)
Allocate new thread instance data for an xlat instance.
Definition xlat.h:252
int(* xlat_instantiate_t)(xlat_inst_ctx_t const *xctx)
Allocate new instance data for an xlat instance.
Definition xlat.h:243
Definition for a single argument consumed by an xlat function.
Definition xlat.h:135
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:435
void _xlat_func_safe_for_set(xlat_t *xlat, uintptr_t escaped)
Set the escaped values for output boxes.
Definition xlat_func.c:445
void xlat_func_free(void)
Definition xlat_func.c:567
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:425
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:55
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:51
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:47
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
@ XLAT_FUNC_FLAG_PRIVATE
Definition xlat_func.h:41
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:534
int xlat_func_init(void)
Definition xlat_func.c:551
void xlat_func_print_set(xlat_t *xlat, xlat_print_t func)
Set a print routine for an xlat function.
Definition xlat_func.c:415
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:520
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:490
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:462
An xlat expansion node.
Definition xlat_priv.h:150