diff options
author | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-01-12 19:34:38 +0000 |
---|---|---|
committer | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-01-12 19:34:38 +0000 |
commit | 8e7cfc7450242952ea63bff093874edaa3e66bd5 (patch) | |
tree | c08bd83f5228be8374250c22b7bdaa69c346f2d2 | |
parent | 0b178b776f11ff1805863957044d1c4bd5ba4ea2 (diff) |
Add a new CLI command, "core set chanvar", which allows you to set a channel
variable (or function) on an active channel from the CLI.
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@98558 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r-- | CHANGES | 1 | ||||
-rw-r--r-- | main/pbx.c | 41 |
2 files changed, 41 insertions, 1 deletions
@@ -76,6 +76,7 @@ CLI Changes * Enhanced "agi debug" to print the channel name as a prefix to the debug output to make debugging on busy systems much easier. * New CLI commands "dialplan set extenpatternmatching true/false" + * New CLI command: "core set chanvar" to set a channel variable from the CLI. SIP changes ----------- diff --git a/main/pbx.c b/main/pbx.c index 6da44b7c3..0c0be0b93 100644 --- a/main/pbx.c +++ b/main/pbx.c @@ -4931,7 +4931,7 @@ static char *handle_set_global(struct ast_cli_entry *e, int cmd, struct ast_cli_ return NULL; } - if (a->argc != 5) + if (a->argc != e->args + 2) return CLI_SHOWUSAGE; pbx_builtin_setvar_helper(NULL, a->argv[3], a->argv[4]); @@ -4940,6 +4940,44 @@ static char *handle_set_global(struct ast_cli_entry *e, int cmd, struct ast_cli_ return CLI_SUCCESS; } +static char *handle_set_chanvar(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) +{ + struct ast_channel *chan; + const char *chan_name, *var_name, *var_value; + + switch (cmd) { + case CLI_INIT: + e->command = "core set chanvar"; + e->usage = + "Usage: core set chanvar <channel> <varname> <value>\n" + " Set channel variable <varname> to <value>\n"; + return NULL; + case CLI_GENERATE: + return ast_complete_channels(a->line, a->word, a->pos, a->n, 3); + } + + if (a->argc != e->args + 3) + return CLI_SHOWUSAGE; + + chan_name = a->argv[e->args]; + var_name = a->argv[e->args + 1]; + var_value = a->argv[e->args + 2]; + + if (!(chan = ast_get_channel_by_name_locked(chan_name))) { + ast_cli(a->fd, "Channel '%s' not found\n", chan_name); + return CLI_FAILURE; + } + + pbx_builtin_setvar_helper(chan, var_name, var_value); + + ast_channel_unlock(chan); + + ast_cli(a->fd, "\n -- Channel variable '%s' set to '%s' for '%s'\n", + var_name, var_value, chan_name); + + return CLI_SUCCESS; +} + static char *handle_set_extenpatternmatchnew(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { int oldval = 0; @@ -5009,6 +5047,7 @@ static struct ast_cli_entry pbx_cli[] = { AST_CLI_DEFINE(handle_show_function, "Describe a specific dialplan function"), AST_CLI_DEFINE(handle_show_application, "Describe a specific dialplan application"), AST_CLI_DEFINE(handle_set_global, "Set global dialplan variable"), + AST_CLI_DEFINE(handle_set_chanvar, "Set a channel variable"), AST_CLI_DEFINE(handle_show_dialplan, "Show dialplan"), AST_CLI_DEFINE(handle_unset_extenpatternmatchnew, "Use the Old extension pattern matching algorithm."), AST_CLI_DEFINE(handle_set_extenpatternmatchnew, "Use the New extension pattern matching algorithm."), |