diff options
author | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-06-06 20:27:51 +0000 |
---|---|---|
committer | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-06-06 20:27:51 +0000 |
commit | b2cbb6a75dfc8ea70554192ea223c3bd5dd52ed8 (patch) | |
tree | 2caa31e5bbb676cf8588f73516608ecef258757b /asterisk.c | |
parent | 2d6a1fbb231a5e8e082a2172a31d8def4a6e9607 (diff) |
remove experimental module version tags
add per-file revision tags and 'show version files' CLI command
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@5864 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'asterisk.c')
-rwxr-xr-x | asterisk.c | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/asterisk.c b/asterisk.c index 1c0ba53d0..91db7d9a5 100755 --- a/asterisk.c +++ b/asterisk.c @@ -28,12 +28,16 @@ #include <grp.h> #include <pwd.h> #include <sys/stat.h> +#include <regex.h> #if defined(__FreeBSD__) || defined( __NetBSD__ ) || defined(SOLARIS) #include <netdb.h> #endif #include "asterisk.h" + +ASTERISK_FILE_VERSION("$Revision$") + #include "asterisk/logger.h" #include "asterisk/options.h" #include "asterisk/cli.h" @@ -60,6 +64,7 @@ #include "asterisk/config.h" #include "asterisk/version.h" #include "asterisk/build.h" +#include "asterisk/linkedlists.h" #include "defaults.h" @@ -147,6 +152,85 @@ static int shuttingdown = 0; static int restartnow = 0; static pthread_t consolethread = AST_PTHREADT_NULL; +struct file_version { + const char *file; + const char *version; + AST_LIST_ENTRY(file_version) list; +}; + +static AST_LIST_HEAD_STATIC(file_versions, file_version); + +void ast_register_file_version(const char *file, const char *version) +{ + struct file_version *new; + + new = calloc(1, sizeof(*new)); + if (!new) + return; + + new->file = file; + new->version = version; + AST_LIST_LOCK(&file_versions); + AST_LIST_INSERT_HEAD(&file_versions, new, list); + AST_LIST_UNLOCK(&file_versions); +} + +void ast_unregister_file_version(const char *file) +{ + struct file_version *find; + + AST_LIST_LOCK(&file_versions); + AST_LIST_TRAVERSE_SAFE_BEGIN(&file_versions, find, list) { + if (!strcasecmp(find->file, file)) { + AST_LIST_REMOVE_CURRENT(&file_versions, list); + break; + } + } + AST_LIST_TRAVERSE_SAFE_END; + AST_LIST_UNLOCK(&file_versions); +} + +static char show_version_files_help[] = +"Usage: show version files [like <pattern>]\n" +" Shows the revision numbers of the files used to build this copy of Asterisk.\n" +" Optional regular expression pattern is used to filter the file list.\n"; + +static int handle_show_version_files(int fd, int argc, char *argv[]) +{ + struct file_version *iterator; + + AST_LIST_LOCK(&file_versions); + AST_LIST_TRAVERSE(&file_versions, iterator, list) { + ast_cli(fd, "%-25.25s %-20.20s\n", iterator->file, iterator->version); + } + AST_LIST_UNLOCK(&file_versions); + return RESULT_SUCCESS; +} + +static char *complete_show_version_files(char *line, char *word, int pos, int state) +{ + struct file_version *find; + int which = 0; + char *ret = NULL; + int matchlen = strlen(word); + + if (pos != 3) + return NULL; + + AST_LIST_LOCK(&file_versions); + AST_LIST_TRAVERSE(&file_versions, find, list) { + if (!strncasecmp(word, find->file, matchlen)) { + if (++which > state) { + ret = strdup(find->file); + break; + } + } + } + AST_LIST_UNLOCK(&file_versions); + + return ret; +} + int ast_register_atexit(void (*func)(void)) { int res = -1; @@ -936,6 +1020,8 @@ static struct ast_cli_entry core_cli[] = { "Restart Asterisk at empty call volume", restart_when_convenient_help }, { { "!", NULL }, handle_bang, "Execute a shell command", bang_help }, + { { "show", "version", "files", NULL }, handle_show_version_files, + "Show versions of files used to build Asterisk", show_version_files_help, complete_show_version_files }, }; static int ast_el_read_char(EditLine *el, char *cp) |