The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
Macros | Functions | Variables
xlat_tokenize.c File Reference

String expansion ("translation"). More...

#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/event.h>
#include <freeradius-devel/util/sbuff.h>
#include <freeradius-devel/util/value.h>
#include <freeradius-devel/server/regex.h>
#include <freeradius-devel/unlang/xlat_priv.h>
+ Include dependency graph for xlat_tokenize.c:

Go to the source code of this file.

Macros

#define INFO_INDENT(_fmt, ...)   INFO("%*s"_fmt, depth * 2, " ", ## __VA_ARGS__)
 
#define XLAT_DEBUG(...)
 
#define XLAT_HEXDUMP(...)
 

Functions

static void _xlat_debug_head (xlat_exp_head_t const *head, int depth)
 
static void _xlat_debug_node (xlat_exp_t const *node, int depth, bool print_flags)
 
fr_type_t xlat_data_type (xlat_exp_head_t const *head)
 
void xlat_debug (xlat_exp_t const *node)
 
void xlat_debug_head (xlat_exp_head_t const *head)
 
bool xlat_impure_func (xlat_exp_head_t const *head)
 
bool xlat_is_literal (xlat_exp_head_t const *head)
 Check to see if the expansion consists entirely of value-box elements.
 
bool xlat_needs_resolving (xlat_exp_head_t const *head)
 Check to see if the expansion needs resolving.
 
ssize_t xlat_print (fr_sbuff_t *out, xlat_exp_head_t const *head, fr_sbuff_escape_rules_t const *e_rules)
 Reconstitute an xlat expression from its constituent nodes.
 
ssize_t xlat_print_node (fr_sbuff_t *out, xlat_exp_head_t const *head, xlat_exp_t const *node, fr_sbuff_escape_rules_t const *e_rules, char c)
 
int xlat_resolve (xlat_exp_head_t *head, xlat_res_rules_t const *xr_rules)
 Walk over an xlat tree recursively, resolving any unresolved functions or references.
 
static int xlat_tmpl_normalize (xlat_exp_t *node)
 Normalize an xlat which contains a tmpl.
 
bool xlat_to_string (TALLOC_CTX *ctx, char **str, xlat_exp_head_t **head)
 Convert an xlat node to an unescaped literal string and free the original node.
 
tmpl_txlat_to_tmpl_attr (TALLOC_CTX *ctx, xlat_exp_head_t *head)
 Try to convert an xlat to a tmpl for efficiency.
 
fr_slen_t xlat_tokenize (TALLOC_CTX *ctx, xlat_exp_head_t **out, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules)
 Tokenize an xlat expansion.
 
fr_slen_t xlat_tokenize_argv (TALLOC_CTX *ctx, xlat_exp_head_t **out, fr_sbuff_t *in, xlat_t const *xlat, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules, bool spaces)
 Tokenize an xlat expansion into a series of XLAT_TYPE_CHILD arguments.
 
static ssize_t xlat_tokenize_attribute (xlat_exp_head_t *head, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules)
 Parse an attribute ref or a virtual attribute.
 
static int xlat_tokenize_expansion (xlat_exp_head_t *head, fr_sbuff_t *in, tmpl_rules_t const *t_rules)
 
static int xlat_tokenize_function_args (xlat_exp_head_t *head, fr_sbuff_t *in, tmpl_rules_t const *t_rules)
 Parse an xlat function and its child argument.
 
static ssize_t xlat_tokenize_input (xlat_exp_head_t *head, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules)
 Parse an xlat string i.e.
 
fr_slen_t xlat_tokenize_word (TALLOC_CTX *ctx, xlat_exp_t **out, fr_sbuff_t *in, fr_token_t quote, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules)
 
static int xlat_validate_function_arg (xlat_arg_parser_t const *arg_p, xlat_exp_t *arg, int argc)
 
int xlat_validate_function_args (xlat_exp_t *node)
 

Variables

static bool const tmpl_attr_allowed_chars [UINT8_MAX+1]
 
static fr_sbuff_escape_rules_t const xlat_escape
 These rules apply to literal values and function arguments inside of an expansion.
 
bool const xlat_func_chars [UINT8_MAX+1]
 
static fr_sbuff_parse_rules_t const xlat_function_arg_rules
 Parse rules for literal values inside of an expansion.
 
static fr_table_num_sorted_t const xlat_quote_table []
 
static size_t xlat_quote_table_len = NUM_ELEMENTS(xlat_quote_table)
 
