[asterisk-commits] rizzo: branch rizzo/astobj2 r47668 - in /team/rizzo/astobj2: include/asterisk...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Wed Nov 15 10:18:11 MST 2006


Author: rizzo
Date: Wed Nov 15 11:18:11 2006
New Revision: 47668

URL: http://svn.digium.com/view/asterisk?view=rev&rev=47668
Log:
update to the version in trunk


Modified:
    team/rizzo/astobj2/include/asterisk/cli.h
    team/rizzo/astobj2/main/cli.c

Modified: team/rizzo/astobj2/include/asterisk/cli.h
URL: http://svn.digium.com/view/asterisk/team/rizzo/astobj2/include/asterisk/cli.h?view=diff&rev=47668&r1=47667&r2=47668
==============================================================================
--- team/rizzo/astobj2/include/asterisk/cli.h (original)
+++ team/rizzo/astobj2/include/asterisk/cli.h Wed Nov 15 11:18:11 2006
@@ -188,7 +188,9 @@
 	AST_LIST_ENTRY(ast_cli_entry) list;
 };
 
-#define NEW_CLI(fn, txt)	{ .new_handler = fn, .summary = txt }
+/* 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 NEW_CLI(fn, txt , ... )	{ .new_handler = fn, .summary = txt, ## __VA_ARGS__ }
 
 /*!
  * Helper function to generate cli entries from a NULL-terminated array.

Modified: team/rizzo/astobj2/main/cli.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/astobj2/main/cli.c?view=diff&rev=47668&r1=47667&r2=47668
==============================================================================
--- team/rizzo/astobj2/main/cli.c (original)
+++ team/rizzo/astobj2/main/cli.c Wed Nov 15 11:18:11 2006
@@ -75,36 +75,12 @@
 
 static AST_LIST_HEAD_STATIC(helpers, ast_cli_entry);
 
-static char load_help[] = 
-"Usage: module load <module name>\n"
-"       Loads the specified module into Asterisk.\n";
-
-static char unload_help[] = 
-"Usage: module unload [-f|-h] <module name>\n"
-"       Unloads the specified module from Asterisk. The -f\n"
-"       option causes the module to be unloaded even if it is\n"
-"       in use (may cause a crash) and the -h module causes the\n"
-"       module to be unloaded even if the module says it cannot, \n"
-"       which almost always will cause a crash.\n";
-
 static char help_help[] =
 "Usage: help [topic]\n"
 "       When called with a topic as an argument, displays usage\n"
 "       information on the given command. If called without a\n"
 "       topic, it provides a list of commands.\n";
 
-static char chanlist_help[] = 
-"Usage: core show channels [concise|verbose]\n"
-"       Lists currently defined channels and some information about them. If\n"
-"       'concise' is specified, the format is abridged and in a more easily\n"
-"       machine parsable format. If 'verbose' is specified, the output includes\n"
-"       more and longer fields.\n";
-
-static char reload_help[] = 
-"Usage: module reload [module ...]\n"
-"       Reloads configuration files for all listed modules which support\n"
-"       reloading, or for all supported modules if none are listed.\n";
-
 static char logger_mute_help[] = 
 "Usage: logger mute\n"
 "       Disables logging output to the current console, making it possible to\n"
@@ -121,51 +97,99 @@
 "       Optional regular expression pattern is matched to group names for each\n"
 "       channel.\n";
 
-static int handle_load(int fd, int argc, char *argv[])
+static char *complete_fn(const char *word, int state)
+{
+	char *c;
+	char filename[256];
+
+	if (word[0] == '/')
+		ast_copy_string(filename, word, sizeof(filename));
+	else
+		snprintf(filename, sizeof(filename), "%s/%s", ast_config_AST_MODULE_DIR, word);
+
+	/* XXX the following function is not reentrant, so we better not use it */
+	c = filename_completion_function(filename, state);
+	
+	if (c && word[0] != '/')
+		c += (strlen(ast_config_AST_MODULE_DIR) + 1);
+	
+	return c ? strdup(c) : c;
+}
+
+static char *handle_load(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	/* "module load <mod>" */
-	if (argc != 3)
-		return RESULT_SHOWUSAGE;
-	if (ast_load_resource(argv[2])) {
-		ast_cli(fd, "Unable to load module %s\n", argv[2]);
-		return RESULT_FAILURE;
-	}
-	return RESULT_SUCCESS;
-}
-
-static int handle_load_deprecated(int fd, int argc, char *argv[])
-{
-	/* I know it is nasty, but they do look very similar, and we never access argv[0] */
-	return handle_load(fd, argc+1, argv - 1);
-}
-
-static int handle_reload(int fd, int argc, char *argv[])
-{
-	/* "module reload [mod_1 ... mod_N]" */
-	struct ast_cli_entry *e = (struct ast_cli_entry *)argv[-1];
-
-	if (argc == e->args)
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "module load";
+		e->usage =
+			"Usage: module load <module name>\n"
+			"       Loads the specified module into Asterisk.\n";
+		return NULL;
+
+	case CLI_GENERATE:
+		if (a->argc != e->args + 1)
+			return NULL;
+		return complete_fn(a->word, a->n);
+	}
+	if (a->argc != e->args + 1)
+		return CLI_SHOWUSAGE;
+	if (ast_load_resource(a->argv[e->args])) {
+		ast_cli(a->fd, "Unable to load module %s\n", a->argv[e->args]);
+		return CLI_FAILURE;
+	}
+	return CLI_SUCCESS;
+}
+
+static char *handle_load_deprecated(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	char *res = handle_load(e, cmd, a);
+	if (cmd == CLI_INIT)
+		e->command = "load";
+	return res;
+}
+
+static char *handle_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	int x;
+
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "module reload";
+		e->usage =
+			"Usage: module reload [module ...]\n"
+			"       Reloads configuration files for all listed modules which support\n"
+			"       reloading, or for all supported modules if none are listed.\n";
+		return NULL;
+
+	case CLI_GENERATE:
+		return ast_module_helper(a->line, a->word, a->pos, a->n, a->pos, 1);
+	}
+	if (a->argc == e->args) {
 		ast_module_reload(NULL);
-	else {
-		int x;
-		for (x = e->args; x < argc; x++) {
-			int res = ast_module_reload(argv[x]);
-			switch(res) {
-			case 0:
-				ast_cli(fd, "No such module '%s'\n", argv[x]);
-				break;
-			case 1:
-				ast_cli(fd, "Module '%s' does not support reload\n", argv[x]);
-				break;
-			}
-		}
-	}
-	return RESULT_SUCCESS;
-}
-
-static int handle_reload_deprecated(int fd, int argc, char *argv[])
-{
-	return handle_reload(fd, argc+1, argv-1);	/* see comment in handle_load_deprecated() */
+		return CLI_SUCCESS;
+	}
+	for (x = e->args; x < a->argc; 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) {
+		case 0:
+			ast_cli(a->fd, "No such module '%s'\n", a->argv[x]);
+			break;
+		case 1:
+			ast_cli(a->fd, "Module '%s' does not support reload\n", a->argv[x]);
+			break;
+		}
+	}
+	return CLI_SUCCESS;
+}
+
+static char *handle_reload_deprecated(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	char *s = handle_reload(e, cmd, a);
+	if (cmd == CLI_INIT)		/* override command name */
+		e->command = "reload";
+	return s;
 }
 
 static char *handle_verbose(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
@@ -310,38 +334,59 @@
 	return RESULT_SUCCESS;
 }
 
