Reported by: eliel
Patches:
      res_features.c.patch uploaded by eliel (license 64)
      res_agi.c.patch uploaded by seanbright (license 71)
      res_musiconhold.c.patch uploaded by seanbright (license 71)
      pbx.c.patch uploaded by moy (license 222)
      logger.c.patch uploaded by moy (license 222)
      frame.c.patch uploaded by moy (license 222)
      manager.c.patch uploaded by moy (license 222)
      http.c.patch uploaded by moy (license 222)
      dnsmgr.c.patch uploaded by moy (license 222)
      res_realtime.c.patch uploaded by eliel (license 64)
      res_odbc.c.patch uploaded by seanbright (license 71)
      res_jabber.c.patch uploaded by eliel (license 64)
      chan_local.c.patch uploaded by eliel (license 64)
      chan_agent.c.patch uploaded by eliel (license 64)
      chan_alsa.c.patch uploaded by eliel (license 64)
      chan_features.c.patch uploaded by eliel (license 64)
      chan_sip.c.patch uploaded by eliel (license 64)
      RollUp.1.patch (includes all of the above patches) uploaded by seanbright (license 71)

Convert many CLI commands to the NEW_CLI format.


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@82930 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.6.0
Jason Parker 18 years ago
parent 0c8381a1f5
commit c7a9ec1691

