From: Alan T. DeKok Date: Tue, 10 May 2022 21:24:31 +0000 (-0400) Subject: remove flags from xlat some functions. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c6d003bb3e1485832d398f0ee19f6e7d3a54693a;p=thirdparty%2Ffreeradius-server.git remove flags from xlat some functions. expose an API to get at the few flags which are needed. move tmpls to use the API --- diff --git a/src/bin/unit_test_attribute.c b/src/bin/unit_test_attribute.c index 6cbf49721d9..d3c02acd14d 100644 --- a/src/bin/unit_test_attribute.c +++ b/src/bin/unit_test_attribute.c @@ -2780,7 +2780,7 @@ static size_t command_xlat_argv(command_result_t *result, command_file_ctx_t *cc size_t input_len = strlen(in); char buff[1024]; - slen = xlat_tokenize_argv(cc->tmp_ctx, &head, NULL, &FR_SBUFF_IN(in, input_len), + slen = xlat_tokenize_argv(cc->tmp_ctx, &head, &FR_SBUFF_IN(in, input_len), NULL, &(tmpl_attr_rules_t) { .dict_def = cc->tmpl_rules.attr.dict_def ? diff --git a/src/lib/server/tmpl_tokenize.c b/src/lib/server/tmpl_tokenize.c index 9cdc6b577a5..ed63da35e61 100644 --- a/src/lib/server/tmpl_tokenize.c +++ b/src/lib/server/tmpl_tokenize.c @@ -2691,12 +2691,14 @@ ssize_t tmpl_afrom_substr(TALLOC_CTX *ctx, tmpl_t **out, if (!head) return slen; - if (flags.needs_resolving) UNRESOLVED_SET(&type); + if (xlat_needs_resolving(head)) UNRESOLVED_SET(&type); tmpl_init(vpt, type, quote, fr_sbuff_start(&our_in), slen, t_rules); vpt->data.xlat.ex = head; vpt->data.xlat.flags = flags; + fr_assert(xlat_needs_resolving(head) == flags.needs_resolving); + *out = vpt; TMPL_VERIFY(vpt); @@ -2908,7 +2910,9 @@ ssize_t tmpl_afrom_substr(TALLOC_CTX *ctx, tmpl_t **out, * If the string actually contains an xlat * store the compiled xlat. */ - if (flags.needs_resolving) UNRESOLVED_SET(&type); + if (xlat_needs_resolving(head)) UNRESOLVED_SET(&type); + + fr_assert(xlat_needs_resolving(head) == flags.needs_resolving); tmpl_init(vpt, type, quote, fr_sbuff_start(&our_in), slen, t_rules); vpt->data.xlat.ex = head; @@ -2932,14 +2936,16 @@ ssize_t tmpl_afrom_substr(TALLOC_CTX *ctx, tmpl_t **out, * FIXME - We need an ephemeral version of this * too. */ - slen = xlat_tokenize_argv(vpt, &head, &flags, &our_in, p_rules, &t_rules->attr); + slen = xlat_tokenize_argv(vpt, &head, &our_in, p_rules, &t_rules->attr); if (slen < 0) { fr_sbuff_advance(&our_in, slen * -1); talloc_free(vpt); return slen; } - if (flags.needs_resolving) UNRESOLVED_SET(&type); + if (xlat_needs_resolving(head)) UNRESOLVED_SET(&type); + + fr_assert(xlat_needs_resolving(head) == flags.needs_resolving); tmpl_init(vpt, type, quote, fr_sbuff_start(&our_in), slen, t_rules); vpt->data.xlat.ex = head; @@ -2985,7 +2991,9 @@ ssize_t tmpl_afrom_substr(TALLOC_CTX *ctx, tmpl_t **out, * will need expanding before evaluation, and can never * be pre-compiled. */ - if (flags.needs_resolving) UNRESOLVED_SET(&type); + if (xlat_needs_resolving(head)) UNRESOLVED_SET(&type); + + fr_assert(xlat_needs_resolving(head) == flags.needs_resolving); tmpl_init(vpt, type, quote, fr_sbuff_start(&our_in), slen, t_rules); vpt->data.xlat.ex = head; @@ -3721,7 +3729,9 @@ int tmpl_attr_to_xlat(TALLOC_CTX *ctx, tmpl_t **vpt_p) return -1; } - if (vpt->data.xlat.flags.needs_resolving) UNRESOLVED_SET(&vpt->type); + if (xlat_needs_resolving(vpt->data.xlat.ex)) UNRESOLVED_SET(&vpt->type); + + fr_assert(xlat_needs_resolving(vpt->data.xlat.ex) == vpt->data.xlat.flags.needs_resolving); *vpt_p = vpt; @@ -4484,15 +4494,16 @@ void tmpl_verify(char const *file, int line, tmpl_t const *vpt) break; case TMPL_TYPE_XLAT_UNRESOLVED: - if (!tmpl_xlat_flags(vpt)->needs_resolving) { - fr_fatal_assert_fail("CONSISTENCY CHECK FAILED %s[%u]: TMPL_TYPE_XLAT_UNRESOLVED " - "does not have xlat_flags_t -> need_pass2 set", file, line); - } - if (!tmpl_xlat(vpt)) { - fr_fatal_assert_fail("CONSISTENCY CHECK FAILED %s[%u]: TMPL_TYPE_XLAT_UNRESOLVED " + if (!vpt->data.xlat.ex) { + fr_fatal_assert_fail("CONSISTENCY CHECK FAILED %s[%u]: TMPL_TYPE_XLAT " "has a NULL xlat.ex field", file, line); } + + if (!xlat_needs_resolving(vpt->data.xlat.ex)) { + fr_fatal_assert_fail("CONSISTENCY CHECK FAILED %s[%u]: TMPL_TYPE_XLAT_UNRESOLVED " + "does not have 'needs resolving' flag set", file, line); + } break; case TMPL_TYPE_XLAT: diff --git a/src/lib/server/trigger.c b/src/lib/server/trigger.c index 247b53e7bf0..c8f5fcee1b1 100644 --- a/src/lib/server/trigger.c +++ b/src/lib/server/trigger.c @@ -414,7 +414,7 @@ int trigger_exec(unlang_interpret_t *intp, trigger->command = talloc_strdup(trigger, value); trigger->timeout = fr_time_delta_from_sec(5); /* FIXME - Should be configurable? */ - slen = xlat_tokenize_argv(trigger, &trigger->xlat, NULL, + slen = xlat_tokenize_argv(trigger, &trigger->xlat, &FR_SBUFF_IN(trigger->command, talloc_array_length(trigger->command) - 1), NULL, NULL); if (slen <= 0) { char *spaces, *text; diff --git a/src/lib/unlang/xlat.h b/src/lib/unlang/xlat.h index 32fc8b329b7..2fb38b51ca7 100644 --- a/src/lib/unlang/xlat.h +++ b/src/lib/unlang/xlat.h @@ -304,7 +304,7 @@ ssize_t xlat_tokenize_ephemeral(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_argv(TALLOC_CTX *ctx, xlat_exp_head_t **head, xlat_flags_t *flags, fr_sbuff_t *in, +ssize_t xlat_tokenize_argv(TALLOC_CTX *ctx, xlat_exp_head_t **head, 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_head_t **head, xlat_flags_t *flags, fr_sbuff_t *in, @@ -324,6 +324,8 @@ void xlat_debug(xlat_exp_head_t const *head); bool xlat_is_literal(xlat_exp_head_t const *head); +bool xlat_needs_resolving(xlat_exp_head_t const *head); + bool xlat_to_string(TALLOC_CTX *ctx, char **str, xlat_exp_head_t **head); int xlat_resolve(xlat_exp_head_t *head, xlat_flags_t *flags, xlat_res_rules_t const *xr_rules); diff --git a/src/lib/unlang/xlat_tokenize.c b/src/lib/unlang/xlat_tokenize.c index 8517e3ce87d..4d90ee20eda 100644 --- a/src/lib/unlang/xlat_tokenize.c +++ b/src/lib/unlang/xlat_tokenize.c @@ -516,9 +516,10 @@ int xlat_tokenize_function_args(TALLOC_CTX *ctx, xlat_exp_t **out, * Now parse the child nodes that form the * function's arguments. */ - if (xlat_tokenize_argv(node, &node->call.args, &node->flags, in, &xlat_multi_arg_rules, rules) < 0) { + if (xlat_tokenize_argv(node, &node->call.args, in, &xlat_multi_arg_rules, rules) < 0) { goto error; } + xlat_flags_merge(&node->flags, &node->call.args->flags); /* * Check we have all the required arguments @@ -1371,8 +1372,6 @@ ssize_t xlat_tokenize_ephemeral(TALLOC_CTX *ctx, xlat_exp_head_t **out, * manipulation by xlat instantiation functions * later. * @param[out] out the head of the xlat list / tree structure. - * @param[out] flags Populated with parameters that control xlat - * evaluation and multi-pass parsing. * @param[in] in the format string to expand. * @param[in] p_rules controlling how to parse the string outside of * any expansions. @@ -1381,7 +1380,7 @@ ssize_t xlat_tokenize_ephemeral(TALLOC_CTX *ctx, xlat_exp_head_t **out, * - <=0 on error. * - >0 on success which is the number of characters parsed. */ -ssize_t xlat_tokenize_argv(TALLOC_CTX *ctx, xlat_exp_head_t **out, xlat_flags_t *flags, fr_sbuff_t *in, +ssize_t xlat_tokenize_argv(TALLOC_CTX *ctx, xlat_exp_head_t **out, 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); @@ -1530,7 +1529,6 @@ ssize_t xlat_tokenize_argv(TALLOC_CTX *ctx, xlat_exp_head_t **out, xlat_flags_t if (our_p_rules != &value_parse_rules_bareword_quoted) talloc_const_free(our_p_rules->terminals); *out = head; - if (flags) xlat_flags_merge(flags, &head->flags); return fr_sbuff_set(in, &our_in); } @@ -1597,6 +1595,18 @@ bool xlat_is_literal(xlat_exp_head_t const *head) return true; } +/** Check to see if the expansion needs resolving + * + * @param[in] head to check. + * @return + * - true if expansion needs resolving + * - false otherwise + */ +bool xlat_needs_resolving(xlat_exp_head_t const *head) +{ + return head->flags.needs_resolving; +} + /** Convert an xlat node to an unescaped literal string and free the original node * * This is really "unparse the xlat nodes, and convert back to their original string".