The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Functions
pair_tokenize.c File Reference

AVP parsing. More...

#include <freeradius-devel/util/misc.h>
#include <freeradius-devel/util/pair.h>
#include <freeradius-devel/util/proto.h>
#include <freeradius-devel/util/regex.h>
#include <freeradius-devel/protocol/radius/rfc2865.h>
#include <freeradius-devel/protocol/freeradius/freeradius.internal.h>
+ Include dependency graph for pair_tokenize.c:

Go to the source code of this file.

Functions

static fr_pair_tfr_pair_afrom_fields (TALLOC_CTX *ctx, fr_dict_attr_t const *da, fr_token_t op, char const *value, size_t value_len, fr_sbuff_unescape_rules_t const *uerules)
 Allocate a fr_pair_t based on pre-parsed fields. More...
 
static ssize_t fr_pair_afrom_str (fr_pair_ctx_t *pair_ctx, char const *start, char const *in, size_t inlen)
 Allocate one fr_pair_t from a string, and add it to the pair_ctx cursor. More...
 
ssize_t fr_pair_ctx_afrom_str (fr_pair_ctx_t *pair_ctx, char const *in, size_t inlen)
 Parse a pair context from a string. More...
 
void fr_pair_ctx_reset (fr_pair_ctx_t *pair_ctx, fr_dict_t const *dict)
 Reset a pair_ctx to the dictionary root. More...
 
static ssize_t fr_pair_ctx_set (fr_pair_ctx_t *pair_ctx, char const *in, size_t inlen)
 Set a new DA context based on the input string. More...
 
static ssize_t op_to_token (fr_token_t *token, char const *op, size_t oplen)
 

Detailed Description

AVP parsing.

Definition in file pair_tokenize.c.

Function Documentation

◆ fr_pair_afrom_fields()

static fr_pair_t* fr_pair_afrom_fields ( TALLOC_CTX *  ctx,
fr_dict_attr_t const *  da,
fr_token_t  op,
char const *  value,
size_t  value_len,
fr_sbuff_unescape_rules_t const *  uerules 
)
static

Allocate a fr_pair_t based on pre-parsed fields.

Parameters
ctxthe talloc ctx
dathe da for the vp
opthe operator
valuethe value to parse
value_lenlength of the value string
uerulesused for unescaping.
Returns
  • fr_pair_t* on success
  • NULL on error

It's just better for this function to take the broken-out / pre-parsed fields. That way the caller can do any necessary parsing.

Definition at line 144 of file pair_tokenize.c.

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

◆ fr_pair_afrom_str()

static ssize_t fr_pair_afrom_str ( fr_pair_ctx_t pair_ctx,
char const *  start,
char const *  in,
size_t  inlen 
)
static

Allocate one fr_pair_t from a string, and add it to the pair_ctx cursor.

Parameters
[in,out]pair_ctxthe parsing context
[in]startWhere to create relative error offsets in relation to.
inString to parse
inlenlength of string to parse
Returns
  • <= 0 on error (offset as negative integer)
  • > 0 on success (number of bytes parsed).

Definition at line 177 of file pair_tokenize.c.

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

◆ fr_pair_ctx_afrom_str()

ssize_t fr_pair_ctx_afrom_str ( fr_pair_ctx_t pair_ctx,
char const *  in,
size_t  inlen 
)

Parse a pair context from a string.

Parameters
pair_ctxthe parsing context
inString to parse
inlenlength of string to parse
Returns
  • <= 0 on error (offset as negative integer)
  • > 0 on success (number of bytes parsed).

This function will parse fr_pair_ts, or context changes, up to end of string, or a trailing ','. The caller is responsible for parsing the comma.

It accepts the following syntax:

  • Attribute = value
    • reset to a new top-level context according to the parent of Attribute
    • parse the attribute and the value
  • .Attribute = value
    • parse the attribute and the value in the CURRENT top-level context
  • .Attribute
    • reset to a new context according to Attribute, relative to the current context
  • ..Attribute
    • reset to a new context according to Attribute, relative to the current context
    • more '.' will walk back up the context tree.
  • Attribute
    • reset to a new top-level context according to Attribute

Definition at line 375 of file pair_tokenize.c.

+ Here is the call 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.

Parameters
pair_ctxthe parsing context
dictthe dictionary to reset to the root

This function is used in order to reset contexts when parsing strings that change attribute lists. i.e. &request.foo, &reply.bar

This function is simple for now, but will get complex once we start using vp->vp_children

Definition at line 495 of file pair_tokenize.c.

+ Here is the call graph for this function:

◆ fr_pair_ctx_set()

static ssize_t fr_pair_ctx_set ( fr_pair_ctx_t pair_ctx,
char const *  in,
size_t  inlen 
)
static

Set a new DA context based on the input string.

Parameters
[in,out]pair_ctxthe parsing context
[in]inString to parse
[in]inlenlength of string to parse
Returns
  • <= 0 on error (offset as negative integer)
  • > 0 on success (number of bytes parsed).

pair_ctx->da is set to the new parsing context.

Todo:
  • allow for child contexts, so that we can parse TLVs into vp->vp_children. This change requires nested cursors, but not necessarily nested contexts. We probably want to have a fr_dlist_t of pair_ctx, and we always operate on the last one. When we change contexts to an attributes parent, we also change pair_ctx to a parent context. This is like the da stack, but with child cursors, too.

We also want to emulate the previous behavior of group attributes based on parent, and increasing child_num. i.e. if we're parsing a series of "attr-foo = bar", then we watch the parent context, and create a new parent VP if this child has a SMALLER attribute number than the previous child. This allows the previous configurations to "just work".

Definition at line 291 of file pair_tokenize.c.

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

◆ op_to_token()

static ssize_t op_to_token ( fr_token_t token,
char const *  op,
size_t  oplen 
)
static

Definition at line 34 of file pair_tokenize.c.

+ Here is the caller graph for this function: