[Asterisk-code-review] cli: Add command to evaluate dialplan functions. (asterisk[master])
Friendly Automation
asteriskteam at digium.com
Tue Apr 26 18:29:52 CDT 2022
Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/17714 )
Change subject: cli: Add command to evaluate dialplan functions.
......................................................................
cli: Add command to evaluate dialplan functions.
Adds the dialplan eval function commands to evaluate a dialplan
function from the CLI. The return value and function result are
printed out and can be used for testing or debugging.
ASTERISK-29820 #close
Change-Id: I833e97ea54c49336aca145330a2adeebfad05209
---
A doc/CHANGES-staging/cli_eval_function.txt
M main/pbx_variables.c
2 files changed, 52 insertions(+), 0 deletions(-)
Approvals:
Joshua Colp: Looks good to me, but someone else must approve
Kevin Harwell: Looks good to me, approved
Friendly Automation: Approved for Submit
diff --git a/doc/CHANGES-staging/cli_eval_function.txt b/doc/CHANGES-staging/cli_eval_function.txt
new file mode 100644
index 0000000..9f7873c
--- /dev/null
+++ b/doc/CHANGES-staging/cli_eval_function.txt
@@ -0,0 +1,5 @@
+Subject: cli
+
+A new CLI command 'dialplan eval function' has been
+added which allows users to test the behavior of
+dialplan function calls directly from the CLI.
diff --git a/main/pbx_variables.c b/main/pbx_variables.c
index 6f7439f..a060bf5 100644
--- a/main/pbx_variables.c
+++ b/main/pbx_variables.c
@@ -924,6 +924,52 @@
return CLI_SUCCESS;
}
+/*! \brief CLI support for executing function */
+static char *handle_eval_function(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+ struct ast_channel *c = NULL;
+ char *fn, *substituted;
+ int ret;
+ char workspace[1024];
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "dialplan eval function";
+ e->usage =
+ "Usage: dialplan eval function <name(args)>\n"
+ " Evaluate a dialplan function call\n"
+ " A dummy channel is used to evaluate\n"
+ " the function call, so only global\n"
+ " variables should be used.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if (a->argc != e->args + 1) {
+ return CLI_SHOWUSAGE;
+ }
+
+ c = ast_dummy_channel_alloc();
+ if (!c) {
+ ast_cli(a->fd, "Unable to allocate bogus channel for function evaluation.\n");
+ return CLI_FAILURE;
+ }
+
+ fn = (char *) a->argv[3];
+ pbx_substitute_variables_helper(c, fn, workspace, sizeof(workspace));
+ substituted = ast_strdupa(workspace);
+ workspace[0] = '\0';
+ ret = ast_func_read(c, substituted, workspace, sizeof(workspace));
+
+ c = ast_channel_unref(c);
+
+ ast_cli(a->fd, "Return Value: %s (%d)\n", ret ? "Failure" : "Success", ret);
+ ast_cli(a->fd, "Result: %s\n", workspace);
+
+ return CLI_SUCCESS;
+}
+
static char *handle_set_global(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
switch (cmd) {
@@ -1218,6 +1264,7 @@
static struct ast_cli_entry vars_cli[] = {
AST_CLI_DEFINE(handle_show_globals, "Show global dialplan variables"),
AST_CLI_DEFINE(handle_show_chanvar, "Show channel variables"),
+ AST_CLI_DEFINE(handle_eval_function, "Evaluate dialplan function"),
AST_CLI_DEFINE(handle_set_global, "Set global dialplan variable"),
AST_CLI_DEFINE(handle_set_chanvar, "Set a channel variable"),
};
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/17714
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: I833e97ea54c49336aca145330a2adeebfad05209
Gerrit-Change-Number: 17714
Gerrit-PatchSet: 7
Gerrit-Owner: N A <mail at interlinked.x10host.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220426/01962beb/attachment.html>
More information about the asterisk-code-review
mailing list