The FreeRADIUS server
$Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
|
String expansion ("translation"). More...
#include <freeradius-devel/unlang/xlat_ctx.h>
#include <freeradius-devel/unlang/xlat.h>
#include <freeradius-devel/unlang/xlat_func.h>
#include <freeradius-devel/server/module_ctx.h>
#include <freeradius-devel/io/pair.h>
#include <freeradius-devel/util/talloc.h>
#include <freeradius-devel/build.h>
Go to the source code of this file.
Data Structures | |
struct | xlat_call_t |
An xlat function call. More... | |
struct | xlat_exp_head_s |
struct | xlat_exp_s |
An xlat expansion node. More... | |
union | xlat_exp_s.__unnamed103__ |
struct | xlat_out_t |
struct | xlat_s |
Macros | |
#define | _CONST const |
#define | XLAT_DEBUG(...) |
#define | xlat_exp_alloc(_ctx, _type, _in, _inlen) _xlat_exp_alloc(NDEBUG_LOCATION_EXP _ctx, _type, _in, _inlen) |
#define | xlat_exp_alloc_null(_ctx) _xlat_exp_alloc_null(NDEBUG_LOCATION_EXP _ctx) |
#define | xlat_exp_foreach(_list_head, _iter) fr_dlist_foreach(&((_list_head)->dlist), xlat_exp_t, _iter) |
Iterate over the contents of a list, only one level. More... | |
#define | xlat_exp_head_alloc(_ctx) _xlat_exp_head_alloc(NDEBUG_LOCATION_EXP _ctx) |
#define | xlat_exp_set_type(_node, _type) _xlat_exp_set_type(NDEBUG_LOCATION_EXP _node, _type) |
Typedefs | |
typedef struct xlat_s | xlat_t |
typedef int(* | xlat_walker_t) (xlat_exp_t *exp, void *uctx) |
Walker callback for xlat_walk() More... | |
Enumerations | |
enum | xlat_type_t { XLAT_INVALID = 0x0000 , XLAT_BOX = 0x0001 , XLAT_ONE_LETTER = 0x0002 , XLAT_FUNC = 0x0004 , XLAT_FUNC_UNRESOLVED = 0x0008 , XLAT_VIRTUAL = 0x0010 , XLAT_VIRTUAL_UNRESOLVED = 0x0020 , XLAT_TMPL = 0x0040 , XLAT_GROUP = 0x0200 } |
Functions | |
xlat_exp_t * | _xlat_exp_alloc (NDEBUG_LOCATION_ARGS TALLOC_CTX *ctx, xlat_type_t type, char const *in, size_t inlen) |
Allocate an xlat node. More... | |
xlat_exp_t * | _xlat_exp_alloc_null (NDEBUG_LOCATION_ARGS TALLOC_CTX *ctx) |
Allocate an xlat node with no name, and no type set. More... | |
xlat_exp_head_t * | _xlat_exp_head_alloc (NDEBUG_LOCATION_ARGS TALLOC_CTX *ctx) |
void | _xlat_exp_set_type (NDEBUG_LOCATION_ARGS xlat_exp_t *node, xlat_type_t type) |
Set the type of an xlat node. More... | |
void | unlang_xlat_init (void) |
Register xlat operation with the interpreter. More... | |
int | unlang_xlat_push_node (TALLOC_CTX *ctx, bool *p_success, fr_value_box_list_t *out, request_t *request, xlat_exp_t *node) |
Push a pre-compiled xlat onto the stack for evaluation. More... | |
int | xlat_decode_value_box_list (TALLOC_CTX *ctx, fr_pair_list_t *out, request_t *request, void *decode_ctx, fr_pair_decode_t decode, fr_value_box_list_t *in) |
Decode all of the value boxes into the output cursor. More... | |
void | xlat_eval_free (void) |
int | xlat_eval_init (void) |
int | xlat_eval_walk (xlat_exp_head_t *head, xlat_walker_t walker, xlat_type_t type, void *uctx) |
Walk over all xlat nodes (depth first) in a xlat expansion, calling a callback. More... | |
static xlat_exp_t * | xlat_exp_head (xlat_exp_head_t const *head) |
static int | xlat_exp_insert_tail (xlat_exp_head_t *head, xlat_exp_t *node) |
static xlat_exp_t * | xlat_exp_next (xlat_exp_head_t const *head, xlat_exp_t const *node) |
void | xlat_exp_set_name (xlat_exp_t *node, char const *fmt, size_t len) |
Set the format string for an xlat node. More... | |
void | xlat_exp_set_name_buffer (xlat_exp_t *node, char const *fmt) |
Set the format string for an xlat node, copying from a talloc'd buffer. More... | |
void | xlat_exp_set_name_buffer_shallow (xlat_exp_t *node, char const *fmt) |
Set the format string for an xlat node from a pre-existing buffer. More... | |
static void | xlat_flags_merge (xlat_flags_t *parent, xlat_flags_t const *child) |
Merge flags from child to parent. More... | |
xlat_action_t | xlat_frame_eval (TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_exp_head_t const **child, request_t *request, xlat_exp_head_t const *head, xlat_exp_t const **in) |
Converts xlat nodes to value boxes. More... | |
xlat_action_t | xlat_frame_eval_repeat (TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_exp_head_t const **child, request_t *request, xlat_exp_head_t const *head, xlat_exp_t const **in, void *env_data, fr_value_box_list_t *result)) |
Process the result of a previous nested expansion. More... | |
xlat_action_t | xlat_frame_eval_resume (TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_exp_head_t const **child, request_t *request, xlat_exp_head_t const *head, xlat_exp_t const **in, fr_value_box_list_t *result, xlat_func_t resume, void *rctx) |
Call an xlat's resumption method. More... | |
xlat_t * | xlat_func_find (char const *name, ssize_t namelen) |
ssize_t | xlat_print_node (fr_sbuff_t *out, xlat_exp_head_t const *head, xlat_exp_t const *node, fr_sbuff_escape_rules_t const *e_rules, char c) |
int | xlat_purify_list (xlat_exp_head_t *head, request_t *request) |
int | xlat_register_expressions (void) |
void | xlat_signal (xlat_func_signal_t signal, xlat_exp_t const *exp, request_t *request, void *rctx, fr_signal_t action) |
Signal an xlat function. More... | |
fr_dict_attr_t const * | xlat_time_res_attr (char const *res) |
int | xlat_tokenize_expansion (xlat_exp_head_t *head, fr_sbuff_t *in, tmpl_rules_t const *t_rules) |
Variables | |
fr_dict_attr_t const * | attr_cast_base |
fr_dict_attr_t const * | attr_expr_bool_enum |
fr_dict_attr_t const * | attr_module_return_code |
bool const | xlat_func_chars [UINT8_MAX+1] |
String expansion ("translation").
Implements Attribute -> value
Private structures for the xlat tokenizer and xlat eval code.
Definition in file xlat_priv.h.
struct xlat_call_t |
An xlat function call.
Definition at line 123 of file xlat_priv.h.
Data Fields | ||
---|---|---|
xlat_exp_head_t * | args | arguments to the function call |
fr_dict_t const * | dict |
Records the namespace this xlat call was created in. Used by the purify code to run fake requests in the correct namespace, and accessible to instantiation functions in case the xlat needs to perform runtime resolution of attributes (as with eval()). |
bool | ephemeral | Instance data is ephemeral (not inserted) into the instance tree. |
xlat_t const * | func | The xlat expansion to expand format with. |
uint64_t | id |
Identifier unique to each permanent xlat node. This is used by the instantiation code to order nodes by the time they were created. |
xlat_input_type_t | input_type | The input type used inferred from the bracketing style. |
xlat_inst_t * | inst | Instance data for the xlat_t. |
xlat_thread_inst_t * | thread_inst |
Thread specific instance. ONLY USED FOR EPHEMERAL XLATS. |
struct xlat_exp_head_s |
Definition at line 188 of file xlat_priv.h.
Data Fields | ||
---|---|---|
fr_dlist_head_t | dlist | |
char const *_CONST | file | File where the xlat was allocated. |
xlat_flags_t | flags | Flags that control resolution and evaluation. |
bool | instantiated | temporary flag until we fix more things |
int | line | Line where the xlat was allocated. |
struct xlat_exp_s |
An xlat expansion node.
These nodes form a tree which represents one or more nested expansions.
Definition at line 151 of file xlat_priv.h.
Data Fields | ||
---|---|---|
union xlat_exp_s | __unnamed__ | |
fr_dlist_t | entry | |
char const *_CONST | file | File where the xlat was allocated. |
xlat_flags_t | flags | Flags that control resolution and evaluation. |
char const *_CONST | fmt | The original format string (a talloced buffer). |
int | line | Line where the xlat was allocated. |
fr_token_t | quote | Type of quoting around XLAT_GROUP types. |
xlat_type_t _CONST | type | type of this expansion. |
union xlat_exp_s.__unnamed103__ |
Definition at line 165 of file xlat_priv.h.
Data Fields | ||
---|---|---|
xlat_call_t | call | An xlat function call. |
fr_value_box_t | data | A value box. |
xlat_exp_head_t * | group | children of a group |
int | regex_index |
A capture group, i.e. for %{1} and friends |
tmpl_t * | vpt |
An tmpl_t reference. May be an attribute to expand, or an exec reference, or a value-box, ... |
struct xlat_out_t |
Definition at line 199 of file xlat_priv.h.
Data Fields | ||
---|---|---|
size_t | len | Length of the output string. |
char const * | out | Output data. |
struct xlat_s |
Definition at line 59 of file xlat_priv.h.
Data Fields | ||
---|---|---|
xlat_arg_parser_t const * | args | Definition of args consumed. |
call_env_method_t const * | call_env_method |
Optional tmpl expansions performed before calling the xlat. Typically used for xlats which refer to tmpls in their module config. |
xlat_detach_t | detach | Destructor for when xlat instances are freed. |
xlat_flags_t | flags | various flags |
xlat_func_t | func | async xlat function (async unsafe). |
fr_rb_node_t | func_node | Entry in the xlat function tree. |
xlat_input_type_t | input_type | Type of input used. |
size_t | inst_size | Size of instance data to pre-allocate. |
char const * | inst_type | C type of instance structure. |
xlat_instantiate_t | instantiate | Instantiation function. |
bool | internal | If true, cannot be redefined. |
module_inst_ctx_t * | mctx | Original module instantiation ctx if this xlat was registered by a module. |
fr_dlist_t | mi_entry | Entry in the list of functions registered to a module instance. |
char const * | name | Name of xlat function. |
xlat_print_t | function to call when printing | |
xlat_purify_t | purify | function to call when purifying the node. |
xlat_resolve_t | resolve | function to call when resolving |
fr_value_box_safe_for_t | return_safe_for | Escaped value to set in output boxes. |
fr_type_t | return_type |
Function is guaranteed to return one or more boxes of this type. If the return type is FR_TYPE_VOID then the xlat function can return any type of output. |
xlat_thread_detach_t | thread_detach | Destructor for when xlat thread instance data is freed. |
size_t | thread_inst_size | Size of the thread instance data to pre-allocate. |
char const * | thread_inst_type | C type of thread instance structure. |
xlat_thread_instantiate_t | thread_instantiate | Thread instantiation function. |
void * | thread_uctx | uctx to pass to instantiation functions. |
fr_token_t | token | for expressions |
void * | uctx | uctx to pass to instantiation functions. |
#define _CONST const |
Definition at line 54 of file xlat_priv.h.
#define XLAT_DEBUG | ( | ... | ) |
Definition at line 44 of file xlat_priv.h.
#define xlat_exp_alloc | ( | _ctx, | |
_type, | |||
_in, | |||
_inlen | |||
) | _xlat_exp_alloc(NDEBUG_LOCATION_EXP _ctx, _type, _in, _inlen) |
Definition at line 280 of file xlat_priv.h.
#define xlat_exp_alloc_null | ( | _ctx | ) | _xlat_exp_alloc_null(NDEBUG_LOCATION_EXP _ctx) |
Definition at line 277 of file xlat_priv.h.
#define xlat_exp_foreach | ( | _list_head, | |
_iter | |||
) | fr_dlist_foreach(&((_list_head)->dlist), xlat_exp_t, _iter) |
Iterate over the contents of a list, only one level.
[in] | _list_head | to iterate over. |
[in] | _iter | Name of iteration variable. Will be declared in the scope of the loop. |
Definition at line 220 of file xlat_priv.h.
#define xlat_exp_head_alloc | ( | _ctx | ) | _xlat_exp_head_alloc(NDEBUG_LOCATION_EXP _ctx) |
Definition at line 271 of file xlat_priv.h.
#define xlat_exp_set_type | ( | _node, | |
_type | |||
) | _xlat_exp_set_type(NDEBUG_LOCATION_EXP _node, _type) |
Definition at line 274 of file xlat_priv.h.
typedef int(* xlat_walker_t) (xlat_exp_t *exp, void *uctx) |
Walker callback for xlat_walk()
[in] | exp | being evaluated. |
[in] | uctx | passed to xlat_walk. |
Definition at line 265 of file xlat_priv.h.
enum xlat_type_t |
Definition at line 105 of file xlat_priv.h.
xlat_exp_t* _xlat_exp_alloc | ( | NDEBUG_LOCATION_ARGS TALLOC_CTX * | ctx, |
xlat_type_t | type, | ||
char const * | in, | ||
size_t | inlen | ||
) |
Allocate an xlat node.
[in] | ctx | to allocate node in. |
[in] | type | of the node. |
[in] | in | original input string. |
[in] | inlen | the length of the original input string. |
Definition at line 138 of file xlat_alloc.c.
xlat_exp_t* _xlat_exp_alloc_null | ( | NDEBUG_LOCATION_ARGS TALLOC_CTX * | ctx | ) |
Allocate an xlat node with no name, and no type set.
[in] | ctx | to allocate node in. |
Definition at line 125 of file xlat_alloc.c.
xlat_exp_head_t* _xlat_exp_head_alloc | ( | NDEBUG_LOCATION_ARGS TALLOC_CTX * | ctx | ) |
Definition at line 35 of file xlat_alloc.c.
void _xlat_exp_set_type | ( | NDEBUG_LOCATION_ARGS xlat_exp_t * | node, |
xlat_type_t | type | ||
) |
Set the type of an xlat node.
Also initialises any xlat_exp_head necessary
[in] | node | to set type for. |
[in] | type | to set. |
Definition at line 58 of file xlat_alloc.c.
void unlang_xlat_init | ( | void | ) |
int unlang_xlat_push_node | ( | TALLOC_CTX * | ctx, |
bool * | p_success, | ||
fr_value_box_list_t * | out, | ||
request_t * | request, | ||
xlat_exp_t * | node | ||
) |
Push a pre-compiled xlat onto the stack for evaluation.
[in] | ctx | To allocate value boxes and values in. |
[out] | p_success | If set, and execution succeeds, true will be written here. If execution fails, false will be written. |
[out] | out | Where to write the result of the expansion. |
[in] | request | to push xlat onto. |
[in] | node | to evaluate. Only this node will be evaluated. |
Definition at line 294 of file xlat.c.
int xlat_decode_value_box_list | ( | TALLOC_CTX * | ctx, |
fr_pair_list_t * | out, | ||
request_t * | request, | ||
void * | decode_ctx, | ||
fr_pair_decode_t | decode, | ||
fr_value_box_list_t * | in | ||
) |
Decode all of the value boxes into the output cursor.
[in] | ctx | to allocate new pairs in. |
[in] | out | the cursor to update |
[in] | request | the request |
[in] | decode_ctx | Any decode specific data such as secrets or configurable. |
[in] | decode | the function used to decode one specific pair. |
[in] | in | the list of value boxes to decode |
Definition at line 90 of file xlat_pair.c.
void xlat_eval_free | ( | void | ) |
Definition at line 1739 of file xlat_eval.c.
int xlat_eval_init | ( | void | ) |
Definition at line 1714 of file xlat_eval.c.
int xlat_eval_walk | ( | xlat_exp_head_t * | head, |
xlat_walker_t | walker, | ||
xlat_type_t | type, | ||
void * | uctx | ||
) |
Walk over all xlat nodes (depth first) in a xlat expansion, calling a callback.
[in] | head | to evaluate. |
[in] | walker | callback to pass nodes to. |
[in] | type | if > 0 a mask of types to call walker for. |
[in] | uctx | to pass to walker. |
Definition at line 1650 of file xlat_eval.c.
|
inlinestatic |
Definition at line 207 of file xlat_priv.h.
|
inlinestatic |
Definition at line 236 of file xlat_priv.h.
|
inlinestatic |
Definition at line 244 of file xlat_priv.h.
void xlat_exp_set_name | ( | xlat_exp_t * | node, |
char const * | fmt, | ||
size_t | len | ||
) |
Set the format string for an xlat node.
[in] | node | to set fmt for. |
[in] | fmt | talloced buffer to set as the fmt string. |
[in] | len | of fmt string. |
Definition at line 191 of file xlat_alloc.c.
void xlat_exp_set_name_buffer | ( | xlat_exp_t * | node, |
char const * | fmt | ||
) |
Set the format string for an xlat node, copying from a talloc'd buffer.
[in] | node | to set fmt for. |
[in] | fmt | talloced buffer to set as the fmt string. |
Definition at line 202 of file xlat_alloc.c.
void xlat_exp_set_name_buffer_shallow | ( | xlat_exp_t * | node, |
char const * | fmt | ||
) |
Set the format string for an xlat node from a pre-existing buffer.
[in] | node | to set fmt for. |
[in] | fmt | talloced buffer to set as the fmt string. |
Definition at line 213 of file xlat_alloc.c.
|
inlinestatic |
Merge flags from child to parent.
For pass2, if either the parent or child is marked up for pass2, then the parent is marked up for pass2.
Definition at line 227 of file xlat_priv.h.
xlat_action_t xlat_frame_eval | ( | TALLOC_CTX * | ctx, |
fr_dcursor_t * | out, | ||
xlat_exp_head_t const ** | child, | ||
request_t * | request, | ||
xlat_exp_head_t const * | head, | ||
xlat_exp_t const ** | in | ||
) |
Converts xlat nodes to value boxes.
Evaluates a single level of expansions.
[in] | ctx | to allocate value boxes in. |
[out] | out | a list of fr_value_box_t to append to. |
[out] | child | to evaluate. If a child needs to be evaluated by the caller, we return XLAT_ACTION_PUSH_CHILD and place the child to be evaluated here. Once evaluation is complete, the caller should call us with the same xlat_exp_t and the result of the nested evaluation in result. |
[in] | request | the current request. |
[in] | head | of the list to evaluate |
[in,out] | in | xlat node to evaluate. Advanced as we process additional xlat_exp_t. |
Definition at line 1110 of file xlat_eval.c.
xlat_action_t xlat_frame_eval_repeat | ( | TALLOC_CTX * | ctx, |
fr_dcursor_t * | out, | ||
xlat_exp_head_t const ** | child, | ||
request_t * | request, | ||
xlat_exp_head_t const * | head, | ||
xlat_exp_t const ** | in, | ||
void * | env_data, | ||
fr_value_box_list_t * | result | ||
) |
Process the result of a previous nested expansion.
[in] | ctx | to allocate value boxes in. |
[out] | out | a list of fr_value_box_t to append to. |
[out] | child | to evaluate. If a child needs to be evaluated by the caller, we return XLAT_ACTION_PUSH_CHILD and place the child to be evaluated here. Once evaluation is complete, the caller should call us with the same xlat_exp_t and the result of the nested evaluation in result. |
[in] | request | the current request. |
[in] | head | of the list to evaluate |
[in,out] | in | xlat node to evaluate. Advanced as we process additional xlat_exp_t. |
[in] | env_data | Expanded call env. |
[in] | result | of a previous nested evaluation. |
Definition at line 944 of file xlat_eval.c.
xlat_action_t xlat_frame_eval_resume | ( | TALLOC_CTX * | ctx, |
fr_dcursor_t * | out, | ||
xlat_exp_head_t const ** | child, | ||
request_t * | request, | ||
xlat_exp_head_t const * | head, | ||
xlat_exp_t const ** | in, | ||
fr_value_box_list_t * | result, | ||
xlat_func_t | resume, | ||
void * | rctx | ||
) |
Call an xlat's resumption method.
[in] | ctx | to allocate value boxes in. |
[out] | out | a list of fr_value_box_t to append to. |
[out] | child | to evaluate. If a child needs to be evaluated by the caller, we return XLAT_ACTION_PUSH_CHILD and place the child to be evaluated here. Once evaluation is complete, the caller should call us with the same xlat_exp_t and the result of the nested evaluation in result. |
[in] | request | the current request. |
[in] | head | of the list to evaluate |
[in,out] | in | xlat node to evaluate. Advanced as we process additional xlat_exp_t. |
[in] | result | Previously expanded arguments to this xlat function. |
[in] | resume | function to call. |
[in] | rctx | Opaque (to us), resume ctx provided by xlat function when it yielded. |
Definition at line 870 of file xlat_eval.c.
Definition at line 79 of file xlat_func.c.
ssize_t xlat_print_node | ( | fr_sbuff_t * | out, |
xlat_exp_head_t const * | head, | ||
xlat_exp_t const * | node, | ||
fr_sbuff_escape_rules_t const * | e_rules, | ||
char | c | ||
) |
Definition at line 1060 of file xlat_tokenize.c.
int xlat_purify_list | ( | xlat_exp_head_t * | head, |
request_t * | request | ||
) |
Definition at line 60 of file xlat_purify.c.
int xlat_register_expressions | ( | void | ) |
Definition at line 1877 of file xlat_expr.c.
void xlat_signal | ( | xlat_func_signal_t | signal, |
xlat_exp_t const * | exp, | ||
request_t * | request, | ||
void * | rctx, | ||
fr_signal_t | action | ||
) |
Signal an xlat function.
[in] | signal | function to call. |
[in] | exp | Xlat node that previously yielded. |
[in] | request | The current request. |
[in] | rctx | Opaque (to us), resume ctx provided by the xlat function when it yielded. |
[in] | action | What the request should do (the type of signal). |
Definition at line 836 of file xlat_eval.c.
fr_dict_attr_t const* xlat_time_res_attr | ( | char const * | res | ) |
int xlat_tokenize_expansion | ( | xlat_exp_head_t * | head, |
fr_sbuff_t * | in, | ||
tmpl_rules_t const * | t_rules | ||
) |
Definition at line 571 of file xlat_tokenize.c.
|
extern |
Definition at line 50 of file xlat_eval.c.
|
extern |
Definition at line 49 of file xlat_eval.c.
|
extern |
Definition at line 168 of file xlat_tokenize.c.