[asterisk-commits] rizzo: branch rizzo/astobj2 r47826 - /team/rizzo/astobj2/channels/chan_sip.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Sat Nov 18 13:01:28 MST 2006


Author: rizzo
Date: Sat Nov 18 14:01:28 2006
New Revision: 47826

URL: http://svn.digium.com/view/asterisk?view=rev&rev=47826
Log:
move "sip show {channels|subscriptions}" to the new CLI structure


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=47826&r1=47825&r2=47826
==============================================================================
--- team/rizzo/astobj2/channels/chan_sip.c (original)
+++ team/rizzo/astobj2/channels/chan_sip.c Sat Nov 18 14:01:28 2006
@@ -1458,10 +1458,6 @@
 static int sip_show_settings(int fd, int argc, char *argv[]);
 static const char *subscription_type2str(enum subscriptiontype subtype) attribute_pure;
 static const struct cfsubscription_types *find_subscription_type(enum subscriptiontype subtype);
-static int __sip_show_channels(int fd, int argc, char *argv[], int subscriptions);
-static int sip_show_channels(int fd, int argc, char *argv[]);
-static int sip_show_subscriptions(int fd, int argc, char *argv[]);
-static int __sip_show_channels(int fd, int argc, char *argv[], int subscriptions);
 static char *complete_sipch(const char *line, const char *word, int pos, int state);
 static char *complete_sip_peer(const char *word, int state, int flags2);
 static char *complete_sip_show_peer(const char *line, const char *word, int pos, int state);
@@ -10748,18 +10744,6 @@
 	return &subscription_types[0];
 }
 
-/*! \brief Show active SIP channels */
-static int sip_show_channels(int fd, int argc, char *argv[])  
-{
-        return __sip_show_channels(fd, argc, argv, 0);
-}
- 
-/*! \brief Show active SIP subscriptions */
-static int sip_show_subscriptions(int fd, int argc, char *argv[])
-{
-        return __sip_show_channels(fd, argc, argv, 1);
-}
-
 struct __show_chan_arg {
 	int fd;
 	int subscriptions;
@@ -10806,19 +10790,30 @@
 	return 0;	/* don't care, we scan all channels */
 }
 
-/*! \brief SIP show channels CLI (main function) */
-static int __sip_show_channels(int fd, int argc, char *argv[], int subscriptions)
+/*! \brief CLI for show channels or subscriptions */
+static char *sip_show_channels(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	struct sip_pvt *cur;
-	struct __show_chan_arg arg = { .fd = fd, .subscriptions = subscriptions, .numchans = 0 };
-
-	if (argc != 3)
-		return RESULT_SHOWUSAGE;
-
-	if (!subscriptions)
-		ast_cli(fd, FORMAT2, "Peer", "User/ANR", "Call ID", "Seq (Tx/Rx)", "Format", "Hold", "Last Message");
+	struct __show_chan_arg arg = { .fd = a->fd, .numchans = 0 };
+
+	if (cmd == CLI_INIT) {
+		e->command = "sip show {channels|subscriptions}";
+		e->usage =
+			"Usage: sip show channels\n"
+			"       Lists all currently active SIP channels.\n"
+			"Usage: sip show subscriptions\n" 
+			"       Lists active SIP subscriptions for extension states\n";
+		return NULL;
+	} else if (cmd == CLI_GENERATE)
+		return NULL;
+
+	if (a->argc != e->args)
+		return CLI_SHOWUSAGE;
+	arg.subscriptions = !strcasecmp(a->argv[e->args - 1], "subscriptions");
+	if (arg.subscriptions)
+		ast_cli(arg.fd, FORMAT2, "Peer", "User/ANR", "Call ID", "Seq (Tx/Rx)", "Format", "Hold", "Last Message");
 	else 
-		ast_cli(fd, FORMAT3, "Peer", "User", "Call ID", "Extension", "Last state", "Type", "Mailbox");
+		ast_cli(arg.fd, FORMAT3, "Peer", "User", "Call ID", "Extension", "Last state", "Type", "Mailbox");
 #ifdef USE_AO2
 	cur = NULL;	/* silence compiler */
         ao2_callback(dialogs, OBJ_MULTIPLE|OBJ_NODATA, show_channels_cb, &arg);
@@ -10829,11 +10824,10 @@
 	}
 	dialoglist_unlock();
 #endif
-	if (!subscriptions)
-		ast_cli(fd, "%d active SIP channel%s\n", arg.numchans, (arg.numchans != 1) ? "s" : "");
-	else
-		ast_cli(fd, "%d active SIP subscription%s\n", arg.numchans, (arg.numchans != 1) ? "s" : "");
-	return RESULT_SUCCESS;
+	ast_cli(arg.fd, "%d active SIP %s%s\n", arg.numchans,
+			(arg.subscriptions ? "subscription" : "channel"),
+			(arg.numchans != 1) ? "s" : "");
+	return CLI_SUCCESS;
 #undef FORMAT
 #undef FORMAT2
 #undef FORMAT3
@@ -11647,9 +11641,6 @@
 "       List all SIP users and peers usage counters and limits.\n"
 "       Add option \"all\" to show all devices, not only those with a limit.\n";
 
-static char show_channels_usage[] = 
-"Usage: sip show channels\n"
-"       Lists all currently active SIP channels.\n";
 
 static char show_channel_usage[] = 
 "Usage: sip show channel <channel>\n"
@@ -11703,10 +11694,6 @@
 static char sip_reload_usage[] =
 "Usage: sip reload\n"
 "       Reloads SIP configuration from sip.conf\n";
-
-static char show_subscriptions_usage[] =
-"Usage: sip show subscriptions\n" 
-"       Lists active SIP subscriptions for extension states\n";
 
 static char show_objects_usage[] =
 "Usage: sip show objects\n" 
@@ -17495,9 +17482,7 @@
 
 /*! \brief SIP Cli commands definition */
 static struct ast_cli_entry cli_sip[] = {
-	{ { "sip", "show", "channels", NULL },
-	sip_show_channels, "List active SIP channels",
-	show_channels_usage },
+	NEW_CLI(sip_show_channels, "List active SIP channels/subscriptions"),
 
 	{ { "sip", "show", "domains", NULL },
 	sip_show_domains, "List our local SIP domains.",
@@ -17522,10 +17507,6 @@
 	{ { "sip", "show", "settings", NULL },
 	sip_show_settings, "Show SIP global settings",
 	show_settings_usage },
-
-	{ { "sip", "show", "subscriptions", NULL },
-	sip_show_subscriptions, "List active SIP subscriptions",
-	show_subscriptions_usage },
 
 	{ { "sip", "show", "users", NULL },
 	sip_show_users, "List defined SIP users",



More information about the asterisk-commits mailing list