aboutsummaryrefslogtreecommitdiffstats
path: root/main/asterisk.c
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2007-10-11 19:03:06 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2007-10-11 19:03:06 +0000
commit13b9c5237c9f5b8b3d72634d575665b1d1147ba3 (patch)
tree44dcb2c14abed6932db4f248b17626a01a38f59b /main/asterisk.c
parenta8506328befc2a11643cea88772609610ec11c33 (diff)
Merge a ton of NEW_CLI conversions. Thanks to everyone that helped out! :)
(closes issue #10724) Reported by: eliel Patches: chan_skinny.c.patch uploaded by eliel (license 64) chan_oss.c.patch uploaded by eliel (license 64) chan_mgcp.c.patch2 uploaded by eliel (license 64) pbx_config.c.patch uploaded by seanbright (license 71) iax2-provision.c.patch uploaded by eliel (license 64) chan_gtalk.c.patch uploaded by eliel (license 64) pbx_ael.c.patch uploaded by seanbright (license 71) file.c.patch uploaded by seanbright (license 71) image.c.patch uploaded by seanbright (license 71) cli.c.patch uploaded by moy (license 222) astobj2.c.patch uploaded by moy (license 222) asterisk.c.patch uploaded by moy (license 222) res_limit.c.patch uploaded by seanbright (license 71) res_convert.c.patch uploaded by seanbright (license 71) res_crypto.c.patch uploaded by seanbright (license 71) app_osplookup.c.patch uploaded by seanbright (license 71) app_rpt.c.patch uploaded by seanbright (license 71) app_mixmonitor.c.patch uploaded by seanbright (license 71) channel.c.patch uploaded by seanbright (license 71) translate.c.patch uploaded by seanbright (license 71) udptl.c.patch uploaded by seanbright (license 71) threadstorage.c.patch uploaded by seanbright (license 71) db.c.patch uploaded by seanbright (license 71) cdr.c.patch uploaded by moy (license 222) pbd_dundi.c.patch uploaded by moy (license 222) app_osplookup-rev83558.patch uploaded by moy (license 222) res_clioriginate.c.patch uploaded by moy (license 222) git-svn-id: http://svn.digium.com/svn/asterisk/trunk@85460 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/asterisk.c')
-rw-r--r--main/asterisk.c656
1 files changed, 368 insertions, 288 deletions
diff --git a/main/asterisk.c b/main/asterisk.c
index 59b97e59e..6e9ccb7d4 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -305,10 +305,6 @@ struct thread_list_t {
static AST_RWLIST_HEAD_STATIC(thread_list, thread_list_t);
-static const char show_threads_help[] =
-"Usage: core show threads\n"
-" List threads currently active in the system.\n";
-
void ast_register_thread(char *name)
{
struct thread_list_t *new = ast_calloc(1, sizeof(*new));
@@ -342,105 +338,130 @@ void ast_unregister_thread(void *id)
}
/*! \brief Give an overview of core settings */
-static int handle_show_settings(int fd, int argc, char *argv[])
+static char *handle_show_settings(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
char buf[BUFSIZ];
struct ast_tm tm;
- ast_cli(fd, "\nPBX Core settings\n");
- ast_cli(fd, "-----------------\n");
- ast_cli(fd, " Version: %s\n", "" ASTERISK_VERSION "" );
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "core show settings";
+ e->usage = "Usage: core show settings\n"
+ " Show core misc settings";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ ast_cli(a->fd, "\nPBX Core settings\n");
+ ast_cli(a->fd, "-----------------\n");
+ ast_cli(a->fd, " Version: %s\n", "" ASTERISK_VERSION "" );
if (option_maxcalls)
- ast_cli(fd, " Max. calls: %d (Current %d)\n", option_maxcalls, ast_active_channels());
+ ast_cli(a->fd, " Max. calls: %d (Current %d)\n", option_maxcalls, ast_active_channels());
else
- ast_cli(fd, " Max. calls: Not set\n");
+ ast_cli(a->fd, " Max. calls: Not set\n");
if (option_maxfiles)
- ast_cli(fd, " Max. open file handles: %d\n", option_maxfiles);
+ ast_cli(a->fd, " Max. open file handles: %d\n", option_maxfiles);
else
- ast_cli(fd, " Max. open file handles: Not set\n");
- ast_cli(fd, " Verbosity: %d\n", option_verbose);
- ast_cli(fd, " Debug level: %d\n", option_debug);
- ast_cli(fd, " Max load avg: %lf\n", option_maxload);
+ ast_cli(a->fd, " Max. open file handles: Not set\n");
+ ast_cli(a->fd, " Verbosity: %d\n", option_verbose);
+ ast_cli(a->fd, " Debug level: %d\n", option_debug);
+ ast_cli(a->fd, " Max load avg: %lf\n", option_maxload);
#if defined(HAVE_SYSINFO)
- ast_cli(fd, " Min Free Memory: %ld MB\n", option_minmemfree);
+ ast_cli(a->fd, " Min Free Memory: %ld MB\n", option_minmemfree);
#endif
if (ast_localtime(&ast_startuptime, &tm, NULL)) {
ast_strftime(buf, sizeof(buf), "%H:%M:%S", &tm);
- ast_cli(fd, " Startup time: %s\n", buf);
+ ast_cli(a->fd, " Startup time: %s\n", buf);
}
if (ast_localtime(&ast_lastreloadtime, &tm, NULL)) {
ast_strftime(buf, sizeof(buf), "%H:%M:%S", &tm);
- ast_cli(fd, " Last reload time: %s\n", buf);
- }
- ast_cli(fd, " System: %s/%s built by %s on %s %s\n", ast_build_os, ast_build_kernel, ast_build_user, ast_build_machine, ast_build_date);
- ast_cli(fd, " System name: %s\n", ast_config_AST_SYSTEM_NAME);
- ast_cli(fd, " Default language: %s\n", defaultlanguage);
- ast_cli(fd, " Language prefix: %s\n", ast_language_is_prefix ? "Enabled" : "Disabled");
- ast_cli(fd, " User name and group: %s/%s\n", ast_config_AST_RUN_USER, ast_config_AST_RUN_GROUP);
- ast_cli(fd, " Executable includes: %s\n", ast_test_flag(&ast_options, AST_OPT_FLAG_EXEC_INCLUDES) ? "Enabled" : "Disabled");
- ast_cli(fd, " Transcode via SLIN: %s\n", ast_test_flag(&ast_options, AST_OPT_FLAG_TRANSCODE_VIA_SLIN) ? "Enabled" : "Disabled");
- ast_cli(fd, " Internal timing: %s\n", ast_test_flag(&ast_options, AST_OPT_FLAG_INTERNAL_TIMING) ? "Enabled" : "Disabled");
- ast_cli(fd, " Transmit silence during rec: %s\n", ast_test_flag(&ast_options, AST_OPT_FLAG_INTERNAL_TIMING) ? "Enabled" : "Disabled");
-
- ast_cli(fd, "\n* Subsystems\n");
- ast_cli(fd, " -------------\n");
- ast_cli(fd, " Manager (AMI): %s\n", check_manager_enabled() ? "Enabled" : "Disabled");
- ast_cli(fd, " Web Manager (AMI/HTTP): %s\n", check_webmanager_enabled() ? "Enabled" : "Disabled");
- ast_cli(fd, " Call data records: %s\n", check_cdr_enabled() ? "Enabled" : "Disabled");
- ast_cli(fd, " Realtime Architecture (ARA): %s\n", ast_realtime_enabled() ? "Enabled" : "Disabled");
+ ast_cli(a->fd, " Last reload time: %s\n", buf);
+ }
+ ast_cli(a->fd, " System: %s/%s built by %s on %s %s\n", ast_build_os, ast_build_kernel, ast_build_user, ast_build_machine, ast_build_date);
+ ast_cli(a->fd, " System name: %s\n", ast_config_AST_SYSTEM_NAME);
+ ast_cli(a->fd, " Default language: %s\n", defaultlanguage);
+ ast_cli(a->fd, " Language prefix: %s\n", ast_language_is_prefix ? "Enabled" : "Disabled");
+ ast_cli(a->fd, " User name and group: %s/%s\n", ast_config_AST_RUN_USER, ast_config_AST_RUN_GROUP);
+ ast_cli(a->fd, " Executable includes: %s\n", ast_test_flag(&ast_options, AST_OPT_FLAG_EXEC_INCLUDES) ? "Enabled" : "Disabled");
+ ast_cli(a->fd, " Transcode via SLIN: %s\n", ast_test_flag(&ast_options, AST_OPT_FLAG_TRANSCODE_VIA_SLIN) ? "Enabled" : "Disabled");
+ ast_cli(a->fd, " Internal timing: %s\n", ast_test_flag(&ast_options, AST_OPT_FLAG_INTERNAL_TIMING) ? "Enabled" : "Disabled");
+ ast_cli(a->fd, " Transmit silence during rec: %s\n", ast_test_flag(&ast_options, AST_OPT_FLAG_INTERNAL_TIMING) ? "Enabled" : "Disabled");
+
+ ast_cli(a->fd, "\n* Subsystems\n");
+ ast_cli(a->fd, " -------------\n");
+ ast_cli(a->fd, " Manager (AMI): %s\n", check_manager_enabled() ? "Enabled" : "Disabled");
+ ast_cli(a->fd, " Web Manager (AMI/HTTP): %s\n", check_webmanager_enabled() ? "Enabled" : "Disabled");
+ ast_cli(a->fd, " Call data records: %s\n", check_cdr_enabled() ? "Enabled" : "Disabled");
+ ast_cli(a->fd, " Realtime Architecture (ARA): %s\n", ast_realtime_enabled() ? "Enabled" : "Disabled");
/*! \todo we could check musiconhold, voicemail, smdi, adsi, queues */
- ast_cli(fd, "\n* Directories\n");
- ast_cli(fd, " -------------\n");
- ast_cli(fd, " Configuration file: %s\n", ast_config_AST_CONFIG_FILE);
- ast_cli(fd, " Configuration directory: %s\n", ast_config_AST_CONFIG_DIR);
- ast_cli(fd, " Module directory: %s\n", ast_config_AST_MODULE_DIR);
- ast_cli(fd, " Spool directory: %s\n", ast_config_AST_SPOOL_DIR);
- ast_cli(fd, " Log directory: %s\n", ast_config_AST_LOG_DIR);
- ast_cli(fd, "\n\n");
- return 0;
+ ast_cli(a->fd, "\n* Directories\n");
+ ast_cli(a->fd, " -------------\n");
+ ast_cli(a->fd, " Configuration file: %s\n", ast_config_AST_CONFIG_FILE);
+ ast_cli(a->fd, " Configuration directory: %s\n", ast_config_AST_CONFIG_DIR);
+ ast_cli(a->fd, " Module directory: %s\n", ast_config_AST_MODULE_DIR);
+ ast_cli(a->fd, " Spool directory: %s\n", ast_config_AST_SPOOL_DIR);
+ ast_cli(a->fd, " Log directory: %s\n", ast_config_AST_LOG_DIR);
+ ast_cli(a->fd, "\n\n");
+ return CLI_SUCCESS;
}
-static int handle_show_threads(int fd, int argc, char *argv[])
+static char *handle_show_threads(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
int count = 0;
struct thread_list_t *cur;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "core show threads";
+ e->usage =
+ "Usage: core show threads\n"
+ " List threads currently active in the system.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
AST_RWLIST_RDLOCK(&thread_list);
AST_RWLIST_TRAVERSE(&thread_list, cur, list) {
- ast_cli(fd, "%p %s\n", (void *)cur->id, cur->name);
+ ast_cli(a->fd, "%p %s\n", (void *)cur->id, cur->name);
count++;
}
AST_RWLIST_UNLOCK(&thread_list);
- ast_cli(fd, "%d threads listed.\n", count);
- return 0;
+ ast_cli(a->fd, "%d threads listed.\n", count);
+ return CLI_SUCCESS;
}
#if defined(HAVE_SYSINFO)
-static const char show_sysinfo_help[] =
-"Usage: core show sysinfo\n"
-" List current system information.\n";
-
/*! \brief Give an overview of system statistics */
-static int handle_show_sysinfo(int fd, int argc, char *argv[])
+static char *handle_show_sysinfo(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct sysinfo sys_info;
-
- if (sysinfo(&sys_info)) {
- ast_cli(fd, "FAILED to retrieve system information\n\n");
- return 0;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "core show sysinfo";
+ e->usage =
+ "Usage: core show sysinfo\n"
+ " List current system information.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
}
- ast_cli(fd, "\nSystem Statistics\n");
- ast_cli(fd, "-----------------\n");
- ast_cli(fd, " System Uptime: %ld hours\n", sys_info.uptime/3600);
- ast_cli(fd, " Total RAM: %ld KiB\n", (sys_info.totalram / sys_info.mem_unit)/1024);
- ast_cli(fd, " Free RAM: %ld KiB\n", (sys_info.freeram / sys_info.mem_unit)/1024);
- ast_cli(fd, " Buffer RAM: %ld KiB\n", (sys_info.bufferram / sys_info.mem_unit)/1024);
- ast_cli(fd, " Total Swap Space: %ld KiB\n", (sys_info.totalswap / sys_info.mem_unit)/1024);
- ast_cli(fd, " Free Swap Space: %ld KiB\n\n", (sys_info.freeswap / sys_info.mem_unit)/1024);
- ast_cli(fd, " Number of Processes: %d \n\n", sys_info.procs);
- return 0;
+ if (sysinfo(&sys_info)) {
+ ast_cli(a->fd, "FAILED to retrieve system information\n\n");
+ return CLI_FAILURE;
+ }
+ ast_cli(a->fd, "\nSystem Statistics\n");
+ ast_cli(a->fd, "-----------------\n");
+ ast_cli(a->fd, " System Uptime: %ld hours\n", sys_info.uptime/3600);
+ ast_cli(a->fd, " Total RAM: %ld KiB\n", (sys_info.totalram / sys_info.mem_unit)/1024);
+ ast_cli(a->fd, " Free RAM: %ld KiB\n", (sys_info.freeram / sys_info.mem_unit)/1024);
+ ast_cli(a->fd, " Buffer RAM: %ld KiB\n", (sys_info.bufferram / sys_info.mem_unit)/1024);
+ ast_cli(a->fd, " Total Swap Space: %ld KiB\n", (sys_info.totalswap / sys_info.mem_unit)/1024);
+ ast_cli(a->fd, " Free Swap Space: %ld KiB\n\n", (sys_info.freeswap / sys_info.mem_unit)/1024);
+ ast_cli(a->fd, " Number of Processes: %d \n\n", sys_info.procs);
+ return CLI_SUCCESS;
}
#endif
@@ -541,59 +562,84 @@ 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[])
+#define DEFINE_PROFILE_MIN_MAX_VALUES min = 0; \
+ max = prof_data->entries;\
+ if (a->argc > 3) { /* specific entries */ \
+ if (isdigit(a->argv[3][0])) { \
+ min = atoi(a->argv[3]); \
+ if (a->argc == 5 && strcmp(a->argv[4], "-")) \
+ max = atoi(a->argv[4]); \
+ } else \
+ search = a->argv[3]; \
+ } \
+ if (max > prof_data->entries) \
+ max = prof_data->entries;
+
+static char *handle_show_profile(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
int i, min, max;
char *search = NULL;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "core show profile";
+ e->usage = "Usage: core show profile\n"
+ " show profile information";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
if (prof_data == NULL)
return 0;
- min = 0;
- max = prof_data->entries;
- if (argc > 3) { /* specific entries */
- if (isdigit(argv[3][0])) {
- min = atoi(argv[3]);
- if (argc == 5 && strcmp(argv[4], "-"))
- max = atoi(argv[4]);
- } else
- search = argv[3];
- }
- 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",
+ DEFINE_PROFILE_MIN_MAX_VALUES;
+ ast_cli(a->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",
+ ast_cli(a->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",
+ ast_cli(a->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;
+ return CLI_SUCCESS;
}
-static const char show_version_files_help[] =
-"Usage: core show file version [like <pattern>]\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";
+static char *handle_clear_profile(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+ int i, min, max;
+ char *search = NULL;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "core clear profile";
+ e->usage = "Usage: core clear profile\n"
+ " clear profile information";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if (prof_data == NULL)
+ return 0;
+
+ DEFINE_PROFILE_MIN_MAX_VALUES;
+ 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 CLI_SUCCESS;
+}
+#undef DEFINE_PROFILE_MIN_MAX_VALUES
/*! \brief CLI command to list module versions */
-static int handle_show_version_files(int fd, int argc, char *argv[])
+static char *handle_show_version_files(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
#define FORMAT "%-25.25s %-40.40s\n"
struct file_version *iterator;
@@ -601,15 +647,42 @@ static int handle_show_version_files(int fd, int argc, char *argv[])
int havepattern = 0;
int havename = 0;
int count_files = 0;
+ char *ret = NULL;
+ int matchlen, which = 0;
+ struct file_version *find;
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "core show file version [like]";
+ e->usage =
+ "Usage: core show file version [like <pattern>]\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";
+ return NULL;
+ case CLI_GENERATE:
+ matchlen = strlen(a->word);
+ if (a->pos != 3)
+ return NULL;
+ AST_RWLIST_RDLOCK(&file_versions);
+ AST_RWLIST_TRAVERSE(&file_versions, find, list) {
+ if (!strncasecmp(a->word, find->file, matchlen) && ++which > a->n) {
+ ret = ast_strdup(find->file);
+ break;
+ }
+ }
+ AST_RWLIST_UNLOCK(&file_versions);
+ return ret;
+ }
- switch (argc) {
+
+ switch (a->argc) {
case 6:
- if (!strcasecmp(argv[4], "like")) {
- if (regcomp(&regexbuf, argv[5], REG_EXTENDED | REG_NOSUB))
- return RESULT_SHOWUSAGE;
+ if (!strcasecmp(a->argv[4], "like")) {
+ if (regcomp(&regexbuf, a->argv[5], REG_EXTENDED | REG_NOSUB))
+ return CLI_SHOWUSAGE;
havepattern = 1;
} else
- return RESULT_SHOWUSAGE;
+ return CLI_SHOWUSAGE;
break;
case 5:
havename = 1;
@@ -617,57 +690,36 @@ static int handle_show_version_files(int fd, int argc, char *argv[])
case 4:
break;
default:
- return RESULT_SHOWUSAGE;
+ return CLI_SHOWUSAGE;
}
- ast_cli(fd, FORMAT, "File", "Revision");
- ast_cli(fd, FORMAT, "----", "--------");
+ ast_cli(a->fd, FORMAT, "File", "Revision");
+ ast_cli(a->fd, FORMAT, "----", "--------");
AST_RWLIST_RDLOCK(&file_versions);
AST_RWLIST_TRAVERSE(&file_versions, iterator, list) {
- if (havename && strcasecmp(iterator->file, argv[4]))
+ if (havename && strcasecmp(iterator->file, a->argv[4]))
continue;
if (havepattern && regexec(&regexbuf, iterator->file, 0, NULL, 0))
continue;
- ast_cli(fd, FORMAT, iterator->file, iterator->version);
+ ast_cli(a->fd, FORMAT, iterator->file, iterator->version);
count_files++;
if (havename)
break;
}
AST_RWLIST_UNLOCK(&file_versions);
if (!havename) {
- ast_cli(fd, "%d files listed.\n", count_files);
+ ast_cli(a->fd, "%d files listed.\n", count_files);
}
if (havepattern)
regfree(&regexbuf);
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
#undef FORMAT
}
-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 != 3)
- return NULL;
-
- AST_RWLIST_RDLOCK(&file_versions);
- AST_RWLIST_TRAVERSE(&file_versions, find, list) {
- if (!strncasecmp(word, find->file, matchlen) && ++which > state) {
- ret = ast_strdup(find->file);
- break;
- }
- }
- AST_RWLIST_UNLOCK(&file_versions);
-
- return ret;
-}
#endif /* ! LOW_MEMORY */
int ast_register_atexit(void (*func)(void))
@@ -1409,62 +1461,25 @@ static int remoteconsolehandler(char *s)
return ret;
}
-static const char abort_halt_help[] =
-"Usage: abort shutdown\n"
-" Causes Asterisk to abort an executing shutdown or restart, and resume normal\n"
-" call operations.\n";
-
-static const char shutdown_now_help[] =
-"Usage: stop now\n"
-" Shuts down a running Asterisk immediately, hanging up all active calls .\n";
-
-static const char shutdown_gracefully_help[] =
-"Usage: stop gracefully\n"
-" Causes Asterisk to not accept new calls, and exit when all\n"
-" active calls have terminated normally.\n";
-
-static const char shutdown_when_convenient_help[] =
-"Usage: stop when convenient\n"
-" Causes Asterisk to perform a shutdown when all active calls have ended.\n";
-
-static const char restart_now_help[] =
-"Usage: restart now\n"
-" Causes Asterisk to hangup all calls and exec() itself performing a cold\n"
-" restart.\n";
-
-static const char restart_gracefully_help[] =
-"Usage: restart gracefully\n"
-" Causes Asterisk to stop accepting new calls and exec() itself performing a cold\n"
-" restart when all active calls have ended.\n";
-
-static const char restart_when_convenient_help[] =
-"Usage: restart when convenient\n"
-" Causes Asterisk to perform a cold restart when all active calls have ended.\n";
-
-static const char bang_help[] =
-"Usage: !<command>\n"
-" Executes a given shell command\n";
-
-static const char show_warranty_help[] =
-"Usage: core show warranty\n"
-" Shows the warranty (if any) for this copy of Asterisk.\n";
-
-static const char show_license_help[] =
-"Usage: core show license\n"
-" Shows the license(s) for this copy of Asterisk.\n";
-
-static const char version_help[] =
-"Usage: core show version\n"
-" Shows Asterisk version information.\n";
-
-static int handle_version(int fd, int argc, char *argv[])
+static char *handle_version(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- ast_cli(fd, "Asterisk %s built by %s @ %s on a %s running %s on %s\n",
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "core show version";
+ e->usage =
+ "Usage: core show version\n"
+ " Shows Asterisk version information.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if (a->argc != 3)
+ return CLI_SHOWUSAGE;
+ ast_cli(a->fd, "Asterisk %s built by %s @ %s on a %s running %s on %s\n",
ASTERISK_VERSION, ast_build_user, ast_build_hostname,
ast_build_machine, ast_build_os, ast_build_date);
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
}
#if 0
@@ -1477,68 +1492,160 @@ static int handle_quit(int fd, int argc, char *argv[])
}
#endif
-static int handle_shutdown_now(int fd, int argc, char *argv[])
+static char *handle_stop_now(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
- if (argc != 2)
- return RESULT_SHOWUSAGE;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "stop now";
+ e->usage =
+ "Usage: stop now\n"
+ " Shuts down a running Asterisk immediately, hanging up all active calls .\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if (a->argc != 2)
+ return CLI_SHOWUSAGE;
quit_handler(0, 0 /* Not nice */, 1 /* safely */, 0 /* not restart */);
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
}
-static int handle_shutdown_gracefully(int fd, int argc, char *argv[])
+static char *handle_stop_gracefully(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
- if (argc != 2)
- return RESULT_SHOWUSAGE;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "stop gracefully";
+ e->usage =
+ "Usage: stop gracefully\n"
+ " Causes Asterisk to not accept new calls, and exit when all\n"
+ " active calls have terminated normally.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if (a->argc != 2)
+ return CLI_SHOWUSAGE;
quit_handler(0, 1 /* nicely */, 1 /* safely */, 0 /* no restart */);
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
}
-static int handle_shutdown_when_convenient(int fd, int argc, char *argv[])
+static char *handle_stop_when_convenient(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- ast_cli(fd, "Waiting for inactivity to perform halt\n");
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "stop when convenient";
+ e->usage =
+ "Usage: stop when convenient\n"
+ " Causes Asterisk to perform a shutdown when all active calls have ended.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if (a->argc != 3)
+ return CLI_SHOWUSAGE;
+ ast_cli(a->fd, "Waiting for inactivity to perform halt\n");
quit_handler(0, 2 /* really nicely */, 1 /* safely */, 0 /* don't restart */);
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
}
-static int handle_restart_now(int fd, int argc, char *argv[])
+static char *handle_restart_now(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
- if (argc != 2)
- return RESULT_SHOWUSAGE;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "restart now";
+ e->usage =
+ "Usage: restart now\n"
+ " Causes Asterisk to hangup all calls and exec() itself performing a cold\n"
+ " restart.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if (a->argc != 2)
+ return CLI_SHOWUSAGE;
quit_handler(0, 0 /* not nicely */, 1 /* safely */, 1 /* restart */);
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
}
-static int handle_restart_gracefully(int fd, int argc, char *argv[])
+static char *handle_restart_gracefully(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
- if (argc != 2)
- return RESULT_SHOWUSAGE;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "restart gracefully";
+ e->usage =
+ "Usage: restart gracefully\n"
+ " Causes Asterisk to stop accepting new calls and exec() itself performing a cold\n"
+ " restart when all active calls have ended.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if (a->argc != 2)
+ return CLI_SHOWUSAGE;
quit_handler(0, 1 /* nicely */, 1 /* safely */, 1 /* restart */);
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
}
-static int handle_restart_when_convenient(int fd, int argc, char *argv[])
+static char *handle_restart_when_convenient(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
- if (argc != 3)
- return RESULT_SHOWUSAGE;
- ast_cli(fd, "Waiting for inactivity to perform restart\n");
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "restart when convenient";
+ e->usage =
+ "Usage: restart when convenient\n"
+ " Causes Asterisk to perform a cold restart when all active calls have ended.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if (a->argc != 3)
+ return CLI_SHOWUSAGE;
+ ast_cli(a->fd, "Waiting for inactivity to perform restart\n");
quit_handler(0, 2 /* really nicely */, 1 /* safely */, 1 /* restart */);
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
}
-static int handle_abort_halt(int fd, int argc, char *argv[])
+static char *handle_abort_shutdown(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
- if (argc != 2)
- return RESULT_SHOWUSAGE;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "abort shutdown";
+ e->usage =
+ "Usage: abort shutdown\n"
+ " Causes Asterisk to abort an executing shutdown or restart, and resume normal\n"
+ " call operations.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if (a->argc != 2)
+ return CLI_SHOWUSAGE;
ast_cancel_shutdown();
shuttingdown = 0;
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
}
-static int handle_bang(int fd, int argc, char *argv[])
+static char *handle_bang(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
- return RESULT_SUCCESS;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "!";
+ e->usage =
+ "Usage: !<command>\n"
+ " Executes a given shell command\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ return CLI_SUCCESS;
}
static const char warranty_lines[] = {
"\n"
@@ -1565,11 +1672,22 @@ static const char warranty_lines[] = {
"POSSIBILITY OF SUCH DAMAGES.\n"
};
-static int show_warranty(int fd, int argc, char *argv[])
+static char *show_warranty(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
- ast_cli(fd, warranty_lines);
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "core show warranty";
+ e->usage =
+ "Usage: core show warranty\n"
+ " Shows the warranty (if any) for this copy of Asterisk.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
- return RESULT_SUCCESS;
+ ast_cli(a->fd, warranty_lines);
+
+ return CLI_SUCCESS;
}
static const char license_lines[] = {
@@ -1591,11 +1709,22 @@ static const char license_lines[] = {
"Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n"
};
-static int show_license(int fd, int argc, char *argv[])
+static char *show_license(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
- ast_cli(fd, license_lines);
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "core show license";
+ e->usage =
+ "Usage: core show license\n"
+ " Shows the license(s) for this copy of Asterisk.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
- return RESULT_SUCCESS;
+ ast_cli(a->fd, license_lines);
+
+ return CLI_SUCCESS;
}
#define ASTERISK_PROMPT "*CLI> "
@@ -1603,75 +1732,26 @@ static int show_license(int fd, int argc, char *argv[])
#define ASTERISK_PROMPT2 "%s*CLI> "
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 },
-
- { { "core", "show", "warranty", NULL },
- show_warranty, "Show the warranty (if any) for this copy of Asterisk",
- show_warranty_help },
-
- { { "core", "show", "license", NULL },
- show_license, "Show the license(s) for this copy of Asterisk",
- show_license_help },
-
- { { "core", "show", "version", NULL },
- handle_version, "Display version info",
- version_help },
-
- { { "!", NULL },
- handle_bang, "Execute a shell command",
- bang_help },
-
+ NEW_CLI(handle_abort_shutdown, "Cancel a running shutdown"),
+ NEW_CLI(handle_stop_now, "Shut down Asterisk immediately"),
+ NEW_CLI(handle_stop_gracefully, "Gracefully shut down Asterisk"),
+ NEW_CLI(handle_stop_when_convenient, "Shut down Asterisk at empty call volume"),
+ NEW_CLI(handle_restart_now, "Restart Asterisk immediately"),
+ NEW_CLI(handle_restart_gracefully, "Restart Asterisk gracefully"),
+ NEW_CLI(handle_restart_when_convenient, "Restart Asterisk at empty call volume"),
+ NEW_CLI(show_warranty, "Show the warranty (if any) for this copy of Asterisk"),
+ NEW_CLI(show_license, "Show the license(s) for this copy of Asterisk"),
+ NEW_CLI(handle_version, "Display version info"),
+ NEW_CLI(handle_bang, "Execute a shell command"),
#if !defined(LOW_MEMORY)
- { { "core", "show", "file", "version", NULL },
- handle_show_version_files, "List versions of files used to build Asterisk",
- show_version_files_help, complete_show_version_files },
-
- { { "core", "show", "threads", NULL },
- handle_show_threads, "Show running threads",
- show_threads_help },
-
+ NEW_CLI(handle_show_version_files, "List versions of files used to build Asterisk"),
+ NEW_CLI(handle_show_threads, "Show running threads"),
#if defined(HAVE_SYSINFO)
- { { "core", "show", "sysinfo", NULL },
- handle_show_sysinfo, "Show System Information",
- show_sysinfo_help },
+ NEW_CLI(handle_show_sysinfo, "Show System Information"),
#endif
-
- { { "core", "show", "profile", NULL },
- handle_show_profile, "Display profiling info",
- NULL },
-
- { { "core", "show", "settings", NULL },
- handle_show_settings, "Show some core settings",
- NULL },
-
- { { "core", "clear", "profile", NULL },
- handle_show_profile, "Clear profiling info",
- NULL },
+ NEW_CLI(handle_show_profile, "Display profiling info"),
+ NEW_CLI(handle_show_settings, "Show some core settings"),
+ NEW_CLI(handle_clear_profile, "Clear profiling info"),
#endif /* ! LOW_MEMORY */
};