The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
jpath.c File Reference

Implements the evaluation and parsing functions for the FreeRADIUS version of jpath. More...

#include <freeradius-devel/util/debug.h>
#include "base.h"
+ Include dependency graph for jpath.c:

Go to the source code of this file.

Data Structures

struct  fr_jpath_node
 Node in a jpath selector sequence. More...
 
struct  jpath_expr_t
 A jpath expression for performing complex comparisons against field values. More...
 
union  jpath_operand_t
 Operand in a jpath expression. More...
 
struct  jpath_selector
 
union  jpath_selector.__unnamed39__
 

Macros

#define NODE_NEW(_node)
 
#define SELECTOR_INDEX_UNSET   INT32_MAX
 

Typedefs

typedef struct jpath_selector jpath_selector_t
 Selects a subset of JSON child nodes. More...
 

Enumerations

enum  jpath_operand_type {
  JPATH_OPERAND_LITERAL = 0 ,
  JPATH_OPERAND_JPATH
}
 
enum  jpath_type_t {
  JPATH_SELECTOR_INVALID = 0 ,
  JPATH_SELECTOR_ROOT ,
  JPATH_SELECTOR_CURRENT ,
  JPATH_SELECTOR_WILDCARD ,
  JPATH_SELECTOR_FIELD ,
  JPATH_SELECTOR_INDEX ,
  JPATH_SELECTOR_SLICE ,
  JPATH_SELECTOR_FILTER_EXPRESSION ,
  JPATH_SELECTOR_EXPRESSION ,
  JPATH_SELECTOR_RECURSIVE_DESCENT
}
 

Functions

char * fr_jpath_asprint (TALLOC_CTX *ctx, fr_jpath_node_t const *head)
 Print a node list to a string for debugging. More...
 
ssize_t fr_jpath_escape_func (UNUSED request_t *request, char *out, size_t outlen, char const *in, UNUSED void *arg)
 Escapes special chars. More...
 
int fr_jpath_evaluate_leaf (TALLOC_CTX *ctx, fr_value_box_list_t *out, fr_type_t dst_type, fr_dict_attr_t const *dst_enumv, json_object *root, fr_jpath_node_t const *jpath)
 Evaluate a parsed jpath expression against a json-c tree. More...
 
ssize_t fr_jpath_parse (TALLOC_CTX *ctx, fr_jpath_node_t **head, char const *in, size_t inlen)
 Parse a jpath string. More...
 
static ssize_t jpath_array_parse (jpath_selector_t *selector, char const *in, size_t inlen)
 Parse index/slice notation. More...
 
static int jpath_evaluate (TALLOC_CTX *ctx, fr_value_box_list_t *tail, fr_type_t dst_type, fr_dict_attr_t const *dst_enumv, json_object *object, fr_jpath_node_t const *jpath)
 Recursive function for jpath_expr_evaluate. More...
 
static ssize_t jpath_expr_parse (UNUSED jpath_selector_t *selector, UNUSED char const *in, UNUSED size_t inlen)
 Parse a jpath expression. More...
 
static size_t jpath_field_parse (fr_jpath_node_t *node, char const *in, size_t inlen)
 Parse a jpath field. More...
 
static ssize_t jpath_filter_expr_parse (UNUSED jpath_selector_t *selector, UNUSED char const *in, UNUSED size_t inlen)
 Parse a jpath filter expression, which in our case, is a FreeRADIUS condition. More...
 
static size_t jpath_selector_parse (fr_jpath_node_t *node, char const *in, size_t inlen)
 parse a jpath selector More...
 

Variables

static char const escape_chars [] = "[],*.:()?"
 

Detailed Description

Implements the evaluation and parsing functions for the FreeRADIUS version of jpath.

Id
a69f0df3752c77e8952ce2c514a98ecfc5961a4d
Author
Arran Cudbard-Bell

Definition in file jpath.c.


Data Structure Documentation

◆ fr_jpath_node

struct fr_jpath_node

Node in a jpath selector sequence.

Definition at line 87 of file jpath.c.

+ Collaboration diagram for fr_jpath_node:
Data Fields
fr_jpath_node_t * next Next in the jpath chain.
jpath_selector_t * selector Jpath selector head (there may be multiple).

