From fcb999c01c22548f582f167e1b1e86f0c3a5a2fd Mon Sep 17 00:00:00 2001 From: "Kevin P. Fleming" Date: Mon, 18 Sep 2006 19:54:18 +0000 Subject: merge qwell's CLI verbification work git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@43212 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- main/asterisk.c | 165 ++++++++++++++---- main/astmm.c | 31 ++-- main/cdr.c | 12 +- main/channel.c | 31 +++- main/cli.c | 517 +++++++++++++++++++++++++++++++++++++++++++++++-------- main/config.c | 16 +- main/db.c | 39 +++-- main/dnsmgr.c | 18 +- main/file.c | 20 ++- main/frame.c | 159 +++++++++++++++-- main/http.c | 20 ++- main/image.c | 35 ++-- main/logger.c | 28 +-- main/manager.c | 65 ++++--- main/pbx.c | 403 +++++++++++++++++++++++++++++++++++++------ main/rtp.c | 231 +++++++++++++++++++------ main/translate.c | 86 ++++++++- main/udptl.c | 41 +++-- 18 files changed, 1550 insertions(+), 367 deletions(-) (limited to 'main') diff --git a/main/asterisk.c b/main/asterisk.c index e5b117baf..e8bf9575b 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -438,7 +438,7 @@ int64_t ast_mark(int i, int startstop) return prof_data->e[i].mark; } -static int handle_show_profile(int fd, int argc, char *argv[]) +static int handle_show_profile_deprecated(int fd, int argc, char *argv[]) { int i, min, max; char *search = NULL; @@ -484,9 +484,55 @@ static int handle_show_profile(int fd, int argc, char *argv[]) return 0; } +static int handle_show_profile(int fd, int argc, char *argv[]) +{ + int i, min, max; + char *search = NULL; + + if (prof_data == NULL) + return 0; + + min = 0; + max = prof_data->entries; + if (argc >= 3) { /* specific entries */ + if (isdigit(argv[2][0])) { + min = atoi(argv[2]); + if (argc == 4 && strcmp(argv[3], "-")) + max = atoi(argv[3]); + } else + search = argv[2]; + } + if (max > prof_data->entries) + max = prof_data->entries; + if (!strcmp(argv[1], "clear")) { + for (i= min; i < max; i++) { + if (!search || strstr(prof_data->e[i].name, search)) { + prof_data->e[i].value = 0; + prof_data->e[i].events = 0; + } + } + return 0; + } + ast_cli(fd, "profile values (%d, allocated %d)\n-------------------\n", + prof_data->entries, prof_data->max_size); + ast_cli(fd, "%6s %8s %10s %12s %12s %s\n", "ID", "Scale", "Events", + "Value", "Average", "Name"); + for (i = min; i < max; i++) { + struct profile_entry *e = &prof_data->e[i]; + if (!search || strstr(prof_data->e[i].name, search)) + ast_cli(fd, "%6d: [%8ld] %10ld %12lld %12lld %s\n", + i, + (long)e->scale, + (long)e->events, (long long)e->value, + (long long)(e->events ? e->value / e->events : e->value), + e->name); + } + return 0; +} + static char show_version_files_help[] = -"Usage: show version files [like ]\n" -" Shows the revision numbers of the files used to build this copy of Asterisk.\n" +"Usage: file list version [like ]\n" +" Lists 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"; /*! \brief CLI command to list module versions */ @@ -1471,38 +1517,83 @@ static int show_license(int fd, int argc, char *argv[]) #define ASTERISK_PROMPT2 "%s*CLI> " -static struct ast_cli_entry core_cli[] = { - { { "abort", "halt", NULL }, handle_abort_halt, - "Cancel a running halt", abort_halt_help }, - { { "stop", "now", NULL }, handle_shutdown_now, - "Shut down Asterisk immediately", shutdown_now_help }, - { { "stop", "gracefully", NULL }, handle_shutdown_gracefully, - "Gracefully shut down Asterisk", shutdown_gracefully_help }, - { { "stop", "when","convenient", NULL }, handle_shutdown_when_convenient, - "Shut down Asterisk at empty call volume", shutdown_when_convenient_help }, - { { "restart", "now", NULL }, handle_restart_now, - "Restart Asterisk immediately", restart_now_help }, - { { "restart", "gracefully", NULL }, handle_restart_gracefully, - "Restart Asterisk gracefully", restart_gracefully_help }, - { { "restart", "when", "convenient", NULL }, handle_restart_when_convenient, - "Restart Asterisk at empty call volume", restart_when_convenient_help }, - { { "show", "warranty", NULL }, show_warranty, - "Show the warranty (if any) for this copy of Asterisk", show_warranty_help }, - { { "show", "license", NULL }, show_license, - "Show the license(s) for this copy of Asterisk", show_license_help }, - { { "show", "version", NULL }, handle_version, - "Display version info", version_help }, - { { "!", NULL }, handle_bang, - "Execute a shell command", bang_help }, #if !defined(LOW_MEMORY) - { { "show", "version", "files", NULL }, handle_show_version_files, - "Show versions of files used to build Asterisk", show_version_files_help, complete_show_version_files }, - { { "show", "threads", NULL }, handle_show_threads, - "Show running threads", show_threads_help, NULL }, - { { "show", "profile", NULL }, handle_show_profile, - "Show profiling info"}, - { { "clear", "profile", NULL }, handle_show_profile, - "Clear profiling info"}, +static struct ast_cli_entry cli_show_version_files_deprecated = { + { "show", "version", "files", NULL }, + handle_show_version_files, NULL, + NULL, complete_show_version_files }; + +static struct ast_cli_entry cli_show_profile_deprecated = { + { "show", "profile", NULL }, + handle_show_profile_deprecated, NULL, + NULL }; + +static struct ast_cli_entry cli_clear_profile_deprecated = { + { "clear", "profile", NULL }, + handle_show_profile_deprecated, NULL, + NULL }; +#endif /* ! LOW_MEMORY */ + +static struct ast_cli_entry cli_asterisk[] = { + { { "abort", "halt", NULL }, + handle_abort_halt, "Cancel a running halt", + abort_halt_help }, + + { { "stop", "now", NULL }, + handle_shutdown_now, "Shut down Asterisk immediately", + shutdown_now_help }, + + { { "stop", "gracefully", NULL }, + handle_shutdown_gracefully, "Gracefully shut down Asterisk", + shutdown_gracefully_help }, + + { { "stop", "when", "convenient", NULL }, + handle_shutdown_when_convenient, "Shut down Asterisk at empty call volume", + shutdown_when_convenient_help }, + + { { "restart", "now", NULL }, + handle_restart_now, "Restart Asterisk immediately", restart_now_help }, + + { { "restart", "gracefully", NULL }, + handle_restart_gracefully, "Restart Asterisk gracefully", + restart_gracefully_help }, + + { { "restart", "when", "convenient", NULL }, + handle_restart_when_convenient, "Restart Asterisk at empty call volume", + restart_when_convenient_help }, + + { { "show", "warranty", NULL }, + show_warranty, "Show the warranty (if any) for this copy of Asterisk", + show_warranty_help }, + + { { "show", "license", NULL }, + show_license, "Show the license(s) for this copy of Asterisk", + show_license_help }, + + { { "show", "version", NULL }, + handle_version, "Display version info", + version_help }, + + { { "!", NULL }, + handle_bang, "Execute a shell command", + bang_help }, + +#if !defined(LOW_MEMORY) + { { "file", "list", "version", NULL }, + handle_show_version_files, "List versions of files used to build Asterisk", + show_version_files_help, complete_show_version_files, &cli_show_version_files_deprecated }, + + { { "show", "threads", NULL }, + handle_show_threads, "Show running threads", + show_threads_help }, + + { { "profile", "list", NULL }, + handle_show_profile, "Display profiling info", + NULL, NULL, &cli_show_profile_deprecated }, + + { { "profile", "clear", NULL }, + handle_show_profile, "Clear profiling info", + NULL, NULL, &cli_clear_profile_deprecated }, #endif /* ! LOW_MEMORY */ }; @@ -2047,9 +2138,9 @@ static void ast_remotecontrol(char * data) pid = atoi(cpid); else pid = -1; - snprintf(tmp, sizeof(tmp), "set verbose atleast %d", option_verbose); + snprintf(tmp, sizeof(tmp), "core verbose %d", option_verbose); fdprint(ast_consock, tmp); - snprintf(tmp, sizeof(tmp), "set debug atleast %d", option_debug); + snprintf(tmp, sizeof(tmp), "core debug %d", option_debug); fdprint(ast_consock, tmp); if (ast_opt_mute) { snprintf(tmp, sizeof(tmp), "log and verbose output currently muted ('logger unmute' to unmute)"); @@ -2708,7 +2799,7 @@ int main(int argc, char *argv[]) #endif time(&ast_startuptime); - ast_cli_register_multiple(core_cli, sizeof(core_cli) / sizeof(core_cli[0])); + ast_cli_register_multiple(cli_asterisk, sizeof(cli_asterisk) / sizeof(struct ast_cli_entry)); if (ast_opt_console) { /* Console stuff now... */ diff --git a/main/astmm.c b/main/astmm.c index b3b68dc06..990fe26f0 100644 --- a/main/astmm.c +++ b/main/astmm.c @@ -302,7 +302,7 @@ static int handle_show_memory(int fd, int argc, char *argv[]) unsigned int count = 0; unsigned int *fence; - if (argc > 3) + if (argc > 3) fn = argv[3]; ast_mutex_lock(&showmemorylock); @@ -395,31 +395,40 @@ static int handle_show_memory_summary(int fd, int argc, char *argv[]) } static char show_memory_help[] = -"Usage: show memory allocations []\n" +"Usage: memory show allocations []\n" " Dumps a list of all segments of allocated memory, optionally\n" "limited to those from a specific file\n"; static char show_memory_summary_help[] = -"Usage: show memory summary []\n" +"Usage: memory show summary []\n" " Summarizes heap memory allocations by file, or optionally\n" "by function, if a file is specified\n"; -static struct ast_cli_entry show_memory_allocations_cli = - { { "show", "memory", "allocations", NULL }, +static struct ast_cli_entry cli_show_memory_allocations_deprecated = { + { "show", "memory", "allocations", NULL }, + handle_show_memory, NULL, + NULL }; + +static struct ast_cli_entry cli_show_memory_summary_deprecated = { + { "show", "memory", "summary", NULL }, + handle_show_memory_summary, NULL, + NULL }; + +static struct ast_cli_entry cli_memory[] = { + { { "memory", "show", "allocations", NULL }, handle_show_memory, "Display outstanding memory allocations", - show_memory_help }; + show_memory_help, NULL, &cli_show_memory_allocations }, -static struct ast_cli_entry show_memory_summary_cli = - { { "show", "memory", "summary", NULL }, + { { "memory", "show", "summary", NULL }, handle_show_memory_summary, "Summarize outstanding memory allocations", - show_memory_summary_help }; + show_memory_summary_help, NULL, &cli_show_memory_summary }, +}; void __ast_mm_init(void) { char filename[PATH_MAX]; - ast_cli_register(&show_memory_allocations_cli); - ast_cli_register(&show_memory_summary_cli); + ast_cli_register_multiple(cli_memory, sizeof(cli_memory) / sizeof(struct ast_cli_entry)); snprintf(filename, sizeof(filename), "%s/mmlog", (char *)ast_config_AST_LOG_DIR); diff --git a/main/cdr.c b/main/cdr.c index 19163cff6..4d3ca86bf 100644 --- a/main/cdr.c +++ b/main/cdr.c @@ -1011,19 +1011,15 @@ static int handle_cli_submit(int fd, int argc, char *argv[]) } static struct ast_cli_entry cli_submit = { - .cmda = { "cdr", "submit", NULL }, - .handler = handle_cli_submit, - .summary = "Posts all pending batched CDR data", - .usage = + { "cdr", "submit", NULL }, + handle_cli_submit, "Posts all pending batched CDR data", "Usage: cdr submit\n" " Posts all pending batched CDR data to the configured CDR backend engine modules.\n" }; static struct ast_cli_entry cli_status = { - .cmda = { "cdr", "status", NULL }, - .handler = handle_cli_status, - .summary = "Display the CDR status", - .usage = + { "cdr", "status", NULL }, + handle_cli_status, "Display the CDR status", "Usage: cdr status\n" " Displays the Call Detail Record engine system status.\n" }; diff --git a/main/channel.c b/main/channel.c index 24fe88a25..9c9f1daa3 100644 --- a/main/channel.c +++ b/main/channel.c @@ -288,18 +288,32 @@ static char *complete_channeltypes(const char *line, const char *word, int pos, } static char show_channeltypes_usage[] = -"Usage: show channeltypes\n" -" Shows available channel types registered in your Asterisk server.\n"; +"Usage: channeltype list\n" +" Lists available channel types registered in your Asterisk server.\n"; static char show_channeltype_usage[] = -"Usage: show channeltype \n" +"Usage: channeltype show \n" " Show details about the specified channel type, .\n"; -static struct ast_cli_entry cli_show_channeltypes = - { { "show", "channeltypes", NULL }, show_channeltypes, "Show available channel types", show_channeltypes_usage }; +static struct ast_cli_entry cli_show_channeltypes_deprecated = { + { "show", "channeltypes", NULL }, + show_channeltypes, NULL, + NULL }; -static struct ast_cli_entry cli_show_channeltype = - { { "show", "channeltype", NULL }, show_channeltype, "Give more details on that channel type", show_channeltype_usage, complete_channeltypes }; +static struct ast_cli_entry cli_show_channeltype_deprecated = { + { "show", "channeltype", NULL }, + show_channeltype, NULL, + NULL, complete_channeltypes }; + +static struct ast_cli_entry cli_channel[] = { + { { "channeltype", "list", NULL }, + show_channeltypes, "List available channel types", + show_channeltypes_usage, NULL, &cli_show_channeltypes_deprecated }, + + { { "channeltype", "show", NULL }, + show_channeltype, "Give more details on that channel type", + show_channeltype_usage, complete_channeltypes, &cli_show_channeltype_deprecated }, +}; /*! \brief Checks to see if a channel is needing hang up */ int ast_check_hangup(struct ast_channel *chan) @@ -4149,8 +4163,7 @@ void ast_moh_cleanup(struct ast_channel *chan) void ast_channels_init(void) { - ast_cli_register(&cli_show_channeltypes); - ast_cli_register(&cli_show_channeltype); + ast_cli_register_multiple(cli_channel, sizeof(cli_channel) / sizeof(struct ast_cli_entry)); } /*! \brief Print call group and pickup group ---*/ diff --git a/main/cli.c b/main/cli.c index 896ef2848..0eb1ef30d 100644 --- a/main/cli.c +++ b/main/cli.c @@ -76,11 +76,11 @@ void ast_cli(int fd, char *fmt, ...) static AST_LIST_HEAD_STATIC(helpers, ast_cli_entry); static char load_help[] = -"Usage: load \n" +"Usage: module load \n" " Loads the specified module into Asterisk.\n"; static char unload_help[] = -"Usage: unload [-f|-h] \n" +"Usage: module unload [-f|-h] \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" @@ -94,28 +94,33 @@ static char help_help[] = " topic, it provides a list of commands.\n"; static char chanlist_help[] = -"Usage: show channels [concise|verbose]\n" +"Usage: channel list [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: reload [module ...]\n" +"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 set_verbose_help[] = -"Usage: set verbose \n" +static char verbose_help[] = +"Usage: core verbose \n" " Sets level of verbose messages to be displayed. 0 means\n" " no messages should be displayed. Equivalent to -v[v[v...]]\n" " on startup\n"; -static char set_debug_help[] = -"Usage: set debug \n" +static char debug_help[] = +"Usage: core debug [filename]\n" " Sets level of core debug messages to be displayed. 0 means\n" -" no messages should be displayed. Equivalent to -d[d[d...]]\n" -" on startup.\n"; +" no messages should be displayed. Equivalent to -d[d[d...]]\n" +" on startup. If filename is specified, debugging will be\n" +" limited to just that file.\n"; + +static char nodebug_help[] = +"Usage: core nodebug\n" +" Turns off core debug messages.\n"; static char logger_mute_help[] = "Usage: logger mute\n" @@ -128,12 +133,12 @@ static char softhangup_help[] = " the next time the driver reads or writes from the channel\n"; static char group_show_channels_help[] = -"Usage: group show channels [pattern]\n" +"Usage: group list channels [pattern]\n" " Lists all currently active channels with channel group(s) specified.\n" " 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 int handle_load_deprecated(int fd, int argc, char *argv[]) { if (argc != 2) return RESULT_SHOWUSAGE; @@ -144,7 +149,18 @@ static int handle_load(int fd, int argc, char *argv[]) return RESULT_SUCCESS; } -static int handle_reload(int fd, int argc, char *argv[]) +static int handle_load(int fd, int argc, char *argv[]) +{ + 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_reload_deprecated(int fd, int argc, char *argv[]) { int x; int res; @@ -167,7 +183,30 @@ static int handle_reload(int fd, int argc, char *argv[]) return RESULT_SUCCESS; } -static int handle_set_verbose(int fd, int argc, char *argv[]) +static int handle_reload(int fd, int argc, char *argv[]) +{ + int x; + int res; + if (argc < 2) + return RESULT_SHOWUSAGE; + if (argc > 2) { + for (x=2;x 0) ast_cli(fd, "Verbosity was %d and is now %d\n", oldval, option_verbose); else if (oldval > 0 && option_verbose > 0) ast_cli(fd, "Verbosity is at least %d\n", option_verbose); else if (oldval > 0 && option_verbose == 0) ast_cli(fd, "Verbosity is now OFF\n"); + + return RESULT_SUCCESS; +} + +static int handle_verbose(int fd, int argc, char *argv[]) +{ + int oldval = option_verbose; + + if (argc == 3) + option_verbose = atoi(argv[2]); + else + return RESULT_SHOWUSAGE; + + if (oldval > 0 && option_verbose == 0) + ast_cli(fd, "Verbosity is now OFF\n"); + else if (option_verbose > 0) { + if (oldval == option_verbose) + ast_cli(fd, "Verbosity is at least %d\n", option_verbose); + else + ast_cli(fd, "Verbosity was %d and is now %d\n", oldval, option_verbose); + } + return RESULT_SUCCESS; } -static int handle_set_debug(int fd, int argc, char *argv[]) +static int handle_set_debug_deprecated(int fd, int argc, char *argv[]) { int val = 0; int oldval = option_debug; @@ -208,12 +270,87 @@ static int handle_set_debug(int fd, int argc, char *argv[]) option_debug = val; } else return RESULT_SHOWUSAGE; + if (oldval != option_debug && option_debug > 0) ast_cli(fd, "Core debug was %d and is now %d\n", oldval, option_debug); else if (oldval > 0 && option_debug > 0) ast_cli(fd, "Core debug is at least %d\n", option_debug); else if (oldval > 0 && option_debug == 0) ast_cli(fd, "Core debug is now OFF\n"); + + return RESULT_SUCCESS; +} + +static int handle_debug(int fd, int argc, char *argv[]) +{ + int oldval = option_debug; + int newlevel; + char *filename = '\0'; + + if ((argc < 3) || (argc > 4)) + return RESULT_SHOWUSAGE; + + if (sscanf(argv[2], "%d", &newlevel) != 1) + return RESULT_SHOWUSAGE; + + option_debug = newlevel; + + if (argc == 4) { + filename = argv[3]; + ast_copy_string(debug_filename, filename, sizeof(debug_filename)); + } else { + debug_filename[0] = '\0'; + } + + if (oldval > 0 && option_debug == 0) + ast_cli(fd, "Core debug is now OFF\n"); + else if (option_debug > 0) { + if (filename) { + if (oldval == option_debug) + ast_cli(fd, "Core debug is at least %d, file '%s'\n", option_debug, filename); + else + ast_cli(fd, "Core debug was %d and is now %d, file '%s'\n", oldval, option_debug, filename); + } else { + if (oldval == option_debug) + ast_cli(fd, "Core debug is at least %d\n", option_debug); + else + ast_cli(fd, "Core debug was %d and is now %d\n", oldval, option_debug); + } + } + + return RESULT_SUCCESS; +} + +static int handle_nodebug(int fd, int argc, char *argv[]) +{ + int oldval = option_debug; + if (argc != 2) + return RESULT_SHOWUSAGE; + + option_debug = 0; + debug_filename[0] = '\0'; + + if (oldval > 0) + ast_cli(fd, "Core debug is now OFF\n"); + return RESULT_SUCCESS; +} + +static int handle_debuglevel_deprecated(int fd, int argc, char *argv[]) +{ + int newlevel; + char *filename = ""; + if ((argc < 3) || (argc > 4)) + return RESULT_SHOWUSAGE; + if (sscanf(argv[2], "%d", &newlevel) != 1) + return RESULT_SHOWUSAGE; + option_debug = newlevel; + if (argc == 4) { + filename = argv[3]; + ast_copy_string(debug_filename, filename, sizeof(debug_filename)); + } else { + debug_filename[0] = '\0'; + } + ast_cli(fd, "Debugging level set to %d, file '%s'\n", newlevel, filename); return RESULT_SUCCESS; } @@ -225,7 +362,7 @@ static int handle_logger_mute(int fd, int argc, char *argv[]) return RESULT_SUCCESS; } -static int handle_unload(int fd, int argc, char *argv[]) +static int handle_unload_deprecated(int fd, int argc, char *argv[]) { int x; int force=AST_FORCE_SOFT; @@ -253,6 +390,34 @@ static int handle_unload(int fd, int argc, char *argv[]) return RESULT_SUCCESS; } +static int handle_unload(int fd, int argc, char *argv[]) +{ + int x; + int force=AST_FORCE_SOFT; + if (argc < 3) + return RESULT_SHOWUSAGE; + for (x=2;x\n" +"Usage: channel show \n" " Shows lots of information about the specified channel.\n"; static char debugchan_help[] = -"Usage: debug channel \n" +"Usage: channel debug \n" " Enables debugging on a specific channel.\n"; -static char debuglevel_help[] = -"Usage: debug level [filename]\n" -" Set debug to specified level (0 to disable). If filename\n" -"is specified, debugging will be limited to just that file.\n"; - static char nodebugchan_help[] = -"Usage: no debug channel \n" +"Usage: channel nodebug \n" " Disables debugging on a specific channel.\n"; static char commandcomplete_help[] = @@ -580,25 +740,6 @@ static int handle_commandcomplete(int fd, int argc, char *argv[]) return RESULT_SUCCESS; } -static int handle_debuglevel(int fd, int argc, char *argv[]) -{ - int newlevel; - char *filename = ""; - if ((argc < 3) || (argc > 4)) - return RESULT_SHOWUSAGE; - if (sscanf(argv[2], "%d", &newlevel) != 1) - return RESULT_SHOWUSAGE; - option_debug = newlevel; - if (argc == 4) { - filename = argv[3]; - ast_copy_string(debug_filename, filename, sizeof(debug_filename)); - } else { - debug_filename[0] = '\0'; - } - ast_cli(fd, "Debugging level set to %d, file '%s'\n", newlevel, filename); - return RESULT_SUCCESS; -} - /* XXX todo: merge next two functions!!! */ static int handle_debugchan(int fd, int argc, char *argv[]) { @@ -634,7 +775,7 @@ static int handle_debugchan(int fd, int argc, char *argv[]) return RESULT_SUCCESS; } -static int handle_nodebugchan(int fd, int argc, char *argv[]) +static int handle_nodebugchan_deprecated(int fd, int argc, char *argv[]) { struct ast_channel *c=NULL; int is_all; @@ -666,6 +807,38 @@ static int handle_nodebugchan(int fd, int argc, char *argv[]) return RESULT_SUCCESS; } +static int handle_nodebugchan(int fd, int argc, char *argv[]) +{ + struct ast_channel *c=NULL; + int is_all; + /* 'no debug channel {all|chan_id}' */ + if (argc != 3) + return RESULT_SHOWUSAGE; + is_all = !strcasecmp("all", argv[2]); + 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[2]); + if (c == NULL) + ast_cli(fd, "No such channel %s\n", argv[2]); + } + 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 int handle_showchan(int fd, int argc, char *argv[]) { struct ast_channel *c=NULL; @@ -814,12 +987,22 @@ static char *complete_mod_2(const char *line, const char *word, int pos, int sta 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) +{ + return ast_module_helper(line, word, pos, state, 2, 1); +} + static char *complete_mod_4(const char *line, const char *word, int pos, int state) { return ast_module_helper(line, word, pos, state, 3, 0); } -static char *complete_fn(const char *line, const char *word, int pos, int state) +static char *complete_fn_deprecated(const char *line, const char *word, int pos, int state) { char *c; char filename[256]; @@ -840,6 +1023,27 @@ static char *complete_fn(const char *line, const char *word, int pos, int state) return c ? strdup(c) : c; } +static char *complete_fn(const char *line, const char *word, int pos, int state) +{ + char *c; + char filename[256]; + + if (pos != 2) + 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[]) { #define FORMAT_STRING "%-25s %-20s %-20s\n" @@ -903,31 +1107,162 @@ static char * complete_help(const char *text, const char *word, int pos, int sta return __ast_cli_generator(text, word, state, 0); } +/* XXX Nothing in this array can currently be deprecated... + You have to change the way find_cli works in order to remove this array + I recommend doing this eventually... + */ static struct ast_cli_entry builtins[] = { /* Keep alphabetized, with longer matches first (example: abcd before abc) */ - { { "_command", "complete", NULL }, handle_commandcomplete, "Command complete", commandcomplete_help }, - { { "_command", "nummatches", NULL }, handle_commandnummatches, "Returns number of command matches", commandnummatches_help }, - { { "_command", "matchesarray", NULL }, handle_commandmatchesarray, "Returns command matches array", commandmatchesarray_help }, - { { "debug", "channel", NULL }, handle_debugchan, "Enable debugging on a channel", debugchan_help, complete_ch_3 }, - { { "debug", "level", NULL }, handle_debuglevel, "Set global debug level", debuglevel_help }, - { { "group", "show", "channels", NULL }, group_show_channels, "Show active channels with group(s)", group_show_channels_help}, - { { "help", NULL }, handle_help, "Display help list, or specific help on a command", help_help, complete_help }, - { { "load", NULL }, handle_load, "Load a module by name", load_help, complete_fn }, - { { "logger", "mute", NULL }, handle_logger_mute, "Toggle logging output to a console", logger_mute_help }, - { { "no", "debug", "channel", NULL }, handle_nodebugchan, "Disable debugging on a channel", nodebugchan_help, complete_ch_4 }, - { { "reload", NULL }, handle_reload, "Reload configuration", reload_help, complete_mod_2 }, - { { "set", "debug", NULL }, handle_set_debug, "Set level of debug chattiness", set_debug_help }, - { { "set", "verbose", NULL }, handle_set_verbose, "Set level of verboseness", set_verbose_help }, - { { "show", "channel", NULL }, handle_showchan, "Display information on a specific channel", showchan_help, complete_ch_3 }, - { { "show", "channels", NULL }, handle_chanlist, "Display information on channels", chanlist_help, complete_show_channels }, - { { "show", "modules", NULL }, handle_modlist, "List modules and info", modlist_help }, - { { "show", "modules", "like", NULL }, handle_modlist, "List modules and info", modlist_help, complete_mod_4 }, - { { "show", "uptime", NULL }, handle_showuptime, "Show uptime information", uptime_help }, - { { "soft", "hangup", NULL }, handle_softhangup, "Request a hangup on a given channel", softhangup_help, complete_ch_3 }, - { { "unload", NULL }, handle_unload, "Unload a module by name", unload_help, complete_mod_2_nr }, + { { "_command", "complete", NULL }, + handle_commandcomplete, "Command complete", + commandcomplete_help }, + + { { "_command", "nummatches", NULL }, + handle_commandnummatches, "Returns number of command matches", + commandnummatches_help }, + + { { "_command", "matchesarray", NULL }, + handle_commandmatchesarray, "Returns command matches array", + commandmatchesarray_help }, + { { NULL }, NULL, NULL, NULL } }; +static struct ast_cli_entry cli_debug_channel_deprecated = { + { "debug", "channel", NULL }, + handle_debugchan, NULL, + NULL, complete_ch_3 }; + +static struct ast_cli_entry cli_debug_level_deprecated = { + { "debug", "level", NULL }, + handle_debuglevel_deprecated, NULL, + NULL }; + +static struct ast_cli_entry cli_group_show_channels_deprecated = { + { "group", "show", "channels", NULL }, + group_show_channels, NULL, + NULL }; + +static struct ast_cli_entry cli_load_deprecated = { + { "load", NULL }, + handle_load_deprecated, NULL, + NULL, complete_fn_deprecated }; + +static struct ast_cli_entry cli_no_debug_channel_deprecated = { + { "no", "debug", "channel", NULL }, + handle_nodebugchan_deprecated, NULL, + NULL, complete_ch_4 }; + +static struct ast_cli_entry cli_reload_deprecated = { + { "reload", NULL }, + handle_reload_deprecated, NULL, + NULL, complete_mod_2 }; + +static struct ast_cli_entry cli_set_debug_deprecated = { + { "set", "debug", NULL }, + handle_set_debug_deprecated, NULL, + NULL, NULL, &cli_debug_level_deprecated }; + +static struct ast_cli_entry cli_set_verbose_deprecated = { + { "set", "verbose", NULL }, + handle_set_verbose_deprecated, NULL, + NULL }; + +static struct ast_cli_entry cli_show_channel_deprecated = { + { "show", "channel", NULL }, + handle_showchan, NULL, + NULL, complete_ch_3 }; + +static struct ast_cli_entry cli_show_channels_deprecated = { + { "show", "channels", NULL }, + handle_chanlist, NULL, + NULL, complete_show_channels }; + +static struct ast_cli_entry cli_show_modules_deprecated = { + { "show", "modules", NULL }, + handle_modlist, NULL, + NULL }; + +static struct ast_cli_entry cli_show_modules_like_deprecated = { + { "show", "modules", "like", NULL }, + handle_modlist, NULL, + NULL, complete_mod_4 }; + +static struct ast_cli_entry cli_unload_deprecated = { + { "unload", NULL }, + handle_unload_deprecated, NULL, + NULL, complete_mod_2_nr }; + +static struct ast_cli_entry cli_cli[] = { + { { "channel", "list", NULL }, + handle_chanlist, "Display information on channels", + chanlist_help, complete_show_channels, &cli_show_channels_deprecated }, + + { { "channel", "show", NULL }, + handle_showchan, "Display information on a specific channel", + showchan_help, complete_ch_3, &cli_show_channel_deprecated }, + + { { "channel", "debug", NULL }, + handle_debugchan, "Enable debugging on a channel", + debugchan_help, complete_ch_3, &cli_debug_channel_deprecated }, + + { { "channel", "nodebug", NULL }, + handle_nodebugchan, "Disable debugging on a channel", + nodebugchan_help, complete_ch_3, &cli_no_debug_channel_deprecated }, + + { { "core", "debug", NULL }, + handle_debug, "Set level of debug chattiness", + debug_help, NULL, &cli_set_debug_deprecated }, + + { { "core", "nodebug", NULL }, + handle_nodebug, "Turns off debug chattiness", + nodebug_help }, + + { { "core", "verbose", NULL }, + handle_verbose, "Set level of verboseness", + verbose_help, NULL, &cli_set_verbose_deprecated }, + + { { "group", "list", "channels", NULL }, + group_show_channels, "Display active channels with group(s)", + group_show_channels_help, NULL, &cli_group_show_channels_deprecated }, + + { { "help", NULL }, + handle_help, "Display help list, or specific help on a command", + help_help, complete_help }, + + { { "logger", "mute", NULL }, + handle_logger_mute, "Toggle logging output to a console", + logger_mute_help }, + + { { "module", "list", NULL }, + handle_modlist, "List modules and info", + modlist_help, NULL, &cli_show_modules_deprecated }, + + { { "module", "list", "like", NULL }, + handle_modlist, "List modules and info", + modlist_help, complete_mod_4, &cli_show_modules_like_deprecated }, + + { { "module", "load", NULL }, + handle_load, "Load a module by name", + load_help, complete_fn, &cli_load_deprecated }, + + { { "module", "reload", NULL }, + handle_reload, "Reload configuration", + reload_help, complete_mod_3, &cli_reload_deprecated }, + + { { "module", "unload", NULL }, + handle_unload, "Unload a module by name", + unload_help, complete_mod_3_nr, &cli_unload_deprecated }, + + { { "show", "uptime", NULL }, + handle_showuptime, "Show uptime information", + uptime_help }, + + { { "soft", "hangup", NULL }, + handle_softhangup, "Request a hangup on a given channel", + softhangup_help, complete_ch_3 }, +}; + /*! \brief initialize the _full_cmd string in * each of the builtins. */ void ast_builtins_init(void) { @@ -940,6 +1275,8 @@ void ast_builtins_init(void) if (!e->_full_cmd) ast_log(LOG_WARNING, "-- cannot allocate <%s>\n", buf); } + + ast_cli_register_multiple(cli_cli, sizeof(cli_cli) / sizeof(struct ast_cli_entry)); } /* @@ -1041,8 +1378,11 @@ static char *find_best(char *argv[]) return cmdline; } -int ast_cli_unregister(struct ast_cli_entry *e) +static int __ast_cli_unregister(struct ast_cli_entry *e, struct ast_cli_entry *ed) { + if (e->deprecate_cmd) { + __ast_cli_unregister(e->deprecate_cmd, e); + } if (e->inuse) { ast_log(LOG_WARNING, "Can't remove command that is in use\n"); } else { @@ -1053,7 +1393,7 @@ int ast_cli_unregister(struct ast_cli_entry *e) return 0; } -int ast_cli_register(struct ast_cli_entry *e) +static int __ast_cli_register(struct ast_cli_entry *e, struct ast_cli_entry *ed) { struct ast_cli_entry *cur; char fulle[80] =""; @@ -1070,6 +1410,19 @@ int ast_cli_register(struct ast_cli_entry *e) e->_full_cmd = ast_strdup(fulle); if (!e->_full_cmd) goto done; + + if (ed) { + e->deprecated = 1; + e->summary = ed->summary; + e->usage = ed->usage; + /* XXX If command A deprecates command B, and command B deprecates command C... + Do we want to show command A or command B when telling the user to use new syntax? + This currently would show command A. + To show command B, you just need to always use ed->_full_cmd. + */ + e->_deprecated_by = S_OR(ed->_deprecated_by, ed->_full_cmd); + } + lf = strlen(fulle); AST_LIST_TRAVERSE_SAFE_BEGIN(&helpers, cur, list) { int len = strlen(cur->_full_cmd); @@ -1088,10 +1441,27 @@ int ast_cli_register(struct ast_cli_entry *e) done: AST_LIST_UNLOCK(&helpers); + + if (e->deprecate_cmd) { + /* This command deprecates another command. Register that one also. */ + __ast_cli_register(e->deprecate_cmd, e); + } return ret; } +/* wrapper function, so we can unregister deprecated commands recursively */ +int ast_cli_unregister(struct ast_cli_entry *e) +{ + return __ast_cli_unregister(e, NULL); +} + +/* wrapper function, so we can register deprecated commands recursively */ +int ast_cli_register(struct ast_cli_entry *e) +{ + return __ast_cli_register(e, NULL); +} + /* * register/unregister an array of entries. */ @@ -1135,6 +1505,9 @@ static int help1(int fd, char *match[], int locked) /* Hide commands that start with '_' */ if (e->_full_cmd[0] == '_') continue; + /* Hide commands that are marked as deprecated. */ + if (e->deprecated) + continue; if (match && strncasecmp(matchstr, e->_full_cmd, len)) continue; ast_cli(fd, "%25.25s %s\n", e->_full_cmd, e->summary); @@ -1378,6 +1751,14 @@ int ast_cli_command(int fd, const char *s) else ast_cli(fd, "Invalid usage, but no usage information available.\n"); break; + default: + AST_LIST_LOCK(&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_LIST_UNLOCK(&helpers); + break; } } else ast_cli(fd, "No such command '%s' (type 'help' for help)\n", find_best(argv)); diff --git a/main/config.c b/main/config.c index 6d88aebec..ffd58b52b 100644 --- a/main/config.c +++ b/main/config.c @@ -1232,14 +1232,22 @@ static int config_command(int fd, int argc, char **argv) } static char show_config_help[] = - "Usage: show config mappings\n" + "Usage: core list config mappings\n" " Shows the filenames to config engines.\n"; -static struct ast_cli_entry config_command_struct = { - { "show", "config", "mappings", NULL }, config_command, "Show Config mappings (file names to config engines)", show_config_help, NULL +static struct ast_cli_entry cli_show_config_mappings_deprecated = { + { "show", "config", "mappings", NULL }, + config_command, NULL, + NULL }; + +static struct ast_cli_entry cli_config[] = { + { { "core", "list", "config", "mappings", NULL }, + config_command, "Display config mappings (file names to config engines)", + show_config_help, NULL, &cli_show_config_mappings_deprecated }, }; int register_config_cli() { - return ast_cli_register(&config_command_struct); + ast_cli_register_multiple(cli_config, sizeof(cli_config) / sizeof(struct ast_cli_entry)); + return 0; } diff --git a/main/db.c b/main/db.c index e64e0f521..b9c9115c2 100644 --- a/main/db.c +++ b/main/db.c @@ -494,23 +494,31 @@ static char database_deltree_usage[] = " Deletes a family or specific keytree within a family\n" "in the Asterisk database.\n"; -struct ast_cli_entry cli_database_show = -{ { "database", "show", NULL }, database_show, "Shows database contents", database_show_usage }; +struct ast_cli_entry cli_database[] = { + { { "database", "show", NULL }, + database_show, "Shows database contents", + database_show_usage }, -struct ast_cli_entry cli_database_showkey = -{ { "database", "showkey", NULL }, database_showkey, "Shows database contents", database_showkey_usage }; + { { "database", "showkey", NULL }, + database_showkey, "Shows database contents", + database_showkey_usage }, -struct ast_cli_entry cli_database_get = -{ { "database", "get", NULL }, database_get, "Gets database value", database_get_usage }; + { { "database", "get", NULL }, + database_get, "Gets database value", + database_get_usage }, -struct ast_cli_entry cli_database_put = -{ { "database", "put", NULL }, database_put, "Adds/updates database value", database_put_usage }; + { { "database", "put", NULL }, + database_put, "Adds/updates database value", + database_put_usage }, -struct ast_cli_entry cli_database_del = -{ { "database", "del", NULL }, database_del, "Removes database key/value", database_del_usage }; + { { "database", "del", NULL }, + database_del, "Removes database key/value", + database_del_usage }, -struct ast_cli_entry cli_database_deltree = -{ { "database", "deltree", NULL }, database_deltree, "Removes database keytree/values", database_deltree_usage }; + { { "database", "deltree", NULL }, + database_deltree, "Removes database keytree/values", + database_deltree_usage }, +}; static int manager_dbput(struct mansession *s, struct message *m) { @@ -581,12 +589,7 @@ static int manager_dbget(struct mansession *s, struct message *m) int astdb_init(void) { dbinit(); - ast_cli_register(&cli_database_show); - ast_cli_register(&cli_database_showkey); - ast_cli_register(&cli_database_get); - ast_cli_register(&cli_database_put); - ast_cli_register(&cli_database_del); - ast_cli_register(&cli_database_deltree); + ast_cli_register_multiple(cli_database, sizeof(cli_database) / sizeof(struct ast_cli_entry)); ast_manager_register("DBGet", EVENT_FLAG_SYSTEM, manager_dbget, "Get DB Entry"); ast_manager_register("DBPut", EVENT_FLAG_SYSTEM, manager_dbput, "Put DB Entry"); return 0; diff --git a/main/dnsmgr.c b/main/dnsmgr.c index 98b7f0905..0cc0d63f8 100644 --- a/main/dnsmgr.c +++ b/main/dnsmgr.c @@ -312,29 +312,23 @@ static int handle_cli_status(int fd, int argc, char *argv[]) } static struct ast_cli_entry cli_reload = { - .cmda = { "dnsmgr", "reload", NULL }, - .handler = handle_cli_reload, - .summary = "Reloads the DNS manager configuration", - .usage = + { "dnsmgr", "reload", NULL }, + handle_cli_reload, "Reloads the DNS manager configuration", "Usage: dnsmgr reload\n" " Reloads the DNS manager configuration.\n" }; static struct ast_cli_entry cli_refresh = { - .cmda = { "dnsmgr", "refresh", NULL }, - .handler = handle_cli_refresh, - .summary = "Performs an immediate refresh", - .usage = + { "dnsmgr", "refresh", NULL }, + handle_cli_refresh, "Performs an immediate refresh", "Usage: dnsmgr refresh [pattern]\n" " Peforms an immediate refresh of the managed DNS entries.\n" " Optional regular expression pattern is used to filter the entries to refresh.\n", }; static struct ast_cli_entry cli_status = { - .cmda = { "dnsmgr", "status", NULL }, - .handler = handle_cli_status, - .summary = "Display the DNS manager status", - .usage = + { "dnsmgr", "status", NULL }, + handle_cli_status, "Display the DNS manager status", "Usage: dnsmgr status\n" " Displays the DNS manager status.\n" }; diff --git a/main/file.c b/main/file.c index 101b9ac66..f130b99c8 100644 --- a/main/file.c +++ b/main/file.c @@ -1148,17 +1148,23 @@ static int show_file_formats(int fd, int argc, char *argv[]) #undef FORMAT2 } -struct ast_cli_entry show_file = -{ +char show_file_formats_usage[] = +"Usage: core list file formats\n" +" Displays currently registered file formats (if any)\n"; + +struct ast_cli_entry cli_show_file_formats_deprecated = { { "show", "file", "formats" }, - show_file_formats, - "Displays file formats", - "Usage: show file formats\n" - " displays currently registered file formats (if any)\n" + show_file_formats, NULL, + NULL }; + +struct ast_cli_entry cli_file[] = { + { { "file", "list", "formats" }, + show_file_formats, "Displays file formats", + show_file_formats_usage, NULL, &cli_show_file_formats_deprecated }, }; int ast_file_init(void) { - ast_cli_register(&show_file); + ast_cli_register_multiple(cli_file, sizeof(cli_file) / sizeof(struct ast_cli_entry)); return 0; } diff --git a/main/frame.c b/main/frame.c index 5650df475..07714e07f 100644 --- a/main/frame.c +++ b/main/frame.c @@ -595,7 +595,7 @@ char *ast_codec2str(int codec) return ret; } -static int show_codecs(int fd, int argc, char *argv[]) +static int show_codecs_deprecated(int fd, int argc, char *argv[]) { int i, found=0; char hex[25]; @@ -639,11 +639,55 @@ static int show_codecs(int fd, int argc, char *argv[]) return RESULT_SUCCESS; } +static int show_codecs(int fd, int argc, char *argv[]) +{ + int i, found=0; + char hex[25]; + + if ((argc < 3) || (argc > 4)) + return RESULT_SHOWUSAGE; + + if (!ast_opt_dont_warn) + ast_cli(fd, "Disclaimer: this command is for informational purposes only.\n" + "\tIt does not indicate anything about your configuration.\n"); + + ast_cli(fd, "%11s %9s %10s TYPE %8s %s\n","INT","BINARY","HEX","NAME","DESC"); + ast_cli(fd, "--------------------------------------------------------------------------------\n"); + if ((argc == 3) || (!strcasecmp(argv[3],"audio"))) { + found = 1; + for (i=0;i<12;i++) { + snprintf(hex,25,"(0x%x)",1<\n" +"Usage: core show codec \n" " Displays codec mapping\n"; /*! Dump a frame for debugging purposes */ @@ -851,7 +917,7 @@ void ast_frame_dump(const char *name, struct ast_frame *f, char *prefix) #ifdef TRACE_FRAMES -static int show_frame_stats(int fd, int argc, char *argv[]) +static int show_frame_stats_deprecated(int fd, int argc, char *argv[]) { struct ast_frame *f; int x=1; @@ -868,27 +934,92 @@ static int show_frame_stats(int fd, int argc, char *argv[]) return RESULT_SUCCESS; } +static int show_frame_stats(int fd, int argc, char *argv[]) +{ + struct ast_frame *f; + int x=1; + if (argc != 4) + return RESULT_SHOWUSAGE; + AST_LIST_LOCK(&headerlist); + ast_cli(fd, " Framer Statistics \n"); + ast_cli(fd, "---------------------------\n"); + ast_cli(fd, "Total allocated headers: %d\n", headers); + ast_cli(fd, "Queue Dump:\n"); + AST_LIST_TRAVERSE(&headerlist, f, frame_list) + ast_cli(fd, "%d. Type %d, subclass %d from %s\n", x++, f->frametype, f->subclass, f->src ? f->src : ""); + AST_LIST_UNLOCK(&headerlist); + return RESULT_SUCCESS; +} + static char frame_stats_usage[] = -"Usage: show frame stats\n" +"Usage: core show frame stats\n" " Displays debugging statistics from framer\n"; #endif /* Builtin Asterisk CLI-commands for debugging */ +static struct ast_cli_entry cli_show_codecs = { + { "show", "codecs", NULL }, + show_codecs_deprecated, NULL, + NULL }; + +static struct ast_cli_entry cli_show_audio_codecs = { + { "show", "audio", "codecs", NULL }, + show_codecs_deprecated, NULL, + NULL }; + +static struct ast_cli_entry cli_show_video_codecs = { + { "show", "video", "codecs", NULL }, + show_codecs_deprecated, NULL, + NULL }; + +static struct ast_cli_entry cli_show_image_codecs = { + { "show", "image", "codecs", NULL }, + show_codecs_deprecated, NULL, + NULL }; + +static struct ast_cli_entry cli_show_codec = { + { "show", "codec", NULL }, + show_codec_n_deprecated, NULL, + NULL }; + +#ifdef TRACE_FRAMES +static struct ast_cli_entry cli_show_frame_stats = { + { "show", "frame", "stats", NULL }, + show_frame_stats, NULL, + NULL }; +#endif + static struct ast_cli_entry my_clis[] = { -{ { "show", "codecs", NULL }, show_codecs, "Shows codecs", frame_show_codecs_usage }, -{ { "show", "audio", "codecs", NULL }, show_codecs, "Shows audio codecs", frame_show_codecs_usage }, -{ { "show", "video", "codecs", NULL }, show_codecs, "Shows video codecs", frame_show_codecs_usage }, -{ { "show", "image", "codecs", NULL }, show_codecs, "Shows image codecs", frame_show_codecs_usage }, -{ { "show", "codec", NULL }, show_codec_n, "Shows a specific codec", frame_show_codec_n_usage }, + { { "core", "list", "codecs", NULL }, + show_codecs, "Displays a list of codecs", + frame_show_codecs_usage, NULL, &cli_show_codecs }, + + { { "core", "list", "codecs", "audio", NULL }, + show_codecs, "Displays a list of audio codecs", + frame_show_codecs_usage, NULL, &cli_show_audio_codecs }, + + { { "core", "list", "codecs", "video", NULL }, + show_codecs, "Displays a list of video codecs", + frame_show_codecs_usage, NULL, &cli_show_video_codecs }, + + { { "core", "list", "codecs", "image", NULL }, + show_codecs, "Displays a list of image codecs", + frame_show_codecs_usage, NULL, &cli_show_image_codecs }, + + { { "core", "show", "codec", NULL }, + show_codec_n, "Shows a specific codec", + frame_show_codec_n_usage, NULL, &cli_show_codec }, + #ifdef TRACE_FRAMES -{ { "show", "frame", "stats", NULL }, show_frame_stats, "Shows frame statistics", frame_stats_usage }, + { { "core", "show", "frame", "stats", NULL }, + show_frame_stats, "Shows frame statistics", + frame_stats_usage, NULL, &cli_show_frame_stats }, #endif }; - int init_framer(void) { - ast_cli_register_multiple(my_clis, sizeof(my_clis)/sizeof(my_clis[0]) ); + ast_cli_register_multiple(my_clis, sizeof(my_clis) / sizeof(struct ast_cli_entry)); return 0; } diff --git a/main/http.c b/main/http.c index 230fec9af..9666539c7 100644 --- a/main/http.c +++ b/main/http.c @@ -681,18 +681,24 @@ int ast_http_reload(void) } static char show_http_help[] = -"Usage: http show status\n" -" Shows status of internal HTTP engine\n"; - -static struct ast_cli_entry http_cli[] = { - { { "http", "show", "status", NULL }, handle_show_http, - "Display HTTP server status", show_http_help }, +"Usage: http list status\n" +" Lists status of internal HTTP engine\n"; + +static struct ast_cli_entry cli_http_show_status_deprecated = { + { "http", "show", "status", NULL }, + handle_show_http, NULL, + NULL }; + +static struct ast_cli_entry cli_http[] = { + { { "http", "list", "status", NULL }, + handle_show_http, "Display HTTP server status", + show_http_help, NULL, &cli_http_show_status_deprecated }, }; int ast_http_init(void) { ast_http_uri_link(&statusuri); ast_http_uri_link(&staticuri); - ast_cli_register_multiple(http_cli, sizeof(http_cli) / sizeof(http_cli[0])); + ast_cli_register_multiple(cli_http, sizeof(cli_http) / sizeof(struct ast_cli_entry)); return __ast_http_load(0); } diff --git a/main/image.c b/main/image.c index ff67c0340..377ce9208 100644 --- a/main/image.c +++ b/main/image.c @@ -46,6 +46,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/cli.h" #include "asterisk/lock.h" +/* XXX Why don't we just use the formats struct for this? */ static AST_LIST_HEAD_STATIC(imagers, ast_imager); int ast_image_register(struct ast_imager *img) @@ -165,7 +166,6 @@ struct ast_frame *ast_read_image(char *filename, const char *preflang, int forma return f; } - int ast_send_image(struct ast_channel *chan, char *filename) { struct ast_frame *f; @@ -180,7 +180,7 @@ int ast_send_image(struct ast_channel *chan, char *filename) return res; } -static int show_image_formats(int fd, int argc, char *argv[]) +static int show_image_formats_deprecated(int fd, int argc, char *argv[]) { #define FORMAT "%10s %10s %50s %10s\n" #define FORMAT2 "%10s %10s %50s %10s\n" @@ -193,18 +193,33 @@ static int show_image_formats(int fd, int argc, char *argv[]) return RESULT_SUCCESS; } -struct ast_cli_entry show_images = +static int show_image_formats(int fd, int argc, char *argv[]) { +#define FORMAT "%10s %10s %50s %10s\n" +#define FORMAT2 "%10s %10s %50s %10s\n" + struct ast_imager *i; + if (argc != 4) + return RESULT_SHOWUSAGE; + ast_cli(fd, FORMAT, "Name", "Extensions", "Description", "Format"); + AST_LIST_TRAVERSE(&imagers, i, list) + ast_cli(fd, FORMAT2, i->name, i->exts, i->desc, ast_getformatname(i->format)); + return RESULT_SUCCESS; +} + +struct ast_cli_entry cli_show_image_formats_deprecated = { { "show", "image", "formats" }, - show_image_formats, - "Displays image formats", -"Usage: show image formats\n" -" displays currently registered image formats (if any)\n" + show_image_formats_deprecated, NULL, + NULL }; + +struct ast_cli_entry cli_image[] = { + { { "file", "list", "formats", "image" }, + show_image_formats, "Displays image formats", + "Usage: file list formats image\n" + " displays currently registered image formats (if any)\n", NULL, &cli_show_image_formats_deprecated }, }; - int ast_image_init(void) { - return ast_cli_register(&show_images); + ast_cli_register_multiple(cli_image, sizeof(cli_image) / sizeof(struct ast_cli_entry)); + return 0; } - diff --git a/main/logger.c b/main/logger.c index e0f88a10e..c9dbf4dea 100644 --- a/main/logger.c +++ b/main/logger.c @@ -554,23 +554,27 @@ static char logger_rotate_help[] = " Rotates and Reopens the log files.\n"; static char logger_show_channels_help[] = -"Usage: logger show channels\n" -" Show configured logger channels.\n"; +"Usage: logger list channels\n" +" List configured logger channels.\n"; -static struct ast_cli_entry logger_show_channels_cli = - { { "logger", "show", "channels", NULL }, +static struct ast_cli_entry cli_logger_show_channels_deprecated = { + { "logger", "show", "channels", NULL }, + handle_logger_show_channels, NULL, + NULL }; + +static struct ast_cli_entry cli_logger[] = { + { { "logger", "list", "channels", NULL }, handle_logger_show_channels, "List configured log channels", - logger_show_channels_help }; + logger_show_channels_help, NULL, &cli_logger_show_channels_deprecated }, -static struct ast_cli_entry reload_logger_cli = { { "logger", "reload", NULL }, handle_logger_reload, "Reopens the log files", - logger_reload_help }; + logger_reload_help }, -static struct ast_cli_entry rotate_logger_cli = { { "logger", "rotate", NULL }, handle_logger_rotate, "Rotates and reopens the log files", - logger_rotate_help }; + logger_rotate_help }, +}; static int handle_SIGXFSZ(int sig) { @@ -587,10 +591,8 @@ int init_logger(void) /* auto rotate if sig SIGXFSZ comes a-knockin */ (void) signal(SIGXFSZ,(void *) handle_SIGXFSZ); - /* register the relaod logger cli command */ - ast_cli_register(&reload_logger_cli); - ast_cli_register(&rotate_logger_cli); - ast_cli_register(&logger_show_channels_cli); + /* register the logger cli commands */ + ast_cli_register_multiple(cli_logger, sizeof(cli_logger) / sizeof(struct ast_cli_entry)); mkdir((char *)ast_config_AST_LOG_DIR, 0755); diff --git a/main/manager.c b/main/manager.c index 90719a0f9..ef72c7c11 100644 --- a/main/manager.c +++ b/main/manager.c @@ -478,38 +478,60 @@ static int handle_showmaneventq(int fd, int argc, char *argv[]) } static char showmancmd_help[] = -"Usage: show manager command \n" +"Usage: manager show command \n" " Shows the detailed description for a specific Asterisk manager interface command.\n"; static char showmancmds_help[] = -"Usage: show manager commands\n" +"Usage: manager list commands\n" " Prints a listing of all the available Asterisk manager interface commands.\n"; static char showmanconn_help[] = -"Usage: show manager connected\n" +"Usage: manager list connected\n" " Prints a listing of the users that are currently connected to the\n" "Asterisk manager interface.\n"; static char showmaneventq_help[] = -"Usage: show manager eventq\n" +"Usage: manager list eventq\n" " Prints a listing of all events pending in the Asterisk manger\n" "event queue.\n"; -static struct ast_cli_entry show_mancmd_cli = - { { "show", "manager", "command", NULL }, - handle_showmancmd, "Show a manager interface command", showmancmd_help, complete_show_mancmd }; - -static struct ast_cli_entry show_mancmds_cli = - { { "show", "manager", "commands", NULL }, - handle_showmancmds, "List manager interface commands", showmancmds_help }; - -static struct ast_cli_entry show_manconn_cli = - { { "show", "manager", "connected", NULL }, - handle_showmanconn, "Show connected manager interface users", showmanconn_help }; - -static struct ast_cli_entry show_maneventq_cli = - { { "show", "manager", "eventq", NULL }, - handle_showmaneventq, "Show manager interface queued events", showmaneventq_help }; +static struct ast_cli_entry cli_show_manager_command_deprecated = { + { "show", "manager", "command", NULL }, + handle_showmancmd, NULL, + NULL, complete_show_mancmd }; + +static struct ast_cli_entry cli_show_manager_commands_deprecated = { + { "show", "manager", "commands", NULL }, + handle_showmancmds, NULL, + NULL }; + +static struct ast_cli_entry cli_show_manager_connected_deprecated = { + { "show", "manager", "connected", NULL }, + handle_showmanconn, NULL, + NULL }; + +static struct ast_cli_entry cli_show_manager_eventq_deprecated = { + { "show", "manager", "eventq", NULL }, + handle_showmaneventq, NULL, + NULL }; + +static struct ast_cli_entry cli_manager[] = { + { { "manager", "show", "command", NULL }, + handle_showmancmd, "Show a manager interface command", + showmancmd_help, complete_show_mancmd, &cli_show_manager_command_deprecated }, + + { { "manager", "list", "commands", NULL }, + handle_showmancmds, "List manager interface commands", + showmancmds_help, NULL, &cli_show_manager_commands_deprecated }, + + { { "manager", "list", "connected", NULL }, + handle_showmanconn, "List connected manager interface users", + showmanconn_help, NULL, &cli_show_manager_connected_deprecated }, + + { { "manager", "list", "eventq", NULL }, + handle_showmaneventq, "List manager interface queued events", + showmaneventq_help, NULL, &cli_show_manager_eventq_deprecated }, +}; static void unuse_eventqent(struct eventqent *e) { @@ -2479,10 +2501,7 @@ int init_manager(void) ast_manager_register2("UserEvent", EVENT_FLAG_USER, action_userevent, "Send an arbitrary event", mandescr_userevent); ast_manager_register2("WaitEvent", 0, action_waitevent, "Wait for an event to occur", mandescr_waitevent); - ast_cli_register(&show_mancmd_cli); - ast_cli_register(&show_mancmds_cli); - ast_cli_register(&show_manconn_cli); - ast_cli_register(&show_maneventq_cli); + ast_cli_register_multiple(cli_manager, sizeof(cli_manager) / sizeof(struct ast_cli_entry)); ast_extension_state_add(NULL, NULL, manager_state_cb, NULL); registered = 1; /* Append placeholder event so master_eventq never runs dry */ diff --git a/main/pbx.c b/main/pbx.c index f07ac5875..977a284f1 100644 --- a/main/pbx.c +++ b/main/pbx.c @@ -1211,7 +1211,7 @@ void pbx_retrieve_variable(struct ast_channel *c, const char *var, char **ret, c /*! \brief CLI function to show installed custom functions \addtogroup CLI_functions */ -static int handle_show_functions(int fd, int argc, char *argv[]) +static int handle_show_functions_deprecated(int fd, int argc, char *argv[]) { struct ast_custom_function *acf; int count_acf = 0; @@ -1238,8 +1238,35 @@ static int handle_show_functions(int fd, int argc, char *argv[]) return RESULT_SUCCESS; } +static int handle_show_functions(int fd, int argc, char *argv[]) +{ + struct ast_custom_function *acf; + int count_acf = 0; + int like = 0; -static int handle_show_function(int fd, int argc, char *argv[]) + if (argc == 5 && (!strcmp(argv[3], "like")) ) { + like = 1; + } else if (argc != 3) { + return RESULT_SHOWUSAGE; + } + + ast_cli(fd, "%s Custom Functions:\n--------------------------------------------------------------------------------\n", like ? "Matching" : "Installed"); + + AST_LIST_LOCK(&acf_root); + AST_LIST_TRAVERSE(&acf_root, acf, acflist) { + if (!like || strstr(acf->name, argv[4])) { + count_acf++; + ast_cli(fd, "%-20.20s %-35.35s %s\n", acf->name, acf->syntax, acf->synopsis); + } + } + AST_LIST_UNLOCK(&acf_root); + + ast_cli(fd, "%d %scustom functions installed.\n", count_acf, like ? "matching " : ""); + + return RESULT_SUCCESS; +} + +static int handle_show_function_deprecated(int fd, int argc, char *argv[]) { struct ast_custom_function *acf; /* Maximum number of characters added by terminal coloring is 22 */ @@ -1295,6 +1322,62 @@ static int handle_show_function(int fd, int argc, char *argv[]) return RESULT_SUCCESS; } +static int handle_show_function(int fd, int argc, char *argv[]) +{ + struct ast_custom_function *acf; + /* Maximum number of characters added by terminal coloring is 22 */ + char infotitle[64 + AST_MAX_APP + 22], syntitle[40], destitle[40]; + char info[64 + AST_MAX_APP], *synopsis = NULL, *description = NULL; + char stxtitle[40], *syntax = NULL; + int synopsis_size, description_size, syntax_size; + + if (argc < 4) + return RESULT_SHOWUSAGE; + + if (!(acf = ast_custom_function_find(argv[3]))) { + ast_cli(fd, "No function by that name registered.\n"); + return RESULT_FAILURE; + + } + + if (acf->synopsis) + synopsis_size = strlen(acf->synopsis) + 23; + else + synopsis_size = strlen("Not available") + 23; + synopsis = alloca(synopsis_size); + + if (acf->desc) + description_size = strlen(acf->desc) + 23; + else + description_size = strlen("Not available") + 23; + description = alloca(description_size); + + if (acf->syntax) + syntax_size = strlen(acf->syntax) + 23; + else + syntax_size = strlen("Not available") + 23; + syntax = alloca(syntax_size); + + snprintf(info, 64 + AST_MAX_APP, "\n -= Info about function '%s' =- \n\n", acf->name); + term_color(infotitle, info, COLOR_MAGENTA, 0, 64 + AST_MAX_APP + 22); + term_color(stxtitle, "[Syntax]\n", COLOR_MAGENTA, 0, 40); + term_color(syntitle, "[Synopsis]\n", COLOR_MAGENTA, 0, 40); + term_color(destitle, "[Description]\n", COLOR_MAGENTA, 0, 40); + term_color(syntax, + acf->syntax ? acf->syntax : "Not available", + COLOR_CYAN, 0, syntax_size); + term_color(synopsis, + acf->synopsis ? acf->synopsis : "Not available", + COLOR_CYAN, 0, synopsis_size); + term_color(description, + acf->desc ? acf->desc : "Not available", + COLOR_CYAN, 0, description_size); + + ast_cli(fd,"%s%s%s\n\n%s%s\n\n%s%s\n", infotitle, stxtitle, syntax, syntitle, synopsis, destitle, description); + + return RESULT_SUCCESS; +} + static char *complete_show_function(const char *line, const char *word, int pos, int state) { struct ast_custom_function *acf; @@ -2882,50 +2965,45 @@ void ast_unregister_switch(struct ast_switch *sw) /* * Help for CLI commands ... */ -static char show_application_help[] = -"Usage: show application [ [ [...]]]\n" -" Describes a particular application.\n"; - -static char show_functions_help[] = -"Usage: show functions [like ]\n" -" List builtin functions, optionally only those matching a given string\n"; - -static char show_function_help[] = -"Usage: show function \n" -" Describe a particular dialplan function.\n"; - static char show_applications_help[] = -"Usage: show applications [{like|describing} ]\n" +"Usage: core list applications [{like|describing} ]\n" " List applications which are currently available.\n" " If 'like', will be a substring of the app name\n" " If 'describing', will be a substring of the description\n"; -static char show_dialplan_help[] = -"Usage: show dialplan [exten@][context]\n" -" Show dialplan\n"; +static char show_functions_help[] = +"Usage: core list functions [like ]\n" +" List builtin functions, optionally only those matching a given string\n"; static char show_switches_help[] = -"Usage: show switches\n" -" Show registered switches\n"; +"Usage: core list switches\n" +" List registered switches\n"; static char show_hints_help[] = -"Usage: show hints\n" -" Show registered hints\n"; +"Usage: core list hints\n" +" List registered hints\n"; static char show_globals_help[] = -"Usage: show globals\n" -" Show current global dialplan variables and their values\n"; +"Usage: core list globals\n" +" List current global dialplan variables and their values\n"; + +static char show_application_help[] = +"Usage: core show application [ [ [...]]]\n" +" Describes a particular application.\n"; + +static char show_function_help[] = +"Usage: core show function \n" +" Describe a particular dialplan function.\n"; + +static char show_dialplan_help[] = +"Usage: dialplan show [exten@][context]\n" +" Show dialplan\n"; static char set_global_help[] = -"Usage: set global \n" +"Usage: core set global \n" " Set global dialplan variable to \n"; -/* - * IMPLEMENTATION OF CLI FUNCTIONS IS IN THE SAME ORDER AS COMMANDS HELPS - * - */ - /* * \brief 'show application' CLI command implementation functions ... */ @@ -2955,7 +3033,7 @@ static char *complete_show_application(const char *line, const char *word, int p return ret; } -static int handle_show_application(int fd, int argc, char *argv[]) +static int handle_show_application_deprecated(int fd, int argc, char *argv[]) { struct ast_app *a; int app, no_registered_app = 1; @@ -3025,6 +3103,76 @@ static int handle_show_application(int fd, int argc, char *argv[]) return RESULT_SUCCESS; } +static int handle_show_application(int fd, int argc, char *argv[]) +{ + struct ast_app *a; + int app, no_registered_app = 1; + + if (argc < 4) + return RESULT_SHOWUSAGE; + + /* ... go through all applications ... */ + AST_LIST_LOCK(&apps); + AST_LIST_TRAVERSE(&apps, a, list) { + /* ... compare this application name with all arguments given + * to 'show application' command ... */ + for (app = 3; app < argc; app++) { + if (!strcasecmp(a->name, argv[app])) { + /* Maximum number of characters added by terminal coloring is 22 */ + char infotitle[64 + AST_MAX_APP + 22], syntitle[40], destitle[40]; + char info[64 + AST_MAX_APP], *synopsis = NULL, *description = NULL; + int synopsis_size, description_size; + + no_registered_app = 0; + + if (a->synopsis) + synopsis_size = strlen(a->synopsis) + 23; + else + synopsis_size = strlen("Not available") + 23; + synopsis = alloca(synopsis_size); + + if (a->description) + description_size = strlen(a->description) + 23; + else + description_size = strlen("Not available") + 23; + description = alloca(description_size); + + if (synopsis && description) { + snprintf(info, 64 + AST_MAX_APP, "\n -= Info about application '%s' =- \n\n", a->name); + term_color(infotitle, info, COLOR_MAGENTA, 0, 64 + AST_MAX_APP + 22); + term_color(syntitle, "[Synopsis]\n", COLOR_MAGENTA, 0, 40); + term_color(destitle, "[Description]\n", COLOR_MAGENTA, 0, 40); + term_color(synopsis, + a->synopsis ? a->synopsis : "Not available", + COLOR_CYAN, 0, synopsis_size); + term_color(description, + a->description ? a->description : "Not available", + COLOR_CYAN, 0, description_size); + + ast_cli(fd,"%s%s%s\n\n%s%s\n", infotitle, syntitle, synopsis, destitle, description); + } else { + /* ... one of our applications, show info ...*/ + ast_cli(fd,"\n -= Info about application '%s' =- \n\n" + "[Synopsis]\n %s\n\n" + "[Description]\n%s\n", + a->name, + a->synopsis ? a->synopsis : "Not available", + a->description ? a->description : "Not available"); + } + } + } + } + AST_LIST_UNLOCK(&apps); + + /* we found at least one app? no? */ + if (no_registered_app) { + ast_cli(fd, "Your application(s) is (are) not registered\n"); + return RESULT_FAILURE; + } + + return RESULT_SUCCESS; +} + /*! \brief handle_show_hints: CLI support for listing registred dial plan hints */ static int handle_show_hints(int fd, int argc, char *argv[]) { @@ -3082,7 +3230,7 @@ static int handle_show_switches(int fd, int argc, char *argv[]) /* * 'show applications' CLI command implementation functions ... */ -static int handle_show_applications(int fd, int argc, char *argv[]) +static int handle_show_applications_deprecated(int fd, int argc, char *argv[]) { struct ast_app *a; int like = 0, describing = 0; @@ -3150,14 +3298,89 @@ static int handle_show_applications(int fd, int argc, char *argv[]) return RESULT_SUCCESS; } +static int handle_show_applications(int fd, int argc, char *argv[]) +{ + struct ast_app *a; + int like = 0, describing = 0; + int total_match = 0; /* Number of matches in like clause */ + int total_apps = 0; /* Number of apps registered */ -static char *complete_show_applications(const char *line, const char *word, int pos, int state) + AST_LIST_LOCK(&apps); + + if (AST_LIST_EMPTY(&apps)) { + ast_cli(fd, "There are no registered applications\n"); + AST_LIST_UNLOCK(&apps); + return -1; + } + + /* core list applications like */ + if ((argc == 5) && (!strcmp(argv[3], "like"))) { + like = 1; + } else if ((argc > 4) && (!strcmp(argv[3], "describing"))) { + describing = 1; + } + + /* core list applications describing [] [...] */ + if ((!like) && (!describing)) { + ast_cli(fd, " -= Registered Asterisk Applications =-\n"); + } else { + ast_cli(fd, " -= Matching Asterisk Applications =-\n"); + } + + AST_LIST_TRAVERSE(&apps, a, list) { + int printapp = 0; + total_apps++; + if (like) { + if (strcasestr(a->name, argv[4])) { + printapp = 1; + total_match++; + } + } else if (describing) { + if (a->description) { + /* Match all words on command line */ + int i; + printapp = 1; + for (i = 4; i < argc; i++) { + if (!strcasestr(a->description, argv[i])) { + printapp = 0; + } else { + total_match++; + } + } + } + } else { + printapp = 1; + } + + if (printapp) { + ast_cli(fd," %20s: %s\n", a->name, a->synopsis ? a->synopsis : ""); + } + } + if ((!like) && (!describing)) { + ast_cli(fd, " -= %d Applications Registered =-\n",total_apps); + } else { + ast_cli(fd, " -= %d Applications Matching =-\n",total_match); + } + + AST_LIST_UNLOCK(&apps); + + return RESULT_SUCCESS; +} + +static char *complete_show_applications_deprecated(const char *line, const char *word, int pos, int state) { static char* choices[] = { "like", "describing", NULL }; return (pos != 2) ? NULL : ast_cli_complete(word, choices, state); } +static char *complete_show_applications(const char *line, const char *word, int pos, int state) +{ + static char* choices[] = { "like", "describing", NULL }; + + return (pos != 3) ? NULL : ast_cli_complete(word, choices, state); +} + /* * 'show dialplan' CLI command implementation functions ... */ @@ -3434,7 +3657,7 @@ static int handle_show_globals(int fd, int argc, char *argv[]) } /*! \brief CLI support for setting global variables */ -static int handle_set_global(int fd, int argc, char *argv[]) +static int handle_set_global_deprecated(int fd, int argc, char *argv[]) { if (argc != 4) return RESULT_SHOWUSAGE; @@ -3446,29 +3669,103 @@ static int handle_set_global(int fd, int argc, char *argv[]) } +static int handle_set_global(int fd, int argc, char *argv[]) +{ + if (argc != 5) + return RESULT_SHOWUSAGE; + + pbx_builtin_setvar_helper(NULL, argv[3], argv[4]); + ast_cli(fd, "\n -- Global variable %s set to %s\n", argv[3], argv[4]); + + return RESULT_SUCCESS; +} + + /* * CLI entries for upper commands ... */ +static struct ast_cli_entry cli_show_applications_deprecated = { + { "show", "applications", NULL }, + handle_show_applications_deprecated, NULL, + NULL, complete_show_applications_deprecated }; + +static struct ast_cli_entry cli_show_functions_deprecated = { + { "show", "functions", NULL }, + handle_show_functions_deprecated, NULL, + NULL }; + +static struct ast_cli_entry cli_show_switches_deprecated = { + { "show", "switches", NULL }, + handle_show_switches, NULL, + NULL }; + +static struct ast_cli_entry cli_show_hints_deprecated = { + { "show", "hints", NULL }, + handle_show_hints, NULL, + NULL }; + +static struct ast_cli_entry cli_show_globals_deprecated = { + { "show", "globals", NULL }, + handle_show_globals, NULL, + NULL }; + +static struct ast_cli_entry cli_show_function_deprecated = { + { "show" , "function", NULL }, + handle_show_function_deprecated, NULL, + NULL, complete_show_function }; + +static struct ast_cli_entry cli_show_application_deprecated = { + { "show", "application", NULL }, + handle_show_application_deprecated, NULL, + NULL, complete_show_application }; + +static struct ast_cli_entry cli_show_dialplan_deprecated = { + { "show", "dialplan", NULL }, + handle_show_dialplan, NULL, + NULL, complete_show_dialplan_context }; + +static struct ast_cli_entry cli_set_global_deprecated = { + { "set", "global", NULL }, + handle_set_global_deprecated, NULL, + NULL }; + static struct ast_cli_entry pbx_cli[] = { - { { "show", "applications", NULL }, handle_show_applications, - "Shows registered dialplan applications", show_applications_help, complete_show_applications }, - { { "show", "functions", NULL }, handle_show_functions, - "Shows registered dialplan functions", show_functions_help }, - { { "show" , "function", NULL }, handle_show_function, - "Describe a specific dialplan function", show_function_help, complete_show_function }, - { { "show", "application", NULL }, handle_show_application, - "Describe a specific dialplan application", show_application_help, complete_show_application }, - { { "show", "dialplan", NULL }, handle_show_dialplan, - "Show dialplan", show_dialplan_help, complete_show_dialplan_context }, - { { "show", "switches", NULL }, handle_show_switches, - "Show alternative switches", show_switches_help }, - { { "show", "hints", NULL }, handle_show_hints, - "Show dialplan hints", show_hints_help }, - { { "show", "globals", NULL }, handle_show_globals, - "Show global dialplan variables", show_globals_help }, - { { "set", "global", NULL }, handle_set_global, - "Set global dialplan variable", set_global_help }, + { { "core", "list", "applications", NULL }, + handle_show_applications, "Shows registered dialplan applications", + show_applications_help, complete_show_applications, &cli_show_applications_deprecated }, + + { { "core", "list", "functions", NULL }, + handle_show_functions, "Shows registered dialplan functions", + show_functions_help, NULL, &cli_show_functions_deprecated }, + + { { "core", "list", "switches", NULL }, + handle_show_switches, "Show alternative switches", + show_switches_help, NULL, &cli_show_switches_deprecated }, + + { { "core", "list", "hints", NULL }, + handle_show_hints, "Show dialplan hints", + show_hints_help, NULL, &cli_show_hints_deprecated }, + + { { "core", "list", "globals", NULL }, + handle_show_globals, "Show global dialplan variables", + show_globals_help, NULL, &cli_show_globals_deprecated }, + + { { "core", "show" , "function", NULL }, + handle_show_function, "Describe a specific dialplan function", + show_function_help, complete_show_function, &cli_show_function_deprecated }, + + { { "core", "show", "application", NULL }, + handle_show_application, "Describe a specific dialplan application", + show_application_help, complete_show_application, &cli_show_application_deprecated }, + + { { "core", "set", "global", NULL }, + handle_set_global, "Set global dialplan variable", + set_global_help, NULL, &cli_set_global_deprecated }, + + { { "dialplan", "show", NULL }, + handle_show_dialplan, "Show dialplan", + show_dialplan_help, complete_show_dialplan_context, &cli_show_dialplan_deprecated }, }; int ast_unregister_application(const char *app) @@ -5699,7 +5996,7 @@ int load_pbx(void) ast_verbose( "Asterisk PBX Core Initializing\n"); ast_verbose( "Registering builtin applications:\n"); } - ast_cli_register_multiple(pbx_cli, sizeof(pbx_cli) / sizeof(pbx_cli[0])); + ast_cli_register_multiple(pbx_cli, sizeof(pbx_cli) / sizeof(struct ast_cli_entry)); /* Register builtin applications */ for (x=0; xh_addr, sizeof(rtcpdebugaddr.sin_addr)); + rtcpdebugaddr.sin_port = htons(port); + if (port == 0) + ast_cli(fd, "RTCP Debugging Enabled for IP: %s\n", ast_inet_ntoa(rtcpdebugaddr.sin_addr)); + else + ast_cli(fd, "RTCP Debugging Enabled for IP: %s:%d\n", ast_inet_ntoa(rtcpdebugaddr.sin_addr), port); + rtcpdebug = 1; + return RESULT_SUCCESS; +} + static int rtp_do_debug(int fd, int argc, char *argv[]) { if (argc != 2) { @@ -3204,10 +3234,22 @@ static int rtp_do_debug(int fd, int argc, char *argv[]) return RESULT_SUCCESS; } -static int rtcp_do_debug(int fd, int argc, char *argv[]) { +static int rtcp_do_debug_deprecated(int fd, int argc, char *argv[]) { if (argc != 3) { if (argc != 5) return RESULT_SHOWUSAGE; + return rtcp_do_debug_ip_deprecated(fd, argc, argv); + } + rtcpdebug = 1; + memset(&rtcpdebugaddr,0,sizeof(rtcpdebugaddr)); + ast_cli(fd, "RTCP Debugging Enabled\n"); + return RESULT_SUCCESS; +} + +static int rtcp_do_debug(int fd, int argc, char *argv[]) { + if (argc != 2) { + if (argc != 4) + return RESULT_SHOWUSAGE; return rtcp_do_debug_ip(fd, argc, argv); } rtcpdebug = 1; @@ -3216,7 +3258,7 @@ static int rtcp_do_debug(int fd, int argc, char *argv[]) { return RESULT_SUCCESS; } -static int rtcp_do_stats(int fd, int argc, char *argv[]) { +static int rtcp_do_stats_deprecated(int fd, int argc, char *argv[]) { if (argc != 3) { return RESULT_SHOWUSAGE; } @@ -3225,7 +3267,16 @@ static int rtcp_do_stats(int fd, int argc, char *argv[]) { return RESULT_SUCCESS; } -static int rtp_no_debug(int fd, int argc, char *argv[]) +static int rtcp_do_stats(int fd, int argc, char *argv[]) { + if (argc != 2) { + return RESULT_SHOWUSAGE; + } + rtcpstats = 1; + ast_cli(fd, "RTCP Stats Enabled\n"); + return RESULT_SUCCESS; +} + +static int rtp_no_debug_deprecated(int fd, int argc, char *argv[]) { if (argc != 3) return RESULT_SHOWUSAGE; @@ -3234,7 +3285,16 @@ static int rtp_no_debug(int fd, int argc, char *argv[]) return RESULT_SUCCESS; } -static int rtcp_no_debug(int fd, int argc, char *argv[]) +static int rtp_no_debug(int fd, int argc, char *argv[]) +{ + if (argc != 2) + return RESULT_SHOWUSAGE; + rtpdebug = 0; + ast_cli(fd,"RTP Debugging Disabled\n"); + return RESULT_SUCCESS; +} + +static int rtcp_no_debug_deprecated(int fd, int argc, char *argv[]) { if (argc != 4) return RESULT_SHOWUSAGE; @@ -3243,7 +3303,16 @@ static int rtcp_no_debug(int fd, int argc, char *argv[]) return RESULT_SUCCESS; } -static int rtcp_no_stats(int fd, int argc, char *argv[]) +static int rtcp_no_debug(int fd, int argc, char *argv[]) +{ + if (argc != 2) + return RESULT_SHOWUSAGE; + rtcpdebug = 0; + ast_cli(fd,"RTCP Debugging Disabled\n"); + return RESULT_SUCCESS; +} + +static int rtcp_no_stats_deprecated(int fd, int argc, char *argv[]) { if (argc != 4) return RESULT_SHOWUSAGE; @@ -3252,6 +3321,14 @@ static int rtcp_no_stats(int fd, int argc, char *argv[]) return RESULT_SUCCESS; } +static int rtcp_no_stats(int fd, int argc, char *argv[]) +{ + if (argc != 2) + return RESULT_SHOWUSAGE; + rtcpstats = 0; + ast_cli(fd,"RTCP Stats Disabled\n"); + return RESULT_SUCCESS; +} static int stun_do_debug(int fd, int argc, char *argv[]) { @@ -3263,7 +3340,7 @@ static int stun_do_debug(int fd, int argc, char *argv[]) return RESULT_SUCCESS; } -static int stun_no_debug(int fd, int argc, char *argv[]) +static int stun_no_debug_deprecated(int fd, int argc, char *argv[]) { if (argc != 3) return RESULT_SHOWUSAGE; @@ -3272,13 +3349,21 @@ static int stun_no_debug(int fd, int argc, char *argv[]) return RESULT_SUCCESS; } +static int stun_no_debug(int fd, int argc, char *argv[]) +{ + if (argc != 2) + return RESULT_SHOWUSAGE; + stundebug = 0; + ast_cli(fd,"STUN Debugging Disabled\n"); + return RESULT_SUCCESS; +} static char debug_usage[] = "Usage: rtp debug [ip host[:port]]\n" " Enable dumping of all RTP packets to and from host.\n"; static char no_debug_usage[] = - "Usage: rtp no debug\n" + "Usage: rtp nodebug\n" " Disable all RTP debugging\n"; static char stun_debug_usage[] = @@ -3286,55 +3371,101 @@ static char stun_debug_usage[] = " Enable STUN (Simple Traversal of UDP through NATs) debugging\n"; static char stun_no_debug_usage[] = - "Usage: stun no debug\n" + "Usage: stun nodebug\n" " Disable STUN debugging\n"; - -static struct ast_cli_entry cli_debug_ip = -{{ "rtp", "debug", "ip", NULL } , rtp_do_debug, "Enable RTP debugging on IP", debug_usage }; - -static struct ast_cli_entry cli_debug = -{{ "rtp", "debug", NULL } , rtp_do_debug, "Enable RTP debugging", debug_usage }; - -static struct ast_cli_entry cli_no_debug = -{{ "rtp", "no", "debug", NULL } , rtp_no_debug, "Disable RTP debugging", no_debug_usage }; - static char rtcp_debug_usage[] = - "Usage: rtp rtcp debug [ip host[:port]]\n" + "Usage: rtcp debug [ip host[:port]]\n" " Enable dumping of all RTCP packets to and from host.\n"; static char rtcp_no_debug_usage[] = - "Usage: rtp rtcp no debug\n" + "Usage: rtcp nodebug\n" " Disable all RTCP debugging\n"; static char rtcp_stats_usage[] = - "Usage: rtp rtcp stats\n" + "Usage: rtcp stats\n" " Enable dumping of RTCP stats.\n"; static char rtcp_no_stats_usage[] = - "Usage: rtp rtcp no stats\n" + "Usage: rtcp nostats\n" " Disable all RTCP stats\n"; -static struct ast_cli_entry cli_debug_ip_rtcp = -{{ "rtp", "rtcp", "debug", "ip", NULL } , rtcp_do_debug, "Enable RTCP debugging on IP", rtcp_debug_usage }; - -static struct ast_cli_entry cli_debug_rtcp = -{{ "rtp", "rtcp", "debug", NULL } , rtcp_do_debug, "Enable RTCP debugging", rtcp_debug_usage }; - -static struct ast_cli_entry cli_no_debug_rtcp = -{{ "rtp", "rtcp", "no", "debug", NULL } , rtcp_no_debug, "Disable RTCP debugging", rtcp_no_debug_usage }; - -static struct ast_cli_entry cli_stats_rtcp = -{{ "rtp", "rtcp", "stats", NULL } , rtcp_do_stats, "Enable RTCP stats", rtcp_stats_usage }; - -static struct ast_cli_entry cli_no_stats_rtcp = -{{ "rtp", "rtcp", "no", "stats", NULL } , rtcp_no_stats, "Disable RTCP stats", rtcp_no_stats_usage }; - -static struct ast_cli_entry cli_stun_debug = -{{ "stun", "debug", NULL } , stun_do_debug, "Enable STUN debugging", stun_debug_usage }; - -static struct ast_cli_entry cli_stun_no_debug = -{{ "stun", "no", "debug", NULL } , stun_no_debug, "Disable STUN debugging", stun_no_debug_usage }; +static struct ast_cli_entry cli_rtp_no_debug_deprecated = { + { "rtp", "no", "debug", NULL }, + rtp_no_debug_deprecated, NULL, + NULL }; + +static struct ast_cli_entry cli_rtp_rtcp_debug_ip_deprecated = { + { "rtp", "rtcp", "debug", "ip", NULL }, + rtcp_do_debug_deprecated, NULL, + NULL }; + +static struct ast_cli_entry cli_rtp_rtcp_debug_deprecated = { + { "rtp", "rtcp", "debug", NULL }, + rtcp_do_debug_deprecated, NULL, + NULL }; + +static struct ast_cli_entry cli_rtp_rtcp_no_debug_deprecated = { + { "rtp", "rtcp", "no", "debug", NULL }, + rtcp_no_debug_deprecated, NULL, + NULL }; + +static struct ast_cli_entry cli_rtp_rtcp_stats_deprecated = { + { "rtp", "rtcp", "stats", NULL }, + rtcp_do_stats_deprecated, NULL, + NULL }; + +static struct ast_cli_entry cli_rtp_rtcp_no_stats_deprecated = { + { "rtp", "rtcp", "no", "stats", NULL }, + rtcp_no_stats_deprecated, NULL, + NULL }; + +static struct ast_cli_entry cli_stun_no_debug_deprecated = { + { "stun", "no", "debug", NULL }, + stun_no_debug_deprecated, NULL, + NULL }; + +static struct ast_cli_entry cli_rtp[] = { + { { "rtp", "debug", "ip", NULL }, + rtp_do_debug, "Enable RTP debugging on IP", + debug_usage }, + + { { "rtp", "debug", NULL }, + rtp_do_debug, "Enable RTP debugging", + debug_usage }, + + { { "rtp", "nodebug", NULL }, + rtp_no_debug, "Disable RTP debugging", + no_debug_usage, NULL, &cli_rtp_no_debug_deprecated }, + + { { "rtcp", "debug", "ip", NULL }, + rtcp_do_debug, "Enable RTCP debugging on IP", + rtcp_debug_usage, NULL, &cli_rtp_rtcp_debug_ip_deprecated }, + + { { "rtcp", "debug", NULL }, + rtcp_do_debug, "Enable RTCP debugging", + rtcp_debug_usage, NULL, &cli_rtp_rtcp_debug_deprecated }, + + { { "rtcp", "nodebug", NULL }, + rtcp_no_debug, "Disable RTCP debugging", + rtcp_no_debug_usage, NULL, &cli_rtp_rtcp_no_debug_deprecated }, + + { { "rtcp", "stats", NULL }, + rtcp_do_stats, "Enable RTCP stats", + rtcp_stats_usage, NULL, &cli_rtp_rtcp_stats_deprecated }, + + { { "rtcp", "nostats", NULL }, + rtcp_no_stats, "Disable RTCP stats", + rtcp_no_stats_usage, NULL, &cli_rtp_rtcp_no_stats_deprecated }, + + { { "stun", "debug", NULL }, + stun_do_debug, "Enable STUN debugging", + stun_debug_usage }, + + { { "stun", "nodebug", NULL }, + stun_no_debug, "Disable STUN debugging", + stun_no_debug_usage, NULL, &cli_stun_no_debug_deprecated }, +}; int ast_rtp_reload(void) { @@ -3403,19 +3534,7 @@ int ast_rtp_reload(void) /*! \brief Initialize the RTP system in Asterisk */ void ast_rtp_init(void) { - ast_cli_register(&cli_debug); - ast_cli_register(&cli_debug_ip); - ast_cli_register(&cli_no_debug); - - ast_cli_register(&cli_debug_rtcp); - ast_cli_register(&cli_debug_ip_rtcp); - ast_cli_register(&cli_no_debug_rtcp); - - ast_cli_register(&cli_stats_rtcp); - ast_cli_register(&cli_no_stats_rtcp); - - ast_cli_register(&cli_stun_debug); - ast_cli_register(&cli_stun_no_debug); + ast_cli_register_multiple(cli_rtp, sizeof(cli_rtp) / sizeof(struct ast_cli_entry)); ast_rtp_reload(); } diff --git a/main/translate.c b/main/translate.c index 45b0292bd..77feabbac 100644 --- a/main/translate.c +++ b/main/translate.c @@ -475,7 +475,7 @@ static void rebuild_matrix(int samples) } /*! \brief CLI "show translation" command handler */ -static int show_translation(int fd, int argc, char *argv[]) +static int show_translation_deprecated(int fd, int argc, char *argv[]) { #define SHOW_TRANS 12 int x, y, z; @@ -544,16 +544,92 @@ static int show_translation(int fd, int argc, char *argv[]) return RESULT_SUCCESS; } +static int show_translation(int fd, int argc, char *argv[]) +{ +#define SHOW_TRANS 12 + int x, y, z; + int curlen = 0, longest = 0; + + if (argc > 5) + return RESULT_SHOWUSAGE; + + AST_LIST_LOCK(&translators); + + if (argv[3] && !strcasecmp(argv[3], "recalc")) { + z = argv[4] ? atoi(argv[4]) : 1; + + if (z <= 0) { + ast_cli(fd, " C'mon let's be serious here... defaulting to 1.\n"); + z = 1; + } + + if (z > MAX_RECALC) { + ast_cli(fd, " Maximum limit of recalc exceeded by %d, truncating value to %d\n", z - MAX_RECALC, MAX_RECALC); + z = MAX_RECALC; + } + ast_cli(fd, " Recalculating Codec Translation (number of sample seconds: %d)\n\n", z); + rebuild_matrix(z); + } + + ast_cli(fd, " Translation times between formats (in milliseconds) for one second of data\n"); + ast_cli(fd, " Source Format (Rows) Destination Format (Columns)\n\n"); + /* Get the length of the longest (usable?) codec name, so we know how wide the left side should be */ + for (x = 0; x < SHOW_TRANS; x++) { + curlen = strlen(ast_getformatname(1 << (x + 1))); + if (curlen > longest) + longest = curlen; + } + for (x = -1; x < SHOW_TRANS; x++) { + char line[80]; + char *buf = line; + size_t left = sizeof(line) - 1; /* one initial space */ + /* next 2 lines run faster than using ast_build_string() */ + *buf++ = ' '; + *buf = '\0'; + for (y = -1; y < SHOW_TRANS; y++) { + curlen = strlen(ast_getformatname(1 << (y))); + + if (x >= 0 && y >= 0 && tr_matrix[x][y].step) { + /* XXX 999 is a little hackish + We don't want this number being larger than the shortest (or current) codec + For now, that is "gsm" */ + ast_build_string(&buf, &left, "%*d", curlen + 1, tr_matrix[x][y].cost > 999 ? 0 : tr_matrix[x][y].cost); + } else if (x == -1 && y >= 0) { + /* Top row - use a dynamic size */ + ast_build_string(&buf, &left, "%*s", curlen + 1, ast_getformatname(1 << (x + y + 1)) ); + } else if (y == -1 && x >= 0) { + /* Left column - use a static size. */ + ast_build_string(&buf, &left, "%*s", longest, ast_getformatname(1 << (x + y + 1)) ); + } else if (x >= 0 && y >= 0) { + ast_build_string(&buf, &left, "%*s", curlen + 1, "-"); + } else { + ast_build_string(&buf, &left, "%*s", longest, ""); + } + } + ast_build_string(&buf, &left, "\n"); + ast_cli(fd, line); + } + AST_LIST_UNLOCK(&translators); + return RESULT_SUCCESS; +} static char show_trans_usage[] = -"Usage: show translation [recalc] []\n" +"Usage: core show translation [recalc] []\n" " Displays known codec translators and the cost associated\n" "with each conversion. If the argument 'recalc' is supplied along\n" "with optional number of seconds to test a new test will be performed\n" "as the chart is being displayed.\n"; -static struct ast_cli_entry show_trans = -{ { "show", "translation", NULL }, show_translation, "Display translation matrix", show_trans_usage }; +static struct ast_cli_entry cli_show_translation_deprecated = { + { "show", "translation", NULL }, + show_translation_deprecated, NULL, + NULL }; + +static struct ast_cli_entry cli_translate[] = { + { { "core", "show", "translation", NULL }, + show_translation, "Display translation matrix", + show_trans_usage, NULL, &cli_show_translation_deprecated }, +}; /*! \brief register codec translator */ int __ast_register_translator(struct ast_translator *t, struct ast_module *mod) @@ -613,7 +689,7 @@ int __ast_register_translator(struct ast_translator *t, struct ast_module *mod) } AST_LIST_LOCK(&translators); if (!added_cli) { - ast_cli_register(&show_trans); + ast_cli_register_multiple(cli_translate, sizeof(cli_translate) / sizeof(struct ast_cli_entry)); added_cli++; } AST_LIST_INSERT_HEAD(&translators, t, list); diff --git a/main/udptl.c b/main/udptl.c index 1264c23fc..d21cfe981 100644 --- a/main/udptl.c +++ b/main/udptl.c @@ -1135,7 +1135,7 @@ static int udptl_do_debug(int fd, int argc, char *argv[]) return RESULT_SUCCESS; } -static int udptl_no_debug(int fd, int argc, char *argv[]) +static int udptl_nodebug_deprecated(int fd, int argc, char *argv[]) { if (argc !=3) return RESULT_SHOWUSAGE; @@ -1144,22 +1144,41 @@ static int udptl_no_debug(int fd, int argc, char *argv[]) return RESULT_SUCCESS; } +static int udptl_nodebug(int fd, int argc, char *argv[]) +{ + if (argc != 2) + return RESULT_SHOWUSAGE; + udptldebug = 0; + ast_cli(fd,"UDPTL Debugging Disabled\n"); + return RESULT_SUCCESS; +} + static char debug_usage[] = "Usage: udptl debug [ip host[:port]]\n" " Enable dumping of all UDPTL packets to and from host.\n"; -static char no_debug_usage[] = - "Usage: udptl no debug\n" +static char nodebug_usage[] = + "Usage: udptl nodebug\n" " Disable all UDPTL debugging\n"; -static struct ast_cli_entry cli_debug_ip = -{{ "udptl", "debug", "ip", NULL } , udptl_do_debug, "Enable UDPTL debugging on IP", debug_usage }; +static struct ast_cli_entry cli_udptl_no_debug = { + { "udptl", "no", "debug", NULL }, + udptl_nodebug_deprecated, NULL, + NULL }; -static struct ast_cli_entry cli_debug = -{{ "udptl", "debug", NULL } , udptl_do_debug, "Enable UDPTL debugging", debug_usage }; +static struct ast_cli_entry cli_udptl[] = { + { { "udptl", "debug", NULL }, + udptl_do_debug, "Enable UDPTL debugging", + debug_usage }, -static struct ast_cli_entry cli_no_debug = -{{ "udptl", "no", "debug", NULL } , udptl_no_debug, "Disable UDPTL debugging", no_debug_usage }; + { { "udptl", "debug", "ip", NULL }, + udptl_do_debug, "Enable UDPTL debugging on IP", + debug_usage }, + + { { "udptl", "nodebug", NULL }, + udptl_nodebug, "Disable UDPTL debugging", + nodebug_usage, NULL, &cli_udptl_no_debug }, +}; void ast_udptl_reload(void) { @@ -1239,8 +1258,6 @@ void ast_udptl_reload(void) void ast_udptl_init(void) { - ast_cli_register(&cli_debug); - ast_cli_register(&cli_debug_ip); - ast_cli_register(&cli_no_debug); + ast_cli_register_multiple(cli_udptl, sizeof(cli_udptl) / sizeof(struct ast_cli_entry)); ast_udptl_reload(); } -- cgit v1.2.3