-static int handle_unload(int fd, int argc, char *argv[])
+static char *handle_unload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	/* "module unload mod_1 [mod_2 .. mod_N]" */
 	int x;
 	int force = AST_FORCE_SOFT;
-	if (argc < 3)
-		return RESULT_SHOWUSAGE;
-	for (x = 2; x < argc; x++) {
-		if (argv[x][0] == '-') {
-			switch(argv[x][1]) {
-			case 'f':
-				force = AST_FORCE_FIRM;
-				break;
-			case 'h':
-				force = AST_FORCE_HARD;
-				break;
-			default:
-				return RESULT_SHOWUSAGE;
-			}
-		} else if (x != argc - 1) 
-			return RESULT_SHOWUSAGE;
-		else if (ast_unload_resource(argv[x], force)) {
-			ast_cli(fd, "Unable to unload resource %s\n", argv[x]);
-			return RESULT_FAILURE;
-		}
-	}
-	return RESULT_SUCCESS;
-}
-
-static int handle_unload_deprecated(int fd, int argc, char *argv[])
-{
-	return handle_unload(fd, argc+1, argv - 1); /* see commment in handle_load_deprecated() */
+	char *s;
+
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "module unload";
+		e->usage =
+			"Usage: module unload [-f|-h] <module_1> [<module_2> ... ]\n"
+			"       Unloads the specified module from Asterisk. The -f\n"
+			"       option causes the module to be unloaded even if it is\n"
+			"       in use (may cause a crash) and the -h module causes the\n"
+			"       module to be unloaded even if the module says it cannot, \n"
+			"       which almost always will cause a crash.\n";
+		return NULL;
+
+	case CLI_GENERATE:
+		return ast_module_helper(a->line, a->word, a->pos, a->n, a->pos, 0);
+	}
+	if (a->argc < e->args + 1)
+		return CLI_SHOWUSAGE;
+	x = e->args;	/* first argument */
+	s = a->argv[x];
+	if (s[0] == '-') {
+		if (s[1] == 'f')
+			force = AST_FORCE_FIRM;
+		else if (s[1] == 'h')
+			force = AST_FORCE_HARD;
+		else
+			return CLI_SHOWUSAGE;
+		if (a->argc < e->args + 2)	/* need at least one module name */
+			return CLI_SHOWUSAGE;
+		x++;	/* skip this argument */
+	}
+
+	for (; x < a->argc; x++) {
+		if (ast_unload_resource(a->argv[x], force)) {
+			ast_cli(a->fd, "Unable to unload resource %s\n", a->argv[x]);
+			return CLI_FAILURE;
+		}
+	}
+	return CLI_SUCCESS;
+}
+
+static char *handle_unload_deprecated(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	char *res = handle_unload(e, cmd, a);
+	if (cmd == CLI_INIT)
+		e->command = "unload";	/* XXX override */
+	return res;
 }
 
 #define MODLIST_FORMAT  "%-30s %-40.40s %-10d\n"
