The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Macros | Functions | Variables
tmpl_tokenize.c File Reference

fr_pair_t template functions More...

#include <freeradius-devel/server/tmpl.h>
#include <freeradius-devel/server/base.h>
#include <freeradius-devel/protocol/freeradius/freeradius.internal.h>
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/base16.h>
#include <freeradius-devel/util/misc.h>
#include <freeradius-devel/util/sbuff.h>
#include <freeradius-devel/util/value.h>
#include <ctype.h>
+ Include dependency graph for tmpl_tokenize.c:

Go to the source code of this file.

Macros

#define _TMPL_PRIVATE   1
 
#define DEFAULT_RULES   tmpl_rules_t const default_rules = { .attr = { .list_def = request_attr_request }}
 Default parser rules. More...
 
#define RESOLVED_SET(_flags)   (*(_flags) = (*(_flags) & ~TMPL_FLAG_UNRESOLVED))
 
#define return_P(_x)   fr_strerror_const(_x);goto return_p
 
#define TMPL_REQUEST_REF_DEF(_name, _ref)
 Define a global variable for specifying a default request reference. More...
 
#define UNRESOLVED_SET(_flags)   (*(_flags) = (*(_flags) | TMPL_FLAG_UNRESOLVED))
 

Functions

ssize_t tmpl_afrom_attr_str (TALLOC_CTX *ctx, tmpl_attr_error_t *err, tmpl_t **out, char const *name, tmpl_rules_t const *t_rules)
 Parse a string into a TMPL_TYPE_ATTR_* type tmpl_t. More...
 
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. More...
 
static fr_slen_t tmpl_afrom_bool_substr (TALLOC_CTX *ctx, tmpl_t **out, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *p_rules)
 Parse a truth value. More...
 
static ssize_t tmpl_afrom_enum (TALLOC_CTX *ctx, tmpl_t **out, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules)
 
static ssize_t tmpl_afrom_ether_substr (TALLOC_CTX *ctx, tmpl_t **out, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *p_rules)
 Try and parse signed or unsigned integers. More...
 
static ssize_t tmpl_afrom_float_substr (TALLOC_CTX *ctx, tmpl_t **out, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *p_rules)
 
static fr_slen_t tmpl_afrom_integer_substr (TALLOC_CTX *ctx, tmpl_t **out, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *p_rules)
 Try and parse signed or unsigned integers. More...
 
static fr_slen_t tmpl_afrom_ipv4_substr (TALLOC_CTX *ctx, tmpl_t **out, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *p_rules)
 Parse bareword as an IPv4 address or prefix. More...
 
static fr_slen_t tmpl_afrom_ipv6_substr (TALLOC_CTX *ctx, tmpl_t **out, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *p_rules)
 Parse bareword as an IPv6 address or prefix. More...
 
static fr_slen_t tmpl_afrom_octets_substr (TALLOC_CTX *ctx, tmpl_t **out, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *p_rules)
 Parse bareword as an octet string. More...
 
fr_slen_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. More...
 
static ssize_t tmpl_afrom_time_delta (TALLOC_CTX *ctx, tmpl_t **out, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *p_rules)
 
static fr_slen_t tmpl_afrom_value_substr (TALLOC_CTX *ctx, tmpl_t **out, fr_sbuff_t *in, fr_token_t quote, tmpl_rules_t const *t_rules, bool allow_enum, fr_sbuff_parse_rules_t const *p_rules)
 Create TMPL_TYPE_DATA from a string. More...
 
bool tmpl_async_required (tmpl_t const *vpt)
 Return whether or not async is required for this tmpl. More...
 
static int tmpl_attr_afrom_attr_substr (TALLOC_CTX *ctx, tmpl_attr_error_t *err, tmpl_t *vpt, fr_dict_attr_t const *parent, fr_dict_attr_t const *namespace, fr_sbuff_t *name, fr_sbuff_parse_rules_t const *p_rules, tmpl_attr_rules_t const *at_rules, unsigned int depth)
 Parse an attribute reference, either an OID or attribute name. More...
 
void tmpl_attr_debug (tmpl_t const *vpt)
 
static void tmpl_attr_insert (tmpl_t *vpt, tmpl_attr_t *ar)
 Insert an attribute reference into a tmpl. More...
 
static fr_slen_t tmpl_attr_parse_filter (tmpl_attr_error_t *err, tmpl_attr_t *ar, fr_sbuff_t *name, tmpl_attr_rules_t const *at_rules)
 Parse array subscript and in future other filters. More...
 
static fr_slen_t tmpl_attr_ref_afrom_unresolved_substr (TALLOC_CTX *ctx, tmpl_attr_error_t *err, tmpl_t *vpt, fr_dict_attr_t const *parent, fr_dict_attr_t const *namespace, fr_sbuff_t *name, tmpl_attr_rules_t const *at_rules)
 Parse an unresolved attribute, i.e. More...
 
void tmpl_attr_ref_debug (const tmpl_attr_t *ar, int i)
 
static void tmpl_attr_ref_fixup (TALLOC_CTX *ctx, tmpl_t *vpt, fr_dict_attr_t const *da, fr_dict_attr_t const *parent)
 
static fr_slen_t tmpl_attr_ref_from_unspecified_substr (tmpl_attr_t *ar, tmpl_attr_error_t *err, tmpl_t *vpt, fr_sbuff_t *name, tmpl_attr_rules_t const *at_rules)
 
void tmpl_attr_ref_list_debug (FR_DLIST_HEAD(tmpl_attr_list) const *ar_head)
 
static void tmpl_attr_rules_debug (tmpl_attr_rules_t const *at_rules)
 
ssize_t tmpl_cast_from_substr (tmpl_rules_t *rules, fr_sbuff_t *in)
 Parse a cast specifier. More...
 
int tmpl_cast_set (tmpl_t *vpt, fr_type_t dst_type)
 Set a cast for a tmpl. More...
 
tmpl_ttmpl_copy (TALLOC_CTX *ctx, tmpl_t const *in)
 Copy a tmpl. More...
 
void tmpl_debug (tmpl_t const *vpt)
 
ssize_t tmpl_preparse (char const **out, size_t *outlen, char const *in, size_t inlen, fr_token_t *type, fr_dict_attr_t const **castda, bool require_regex, bool allow_xlat)
 Preparse a string in preparation for passing it to tmpl_afrom_substr() More...
 
 TMPL_REQUEST_REF_DEF (tmpl_request_def_current, REQUEST_CURRENT)
 Use the current request as the default. More...
 
 TMPL_REQUEST_REF_DEF (tmpl_request_def_outer, REQUEST_OUTER)
 Use the outer request as the default. More...
 
 TMPL_REQUEST_REF_DEF (tmpl_request_def_parent, REQUEST_PARENT)
 Use the parent request as the default. More...
 
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. More...
 
void tmpl_rules_debug (tmpl_rules_t const *rules)
 
static bool tmpl_substr_terminal_check (fr_sbuff_t *in, fr_sbuff_parse_rules_t const *p_rules)
 Verify, after skipping whitespace, that a substring ends in a terminal char, or ends without further chars. More...
 

Variables

static fr_table_num_sorted_t const attr_num_table []
 Special attribute reference indexes. More...
 
static size_t attr_num_table_len = NUM_ELEMENTS(attr_num_table)
 
static fr_table_num_ordered_t const attr_table []
 Attr ref types. More...
 
static size_t attr_table_len = NUM_ELEMENTS(attr_table)
 