◆ jpath_expr_t

struct jpath_expr_t

A jpath expression for performing complex comparisons against field values.

Definition at line 63 of file jpath.c.

+ Collaboration diagram for jpath_expr_t:
Data Fields
jpath_operand_t lhs LHS value.
jpath_operand_t rhs RHS value.

◆ jpath_operand_t

union jpath_operand_t

Operand in a jpath expression.

Definition at line 55 of file jpath.c.

+ Collaboration diagram for jpath_operand_t:
Data Fields
fr_jpath_node_t * jpath Operand is a jpath expression.
char const * literal Operand is a literal (value)

◆ jpath_selector

struct jpath_selector

Definition at line 73 of file jpath.c.

+ Collaboration diagram for jpath_selector:
Data Fields
union jpath_selector __unnamed__
jpath_selector_t * next
jpath_type_t type Type of the Jpath node.

◆ jpath_selector.__unnamed39__

union jpath_selector.__unnamed39__

Definition at line 74 of file jpath.c.

Data Fields
jpath_expr_t expr Expression.
char const * field JSON object name.
int32_t slice[3] Array index, or slice, or step.

Macro Definition Documentation

◆ NODE_NEW

#define NODE_NEW (   _node)
Value:
do { \
tail_ctx = *tail = (_node) = talloc_zero(tail_ctx, fr_jpath_node_t); \
(_node)->selector = talloc_zero((_node), jpath_selector_t); \
tail = &(_node)->next; \
} while (0)
next
Definition: dcursor.h:178
struct jpath_selector jpath_selector_t
Selects a subset of JSON child nodes.
Definition: jpath.c:72
Node in a jpath selector sequence.
Definition: jpath.c:87

◆ SELECTOR_INDEX_UNSET

#define SELECTOR_INDEX_UNSET   INT32_MAX

Definition at line 31 of file jpath.c.

Typedef Documentation

◆ jpath_selector_t

Selects a subset of JSON child nodes.

Definition at line 1 of file jpath.c.

Enumeration Type Documentation

◆ jpath_operand_type

Enumerator
JPATH_OPERAND_LITERAL 

Operand is a literal.

JPATH_OPERAND_JPATH 

Operand is a jpath sequence.

Definition at line 33 of file jpath.c.

◆ jpath_type_t

Enumerator
JPATH_SELECTOR_INVALID 
JPATH_SELECTOR_ROOT 

Jump to the root of the document.

JPATH_SELECTOR_CURRENT 

Continue at the current node in the document.

JPATH_SELECTOR_WILDCARD 

Wildcard, operate over all array indices, or fields.

JPATH_SELECTOR_FIELD 

A field, current JSON node must be an object.

JPATH_SELECTOR_INDEX 

Array index, current JSON node must be an array.

JPATH_SELECTOR_SLICE 

Array slice, current JSON node must be an array.

JPATH_SELECTOR_FILTER_EXPRESSION 

Complex filter expression (NYI).

JPATH_SELECTOR_EXPRESSION 

Expression (NYI).

JPATH_SELECTOR_RECURSIVE_DESCENT 

Descend through the JSON tree, looking for a node which matches the next one in the jpath sequence.

Definition at line 38 of file jpath.c.

Function Documentation

◆ fr_jpath_asprint()

char* fr_jpath_asprint ( TALLOC_CTX *  ctx,
fr_jpath_node_t const *  head 
)

Print a node list to a string for debugging.

Will not be identical to the original parsed string, but should be sufficient for testing purposes.

Parameters
ctxto allocate string in.
headof the node list.
Returns
the string representation of the node list.

Definition at line 411 of file jpath.c.

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

◆ fr_jpath_escape_func()

ssize_t fr_jpath_escape_func ( UNUSED request_t request,
char *  out,
size_t  outlen,
char const *  in,
UNUSED void *  arg 
)

Escapes special chars.

Escapes any characters that may have special meaning within a jpath expression

Parameters
requestCurrent request (unused may be NULL).
outWhere to write the escaped string.
outlenLength of the output buffer.
indata to escape.
arguctx data, not used.
Returns
the number of chars written to out.

Definition at line 106 of file jpath.c.

+ Here is the caller graph for this function:

◆ fr_jpath_evaluate_leaf()

