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: e5719f3936212676b695ebe3ca7ff8e816c5f54b $
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: e5719f3936212676b695ebe3ca7ff8e816c5f54b $")
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
124/** A function used to escape an argument passed to an xlat
125 *
126 * @param[in] request being processed. Used mostly for debugging.
127 * @param[in,out] vb to escape
128 * @param[in] uctx a "context" for the escaping
129 * @return
130 * - 0 on success.
131 * - -1 on failure.
132 */
133typedef int (*xlat_escape_func_t)(request_t *request, fr_value_box_t *vb, void *uctx);
134
135typedef enum {
137 XLAT_ARG_VARIADIC_EMPTY_SQUASH = 1, //!< Empty argument groups are removed.
138 XLAT_ARG_VARIADIC_EMPTY_KEEP = 2, //!< Empty argument groups are left alone,
139 ///< and either passed through as empty groups
140 ///< or null boxes.
142
143/** Definition for a single argument consumed by an xlat function
144 *
145 */
146typedef struct {
147 unsigned int required : 1; //!< Argument must be present, and non-empty.
148 unsigned int concat : 1; //!< Concat boxes together.
149 unsigned int single : 1; //!< Argument must only contain a single box
150 unsigned int allow_wildcard : 1; //!< For parsing the cursor
151 unsigned int will_escape : 1; //!< the function will do escaping and concatenation.
152 unsigned int always_escape : 1; //!< Pass all arguments to escape function not just
153 ///< tainted ones.
154 xlat_arg_parser_variadic_t variadic; //!< All additional boxes should be processed
155 ///< using this definition.
156 fr_type_t type; //!< Type to cast argument to.
157 xlat_escape_func_t func; //!< Function to handle tainted values.
158 fr_value_box_safe_for_t safe_for; //!< Escaped value to set for boxes processed by
159 ///< this escape function.
160 void *uctx; //!< Argument to pass to escape callback.
162
163#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 }
164
165typedef struct {
166 tmpl_res_rules_t const *tr_rules; //!< tmpl resolution rules.
167 bool allow_unresolved; //!< If false, all resolution steps must be completed
168 ///< this round, otherwise an error will be produced.
170
171#define XLAT_ARG_PARSER_TERMINATOR { .required = false, .concat = false, .single = false, .variadic = false, \
172 .type = FR_TYPE_NULL, .func = NULL, .uctx = NULL }
173
174/** A callback when the timeout occurs
175 *
176 * Used when a xlat needs to wait for an event.
177 * Typically the callback is set, and then the xlat returns unlang_xlat_yield().
178 *
179 * @note The callback is automatically removed on unlang_interpret_mark_runnable(), i.e. if an event
180 * on a registered FD occurs before the timeout event fires.
181 *
182 * @param[in] xctx xlat calling ctx. Contains all instance data.
183 * @param[in] request the request.
184 * @param[in] fired the time the timeout event actually fired.
185 */
186typedef void (*fr_unlang_xlat_timeout_t)(xlat_ctx_t const *xctx, request_t *request, fr_time_t fired);
187
188/** A callback when the timeout occurs
189 *
190 * Used when a xlat needs to wait for an event.
191 * Typically the callback is set, and then the xlat returns unlang_xlat_yield().
192 *
193 * @note The callback is automatically removed on unlang_interpret_mark_runnable(), i.e. if an event
194 * on a registered FD occurs before the timeout event fires.
195 *
196 * @param[in] xctx xlat calling ctx. Contains all instance data.
197 * @param[in] request the request.
198 * @param[in] retry retry status. "now" is in retry->updated
199 */
200typedef void (*fr_unlang_xlat_retry_t)(xlat_ctx_t const *xctx, request_t *request, fr_retry_t const *retry);
201
202/** A callback when the FD is ready for reading
203 *
204 * Used when a xlat needs to read from an FD. Typically the callback is set, and then the
205 * xlat returns unlang_xlat_yield().
206 *
207 * @note The callback is automatically removed on unlang_interpret_mark_runnable(), so
208 *
209 * @param[in] xctx xlat calling ctx. Contains all instance data.
210 * @param[in] request the current request.
211 * @param[in] fd the file descriptor.
212 */
213typedef void (*fr_unlang_xlat_fd_event_t)(xlat_ctx_t const *xctx, request_t *request, int fd);
214
215/** xlat callback function
216 *
217 * Ingests a list of value boxes as arguments.
218 *
219 * @param[in] ctx to allocate any fr_value_box_t in.
220 * @param[out] out Where to append #fr_value_box_t containing the output of
221 * this function.
222 * @param[in] xctx xlat calling ctx. Contains all instance data and the resume
223 * ctx if this function is being resumed.
224 * @param[in] request The current request.
225 * @param[in] in Input arguments.
226 * @return
227 * - XLAT_ACTION_YIELD xlat function is waiting on an I/O event and
228 * has pushed a resumption function onto the stack.
229 * - XLAT_ACTION_DONE xlat function completed. This does not necessarily
230 * mean it turned a result.
231 * - XLAT_ACTION_FAIL the xlat function failed.
232 */
233typedef xlat_action_t (*xlat_func_t)(TALLOC_CTX *ctx, fr_dcursor_t *out,
234 xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in);
235
236/** A callback when the request gets a fr_signal_t.
237 *
238 * @note The callback is automatically removed on unlang_interpret_mark_runnable().
239 *
240 * @param[in] request The current request.
241 * @param[in] xctx xlat calling ctx. Contains all instance data.
242 * @param[in] action which is signalling the request.
243 */
244typedef void (*xlat_func_signal_t)(xlat_ctx_t const *xctx, request_t *request, fr_signal_t action);
245
246/** Allocate new instance data for an xlat instance
247 *
248 * @param[in] xctx instantiate/detach calling ctx.
249
250 * @return
251 * - 0 on success.
252 * - -1 on failure.
253 */
254typedef int (*xlat_instantiate_t)(xlat_inst_ctx_t const *xctx);
255
256/** Allocate new thread instance data for an xlat instance
257 *
258 * @param[in] xctx thread instantiate/detach ctx.
259 * @return
260 * - 0 on success.
261 * - -1 on failure.
262 */
264
265/** xlat detach callback
266 *
267 * Is called whenever an xlat_node_t is freed.
268 *
269 * Detach should close all handles associated with the xlat instance, and
270 * free any memory allocated during instantiate.
271 *
272 * @param[in] xctx instantiate/detach calling ctx.
273 * @return
274 * - 0 on success.
275 * - -1 if detach failed.
276 */
277typedef int (*xlat_detach_t)(xlat_inst_ctx_t const *xctx);
278
279/** xlat thread detach callback
280 *
281 * Is called whenever an xlat_node_t is freed (if ephemeral),
282 * or when a thread exits.
283 *
284 * Detach should close all handles associated with the xlat instance, and
285 * free any memory allocated during instantiate.
286 *
287 * @param[in] xctx thread instantiate/detach calling ctx.
288 * @return
289 * - 0 on success.
290 * - -1 if detach failed.
291 */
293
294/** Set the next argument to the next item in the input list or NULL
295 *
296 * @param[in] _list we're extracting arguments from.
297 * @param[in] _prev argument.
298 * @param[in] _curr argument we're populating.
299 */
300#define XLAT_ARGS_NEXT(_list, _prev, _curr) *(_curr) = likely(*(_prev) != NULL) ? fr_value_box_list_next(_list, *(_prev)) : NULL
301
302#define XLAT_ARGS_1(_list, _a) \
303 *(_a) = fr_value_box_list_head(_list)
304
305#define XLAT_ARGS_2(_list, _a, _b) \
306 do { \
307 *(_a) = fr_value_box_list_head(_list); \
308 XLAT_ARGS_NEXT(_list, _a, _b); \
309 } while (0)
310
311#define XLAT_ARGS_3(_list, _a, _b, _c) \
312 do { \
313 *(_a) = fr_value_box_list_head(_list); \
314 XLAT_ARGS_NEXT(_list, _a, _b); \
315 XLAT_ARGS_NEXT(_list, _b, _c); \
316 } while (0)
317
318#define XLAT_ARGS_4(_list, _a, _b, _c, _d) \
319 do { \
320 *(_a) = fr_value_box_list_head(_list); \
321 XLAT_ARGS_NEXT(_list, _a, _b); \
322 XLAT_ARGS_NEXT(_list, _b, _c); \
323 XLAT_ARGS_NEXT(_list, _c, _d); \
324 } while (0)
325
326#define XLAT_ARGS_5(_list, _a, _b, _c, _d, _e) \
327 do { \
328 *(_a) = fr_value_box_list_head(_list); \
329 XLAT_ARGS_NEXT(_list, _a, _b); \
330 XLAT_ARGS_NEXT(_list, _b, _c); \
331 XLAT_ARGS_NEXT(_list, _c, _d); \
332 XLAT_ARGS_NEXT(_list, _d, _e); \
333 } while (0)
334
335#define XLAT_ARGS_6(_list, _a, _b, _c, _d, _e, _f) \
336 do { \
337 *(_a) = fr_value_box_list_head(_list); \
338 XLAT_ARGS_NEXT(_list, _a, _b); \
339 XLAT_ARGS_NEXT(_list, _b, _c); \
340 XLAT_ARGS_NEXT(_list, _c, _d); \
341 XLAT_ARGS_NEXT(_list, _d, _e); \
342 XLAT_ARGS_NEXT(_list, _e, _f); \
343 } while (0)
344
345#define XLAT_ARGS_7(_list, _a, _b, _c, _d, _e, _f, _g) \
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 } while (0)
355
356#define XLAT_ARGS_8(_list, _a, _b, _c, _d, _e, _f, _g, _h) \
357 do { \
358 *(_a) = fr_value_box_list_head(_list); \
359 XLAT_ARGS_NEXT(_list, _a, _b); \
360 XLAT_ARGS_NEXT(_list, _b, _c); \
361 XLAT_ARGS_NEXT(_list, _c, _d); \
362 XLAT_ARGS_NEXT(_list, _d, _e); \
363 XLAT_ARGS_NEXT(_list, _e, _f); \
364 XLAT_ARGS_NEXT(_list, _f, _g); \
365 XLAT_ARGS_NEXT(_list, _g, _h); \
366 } while (0)
367
368/** Trampoline macro for selecting which ``XLAT_ARGS_<num>`` macro to expand
369 *
370 *
371 * @param[in] XLAT_ARGS_N the name of the macro to expand.
372 * Created by concatenating ``XLAT_ARGS_ + <number of variadic arguments>``.
373 * @param[in] _list The input list of value boxes.
374 * @param[in] ... The variadic arguments themselves.
375 */
376#define _XLAT_ARGS_X(XLAT_ARGS_N, _list, ...) XLAT_ARGS_N(_list, __VA_ARGS__)
377
378/** Populate local variables with value boxes from the input list
379 *
380 * @param[in] _list input list to pull arguments from.
381 * @param[in] ... 1-8 output boxes pointers `fr_value_box_t **`
382 * e.g. `XLAT_ARGS(in, &arg0, &arg1, &argN)``.
383 */
384#define XLAT_ARGS(_list, ...) _XLAT_ARGS_X(JOIN(XLAT_ARGS_, VA_NARG(__VA_ARGS__)), _list, __VA_ARGS__)
385
386ssize_t xlat_eval(char *out, size_t outlen, request_t *request, char const *fmt, xlat_escape_legacy_t escape,
387 void const *escape_ctx)
388 CC_HINT(nonnull (1 ,3 ,4));
389
390ssize_t xlat_eval_compiled(char *out, size_t outlen, request_t *request, xlat_exp_head_t const *head,
391 xlat_escape_legacy_t escape, void const *escape_ctx)
392 CC_HINT(nonnull (1 ,3 ,4));
393
394ssize_t xlat_aeval(TALLOC_CTX *ctx, char **out, request_t *request,
395 char const *fmt, xlat_escape_legacy_t escape, void const *escape_ctx)
396 CC_HINT(nonnull(2, 3, 4));
397
398ssize_t xlat_aeval_compiled(TALLOC_CTX *ctx, char **out, request_t *request,
399 xlat_exp_head_t const *head, xlat_escape_legacy_t escape, void const *escape_ctx)
400 CC_HINT(nonnull (2, 3, 4));
401
402int xlat_flatten_to_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) CC_HINT(nonnull(1,2,3));
406
408 fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules) CC_HINT(nonnull(1,2,3));
409
411 xlat_arg_parser_t const *xlat_args, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules,
412 bool spaces) CC_HINT(nonnull(1,2,3,6));
413
415 fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules);
416
418
419static inline fr_slen_t xlat_aprint(TALLOC_CTX *ctx, char **out, xlat_exp_head_t const *head,
420 fr_sbuff_escape_rules_t const *e_rules)
422
423bool xlat_is_truthy(xlat_exp_head_t const *head, bool *out);
424
426
427void xlat_debug(xlat_exp_t const *node);
428
430
432
434
435bool xlat_to_string(TALLOC_CTX *ctx, char **str, xlat_exp_head_t **head);
436
438
440 UNUSED xlat_ctx_t const *xctx,
441 request_t *request, fr_value_box_list_t *args);
442
443/*
444 * xlat_tokenize.c
445 */
446tmpl_t *xlat_to_tmpl_attr(TALLOC_CTX *ctx, xlat_exp_head_t *xlat);
447
448bool xlat_impure_func(xlat_exp_head_t const *head) CC_HINT(nonnull);
449
451
452/*
453 * xlat_alloc.c
454 */
456#define xlat_copy(_ctx, _out, _in) _xlat_copy(NDEBUG_LOCATION_EXP _ctx, _out, _in)
457#ifdef WITH_VERIFY_PTR
458void xlat_exp_verify(xlat_exp_t const *node);
459void xlat_exp_head_verify(xlat_exp_head_t const *head);
460
461# define XLAT_VERIFY(_node) xlat_exp_verify(_node)
462# define XLAT_HEAD_VERIFY(_head) xlat_exp_head_verify(_head)
463#else
464# define XLAT_VERIFY(_node)
465# define XLAT_HEAD_VERIFY(_head)
466#endif
467
468/*
469 * xlat_inst.c
470 */
472
473int xlat_thread_instantiate(TALLOC_CTX *ctx, fr_event_list_t *el);
474
475int xlat_instantiate(void);
476
477void xlat_thread_detach(void);
478
480
482
483int xlat_finalize(xlat_exp_head_t *head, fr_event_list_t *runtime_el); /* xlat_instance_register() or xlat_instantiate_ephemeral() */
484
485void xlat_instances_free(void);
486
487/*
488 * xlat_purify.c
489 */
492
493int xlat_purify_op(TALLOC_CTX *ctx, xlat_exp_t **out, xlat_exp_t *lhs, fr_token_t op, xlat_exp_t *rhs);
494
495/*
496 * xlat.c
497 */
499 void const *rctx, fr_time_t when);
500
501#define XLAT_RESULT_SUCCESS(_p_result) ((_p_result)->rcode == RLM_MODULE_OK)
502
503int unlang_xlat_push(TALLOC_CTX *ctx, unlang_result_t *p_result, fr_value_box_list_t *out,
504 request_t *request, xlat_exp_head_t const *head, bool top_frame)
505 CC_HINT(warn_unused_result);
506
507int unlang_xlat_eval(TALLOC_CTX *ctx, fr_value_box_list_t *out,
508 request_t *request, xlat_exp_head_t const *head)
509 CC_HINT(warn_unused_result);
510
511int unlang_xlat_eval_type(TALLOC_CTX *ctx, fr_value_box_t *out, fr_type_t type, fr_dict_attr_t const *enumv,
512 request_t *request, xlat_exp_head_t const *head)
513 CC_HINT(warn_unused_result);
514
516 xlat_func_t callback, xlat_func_signal_t signal, fr_signal_t sigmask,
517 void *rctx);
518
520 xlat_func_signal_t signal, fr_signal_t sigmask, void *rctx,
521 fr_retry_config_t const *retry_cfg);
522
523/*
524 * xlat_builtin.c
525 */
527int xlat_global_init(void);
528
529void xlat_arg_copy_out(TALLOC_CTX *ctx, fr_dcursor_t *cursor, fr_value_box_list_t *in, fr_value_box_t *vb);
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: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:882
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:368
Optional arguments passed to vp_tmpl functions.
Definition tmpl.h:336
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:166
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:156
int(* xlat_thread_detach_t)(xlat_thread_inst_ctx_t const *xctx)
xlat thread detach callback
Definition xlat.h:292
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:277
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:213
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:3202
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:592
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:3237
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:160
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
xlat_escape_func_t func
Function to handle tainted values.
Definition xlat.h:157
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
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:1903
bool allow_unresolved
If false, all resolution steps must be completed.
Definition xlat.h:167
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:148
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:135
@ XLAT_ARG_VARIADIC_EMPTY_KEEP
Empty argument groups are left alone, and either passed through as empty groups or null boxes.
Definition xlat.h:138
@ XLAT_ARG_VARIADIC_EMPTY_SQUASH
Empty argument groups are removed.
Definition xlat.h:137
@ XLAT_ARG_VARIADIC_DISABLED
Definition xlat.h:136
static fr_slen_t head
Definition xlat.h:421
xlat_arg_parser_variadic_t variadic
All additional boxes should be processed using this definition.
Definition xlat.h:154
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:150
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:244
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:1920
fr_value_box_safe_for_t safe_for
Escaped value to set for boxes processed by this escape function.
Definition xlat.h:158
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:200
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:233
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:152
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:1934
unsigned int required
Argument must be present, and non-empty.
Definition xlat.h:147
int _xlat_copy(NDEBUG_LOCATION_ARGS TALLOC_CTX *ctx, xlat_exp_head_t *out, xlat_exp_head_t const *in)
Definition xlat_alloc.c:433
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:706
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:263
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:186
unsigned int single
Argument must only contain a single box.
Definition xlat.h:149
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:692
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
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:133
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:3174
unsigned int will_escape
the function will do escaping and concatenation.
Definition xlat.h:151
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:1911
int(* xlat_instantiate_t)(xlat_inst_ctx_t const *xctx)
Allocate new instance data for an xlat instance.
Definition xlat.h:254
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:146
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
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))
static size_t char ** out
Definition value.h:1030
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