The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
Loading...
Searching...
No Matches
Functions | Variables
pair_tokenize.c File Reference

Parse attribute value pairs from text. More...

#include <freeradius-devel/util/pair.h>
#include <freeradius-devel/util/value.h>
+ Include dependency graph for pair_tokenize.c:

Go to the source code of this file.

Functions

fr_slen_t fr_pair_ctx_afrom_substr (fr_pair_ctx_t *pair_ctx, fr_sbuff_t *in)
 Parse one pair, or one context change, from a string.
 
void fr_pair_ctx_reset (fr_pair_ctx_t *pair_ctx, fr_dict_t const *dict)
 Reset a pair_ctx to the dictionary root.
 
static fr_slen_t pair_afrom_substr (fr_pair_ctx_t *pair_ctx, fr_sbuff_t *in)
 Parse Attribute op value and append the pair to pair_ctx->list.
 
static fr_slen_t pair_ctx_set_from_substr (fr_pair_ctx_t *pair_ctx, fr_sbuff_t *in)
 Set a new parent from a dotted attribute reference.
 

Variables

fr_table_num_sorted_t const fr_pair_comparison_op_table []
 Operators that may appear between an attribute name and a value.
 
size_t fr_pair_comparison_op_table_len = NUM_ELEMENTS(fr_pair_comparison_op_table)
 
static fr_sbuff_parse_rules_t const pair_value_bareword_rules
 A bare word value ends at whitespace or at the comma before the next pair.
 

Detailed Description

Parse attribute value pairs from text.

Definition in file pair_tokenize.c.

Function Documentation

◆ fr_pair_ctx_afrom_substr()

fr_slen_t fr_pair_ctx_afrom_substr ( fr_pair_ctx_t *  pair_ctx,
fr_sbuff_t *  in 
)

Parse one pair, or one context change, from a string.

The function stops at the end of the input or at a comma. The comma remains in the buffer for the caller.

The syntax is:

  • Attribute = value The function resets the context to the parent of Attribute, a top level attribute, then parses the attribute and the value.
  • Attribute The function resets the context to Attribute, a top level structural attribute (a group, a TLV, or a struct).
  • Attribute.Child The function resets the context to Child, where each component is a structural attribute and a direct child of the component before.
  • .Attribute = value, .Attribute and .Attribute.Child As above, with the lookup starting at the current context.
  • ..Attribute = value, ..Attribute and ..Attribute.Child As above, with the lookup starting at the parent of the current context. Each further '.' starts one level further up, and a reference of dots alone only moves the context up.
Parameters
[in,out]pair_ctxthe parsing context.
[in,out]into parse. Advanced past what was parsed on success.
Returns
  • >=0 the number of bytes parsed.
  • <0 the negative offset of the error.

Definition at line 228 of file pair_tokenize.c.

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

◆ fr_pair_ctx_reset()

void fr_pair_ctx_reset ( fr_pair_ctx_t *  pair_ctx,
fr_dict_t const *  dict 
)

Reset a pair_ctx to the dictionary root.

Callers reset the context when the parsed text switches to a different attribute list, for example from request.foo to reply.bar.

The function will need to reset child contexts once pairs store children in vp->vp_children.

Parameters
[in,out]pair_ctxthe parsing context.
[in]dictwhose root becomes the parent.

Definition at line 320 of file pair_tokenize.c.

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

◆ pair_afrom_substr()

static fr_slen_t pair_afrom_substr ( fr_pair_ctx_t *  pair_ctx,
fr_sbuff_t *  in 
)
static

Parse Attribute op value and append the pair to pair_ctx->list.

The function looks the attribute name up under pair_ctx->parent, and the attribute must be a direct child of pair_ctx->parent.

Parameters
[in,out]pair_ctxthe parsing context.
[in,out]into parse. Advanced past the value on success.
Returns
  • >0 the number of bytes parsed.
  • <0 the negative offset of the error.

