[Asterisk-code-review] cli: Add command to evaluate dialplan functions (asterisk[master])
N A
asteriskteam at digium.com
Sun Dec 26 15:41:15 CST 2021
N A has uploaded this change for review. ( 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
---
M main/pbx_variables.c
1 file changed, 42 insertions(+), 0 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/14/17714/1
diff --git a/main/pbx_variables.c b/main/pbx_variables.c
index 7a85989..bb7e385 100644
--- a/main/pbx_variables.c
+++ b/main/pbx_variables.c
@@ -922,6 +922,47 @@
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 *evalvalue;
+ int ret;
+ char workspace[1024];
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "dialplan eval function";
+ e->usage =
+ "Usage: dialplan eval function <function>\n"
+ " Evaluate a dialplan function\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;
+ }
+
+ ret = ast_func_read(c, (char *) a->argv[3], workspace, sizeof(workspace));
+
+ evalvalue = workspace;
+
+ c = ast_channel_unref(c);
+
+ ast_cli(a->fd, "Retval: %d\n", ret);
+ ast_cli(a->fd, "Result: %s\n", evalvalue);
+
+ return CLI_SUCCESS;
+}
+
static char *handle_set_global(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
switch (cmd) {
@@ -1216,6 +1257,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: 1
Gerrit-Owner: N A <mail at interlinked.x10host.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20211226/0d934b10/attachment.html>
More information about the asterisk-code-review
mailing list