@@ -485,8 +530,7 @@
 #undef MODLIST_FORMAT
 #undef MODLIST_FORMAT2
 
-/* core show channels [concise|verbose] */
-static int handle_chanlist(int fd, int argc, char *argv[])
+static char *handle_chanlist(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 #define FORMAT_STRING  "%-20.20s %-20.20s %-7.7s %-30.30s\n"
 #define FORMAT_STRING2 "%-20.20s %-20.20s %-7.7s %-30.30s\n"
@@ -495,18 +539,39 @@
 #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"
 
 	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 == 4 && (!strcasecmp(argv[3],"concise")));
-	verbose = (argc == 4 && (!strcasecmp(argv[3],"verbose")));
-
-	if (argc < 3 || argc > 4 || (argc == 4 && !concise && !verbose))
-		return RESULT_SHOWUSAGE;
+	int fd, argc;
+	char **argv;
+
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "core show channels";
+		e->usage =
+			"Usage: core show channels [concise|verbose]\n"
+			"       Lists currently defined channels and some information about them. If\n"
+			"       'concise' is specified, the format is abridged and in a more easily\n"
+			"       machine parsable format. If 'verbose' is specified, the output includes\n"
+			"       more and longer fields.\n";
+		return NULL;
+
+	case CLI_GENERATE: {
+		static char *choices[] = { "concise", "verbose", NULL };
+		return (a->pos != e->args) ? NULL : ast_cli_complete(a->word, choices, a->n);
+		}
+	}
+	fd = a->fd;
+	argc = a->argc;
+	argv = a->argv;
+
+	if (a->argc == e->args + 1) {
+		if (!strcasecmp(argv[3],"concise"))
+			concise = 1;
+		else if (!strcasecmp(argv[3],"verbose"))
+			verbose = 1;
+		else
+			return CLI_SHOWUSAGE;
+	} else if (a->argc != e->args)
+		return CLI_SHOWUSAGE;
 
 	if (!concise && !verbose)
 		ast_cli(fd, FORMAT_STRING2, "Channel", "Location", "State", "Application(Data)");