fr_dict_attr_t const * tmpl_attr_unspec
 Placeholder attribute for uses of unspecified attribute references. More...
 
fr_table_num_sorted_t const tmpl_request_ref_table []
 Map keywords to tmpl_request_ref_t values. More...
 
size_t tmpl_request_ref_table_len = NUM_ELEMENTS(tmpl_request_ref_table)
 
fr_table_num_ordered_t const tmpl_type_table []
 Map tmpl_type_t values to descriptive strings. More...
 
size_t tmpl_type_table_len = NUM_ELEMENTS(tmpl_type_table)
 

Change a #tmpl_t type, usually by casting or resolving a reference

tmpl_cast_in_place can be used to convert TMPL_TYPE_DATA_UNRESOLVED to a TMPL_TYPE_DATA of a specified fr_type_t.

tmpl_attr_unknown_add converts a TMPL_TYPE_ATTR with an unknown fr_dict_attr_t to a TMPL_TYPE_ATTR with a known fr_dict_attr_t, by adding the unknown fr_dict_attr_t to the main dictionary, and updating the tmpl_attr_tail_da pointer.

static void attr_to_raw (tmpl_t *vpt, tmpl_attr_t *ref)
 
static int tmpl_attr_resolve (tmpl_t *vpt, tmpl_res_rules_t const *tr_rules)
 Resolve an unresolved attribute. More...
 
int tmpl_attr_tail_unresolved_add (fr_dict_t *dict_def, 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. More...
 
void tmpl_attr_to_raw (tmpl_t *vpt)
 Convert the leaf attribute of a tmpl to a unknown/raw type. More...
 
int tmpl_attr_to_xlat (TALLOC_CTX *ctx, tmpl_t **vpt_p)
 Convert an attribute reference to an xlat expansion. More...
 
int tmpl_attr_unknown_add (tmpl_t *vpt)
 Add an unknown fr_dict_attr_t specified by a tmpl_t to the main dictionary. More...
 
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 specified. More...
 
static fr_token_t tmpl_cast_quote (fr_token_t existing_quote, fr_type_t type, fr_dict_attr_t const *enumv, char const *unescaped, size_t unescaped_len)
 Determine the correct quoting after a cast. More...
 
int tmpl_resolve (tmpl_t *vpt, tmpl_res_rules_t const *tr_rules)
 Attempt to resolve functions and attributes in xlats and attribute references. More...
 
void tmpl_unresolve (tmpl_t *vpt)
 Reset the tmpl, leaving only the name in place. More...
 
static int tmpl_xlat_resolve (tmpl_t *vpt, tmpl_res_rules_t const *tr_rules)
 Resolve an unresolved xlat, i.e. More...
 

Parse list and request qualifiers to #fr_pair_list_t and #tmpl_request_ref_t values

These functions also resolve fr_pair_list_t and tmpl_request_ref_t values to request_t structs and the head of fr_pair_t lists in those structs.

For adding new fr_pair_t to the lists, the tmpl_list_ctx function can be used to obtain the appropriate TALLOC_CTX pointer.

Note
These don't really have much to do with tmpl_t. They're in the same file as they're used almost exclusively by the tmpl_* functions.
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. More...
 
static void tmpl_request_ref_list_acopy (TALLOC_CTX *ctx, FR_DLIST_HEAD(tmpl_request_list) **out, FR_DLIST_HEAD(tmpl_request_list) const *in)
 Allocate a new request reference list and copy request references into it. More...
 
fr_slen_t tmpl_request_ref_list_afrom_substr (TALLOC_CTX *ctx, tmpl_attr_error_t *err, FR_DLIST_HEAD(tmpl_request_list) **out, fr_sbuff_t *in)
 Parse one or more request references, allocing a new list and adding the references to it. More...
 
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. More...
 
static void tmpl_request_ref_list_copy (TALLOC_CTX *ctx, FR_DLIST_HEAD(tmpl_request_list) *out, FR_DLIST_HEAD(tmpl_request_list) const *in)
 Allocate a new request reference and add it to the end of the attribute reference list. More...
 
void tmpl_request_ref_list_debug (FR_DLIST_HEAD(tmpl_request_list) const *rql)
 Dump a request list to stderr. More...
 
static fr_slen_t tmpl_request_ref_list_from_substr (TALLOC_CTX *ctx, tmpl_attr_error_t *err, FR_DLIST_HEAD(tmpl_request_list) *out, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules, fr_dict_attr_t const **namespace)
 Parse one or more request references, writing the list to out. More...
 

Alloc or initialise #tmpl_t

Note
Should not usually be called outside of tmpl_* functions, use one of the tmpl_*from_* functions instead.
tmpl_ttmpl_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. More...
 
static tmpl_ttmpl_alloc_null (TALLOC_CTX *ctx)
 Create a new heap allocated tmpl_t. More...
 
tmpl_ttmpl_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. More...
 
tmpl_ttmpl_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. More...
 
tmpl_ttmpl_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. More...
 
void tmpl_set_dict_def (tmpl_t *vpt, fr_dict_t const *dict)
 Change the default dictionary in the tmpl's resolution rules. More...
 
void tmpl_set_escape (tmpl_t *vpt, tmpl_escape_t const *escape)
 Set escape parameters for the tmpl output. More...
 
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. More...
 
void tmpl_set_name_printf (tmpl_t *vpt, fr_token_t quote, char const *fmt,...)
 Set the name on a pre-initialised tmpl. More...
 
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. More...
 
void tmpl_set_xlat (tmpl_t *vpt, xlat_exp_head_t *xlat)
 Change the default dictionary in the tmpl's resolution rules. More...
 
static void tmpl_type_init (tmpl_t *vpt, tmpl_type_t type)
 Initialise fields inside a tmpl depending on its type. More...
 

Create new #tmpl_t from a string

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. More...
 
static tmpl_attr_ttmpl_attr_add (tmpl_t *vpt, tmpl_attr_type_t type)
 Allocate a new attribute reference and add it to the end of the attribute reference list. More...
 
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. More...
 
int tmpl_attr_copy (tmpl_t *dst, tmpl_t const *src)
 Copy a list of attribute and request references from one tmpl to another. More...
 
void tmpl_attr_rewrite_leaf_num (tmpl_t *vpt, int16_t from, int16_t to)
 Rewrite the leaf's instance number. More...
 
void tmpl_attr_rewrite_num (tmpl_t *vpt, int16_t from, int16_t to)
 Rewrite all instances of an array number. More...
 
int tmpl_attr_set_da (tmpl_t *vpt, fr_dict_attr_t const *da)
 Replace the current attribute reference. More...
 
int tmpl_attr_set_leaf_da (tmpl_t *vpt, fr_dict_attr_t const *da)
 Replace the leaf attribute only. More...
 
void tmpl_attr_set_leaf_num (tmpl_t *vpt, int16_t num)
 
void tmpl_attr_set_list (tmpl_t *vpt, fr_dict_attr_t const *list)
 
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. More...
 

Print the contents of a #tmpl_t

fr_slen_t tmpl_attr_print (fr_sbuff_t *out, tmpl_t const *vpt, tmpl_attr_prefix_t ar_prefix)
 Print an attribute or list tmpl_t to a string. More...
 
fr_slen_t tmpl_print (fr_sbuff_t *out, tmpl_t const *vpt, tmpl_attr_prefix_t ar_prefix, fr_sbuff_escape_rules_t const *e_rules)
 Print a tmpl_t to a string. More...
 
fr_slen_t tmpl_print_quoted (fr_sbuff_t *out, tmpl_t const *vpt, tmpl_attr_prefix_t ar_prefix)
 Print a tmpl_t to a string with quotes. More...
 
fr_slen_t tmpl_request_ref_list_print (fr_sbuff_t *out, FR_DLIST_HEAD(tmpl_request_list) const *rql)
 

Detailed Description

fr_pair_t template functions

Id
6d6d65a26488c2c79b0252be5445096d23bc9032

Definition in file tmpl_tokenize.c.

Macro Definition Documentation

◆ _TMPL_PRIVATE

#define _TMPL_PRIVATE   1

Definition at line 29 of file tmpl_tokenize.c.

◆ DEFAULT_RULES

#define DEFAULT_RULES   tmpl_rules_t const default_rules = { .attr = { .list_def = request_attr_request }}

Default parser rules.

Because this is getting to be a ridiculous number of parsing rules to pass in via arguments.

Defaults are used if a NULL rules pointer is passed to the parsing function.

Definition at line 99 of file tmpl_tokenize.c.

◆ RESOLVED_SET

#define RESOLVED_SET (   _flags)    (*(_flags) = (*(_flags) & ~TMPL_FLAG_UNRESOLVED))

Definition at line 165 of file tmpl_tokenize.c.

◆ return_P

#define return_P (   _x)    fr_strerror_const(_x);goto return_p

Definition at line 5181 of file tmpl_tokenize.c.

◆ TMPL_REQUEST_REF_DEF

#define TMPL_REQUEST_REF_DEF (   _name,
  _ref 
)
Value:
static tmpl_request_t _name ## _entry = { \
.entry = { \
.entry = { \
.next = &_name.head.entry, \
.prev = &_name.head.entry \
} \
}, \
.request = _ref \
}; \
FR_DLIST_HEAD(tmpl_request_list) _name = { \
.head = { \
.offset = offsetof(tmpl_request_t, entry), \
.entry = { \
.next = &_name ## _entry.entry.entry, \
.prev = &_name ## _entry.entry.entry, \
}, \
.num_elements = 1, \
} \
}
Define manipulation functions for the attribute reference list.
Definition: tmpl.h:468
tmpl_request_ref_t _CONST request
Definition: tmpl.h:472

