From: Alan T. DeKok Date: Thu, 21 Apr 2022 17:43:29 +0000 (-0400) Subject: add fake xlat_exp_head_t, which is just xlat_exp_t for now X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1fc808b25a06f4fc9ea5549f051037f65e170e49;p=thirdparty%2Ffreeradius-server.git add fake xlat_exp_head_t, which is just xlat_exp_t for now and update function signatures, etc. to use it. In preparation for moving to tlists --- diff --git a/src/bin/radsizes.c b/src/bin/radsizes.c index af24ce8363d..8b7738e1990 100644 --- a/src/bin/radsizes.c +++ b/src/bin/radsizes.c @@ -29,6 +29,7 @@ int main(UNUSED int argc, UNUSED char **argv) SIZEOF(xlat_call_t); SIZEOF(xlat_exp_t); + SIZEOF(xlat_exp_head_t); return 0; } diff --git a/src/bin/unit_test_attribute.c b/src/bin/unit_test_attribute.c index 7f3c39875f6..b0f0ee88797 100644 --- a/src/bin/unit_test_attribute.c +++ b/src/bin/unit_test_attribute.c @@ -2665,7 +2665,7 @@ static size_t command_xlat_normalise(command_result_t *result, command_file_ctx_ char *data, UNUSED size_t data_used, char *in, UNUSED size_t inlen) { ssize_t dec_len; - xlat_exp_t *head = NULL; + xlat_exp_head_t *head = NULL; size_t input_len = strlen(in), escaped_len; fr_sbuff_parse_rules_t p_rules = { .escapes = &fr_value_unescape_double }; @@ -2698,7 +2698,7 @@ static size_t command_xlat_expr(command_result_t *result, command_file_ctx_t *cc char *data, UNUSED size_t data_used, char *in, UNUSED size_t inlen) { ssize_t dec_len; - xlat_exp_t *head = NULL; + xlat_exp_head_t *head = NULL; size_t input_len = strlen(in), escaped_len; // fr_sbuff_parse_rules_t p_rules = { .escapes = &fr_value_unescape_double }; @@ -2733,7 +2733,7 @@ static size_t command_xlat_purify(command_result_t *result, command_file_ctx_t * char *data, UNUSED size_t data_used, char *in, UNUSED size_t inlen) { ssize_t dec_len; - xlat_exp_t *head = NULL; + xlat_exp_head_t *head = NULL; size_t input_len = strlen(in), escaped_len; // fr_sbuff_parse_rules_t p_rules = { .escapes = &fr_value_unescape_double }; xlat_flags_t flags = { @@ -2774,8 +2774,8 @@ static size_t command_xlat_argv(command_result_t *result, command_file_ctx_t *cc int i, argc; char *p; ssize_t slen; - xlat_exp_t *head = NULL; - xlat_exp_t const **argv; + xlat_exp_head_t *head = NULL; + xlat_exp_head_t const **argv; size_t len; size_t input_len = strlen(in); char buff[1024]; diff --git a/src/bin/unit_test_module.c b/src/bin/unit_test_module.c index 3d59bcce197..62cd7d144c3 100644 --- a/src/bin/unit_test_module.c +++ b/src/bin/unit_test_module.c @@ -382,7 +382,7 @@ static bool do_xlats(fr_event_list_t *el, char const *filename, FILE *fp) ssize_t slen; TALLOC_CTX *xlat_ctx = talloc_init_const("xlat"); char *fmt = talloc_typed_strdup(xlat_ctx, input + 5); - xlat_exp_t *head = NULL; + xlat_exp_head_t *head = NULL; fr_sbuff_parse_rules_t p_rules = { .escapes = &fr_value_unescape_double }; slen = xlat_tokenize_ephemeral(xlat_ctx, &head, el, NULL, @@ -419,7 +419,7 @@ static bool do_xlats(fr_event_list_t *el, char const *filename, FILE *fp) ssize_t slen; TALLOC_CTX *xlat_ctx = talloc_init_const("xlat"); char *fmt = talloc_typed_strdup(xlat_ctx, input + 10); - xlat_exp_t *head = NULL; + xlat_exp_head_t *head = NULL; xlat_flags_t flags = { }; slen = xlat_tokenize_ephemeral_expression(xlat_ctx, &head, el, &flags, diff --git a/src/lib/server/cf_parse.c b/src/lib/server/cf_parse.c index 652ba170407..1e0b6413ed1 100644 --- a/src/lib/server/cf_parse.c +++ b/src/lib/server/cf_parse.c @@ -1478,7 +1478,7 @@ int cf_section_parse_pass2(void *base, CONF_SECTION *cs) */ if (is_xlat) { ssize_t slen; - xlat_exp_t *xlat; + xlat_exp_head_t *xlat; redo: xlat = NULL; diff --git a/src/lib/server/map.c b/src/lib/server/map.c index 711ecebfc67..41984470dd1 100644 --- a/src/lib/server/map.c +++ b/src/lib/server/map.c @@ -1218,7 +1218,7 @@ int map_to_vp(TALLOC_CTX *ctx, fr_pair_list_t *out, request_t *request, map_t co /* * We do the debug printing because xlat_aeval_compiled * doesn't have access to the original string. It's been - * mangled during the parsing to xlat_exp_t + * mangled during the parsing to an internal data structure */ RDEBUG2("EXPAND %s", map->rhs->name); RINDENT(); diff --git a/src/lib/server/tmpl.h b/src/lib/server/tmpl.h index a33ce56c8ee..faf7cfd05c7 100644 --- a/src/lib/server/tmpl.h +++ b/src/lib/server/tmpl.h @@ -534,7 +534,7 @@ struct tmpl_s { struct { union { _CONST struct { - xlat_exp_t *ex; //!< pre-parsed xlat_exp_t + xlat_exp_head_t *ex; //!< pre-parsed xlat expansion xlat_flags_t flags; //!< Flags controlling evaluation ///< and expansion. } xlat; diff --git a/src/lib/server/tmpl_tokenize.c b/src/lib/server/tmpl_tokenize.c index 9493ad96cf6..3aac7abaae9 100644 --- a/src/lib/server/tmpl_tokenize.c +++ b/src/lib/server/tmpl_tokenize.c @@ -2677,7 +2677,7 @@ ssize_t tmpl_afrom_substr(TALLOC_CTX *ctx, tmpl_t **out, */ if (fr_sbuff_is_char(&our_in, '%')) { tmpl_type_t type = TMPL_TYPE_XLAT; - xlat_exp_t *head = NULL; + xlat_exp_head_t *head = NULL; xlat_flags_t flags = {}; vpt = tmpl_alloc_null(ctx); @@ -2861,7 +2861,7 @@ ssize_t tmpl_afrom_substr(TALLOC_CTX *ctx, tmpl_t **out, case T_DOUBLE_QUOTED_STRING: { - xlat_exp_t *head = NULL; + xlat_exp_head_t *head = NULL; xlat_flags_t flags = {}; tmpl_type_t type = TMPL_TYPE_XLAT; @@ -2919,7 +2919,7 @@ ssize_t tmpl_afrom_substr(TALLOC_CTX *ctx, tmpl_t **out, case T_BACK_QUOTED_STRING: { tmpl_type_t type = TMPL_TYPE_EXEC; - xlat_exp_t *head = NULL; + xlat_exp_head_t *head = NULL; xlat_flags_t flags = {}; vpt = tmpl_alloc_null(ctx); @@ -2950,7 +2950,7 @@ ssize_t tmpl_afrom_substr(TALLOC_CTX *ctx, tmpl_t **out, case T_SOLIDUS_QUOTED_STRING: { - xlat_exp_t *head = NULL; + xlat_exp_head_t *head = NULL; xlat_flags_t flags = {}; tmpl_type_t type = TMPL_TYPE_REGEX_XLAT; diff --git a/src/lib/server/trigger.c b/src/lib/server/trigger.c index 54403893bb4..247b53e7bf0 100644 --- a/src/lib/server/trigger.c +++ b/src/lib/server/trigger.c @@ -185,7 +185,7 @@ bool trigger_enabled(void) typedef struct { char *command; //!< Name of the trigger. - xlat_exp_t *xlat; //!< xlat representation of the trigger args. + xlat_exp_head_t *xlat; //!< xlat representation of the trigger args. fr_value_box_list_t args; //!< Arguments to pass to the trigger exec. fr_exec_state_t exec; //!< Used for asynchronous execution. diff --git a/src/lib/unlang/tmpl.c b/src/lib/unlang/tmpl.c index a6d9b6227ea..02d3f7993a6 100644 --- a/src/lib/unlang/tmpl.c +++ b/src/lib/unlang/tmpl.c @@ -211,7 +211,7 @@ static unlang_action_t unlang_tmpl(rlm_rcode_t *p_result, request_t *request, un { unlang_frame_state_tmpl_t *state = talloc_get_type_abort(frame->state, unlang_frame_state_tmpl_t); unlang_tmpl_t *ut = unlang_generic_to_tmpl(frame->instruction); - xlat_exp_t const *xlat; + xlat_exp_head_t const *xlat; /* * If we're not called from unlang_tmpl_push(), then diff --git a/src/lib/unlang/xlat.c b/src/lib/unlang/xlat.c index 3a9c503f505..b0a0e3c2cdc 100644 --- a/src/lib/unlang/xlat.c +++ b/src/lib/unlang/xlat.c @@ -39,7 +39,7 @@ RCSID("$Id$") typedef struct { TALLOC_CTX *ctx; //!< to allocate boxes and values in. TALLOC_CTX *event_ctx; //!< for temporary events - xlat_exp_t const *head; //!< of the xlat list + xlat_exp_head_t const *head; //!< of the xlat list xlat_exp_t const *exp; //!< current one we're evaluating fr_dcursor_t values; //!< Values aggregated so far. @@ -178,7 +178,7 @@ int unlang_xlat_timeout_add(request_t *request, * here. If execution fails, false will be written. * @param[out] out Where to write the result of the expansion. * @param[in] request to push xlat onto. - * @param[in] exp node to evaluate. + * @param[in] xlat to evaluate. * @param[in] top_frame Set to UNLANG_TOP_FRAME if the interpreter should return. * Set to UNLANG_SUB_FRAME if the interprer should continue. * @return @@ -186,7 +186,7 @@ int unlang_xlat_timeout_add(request_t *request, * - -1 on failure. */ int unlang_xlat_push(TALLOC_CTX *ctx, bool *p_success, fr_value_box_list_t *out, - request_t *request, xlat_exp_t const *exp, bool top_frame) + request_t *request, xlat_exp_head_t const *xlat, bool top_frame) { /** Static instruction for performing xlat evaluations * @@ -226,8 +226,8 @@ int unlang_xlat_push(TALLOC_CTX *ctx, bool *p_success, fr_value_box_list_t *out, * Allocate its state, and setup a cursor for the xlat nodes */ MEM(frame->state = state = talloc_zero(stack, unlang_frame_state_xlat_t)); - state->head = talloc_get_type_abort_const(exp, xlat_exp_t); /* Ensure the node is valid */ - state->exp = state->head; + state->head = talloc_get_type_abort_const(xlat, xlat_exp_t); /* Ensure the node is valid */ + state->exp = xlat_exp_head(state->head); state->success = p_success; state->ctx = ctx; diff --git a/src/lib/unlang/xlat.h b/src/lib/unlang/xlat.h index c2acaa0069d..43cb1528858 100644 --- a/src/lib/unlang/xlat.h +++ b/src/lib/unlang/xlat.h @@ -271,7 +271,7 @@ ssize_t xlat_eval(char *out, size_t outlen, request_t *request, char const *fmt void const *escape_ctx) CC_HINT(nonnull (1 ,3 ,4)); -ssize_t xlat_eval_compiled(char *out, size_t outlen, request_t *request, xlat_exp_t const *xlat, +ssize_t xlat_eval_compiled(char *out, size_t outlen, request_t *request, xlat_exp_head_t const *head, xlat_escape_legacy_t escape, void const *escape_ctx) CC_HINT(nonnull (1 ,3 ,4)); @@ -280,53 +280,53 @@ ssize_t xlat_aeval(TALLOC_CTX *ctx, char **out, request_t *request, CC_HINT(nonnull(2, 3, 4)); ssize_t xlat_aeval_compiled(TALLOC_CTX *ctx, char **out, request_t *request, - xlat_exp_t const *xlat, xlat_escape_legacy_t escape, void const *escape_ctx) + xlat_exp_head_t const *head, xlat_escape_legacy_t escape, void const *escape_ctx) CC_HINT(nonnull (2, 3, 4)); int xlat_aeval_compiled_argv(TALLOC_CTX *ctx, char ***argv, request_t *request, - xlat_exp_t const *xlat, xlat_escape_legacy_t escape, void const *escape_ctx); + xlat_exp_head_t const *head, xlat_escape_legacy_t escape, void const *escape_ctx); -int xlat_flatten_compiled_argv(TALLOC_CTX *ctx, xlat_exp_t const ***argv, xlat_exp_t const *xlat); +int xlat_flatten_compiled_argv(TALLOC_CTX *ctx, xlat_exp_head_t const ***argv, xlat_exp_head_t const *head); -bool xlat_async_required(xlat_exp_t const *xlat); +bool xlat_async_required(xlat_exp_head_t const *xlat); -ssize_t xlat_tokenize_expression(TALLOC_CTX *ctx, xlat_exp_t **head, xlat_flags_t *flags, fr_sbuff_t *in, +ssize_t xlat_tokenize_expression(TALLOC_CTX *ctx, xlat_exp_head_t **head, xlat_flags_t *flags, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules); -ssize_t xlat_tokenize_ephemeral_expression(TALLOC_CTX *ctx, xlat_exp_t **head, +ssize_t xlat_tokenize_ephemeral_expression(TALLOC_CTX *ctx, xlat_exp_head_t **head, fr_event_list_t *el, xlat_flags_t *flags, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules); -ssize_t xlat_tokenize_ephemeral(TALLOC_CTX *ctx, xlat_exp_t **head, +ssize_t xlat_tokenize_ephemeral(TALLOC_CTX *ctx, xlat_exp_head_t **head, fr_event_list_t *el, xlat_flags_t *flags, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules); -ssize_t xlat_tokenize_argv(TALLOC_CTX *ctx, xlat_exp_t **head, xlat_flags_t *flags, fr_sbuff_t *in, +ssize_t xlat_tokenize_argv(TALLOC_CTX *ctx, xlat_exp_head_t **head, xlat_flags_t *flags, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *p_rules, tmpl_attr_rules_t const *t_rules); -ssize_t xlat_tokenize(TALLOC_CTX *ctx, xlat_exp_t **head, xlat_flags_t *flags, fr_sbuff_t *in, +ssize_t xlat_tokenize(TALLOC_CTX *ctx, xlat_exp_head_t **head, xlat_flags_t *flags, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *p_rules, tmpl_attr_rules_t const *t_rules); -ssize_t xlat_print(fr_sbuff_t *in, xlat_exp_t const *node, fr_sbuff_escape_rules_t const *e_rules); +ssize_t xlat_print(fr_sbuff_t *in, xlat_exp_head_t const *node, fr_sbuff_escape_rules_t const *e_rules); -static inline fr_slen_t xlat_aprint(TALLOC_CTX *ctx, char **out, xlat_exp_t const *node, +static inline fr_slen_t xlat_aprint(TALLOC_CTX *ctx, char **out, xlat_exp_head_t const *head, fr_sbuff_escape_rules_t const *e_rules) - SBUFF_OUT_TALLOC_FUNC_NO_LEN_DEF(xlat_print, node, e_rules) + SBUFF_OUT_TALLOC_FUNC_NO_LEN_DEF(xlat_print, head, e_rules) int xlat_validate_function_mono(xlat_exp_t *node); int xlat_validate_function_args(xlat_exp_t *node); -void xlat_debug(xlat_exp_t const *node); +void xlat_debug(xlat_exp_head_t const *head); -bool xlat_is_literal(xlat_exp_t const *head); +bool xlat_is_literal(xlat_exp_head_t const *head); -bool xlat_to_string(TALLOC_CTX *ctx, char **str, xlat_exp_t **head); +bool xlat_to_string(TALLOC_CTX *ctx, char **str, xlat_exp_head_t **head); -int xlat_resolve(xlat_exp_t **head, xlat_flags_t *flags, xlat_res_rules_t const *xr_rules); +int xlat_resolve(xlat_exp_head_t **head, xlat_flags_t *flags, xlat_res_rules_t const *xr_rules); xlat_t *xlat_register_module(TALLOC_CTX *ctx, module_inst_ctx_t const *mctx, char const *name, xlat_func_t func, xlat_flags_t const *flags); @@ -376,20 +376,20 @@ void xlat_free(void); /* * xlat_tokenize.c */ -xlat_exp_t *xlat_exp_func_alloc(TALLOC_CTX *ctx, xlat_t *func, xlat_exp_t const *args); +xlat_exp_t *xlat_exp_func_alloc(TALLOC_CTX *ctx, xlat_t *func, xlat_exp_head_t const *args); -void xlat_exp_free(xlat_exp_t **head); +void xlat_exp_free(xlat_exp_head_t **head); -tmpl_t *xlat_to_tmpl_attr(TALLOC_CTX *ctx, xlat_exp_t *xlat); +tmpl_t *xlat_to_tmpl_attr(TALLOC_CTX *ctx, xlat_exp_head_t *xlat); -int xlat_from_tmpl_attr(TALLOC_CTX *ctx, xlat_exp_t **head, xlat_flags_t *flags, tmpl_t **vpt_p); +int xlat_from_tmpl_attr(TALLOC_CTX *ctx, xlat_exp_head_t **head, xlat_flags_t *flags, tmpl_t **vpt_p); int xlat_copy(TALLOC_CTX *ctx, xlat_exp_t **out, xlat_exp_t const *in); /* * xlat_inst.c */ -int xlat_instantiate_ephemeral(xlat_exp_t *root, fr_event_list_t *el) CC_HINT(nonnull(1)); +int xlat_instantiate_ephemeral(xlat_exp_head_t *head, fr_event_list_t *el) CC_HINT(nonnull(1)); xlat_thread_inst_t *xlat_thread_instance_find(xlat_exp_t const *node); @@ -412,7 +412,7 @@ int unlang_xlat_timeout_add(request_t *request, fr_unlang_xlat_timeout_t callba void const *rctx, fr_time_t when); int unlang_xlat_push(TALLOC_CTX *ctx, bool *p_success, fr_value_box_list_t *out, - request_t *request, xlat_exp_t const *exp, bool top_frame) + request_t *request, xlat_exp_head_t const *head, bool top_frame) CC_HINT(warn_unused_result); xlat_action_t unlang_xlat_yield(request_t *request, diff --git a/src/lib/unlang/xlat_ctx.h b/src/lib/unlang/xlat_ctx.h index a87d26cd1b7..59bbab437ba 100644 --- a/src/lib/unlang/xlat_ctx.h +++ b/src/lib/unlang/xlat_ctx.h @@ -33,6 +33,7 @@ extern "C" { /* So we don't need to include xlat.h */ typedef struct xlat_exp xlat_exp_t; +typedef struct xlat_exp xlat_exp_head_t; /** An xlat calling ctx * diff --git a/src/lib/unlang/xlat_eval.c b/src/lib/unlang/xlat_eval.c index 658dc33b307..c8aa5f4d431 100644 --- a/src/lib/unlang/xlat_eval.c +++ b/src/lib/unlang/xlat_eval.c @@ -89,8 +89,8 @@ fr_table_num_sorted_t const xlat_action_table[] = { }; size_t xlat_action_table_len = NUM_ELEMENTS(xlat_action_table); -static ssize_t xlat_eval_sync(TALLOC_CTX *ctx, char **out, request_t *request, xlat_exp_t const * const head, - xlat_escape_legacy_t escape, void const *escape_ctx); +static ssize_t xlat_eval_sync(TALLOC_CTX *ctx, char **out, request_t *request, xlat_exp_head_t const * const head, + xlat_escape_legacy_t escape, void const *escape_ctx); /** Reconstruct the original expansion string from an xlat tree * @@ -178,8 +178,8 @@ static char *xlat_fmt_aprint(TALLOC_CTX *ctx, xlat_exp_t const *node) { char *first, *second, *result; - first = xlat_fmt_aprint(NULL, node->alternate[0]); - second = xlat_fmt_aprint(NULL, node->alternate[1]); + first = xlat_fmt_aprint(NULL, xlat_exp_head(node->alternate[0])); + second = xlat_fmt_aprint(NULL, xlat_exp_head(node->alternate[1])); result = talloc_asprintf(ctx, "%%{%s:-%s}", first, second); talloc_free(first); talloc_free(second); @@ -213,7 +213,7 @@ static inline void xlat_debug_log_expansion(request_t *request, xlat_exp_t const * we print the concatenated arguments list as * well as the original fmt string. */ - if ((node->type == XLAT_FUNC) && !xlat_is_literal(xlat_exp_head(node->call.args))) { + if ((node->type == XLAT_FUNC) && !xlat_is_literal(node->call.args)) { RDEBUG2(" (%%%c%s:%pM%c)", (node->call.func->input_type == XLAT_INPUT_ARGS) ? '(' : '{', node->call.func->name, args, @@ -1011,8 +1011,8 @@ xlat_action_t xlat_frame_eval_resume(TALLOC_CTX *ctx, fr_dcursor_t *out, * @param[in] result of a previous nested evaluation. */ xlat_action_t xlat_frame_eval_repeat(TALLOC_CTX *ctx, fr_dcursor_t *out, - xlat_exp_t const **child, bool *alternate, - request_t *request, xlat_exp_t const *head, xlat_exp_t const **in, + xlat_exp_head_t const **child, bool *alternate, + request_t *request, xlat_exp_head_t const *head, xlat_exp_t const **in, fr_value_box_list_t *result) { xlat_exp_t const *node = *in; @@ -1189,8 +1189,8 @@ xlat_action_t xlat_frame_eval_repeat(TALLOC_CTX *ctx, fr_dcursor_t *out, * - XLAT_ACTION_DONE we're done, pop the frame. * - XLAT_ACTION_FAIL an xlat module failed. */ -xlat_action_t xlat_frame_eval(TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_exp_t const **child, - request_t *request, xlat_exp_t const *head, xlat_exp_t const **in) +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) { xlat_action_t xa = XLAT_ACTION_DONE; xlat_exp_t const *node; @@ -1296,7 +1296,7 @@ xlat_action_t xlat_frame_eval(TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_exp_t con * for evaluation. */ if (xlat_exp_head(node->call.args)) { - *child = xlat_exp_head(node->call.args); + *child = node->call.args; xa = XLAT_ACTION_PUSH_CHILD; goto finish; } @@ -1373,7 +1373,7 @@ finish: return xa; } -static ssize_t xlat_eval_sync(TALLOC_CTX *ctx, char **out, request_t *request, xlat_exp_t const * const head, +static ssize_t xlat_eval_sync(TALLOC_CTX *ctx, char **out, request_t *request, xlat_exp_head_t const * const head, xlat_escape_legacy_t escape, void const *escape_ctx) { fr_value_box_list_t result; @@ -1467,20 +1467,20 @@ static ssize_t xlat_eval_sync(TALLOC_CTX *ctx, char **out, request_t *request, x * @param[out] out Where to write pointer to output buffer. * @param[in] outlen Size of out. * @param[in] request current request. - * @param[in] node the xlat structure to expand + * @param[in] head the xlat structure to expand * @param[in] escape function to escape final value e.g. SQL quoting. * @param[in] escape_ctx pointer to pass to escape function. * @return length of string written @bug should really have -1 for failure. */ static ssize_t _xlat_eval_compiled(TALLOC_CTX *ctx, char **out, size_t outlen, request_t *request, - xlat_exp_t const *node, xlat_escape_legacy_t escape, void const *escape_ctx) + xlat_exp_head_t const *head, xlat_escape_legacy_t escape, void const *escape_ctx) { char *buff; ssize_t slen; - fr_assert(node != NULL); + fr_assert(head != NULL); - slen = xlat_eval_sync(ctx, &buff, request, node, escape, escape_ctx); + slen = xlat_eval_sync(ctx, &buff, request, head, escape, escape_ctx); if (slen < 0) { fr_assert(buff == NULL); if (*out) **out = '\0'; @@ -1522,14 +1522,14 @@ ssize_t _xlat_eval(TALLOC_CTX *ctx, char **out, size_t outlen, request_t *reques xlat_escape_legacy_t escape, void const *escape_ctx) { ssize_t len; - xlat_exp_t *node; + xlat_exp_head_t *head; RINDENT(); /* * Give better errors than the old code. */ - len = xlat_tokenize_ephemeral(ctx, &node, unlang_interpret_event_list(request), NULL, + len = xlat_tokenize_ephemeral(ctx, &head, unlang_interpret_event_list(request), NULL, &FR_SBUFF_IN(fmt, strlen(fmt)), NULL, &(tmpl_rules_t){ @@ -1554,8 +1554,8 @@ ssize_t _xlat_eval(TALLOC_CTX *ctx, char **out, size_t outlen, request_t *reques return -1; } - len = _xlat_eval_compiled(ctx, out, outlen, request, node, escape, escape_ctx); - talloc_free(node); + len = _xlat_eval_compiled(ctx, out, outlen, request, head, escape, escape_ctx); + talloc_free(head); REXDENT(); @@ -1571,7 +1571,7 @@ ssize_t xlat_eval(char *out, size_t outlen, request_t *request, } ssize_t xlat_eval_compiled(char *out, size_t outlen, request_t *request, - xlat_exp_t const *xlat, xlat_escape_legacy_t escape, void const *escape_ctx) + xlat_exp_head_t const *xlat, xlat_escape_legacy_t escape, void const *escape_ctx) { fr_assert(done_init); @@ -1588,7 +1588,7 @@ ssize_t xlat_aeval(TALLOC_CTX *ctx, char **out, request_t *request, char const * } ssize_t xlat_aeval_compiled(TALLOC_CTX *ctx, char **out, request_t *request, - xlat_exp_t const *xlat, xlat_escape_legacy_t escape, void const *escape_ctx) + xlat_exp_head_t const *xlat, xlat_escape_legacy_t escape, void const *escape_ctx) { fr_assert(done_init); @@ -1612,14 +1612,14 @@ ssize_t xlat_aeval_compiled(TALLOC_CTX *ctx, char **out, request_t *request, * - >0 on success which is argc to the corresponding argv */ int xlat_aeval_compiled_argv(TALLOC_CTX *ctx, char ***argv, request_t *request, - xlat_exp_t const *head, xlat_escape_legacy_t escape, void const *escape_ctx) + xlat_exp_head_t const *head, xlat_escape_legacy_t escape, void const *escape_ctx) { int i; ssize_t slen; char **my_argv; size_t count; - if (head->type != XLAT_GROUP) return -1; + if (!xlat_exp_is_head(head)) return -1; count = 0; xlat_exp_foreach(head, node) { @@ -1648,20 +1648,20 @@ int xlat_aeval_compiled_argv(TALLOC_CTX *ctx, char ***argv, request_t *request, * * This is mostly for async use. */ -int xlat_flatten_compiled_argv(TALLOC_CTX *ctx, xlat_exp_t const ***argv, xlat_exp_t const *head) +int xlat_flatten_compiled_argv(TALLOC_CTX *ctx, xlat_exp_head_t const ***argv, xlat_exp_head_t const *head) { int i; - xlat_exp_t const **my_argv; + xlat_exp_head_t const **my_argv; size_t count; - if (head->type != XLAT_GROUP) return -1; + if (!xlat_exp_is_head(head)) return -1; count = 0; xlat_exp_foreach(head, node) { count++; } - MEM(my_argv = talloc_zero_array(ctx, xlat_exp_t const *, count + 1)); + MEM(my_argv = talloc_zero_array(ctx, xlat_exp_head_t const *, count + 1)); *argv = my_argv; fr_assert(done_init); @@ -1684,7 +1684,7 @@ int xlat_flatten_compiled_argv(TALLOC_CTX *ctx, xlat_exp_t const ***argv, xlat_e * - 0 on success (walker always returned 0). * - <0 if walker returned <0. */ -int xlat_eval_walk(xlat_exp_t *head, xlat_walker_t walker, xlat_type_t type, void *uctx) +int xlat_eval_walk(xlat_exp_head_t *head, xlat_walker_t walker, xlat_type_t type, void *uctx) { int ret; @@ -1799,10 +1799,15 @@ void xlat_eval_free(void) * * If the xlat yields, then async is required. */ -bool xlat_async_required(xlat_exp_t const *head) +bool xlat_async_required(xlat_exp_head_t const *head) { - if (head->type != XLAT_GROUP) { - return head->flags.needs_async; + xlat_exp_t *first; + + if (head) return false; + + first = xlat_exp_head(head); + if (first->type != XLAT_GROUP) { + return first->flags.needs_async; } /* diff --git a/src/lib/unlang/xlat_expr.c b/src/lib/unlang/xlat_expr.c index 115732ff527..3f322b4c2e7 100644 --- a/src/lib/unlang/xlat_expr.c +++ b/src/lib/unlang/xlat_expr.c @@ -91,7 +91,7 @@ static fr_slen_t xlat_expr_print_unary(fr_sbuff_t *out, xlat_exp_t const *node, size_t at_in = fr_sbuff_used_total(out); FR_SBUFF_IN_STRCPY_RETURN(out, fr_tokens[node->call.func->token]); - xlat_print_node(out, xlat_exp_head(node->call.args), e_rules); + xlat_print_node(out, node->call.args, xlat_exp_head(node->call.args), e_rules); return fr_sbuff_used_total(out) - at_in; } @@ -101,7 +101,7 @@ static fr_slen_t xlat_expr_print_binary(fr_sbuff_t *out, xlat_exp_t const *node, size_t at_in = fr_sbuff_used_total(out); FR_SBUFF_IN_CHAR_RETURN(out, '('); - xlat_print_node(out, xlat_exp_head(node->call.args), e_rules); /* prints a space after the first argument */ + xlat_print_node(out, node->call.args, xlat_exp_head(node->call.args), e_rules); /* prints a space after the first argument */ /* * @todo - when things like "+" support more than 2 arguments, print them all out @@ -109,7 +109,7 @@ static fr_slen_t xlat_expr_print_binary(fr_sbuff_t *out, xlat_exp_t const *node, */ FR_SBUFF_IN_STRCPY_RETURN(out, fr_tokens[node->call.func->token]); FR_SBUFF_IN_CHAR_RETURN(out, ' '); - xlat_print_node(out, xlat_exp_next(node->call.args, xlat_exp_head(node->call.args)), e_rules); + xlat_print_node(out, node->call.args, xlat_exp_next(node->call.args, xlat_exp_head(node->call.args)), e_rules); FR_SBUFF_IN_CHAR_RETURN(out, ')'); @@ -409,7 +409,7 @@ static fr_slen_t xlat_expr_print_logical(fr_sbuff_t *out, xlat_exp_t const *node { size_t at_in = fr_sbuff_used_total(out); xlat_logical_inst_t *inst = instance; - xlat_exp_t *head = inst->args; + xlat_exp_head_t *head = inst->args; /* * We might get called before the node is instantiated. @@ -421,7 +421,7 @@ static fr_slen_t xlat_expr_print_logical(fr_sbuff_t *out, xlat_exp_t const *node FR_SBUFF_IN_CHAR_RETURN(out, '('); xlat_exp_foreach(head, child) { - xlat_print_node(out, child, e_rules); + xlat_print_node(out, head, child, e_rules); if (!xlat_exp_next(head, child)) break; @@ -770,7 +770,7 @@ static const int precedence[T_TOKEN_LAST] = { while (isspace((int) *fr_sbuff_current(_x))) fr_sbuff_advance(_x, 1); \ } while (0) -static ssize_t tokenize_expression(TALLOC_CTX *ctx, xlat_exp_t **head, xlat_flags_t *flags, fr_sbuff_t *in, +static ssize_t tokenize_expression(TALLOC_CTX *ctx, xlat_exp_head_t **head, xlat_flags_t *flags, 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); @@ -784,7 +784,7 @@ static fr_table_num_sorted_t const expr_quote_table[] = { static size_t expr_quote_table_len = NUM_ELEMENTS(expr_quote_table); #ifdef HAVE_REGEX -static ssize_t tokenize_regex(TALLOC_CTX *ctx, xlat_exp_t **head, xlat_flags_t *flags, fr_sbuff_t *in, +static ssize_t tokenize_regex(TALLOC_CTX *ctx, xlat_exp_head_t **head, xlat_flags_t *flags, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules) { ssize_t slen; @@ -871,7 +871,7 @@ static ssize_t tokenize_regex(TALLOC_CTX *ctx, xlat_exp_t **head, xlat_flags_t * * to parse the next thing we get. Otherwise, parse the thing as * int64_t. */ -static ssize_t tokenize_field(TALLOC_CTX *input_ctx, xlat_exp_t **head, xlat_flags_t *flags, fr_sbuff_t *in, +static ssize_t tokenize_field(TALLOC_CTX *input_ctx, xlat_exp_head_t **head, xlat_flags_t *flags, 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) { @@ -1132,7 +1132,7 @@ static size_t const expr_assignment_op_table_len = NUM_ELEMENTS(expr_assignment_ * !EXPR * A OP B */ -static ssize_t tokenize_expression(TALLOC_CTX *ctx, xlat_exp_t **head, xlat_flags_t *flags, fr_sbuff_t *in, +static ssize_t tokenize_expression(TALLOC_CTX *ctx, xlat_exp_head_t **head, xlat_flags_t *flags, 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) { @@ -1366,7 +1366,7 @@ static const fr_sbuff_term_t operator_terms = FR_SBUFF_TERMS( L("<"), ); -ssize_t xlat_tokenize_expression(TALLOC_CTX *ctx, xlat_exp_t **head, xlat_flags_t *flags, fr_sbuff_t *in, +ssize_t xlat_tokenize_expression(TALLOC_CTX *ctx, xlat_exp_head_t **head, xlat_flags_t *flags, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules) { ssize_t slen; @@ -1450,7 +1450,7 @@ ssize_t xlat_tokenize_expression(TALLOC_CTX *ctx, xlat_exp_t **head, xlat_flags_ * - 0 and *head != NULL - Zero length expansion * - <0 the negative offset of the parse failure. */ -ssize_t xlat_tokenize_ephemeral_expression(TALLOC_CTX *ctx, xlat_exp_t **head, +ssize_t xlat_tokenize_ephemeral_expression(TALLOC_CTX *ctx, xlat_exp_head_t **head, fr_event_list_t *el, xlat_flags_t *flags, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules) diff --git a/src/lib/unlang/xlat_inst.c b/src/lib/unlang/xlat_inst.c index 2115ec8e61d..529814005a1 100644 --- a/src/lib/unlang/xlat_inst.c +++ b/src/lib/unlang/xlat_inst.c @@ -304,11 +304,11 @@ static int _xlat_instantiate_ephemeral_walker(xlat_exp_t *node, void *uctx) * * @note This must only be used for xlats created at runtime. * - * @param[in] root of xlat tree to create instance data for. + * @param[in] head of xlat tree to create instance data for. */ -int xlat_instantiate_ephemeral(xlat_exp_t *root, fr_event_list_t *el) +int xlat_instantiate_ephemeral(xlat_exp_head_t *head, fr_event_list_t *el) { - return xlat_eval_walk(root, _xlat_instantiate_ephemeral_walker, XLAT_FUNC, el); + return xlat_eval_walk(head, _xlat_instantiate_ephemeral_walker, XLAT_FUNC, el); } /** Retrieve xlat/thread specific instance data diff --git a/src/lib/unlang/xlat_priv.h b/src/lib/unlang/xlat_priv.h index 10bd94b751d..d9942a5f9f9 100644 --- a/src/lib/unlang/xlat_priv.h +++ b/src/lib/unlang/xlat_priv.h @@ -40,7 +40,6 @@ extern "C" { typedef fr_slen_t (*xlat_print_t)(fr_sbuff_t *in, xlat_exp_t const *self, void *inst, fr_sbuff_escape_rules_t const *e_rules); - typedef struct xlat_s { fr_rb_node_t node; //!< Entry in the xlat function tree. char const *name; //!< Name of xlat function. @@ -98,7 +97,7 @@ typedef struct { ///< nodes by the time they were created. xlat_t const *func; //!< The xlat expansion to expand format with. - xlat_exp_t *args; //!< arguments to the function call + xlat_exp_head_t *args; //!< arguments to the function call xlat_inst_t *inst; //!< Instance data for the #xlat_t. xlat_thread_inst_t *thread_inst; //!< Thread specific instance. @@ -124,9 +123,9 @@ struct xlat_exp { xlat_exp_t *next; //!< Next in the list. union { - xlat_exp_t *alternate[2]; //!< alternate expansions + xlat_exp_head_t *alternate[2]; //!< alternate expansions - xlat_exp_t *group; //!< children of a group + xlat_exp_head_t *group; //!< children of a group /** An tmpl_t reference * @@ -289,14 +288,14 @@ xlat_action_t xlat_frame_eval_resume(TALLOC_CTX *ctx, fr_dcursor_t *out, request_t *request, fr_value_box_list_t *result, void *rctx); xlat_action_t xlat_frame_eval_repeat(TALLOC_CTX *ctx, fr_dcursor_t *out, - xlat_exp_t const **child, bool *alternate, - request_t *request, xlat_exp_t const *head, xlat_exp_t const **in, + xlat_exp_head_t const **child, bool *alternate, + request_t *request, xlat_exp_head_t const *head, xlat_exp_t const **in, fr_value_box_list_t *result) CC_HINT(nonnull(1,2,3,5,6)); -xlat_action_t xlat_frame_eval(TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_exp_t const **child, - request_t *request, xlat_exp_t const *head, xlat_exp_t const **in); +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); -int xlat_eval_walk(xlat_exp_t *exp, xlat_walker_t walker, xlat_type_t type, void *uctx); +int xlat_eval_walk(xlat_exp_head_t *head, xlat_walker_t walker, xlat_type_t type, void *uctx); int xlat_eval_init(void); @@ -315,13 +314,18 @@ int xlat_register_expressions(void); /* * xlat_tokenize.c */ -int xlat_tokenize_expansion(TALLOC_CTX *ctx, xlat_exp_t **head, xlat_flags_t *flags, fr_sbuff_t *in, +int xlat_tokenize_expansion(TALLOC_CTX *ctx, xlat_exp_head_t **head, xlat_flags_t *flags, fr_sbuff_t *in, tmpl_attr_rules_t const *t_rules); -int xlat_tokenize_function_args(TALLOC_CTX *ctx, xlat_exp_t **head, xlat_flags_t *flags, fr_sbuff_t *in, +int xlat_tokenize_function_args(TALLOC_CTX *ctx, xlat_exp_head_t **head, xlat_flags_t *flags, fr_sbuff_t *in, tmpl_attr_rules_t const *rules); -ssize_t xlat_print_node(fr_sbuff_t *out, xlat_exp_t const *head, fr_sbuff_escape_rules_t const *e_rules); +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); + +static inline xlat_exp_t *xlat_exp_head(xlat_exp_head_t const *head) +{ + return UNCONST(xlat_exp_t *, head); +} /** Iterate over the contents of a list, only one level * @@ -330,18 +334,20 @@ ssize_t xlat_print_node(fr_sbuff_t *out, xlat_exp_t const *head, fr_sbuff_escap * Will be declared in the scope of the loop. */ #define xlat_exp_foreach(_list_head, _iter) \ - for (xlat_exp_t *_iter = UNCONST(xlat_exp_t *, _list_head); _iter; _iter = _iter->next) + for (xlat_exp_t *_iter = xlat_exp_head(_list_head); _iter; _iter = _iter->next) -static inline xlat_exp_t *xlat_exp_head(xlat_exp_t const *head) +static inline xlat_exp_t *xlat_exp_next(UNUSED xlat_exp_head_t const *head, xlat_exp_t const *item) { - return UNCONST(xlat_exp_t *, head); + if (!item->next) return NULL; + + return UNCONST(xlat_exp_t *, item->next); } -static inline xlat_exp_t *xlat_exp_next(UNUSED xlat_exp_t const *head, xlat_exp_t const *item) +static inline bool xlat_exp_is_head(xlat_exp_head_t const *head) { - if (!item->next) return NULL; + return (head && (head->type == XLAT_GROUP)); - return UNCONST(xlat_exp_t *, item->next); +// return (head && head->next && (head->next->type == XLAT_GROUP)); } #ifdef __cplusplus diff --git a/src/lib/unlang/xlat_tokenize.c b/src/lib/unlang/xlat_tokenize.c index 7ec46063e49..398a8aa5d2a 100644 --- a/src/lib/unlang/xlat_tokenize.c +++ b/src/lib/unlang/xlat_tokenize.c @@ -155,9 +155,9 @@ static inline CC_HINT(always_inline) void xlat_exp_set_name_buffer(xlat_exp_t *n * * @param[in,out] head to free. Will be set to NULL */ -void xlat_exp_free(xlat_exp_t **head) +void xlat_exp_free(xlat_exp_head_t **head) { - xlat_exp_t *to_free = *head, *next; + xlat_exp_t *to_free = xlat_exp_head(*head), *next; while (to_free) { next = to_free->next; @@ -1038,7 +1038,7 @@ static fr_table_num_sorted_t const xlat_quote_table[] = { }; static size_t xlat_quote_table_len = NUM_ELEMENTS(xlat_quote_table); -static void _xlat_debug(xlat_exp_t const *head, int depth) +static void _xlat_debug(xlat_exp_head_t const *head, int depth) { #define INFO_INDENT(_fmt, ...) INFO("%*s"_fmt, depth * 2, " ", ## __VA_ARGS__) @@ -1132,19 +1132,17 @@ static void _xlat_debug(xlat_exp_t const *head, int depth) } } -void xlat_debug(xlat_exp_t const *node) +void xlat_debug(xlat_exp_head_t const *head) { - _xlat_debug(node, 0); + _xlat_debug(head, 0); } -ssize_t xlat_print_node(fr_sbuff_t *out, xlat_exp_t const *head, fr_sbuff_escape_rules_t const *e_rules) +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) { ssize_t slen; size_t at_in = fr_sbuff_used_total(out); - xlat_exp_t const *node; char close; - node = xlat_exp_head(head); if (!node) return 0; switch (node->type) { @@ -1294,7 +1292,7 @@ ssize_t xlat_print(fr_sbuff_t *out, xlat_exp_t const *head, fr_sbuff_escape_rule size_t at_in = fr_sbuff_used_total(out); xlat_exp_foreach(head, node) { - slen = xlat_print_node(out, node, e_rules); + slen = xlat_print_node(out, head, node, e_rules); if (slen < 0) return slen - (fr_sbuff_used_total(out) - at_in); } @@ -1320,7 +1318,7 @@ ssize_t xlat_print(fr_sbuff_t *out, xlat_exp_t const *head, fr_sbuff_escape_rule * - 0 and *head != NULL - Zero length expansion * - <0 the negative offset of the parse failure. */ -ssize_t xlat_tokenize_ephemeral(TALLOC_CTX *ctx, xlat_exp_t **head, +ssize_t xlat_tokenize_ephemeral(TALLOC_CTX *ctx, xlat_exp_head_t **head, fr_event_list_t *el, xlat_flags_t *flags, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules) @@ -1378,7 +1376,7 @@ ssize_t xlat_tokenize_ephemeral(TALLOC_CTX *ctx, xlat_exp_t **head, * - <=0 on error. * - >0 on success which is the number of characters parsed. */ -ssize_t xlat_tokenize_argv(TALLOC_CTX *ctx, xlat_exp_t **head, xlat_flags_t *flags, fr_sbuff_t *in, +ssize_t xlat_tokenize_argv(TALLOC_CTX *ctx, xlat_exp_head_t **head, xlat_flags_t *flags, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *p_rules, tmpl_attr_rules_t const *t_rules) { fr_sbuff_t our_in = FR_SBUFF(in); @@ -1548,7 +1546,7 @@ ssize_t xlat_tokenize_argv(TALLOC_CTX *ctx, xlat_exp_t **head, xlat_flags_t *fla * - 0 and *head != NULL - Zero length expansion * - < 0 the negative offset of the parse failure. */ -ssize_t xlat_tokenize(TALLOC_CTX *ctx, xlat_exp_t **head, xlat_flags_t *flags, fr_sbuff_t *in, +ssize_t xlat_tokenize(TALLOC_CTX *ctx, xlat_exp_head_t **head, xlat_flags_t *flags, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *p_rules, tmpl_attr_rules_t const *t_rules) { fr_sbuff_t our_in = FR_SBUFF(in); @@ -1589,7 +1587,7 @@ ssize_t xlat_tokenize(TALLOC_CTX *ctx, xlat_exp_t **head, xlat_flags_t *flags, f * - true if expansion contains only literal elements. * - false if expansion contains expandable elements. */ -bool xlat_is_literal(xlat_exp_t const *head) +bool xlat_is_literal(xlat_exp_head_t const *head) { xlat_exp_foreach(head, node) { if (node->type != XLAT_BOX) return false; @@ -1609,7 +1607,7 @@ bool xlat_is_literal(xlat_exp_t const *head) * - true the tree consists of a single value node which was converted. * - false the tree was more complex than a single literal, op was a noop. */ -bool xlat_to_string(TALLOC_CTX *ctx, char **str, xlat_exp_t **head) +bool xlat_to_string(TALLOC_CTX *ctx, char **str, xlat_exp_head_t **head) { fr_sbuff_t out; fr_sbuff_uctx_talloc_t tctx; @@ -1649,7 +1647,7 @@ bool xlat_to_string(TALLOC_CTX *ctx, char **str, xlat_exp_t **head) * - 0 on success. * - -1 on failure. */ -int xlat_resolve(xlat_exp_t **head, xlat_flags_t *flags, xlat_res_rules_t const *xr_rules) +int xlat_resolve(xlat_exp_head_t **head, xlat_flags_t *flags, xlat_res_rules_t const *xr_rules) { static xlat_res_rules_t xr_default; xlat_flags_t our_flags; @@ -1871,7 +1869,7 @@ tmpl_t *xlat_to_tmpl_attr(TALLOC_CTX *ctx, xlat_exp_t *node) * - 0 on success. * - -1 on failure. */ -int xlat_from_tmpl_attr(TALLOC_CTX *ctx, xlat_exp_t **head, xlat_flags_t *flags, tmpl_t **vpt_p) +int xlat_from_tmpl_attr(TALLOC_CTX *ctx, xlat_exp_head_t **head, xlat_flags_t *flags, tmpl_t **vpt_p) { xlat_exp_t *node; xlat_t *func;