![]() |
The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
|
Tokenizers and support functions for xlat expressions. More...
#include <freeradius-devel/server/base.h>
#include <freeradius-devel/unlang/xlat_priv.h>
#include <freeradius-devel/util/calc.h>
#include <freeradius-devel/server/tmpl_dcursor.h>
#include <freeradius-devel/unlang/xlat_func.h>
Go to the source code of this file.
Data Structures | |
struct | xlat_exists_inst_t |
struct | xlat_exists_rctx_t |
struct | xlat_logical_inst_t |
struct | xlat_logical_rctx_t |
struct | xlat_rcode_inst_t |
Holds the result of pre-parsing the rcode on startup. More... | |
struct | xlat_regex_inst_t |
struct | xlat_regex_rctx_t |
Macros | |
#define | fr_sbuff_skip_whitespace(_x) |
#define | P(_x, _y) (((_x) << 4) | (_y)) |
#define | XLAT_BINARY_FUNC(_name, _op) |
#define | XLAT_CMP_FUNC(_name, _op) |
#define | XLAT_DEBUG(...) |
#define | XLAT_REGEX_FUNC(_name, _op) |
#define | XLAT_REGISTER_BINARY_CMP(_op, _name) |
#define | XLAT_REGISTER_BINARY_OP(_op, _name) |
#define | XLAT_REGISTER_BOOL(_xlat, _func, _arg, _ret_type) |
#define | XLAT_REGISTER_NARY_OP(_op, _name, _func_name) |
#define | XLAT_REGISTER_REGEX_OP(_op, _name) |
#define | XLAT_REGISTER_UNARY(_op, _xlat, _func) |
Functions | |
static xlat_exp_t * | expr_cast_alloc (TALLOC_CTX *ctx, fr_type_t type) |
Allocate a specific cast node. | |
static fr_slen_t | expr_cast_from_substr (fr_type_t *cast, fr_sbuff_t *in) |
static void | fr_value_box_init_zero (fr_value_box_t *vb, fr_type_t type) |
static ssize_t | tokenize_expression (xlat_exp_head_t *head, xlat_exp_t **out, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules, fr_token_t prev, fr_sbuff_parse_rules_t const *bracket_rules, fr_sbuff_parse_rules_t const *input_rules, bool cond) |
Tokenize a mathematical operation. | |
static ssize_t | tokenize_field (xlat_exp_head_t *head, xlat_exp_t **out, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules, fr_sbuff_parse_rules_t const *bracket_rules, char *out_c, bool cond) |
static fr_slen_t | tokenize_rcode (xlat_exp_head_t *head, xlat_exp_t **out, fr_sbuff_t *in) |
static fr_slen_t | tokenize_regex_rhs (xlat_exp_head_t *head, xlat_exp_t **out, fr_sbuff_t *in, tmpl_rules_t const *t_rules, fr_sbuff_parse_rules_t const *bracket_rules) |
static fr_slen_t | tokenize_unary (xlat_exp_head_t *head, xlat_exp_t **out, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules, fr_sbuff_parse_rules_t const *bracket_rules, char *out_c, bool cond) |
static bool | valid_type (xlat_exp_t *node) |
static xlat_action_t | xlat_attr_exists (TALLOC_CTX *ctx, fr_dcursor_t *out, request_t *request, tmpl_t const *vpt, bool do_free) |
static xlat_action_t | xlat_binary_op (TALLOC_CTX *ctx, fr_dcursor_t *out, UNUSED xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in, fr_token_t op, fr_type_t default_type, fr_dict_attr_t const *enumv) |
static xlat_action_t | xlat_cmp_op (TALLOC_CTX *ctx, fr_dcursor_t *out, UNUSED xlat_ctx_t const *xctx, UNUSED request_t *request, fr_value_box_list_t *in, fr_token_t op) |
static xlat_exp_t * | xlat_exists_alloc (TALLOC_CTX *ctx, xlat_exp_t *child) |
Allocate a specific cast node. | |
static xlat_action_t | xlat_exists_resume (TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, UNUSED fr_value_box_list_t *in) |
static int | xlat_expr_logical_purify (xlat_exp_t *node, void *instance, request_t *request) |
If any argument resolves to inst->stop_on_match, the entire thing is a bool of inst->stop_on_match. | |
static fr_slen_t | xlat_expr_print_binary (fr_sbuff_t *out, xlat_exp_t const *node, UNUSED void *inst, fr_sbuff_escape_rules_t const *e_rules) |
static fr_slen_t | xlat_expr_print_exists (fr_sbuff_t *out, xlat_exp_t const *node, void *instance, fr_sbuff_escape_rules_t const *e_rules) |
static fr_slen_t | xlat_expr_print_nary (fr_sbuff_t *out, xlat_exp_t const *node, void *instance, fr_sbuff_escape_rules_t const *e_rules) |
static fr_slen_t | xlat_expr_print_rcode (fr_sbuff_t *out, xlat_exp_t const *node, void *instance, UNUSED fr_sbuff_escape_rules_t const *e_rules) |
static fr_slen_t | xlat_expr_print_regex (fr_sbuff_t *out, xlat_exp_t const *node, void *instance, fr_sbuff_escape_rules_t const *e_rules) |
static fr_slen_t | xlat_expr_print_unary (fr_sbuff_t *out, xlat_exp_t const *node, UNUSED void *inst, fr_sbuff_escape_rules_t const *e_rules) |
static int | xlat_expr_resolve_binary (xlat_exp_t *node, UNUSED void *inst, xlat_res_rules_t const *xr_rules) |
static void | xlat_func_append_arg (xlat_exp_t *head, xlat_exp_t *node, bool exists) |
static xlat_action_t | xlat_func_exists (TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, UNUSED fr_value_box_list_t *in) |
See if a named attribute exists. | |
static xlat_action_t | xlat_func_expr_rcode (TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *args) |
Match the passed rcode against request->rcode. | |
static xlat_action_t | xlat_func_logical (TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in) |
Process logical &&, ||. | |
static xlat_action_t | xlat_func_rcode (TALLOC_CTX *ctx, fr_dcursor_t *out, UNUSED xlat_ctx_t const *xctx, request_t *request, UNUSED fr_value_box_list_t *args) |
Return the current rcode as a string. | |
static xlat_action_t | xlat_func_unary_complement (TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in) |
static xlat_action_t | xlat_func_unary_minus (TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in) |
static xlat_action_t | xlat_func_unary_not (TALLOC_CTX *ctx, fr_dcursor_t *out, UNUSED xlat_ctx_t const *xctx, UNUSED request_t *request, fr_value_box_list_t *in) |
static xlat_action_t | xlat_func_unary_op (TALLOC_CTX *ctx, fr_dcursor_t *out, UNUSED xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in, fr_token_t op) |
static int | xlat_function_args_to_tmpl (xlat_inst_ctx_t const *xctx) |
Convert XLAT_BOX arguments to XLAT_TMPL. | |
static int | xlat_instantiate_exists (xlat_inst_ctx_t const *xctx) |
static int | xlat_instantiate_expr_rcode (xlat_inst_ctx_t const *xctx) |
Convert static expr_rcode arguments into rcodes. | |
static int | xlat_instantiate_logical (xlat_inst_ctx_t const *xctx) |
static int | xlat_instantiate_regex (xlat_inst_ctx_t const *xctx) |
bool | xlat_is_truthy (xlat_exp_head_t const *head, bool *out) |
Allow callers to see if an xlat is truthy. | |
static bool | xlat_logical_and (xlat_logical_rctx_t *rctx, fr_value_box_list_t const *in) |
See if the input is truthy or not. | |
static xlat_action_t | xlat_logical_and_resume (TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in) |
static bool | xlat_logical_or (xlat_logical_rctx_t *rctx, fr_value_box_list_t const *in) |
See if the input is truthy or not. | |
static xlat_action_t | xlat_logical_or_resume (TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in) |
static xlat_action_t | xlat_logical_process_arg (UNUSED TALLOC_CTX *ctx, UNUSED fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, UNUSED fr_value_box_list_t *in) |
Process one argument of a logical operation. | |
static bool | xlat_node_matches_bool (bool *result, xlat_exp_t *parent, xlat_exp_head_t *head, bool sense) |
static xlat_action_t | xlat_regex_match (TALLOC_CTX *ctx, request_t *request, fr_value_box_list_t *in, regex_t **preg, fr_dcursor_t *out, fr_token_t op) |
Perform a regular expressions comparison between two operands. | |
static xlat_action_t | xlat_regex_op (TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in, fr_token_t op) |
static xlat_action_t | xlat_regex_resume (TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in) |
int | xlat_register_expressions (void) |
fr_slen_t | xlat_tokenize_condition (TALLOC_CTX *ctx, xlat_exp_head_t **out, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules) |
fr_slen_t | xlat_tokenize_expression (TALLOC_CTX *ctx, xlat_exp_head_t **out, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules) |
static fr_slen_t | xlat_tokenize_expression_internal (TALLOC_CTX *ctx, xlat_exp_head_t **out, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules, bool cond) |
static void | xlat_ungroup (xlat_exp_head_t *head) |
Undo work which shouldn't have been done. | |
Tokenizers and support functions for xlat expressions.
Definition in file xlat_expr.c.
struct xlat_exists_inst_t |
Definition at line 1667 of file xlat_expr.c.
Data Fields | ||
---|---|---|
tmpl_t const * | vpt | the attribute reference |
xlat_exp_head_t * | xlat | the xlat which needs expanding |
struct xlat_exists_rctx_t |
Definition at line 1672 of file xlat_expr.c.
Data Fields | ||
---|---|---|
bool | last_success | |
fr_value_box_list_t | list |
struct xlat_logical_inst_t |
Definition at line 787 of file xlat_expr.c.
Data Fields | ||
---|---|---|
int | argc | |
xlat_exp_head_t ** | argv | |
xlat_func_t | callback | |
bool | stop_on_match |
struct xlat_logical_rctx_t |
Definition at line 794 of file xlat_expr.c.
Data Fields | ||
---|---|---|
fr_value_box_t * | box | output value-box |
TALLOC_CTX * | ctx | |
int | current | |
bool | last_success | |
fr_value_box_list_t | list |
struct xlat_rcode_inst_t |
Holds the result of pre-parsing the rcode on startup.
Definition at line 1481 of file xlat_expr.c.
Data Fields | ||
---|---|---|
rlm_rcode_t | rcode | The preparsed rcode. |
struct xlat_regex_inst_t |
Definition at line 442 of file xlat_expr.c.
Data Fields | ||
---|---|---|
fr_token_t | op | |
regex_t * | regex | precompiled regex |
fr_regex_flags_t * | regex_flags | |
xlat_exp_t * | xlat | to expand |
struct xlat_regex_rctx_t |
Definition at line 449 of file xlat_expr.c.
Data Fields | ||
---|---|---|
bool | last_success | |
fr_value_box_list_t | list |
#define fr_sbuff_skip_whitespace | ( | _x | ) |
Definition at line 2070 of file xlat_expr.c.
#define P | ( | _x, | |
_y | |||
) | (((_x) << 4) | (_y)) |
Definition at line 2014 of file xlat_expr.c.
#define XLAT_BINARY_FUNC | ( | _name, | |
_op | |||
) |
Definition at line 362 of file xlat_expr.c.
#define XLAT_CMP_FUNC | ( | _name, | |
_op | |||
) |
Definition at line 425 of file xlat_expr.c.
#define XLAT_DEBUG | ( | ... | ) |
Definition at line 39 of file xlat_expr.c.
#define XLAT_REGEX_FUNC | ( | _name, | |
_op | |||
) |
Definition at line 776 of file xlat_expr.c.
#define XLAT_REGISTER_BINARY_CMP | ( | _op, | |
_name | |||
) |
Definition at line 1852 of file xlat_expr.c.
#define XLAT_REGISTER_BINARY_OP | ( | _op, | |
_name | |||
) |
Definition at line 1841 of file xlat_expr.c.
#define XLAT_REGISTER_BOOL | ( | _xlat, | |
_func, | |||
_arg, | |||
_ret_type | |||
) |
Definition at line 1884 of file xlat_expr.c.
#define XLAT_REGISTER_NARY_OP | ( | _op, | |
_name, | |||
_func_name | |||
) |
Definition at line 1863 of file xlat_expr.c.
#define XLAT_REGISTER_REGEX_OP | ( | _op, | |
_name | |||
) |
Definition at line 1874 of file xlat_expr.c.
#define XLAT_REGISTER_UNARY | ( | _op, | |
_xlat, | |||
_func | |||
) |
Definition at line 1891 of file xlat_expr.c.
|
static |
Allocate a specific cast node.
With the first argument being a UINT8 of the data type. See xlat_func_cast() for the implementation.
Definition at line 2210 of file xlat_expr.c.
|
static |
Definition at line 2245 of file xlat_expr.c.
|
static |
Definition at line 273 of file xlat_expr.c.
|
static |
Tokenize a mathematical operation.
(EXPR) !EXPR A OP B If "out" is NULL then the expression is added to "head". Otherwise, it's returned to the caller.
Definition at line 2885 of file xlat_expr.c.
|
static |
Definition at line 2428 of file xlat_expr.c.
|
static |
Definition at line 2382 of file xlat_expr.c.
|
static |
Definition at line 2285 of file xlat_expr.c.
|
static |
Definition at line 2106 of file xlat_expr.c.
|
static |
Definition at line 2846 of file xlat_expr.c.
|
static |
Definition at line 1726 of file xlat_expr.c.
|
static |
|
static |
|
static |
Allocate a specific cast node.
With the first argument being a UINT8 of the data type. See xlat_func_cast() for the implementation.
Definition at line 113 of file xlat_expr.c.
|
static |
Definition at line 1745 of file xlat_expr.c.
|
static |
If any argument resolves to inst->stop_on_match, the entire thing is a bool of inst->stop_on_match.
If any argument resolves to !inst->stop_on_match, it is removed.
Definition at line 927 of file xlat_expr.c.
|
static |
|
static |
Definition at line 1685 of file xlat_expr.c.
|
static |
|
static |
Definition at line 1562 of file xlat_expr.c.
|
static |
|
static |
|
static |
|
static |
Definition at line 73 of file xlat_expr.c.
|
static |
Process logical &&, ||.
Definition at line 1315 of file xlat_expr.c.
|
static |
Definition at line 1423 of file xlat_expr.c.
|
static |
Definition at line 1416 of file xlat_expr.c.
|
static |
Definition at line 1389 of file xlat_expr.c.
|
static |
Definition at line 1345 of file xlat_expr.c.
|
static |
Convert XLAT_BOX arguments to XLAT_TMPL.
xlat_tokenize() just makes all unknown arguments into XLAT_BOX, of data type FR_TYPE_STRING. Whereas xlat_tokenize_expr() calls tmpl_afrom_substr(), which tries hard to create a particular data type.
This function fixes up calls of the form op_add(3, 4), which normally passes 2 arguments of "3" and "4", so that the arguments are instead passed as integers 3 and 4.
This fixup isn't strictly necessary, but it's good to have no surprises in the code, if the user creates an expression manually.
Definition at line 1441 of file xlat_expr.c.
|
static |
Definition at line 1702 of file xlat_expr.c.
|
static |
Convert static expr_rcode arguments into rcodes.
This saves doing the lookup at runtime, which given how frequently this xlat is used could get quite expensive.
Definition at line 1490 of file xlat_expr.c.
|
static |
|
static |
bool xlat_is_truthy | ( | xlat_exp_head_t const * | head, |
bool * | out | ||
) |
Allow callers to see if an xlat is truthy.
So the caller can cache it, and needs to check fewer things at run time.
[in] | head | of the xlat to check |
[out] | out | truthiness of the box |
Definition at line 3281 of file xlat_expr.c.
|
static |
See if the input is truthy or not.
[in] | rctx | our ctx |
[in] | in | list of value-boxes to check |
Empty lists are not truthy.
Definition at line 1193 of file xlat_expr.c.
|
static |
Definition at line 1243 of file xlat_expr.c.
|
static |
See if the input is truthy or not.
[in] | rctx | our ctx |
[in] | in | list of value-boxes to check |
Empty lists are not truthy.
Definition at line 1090 of file xlat_expr.c.
|
static |
Definition at line 1135 of file xlat_expr.c.
|
static |
Process one argument of a logical operation.
If we see a list in a truthy context, then we DON'T expand the list. Instead, we return a bool which indicates if the list was empty (or not). This prevents us from returning a whole mess of value-boxes when the user just wanted to see if the list existed.
Otherwise, we expand the xlat, and continue.
Definition at line 1053 of file xlat_expr.c.
|
static |
Definition at line 850 of file xlat_expr.c.
|
static |
Perform a regular expressions comparison between two operands.
[in] | ctx | to allocate resulting box in. |
[in] | request | The current request. |
[in] | in | list of item or items |
[in,out] | preg | Pointer to pre-compiled or runtime-compiled regular expression. In the case of runtime-compiled the pattern may be stolen by the regex_sub_to_request function as the original pattern is needed to resolve capture groups. The caller should only free the regex_t * if it compiled it, and the pointer has not been set to NULL when this function returns. |
[out] | out | Where result is written. |
[in] | op | the operation to perform. |
Definition at line 618 of file xlat_expr.c.
|
static |
|
static |
Definition at line 703 of file xlat_expr.c.
int xlat_register_expressions | ( | void | ) |
Definition at line 1900 of file xlat_expr.c.
fr_slen_t xlat_tokenize_condition | ( | TALLOC_CTX * | ctx, |
xlat_exp_head_t ** | out, | ||
fr_sbuff_t * | in, | ||
fr_sbuff_parse_rules_t const * | p_rules, | ||
tmpl_rules_t const * | t_rules | ||
) |
Definition at line 3264 of file xlat_expr.c.
fr_slen_t xlat_tokenize_expression | ( | TALLOC_CTX * | ctx, |
xlat_exp_head_t ** | out, | ||
fr_sbuff_t * | in, | ||
fr_sbuff_parse_rules_t const * | p_rules, | ||
tmpl_rules_t const * | t_rules | ||
) |
Definition at line 3258 of file xlat_expr.c.
|
static |
Definition at line 3171 of file xlat_expr.c.
|
static |
Undo work which shouldn't have been done.
:(
Definition at line 901 of file xlat_expr.c.
|
static |
Definition at line 381 of file xlat_expr.c.
|
static |
Definition at line 290 of file xlat_expr.c.
|
static |
Definition at line 1963 of file xlat_expr.c.
|
static |
Definition at line 3146 of file xlat_expr.c.
|
static |
Definition at line 2812 of file xlat_expr.c.
|
static |
Definition at line 2844 of file xlat_expr.c.
|
static |
Definition at line 2084 of file xlat_expr.c.
|
static |
Definition at line 2090 of file xlat_expr.c.
|
static |
Definition at line 1995 of file xlat_expr.c.
|
static |
Definition at line 2003 of file xlat_expr.c.
|
static |
|
static |
Definition at line 2016 of file xlat_expr.c.
|
static |
Definition at line 560 of file xlat_expr.c.
|
static |
Definition at line 591 of file xlat_expr.c.
|
extern |
Definition at line 49 of file tmpl_tokenize.c.
|
static |
Definition at line 1340 of file xlat_expr.c.
|
static |
Definition at line 1677 of file xlat_expr.c.
|
static |
Definition at line 1474 of file xlat_expr.c.
|
static |
Takes no arguments.
Definition at line 1634 of file xlat_expr.c.