Define a global variable for specifying a default request reference.

Parameters
[in]_namewhat the global variable should be called.
[in]_refone of the values of tmpl_request_ref_t
  • REQUEST_CURRENT
  • REQUEST_OUTER,
  • REQUEST_PARENT,
  • REQUEST_UNKNOWN

Definition at line 53 of file tmpl_tokenize.c.

◆ UNRESOLVED_SET

#define UNRESOLVED_SET (   _flags)    (*(_flags) = (*(_flags) | TMPL_FLAG_UNRESOLVED))

Definition at line 164 of file tmpl_tokenize.c.

Function Documentation

◆ attr_to_raw()

static void attr_to_raw ( tmpl_t vpt,
tmpl_attr_t ref 
)
static

Definition at line 4226 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_afrom_attr_str()

ssize_t tmpl_afrom_attr_str ( TALLOC_CTX *  ctx,
tmpl_attr_error_t err,
tmpl_t **  out,
char const *  name,
tmpl_rules_t const *  t_rules 
)

Parse a string into a TMPL_TYPE_ATTR_* type tmpl_t.

Parameters
[in,out]ctxto allocate tmpl_t in.
[out]errMay be NULL. Provides the exact error that the parser hit when processing the attribute ref.
[out]outWhere to write pointer to new tmpl_t.
[in]nameof attribute including tmpl_request_ref_t and fr_pair_list_t qualifiers.
[in]t_rulesRules which control parsing. See tmpl_afrom_attr_substr() for details.
Note
Unlike tmpl_afrom_attr_substr this function will error out if the entire name string isn't parsed.

Definition at line 2354 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_afrom_attr_substr()

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.

Parameters
[in,out]ctxto allocate tmpl_t in.
[out]errMay be NULL. Provides the exact error that the parser hit when processing the attribute ref.
[out]outWhere to write pointer to new tmpl_t.
[in]nameof attribute including tmpl_request_ref_t and fr_pair_list_t qualifiers.
[in]p_rulesFormatting rules used to check for trailing garbage.
[in]t_rulesRules which control parsing:
  • dict_def The default dictionary to use if attributes are unqualified.
  • request_def The default request_t to set if no tmpl_request_ref_t qualifiers are found in name.
  • list_def The default list to set if no fr_pair_list_t qualifiers are found in the name.
  • allow_unknown If true attributes in the format accepted by fr_dict_unknown_afrom_oid_substr will be allowed, even if they're not in the main dictionaries. If an unknown attribute is found a TMPL_TYPE_ATTR tmpl_t will be produced. If tmpl_afrom_attr_substr is being called on startup, the tmpl_t may be passed to tmpl_attr_unknown_add to add the unknown attribute to the main dictionary. If the unknown attribute is not added to the main dictionary the tmpl_t cannot be used to search for a fr_pair_t in a request_t.
  • allow_unresolved If true, we don't generate a parse error on unknown attributes. If an unknown attribute is found a TMPL_TYPE_ATTR_UNRESOLVED tmpl_t will be produced.
  • allow_foreign If true, allow attribute names to be qualified with a protocol outside of the passed dict_def.
  • disallow_filters
See also
REMARKER to produce pretty error markers from the return value.
Returns
  • <= 0 on error (offset as negative integer)
  • > 0 on success (number of bytes parsed).

Definition at line 2095 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_afrom_bool_substr()

static fr_slen_t tmpl_afrom_bool_substr ( TALLOC_CTX *  ctx,
tmpl_t **  out,
fr_sbuff_t in,
fr_sbuff_parse_rules_t const *  p_rules 
)
static

Parse a truth value.

Parameters
[in]ctxto allocate tmpl to.
[out]outwhere to write tmpl.
[in]insbuff to parse.
[in]p_rulesformatting rules.
Returns
  • < 0 sbuff does not contain a boolean value.
  • > 0 how many bytes were parsed.

Definition at line 2443 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_afrom_enum()

static ssize_t tmpl_afrom_enum ( TALLOC_CTX *  ctx,
tmpl_t **  out,
fr_sbuff_t in,
fr_sbuff_parse_rules_t const *  p_rules,
tmpl_rules_t const *  t_rules 
)
static

Definition at line 2942 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_afrom_ether_substr()

static ssize_t tmpl_afrom_ether_substr ( TALLOC_CTX *  ctx,
tmpl_t **  out,
fr_sbuff_t in,
fr_sbuff_parse_rules_t const *  p_rules 
)
static

Try and parse signed or unsigned integers.

Parameters
[in]ctxto allocate tmpl to.
[out]outwhere to write tmpl.
[in]insbuff to parse.
[in]p_rulesformatting rules.
Returns
  • < 0 sbuff does not contain a mac address.
  • > 0 how many bytes were parsed.

Definition at line 2726 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_afrom_float_substr()

static ssize_t tmpl_afrom_float_substr ( TALLOC_CTX *  ctx,
tmpl_t **  out,
fr_sbuff_t in,
fr_sbuff_parse_rules_t const *  p_rules 
)
static

Definition at line 2869 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_afrom_integer_substr()

static fr_slen_t tmpl_afrom_integer_substr ( TALLOC_CTX *  ctx,
tmpl_t **  out,
fr_sbuff_t in,
fr_sbuff_parse_rules_t const *  p_rules 
)
static

Try and parse signed or unsigned integers.

