move "core set debug" to the new style, and remove duplicated

code for the deprecated handler.

On passing fix a long standing bug in find_cli() which would not
find the longest match - this part (trivial, basically
just update matchlen on a match) must go in 1.4 and possibly 1.2 as well.




git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@47662 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Luigi Rizzo
2006-11-15 16:13:30 +00:00
parent 188325947c
commit 0e9753f401

View File

@@ -148,6 +148,7 @@ static char *handle_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args
} }
for (x = e->args; x < a->argc; x++) { for (x = e->args; x < a->argc; x++) {
int res = ast_module_reload(a->argv[x]); int res = ast_module_reload(a->argv[x]);
/* XXX reload has multiple error returns, including -1 on error and 2 on success */
switch(res) { switch(res) {
case 0: case 0:
ast_cli(a->fd, "No such module '%s'\n", a->argv[x]); ast_cli(a->fd, "No such module '%s'\n", a->argv[x]);
@@ -603,10 +604,6 @@ static char showchan_help[] =
"Usage: core show channel <channel>\n" "Usage: core show channel <channel>\n"
" Shows lots of information about the specified channel.\n"; " Shows lots of information about the specified channel.\n";
static char debugchan_help[] =
"Usage: core set debug channel <channel> [off]\n"
" Enables/disables debugging on a specific channel.\n";
static char commandcomplete_help[] = static char commandcomplete_help[] =
"Usage: _command complete \"<line>\" text state\n" "Usage: _command complete \"<line>\" text state\n"
" This function is used internally to help with command completion and should.\n" " This function is used internally to help with command completion and should.\n"
@@ -745,18 +742,35 @@ static int handle_debugchan_deprecated(int fd, int argc, char *argv[])
return RESULT_SUCCESS; return RESULT_SUCCESS;
} }
static int handle_core_set_debug_channel(int fd, int argc, char *argv[]) static char *handle_core_set_debug_channel(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{ {
struct ast_channel *c = NULL; struct ast_channel *c = NULL;
int is_all, is_off = 0; int is_all, is_off = 0;
/* 'core set debug channel {all|chan_id}' */ switch (cmd) {
if (argc == 6 && strcmp(argv[5], "off") == 0) case CLI_INIT:
is_off = 1; e->command = "core set debug channel";
else if (argc != 5) e->usage =
return RESULT_SHOWUSAGE; "Usage: core set debug channel <all|channel> [off]\n"
" Enables/disables debugging on all or on a specific channel.\n";
return NULL;
is_all = !strcasecmp("all", argv[4]); case CLI_GENERATE:
/* XXX remember to handle the optional "off" */
if (a->pos != e->args)
return NULL;
return a->n == 0 ? strdup("all") : ast_complete_channels(a->line, a->word, a->pos, a->n - 1, e->args);
}
/* 'core set debug channel {all|chan_id}' */
if (a->argc == e->args + 2) {
if (!strcasecmp(a->argv[e->args + 1], "off"))
is_off = 1;
else
return CLI_SHOWUSAGE;
} else if (a->argc != e->args + 1)
return CLI_SHOWUSAGE;
is_all = !strcasecmp("all", a->argv[e->args]);
if (is_all) { if (is_all) {
if (is_off) { if (is_off) {
global_fin &= ~DEBUGCHAN_FLAG; global_fin &= ~DEBUGCHAN_FLAG;
@@ -767,9 +781,9 @@ static int handle_core_set_debug_channel(int fd, int argc, char *argv[])
} }
c = ast_channel_walk_locked(NULL); c = ast_channel_walk_locked(NULL);
} else { } else {
c = ast_get_channel_by_name_locked(argv[4]); c = ast_get_channel_by_name_locked(a->argv[e->args]);
if (c == NULL) if (c == NULL)
ast_cli(fd, "No such channel %s\n", argv[4]); ast_cli(a->fd, "No such channel %s\n", a->argv[e->args]);
} }
while (c) { while (c) {
if (!(c->fin & DEBUGCHAN_FLAG) || !(c->fout & DEBUGCHAN_FLAG)) { if (!(c->fin & DEBUGCHAN_FLAG) || !(c->fout & DEBUGCHAN_FLAG)) {
@@ -780,47 +794,33 @@ static int handle_core_set_debug_channel(int fd, int argc, char *argv[])
c->fin |= DEBUGCHAN_FLAG; c->fin |= DEBUGCHAN_FLAG;
c->fout |= DEBUGCHAN_FLAG; c->fout |= DEBUGCHAN_FLAG;
} }
ast_cli(fd, "Debugging %s on channel %s\n", is_off ? "disabled" : "enabled", c->name); ast_cli(a->fd, "Debugging %s on channel %s\n", is_off ? "disabled" : "enabled", c->name);
} }
ast_channel_unlock(c); ast_channel_unlock(c);
if (!is_all) if (!is_all)
break; break;
c = ast_channel_walk_locked(c); c = ast_channel_walk_locked(c);
} }
ast_cli(fd, "Debugging on new channels is %s\n", is_off ? "disabled" : "enabled"); ast_cli(a->fd, "Debugging on new channels is %s\n", is_off ? "disabled" : "enabled");
return RESULT_SUCCESS; return RESULT_SUCCESS;
} }
static int handle_nodebugchan_deprecated(int fd, int argc, char *argv[]) static char *handle_nodebugchan_deprecated(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{ {
struct ast_channel *c=NULL; char *res;
int is_all; if (cmd == CLI_HANDLER) {
/* 'no debug channel {all|chan_id}' */ if (a->argc != e->args + 1)
if (argc != 4) return CLI_SHOWUSAGE;
return RESULT_SHOWUSAGE; /* pretend we have an extra "off" at the end. We can do this as the array
is_all = !strcasecmp("all", argv[3]); * is NULL terminated so we overwrite that entry.
if (is_all) { */
global_fin &= ~DEBUGCHAN_FLAG; a->argv[e->args+1] = "off";
global_fout &= ~DEBUGCHAN_FLAG; a->argc++;
c = ast_channel_walk_locked(NULL);
} else {
c = ast_get_channel_by_name_locked(argv[3]);
if (c == NULL)
ast_cli(fd, "No such channel %s\n", argv[3]);
} }
while(c) { res = handle_core_set_debug_channel(e, cmd, a);
if ((c->fin & DEBUGCHAN_FLAG) || (c->fout & DEBUGCHAN_FLAG)) { if (cmd == CLI_INIT)
c->fin &= ~DEBUGCHAN_FLAG; e->command = "no debug channel";
c->fout &= ~DEBUGCHAN_FLAG; return res;
ast_cli(fd, "Debugging disabled on channel %s\n", c->name);
}
ast_channel_unlock(c);
if (!is_all)
break;
c = ast_channel_walk_locked(c);
}
ast_cli(fd, "Debugging on new channels is disabled\n");
return RESULT_SUCCESS;
} }
static int handle_showchan(int fd, int argc, char *argv[]) static int handle_showchan(int fd, int argc, char *argv[])
@@ -1086,9 +1086,7 @@ static struct ast_cli_entry cli_module_unload_deprecated = NEW_CLI(handle_unload
static struct ast_cli_entry cli_cli[] = { static struct ast_cli_entry cli_cli[] = {
/* Deprecated, but preferred command is now consolidated (and already has a deprecated command for it). */ /* Deprecated, but preferred command is now consolidated (and already has a deprecated command for it). */
{ { "no", "debug", "channel", NULL }, NEW_CLI(handle_nodebugchan_deprecated, "Disable debugging on channel(s)"),
handle_nodebugchan_deprecated, NULL,
NULL, complete_ch_4 },
{ { "core", "show", "channels", NULL }, { { "core", "show", "channels", NULL },
handle_chanlist, "Display information on channels", handle_chanlist, "Display information on channels",
@@ -1098,9 +1096,8 @@ static struct ast_cli_entry cli_cli[] = {
handle_showchan, "Display information on a specific channel", handle_showchan, "Display information on a specific channel",
showchan_help, complete_ch_4 }, showchan_help, complete_ch_4 },
{ { "core", "set", "debug", "channel", NULL }, NEW_CLI(handle_core_set_debug_channel, "Enable/disable debugging on a channel",
handle_core_set_debug_channel, "Enable/disable debugging on a channel", .deprecate_cmd = &cli_debug_channel_deprecated),
debugchan_help, complete_ch_5, &cli_debug_channel_deprecated },
NEW_CLI(handle_set_debug, "Set level of debug chattiness"), NEW_CLI(handle_set_debug, "Set level of debug chattiness"),
@@ -1225,8 +1222,10 @@ static struct ast_cli_entry *find_cli(char *const cmds[], int match_type)
continue; continue;
/* we are in case match_type == -1 and mismatch on last word */ /* we are in case match_type == -1 and mismatch on last word */
} }
if (cand == NULL || y > matchlen) /* remember the candidate */ if (y > matchlen) { /* remember the candidate */
matchlen = y;
cand = e; cand = e;
}
} }
return e ? e : cand; return e ? e : cand;
} }