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_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_MONO(_xlat, _func, _arg) |
#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. More... | |
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 int | reparse_rcode (TALLOC_CTX *ctx, xlat_exp_t **p_arg, bool allow) |
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. More... | |
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_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. More... | |
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. More... | |
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_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. More... | |
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 &&, ||. More... | |
static xlat_action_t | xlat_func_rcode (TALLOC_CTX *ctx, fr_dcursor_t *out, UNUSED xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *args) |
Return the rcode as a string, or bool match if the argument is an rcode name. More... | |
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. More... | |
static int | xlat_instantiate_exists (xlat_inst_ctx_t const *xctx) |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
Variables | |
static xlat_arg_parser_t const | binary_cmp_xlat_args [] |
static xlat_arg_parser_t const | binary_op_xlat_args [] |
static const fr_sbuff_term_elem_t | binary_ops [T_TOKEN_LAST] |
static const fr_sbuff_term_t | bracket_terms |
static fr_table_num_ordered_t const | expr_assignment_op_table [] |
static size_t const | expr_assignment_op_table_len = NUM_ELEMENTS(expr_assignment_op_table) |
static fr_table_num_sorted_t const | expr_quote_table [] |
static size_t | expr_quote_table_len = NUM_ELEMENTS(expr_quote_table) |
static const bool | logical_ops [T_TOKEN_LAST] |
static const bool | multivalue_ops [T_TOKEN_LAST] |
static const fr_sbuff_term_t | operator_terms |
static const int | precedence [T_TOKEN_LAST] |
static const fr_sbuff_escape_rules_t | regex_escape_rules |
static xlat_arg_parser_t const | regex_op_xlat_args [] |
static xlat_arg_parser_t const | unary_op_xlat_args [] |
static xlat_arg_parser_t const | xlat_func_exists_arg [] |
static xlat_arg_parser_t const | xlat_func_rcode_arg [] |
Tokenizers and support functions for xlat expressions.
Definition in file xlat_expr.c.
struct xlat_exists_inst_t |
Definition at line 1574 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 1579 of file xlat_expr.c.
Data Fields | ||
---|---|---|
bool | last_success | |
fr_value_box_list_t | list |
struct xlat_logical_inst_t |
Definition at line 839 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 846 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_regex_inst_t |
Definition at line 516 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 523 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 1970 of file xlat_expr.c.
#define P | ( | _x, | |
_y | |||
) | (((_x) << 4) | (_y)) |
Definition at line 1914 of file xlat_expr.c.
#define XLAT_BINARY_FUNC | ( | _name, | |
_op | |||
) |
Definition at line 436 of file xlat_expr.c.
#define XLAT_CMP_FUNC | ( | _name, | |
_op | |||
) |
Definition at line 499 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 828 of file xlat_expr.c.
#define XLAT_REGISTER_BINARY_CMP | ( | _op, | |
_name | |||
) |
Definition at line 1759 of file xlat_expr.c.
#define XLAT_REGISTER_BINARY_OP | ( | _op, | |
_name | |||
) |
Definition at line 1748 of file xlat_expr.c.
#define XLAT_REGISTER_MONO | ( | _xlat, | |
_func, | |||
_arg | |||
) |
Definition at line 1791 of file xlat_expr.c.
#define XLAT_REGISTER_NARY_OP | ( | _op, | |
_name, | |||
_func_name | |||
) |
Definition at line 1770 of file xlat_expr.c.
#define XLAT_REGISTER_REGEX_OP | ( | _op, | |
_name | |||
) |
Definition at line 1781 of file xlat_expr.c.
#define XLAT_REGISTER_UNARY | ( | _op, | |
_xlat, | |||
_func | |||
) |
Definition at line 1798 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 2121 of file xlat_expr.c.
|
static |
Definition at line 2156 of file xlat_expr.c.
|
static |
Definition at line 347 of file xlat_expr.c.
|
static |
Definition at line 133 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 2649 of file xlat_expr.c.
|
static |
Definition at line 2296 of file xlat_expr.c.
|
static |
Definition at line 2196 of file xlat_expr.c.
|
static |
Definition at line 2006 of file xlat_expr.c.
|
static |
Definition at line 2610 of file xlat_expr.c.
|
static |
Definition at line 1633 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 111 of file xlat_expr.c.
|
static |
Definition at line 1652 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 979 of file xlat_expr.c.
|
static |
|
static |
Definition at line 1592 of file xlat_expr.c.
|
static |
|
static |
|
static |
|
static |
|
static |
Definition at line 71 of file xlat_expr.c.
|
static |
Process logical &&, ||.
Definition at line 1367 of file xlat_expr.c.
|
static |
Definition at line 1475 of file xlat_expr.c.
|
static |
Definition at line 1468 of file xlat_expr.c.
|
static |
Definition at line 1441 of file xlat_expr.c.
|
static |
Definition at line 1397 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 1493 of file xlat_expr.c.
|
static |
Definition at line 1609 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 3040 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 1245 of file xlat_expr.c.
|
static |
Definition at line 1295 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 1142 of file xlat_expr.c.
|
static |
Definition at line 1187 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 1105 of file xlat_expr.c.
|
static |
Definition at line 902 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 669 of file xlat_expr.c.
|
static |
|
static |
Definition at line 755 of file xlat_expr.c.
int xlat_register_expressions | ( | void | ) |
Definition at line 1807 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 3023 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 3017 of file xlat_expr.c.
|
static |
Definition at line 2935 of file xlat_expr.c.
|
static |
Undo work which shouldn't have been done.
:(
Definition at line 953 of file xlat_expr.c.
|
static |
Definition at line 455 of file xlat_expr.c.
|
static |
Definition at line 364 of file xlat_expr.c.
|
static |
Definition at line 1863 of file xlat_expr.c.
|
static |
Definition at line 2910 of file xlat_expr.c.
|
static |
Definition at line 2576 of file xlat_expr.c.
|
static |
Definition at line 2608 of file xlat_expr.c.
|
static |
Definition at line 1984 of file xlat_expr.c.
|
static |
Definition at line 1990 of file xlat_expr.c.
|
static |
Definition at line 1895 of file xlat_expr.c.
|
static |
Definition at line 1903 of file xlat_expr.c.
|
static |
|
static |
Definition at line 1916 of file xlat_expr.c.
|
static |
Definition at line 611 of file xlat_expr.c.
|
static |
Definition at line 642 of file xlat_expr.c.
|
static |
Definition at line 1392 of file xlat_expr.c.
|
static |
Definition at line 1584 of file xlat_expr.c.
|
static |
Definition at line 1527 of file xlat_expr.c.