Parameters
[in]ctxto allocate tmpl to.
[out]outwhere to write tmpl.
[in]insbuff to parse.
[in]p_rulesformatting rules.
Returns
  • < 0 sbuff does not contain an integer.
  • > 0 how many bytes were parsed.

Definition at line 2793 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_afrom_ipv4_substr()

static fr_slen_t tmpl_afrom_ipv4_substr ( TALLOC_CTX *  ctx,
tmpl_t **  out,
fr_sbuff_t in,
fr_sbuff_parse_rules_t const *  p_rules 
)
static

Parse bareword as an IPv4 address or prefix.

Parameters
[in]ctxto allocate tmpl to.
[out]outwhere to write tmpl.
[in]insbuff to parse.
[in]p_rulesformatting rules.
Returns
  • < 0 sbuff does not contain an IPv4 address or prefix.
  • > 0 how many bytes were parsed.

Definition at line 2540 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_afrom_ipv6_substr()

static fr_slen_t tmpl_afrom_ipv6_substr ( TALLOC_CTX *  ctx,
tmpl_t **  out,
fr_sbuff_t in,
fr_sbuff_parse_rules_t const *  p_rules 
)
static

Parse bareword as an IPv6 address or prefix.

Parameters
[in]ctxto allocate tmpl to.
[out]outwhere to write tmpl.
[in]insbuff to parse.
[in]p_rulesformatting rules.
Returns
  • < 0 sbuff does not contain an IPv4 address or prefix.
  • > 0 how many bytes were parsed.

Definition at line 2608 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_afrom_octets_substr()

static fr_slen_t tmpl_afrom_octets_substr ( TALLOC_CTX *  ctx,
tmpl_t **  out,
fr_sbuff_t in,
fr_sbuff_parse_rules_t const *  p_rules 
)
static

Parse bareword as an octet string.

Parameters
[in]ctxto allocate tmpl to.
[out]outwhere to write tmpl.
[in]insbuff to parse.
[in]p_rulesformatting rules.
Returns
  • < 0 negative offset where parse error occurred.
  • 0 sbuff does not contain a hex string.
  • > 0 how many bytes were parsed.

Definition at line 2481 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_afrom_substr()

fr_slen_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.

Note
Unlike tmpl_afrom_attr_str return code 0 doesn't necessarily indicate failure, may just mean a 0 length string was parsed. Check to see if the function emitted a tmpl_t in *out.
xlats and regexes are left uncompiled. This is to support the two pass parsing done by the modcall code. Compilation on pass1 of that code could fail, as attributes or xlat functions registered by modules may not be available (yet).
For details of attribute parsing see tmpl_afrom_attr_substr.
Parameters
[in,out]ctxTo allocate tmpl_t in.
[out]outWhere to write the pointer to the new tmpl_t.
[in]inString to parse.
[in]quoteQuoting around the tmpl. Determines what we attempt to parse the string as.
[in]p_rulesFormatting rules for the tmpl.
[in]t_rulesValidation rules for attribute references.
Returns
  • < 0 on error (offset as negative integer)
  • >= 0 on success (number of bytes parsed).
See also
REMARKER to produce pretty error markers from the return value.
tmpl_afrom_attr_substr

Definition at line 3049 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_afrom_time_delta()

static ssize_t tmpl_afrom_time_delta ( TALLOC_CTX *  ctx,
tmpl_t **  out,
fr_sbuff_t in,
fr_sbuff_parse_rules_t const *  p_rules 
)
static

Definition at line 2897 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_afrom_value_box()

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.

Parameters
[in,out]ctxto allocate tmpl_t in.
[out]outWhere to write pointer to new tmpl_t.
[in]datato convert.
[in]stealIf true, any buffers are moved to the new ctx instead of being duplicated.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 998 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_afrom_value_substr()

static fr_slen_t tmpl_afrom_value_substr ( TALLOC_CTX *  ctx,
tmpl_t **  out,
fr_sbuff_t in,
fr_token_t  quote,
tmpl_rules_t const *  t_rules,
bool  allow_enum,
fr_sbuff_parse_rules_t const *  p_rules 
)
static

Create TMPL_TYPE_DATA from a string.

Parameters
[in]ctxto allocate tmpl to.
[out]outwhere to write tmpl.
[in]insbuff to parse.
[in]quotesurrounding the operand to parse.
[in]t_rulesspecifying the cast and any enumeration values.
[in]allow_enumWhether parsing the value as an enum should be allowed.
[in]p_rulesformatting rules.
Returns
  • <0 on error
  • >=0 on success.

Definition at line 2393 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_alloc()

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.

Parameters
[in,out]ctxto allocate in.
[in]typeto set in the tmpl_t.
[in]nameof the tmpl_t (will be copied to a new talloc buffer parented by the tmpl_t).
[in]lenThe length of the buffer (or a substring of the buffer) pointed to by name. If < 0 strlen will be used to determine the length.
[in]quoteThe type of quoting around the template name.
Returns
the newly allocated tmpl_t.

Definition at line 942 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_alloc_null()

static tmpl_t* tmpl_alloc_null ( TALLOC_CTX *  ctx)
inlinestatic

Create a new heap allocated tmpl_t.

Must be later initialised with a tmpl_init_* function.

This function is provided to allow tmpls to be pre-allocated for talloc purposes before their name is known.

Definition at line 916 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_async_required()

bool tmpl_async_required ( tmpl_t const *  vpt)

Return whether or not async is required for this tmpl.

If the tmpl is needs_async, then it is async
If the tmpl is not needs_async, then it will not yield

If the tmpl yields, then async is required.

Definition at line 5653 of file tmpl_tokenize.c.

+ Here is the caller graph for this function:

◆ tmpl_attr_add()

static tmpl_attr_t* tmpl_attr_add ( tmpl_t vpt,
tmpl_attr_type_t  type 
)
static

Allocate a new attribute reference and add it to the end of the attribute reference list.

Definition at line 964 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_attr_afrom_attr_substr()

static int tmpl_attr_afrom_attr_substr ( TALLOC_CTX *  ctx,
tmpl_attr_error_t err,
tmpl_t vpt,
fr_dict_attr_t const *  parent,
fr_dict_attr_t const *  namespace,
fr_sbuff_t name,
fr_sbuff_parse_rules_t const *  p_rules,
tmpl_attr_rules_t const *  at_rules,
unsigned int  depth 
)
inlinestatic

Parse an attribute reference, either an OID or attribute name.

Note
Do not call directly.
Parameters
[in]ctxto allocate new attribute reference in.
[out]errParse error.
[in,out]vptto append this reference to.
[in]parentParent where the attribute will be placed (group, struct, tlv, etc).
[in]namespaceWhere the child attribute will be parsed from (dict root, struct member, TLV child, etc)
[in]nameto parse.
[in]p_rulesFormatting rules used to check for trailing garbage.
[in]at_ruleswhich places constraints on attribute reference parsing. Rules interpreted by this function is:
  • allow_unknown - If false unknown OID components result in a parse error.
  • allow_unresolved - If false unknown attribute names result in a parse error.
  • allow_foreign - If an attribute resolves in a dictionary that does not match the parent (exception being FR_TYPE_GROUP) then that results in a parse error.
[in]depthHow deep we are. Used to check for maximum nesting level.
Returns
  • <0 on error.
  • 0 on success.

Definition at line 1648 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_attr_afrom_list()

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.

Definition at line 1240 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_attr_copy()

int tmpl_attr_copy ( tmpl_t dst,
tmpl_t const *  src 
)

Copy a list of attribute and request references from one tmpl to another.

