[svn-commits] qwell: trunk r90038 - in /trunk: include/asterisk/ main/ res/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Nov 28 14:27:40 CST 2007


Author: qwell
Date: Wed Nov 28 14:27:40 2007
New Revision: 90038

URL: http://svn.digium.com/view/asterisk?view=rev&rev=90038
Log:
Remove "old"-style CLI handler, since nothing uses it anymore.

Closes issue #11403, patch by eliel.  This also completes the janitor project.

Modified:
    trunk/include/asterisk/cli.h
    trunk/main/cli.c
    trunk/main/pbx.c
    trunk/res/res_crypto.c

Modified: trunk/include/asterisk/cli.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/cli.h?view=diff&rev=90038&r1=90037&r2=90038
==============================================================================
--- trunk/include/asterisk/cli.h (original)
+++ trunk/include/asterisk/cli.h Wed Nov 28 14:27:40 2007
@@ -142,60 +142,40 @@
 };
 
 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. */
-
-	/*! 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 */
-
-	/*! 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);
+						* set the first entry to NULL for a new-style entry. */
+
+	const char *summary; 			/*!< Summary of the command (< 60 characters) */
+	const char *usage; 			/*!< Detailed usage information */
+
 	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.

Modified: trunk/main/cli.c
URL: http://svn.digium.com/view/asterisk/trunk/main/cli.c?view=diff&rev=90038&r1=90037&r2=90038
==============================================================================
--- trunk/main/cli.c (original)
+++ trunk/main/cli.c Wed Nov 28 14:27:40 2007
@@ -565,7 +565,7 @@
 	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 @@
 		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 @@
 		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 @@
 	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;
-
-		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;
-	}
+	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->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 @@
 		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 @@
 			 * (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 @@
 	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 @@
 	 */
 	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);
-
-		if (retval == CLI_SUCCESS)
-			res = RESULT_SUCCESS;
-		else if (retval == CLI_SHOWUSAGE)
-			res = RESULT_SHOWUSAGE;
-		else
-			res = RESULT_FAILURE;
-	}
-	switch (res) {
-	case RESULT_SHOWUSAGE:
+	struct ast_cli_args a = {
+		.fd = fd, .argc = x, .argv = args+1 };
+	char *retval = e->handler(e, CLI_HANDLER, &a);
+
+	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:

Modified: trunk/main/pbx.c
URL: http://svn.digium.com/view/asterisk/trunk/main/pbx.c?view=diff&rev=90038&r1=90037&r2=90038
==============================================================================
--- trunk/main/pbx.c (original)
+++ trunk/main/pbx.c Wed Nov 28 14:27:40 2007
@@ -4230,7 +4230,7 @@
 	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");

Modified: trunk/res/res_crypto.c
URL: http://svn.digium.com/view/asterisk/trunk/res/res_crypto.c?view=diff&rev=90038&r1=90037&r2=90038
==============================================================================
--- trunk/res/res_crypto.c (original)
+++ trunk/res/res_crypto.c Wed Nov 28 14:27:40 2007
@@ -487,7 +487,7 @@
  * \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 @@
  * \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)
 {




More information about the svn-commits mailing list