Definition at line 73 of file pair_tokenize.c.

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

◆ pair_ctx_set_from_substr()

static fr_slen_t pair_ctx_set_from_substr ( fr_pair_ctx_t *  pair_ctx,
fr_sbuff_t *  in 
)
static

Set a new parent from a dotted attribute reference.

The first component must be a direct child of pair_ctx->parent, and each later component must be a direct child of the component before. The last component becomes the new pair_ctx->parent. The function stops at the end of the input or at a comma. The comma remains in the buffer for the caller.

Parameters
[in,out]pair_ctxthe parsing context.
[in,out]into parse. Advanced past the reference on success.
Returns
  • >0 the number of bytes parsed.
  • <0 the negative offset of the error.
Todo:
  • allow for child contexts, so that the parser can parse TLVs into vp->vp_children. The change requires nested cursors, but not necessarily nested contexts. One design is a fr_dlist_t of pair_ctx, where the parser always operates on the last pair_ctx in the list. When the context changes to the parent of an attribute, pair_ctx also changes to a parent context. The list resembles the da stack, but with child cursors as well.

The parser also needs to emulate the previous behavior of group attributes, based on the parent and an increasing child_num. When the parser reads a series of "attr-foo = bar" pairs, the parser watches the parent context, and creates a new parent VP when a child has a SMALLER attribute number than the previous child. Emulating the previous behavior keeps existing configurations working.

Definition at line 165 of file pair_tokenize.c.

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

Variable Documentation

◆ fr_pair_comparison_op_table

fr_table_num_sorted_t const fr_pair_comparison_op_table[]
Initial value:
= {
{ L("!*"), T_OP_CMP_FALSE },
{ L("!="), T_OP_NE },
{ L("!~"), T_OP_REG_NE },
{ L("+="), T_OP_ADD_EQ },
{ L(":="), T_OP_SET },
{ L("<"), T_OP_LT },
{ L("<="), T_OP_LE },
{ L("="), T_OP_EQ },
{ L("=*"), T_OP_CMP_TRUE },
{ L("=="), T_OP_CMP_EQ },
{ L("=~"), T_OP_REG_EQ },
{ L(">"), T_OP_GT },
{ L(">="), T_OP_GE }
}
#define L(_str)
Helper for initialising arrays of string literals.
Definition build.h:245
@ T_OP_CMP_TRUE
Definition token.h:102
@ T_OP_EQ
Definition token.h:81
@ T_OP_SET
Definition token.h:82
@ T_OP_NE
Definition token.h:95
@ T_OP_ADD_EQ
Definition token.h:67
@ T_OP_CMP_FALSE
Definition token.h:103
@ T_OP_REG_EQ
Definition token.h:100
@ T_OP_CMP_EQ
Definition token.h:104
@ T_OP_LE
Definition token.h:98
@ T_OP_GE
Definition token.h:96
@ T_OP_GT
Definition token.h:97
@ T_OP_LT
Definition token.h:99
@ T_OP_REG_NE
Definition token.h:101

Operators that may appear between an attribute name and a value.

fr_table_num_sorted_t requires the entries in sorted order, so keep the entries sorted.

Definition at line 32 of file pair_tokenize.c.

◆ fr_pair_comparison_op_table_len

size_t fr_pair_comparison_op_table_len = NUM_ELEMENTS(fr_pair_comparison_op_table)

Definition at line 47 of file pair_tokenize.c.

◆ pair_value_bareword_rules

fr_sbuff_parse_rules_t const pair_value_bareword_rules
static
Initial value:
= {
.terminals = &FR_SBUFF_TERMS(
L("\t"),
L("\n"),
L("\r"),
L(" "),
L(",")
)
}
#define FR_SBUFF_TERMS(...)
Initialise a terminal structure with a list of sorted strings.
Definition sbuff.h:191

A bare word value ends at whitespace or at the comma before the next pair.

Definition at line 52 of file pair_tokenize.c.