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

Parses JSON responses. More...

#include <freeradius-devel/server/base.h>
#include <freeradius-devel/server/module_rlm.h>
#include <freeradius-devel/server/map_proc.h>
#include <freeradius-devel/util/base16.h>
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/sbuff.h>
#include <freeradius-devel/util/types.h>
#include <freeradius-devel/util/value.h>
#include <freeradius-devel/unlang/xlat_func.h>
#include <freeradius-devel/json/base.h>
#include <ctype.h>
+ Include dependency graph for rlm_json.c:

Go to the source code of this file.

Data Structures

struct  rlm_json_jpath_cache
 
struct  rlm_json_jpath_to_eval_t
 
struct  rlm_json_t
 rlm_json module instance More...
 

Typedefs

typedef struct rlm_json_jpath_cache rlm_json_jpath_cache_t
 Forms a linked list of jpath head node pointers (a list of jpaths) More...
 

Functions

static int _json_map_proc_get_value (TALLOC_CTX *ctx, fr_pair_list_t *out, request_t *request, map_t const *map, void *uctx)
 Converts a string value into a fr_pair_t. More...
 
static xlat_action_t json_encode_xlat (TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in)
 Convert given attributes to a JSON document. More...
 
static xlat_action_t json_escape (TALLOC_CTX *ctx, fr_dcursor_t *out, UNUSED xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in, bool quote)
 
static xlat_action_t json_escape_xlat (TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in)
 Ensure contents are escaped correctly for a JSON document. More...
 
static xlat_action_t json_jpath_validate_xlat (TALLOC_CTX *ctx, fr_dcursor_t *out, UNUSED xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in)
 Determine if a jpath expression is valid. More...
 
static xlat_action_t json_quote_xlat (TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in)
 Ensure contents are quoted correctly for a JSON document. More...
 
static int mod_bootstrap (module_inst_ctx_t const *mctx)
 
static int mod_load (void)
 
static unlang_action_t mod_map_proc (rlm_rcode_t *p_result, UNUSED void *mod_inst, void *proc_inst, request_t *request, fr_value_box_list_t *json, map_list_t const *maps)
 Parses a JSON string, and executes jpath queries against it to map values to attributes. More...
 
static int mod_map_proc_instantiate (CONF_SECTION *cs, UNUSED void *mod_inst, void *proc_inst, tmpl_t const *src, map_list_t const *maps)
 Pre-parse and validate literal jpath expressions for maps. More...
 
static void mod_unload (void)
 

Variables

static fr_sbuff_parse_rules_t const json_arg_parse_rules
 
static xlat_arg_parser_t const json_encode_xlat_arg []
 
static xlat_arg_parser_t const json_escape_xlat_arg []
 
static xlat_arg_parser_t const json_jpath_validate_xlat_arg []
 
static conf_parser_t const module_config []
 
module_rlm_t rlm_json
 

Detailed Description

Parses JSON responses.

Id
a5077140e5bd01897f1aee8cd018a0bd37e05e84
Author
Arran Cudbard-Bell
Matthew Newton

Definition in file rlm_json.c.


Data Structure Documentation

◆ rlm_json_jpath_cache

struct rlm_json_jpath_cache

Definition at line 74 of file rlm_json.c.

+ Collaboration diagram for rlm_json_jpath_cache:
Data Fields
fr_jpath_node_t * jpath First node in jpath expression.
rlm_json_jpath_cache_t * next Next jpath cache entry.

◆ rlm_json_jpath_to_eval_t

struct rlm_json_jpath_to_eval_t

Definition at line 79 of file rlm_json.c.

+ Collaboration diagram for rlm_json_jpath_to_eval_t:
Data Fields
fr_jpath_node_t const * jpath
json_object * root

◆ rlm_json_t

struct rlm_json_t

rlm_json module instance

Definition at line 59 of file rlm_json.c.

+ Collaboration diagram for rlm_json_t:
Data Fields
fr_json_format_t * format

Typedef Documentation

◆ rlm_json_jpath_cache_t

Forms a linked list of jpath head node pointers (a list of jpaths)

Definition at line 64 of file rlm_json.c.

Function Documentation

◆ _json_map_proc_get_value()

static int _json_map_proc_get_value ( TALLOC_CTX *  ctx,
fr_pair_list_t out,
request_t request,
map_t const *  map,
void *  uctx 
)
static

Converts a string value into a fr_pair_t.

Parameters
[in,out]ctxto allocate fr_pair_t (s).
[out]outwhere to write the resulting fr_pair_t.
[in]requestThe current request.
[in]mapto process.
[in]uctxThe json tree/jpath expression to evaluate.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 406 of file rlm_json.c.

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

◆ json_escape()

static xlat_action_t json_escape ( TALLOC_CTX *  ctx,
fr_dcursor_t out,
UNUSED xlat_ctx_t const *  xctx,
request_t request,
fr_value_box_list_t *  in,
bool  quote 
)
static

