[asterisk-commits] file: branch 1.4 r56783 - /branches/1.4/main/asterisk.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Mon Feb 26 09:36:08 MST 2007


Author: file
Date: Mon Feb 26 10:36:08 2007
New Revision: 56783

URL: http://svn.digium.com/view/asterisk?view=rev&rev=56783
Log:
Allow both of the show version files and core show file versions CLI commands to work. (issue #9135 reported by mvanbaak)

Modified:
    branches/1.4/main/asterisk.c

Modified: branches/1.4/main/asterisk.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/main/asterisk.c?view=diff&rev=56783&r1=56782&r2=56783
==============================================================================
--- branches/1.4/main/asterisk.c (original)
+++ branches/1.4/main/asterisk.c Mon Feb 26 10:36:08 2007
@@ -540,7 +540,7 @@
 "       Optional regular expression pattern is used to filter the file list.\n";
 
 /*! \brief CLI command to list module versions */
-static int handle_show_version_files(int fd, int argc, char *argv[])
+static int handle_show_version_files_deprecated(int fd, int argc, char *argv[])
 {
 #define FORMAT "%-25.25s %-40.40s\n"
 	struct file_version *iterator;
@@ -594,7 +594,61 @@
 #undef FORMAT
 }
 
-static char *complete_show_version_files(const char *line, const char *word, int pos, int state)
+static int handle_show_version_files(int fd, int argc, char *argv[])
+{
+#define FORMAT "%-25.25s %-40.40s\n"
+	struct file_version *iterator;
+	regex_t regexbuf;
+	int havepattern = 0;
+	int havename = 0;
+	int count_files = 0;
+
+	switch (argc) {
+	case 6:
+		if (!strcasecmp(argv[4], "like")) {
+			if (regcomp(&regexbuf, argv[5], REG_EXTENDED | REG_NOSUB))
+				return RESULT_SHOWUSAGE;
+			havepattern = 1;
+		} else
+			return RESULT_SHOWUSAGE;
+		break;
+	case 5:
+		havename = 1;
+		break;
+	case 4:
+		break;
+	default:
+		return RESULT_SHOWUSAGE;
+	}
+
+	ast_cli(fd, FORMAT, "File", "Revision");
+	ast_cli(fd, FORMAT, "----", "--------");
+	AST_LIST_LOCK(&file_versions);
+	AST_LIST_TRAVERSE(&file_versions, iterator, list) {
+		if (havename && strcasecmp(iterator->file, argv[4]))
+			continue;
+		
+		if (havepattern && regexec(&regexbuf, iterator->file, 0, NULL, 0))
+			continue;
+
+		ast_cli(fd, FORMAT, iterator->file, iterator->version);
+		count_files++;
+		if (havename)
+			break;
+	}
+	AST_LIST_UNLOCK(&file_versions);
+	if (!havename) {
+		ast_cli(fd, "%d files listed.\n", count_files);
+	}
+
+	if (havepattern)
+		regfree(&regexbuf);
+
+	return RESULT_SUCCESS;
+#undef FORMAT
+}
+
+static char *complete_show_version_files_deprecated(const char *line, const char *word, int pos, int state)
 {
 	struct file_version *find;
 	int which = 0;
@@ -615,6 +669,29 @@
 
 	return ret;
 }
+
+static char *complete_show_version_files(const char *line, const char *word, int pos, int state)
+{
+	struct file_version *find;
+	int which = 0;
+	char *ret = NULL;
+	int matchlen = strlen(word);
+	
+	if (pos != 4)
+		return NULL;
+
+	AST_LIST_LOCK(&file_versions);
+	AST_LIST_TRAVERSE(&file_versions, find, list) {
+		if (!strncasecmp(word, find->file, matchlen) && ++which > state) {
+			ret = ast_strdup(find->file);
+			break;
+		}
+	}
+	AST_LIST_UNLOCK(&file_versions);
+
+	return ret;
+}
+
 #endif /* ! LOW_MEMORY */
 
 int ast_register_atexit(void (*func)(void))
@@ -1550,8 +1627,8 @@
 #if !defined(LOW_MEMORY)
 static struct ast_cli_entry cli_show_version_files_deprecated = {
 	{ "show", "version", "files", NULL },
-	handle_show_version_files, NULL,
-	NULL, complete_show_version_files };
+	handle_show_version_files_deprecated, NULL,
+	NULL, complete_show_version_files_deprecated };
 
 static struct ast_cli_entry cli_show_profile_deprecated = {
 	{ "show", "profile", NULL },



More information about the asterisk-commits mailing list