Definition at line 1028 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_attr_debug()

void tmpl_attr_debug ( tmpl_t const *  vpt)

Definition at line 266 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_attr_insert()

static void tmpl_attr_insert ( tmpl_t vpt,
tmpl_attr_t ar 
)
inlinestatic

Insert an attribute reference into a tmpl.

Not all attribute references can be used to create new attributes, for example those accessing instance > 0 or those that resolve to special indexes.

We mark up these references and their parents as resolve only meaning that if any code needs to use a reference chain to build out a pair tree, it bails out early.

Parameters
[in]vptcontaining the reference list.
[in]arto insert and check.

Definition at line 1298 of file tmpl_tokenize.c.

+ Here is the caller graph for this function:

◆ tmpl_attr_list_from_substr()

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.

Parameters
[out]da_pattribute representing a list.
[in]inSbuff to read request references from.
Returns
  • > 0 the number of bytes parsed.
  • 0 no list qualifier found.

Definition at line 394 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_attr_parse_filter()

static fr_slen_t tmpl_attr_parse_filter ( tmpl_attr_error_t err,
tmpl_attr_t ar,
fr_sbuff_t name,
tmpl_attr_rules_t const *  at_rules 
)
static

Parse array subscript and in future other filters.

Parameters
[out]errParse error code.
[in]arto populate filter for.
[in]namecontaining more attribute ref data.
[in]at_rulessee tmpl_attr_afrom_attr_substr.
Returns
  • >0 if a filter was parsed.
  • 0 if no filter was available.
  • <0 on filter parse error.

Definition at line 1328 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_attr_print()

fr_slen_t tmpl_attr_print ( fr_sbuff_t out,
tmpl_t const *  vpt,
tmpl_attr_prefix_t  ar_prefix 
)

Print an attribute or list tmpl_t to a string.

This function is the direct counterpart to tmpl_afrom_attr_substr.

Parameters
[in]outWhere to write the presentation format tmpl_t string.
[in]vptto print.
[in]ar_prefixWhether to print the '&' at the beginning of attribute references.
  • TMPL_ATTR_REF_PREFIX_YES - always print.
  • TMPL_ATTR_REF_PREFIX_NO - never print.
  • TMPL_ATTR_REF_PREFIX_AUTO - print if the original tmpl was prefixed.
Returns
  • >0 the number of bytes written to the out buffer.
  • 0 invalid argument.
  • <0 the number of bytes we would have needed to complete the print.

Definition at line 4478 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_attr_ref_afrom_unresolved_substr()

static fr_slen_t tmpl_attr_ref_afrom_unresolved_substr ( TALLOC_CTX *  ctx,
tmpl_attr_error_t err,
tmpl_t vpt,
fr_dict_attr_t const *  parent,
fr_dict_attr_t const *  namespace,
fr_sbuff_t name,
tmpl_attr_rules_t const *  at_rules 
)
inlinestatic

Parse an unresolved attribute, i.e.

one which can't be found in the current dictionary

This function calls itself recursively to process additional OID components once we've failed to resolve one component.

Note
Do not call directly.
Parameters
[in]ctxto allocate new attribute reference in.
[out]errParse error.
[in,out]vptto append this reference to.
[in]parentLast known parent.
[in]namespacein which the attribute will be resolved.
[in]nameto parse.
[in]at_rulessee tmpl_attr_afrom_attr_substr.
Returns
  • <0 on error.
  • 0 on success.

Definition at line 1527 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_attr_ref_debug()

void tmpl_attr_ref_debug ( const tmpl_attr_t ar,
int  i 
)

Definition at line 191 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_attr_ref_fixup()

static void tmpl_attr_ref_fixup ( TALLOC_CTX *  ctx,
tmpl_t vpt,
fr_dict_attr_t const *  da,
fr_dict_attr_t const *  parent 
)
static

Definition at line 1603 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_attr_ref_from_unspecified_substr()

static fr_slen_t tmpl_attr_ref_from_unspecified_substr ( tmpl_attr_t ar,
tmpl_attr_error_t err,
tmpl_t vpt,
fr_sbuff_t name,
tmpl_attr_rules_t const *  at_rules 
)
inlinestatic

Definition at line 1474 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_attr_ref_list_debug()

void tmpl_attr_ref_list_debug ( FR_DLIST_HEAD(tmpl_attr_list) const *  ar_head)

Definition at line 251 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_attr_resolve()

static int tmpl_attr_resolve ( tmpl_t vpt,
tmpl_res_rules_t const *  tr_rules 
)
inlinestatic

Resolve an unresolved attribute.

Multi-pass parsing fixups for attribute references.

Parameters
[in]vptto resolve.
[in]tr_rulesCombined with the original parse rules for additional resolution passes.
Returns
  • 0 if all references were resolved.
  • -1 if there are unknown attributes which need adding to the global dictionary first.
  • -2 if there are attributes we couldn't resolve.

Definition at line 3825 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_attr_rewrite_leaf_num()

void tmpl_attr_rewrite_leaf_num ( tmpl_t vpt,
int16_t  from,
int16_t  to 
)

Rewrite the leaf's instance number.

Definition at line 1184 of file tmpl_tokenize.c.

+ Here is the caller graph for this function:

◆ tmpl_attr_rewrite_num()

void tmpl_attr_rewrite_num ( tmpl_t vpt,
int16_t  from,
int16_t  to 
)

Rewrite all instances of an array number.

Definition at line 1201 of file tmpl_tokenize.c.

◆ tmpl_attr_rules_debug()

static void tmpl_attr_rules_debug ( tmpl_attr_rules_t const *  at_rules)
static

Definition at line 5731 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_attr_set_da()

int tmpl_attr_set_da ( tmpl_t vpt,
fr_dict_attr_t const *  da 
)

Replace the current attribute reference.

Definition at line 1079 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_attr_set_leaf_da()

int tmpl_attr_set_leaf_da ( tmpl_t vpt,
fr_dict_attr_t const *  da 
)

Replace the leaf attribute only.

Definition at line 1112 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_attr_set_leaf_num()

void tmpl_attr_set_leaf_num ( tmpl_t vpt,
int16_t  num 
)

Definition at line 1164 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_attr_set_list()

void tmpl_attr_set_list ( tmpl_t vpt,
fr_dict_attr_t const *  list 
)

Definition at line 1229 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_attr_set_request_ref()

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.

Definition at line 1215 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_attr_tail_unresolved_add()