int fr_jpath_evaluate_leaf ( TALLOC_CTX *  ctx,
fr_value_box_list_t *  out,
fr_type_t  dst_type,
fr_dict_attr_t const *  dst_enumv,
json_object *  root,
fr_jpath_node_t const *  jpath 
)

Evaluate a parsed jpath expression against a json-c tree.

Will produce one or more fr_value_box_t structures of the desired type, or error out if the conversion between types fails.

Parameters
[in,out]ctxto allocate fr_value_box_t in.
[out]outWhere to write fr_value_box_t.
[in]dst_typeFreeRADIUS type to convert to.
[in]dst_enumvEnumeration values to allow string to integer conversions.
[in]rootof the json-c tree.
[in]jpathto evaluate.
Returns
  • 1 on match.
  • 0 on no match.
  • -1 on error.

Definition at line 383 of file jpath.c.

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

◆ fr_jpath_parse()

ssize_t fr_jpath_parse ( TALLOC_CTX *  ctx,
fr_jpath_node_t **  head,
char const *  in,
size_t  inlen 
)

Parse a jpath string.

Based on the syntax described here http://goessner.net/articles/JsonPath/

Implements parser for everything except unions and expressions

Returns
  • > 0 on success.
  • <= 0 on error (* -1 to get offset error occurred at).

Definition at line 813 of file jpath.c.

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

◆ jpath_array_parse()

static ssize_t jpath_array_parse ( jpath_selector_t selector,
char const *  in,
size_t  inlen 
)
static

Parse index/slice notation.

Expects in to point to a buffer containing:

        [<int0>:<int1>:<int2>]

Where each of the integers and its accompanying delimiter is optional.

Parameters
selectorto populate with index/slice info.
ininput.
inlenlength of in.
Returns
  • > 0 on success.
  • <= 0 on error (* -1 to get offset error occurred at).

Definition at line 544 of file jpath.c.

+ Here is the caller graph for this function:

◆ jpath_evaluate()

static int jpath_evaluate ( TALLOC_CTX *  ctx,
fr_value_box_list_t *  tail,
fr_type_t  dst_type,
fr_dict_attr_t const *  dst_enumv,
json_object *  object,
fr_jpath_node_t const *  jpath 
)
static

Recursive function for jpath_expr_evaluate.

Parameters
[in,out]ctxto allocate fr_value_box_t in.
[out]tailWhere to write fr_value_box_t.
[in]dst_typeFreeRADIUS type to convert to.
[in]dst_enumvEnumeration values to allow string to integer conversions.
[in]objectcurrent node in the json tree.
[in]jpathto evaluate.
Returns
  • 1 on match.
  • 0 on no match.
  • -1 on error.

Definition at line 141 of file jpath.c.

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

◆ jpath_expr_parse()

static ssize_t jpath_expr_parse ( UNUSED jpath_selector_t selector,
UNUSED char const *  in,
UNUSED size_t  inlen 
)
static

Parse a jpath expression.

Note
this requires reworking some of the condition code to accept callbacks to retrieve virtual attributes, so is not yet implemented.

Definition at line 519 of file jpath.c.

+ Here is the caller graph for this function:

◆ jpath_field_parse()

static size_t jpath_field_parse ( fr_jpath_node_t node,
char const *  in,
size_t  inlen 
)
static

Parse a jpath field.

Definition at line 652 of file jpath.c.

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

◆ jpath_filter_expr_parse()

static ssize_t jpath_filter_expr_parse ( UNUSED jpath_selector_t selector,
UNUSED char const *  in,
UNUSED size_t  inlen 
)
static

Parse a jpath filter expression, which in our case, is a FreeRADIUS condition.

Note
this requires reworking some of the condition code to accept callbacks to retrieve virtual attributes, so is not yet implemented.

Definition at line 506 of file jpath.c.

+ Here is the caller graph for this function:

◆ jpath_selector_parse()

static size_t jpath_selector_parse ( fr_jpath_node_t node,
char const *  in,
size_t  inlen 
)
static

parse a jpath selector

Definition at line 730 of file jpath.c.

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

Variable Documentation

◆ escape_chars

char const escape_chars[] = "[],*.:()?"
static

Definition at line 92 of file jpath.c.