Skip to content

Commit

Permalink
remove old-style functions %(foo:bar)
Browse files Browse the repository at this point in the history
  • Loading branch information
alandekok committed Mar 26, 2024
1 parent 9270490 commit 622ed9c
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 127 deletions.
2 changes: 1 addition & 1 deletion doc/antora/modules/installation/pages/upgrade.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,7 @@ will no longer work.

=== rlm_winbind

The `winbind` module uses an expansion `%(winbind.group(<name>)` instead of
The `winbind` module uses an expansion `%winbind.group(<name>)` instead of
`Winbind-Group == <name>`.

== Deleted Modules
Expand Down
4 changes: 2 additions & 2 deletions doc/antora/modules/raddb/pages/mods-available/client.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ map client [<ipaddr>] { // <1>
[options="header,autowidth"]
|===
| XLAT | Description
| `%client(<field>)` | Expands to a field in the client definition.
| `%(client(<field>, <ipaddr>)` | Expands to a field in the client definition specified by `<ipaddr>`.
| `%client(<field>)` | Expands to the named _field_ in the current client definition.
| `%client(<field>, <ipaddr>)` | Expands to the named _field_ in the client specified by _ipaddr_.
|===


Expand Down
4 changes: 2 additions & 2 deletions raddb/mods-available/client
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@
# [options="header,autowidth"]
# |===
# | XLAT | Description
# | `%client(<field>)` | Expands to a field in the client definition.
# | `%(client(<field>, <ipaddr>)` | Expands to a field in the client definition specified by `<ipaddr>`.
# | `%client(<field>)` | Expands to the named _field_ in the current client definition.
# | `%client(<field>, <ipaddr>)` | Expands to the named _field_ in the client specified by _ipaddr_.
# |===
#

Expand Down
3 changes: 0 additions & 3 deletions src/lib/unlang/xlat_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,6 @@ int xlat_register_expressions(void);
int xlat_tokenize_expansion(xlat_exp_head_t *head, fr_sbuff_t *in,
tmpl_rules_t const *t_rules);

int xlat_tokenize_function_args(xlat_exp_head_t *head, fr_sbuff_t *in,
tmpl_rules_t const *t_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, char c);

Expand Down
123 changes: 4 additions & 119 deletions src/lib/unlang/xlat_tokenize.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,7 @@ static fr_sbuff_escape_rules_t const xlat_escape = {
* The caller sets the literal parse rules for outside of expansions when they
* call xlat_tokenize.
*/
static fr_sbuff_parse_rules_t const xlat_multi_arg_rules = {
.escapes = &xlat_unescape,
.terminals = &FR_SBUFF_TERM(")") /* These get merged with other literal terminals */
};

static fr_sbuff_parse_rules_t const xlat_new_arg_rules = {
static fr_sbuff_parse_rules_t const xlat_function_arg_rules = {
.escapes = &xlat_unescape,
.terminals = &FR_SBUFF_TERMS( /* These get merged with other literal terminals */
L(")"),
Expand Down Expand Up @@ -278,107 +273,6 @@ int xlat_validate_function_args(xlat_exp_t *node)
return 0;
}

/** Parse an xlat function and its child arguments
*
* Parses a function call string in the format
* @verbatim %(<func>:<arguments>) @endverbatim
*
* @return
* - 0 if the string was parsed into a function.
* - <0 on parse error.
*/
int xlat_tokenize_function_args(xlat_exp_head_t *head, fr_sbuff_t *in, tmpl_rules_t const *t_rules)
{
xlat_exp_t *node;
xlat_t *func;
fr_sbuff_marker_t m_s;

/*
* Special characters, spaces, etc. cannot be
* module names.
*/
XLAT_DEBUG("FUNC-ARGS <-- %.*s", (int) fr_sbuff_remaining(in), fr_sbuff_current(in));

/*
* %(function:args)
*/
fr_sbuff_marker(&m_s, in);
fr_sbuff_adv_past_allowed(in, SIZE_MAX, xlat_func_chars, NULL);

if (!fr_sbuff_is_char(in, ':')) {
fr_strerror_const("Can't find function/argument separator");
bad_function:
fr_sbuff_set(in, &m_s); /* backtrack */
fr_sbuff_marker_release(&m_s);
return -1;
}

func = xlat_func_find(fr_sbuff_current(&m_s), fr_sbuff_behind(&m_s));

/*
* Allocate a node to hold the function
*/
node = xlat_exp_alloc(head, XLAT_FUNC, fr_sbuff_current(&m_s), fr_sbuff_behind(&m_s));
if (!func) {
if (!t_rules || !t_rules->attr.allow_unresolved || t_rules->at_runtime) {
fr_strerror_const("Unresolved expansion functions are not allowed here");
goto bad_function;
}
xlat_exp_set_type(node, XLAT_FUNC_UNRESOLVED);
node->flags.needs_resolving = true; /* Needs resolution during pass2 */
} else {
if (func->input_type != XLAT_INPUT_ARGS) {
fr_strerror_const("Function should be called using %{func:arg} syntax");
error:
talloc_free(node);
return -1;
}
node->call.func = func;
if (t_rules) node->call.dict = t_rules->attr.dict_def;
node->flags = func->flags;
}

/*
* Record the calling style, this is useful
* for checking later with unresolved
* functions, for printing accurate debug
* info, and for weird xlats like the
* redundant xlat
*/
node->call.input_type = XLAT_INPUT_ARGS;

fr_sbuff_next(in); /* Skip the ':' */
XLAT_DEBUG("FUNC-ARGS <-- %s ... %.*s", node->fmt, (int) fr_sbuff_remaining(in), fr_sbuff_current(in));

fr_sbuff_marker_release(&m_s);

/*
* Now parse the child nodes that form the
* function's arguments.
*/
if (xlat_tokenize_argv(node, &node->call.args, in, func, &xlat_multi_arg_rules, t_rules, false, false) < 0) {
goto error;
}
xlat_flags_merge(&node->flags, &node->call.args->flags);

/*
* Check we have all the required arguments
*/
if (node->type == XLAT_FUNC) {
if (xlat_validate_function_args(node) < 0) goto error;

node->flags.can_purify = (node->call.func->flags.pure && node->call.args->flags.pure) | node->call.args->flags.can_purify;
}

if (!fr_sbuff_next_if_char(in, ')')) {
fr_strerror_const("Missing closing brace");
goto error;
}

xlat_exp_insert_tail(head, node);
return 0;
}

/** Parse an xlat function and its child argument
*
* Parses a function call string in the format
Expand All @@ -388,7 +282,7 @@ int xlat_tokenize_function_args(xlat_exp_head_t *head, fr_sbuff_t *in, tmpl_rule
* - 0 if the string was parsed into a function.
* - <0 on parse error.
*/
static int xlat_tokenize_function_new(xlat_exp_head_t *head, fr_sbuff_t *in, tmpl_rules_t const *t_rules)
static int xlat_tokenize_function_args(xlat_exp_head_t *head, fr_sbuff_t *in, tmpl_rules_t const *t_rules)
{
char c;
xlat_exp_t *node;
Expand Down Expand Up @@ -502,7 +396,7 @@ static int xlat_tokenize_function_new(xlat_exp_head_t *head, fr_sbuff_t *in, tmp
* function's arguments.
*/
if (xlat_tokenize_argv(node, &node->call.args, in, func,
&xlat_new_arg_rules, t_rules, true, (node->call.input_type == XLAT_INPUT_MONO)) < 0) {
&xlat_function_arg_rules, t_rules, true, (node->call.input_type == XLAT_INPUT_MONO)) < 0) {
error:
talloc_free(node);
return -1;
Expand Down Expand Up @@ -988,15 +882,6 @@ static int xlat_tokenize_input(xlat_exp_head_t *head, fr_sbuff_t *in,
continue;
}

/*
* xlat function call with discrete arguments
*/
if (fr_sbuff_adv_past_str_literal(in, "%(")) {
TALLOC_FREE(node); /* nope, couldn't use it */
if (xlat_tokenize_function_args(head, in, t_rules) < 0) goto error;
goto next;
}

/*
* More migration hacks: allow %foo(...)
*/
Expand All @@ -1016,7 +901,7 @@ static int xlat_tokenize_input(xlat_exp_head_t *head, fr_sbuff_t *in,
/*
* Tokenize the function arguments using the new method.
*/
if (xlat_tokenize_function_new(head, in, t_rules) < 0) goto error;
if (xlat_tokenize_function_args(head, in, t_rules) < 0) goto error;
goto next;
}

Expand Down

0 comments on commit 622ed9c

Please sign in to comment.