]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
move check for brace to calling function
authorAlan T. DeKok <aland@freeradius.org>
Tue, 26 Sep 2023 20:23:01 +0000 (16:23 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 26 Sep 2023 20:23:01 +0000 (16:23 -0400)
so xlat_tokenize_input() does not need to do it.

src/lib/unlang/xlat_tokenize.c

index bf21e11c6d6f2c6605b058c8b71d3c7589bfc646..fff00a5f2bae8142492d4b536b95e4316a4a7dc6 100644 (file)
@@ -136,7 +136,7 @@ xlat_exp_t *xlat_exp_func_alloc(TALLOC_CTX *ctx, xlat_t *func, xlat_exp_head_t c
        return node;
 }
 
-static int xlat_tokenize_input(xlat_exp_head_t *head, fr_sbuff_t *in, bool brace,
+static int xlat_tokenize_input(xlat_exp_head_t *head, fr_sbuff_t *in,
                                fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules);
 
 static inline int xlat_tokenize_alternation(xlat_exp_head_t *head, fr_sbuff_t *in,
@@ -172,17 +172,18 @@ static inline int xlat_tokenize_alternation(xlat_exp_head_t *head, fr_sbuff_t *i
         *      Parse the alternate expansion.
         */
        if (xlat_tokenize_input(node->alternate[1], in,
-                                true, &xlat_expansion_rules, t_rules) < 0) goto error;
+                               &xlat_expansion_rules, t_rules) < 0) goto error;
 
-       if (!xlat_exp_head(node->alternate[1])) {
-               fr_strerror_const("Empty expansion is invalid");
+       if (!fr_sbuff_next_if_char(in, '}')) {
+               fr_strerror_const("Missing closing brace");
                goto error;
        }
 
-       if (!fr_sbuff_next_if_char(in, '}')) {
-               fr_strerror_const("Missing closing brace");
+       if (!xlat_exp_head(node->alternate[1])) {
+               fr_strerror_const("Empty expansion is invalid");
                goto error;
        }
+
        xlat_flags_merge(&node->flags, &node->alternate[1]->flags);
 
 done:
@@ -355,9 +356,10 @@ static inline int xlat_tokenize_function_mono(xlat_exp_head_t *head,
        bareword:
                arg_group->quote = T_BARE_WORD;
 
-               if (xlat_tokenize_input(arg_group->group, in, true, &xlat_expansion_rules, t_rules) < 0) {
+               if (xlat_tokenize_input(arg_group->group, in, &xlat_expansion_rules, t_rules) < 0) {
                        goto error;
                }
+
                xlat_flags_merge(&arg_group->flags, &arg_group->group->flags);
        /*
         *      Support passing the monolithic argument
@@ -392,7 +394,7 @@ static inline int xlat_tokenize_function_mono(xlat_exp_head_t *head,
        } else if (fr_sbuff_next_if_char(in, '"')) {
                arg_group->quote = T_DOUBLE_QUOTED_STRING;
 
-               if (xlat_tokenize_input(arg_group->group, in, false,
+               if (xlat_tokenize_input(arg_group->group, in,
                                         &value_parse_rules_double_quoted, t_rules) < 0) {
                        goto error;
                }
@@ -996,16 +998,14 @@ int xlat_tokenize_expansion(xlat_exp_head_t *head, fr_sbuff_t *in,
  * @param[out] head            to allocate nodes in, and where to write the first
  *                             child, and where the flags are stored.
  * @param[in] in               sbuff to parse.
- * @param[in] brace            true if we're inside a braced expansion, else false.
  * @param[in] p_rules          that control parsing.
  * @param[in] t_rules          that control attribute reference and xlat function parsing.
  * @return
  *     - 0 on success.
  *     - -1 on failure.
  */
-static int xlat_tokenize_input(xlat_exp_head_t *head,
-                               fr_sbuff_t *in, bool brace,
-                               fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules)
+static int xlat_tokenize_input(xlat_exp_head_t *head, fr_sbuff_t *in,
+                              fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules)
 {
        xlat_exp_t                      *node = NULL;
        fr_slen_t                       slen;
@@ -1145,20 +1145,9 @@ static int xlat_tokenize_input(xlat_exp_head_t *head,
                }
 
                /*
-                *      We were told to look for a brace, but we ran off of
-                *      the end of the string before we found one.
-                */
-               if (brace) {
-                       if (slen == 0) TALLOC_FREE(node); /* Free the empty node */
-
-                       if (!fr_sbuff_is_char(in, '}')) {
-                               fr_strerror_const("Missing closing brace");
-                               goto error;
-                       }
-               /*
-                *      Empty input, emit no arguments
+                *      Nothing we recognize.  Just return nothing.
                 */
-               } else if (slen == 0) {
+               if (slen == 0) {
                        TALLOC_FREE(node);
                        XLAT_DEBUG("VALUE-BOX <-- (empty)");
                }
@@ -1568,7 +1557,7 @@ fr_slen_t xlat_tokenize_ephemeral(TALLOC_CTX *ctx, xlat_exp_head_t **out,
        our_t_rules.xlat.runtime_el = el;
 
        fr_strerror_clear();    /* Clear error buffer */
-       if (xlat_tokenize_input(head, &our_in, false, p_rules, &our_t_rules) < 0) {
+       if (xlat_tokenize_input(head, &our_in, p_rules, &our_t_rules) < 0) {
                talloc_free(head);
                FR_SBUFF_ERROR_RETURN(&our_in);
        }
@@ -1665,7 +1654,7 @@ fr_slen_t xlat_tokenize_argv(TALLOC_CTX *ctx, xlat_exp_head_t **out, fr_sbuff_t
                 */
                case T_BARE_WORD:
                        if (xlat_tokenize_input(node->group, &our_in,
-                                                 false, our_p_rules, t_rules) < 0) {
+                                               our_p_rules, t_rules) < 0) {
                        error:
                                if (our_p_rules != &value_parse_rules_bareword_quoted) {
                                        talloc_const_free(our_p_rules->terminals);
@@ -1681,7 +1670,7 @@ fr_slen_t xlat_tokenize_argv(TALLOC_CTX *ctx, xlat_exp_head_t **out, fr_sbuff_t
                 */
                case T_DOUBLE_QUOTED_STRING:
                        if (xlat_tokenize_input(node->group, &our_in,
-                                                 false, &value_parse_rules_double_quoted, t_rules) < 0) goto error;
+                                               &value_parse_rules_double_quoted, t_rules) < 0) goto error;
                        break;
 
                /*
@@ -1789,7 +1778,7 @@ fr_slen_t xlat_tokenize(TALLOC_CTX *ctx, xlat_exp_head_t **out, fr_sbuff_t *in,
 
        fr_strerror_clear();    /* Clear error buffer */
 
-       if (xlat_tokenize_input(head, &our_in, false, p_rules, t_rules) < 0) {
+       if (xlat_tokenize_input(head, &our_in, p_rules, t_rules) < 0) {
                talloc_free(head);
                FR_SBUFF_ERROR_RETURN(&our_in);
        }