/* * Asterisk -- A telephony toolkit for Linux. * * Standard Command Line Interface * * Copyright (C) 1999 - 2005, Digium, Inc. * * Mark Spencer * * This program is free software, distributed under the terms of * the GNU General Public License */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* For rl_filename_completion */ #include "editline/readline/readline.h" /* For module directory */ #include "asterisk.h" #include "build.h" #include "astconf.h" #define VERSION_INFO "Asterisk " ASTERISK_VERSION " built by " BUILD_USER "@" BUILD_HOSTNAME \ " on a " BUILD_MACHINE " running " BUILD_OS extern unsigned long global_fin, global_fout; void ast_cli(int fd, char *fmt, ...) { char *stuff; int res = 0; va_list ap; va_start(ap, fmt); #ifdef SOLARIS stuff = (char *)malloc(10240); vsnprintf(stuff, 10240, fmt, ap); #else res = vasprintf(&stuff, fmt, ap); #endif va_end(ap); if (res == -1) { ast_log(LOG_ERROR, "Out of memory\n"); } else { ast_carefulwrite(fd, stuff, strlen(stuff), 100); free(stuff); } } AST_MUTEX_DEFINE_STATIC(clilock); struct ast_cli_entry *helpers = NULL; static char load_help[] = "Usage: load \n" " Loads the specified module into Asterisk.\n"; static char unload_help[] = "Usage: 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" " module to be unloaded even if the module says it cannot, \n" " which almost always will cause a crash.\n"; static char help_help[] = "Usage: help [topic]\n" " When called with a topic as an argument, displays usage\n" " information on the given command. If called without a\n" " topic, it provides a list of commands.\n"; static char chanlist_help[] = "Usage: show channels [concise]\n" " Lists currently defined channels and some information about\n" " them. If 'concise' is specified, format is abridged and in\n" " a more easily machine parsable format\n"; static char reload_help[] = "Usage: 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" " 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" " 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"; static char softhangup_help[] = "Usage: soft hangup \n" " Request that a channel be hung up. The hangup takes effect\n" " the next time the driver reads or writes from the channel\n"; static int handle_load(int fd, int argc, char *argv[]) { if (argc != 2) return RESULT_SHOWUSAGE; if (ast_load_resource(argv[1])) { ast_cli(fd, "Unable to load module %s\n", argv[1]); return RESULT_FAILURE; } return RESULT_SUCCESS; } static int handle_reload(int fd, int argc, char *argv[]) { int x; int res; if (argc < 1) return RESULT_SHOWUSAGE; if (argc > 1) { for (x=1;x