int tmpl_attr_tail_unresolved_add ( fr_dict_t dict_def,
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.

Note
fr_dict_attr_add will not return an error if the attribute already exists meaning that multiple tmpl_t specifying the same attribute can be passed to this function to be fixed up, so long as the type and flags are identical.
Parameters
[in]dict_defDefault dictionary to use if none is specified by the tmpl_attr_tail_unresolved.
[in]vptspecifying unresolved attribute to add. tmpl_attr_tail_da pointer will be updated to point to the fr_dict_attr_t inserted into the dictionary. Lists and requests will be preserved.
[in]typeto define unresolved attribute as.
[in]flagsto define unresolved attribute with.
Returns
  • 1 noop (did nothing) - Not possible to convert tmpl.
  • 0 on success.
  • -1 on failure.

Definition at line 4375 of file tmpl_tokenize.c.

+ Here is the call graph for this function:

◆ tmpl_attr_to_raw()

void tmpl_attr_to_raw ( tmpl_t vpt)

Convert the leaf attribute of a tmpl to a unknown/raw type.

Definition at line 4259 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_attr_to_xlat()

int tmpl_attr_to_xlat ( TALLOC_CTX *  ctx,
tmpl_t **  vpt_p 
)

Convert an attribute reference to an xlat expansion.

This is where a user attempts to use an attribute reference which is actually a virtual attribute.

Parameters
[in]ctxto convert new tmpl in.
[in,out]vpt_ppointer to tmpl_t of TMPL_TYPE_ATTR | TMPL_TYPE_ATTR_UNPARSED.

Definition at line 4199 of file tmpl_tokenize.c.

+ Here is the call graph for this function:

◆ tmpl_attr_unknown_add()

int tmpl_attr_unknown_add ( tmpl_t vpt)

Add an unknown fr_dict_attr_t specified by a tmpl_t to the main dictionary.

Parameters
vptto add. tmpl_attr_tail_da pointer will be updated to point to the fr_dict_attr_t inserted into the dictionary.
Returns
  • 1 noop (did nothing) - Not possible to convert tmpl.
  • 0 on success.
  • -1 on failure.

Definition at line 4273 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_cast_from_substr()

ssize_t tmpl_cast_from_substr ( tmpl_rules_t rules,
fr_sbuff_t in 
)

Parse a cast specifier.

Note that casts are

(foo)

and NOT

( foo )

Not for any particular reason, but to emphasize a bit that they're not mathematical expressions.

Parameters
[out]rulesto set the cast type in.
[in]inString containing the cast marker.
Returns
  • 0 no cast specifier found.
  • >0 the number of bytes parsed.
  • <0 offset of parse error.

Definition at line 3494 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_cast_in_place()

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 specified.

Note
Conversion is done in place.
Irrespective of whether the tmpl_t was TMPL_TYPE_DATA_UNRESOLVED or TMPL_TYPE_DATA, on successful cast it will be TMPL_TYPE_DATA.
Parameters
[in,out]vptThe template to modify. Must be of type TMPL_TYPE_DATA_UNRESOLVED or TMPL_TYPE_DATA.
[in]typeto cast to.
[in]enumvEnumerated dictionary values associated with a fr_dict_attr_t.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 3712 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_cast_quote()

static fr_token_t tmpl_cast_quote ( fr_token_t  existing_quote,
fr_type_t  type,
fr_dict_attr_t const *  enumv,
char const *  unescaped,
size_t  unescaped_len 
)
inlinestatic

Determine the correct quoting after a cast.

Parameters
[in]existing_quoteExiting quotation type.
[in]typeCast type.
[in]enumvEnumeration values.
[in]unescapedThe unescaped value of an enumeration.
[in]unescaped_lenLength of unescaped.

Definition at line 3674 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_cast_set()

int tmpl_cast_set ( tmpl_t vpt,
fr_type_t  dst_type 
)

Set a cast for a tmpl.

Parameters
[in,out]vptto set cast for.
[in]dst_typeto set.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 3543 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_copy()

tmpl_t* tmpl_copy ( TALLOC_CTX *  ctx,
tmpl_t const *  in 
)

Copy a tmpl.

Fully duplicates the contents of a tmpl including any nested attribute references.

Parameters
[in]ctxto perform allocations under.
[in]intmpl to duplicate.
Returns
  • NULL on error.
  • A new tmpl on success.

Definition at line 3413 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_debug()

void tmpl_debug ( tmpl_t const *  vpt)

Definition at line 305 of file tmpl_tokenize.c.

+ Here is the call graph for this function:

◆ tmpl_init()

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.

Parameters
[in]vptto initialise.
[in]typeof tmpl to initialise.
[in]quoteOriginal quoting around the name.
[in]nameto set for the tmpl.
[in]lenName length. If < 0 strlen will be used to determine the name.
[in]t_rulesused during parsing.
Returns
A pointer to the newly initialised tmpl.

Definition at line 898 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_init_printf()

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.

Parameters
[in]vptto initialise.
[in]typeof tmpl to initialise.
[in]quoteOriginal quoting around the name.
[in]fmtstring.
[in]...format arguments.
Returns
A pointer to the newly initialised tmpl.

Definition at line 846 of file tmpl_tokenize.c.

+ Here is the call graph for this function:

◆ tmpl_init_shallow()

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.

Note
Name is not talloc_strdup'd or memcpy'd so must be available, and must not change for the lifetime of the tmpl_t.
Parameters
[out]vptto initialise.
[in]typeto set in the tmpl_t.
[in]quoteThe type of quoting around the template name.
[in]nameof the tmpl_t.
[in]lenThe length of the buffer (or a substring of the buffer) pointed to by name. If < 0 strlen will be used to determine the length.
[in]t_rulesused during parsing.
Returns
a pointer to the initialised tmpl_t. The same value as vpt.

Definition at line 876 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_preparse()

ssize_t tmpl_preparse ( char const **  out,
size_t outlen,
char const *  in,
size_t  inlen,
fr_token_t type,
fr_dict_attr_t const **  castda,
bool  require_regex,
bool  allow_xlat 
)

Preparse a string in preparation for passing it to tmpl_afrom_substr()

Note that the input string is not modified, which means that the tmpl_afrom_substr() function MUST un-escape it.

The caller should pass 'out' and 'outlen' to tmpl_afrom_substr() as 'in' and 'inlen'. The caller should also pass 'type'. The caller should also pass do_unescape=true.

Parameters
[out]outstart of the string to parse
[out]outlenlength of the string to parse
inwhere we start looking for the string
inlenlength of the input string
[out]typetoken type of the string.
[out]castdaNULL if casting is not allowed, otherwise the cast
require_regexwhether or not to require regular expressions
allow_xlatwhether or not "bare" xlat's are allowed
Returns
  • > 0, amount of parsed string to skip, to get to the next token
  • <=0, -offset in 'start' where the parse error was located

Definition at line 5204 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_print()

fr_slen_t tmpl_print ( fr_sbuff_t out,
tmpl_t const *  vpt,
tmpl_attr_prefix_t  ar_prefix,
fr_sbuff_escape_rules_t const *  e_rules 
)

Print a tmpl_t to a string.

This function should primarily be used for regenerating vpt->name when the contents of the tmpl_t is changed programmatically, or when the tmpl_t is being serialized in some non-standard way, i.e. as a value for a field in a database.

This function is the direct counterpart to tmpl_afrom_substr.

Note
Does not print flags for regular expressions, as the quoting char is needed to separate the elements of the expression. Call regex_flags_print to write the flags values to the output buffer.
Parameters
[out]outWhere to write the presentation format tmpl_t string.
[in]vptto print.
[in]ar_prefixWhether to print the '&' at the beginning of attribute references.
  • TMPL_ATTR_REF_PREFIX_YES - always print.
  • TMPL_ATTR_REF_PREFIX_NO - never print.
  • TMPL_ATTR_REF_PREFIX_AUTO - print if the original tmpl was prefixed.
[in]e_rulesEscaping rules used to print strings.
Returns
  • >0 the number of bytes written to the out buffer.
  • 0 invalid argument.
  • <0 the number of bytes we would have needed to complete the print.

Definition at line 4686 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_print_quoted()

fr_slen_t tmpl_print_quoted ( fr_sbuff_t out,
tmpl_t const *  vpt,
tmpl_attr_prefix_t  ar_prefix 
)

Print a tmpl_t to a string with quotes.

This function should be used when the tmpl is embedded in some other construct in the server's configuration.

It adds standard quoting around tmpl's used as operands in expressions and applies the correct escaping rules.

Parameters
[out]outWhere to write the presentation format tmpl_t string.
[in]vptto print.
[in]ar_prefixWhether to print the '&' at the beginning of attribute references.
  • TMPL_ATTR_REF_PREFIX_YES - always print.
  • TMPL_ATTR_REF_PREFIX_NO - never print.
  • TMPL_ATTR_REF_PREFIX_AUTO - print if the original tmpl was prefixed.
Returns
  • >0 the number of bytes written to the out buffer.
  • 0 invalid argument.
  • <0 the number of bytes we would have needed to complete the print.

Definition at line 4768 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ TMPL_REQUEST_REF_DEF() [1/3]

TMPL_REQUEST_REF_DEF ( tmpl_request_def_current  ,
REQUEST_CURRENT   
)

Use the current request as the default.

Used as .attr.request_def = &tmpl_request_def_current;

◆ TMPL_REQUEST_REF_DEF() [2/3]

TMPL_REQUEST_REF_DEF ( tmpl_request_def_outer  ,
REQUEST_OUTER   
)

Use the outer request as the default.

Used as .attr.request_def = &tmpl_request_def_outer;

◆ TMPL_REQUEST_REF_DEF() [3/3]

TMPL_REQUEST_REF_DEF ( tmpl_request_def_parent  ,
REQUEST_PARENT   
)

Use the parent request as the default.

Used as .attr.request_def = &tmpl_request_def_parent;

◆ tmpl_request_ref_list_acopy()

static void tmpl_request_ref_list_acopy ( TALLOC_CTX *  ctx,
FR_DLIST_HEAD(tmpl_request_list) **  out,
FR_DLIST_HEAD(tmpl_request_list) const *  in 
)
inlinestatic

Allocate a new request reference list and copy request references into it.

Definition at line 442 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_request_ref_list_afrom_substr()

fr_slen_t tmpl_request_ref_list_afrom_substr ( TALLOC_CTX *  ctx,
tmpl_attr_error_t err,
FR_DLIST_HEAD(tmpl_request_list) **  out,
fr_sbuff_t in 
)

Parse one or more request references, allocing a new list and adding the references to it.

This can be used to create request ref lists for rules and for tmpls.

Parameters
[in]ctxto allocate request refs in.
[out]errIf !NULL where to write the parsing error.
[out]outThe new list.
[in]inSbuff to read request references from.
Returns
  • >= 0 the number of bytes parsed.
  • <0 negative offset for where the error occurred

Definition at line 687 of file tmpl_tokenize.c.

+ Here is the call graph for this function:

◆ tmpl_request_ref_list_cmp()

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.

Parameters
[in]afirst list. If NULL tmpl_request_def_current will be used.
[in]bsecond list. If NULL tmpl_request_def_current will be used.
Returns
  • >0 a > b
  • 0 a == b
  • <0 a < b

Definition at line 478 of file tmpl_tokenize.c.

+ Here is the caller graph for this function:

◆ tmpl_request_ref_list_copy()

static void tmpl_request_ref_list_copy ( TALLOC_CTX *  ctx,
FR_DLIST_HEAD(tmpl_request_list) *  out,
FR_DLIST_HEAD(tmpl_request_list) const *  in 
)
inlinestatic

Allocate a new request reference and add it to the end of the attribute reference list.

Definition at line 419 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_request_ref_list_debug()

void tmpl_request_ref_list_debug ( FR_DLIST_HEAD(tmpl_request_list) const *  rql)

Dump a request list to stderr.

Definition at line 458 of file tmpl_tokenize.c.

◆ tmpl_request_ref_list_from_substr()

static fr_slen_t tmpl_request_ref_list_from_substr ( TALLOC_CTX *  ctx,
tmpl_attr_error_t err,
FR_DLIST_HEAD(tmpl_request_list) *  out,
fr_sbuff_t in,
fr_sbuff_parse_rules_t const *  p_rules,
tmpl_rules_t const *  t_rules,
fr_dict_attr_t const **  namespace 
)
static

Parse one or more request references, writing the list to out.

Parameters
[in]ctxto allocate request refs in.
[out]errIf !NULL where to write the parsing error.
[in]outThe list to write to.
[in]inSbuff to read request references from.
[in]p_rulesParse rules.
[in]t_rulesDefault list and other rules.
[out]namespacethe namespace to use
Returns
  • >= 0 the number of bytes parsed.
  • <0 negative offset for where the error occurred

Definition at line 520 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_request_ref_list_print()

fr_slen_t tmpl_request_ref_list_print ( fr_sbuff_t out,
FR_DLIST_HEAD(tmpl_request_list) const *  rql 
)

Definition at line 4444 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_resolve()

int tmpl_resolve ( tmpl_t vpt,
tmpl_res_rules_t const *  tr_rules 
)

Attempt to resolve functions and attributes in xlats and attribute references.

Note
If resolution is successful, the rules->attr.dict_def field will be modified to reflect the dictionary resolution was successful in.
Parameters
[in,out]vptto resolve. Should be of type TMPL_TYPE_XLAT_UNRESOLVED or TMPL_TYPE_ATTR_UNRESOLVED. All other types will be noops.
[in]tr_rulesCombined with the original parse rules for additional resolution passes.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 4019 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_rules_child_init()

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.

Definition at line 5675 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_rules_debug()

void tmpl_rules_debug ( tmpl_rules_t const *  rules)

Definition at line 5746 of file tmpl_tokenize.c.

+ Here is the call graph for this function:

◆ tmpl_set_dict_def()

void tmpl_set_dict_def ( tmpl_t vpt,
fr_dict_t const *  dict 
)

Change the default dictionary in the tmpl's resolution rules.

Parameters
[in]vptto alter.
[in]dictto set.

Definition at line 809 of file tmpl_tokenize.c.

+ Here is the caller graph for this function:

◆ tmpl_set_escape()

void tmpl_set_escape ( tmpl_t vpt,
tmpl_escape_t const *  escape 
)

Set escape parameters for the tmpl output.

Parameters
[in]vptto alter.
[in]escapeto set.

Definition at line 819 of file tmpl_tokenize.c.

◆ tmpl_set_name()

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.

Parameters
[in]vptto set the name for.
[in]quoteOriginal quoting around the name.
[in]nameof the tmpl_t.
[in]lenThe length of the buffer (or a substring of the buffer) pointed to by name. If < 0 strlen will be used to determine the length.

Definition at line 793 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_set_name_printf()

void tmpl_set_name_printf ( tmpl_t vpt,
fr_token_t  quote,
char const *  fmt,
  ... 
)

Set the name on a pre-initialised tmpl.

Parameters
[in]vptto set the name for.
[in]quoteOriginal quoting around the name.
[in]fmtstring.
[in]...format arguments.

Definition at line 752 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_set_name_shallow()

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.

Parameters
[in]vptto set the name for.
[in]quoteOriginal quoting around the name.
[in]nameof the tmpl_t.
[in]lenThe length of the buffer (or a substring of the buffer) pointed to by name. If < 0 strlen will be used to determine the length.

Definition at line 776 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_set_xlat()

void tmpl_set_xlat ( tmpl_t vpt,
xlat_exp_head_t xlat 
)

Change the default dictionary in the tmpl's resolution rules.

Parameters
[in]vptto alter.
[in]xlatto set.

Definition at line 829 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_substr_terminal_check()

static bool tmpl_substr_terminal_check ( fr_sbuff_t in,
fr_sbuff_parse_rules_t const *  p_rules 
)
inlinestatic

Verify, after skipping whitespace, that a substring ends in a terminal char, or ends without further chars.

Parameters
[in]inthe sbuff to check.
[in]p_rulesto use terminals from.
Returns
  • true if substr is terminated correctly.
  • false if subst is not terminated correctly.

Definition at line 175 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_type_init()

static void tmpl_type_init ( tmpl_t vpt,
tmpl_type_t  type 
)
inlinestatic

Initialise fields inside a tmpl depending on its type.

Definition at line 720 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tmpl_unresolve()

void tmpl_unresolve ( tmpl_t vpt)

Reset the tmpl, leaving only the name in place.

After calling this function, the tmpl type will revert to TMPL_TYPE_DATA_UNRESOLVED and only the name and quoting will be preserved.

Parameters
[in]vptto reset.

Definition at line 4134 of file tmpl_tokenize.c.

+ Here is the call graph for this function:

◆ tmpl_xlat_resolve()

static int tmpl_xlat_resolve ( tmpl_t vpt,
tmpl_res_rules_t const *  tr_rules 
)
inlinestatic

Resolve an unresolved xlat, i.e.

one containing unresolved attribute references or xlat functions

Multi-pass parsing fixups for attribute references.

Works for base types:

  • TMPL_TYPE_XLAT
  • TMPL_TYPE_EXEC
  • TMPL_TYPE_REGEX_XLAT
Parameters
[in]vptContaining the xlat expansion to resolve.
[in]tr_rulesCombined with the original parse rules for additional resolution passes.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 3989 of file tmpl_tokenize.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ attr_num_table

fr_table_num_sorted_t const attr_num_table[]
static
Initial value:
= {
{ L("*"), NUM_ALL },
{ L("#"), NUM_COUNT },
{ L("u"), NUM_UNSPEC },
{ L("n"), NUM_LAST }
}
#define L(_str)
Helper for initialising arrays of string literals.
Definition: build.h:207
#define NUM_LAST
Definition: tmpl.h:402
#define NUM_ALL
Definition: tmpl.h:400
#define NUM_COUNT
Definition: tmpl.h:401
#define NUM_UNSPEC
Definition: tmpl.h:399

Special attribute reference indexes.

Definition at line 150 of file tmpl_tokenize.c.

◆ attr_num_table_len

size_t attr_num_table_len = NUM_ELEMENTS(attr_num_table)
static

Definition at line 156 of file tmpl_tokenize.c.

◆ attr_table

fr_table_num_ordered_t const attr_table[]
static
Initial value:
= {
{ L("normal"), TMPL_ATTR_TYPE_NORMAL },
{ L("unspecified"), TMPL_ATTR_TYPE_UNSPEC },
{ L("unknown"), TMPL_ATTR_TYPE_UNKNOWN },
{ L("unresolved"), TMPL_ATTR_TYPE_UNRESOLVED }
}
@ TMPL_ATTR_TYPE_UNSPEC
No attribute was specified as this level only a filter.
Definition: tmpl.h:387
@ TMPL_ATTR_TYPE_NORMAL
Normal, resolved, attribute ref.
Definition: tmpl.h:386
@ 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:389
@ TMPL_ATTR_TYPE_UNRESOLVED
We have a name, but nothing else to identify the attribute.
Definition: tmpl.h:394

Attr ref types.

Definition at line 130 of file tmpl_tokenize.c.

◆ attr_table_len

size_t attr_table_len = NUM_ELEMENTS(attr_table)
static

Definition at line 136 of file tmpl_tokenize.c.

◆ tmpl_attr_unspec

fr_dict_attr_t const* tmpl_attr_unspec
extern

Placeholder attribute for uses of unspecified attribute references.

Definition at line 59 of file tmpl_eval.c.

◆ tmpl_request_ref_table

fr_table_num_sorted_t const tmpl_request_ref_table[]
Initial value:
= {
{ L("current"), REQUEST_CURRENT },
{ L("outer"), REQUEST_OUTER },
{ L("parent"), REQUEST_PARENT },
}
@ 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_CURRENT
The current request (default).
Definition: tmpl.h:91

Map keywords to tmpl_request_ref_t values.

Definition at line 140 of file tmpl_tokenize.c.

◆ tmpl_request_ref_table_len

size_t tmpl_request_ref_table_len = NUM_ELEMENTS(tmpl_request_ref_table)

Definition at line 145 of file tmpl_tokenize.c.

◆ tmpl_type_table

fr_table_num_ordered_t const tmpl_type_table[]
Initial value:
= {
{ L("uninitialised"), TMPL_TYPE_UNINITIALISED },
{ L("null"), TMPL_TYPE_NULL },
{ L("data"), TMPL_TYPE_DATA },
{ L("attr"), TMPL_TYPE_ATTR },
{ L("exec"), TMPL_TYPE_EXEC },
{ L("xlat"), TMPL_TYPE_XLAT },
{ L("regex"), TMPL_TYPE_REGEX },
{ L("regex-uncompiled"), TMPL_TYPE_REGEX_UNCOMPILED },
{ L("regex-xlat"), TMPL_TYPE_REGEX_XLAT },
{ L("data-unresolved"), TMPL_TYPE_DATA_UNRESOLVED },
{ L("attr-unresolved"), TMPL_TYPE_ATTR_UNRESOLVED },
{ L("exec-unresolved"), TMPL_TYPE_EXEC_UNRESOLVED },
{ L("xlat-unresolved"), TMPL_TYPE_XLAT_UNRESOLVED },
{ L("regex-unresolved"), TMPL_TYPE_REGEX_XLAT_UNRESOLVED }
}
@ TMPL_TYPE_REGEX_UNCOMPILED
Regex where compilation is possible but hasn't been performed yet.
Definition: tmpl.h:162
@ TMPL_TYPE_ATTR_UNRESOLVED
An attribute reference that we couldn't resolve but looked valid.
Definition: tmpl.h:189
@ TMPL_TYPE_ATTR
Reference to one or more attributes.
Definition: tmpl.h:146
@ TMPL_TYPE_XLAT
Pre-parsed xlat expansion.
Definition: tmpl.h:150
@ TMPL_TYPE_NULL
Has no value.
Definition: tmpl.h:138
@ TMPL_TYPE_EXEC
Callout to an external script or program.
Definition: tmpl.h:154
@ TMPL_TYPE_REGEX_XLAT_UNRESOLVED
A regular expression with unresolved xlat functions or attribute references.
Definition: tmpl.h:201
@ TMPL_TYPE_DATA
Value in native boxed format.
Definition: tmpl.h:142
@ TMPL_TYPE_REGEX
Compiled (and possibly JIT'd) regular expression.
Definition: tmpl.h:158
@ TMPL_TYPE_DATA_UNRESOLVED
Unparsed literal string.
Definition: tmpl.h:183
@ TMPL_TYPE_XLAT_UNRESOLVED
A xlat expansion with unresolved xlat functions or attribute references.
Definition: tmpl.h:197
@ TMPL_TYPE_REGEX_XLAT
A regex containing xlat expansions.
Definition: tmpl.h:166
@ TMPL_TYPE_EXEC_UNRESOLVED
An exec with unresolved xlat function or attribute references.
Definition: tmpl.h:193
@ TMPL_TYPE_UNINITIALISED
Uninitialised.
Definition: tmpl.h:134

Map tmpl_type_t values to descriptive strings.

Definition at line 105 of file tmpl_tokenize.c.

◆ tmpl_type_table_len

size_t tmpl_type_table_len = NUM_ELEMENTS(tmpl_type_table)

Definition at line 126 of file tmpl_tokenize.c.