The FreeRADIUS server $Id: f3670dba8951ca10eb4948feb3dc3db9423a334f $
Loading...
Searching...
No Matches
xlat.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: 56c60f95b9e7b15ce6588b74528370d029a755e7 $
20 *
21 * @file lib/unlang/xlat.h
22 * @brief xlat expansion parsing and evaluation API.
23 *
24 * @copyright 2015 The FreeRADIUS server project
25 */
26RCSIDH(xlat_h, "$Id: 56c60f95b9e7b15ce6588b74528370d029a755e7 $")
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32#include <freeradius-devel/util/retry.h>
33
34/*
35 * Forward declarations
36 */
37typedef enum {
38 XLAT_ACTION_PUSH_CHILD = 1, //!< A deeper level of nesting needs to be evaluated.
39 XLAT_ACTION_PUSH_UNLANG, //!< An xlat function pushed an unlang frame onto the unlang stack.
40 ///< This frame needs to be evaluated, and then we need to call
41 ///< the xlat's resume function.
42 XLAT_ACTION_YIELD, //!< An xlat function pushed a resume frame onto the stack.
43 XLAT_ACTION_DONE, //!< We're done evaluating this level of nesting.
44 XLAT_ACTION_FAIL //!< An xlat function failed.
46
47typedef struct xlat_inst_s xlat_inst_t;
49
50#include <freeradius-devel/server/request.h>
51
52typedef ssize_t (*xlat_escape_legacy_t)(request_t *request, char *out, size_t outlen, char const *in, void *arg);
53
54#include <freeradius-devel/server/cf_util.h>
55#include <freeradius-devel/server/signal.h>
56#include <freeradius-devel/server/tmpl.h>
57
58#include <freeradius-devel/util/heap.h>
59#include <freeradius-devel/util/pair.h>
60#include <freeradius-devel/util/sbuff.h>
61#include <freeradius-devel/util/time.h>
62#include <freeradius-devel/util/value.h>
63
64#include <freeradius-devel/unlang/call_env.h>
65#include <freeradius-devel/unlang/xlat_ctx.h>
66#include <freeradius-devel/unlang/interpret.h>
67
68/** Instance data for an xlat expansion node
69 *
70 */
72 fr_heap_index_t idx; //!< Entry in heap of xlat instances.
73 ///< Identical instances are used for
74 ///< global instance data and thread-specific
75 ///< instance data.
76
77 xlat_exp_t *node; //!< Node this data relates to.
78 void *data; //!< xlat node specific instance data.
79 call_env_t const *call_env; //!< Per call environment.
80};
81
82/** Thread specific instance data for xlat expansion node
83 *
84 */
86 fr_heap_index_t idx; //!< Entry in heap of xlat thread instances.
87 ///< Identical instances are used for
88 ///< global instance data and thread-specific
89 ///< instance data.
90
91 fr_event_list_t *el; //!< Event list associated with this thread.
92
93 xlat_exp_t const *node; //!< Node this data relates to.
94 void *data; //!< Thread specific instance data.
95
96 module_ctx_t const *mctx; //!< A synthesised module calling ctx containing
97 ///< module global and thread instance data.
98
99 uint64_t total_calls; //! total number of times we've been called
100 uint64_t active_callers; //! number of active callers. i.e. number of current yields
101};
102
103typedef struct xlat_s xlat_t;
104
105/** Flags that control resolution and evaluation
106 *
107 */
108typedef struct {
109 unsigned int needs_resolving : 1; //!< Needs pass2 resolution.
110 unsigned int pure : 1; //!< has no external side effects, true for BOX, LITERAL, and some functions
111 unsigned int impure_func : 1; //!< xlat contains an impure function
112 unsigned int can_purify : 1; //!< if the xlat has a pure function with pure arguments.
113
114 unsigned int constant : 1; //!< xlat is just tmpl_attr_tail_data, or XLAT_BOX
115 unsigned int xlat : 1; //!< it's an xlat wrapper
116 unsigned int use_module_status : 1; //!< use the module thread status to force early failure.
118
119#define XLAT_FLAGS_INIT ((xlat_flags_t) { .pure = true, .can_purify = true, .constant = true, })
120
122extern size_t xlat_action_table_len;
123
124typedef enum {
126 XLAT_ARG_VARIADIC_EMPTY_SQUASH = 1, //!< Empty argument groups are removed.
127 XLAT_ARG_VARIADIC_EMPTY_KEEP = 2, //!< Empty argument groups are left alone,
128 ///< and either passed through as empty groups
129 ///< or null boxes.
131
132/** Definition for a single argument consumed by an xlat function
133 *
134 */
135typedef struct {
136 unsigned int required : 1; //!< Argument must be present, and non-empty.
137 unsigned int concat : 1; //!< Concat boxes together.
138 unsigned int single : 1; //!< Argument must only contain a single box
139 unsigned int allow_wildcard : 1; //!< For parsing the cursor
140 unsigned int will_escape : 1; //!< the function will do escaping and concatenation.
141 unsigned int always_escape : 1; //!< Pass all arguments to escape function not just
142 ///< tainted ones.
143 xlat_arg_parser_variadic_t variadic; //!< All additional boxes should be processed
144 ///< using this definition.
145 fr_type_t type; //!< Type to cast argument to.
146 fr_value_box_escape_func_t func; //!< Function to escape unsafe values.
147 fr_value_box_safe_for_t safe_for; //!< Escaped value to set for boxes processed by
148 ///< this escape function.
149 void *uctx; //!< Argument to pass to escape callback.
151
152#define XLAT_ARG_PARSER_CURSOR { .required = true, .single = true, .allow_wildcard = true, .type = FR_TYPE_PAIR_CURSOR, .safe_for = FR_VALUE_BOX_SAFE_FOR_ANY }
153
154typedef struct {
155 tmpl_res_rules_t const *tr_rules; //!< tmpl resolution rules.
156 bool allow_unresolved; //!< If false, all resolution steps must be completed
157 ///< this round, otherwise an error will be produced.
159
160#define XLAT_ARG_PARSER_TERMINATOR { .required = false, .concat = false, .single = false, .variadic = false, \
161 .type = FR_TYPE_NULL, .func = NULL, .uctx = NULL }
162
163/** A callback when the timeout occurs
164 *
165 * Used when a xlat needs to wait for an event.
166 * Typically the callback is set, and then the xlat returns unlang_xlat_yield().
167 *
168 * @note The callback is automatically removed on unlang_interpret_mark_runnable(), i.e. if an event
169 * on a registered FD occurs before the timeout event fires.
170 *
171 * @param[in] xctx xlat calling ctx. Contains all instance data.
172 * @param[in] request the request.
173 * @param[in] fired the time the timeout event actually fired.
174 */
175typedef void (*fr_unlang_xlat_timeout_t)(xlat_ctx_t const *xctx, request_t *request, fr_time_t fired);
176
177/** A callback when the timeout occurs
178 *
179 * Used when a xlat needs to wait for an event.
180 * Typically the callback is set, and then the xlat returns unlang_xlat_yield().
181 *
182 * @note The callback is automatically removed on unlang_interpret_mark_runnable(), i.e. if an event
183 * on a registered FD occurs before the timeout event fires.
184 *
185 * @param[in] xctx xlat calling ctx. Contains all instance data.
186 * @param[in] request the request.
187 * @param[in] retry retry status. "now" is in retry->updated
188 */
189typedef void (*fr_unlang_xlat_retry_t)(xlat_ctx_t const *xctx, request_t *request, fr_retry_t const *retry);
190
191/** A callback when the FD is ready for reading
192 *
193 * Used when a xlat needs to read from an FD. Typically the callback is set, and then the
194 * xlat returns unlang_xlat_yield().
195 *
196 * @note The callback is automatically removed on unlang_interpret_mark_runnable(), so
197 *
198 * @param[in] xctx xlat calling ctx. Contains all instance data.
199 * @param[in] request the current request.
200 * @param[in] fd the file descriptor.
201 */
202typedef void (*fr_unlang_xlat_fd_event_t)(xlat_ctx_t const *xctx, request_t *request, int fd);
203
204/** xlat callback function
205 *
206 * Ingests a list of value boxes as arguments.
207 *
208 * @param[in] ctx to allocate any fr_value_box_t in.
209 * @param[out] out Where to append #fr_value_box_t containing the output of
210 * this function.
211 * @param[in] xctx xlat calling ctx. Contains all instance data and the resume
212 * ctx if this function is being resumed.
213 * @param[in] request The current request.
214 * @param[in] in Input arguments.
215 * @return
216 * - XLAT_ACTION_YIELD xlat function is waiting on an I/O event and
217 * has pushed a resumption function onto the stack.
218 * - XLAT_ACTION_DONE xlat function completed. This does not necessarily
219 * mean it turned a result.
220 * - XLAT_ACTION_FAIL the xlat function failed.
221 */
222typedef xlat_action_t (*xlat_func_t)(TALLOC_CTX *ctx, fr_dcursor_t *out,
223 xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in);
224
225/** A callback when the request gets a fr_signal_t.
226 *
227 * @note The callback is automatically removed on unlang_interpret_mark_runnable().
228 *
229 * @param[in] request The current request.
230 * @param[in] xctx xlat calling ctx. Contains all instance data.
231 * @param[in] action which is signalling the request.
232 */
233typedef void (*xlat_func_signal_t)(xlat_ctx_t const *xctx, request_t *request, fr_signal_t action);
234
235/** Allocate new instance data for an xlat instance
236 *
237 * @param[in] xctx instantiate/detach calling ctx.
238
239 * @return
240 * - 0 on success.
241 * - -1 on failure.
242 */
243typedef int (*xlat_instantiate_t)(xlat_inst_ctx_t const *xctx);
244
245/** Allocate new thread instance data for an xlat instance
246 *
247 * @param[in] xctx thread instantiate/detach ctx.
248 * @return
249 * - 0 on success.
250 * - -1 on failure.
251 */
253
254/** xlat detach callback
255 *
256 * Is called whenever an xlat_node_t is freed.
257 *
258 * Detach should close all handles associated with the xlat instance, and
259 * free any memory allocated during instantiate.
260 *
261 * @param[in] xctx instantiate/detach calling ctx.
262 * @return
263 * - 0 on success.
264 * - -1 if detach failed.
265 */
266typedef int (*xlat_detach_t)(xlat_inst_ctx_t const *xctx);
267
268/** xlat thread detach callback
269 *
270 * Is called whenever an xlat_node_t is freed (if ephemeral),
271 * or when a thread exits.
272 *
273 * Detach should close all handles associated with the xlat instance, and
274 * free any memory allocated during instantiate.
275 *
276 * @param[in] xctx thread instantiate/detach calling ctx.
277 * @return
278 * - 0 on success.
279 * - -1 if detach failed.
280 */
282
283/** Set the next argument to the next item in the input list or NULL
284 *
285 * @param[in] _list we're extracting arguments from.
286 * @param[in] _prev argument.
287 * @param[in] _curr argument we're populating.
288 */
289#define XLAT_ARGS_NEXT(_list, _prev, _curr) *(_curr) = likely(*(_prev) != NULL) ? fr_value_box_list_next(_list, *(_prev)) : NULL
290
291#define XLAT_ARGS_1(_list, _a) \
292 *(_a) = fr_value_box_list_head(_list)
293
294#define XLAT_ARGS_2(_list, _a, _b) \
295 do { \
296 *(_a) = fr_value_box_list_head(_list); \
297 XLAT_ARGS_NEXT(_list, _a, _b); \
298 } while (0)
299
300#define XLAT_ARGS_3(_list, _a, _b, _c) \
301 do { \
302 *(_a) = fr_value_box_list_head(_list); \
303 XLAT_ARGS_NEXT(_list, _a, _b); \
304 XLAT_ARGS_NEXT(_list, _b, _c); \
305 } while (0)
306
307#define XLAT_ARGS_4(_list, _a, _b, _c, _d) \
308 do { \
309 *(_a) = fr_value_box_list_head(_list); \
310 XLAT_ARGS_NEXT(_list, _a, _b); \
311 XLAT_ARGS_NEXT(_list, _b, _c); \
312 XLAT_ARGS_NEXT(_list, _c, _d); \
313 } while (0)
314
315#define XLAT_ARGS_5(_list, _a, _b, _c, _d, _e) \
316 do { \
317 *(_a) = fr_value_box_list_head(_list); \
318 XLAT_ARGS_NEXT(_list, _a, _b); \
319 XLAT_ARGS_NEXT(_list, _b, _c); \
320 XLAT_ARGS_NEXT(_list, _c, _d); \
321 XLAT_ARGS_NEXT(_list, _d, _e); \
322 } while (0)
323
324#define XLAT_ARGS_6(_list, _a, _b, _c, _d, _e, _f) \
325 do { \
326 *(_a) = fr_value_box_list_head(_list); \
327 XLAT_ARGS_NEXT(_list, _a, _b); \
328 XLAT_ARGS_NEXT(_list, _b, _c); \
329 XLAT_ARGS_NEXT(_list, _c, _d); \
330 XLAT_ARGS_NEXT(_list, _d, _e); \
331 XLAT_ARGS_NEXT(_list, _e, _f); \
332 } while (0)
333
334#define XLAT_ARGS_7(_list, _a, _b, _c, _d, _e, _f, _g) \
335 do { \
336 *(_a) = fr_value_box_list_head(_list); \
337 XLAT_ARGS_NEXT(_list, _a, _b); \
338 XLAT_ARGS_NEXT(_list, _b, _c); \
339 XLAT_ARGS_NEXT(_list, _c, _d); \
340 XLAT_ARGS_NEXT(_list, _d, _e); \
341 XLAT_ARGS_NEXT(_list, _e, _f); \
342 XLAT_ARGS_NEXT(_list, _f, _g); \
343 } while (0)
344
345#define XLAT_ARGS_8(_list, _a, _b, _c, _d, _e, _f, _g, _h) \
346 do { \
347 *(_a) = fr_value_box_list_head(_list); \
348 XLAT_ARGS_NEXT(_list, _a, _b); \
349 XLAT_ARGS_NEXT(_list, _b, _c); \
350 XLAT_ARGS_NEXT(_list, _c, _d); \
351 XLAT_ARGS_NEXT(_list, _d, _e); \
352 XLAT_ARGS_NEXT(_list, _e, _f); \
353 XLAT_ARGS_NEXT(_list, _f, _g); \
354 XLAT_ARGS_NEXT(_list, _g, _h); \
355 } while (0)
356
357/** Trampoline macro for selecting which ``XLAT_ARGS_<num>`` macro to expand
358 *
359 *
360 * @param[in] XLAT_ARGS_N the name of the macro to expand.
361 * Created by concatenating ``XLAT_ARGS_ + <number of variadic arguments>``.
362 * @param[in] _list The input list of value boxes.
363 * @param[in] ... The variadic arguments themselves.
364 */
365#define _XLAT_ARGS_X(XLAT_ARGS_N, _list, ...) XLAT_ARGS_N(_list, __VA_ARGS__)
366
367/** Populate local variables with value boxes from the input list
368 *
369 * @param[in] _list input list to pull arguments from.
370 * @param[in] ... 1-8 output boxes pointers `fr_value_box_t **`
371 * e.g. `XLAT_ARGS(in, &arg0, &arg1, &argN)``.
372 */
373#define XLAT_ARGS(_list, ...) _XLAT_ARGS_X(JOIN(XLAT_ARGS_, VA_NARG(__VA_ARGS__)), _list, __VA_ARGS__)
374
375ssize_t xlat_eval(char *out, size_t outlen, request_t *request, char const *fmt, xlat_escape_legacy_t escape,
376 void const *escape_ctx)
377 CC_HINT(nonnull (1 ,3 ,4));
378
379ssize_t xlat_eval_compiled(char *out, size_t outlen, request_t *request, xlat_exp_head_t const *head,
380 xlat_escape_legacy_t escape, void const *escape_ctx)
381 CC_HINT(nonnull (1 ,3 ,4));
382
383ssize_t xlat_aeval(TALLOC_CTX *ctx, char **out, request_t *request,
384 char const *fmt, xlat_escape_legacy_t escape, void const *escape_ctx)
385 CC_HINT(nonnull(2, 3, 4));
386
387ssize_t xlat_aeval_compiled(TALLOC_CTX *ctx, char **out, request_t *request,
388 xlat_exp_head_t const *head, xlat_escape_legacy_t escape, void const *escape_ctx)
389 CC_HINT(nonnull (2, 3, 4));
390
391int xlat_flatten_to_argv(TALLOC_CTX *ctx, xlat_exp_head_t ***argv, xlat_exp_head_t *head);
392
394 fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules) CC_HINT(nonnull(1,2,3));
395
397 fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules) CC_HINT(nonnull(1,2,3));
398
400 xlat_arg_parser_t const *xlat_args, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules,
401 bool spaces) CC_HINT(nonnull(1,2,3,6));
402
404 fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules);
405
407
408static inline fr_slen_t xlat_aprint(TALLOC_CTX *ctx, char **out, xlat_exp_head_t const *head,
409 fr_sbuff_escape_rules_t const *e_rules)
411
412bool xlat_is_truthy(xlat_exp_head_t const *head, bool *out);
413
415
416void xlat_debug(xlat_exp_t const *node) CC_HINT(nonnull);
417
418void xlat_debug_head(xlat_exp_head_t const *head) CC_HINT(nonnull);
419
420bool xlat_is_literal(xlat_exp_head_t const *head) CC_HINT(nonnull);
421
423
424bool xlat_to_string(TALLOC_CTX *ctx, char **str, xlat_exp_head_t **head);
425
427
429 UNUSED xlat_ctx_t const *xctx,
430 request_t *request, fr_value_box_list_t *args);
431
432/*
433 * xlat_tokenize.c
434 */
435tmpl_t *xlat_to_tmpl_attr(TALLOC_CTX *ctx, xlat_exp_head_t *xlat);
436
437bool xlat_impure_func(xlat_exp_head_t const *head) CC_HINT(nonnull);
438
439fr_type_t xlat_node_data_type(xlat_exp_t const *node) CC_HINT(nonnull);
440
442
443/*
444 * xlat_alloc.c
445 */
447#define xlat_copy(_ctx, _out, _in) _xlat_copy(NDEBUG_LOCATION_EXP _ctx, _out, _in)
448#ifdef WITH_VERIFY_PTR
449void xlat_exp_verify(xlat_exp_t const *node);
450void xlat_exp_head_verify(xlat_exp_head_t const *head);
451
452# define XLAT_VERIFY(_node) xlat_exp_verify(_node)
453# define XLAT_HEAD_VERIFY(_head) xlat_exp_head_verify(_head)
454#else
455# define XLAT_VERIFY(_node)
456# define XLAT_HEAD_VERIFY(_head)
457#endif
458
459/*
460 * xlat_inst.c
461 */
463
464int xlat_thread_instantiate(TALLOC_CTX *ctx, fr_event_list_t *el);
465
466int xlat_instantiate(void);
467
468void xlat_thread_detach(void);
469
471
473
474int xlat_finalize(xlat_exp_head_t *head, fr_event_list_t *runtime_el); /* xlat_instance_register() or xlat_instantiate_ephemeral() */
475
476void xlat_instances_free(void);
477
478/*
479 * xlat_purify.c
480 */
483
484int xlat_purify_op(TALLOC_CTX *ctx, xlat_exp_t **out, xlat_exp_t *lhs, fr_token_t op, xlat_exp_t *rhs);
485
486/*
487 * xlat.c
488 */
490 void const *rctx, fr_time_t when);
491
492#define XLAT_RESULT_SUCCESS(_p_result) ((_p_result)->rcode == RLM_MODULE_OK)
493
494int unlang_xlat_push(TALLOC_CTX *ctx, unlang_result_t *p_result, fr_value_box_list_t *out,
495 request_t *request, xlat_exp_head_t const *head, bool top_frame)
496 CC_HINT(warn_unused_result);
497
498int unlang_xlat_eval(TALLOC_CTX *ctx, fr_value_box_list_t *out,
499 request_t *request, xlat_exp_head_t const *head)
500 CC_HINT(warn_unused_result);
501
502int unlang_xlat_eval_type(TALLOC_CTX *ctx, fr_value_box_t *out, fr_type_t type, fr_dict_attr_t const *enumv,
503 request_t *request, xlat_exp_head_t const *head)
504 CC_HINT(warn_unused_result);
505
507 xlat_func_t callback, xlat_func_signal_t signal, fr_signal_t sigmask,
508 void *rctx);
509
511 xlat_func_signal_t signal, fr_signal_t sigmask, void *rctx,
512 fr_retry_config_t const *retry_cfg);
513
514/*
515 * xlat_builtin.c
516 */
518int xlat_global_init(void);
519
520void xlat_arg_copy_out(TALLOC_CTX *ctx, fr_dcursor_t *cursor, fr_value_box_list_t *in, fr_value_box_t *vb);
521
522#ifdef __cplusplus
523}
524#endif
va_list args
Definition acutest.h:770
static int const char * fmt
Definition acutest.h:573
#define RCSIDH(h, id)
Definition build.h:561
#define NDEBUG_LOCATION_ARGS
Pass caller information to the function.
Definition build.h:330
#define UNUSED
Definition build.h:384
Structure containing both a talloc pool, a list of parsed call_env_pairs.
Definition call_env.h:252
static fr_slen_t in
Definition dict.h:904
unsigned int fr_heap_index_t
Definition heap.h:82
Stores all information relating to an event list.
Definition event.c:377
fr_type_t
long int ssize_t
ssize_t fr_slen_t
Temporary structure to hold arguments for module calls.
Definition module_ctx.h:41
static const char * spaces
Definition radict.c:177
#define SBUFF_OUT_TALLOC_FUNC_NO_LEN_DEF(_func,...)
Similar to tmpl_rules_t, but used to specify parameters that may change during subsequent resolution ...
Definition tmpl.h:391
Optional arguments passed to vp_tmpl functions.
Definition tmpl.h:343
fr_signal_t
Signals that can be generated/processed by request signal handlers.
Definition signal.h:38
fr_aka_sim_id_type_t type
An element in a lexicographically sorted array of name to num mappings.
Definition table.h:49
"server local" time.
Definition time.h:69
enum fr_token fr_token_t
static fr_event_list_t * el
bool xlat_needs_resolving(xlat_exp_head_t const *head)
Check to see if the expansion needs resolving.
fr_heap_index_t idx
Entry in heap of xlat instances.
Definition xlat.h:72
tmpl_res_rules_t const * tr_rules
tmpl resolution rules.
Definition xlat.h:155
tmpl_t * xlat_to_tmpl_attr(TALLOC_CTX *ctx, xlat_exp_head_t *xlat)
Try to convert an xlat to a tmpl for efficiency.
fr_type_t type
Type to cast argument to.
Definition xlat.h:145
int(* xlat_thread_detach_t)(xlat_thread_inst_ctx_t const *xctx)
xlat thread detach callback
Definition xlat.h:281
xlat_exp_t * node
Node this data relates to.
Definition xlat.h:77
int unlang_xlat_eval(TALLOC_CTX *ctx, fr_value_box_list_t *out, request_t *request, xlat_exp_head_t const *head)
Evaluate a "pure" (or not impure) xlat.
Definition xlat.c:711
void * data
Thread specific instance data.
Definition xlat.h:94
xlat_thread_inst_t * xlat_thread_instance_find(xlat_exp_t const *node)
Retrieve xlat/thread specific instance data.
Definition xlat_inst.c:404
bool xlat_is_literal(xlat_exp_head_t const *head)
Check to see if the expansion consists entirely of value-box elements.
xlat_exp_t const * node
Node this data relates to.
Definition xlat.h:93
int(* xlat_detach_t)(xlat_inst_ctx_t const *xctx)
xlat detach callback
Definition xlat.h:266
void xlat_arg_copy_out(TALLOC_CTX *ctx, fr_dcursor_t *cursor, fr_value_box_list_t *in, fr_value_box_t *vb)
Copy an argument from the input list to the output cursor.
void(* fr_unlang_xlat_fd_event_t)(xlat_ctx_t const *xctx, request_t *request, int fd)
A callback when the FD is ready for reading.
Definition xlat.h:202
fr_slen_t xlat_tokenize_condition(TALLOC_CTX *ctx, xlat_exp_head_t **head, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules))
Definition xlat_expr.c:3247
unsigned int pure
has no external side effects, true for BOX, LITERAL, and some functions
Definition xlat.h:110
fr_heap_index_t idx
Entry in heap of xlat thread instances.
Definition xlat.h:86
int xlat_validate_function_args(xlat_exp_t *node)
int xlat_instance_register_func(xlat_exp_t *node)
Callback for creating "permanent" instance data for a xlat_exp_t.
Definition xlat_inst.c:594
uint64_t active_callers
total number of times we've been called
Definition xlat.h:100
static fr_slen_t e_rules bool xlat_is_truthy(xlat_exp_head_t const *head, bool *out)
Allow callers to see if an xlat is truthy.
Definition xlat_expr.c:3282
fr_slen_t xlat_print(fr_sbuff_t *in, xlat_exp_head_t const *node, fr_sbuff_escape_rules_t const *e_rules)
Reconstitute an xlat expression from its constituent nodes.
void * uctx
Argument to pass to escape callback.
Definition xlat.h:149
void xlat_debug_head(xlat_exp_head_t const *head)
void xlat_thread_detach(void)
Destroy any thread specific xlat instances.
Definition xlat_inst.c:486
fr_table_num_sorted_t const xlat_action_table[]
Definition xlat_eval.c:76
bool xlat_impure_func(xlat_exp_head_t const *head)
unsigned int xlat
it's an xlat wrapper
Definition xlat.h:115
fr_event_list_t * el
Event list associated with this thread.
Definition xlat.h:91
unsigned int impure_func
xlat contains an impure function
Definition xlat.h:111
fr_slen_t xlat_tokenize(TALLOC_CTX *ctx, xlat_exp_head_t **head, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules)
Tokenize an xlat expansion.
ssize_t(* xlat_escape_legacy_t)(request_t *request, char *out, size_t outlen, char const *in, void *arg)
Definition xlat.h:52
fr_value_box_escape_func_t func
Function to escape unsafe values.
Definition xlat.h:146
ssize_t xlat_eval_compiled(char *out, size_t outlen, request_t *request, xlat_exp_head_t const *head, xlat_escape_legacy_t escape, void const *escape_ctx))
Definition xlat_eval.c:1908
bool allow_unresolved
If false, all resolution steps must be completed.
Definition xlat.h:156
ssize_t xlat_eval(char *out, size_t outlen, request_t *request, char const *fmt, xlat_escape_legacy_t escape, void const *escape_ctx))
unsigned int concat
Concat boxes together.
Definition xlat.h:137
xlat_action_t xlat_transparent(UNUSED TALLOC_CTX *ctx, fr_dcursor_t *out, UNUSED xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *args)
xlat_arg_parser_variadic_t
Definition xlat.h:124
@ XLAT_ARG_VARIADIC_EMPTY_KEEP
Empty argument groups are left alone, and either passed through as empty groups or null boxes.
Definition xlat.h:127
@ XLAT_ARG_VARIADIC_EMPTY_SQUASH
Empty argument groups are removed.
Definition xlat.h:126
@ XLAT_ARG_VARIADIC_DISABLED
Definition xlat.h:125
static fr_slen_t head
Definition xlat.h:410
xlat_arg_parser_variadic_t variadic
All additional boxes should be processed using this definition.
Definition xlat.h:143
int xlat_instantiate(void)
Call instantiation functions for all registered, "permanent" xlats.
Definition xlat_inst.c:510
xlat_action_t unlang_xlat_yield_to_retry(request_t *request, xlat_func_t resume, fr_unlang_xlat_retry_t retry, xlat_func_signal_t signal, fr_signal_t sigmask, void *rctx, fr_retry_config_t const *retry_cfg)
Yield a request back to the interpreter, with retries.
Definition xlat.c:663
unsigned int allow_wildcard
For parsing the cursor.
Definition xlat.h:139
size_t xlat_action_table_len
Definition xlat_eval.c:82
int xlat_protocols_register(void)
Register xlats for any loaded dictionaries.
void(* xlat_func_signal_t)(xlat_ctx_t const *xctx, request_t *request, fr_signal_t action)
A callback when the request gets a fr_signal_t.
Definition xlat.h:233
static fr_slen_t xlat_aprint(TALLOC_CTX *ctx, char **out, xlat_exp_head_t const *head, fr_sbuff_escape_rules_t const *e_rules) 1(xlat_print
ssize_t xlat_aeval_compiled(TALLOC_CTX *ctx, char **out, request_t *request, xlat_exp_head_t const *head, xlat_escape_legacy_t escape, void const *escape_ctx))
Definition xlat_eval.c:1925
fr_value_box_safe_for_t safe_for
Escaped value to set for boxes processed by this escape function.
Definition xlat.h:147
bool xlat_to_string(TALLOC_CTX *ctx, char **str, xlat_exp_head_t **head)
Convert an xlat node to an unescaped literal string and free the original node.
int xlat_global_init(void)
int xlat_thread_instantiate(TALLOC_CTX *ctx, fr_event_list_t *el)
Create thread specific instance tree and create thread instances.
Definition xlat_inst.c:441
int xlat_purify_op(TALLOC_CTX *ctx, xlat_exp_t **out, xlat_exp_t *lhs, fr_token_t op, xlat_exp_t *rhs)
void(* fr_unlang_xlat_retry_t)(xlat_ctx_t const *xctx, request_t *request, fr_retry_t const *retry)
A callback when the timeout occurs.
Definition xlat.h:189
int xlat_purify(xlat_exp_head_t *head, unlang_interpret_t *intp)
Purify an xlat.
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
void xlat_debug(xlat_exp_t const *node)
unsigned int always_escape
Pass all arguments to escape function not just tainted ones.
Definition xlat.h:141
int xlat_flatten_to_argv(TALLOC_CTX *ctx, xlat_exp_head_t ***argv, xlat_exp_head_t *head)
Turn am xlat list into an argv[] array, and nuke the input list.
Definition xlat_eval.c:1939
unsigned int required
Argument must be present, and non-empty.
Definition xlat.h:136
int _xlat_copy(NDEBUG_LOCATION_ARGS TALLOC_CTX *ctx, xlat_exp_head_t *out, xlat_exp_head_t const *in)
Definition xlat_alloc.c:459
void * data
xlat node specific instance data.
Definition xlat.h:78
int unlang_xlat_eval_type(TALLOC_CTX *ctx, fr_value_box_t *out, fr_type_t type, fr_dict_attr_t const *enumv, request_t *request, xlat_exp_head_t const *head)
Evaluate a "pure" (or not impure) xlat.
Definition xlat.c:741
xlat_action_t unlang_xlat_yield(request_t *request, xlat_func_t callback, xlat_func_signal_t signal, fr_signal_t sigmask, void *rctx)
Yield a request back to the interpreter from within a module.
Definition xlat.c:543
unsigned int use_module_status
use the module thread status to force early failure.
Definition xlat.h:116
void xlat_instances_free(void)
Walk over all registered instance data and free them explicitly.
Definition xlat_inst.c:726
int unlang_xlat_push(TALLOC_CTX *ctx, unlang_result_t *p_result, fr_value_box_list_t *out, request_t *request, xlat_exp_head_t const *head, bool top_frame)
Push a pre-compiled xlat onto the stack for evaluation.
Definition xlat.c:269
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
void(* fr_unlang_xlat_timeout_t)(xlat_ctx_t const *xctx, request_t *request, fr_time_t fired)
A callback when the timeout occurs.
Definition xlat.h:175
unsigned int single
Argument must only contain a single box.
Definition xlat.h:138
int xlat_resolve(xlat_exp_head_t *head, xlat_res_rules_t const *xr_rules)
Walk over an xlat tree recursively, resolving any unresolved functions or references.
uint64_t total_calls
Definition xlat.h:99
int unlang_xlat_timeout_add(request_t *request, fr_unlang_xlat_timeout_t callback, void const *rctx, fr_time_t when)
Add a timeout for an xlat handler.
Definition xlat.c:150
int xlat_finalize(xlat_exp_head_t *head, fr_event_list_t *runtime_el)
Bootstrap static xlats, or instantiate ephemeral ones.
Definition xlat_inst.c:699
xlat_action_t
Definition xlat.h:37
@ XLAT_ACTION_FAIL
An xlat function failed.
Definition xlat.h:44
@ XLAT_ACTION_YIELD
An xlat function pushed a resume frame onto the stack.
Definition xlat.h:42
@ XLAT_ACTION_PUSH_UNLANG
An xlat function pushed an unlang frame onto the unlang stack.
Definition xlat.h:39
@ XLAT_ACTION_DONE
We're done evaluating this level of nesting.
Definition xlat.h:43
@ XLAT_ACTION_PUSH_CHILD
A deeper level of nesting needs to be evaluated.
Definition xlat.h:38
call_env_t const * call_env
Per call environment.
Definition xlat.h:79
fr_slen_t xlat_tokenize_argv(TALLOC_CTX *ctx, xlat_exp_head_t **head, fr_sbuff_t *in, xlat_arg_parser_t const *xlat_args, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules, bool spaces))
Tokenize an xlat expansion into a series of XLAT_TYPE_CHILD arguments.
unsigned int can_purify
if the xlat has a pure function with pure arguments.
Definition xlat.h:112
fr_slen_t xlat_tokenize_expression(TALLOC_CTX *ctx, xlat_exp_head_t **head, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules))
Definition xlat_expr.c:3219
unsigned int will_escape
the function will do escaping and concatenation.
Definition xlat.h:140
unsigned int constant
xlat is just tmpl_attr_tail_data, or XLAT_BOX
Definition xlat.h:114
unsigned int needs_resolving
Needs pass2 resolution.
Definition xlat.h:109
int xlat_instance_unregister_func(xlat_exp_t *node)
Remove a node from the list of xlat instance data.
Definition xlat_inst.c:547
ssize_t xlat_aeval(TALLOC_CTX *ctx, char **out, request_t *request, char const *fmt, xlat_escape_legacy_t escape, void const *escape_ctx))
Definition xlat_eval.c:1916
fr_type_t xlat_node_data_type(xlat_exp_t const *node)
int(* xlat_instantiate_t)(xlat_inst_ctx_t const *xctx)
Allocate new instance data for an xlat instance.
Definition xlat.h:243
module_ctx_t const * mctx
A synthesised module calling ctx containing module global and thread instance data.
Definition xlat.h:96
fr_type_t xlat_data_type(xlat_exp_head_t const *head)
Definition for a single argument consumed by an xlat function.
Definition xlat.h:135
Flags that control resolution and evaluation.
Definition xlat.h:108
Instance data for an xlat expansion node.
Definition xlat.h:71
Thread specific instance data for xlat expansion node.
Definition xlat.h:85
int(* fr_value_box_escape_func_t)(fr_value_box_t *vb, void *uctx)
Escape a value box.
Definition value.h:703
static fr_sbuff_err_t char ** out
Definition value.h:1062
uintptr_t fr_value_box_safe_for_t
Escaping that's been applied to a value box.
Definition value.h:162
int nonnull(2, 5))
An xlat calling ctx.
Definition xlat_ctx.h:49
An xlat instantiation ctx.
Definition xlat_ctx.h:62
An xlat thread instantiation ctx.
Definition xlat_ctx.h:73
An xlat expansion node.
Definition xlat_priv.h:150