The FreeRADIUS server
$Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
|
Implements the evaluation and parsing functions for the FreeRADIUS version of jpath. More...
#include "config.h"
#include <freeradius-devel/server/base.h>
Go to the source code of this file.
Data Structures | |
struct | fr_json_format_attr_t |
Attribute formatting options for fr_json_afrom_pair_list() More... | |
struct | fr_json_format_s |
JSON document formatting options. More... | |
struct | fr_json_format_value_t |
Value formatting options for fr_json_afrom_pair_list() More... | |
Typedefs | |
typedef struct fr_jpath_node | fr_jpath_node_t |
typedef struct fr_json_format_s | fr_json_format_t |
Enumerations | |
enum | json_mode_type_t { JSON_MODE_UNSET = 0 , JSON_MODE_OBJECT , JSON_MODE_OBJECT_SIMPLE , JSON_MODE_ARRAY , JSON_MODE_ARRAY_OF_VALUES , JSON_MODE_ARRAY_OF_NAMES } |
List of possible JSON format output modes. More... | |
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... | |
char * | fr_json_afrom_pair_list (TALLOC_CTX *ctx, fr_pair_list_t *vps, fr_json_format_t const *format) |
Returns a JSON string of a list of value pairs. More... | |
bool | fr_json_format_verify (fr_json_format_t const *format, bool verbose) |
Verify that the options in fr_json_format_t are valid. More... | |
int | fr_json_object_to_value_box (TALLOC_CTX *ctx, fr_value_box_t *out, json_object *object, fr_dict_attr_t const *enumv, bool tainted) |
Convert json object to fr_value_box_t. More... | |
fr_slen_t | fr_json_str_from_value (fr_sbuff_t *out, fr_value_box_t *vb, bool include_quotes) |
Print a value box as its equivalent JSON format without going via a struct json_object (in most cases) More... | |
void | fr_json_version_print (void) |
Print JSON-C version. More... | |
json_object * | json_object_from_value_box (fr_value_box_t const *data) |
Convert boxed value_box to a JSON object. More... | |
Variables | |
conf_parser_t const | fr_json_format_config [] |
fr_table_num_sorted_t const | fr_json_format_table [] |
size_t | fr_json_format_table_len |
Implements the evaluation and parsing functions for the FreeRADIUS version of jpath.
Definition in file base.h.
struct fr_json_format_attr_t |
Attribute formatting options for fr_json_afrom_pair_list()
Controls how attributes are formatted in JSON documents produced from fr_json_afrom_pair_list().
prefix adds a string prefix to all attribute names in the JSON document, with a colon delimiter.
Example, when prefix is NULL:
{"User-Name":{"type":"string","value":["john"]}}
Example, when prefix is set to foo
:
{"foo:User-Name":{"type":"string","value":["john"]}}
Data Fields | ||
---|---|---|
char const * | prefix | Prefix to add to all attribute names. |
struct fr_json_format_s |
JSON document formatting options.
These options control the format of JSON document which is produced by fr_json_afrom_pair_list().
The output_mode determines the format of JSON that is created:
When JSON_MODE_OBJECT:
{ "<attribute0>": { "type":"<str-type0>", "value":["value0"] }, "<attribute1>": { "type":"<str-type1>", "value":["value1.0", "value1.1"] }, "<attribute2>": { "type":"<int-type2>", "value":[2] }, }
When JSON_MODE_OBJECT_SIMPLE:
{ "<attribute0>":"<value0>", "<attribute1>":["<value1.0>","<value1.1>"], "<attribute2>":2 }
When JSON_MODE_ARRAY:
[ {"name":"<attribute0>","type":"<str-type0>","value":"<value0>"}, {"name":"<attribute1>","type":"<str-type1>","value":"<value1.0>"}, {"name":"<attribute1>","type":"<str-type1>","value":"<value1.1>"}, {"name":"<attribute2>","type":"<int-type2>","value":2} ]
When JSON_MODE_ARRAY_OF_VALUES:
[ <value0>, <value1.0>, <value1.1>, <value2> ]
When JSON_MODE_ARRAY_OF_NAMES:
[ <attribute0>, <attribute1>, <attribute1>, <attribute2> ]
Data Fields | ||
---|---|---|
fr_json_format_attr_t | attr | Formatting options for attribute names. |
bool | include_type | Include attribute type where possible. |
json_mode_type_t | output_mode | Determine the format of JSON document to generate. |
char const * | output_mode_str | For conf_parser_t only. |
fr_json_format_value_t | value | Formatting options for attribute values. |
struct fr_json_format_value_t |
Value formatting options for fr_json_afrom_pair_list()
Controls how values are formatted in JSON documents produced from fr_json_afrom_pair_list().
Not all these options are valid for all output modes.
If an attribute appears only once then the value will normally be written as an object. When an attribute appears more than once then the values will be added as an array instead. Setting value_is_always_array will ensure that values are always written as an array, even if containing only a single entry.
Example with output_mode JSON_MODE_OBJECT_SIMPLE
and value_is_always_array
is false:
{"User-Name":"john","Filter-Id":["f1","f2"]}
Example with output_mode JSON_MODE_OBJECT_SIMPLE
and value_is_always_array
is true:
{"User-Name":["john"],"Filter-Id":["f1","f2"]}
Set enum_as_int to write enumerated values in their integer form.
When false, the string form is output:
{"Service-Type":{"type":"uint32","value":"Login-User"}}
When true, the integer is output:
{"Service-Type":{"type":"uint32","value":1}}
Numeric data types will usually be written to the JSON document as numbers. always_string ensures that all values are written as strings:
Example when always_string
is false:
{"NAS-Port":{"type":"uint32","value":999}}
Example when always_string
is true:
{"NAS-Port":{"type":"uint32","value":"999"}}
Data Fields | ||
---|---|---|
bool | always_string | Output all data types as strings. |
bool | enum_as_int | Output enums as value, not their string representation. |
bool | value_is_always_array | Use JSON array for multiple attribute values. |
typedef struct fr_jpath_node fr_jpath_node_t |
typedef struct fr_json_format_s fr_json_format_t |
enum json_mode_type_t |
List of possible JSON format output modes.
Enumerator | |
---|---|
JSON_MODE_UNSET | |
JSON_MODE_OBJECT | |
JSON_MODE_OBJECT_SIMPLE | |
JSON_MODE_ARRAY | |
JSON_MODE_ARRAY_OF_VALUES | |
JSON_MODE_ARRAY_OF_NAMES |
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.
ctx | to allocate string in. |
head | of the node list. |
Definition at line 411 of file jpath.c.
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
request | Current request (unused may be NULL). |
out | Where to write the escaped string. |
outlen | Length of the output buffer. |
in | data to escape. |
arg | uctx data, not used. |
Definition at line 106 of file jpath.c.
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.
[in,out] | ctx | to allocate fr_value_box_t in. |
[out] | out | Where to write fr_value_box_t. |
[in] | dst_type | FreeRADIUS type to convert to. |
[in] | dst_enumv | Enumeration values to allow string to integer conversions. |
[in] | root | of the json-c tree. |
[in] | jpath | to evaluate. |
Definition at line 383 of file jpath.c.
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
Definition at line 813 of file jpath.c.
char* fr_json_afrom_pair_list | ( | TALLOC_CTX * | ctx, |
fr_pair_list_t * | vps, | ||
fr_json_format_t const * | format | ||
) |
Returns a JSON string of a list of value pairs.
The result is a talloc-ed string, freeing the string is the responsibility of the caller.
The 'format' struct contains settings to configure the output JSON document format.
Default output, when format is NULL, is:
{ "<attribute0>":{ "type":"<type0>", "value":[<value0>,<value1>,<valueN>] }, "<attribute1>":{ "type":"<type1>", "value":[...] }, "<attributeN>":{ "type":"<typeN>", "value":[...] } }
[in] | ctx | Talloc context. |
[in] | vps | a list of value pairs. |
[in] | format | Formatting control, can be NULL to use default format. |
Definition at line 1239 of file json.c.
bool fr_json_format_verify | ( | fr_json_format_t const * | format, |
bool | verbose | ||
) |
Verify that the options in fr_json_format_t are valid.
Warnings are optional, will fatal error if the format is corrupt.
[in] | format | the format structure to check |
[in] | verbose | print out warnings if set |
Definition at line 559 of file json.c.
int fr_json_object_to_value_box | ( | TALLOC_CTX * | ctx, |
fr_value_box_t * | out, | ||
json_object * | object, | ||
fr_dict_attr_t const * | enumv, | ||
bool | tainted | ||
) |
Convert json object to fr_value_box_t.
[in] | ctx | to allocate any value buffers in (should usually be the same as out). |
[in] | out | Where to write value. Must be initialised. |
[in] | object | to convert. |
[in] | enumv | Any string values are assumed to be in PRESENTATION format, meaning that if an enumv is specified, they'll be checked against the list of aliases for that enumeration, and possibly converted into one of the enumeration values (which may not be a string). |
[in] | tainted | Whether the data source is untrusted. |
Definition at line 96 of file json.c.
fr_slen_t fr_json_str_from_value | ( | fr_sbuff_t * | out, |
fr_value_box_t * | vb, | ||
bool | include_quotes | ||
) |
Print a value box as its equivalent JSON format without going via a struct json_object (in most cases)
[out] | out | buffer to write to. |
[in] | vb | to print. |
[in] | include_quotes | whether we should wrap string values, or non-native types like IPv4 addresses in quotes. |
Definition at line 279 of file json.c.
void fr_json_version_print | ( | void | ) |
json_object* json_object_from_value_box | ( | fr_value_box_t const * | data | ) |
|
extern |
|
extern |