[svn-commits] russell: trunk r98558 - in /trunk: CHANGES main/pbx.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Sat Jan 12 13:34:39 CST 2008


Author: russell
Date: Sat Jan 12 13:34:38 2008
New Revision: 98558

URL: http://svn.digium.com/view/asterisk?view=rev&rev=98558
Log:
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.

Modified:
    trunk/CHANGES
    trunk/main/pbx.c

Modified: trunk/CHANGES
URL: http://svn.digium.com/view/asterisk/trunk/CHANGES?view=diff&rev=98558&r1=98557&r2=98558
==============================================================================
--- trunk/CHANGES (original)
+++ trunk/CHANGES Sat Jan 12 13:34:38 2008
@@ -76,6 +76,7 @@
   * 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
 -----------

Modified: trunk/main/pbx.c
URL: http://svn.digium.com/view/asterisk/trunk/main/pbx.c?view=diff&rev=98558&r1=98557&r2=98558
==============================================================================
--- trunk/main/pbx.c (original)
+++ trunk/main/pbx.c Sat Jan 12 13:34:38 2008
@@ -4931,11 +4931,49 @@
 		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]);
 	ast_cli(a->fd, "\n    -- Global variable %s set to %s\n", a->argv[3], a->argv[4]);
+
+	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;
 }
@@ -5009,6 +5047,7 @@
 	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."),




More information about the svn-commits mailing list