The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
tmpl.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: d2be6918826d1601038f6ee8d3a28211d0b4fffe $
20 *
21 * @file lib/server/tmpl.h
22 * @brief Structures and prototypes for templates
23 *
24 * These functions are used to work with #tmpl_t structs.
25 *
26 * #tmpl_t (VPTs) specify either a data source, or a data sink.
27 *
28 * Examples of sources are #TMPL_TYPE_XLAT_UNRESOLVED, #TMPL_TYPE_EXEC and #TMPL_TYPE_ATTR.
29 * Examples of sinks are #TMPL_TYPE_ATTR.
30 *
31 * VPTs are used to gather values or attributes for evaluation, or copying, and to specify
32 * where values or #fr_pair_t should be copied to.
33 *
34 * To create new #tmpl_t use one of the tmpl_*from_* functions. These parse
35 * strings into VPTs. The main parsing function is #tmpl_afrom_substr, which can produce
36 * most types of VPTs. It uses the type of quoting (passed as an #fr_token_t) to determine
37 * what type of VPT to parse the string as. For example a #T_DOUBLE_QUOTED_STRING will
38 * produce either a #TMPL_TYPE_XLAT_UNRESOLVED or a #TMPL_TYPE_DATA_UNRESOLVED (depending if the string
39 * contained a non-literal expansion).
40 *
41 * @see tmpl_afrom_substr
42 * @see tmpl_afrom_attr_str
43 *
44 * In the case of #TMPL_TYPE_ATTR, there are special cursor overlay
45 * functions which can be used to iterate over only the #fr_pair_t that match a
46 * tmpl_t in a given list.
47 *
48 * @see tmpl_dcursor_init
49 * @see tmpl_cursor_next
50 *
51 * Or for simplicity, there are functions which wrap the cursor functions, to copy or
52 * return the #fr_pair_t that match the VPT.
53 *
54 * @see tmpl_copy_pairs
55 * @see tmpl_find_vp
56 *
57 * If you just need the string value of whatever the VPT refers to, the tmpl_*expand
58 * functions may be used. These functions evaluate the VPT, execing, and xlat expanding
59 * as necessary. In the case of #TMPL_TYPE_ATTR, and #FR_TYPE_STRING or #FR_TYPE_OCTETS
60 * #tmpl_expand will return a pointer to the raw #fr_pair_t buffer. This can be very
61 * useful when using the #CONF_FLAG_TMPL type in #conf_parser_t structs, as it allows the
62 * user to determine whether they want the module to sanitise the value using presentation
63 * format specific #xlat_escape_legacy_t function, or to operate on the raw value.
64 *
65 * @see tmpl_expand
66 * @see tmpl_aexpand
67 *
68 * @copyright 2014-2015 The FreeRADIUS server project
69 */
70RCSIDH(tmpl_h, "$Id: d2be6918826d1601038f6ee8d3a28211d0b4fffe $")
71
72#ifdef __cplusplus
73extern "C" {
74#endif
75
76#include <freeradius-devel/util/table.h>
77#include <freeradius-devel/util/dlist.h>
78#include <freeradius-devel/util/value.h>
79
80#include <freeradius-devel/server/tmpl_escape.h>
81
82/** The maximum number of request references allowed
83 *
84 */
85#define TMPL_MAX_REQUEST_REF_NESTING 10
86
88extern size_t pair_list_table_len;
89
90typedef enum requests_ref_e {
91 REQUEST_CURRENT = 0, //!< The current request (default).
92 REQUEST_OUTER, //!< #request_t containing the outer layer of the EAP
93 //!< conversation. Usually the RADIUS request sent
94 //!< by the NAS.
95
96 REQUEST_PARENT, //!< Parent (whatever it is).
97 REQUEST_UNKNOWN //!< Unknown request.
99
101extern size_t tmpl_request_ref_table_len;
102
103/** Base data type is an attribute reference
104 *
105 */
106#define TMPL_FLAG_ATTR 0x01000000
107
108/** Base data type is an xlat expansion
109 *
110 */
111#define TMPL_FLAG_XLAT 0x02000000
112
113/** Is a type of regular expression
114 *
115 */
116#define TMPL_FLAG_REGEX 0x04000000
117
118/** Needs resolution
119 *
120 */
121#define TMPL_FLAG_UNRESOLVED 0x08000000
122
123/** Types of #tmpl_t
124 *
125 * Types may be compound types made up of multiple other types.
126 *
127 * Types which are used as part of compound types are:
128 * - XLAT_TYPE_XLAT - #tmpl_t contains xlat expansion.
129 * - XLAT_TYPE_UNRESOLVED - #tmpl_t contains unresolved elements such as xlat functions or other expansions.
130 */
131typedef enum tmpl_type_e {
132 /** Uninitialised
133 */
135
136 /** Value in native boxed format
137 */
139
140 /** Reference to one or more attributes
141 */
143
144 /** Pre-parsed xlat expansion
145 */
147
148 /** Callout to an external script or program
149 */
151
152 /** Compiled (and possibly JIT'd) regular expression
153 */
155
156 /** Regex where compilation is possible but hasn't been performed yet
157 */
159
160 /** A regex containing xlat expansions. Cannot be pre-compiled
161 */
163
164 /** @name unresolved types
165 *
166 * These are tmpls which could not immediately be transformed into
167 * their "resolved" form due to missing references or because
168 * additional parsing is required.
169 *
170 * @{
171 */
172
173 /** Unparsed literal string
174 *
175 * May be an intermediary phase where the tmpl is created as a
176 * temporary structure during parsing. The value here MUST be raw
177 * data, and cannot be anything else.
178 */
180
181 /** An attribute reference that we couldn't resolve but looked valid
182 *
183 * May be resolvable later once more attributes are defined.
184 */
186
187 /** An exec with unresolved xlat function or attribute references
188 */
190
191 /** A xlat expansion with unresolved xlat functions or attribute references
192 */
194
195 /** A regular expression with unresolved xlat functions or attribute references
196 */
198
199 TMPL_TYPE_MAX //!< Marker for the last tmpl type.
201
202/** Helpers to verify the type of #tmpl_t
203 */
204#define tmpl_is_uninitialised(vpt) ((vpt)->type == TMPL_TYPE_UNINITIALISED)
205
206#define tmpl_is_data(vpt) ((vpt)->type == TMPL_TYPE_DATA)
207
208#define tmpl_is_attr(vpt) ((vpt)->type == TMPL_TYPE_ATTR)
209
210#define tmpl_is_xlat(vpt) ((vpt)->type == TMPL_TYPE_XLAT)
211#define tmpl_is_exec(vpt) ((vpt)->type == TMPL_TYPE_EXEC)
212
213#define tmpl_is_regex(vpt) ((vpt)->type == TMPL_TYPE_REGEX)
214#define tmpl_is_regex_uncompiled(vpt) ((vpt)->type == TMPL_TYPE_REGEX_UNCOMPILED)
215#define tmpl_is_regex_xlat(vpt) ((vpt)->type == TMPL_TYPE_REGEX_XLAT)
216
217#define tmpl_is_data_unresolved(vpt) ((vpt)->type == TMPL_TYPE_DATA_UNRESOLVED)
218#define tmpl_is_exec_unresolved(vpt) ((vpt)->type == TMPL_TYPE_EXEC_UNRESOLVED)
219#define tmpl_is_attr_unresolved(vpt) ((vpt)->type == TMPL_TYPE_ATTR_UNRESOLVED)
220#define tmpl_is_xlat_unresolved(vpt) ((vpt)->type == TMPL_TYPE_XLAT_UNRESOLVED)
221#define tmpl_is_regex_xlat_unresolved(vpt) ((vpt)->type == TMPL_TYPE_REGEX_XLAT_UNRESOLVED)
222
223#define tmpl_needs_resolving(vpt) (((vpt)->type & TMPL_FLAG_UNRESOLVED) != 0)
224#define tmpl_contains_data(vpt) (((vpt)->type & TMPL_TYPE_DATA) != 0)
225#define tmpl_contains_attr(vpt) (((vpt)->type & TMPL_FLAG_ATTR) != 0)
226#define tmpl_contains_regex(vpt) (((vpt)->type & TMPL_FLAG_REGEX) != 0)
227#define tmpl_contains_xlat(vpt) (((vpt)->type & TMPL_FLAG_XLAT) != 0)
228
229
231extern size_t tmpl_type_table_len;
232
236typedef struct tmpl_literal_rules_s tmpl_literal_rules_t;
238typedef struct tmpl_s tmpl_t;
239
240#include <freeradius-devel/unlang/xlat.h>
241#include <freeradius-devel/unlang/xlat_ctx.h>
242#include <freeradius-devel/util/packet.h>
243#include <freeradius-devel/util/proto.h>
244#include <freeradius-devel/util/regex.h>
245
246/*
247 * Allow public and private versions of the same structures
248 */
249#ifdef _CONST
250# error _CONST can only be defined in the local header
251#endif
252#ifndef _TMPL_PRIVATE
253# define _CONST const
254#else
255# define _CONST
256#endif
257
258/** Specify whether attribute references can have a list (or parent) reference
259 *
260 */
261typedef enum {
262 TMPL_ATTR_LIST_ALLOW = 0, //!< Attribute refs are allowed to have a list
263 TMPL_ATTR_LIST_FORBID, //!< Attribute refs are forbidden from having a list
264 TMPL_ATTR_LIST_REQUIRE //!< Attribute refs are required to have a list.
266
267/** Define entry and head types for tmpl request references
268 *
269 */
270FR_DLIST_TYPES(tmpl_request_list)
271
273 fr_dict_t const *dict_def; //!< Default dictionary to use
274 ///< with unqualified attribute references.
275
276 fr_dict_attr_t const *namespace; //!< Point in dictionary tree to resume parsing
277 ///< from. If this is provided then dict_def
278 ///< request_def and list_def will be ignored
279 ///< and the presence of any of those qualifiers
280 ///< will be treated as an error.
281
282 FR_DLIST_HEAD(tmpl_request_list) _CONST *request_def; //!< Default request to use with
283 ///< unqualified attribute references.
284 ///< If NULL the request is assumed to
285 ///< but the current request.
286 ///< Usually this will be one of
287 ///< - tmpl_request_def_current
288 ///< - tmpl_request_def_outer
289 ///< - tmpl_request_def_parent
290 ///< If a custom list needs to be
291 ///< used it should be allocated on
292 ///< the stack and a pointer to it
293 ///< placed here.
294
295 fr_dict_attr_t const *list_def; //!< Default list to use with unqualified
296 ///< attribute reference.
297
298 tmpl_attr_list_presence_t list_presence; //!< Whether the attribute reference can
299 ///< have a list, forbid it, or require it.
300
301 CONF_ITEM *ci; //!< for migration support and various warnings
302
303 uint8_t allow_unknown:1; //!< Allow unknown attributes i.e. attributes
304 ///< defined by OID string.
305
306 uint8_t allow_unresolved:1; //!< Allow attributes that look valid but were
307 ///< not found in the dictionaries.
308 ///< This should be used as part of a multi-pass
309 ///< approach to parsing.
310
311 uint8_t allow_wildcard:1; //!< Allow the special case of .[*] representing
312 ///< all children of a structural attribute.
313
314 uint8_t allow_foreign:1; //!< Allow arguments not found in dict_def.
315
316 uint8_t disallow_filters:1; //!< disallow filters.
317
318 uint8_t xlat:1 ; //!< for %{User-Name}
319
320 uint8_t bare_word_enum:1; //!< for v3 compatibility.
321
322 uint8_t disallow_rhs_resolve:1; //!< map RHS is NOT immediately resolved in the context of the LHS.
323};
324
326 fr_event_list_t *runtime_el; //!< The eventlist to use for runtime instantiation
327 ///< of xlats.
328 bool new_functions; //!< new function syntax
329};
330
331/** Optional arguments passed to vp_tmpl functions
332 *
333 */
335 tmpl_rules_t const *parent; //!< for parent / child relationships
336
337 tmpl_attr_rules_t attr; //!< Rules/data for parsing attribute references.
338 tmpl_xlat_rules_t xlat; //!< Rules/data for parsing xlats.
339
340 fr_dict_attr_t const *enumv; //!< Enumeration attribute used to resolve enum values.
341
342 fr_type_t cast; //!< Whether there was an explicit cast.
343 ///< Used to determine if barewords or other values
344 ///< should be converted to an internal data type.
345
346 bool at_runtime; //!< Produce an ephemeral/runtime tmpl.
347 ///< Instantiated xlats are not added to the global
348 ///< trees, regexes are not JIT'd.
349 fr_value_box_safe_for_t literals_safe_for; //!< safe_for value assigned to literal values in
350 ///< xlats, execs, and data.
351 tmpl_escape_t escape; //!< How escaping should be handled during evaluation.
352};
353
354/** Similar to tmpl_rules_t, but used to specify parameters that may change during subsequent resolution passes
355 *
356 * When a tmpl is parsed initially the rules are stored in the #tmpl_t.
357 *
358 * During subsequent resolution phases where unresolved attributes are resolved to dictionary
359 * attributes the initial #tmpl_rules_t is used to control resolution.
360 *
361 * In some instances however (primarily policies), some rules may need change between initial
362 * parsing and subsequent resolution phases.
363 *
364 * This structure holds rules which may override the tmpl_rules_s during subsequent resolution passes.
365 */
367 fr_dict_t const *dict_def; //!< Alternative default dictionary to use if
368 ///< vpt->rules->dict_def is NULL.
369 //!< Will be written to vpt->rules->dict_def
370 ///< if used.
371
372 bool force_dict_def; //!< Use supplied dict_def even if original
373 ///< vpt->rules->dict_def was not NULL.
374
375 fr_dict_attr_t const *enumv; //!< for resolving T_BARE_WORD
376};
377
378typedef enum {
379 TMPL_ATTR_TYPE_NORMAL = 0, //!< Normal, resolved, attribute ref.
380 TMPL_ATTR_TYPE_UNSPEC, //!< No attribute was specified as this level
381 ///< only a filter.
382 TMPL_ATTR_TYPE_UNKNOWN, //!< We have an attribute number but
383 ///< it doesn't match anything in the
384 ///< dictionary, or isn't a child of
385 ///< the previous ref. May be resolved
386 ///< later.
387 TMPL_ATTR_TYPE_UNRESOLVED //!< We have a name, but nothing else
388 ///< to identify the attribute.
389 ///< may be resolved later.
391
392#define NUM_UNSPEC INT16_MIN
393#define NUM_ALL (INT16_MIN + 1)
394#define NUM_COUNT (INT16_MIN + 2)
395#define NUM_LAST (INT16_MIN + 3)
396
397/** Define entry and head types for attribute reference lists
398 *
399 */
400FR_DLIST_TYPES(tmpl_attr_list)
401
402/** Different types of filter that can be applied to an attribute reference
403 *
404 */
405typedef enum {
406 TMPL_ATTR_FILTER_TYPE_NONE = 0, //!< No filter present.
407 TMPL_ATTR_FILTER_TYPE_INDEX, //!< Filter is an index type.
408 TMPL_ATTR_FILTER_TYPE_CONDITION, //!< Filter is a condition
409 TMPL_ATTR_FILTER_TYPE_TMPL, //!< Filter is a tmpl
410 TMPL_ATTR_FILTER_TYPE_EXPR, //!< Filter is an expression
412
413typedef struct {
414 tmpl_attr_filter_type_t _CONST type; //!< Type of filter this is.
415 int16_t _CONST num; //!< For array references.
416
417 /*
418 * These are "union" because they are disjoint. The "num" field is arguably disjoint, too, but
419 * there is currently a lot of code in tmpl_tokenize.c which directly references ar->ar_num
420 * without checking the type.
421 */
422 union {
423 xlat_exp_head_t _CONST *cond; //!< xlat condition
424 tmpl_t _CONST *tmpl; //!< tmpl
425 xlat_exp_head_t _CONST *expr; //!< xlat expression
426 };
428
429/** An element in a list of nested attribute references
430 *
431 */
432typedef struct {
433 FR_DLIST_ENTRY(tmpl_attr_list) _CONST entry; //!< Entry in the doubly linked list
434 ///< of attribute references.
435
436 fr_dict_attr_t const * _CONST da; //!< Resolved dictionary attribute.
437
438 union {
439 struct {
440 fr_dict_attr_t * _CONST da; //!< Unknown dictionary attribute.
441 } unknown;
442
443 struct {
444 char * _CONST name; //!< Undefined reference type.
445 fr_dict_attr_t const * _CONST namespace; //!< Namespace we should be trying
446 ///< to resolve this attribute in.
447 } unresolved;
448 };
449
450 fr_dict_attr_t const * _CONST parent; //!< The parent we used when trying to
451 ///< resolve the attribute originally.
452 ///< Should point to the referenced
453 ///< attribute.
454
455 unsigned int _CONST resolve_only : 1; //!< This reference and those before it
456 ///< in the list can only be used for
457 ///< resolution, not building out trees.
458 unsigned int _CONST is_raw : 1; /// is a raw reference
459
460 tmpl_attr_type_t _CONST type; //!< Type of attribute reference.
461
462 tmpl_attr_filter_t _CONST filter; //!< Filter associated with the attribute reference.
464
465/** Define manipulation functions for the attribute reference list
466 *
467 */
468FR_DLIST_FUNCS(tmpl_attr_list, tmpl_attr_t, entry)
469
470/** An element in a list of request references
471 *
472 */
473typedef struct {
474 FR_DLIST_ENTRY(tmpl_request_list) _CONST entry; //!< Entry in the doubly linked list
475 ///< of request references.
476
479
480/** Define manipulation functions for the attribute reference list
481 *
482 */
483FR_DLIST_FUNCS(tmpl_request_list, tmpl_request_t, entry)
484
485/** How many additional headers to allocate in a pool for a tmpl_t
486 *
487 */
488#define TMPL_POOL_DEF_HEADERS 4
489
490/** How many additional bytes to allocate in a pool for a tmpl_t
491 *
492 */
493#define TMPL_POOL_DEF_LEN (sizeof(tmpl_t) + 64 + sizeof(tmpl_attr_t) + sizeof(tmpl_request_t))
494
495/** @name Field accessors for attribute references
496 *
497 * @{
498 */
499#define ar_type type
500#define ar_depth depth
501#define ar_da da
502#define ar_parent parent
503#define ar_unknown unknown.da
504#define ar_unresolved unresolved.name
505#define ar_unresolved_namespace unresolved.namespace
506
507#define ar_is_normal(_ar) ((_ar)->ar_type == TMPL_ATTR_TYPE_NORMAL)
508#define ar_is_unspecified(_ar) ((_ar)->ar_type == TMPL_ATTR_TYPE_UNSPEC)
509#define ar_is_unknown(_ar) ((_ar)->ar_type == TMPL_ATTR_TYPE_UNKNOWN)
510#define ar_is_unresolved(_ar) ((_ar)->ar_type == TMPL_ATTR_TYPE_UNRESOLVED)
511#define ar_is_raw(_ar) ((_ar)->is_raw)
512
513#define ar_num filter.num
514#define ar_cond filter.cond
515#define ar_tmpl filter.tmpl
516#define ar_expr filter.expr
517#define ar_filter_type filter.type
518
519#define ar_filter_is_none(_ar) ((_ar)->ar_filter_type == TMPL_ATTR_FILTER_TYPE_NONE)
520#define ar_filter_is_num(_ar) ((_ar)->ar_filter_type == TMPL_ATTR_FILTER_TYPE_INDEX)
521#define ar_filter_is_cond(_ar) ((_ar)->ar_filter_type == TMPL_ATTR_FILTER_TYPE_CONDITION)
522#define ar_filter_is_tmpl(_ar) ((_ar)->ar_filter_type == TMPL_ATTR_FILTER_TYPE_TMPL)
523#define ar_filter_is_expr(_ar) ((_ar)->ar_filter_type == TMPL_ATTR_FILTER_TYPE_EXPR)
524/** @} */
525
526/** A source or sink of value data.
527 *
528 * Is used as both the RHS and LHS of a map (both update, and conditional types)
529 *
530 * @section update_maps Use in update map_t
531 * When used on the LHS it describes an attribute to create and should be one of these types:
532 * - #TMPL_TYPE_ATTR
533 *
534 * When used on the RHS it describes the value to assign to the attribute being created and
535 * should be one of these types:
536 * - #TMPL_TYPE_DATA_UNRESOLVED
537 * - #TMPL_TYPE_XLAT_UNRESOLVED
538 * - #TMPL_TYPE_ATTR
539 * - #TMPL_TYPE_EXEC
540 * - #TMPL_TYPE_DATA
541 * - #TMPL_TYPE_XLAT (pre-parsed xlat)
542 *
543 * @section conditional_maps Use in conditional map_t
544 * When used as part of a condition it may be any of the RHS side types, as well as:
545 * - #TMPL_TYPE_REGEX (pre-parsed regex)
546 *
547 * @see map_t
548 */
549struct tmpl_s {
550 tmpl_type_t _CONST type; //!< What type of value tmpl refers to.
551
552 char const * _CONST name; //!< Raw string used to create the template.
553 ///< this string will have any escape sequences left intact.
554 size_t _CONST len; //!< Length of the raw string used to create the template.
555 fr_token_t _CONST quote; //!< What type of quoting was around the raw string.
556
557 union {
558 char *unescaped; //!< Unescaped form of the name, used for TMPL_TYPE_DATA_UNRESOLVED
559 ///< and TMPL_TYPE_REGEX_UNCOMPILED.
560
561 _CONST struct {
562 FR_DLIST_HEAD(tmpl_request_list) rr; //!< Request to search or insert in.
563 FR_DLIST_HEAD(tmpl_attr_list) ar; //!< Head of the attribute reference list.
564 } attribute;
565
566 /*
567 * Attribute value. Typically used as the RHS of an update map.
568 */
569 fr_value_box_t literal; //!< Value data.
570
571 struct {
572 union {
573 _CONST struct {
574 xlat_exp_head_t *ex; //!< pre-parsed xlat expansion
575 ///< and expansion.
576 } xlat;
577#ifdef HAVE_REGEX
578 _CONST struct {
579 char *src; //!< Original unescaped source string.
580 regex_t *ex; //!< pre-parsed regex_t
581 bool subcaptures; //!< Whether the regex was compiled with
582 ///< subcaptures.
583 } reg;
584#endif
585 };
586 fr_regex_flags_t reg_flags; //!< Flags for regular expressions.
587 ///< Used by:
588 ///< - TMPL_TYPE_REGEX_XLAT
589 ///< - TMPL_TYPE_REGEX_UNCOMPILED
590 ///< - TMPL_TYPE_REGEX
591 ///< - TMPL_TYPE_REGEX_XLAT_UNRESOLVED
592 };
594
595 tmpl_rules_t _CONST rules; //!< The rules that were used when creating the tmpl.
596 ///< These are useful for multiple resolution passes as
597 ///< they ensure the correct parsing rules are applied.
598};
599
600/** Describes the current extents of a pair tree in relation to the tree described by a tmpl_t
601 *
602 */
603typedef struct {
604 fr_dlist_t entry; //!< Entry in the dlist of extents
605
606 tmpl_attr_t const *ar; //!< Attribute representing the ar
607 ///< after the deepest node that was found
608 ///< in the existing pair tree when evaluating
609 ///< this path. If this is NULL, then all ars
610 ///< were evaluated.
611
612 TALLOC_CTX *list_ctx; //!< Where to allocate new attributes if building
613 ///< out from the current extents of the tree.
614 fr_pair_list_t *list; //!< List that we tried to evaluate ar in and failed.
615 ///< Or if ar is NULL, the list that represents the
616 ///< deepest grouping or TLV attribute the chain of
617 ///< ars referenced.
619
620/** Convenience macro for printing a meaningful assert message when we get a bad tmpl type
621 */
622#define tmpl_assert_type(_cond) \
623 fr_assert_msg(_cond, "Unexpected tmpl type '%s'", \
624 tmpl_type_to_str(vpt->type))
625
626
627/** @name Functions for printing and parsing tmpl type names
628 *
629 * @{
630 */
631/** Return a static string containing the type name
632 *
633 * @param[in] type to return name for.
634 * @return name of the type
635 */
636static inline char const *tmpl_type_to_str(tmpl_type_t type)
637{
638 return fr_table_str_by_value(tmpl_type_table, type, "<INVALID>");
639}
640
641/** Return the constant value representing a type
642 *
643 * @param[in] type to return the constant value for.
644 * @return The constant type value or TMPL_TYPE_UNINITIALISED if no type matches.
645 */
650/** @} */
651
652/** @name Field accessors for #TMPL_TYPE_ATTR, #TMPL_TYPE_ATTR_UNRESOLVED
653 *
654 * @{
655 */
656 #define tmpl_attr(_tmpl) &(_tmpl)->data.attribute.ar
657
658static inline FR_DLIST_HEAD(tmpl_request_list) const *tmpl_request(tmpl_t const *vpt)
659{
662
663 return &vpt->data.attribute.rr;
664}
665
666/** The number of request references contained within a tmpl
667 *
668 */
669static inline size_t tmpl_request_ref_count(tmpl_t const *vpt)
670{
673
674 return tmpl_request_list_num_elements(&vpt->data.attribute.rr);
675}
676
677/** Return true if the tmpl_attr is one of the list types
678 *
679 * @hidecallergraph
680*/
681static inline bool tmpl_attr_is_list_attr(tmpl_attr_t const *ar)
682{
683 if (!ar || !ar_is_normal(ar)) return false;
684
685 return (ar->ar_da == request_attr_request) ||
686 (ar->ar_da == request_attr_reply) ||
687 (ar->ar_da == request_attr_control) ||
688 (ar->ar_da == request_attr_state) ||
689 (ar->ar_da == request_attr_local);
690}
691
692/** Return true if the head attribute reference is a list reference
693 *
694 * @hidecallergraph
695 */
696static inline bool tmpl_attr_head_is_list(tmpl_t const *vpt)
697{
698 tmpl_attr_t *ar;
699
701
702 ar = tmpl_attr_list_head(tmpl_attr(vpt));
703 if (unlikely(!ar)) return false;
704
705 return tmpl_attr_is_list_attr(ar);
706}
707
708/** Return true if the last attribute reference is "normal"
709 *
710 * @hidecallergraph
711 */
712static inline bool tmpl_attr_tail_is_normal(tmpl_t const *vpt)
713{
714 tmpl_attr_t *ar;
715
717
718 ar = tmpl_attr_list_tail(tmpl_attr(vpt));
719 if (unlikely(!ar)) return false;
720
721 return ar_is_normal(ar);
722}
723
724/** Return true if the last attribute reference is "unspecified"
725 *
726 * @hidecallergraph
727 */
728static inline bool tmpl_attr_tail_is_unspecified(tmpl_t const *vpt)
729{
730 tmpl_attr_t *ar;
731
733
734 ar = tmpl_attr_list_tail(tmpl_attr(vpt));
735 if (unlikely(!ar)) return false;
736
737 return ar_is_unspecified(ar);
738}
739
740/** Return true if the last attribute reference is "unknown"
741 *
742 * @hidecallergraph
743 */
744static inline bool tmpl_attr_tail_is_unknown(tmpl_t const *vpt)
745{
746 tmpl_attr_t *ar;
747
749
750 ar = tmpl_attr_list_tail(tmpl_attr(vpt));
751 if (unlikely(!ar)) return false;
752
753 return ar_is_unknown(ar);
754}
755
756/** Return true if the last attribute reference is "unresolved"
757 *
758 * @hidecallergraph
759 */
760static inline bool tmpl_attr_tail_is_unresolved(tmpl_t const *vpt)
761{
762 tmpl_attr_t *ar;
763
765
766 ar = tmpl_attr_list_tail(tmpl_attr(vpt));
767 if (unlikely(!ar)) return false;
768
769 return ar_is_unresolved(ar);
770}
771
772/** Return true if the last attribute reference is "raw"
773 *
774 * @hidecallergraph
775 */
776static inline bool tmpl_attr_tail_is_raw(tmpl_t const *vpt)
777{
778 tmpl_attr_t *ar;
779
781
782 ar = tmpl_attr_list_tail(tmpl_attr(vpt));
783 if (unlikely(!ar)) return false;
784
785 return ar_is_raw(ar);
786}
787
788/** Return the last attribute reference
789 *
790 * @hidecallergraph
791 */
792static inline tmpl_attr_t const *tmpl_attr_tail(tmpl_t const *vpt)
793{
795
796 return tmpl_attr_list_tail(tmpl_attr(vpt));
797}
798
799/** Return the last attribute reference da
800 *
801 * @hidecallergraph
802 */
803static inline fr_dict_attr_t const *tmpl_attr_tail_da(tmpl_t const *vpt)
804{
805 tmpl_attr_t *ar;
806
808
809 ar = tmpl_attr_list_tail(tmpl_attr(vpt));
810 if (!ar) return NULL;
811
812 return ar->ar_da;
813}
814
815/** Return true if the the last attribute reference is a leaf attribute
816 *
817 * @hidecallergraph
818 */
819static inline bool tmpl_attr_tail_da_is_leaf(tmpl_t const *vpt)
820{
821 tmpl_attr_t *ar;
822
824
825 ar = tmpl_attr_list_tail(tmpl_attr(vpt));
826 if (!ar) return false;
827
829
830 return fr_type_is_leaf(ar->ar_da->type);
831}
832
833/** Return true if the the last attribute reference is a structural attribute
834 *
835 * @hidecallergraph
836 */
838{
839 tmpl_attr_t *ar;
840
842
843 ar = tmpl_attr_list_tail(tmpl_attr(vpt));
844 if (!ar) return false;
845
847
848 return fr_type_is_structural(ar->ar_da->type);
849}
850
851/** Return the last attribute reference unknown da
852 *
853 * @hidecallergraph
854 */
856{
857 tmpl_attr_t *ar;
858
860
861 ar = tmpl_attr_list_tail(tmpl_attr(vpt));
862 if (!ar) return NULL;
863
864 return ar->ar_unknown;
865}
866
867/** Return the last attribute reference unresolved da
868 *
869 * @hidecallergraph
870 */
871static inline char const *tmpl_attr_tail_unresolved(tmpl_t const *vpt)
872{
873 tmpl_attr_t *ar;
874
876
877 ar = tmpl_attr_list_tail(tmpl_attr(vpt));
878 if (!ar) return NULL;
879
880 return ar->ar_unresolved;
881}
882
883/** Return the last attribute reference's attribute number
884 *
885 * @hidecallergraph
886 */
887static inline int16_t tmpl_attr_tail_num(tmpl_t const *vpt)
888{
891
892 return tmpl_attr_list_tail(tmpl_attr(vpt))->ar_num;
893}
894
895/** The number of attribute references contained within a tmpl
896 *
897 */
898static inline size_t tmpl_attr_num_elements(tmpl_t const *vpt)
899{
902
903 return tmpl_attr_list_num_elements(tmpl_attr(vpt));
904}
905
906static inline fr_dict_attr_t const *tmpl_list(tmpl_t const *vpt)
907{
908 if (!tmpl_attr_head_is_list(vpt)) return NULL;
909
910 return tmpl_attr_list_head(tmpl_attr(vpt))->ar_da;
911}
912/** @} */
913
914/** Return the name of a tmpl list or def if list not provided
915 *
916*/
917static inline char const *tmpl_list_name(fr_dict_attr_t const *list, char const *def)
918{
919 return (list ? list->name : def);
920}
921
922static inline bool tmpl_is_list(tmpl_t const *vpt)
923{
924 if (!tmpl_is_attr(vpt)) return false;
926}
927
928/** @name Field accessors for #TMPL_TYPE_XLAT
929 *
930 * @{
931 */
932#define tmpl_xlat(_tmpl) (_tmpl)->data.xlat.ex
933/** @} */
934
935/** @name Field accessors for #TMPL_TYPE_DATA
936 *
937 * @{
938 */
939#define tmpl_value(_tmpl) (&(_tmpl)->data.literal)
940#define tmpl_value_length(_tmpl) (_tmpl)->data.literal.vb_length
941#define tmpl_value_type(_tmpl) (_tmpl)->data.literal.type
942#define tmpl_value_enumv(_tmpl) (_tmpl)->data.literal.enumv
943
944#define tmpl_rules_cast(_tmpl) (_tmpl)->rules.cast
945#define tmpl_rules_enumv(_tmpl) (_tmpl)->rules.enumv
946
947fr_type_t tmpl_data_type(tmpl_t const *vpt) CC_HINT(nonnull);
948
949/** @} */
950
951/** @name Field accessors for #TMPL_TYPE_REGEX and #TMPL_TYPE_REGEX_XLAT_UNRESOLVED
952 *
953 * @{
954 */
955#ifdef HAVE_REGEX
956# define tmpl_regex(_tmpl) (_tmpl)->data.reg.ex //!< #TMPL_TYPE_REGEX only.
957# define tmpl_regex_flags(_tmpl) (&(_tmpl)->data.reg_flags)
958#endif
959/** @} */
960
961#ifndef WITH_VERIFY_PTR
962# define TMPL_ATTR_VERIFY(_vpt)
963# define TMPL_VERIFY(_vpt)
964#else
965# define TMPL_ATTR_VERIFY(_vpt) tmpl_attr_verify(__FILE__, __LINE__, _vpt)
966# define TMPL_VERIFY(_vpt) tmpl_verify(__FILE__, __LINE__, _vpt)
967void tmpl_attr_verify(char const *file, int line, tmpl_t const *vpt);
968void tmpl_verify(char const *file, int line, tmpl_t const *vpt);
969#endif
970
971/** Determine the correct context and list head
972 *
973 * Used in conjunction with the fr_dcursor functions to determine the correct list
974 * and TALLOC_CTX for inserting fr_pair_ts.
975 *
976 * Example:
977 @code{.c}
978 TALLOC_CTX *ctx;
979 fr_pair_list_t *head;
980 fr_value_box_t value;
981
982 tmpl_pair_list_and_ctx(ctx, head, request, CURRENT_REQUEST, request_attr_request);
983 if (!list) return -1; // error
984
985 value.strvalue = talloc_typed_strdup(NULL, "my new username");
986 value.length = talloc_array_length(value.strvalue) - 1;
987 @endcode
988 *
989 * @param _ctx new #fr_pair_t s should be allocated in for the specified list.
990 * @param _head of the #fr_pair_t list.
991 * @param _request The current request.
992 * @param _ref to resolve.
993 * @param _list to resolve.
994 */
995#define tmpl_pair_list_and_ctx(_ctx, _head, _request, _ref, _list) \
996do {\
997 request_t *_rctx = _request; \
998 if ((tmpl_request_ptr(&_rctx, _ref) < 0) || \
999 !(_head = tmpl_list_head(_rctx, _list)) || \
1000 !(_ctx = tmpl_list_ctx(_rctx, _list))) {\
1001 _ctx = NULL; \
1002 _head = NULL; \
1003 }\
1004} while (0)
1005
1006typedef enum {
1007 TMPL_ATTR_ERROR_NONE = 0, //!< No error.
1008 TMPL_ATTR_ERROR_EMPTY, //!< Attribute ref contains no data.
1009 TMPL_ATTR_ERROR_BAD_PREFIX, //!< Missing '&' or has '&' when it shouldn't.
1010 TMPL_ATTR_ERROR_LIST_NOT_ALLOWED, //!< List qualifier is not allowed here.
1011 TMPL_ATTR_ERROR_LIST_MISSING, //!< List qualifier is required, but missing.
1012 TMPL_ATTR_ERROR_UNKNOWN_NOT_ALLOWED, //!< Attribute specified as OID, could not be
1013 ///< found in the dictionaries, and is disallowed
1014 ///< because 'disallow_internal' in tmpl_rules_t
1015 ///< is trie.
1016 TMPL_ATTR_ERROR_UNRESOLVED_NOT_ALLOWED, //!< Attribute couldn't be found in the dictionaries.
1017 TMPL_ATTR_ERROR_UNQUALIFIED_NOT_ALLOWED, //!< Attribute must be qualified to be used here.
1018 TMPL_ATTR_ERROR_INVALID_NAME, //!< Attribute ref length is zero, or longer than
1019 ///< the maximum.
1020 TMPL_ATTR_ERROR_INTERNAL_NOT_ALLOWED, //!< Attribute resolved to an internal attribute
1021 ///< which is disallowed.
1022 TMPL_ATTR_ERROR_FOREIGN_NOT_ALLOWED, //!< Attribute resolved in a dictionary different
1023 ///< to the one specified.
1024 TMPL_ATTR_ERROR_FILTER_NOT_ALLOWED, //!< Filters disallowed by rules.
1025 TMPL_ATTR_ERROR_INVALID_ARRAY_INDEX, //!< Invalid array index.
1027 TMPL_ATTR_ERROR_NESTING_TOO_DEEP, //!< Too many levels of nesting.
1028 TMPL_ATTR_ERROR_MISSING_TERMINATOR, //!< Unexpected text found after attribute reference
1029 TMPL_ATTR_ERROR_BAD_CAST //!< Specified cast was invalid.
1031
1032/** Map ptr type to a boxed type
1033 *
1034 */
1035#define FR_TYPE_FROM_PTR(_ptr) \
1036 _Generic((_ptr), \
1037 char **: FR_TYPE_STRING, \
1038 char const **: FR_TYPE_STRING, \
1039 uint8_t **: FR_TYPE_OCTETS, \
1040 uint8_t const **: FR_TYPE_OCTETS, \
1041 uint8_t *: FR_TYPE_UINT8, \
1042 uint16_t *: FR_TYPE_UINT16, \
1043 uint32_t *: FR_TYPE_UINT32, \
1044 uint64_t *: FR_TYPE_UINT64, \
1045 fr_value_box_t **: FR_TYPE_VALUE_BOX, \
1046 fr_value_box_t const **: FR_TYPE_VALUE_BOX)
1047
1048/** Expand a tmpl to a C type, using existing storage to hold variably sized types
1049 *
1050 * Expands a template using the _out ptr to determinate the cast type.
1051 *
1052 * @see _tmpl_to_type
1053 */
1054#define tmpl_expand(_out, _buff, _buff_len, _request, _vpt) \
1055 _tmpl_to_type((void *)(_out), (uint8_t *)_buff, _buff_len, \
1056 _request, _vpt, FR_TYPE_FROM_PTR(_out))
1057
1058/** Expand a tmpl to a C type, allocing a new buffer to hold the string
1059 *
1060 * Expands a template using the _out ptr to determinate the cast type.
1061 *
1062 * @see _tmpl_to_atype
1063 */
1064#define tmpl_aexpand(_ctx, _out, _request, _vpt, _escape, _escape_ctx) \
1065 _tmpl_to_atype(_ctx, (void *)(_out), _request, _vpt, _escape, _escape_ctx, FR_TYPE_FROM_PTR(_out))
1066
1067/** Expand a tmpl to a C type, allocing a new buffer to hold the string
1068 *
1069 * Takes an explicit type which must match the ctype pointed to by out.
1070 *
1071 * @see _tmpl_to_atype
1072 */
1073#define tmpl_aexpand_type(_ctx, _out, _type, _request, _vpt) \
1074 _tmpl_to_atype(_ctx, (void *)(_out), _request, _vpt, NULL, NULL, _type)
1075
1076void tmpl_debug(FILE *fp, tmpl_t const *vpt) CC_HINT(nonnull);
1077
1079
1080fr_packet_t *tmpl_packet_ptr(request_t *request, fr_dict_attr_t const *list) CC_HINT(nonnull);
1081
1082TALLOC_CTX *tmpl_list_ctx(request_t *request, fr_dict_attr_t const *list);
1083
1085
1086tmpl_t *tmpl_init_printf(tmpl_t *vpt, tmpl_type_t type, fr_token_t quote, char const *fmt, ...) CC_HINT(nonnull(1,4));
1087
1089 char const *name, ssize_t len,
1090 tmpl_rules_t const *t_rules) CC_HINT(nonnull(1,4));
1091
1093 char const *name, ssize_t len,
1094 tmpl_rules_t const *t_rules) CC_HINT(nonnull(1,4));
1095
1096tmpl_t *tmpl_alloc(TALLOC_CTX *ctx, tmpl_type_t type, fr_token_t quote, char const *name, ssize_t len);
1097
1098/** @name Parse request qualifiers
1099 *
1100 * @{
1101 */
1102/** Static default request ref list for the current request
1103 *
1104 * Passed as request_def in tmpl_attr_rules_t.
1105 */
1106extern FR_DLIST_HEAD(tmpl_request_list) tmpl_request_def_current;
1107
1108/** Static default request ref list for the outer request
1109 *
1110 * Passed as request_def in tmpl_attr_rules_t.
1111 */
1112extern FR_DLIST_HEAD(tmpl_request_list) tmpl_request_def_outer;
1113
1114/** Static default request ref list for the parent request
1115 *
1116 * Passed as request_def in tmpl_attr_rules_t.
1117 */
1118extern FR_DLIST_HEAD(tmpl_request_list) tmpl_request_def_parent;
1119
1120int tmpl_request_ptr(request_t **request, FR_DLIST_HEAD(tmpl_request_list) const *rql) CC_HINT(nonnull);
1121
1122void tmpl_request_ref_list_debug(FR_DLIST_HEAD(tmpl_request_list) const *rql);
1123
1124int8_t tmpl_request_ref_list_cmp(FR_DLIST_HEAD(tmpl_request_list) const *a,
1125 FR_DLIST_HEAD(tmpl_request_list) const *b);
1126
1127/** Returns true if the specified qualifier list points to the current request
1128 *
1129 * @param[in] _list to check.
1130 * @return
1131 * - true if the list only contains a current request qualifier.
1132 * - false otherwise.
1133 */
1134#define tmpl_request_ref_is_current(_list) (tmpl_request_ref_list_cmp(_list, &tmpl_request_def_current) == 0)
1135
1136/** Returns true if the specified qualifier list points to the parent request
1137 *
1138 * @param[in] _list to check.
1139 * @return
1140 * - true if the list only contains a parent request qualifier.
1141 * - false otherwise.
1142 */
1143#define tmpl_request_ref_is_parent(_list) (tmpl_request_ref_list_cmp(_list, &tmpl_request_def_parent) == 0)
1144
1145/** Returns true if the specified qualifier list points to the outer request
1146 *
1147 * @param[in] _list to check.
1148 * @return
1149 * - true if the list only contains a outer request qualifier.
1150 * - false otherwise.
1151 */
1152#define tmpl_request_ref_is_outer(_list) (tmpl_request_ref_list_cmp(_list, &tmpl_request_def_outer) == 0)
1153
1154
1156 FR_DLIST_HEAD(tmpl_request_list) _CONST **out,
1157 fr_sbuff_t *in);
1158/** @} */
1159
1160void tmpl_set_name_printf(tmpl_t *vpt, fr_token_t quote, char const *fmt, ...) CC_HINT(nonnull(1,3));
1161
1162void tmpl_set_name_shallow(tmpl_t *vpt, fr_token_t quote, char const *name, ssize_t len) CC_HINT(nonnull);
1163
1164void tmpl_set_name(tmpl_t *vpt, fr_token_t quote, char const *name, ssize_t len) CC_HINT(nonnull);
1165
1166void tmpl_set_dict_def(tmpl_t *vpt, fr_dict_t const *dict) CC_HINT(nonnull);
1167
1168void tmpl_set_escape(tmpl_t *vpt, tmpl_escape_t const *escape) CC_HINT(nonnull);
1169
1170void tmpl_set_xlat(tmpl_t *vpt, xlat_exp_head_t *xlat) CC_HINT(nonnull);
1171
1172int tmpl_afrom_value_box(TALLOC_CTX *ctx, tmpl_t **out, fr_value_box_t *data, bool steal) CC_HINT(nonnull);
1173
1174void tmpl_attr_ref_debug(FILE *fp, const tmpl_attr_t *ar, int idx) CC_HINT(nonnull);
1175
1176void tmpl_attr_ref_list_debug(FILE *fp, FR_DLIST_HEAD(tmpl_attr_list) const *ar_head) CC_HINT(nonnull);
1177
1178void tmpl_attr_debug(FILE *fp, tmpl_t const *vpt) CC_HINT(nonnull);
1179
1180int tmpl_attr_copy(tmpl_t *dst, tmpl_t const *src) CC_HINT(nonnull);
1181
1182int tmpl_attr_set_da(tmpl_t *vpt, fr_dict_attr_t const *da) CC_HINT(nonnull);
1183
1184int tmpl_attr_set_leaf_da(tmpl_t *vpt, fr_dict_attr_t const *da) CC_HINT(nonnull);
1185
1186void tmpl_attr_rewrite_leaf_num(tmpl_t *vpt, int16_t num) CC_HINT(nonnull);
1187
1188void tmpl_attr_set_request_ref(tmpl_t *vpt, FR_DLIST_HEAD(tmpl_request_list) const *request_def) CC_HINT(nonnull);
1189
1190void tmpl_attr_set_list(tmpl_t *vpt, fr_dict_attr_t const *list) CC_HINT(nonnull);
1191
1192int tmpl_attr_afrom_list(TALLOC_CTX *ctx, tmpl_t **out, tmpl_t const *list,
1193 fr_dict_attr_t const *da) CC_HINT(nonnull);
1194
1195/** @name Produce a #tmpl_t from a string or substring
1196 *
1197 * @{
1198 */
1201 fr_sbuff_parse_rules_t const *p_rules,
1202 tmpl_rules_t const *t_rules) CC_HINT(nonnull(3,4));
1203
1205 tmpl_t **out, char const *name,
1206 tmpl_rules_t const *rules) CC_HINT(nonnull (3, 4));
1207
1208ssize_t tmpl_afrom_substr(TALLOC_CTX *ctx, tmpl_t **out,
1209 fr_sbuff_t *in,
1210 fr_token_t quote,
1211 fr_sbuff_parse_rules_t const *p_rules,
1212 tmpl_rules_t const *t_rules) CC_HINT(nonnull(2,3));
1213
1214tmpl_t *tmpl_copy(TALLOC_CTX *ctx, tmpl_t const *in) CC_HINT(nonnull);
1215
1216ssize_t tmpl_cast_from_substr(tmpl_rules_t *t_rules, fr_sbuff_t *in) CC_HINT(nonnull(2)); /* Parses cast string */
1217
1218int tmpl_cast_set(tmpl_t *vpt, fr_type_t type) CC_HINT(nonnull); /* Sets cast type */
1219
1221{
1222 return vpt->rules.cast;
1223}
1224
1225#ifdef HAVE_REGEX
1226ssize_t tmpl_regex_flags_substr(tmpl_t *vpt, fr_sbuff_t *in,
1227 fr_sbuff_term_t const *terminals) CC_HINT(nonnull(1,2));
1228#endif
1229/** @} */
1230
1231/** @name Change a #tmpl_t type, usually by casting or resolving a reference
1232 * @{
1233 */
1234int tmpl_cast_in_place(tmpl_t *vpt, fr_type_t type, fr_dict_attr_t const *enumv) CC_HINT(nonnull(1));
1235
1236int tmpl_resolve(tmpl_t *vpt, tmpl_res_rules_t const *tr_rules) CC_HINT(nonnull(1));
1237
1238void tmpl_unresolve(tmpl_t *vpt) CC_HINT(nonnull);
1239
1240void tmpl_attr_to_raw(tmpl_t *vpt) CC_HINT(nonnull);
1241
1243
1245 fr_type_t type, fr_dict_attr_flags_t const *flags) CC_HINT(nonnull(1));
1246
1247#ifdef HAVE_REGEX
1248ssize_t tmpl_regex_compile(tmpl_t *vpt, bool subcaptures) CC_HINT(nonnull);
1249#endif
1250/** @} */
1251
1252/** @name Print the contents of a #tmpl_t
1253 * @{
1254 */
1255fr_slen_t tmpl_request_ref_list_print(fr_sbuff_t *out, FR_DLIST_HEAD(tmpl_request_list) const *rql)
1256 CC_HINT(nonnull(1,2));
1257
1258static inline fr_slen_t tmpl_request_ref_list_aprint(TALLOC_CTX *ctx, char **out, FR_DLIST_HEAD(tmpl_request_list) const *rql)
1260
1262
1263static inline fr_slen_t tmpl_attr_aprint(TALLOC_CTX *ctx, char **out, tmpl_t const *vpt)
1265
1267 fr_sbuff_escape_rules_t const *e_rules) CC_HINT(nonnull(1,2));
1268
1269static inline fr_slen_t tmpl_aprint(TALLOC_CTX *ctx, char **out, tmpl_t const *vpt,
1270 fr_sbuff_escape_rules_t const *e_rules)
1272
1274
1275static inline fr_slen_t tmpl_aprint_quoted(TALLOC_CTX *ctx, char **out, tmpl_t const *vpt)
1277/** @} */
1278
1279/** @name Expand the tmpl, returning one or more values
1280 * @{
1281 */
1283
1285 uint8_t *buff, size_t outlen,
1286 request_t *request,
1287 tmpl_t const *vpt,
1288 fr_type_t dst_type)
1289 CC_HINT(nonnull (1, 4, 5));
1290
1291ssize_t _tmpl_to_atype(TALLOC_CTX *ctx, void *out,
1292 request_t *request,
1293 tmpl_t const *vpt,
1294 xlat_escape_legacy_t escape, void const *escape_ctx,
1295 fr_type_t dst_type)
1296 CC_HINT(nonnull (2, 3, 4));
1297
1298int tmpl_copy_pairs(TALLOC_CTX *ctx, fr_pair_list_t *out,
1299 request_t *request, tmpl_t const *vpt) CC_HINT(nonnull(2,3,4));
1300
1301int tmpl_copy_pair_children(TALLOC_CTX *ctx, fr_pair_list_t *out,
1302 request_t *request, tmpl_t const *vpt) CC_HINT(nonnull(2,3,4));
1303
1304int tmpl_find_vp(fr_pair_t **out, request_t *request, tmpl_t const *vpt) CC_HINT(nonnull(2,3));
1305
1306int tmpl_find_or_add_vp(fr_pair_t **out, request_t *request, tmpl_t const *vpt) CC_HINT(nonnull);
1307
1308int pair_append_by_tmpl_parent(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list,
1309 tmpl_t const *vpt, bool skip_list) CC_HINT(nonnull(1,3,4));
1310
1311int tmpl_extents_find(TALLOC_CTX *ctx,
1312 fr_dlist_head_t *leaf, fr_dlist_head_t *interior,
1313 request_t *request, tmpl_t const *vpt) CC_HINT(nonnull(5));
1314
1316 tmpl_t const *vpt) CC_HINT(nonnull);
1317
1318void tmpl_extents_debug(FILE *fp, fr_dlist_head_t *head) CC_HINT(nonnull);
1319
1320int tmpl_eval_pair(TALLOC_CTX *ctx, fr_value_box_list_t *out, request_t *request, tmpl_t const *vpt);
1321
1322int tmpl_eval(TALLOC_CTX *ctx, fr_value_box_list_t *out, request_t *request, tmpl_t const *vpt);
1323
1324int tmpl_eval_cast_in_place(fr_value_box_list_t *out, request_t *request, tmpl_t const *vpt);
1325/** @} */
1326
1327ssize_t tmpl_preparse(char const **out, size_t *outlen, char const *in, size_t inlen,
1328 fr_token_t *type) CC_HINT(nonnull(1,2,3,5));
1329
1330bool tmpl_async_required(tmpl_t const *vpt) CC_HINT(nonnull);
1331
1332int tmpl_value_list_insert_tail(fr_value_box_list_t *list, fr_value_box_t *vb, tmpl_t const *vpt) CC_HINT(nonnull);
1333
1334void tmpl_rules_child_init(TALLOC_CTX *ctx, tmpl_rules_t *out, tmpl_rules_t const *parent, tmpl_t *vpt) CC_HINT(nonnull);
1335
1336void tmpl_rules_debug(tmpl_rules_t const *rules) CC_HINT(nonnull);
1337
1338int tmpl_global_init(void);
1339
1340#undef _CONST
1341
1342#ifdef __cplusplus
1343}
1344#endif
int const char * file
Definition acutest.h:704
static int const char * fmt
Definition acutest.h:575
int const char int line
Definition acutest.h:704
#define RCSIDH(h, id)
Definition build.h:486
#define unlikely(_x)
Definition build.h:383
Common header for all CONF_* types.
Definition cf_priv.h:49
static fr_slen_t err
Definition dict.h:864
static fr_slen_t in
Definition dict.h:864
Values of the encryption flags.
#define FR_DLIST_TYPES(_name)
Define type specific wrapper structs for dlists.
Definition dlist.h:1129
#define FR_DLIST_FUNCS(_name, _element_type, _element_entry)
Define type specific wrapper functions for dlists.
Definition dlist.h:1152
#define FR_DLIST_HEAD(_name)
Expands to the type name used for the head wrapper structure.
Definition dlist.h:1122
Head of a doubly linked list.
Definition dlist.h:51
Entry in a doubly linked list.
Definition dlist.h:41
Stores all information relating to an event list.
Definition event.c:377
size_t(* xlat_escape_legacy_t)(request_t *request, char *out, size_t outlen, char const *in, void *arg)
fr_type_t
long int ssize_t
unsigned char uint8_t
ssize_t fr_slen_t
#define fr_assert(_expr)
Definition rad_assert.h:38
fr_dict_attr_t const * request_attr_request
Definition request.c:43
fr_dict_attr_t const * request_attr_control
Definition request.c:45
fr_dict_attr_t const * request_attr_local
Definition request.c:47
fr_dict_attr_t const * request_attr_state
Definition request.c:46
fr_dict_attr_t const * request_attr_reply
Definition request.c:44
static char const * name
#define SBUFF_OUT_TALLOC_FUNC_NO_LEN_DEF(_func,...)
Set of terminal elements.
int8_t tmpl_request_ref_list_cmp(FR_DLIST_HEAD(tmpl_request_list) const *a, FR_DLIST_HEAD(tmpl_request_list) const *b)
Compare a list of request qualifiers.
int tmpl_find_vp(fr_pair_t **out, request_t *request, tmpl_t const *vpt))
Returns the first VP matching a tmpl_t.
Definition tmpl_eval.c:772
void tmpl_request_ref_list_debug(FR_DLIST_HEAD(tmpl_request_list) const *rql)
Dump a request list to stderr.
static tmpl_attr_t const * tmpl_attr_tail(tmpl_t const *vpt)
Return the last attribute reference.
Definition tmpl.h:792
static int16_t tmpl_attr_tail_num(tmpl_t const *vpt)
Return the last attribute reference's attribute number.
Definition tmpl.h:887
void tmpl_attr_set_list(tmpl_t *vpt, fr_dict_attr_t const *list)
#define ar_is_unspecified(_ar)
Definition tmpl.h:508
static char const * tmpl_type_to_str(tmpl_type_t type)
Return a static string containing the type name.
Definition tmpl.h:636
void tmpl_unresolve(tmpl_t *vpt)
Reset the tmpl, leaving only the name in place.
#define tmpl_is_attr_unresolved(vpt)
Definition tmpl.h:219
enum requests_ref_e tmpl_request_ref_t
void tmpl_set_name_printf(tmpl_t *vpt, fr_token_t quote, char const *fmt,...))
Set the name on a pre-initialised tmpl.
static bool tmpl_attr_tail_is_unspecified(tmpl_t const *vpt)
Return true if the last attribute reference is "unspecified".
Definition tmpl.h:728
void tmpl_set_xlat(tmpl_t *vpt, xlat_exp_head_t *xlat)
Change the default dictionary in the tmpl's resolution rules.
void tmpl_attr_ref_debug(FILE *fp, const tmpl_attr_t *ar, int idx)
void tmpl_attr_set_request_ref(tmpl_t *vpt, FR_DLIST_HEAD(tmpl_request_list) const *request_def)
Set the request for an attribute ref.
int tmpl_attr_set_da(tmpl_t *vpt, fr_dict_attr_t const *da)
Replace the current attribute reference.
fr_packet_t * tmpl_packet_ptr(request_t *request, fr_dict_attr_t const *list)
Resolve a list to the fr_packet_t holding the HEAD pointer for a fr_pair_t list.
Definition tmpl_eval.c:140
tmpl_escape_t escape
How escaping should be handled during evaluation.
Definition tmpl.h:351
static bool tmpl_attr_tail_is_normal(tmpl_t const *vpt)
Return true if the last attribute reference is "normal".
Definition tmpl.h:712
tmpl_t * tmpl_init(tmpl_t *vpt, tmpl_type_t type, fr_token_t quote, char const *name, ssize_t len, tmpl_rules_t const *t_rules))
Initialise a tmpl using a literal string to create the name.
int tmpl_resolve(tmpl_t *vpt, tmpl_res_rules_t const *tr_rules))
Attempt to resolve functions and attributes in xlats and attribute references.
static fr_slen_t tmpl_aprint_quoted(TALLOC_CTX *ctx, char **out, tmpl_t const *vpt) 1(tmpl_print_quoted
TALLOC_CTX * list_ctx
Where to allocate new attributes if building out from the current extents of the tree.
Definition tmpl.h:612
fr_table_num_sorted_t const tmpl_request_ref_table[]
Map keywords to tmpl_request_ref_t values.
static fr_slen_t rql fr_slen_t tmpl_attr_print(fr_sbuff_t *out, tmpl_t const *vpt)
Print an attribute or list tmpl_t to a string.
#define TMPL_FLAG_ATTR
Base data type is an attribute reference.
Definition tmpl.h:106
void tmpl_attr_debug(FILE *fp, tmpl_t const *vpt)
int tmpl_afrom_value_box(TALLOC_CTX *ctx, tmpl_t **out, fr_value_box_t *data, bool steal)
Create a tmpl_t from a fr_value_box_t.
#define ar_is_unknown(_ar)
Definition tmpl.h:509
tmpl_t * tmpl_alloc(TALLOC_CTX *ctx, tmpl_type_t type, fr_token_t quote, char const *name, ssize_t len)
Create a new heap allocated tmpl_t.
int tmpl_attr_unknown_add(tmpl_t *vpt)
Add an unknown fr_dict_attr_t specified by a tmpl_t to the main dictionary.
static bool tmpl_attr_tail_is_unknown(tmpl_t const *vpt)
Return true if the last attribute reference is "unknown".
Definition tmpl.h:744
int tmpl_extents_build_to_leaf_parent(fr_dlist_head_t *leaf, fr_dlist_head_t *interior, tmpl_t const *vpt)
Allocate interior pairs.
static tmpl_type_t tmpl_type_from_str(char const *type)
Return the constant value representing a type.
Definition tmpl.h:646
fr_value_box_safe_for_t literals_safe_for
safe_for value assigned to literal values in xlats, execs, and data.
Definition tmpl.h:349
void tmpl_set_escape(tmpl_t *vpt, tmpl_escape_t const *escape)
Set escape parameters for the tmpl output.
#define TMPL_FLAG_UNRESOLVED
Needs resolution.
Definition tmpl.h:121
#define ar_is_raw(_ar)
Definition tmpl.h:511
size_t pair_list_table_len
#define tmpl_is_attr(vpt)
Definition tmpl.h:208
bool tmpl_async_required(tmpl_t const *vpt)
Return whether or not async is required for this tmpl.
fr_dict_attr_t const * enumv
Enumeration attribute used to resolve enum values.
Definition tmpl.h:340
tmpl_rules_t const * parent
for parent / child relationships
Definition tmpl.h:335
void tmpl_rules_child_init(TALLOC_CTX *ctx, tmpl_rules_t *out, tmpl_rules_t const *parent, tmpl_t *vpt)
Initialize a set of rules from a parent set of rules, and a parsed tmpl_t.
static fr_slen_t tmpl_aprint(TALLOC_CTX *ctx, char **out, tmpl_t const *vpt, fr_sbuff_escape_rules_t const *e_rules) 1(tmpl_print
static fr_dict_attr_t const * tmpl_list(tmpl_t const *vpt)
Definition tmpl.h:906
int16_t _CONST num
For array references.
Definition tmpl.h:415
static bool tmpl_attr_is_list_attr(tmpl_attr_t const *ar)
Return true if the tmpl_attr is one of the list types.
Definition tmpl.h:681
void tmpl_attr_ref_list_debug(FILE *fp, FR_DLIST_HEAD(tmpl_attr_list) const *ar_head)
int tmpl_extents_find(TALLOC_CTX *ctx, fr_dlist_head_t *leaf, fr_dlist_head_t *interior, request_t *request, tmpl_t const *vpt))
Determines points where the reference list extends beyond the current pair tree.
ssize_t tmpl_afrom_attr_str(TALLOC_CTX *ctx, tmpl_attr_error_t *err, tmpl_t **out, char const *name, tmpl_rules_t const *rules))
Parse a string into a TMPL_TYPE_ATTR_* type tmpl_t.
static fr_slen_t tmpl_request_ref_list_aprint(TALLOC_CTX *ctx, char **out, FR_DLIST_HEAD(tmpl_request_list) const *rql) 1(tmpl_request_ref_list_print
int tmpl_eval_cast_in_place(fr_value_box_list_t *out, request_t *request, tmpl_t const *vpt)
Casts a value or list of values according to the tmpl.
Definition tmpl_eval.c:1240
void tmpl_set_name(tmpl_t *vpt, fr_token_t quote, char const *name, ssize_t len)
Set the name on a pre-initialised tmpl.
tmpl_type_e
Types of tmpl_t.
Definition tmpl.h:131
@ TMPL_TYPE_REGEX_UNCOMPILED
Regex where compilation is possible but hasn't been performed yet.
Definition tmpl.h:158
@ TMPL_TYPE_MAX
Marker for the last tmpl type.
Definition tmpl.h:199
@ TMPL_TYPE_ATTR_UNRESOLVED
An attribute reference that we couldn't resolve but looked valid.
Definition tmpl.h:185
@ TMPL_TYPE_ATTR
Reference to one or more attributes.
Definition tmpl.h:142
@ TMPL_TYPE_XLAT
Pre-parsed xlat expansion.
Definition tmpl.h:146
@ TMPL_TYPE_EXEC
Callout to an external script or program.
Definition tmpl.h:150
@ TMPL_TYPE_REGEX_XLAT_UNRESOLVED
A regular expression with unresolved xlat functions or attribute references.
Definition tmpl.h:197
@ TMPL_TYPE_DATA
Value in native boxed format.
Definition tmpl.h:138
@ TMPL_TYPE_REGEX
Compiled (and possibly JIT'd) regular expression.
Definition tmpl.h:154
@ TMPL_TYPE_DATA_UNRESOLVED
Unparsed literal string.
Definition tmpl.h:179
@ TMPL_TYPE_XLAT_UNRESOLVED
A xlat expansion with unresolved xlat functions or attribute references.
Definition tmpl.h:193
@ TMPL_TYPE_REGEX_XLAT
A regex containing xlat expansions.
Definition tmpl.h:162
@ TMPL_TYPE_EXEC_UNRESOLVED
An exec with unresolved xlat function or attribute references.
Definition tmpl.h:189
@ TMPL_TYPE_UNINITIALISED
Uninitialised.
Definition tmpl.h:134
int tmpl_attr_afrom_list(TALLOC_CTX *ctx, tmpl_t **out, tmpl_t const *list, fr_dict_attr_t const *da)
Create a new tmpl from a list tmpl and a da.
void tmpl_attr_to_raw(tmpl_t *vpt)
Convert the leaf attribute of a tmpl to a unknown/raw type.
static bool tmpl_attr_tail_da_is_leaf(tmpl_t const *vpt)
Return true if the the last attribute reference is a leaf attribute.
Definition tmpl.h:819
#define tmpl_assert_type(_cond)
Convenience macro for printing a meaningful assert message when we get a bad tmpl type.
Definition tmpl.h:622
static fr_slen_t vpt fr_slen_t tmpl_print(fr_sbuff_t *out, tmpl_t const *vpt, fr_sbuff_escape_rules_t const *e_rules))
Print a tmpl_t to a string.
#define tmpl_contains_attr(vpt)
Definition tmpl.h:225
int tmpl_eval(TALLOC_CTX *ctx, fr_value_box_list_t *out, request_t *request, tmpl_t const *vpt)
Gets the value of a tmpl.
Definition tmpl_eval.c:1109
tmpl_t * tmpl_copy(TALLOC_CTX *ctx, tmpl_t const *in)
Copy a tmpl.
static bool tmpl_attr_tail_da_is_structural(tmpl_t const *vpt)
Return true if the the last attribute reference is a structural attribute.
Definition tmpl.h:837
int tmpl_copy_pairs(TALLOC_CTX *ctx, fr_pair_list_t *out, request_t *request, tmpl_t const *vpt))
Copy pairs matching a tmpl_t in the current request_t.
Definition tmpl_eval.c:681
ssize_t _tmpl_to_atype(TALLOC_CTX *ctx, void *out, request_t *request, tmpl_t const *vpt, xlat_escape_legacy_t escape, void const *escape_ctx, fr_type_t dst_type))
Expand a template to a string, allocing a new buffer to hold the string.
Definition tmpl_eval.c:461
#define TMPL_FLAG_REGEX
Is a type of regular expression.
Definition tmpl.h:116
fr_pair_list_t * tmpl_list_head(request_t *request, fr_dict_attr_t const *list)
Resolve attribute fr_pair_list_t value to an attribute list.
Definition tmpl_eval.c:70
static size_t tmpl_request_ref_count(tmpl_t const *vpt)
The number of request references contained within a tmpl.
Definition tmpl.h:669
TALLOC_CTX * tmpl_list_ctx(request_t *request, fr_dict_attr_t const *list)
Return the correct TALLOC_CTX to alloc fr_pair_t in, for a list.
Definition tmpl_eval.c:110
ssize_t tmpl_afrom_substr(TALLOC_CTX *ctx, tmpl_t **out, fr_sbuff_t *in, fr_token_t quote, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules))
Convert an arbitrary string into a tmpl_t.
tmpl_rules_t _CONST rules
The rules that were used when creating the tmpl.
Definition tmpl.h:595
static fr_slen_t e_rules fr_slen_t tmpl_print_quoted(fr_sbuff_t *out, tmpl_t const *vpt)
Print a tmpl_t to a string with quotes.
fr_dlist_t entry
Entry in the dlist of extents.
Definition tmpl.h:604
fr_type_t tmpl_data_type(tmpl_t const *vpt)
Definition tmpl_eval.c:1347
int tmpl_global_init(void)
Definition tmpl_eval.c:1388
tmpl_xlat_rules_t xlat
Rules/data for parsing xlats.
Definition tmpl.h:338
static char const * tmpl_attr_tail_unresolved(tmpl_t const *vpt)
Return the last attribute reference unresolved da.
Definition tmpl.h:871
bool at_runtime
Produce an ephemeral/runtime tmpl.
Definition tmpl.h:346
static bool tmpl_is_list(tmpl_t const *vpt)
Definition tmpl.h:922
ssize_t tmpl_afrom_attr_substr(TALLOC_CTX *ctx, tmpl_attr_error_t *err, tmpl_t **out, fr_sbuff_t *name, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules))
Parse a string into a TMPL_TYPE_ATTR_* type tmpl_t.
bool new_functions
new function syntax
Definition tmpl.h:328
int tmpl_eval_pair(TALLOC_CTX *ctx, fr_value_box_list_t *out, request_t *request, tmpl_t const *vpt)
Gets the value of a real or virtual attribute.
Definition tmpl_eval.c:962
int tmpl_cast_in_place(tmpl_t *vpt, fr_type_t type, fr_dict_attr_t const *enumv))
Convert tmpl_t of type TMPL_TYPE_DATA_UNRESOLVED or TMPL_TYPE_DATA to TMPL_TYPE_DATA of type specifie...
bool force_dict_def
Use supplied dict_def even if original vpt->rules->dict_def was not NULL.
Definition tmpl.h:372
void tmpl_set_name_shallow(tmpl_t *vpt, fr_token_t quote, char const *name, ssize_t len)
Set the name on a pre-initialised tmpl.
static fr_slen_t vpt
Definition tmpl.h:1271
fr_dict_t const * dict_def
Alternative default dictionary to use if vpt->rules->dict_def is NULL.
Definition tmpl.h:367
static bool tmpl_attr_tail_is_unresolved(tmpl_t const *vpt)
Return true if the last attribute reference is "unresolved".
Definition tmpl.h:760
tmpl_type_t _CONST type
What type of value tmpl refers to.
Definition tmpl.h:550
#define _CONST
Definition tmpl.h:253
ssize_t tmpl_preparse(char const **out, size_t *outlen, char const *in, size_t inlen, fr_token_t *type))
Preparse a string in preparation for passing it to tmpl_afrom_substr()
union tmpl_s::@87 data
static size_t tmpl_attr_num_elements(tmpl_t const *vpt)
The number of attribute references contained within a tmpl.
Definition tmpl.h:898
fr_slen_t tmpl_request_ref_list_afrom_substr(TALLOC_CTX *ctx, tmpl_attr_error_t *err, FR_DLIST_HEAD(tmpl_request_list) _CONST **out, fr_sbuff_t *in)
fr_table_num_ordered_t const pair_list_table[]
void tmpl_debug(FILE *fp, tmpl_t const *vpt)
#define tmpl_attr(_tmpl)
Definition tmpl.h:656
void tmpl_attr_rewrite_leaf_num(tmpl_t *vpt, int16_t num)
Rewrite the leaf's instance number.
static fr_slen_t tmpl_attr_aprint(TALLOC_CTX *ctx, char **out, tmpl_t const *vpt) 1(tmpl_attr_print
static fr_type_t tmpl_cast_get(tmpl_t *vpt)
Definition tmpl.h:1220
int tmpl_request_ptr(request_t **request, FR_DLIST_HEAD(tmpl_request_list) const *rql)
Resolve a tmpl_request_ref_t to a request_t.
Definition tmpl_eval.c:163
char const *_CONST name
Raw string used to create the template.
Definition tmpl.h:552
tmpl_attr_error_t
Definition tmpl.h:1006
@ TMPL_ATTR_ERROR_INVALID_ARRAY_INDEX
Invalid array index.
Definition tmpl.h:1025
@ TMPL_ATTR_ERROR_LIST_NOT_ALLOWED
List qualifier is not allowed here.
Definition tmpl.h:1010
@ TMPL_ATTR_ERROR_INTERNAL_NOT_ALLOWED
Attribute resolved to an internal attribute which is disallowed.
Definition tmpl.h:1020
@ TMPL_ATTR_ERROR_UNRESOLVED_NOT_ALLOWED
Attribute couldn't be found in the dictionaries.
Definition tmpl.h:1016
@ TMPL_ATTR_ERROR_INVALID_FILTER
Invalid filter.
Definition tmpl.h:1026
@ TMPL_ATTR_ERROR_BAD_CAST
Specified cast was invalid.
Definition tmpl.h:1029
@ TMPL_ATTR_ERROR_INVALID_NAME
Attribute ref length is zero, or longer than the maximum.
Definition tmpl.h:1018
@ TMPL_ATTR_ERROR_UNQUALIFIED_NOT_ALLOWED
Attribute must be qualified to be used here.
Definition tmpl.h:1017
@ TMPL_ATTR_ERROR_MISSING_TERMINATOR
Unexpected text found after attribute reference.
Definition tmpl.h:1028
@ TMPL_ATTR_ERROR_LIST_MISSING
List qualifier is required, but missing.
Definition tmpl.h:1011
@ TMPL_ATTR_ERROR_NONE
No error.
Definition tmpl.h:1007
@ TMPL_ATTR_ERROR_FOREIGN_NOT_ALLOWED
Attribute resolved in a dictionary different to the one specified.
Definition tmpl.h:1022
@ TMPL_ATTR_ERROR_UNKNOWN_NOT_ALLOWED
Attribute specified as OID, could not be found in the dictionaries, and is disallowed because 'disall...
Definition tmpl.h:1012
@ TMPL_ATTR_ERROR_FILTER_NOT_ALLOWED
Filters disallowed by rules.
Definition tmpl.h:1024
@ TMPL_ATTR_ERROR_EMPTY
Attribute ref contains no data.
Definition tmpl.h:1008
@ TMPL_ATTR_ERROR_NESTING_TOO_DEEP
Too many levels of nesting.
Definition tmpl.h:1027
@ TMPL_ATTR_ERROR_BAD_PREFIX
Missing '&' or has '&' when it shouldn't.
Definition tmpl.h:1009
fr_type_t cast
Whether there was an explicit cast.
Definition tmpl.h:342
void tmpl_extents_debug(FILE *fp, fr_dlist_head_t *head)
tmpl_attr_rules_t attr
Rules/data for parsing attribute references.
Definition tmpl.h:337
void tmpl_rules_debug(tmpl_rules_t const *rules)
int tmpl_attr_copy(tmpl_t *dst, tmpl_t const *src)
Copy a list of attribute and request references from one tmpl to another.
fr_pair_list_t * list
List that we tried to evaluate ar in and failed.
Definition tmpl.h:614
ssize_t _tmpl_to_type(void *out, uint8_t *buff, size_t outlen, request_t *request, tmpl_t const *vpt, fr_type_t dst_type))
Expand a tmpl_t to a string writing the result to a buffer.
Definition tmpl_eval.c:276
tmpl_t * tmpl_init_printf(tmpl_t *vpt, tmpl_type_t type, fr_token_t quote, char const *fmt,...))
Initialise a tmpl using a format string to create the name.
static fr_dict_attr_t const * tmpl_attr_tail_da(tmpl_t const *vpt)
Return the last attribute reference da.
Definition tmpl.h:803
tmpl_attr_list_presence_t
Specify whether attribute references can have a list (or parent) reference.
Definition tmpl.h:261
@ TMPL_ATTR_LIST_REQUIRE
Attribute refs are required to have a list.
Definition tmpl.h:264
@ TMPL_ATTR_LIST_ALLOW
Attribute refs are allowed to have a list.
Definition tmpl.h:262
@ TMPL_ATTR_LIST_FORBID
Attribute refs are forbidden from having a list.
Definition tmpl.h:263
#define ar_is_unresolved(_ar)
Definition tmpl.h:510
static bool tmpl_attr_head_is_list(tmpl_t const *vpt)
Return true if the head attribute reference is a list reference.
Definition tmpl.h:696
enum tmpl_type_e tmpl_type_t
Types of tmpl_t.
size_t tmpl_type_table_len
struct tmpl_literal_rules_s tmpl_literal_rules_t
Definition tmpl.h:236
#define ar_is_normal(_ar)
Definition tmpl.h:507
int tmpl_attr_set_leaf_da(tmpl_t *vpt, fr_dict_attr_t const *da)
Replace the leaf attribute only.
static fr_dict_attr_t const * tmpl_attr_tail_unknown(tmpl_t const *vpt)
Return the last attribute reference unknown da.
Definition tmpl.h:855
static char const * tmpl_list_name(fr_dict_attr_t const *list, char const *def)
Return the name of a tmpl list or def if list not provided.
Definition tmpl.h:917
static bool tmpl_attr_tail_is_raw(tmpl_t const *vpt)
Return true if the last attribute reference is "raw".
Definition tmpl.h:776
requests_ref_e
Definition tmpl.h:90
@ REQUEST_OUTER
request_t containing the outer layer of the EAP conversation.
Definition tmpl.h:92
@ REQUEST_PARENT
Parent (whatever it is).
Definition tmpl.h:96
@ REQUEST_UNKNOWN
Unknown request.
Definition tmpl.h:97
@ REQUEST_CURRENT
The current request (default).
Definition tmpl.h:91
fr_slen_t tmpl_request_ref_list_print(fr_sbuff_t *out, FR_DLIST_HEAD(tmpl_request_list) const *rql))
int tmpl_find_or_add_vp(fr_pair_t **out, request_t *request, tmpl_t const *vpt)
Returns the first VP matching a tmpl_t, or if no VPs match, creates a new one.
Definition tmpl_eval.c:801
int tmpl_value_list_insert_tail(fr_value_box_list_t *list, fr_value_box_t *vb, tmpl_t const *vpt)
Insert a value-box to a list, with casting.
Definition tmpl_eval.c:937
void tmpl_set_dict_def(tmpl_t *vpt, fr_dict_t const *dict)
Change the default dictionary in the tmpl's resolution rules.
int tmpl_attr_tail_unresolved_add(fr_dict_t *dict, tmpl_t *vpt, fr_type_t type, fr_dict_attr_flags_t const *flags))
Add an unresolved fr_dict_attr_t specified by a tmpl_t to the main dictionary.
int tmpl_copy_pair_children(TALLOC_CTX *ctx, fr_pair_list_t *out, request_t *request, tmpl_t const *vpt))
Copy children of pairs matching a tmpl_t in the current request_t.
Definition tmpl_eval.c:724
fr_dict_attr_t const * enumv
for resolving T_BARE_WORD
Definition tmpl.h:375
size_t _CONST len
Length of the raw string used to create the template.
Definition tmpl.h:554
ssize_t tmpl_cast_from_substr(tmpl_rules_t *t_rules, fr_sbuff_t *in))
Parse a cast specifier.
int pair_append_by_tmpl_parent(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list, tmpl_t const *vpt, bool skip_list))
Allocate and insert a leaf vp from a tmpl_t, building the parent vps if needed.
Definition tmpl_eval.c:857
tmpl_attr_type_t
Definition tmpl.h:378
@ TMPL_ATTR_TYPE_UNSPEC
No attribute was specified as this level only a filter.
Definition tmpl.h:380
@ TMPL_ATTR_TYPE_NORMAL
Normal, resolved, attribute ref.
Definition tmpl.h:379
@ TMPL_ATTR_TYPE_UNKNOWN
We have an attribute number but it doesn't match anything in the dictionary, or isn't a child of the ...
Definition tmpl.h:382
@ TMPL_ATTR_TYPE_UNRESOLVED
We have a name, but nothing else to identify the attribute.
Definition tmpl.h:387
#define TMPL_FLAG_XLAT
Base data type is an xlat expansion.
Definition tmpl.h:111
tmpl_attr_t const * ar
Attribute representing the ar after the deepest node that was found in the existing pair tree when ev...
Definition tmpl.h:606
fr_slen_t tmpl_attr_list_from_substr(fr_dict_attr_t const **da_p, fr_sbuff_t *in)
Parse one a single list reference.
tmpl_attr_filter_type_t
Define entry and head types for attribute reference lists.
Definition tmpl.h:405
@ TMPL_ATTR_FILTER_TYPE_TMPL
Filter is a tmpl.
Definition tmpl.h:409
@ TMPL_ATTR_FILTER_TYPE_INDEX
Filter is an index type.
Definition tmpl.h:407
@ TMPL_ATTR_FILTER_TYPE_CONDITION
Filter is a condition.
Definition tmpl.h:408
@ TMPL_ATTR_FILTER_TYPE_NONE
No filter present.
Definition tmpl.h:406
@ TMPL_ATTR_FILTER_TYPE_EXPR
Filter is an expression.
Definition tmpl.h:410
fr_event_list_t * runtime_el
The eventlist to use for runtime instantiation of xlats.
Definition tmpl.h:326
fr_table_num_ordered_t const tmpl_type_table[]
Map tmpl_type_t values to descriptive strings.
int tmpl_cast_set(tmpl_t *vpt, fr_type_t type)
Set a cast for a tmpl.
fr_token_t _CONST quote
What type of quoting was around the raw string.
Definition tmpl.h:555
tmpl_t * tmpl_init_shallow(tmpl_t *vpt, tmpl_type_t type, fr_token_t quote, char const *name, ssize_t len, tmpl_rules_t const *t_rules))
Initialise a tmpl without copying the input name string.
fr_type_t tmpl_expanded_type(tmpl_t const *vpt)
Return the native data type of the expression.
Definition tmpl_eval.c:203
tmpl_attr_filter_type_t _CONST type
Type of filter this is.
Definition tmpl.h:414
size_t tmpl_request_ref_table_len
Describes the current extents of a pair tree in relation to the tree described by a tmpl_t.
Definition tmpl.h:603
Similar to tmpl_rules_t, but used to specify parameters that may change during subsequent resolution ...
Definition tmpl.h:366
Optional arguments passed to vp_tmpl functions.
Definition tmpl.h:334
A source or sink of value data.
Definition tmpl.h:549
static char buff[sizeof("18446744073709551615")+3]
Definition size_tests.c:41
fr_aka_sim_id_type_t type
Define entry and head types for tmpl request references.
Definition tmpl.h:272
uint8_t disallow_rhs_resolve
map RHS is NOT immediately resolved in the context of the LHS.
Definition tmpl.h:322
tmpl_attr_list_presence_t list_presence
Whether the attribute reference can have a list, forbid it, or require it.
Definition tmpl.h:298
fr_dict_attr_t const * list_def
Default list to use with unqualified attribute reference.
Definition tmpl.h:295
uint8_t disallow_filters
disallow filters.
Definition tmpl.h:316
uint8_t allow_unresolved
Allow attributes that look valid but were not found in the dictionaries.
Definition tmpl.h:306
uint8_t bare_word_enum
for v3 compatibility.
Definition tmpl.h:320
CONF_ITEM * ci
for migration support and various warnings
Definition tmpl.h:301
uint8_t allow_foreign
Allow arguments not found in dict_def.
Definition tmpl.h:314
fr_dict_t const * dict_def
Default dictionary to use with unqualified attribute references.
Definition tmpl.h:273
FR_DLIST_HEAD(tmpl_request_list) _CONST *request_def
< Point in dictionary tree to resume parsing from.
uint8_t allow_wildcard
Allow the special case of .
Definition tmpl.h:311
uint8_t allow_unknown
Allow unknown attributes i.e.
Definition tmpl.h:303
uint8_t xlat
for %{User-Name}
Definition tmpl.h:318
An element in a list of nested attribute references.
Definition tmpl.h:432
unsigned int _CONST resolve_only
This reference and those before it.
Definition tmpl.h:455
unsigned int _CONST is_raw
Definition tmpl.h:458
fr_dict_attr_t const *_CONST da
Resolved dictionary attribute.
Definition tmpl.h:436
fr_dict_attr_t const *_CONST parent
The parent we used when trying to resolve the attribute originally.
Definition tmpl.h:450
FR_DLIST_ENTRY(tmpl_attr_list) _CONST entry
Entry in the doubly linked list of attribute references.
tmpl_attr_filter_t _CONST filter
Filter associated with the attribute reference.
Definition tmpl.h:462
tmpl_attr_type_t _CONST type
is a raw reference
Definition tmpl.h:460
Define manipulation functions for the attribute reference list.
Definition tmpl.h:473
FR_DLIST_ENTRY(tmpl_request_list) _CONST entry
Entry in the doubly linked list of request references.
tmpl_request_ref_t _CONST request
Definition tmpl.h:477
Stores an attribute, a value and various bits of other data.
Definition pair.h:68
#define fr_table_value_by_str(_table, _name, _def)
Convert a string to a value using a sorted or ordered table.
Definition table.h:653
#define fr_table_str_by_value(_table, _number, _def)
Convert an integer to a string.
Definition table.h:772
An element in an arbitrarily ordered array of name to num mappings.
Definition table.h:57
An element in a lexicographically sorted array of name to num mappings.
Definition table.h:49
Escaping rules for tmpls.
Definition tmpl_escape.h:80
enum fr_token fr_token_t
static fr_slen_t head
Definition xlat.h:420
static fr_slen_t parent
Definition pair.h:841
#define fr_type_is_structural(_x)
Definition types.h:393
#define fr_type_is_leaf(_x)
Definition types.h:394
static fr_slen_t data
Definition value.h:1293
static size_t char fr_sbuff_t size_t inlen
Definition value.h:1023
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:1023