* for the new node can operate
* correctly.
*/
- MEM(node = xlat_exp_func_alloc(xri->ex, xrf->func, xctx->ex->child));
+ MEM(node = xlat_exp_func_alloc(xri->ex, xrf->func, xctx->ex->call.args));
switch (xrf->func->input_type) {
case XLAT_INPUT_UNPROCESSED:
* a copy of the original arguments with each
* function that's called.
*/
- xlat_exp_free(&xctx->ex->child);
+ xlat_exp_free(&xctx->ex->call.args);
return 0;
}
case XLAT_FUNC:
{
- xlat_exp_t const *child = node->child;
+ xlat_exp_t const *arg = node->call.args;
char *out, *n_out;
TALLOC_CTX *pool;
char open = '{', close = '}';
open = '(';
close = ')';
}
- if (!child) return talloc_asprintf(ctx, "%%%c%s:%c", open, node->call.func->name, close);
+ if (!arg) return talloc_asprintf(ctx, "%%%c%s:%c", open, node->call.func->name, close);
out = talloc_asprintf(ctx, "%%%c%s:", open, node->call.func->name);
pool = talloc_pool(NULL, 128); /* Size of a single child (probably ok...) */
do {
- char *child_str;
+ char *arg_str;
- child_str = xlat_fmt_aprint(pool, child);
- if (child_str) {
+ arg_str = xlat_fmt_aprint(pool, arg);
+ if (arg_str) {
if ((first_done) && (node->call.func->input_type == XLAT_INPUT_ARGS)) {
n_out = talloc_strdup_append_buffer(out, " ");
if (!n_out) {
out = n_out;
}
- n_out = talloc_buffer_append_buffer(ctx, out, child_str);
+ n_out = talloc_buffer_append_buffer(ctx, out, arg_str);
if (!n_out) goto child_error;
out = n_out;
first_done = true;
}
talloc_free_children(pool); /* Clear pool contents */
- } while ((child = child->next));
+ } while ((arg = arg->next));
talloc_free(pool);
n_out = talloc_strndup_append_buffer(out, &close, 1);
* we print the concatenated arguments list as
* well as the original fmt string.
*/
- if ((node->type == XLAT_FUNC) && !xlat_is_literal(node->child)) {
+ 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,
* Hand back the child node to the caller
* for evaluation.
*/
- if (node->child) {
- *child = node->child;
+ if (node->call.args) {
+ *child = node->call.args;
xa = XLAT_ACTION_PUSH_CHILD;
goto finish;
}
case XLAT_ALTERNATE:
XLAT_DEBUG("** [%i] %s(alternate) - %%{%%{%s}:-%%{%s}}", unlang_interpret_stack_depth(request),
__FUNCTION__, node->alternate[0]->fmt, node->alternate[1]->fmt);
- fr_assert(node->child == NULL);
fr_assert(node->alternate[0] != NULL);
fr_assert(node->alternate[1] != NULL);
case XLAT_GROUP:
XLAT_DEBUG("** [%i] %s(child) - %%{%s ...}", unlang_interpret_stack_depth(request), __FUNCTION__,
node->fmt);
- if (!node->child) return XLAT_ACTION_DONE;
+ if (!node->group) return XLAT_ACTION_DONE;
/*
* Hand back the child node to the caller
* for evaluation.
*/
- *child = node->child;
+ *child = node->group;
xa = XLAT_ACTION_PUSH_CHILD;
goto finish;
for (i = 0, node = xlat; node != NULL; i++, node = node->next) {
my_argv[i] = NULL;
- slen = _xlat_eval_compiled(my_argv, &my_argv[i], 0, request, node->child, escape, escape_ctx);
+ slen = _xlat_eval_compiled(my_argv, &my_argv[i], 0, request, node->group, escape, escape_ctx);
if (slen < 0) return -i;
}
fr_assert(done_init);
for (i = 0, node = xlat; node != NULL; i++, node = node->next) {
- my_argv[i] = node->child;
+ my_argv[i] = node->group;
}
return count;
/*
* Now evaluate the function's arguments
*/
- if (node->child) {
- ret = xlat_eval_walk(node->child, walker, type, uctx);
+ if (node->call.args) {
+ ret = xlat_eval_walk(node->call.args, walker, type, uctx);
if (ret < 0) return ret;
}
break;
/*
* Now evaluate the function's arguments
*/
- if (node->child) {
- ret = xlat_eval_walk(node->child, walker, type, uctx);
+ if (node->call.args) {
+ ret = xlat_eval_walk(node->call.args, walker, type, uctx);
if (ret < 0) return ret;
}
break;
/*
* Evaluate the child.
*/
- ret = xlat_eval_walk(node->child, walker, type, uctx);
+ ret = xlat_eval_walk(node->group, walker, type, uctx);
if (ret < 0) return ret;
break;
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, node->child, e_rules);
+ xlat_print_node(out, node->call.args, e_rules);
return fr_sbuff_used_total(out) - at_in;
}
size_t at_in = fr_sbuff_used_total(out);
FR_SBUFF_IN_CHAR_RETURN(out, '(');
- xlat_print_node(out, node->child, e_rules); /* prints a space after the first argument */
+ xlat_print_node(out, 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
*/
FR_SBUFF_IN_STRCPY_RETURN(out, fr_tokens[node->call.func->token]);
FR_SBUFF_IN_CHAR_RETURN(out, ' ');
- xlat_print_node(out, node->child->next, e_rules);
+ xlat_print_node(out, node->call.args->next, e_rules);
FR_SBUFF_IN_CHAR_RETURN(out, ')');
{
int rcode = -1;
xlat_t const *func;
- xlat_exp_t *child;
+ xlat_exp_t *arg;
fr_value_box_t *dst = NULL, *box;
- xlat_arg_parser_t const *arg;
+ xlat_arg_parser_t const *arg_p;
xlat_action_t xa;
fr_value_box_list_t input, output;
fr_dcursor_t cursor;
/*
* A child isn't a value-box. We leave it alone.
*/
- for (child = node->child; child != NULL; child = child->next) {
- fr_assert(child->type == XLAT_GROUP);
+ for (arg = node->call.args; arg != NULL; arg = arg->next) {
+ fr_assert(arg->type == XLAT_GROUP);
- if (!xlat_is_box(child->child)) return 0;
- if (child->child->next) return 0;
+ if (!xlat_is_box(arg->group)) return 0;
+ if (arg->group->next) return 0;
}
fr_value_box_list_init(&input);
* have to cast the box to the correct data type (or copy
* it), and then add the box to the source list.
*/
- for (child = node->child, arg = func->args;
- child != NULL;
- child = child->next, arg++) {
+ for (arg = node->call.args, arg_p = func->args;
+ arg != NULL;
+ arg = arg->next, arg_p++) {
MEM(box = fr_value_box_alloc_null(node));
- if ((arg->type != FR_TYPE_VOID) && (arg->type != box->type)) {
- if (fr_value_box_cast(node, box, arg->type, NULL, xlat_box(child->child)) < 0) goto fail;
+ if ((arg_p->type != FR_TYPE_VOID) && (arg_p->type != box->type)) {
+ if (fr_value_box_cast(node, box, arg_p->type, NULL, xlat_box(arg->group)) < 0) goto fail;
- } else if (fr_value_box_copy(node, box, xlat_box(child->child)) < 0) {
+ } else if (fr_value_box_copy(node, box, xlat_box(arg->group)) < 0) {
fail:
talloc_free(box);
goto cleanup;
goto cleanup;
}
- while ((child = node->child) != NULL) {
- node->child = child->next;
- talloc_free(child);
+ while ((arg = node->call.args) != NULL) {
+ node->call.args = arg->next;
+ talloc_free(arg);
}
dst = fr_dcursor_head(&cursor);
group->quote = T_BARE_WORD;
group->fmt = node->fmt; /* not entirely correct, but good enough for now */
- group->child = talloc_steal(group, node);
+ group->group = talloc_steal(group, node);
group->flags = node->flags;
if (node->next) {
/*
* It's already been groupified, don't do anything.
*/
- if (node->child->type == XLAT_GROUP) return;
+ if (node->call.args->type == XLAT_GROUP) return;
- node->child = xlat_groupify_node(node, node->child);
+ node->call.args = xlat_groupify_node(node, node->call.args);
}
static xlat_arg_parser_t const binary_op_xlat_args[] = {
/*
* We might get called before the node is instantiated.
*/
- if (!inst->args) current = node->child;
+ if (!inst->args) current = node->call.args;
fr_assert(current != NULL);
{
xlat_logical_inst_t *inst = talloc_get_type_abort(xctx->inst, xlat_logical_inst_t);
- inst->args = xctx->ex->child;
- xctx->ex->child = NULL;
+ inst->args = xctx->ex->call.args;
+ xctx->ex->call.args = NULL;
inst->sense = (xctx->ex->call.func->token == T_LOR);
return 0;
static xlat_exp_t *xlat_exp_func_alloc_args(TALLOC_CTX *ctx, char const *name, size_t namelen, int argc)
{
int i;
- xlat_exp_t *node, *child, **last;
+ xlat_exp_t *node, *arg, **last;
MEM(node = xlat_exp_alloc(ctx, XLAT_FUNC, name, namelen));
- last = &node->child;
+ last = &node->call.args;
for (i = 0; i < argc; i++) {
- MEM(child = xlat_exp_alloc_null(node));
- xlat_exp_set_type(child, XLAT_GROUP);
- child->quote = T_BARE_WORD;
- *last = child;
- last = &child->next;
+ MEM(arg = xlat_exp_alloc_null(node));
+ xlat_exp_set_type(arg, XLAT_GROUP);
+ arg->quote = T_BARE_WORD;
+ *last = arg;
+ last = &arg->next;
}
return node;
* @todo - purify the node.
*/
if (unary) {
- unary->child = node;
+ unary->call.args = node;
xlat_flags_merge(&unary->flags, &node->flags);
node = unary;
}
fr_assert(lhs->call.func == func);
node = xlat_groupify_node(lhs, rhs);
- last = &lhs->child;
+ last = &lhs->call.args;
/*
* Find the last child.
node->call.func = func;
node->flags = func->flags;
- node->child = xlat_groupify_node(node, lhs);
- node->child->flags = lhs->flags;
+ node->call.args = xlat_groupify_node(node, lhs);
+ node->call.args->flags = lhs->flags;
- node->child->next = xlat_groupify_node(node, rhs);
- node->child->next->flags = rhs->flags;
+ node->call.args->next = xlat_groupify_node(node, rhs);
+ node->call.args->next->flags = rhs->flags;
xlat_flags_merge(&node->flags, &lhs->flags);
xlat_flags_merge(&node->flags, &rhs->flags);
///< 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_inst_t *inst; //!< Instance data for the #xlat_t.
xlat_thread_inst_t *thread_inst; //!< Thread specific instance.
///< ONLY USED FOR EPHEMERAL XLATS.
xlat_type_t type; //!< type of this expansion.
xlat_exp_t *next; //!< Next in the list.
- xlat_exp_t *child; //!< Nested expansion, i.e. arguments for an xlat function.
-
union {
xlat_exp_t *alternate[2]; //!< alternate expansions
+ xlat_exp_t *group; //!< children of a group
+
/** An tmpl_t reference
*
* May be an attribute to expand, or an exec reference, or a value-box, ...
MEM(node = xlat_exp_alloc(ctx, XLAT_FUNC, func->name, strlen(func->name)));
node->call.func = func;
- if (unlikely(xlat_copy(node, &node->child, args) < 0)) {
+ if (unlikely(xlat_copy(node, &node->call.args, args) < 0)) {
talloc_free(node);
return NULL;
}
{
fr_assert(node->type == XLAT_FUNC);
- if (node->call.func->args && node->call.func->args->required && !node->child) {
+ if (node->call.func->args && node->call.func->args->required && !node->call.args) {
fr_strerror_const("Missing required input");
return -1;
}
* Now parse the child nodes that form the
* function's arguments.
*/
- if (xlat_tokenize_string(node, &node->child, &node->flags, in, true, &xlat_expansion_rules, rules) < 0) {
+ if (xlat_tokenize_string(node, &node->call.args, &node->flags, in, true, &xlat_expansion_rules, rules) < 0) {
goto error;
}
int xlat_validate_function_args(xlat_exp_t *node)
{
xlat_arg_parser_t const *arg_p;
- xlat_exp_t *child = node->child;
+ xlat_exp_t *arg = node->call.args;
fr_assert(node->type == XLAT_FUNC);
for (arg_p = node->call.func->args; arg_p->type != FR_TYPE_NULL; arg_p++) {
if (!arg_p->required) break;
- if (!child) {
+ if (!arg) {
fr_strerror_printf("Missing required arg %u",
(unsigned int)(arg_p - node->call.func->args) + 1);
return -1;
* All arguments MUST be put into a group, even
* if they're just one element.
*/
- fr_assert(child->type == XLAT_GROUP);
+ fr_assert(arg->type == XLAT_GROUP);
- child = child->next;
+ arg = arg->next;
}
return 0;
* Now parse the child nodes that form the
* function's arguments.
*/
- if (xlat_tokenize_argv(node, &node->child, &node->flags, in, &xlat_multi_arg_rules, rules) < 0) {
+ if (xlat_tokenize_argv(node, &node->call.args, &node->flags, in, &xlat_multi_arg_rules, rules) < 0) {
goto error;
}
case XLAT_GROUP:
INFO_INDENT("child \"%s\"", node->fmt);
INFO_INDENT("{");
- _xlat_debug(node->child, depth + 1);
+ _xlat_debug(node->group, depth + 1);
INFO_INDENT("}");
break;
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->vpt) != NUM_ANY) {
INFO_INDENT("{");
INFO_INDENT("ref %d", tmpl_request(node->vpt));
case XLAT_FUNC:
fr_assert(node->call.func != NULL);
INFO_INDENT("xlat (%s)", node->call.func->name);
- if (node->child) {
+ if (node->call.args) {
INFO_INDENT("{");
- _xlat_debug(node->child, depth + 1);
+ _xlat_debug(node->call.args, depth + 1);
INFO_INDENT("}");
}
break;
case XLAT_FUNC_UNRESOLVED:
INFO_INDENT("xlat-unresolved (%s)", node->fmt);
- if (node->child) {
+ if (node->call.args) {
INFO_INDENT("{");
- _xlat_debug(node->child, depth + 1);
+ _xlat_debug(node->call.args, depth + 1);
INFO_INDENT("}");
}
break;
#endif
case XLAT_ALTERNATE:
- fr_assert(node->child == NULL);
DEBUG("XLAT-IF {");
_xlat_debug(node->alternate[0], depth + 1);
DEBUG("}");
switch (node->type) {
case XLAT_GROUP:
if (node->quote != T_BARE_WORD) FR_SBUFF_IN_CHAR_RETURN(out, fr_token_quote[node->quote]);
- xlat_print(out, node->child, fr_value_escape_by_quote[node->quote]);
+ xlat_print(out, node->group, fr_value_escape_by_quote[node->quote]);
if (node->quote != T_BARE_WORD) FR_SBUFF_IN_CHAR_RETURN(out, fr_token_quote[node->quote]);
if (node->next) FR_SBUFF_IN_CHAR_RETURN(out, ' '); /* Add ' ' between args */
goto done;
FR_SBUFF_IN_BSTRCPY_BUFFER_RETURN(out, node->call.func->name);
FR_SBUFF_IN_CHAR_RETURN(out, ':');
- if (node->child) {
- slen = xlat_print(out, node->child, &xlat_escape);
+ if (node->call.args) {
+ slen = xlat_print(out, node->call.args, &xlat_escape);
if (slen < 0) goto error;
}
break;
FR_SBUFF_IN_BSTRCPY_BUFFER_RETURN(out, node->fmt);
FR_SBUFF_IN_CHAR_RETURN(out, ':');
- if (node->child) {
- slen = xlat_print(out, node->child, &xlat_escape);
+ if (node->call.args) {
+ slen = xlat_print(out, node->call.args, &xlat_escape);
if (slen < 0) goto error;
}
break;
* Barewords --may-contain=%{expansions}
*/
case T_BARE_WORD:
- if (xlat_tokenize_string(node, &node->child, &node->flags, &our_in,
+ if (xlat_tokenize_string(node, &node->group, &node->flags, &our_in,
false, our_p_rules, t_rules) < 0) {
error:
if (our_p_rules != &value_parse_rules_bareword_quoted) {
* "Double quoted strings may contain %{expansions}"
*/
case T_DOUBLE_QUOTED_STRING:
- if (xlat_tokenize_string(node, &node->child, &node->flags, &our_in,
+ if (xlat_tokenize_string(node, &node->group, &node->flags, &our_in,
false, &value_parse_rules_double_quoted, t_rules) < 0) goto error;
xlat_flags_merge(flags, &node->flags);
break;
{
char *str;
- node->child = xlat_exp_alloc_null(node);
- xlat_exp_set_type(node->child, XLAT_BOX);
+ node->group = xlat_exp_alloc_null(node);
+ xlat_exp_set_type(node->group, XLAT_BOX);
- slen = fr_sbuff_out_aunescape_until(node->child, &str, &our_in, SIZE_MAX,
+ slen = fr_sbuff_out_aunescape_until(node->group, &str, &our_in, SIZE_MAX,
value_parse_rules_single_quoted.terminals,
value_parse_rules_single_quoted.escapes);
if (slen < 0) goto error;
- xlat_exp_set_name_buffer_shallow(node->child, str);
- fr_value_box_strdup_shallow(&node->child->data, NULL, str, false);
+ xlat_exp_set_name_buffer_shallow(node->group, str);
+ fr_value_box_strdup_shallow(&node->group->data, NULL, str, false);
xlat_flags_merge(flags, &node->flags);
}
break;
switch (node->type) {
case XLAT_GROUP:
- if (xlat_resolve(&node->child, &node->flags, xr_rules) < 0) return -1;
+ if (xlat_resolve(&node->group, &node->flags, xr_rules) < 0) return -1;
break;
/*
* A resolved function with unresolved args
*/
case XLAT_FUNC:
- if (xlat_resolve(&node->child, &node->flags, xr_rules) < 0) return -1;
+ if (xlat_resolve(&node->call.args, &node->flags, xr_rules) < 0) return -1;
break;
/*
* We can't tell if it's just the function
* that needs resolving or its children too.
*/
- if (xlat_resolve(&node->child, &child_flags, xr_rules) < 0) return -1;
+ if (xlat_resolve(&node->call.args, &child_flags, xr_rules) < 0) return -1;
/*
* Try and find the function
*/
node->call.func = p->call.func;
node->call.ephemeral = p->call.ephemeral;
- if (unlikely(xlat_copy(node, &node->child, p->child) < 0)) goto error;
+ if (unlikely(xlat_copy(node, &node->call.args, p->call.args) < 0)) goto error;
break;
case XLAT_TMPL:
break;
case XLAT_GROUP:
- if (unlikely(xlat_copy(node, &node->child, p->child) < 0)) goto error;
+ if (unlikely(xlat_copy(node, &node->group, p->group) < 0)) goto error;
break;
}