mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-20 20:44:20 +00:00
Remove "old"-style CLI handler, since nothing uses it anymore.
Closes issue #11403, patch by eliel. This also completes the janitor project. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@90038 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -142,60 +142,40 @@ struct ast_cli_args {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct ast_cli_entry;
|
struct ast_cli_entry;
|
||||||
typedef int (*old_cli_fn)(int fd, int argc, char *argv[]);
|
typedef char *(*cli_fn)(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
|
||||||
typedef char *(*new_cli_fn)(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
|
|
||||||
|
|
||||||
/*! \brief descriptor for a cli entry.
|
/*! \brief descriptor for a cli entry.
|
||||||
* \arg \ref CLI_command_API
|
* \arg \ref CLI_command_API
|
||||||
*/
|
*/
|
||||||
struct ast_cli_entry {
|
struct ast_cli_entry {
|
||||||
char * const cmda[AST_MAX_CMD_LEN]; /*!< words making up the command.
|
char * const cmda[AST_MAX_CMD_LEN]; /*!< words making up the command.
|
||||||
* set the first entry to NULL for a new-style entry. */
|
* set the first entry to NULL for a new-style entry. */
|
||||||
|
|
||||||
/*! Handler for the command (fd for output, # of args, argument list).
|
const char *summary; /*!< Summary of the command (< 60 characters) */
|
||||||
Returns RESULT_SHOWUSAGE for improper arguments.
|
const char *usage; /*!< Detailed usage information */
|
||||||
argv[] has argc 'useful' entries, and an additional NULL entry
|
|
||||||
at the end so that clients requiring NULL terminated arrays
|
|
||||||
can use it without need for copies.
|
|
||||||
You can overwrite argv or the strings it points to, but remember
|
|
||||||
that this memory is deallocated after the handler returns.
|
|
||||||
*/
|
|
||||||
old_cli_fn handler;
|
|
||||||
|
|
||||||
const char *summary; /*!< Summary of the command (< 60 characters) */
|
|
||||||
const char *usage; /*!< Detailed usage information */
|
|
||||||
|
|
||||||
/*! Generate the n-th (starting from 0) possible completion
|
|
||||||
for a given 'word' following 'line' in position 'pos'.
|
|
||||||
'line' and 'word' must not be modified.
|
|
||||||
Must return a malloc'ed string with the n-th value when available,
|
|
||||||
or NULL if the n-th completion does not exist.
|
|
||||||
Typically, the function is called with increasing values for n
|
|
||||||
until a NULL is returned.
|
|
||||||
*/
|
|
||||||
char *(*generator)(const char *line, const char *word, int pos, int n);
|
|
||||||
struct ast_cli_entry *deprecate_cmd;
|
struct ast_cli_entry *deprecate_cmd;
|
||||||
|
|
||||||
int inuse; /*!< For keeping track of usage */
|
int inuse; /*!< For keeping track of usage */
|
||||||
struct module *module; /*!< module this belongs to */
|
struct module *module; /*!< module this belongs to */
|
||||||
char *_full_cmd; /*!< built at load time from cmda[] */
|
char *_full_cmd; /*!< built at load time from cmda[] */
|
||||||
int cmdlen; /*!< len up to the first invalid char [<{% */
|
int cmdlen; /*!< len up to the first invalid char [<{% */
|
||||||
/*! \brief This gets set in ast_cli_register()
|
/*! \brief This gets set in ast_cli_register()
|
||||||
It then gets set to something different when the deprecated command
|
It then gets set to something different when the deprecated command
|
||||||
is run for the first time (ie; after we warn the user that it's deprecated)
|
is run for the first time (ie; after we warn the user that it's deprecated)
|
||||||
*/
|
*/
|
||||||
int args; /*!< number of non-null entries in cmda */
|
int args; /*!< number of non-null entries in cmda */
|
||||||
char *command; /*!< command, non-null for new-style entries */
|
char *command; /*!< command, non-null for new-style entries */
|
||||||
int deprecated;
|
int deprecated;
|
||||||
new_cli_fn new_handler;
|
cli_fn handler;
|
||||||
char *_deprecated_by; /*!< copied from the "parent" _full_cmd, on deprecated commands */
|
char *_deprecated_by; /*!< copied from the "parent" _full_cmd, on deprecated commands */
|
||||||
/*! For linking */
|
/*! For linking */
|
||||||
AST_LIST_ENTRY(ast_cli_entry) list;
|
AST_LIST_ENTRY(ast_cli_entry) list;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* XXX the parser in gcc 2.95 gets confused if you don't put a space
|
/* XXX the parser in gcc 2.95 gets confused if you don't put a space
|
||||||
* between the last arg before VA_ARGS and the comma */
|
* between the last arg before VA_ARGS and the comma */
|
||||||
#define AST_CLI_DEFINE(fn, txt , ... ) { .new_handler = fn, .summary = txt, ## __VA_ARGS__ }
|
#define AST_CLI_DEFINE(fn, txt , ... ) { .handler = fn, .summary = txt, ## __VA_ARGS__ }
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Helper function to generate cli entries from a NULL-terminated array.
|
* Helper function to generate cli entries from a NULL-terminated array.
|
||||||
|
78
main/cli.c
78
main/cli.c
@@ -565,7 +565,7 @@ static char *handle_modlist(struct ast_cli_entry *e, int cmd, struct ast_cli_arg
|
|||||||
ast_cli(a->fd,"%d modules loaded\n", ast_update_module_list(modlist_modentry, like));
|
ast_cli(a->fd,"%d modules loaded\n", ast_update_module_list(modlist_modentry, like));
|
||||||
climodentryfd = -1;
|
climodentryfd = -1;
|
||||||
ast_mutex_unlock(&climodentrylock);
|
ast_mutex_unlock(&climodentrylock);
|
||||||
return RESULT_SUCCESS;
|
return CLI_SUCCESS;
|
||||||
}
|
}
|
||||||
#undef MODLIST_FORMAT
|
#undef MODLIST_FORMAT
|
||||||
#undef MODLIST_FORMAT2
|
#undef MODLIST_FORMAT2
|
||||||
@@ -885,7 +885,7 @@ static char *handle_core_set_debug_channel(struct ast_cli_entry *e, int cmd, str
|
|||||||
c = ast_channel_walk_locked(c);
|
c = ast_channel_walk_locked(c);
|
||||||
}
|
}
|
||||||
ast_cli(a->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 CLI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *handle_debugchan_deprecated(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
static char *handle_debugchan_deprecated(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
||||||
@@ -1354,7 +1354,7 @@ static int __ast_cli_unregister(struct ast_cli_entry *e, struct ast_cli_entry *e
|
|||||||
AST_RWLIST_UNLOCK(&helpers);
|
AST_RWLIST_UNLOCK(&helpers);
|
||||||
ast_free(e->_full_cmd);
|
ast_free(e->_full_cmd);
|
||||||
e->_full_cmd = NULL;
|
e->_full_cmd = NULL;
|
||||||
if (e->new_handler) {
|
if (e->handler) {
|
||||||
/* this is a new-style entry. Reset fields and free memory. */
|
/* this is a new-style entry. Reset fields and free memory. */
|
||||||
bzero((char **)(e->cmda), sizeof(e->cmda));
|
bzero((char **)(e->cmda), sizeof(e->cmda));
|
||||||
ast_free(e->command);
|
ast_free(e->command);
|
||||||
@@ -1370,26 +1370,25 @@ static int __ast_cli_register(struct ast_cli_entry *e, struct ast_cli_entry *ed)
|
|||||||
struct ast_cli_entry *cur;
|
struct ast_cli_entry *cur;
|
||||||
int i, lf, ret = -1;
|
int i, lf, ret = -1;
|
||||||
|
|
||||||
if (e->handler == NULL) { /* new style entry, run the handler to init fields */
|
struct ast_cli_args a; /* fake argument */
|
||||||
struct ast_cli_args a; /* fake argument */
|
char **dst = (char **)e->cmda; /* need to cast as the entry is readonly */
|
||||||
char **dst = (char **)e->cmda; /* need to cast as the entry is readonly */
|
char *s;
|
||||||
char *s;
|
|
||||||
|
|
||||||
bzero (&a, sizeof(a));
|
bzero (&a, sizeof(a));
|
||||||
e->new_handler(e, CLI_INIT, &a);
|
e->handler(e, CLI_INIT, &a);
|
||||||
/* XXX check that usage and command are filled up */
|
/* XXX check that usage and command are filled up */
|
||||||
s = ast_skip_blanks(e->command);
|
s = ast_skip_blanks(e->command);
|
||||||
s = e->command = ast_strdup(s);
|
s = e->command = ast_strdup(s);
|
||||||
for (i=0; !ast_strlen_zero(s) && i < AST_MAX_CMD_LEN-1; i++) {
|
for (i=0; !ast_strlen_zero(s) && i < AST_MAX_CMD_LEN-1; i++) {
|
||||||
*dst++ = s; /* store string */
|
*dst++ = s; /* store string */
|
||||||
s = ast_skip_nonblanks(s);
|
s = ast_skip_nonblanks(s);
|
||||||
if (*s == '\0') /* we are done */
|
if (*s == '\0') /* we are done */
|
||||||
break;
|
break;
|
||||||
*s++ = '\0';
|
*s++ = '\0';
|
||||||
s = ast_skip_blanks(s);
|
s = ast_skip_blanks(s);
|
||||||
}
|
|
||||||
*dst++ = NULL;
|
|
||||||
}
|
}
|
||||||
|
*dst++ = NULL;
|
||||||
|
|
||||||
AST_RWLIST_WRLOCK(&helpers);
|
AST_RWLIST_WRLOCK(&helpers);
|
||||||
|
|
||||||
if (find_cli(e->cmda, 1)) {
|
if (find_cli(e->cmda, 1)) {
|
||||||
@@ -1549,7 +1548,7 @@ static char *handle_help(struct ast_cli_entry *e, int cmd, struct ast_cli_args *
|
|||||||
ast_cli(a->fd, "No help text available for '%s'.\n", fullcmd);
|
ast_cli(a->fd, "No help text available for '%s'.\n", fullcmd);
|
||||||
}
|
}
|
||||||
AST_RWLIST_UNLOCK(&helpers);
|
AST_RWLIST_UNLOCK(&helpers);
|
||||||
return RESULT_SUCCESS;
|
return CLI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *parse_args(const char *s, int *argc, char *argv[], int max, int *trailingwhitespace)
|
static char *parse_args(const char *s, int *argc, char *argv[], int max, int *trailingwhitespace)
|
||||||
@@ -1760,14 +1759,12 @@ static char *__ast_cli_generator(const char *text, const char *word, int state,
|
|||||||
* (only one entry in the list should have this property).
|
* (only one entry in the list should have this property).
|
||||||
* Run the generator if one is available. In any case we are done.
|
* Run the generator if one is available. In any case we are done.
|
||||||
*/
|
*/
|
||||||
if (e->generator)
|
if (e->handler) { /* new style command */
|
||||||
ret = e->generator(matchstr, word, argindex, state - matchnum);
|
|
||||||
else if (e->new_handler) { /* new style command */
|
|
||||||
struct ast_cli_args a = {
|
struct ast_cli_args a = {
|
||||||
.line = matchstr, .word = word,
|
.line = matchstr, .word = word,
|
||||||
.pos = argindex,
|
.pos = argindex,
|
||||||
.n = state - matchnum };
|
.n = state - matchnum };
|
||||||
ret = e->new_handler(e, CLI_GENERATE, &a);
|
ret = e->handler(e, CLI_GENERATE, &a);
|
||||||
}
|
}
|
||||||
if (ret)
|
if (ret)
|
||||||
break;
|
break;
|
||||||
@@ -1789,7 +1786,6 @@ int ast_cli_command(int fd, const char *s)
|
|||||||
char *args[AST_MAX_ARGS + 1];
|
char *args[AST_MAX_ARGS + 1];
|
||||||
struct ast_cli_entry *e;
|
struct ast_cli_entry *e;
|
||||||
int x;
|
int x;
|
||||||
int res;
|
|
||||||
char *dup = parse_args(s, &x, args + 1, AST_MAX_ARGS, NULL);
|
char *dup = parse_args(s, &x, args + 1, AST_MAX_ARGS, NULL);
|
||||||
|
|
||||||
if (dup == NULL)
|
if (dup == NULL)
|
||||||
@@ -1813,39 +1809,25 @@ int ast_cli_command(int fd, const char *s)
|
|||||||
*/
|
*/
|
||||||
args[0] = (char *)e;
|
args[0] = (char *)e;
|
||||||
|
|
||||||
if (!e->new_handler) /* old style */
|
struct ast_cli_args a = {
|
||||||
res = e->handler(fd, x, args + 1);
|
.fd = fd, .argc = x, .argv = args+1 };
|
||||||
else {
|
char *retval = e->handler(e, CLI_HANDLER, &a);
|
||||||
struct ast_cli_args a = {
|
|
||||||
.fd = fd, .argc = x, .argv = args+1 };
|
|
||||||
char *retval = e->new_handler(e, CLI_HANDLER, &a);
|
|
||||||
|
|
||||||
if (retval == CLI_SUCCESS)
|
if (retval == CLI_SHOWUSAGE) {
|
||||||
res = RESULT_SUCCESS;
|
|
||||||
else if (retval == CLI_SHOWUSAGE)
|
|
||||||
res = RESULT_SHOWUSAGE;
|
|
||||||
else
|
|
||||||
res = RESULT_FAILURE;
|
|
||||||
}
|
|
||||||
switch (res) {
|
|
||||||
case RESULT_SHOWUSAGE:
|
|
||||||
ast_cli(fd, "%s", S_OR(e->usage, "Invalid usage, but no usage information available.\n"));
|
ast_cli(fd, "%s", S_OR(e->usage, "Invalid usage, but no usage information available.\n"));
|
||||||
AST_RWLIST_RDLOCK(&helpers);
|
AST_RWLIST_RDLOCK(&helpers);
|
||||||
if (e->deprecated)
|
if (e->deprecated)
|
||||||
ast_cli(fd, "The '%s' command is deprecated and will be removed in a future release. Please use '%s' instead.\n", e->_full_cmd, e->_deprecated_by);
|
ast_cli(fd, "The '%s' command is deprecated and will be removed in a future release. Please use '%s' instead.\n", e->_full_cmd, e->_deprecated_by);
|
||||||
AST_RWLIST_UNLOCK(&helpers);
|
AST_RWLIST_UNLOCK(&helpers);
|
||||||
break;
|
} else {
|
||||||
case RESULT_FAILURE:
|
if (retval == CLI_FAILURE)
|
||||||
ast_cli(fd, "Command '%s' failed.\n", s);
|
ast_cli(fd, "Command '%s' failed.\n", s);
|
||||||
/* FALLTHROUGH */
|
|
||||||
default:
|
|
||||||
AST_RWLIST_RDLOCK(&helpers);
|
AST_RWLIST_RDLOCK(&helpers);
|
||||||
if (e->deprecated == 1) {
|
if (e->deprecated == 1) {
|
||||||
ast_cli(fd, "The '%s' command is deprecated and will be removed in a future release. Please use '%s' instead.\n", e->_full_cmd, e->_deprecated_by);
|
ast_cli(fd, "The '%s' command is deprecated and will be removed in a future release. Please use '%s' instead.\n", e->_full_cmd, e->_deprecated_by);
|
||||||
e->deprecated = 2;
|
e->deprecated = 2;
|
||||||
}
|
}
|
||||||
AST_RWLIST_UNLOCK(&helpers);
|
AST_RWLIST_UNLOCK(&helpers);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
ast_atomic_fetchadd_int(&e->inuse, -1);
|
ast_atomic_fetchadd_int(&e->inuse, -1);
|
||||||
done:
|
done:
|
||||||
|
@@ -4230,7 +4230,7 @@ static char *handle_show_switches(struct ast_cli_entry *e, int cmd, struct ast_c
|
|||||||
if (AST_RWLIST_EMPTY(&switches)) {
|
if (AST_RWLIST_EMPTY(&switches)) {
|
||||||
AST_RWLIST_UNLOCK(&switches);
|
AST_RWLIST_UNLOCK(&switches);
|
||||||
ast_cli(a->fd, "There are no registered alternative switches\n");
|
ast_cli(a->fd, "There are no registered alternative switches\n");
|
||||||
return RESULT_SUCCESS;
|
return CLI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
ast_cli(a->fd, "\n -= Registered Asterisk Alternative Switches =-\n");
|
ast_cli(a->fd, "\n -= Registered Asterisk Alternative Switches =-\n");
|
||||||
|
@@ -487,7 +487,7 @@ static void md52sum(char *sum, unsigned char *md5)
|
|||||||
* \param e CLI command
|
* \param e CLI command
|
||||||
* \param cmd
|
* \param cmd
|
||||||
* \param a list of CLI arguments
|
* \param a list of CLI arguments
|
||||||
* \return RESULT_SUCCESS
|
* \return CLI_SUCCESS
|
||||||
*/
|
*/
|
||||||
static char *handle_cli_keys_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
static char *handle_cli_keys_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
||||||
{
|
{
|
||||||
@@ -533,7 +533,7 @@ static char *handle_cli_keys_show(struct ast_cli_entry *e, int cmd, struct ast_c
|
|||||||
* \param e CLI command
|
* \param e CLI command
|
||||||
* \param cmd
|
* \param cmd
|
||||||
* \param a list of CLI arguments
|
* \param a list of CLI arguments
|
||||||
* \return RESULT_SUCCESS
|
* \return CLI_SUCCESS
|
||||||
*/
|
*/
|
||||||
static char *handle_cli_keys_init(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
static char *handle_cli_keys_init(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user