From aa0f63d65f4fd0cff7ec431e070f9e269d4fee91 Mon Sep 17 00:00:00 2001 From: Jason Parker Date: Wed, 28 Nov 2007 20:27:40 +0000 Subject: [PATCH] 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 --- include/asterisk/cli.h | 46 +++++++------------------ main/cli.c | 78 ++++++++++++++++-------------------------- main/pbx.c | 2 +- res/res_crypto.c | 4 +-- 4 files changed, 46 insertions(+), 84 deletions(-) diff --git a/include/asterisk/cli.h b/include/asterisk/cli.h index d29917d1d9..854c189ffa 100644 --- a/include/asterisk/cli.h +++ b/include/asterisk/cli.h @@ -142,60 +142,40 @@ struct ast_cli_args { }; struct ast_cli_entry; -typedef int (*old_cli_fn)(int fd, int argc, char *argv[]); -typedef char *(*new_cli_fn)(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a); +typedef char *(*cli_fn)(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a); /*! \brief descriptor for a cli entry. * \arg \ref CLI_command_API */ struct ast_cli_entry { 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). - Returns RESULT_SHOWUSAGE for improper arguments. - 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 */ - 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; - int inuse; /*!< For keeping track of usage */ - struct module *module; /*!< module this belongs to */ - char *_full_cmd; /*!< built at load time from cmda[] */ - int cmdlen; /*!< len up to the first invalid char [<{% */ + int inuse; /*!< For keeping track of usage */ + struct module *module; /*!< module this belongs to */ + char *_full_cmd; /*!< built at load time from cmda[] */ + int cmdlen; /*!< len up to the first invalid char [<{% */ /*! \brief This gets set in ast_cli_register() 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) */ - int args; /*!< number of non-null entries in cmda */ - char *command; /*!< command, non-null for new-style entries */ + int args; /*!< number of non-null entries in cmda */ + char *command; /*!< command, non-null for new-style entries */ int deprecated; - new_cli_fn new_handler; - char *_deprecated_by; /*!< copied from the "parent" _full_cmd, on deprecated commands */ + cli_fn handler; + char *_deprecated_by; /*!< copied from the "parent" _full_cmd, on deprecated commands */ /*! For linking */ AST_LIST_ENTRY(ast_cli_entry) list; }; /* 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 */ -#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. diff --git a/main/cli.c b/main/cli.c index c71c49e6ea..ca69e58fcd 100644 --- a/main/cli.c +++ b/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)); climodentryfd = -1; ast_mutex_unlock(&climodentrylock); - return RESULT_SUCCESS; + return CLI_SUCCESS; } #undef MODLIST_FORMAT #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); } 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) @@ -1354,7 +1354,7 @@ static int __ast_cli_unregister(struct ast_cli_entry *e, struct ast_cli_entry *e AST_RWLIST_UNLOCK(&helpers); ast_free(e->_full_cmd); e->_full_cmd = NULL; - if (e->new_handler) { + if (e->handler) { /* this is a new-style entry. Reset fields and free memory. */ bzero((char **)(e->cmda), sizeof(e->cmda)); 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; 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 */ - char **dst = (char **)e->cmda; /* need to cast as the entry is readonly */ - char *s; + struct ast_cli_args a; /* fake argument */ + char **dst = (char **)e->cmda; /* need to cast as the entry is readonly */ + char *s; - bzero (&a, sizeof(a)); - e->new_handler(e, CLI_INIT, &a); - /* XXX check that usage and command are filled up */ - s = ast_skip_blanks(e->command); - s = e->command = ast_strdup(s); - for (i=0; !ast_strlen_zero(s) && i < AST_MAX_CMD_LEN-1; i++) { - *dst++ = s; /* store string */ - s = ast_skip_nonblanks(s); - if (*s == '\0') /* we are done */ - break; - *s++ = '\0'; - s = ast_skip_blanks(s); - } - *dst++ = NULL; + bzero (&a, sizeof(a)); + e->handler(e, CLI_INIT, &a); + /* XXX check that usage and command are filled up */ + s = ast_skip_blanks(e->command); + s = e->command = ast_strdup(s); + for (i=0; !ast_strlen_zero(s) && i < AST_MAX_CMD_LEN-1; i++) { + *dst++ = s; /* store string */ + s = ast_skip_nonblanks(s); + if (*s == '\0') /* we are done */ + break; + *s++ = '\0'; + s = ast_skip_blanks(s); } + *dst++ = NULL; + AST_RWLIST_WRLOCK(&helpers); 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_RWLIST_UNLOCK(&helpers); - return RESULT_SUCCESS; + return CLI_SUCCESS; } 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). * Run the generator if one is available. In any case we are done. */ - if (e->generator) - ret = e->generator(matchstr, word, argindex, state - matchnum); - else if (e->new_handler) { /* new style command */ + if (e->handler) { /* new style command */ struct ast_cli_args a = { .line = matchstr, .word = word, .pos = argindex, .n = state - matchnum }; - ret = e->new_handler(e, CLI_GENERATE, &a); + ret = e->handler(e, CLI_GENERATE, &a); } if (ret) break; @@ -1789,7 +1786,6 @@ int ast_cli_command(int fd, const char *s) char *args[AST_MAX_ARGS + 1]; struct ast_cli_entry *e; int x; - int res; char *dup = parse_args(s, &x, args + 1, AST_MAX_ARGS, NULL); if (dup == NULL) @@ -1813,39 +1809,25 @@ int ast_cli_command(int fd, const char *s) */ args[0] = (char *)e; - if (!e->new_handler) /* old style */ - res = e->handler(fd, x, args + 1); - else { - struct ast_cli_args a = { - .fd = fd, .argc = x, .argv = args+1 }; - char *retval = e->new_handler(e, CLI_HANDLER, &a); + struct ast_cli_args a = { + .fd = fd, .argc = x, .argv = args+1 }; + char *retval = e->handler(e, CLI_HANDLER, &a); - if (retval == CLI_SUCCESS) - res = RESULT_SUCCESS; - else if (retval == CLI_SHOWUSAGE) - res = RESULT_SHOWUSAGE; - else - res = RESULT_FAILURE; - } - switch (res) { - case RESULT_SHOWUSAGE: + if (retval == CLI_SHOWUSAGE) { ast_cli(fd, "%s", S_OR(e->usage, "Invalid usage, but no usage information available.\n")); AST_RWLIST_RDLOCK(&helpers); 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_RWLIST_UNLOCK(&helpers); - break; - case RESULT_FAILURE: - ast_cli(fd, "Command '%s' failed.\n", s); - /* FALLTHROUGH */ - default: + } else { + if (retval == CLI_FAILURE) + ast_cli(fd, "Command '%s' failed.\n", s); AST_RWLIST_RDLOCK(&helpers); 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); e->deprecated = 2; } AST_RWLIST_UNLOCK(&helpers); - break; } ast_atomic_fetchadd_int(&e->inuse, -1); done: diff --git a/main/pbx.c b/main/pbx.c index e3498c5adf..972d8e24b3 100644 --- a/main/pbx.c +++ b/main/pbx.c @@ -4230,7 +4230,7 @@ static char *handle_show_switches(struct ast_cli_entry *e, int cmd, struct ast_c if (AST_RWLIST_EMPTY(&switches)) { AST_RWLIST_UNLOCK(&switches); 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"); diff --git a/res/res_crypto.c b/res/res_crypto.c index caaea5aff6..903d87285d 100644 --- a/res/res_crypto.c +++ b/res/res_crypto.c @@ -487,7 +487,7 @@ static void md52sum(char *sum, unsigned char *md5) * \param e CLI command * \param cmd * \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) { @@ -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 cmd * \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) {