[svn-commits] rizzo: branch rizzo/astobj2 r47501 - /team/rizzo/astobj2/channels/chan_sip.c

svn-commits at lists.digium.com svn-commits at lists.digium.com
Sun Nov 12 07:48:02 MST 2006


Author: rizzo
Date: Sun Nov 12 08:48:01 2006
New Revision: 47501

URL: http://svn.digium.com/view/asterisk?view=rev&rev=47501
Log:
merge version 47439, fix some CLI commands.

There are certainly a few things that
the recent CLI changes have taught me:

1. CLI handlers should be passed a pointer to the entry that
   calls them, so the handlers could grab the base value
   for argument checking directly from the entry, and
   changes in the syntax (or even adding prefixes) would
   be a lot simpler to implement and debug.

2. having the implementation of a command split in 4 places
   (the ast_cli entry, the handler, the _complete() function, and
   the _usage string) is a guarantee to have inconsistent info.
   Take e.g. sip_debug(), complete_sip_debug_peer(), debug_usage.

I believe the right way to do this is have just one handler
function that, depending on the call arguments, does the following:
1.- returns the usage message
2.- implements the 'complete' functionality;
3.- implements the command itself
4.- possibly, even returns a strings with the actual command
    to be installed in the "ast_cli" entry.

This way everything would be in the same place and it is trivial
to find inconsistencies.


Modified:
    team/rizzo/astobj2/channels/chan_sip.c

Modified: team/rizzo/astobj2/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/astobj2/channels/chan_sip.c?view=diff&rev=47501&r1=47500&r2=47501
==============================================================================
--- team/rizzo/astobj2/channels/chan_sip.c (original)
+++ team/rizzo/astobj2/channels/chan_sip.c Sun Nov 12 08:48:01 2006
@@ -11152,9 +11152,10 @@
 	int port = 0;
 	char *p, *arg;
 
-	if (argc != 4)
+	/* sip set debug ip <ip> */
+	if (argc != 5)
 		return RESULT_SHOWUSAGE;
-	p = arg = argv[3];
+	p = arg = argv[4];
 	strsep(&p, ":");
 	if (p)
 		port = atoi(p);
@@ -11179,9 +11180,9 @@
 static int sip_do_debug_peer(int fd, int argc, char *argv[])
 {
 	struct sip_peer *peer;
-	if (argc != 4)
+	if (argc != 5)
 		return RESULT_SHOWUSAGE;
-	peer = find_peer(argv[3], NULL, 1);
+	peer = find_peer(argv[4], NULL, 1);
 	if (peer) {
 		if (peer->addr.sin_addr.s_addr) {
 			debugaddr.sin_family = AF_INET;
@@ -11193,7 +11194,7 @@
 			ast_cli(fd, "Unable to get IP address of peer '%s'\n", argv[3]);
 		unref_peer(peer);
 	} else
-		ast_cli(fd, "No such peer '%s'\n", argv[3]);
+		ast_cli(fd, "No such peer '%s'\n", argv[4]);
 	return RESULT_SUCCESS;
 }
 
@@ -11201,12 +11202,12 @@
 static int sip_do_debug(int fd, int argc, char *argv[])
 {
 	int oldsipdebug = sipdebug_console;
-	if (argc != 2) {
-		if (argc != 4) 
+	if (argc != 4) {
+		if (argc != 5) 
 			return RESULT_SHOWUSAGE;
-		else if (strcmp(argv[2], "ip") == 0)
+		else if (strcmp(argv[3], "ip") == 0)
 			return sip_do_debug_ip(fd, argc, argv);
-		else if (strcmp(argv[2], "peer") == 0)
+		else if (strcmp(argv[3], "peer") == 0)
 			return sip_do_debug_peer(fd, argc, argv);
 		else
 			return RESULT_SHOWUSAGE;
@@ -11277,7 +11278,7 @@
 /*! \brief Disable SIP Debugging in CLI */
 static int sip_no_debug(int fd, int argc, char *argv[])
 {
-	if (argc != 3)
+	if (argc != 4)
 		return RESULT_SHOWUSAGE;
 	ast_clear_flag(&global_flags[1], SIP_PAGE2_DEBUG_CONSOLE);
 	ast_cli(fd, "SIP Debugging Disabled\n");
@@ -11578,8 +11579,7 @@
 
 static char sip_reload_usage[] =
 "Usage: sip reload\n"
-"       Reloads SIP configuration from sip.conf\n"
-"       Deprecated:  please use 'reload chan_sip.so'\n";
+"       Reloads SIP configuration from sip.conf\n";
 
 static char show_subscriptions_usage[] =
 "Usage: sip show subscriptions\n" 
@@ -17377,12 +17377,6 @@
 /*! \brief Force reload of module from cli */
 static int sip_reload(int fd, int argc, char *argv[])
 {
-	static int deprecated = 0;
-	if (!deprecated && argc > 0) {
-		ast_log(LOG_WARNING, "\"sip reload\" is deprecated.  Please use 'reload chan_sip.so' instead.\n");
-		deprecated = 1;
-	}
-
 	ast_mutex_lock(&sip_reload_lock);
 	if (sip_reloading) 
 		ast_verbose("Previous SIP reload not yet done\n");
@@ -17475,19 +17469,19 @@
 	sip_prune_realtime, "Prune cached Realtime user(s)",
 	prune_realtime_usage, complete_sip_prune_realtime_user },
 
-	{ { "sip", "debug", NULL },
+	{ { "sip", "set", "debug", NULL },
 	sip_do_debug, "Enable SIP debugging",
 	debug_usage },
 
-	{ { "sip", "debug", "ip", NULL },
+	{ { "sip", "set", "debug", "ip", NULL },
 	sip_do_debug, "Enable SIP debugging on IP",
 	debug_usage },
 
-	{ { "sip", "debug", "peer", NULL },
+	{ { "sip", "set", "debug", "peer", NULL },
 	sip_do_debug, "Enable SIP debugging on Peername",
 	debug_usage, complete_sip_debug_peer },
 
-	{ { "sip", "debug", "off", NULL },
+	{ { "sip", "set", "debug", "off", NULL },
 	sip_no_debug, "Disable SIP debugging",
 	no_debug_usage },
 



More information about the svn-commits mailing list