aboutsummaryrefslogtreecommitdiffstats
path: root/cli.c
diff options
context:
space:
mode:
authormarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2004-06-11 00:18:30 +0000
committermarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2004-06-11 00:18:30 +0000
commit588ea7fd9d97045353a49d2e9bb3d265ed3f08ba (patch)
tree218f12dcac3ba513ecf043e17ac7d9641bbb8059 /cli.c
parenta5e941b56ea72044c4dadd9bdb8221cb919bea85 (diff)
Add "show channels concise" for machine readable format
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@3187 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'cli.c')
-rwxr-xr-xcli.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/cli.c b/cli.c
index 69d9e67fb..421617d01 100755
--- a/cli.c
+++ b/cli.c
@@ -69,9 +69,10 @@ static char help_help[] =
" topic, it provides a list of commands.\n";
static char chanlist_help[] =
-"Usage: show channels\n"
+"Usage: show channels [concise]\n"
" Lists currently defined channels and some information about\n"
-" them.\n";
+" them. If 'concise' is specified, format is abridged and in\n"
+" a more easily machine parsable format\n";
static char reload_help[] =
"Usage: reload\n"
@@ -286,20 +287,34 @@ static int handle_chanlist(int fd, int argc, char *argv[])
{
#define FORMAT_STRING "%15s (%-10s %-12s %-4d) %7s %-12s %-15s\n"
#define FORMAT_STRING2 "%15s (%-10s %-12s %-4s) %7s %-12s %-15s\n"
+#define CONCISE_FORMAT_STRING "%s:%s:%s:%d:%s:%s:%s:%s:%s:%d\n"
+
struct ast_channel *c=NULL;
int numchans = 0;
- if (argc != 2)
+ int concise = 0;
+ if (argc < 2 || argc > 3)
return RESULT_SHOWUSAGE;
+
+ concise = (argc == 3 && (!strcasecmp(argv[2],"concise")));
c = ast_channel_walk_locked(NULL);
- ast_cli(fd, FORMAT_STRING2, "Channel", "Context", "Extension", "Pri", "State", "Appl.", "Data");
+ if(!concise)
+ ast_cli(fd, FORMAT_STRING2, "Channel", "Context", "Extension", "Pri", "State", "Appl.", "Data");
while(c) {
- ast_cli(fd, FORMAT_STRING, c->name, c->context, c->exten, c->priority, ast_state2str(c->_state),
- c->appl ? c->appl : "(None)", c->data ? ( !ast_strlen_zero(c->data) ? c->data : "(Empty)" ): "(None)");
+ if(concise)
+ ast_cli(fd, CONCISE_FORMAT_STRING, c->name, c->context, c->exten, c->priority, ast_state2str(c->_state),
+ c->appl ? c->appl : "(None)", c->data ? ( !ast_strlen_zero(c->data) ? c->data : "" ): "",
+ (c->callerid && !ast_strlen_zero(c->callerid)) ? c->callerid : "",
+ (c->accountcode && !ast_strlen_zero(c->accountcode)) ? c->accountcode : "",c->amaflags);
+ else
+ ast_cli(fd, FORMAT_STRING, c->name, c->context, c->exten, c->priority, ast_state2str(c->_state),
+ c->appl ? c->appl : "(None)", c->data ? ( !ast_strlen_zero(c->data) ? c->data : "(Empty)" ): "(None)");
+
numchans++;
ast_mutex_unlock(&c->lock);
c = ast_channel_walk_locked(c);
}
- ast_cli(fd, "%d active channel(s)\n", numchans);
+ if(!concise)
+ ast_cli(fd, "%d active channel(s)\n", numchans);
return RESULT_SUCCESS;
}