@@ -516,18 +581,18 @@
 
 	while ((c = ast_channel_walk_locked(c)) != NULL) {
 		struct ast_channel *bc = ast_bridged_channel(c);
+		char durbuf[10] = "-";
+
 		if ((concise || verbose)  && c->cdr && !ast_tvzero(c->cdr->start)) {
-			duration = (int)(ast_tvdiff_ms(ast_tvnow(), c->cdr->start) / 1000);
+			int duration = (int)(ast_tvdiff_ms(ast_tvnow(), c->cdr->start) / 1000);
 			if (verbose) {
-				durh = duration / 3600;
-				durm = (duration % 3600) / 60;
-				durs = duration % 60;
+				int durh = duration / 3600;
+				int durm = (duration % 3600) / 60;
+				int 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),
@@ -547,14 +612,13 @@
 			        S_OR(c->accountcode, ""),
 				bc ? bc->name : "(None)");
 		} else {
+			char locbuf[40] = "(None)";
+			char appdata[40] = "(None)";
+
 			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)");
+				snprintf(appdata, sizeof(appdata), "%s(%s)", c->appl, S_OR(c->data, ""));
 			ast_cli(fd, FORMAT_STRING, c->name, locbuf, ast_state2str(c->_state), appdata);
 		}
 		numchans++;
@@ -569,7 +633,7 @@
 		else
 			ast_cli(fd, "%d active call%s\n", ast_active_calls(), ESS(ast_active_calls()));
 	}
-	return RESULT_SUCCESS;
+	return CLI_SUCCESS;
 	
 #undef FORMAT_STRING
 #undef FORMAT_STRING2
@@ -581,10 +645,6 @@
 static char showchan_help[] = 
 "Usage: core show channel <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[] = 
 "Usage: _command complete \"<line>\" text state\n"
@@ -690,52 +750,35 @@
 	return RESULT_SUCCESS;
 }
 
