From: Alan T. DeKok Date: Wed, 19 Jan 2022 14:28:32 +0000 (-0500) Subject: rename XLAT_ATTRIBUTE to XLAT_TMPL X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e65a7244413981ee7485a57e9664a0c5aacdd6a;p=thirdparty%2Ffreeradius-server.git rename XLAT_ATTRIBUTE to XLAT_TMPL in preparation for making RHS of expressions into TMPLs, too --- diff --git a/src/lib/unlang/xlat_eval.c b/src/lib/unlang/xlat_eval.c index 266d5d70025..5abbcd13102 100644 --- a/src/lib/unlang/xlat_eval.c +++ b/src/lib/unlang/xlat_eval.c @@ -110,7 +110,7 @@ static char *xlat_fmt_aprint(TALLOC_CTX *ctx, xlat_exp_t const *node) case XLAT_ONE_LETTER: return talloc_asprintf(ctx, "%%%s", node->fmt); - case XLAT_ATTRIBUTE: + case XLAT_TMPL: return talloc_asprintf(ctx, "%%{%s}", node->fmt); case XLAT_VIRTUAL: @@ -1245,12 +1245,13 @@ xlat_action_t xlat_frame_eval(TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_exp_t con fr_dlist_move(out->dlist, &result); continue; - case XLAT_ATTRIBUTE: + case XLAT_TMPL: XLAT_DEBUG("** [%i] %s(attribute) - %%{%s}", unlang_interpret_stack_depth(request), __FUNCTION__, node->fmt); xlat_debug_log_expansion(request, node, NULL); - if (xlat_eval_pair_real(ctx, &result, request, node->attr) == XLAT_ACTION_FAIL) goto fail; + + if (xlat_eval_pair_real(ctx, &result, request, node->vpt) == XLAT_ACTION_FAIL) goto fail; xlat_debug_log_list_result(request, &result); fr_dlist_move(out->dlist, &result); diff --git a/src/lib/unlang/xlat_expr.c b/src/lib/unlang/xlat_expr.c index fa1b45cae48..37481ac96f3 100644 --- a/src/lib/unlang/xlat_expr.c +++ b/src/lib/unlang/xlat_expr.c @@ -636,7 +636,7 @@ check_more: tmpl_t *vpt = NULL; MEM(node = xlat_exp_alloc_null(ctx)); - xlat_exp_set_type(node, XLAT_ATTRIBUTE); + xlat_exp_set_type(node, XLAT_TMPL); slen = tmpl_afrom_attr_substr(node, NULL, &vpt, &in, p_rules, t_rules); if (slen <= 0) { @@ -646,7 +646,7 @@ check_more: } xlat_exp_set_name_buffer_shallow(node, vpt->name); - node->attr = vpt; + node->vpt = vpt; goto done; } @@ -818,7 +818,7 @@ done: /* * Wrap the result in a cast. * - * @todo - if the node is an XLAT_ATTR or XLAT_BOX and is already of the correct data type, then reparent + * @todo - if the node is an XLAT_TMPL or XLAT_BOX and is already of the correct data type, then reparent * "node" to the parent of "cast", and free "cast". */ if (cast) { @@ -1004,8 +1004,9 @@ redo: * If the LHS is typed, try to parse the RHS as the given * type. Otherwise, don't parse the RHS using enums. */ - if (lhs->type == XLAT_ATTRIBUTE) { - da = tmpl_da(lhs->attr); + if (lhs->type == XLAT_TMPL) { + fr_assert(tmpl_is_attr(lhs->vpt) || tmpl_is_list(lhs->vpt)); + da = tmpl_da(lhs->vpt); } else { da = NULL; } diff --git a/src/lib/unlang/xlat_priv.h b/src/lib/unlang/xlat_priv.h index fdfc4daa0b8..d00aa778719 100644 --- a/src/lib/unlang/xlat_priv.h +++ b/src/lib/unlang/xlat_priv.h @@ -83,9 +83,9 @@ typedef enum { XLAT_FUNC_UNRESOLVED = 0x0008, //!< func needs resolution during pass2. XLAT_VIRTUAL = 0x0010, //!< virtual attribute XLAT_VIRTUAL_UNRESOLVED = 0x0020, //!< virtual attribute needs resolution during pass2. - XLAT_ATTRIBUTE = 0x0040, //!< xlat attribute + XLAT_TMPL = 0x0040, //!< xlat attribute #ifdef HAVE_REGEX - XLAT_REGEX = 0x0080, //!< regex reference + XLAT_REGEX = 0x0080, //!< regex reference %{1}, etc. #endif XLAT_ALTERNATE = 0x0100, //!< xlat conditional syntax :- XLAT_GROUP = 0x0200 //!< encapsulated string of xlats @@ -128,11 +128,11 @@ struct xlat_exp { union { xlat_exp_t *alternate; //!< Alternative expansion if this expansion produced no values. - /** An attribute reference + /** An tmpl_t reference * - * May be an attribute to expand, or provide context for a call. + * May be an attribute to expand, or an exec reference, or a value-box, ... */ - tmpl_t *attr; + tmpl_t *vpt; /** A capture group, i.e. for %{1} and friends */ diff --git a/src/lib/unlang/xlat_tokenize.c b/src/lib/unlang/xlat_tokenize.c index b380590e359..5fe9e21a9db 100644 --- a/src/lib/unlang/xlat_tokenize.c +++ b/src/lib/unlang/xlat_tokenize.c @@ -669,16 +669,16 @@ static inline int xlat_tokenize_attribute(TALLOC_CTX *ctx, xlat_exp_t **head, xl */ xlat_exp_set_type(node, XLAT_VIRTUAL_UNRESOLVED); xlat_exp_set_name_buffer_shallow(node, vpt->name); - node->attr = vpt; + node->vpt = vpt; node->flags.needs_resolving = true; /* * Deal with normal attribute (or list) */ } else { do_attr: - xlat_exp_set_type(node, XLAT_ATTRIBUTE); + xlat_exp_set_type(node, XLAT_TMPL); xlat_exp_set_name_buffer_shallow(node, vpt->name); - node->attr = vpt; + node->vpt = vpt; } done: @@ -1046,21 +1046,21 @@ static void _xlat_debug(xlat_exp_t const *node, int depth) INFO_INDENT("percent (%c)", node->fmt[0]); break; - case XLAT_ATTRIBUTE: - fr_assert(tmpl_da(node->attr) != NULL); - INFO_INDENT("attribute (%s)", tmpl_da(node->attr)->name); + case XLAT_TMPL: + fr_assert(tmpl_da(node->vpt) != NULL); + INFO_INDENT("attribute (%s)", tmpl_da(node->vpt)->name); fr_assert(node->child == NULL); - if (tmpl_num(node->attr) != NUM_ANY) { + if (tmpl_num(node->vpt) != NUM_ANY) { INFO_INDENT("{"); - INFO_INDENT("ref %d", tmpl_request(node->attr)); - INFO_INDENT("list %d", tmpl_list(node->attr)); - if (tmpl_num(node->attr) != NUM_ANY) { - if (tmpl_num(node->attr) == NUM_COUNT) { + INFO_INDENT("ref %d", tmpl_request(node->vpt)); + INFO_INDENT("list %d", tmpl_list(node->vpt)); + if (tmpl_num(node->vpt) != NUM_ANY) { + if (tmpl_num(node->vpt) == NUM_COUNT) { INFO_INDENT("[#]"); - } else if (tmpl_num(node->attr) == NUM_ALL) { + } else if (tmpl_num(node->vpt) == NUM_ALL) { INFO_INDENT("[*]"); } else { - INFO_INDENT("[%d]", tmpl_num(node->attr)); + INFO_INDENT("[%d]", tmpl_num(node->vpt)); } } INFO_INDENT("}"); @@ -1194,8 +1194,8 @@ static ssize_t xlat_print_node(fr_sbuff_t *out, xlat_exp_t const *head, fr_sbuff } switch (node->type) { - case XLAT_ATTRIBUTE: - slen = tmpl_attr_print(out, node->attr, TMPL_ATTR_REF_PREFIX_NO); + case XLAT_TMPL: + slen = tmpl_attr_print(out, node->vpt, TMPL_ATTR_REF_PREFIX_NO); if (slen < 0) { error: return slen; @@ -1774,13 +1774,13 @@ int xlat_resolve(xlat_exp_t **head, xlat_flags_t *flags, xlat_res_rules_t const */ case XLAT_VIRTUAL_UNRESOLVED: { - if (xlat_resolve_virtual_attribute(node, node->attr) == 0) break; + if (xlat_resolve_virtual_attribute(node, node->vpt) == 0) break; /* * Try and resolve (in-place) as an attribute */ - if ((tmpl_resolve(node->attr, xr_rules->tr_rules) < 0) || - (node->attr->type != TMPL_TYPE_ATTR)) { + if ((tmpl_resolve(node->vpt, xr_rules->tr_rules) < 0) || + (node->vpt->type != TMPL_TYPE_ATTR)) { /* * FIXME - Produce proper error with marker */ @@ -1798,7 +1798,7 @@ int xlat_resolve(xlat_exp_t **head, xlat_flags_t *flags, xlat_res_rules_t const * Just need to flip the type as the tmpl * should already have been fixed up */ - xlat_exp_set_type(node, XLAT_ATTRIBUTE); + xlat_exp_set_type(node, XLAT_TMPL); /* * Reset node flags @@ -1807,7 +1807,7 @@ int xlat_resolve(xlat_exp_t **head, xlat_flags_t *flags, xlat_res_rules_t const } break; - case XLAT_ATTRIBUTE: + case XLAT_TMPL: if (!xr_rules->allow_unresolved) goto error_unresolved; break; @@ -1837,18 +1837,18 @@ tmpl_t *xlat_to_tmpl_attr(TALLOC_CTX *ctx, xlat_exp_t *node) { tmpl_t *vpt; - if (node->next || (node->type != XLAT_ATTRIBUTE) || !tmpl_is_attr(node->attr)) return NULL; + if (node->next || (node->type != XLAT_TMPL) || !tmpl_is_attr(node->vpt)) return NULL; /* * Concat means something completely different as an attribute reference * Count isn't implemented. */ - if ((tmpl_num(node->attr) == NUM_COUNT) || (tmpl_num(node->attr) == NUM_ALL)) return NULL; + if ((tmpl_num(node->vpt) == NUM_COUNT) || (tmpl_num(node->vpt) == NUM_ALL)) return NULL; vpt = tmpl_alloc(ctx, TMPL_TYPE_ATTR, T_BARE_WORD, node->fmt, talloc_array_length(node->fmt) - 1); if (!vpt) return NULL; - tmpl_attr_copy(vpt, node->attr); + tmpl_attr_copy(vpt, node->vpt); TMPL_VERIFY(vpt); @@ -1890,7 +1890,7 @@ int xlat_from_tmpl_attr(TALLOC_CTX *ctx, xlat_exp_t **head, xlat_flags_t *flags, * the assignment of the tmpl to the new * xlat expression */ - node->attr = talloc_move(node, vpt_p); + node->vpt = talloc_move(node, vpt_p); node->flags = (xlat_flags_t) { .needs_resolving = true }; *head = node; xlat_flags_merge(flags, &node->flags); @@ -1899,7 +1899,7 @@ int xlat_from_tmpl_attr(TALLOC_CTX *ctx, xlat_exp_t **head, xlat_flags_t *flags, virtual: node = xlat_exp_alloc(ctx, XLAT_VIRTUAL, vpt->name, vpt->len); - node->attr = talloc_move(node, vpt_p); + node->vpt = talloc_move(node, vpt_p); node->call.func = func; node->flags = func->flags; @@ -1911,8 +1911,8 @@ int xlat_from_tmpl_attr(TALLOC_CTX *ctx, xlat_exp_t **head, xlat_flags_t *flags, } } - node = xlat_exp_alloc(ctx, XLAT_ATTRIBUTE, vpt->name, vpt->len); - node->attr = talloc_move(node, vpt_p); + node = xlat_exp_alloc(ctx, XLAT_TMPL, vpt->name, vpt->len); + node->vpt = talloc_move(node, vpt_p); return 0; } @@ -1982,8 +1982,8 @@ int xlat_copy(TALLOC_CTX *ctx, xlat_exp_t **out, xlat_exp_t const *in) if (unlikely(xlat_copy(node, &node->child, p->child) < 0)) goto error; break; - case XLAT_ATTRIBUTE: - node->attr = tmpl_copy(node, p->attr); + case XLAT_TMPL: + node->vpt = tmpl_copy(node, p->vpt); continue; #ifdef HAVE_REGEX