Index: cli.c =================================================================== RCS file: /usr/cvsroot/asterisk/cli.c,v retrieving revision 1.72 diff -u -r1.72 cli.c --- cli.c 5 Feb 2005 16:49:14 -0000 1.72 +++ cli.c 26 Feb 2005 22:56:40 -0000 @@ -438,6 +438,10 @@ "Usage: show channel \n" " Shows lots of information about the specified channel.\n"; +static char showexten_help[] = +"Usage: show extension \n" +" Shows total of active channels on the specified extension.\n"; + static char debugchan_help[] = "Usage: debug channel \n" " Enables debugging on a specific channel.\n"; @@ -644,7 +648,74 @@ ast_cli(fd, "Debugging on new channels is disabled\n"); return RESULT_SUCCESS; } - + + +static int handle_showexten(int fd, int argc, char *argv[]) { + struct ast_channel *c=NULL; + struct ast_context *cont=NULL; + int numexten = 0; + int context_existence = 0; + char *exten = NULL; + char *context = NULL; + + if (argc != 3) + return RESULT_SHOWUSAGE; + + char *splitter = ast_strdupa(argv[2]); + /* is there a '@' character? */ + if (splitter && strchr(argv[2], '@')) { + /* yes, split into exten & context ... */ + exten = strsep(&splitter, "@"); + context = splitter; + /* check for length and change to NULL if ast_strlen_zero() */ + if (ast_strlen_zero(exten)) exten = NULL; + if (ast_strlen_zero(context)) context = NULL; + /* check for that context existence */ + cont = ast_walk_contexts(NULL); + while ( cont ) { + if ( !context || !strcmp(ast_get_context_name(cont), context) ) { + context_existence = 1; + } + cont = ast_walk_contexts(cont); + } + } else { + /* no '@' char, only context given */ + exten = argv[2]; + } + + if ( context && !context_existence ) { + ast_cli(fd,"There is no existence of '%s' context\n",context); + return RESULT_FAILURE; + } + + + + c = ast_channel_walk_locked(NULL); + while(c) { + if ( context ) { + if ( !strcmp(exten,c->exten) && !strcmp(context,c->context) ) { + numexten++; + } + + } else { + if ( !strcmp(exten,c->exten) ) { + numexten++; + } + + } + ast_mutex_unlock(&c->lock); + c = ast_channel_walk_locked(c); + } + if ( context ) { + ast_cli(fd,"Extension %s (%s) is currently used on %d channel(s)\n",exten,context,numexten); + } else { + ast_cli(fd,"Extension %s is currently used on %d channel(s)\n",exten,numexten); + + } + + + return RESULT_SUCCESS; +} static int handle_showchan(int fd, int argc, char *argv[]) @@ -798,6 +869,7 @@ { { "set", "verbose", NULL }, handle_set_verbose, "Set level of verboseness", set_verbose_help }, { { "show", "channel", NULL }, handle_showchan, "Display information on a specific channel", showchan_help, complete_ch_3 }, { { "show", "channels", NULL }, handle_chanlist, "Display information on channels", chanlist_help }, + { { "show", "extension", NULL }, handle_showexten, "Display total users on the specific extension", showexten_help }, { { "show", "modules", NULL }, handle_modlist, "List modules and info", modlist_help }, { { "show", "modules", "like", NULL }, handle_modlist, "List modules and info", modlist_help, complete_mod_4 }, { { "show", "uptime", NULL }, handle_showuptime, "Show uptime information", uptime_help },