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