@ -230,6 +230,7 @@ static int agent_indicate(struct ast_channel *ast, int condition, const void *da
static int agent_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
static struct ast_channel *agent_bridgedchannel(struct ast_channel *chan, struct ast_channel *bridge);
static void set_agentbycallerid(const char *callerid, const char *agent);
static char *complete_agent_logoff_cmd(const char *line, const char *word, int pos, int state);
/*! \brief Channel interface description for PBX integration */
static const struct ast_channel_tech agent_tech = {
@ -1496,22 +1497,34 @@ static int agent_logoff(const char *agent, int soft)
return ret;
}
static int agent_logoff_cmd(int fd, int argc, char **argv)
static char *agent_logoff_cmd(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
int ret;
char *agent;
if (argc < 3 || argc > 4)
return RESULT_SHOWUSAGE;
if (argc == 4 && strcasecmp(argv[3], "soft"))
return RESULT_SHOWUSAGE;
switch (cmd) {
case CLI_INIT:
e->command = "agent logoff";
e->usage =
"Usage: agent logoff <channel> [soft]\n"
" Sets an agent as no longer logged in.\n"
" If 'soft' is specified, do not hangup existing calls.\n";
return NULL;
case CLI_GENERATE:
return complete_agent_logoff_cmd(a->line, a->word, a->pos, a->n);
}
if (a->argc < 3 || a->argc > 4)
return CLI_SHOWUSAGE;
if (a->argc == 4 && strcasecmp(a->argv[3], "soft"))
return CLI_SHOWUSAGE;
agent = argv[2] + 6;
ret = agent_logoff(agent, argc == 4);
agent = a->argv[2] + 6;
ret = agent_logoff(agent, a->argc == 4);
if (ret == 0)
ast_cli(fd, "Logging out %s\n", agent);
ast_cli(a->fd, "Logging out %s\n", agent);
return RESULT_SUCCESS;
return CLI_SUCCESS;
}
/*!
@ -1565,7 +1578,7 @@ static char *complete_agent_logoff_cmd(const char *line, const char *word, int p
/*!
* Show agents in cli.
*/
static int agents_show(int fd, int argc, char **argv)
static char *agents_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct agent_pvt *p;
char username[AST_MAX_BUF];
@ -1575,16 +1588,29 @@ static int agents_show(int fd, int argc, char **argv)
int count_agents = 0; /*!< Number of agents configured */
int online_agents = 0; /*!< Number of online agents */
int offline_agents = 0; /*!< Number of offline agents */
if (argc != 2)
return RESULT_SHOWUSAGE;
switch (cmd) {
case CLI_INIT:
e->command = "agent show";
e->usage =
"Usage: agent show\n"
" Provides summary information on agents.\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
if (a->argc != 2)
return CLI_SHOWUSAGE;
AST_LIST_LOCK(&agents);
AST_LIST_TRAVERSE(&agents, p, list) {
ast_mutex_lock(&p->lock);
if (p->pending) {
if (p->group)
ast_cli(fd, "-- Pending call to group %d\n", powerof(p->group));
ast_cli(a->fd, "-- Pending call to group %d\n", powerof(p->group));
else
ast_cli(fd, "-- Pending call to agent %s\n", p->agent);
ast_cli(a->fd, "-- Pending call to agent %s\n", p->agent);
} else {
if (!ast_strlen_zero(p->name))
snprintf(username, sizeof(username), "(%s) ", p->name);
@ -1613,7 +1639,7 @@ static int agents_show(int fd, int argc, char **argv)
}
if (!ast_strlen_zero(p->moh))
snprintf(moh, sizeof(moh), " (musiconhold is '%s')", p->moh);
ast_cli(fd, "%-12.12s %s%s%s%s\n", p->agent,
ast_cli(a->fd, "%-12.12s %s%s%s%s\n", p->agent,
username, location, talkingto, moh);
count_agents++;
}
@ -1621,16 +1647,16 @@ static int agents_show(int fd, int argc, char **argv)
}
AST_LIST_UNLOCK(&agents);
if ( !count_agents )
ast_cli(fd, "No Agents are configured in %s\n",config);
ast_cli(a->fd, "No Agents are configured in %s\n",config);
else
ast_cli(fd, "%d agents configured [%d online , %d offline]\n",count_agents, online_agents, offline_agents);
ast_cli(fd, "\n");
ast_cli(a->fd, "%d agents configured [%d online , %d offline]\n",count_agents, online_agents, offline_agents);
ast_cli(a->fd, "\n");
return RESULT_SUCCESS;
return CLI_SUCCESS;
}
static int agents_show_online(int fd, int argc, char **argv)
static char *agents_show_online(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct agent_pvt *p;
char username[AST_MAX_BUF];
@ -1640,8 +1666,21 @@ static int agents_show_online(int fd, int argc, char **argv)
int count_agents = 0; /* Number of agents configured */
int online_agents = 0; /* Number of online agents */
int agent_status = 0; /* 0 means offline, 1 means online */
if (argc != 3)
return RESULT_SHOWUSAGE;
switch (cmd) {
case CLI_INIT:
e->command = "agent show online";
e->usage =
"Usage: agent show online\n"
" Provides a list of all online agents.\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
if (a->argc != 3)
return CLI_SHOWUSAGE;
AST_LIST_LOCK(&agents);
AST_LIST_TRAVERSE(&agents, p, list) {
agent_status = 0; /* reset it to offline */
@ -1669,46 +1708,28 @@ static int agents_show_online(int fd, int argc, char **argv)
if (!ast_strlen_zero(p->moh))
snprintf(moh, sizeof(moh), " (musiconhold is '%s')", p->moh);
if (agent_status)
ast_cli(fd, "%-12.12s %s%s%s%s\n", p->agent, username, location, talkingto, moh);
ast_cli(a->fd, "%-12.12s %s%s%s%s\n", p->agent, username, location, talkingto, moh);
count_agents++;
ast_mutex_unlock(&p->lock);
}
AST_LIST_UNLOCK(&agents);
if (!count_agents)
ast_cli(fd, "No Agents are configured in %s\n", config);
ast_cli(a->fd, "No Agents are configured in %s\n", config);
else
ast_cli(fd, "%d agents online\n", online_agents);
ast_cli(fd, "\n");
return RESULT_SUCCESS;
ast_cli(a->fd, "%d agents online\n", online_agents);
ast_cli(a->fd, "\n");
return CLI_SUCCESS;
}
static const char show_agents_usage[] =
"Usage: agent show\n"
" Provides summary information on agents.\n";
static const char show_agents_online_usage[] =
"Usage: agent show online\n"
" Provides a list of all online agents.\n";
static const char agent_logoff_usage[] =
"Usage: agent logoff <channel> [soft]\n"
" Sets an agent as no longer logged in.\n"
" If 'soft' is specified, do not hangup existing calls.\n";
static struct ast_cli_entry cli_agents[] = {
{ { "agent", "show", NULL },
agents_show, "Show status of agents",
show_agents_usage },
{ { "agent", "show", "online" },
agents_show_online, "Show all online agents",
show_agents_online_usage },
{ { "agent", "logoff", NULL },
agent_logoff_cmd, "Sets an agent offline",
agent_logoff_usage, complete_agent_logoff_cmd },
NEW_CLI(agents_show, "Show status of agents"),
NEW_CLI(agents_show_online, "Show all online agents"),
NEW_CLI(agent_logoff_cmd, "Sets an agent offline"),
};
/*!

@ -838,26 +838,6 @@ static struct ast_channel *alsa_request(const char *type, int format, void *data
return tmp;
}
static int console_autoanswer(int fd, int argc, char *argv[])
{
int res = RESULT_SUCCESS;;
if ((argc != 2) && (argc != 3))
return RESULT_SHOWUSAGE;
ast_mutex_lock(&alsalock);
if (argc == 2) {
ast_cli(fd, "Auto answer is %s.\n", autoanswer ? "on" : "off");
} else {
if (!strcasecmp(argv[2], "on"))
autoanswer = -1;
else if (!strcasecmp(argv[2], "off"))
autoanswer = 0;
else
res = RESULT_SHOWUSAGE;
}
ast_mutex_unlock(&alsalock);
return res;
}
static char *autoanswer_complete(const char *line, const char *word, int pos, int state)
{
#ifndef MIN
@ -876,24 +856,65 @@ static char *autoanswer_complete(const char *line, const char *word, int pos, in
return NULL;
}
static const char autoanswer_usage[] =
"Usage: console autoanswer [on|off]\n"
" Enables or disables autoanswer feature. If used without\n"
" argument, displays the current on/off status of autoanswer.\n"
" The default value of autoanswer is in 'alsa.conf'.\n";
static char *console_autoanswer(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
char *res = CLI_SUCCESS;
switch (cmd) {
case CLI_INIT:
e->command = "console autoanswer";
e->usage =
"Usage: console autoanswer [on|off]\n"
" Enables or disables autoanswer feature. If used without\n"
" argument, displays the current on/off status of autoanswer.\n"
" The default value of autoanswer is in 'alsa.conf'.\n";
return NULL;
case CLI_GENERATE:
return autoanswer_complete(a->line, a->word, a->pos, a->n);
}
if ((a->argc != 2) && (a->argc != 3))
return CLI_SHOWUSAGE;
ast_mutex_lock(&alsalock);
if (a->argc == 2) {
ast_cli(a->fd, "Auto answer is %s.\n", autoanswer ? "on" : "off");
} else {
if (!strcasecmp(a->argv[2], "on"))
autoanswer = -1;
else if (!strcasecmp(a->argv[2], "off"))
autoanswer = 0;
else
res = CLI_SHOWUSAGE;
}
ast_mutex_unlock(&alsalock);
return res;
}
static int console_answer(int fd, int argc, char *argv[])
static char *console_answer(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
int res = RESULT_SUCCESS;
char *res = CLI_SUCCESS;
switch (cmd) {
case CLI_INIT:
e->command = "console answer";
e->usage =
"Usage: console answer\n"
" Answers an incoming call on the console (ALSA) channel.\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
if (argc != 2)
return RESULT_SHOWUSAGE;
if (a->argc != 2)
return CLI_SHOWUSAGE;
ast_mutex_lock(&alsalock);
if (!alsa.owner) {
ast_cli(fd, "No one is calling us\n");
res = RESULT_FAILURE;
ast_cli(a->fd, "No one is calling us\n");
res = CLI_FAILURE;
} else {
hookstate = 1;
cursound = -1;
@ -911,32 +932,39 @@ static int console_answer(int fd, int argc, char *argv[])
ast_mutex_unlock(&alsalock);
return RESULT_SUCCESS;
return res;
}
static const char sendtext_usage[] =
"Usage: console send text <message>\n"
" Sends a text message for display on the remote terminal.\n";
static int console_sendtext(int fd, int argc, char *argv[])
static char *console_sendtext(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
int tmparg = 3;
int res = RESULT_SUCCESS;
char *res = CLI_SUCCESS;
switch (cmd) {
case CLI_INIT:
e->command = "console send text";
e->usage =
"Usage: console send text <message>\n"
" Sends a text message for display on the remote terminal.\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
if (argc < 3)
return RESULT_SHOWUSAGE;
if (a->argc < 3)
return CLI_SHOWUSAGE;
ast_mutex_lock(&alsalock);
if (!alsa.owner) {
ast_cli(fd, "No one is calling us\n");
res = RESULT_FAILURE;
ast_cli(a->fd, "No one is calling us\n");
res = CLI_FAILURE;
} else {
struct ast_frame f = { AST_FRAME_TEXT, 0 };
char text2send[256] = "";
text2send[0] = '\0';
while (tmparg < argc) {
strncat(text2send, argv[tmparg++], sizeof(text2send) - strlen(text2send) - 1);
while (tmparg < a->argc) {
strncat(text2send, a->argv[tmparg++], sizeof(text2send) - strlen(text2send) - 1);
strncat(text2send, " ", sizeof(text2send) - strlen(text2send) - 1);
}
text2send[strlen(text2send) - 1] = '\n';
@ -959,24 +987,32 @@ static int console_sendtext(int fd, int argc, char *argv[])
return res;
}
static const char answer_usage[] =
"Usage: console answer\n"
" Answers an incoming call on the console (ALSA) channel.\n";
static int console_hangup(int fd, int argc, char *argv[])
static char *console_hangup(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
int res = RESULT_SUCCESS;
char *res = CLI_SUCCESS;
switch (cmd) {
case CLI_INIT:
e->command = "console hangup";
e->usage =
"Usage: console hangup\n"
" Hangs up any call currently placed on the console.\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
if (argc != 2)
return RESULT_SHOWUSAGE;
if (a->argc != 2)
return CLI_SHOWUSAGE;
cursound = -1;
ast_mutex_lock(&alsalock);
if (!alsa.owner && !hookstate) {
ast_cli(fd, "No call to hangup up\n");
res = RESULT_FAILURE;
ast_cli(a->fd, "No call to hangup up\n");
res = CLI_FAILURE;
} else {
hookstate = 0;
grab_owner();
@ -991,25 +1027,32 @@ static int console_hangup(int fd, int argc, char *argv[])
return res;
}
static const char hangup_usage[] =
"Usage: console hangup\n"
" Hangs up any call currently placed on the console.\n";
static int console_dial(int fd, int argc, char *argv[])
static char *console_dial(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
char tmp[256], *tmp2;
char *mye, *myc;
char *d;
int res = RESULT_SUCCESS;
char *res = CLI_SUCCESS;
switch (cmd) {
case CLI_INIT:
e->command = "console dial";
e->usage =
"Usage: console dial [extension[@context]]\n"
" Dials a given extension (and context if specified)\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
if ((argc != 2) && (argc != 3))
return RESULT_SHOWUSAGE;
if ((a->argc != 2) && (a->argc != 3))
return CLI_SHOWUSAGE;
ast_mutex_lock(&alsalock);
if (alsa.owner) {
if (argc == 3) {
d = argv[2];
if (a->argc == 3) {
d = a->argv[2];
if (alsa.owner) {
struct ast_frame f = { AST_FRAME_DTMF };
while (*d) {
@ -1019,15 +1062,15 @@ static int console_dial(int fd, int argc, char *argv[])
}
}
} else {
ast_cli(fd, "You're already in a call. You can use this only to dial digits until you hangup\n");
res = RESULT_FAILURE;
ast_cli(a->fd, "You're already in a call. You can use this only to dial digits until you hangup\n");
res = CLI_FAILURE;
}
} else {
mye = exten;
myc = context;
if (argc == 3) {
if (a->argc == 3) {
char *stringp = NULL;
ast_copy_string(tmp, argv[2], sizeof(tmp));
ast_copy_string(tmp, a->argv[2], sizeof(tmp));
stringp = tmp;
strsep(&stringp, "@");
tmp2 = strsep(&stringp, "@");
@ -1042,7 +1085,7 @@ static int console_dial(int fd, int argc, char *argv[])
hookstate = 1;
alsa_new(&alsa, AST_STATE_RINGING);
} else
ast_cli(fd, "No such extension '%s' in context '%s'\n", mye, myc);
ast_cli(a->fd, "No such extension '%s' in context '%s'\n", mye, myc);
}
ast_mutex_unlock(&alsalock);
@ -1050,30 +1093,12 @@ static int console_dial(int fd, int argc, char *argv[])
return res;
}
static const char dial_usage[] =
"Usage: console dial [extension[@context]]\n"
" Dials a given extension (and context if specified)\n";
static struct ast_cli_entry cli_alsa[] = {
{ { "console", "answer", NULL },
console_answer, "Answer an incoming console call",
answer_usage },
{ { "console", "hangup", NULL },
console_hangup, "Hangup a call on the console",
hangup_usage },
{ { "console", "dial", NULL },
console_dial, "Dial an extension on the console",
dial_usage },
{ { "console", "send", "text", NULL },
console_sendtext, "Send text to the remote device",
sendtext_usage },
{ { "console", "autoanswer", NULL },
console_autoanswer, "Sets/displays autoanswer",
autoanswer_usage, autoanswer_complete },
NEW_CLI(console_answer, "Answer an incoming console call"),
NEW_CLI(console_hangup, "Hangup a call on the console"),
NEW_CLI(console_dial, "Dial an extension on the console"),
NEW_CLI(console_sendtext, "Send text to the remote device"),
NEW_CLI(console_autoanswer, "Sets/displays autoanswer"),
};
static int load_module(void)

@ -509,36 +509,41 @@ static struct ast_channel *features_request(const char *type, int format, void *
return chan;
}
static int features_show(int fd, int argc, char **argv)
static char *features_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct feature_pvt *p;
if (argc != 3)
return RESULT_SHOWUSAGE;
switch (cmd) {
case CLI_INIT:
e->command = "feature show channels";
e->usage =
"Usage: feature show channels\n"
" Provides summary information on feature channels.\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
if (a->argc != 3)
return CLI_SHOWUSAGE;
if (AST_LIST_EMPTY(&features)) {
ast_cli(fd, "No feature channels in use\n");
return RESULT_SUCCESS;
ast_cli(a->fd, "No feature channels in use\n");
return CLI_SUCCESS;
}
AST_LIST_LOCK(&features);
AST_LIST_TRAVERSE(&features, p, list) {
ast_mutex_lock(&p->lock);
ast_cli(fd, "%s -- %s/%s\n", p->owner ? p->owner->name : "<unowned>", p->tech, p->dest);
ast_cli(a->fd, "%s -- %s/%s\n", p->owner ? p->owner->name : "<unowned>", p->tech, p->dest);
ast_mutex_unlock(&p->lock);
}
AST_LIST_UNLOCK(&features);
return RESULT_SUCCESS;
return CLI_SUCCESS;
}
static const char show_features_usage[] =
"Usage: feature show channels\n"
" Provides summary information on feature channels.\n";
static struct ast_cli_entry cli_features[] = {
{ { "feature", "show", "channels", NULL },
features_show, "List status of feature channels",
show_features_usage },
NEW_CLI(features_show, "List status of feature channels"),
};
static int load_module(void)

@ -670,35 +670,40 @@ static struct ast_channel *local_request(const char *type, int format, void *dat
}
/*! \brief CLI command "local show channels" */
static int locals_show(int fd, int argc, char **argv)
static char *locals_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct local_pvt *p = NULL;
if (argc != 3)
return RESULT_SHOWUSAGE;
switch (cmd) {
case CLI_INIT:
e->command = "local show channels";
e->usage =
"Usage: local show channels\n"
" Provides summary information on active local proxy channels.\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
if (a->argc != 3)
return CLI_SHOWUSAGE;
AST_LIST_LOCK(&locals);
if (!AST_LIST_EMPTY(&locals)) {
AST_LIST_TRAVERSE(&locals, p, list) {
ast_mutex_lock(&p->lock);
ast_cli(fd, "%s -- %s@%s\n", p->owner ? p->owner->name : "<unowned>", p->exten, p->context);
ast_cli(a->fd, "%s -- %s@%s\n", p->owner ? p->owner->name : "<unowned>", p->exten, p->context);
ast_mutex_unlock(&p->lock);
}
} else
ast_cli(fd, "No local channels in use\n");
ast_cli(a->fd, "No local channels in use\n");
AST_LIST_UNLOCK(&locals);
return RESULT_SUCCESS;
return CLI_SUCCESS;
}
static const char show_locals_usage[] =
"Usage: local show channels\n"
" Provides summary information on active local proxy channels.\n";
static struct ast_cli_entry cli_local[] = {
{ { "local", "show", "channels", NULL },
locals_show, "List status of local channels",
show_locals_usage },
NEW_CLI(locals_show, "List status of local channels"),
};
/*! \brief Load module into PBX, register channel */

File diff suppressed because it is too large Load Diff

@ -255,28 +255,48 @@ void dnsmgr_start_refresh(void)
static int do_reload(int loading);
static int handle_cli_reload(int fd, int argc, char *argv[])
static char *handle_cli_reload(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 = "dnsmgr reload";
e->usage =
"Usage: dnsmgr reload\n"
" Reloads the DNS manager configuration.\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
if (a->argc > 2)
return CLI_SHOWUSAGE;
do_reload(0);
return 0;
return CLI_SUCCESS;
}
static int handle_cli_refresh(int fd, int argc, char *argv[])
static char *handle_cli_refresh(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct refresh_info info = {
.entries = &entry_list,
.verbose = 1,
};
switch (cmd) {
case CLI_INIT:
e->command = "dnsmgr refresh";
e->usage =
"Usage: dnsmgr refresh [pattern]\n"
" Peforms an immediate refresh of the managed DNS entries.\n"
" Optional regular expression pattern is used to filter the entries to refresh.\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
if (a->argc > 3)
return CLI_SHOWUSAGE;
if (argc > 3)
return RESULT_SHOWUSAGE;
if (argc == 3) {
if (regcomp(&info.filter, argv[2], REG_EXTENDED | REG_NOSUB))
return RESULT_SHOWUSAGE;
if (a->argc == 3) {
if ( regcomp(&info.filter, a->argv[2], REG_EXTENDED | REG_NOSUB) )
return CLI_SHOWUSAGE;
else
info.regex_present = 1;
}
@ -286,49 +306,41 @@ static int handle_cli_refresh(int fd, int argc, char *argv[])
if (info.regex_present)
regfree(&info.filter);
return 0;
return CLI_SUCCESS;
}
static int handle_cli_status(int fd, int argc, char *argv[])
static char *handle_cli_status(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
int count = 0;
struct ast_dnsmgr_entry *entry;
switch (cmd) {
case CLI_INIT:
e->command = "dnsmgr status";
e->usage =
"Usage: dnsmgr status\n"
" Displays the DNS manager status.\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
if (argc > 2)
return RESULT_SHOWUSAGE;
if (a->argc > 2)
return CLI_SHOWUSAGE;
ast_cli(fd, "DNS Manager: %s\n", enabled ? "enabled" : "disabled");
ast_cli(fd, "Refresh Interval: %d seconds\n", refresh_interval);
ast_cli(a->fd, "DNS Manager: %s\n", enabled ? "enabled" : "disabled");
ast_cli(a->fd, "Refresh Interval: %d seconds\n", refresh_interval);
AST_RWLIST_RDLOCK(&entry_list);
AST_RWLIST_TRAVERSE(&entry_list, entry, list)
count++;
AST_RWLIST_UNLOCK(&entry_list);
ast_cli(fd, "Number of entries: %d\n", count);
ast_cli(a->fd, "Number of entries: %d\n", count);
return 0;
return CLI_SUCCESS;
}
static struct ast_cli_entry cli_reload = {
{ "dnsmgr", "reload", NULL },
handle_cli_reload, "Reloads the DNS manager configuration",
"Usage: dnsmgr reload\n"
" Reloads the DNS manager configuration.\n"
};
static struct ast_cli_entry cli_refresh = {
{ "dnsmgr", "refresh", NULL },
handle_cli_refresh, "Performs an immediate refresh",
"Usage: dnsmgr refresh [pattern]\n"
" Peforms an immediate refresh of the managed DNS entries.\n"
" Optional regular expression pattern is used to filter the entries to refresh.\n",
};
static struct ast_cli_entry cli_status = {
{ "dnsmgr", "status", NULL },
handle_cli_status, "Display the DNS manager status",
"Usage: dnsmgr status\n"
" Displays the DNS manager status.\n"
};
static struct ast_cli_entry cli_reload = NEW_CLI(handle_cli_reload, "Reloads the DNS manager configuration");
static struct ast_cli_entry cli_refresh = NEW_CLI(handle_cli_refresh, "Performs an immediate refresh");
static struct ast_cli_entry cli_status = NEW_CLI(handle_cli_status, "Display the DNS manager status");
int dnsmgr_init(void)
{
@ -338,6 +350,7 @@ int dnsmgr_init(void)
}
ast_cli_register(&cli_reload);
ast_cli_register(&cli_status);
ast_cli_register(&cli_refresh);
return do_reload(1);
}

@ -611,80 +611,94 @@ char *ast_codec2str(int codec)
return ret;
}
static int show_codecs(int fd, int argc, char *argv[])
static char *show_codecs(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
int i, found=0;
char hex[25];
switch (cmd) {
case CLI_INIT:
e->command = "core show codecs [audio|video|image]";
e->usage =
"Usage: core show codecs [audio|video|image]\n"
" Displays codec mapping\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
if ((argc < 3) || (argc > 4))
return RESULT_SHOWUSAGE;
if ((a->argc < 3) || (a->argc > 4))
return CLI_SHOWUSAGE;
if (!ast_opt_dont_warn)
ast_cli(fd, "Disclaimer: this command is for informational purposes only.\n"
ast_cli(a->fd, "Disclaimer: this command is for informational purposes only.\n"
"\tIt does not indicate anything about your configuration.\n");
ast_cli(fd, "%11s %9s %10s TYPE %8s %s\n","INT","BINARY","HEX","NAME","DESC");
ast_cli(fd, "--------------------------------------------------------------------------------\n");
if ((argc == 3) || (!strcasecmp(argv[3],"audio"))) {
ast_cli(a->fd, "%11s %9s %10s TYPE %8s %s\n","INT","BINARY","HEX","NAME","DESC");
ast_cli(a->fd, "--------------------------------------------------------------------------------\n");
if ((a->argc == 3) || (!strcasecmp(a->argv[3],"audio"))) {
found = 1;
for (i=0;i<13;i++) {
snprintf(hex,25,"(0x%x)",1<<i);
ast_cli(fd, "%11u (1 << %2d) %10s audio %8s (%s)\n",1 << i,i,hex,ast_getformatname(1<<i),ast_codec2str(1<<i));
ast_cli(a->fd, "%11u (1 << %2d) %10s audio %8s (%s)\n",1 << i,i,hex,ast_getformatname(1<<i),ast_codec2str(1<<i));
}
}
if ((argc == 3) || (!strcasecmp(argv[3],"image"))) {
if ((a->argc == 3) || (!strcasecmp(a->argv[3],"image"))) {
found = 1;
for (i=16;i<18;i++) {
snprintf(hex,25,"(0x%x)",1<<i);
ast_cli(fd, "%11u (1 << %2d) %10s image %8s (%s)\n",1 << i,i,hex,ast_getformatname(1<<i),ast_codec2str(1<<i));
ast_cli(a->fd, "%11u (1 << %2d) %10s image %8s (%s)\n",1 << i,i,hex,ast_getformatname(1<<i),ast_codec2str(1<<i));
}
}
if ((argc == 3) || (!strcasecmp(argv[3],"video"))) {
if ((a->argc == 3) || (!strcasecmp(a->argv[3],"video"))) {
found = 1;
for (i=18;i<22;i++) {
snprintf(hex,25,"(0x%x)",1<<i);
ast_cli(fd, "%11u (1 << %2d) %10s video %8s (%s)\n",1 << i,i,hex,ast_getformatname(1<<i),ast_codec2str(1<<i));
ast_cli(a->fd, "%11u (1 << %2d) %10s video %8s (%s)\n",1 << i,i,hex,ast_getformatname(1<<i),ast_codec2str(1<<i));
}
}
if (! found)
return RESULT_SHOWUSAGE;
if (!found)
return CLI_SHOWUSAGE;
else
return RESULT_SUCCESS;
return CLI_SUCCESS;
}
static const char frame_show_codecs_usage[] =
"Usage: core show codecs [audio|video|image]\n"
" Displays codec mapping\n";
static int show_codec_n(int fd, int argc, char *argv[])
static char *show_codec_n(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
int codec, i, found=0;
if (argc != 4)
return RESULT_SHOWUSAGE;
switch (cmd) {
case CLI_INIT:
e->command = "core show codec";
e->usage =
"Usage: core show codec <number>\n"
" Displays codec mapping\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
if (sscanf(argv[3],"%d",&codec) != 1)
return RESULT_SHOWUSAGE;
if (a->argc != 4)
return CLI_SHOWUSAGE;
if (sscanf(a->argv[3],"%d",&codec) != 1)
return CLI_SHOWUSAGE;
for (i = 0; i < 32; i++)
if (codec & (1 << i)) {
found = 1;
ast_cli(fd, "%11u (1 << %2d) %s\n",1 << i,i,ast_codec2str(1<<i));
ast_cli(a->fd, "%11u (1 << %2d) %s\n",1 << i,i,ast_codec2str(1<<i));
}
if (!found)
ast_cli(fd, "Codec %d not found\n", codec);
ast_cli(a->fd, "Codec %d not found\n", codec);
return RESULT_SUCCESS;
return CLI_SUCCESS;
}
static char frame_show_codec_n_usage[] =
"Usage: core show codec <number>\n"
" Displays codec mapping\n";
/*! Dump a frame for debugging purposes */
void ast_frame_dump(const char *name, struct ast_frame *f, char *prefix)
{
@ -867,54 +881,42 @@ void ast_frame_dump(const char *name, struct ast_frame *f, char *prefix)
#ifdef TRACE_FRAMES
static int show_frame_stats(int fd, int argc, char *argv[])
static char *show_frame_stats(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct ast_frame *f;
int x=1;
if (argc != 4)
return RESULT_SHOWUSAGE;
switch (cmd) {
case CLI_INIT:
e->command = "core show frame stats";
e->usage =
"Usage: core show frame stats\n"
" Displays debugging statistics from framer\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
if (a->argc != 4)
return CLI_SHOWUSAGE;
AST_LIST_LOCK(&headerlist);
ast_cli(fd, " Framer Statistics \n");
ast_cli(fd, "---------------------------\n");
ast_cli(fd, "Total allocated headers: %d\n", headers);
ast_cli(fd, "Queue Dump:\n");
ast_cli(a->fd, " Framer Statistics \n");
ast_cli(a->fd, "---------------------------\n");
ast_cli(a->fd, "Total allocated headers: %d\n", headers);
ast_cli(a->fd, "Queue Dump:\n");
AST_LIST_TRAVERSE(&headerlist, f, frame_list)
ast_cli(fd, "%d. Type %d, subclass %d from %s\n", x++, f->frametype, f->subclass, f->src ? f->src : "<Unknown>");
ast_cli(a->fd, "%d. Type %d, subclass %d from %s\n", x++, f->frametype, f->subclass, f->src ? f->src : "<Unknown>");
AST_LIST_UNLOCK(&headerlist);
return RESULT_SUCCESS;
return CLI_SUCCESS;
}
static const char frame_stats_usage[] =
"Usage: core show frame stats\n"
" Displays debugging statistics from framer\n";
#endif
/* Builtin Asterisk CLI-commands for debugging */
static struct ast_cli_entry my_clis[] = {
{ { "core", "show", "codecs", NULL },
show_codecs, "Displays a list of codecs",
frame_show_codecs_usage },
{ { "core", "show", "codecs", "audio", NULL },
show_codecs, "Displays a list of audio codecs",
frame_show_codecs_usage },
{ { "core", "show", "codecs", "video", NULL },
show_codecs, "Displays a list of video codecs",
frame_show_codecs_usage },
{ { "core", "show", "codecs", "image", NULL },
show_codecs, "Displays a list of image codecs",
frame_show_codecs_usage },
{ { "core", "show", "codec", NULL },
show_codec_n, "Shows a specific codec",
frame_show_codec_n_usage },
NEW_CLI(show_codecs, "Displays a list of codecs"),
NEW_CLI(show_codec_n, "Shows a specific codec"),
#ifdef TRACE_FRAMES
{ { "core", "show", "frame", "stats", NULL },
show_frame_stats, "Shows frame statistics",
frame_stats_usage },
NEW_CLI(show_frame_stats, "Shows frame statistics"),
#endif
};

@ -1232,56 +1232,65 @@ static int __ast_http_load(int reload)
return 0;
}
static int handle_show_http(int fd, int argc, char *argv[])
static char *handle_show_http(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct ast_http_uri *urih;
struct http_uri_redirect *redirect;
struct ast_http_post_mapping *post_map;
if (argc != 3)
return RESULT_SHOWUSAGE;
ast_cli(fd, "HTTP Server Status:\n");
ast_cli(fd, "Prefix: %s\n", prefix);
switch (cmd) {
case CLI_INIT:
e->command = "http show status";
e->usage =
"Usage: http show status\n"
" Lists status of internal HTTP engine\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
if (a->argc != 3)
return CLI_SHOWUSAGE;
ast_cli(a->fd, "HTTP Server Status:\n");
ast_cli(a->fd, "Prefix: %s\n", prefix);
if (!http_desc.oldsin.sin_family)
ast_cli(fd, "Server Disabled\n\n");
ast_cli(a->fd, "Server Disabled\n\n");
else {
ast_cli(fd, "Server Enabled and Bound to %s:%d\n\n",
ast_cli(a->fd, "Server Enabled and Bound to %s:%d\n\n",
ast_inet_ntoa(http_desc.oldsin.sin_addr),
ntohs(http_desc.oldsin.sin_port));
if (http_tls_cfg.enabled)
ast_cli(fd, "HTTPS Server Enabled and Bound to %s:%d\n\n",
ast_cli(a->fd, "HTTPS Server Enabled and Bound to %s:%d\n\n",
ast_inet_ntoa(https_desc.oldsin.sin_addr),
ntohs(https_desc.oldsin.sin_port));
}
ast_cli(fd, "Enabled URI's:\n");
ast_cli(a->fd, "Enabled URI's:\n");
AST_RWLIST_RDLOCK(&uris);
if (AST_RWLIST_EMPTY(&uris)) {
ast_cli(fd, "None.\n");
ast_cli(a->fd, "None.\n");
} else {
AST_RWLIST_TRAVERSE(&uris, urih, entry)
ast_cli(fd, "%s/%s%s => %s\n", prefix, urih->uri, (urih->has_subtree ? "/..." : "" ), urih->description);
ast_cli(a->fd, "%s/%s%s => %s\n", prefix, urih->uri, (urih->has_subtree ? "/..." : "" ), urih->description);
}
AST_RWLIST_UNLOCK(&uris);
ast_cli(fd, "\nEnabled Redirects:\n");
ast_cli(a->fd, "\nEnabled Redirects:\n");
AST_RWLIST_RDLOCK(&uri_redirects);
AST_RWLIST_TRAVERSE(&uri_redirects, redirect, entry)
ast_cli(fd, " %s => %s\n", redirect->target, redirect->dest);
ast_cli(a->fd, " %s => %s\n", redirect->target, redirect->dest);
if (AST_RWLIST_EMPTY(&uri_redirects))
ast_cli(fd, " None.\n");
ast_cli(a->fd, " None.\n");
AST_RWLIST_UNLOCK(&uri_redirects);
ast_cli(fd, "\nPOST mappings:\n");
ast_cli(a->fd, "\nPOST mappings:\n");
AST_RWLIST_RDLOCK(&post_mappings);
AST_LIST_TRAVERSE(&post_mappings, post_map, entry)
ast_cli(fd, "%s/%s => %s\n", prefix, post_map->from, post_map->to);
ast_cli(fd, "%s\n", AST_LIST_EMPTY(&post_mappings) ? "None.\n" : "");
ast_cli(a->fd, "%s/%s => %s\n", prefix, post_map->from, post_map->to);
ast_cli(a->fd, "%s\n", AST_LIST_EMPTY(&post_mappings) ? "None.\n" : "");
AST_RWLIST_UNLOCK(&post_mappings);
return RESULT_SUCCESS;
return CLI_SUCCESS;
}
int ast_http_reload(void)
@ -1289,14 +1298,8 @@ int ast_http_reload(void)
return __ast_http_load(1);
}
static char show_http_help[] =
"Usage: http show status\n"
" Lists status of internal HTTP engine\n";
static struct ast_cli_entry cli_http[] = {
{ { "http", "show", "status", NULL },
handle_show_http, "Display HTTP server status",
show_http_help },
NEW_CLI(handle_show_http, "Display HTTP server status"),
};
int ast_http_init(void)

@ -616,59 +616,88 @@ int reload_logger(int rotate)
return res;
}
static int handle_logger_reload(int fd, int argc, char *argv[])
static char *handle_logger_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
switch (cmd) {
case CLI_INIT:
e->command = "logger reload";
e->usage =
"Usage: logger reload\n"
" Reloads the logger subsystem state. Use after restarting syslogd(8) if you are using syslog logging.\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
if (reload_logger(0)) {
ast_cli(fd, "Failed to reload the logger\n");
return RESULT_FAILURE;
ast_cli(a->fd, "Failed to reload the logger\n");
return CLI_FAILURE;
} else
return RESULT_SUCCESS;
return CLI_SUCCESS;
}
static int handle_logger_rotate(int fd, int argc, char *argv[])
static char *handle_logger_rotate(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
switch (cmd) {
case CLI_INIT:
e->command = "logger rotate";
e->usage =
"Usage: logger rotate\n"
" Rotates and Reopens the log files.\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
if (reload_logger(1)) {
ast_cli(fd, "Failed to reload the logger and rotate log files\n");
return RESULT_FAILURE;
ast_cli(a->fd, "Failed to reload the logger and rotate log files\n");
return CLI_FAILURE;
} else
return RESULT_SUCCESS;
return CLI_SUCCESS;
}
/*! \brief CLI command to show logging system configuration */
static int handle_logger_show_channels(int fd, int argc, char *argv[])
static char *handle_logger_show_channels(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
#define FORMATL "%-35.35s %-8.8s %-9.9s "
struct logchannel *chan;
ast_cli(fd,FORMATL, "Channel", "Type", "Status");
ast_cli(fd, "Configuration\n");
ast_cli(fd,FORMATL, "-------", "----", "------");
ast_cli(fd, "-------------\n");
switch (cmd) {
case CLI_INIT:
e->command = "logger show channels";
e->usage =
"Usage: logger show channels\n"
" List configured logger channels.\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
ast_cli(a->fd,FORMATL, "Channel", "Type", "Status");
ast_cli(a->fd, "Configuration\n");
ast_cli(a->fd,FORMATL, "-------", "----", "------");
ast_cli(a->fd, "-------------\n");
AST_RWLIST_RDLOCK(&logchannels);
AST_RWLIST_TRAVERSE(&logchannels, chan, list) {
ast_cli(fd, FORMATL, chan->filename, chan->type==LOGTYPE_CONSOLE ? "Console" : (chan->type==LOGTYPE_SYSLOG ? "Syslog" : "File"),
ast_cli(a->fd, FORMATL, chan->filename, chan->type==LOGTYPE_CONSOLE ? "Console" : (chan->type==LOGTYPE_SYSLOG ? "Syslog" : "File"),
chan->disabled ? "Disabled" : "Enabled");
ast_cli(fd, " - ");
ast_cli(a->fd, " - ");
if (chan->logmask & (1 << __LOG_DEBUG))
ast_cli(fd, "Debug ");
ast_cli(a->fd, "Debug ");
if (chan->logmask & (1 << __LOG_DTMF))
ast_cli(fd, "DTMF ");
ast_cli(a->fd, "DTMF ");
if (chan->logmask & (1 << __LOG_VERBOSE))
ast_cli(fd, "Verbose ");
ast_cli(a->fd, "Verbose ");
if (chan->logmask & (1 << __LOG_WARNING))
ast_cli(fd, "Warning ");
ast_cli(a->fd, "Warning ");
if (chan->logmask & (1 << __LOG_NOTICE))
ast_cli(fd, "Notice ");
ast_cli(a->fd, "Notice ");
if (chan->logmask & (1 << __LOG_ERROR))
ast_cli(fd, "Error ");
ast_cli(a->fd, "Error ");
if (chan->logmask & (1 << __LOG_EVENT))
ast_cli(fd, "Event ");
ast_cli(fd, "\n");
ast_cli(a->fd, "Event ");
ast_cli(a->fd, "\n");
}
AST_RWLIST_UNLOCK(&logchannels);
ast_cli(fd, "\n");
ast_cli(a->fd, "\n");
return RESULT_SUCCESS;
return CLI_SUCCESS;
}
struct verb {
@ -678,30 +707,10 @@ struct verb {
static AST_RWLIST_HEAD_STATIC(verbosers, verb);
static char logger_reload_help[] =
"Usage: logger reload\n"
" Reloads the logger subsystem state. Use after restarting syslogd(8) if you are using syslog logging.\n";
static char logger_rotate_help[] =
"Usage: logger rotate\n"
" Rotates and Reopens the log files.\n";
static char logger_show_channels_help[] =
"Usage: logger show channels\n"
" List configured logger channels.\n";
static struct ast_cli_entry cli_logger[] = {
{ { "logger", "show", "channels", NULL },
handle_logger_show_channels, "List configured log channels",
logger_show_channels_help },
{ { "logger", "reload", NULL },
handle_logger_reload, "Reopens the log files",
logger_reload_help },
{ { "logger", "rotate", NULL },
handle_logger_rotate, "Rotates and reopens the log files",
logger_rotate_help },
NEW_CLI(handle_logger_show_channels, "List configured log channels"),
NEW_CLI(handle_logger_reload, "Reopens the log files"),
NEW_CLI(handle_logger_rotate, "Rotates and reopens the log files")
};
static int handle_SIGXFSZ(int sig)

@ -406,45 +406,6 @@ static int strings_to_mask(const char *string)
return get_perm(string);
}
static char *complete_show_mancmd(const char *line, const char *word, int pos, int state)
{
struct manager_action *cur;
int l = strlen(word), which = 0;
char *ret = NULL;
AST_RWLIST_RDLOCK(&actions);
AST_RWLIST_TRAVERSE(&actions, cur, list) {
if (!strncasecmp(word, cur->action, l) && ++which > state) {
ret = ast_strdup(cur->action);
break; /* make sure we exit even if ast_strdup() returns NULL */
}
}
AST_RWLIST_UNLOCK(&actions);
return ret;
}
static char *complete_show_manuser(const char *line, const char *word, int pos, int state)
{
struct ast_manager_user *user = NULL;
int l = strlen(word), which = 0;
char *ret = NULL;
if (pos != 3)
return NULL;
AST_RWLIST_RDLOCK(&users);
AST_RWLIST_TRAVERSE(&users, user, list) {
if (!strncasecmp(word, user->username, l) && ++which > state) {
ret = ast_strdup(user->username);
break;
}
}
AST_RWLIST_UNLOCK(&users);
return ret;
}
static int check_manager_session_inuse(const char *name)
{
struct mansession *session = NULL;
@ -491,63 +452,116 @@ static int manager_displayconnects (struct mansession *s)
return ret;
}
static int handle_showmancmd(int fd, int argc, char *argv[])
static char *handle_showmancmd(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct manager_action *cur;
struct ast_str *authority = ast_str_alloca(80);
int num;
if (argc != 4)
return RESULT_SHOWUSAGE;
struct ast_str *authority;
int num, l, which;
char *ret = NULL;
switch (cmd) {
case CLI_INIT:
e->command = "manager show command";
e->usage =
"Usage: manager show command <actionname>\n"
" Shows the detailed description for a specific Asterisk manager interface command.\n";
return NULL;
case CLI_GENERATE:
l = strlen(a->word);
which = 0;
AST_RWLIST_RDLOCK(&actions);
AST_RWLIST_TRAVERSE(&actions, cur, list) {
if (!strncasecmp(a->word, cur->action, l) && ++which > a->n) {
ret = ast_strdup(cur->action);
break; /* make sure we exit even if ast_strdup() returns NULL */
}
}
AST_RWLIST_UNLOCK(&actions);
return ret;
}
authority = ast_str_alloca(80);
if (a->argc != 4)
return CLI_SHOWUSAGE;
AST_RWLIST_RDLOCK(&actions);
AST_RWLIST_TRAVERSE(&actions, cur, list) {
for (num = 3; num < argc; num++) {
if (!strcasecmp(cur->action, argv[num])) {
ast_cli(fd, "Action: %s\nSynopsis: %s\nPrivilege: %s\n%s\n",
for (num = 3; num < a->argc; num++) {
if (!strcasecmp(cur->action, a->argv[num])) {
ast_cli(a->fd, "Action: %s\nSynopsis: %s\nPrivilege: %s\n%s\n",
cur->action, cur->synopsis,
authority_to_str(cur->authority, &authority),
S_OR(cur->description, "") );
S_OR(cur->description, ""));
}
}
}
AST_RWLIST_UNLOCK(&actions);
return RESULT_SUCCESS;
return CLI_SUCCESS;
}
static int handle_mandebug(int fd, int argc, char *argv[])
static char *handle_mandebug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
if (argc == 2)
ast_cli(fd, "manager debug is %s\n", manager_debug? "on" : "off");
else if (argc == 3) {
if (!strcasecmp(argv[2], "on"))
switch (cmd) {
case CLI_INIT:
e->command = "manager debug [on|off]";
e->usage = "Usage: manager debug [on|off]\n Show, enable, disable debugging of the manager code.\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
if (a->argc == 2)
ast_cli(a->fd, "manager debug is %s\n", manager_debug? "on" : "off");
else if (a->argc == 3) {
if (!strcasecmp(a->argv[2], "on"))
manager_debug = 1;
else if (!strcasecmp(argv[2], "off"))
else if (!strcasecmp(a->argv[2], "off"))
manager_debug = 0;
else
return RESULT_SHOWUSAGE;
return CLI_SHOWUSAGE;
}
return RESULT_SUCCESS;
return CLI_SUCCESS;
}
static int handle_showmanager(int fd, int argc, char *argv[])
static char *handle_showmanager(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct ast_manager_user *user = NULL;
int l, which;
char *ret = NULL;
switch (cmd) {
case CLI_INIT:
e->command = "manager show user";
e->usage =
" Usage: manager show user <user>\n"
" Display all information related to the manager user specified.\n";
return NULL;
case CLI_GENERATE:
l = strlen(a->word);
which = 0;
if (a->pos != 3)
return NULL;
AST_RWLIST_RDLOCK(&users);
AST_RWLIST_TRAVERSE(&users, user, list) {
if ( !strncasecmp(a->word, user->username, l) && ++which > a->n ) {
ret = ast_strdup(user->username);
break;
}
}
AST_RWLIST_UNLOCK(&users);
return ret;
}
if (argc != 4)
return RESULT_SHOWUSAGE;
if (a->argc != 4)
return CLI_SHOWUSAGE;
AST_RWLIST_RDLOCK(&users);
if (!(user = get_manager_by_name_locked(argv[3]))) {
ast_cli(fd, "There is no manager called %s\n", argv[3]);
if (!(user = get_manager_by_name_locked(a->argv[3]))) {
ast_cli(a->fd, "There is no manager called %s\n", a->argv[3]);
AST_RWLIST_UNLOCK(&users);
return -1;
return CLI_SUCCESS;
}
ast_cli(fd,"\n");
ast_cli(fd,
ast_cli(a->fd,"\n");
ast_cli(a->fd,
" username: %s\n"
" secret: %s\n"
" deny: %s\n"
@ -565,154 +579,147 @@ static int handle_showmanager(int fd, int argc, char *argv[])
AST_RWLIST_UNLOCK(&users);
return RESULT_SUCCESS;
return CLI_SUCCESS;
}
static int handle_showmanagers(int fd, int argc, char *argv[])
static char *handle_showmanagers(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct ast_manager_user *user = NULL;
int count_amu = 0;
if (argc != 3)
return RESULT_SHOWUSAGE;
switch (cmd) {
case CLI_INIT:
e->command = "manager show users";
e->usage =
"Usage: manager show users\n"
" Prints a listing of all managers that are currently configured on that\n"
" system.\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
if (a->argc != 3)
return CLI_SHOWUSAGE;
AST_RWLIST_RDLOCK(&users);
/* If there are no users, print out something along those lines */
if (AST_RWLIST_EMPTY(&users)) {
ast_cli(fd, "There are no manager users.\n");
ast_cli(a->fd, "There are no manager users.\n");
AST_RWLIST_UNLOCK(&users);
return RESULT_SUCCESS;
return CLI_SUCCESS;
}
ast_cli(fd, "\nusername\n--------\n");
ast_cli(a->fd, "\nusername\n--------\n");
AST_RWLIST_TRAVERSE(&users, user, list) {
ast_cli(fd, "%s\n", user->username);
ast_cli(a->fd, "%s\n", user->username);
count_amu++;
}
AST_RWLIST_UNLOCK(&users);
ast_cli(fd,"-------------------\n");
ast_cli(fd,"%d manager users configured.\n", count_amu);
ast_cli(a->fd,"-------------------\n");
ast_cli(a->fd,"%d manager users configured.\n", count_amu);
return RESULT_SUCCESS;
return CLI_SUCCESS;
}
/*! \brief CLI command manager list commands */
static int handle_showmancmds(int fd, int argc, char *argv[])
static char *handle_showmancmds(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct manager_action *cur;
struct ast_str *authority = ast_str_alloca(80);
char *format = " %-15.15s %-15.15s %-55.55s\n";
ast_cli(fd, format, "Action", "Privilege", "Synopsis");
ast_cli(fd, format, "------", "---------", "--------");
struct ast_str *authority;
static const char *format = " %-15.15s %-15.15s %-55.55s\n";
switch (cmd) {
case CLI_INIT:
e->command = "manager show commands";
e->usage =
"Usage: manager show commands\n"
" Prints a listing of all the available Asterisk manager interface commands.\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
authority = ast_str_alloca(80);
ast_cli(a->fd, format, "Action", "Privilege", "Synopsis");
ast_cli(a->fd, format, "------", "---------", "--------");
AST_RWLIST_RDLOCK(&actions);
AST_RWLIST_TRAVERSE(&actions, cur, list)
ast_cli(fd, format, cur->action, authority_to_str(cur->authority, &authority), cur->synopsis);
ast_cli(a->fd, format, cur->action, authority_to_str(cur->authority, &authority), cur->synopsis);
AST_RWLIST_UNLOCK(&actions);
return RESULT_SUCCESS;
return CLI_SUCCESS;
}
/*! \brief CLI command manager list connected */
static int handle_showmanconn(int fd, int argc, char *argv[])
static char *handle_showmanconn(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct mansession *s;
char *format = " %-15.15s %-15.15s\n";
static const char *format = " %-15.15s %-15.15s\n";
int count = 0;
ast_cli(fd, format, "Username", "IP Address");
switch (cmd) {
case CLI_INIT:
e->command = "manager show connected";
e->usage =
"Usage: manager show connected\n"
" Prints a listing of the users that are currently connected to the\n"
"Asterisk manager interface.\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
ast_cli(a->fd, format, "Username", "IP Address");
AST_LIST_LOCK(&sessions);
AST_LIST_TRAVERSE(&sessions, s, list) {
ast_cli(fd, format,s->username, ast_inet_ntoa(s->sin.sin_addr));
ast_cli(a->fd, format,s->username, ast_inet_ntoa(s->sin.sin_addr));
count++;
}
AST_LIST_UNLOCK(&sessions);
ast_cli(fd, "%d users connected.\n", count);
ast_cli(a->fd, "%d users connected.\n", count);
return RESULT_SUCCESS;
return CLI_SUCCESS;
}
/*! \brief CLI command manager list eventq */
/* Should change to "manager show connected" */
static int handle_showmaneventq(int fd, int argc, char *argv[])
static char *handle_showmaneventq(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct eventqent *s;
switch (cmd) {
case CLI_INIT:
e->command = "manager show eventq";
e->usage =
"Usage: manager show eventq\n"
" Prints a listing of all events pending in the Asterisk manger\n"
"event queue.\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
AST_LIST_LOCK(&all_events);
AST_LIST_TRAVERSE(&all_events, s, eq_next) {
ast_cli(fd, "Usecount: %d\n",s->usecount);
ast_cli(fd, "Category: %d\n", s->category);
ast_cli(fd, "Event:\n%s", s->eventdata);
ast_cli(a->fd, "Usecount: %d\n",s->usecount);
ast_cli(a->fd, "Category: %d\n", s->category);
ast_cli(a->fd, "Event:\n%s", s->eventdata);
}
AST_LIST_UNLOCK(&all_events);
return RESULT_SUCCESS;
return CLI_SUCCESS;
}
static char showmancmd_help[] =
"Usage: manager show command <actionname>\n"
" Shows the detailed description for a specific Asterisk manager interface command.\n";
static char showmancmds_help[] =
"Usage: manager show commands\n"
" Prints a listing of all the available Asterisk manager interface commands.\n";
static char showmanconn_help[] =
"Usage: manager show connected\n"
" Prints a listing of the users that are currently connected to the\n"
"Asterisk manager interface.\n";
static char showmaneventq_help[] =
"Usage: manager show eventq\n"
" Prints a listing of all events pending in the Asterisk manger\n"
"event queue.\n";
static char showmanagers_help[] =
"Usage: manager show users\n"
" Prints a listing of all managers that are currently configured on that\n"
" system.\n";
static char showmanager_help[] =
" Usage: manager show user <user>\n"
" Display all information related to the manager user specified.\n";
static struct ast_cli_entry cli_manager[] = {
{ { "manager", "show", "command", NULL },
handle_showmancmd, "Show a manager interface command",
showmancmd_help, complete_show_mancmd },
{ { "manager", "show", "commands", NULL },
handle_showmancmds, "List manager interface commands",
showmancmds_help },
{ { "manager", "show", "connected", NULL },
handle_showmanconn, "List connected manager interface users",
showmanconn_help },
{ { "manager", "show", "eventq", NULL },
handle_showmaneventq, "List manager interface queued events",
showmaneventq_help },
{ { "manager", "show", "users", NULL },
handle_showmanagers, "List configured manager users",
showmanagers_help, NULL, NULL },
{ { "manager", "show", "user", NULL },
handle_showmanager, "Display information on a specific manager user",
showmanager_help, complete_show_manuser, NULL },
{ { "manager", "debug", NULL },
handle_mandebug, "Show, enable, disable debugging of the manager code",
"Usage: manager debug [on|off]\n Show, enable, disable debugging of the manager code.\n", NULL, NULL },
NEW_CLI(handle_showmancmd, "Show a manager interface command"),
NEW_CLI(handle_showmancmds, "List manager interface commands"),
NEW_CLI(handle_showmanconn, "List connected manager interface users"),
NEW_CLI(handle_showmaneventq, "List manager interface queued events"),
NEW_CLI(handle_showmanagers, "List configured manager users"),
NEW_CLI(handle_showmanager, "Display information on a specific manager user"),
NEW_CLI(handle_mandebug, "Show, enable, disable debugging of the manager code"),
};
/*

@ -1246,35 +1246,46 @@ void pbx_retrieve_variable(struct ast_channel *c, const char *var, char **ret, c
}
}
static int handle_show_functions(int fd, int argc, char *argv[])
static char *handle_show_functions(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct ast_custom_function *acf;
int count_acf = 0;
int like = 0;
if (argc == 5 && (!strcmp(argv[3], "like")) ) {
switch (cmd) {
case CLI_INIT:
e->command = "core show functions [like]";
e->usage =
"Usage: core show functions [like <text>]\n"
" List builtin functions, optionally only those matching a given string\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
if (a->argc == 5 && (!strcmp(a->argv[3], "like")) ) {
like = 1;
} else if (argc != 3) {
return RESULT_SHOWUSAGE;
} else if (a->argc != 3) {
return CLI_SHOWUSAGE;
}
ast_cli(fd, "%s Custom Functions:\n--------------------------------------------------------------------------------\n", like ? "Matching" : "Installed");
ast_cli(a->fd, "%s Custom Functions:\n--------------------------------------------------------------------------------\n", like ? "Matching" : "Installed");
AST_RWLIST_RDLOCK(&acf_root);
AST_RWLIST_TRAVERSE(&acf_root, acf, acflist) {
if (!like || strstr(acf->name, argv[4])) {
if (!like || strstr(acf->name, a->argv[4])) {
count_acf++;
ast_cli(fd, "%-20.20s %-35.35s %s\n", acf->name, acf->syntax, acf->synopsis);
ast_cli(a->fd, "%-20.20s %-35.35s %s\n", acf->name, acf->syntax, acf->synopsis);
}
}
AST_RWLIST_UNLOCK(&acf_root);
ast_cli(fd, "%d %scustom functions installed.\n", count_acf, like ? "matching " : "");
ast_cli(a->fd, "%d %scustom functions installed.\n", count_acf, like ? "matching " : "");
return RESULT_SUCCESS;
return CLI_SUCCESS;
}
static int handle_show_function(int fd, int argc, char *argv[])
static char *handle_show_function(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct ast_custom_function *acf;
/* Maximum number of characters added by terminal coloring is 22 */
@ -1282,13 +1293,38 @@ static int handle_show_function(int fd, int argc, char *argv[])
char info[64 + AST_MAX_APP], *synopsis = NULL, *description = NULL;
char stxtitle[40], *syntax = NULL;
int synopsis_size, description_size, syntax_size;
char *ret = NULL;
int which = 0;
int wordlen;
if (argc < 4)
return RESULT_SHOWUSAGE;
switch (cmd) {
case CLI_INIT:
e->command = "core show function";
e->usage =
"Usage: core show function <function>\n"
" Describe a particular dialplan function.\n";
return NULL;
case CLI_GENERATE:
wordlen = strlen(a->word);
/* case-insensitive for convenience in this 'complete' function */
AST_RWLIST_RDLOCK(&acf_root);
AST_RWLIST_TRAVERSE(&acf_root, acf, acflist) {
if (!strncasecmp(a->word, acf->name, wordlen) && ++which > a->n) {
ret = ast_strdup(acf->name);
break;
}
}
AST_RWLIST_UNLOCK(&acf_root);
if (!(acf = ast_custom_function_find(argv[3]))) {
ast_cli(fd, "No function by that name registered.\n");
return RESULT_FAILURE;
return ret;
}
if (a->argc < 4)
return CLI_SHOWUSAGE;
if (!(acf = ast_custom_function_find(a->argv[3]))) {
ast_cli(a->fd, "No function by that name registered.\n");
return CLI_FAILURE;
}
@ -1325,29 +1361,9 @@ static int handle_show_function(int fd, int argc, char *argv[])
acf->desc ? acf->desc : "Not available",
COLOR_CYAN, 0, description_size);
ast_cli(fd,"%s%s%s\n\n%s%s\n\n%s%s\n", infotitle, stxtitle, syntax, syntitle, synopsis, destitle, description);
return RESULT_SUCCESS;
}
static char *complete_show_function(const char *line, const char *word, int pos, int state)
{
struct ast_custom_function *acf;
char *ret = NULL;
int which = 0;
int wordlen = strlen(word);
/* case-insensitive for convenience in this 'complete' function */
AST_RWLIST_RDLOCK(&acf_root);
AST_RWLIST_TRAVERSE(&acf_root, acf, acflist) {
if (!strncasecmp(word, acf->name, wordlen) && ++which > state) {
ret = ast_strdup(acf->name);
break;
}
}
AST_RWLIST_UNLOCK(&acf_root);
ast_cli(a->fd,"%s%s%s\n\n%s%s\n\n%s%s\n", infotitle, stxtitle, syntax, syntitle, synopsis, destitle, description);
return ret;
return CLI_SUCCESS;
}
struct ast_custom_function *ast_custom_function_find(const char *name)
@ -3008,89 +3024,55 @@ void ast_unregister_switch(struct ast_switch *sw)
/*
* Help for CLI commands ...
*/
static char show_applications_help[] =
"Usage: core show applications [{like|describing} <text>]\n"
" List applications which are currently available.\n"
" If 'like', <text> will be a substring of the app name\n"
" If 'describing', <text> will be a substring of the description\n";
static char show_functions_help[] =
"Usage: core show functions [like <text>]\n"
" List builtin functions, optionally only those matching a given string\n";
static char show_switches_help[] =
"Usage: core show switches\n"
" List registered switches\n";
static char show_hints_help[] =
"Usage: core show hints\n"
" List registered hints\n";
static char show_globals_help[] =
"Usage: core show globals\n"
" List current global dialplan variables and their values\n";
static char show_application_help[] =
"Usage: core show application <application> [<application> [<application> [...]]]\n"
" Describes a particular application.\n";
static char show_function_help[] =
"Usage: core show function <function>\n"
" Describe a particular dialplan function.\n";
static char show_dialplan_help[] =
"Usage: core show dialplan [exten@][context]\n"
" Show dialplan\n";
static char set_global_help[] =
"Usage: core set global <name> <value>\n"
" Set global dialplan variable <name> to <value>\n";
/*
* \brief 'show application' CLI command implementation functions ...
*/
/*
* There is a possibility to show informations about more than one
* application at one time. You can type 'show application Dial Echo' and
* you will see informations about these two applications ...
* \brief 'show application' CLI command implementation function...
*/
static char *complete_show_application(const char *line, const char *word, int pos, int state)
static char *handle_show_application(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct ast_app *a;
struct ast_app *aa;
int app, no_registered_app = 1;
char *ret = NULL;
int which = 0;
int wordlen = strlen(word);
int wordlen;
/* return the n-th [partial] matching entry */
AST_RWLIST_RDLOCK(&apps);
AST_RWLIST_TRAVERSE(&apps, a, list) {
if (!strncasecmp(word, a->name, wordlen) && ++which > state) {
ret = ast_strdup(a->name);
break;
switch (cmd) {
case CLI_INIT:
e->command = "core show application";
e->usage =
"Usage: core show application <application> [<application> [<application> [...]]]\n"
" Describes a particular application.\n";
return NULL;
case CLI_GENERATE:
/*
* There is a possibility to show informations about more than one
* application at one time. You can type 'show application Dial Echo' and
* you will see informations about these two applications ...
*/
wordlen = strlen(a->word);
/* return the n-th [partial] matching entry */
AST_RWLIST_RDLOCK(&apps);
AST_RWLIST_TRAVERSE(&apps, aa, list) {
if (!strncasecmp(a->word, aa->name, wordlen) && ++which > a->n) {
ret = ast_strdup(aa->name);
break;
}
}
}
AST_RWLIST_UNLOCK(&apps);
return ret;
}
AST_RWLIST_UNLOCK(&apps);
static int handle_show_application(int fd, int argc, char *argv[])
{
struct ast_app *a;
int app, no_registered_app = 1;
return ret;
}
if (argc < 4)
return RESULT_SHOWUSAGE;
if (a->argc < 4)
return CLI_SHOWUSAGE;
/* ... go through all applications ... */
AST_RWLIST_RDLOCK(&apps);
AST_RWLIST_TRAVERSE(&apps, a, list) {
AST_RWLIST_TRAVERSE(&apps, aa, list) {
/* ... compare this application name with all arguments given
* to 'show application' command ... */
for (app = 3; app < argc; app++) {
if (!strcasecmp(a->name, argv[app])) {
for (app = 3; app < a->argc; app++) {
if (!strcasecmp(aa->name, a->argv[app])) {
/* Maximum number of characters added by terminal coloring is 22 */
char infotitle[64 + AST_MAX_APP + 22], syntitle[40], destitle[40];
char info[64 + AST_MAX_APP], *synopsis = NULL, *description = NULL;
@ -3098,39 +3080,39 @@ static int handle_show_application(int fd, int argc, char *argv[])
no_registered_app = 0;
if (a->synopsis)
synopsis_size = strlen(a->synopsis) + 23;
if (aa->synopsis)
synopsis_size = strlen(aa->synopsis) + 23;
else
synopsis_size = strlen("Not available") + 23;
synopsis = alloca(synopsis_size);
if (a->description)
description_size = strlen(a->description) + 23;
if (aa->description)
description_size = strlen(aa->description) + 23;
else
description_size = strlen("Not available") + 23;
description = alloca(description_size);
if (synopsis && description) {
snprintf(info, 64 + AST_MAX_APP, "\n -= Info about application '%s' =- \n\n", a->name);
snprintf(info, 64 + AST_MAX_APP, "\n -= Info about application '%s' =- \n\n", aa->name);
term_color(infotitle, info, COLOR_MAGENTA, 0, 64 + AST_MAX_APP + 22);
term_color(syntitle, "[Synopsis]\n", COLOR_MAGENTA, 0, 40);
term_color(destitle, "[Description]\n", COLOR_MAGENTA, 0, 40);
term_color(synopsis,
a->synopsis ? a->synopsis : "Not available",
aa->synopsis ? aa->synopsis : "Not available",
COLOR_CYAN, 0, synopsis_size);
term_color(description,
a->description ? a->description : "Not available",
aa->description ? aa->description : "Not available",
COLOR_CYAN, 0, description_size);
ast_cli(fd,"%s%s%s\n\n%s%s\n", infotitle, syntitle, synopsis, destitle, description);
ast_cli(a->fd,"%s%s%s\n\n%s%s\n", infotitle, syntitle, synopsis, destitle, description);
} else {
/* ... one of our applications, show info ...*/
ast_cli(fd,"\n -= Info about application '%s' =- \n\n"
ast_cli(a->fd,"\n -= Info about application '%s' =- \n\n"
"[Synopsis]\n %s\n\n"
"[Description]\n%s\n",
a->name,
a->synopsis ? a->synopsis : "Not available",
a->description ? a->description : "Not available");
aa->name,
aa->synopsis ? aa->synopsis : "Not available",
aa->description ? aa->description : "Not available");
}
}
}
@ -3139,112 +3121,148 @@ static int handle_show_application(int fd, int argc, char *argv[])
/* we found at least one app? no? */
if (no_registered_app) {
ast_cli(fd, "Your application(s) is (are) not registered\n");
return RESULT_FAILURE;
ast_cli(a->fd, "Your application(s) is (are) not registered\n");
return CLI_FAILURE;
}
return RESULT_SUCCESS;
return CLI_SUCCESS;
}
/*! \brief handle_show_hints: CLI support for listing registered dial plan hints */
static int handle_show_hints(int fd, int argc, char *argv[])
static char *handle_show_hints(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct ast_hint *hint;
int num = 0;
int watchers;
struct ast_state_cb *watcher;
switch (cmd) {
case CLI_INIT:
e->command = "core show hints";
e->usage =
"Usage: core show hints\n"
" List registered hints\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
AST_RWLIST_RDLOCK(&hints);
if (AST_RWLIST_EMPTY(&hints)) {
ast_cli(fd, "There are no registered dialplan hints\n");
ast_cli(a->fd, "There are no registered dialplan hints\n");
AST_RWLIST_UNLOCK(&hints);
return RESULT_SUCCESS;
return CLI_SUCCESS;
}
/* ... we have hints ... */
ast_cli(fd, "\n -= Registered Asterisk Dial Plan Hints =-\n");
ast_cli(a->fd, "\n -= Registered Asterisk Dial Plan Hints =-\n");
AST_RWLIST_TRAVERSE(&hints, hint, list) {
watchers = 0;
for (watcher = hint->callbacks; watcher; watcher = watcher->next)
watchers++;
ast_cli(fd, " %20s@%-20.20s: %-20.20s State:%-15.15s Watchers %2d\n",
ast_cli(a->fd, " %20s@%-20.20s: %-20.20s State:%-15.15s Watchers %2d\n",
ast_get_extension_name(hint->exten),
ast_get_context_name(ast_get_extension_context(hint->exten)),
ast_get_extension_app(hint->exten),
ast_extension_state2str(hint->laststate), watchers);
num++;
}
ast_cli(fd, "----------------\n");
ast_cli(fd, "- %d hints registered\n", num);
ast_cli(a->fd, "----------------\n");
ast_cli(a->fd, "- %d hints registered\n", num);
AST_RWLIST_UNLOCK(&hints);
return RESULT_SUCCESS;
return CLI_SUCCESS;
}
/*! \brief handle_show_switches: CLI support for listing registered dial plan switches */
static int handle_show_switches(int fd, int argc, char *argv[])
static char *handle_show_switches(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct ast_switch *sw;
switch (cmd) {
case CLI_INIT:
e->command = "core show switches";
e->usage =
"Usage: core show switches\n"
" List registered switches\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
AST_RWLIST_RDLOCK(&switches);
if (AST_RWLIST_EMPTY(&switches)) {
AST_RWLIST_UNLOCK(&switches);
ast_cli(fd, "There are no registered alternative switches\n");
ast_cli(a->fd, "There are no registered alternative switches\n");
return RESULT_SUCCESS;
}
ast_cli(fd, "\n -= Registered Asterisk Alternative Switches =-\n");
ast_cli(a->fd, "\n -= Registered Asterisk Alternative Switches =-\n");
AST_RWLIST_TRAVERSE(&switches, sw, list)
ast_cli(fd, "%s: %s\n", sw->name, sw->description);
ast_cli(a->fd, "%s: %s\n", sw->name, sw->description);
AST_RWLIST_UNLOCK(&switches);
return RESULT_SUCCESS;
return CLI_SUCCESS;
}
static int handle_show_applications(int fd, int argc, char *argv[])
static char *handle_show_applications(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct ast_app *a;
struct ast_app *aa;
int like = 0, describing = 0;
int total_match = 0; /* Number of matches in like clause */
int total_apps = 0; /* Number of apps registered */
static char* choices[] = { "like", "describing", NULL };
switch (cmd) {
case CLI_INIT:
e->command = "core show applications [like|describing]";
e->usage =
"Usage: core show applications [{like|describing} <text>]\n"
" List applications which are currently available.\n"
" If 'like', <text> will be a substring of the app name\n"
" If 'describing', <text> will be a substring of the description\n";
return NULL;
case CLI_GENERATE:
return (a->pos != 3) ? NULL : ast_cli_complete(a->word, choices, a->n);
}
AST_RWLIST_RDLOCK(&apps);
if (AST_RWLIST_EMPTY(&apps)) {
ast_cli(fd, "There are no registered applications\n");
ast_cli(a->fd, "There are no registered applications\n");
AST_RWLIST_UNLOCK(&apps);
return -1;
return CLI_SUCCESS;
}
/* core list applications like <keyword> */
if ((argc == 5) && (!strcmp(argv[3], "like"))) {
if ((a->argc == 5) && (!strcmp(a->argv[3], "like"))) {
like = 1;
} else if ((argc > 4) && (!strcmp(argv[3], "describing"))) {
} else if ((a->argc > 4) && (!strcmp(a->argv[3], "describing"))) {
describing = 1;
}
/* core list applications describing <keyword1> [<keyword2>] [...] */
if ((!like) && (!describing)) {
ast_cli(fd, " -= Registered Asterisk Applications =-\n");
ast_cli(a->fd, " -= Registered Asterisk Applications =-\n");
} else {
ast_cli(fd, " -= Matching Asterisk Applications =-\n");
ast_cli(a->fd, " -= Matching Asterisk Applications =-\n");
}
AST_RWLIST_TRAVERSE(&apps, a, list) {
AST_RWLIST_TRAVERSE(&apps, aa, list) {
int printapp = 0;
total_apps++;
if (like) {
if (strcasestr(a->name, argv[4])) {
if (strcasestr(aa->name, a->argv[4])) {
printapp = 1;
total_match++;
}
} else if (describing) {
if (a->description) {
if (aa->description) {
/* Match all words on command line */
int i;
printapp = 1;
for (i = 4; i < argc; i++) {
if (!strcasestr(a->description, argv[i])) {
for (i = 4; i < a->argc; i++) {
if (!strcasestr(aa->description, a->argv[i])) {
printapp = 0;
} else {
total_match++;
@ -3256,25 +3274,18 @@ static int handle_show_applications(int fd, int argc, char *argv[])
}
if (printapp) {
ast_cli(fd," %20s: %s\n", a->name, a->synopsis ? a->synopsis : "<Synopsis not available>");
ast_cli(a->fd," %20s: %s\n", aa->name, aa->synopsis ? aa->synopsis : "<Synopsis not available>");
}
}
if ((!like) && (!describing)) {
ast_cli(fd, " -= %d Applications Registered =-\n",total_apps);
ast_cli(a->fd, " -= %d Applications Registered =-\n",total_apps);
} else {
ast_cli(fd, " -= %d Applications Matching =-\n",total_match);
ast_cli(a->fd, " -= %d Applications Matching =-\n",total_match);
}
AST_RWLIST_UNLOCK(&apps);
return RESULT_SUCCESS;
}
static char *complete_show_applications(const char *line, const char *word, int pos, int state)
{
static char* choices[] = { "like", "describing", NULL };
return (pos != 3) ? NULL : ast_cli_complete(word, choices, state);
return CLI_SUCCESS;
}
/*
@ -3485,59 +3496,70 @@ static int show_dialplan_helper(int fd, const char *context, const char *exten,
return (dpc->total_exten == old_total_exten) ? -1 : res;
}
static int handle_show_dialplan(int fd, int argc, char *argv[])
static char *handle_show_dialplan(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
char *exten = NULL, *context = NULL;
/* Variables used for different counters */
struct dialplan_counters counters;
const char *incstack[AST_PBX_MAX_STACK];
switch (cmd) {
case CLI_INIT:
e->command = "dialplan show";
e->usage =
"Usage: core show dialplan [exten@][context]\n"
" Show dialplan\n";
return NULL;
case CLI_GENERATE:
return complete_show_dialplan_context(a->line, a->word, a->pos, a->n);
}
memset(&counters, 0, sizeof(counters));
if (argc != 2 && argc != 3)
return RESULT_SHOWUSAGE;
if (a->argc != 2 && a->argc != 3)
return CLI_SHOWUSAGE;
/* we obtain [exten@]context? if yes, split them ... */
if (argc == 3) {
if (strchr(argv[2], '@')) { /* split into exten & context */
context = ast_strdupa(argv[2]);
if (a->argc == 3) {
if (strchr(a->argv[2], '@')) { /* split into exten & context */
context = ast_strdupa(a->argv[2]);
exten = strsep(&context, "@");
/* change empty strings to NULL */
if (ast_strlen_zero(exten))
exten = NULL;
} else { /* no '@' char, only context given */
context = argv[2];
context = a->argv[2];
}
if (ast_strlen_zero(context))
context = NULL;
}
/* else Show complete dial plan, context and exten are NULL */
show_dialplan_helper(fd, context, exten, &counters, NULL, 0, incstack);
show_dialplan_helper(a->fd, context, exten, &counters, NULL, 0, incstack);
/* check for input failure and throw some error messages */
if (context && !counters.context_existence) {
ast_cli(fd, "There is no existence of '%s' context\n", context);
return RESULT_FAILURE;
ast_cli(a->fd, "There is no existence of '%s' context\n", context);
return CLI_FAILURE;
}
if (exten && !counters.extension_existence) {
if (context)
ast_cli(fd, "There is no existence of %s@%s extension\n",
ast_cli(a->fd, "There is no existence of %s@%s extension\n",
exten, context);
else
ast_cli(fd,
ast_cli(a->fd,
"There is no existence of '%s' extension in all contexts\n",
exten);
return RESULT_FAILURE;
return CLI_FAILURE;
}
ast_cli(fd,"-= %d %s (%d %s) in %d %s. =-\n",
ast_cli(a->fd,"-= %d %s (%d %s) in %d %s. =-\n",
counters.total_exten, counters.total_exten == 1 ? "extension" : "extensions",
counters.total_prio, counters.total_prio == 1 ? "priority" : "priorities",
counters.total_context, counters.total_context == 1 ? "context" : "contexts");
/* everything ok */
return RESULT_SUCCESS;
return CLI_SUCCESS;
}
/*! \brief Send ack once */
@ -3751,74 +3773,68 @@ static char mandescr_show_dialplan[] =
/*! \brief CLI support for listing global variables in a parseable way */
static int handle_show_globals(int fd, int argc, char *argv[])
static char *handle_show_globals(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
int i = 0;
struct ast_var_t *newvariable;
switch (cmd) {
case CLI_INIT:
e->command = "core show globals";
e->usage =
"Usage: core show globals\n"
" List current global dialplan variables and their values\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
ast_rwlock_rdlock(&globalslock);
AST_LIST_TRAVERSE (&globals, newvariable, entries) {
i++;
ast_cli(fd, " %s=%s\n", ast_var_name(newvariable), ast_var_value(newvariable));
ast_cli(a->fd, " %s=%s\n", ast_var_name(newvariable), ast_var_value(newvariable));
}
ast_rwlock_unlock(&globalslock);
ast_cli(fd, "\n -- %d variables\n", i);
ast_cli(a->fd, "\n -- %d variables\n", i);
return RESULT_SUCCESS;
return CLI_SUCCESS;
}
static int handle_set_global(int fd, int argc, char *argv[])
static char *handle_set_global(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
if (argc != 5)
return RESULT_SHOWUSAGE;
pbx_builtin_setvar_helper(NULL, argv[3], argv[4]);
ast_cli(fd, "\n -- Global variable %s set to %s\n", argv[3], argv[4]);
switch (cmd) {
case CLI_INIT:
e->command = "core set global";
e->usage =
"Usage: core set global <name> <value>\n"
" Set global dialplan variable <name> to <value>\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
return RESULT_SUCCESS;
}
if (a->argc != 5)
return CLI_SHOWUSAGE;
pbx_builtin_setvar_helper(NULL, a->argv[3], a->argv[4]);
ast_cli(a->fd, "\n -- Global variable %s set to %s\n", a->argv[3], a->argv[4]);
return CLI_SUCCESS;
}
/*
* CLI entries for upper commands ...
*/
static struct ast_cli_entry pbx_cli[] = {
{ { "core", "show", "applications", NULL },
handle_show_applications, "Shows registered dialplan applications",
show_applications_help, complete_show_applications },
{ { "core", "show", "functions", NULL },
handle_show_functions, "Shows registered dialplan functions",
show_functions_help },
{ { "core", "show", "switches", NULL },
handle_show_switches, "Show alternative switches",
show_switches_help },
{ { "core", "show", "hints", NULL },
handle_show_hints, "Show dialplan hints",
show_hints_help },
{ { "core", "show", "globals", NULL },
handle_show_globals, "Show global dialplan variables",
show_globals_help },
{ { "core", "show" , "function", NULL },
handle_show_function, "Describe a specific dialplan function",
show_function_help, complete_show_function },
{ { "core", "show", "application", NULL },
handle_show_application, "Describe a specific dialplan application",
show_application_help, complete_show_application },
{ { "core", "set", "global", NULL },
handle_set_global, "Set global dialplan variable",
set_global_help },
{ { "dialplan", "show", NULL },
handle_show_dialplan, "Show dialplan",
show_dialplan_help, complete_show_dialplan_context },
NEW_CLI(handle_show_applications, "Shows registered dialplan applications"),
NEW_CLI(handle_show_functions, "Shows registered dialplan functions"),
NEW_CLI(handle_show_switches, "Show alternative switches"),
NEW_CLI(handle_show_hints, "Show dialplan hints"),
NEW_CLI(handle_show_globals, "Show global dialplan variables"),
NEW_CLI(handle_show_function, "Describe a specific dialplan function"),
NEW_CLI(handle_show_application, "Describe a specific dialplan application"),
NEW_CLI(handle_set_global, "Set global dialplan variable"),
NEW_CLI(handle_show_dialplan, "Show dialplan"),
};
static void unreference_cached_app(struct ast_app *app)

@ -1300,30 +1300,33 @@ static int handle_dbdeltree(struct ast_channel *chan, AGI *agi, int argc, char *
return RESULT_SUCCESS;
}
static const char debug_usage[] =
"Usage: agi debug\n"
" Enables dumping of AGI transactions for debugging purposes\n";
static const char no_debug_usage[] =
"Usage: agi debug off\n"
" Disables dumping of AGI transactions for debugging purposes\n";
static int agi_do_debug(int fd, int argc, char *argv[])
static char *handle_cli_agi_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
if (argc != 2)
return RESULT_SHOWUSAGE;
agidebug = 1;
ast_cli(fd, "AGI Debugging Enabled\n");
return RESULT_SUCCESS;
}
static int agi_no_debug(int fd, int argc, char *argv[])
{
if (argc != 3)
return RESULT_SHOWUSAGE;
agidebug = 0;
ast_cli(fd, "AGI Debugging Disabled\n");
return RESULT_SUCCESS;
switch (cmd) {
case CLI_INIT:
e->command = "agi debug [off]";
e->usage =
"Usage: agi debug [off]\n"
" Enables/disables dumping of AGI transactions for\n"
" debugging purposes.\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
if (a->argc < e->args - 1 || a->argc > e->args )
return CLI_SHOWUSAGE;
if (a->argc == e->args - 1) {
agidebug = 1;
} else {
if (strncasecmp(a->argv[e->args - 1], "off", 3) == 0) {
agidebug = 0;
} else {
return CLI_SHOWUSAGE;
}
}
ast_cli(a->fd, "AGI Debugging %sabled\n", agidebug ? "En" : "Dis");
return CLI_SUCCESS;
}
static int handle_noop(struct ast_channel *chan, AGI *agi, int arg, char *argv[])
@ -1634,7 +1637,7 @@ static struct agi_command commands[] = {
static AST_RWLIST_HEAD_STATIC(agi_commands, agi_command);
static int help_workhorse(int fd, char *match[])
static char *help_workhorse(int fd, char *match[])
{
char fullcmd[80], matchstr[80];
struct agi_command *e;
@ -1656,7 +1659,8 @@ static int help_workhorse(int fd, char *match[])
ast_cli(fd, "%5.5s %20.20s %s\n", e->dead ? "Yes" : "No" , fullcmd, e->summary);
}
AST_RWLIST_UNLOCK(&agi_commands);
return 0;
return CLI_SUCCESS;
}
int ast_agi_register(struct ast_module *mod, agi_command *cmd)
@ -1951,31 +1955,42 @@ static enum agi_result run_agi(struct ast_channel *chan, char *request, AGI *agi
return returnstatus;
}
static int handle_showagi(int fd, int argc, char *argv[])
static char *handle_cli_agi_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct agi_command *e;
struct agi_command *command;
char fullcmd[80];
if ((argc < 2))
return RESULT_SHOWUSAGE;
if (argc > 2) {
e = find_command(argv + 2, 1);
if (e) {
ast_cli(fd, e->usage);
ast_cli(fd, " Runs Dead : %s\n", e->dead ? "Yes" : "No");
switch (cmd) {
case CLI_INIT:
e->command = "agi show";
e->usage =
"Usage: agi show [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 AGI commands.\n";
break;
case CLI_GENERATE:
return NULL;
}
if (a->argc < e->args)
return CLI_SHOWUSAGE;
if (a->argc > e->args) {
command = find_command(a->argv + e->args, 1);
if (command) {
ast_cli(a->fd, command->usage);
ast_cli(a->fd, " Runs Dead : %s\n", command->dead ? "Yes" : "No");
} else {
if (find_command(argv + 2, -1)) {
return help_workhorse(fd, argv + 2);
if (find_command(a->argv + e->args, -1)) {
return help_workhorse(a->fd, a->argv + e->args);
} else {
ast_join(fullcmd, sizeof(fullcmd), argv + 2);
ast_cli(fd, "No such command '%s'.\n", fullcmd);
ast_join(fullcmd, sizeof(fullcmd), a->argv + e->args);
ast_cli(a->fd, "No such command '%s'.\n", fullcmd);
}
}
} else {
return help_workhorse(fd, NULL);
return help_workhorse(a->fd, NULL);
}
return RESULT_SUCCESS;
return CLI_SUCCESS;
}
/*! \brief Convert string to use HTML escaped characters
@ -2009,49 +2024,57 @@ static void write_html_escaped(FILE *htmlfile, char *str)
return;
}
static int handle_agidumphtml(int fd, int argc, char *argv[])
static char *handle_cli_agi_dumphtml(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct agi_command *e;
struct agi_command *command;
char fullcmd[80];
FILE *htmlfile;
if ((argc < 3))
return RESULT_SHOWUSAGE;
switch (cmd) {
case CLI_INIT:
e->command = "agi dumphtml";
e->usage =
"Usage: agi dumphtml <filename>\n"
" Dumps the AGI command list in HTML format to the given\n"
" file.\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
if (a->argc < e->args + 1)
return CLI_SHOWUSAGE;
if (!(htmlfile = fopen(argv[2], "wt"))) {
ast_cli(fd, "Could not create file '%s'\n", argv[2]);
return RESULT_SHOWUSAGE;
if (!(htmlfile = fopen(a->argv[2], "wt"))) {
ast_cli(a->fd, "Could not create file '%s'\n", a->argv[2]);
return CLI_SHOWUSAGE;
}
fprintf(htmlfile, "<HTML>\n<HEAD>\n<TITLE>AGI Commands</TITLE>\n</HEAD>\n");
fprintf(htmlfile, "<BODY>\n<CENTER><B><H1>AGI Commands</H1></B></CENTER>\n\n");
fprintf(htmlfile, "<TABLE BORDER=\"0\" CELLSPACING=\"10\">\n");
AST_RWLIST_RDLOCK(&agi_commands);
AST_RWLIST_TRAVERSE(&agi_commands, e, list) {
AST_RWLIST_TRAVERSE(&agi_commands, command, list) {
char *stringp, *tempstr;
if (!e->cmda[0]) /* end ? */
if (!command->cmda[0]) /* end ? */
break;
/* Hide commands that start with '_' */
if ((e->cmda[0])[0] == '_')
if ((command->cmda[0])[0] == '_')
continue;
ast_join(fullcmd, sizeof(fullcmd), e->cmda);
ast_join(fullcmd, sizeof(fullcmd), command->cmda);
fprintf(htmlfile, "<TR><TD><TABLE BORDER=\"1\" CELLPADDING=\"5\" WIDTH=\"100%%\">\n");
fprintf(htmlfile, "<TR><TH ALIGN=\"CENTER\"><B>%s - %s</B></TH></TR>\n", fullcmd,e->summary);
fprintf(htmlfile, "<TR><TH ALIGN=\"CENTER\"><B>%s - %s</B></TH></TR>\n", fullcmd, command->summary);
stringp=e->usage;
stringp = command->usage;
tempstr = strsep(&stringp, "\n");
fprintf(htmlfile, "<TR><TD ALIGN=\"CENTER\">");
write_html_escaped(htmlfile, tempstr);
fprintf(htmlfile, "</TD></TR>\n");
fprintf(htmlfile, "<TR><TD ALIGN=\"CENTER\">\n");
while ((tempstr = strsep(&stringp, "\n")) != NULL) {
write_html_escaped(htmlfile, tempstr);
fprintf(htmlfile, "<BR>\n");
@ -2062,8 +2085,8 @@ static int handle_agidumphtml(int fd, int argc, char *argv[])
AST_RWLIST_UNLOCK(&agi_commands);
fprintf(htmlfile, "</TABLE>\n</BODY>\n</HTML>\n");
fclose(htmlfile);
ast_cli(fd, "AGI HTML Commands Dumped to: %s\n", argv[2]);
return RESULT_SUCCESS;
ast_cli(a->fd, "AGI HTML commands dumped to: %s\n", a->argv[2]);
return CLI_SUCCESS;
}
static int agi_exec_full(struct ast_channel *chan, void *data, int enhanced, int dead)
@ -2170,38 +2193,14 @@ static int deadagi_exec(struct ast_channel *chan, void *data)
return agi_exec(chan, data);
}
static char showagi_help[] =
"Usage: agi show [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 AGI commands.\n";
static char dumpagihtml_help[] =
"Usage: agi dumphtml <filename>\n"
" Dumps the agi command list in html format to given filename\n";
static struct ast_cli_entry cli_agi[] = {
{ { "agi", "debug", NULL },
agi_do_debug, "Enable AGI debugging",
debug_usage },
{ { "agi", "debug", "off", NULL },
agi_no_debug, "Disable AGI debugging",
no_debug_usage },
{ { "agi", "show", NULL },
handle_showagi, "List AGI commands or specific help",
showagi_help },
{ { "agi", "dumphtml", NULL },
handle_agidumphtml, "Dumps a list of agi commands in html format",
dumpagihtml_help },
NEW_CLI(handle_cli_agi_debug, "Enable/Disable AGI debugging"),
NEW_CLI(handle_cli_agi_show, "List AGI commands or specific help"),
NEW_CLI(handle_cli_agi_dumphtml, "Dumps a list of AGI commands in HTML format")
};
static int unload_module(void)
{
ast_cli_unregister_multiple(cli_agi, sizeof(cli_agi) / sizeof(struct ast_cli_entry));
ast_agi_unregister_multiple(ast_module_info->self, commands, sizeof(commands) / sizeof(struct agi_command));
ast_unregister_application(eapp);

@ -2364,41 +2364,61 @@ static int park_exec(struct ast_channel *chan, void *data)
return res;
}
static int handle_showfeatures(int fd, int argc, char *argv[])
{
/*!
* \brief CLI command to list configured features
* \param e
* \param cmd
* \param a
*
* \retval CLI_SUCCESS on success.
* \retval NULL when tab completion is used.
*/
static char *handle_feature_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) {
int i;
struct ast_call_feature *feature;
char format[] = "%-25s %-7s %-7s\n";
ast_cli(fd, format, "Builtin Feature", "Default", "Current");
ast_cli(fd, format, "---------------", "-------", "-------");
switch (cmd) {
case CLI_INIT:
e->command = "features show";
e->usage =
"Usage: features show\n"
" Lists configured features\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
ast_cli(a->fd, format, "Builtin Feature", "Default", "Current");
ast_cli(a->fd, format, "---------------", "-------", "-------");
ast_cli(fd, format, "Pickup", "*8", ast_pickup_ext()); /* default hardcoded above, so we'll hardcode it here */
ast_cli(a->fd, format, "Pickup", "*8", ast_pickup_ext()); /* default hardcoded above, so we'll hardcode it here */
ast_rwlock_rdlock(&features_lock);
for (i = 0; i < FEATURES_COUNT; i++)
ast_cli(fd, format, builtin_features[i].fname, builtin_features[i].default_exten, builtin_features[i].exten);
ast_cli(a->fd, format, builtin_features[i].fname, builtin_features[i].default_exten, builtin_features[i].exten);
ast_rwlock_unlock(&features_lock);
ast_cli(fd, "\n");
ast_cli(fd, format, "Dynamic Feature", "Default", "Current");
ast_cli(fd, format, "---------------", "-------", "-------");
ast_cli(a->fd, "\n");
ast_cli(a->fd, format, "Dynamic Feature", "Default", "Current");
ast_cli(a->fd, format, "---------------", "-------", "-------");
if (AST_LIST_EMPTY(&feature_list))
ast_cli(fd, "(none)\n");
ast_cli(a->fd, "(none)\n");
else {
AST_LIST_LOCK(&feature_list);
AST_LIST_TRAVERSE(&feature_list, feature, feature_entry)
ast_cli(fd, format, feature->sname, "no def", feature->exten);
ast_cli(a->fd, format, feature->sname, "no def", feature->exten);
AST_LIST_UNLOCK(&feature_list);
}
ast_cli(fd, "\nCall parking\n");
ast_cli(fd, "------------\n");
ast_cli(fd,"%-20s: %s\n", "Parking extension", parking_ext);
ast_cli(fd,"%-20s: %s\n", "Parking context", parking_con);
ast_cli(fd,"%-20s: %d-%d\n", "Parked call extensions", parking_start, parking_stop);
ast_cli(fd,"\n");
return RESULT_SUCCESS;
ast_cli(a->fd, "\nCall parking\n");
ast_cli(a->fd, "------------\n");
ast_cli(a->fd,"%-20s: %s\n", "Parking extension", parking_ext);
ast_cli(a->fd,"%-20s: %s\n", "Parking context", parking_con);
ast_cli(a->fd,"%-20s: %d-%d\n", "Parked call extensions", parking_start, parking_stop);
ast_cli(a->fd,"\n");
return CLI_SUCCESS;
}
static char mandescr_bridge[] =
@ -2542,10 +2562,6 @@ static int action_bridge(struct mansession *s, const struct message *m)
return 0;
}
static char showfeatures_help[] =
"Usage: feature list\n"
" Lists currently configured features.\n";
/*!
* \brief CLI command to list parked calls
* \param e
@ -2605,10 +2621,7 @@ static char *handle_parkedcalls_deprecated(struct ast_cli_entry *e, int cmd, str
static struct ast_cli_entry cli_show_parkedcalls_deprecated = NEW_CLI(handle_parkedcalls_deprecated, "List currently parked calls.");
static struct ast_cli_entry cli_features[] = {
{ { "feature", "show", NULL },
handle_showfeatures, "Lists configured features",
showfeatures_help },
NEW_CLI(handle_feature_show, "Lists configured features"),
NEW_CLI(handle_parkedcalls, "List currently parked calls", .deprecate_cmd = &cli_show_parkedcalls_deprecated),
};

@ -87,11 +87,11 @@ static void *aji_recv_loop(void *data);
static int aji_initialize(struct aji_client *client);
static int aji_client_connect(void *data, ikspak *pak);
static void aji_set_presence(struct aji_client *client, char *to, char *from, int level, char *desc);
static int aji_do_debug(int fd, int argc, char *argv[]);
static int aji_do_reload(int fd, int argc, char *argv[]);
static int aji_no_debug(int fd, int argc, char *argv[]);
static int aji_test(int fd, int argc, char *argv[]);
static int aji_show_clients(int fd, int argc, char *argv[]);
static char *aji_do_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
static char *aji_do_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
static char *aji_no_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
static char *aji_test(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
static char *aji_show_clients(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
static int aji_create_client(char *label, struct ast_variable *var, int debug);
static int aji_create_buddy(char *label, struct aji_client *client);
static int aji_reload(int reload);
@ -113,43 +113,12 @@ static int aji_register_transport(void *data, ikspak *pak);
static int aji_register_transport2(void *data, ikspak *pak);
*/
static const char debug_usage[] =
"Usage: jabber debug\n"
" Enables dumping of Jabber packets for debugging purposes.\n";
static const char no_debug_usage[] =
"Usage: jabber debug off\n"
" Disables dumping of Jabber packets for debugging purposes.\n";
static const char reload_usage[] =
"Usage: jabber reload\n"
" Enables reloading of Jabber module.\n";
static const char test_usage[] =
"Usage: jabber test [client]\n"
" Sends test message for debugging purposes. A specific client\n"
" as configured in jabber.conf can be optionally specified.\n";
static struct ast_cli_entry aji_cli[] = {
{ { "jabber", "debug", NULL},
aji_do_debug, "Enable Jabber debugging",
debug_usage },
{ { "jabber", "reload", NULL},
aji_do_reload, "Reload Jabber configuration",
reload_usage },
{ { "jabber", "show", "connected", NULL},
aji_show_clients, "Show state of clients and components",
debug_usage },
{ { "jabber", "debug", "off", NULL},
aji_no_debug, "Disable Jabber debug",
no_debug_usage },
{ { "jabber", "test", NULL},
aji_test, "Shows roster, but is generally used for mog's debugging.",
test_usage },
NEW_CLI(aji_do_debug, "Enable jabber debugging"),
NEW_CLI(aji_no_debug, "Disable Jabber debug"),
NEW_CLI(aji_do_reload, "Reload Jabber configuration"),
NEW_CLI(aji_show_clients, "Show state of clients and components"),
NEW_CLI(aji_test, "Shows roster, but is generally used for mog's debugging."),
};
static char *app_ajisend = "JabberSend";
@ -2037,67 +2006,101 @@ static void aji_set_presence(struct aji_client *client, char *to, char *from, in
}
/*!
* \brief turnon console debugging.
* \param fd
* \param argc Integer. Number of args
* \param argv List of arguements
* \return RESULT_SUCCESS.
* \brief Turn on console debugging.
* \return CLI_SUCCESS.
*/
static int aji_do_debug(int fd, int argc, char *argv[])
static char *aji_do_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
switch (cmd) {
case CLI_INIT:
e->command = "jabber debug";
e->usage =
"Usage: jabber debug\n"
" Enables dumping of Jabber packets for debugging purposes.\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
ASTOBJ_CONTAINER_TRAVERSE(&clients, 1, {
ASTOBJ_RDLOCK(iterator);
iterator->debug = 1;
ASTOBJ_UNLOCK(iterator);
});
ast_cli(fd, "Jabber Debugging Enabled.\n");
return RESULT_SUCCESS;
ast_cli(a->fd, "Jabber Debugging Enabled.\n");
return CLI_SUCCESS;
}
/*!
* \brief reload jabber module.
* \param fd
* \param argc no of args
* \param argv list of arguements
* \return RESULT_SUCCESS.
* \brief Reload jabber module.
* \return CLI_SUCCESS.
*/
static int aji_do_reload(int fd, int argc, char *argv[])
static char *aji_do_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
switch (cmd) {
case CLI_INIT:
e->command = "jabber reload";
e->usage =
"Usage: jabber reload\n"
" Reloads the Jabber module.\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
aji_reload(1);
ast_cli(fd, "Jabber Reloaded.\n");
return RESULT_SUCCESS;
ast_cli(a->fd, "Jabber Reloaded.\n");
return CLI_SUCCESS;
}
/*!
* \brief turnoff console debugging.
* \param fd
* \param argc Integer. number of args
* \param argv list of arguements
* \return RESULT_SUCCESS.
* \brief Turn off console debugging.
* \return CLI_SUCCESS.
*/
static int aji_no_debug(int fd, int argc, char *argv[])
static char *aji_no_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
switch (cmd) {
case CLI_INIT:
e->command = "jabber debug off";
e->usage =
"Usage: jabber debug off\n"
" Disables dumping of Jabber packets for debugging purposes.\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
ASTOBJ_CONTAINER_TRAVERSE(&clients, 1, {
ASTOBJ_RDLOCK(iterator);
iterator->debug = 0;
ASTOBJ_UNLOCK(iterator);
});
ast_cli(fd, "Jabber Debugging Disabled.\n");
return RESULT_SUCCESS;
ast_cli(a->fd, "Jabber Debugging Disabled.\n");
return CLI_SUCCESS;
}
/*!
* \brief show client status.
* \param fd
* \param argc Integer. number of args
* \param argv list of arguements
* \return RESULT_SUCCESS.
* \brief Show client status.
* \return CLI_SUCCESS.
*/
static int aji_show_clients(int fd, int argc, char *argv[])
static char *aji_show_clients(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
char *status;
int count = 0;
ast_cli(fd, "Jabber Users and their status:\n");
switch (cmd) {
case CLI_INIT:
e->command = "jabber show connected";
e->usage =
"Usage: jabber show connected\n"
" Shows state of clients and components\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
ast_cli(a->fd, "Jabber Users and their status:\n");
ASTOBJ_CONTAINER_TRAVERSE(&clients, 1, {
ASTOBJ_RDLOCK(iterator);
count++;
@ -2114,36 +2117,45 @@ static int aji_show_clients(int fd, int argc, char *argv[])
default:
status = "Unknown";
}
ast_cli(fd, " User: %s - %s\n", iterator->user, status);
ast_cli(a->fd, " User: %s - %s\n", iterator->user, status);
ASTOBJ_UNLOCK(iterator);
});
ast_cli(fd, "----\n");
ast_cli(fd, " Number of users: %d\n", count);
return RESULT_SUCCESS;
ast_cli(a->fd, "----\n");
ast_cli(a->fd, " Number of users: %d\n", count);
return CLI_SUCCESS;
}
/*!
* \brief send test message for debugging.
* \param fd
* \param argc Integer. number of args
* \param argv list of arguements
* \return RESULT_SUCCESS,RESULT_FAILURE.
* \brief Send test message for debugging.
* \return CLI_SUCCESS,CLI_FAILURE.
*/
static int aji_test(int fd, int argc, char *argv[])
static char *aji_test(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct aji_client *client;
struct aji_resource *resource;
const char *name = "asterisk";
struct aji_message *tmp;
if (argc > 3)
return RESULT_SHOWUSAGE;
else if (argc == 3)
name = argv[2];
switch (cmd) {
case CLI_INIT:
e->command = "jabber test";
e->usage =
"Usage: jabber test [client]\n"
" Sends test message for debugging purposes. A specific client\n"
" as configured in jabber.conf can be optionally specified.\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
if (a->argc > 3)
return CLI_SHOWUSAGE;
else if (a->argc == 3)
name = a->argv[2];
if (!(client = ASTOBJ_CONTAINER_FIND(&clients, name))) {
ast_cli(fd, "Unable to find client '%s'!\n", name);
return RESULT_FAILURE;
ast_cli(a->fd, "Unable to find client '%s'!\n", name);
return CLI_FAILURE;
}
/* XXX Does Matt really want everyone to use his personal address for tests? */ /* XXX yes he does */
@ -2172,7 +2184,7 @@ static int aji_test(int fd, int argc, char *argv[])
AST_LIST_UNLOCK(&client->messages);
ASTOBJ_UNREF(client, aji_client_destroy);
return RESULT_SUCCESS;
return CLI_SUCCESS;
}
/*!

@ -854,10 +854,8 @@ static int moh_scan_files(struct mohclass *class) {
if (!S_ISREG(statbuf.st_mode))
continue;
if ((ext = strrchr(filepath, '.'))) {
if ((ext = strrchr(filepath, '.')))
*ext = '\0';
ext++;
}
/* if the file is present in multiple formats, ensure we only put it into the list once */
for (i = 0; i < class->total_files; i++)
@ -1147,66 +1145,102 @@ static void ast_moh_destroy(void)
AST_RWLIST_UNLOCK(&mohclasses);
}
static int moh_cli(int fd, int argc, char *argv[])
static char *handle_cli_moh_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
switch (cmd) {
case CLI_INIT:
e->command = "moh reload";
e->usage =
"Usage: moh reload\n"
" Reloads the MusicOnHold module.\n"
" Alias for 'module reload res_musiconhold.so'\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
if (a->argc != e->args)
return CLI_SHOWUSAGE;
reload();
return 0;
return CLI_SUCCESS;
}
static int cli_files_show(int fd, int argc, char *argv[])
static char *handle_cli_moh_show_files(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
int i;
struct mohclass *class;
switch (cmd) {
case CLI_INIT:
e->command = "moh show files";
e->usage =
"Usage: moh show files\n"
" Lists all loaded file-based MusicOnHold classes and their\n"
" files.\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
if (a->argc != e->args)
return CLI_SHOWUSAGE;
AST_RWLIST_RDLOCK(&mohclasses);
AST_RWLIST_TRAVERSE(&mohclasses, class, list) {
if (!class->total_files)
continue;
ast_cli(fd, "Class: %s\n", class->name);
ast_cli(a->fd, "Class: %s\n", class->name);
for (i = 0; i < class->total_files; i++)
ast_cli(fd, "\tFile: %s\n", class->filearray[i]);
ast_cli(a->fd, "\tFile: %s\n", class->filearray[i]);
}
AST_RWLIST_UNLOCK(&mohclasses);
return 0;
return CLI_SUCCESS;
}
static int moh_classes_show(int fd, int argc, char *argv[])
static char *handle_cli_moh_show_classes(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct mohclass *class;
switch (cmd) {
case CLI_INIT:
e->command = "moh show classes";
e->usage =
"Usage: moh show classes\n"
" Lists all MusicOnHold classes.\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
if (a->argc != e->args)
return CLI_SHOWUSAGE;
AST_RWLIST_RDLOCK(&mohclasses);
AST_RWLIST_TRAVERSE(&mohclasses, class, list) {
ast_cli(fd, "Class: %s\n", class->name);
ast_cli(fd, "\tMode: %s\n", S_OR(class->mode, "<none>"));
ast_cli(fd, "\tDirectory: %s\n", S_OR(class->dir, "<none>"));
ast_cli(fd, "\tUse Count: %d\n", class->inuse);
ast_cli(a->fd, "Class: %s\n", class->name);
ast_cli(a->fd, "\tMode: %s\n", S_OR(class->mode, "<none>"));
ast_cli(a->fd, "\tDirectory: %s\n", S_OR(class->dir, "<none>"));
ast_cli(a->fd, "\tUse Count: %d\n", class->inuse);
if (class->digit)
ast_cli(fd, "\tDigit: %c\n", class->digit);
ast_cli(a->fd, "\tDigit: %c\n", class->digit);
if (ast_test_flag(class, MOH_CUSTOM))
ast_cli(fd, "\tApplication: %s\n", S_OR(class->args, "<none>"));
ast_cli(a->fd, "\tApplication: %s\n", S_OR(class->args, "<none>"));
if (strcasecmp(class->mode, "files"))
ast_cli(fd, "\tFormat: %s\n", ast_getformatname(class->format));
ast_cli(a->fd, "\tFormat: %s\n", ast_getformatname(class->format));
}
AST_RWLIST_UNLOCK(&mohclasses);
return 0;
return CLI_SUCCESS;
}
static struct ast_cli_entry cli_moh[] = {
{ { "moh", "reload"},
moh_cli, "Music On Hold",
"Music On Hold" },
{ { "moh", "show", "classes"},
moh_classes_show, "List MOH classes",
"Lists all MOH classes" },
{ { "moh", "show", "files"},
cli_files_show, "List MOH file-based classes",
"Lists all loaded file-based MOH classes and their files" },
NEW_CLI(handle_cli_moh_reload, "Reload MusicOnHold"),
NEW_CLI(handle_cli_moh_show_classes, "List MusicOnHold classes"),
NEW_CLI(handle_cli_moh_show_files, "List MusicOnHold file-based classes")
};
static int init_classes(int reload)

@ -333,47 +333,70 @@ static int load_odbc_config(void)
return res;
}
static int odbc_show_command(int fd, int argc, char **argv)
static char *handle_cli_odbc_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct odbc_class *class;
struct odbc_obj *current;
int length = 0;
int which = 0;
char *ret = NULL;
switch (cmd) {
case CLI_INIT:
e->command = "odbc show";
e->usage =
"Usage: odbc show [class]\n"
" List settings of a particular ODBC class or,\n"
" if not specified, all classes.\n";
return NULL;
case CLI_GENERATE:
if (a->pos != 2)
return NULL;
length = strlen(a->word);
AST_LIST_LOCK(&odbc_list);
AST_LIST_TRAVERSE(&odbc_list, class, list) {
if (!strncasecmp(a->word, class->name, length) && ++which > a->n) {
ret = ast_strdup(class->name);
break;
}
}
if (!ret && !strncasecmp(a->word, "all", length) && ++which > a->n) {
ret = ast_strdup("all");
}
AST_LIST_UNLOCK(&odbc_list);
return ret;
}
ast_cli(a->fd, "\nODBC DSN Settings\n");
ast_cli(a->fd, "-----------------\n\n");
AST_LIST_LOCK(&odbc_list);
AST_LIST_TRAVERSE(&odbc_list, class, list) {
if ((argc == 2) || (argc == 3 && !strcmp(argv[2], "all")) || (!strcmp(argv[2], class->name))) {
if ((a->argc == 2) || (a->argc == 3 && !strcmp(a->argv[2], "all")) || (!strcmp(a->argv[2], class->name))) {
int count = 0;
ast_cli(fd, "Name: %s\nDSN: %s\n", class->name, class->dsn);
ast_cli(a->fd, " Name: %s\n DSN: %s\n", class->name, class->dsn);
if (class->haspool) {
ast_cli(fd, "Pooled: yes\nLimit: %d\nConnections in use: %d\n", class->limit, class->count);
ast_cli(a->fd, " Pooled: Yes\n Limit: %d\n Connections in use: %d\n", class->limit, class->count);
AST_LIST_TRAVERSE(&(class->odbc_obj), current, list) {
ast_cli(fd, " Connection %d: %s\n", ++count, current->up && ast_odbc_sanity_check(current) ? "connected" : "disconnected");
ast_cli(a->fd, " - Connection %d: %s\n", ++count, current->up && ast_odbc_sanity_check(current) ? "Connected" : "Disconnected");
}
} else {
/* Should only ever be one of these */
AST_LIST_TRAVERSE(&(class->odbc_obj), current, list) {
ast_cli(fd, "Pooled: no\nConnected: %s\n", current->up && ast_odbc_sanity_check(current) ? "yes" : "no");
ast_cli(a->fd, " Pooled: No\n Connected: %s\n", current->up && ast_odbc_sanity_check(current) ? "Yes" : "No");
}
}
ast_cli(fd, "\n");
ast_cli(a->fd, "\n");
}
}
AST_LIST_UNLOCK(&odbc_list);
return 0;
return CLI_SUCCESS;
}
static const char show_usage[] =
"Usage: odbc show [<class>]\n"
" List settings of a particular ODBC class.\n"
" or, if not specified, all classes.\n";
static struct ast_cli_entry cli_odbc[] = {
{ { "odbc", "show", NULL },
odbc_show_command, "List ODBC DSN(s)",
show_usage },
NEW_CLI(handle_cli_odbc_show, "List ODBC DSN(s)")
};
static int odbc_register_class(struct odbc_class *class, int connect)

@ -47,68 +47,78 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/cli.h"
static int cli_realtime_load(int fd, int argc, char **argv)
static char *cli_realtime_load(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
char *header_format = "%30s %-30s\n";
struct ast_variable *var=NULL;
if(argc<5) {
ast_cli(fd, "You must supply a family name, a column to match on, and a value to match to.\n");
return RESULT_FAILURE;
switch (cmd) {
case CLI_INIT:
e->command = "realtime load";
e->usage =
"Usage: realtime load <family> <colmatch> <value>\n"
" Prints out a list of variables using the RealTime driver.\n"
" You must supply a family name, a column to match on, and a value to match to.\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
var = ast_load_realtime_all(argv[2], argv[3], argv[4], NULL);
if(var) {
ast_cli(fd, header_format, "Column Name", "Column Value");
ast_cli(fd, header_format, "--------------------", "--------------------");
while(var) {
ast_cli(fd, header_format, var->name, var->value);
if (a->argc < 5)
return CLI_SHOWUSAGE;
var = ast_load_realtime_all(a->argv[2], a->argv[3], a->argv[4], NULL);
if (var) {
ast_cli(a->fd, header_format, "Column Name", "Column Value");
ast_cli(a->fd, header_format, "--------------------", "--------------------");
while (var) {
ast_cli(a->fd, header_format, var->name, var->value);
var = var->next;
}
} else {
ast_cli(fd, "No rows found matching search criteria.\n");
ast_cli(a->fd, "No rows found matching search criteria.\n");
}
return RESULT_SUCCESS;
return CLI_SUCCESS;
}
static int cli_realtime_update(int fd, int argc, char **argv) {
static char *cli_realtime_update(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) {
int res = 0;
if(argc<7) {
ast_cli(fd, "You must supply a family name, a column to update on, a new value, column to match, and value to to match.\n");
ast_cli(fd, "Ex: realtime update sipfriends name bobsphone port 4343\n will execute SQL as UPDATE sipfriends SET port = 4343 WHERE name = bobsphone\n");
return RESULT_FAILURE;
switch (cmd) {
case CLI_INIT:
e->command = "realtime update";
e->usage =
"Usage: realtime update <family> <colupdate> <newvalue> <colmatch> <valuematch>\n"
" Update a single variable using the RealTime driver.\n"
" You must supply a family name, a column to update on, a new value, column to match, and value to match.\n"
" Ex: realtime update sipfriends name bobsphone port 4343\n"
" will execute SQL as UPDATE sipfriends SET port = 4343 WHERE name = bobsphone\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
res = ast_update_realtime(argv[2], argv[3], argv[4], argv[5], argv[6], NULL);
if (a->argc < 7)
return CLI_SHOWUSAGE;
res = ast_update_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], NULL);
if(res < 0) {
ast_cli(fd, "Failed to update. Check the debug log for possible SQL related entries.\n");
return RESULT_SUCCESS;
ast_cli(a->fd, "Failed to update. Check the debug log for possible SQL related entries.\n");
return CLI_FAILURE;
}
ast_cli(fd, "Updated %d RealTime record%s.\n", res, ESS(res));
ast_cli(a->fd, "Updated %d RealTime record%s.\n", res, ESS(res));
return RESULT_SUCCESS;
return CLI_SUCCESS;
}
static const char cli_realtime_load_usage[] =
"Usage: realtime load <family> <colmatch> <value>\n"
" Prints out a list of variables using the RealTime driver.\n";
static const char cli_realtime_update_usage[] =
"Usage: realtime update <family> <colmatch> <value>\n"
" Update a single variable using the RealTime driver.\n";
static struct ast_cli_entry cli_realtime[] = {
{ { "realtime", "load", NULL, NULL },
cli_realtime_load, "Used to print out RealTime variables.",
cli_realtime_load_usage, NULL },
{ { "realtime", "update", NULL, NULL },
cli_realtime_update, "Used to update RealTime variables.",
cli_realtime_update_usage, NULL },
NEW_CLI(cli_realtime_load, "Used to print out RealTime variables."),
NEW_CLI(cli_realtime_update, "Used to update RealTime variables."),
};
static int unload_module(void)

Loading…
Cancel
Save