Definition at line 89 of file rlm_json.c.

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

◆ mod_bootstrap()

static int mod_bootstrap ( module_inst_ctx_t const *  mctx)
static

Definition at line 556 of file rlm_json.c.

+ Here is the call graph for this function:

◆ mod_load()

static int mod_load ( void  )
static

Definition at line 582 of file rlm_json.c.

+ Here is the call graph for this function:

◆ mod_map_proc()

static unlang_action_t mod_map_proc ( rlm_rcode_t p_result,
UNUSED void *  mod_inst,
void *  proc_inst,
request_t request,
fr_value_box_list_t *  json,
map_list_t const *  maps 
)
static

Parses a JSON string, and executes jpath queries against it to map values to attributes.

Parameters
p_resultResult of applying map:
mod_instunused.
proc_instcached jpath sequences.
requestThe current request.
jsonJSON string to parse.
mapsHead of the map list.
Returns
UNLANG_ACTION_CALCULATE_RESULT

Definition at line 456 of file rlm_json.c.

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

◆ mod_map_proc_instantiate()

static int mod_map_proc_instantiate ( CONF_SECTION cs,
UNUSED void *  mod_inst,
void *  proc_inst,
tmpl_t const *  src,
map_list_t const *  maps 
)
static

Pre-parse and validate literal jpath expressions for maps.

Parameters
[in]csCONF_SECTION that defined the map instance.
[in]mod_instmodule instance (unused).
[in]proc_instthe cache structure to fill.
[in]srcWhere to get the JSON data from.
[in]mapsset of maps to translate to jpaths.
Returns
  • 0 on success.
    • -1 on failure.

Definition at line 330 of file rlm_json.c.

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

◆ mod_unload()

static void mod_unload ( void  )
static

Definition at line 598 of file rlm_json.c.

+ Here is the call graph for this function:

Variable Documentation

◆ json_arg_parse_rules

fr_sbuff_parse_rules_t const json_arg_parse_rules
static
Initial value:
= {
.terminals = &FR_SBUFF_TERMS(
L("\t"),
L(" "),
L("!")
)
}
#define L(_str)
Helper for initialising arrays of string literals.
Definition: build.h:207
#define FR_SBUFF_TERMS(...)
Initialise a terminal structure with a list of sorted strings.
Definition: sbuff.h:167

Definition at line 48 of file rlm_json.c.

◆ json_encode_xlat_arg

xlat_arg_parser_t const json_encode_xlat_arg[]
static
Initial value:
= {
{ .required = true, .concat = true, .type = FR_TYPE_STRING },
}
@ FR_TYPE_STRING
String of printable characters.
Definition: merged_model.c:83
#define XLAT_ARG_PARSER_TERMINATOR
Definition: xlat.h:166

Definition at line 196 of file rlm_json.c.

◆ json_escape_xlat_arg

xlat_arg_parser_t const json_escape_xlat_arg[]
static
Initial value:
= {
{ .type = FR_TYPE_VOID },
}
@ FR_TYPE_VOID
User data.
Definition: merged_model.c:127

Definition at line 84 of file rlm_json.c.

◆ json_jpath_validate_xlat_arg

xlat_arg_parser_t const json_jpath_validate_xlat_arg[]
static
Initial value:
= {
{ .required = true, .concat = true, .type = FR_TYPE_STRING },
}

Definition at line 137 of file rlm_json.c.

◆ module_config

conf_parser_t const module_config[]
static
Initial value:
= {
.subcs_size = sizeof(fr_json_format_t), .subcs_type = "fr_json_format_t" },
}
#define CONF_PARSER_TERMINATOR
Definition: cf_parse.h:626
#define FR_CONF_OFFSET_SUBSECTION(_name, _flags, _struct, _field, _subcs)
conf_parser_t which populates a sub-struct using a CONF_SECTION
Definition: cf_parse.h:297
struct fr_json_format_s fr_json_format_t
Definition: base.h:231
conf_parser_t const fr_json_format_config[]
Definition: json.c:63
rlm_json module instance
Definition: rlm_json.c:59
int format(printf, 5, 0))

Definition at line 64 of file rlm_json.c.

◆ rlm_json

module_rlm_t rlm_json
Initial value:
= {
.common = {
.name = "json",
.onload = mod_load,
.unload = mod_unload,
.config = module_config,
.inst_size = sizeof(rlm_json_t),
.bootstrap = mod_bootstrap
}
}
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition: dl_module.h:65
static int mod_load(void)
Definition: rlm_json.c:582
static int mod_bootstrap(module_inst_ctx_t const *mctx)
Definition: rlm_json.c:556
static void mod_unload(void)
Definition: rlm_json.c:598
static conf_parser_t const module_config[]
Definition: rlm_json.c:64
@ MODULE_TYPE_THREAD_SAFE
Module is threadsafe.
Definition: module.h:49

Definition at line 615 of file rlm_json.c.