The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
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: 2af31000f4b8eed253d02cb983f28c012c3e92d1 $
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: 2af31000f4b8eed253d02cb983f28c012c3e92d1 $")
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 enum {
48 XLAT_INPUT_UNPROCESSED, //!< No input argument processing
49 XLAT_INPUT_ARGS //!< Ingests a number of arguments
51
52typedef struct xlat_inst_s xlat_inst_t;
54
55#include <freeradius-devel/server/request.h>
56
57typedef ssize_t (*xlat_escape_legacy_t)(request_t *request, char *out, size_t outlen, char const *in, void *arg);
58
59#include <freeradius-devel/server/cf_util.h>
60#include <freeradius-devel/server/signal.h>
61#include <freeradius-devel/server/tmpl.h>
62
63#include <freeradius-devel/util/heap.h>
64#include <freeradius-devel/util/pair.h>
65#include <freeradius-devel/util/sbuff.h>
66#include <freeradius-devel/util/time.h>
67#include <freeradius-devel/util/value.h>
68
69#include <freeradius-devel/unlang/call_env.h>
70#include <freeradius-devel/unlang/xlat_ctx.h>
71
72/** Instance data for an xlat expansion node
73 *
74 */
76 fr_heap_index_t idx; //!< Entry in heap of xlat instances.
77 ///< Identical instances are used for
78 ///< global instance data and thread-specific
79 ///< instance data.
80
81 xlat_exp_t *node; //!< Node this data relates to.
82 void *data; //!< xlat node specific instance data.
83 call_env_t const *call_env; //!< Per call environment.
84};
85
86/** Thread specific instance data for xlat expansion node
87 *
88 */
90 fr_heap_index_t idx; //!< Entry in heap of xlat thread instances.
91 ///< Identical instances are used for
92 ///< global instance data and thread-specific
93 ///< instance data.
94
95 fr_event_list_t *el; //!< Event list associated with this thread.
96
97 xlat_exp_t const *node; //!< Node this data relates to.
98 void *data; //!< Thread specific instance data.
99
100 module_ctx_t const *mctx; //!< A synthesised module calling ctx containing
101 ///< module global and thread instance data.
102
103 uint64_t total_calls; //! total number of times we've been called
104 uint64_t active_callers; //! number of active callers. i.e. number of current yields
105};
106
107typedef struct xlat_s xlat_t;
108
109/** Flags that control resolution and evaluation
110 *
111 */
112typedef struct {
113 bool needs_resolving;//!< Needs pass2 resolution.
114 bool pure; //!< has no external side effects, true for BOX, LITERAL, and some functions
115 bool impure_func; //!< xlat contains an impure function
116 bool can_purify; //!< if the xlat has a pure function with pure arguments.
117
118 bool constant; //!< xlat is just tmpl_attr_tail_data, or XLAT_BOX
119 bool xlat; //!< it's an xlat wrapper
121
123extern size_t xlat_action_table_len;
124
125/** A function used to escape an argument passed to an xlat
126 *
127 * @param[in] request being processed. Used mostly for debugging.
128 * @param[in,out] vb to escape
129 * @param[in] uctx a "context" for the escaping
130 * @return
131 * - 0 on success.
132 * - -1 on failure.
133 */
134typedef int (*xlat_escape_func_t)(request_t *request, fr_value_box_t *vb, void *uctx);
135
136typedef enum {
138 XLAT_ARG_VARIADIC_EMPTY_SQUASH = 1, //!< Empty argument groups are removed.
139 XLAT_ARG_VARIADIC_EMPTY_KEEP = 2, //!< Empty argument groups are left alone,
140 ///< and either passed through as empty groups
141 ///< or null boxes.
143
144/** Definition for a single argument consumend by an xlat function
145 *
146 */
147typedef struct {
148 bool required; //!< Argument must be present, and non-empty.
149 bool concat; //!< Concat boxes together.
150 bool single; //!< Argument must only contain a single box
151 xlat_arg_parser_variadic_t variadic; //!< All additional boxes should be processed
152 ///< using this definition.
153 bool always_escape; //!< Pass all arguments to escape function not just
154 ///< tainted ones.
155 fr_type_t type; //!< Type to cast argument to.
156 xlat_escape_func_t func; //!< Function to handle tainted values.
157 fr_value_box_safe_for_t safe_for; //!< Escaped value to set for boxes processed by
158 ///< this escape function.
159 void *uctx; //!< Argument to pass to escape callback.
161
162typedef struct {
163 tmpl_res_rules_t const *tr_rules; //!< tmpl resolution rules.
164 bool allow_unresolved; //!< If false, all resolution steps must be completed
165 ///< this round, otherwise an error will be produced.
167
168#define XLAT_ARG_PARSER_TERMINATOR { .required = false, .concat = false, .single = false, .variadic = false, \
169 .type = FR_TYPE_NULL, .func = NULL, .uctx = NULL }
170
171/** A callback when the the timeout occurs
172 *
173 * Used when a xlat needs wait for an event.
174 * Typically the callback is set, and then the xlat returns unlang_xlat_yield().
175 *
176 * @note The callback is automatically removed on unlang_interpret_mark_runnable(), i.e. if an event
177 * on a registered FD occurs before the timeout event fires.
178 *
179 * @param[in] xctx xlat calling ctx. Contains all instance data.
180 * @param[in] request the request.
181 * @param[in] fired the time the timeout event actually fired.
182 */
183typedef void (*fr_unlang_xlat_timeout_t)(xlat_ctx_t const *xctx, request_t *request, fr_time_t fired);
184
185/** A callback when the the timeout occurs
186 *
187 * Used when a xlat needs wait for an event.
188 * Typically the callback is set, and then the xlat returns unlang_xlat_yield().
189 *
190 * @note The callback is automatically removed on unlang_interpret_mark_runnable(), i.e. if an event
191 * on a registered FD occurs before the timeout event fires.
192 *
193 * @param[in] xctx xlat calling ctx. Contains all instance data.
194 * @param[in] request the request.
195 * @param[in] retry retry status. "now" is in retry->updated
196 */
197typedef void (*fr_unlang_xlat_retry_t)(xlat_ctx_t const *xctx, request_t *request, fr_retry_t const *retry);
198
199/** A callback when the FD is ready for reading
200 *
201 * Used when a xlat needs to read from an FD. Typically the callback is set, and then the
202 * xlat returns unlang_xlat_yield().
203 *
204 * @note The callback is automatically removed on unlang_interpret_mark_runnable(), so
205 *
206 * @param[in] xctx xlat calling ctx. Contains all instance data.
207 * @param[in] request the current request.
208 * @param[in] fd the file descriptor.
209 */
210typedef void (*fr_unlang_xlat_fd_event_t)(xlat_ctx_t const *xctx, request_t *request, int fd);
211
212/** xlat callback function
213 *
214 * Ingests a list of value boxes as arguments.
215 *
216 * @param[in] ctx to allocate any fr_value_box_t in.
217 * @param[out] out Where to append #fr_value_box_t containing the output of
218 * this function.
219 * @param[in] xctx xlat calling ctx. Contains all instance data and the resume
220 * ctx if this function is being resumed.
221 * @param[in] request The current request.
222 * @param[in] in Input arguments.
223 * @return
224 * - XLAT_ACTION_YIELD xlat function is waiting on an I/O event and
225 * has pushed a resumption function onto the stack.
226 * - XLAT_ACTION_DONE xlat function completed. This does not necessarily
227 * mean it turned a result.
228 * - XLAT_ACTION_FAIL the xlat function failed.
229 */
230typedef xlat_action_t (*xlat_func_t)(TALLOC_CTX *ctx, fr_dcursor_t *out,
231 xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in);
232
233/** A callback when the request gets a fr_signal_t.
234 *
235 * @note The callback is automatically removed on unlang_interpret_mark_runnable().
236 *
237 * @param[in] request The current request.
238 * @param[in] xctx xlat calling ctx. Contains all instance data.
239 * @param[in] action which is signalling the request.
240 */
241typedef void (*xlat_func_signal_t)(xlat_ctx_t const *xctx, request_t *request, fr_signal_t action);
242
243/** Allocate new instance data for an xlat instance
244 *
245 * @param[in] xctx instantiate/detach calling ctx.
246
247 * @return
248 * - 0 on success.
249 * - -1 on failure.
250 */
251typedef int (*xlat_instantiate_t)(xlat_inst_ctx_t const *xctx);
252
253/** Allocate new thread instance data for an xlat instance
254 *
255 * @param[in] xctx thread instantiate/detach ctx.
256 * @return
257 * - 0 on success.
258 * - -1 on failure.
259 */
261
262/** xlat detach callback
263 *
264 * Is called whenever an xlat_node_t is freed.
265 *
266 * Detach should close all handles associated with the xlat instance, and
267 * free any memory allocated during instantiate.
268 *
269 * @param[in] xctx instantiate/detach calling ctx.
270 * @return
271 * - 0 on success.
272 * - -1 if detach failed.
273 */
274typedef int (*xlat_detach_t)(xlat_inst_ctx_t const *xctx);
275
276/** xlat thread detach callback
277 *
278 * Is called whenever an xlat_node_t is freed (if ephemeral),
279 * or when a thread exits.
280 *
281 * Detach should close all handles associated with the xlat instance, and
282 * free any memory allocated during instantiate.
283 *
284 * @param[in] xctx thread instantiate/detach calling ctx.
285 * @return
286 * - 0 on success.
287 * - -1 if detach failed.
288 */
290
291/** Set the next argument to the next item in the input list or NULL
292 *
293 * @param[in] _list we're extracting arguments from.
294 * @param[in] _prev argument.
295 * @param[in] _curr argument we're populating.
296 */
297#define XLAT_ARGS_NEXT(_list, _prev, _curr) *(_curr) = likely(*(_prev) != NULL) ? fr_value_box_list_next(_list, *(_prev)) : NULL
298
299#define XLAT_ARGS_1(_list, _a) \
300 *(_a) = fr_value_box_list_head(_list)
301
302#define XLAT_ARGS_2(_list, _a, _b) \
303 do { \
304 *(_a) = fr_value_box_list_head(_list); \
305 XLAT_ARGS_NEXT(_list, _a, _b); \
306 } while (0)
307
308#define XLAT_ARGS_3(_list, _a, _b, _c) \
309 do { \
310 *(_a) = fr_value_box_list_head(_list); \
311 XLAT_ARGS_NEXT(_list, _a, _b); \
312 XLAT_ARGS_NEXT(_list, _b, _c); \
313 } while (0)
314
315#define XLAT_ARGS_4(_list, _a, _b, _c, _d) \
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 } while (0)
322
323#define XLAT_ARGS_5(_list, _a, _b, _c, _d, _e) \
324 do { \
325 *(_a) = fr_value_box_list_head(_list); \
326 XLAT_ARGS_NEXT(_list, _a, _b); \
327 XLAT_ARGS_NEXT(_list, _b, _c); \
328 XLAT_ARGS_NEXT(_list, _c, _d); \
329 XLAT_ARGS_NEXT(_list, _d, _e); \
330 } while (0)
331
332#define XLAT_ARGS_6(_list, _a, _b, _c, _d, _e, _f) \
333 do { \
334 *(_a) = fr_value_box_list_head(_list); \
335 XLAT_ARGS_NEXT(_list, _a, _b); \
336 XLAT_ARGS_NEXT(_list, _b, _c); \
337 XLAT_ARGS_NEXT(_list, _c, _d); \
338 XLAT_ARGS_NEXT(_list, _d, _e); \
339 XLAT_ARGS_NEXT(_list, _e, _f); \
340 } while (0)
341
342#define XLAT_ARGS_7(_list, _a, _b, _c, _d, _e, _f, _g) \
343 do { \
344 *(_a) = fr_value_box_list_head(_list); \
345 XLAT_ARGS_NEXT(_list, _a, _b); \
346 XLAT_ARGS_NEXT(_list, _b, _c); \
347 XLAT_ARGS_NEXT(_list, _c, _d); \
348 XLAT_ARGS_NEXT(_list, _d, _e); \
349 XLAT_ARGS_NEXT(_list, _e, _f); \
350 XLAT_ARGS_NEXT(_list, _f, _g); \
351 } while (0)
352
353#define XLAT_ARGS_8(_list, _a, _b, _c, _d, _e, _f, _g, _h) \
354 do { \
355 *(_a) = fr_value_box_list_head(_list); \
356 XLAT_ARGS_NEXT(_list, _a, _b); \
357 XLAT_ARGS_NEXT(_list, _b, _c); \
358 XLAT_ARGS_NEXT(_list, _c, _d); \
359 XLAT_ARGS_NEXT(_list, _d, _e); \
360 XLAT_ARGS_NEXT(_list, _e, _f); \
361 XLAT_ARGS_NEXT(_list, _f, _g); \
362 XLAT_ARGS_NEXT(_list, _g, _h); \
363 } while (0)
364
365/** Trampoline macro for selecting which ``XLAT_ARGS_<num>`` macro to expand
366 *
367 *
368 * @param[in] XLAT_ARGS_N the name of the macro to expand.
369 * Created by concatenating ``XLAT_ARGS_ + <number of variadic arguments>``.
370 * @param[in] _list The input list of value boxes.
371 * @param[in] ... The variadic arguments themselves.
372 */
373#define _XLAT_ARGS_X(XLAT_ARGS_N, _list, ...) XLAT_ARGS_N(_list, __VA_ARGS__)
374
375/** Populate local variables with value boxes from the input list
376 *
377 * @param[in] _list input list to pull arguments from.
378 * @param[in] ... 1-8 output boxes pointers `fr_value_box_t **`
379 * e.g. `XLAT_ARGS(in, &arg0, &arg1, &argN)``.
380 */
381#define XLAT_ARGS(_list, ...) _XLAT_ARGS_X(JOIN(XLAT_ARGS_, VA_NARG(__VA_ARGS__)), _list, __VA_ARGS__)
382
383ssize_t xlat_eval(char *out, size_t outlen, request_t *request, char const *fmt, xlat_escape_legacy_t escape,
384 void const *escape_ctx)
385 CC_HINT(nonnull (1 ,3 ,4));
386
387ssize_t xlat_eval_compiled(char *out, size_t outlen, request_t *request, xlat_exp_head_t const *head,
388 xlat_escape_legacy_t escape, void const *escape_ctx)
389 CC_HINT(nonnull (1 ,3 ,4));
390
391ssize_t xlat_aeval(TALLOC_CTX *ctx, char **out, request_t *request,
392 char const *fmt, xlat_escape_legacy_t escape, void const *escape_ctx)
393 CC_HINT(nonnull(2, 3, 4));
394
395ssize_t xlat_aeval_compiled(TALLOC_CTX *ctx, char **out, request_t *request,
396 xlat_exp_head_t const *head, xlat_escape_legacy_t escape, void const *escape_ctx)
397 CC_HINT(nonnull (2, 3, 4));
398
399int xlat_aeval_compiled_argv(TALLOC_CTX *ctx, char ***argv, request_t *request,
400 xlat_exp_head_t const *head, xlat_escape_legacy_t escape, void const *escape_ctx);
401
402int xlat_flatten_compiled_argv(TALLOC_CTX *ctx, xlat_exp_head_t ***argv, xlat_exp_head_t *head);
403
405 fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules);
406
408 fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules);
409
411 xlat_t const *xlat,
412 fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules, bool comma, bool allow_attr);
413
415 fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules,
416 fr_value_box_safe_for_t literals_safe_for);
417
419
420static inline fr_slen_t xlat_aprint(TALLOC_CTX *ctx, char **out, xlat_exp_head_t const *head,
421 fr_sbuff_escape_rules_t const *e_rules)
423
424bool xlat_is_truthy(xlat_exp_head_t const *head, bool *out);
425
427
428void xlat_debug(xlat_exp_t const *node);
429
431
433
435
436bool xlat_to_string(TALLOC_CTX *ctx, char **str, xlat_exp_head_t **head);
437
439
440void xlat_debug_attr_list(request_t *request, fr_pair_list_t const *list);
441void xlat_debug_attr_vp(request_t *request, fr_pair_t *vp, tmpl_t const *vpt);
442
444 UNUSED xlat_ctx_t const *xctx,
445 request_t *request, fr_value_box_list_t *args);
446/*
447 * xlat_tokenize.c
448 */
449tmpl_t *xlat_to_tmpl_attr(TALLOC_CTX *ctx, xlat_exp_head_t *xlat);
450
451int xlat_from_tmpl_attr(TALLOC_CTX *ctx, xlat_exp_head_t **head, tmpl_t **vpt_p);
452
453bool xlat_impure_func(xlat_exp_head_t const *head) CC_HINT(nonnull);
454
455/*
456 * xlat_alloc.c
457 */
459#define xlat_copy(_ctx, _out, _in) _xlat_copy(NDEBUG_LOCATION_EXP _ctx, _out, _in)
460#ifdef WITH_VERIFY_PTR
461void xlat_exp_verify(xlat_exp_t const *node);
462void xlat_exp_head_verify(xlat_exp_head_t const *head);
463
464# define XLAT_VERIFY(_node) xlat_exp_verify(_node)
465# define XLAT_HEAD_VERIFY(_head) xlat_exp_head_verify(_head)
466#else
467# define XLAT_VERIFY(_node)
468# define XLAT_HEAD_VERIFY(_head)
469#endif
470
471/*
472 * xlat_inst.c
473 */
475
476int xlat_thread_instantiate(TALLOC_CTX *ctx, fr_event_list_t *el);
477
478int xlat_instantiate(void);
479
480void xlat_thread_detach(void);
481
483
485
486int xlat_finalize(xlat_exp_head_t *head, fr_event_list_t *runtime_el); /* xlat_instance_register() or xlat_instantiate_ephemeral() */
487
488void xlat_instances_free(void);
489
490/*
491 * xlat_purify.c
492 */
495
496int xlat_purify_op(TALLOC_CTX *ctx, xlat_exp_t **out, xlat_exp_t *lhs, fr_token_t op, xlat_exp_t *rhs);
497
498/*
499 * xlat.c
500 */
502 void const *rctx, fr_time_t when);
503
504int unlang_xlat_push(TALLOC_CTX *ctx, bool *p_success, fr_value_box_list_t *out,
505 request_t *request, xlat_exp_head_t const *head, bool top_frame)
506 CC_HINT(warn_unused_result);
507
508int unlang_xlat_eval(TALLOC_CTX *ctx, fr_value_box_list_t *out,
509 request_t *request, xlat_exp_head_t const *head)
510 CC_HINT(warn_unused_result);
511
512int unlang_xlat_eval_type(TALLOC_CTX *ctx, fr_value_box_t *out, fr_type_t type, fr_dict_attr_t const *enumv,
513 request_t *request, xlat_exp_head_t const *head)
514 CC_HINT(warn_unused_result);
515
517 xlat_func_t callback, xlat_func_signal_t signal, fr_signal_t sigmask,
518 void *rctx);
519
521 xlat_func_signal_t signal, fr_signal_t sigmask, void *rctx,
522 fr_retry_config_t const *retry_cfg);
523
524/*
525 * xlat_builtin.c
526 */
528int xlat_global_init(void);
530
531#ifdef __cplusplus
532}
533#endif
va_list args
Definition acutest.h:770
static int const char * fmt
Definition acutest.h:573
#define RCSIDH(h, id)
Definition build.h:484
#define NDEBUG_LOCATION_ARGS
Pass caller information to the function.
Definition build.h:263
#define UNUSED
Definition build.h:315
Structure containing both a talloc pool, a list of parsed call_env_pairs.
Definition call_env.h:247
static fr_slen_t in
Definition dict.h:824
unsigned int fr_heap_index_t
Definition heap.h:80
Stores all information relating to an event list.
Definition event.c:411
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
#define SBUFF_OUT_TALLOC_FUNC_NO_LEN_DEF(_func,...)
static fr_slen_t vpt
Definition tmpl.h:1272
Similar to tmpl_rules_t, but used to specify parameters that may change during subsequent resolution ...
Definition tmpl.h:373
Optional arguments passed to vp_tmpl functions.
Definition tmpl.h:341
fr_signal_t
Signals that can be generated/processed by request signal handlers.
Definition signal.h:38
fr_aka_sim_id_type_t type
fr_pair_t * vp
Stores an attribute, a value and various bits of other data.
Definition pair.h:68
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:76
tmpl_res_rules_t const * tr_rules
tmpl resolution rules.
Definition xlat.h:163
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:155
int(* xlat_thread_detach_t)(xlat_thread_inst_ctx_t const *xctx)
xlat thread detach callback
Definition xlat.h:289
xlat_exp_t * node
Node this data relates to.
Definition xlat.h:81
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:739
void * data
Thread specific instance data.
Definition xlat.h:98
xlat_thread_inst_t * xlat_thread_instance_find(xlat_exp_t const *node)
Retrieve xlat/thread specific instance data.
Definition xlat_inst.c:407
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:97
int(* xlat_detach_t)(xlat_inst_ctx_t const *xctx)
xlat detach callback
Definition xlat.h:274
int xlat_from_tmpl_attr(TALLOC_CTX *ctx, xlat_exp_head_t **head, tmpl_t **vpt_p)
Convert attr tmpl to an xlat for &attr[*].
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:210
fr_heap_index_t idx
Entry in heap of xlat thread instances.
Definition xlat.h:90
int xlat_instance_register_func(xlat_exp_t *node)
Callback for creating "permanent" instance data for a xlat_exp_t.
Definition xlat_inst.c:595
uint64_t active_callers
total number of times we've been called
Definition xlat.h:104
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:3188
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:159
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:489
bool required
Argument must be present, and non-empty.
Definition xlat.h:148
fr_table_num_sorted_t const xlat_action_table[]
Definition xlat_eval.c:83
bool xlat_impure_func(xlat_exp_head_t const *head)
xlat_escape_func_t func
Function to handle tainted values.
Definition xlat.h:156
fr_event_list_t * el
Event list associated with this thread.
Definition xlat.h:95
ssize_t(* xlat_escape_legacy_t)(request_t *request, char *out, size_t outlen, char const *in, void *arg)
Definition xlat.h:57
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:1546
bool allow_unresolved
If false, all resolution steps must be completed.
Definition xlat.h:164
fr_slen_t xlat_tokenize_argv(TALLOC_CTX *ctx, xlat_exp_head_t **head, fr_sbuff_t *in, xlat_t const *xlat, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules, bool comma, bool allow_attr)
Tokenize an xlat expansion into a series of XLAT_TYPE_CHILD arguments.
ssize_t xlat_eval(char *out, size_t outlen, request_t *request, char const *fmt, xlat_escape_legacy_t escape, void const *escape_ctx))
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)
bool xlat
it's an xlat wrapper
Definition xlat.h:119
xlat_arg_parser_variadic_t
Definition xlat.h:136
@ XLAT_ARG_VARIADIC_EMPTY_KEEP
Empty argument groups are left alone, and either passed through as empty groups or null boxes.
Definition xlat.h:139
@ XLAT_ARG_VARIADIC_EMPTY_SQUASH
Empty argument groups are removed.
Definition xlat.h:138
@ XLAT_ARG_VARIADIC_DISABLED
Definition xlat.h:137
static fr_slen_t head
Definition xlat.h:422
xlat_arg_parser_variadic_t variadic
All additional boxes should be processed using this definition.
Definition xlat.h:151
int xlat_instantiate(void)
Call instantiation functions for all registered, "permanent" xlats.
Definition xlat_inst.c:513
int xlat_flatten_compiled_argv(TALLOC_CTX *ctx, xlat_exp_head_t ***argv, xlat_exp_head_t *head)
Turn xlat_tokenize_argv() into an argv[] array, and nuke the input list.
Definition xlat_eval.c:1622
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:691
bool concat
Concat boxes together.
Definition xlat.h:149
bool single
Argument must only contain a single box.
Definition xlat.h:150
size_t xlat_action_table_len
Definition xlat_eval.c:89
int xlat_protocols_register(void)
Register xlats for any loaded dictionaries.
void xlat_debug_attr_list(request_t *request, fr_pair_list_t const *list)
bool always_escape
Pass all arguments to escape function not just tainted ones.
Definition xlat.h:153
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:241
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:1563
fr_value_box_safe_for_t safe_for
Escaped value to set for boxes processed by this escape function.
Definition xlat.h:157
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)
bool can_purify
if the xlat has a pure function with pure arguments.
Definition xlat.h:116
xlat_input_type_t
Definition xlat.h:47
@ XLAT_INPUT_ARGS
Ingests a number of arguments.
Definition xlat.h:49
@ XLAT_INPUT_UNPROCESSED
No input argument processing.
Definition xlat.h:48
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:444
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 the timeout occurs.
Definition xlat.h:197
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:230
void xlat_debug(xlat_exp_t const *node)
int _xlat_copy(NDEBUG_LOCATION_ARGS TALLOC_CTX *ctx, xlat_exp_head_t *out, xlat_exp_head_t const *in)
Definition xlat_alloc.c:314
fr_slen_t xlat_validate_function_args(xlat_exp_t *node)
void * data
xlat node specific instance data.
Definition xlat.h:82
void xlat_debug_attr_vp(request_t *request, fr_pair_t *vp, tmpl_t const *vpt)
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:769
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:573
void xlat_instances_free(void)
Walk over all registered instance data and free them explicitly.
Definition xlat_inst.c:709
int unlang_xlat_push(TALLOC_CTX *ctx, bool *p_success, 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:286
bool pure
has no external side effects, true for BOX, LITERAL, and some functions
Definition xlat.h:114
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, fr_value_box_safe_for_t literals_safe_for)
Tokenize an xlat expansion.
int xlat_aeval_compiled_argv(TALLOC_CTX *ctx, char ***argv, request_t *request, xlat_exp_head_t const *head, xlat_escape_legacy_t escape, void const *escape_ctx)
Synchronous compile xlat_tokenize_argv() into argv[] array.
Definition xlat_eval.c:1587
bool needs_resolving
Needs pass2 resolution.
Definition xlat.h:113
int(* xlat_thread_instantiate_t)(xlat_thread_inst_ctx_t const *xctx)
Allocate new thread instance data for an xlat instance.
Definition xlat.h:260
void(* fr_unlang_xlat_timeout_t)(xlat_ctx_t const *xctx, request_t *request, fr_time_t fired)
A callback when the the timeout occurs.
Definition xlat.h:183
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:103
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:152
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:695
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_PUSH_CHILD
A deeper level of nesting needs to be evaluated.
Definition xlat.h:38
@ XLAT_ACTION_DONE
We're done evaluating this level of nesting.
Definition xlat.h:43
call_env_t const * call_env
Per call environment.
Definition xlat.h:83
bool constant
xlat is just tmpl_attr_tail_data, or XLAT_BOX
Definition xlat.h:118
int(* xlat_escape_func_t)(request_t *request, fr_value_box_t *vb, void *uctx)
A function used to escape an argument passed to an xlat.
Definition xlat.h:134
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:3171
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:3165
bool impure_func
xlat contains an impure function
Definition xlat.h:115
int xlat_instance_unregister_func(xlat_exp_t *node)
Remove a node from the list of xlat instance data.
Definition xlat_inst.c:550
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:1554
void xlat_global_free(void)
int(* xlat_instantiate_t)(xlat_inst_ctx_t const *xctx)
Allocate new instance data for an xlat instance.
Definition xlat.h:251
module_ctx_t const * mctx
A synthesised module calling ctx containing module global and thread instance data.
Definition xlat.h:100
Definition for a single argument consumend by an xlat function.
Definition xlat.h:147
Flags that control resolution and evaluation.
Definition xlat.h:112
Instance data for an xlat expansion node.
Definition xlat.h:75
Thread specific instance data for xlat expansion node.
Definition xlat.h:89
uintptr_t fr_value_box_safe_for_t
Escaping that's been applied to a value box.
Definition value.h:155
int nonnull(2, 5))
static size_t char ** out
Definition value.h:997
An xlat calling ctx.
Definition xlat_ctx.h:49
An xlat instantiation ctx.
Definition xlat_ctx.h:61
An xlat thread instantiation ctx.
Definition xlat_ctx.h:72
An xlat expansion node.
Definition xlat_priv.h:151