/* * Asterisk -- An open source telephony toolkit. * * Copyright (C) 1999 - 2005, Digium, Inc. * * Mark Spencer * * See http://www.asterisk.org for more information about * the Asterisk project. Please do not directly contact * any of the maintainers of this project for assistance; * the project provides a web site, mailing lists and IRC * channels for your use. * * This program is free software, distributed under the terms of * the GNU General Public License Version 2. See the LICENSE file * at the top of the source tree. */ /*! \file * * \brief Standard Command Line Interface * */ #include #include #include #include #include #include #include #include "asterisk.h" ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/logger.h" #include "asterisk/options.h" #include "asterisk/cli.h" #include "asterisk/module.h" #include "asterisk/pbx.h" #include "asterisk/channel.h" #include "asterisk/manager.h" #include "asterisk/utils.h" #include "asterisk/lock.h" /* For rl_filename_completion */ #include "editline/readline/readline.h" /* For module directory */ #include "asterisk/version.h" extern const char *ast_build_hostname; extern const char *ast_build_kernel; extern const char *ast_build_machine; extern const char *ast_build_os; extern const char *ast_build_date; extern const char *ast_build_user; 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); res = vasprintf(&stuff, fmt, ap); 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|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" " 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