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