-static int handle_debugchan_deprecated(int fd, int argc, char *argv[])
-{
-	struct ast_channel *c=NULL;
-	int is_all;
-
-	/* 'debug channel {all|chan_id}' */
-	if (argc != 4)
-		return RESULT_SHOWUSAGE;
-
-	is_all = !strcasecmp("all", argv[3]);
-	if (is_all) {
-		global_fin |= DEBUGCHAN_FLAG;
-		global_fout |= DEBUGCHAN_FLAG;
-		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) {
-		if (!(c->fin & DEBUGCHAN_FLAG) || !(c->fout & DEBUGCHAN_FLAG)) {
-			c->fin |= DEBUGCHAN_FLAG;
-			c->fout |= DEBUGCHAN_FLAG;
-			ast_cli(fd, "Debugging enabled 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 enabled\n");
-	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;
 	int is_all, is_off = 0;
 
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "core set debug channel";
+		e->usage =
+			"Usage: core set debug channel <all|channel> [off]\n"
+			"       Enables/disables debugging on all or on a specific channel.\n";
+		return NULL;
+
+	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 (argc == 6 && strcmp(argv[5], "off") == 0)
-		is_off = 1;
-	else if (argc != 5)
-		return RESULT_SHOWUSAGE;
-
-	is_all = !strcasecmp("all", argv[4]);
+	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_off) {
 			global_fin &= ~DEBUGCHAN_FLAG;
@@ -746,9 +789,9 @@
 		}
 		c = ast_channel_walk_locked(NULL);
 	} else {
-		c = ast_get_channel_by_name_locked(argv[4]);
+		c = ast_get_channel_by_name_locked(a->argv[e->args]);
 		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) {
 		if (!(c->fin & DEBUGCHAN_FLAG) || !(c->fout & DEBUGCHAN_FLAG)) {
@@ -759,47 +802,45 @@
 				c->fin |= 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);
 		if (!is_all)
 			break;
 		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;
 }
 
-static int handle_nodebugchan_deprecated(int fd, int argc, char *argv[])
-{
-	struct ast_channel *c=NULL;
-	int is_all;
-	/* 'no debug channel {all|chan_id}' */
-	if (argc != 4)
-		return RESULT_SHOWUSAGE;
-	is_all = !strcasecmp("all", argv[3]);
-	if (is_all) {
-		global_fin &= ~DEBUGCHAN_FLAG;
-		global_fout &= ~DEBUGCHAN_FLAG;
-		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) {
-		if ((c->fin & DEBUGCHAN_FLAG) || (c->fout & DEBUGCHAN_FLAG)) {
-			c->fin &= ~DEBUGCHAN_FLAG;
-			c->fout &= ~DEBUGCHAN_FLAG;
-			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 char *handle_debugchan_deprecated(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	char *res;
+
+	if (cmd == CLI_HANDLER && a->argc != e->args + 1)
+		return CLI_SHOWUSAGE;
+	res = handle_core_set_debug_channel(e, cmd, a);
+	if (cmd == CLI_INIT)
+		e->command = "debug channel";
+	return res;
+}
+
+static char *handle_nodebugchan_deprecated(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	char *res;
+	if (cmd == CLI_HANDLER) {
+		if (a->argc != e->args + 1)
+			return CLI_SHOWUSAGE;
+		/* pretend we have an extra "off" at the end. We can do this as the array
+		 * is NULL terminated so we overwrite that entry.
+		 */
+		a->argv[e->args+1] = "off";
+		a->argc++;
+	}
+	res = handle_core_set_debug_channel(e, cmd, a);
+	if (cmd == CLI_INIT)
+		e->command = "no debug channel";
+	return res;
 }
 		
 static int handle_showchan(int fd, int argc, char *argv[])
@@ -902,13 +943,6 @@
 	return NULL;
 }
 
-static char *complete_show_channels(const char *line, const char *word, int pos, int state)
-{
-	static char *choices[] = { "concise", "verbose", NULL };
-
-	return (pos != 3) ? NULL : ast_cli_complete(word, choices, state);
-}
-
 char *ast_complete_channels(const char *line, const char *word, int pos, int state, int rpos)
 {
 	struct ast_channel *c = NULL;
@@ -945,43 +979,6 @@
 	return ast_complete_channels(line, word, pos, state, 4);
 }
 
-static char *complete_mod_2(const char *line, const char *word, int pos, int state)
-{
-	return ast_module_helper(line, word, pos, state, 1, 1);
-}
-
-static char *complete_mod_3_nr(const char *line, const char *word, int pos, int state)
-{
-	return ast_module_helper(line, word, pos, state, 2, 0);
-}
-
-static char *complete_mod_3(const char *line, const char *word, int pos, int state)
-{
-	if (pos < 2)
-		return NULL;
-	return ast_module_helper(line, word, pos, state, pos, 1);
-}
-
-static char *complete_fn(const char *line, const char *word, int pos, int state)
-{
-	char *c;
-	char filename[256];
-
-	if (pos != 1)
-		return NULL;
-	
-	if (word[0] == '/')
-		ast_copy_string(filename, word, sizeof(filename));
-	else
-		snprintf(filename, sizeof(filename), "%s/%s", ast_config_AST_MODULE_DIR, word);
-	
-	c = filename_completion_function(filename, state);
-	
-	if (c && word[0] != '/')
-		c += (strlen(ast_config_AST_MODULE_DIR) + 1);
-	
-	return c ? strdup(c) : c;
-}
 
 static int group_show_channels(int fd, int argc, char *argv[])
 {
@@ -1067,43 +1064,23 @@
 	{ { NULL }, NULL, NULL, NULL }
 };
 
-static struct ast_cli_entry cli_debug_channel_deprecated = {
-	{ "debug", "channel", NULL },
-	handle_debugchan_deprecated, NULL,
-	NULL, complete_ch_3 };
-
-static struct ast_cli_entry cli_module_load_deprecated = {
-	{ "load", NULL },
-	handle_load_deprecated, NULL,
-	NULL, complete_fn };
-
-static struct ast_cli_entry cli_module_reload_deprecated = {
-	{ "reload", NULL },
-	handle_reload_deprecated, NULL,
-	NULL, complete_mod_2 };
-
-static struct ast_cli_entry cli_module_unload_deprecated = {
-	{ "unload", NULL },
-	handle_unload_deprecated, NULL,
-	NULL, complete_mod_2 };
+static struct ast_cli_entry cli_debug_channel_deprecated = NEW_CLI(handle_debugchan_deprecated, "Enable debugging on channel");
+static struct ast_cli_entry cli_module_load_deprecated = NEW_CLI(handle_load_deprecated, "Load a module");
+static struct ast_cli_entry cli_module_reload_deprecated = NEW_CLI(handle_reload_deprecated, "reload modules by name");
+static struct ast_cli_entry cli_module_unload_deprecated = NEW_CLI(handle_unload_deprecated, "unload modules by name");
 
 static struct ast_cli_entry cli_cli[] = {
 	/* Deprecated, but preferred command is now consolidated (and already has a deprecated command for it). */
-	{ { "no", "debug", "channel", NULL },
-	handle_nodebugchan_deprecated, NULL,
-	NULL, complete_ch_4 },
-
-	{ { "core", "show", "channels", NULL },
-	handle_chanlist, "Display information on channels",
-	chanlist_help, complete_show_channels },
+	NEW_CLI(handle_nodebugchan_deprecated, "Disable debugging on channel(s)"),
+
+	NEW_CLI(handle_chanlist, "Display information on channels"),
 
 	{ { "core", "show", "channel", NULL },
 	handle_showchan, "Display information on a specific channel",
 	showchan_help, complete_ch_4 },
 
-	{ { "core", "set", "debug", "channel", NULL },
-	handle_core_set_debug_channel, "Enable/disable debugging on a channel",
-	debugchan_help, complete_ch_5, &cli_debug_channel_deprecated },
+	NEW_CLI(handle_core_set_debug_channel, "Enable/disable debugging on a channel",
+		.deprecate_cmd = &cli_debug_channel_deprecated),
 
 	NEW_CLI(handle_set_debug, "Set level of debug chattiness"),
 
@@ -1123,17 +1100,11 @@
 
 	NEW_CLI(handle_modlist, "List modules and info"),
 
-	{ { "module", "load", NULL },
-	handle_load, "Load a module by name",
-	load_help, complete_fn, &cli_module_load_deprecated },
-
-	{ { "module", "reload", NULL },
-	handle_reload, "Reload configuration",
-	reload_help, complete_mod_3, &cli_module_reload_deprecated },
-
-	{ { "module", "unload", NULL },
-	handle_unload, "Unload a module by name",
-	unload_help, complete_mod_3_nr, &cli_module_unload_deprecated },
+	NEW_CLI(handle_load, "Load a module by name", .deprecate_cmd = &cli_module_load_deprecated),
+
+	NEW_CLI(handle_reload, "Reload configuration", .deprecate_cmd = &cli_module_reload_deprecated),
+
+	NEW_CLI(handle_unload, "Unload a module by name", .deprecate_cmd = &cli_module_unload_deprecated ),
 
 	NEW_CLI(handle_showuptime, "Show uptime information"),
 
@@ -1232,8 +1203,10 @@
 				continue;
 			/* 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;
+		}
 	}
 	return e ? e : cand;
 }



More information about the asterisk-commits mailing list