static fr_sbuff_unescape_rules_t const xlat_unescape
 These rules apply to literal values and function arguments inside of an expansion.
 

Detailed Description

String expansion ("translation").

Id
2699e0106b9345dfdbfda0faa146ddc89f92e873

Tokenizes xlat expansion strings.

Definition in file xlat_tokenize.c.

Macro Definition Documentation

◆ INFO_INDENT

#define INFO_INDENT (   _fmt,
  ... 
)    INFO("%*s"_fmt, depth * 2, " ", ## __VA_ARGS__)

Definition at line 917 of file xlat_tokenize.c.

◆ XLAT_DEBUG

#define XLAT_DEBUG (   ...)

Definition at line 44 of file xlat_tokenize.c.

◆ XLAT_HEXDUMP

#define XLAT_HEXDUMP (   ...)

Definition at line 45 of file xlat_tokenize.c.

Function Documentation

◆ _xlat_debug_head()

static void _xlat_debug_head ( xlat_exp_head_t const *  head,
int  depth 
)
static

Definition at line 1042 of file xlat_tokenize.c.

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

◆ _xlat_debug_node()

static void _xlat_debug_node ( xlat_exp_t const *  node,
int  depth,
bool  print_flags 
)
static

Definition at line 920 of file xlat_tokenize.c.

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

◆ xlat_data_type()

fr_type_t xlat_data_type ( xlat_exp_head_t const *  head)

Definition at line 2063 of file xlat_tokenize.c.

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

◆ xlat_debug()

void xlat_debug ( xlat_exp_t const *  node)

Definition at line 1037 of file xlat_tokenize.c.

+ Here is the call graph for this function:

◆ xlat_debug_head()

void xlat_debug_head ( xlat_exp_head_t const *  head)

Definition at line 1069 of file xlat_tokenize.c.

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

◆ xlat_impure_func()

bool xlat_impure_func ( xlat_exp_head_t const *  head)

Definition at line 2053 of file xlat_tokenize.c.

+ Here is the caller graph for this function:

◆ xlat_is_literal()

bool xlat_is_literal ( xlat_exp_head_t const *  head)

Check to see if the expansion consists entirely of value-box elements.

Parameters
[in]headto check.
Returns
  • true if expansion contains only literal elements.
  • false if expansion contains expandable elements.

Definition at line 1835 of file xlat_tokenize.c.

+ Here is the caller graph for this function:

◆ xlat_needs_resolving()

bool xlat_needs_resolving ( xlat_exp_head_t const *  head)

Check to see if the expansion needs resolving.

Parameters
[in]headto check.
Returns
  • true if expansion needs resolving
  • false otherwise

Definition at line 1851 of file xlat_tokenize.c.

+ Here is the caller graph for this function:

◆ xlat_print()

ssize_t xlat_print ( fr_sbuff_t out,
xlat_exp_head_t const *  head,
fr_sbuff_escape_rules_t const *  e_rules 
)

Reconstitute an xlat expression from its constituent nodes.

Parameters
[in]outWhere to write the output string.
[in]headFirst node to print.
[in]e_rulesSpecifying how to escape literal values.

Definition at line 1272 of file xlat_tokenize.c.

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

◆ xlat_print_node()

ssize_t xlat_print_node ( fr_sbuff_t out,
xlat_exp_head_t const *  head,
xlat_exp_t const *  node,
fr_sbuff_escape_rules_t const *  e_rules,
char  c 
)

Definition at line 1074 of file xlat_tokenize.c.

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

◆ xlat_resolve()

int xlat_resolve ( xlat_exp_head_t head,
xlat_res_rules_t const *  xr_rules 
)

Walk over an xlat tree recursively, resolving any unresolved functions or references.

Parameters
[in,out]headof xlat tree to resolve.
[in]xr_rulesSpecifies rules to use for resolution passes after initial tokenization.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 1906 of file xlat_tokenize.c.

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

◆ xlat_tmpl_normalize()

static int xlat_tmpl_normalize ( xlat_exp_t node)
static

Normalize an xlat which contains a tmpl.

Constant data is turned into XLAT_BOX, and some other thingies are done.

Definition at line 164 of file xlat_tokenize.c.

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

◆ xlat_to_string()

bool xlat_to_string ( TALLOC_CTX *  ctx,
char **  str,
xlat_exp_head_t **  head 
)

Convert an xlat node to an unescaped literal string and free the original node.

This is really "unparse the xlat nodes, and convert back to their original string".

Parameters
[in]ctxto allocate the new string in.
[out]stra duplicate of the node's fmt string.
[in,out]headto convert.
Returns
  • true the tree consists of a single value node which was converted.
  • false the tree was more complex than a single literal, op was a noop.

Definition at line 1867 of file xlat_tokenize.c.

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

◆ xlat_to_tmpl_attr()

tmpl_t * xlat_to_tmpl_attr ( TALLOC_CTX *  ctx,
xlat_exp_head_t head 
)

Try to convert an xlat to a tmpl for efficiency.

Parameters
ctxto allocate new tmpl_t in.
headto convert.
Returns
  • NULL if unable to convert (not necessarily error).
  • A new tmpl_t.

Definition at line 2030 of file xlat_tokenize.c.

+ Here is the call graph for this function:

◆ xlat_tokenize()

fr_slen_t xlat_tokenize ( TALLOC_CTX *  ctx,
xlat_exp_head_t **  out,
fr_sbuff_t in,
fr_sbuff_parse_rules_t const *  p_rules,
tmpl_rules_t const *  t_rules 
)

Tokenize an xlat expansion.

Parameters
[in]ctxto allocate dynamic buffers in.
[out]outthe head of the xlat list / tree structure.
[in]inthe format string to expand.
[in]p_rulescontrolling how the string containing the xlat expansions should be parsed.
[in]t_rulescontrolling how attribute references are parsed.
Returns
  • >0 on success.
  • 0 and *head == NULL - Parse failure on first char.
  • 0 and *head != NULL - Zero length expansion
  • < 0 the negative offset of the parse failure.

Definition at line 1799 of file xlat_tokenize.c.

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

◆ xlat_tokenize_argv()

fr_slen_t xlat_tokenize_argv ( TALLOC_CTX *  ctx,
xlat_exp_head_t **  out,
fr_sbuff_t in,
xlat_t const *  xlat,
fr_sbuff_parse_rules_t const *  p_rules,
tmpl_rules_t const *  t_rules,
bool  spaces 
)

Tokenize an xlat expansion into a series of XLAT_TYPE_CHILD arguments.

Parameters
[in]ctxto allocate nodes in. Note: All nodes will be allocated in the same ctx. This is to allow manipulation by xlat instantiation functions later.
[out]outthe head of the xlat list / tree structure.
[in]inthe format string to expand.
[in]xlatwe're tokenizing arguments for.
[in]p_rulescontrolling how to parse the string outside of any expansions.
[in]t_rulescontrolling how attribute references are parsed.
[in]spaceswhether the arguments are delimited by spaces
Returns
  • < 0 on error.
  • >0 on success which is the number of characters parsed.

Definition at line 1553 of file xlat_tokenize.c.

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

◆ xlat_tokenize_attribute()

static ssize_t xlat_tokenize_attribute ( xlat_exp_head_t head,
fr_sbuff_t in,
fr_sbuff_parse_rules_t const *  p_rules,
tmpl_rules_t const *  t_rules 
)
static

Parse an attribute ref or a virtual attribute.

Definition at line 498 of file xlat_tokenize.c.

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

◆ xlat_tokenize_expansion()

static int xlat_tokenize_expansion ( xlat_exp_head_t head,
fr_sbuff_t in,
tmpl_rules_t const *  t_rules 
)
static

Definition at line 574 of file xlat_tokenize.c.

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

◆ xlat_tokenize_function_args()

static int xlat_tokenize_function_args ( xlat_exp_head_t head,
fr_sbuff_t in,
tmpl_rules_t const *  t_rules 
)
static

Parse an xlat function and its child argument.

Parses a function call string in the format

%<func>(<argument>) 
Returns
  • 0 if the string was parsed into a function.
  • <0 on parse error.

Definition at line 359 of file xlat_tokenize.c.

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

◆ xlat_tokenize_input()

static ssize_t xlat_tokenize_input ( xlat_exp_head_t head,
fr_sbuff_t in,
fr_sbuff_parse_rules_t const *  p_rules,
tmpl_rules_t const *  t_rules 
)
static

Parse an xlat string i.e.

a non-expansion or non-function

When this function is being used outside of an xlat expansion, i.e. on a string which contains one or more xlat expansions, it uses the terminal grammar and escaping rules of that string type.

Which this function is being used inside of an xlat expansion, it uses xlat specific terminal grammar and escaping rules.

This allows us to be smart about processing quotes within the expansions themselves.

Parameters
[out]headto allocate nodes in, and where to write the first child, and where the flags are stored.
[in]insbuff to parse.
[in]p_rulesthat control parsing.
[in]t_rulesthat control attribute reference and xlat function parsing.
Returns
  • <0 on failure
  • >=0 for number of bytes parsed

Definition at line 775 of file xlat_tokenize.c.

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

◆ xlat_tokenize_word()

fr_slen_t xlat_tokenize_word ( TALLOC_CTX *  ctx,
xlat_exp_t **  out,
fr_sbuff_t in,
fr_token_t  quote,
fr_sbuff_parse_rules_t const *  p_rules,
tmpl_rules_t const *  t_rules 
)

Definition at line 1318 of file xlat_tokenize.c.

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

◆ xlat_validate_function_arg()

static int xlat_validate_function_arg ( xlat_arg_parser_t const *  arg_p,
xlat_exp_t arg,
int  argc 
)
static

Definition at line 217 of file xlat_tokenize.c.

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

◆ xlat_validate_function_args()

int xlat_validate_function_args ( xlat_exp_t node)

Definition at line 290 of file xlat_tokenize.c.

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

Variable Documentation

◆ tmpl_attr_allowed_chars

bool const tmpl_attr_allowed_chars[UINT8_MAX+1]
static
Initial value:
= {
['-'] = true, ['/'] = true, ['_'] = true,
['.'] = true, ['*'] = true, ['#'] = true,
['['] = true, [']'] = true,
}
#define SBUFF_CHAR_CLASS_ALPHA_NUM

Definition at line 567 of file xlat_tokenize.c.

◆ xlat_escape

fr_sbuff_escape_rules_t const xlat_escape
static
Initial value:
= {
.name = "xlat",
.chr = '\\',
.subs = {
['\a'] = 'a',
['\b'] = 'b',
['\n'] = 'n',
['\r'] = 'r',
['\t'] = 't',
['\v'] = 'v',
['\\'] = '\\',
['%'] = '%',
['}'] = '}'
},
.esc = {
},
.do_utf8 = true,
.do_oct = true
}
#define SBUFF_CHAR_UNPRINTABLES_EXTENDED
#define SBUFF_CHAR_UNPRINTABLES_LOW

These rules apply to literal values and function arguments inside of an expansion.

Definition at line 73 of file xlat_tokenize.c.

◆ xlat_func_chars

bool const xlat_func_chars[UINT8_MAX+1]
Initial value:
= {
['.'] = true, ['-'] = true, ['_'] = true,
}

Definition at line 154 of file xlat_tokenize.c.

◆ xlat_function_arg_rules

fr_sbuff_parse_rules_t const xlat_function_arg_rules
static
Initial value:
= {
.escapes = &xlat_unescape,
.terminals = &FR_SBUFF_TERMS(
L(")"),
L(","),
),
}
#define L(_str)
Helper for initialising arrays of string literals.
Definition build.h:209
#define FR_SBUFF_TERMS(...)
Initialise a terminal structure with a list of sorted strings.
Definition sbuff.h:192
static fr_sbuff_unescape_rules_t const xlat_unescape
These rules apply to literal values and function arguments inside of an expansion.

Parse rules for literal values inside of an expansion.

These rules are used to parse literals as arguments to functions.

The caller sets the literal parse rules for outside of expansions when they call xlat_tokenize.

Definition at line 102 of file xlat_tokenize.c.

◆ xlat_quote_table

fr_table_num_sorted_t const xlat_quote_table[]
static
Initial value:
= {
}
@ T_SINGLE_QUOTED_STRING
Definition token.h:122
@ T_BACK_QUOTED_STRING
Definition token.h:123
@ T_DOUBLE_QUOTED_STRING
Definition token.h:121

Definition at line 910 of file xlat_tokenize.c.

◆ xlat_quote_table_len

size_t xlat_quote_table_len = NUM_ELEMENTS(xlat_quote_table)
static

Definition at line 915 of file xlat_tokenize.c.

◆ xlat_unescape

fr_sbuff_unescape_rules_t const xlat_unescape
static
Initial value:
= {
.name = "xlat",
.chr = '\\',
.subs = {
['a'] = '\a',
['b'] = '\b',
['e'] = '\\',
['n'] = '\n',
['r'] = '\r',
['t'] = '\t',
['v'] = '\v',
['\\'] = '\\',
['%'] = '%',
['}'] = '}'
},
.do_hex = true,
.do_oct = true
}

These rules apply to literal values and function arguments inside of an expansion.

Definition at line 51 of file xlat_tokenize.c.