mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-04 20:04:50 +00:00
Fix some deprecated commands.
Issue 8682, patch by me git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@49035 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
183
main/cli.c
183
main/cli.c
@@ -578,14 +578,94 @@ static int handle_modlist(int fd, int argc, char *argv[])
|
||||
#undef MODLIST_FORMAT
|
||||
#undef MODLIST_FORMAT2
|
||||
|
||||
static int handle_chanlist(int fd, int argc, char *argv[])
|
||||
{
|
||||
#define FORMAT_STRING "%-20.20s %-20.20s %-7.7s %-30.30s\n"
|
||||
#define FORMAT_STRING2 "%-20.20s %-20.20s %-7.7s %-30.30s\n"
|
||||
#define CONCISE_FORMAT_STRING "%s!%s!%s!%d!%s!%s!%s!%s!%s!%d!%s!%s\n"
|
||||
#define VERBOSE_FORMAT_STRING "%-20.20s %-20.20s %-16.16s %4d %-7.7s %-12.12s %-25.25s %-15.15s %8.8s %-11.11s %-20.20s\n"
|
||||
#define VERBOSE_FORMAT_STRING2 "%-20.20s %-20.20s %-16.16s %-4.4s %-7.7s %-12.12s %-25.25s %-15.15s %8.8s %-11.11s %-20.20s\n"
|
||||
|
||||
static int handle_chanlist_deprecated(int fd, int argc, char *argv[])
|
||||
{
|
||||
struct ast_channel *c = NULL;
|
||||
char durbuf[10] = "-";
|
||||
char locbuf[40];
|
||||
char appdata[40];
|
||||
int duration;
|
||||
int durh, durm, durs;
|
||||
int numchans = 0, concise = 0, verbose = 0;
|
||||
|
||||
concise = (argc == 3 && (!strcasecmp(argv[2],"concise")));
|
||||
verbose = (argc == 3 && (!strcasecmp(argv[2],"verbose")));
|
||||
|
||||
if (argc < 2 || argc > 3 || (argc == 3 && !concise && !verbose))
|
||||
return RESULT_SHOWUSAGE;
|
||||
|
||||
if (!concise && !verbose)
|
||||
ast_cli(fd, FORMAT_STRING2, "Channel", "Location", "State", "Application(Data)");
|
||||
else if (verbose)
|
||||
ast_cli(fd, VERBOSE_FORMAT_STRING2, "Channel", "Context", "Extension", "Priority", "State", "Application", "Data",
|
||||
"CallerID", "Duration", "Accountcode", "BridgedTo");
|
||||
|
||||
while ((c = ast_channel_walk_locked(c)) != NULL) {
|
||||
struct ast_channel *bc = ast_bridged_channel(c);
|
||||
if ((concise || verbose) && c->cdr && !ast_tvzero(c->cdr->start)) {
|
||||
duration = (int)(ast_tvdiff_ms(ast_tvnow(), c->cdr->start) / 1000);
|
||||
if (verbose) {
|
||||
durh = duration / 3600;
|
||||
durm = (duration % 3600) / 60;
|
||||
durs = duration % 60;
|
||||
snprintf(durbuf, sizeof(durbuf), "%02d:%02d:%02d", durh, durm, durs);
|
||||
} else {
|
||||
snprintf(durbuf, sizeof(durbuf), "%d", duration);
|
||||
}
|
||||
} else {
|
||||
durbuf[0] = '\0';
|
||||
}
|
||||
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)",
|
||||
S_OR(c->data, ""), /* XXX different from verbose ? */
|
||||
S_OR(c->cid.cid_num, ""),
|
||||
S_OR(c->accountcode, ""),
|
||||
c->amaflags,
|
||||
durbuf,
|
||||
bc ? bc->name : "(None)");
|
||||
} else if (verbose) {
|
||||
ast_cli(fd, VERBOSE_FORMAT_STRING, c->name, c->context, c->exten, c->priority, ast_state2str(c->_state),
|
||||
c->appl ? c->appl : "(None)",
|
||||
c->data ? S_OR(c->data, "(Empty)" ): "(None)",
|
||||
S_OR(c->cid.cid_num, ""),
|
||||
durbuf,
|
||||
S_OR(c->accountcode, ""),
|
||||
bc ? bc->name : "(None)");
|
||||
} else {
|
||||
if (!ast_strlen_zero(c->context) && !ast_strlen_zero(c->exten))
|
||||
snprintf(locbuf, sizeof(locbuf), "%s@%s:%d", c->exten, c->context, c->priority);
|
||||
else
|
||||
strcpy(locbuf, "(None)");
|
||||
if (c->appl)
|
||||
snprintf(appdata, sizeof(appdata), "%s(%s)", c->appl, c->data ? c->data : "");
|
||||
else
|
||||
strcpy(appdata, "(None)");
|
||||
ast_cli(fd, FORMAT_STRING, c->name, locbuf, ast_state2str(c->_state), appdata);
|
||||
}
|
||||
numchans++;
|
||||
ast_channel_unlock(c);
|
||||
}
|
||||
if (!concise) {
|
||||
ast_cli(fd, "%d active channel%s\n", numchans, ESS(numchans));
|
||||
if (option_maxcalls)
|
||||
ast_cli(fd, "%d of %d max active call%s (%5.2f%% of capacity)\n",
|
||||
ast_active_calls(), option_maxcalls, ESS(ast_active_calls()),
|
||||
((double)ast_active_calls() / (double)option_maxcalls) * 100.0);
|
||||
else
|
||||
ast_cli(fd, "%d active call%s\n", ast_active_calls(), ESS(ast_active_calls()));
|
||||
}
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static int handle_chanlist(int fd, int argc, char *argv[])
|
||||
{
|
||||
struct ast_channel *c = NULL;
|
||||
char durbuf[10] = "-";
|
||||
char locbuf[40];
|
||||
@@ -662,13 +742,13 @@ static int handle_chanlist(int fd, int argc, char *argv[])
|
||||
ast_cli(fd, "%d active call%s\n", ast_active_calls(), ESS(ast_active_calls()));
|
||||
}
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
#undef FORMAT_STRING
|
||||
#undef FORMAT_STRING2
|
||||
#undef CONCISE_FORMAT_STRING
|
||||
#undef VERBOSE_FORMAT_STRING
|
||||
#undef VERBOSE_FORMAT_STRING2
|
||||
}
|
||||
|
||||
static char showchan_help[] =
|
||||
"Usage: core show channel <channel>\n"
|
||||
@@ -894,6 +974,90 @@ static int handle_nodebugchan_deprecated(int fd, int argc, char *argv[])
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static int handle_showchan_deprecated(int fd, int argc, char *argv[])
|
||||
{
|
||||
struct ast_channel *c=NULL;
|
||||
struct timeval now;
|
||||
char buf[2048];
|
||||
char cdrtime[256];
|
||||
char nf[256], wf[256], rf[256];
|
||||
long elapsed_seconds=0;
|
||||
int hour=0, min=0, sec=0;
|
||||
|
||||
if (argc != 3)
|
||||
return RESULT_SHOWUSAGE;
|
||||
now = ast_tvnow();
|
||||
c = ast_get_channel_by_name_locked(argv[2]);
|
||||
if (!c) {
|
||||
ast_cli(fd, "%s is not a known channel\n", argv[2]);
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
if(c->cdr) {
|
||||
elapsed_seconds = now.tv_sec - c->cdr->start.tv_sec;
|
||||
hour = elapsed_seconds / 3600;
|
||||
min = (elapsed_seconds % 3600) / 60;
|
||||
sec = elapsed_seconds % 60;
|
||||
snprintf(cdrtime, sizeof(cdrtime), "%dh%dm%ds", hour, min, sec);
|
||||
} else
|
||||
strcpy(cdrtime, "N/A");
|
||||
ast_cli(fd,
|
||||
" -- General --\n"
|
||||
" Name: %s\n"
|
||||
" Type: %s\n"
|
||||
" UniqueID: %s\n"
|
||||
" Caller ID: %s\n"
|
||||
" Caller ID Name: %s\n"
|
||||
" DNID Digits: %s\n"
|
||||
" State: %s (%d)\n"
|
||||
" Rings: %d\n"
|
||||
" NativeFormats: %s\n"
|
||||
" WriteFormat: %s\n"
|
||||
" ReadFormat: %s\n"
|
||||
" WriteTranscode: %s\n"
|
||||
" ReadTranscode: %s\n"
|
||||
"1st File Descriptor: %d\n"
|
||||
" Frames in: %d%s\n"
|
||||
" Frames out: %d%s\n"
|
||||
" Time to Hangup: %ld\n"
|
||||
" Elapsed Time: %s\n"
|
||||
" Direct Bridge: %s\n"
|
||||
"Indirect Bridge: %s\n"
|
||||
" -- PBX --\n"
|
||||
" Context: %s\n"
|
||||
" Extension: %s\n"
|
||||
" Priority: %d\n"
|
||||
" Call Group: %llu\n"
|
||||
" Pickup Group: %llu\n"
|
||||
" Application: %s\n"
|
||||
" Data: %s\n"
|
||||
" Blocking in: %s\n",
|
||||
c->name, c->tech->type, c->uniqueid,
|
||||
S_OR(c->cid.cid_num, "(N/A)"),
|
||||
S_OR(c->cid.cid_name, "(N/A)"),
|
||||
S_OR(c->cid.cid_dnid, "(N/A)"), ast_state2str(c->_state), c->_state, c->rings,
|
||||
ast_getformatname_multiple(nf, sizeof(nf), c->nativeformats),
|
||||
ast_getformatname_multiple(wf, sizeof(wf), c->writeformat),
|
||||
ast_getformatname_multiple(rf, sizeof(rf), c->readformat),
|
||||
c->writetrans ? "Yes" : "No",
|
||||
c->readtrans ? "Yes" : "No",
|
||||
c->fds[0],
|
||||
c->fin & ~DEBUGCHAN_FLAG, (c->fin & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "",
|
||||
c->fout & ~DEBUGCHAN_FLAG, (c->fout & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "",
|
||||
(long)c->whentohangup,
|
||||
cdrtime, c->_bridge ? c->_bridge->name : "<none>", ast_bridged_channel(c) ? ast_bridged_channel(c)->name : "<none>",
|
||||
c->context, c->exten, c->priority, c->callgroup, c->pickupgroup, ( c->appl ? c->appl : "(N/A)" ),
|
||||
( c-> data ? S_OR(c->data, "(Empty)") : "(None)"),
|
||||
(ast_test_flag(c, AST_FLAG_BLOCKING) ? c->blockproc : "(Not Blocking)"));
|
||||
|
||||
if(pbx_builtin_serialize_variables(c,buf,sizeof(buf)))
|
||||
ast_cli(fd," Variables:\n%s\n",buf);
|
||||
if(c->cdr && ast_cdr_serialize_variables(c->cdr,buf, sizeof(buf), '=', '\n', 1))
|
||||
ast_cli(fd," CDR Variables:\n%s\n",buf);
|
||||
|
||||
ast_channel_unlock(c);
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static int handle_showchan(int fd, int argc, char *argv[])
|
||||
{
|
||||
struct ast_channel *c=NULL;
|
||||
@@ -994,6 +1158,13 @@ char *ast_cli_complete(const char *word, char *const choices[], int state)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char *complete_show_channels_deprecated(const char *line, const char *word, int pos, int state)
|
||||
{
|
||||
static char *choices[] = { "concise", "verbose", NULL };
|
||||
|
||||
return (pos != 2) ? NULL : ast_cli_complete(word, choices, state);
|
||||
}
|
||||
|
||||
static char *complete_show_channels(const char *line, const char *word, int pos, int state)
|
||||
{
|
||||
static char *choices[] = { "concise", "verbose", NULL };
|
||||
@@ -1184,13 +1355,13 @@ static struct ast_cli_entry cli_set_verbose_deprecated = {
|
||||
|
||||
static struct ast_cli_entry cli_show_channel_deprecated = {
|
||||
{ "show", "channel", NULL },
|
||||
handle_showchan, NULL,
|
||||
handle_showchan_deprecated, NULL,
|
||||
NULL, complete_ch_3 };
|
||||
|
||||
static struct ast_cli_entry cli_show_channels_deprecated = {
|
||||
{ "show", "channels", NULL },
|
||||
handle_chanlist, NULL,
|
||||
NULL, complete_show_channels };
|
||||
handle_chanlist_deprecated, NULL,
|
||||
NULL, complete_show_channels_deprecated };
|
||||
|
||||
static struct ast_cli_entry cli_show_modules_deprecated = {
|
||||
{ "show", "modules", NULL },
|
||||
|
Reference in New Issue
Block a user