Newer
Older
* Asterisk -- An open source telephony toolkit.
Kevin P. Fleming
committed
* Copyright (C) 1999 - 2006, Digium, Inc.
* Mark Spencer <markster@digium.com>
* 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.
*/
*
* \brief Standard Command Line Interface
*
* \author Mark Spencer <markster@digium.com>
*/
#include <unistd.h>
#include <stdlib.h>
#include <sys/signal.h>
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <ctype.h>
Russell Bryant
committed
#include <regex.h>
Kevin P. Fleming
committed
#include "asterisk/logger.h"
#include "asterisk/options.h"
#include "asterisk/cli.h"
#include "asterisk/linkedlists.h"
#define MOD_LOADER
Kevin P. Fleming
committed
#include "asterisk/module.h"
#include "asterisk/pbx.h"
#include "asterisk/channel.h"
#include "asterisk/utils.h"
Russell Bryant
committed
#include "asterisk/app.h"
Kevin P. Fleming
committed
#include "asterisk/lock.h"
Mark Spencer
committed
extern unsigned long global_fin, global_fout;
Russell Bryant
committed
int res;
res = vasprintf(&stuff, fmt, ap);
Russell Bryant
committed
ast_log(LOG_ERROR, "Memory allocation failure\n");
ast_carefulwrite(fd, stuff, strlen(stuff), 100);
free(stuff);
}
Kevin P. Fleming
committed
static AST_LIST_HEAD_STATIC(helpers, ast_cli_entry);
static char load_help[] =
"Usage: load <module name>\n"
" Loads the specified module into Asterisk.\n";
static char unload_help[] =
"Usage: unload [-f|-h] <module name>\n"
Mark Spencer
committed
" 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"
Mark Spencer
committed
" information on the given command. If called without a\n"
" topic, it provides a list of commands.\n";
static char chanlist_help[] =
Mark Spencer
committed
"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";
"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 <level>\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 <level>\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";
Joshua Colp
committed
static char logger_mute_help[] =
"Usage: logger mute\n"
" Disables logging output to the current console, making it possible to\n"
" gather information without being disturbed by scrolling lines.\n";
static char softhangup_help[] =
"Usage: soft hangup <channel>\n"
Mark Spencer
committed
" Request that a channel be hung up. The hangup takes effect\n"
" the next time the driver reads or writes from the channel\n";
Russell Bryant
committed
static char group_show_channels_help[] =
"Usage: group show 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[])
{
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[])
{
Mark Spencer
committed
int x;
Mark Spencer
committed
if (argc < 1)
Mark Spencer
committed
if (argc > 1) {
for (x=1;x<argc;x++) {
res = ast_module_reload(argv[x]);
switch(res) {
case 0:
ast_cli(fd, "No such module '%s'\n", argv[x]);
break;
case 1:
ast_cli(fd, "Module '%s' does not support reload\n", argv[x]);
break;
}
}
Mark Spencer
committed
} else
ast_module_reload(NULL);
return RESULT_SUCCESS;
}
static int handle_set_verbose(int fd, int argc, char *argv[])
{
int val = 0;
int oldval = option_verbose;
/* "set verbose [atleast] N" */
if (argc == 3)
option_verbose = atoi(argv[2]);
else if (argc == 4) {
if (strcasecmp(argv[2], "atleast"))
return RESULT_SHOWUSAGE;
val = atoi(argv[3]);
if (val > option_verbose)
option_verbose = val;
} else
return RESULT_SHOWUSAGE;
if (oldval != option_verbose && option_verbose > 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_set_debug(int fd, int argc, char *argv[])
{
int val = 0;
int oldval = option_debug;
/* "set debug [atleast] N" */
if (argc == 3)
option_debug = atoi(argv[2]);
else if (argc == 4) {
Loading
Loading full blame...