summaryrefslogtreecommitdiff
path: root/cli.c
diff options
context:
space:
mode:
authorRussell Bryant <russell@russellbryant.com>2005-12-07 15:36:55 +0000
committerRussell Bryant <russell@russellbryant.com>2005-12-07 15:36:55 +0000
commitcac0f4d09550c44e570850b1cbf9de9127499b8c (patch)
treee5dc40ad9425950e8cb0338dd3f260705381898a /cli.c
parente2f674787bbb280fe9fc67b8a1fe3b46ef848faa (diff)
This is the first round of removing applications that were marked as deprecated
in the 1.2 release. They are being removed from the trunk and will not be in the next major release. The following is a list of the applications that are being removed in this commit: Curl, Cut, Sort, DBPut, DBGet, ENUMLookup, Eval GetGroupCount, SetGroup, CheckGroup, GetGroupMatchCount MD5, MD5Check, Math, SetCIDName, SetCIDNum, SetRDNIS, SetCallerID TXTCIDName, AbsoluteTimeout, DigitTimeout, ResponseTimeout, SetAccount SetLanguage, SetVar (renamed to Set) These changes also include moving the "group show channels" cli command from app_groupcount.c to cli.c. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@7379 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'cli.c')
-rw-r--r--cli.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/cli.c b/cli.c
index 8ea63ca78..f1a241e40 100644
--- a/cli.c
+++ b/cli.c
@@ -29,6 +29,7 @@
#include <signal.h>
#include <string.h>
#include <ctype.h>
+#include <regex.h>
#include "asterisk.h"
@@ -42,6 +43,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/channel.h"
#include "asterisk/manager.h"
#include "asterisk/utils.h"
+#include "asterisk/app.h"
#include "asterisk/lock.h"
/* For rl_filename_completion */
#include "editline/readline/readline.h"
@@ -125,6 +127,12 @@ static char softhangup_help[] =
" Request that a channel be hung up. The hangup takes effect\n"
" the next time the driver reads or writes from the channel\n";
+static char group_show_channels_help[] =
+"Usage: group show channels [pattern]\n"
+" Lists all currently active channels with channel group(s) specified.\n"
+" Optional regular expression pattern is matched to group names for each\n"
+" channel.\n";
+
static int handle_load(int fd, int argc, char *argv[])
{
if (argc != 2)
@@ -887,6 +895,55 @@ static char *complete_fn(char *line, char *word, int pos, int state)
return c ? strdup(c) : c;
}
+static int group_show_channels(int fd, int argc, char *argv[])
+{
+#define FORMAT_STRING "%-25s %-20s %-20s\n"
+
+ struct ast_channel *c = NULL;
+ int numchans = 0;
+ struct ast_var_t *current;
+ struct varshead *headp;
+ regex_t regexbuf;
+ int havepattern = 0;
+
+ if (argc < 3 || argc > 4)
+ return RESULT_SHOWUSAGE;
+
+ if (argc == 4) {
+ if (regcomp(&regexbuf, argv[3], REG_EXTENDED | REG_NOSUB))
+ return RESULT_SHOWUSAGE;
+ havepattern = 1;
+ }
+
+ ast_cli(fd, FORMAT_STRING, "Channel", "Group", "Category");
+ while ( (c = ast_channel_walk_locked(c)) != NULL) {
+ headp=&c->varshead;
+ AST_LIST_TRAVERSE(headp,current,entries) {
+ if (!strncmp(ast_var_name(current), GROUP_CATEGORY_PREFIX "_", strlen(GROUP_CATEGORY_PREFIX) + 1)) {
+ if (!havepattern || !regexec(&regexbuf, ast_var_value(current), 0, NULL, 0)) {
+ ast_cli(fd, FORMAT_STRING, c->name, ast_var_value(current),
+ (ast_var_name(current) + strlen(GROUP_CATEGORY_PREFIX) + 1));
+ numchans++;
+ }
+ } else if (!strcmp(ast_var_name(current), GROUP_CATEGORY_PREFIX)) {
+ if (!havepattern || !regexec(&regexbuf, ast_var_value(current), 0, NULL, 0)) {
+ ast_cli(fd, FORMAT_STRING, c->name, ast_var_value(current), "(default)");
+ numchans++;
+ }
+ }
+ }
+ numchans++;
+ ast_mutex_unlock(&c->lock);
+ }
+
+ if (havepattern)
+ regfree(&regexbuf);
+
+ ast_cli(fd, "%d active channel%s\n", numchans, (numchans != 1) ? "s" : "");
+ return RESULT_SUCCESS;
+#undef FORMAT_STRING
+}
+
static int handle_help(int fd, int argc, char *argv[]);
static struct ast_cli_entry builtins[] = {
@@ -910,6 +967,7 @@ static struct ast_cli_entry builtins[] = {
{ { "show", "version", NULL }, handle_version, "Display version info", version_help },
{ { "soft", "hangup", NULL }, handle_softhangup, "Request a hangup on a given channel", softhangup_help, complete_ch_3 },
{ { "unload", NULL }, handle_unload, "Unload a dynamic module by name", unload_help, complete_fn },
+ { { "group", "show", "channels", NULL }, group_show_channels, "Show active channels with group(s)", group_show_channels_help},
{ { NULL }, NULL, NULL, NULL }
};