/* * CallWeaver -- An open source telephony toolkit. * * Copyright (C) 1999 - 2005, Digium, Inc. * * Mark Spencer * * See http://www.callweaver.org for more information about * the CallWeaver 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 * */ #ifdef HAVE_CONFIG_H #include "confdefs.h" #endif #include #include #include #include #include #include #include #include "callweaver.h" CALLWEAVER_FILE_VERSION("$HeadURL$", "$Revision$") #include "callweaver/logger.h" #include "callweaver/options.h" #include "callweaver/cli.h" #include "callweaver/module.h" #include "callweaver/pbx.h" #include "callweaver/channel.h" #include "callweaver/manager.h" #include "callweaver/utils.h" #include "callweaver/lock.h" /* For rl_filename_completion */ #include extern unsigned long global_fin; extern unsigned long global_fout; void cw_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) { cw_log(LOG_ERROR, "Out of memory\n"); } else { cw_carefulwrite(fd, stuff, strlen(stuff), 100); free(stuff); } } CW_MUTEX_DEFINE_STATIC(clilock); struct cw_cli_entry *helpers = NULL; static char load_help[] = "Usage: load \n" " Loads the specified module into CallWeaver.\n"; static char unload_help[] = "Usage: unload [-f|-h] \n" " Unloads the specified module from CallWeaver. 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 (cw_load_resource(argv[1])) { cw_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