aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorqwell <qwell@f38db490-d61c-443f-a65b-d21fe96a405b>2007-09-19 23:16:51 +0000
committerqwell <qwell@f38db490-d61c-443f-a65b-d21fe96a405b>2007-09-19 23:16:51 +0000
commita35dd640cdbbe41347f01d70d63065349d0d7f77 (patch)
tree61ab10502e5eb1c8290496cd125473dc3b78cc13
parente346df68a26ee68e3a5612add3ce1514146e1c4f (diff)
More conversions to NEW_CLI
(issue #10724) Patches: chan_zap.c.patch uploaded by moy (license 222) app_queue.c.patch uploaded by eliel (license 64) app_voicemail.c.patch uploaded by eliel (license 64) app_meetme.c.patch uploaded by eliel (license 64) git-svn-id: http://svn.digium.com/svn/asterisk/trunk@83213 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r--apps/app_meetme.c304
-rw-r--r--apps/app_queue.c240
-rw-r--r--apps/app_voicemail.c151
-rw-r--r--channels/chan_zap.c849
4 files changed, 831 insertions, 713 deletions
diff --git a/apps/app_meetme.c b/apps/app_meetme.c
index 8dfa382c2..da52f3a8b 100644
--- a/apps/app_meetme.c
+++ b/apps/app_meetme.c
@@ -845,7 +845,70 @@ cnfout:
return cnf;
}
-static int meetme_cmd(int fd, int argc, char **argv)
+
+static char *complete_meetmecmd(const char *line, const char *word, int pos, int state)
+{
+ static char *cmds[] = {"lock", "unlock", "mute", "unmute", "kick", "list", NULL};
+
+ int len = strlen(word);
+ int which = 0;
+ struct ast_conference *cnf = NULL;
+ struct ast_conf_user *usr = NULL;
+ char *confno = NULL;
+ char usrno[50] = "";
+ char *myline, *ret = NULL;
+
+ if (pos == 1) { /* Command */
+ return ast_cli_complete(word, cmds, state);
+ } else if (pos == 2) { /* Conference Number */
+ AST_LIST_LOCK(&confs);
+ AST_LIST_TRAVERSE(&confs, cnf, list) {
+ if (!strncasecmp(word, cnf->confno, len) && ++which > state) {
+ ret = cnf->confno;
+ break;
+ }
+ }
+ ret = ast_strdup(ret); /* dup before releasing the lock */
+ AST_LIST_UNLOCK(&confs);
+ return ret;
+ } else if (pos == 3) {
+ /* User Number || Conf Command option*/
+ if (strstr(line, "mute") || strstr(line, "kick")) {
+ if (state == 0 && (strstr(line, "kick") || strstr(line,"mute")) && !strncasecmp(word, "all", len))
+ return ast_strdup("all");
+ which++;
+ AST_LIST_LOCK(&confs);
+
+ /* TODO: Find the conf number from the cmdline (ignore spaces) <- test this and make it fail-safe! */
+ myline = ast_strdupa(line);
+ if (strsep(&myline, " ") && strsep(&myline, " ") && !confno) {
+ while((confno = strsep(&myline, " ")) && (strcmp(confno, " ") == 0))
+ ;
+ }
+
+ AST_LIST_TRAVERSE(&confs, cnf, list) {
+ if (!strcmp(confno, cnf->confno))
+ break;
+ }
+
+ if (cnf) {
+ /* Search for the user */
+ AST_LIST_TRAVERSE(&cnf->userlist, usr, list) {
+ snprintf(usrno, sizeof(usrno), "%d", usr->user_no);
+ if (!strncasecmp(word, usrno, len) && ++which > state)
+ break;
+ }
+ }
+ AST_LIST_UNLOCK(&confs);
+ return usr ? ast_strdup(usrno) : NULL;
+ } else if ( strstr(line, "list") && ( 0 == state ) )
+ return ast_strdup("concise");
+ }
+
+ return NULL;
+}
+
+static char *meetme_cmd(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
/* Process the command */
struct ast_conference *cnf;
@@ -857,23 +920,34 @@ static int meetme_cmd(int fd, int argc, char **argv)
char *data_format = "%-12.12s %4.4d %4.4s %02d:%02d:%02d %-8s %-6s\n";
char cmdline[1024] = "";
- if (argc > 8)
- ast_cli(fd, "Invalid Arguments.\n");
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "meetme";
+ e->usage =
+ "Usage: meetme (un)lock|(un)mute|kick|list [concise] <confno> <usernumber>\n"
+ " Executes a command for the conference or on a conferee\n";
+ return NULL;
+ case CLI_GENERATE:
+ return complete_meetmecmd(a->line, a->word, a->pos, a->n);
+ }
+
+ if (a->argc > 8)
+ ast_cli(a->fd, "Invalid Arguments.\n");
/* Check for length so no buffer will overflow... */
- for (i = 0; i < argc; i++) {
- if (strlen(argv[i]) > 100)
- ast_cli(fd, "Invalid Arguments.\n");
+ for (i = 0; i < a->argc; i++) {
+ if (strlen(a->argv[i]) > 100)
+ ast_cli(a->fd, "Invalid Arguments.\n");
}
- if (argc == 1) {
+ if (a->argc == 1) {
/* 'MeetMe': List all the conferences */
now = time(NULL);
AST_LIST_LOCK(&confs);
if (AST_LIST_EMPTY(&confs)) {
- ast_cli(fd, "No active MeetMe conferences.\n");
+ ast_cli(a->fd, "No active MeetMe conferences.\n");
AST_LIST_UNLOCK(&confs);
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
}
- ast_cli(fd, header_format, "Conf Num", "Parties", "Marked", "Activity", "Creation", "Locked");
+ ast_cli(a->fd, header_format, "Conf Num", "Parties", "Marked", "Activity", "Creation", "Locked");
AST_LIST_TRAVERSE(&confs, cnf, list) {
if (cnf->markedusers == 0)
strcpy(cmdline, "N/A ");
@@ -883,75 +957,75 @@ static int meetme_cmd(int fd, int argc, char **argv)
min = ((now - cnf->start) % 3600) / 60;
sec = (now - cnf->start) % 60;
- ast_cli(fd, data_format, cnf->confno, cnf->users, cmdline, hr, min, sec, cnf->isdynamic ? "Dynamic" : "Static", cnf->locked ? "Yes" : "No");
+ ast_cli(a->fd, data_format, cnf->confno, cnf->users, cmdline, hr, min, sec, cnf->isdynamic ? "Dynamic" : "Static", cnf->locked ? "Yes" : "No");
total += cnf->users;
}
AST_LIST_UNLOCK(&confs);
- ast_cli(fd, "* Total number of MeetMe users: %d\n", total);
- return RESULT_SUCCESS;
- }
- if (argc < 3)
- return RESULT_SHOWUSAGE;
- ast_copy_string(cmdline, argv[2], sizeof(cmdline)); /* Argv 2: conference number */
- if (strstr(argv[1], "lock")) {
- if (strcmp(argv[1], "lock") == 0) {
+ ast_cli(a->fd, "* Total number of MeetMe users: %d\n", total);
+ return CLI_SUCCESS;
+ }
+ if (a->argc < 3)
+ return CLI_SHOWUSAGE;
+ ast_copy_string(cmdline, a->argv[2], sizeof(cmdline)); /* Argv 2: conference number */
+ if (strstr(a->argv[1], "lock")) {
+ if (strcmp(a->argv[1], "lock") == 0) {
/* Lock */
strncat(cmdline, ",L", sizeof(cmdline) - strlen(cmdline) - 1);
} else {
/* Unlock */
strncat(cmdline, ",l", sizeof(cmdline) - strlen(cmdline) - 1);
}
- } else if (strstr(argv[1], "mute")) {
- if (argc < 4)
- return RESULT_SHOWUSAGE;
- if (strcmp(argv[1], "mute") == 0) {
+ } else if (strstr(a->argv[1], "mute")) {
+ if (a->argc < 4)
+ return CLI_SHOWUSAGE;
+ if (strcmp(a->argv[1], "mute") == 0) {
/* Mute */
- if (strcmp(argv[3], "all") == 0) {
+ if (strcmp(a->argv[3], "all") == 0) {
strncat(cmdline, ",N", sizeof(cmdline) - strlen(cmdline) - 1);
} else {
strncat(cmdline, ",M,", sizeof(cmdline) - strlen(cmdline) - 1);
- strncat(cmdline, argv[3], sizeof(cmdline) - strlen(cmdline) - 1);
+ strncat(cmdline, a->argv[3], sizeof(cmdline) - strlen(cmdline) - 1);
}
} else {
/* Unmute */
- if (strcmp(argv[3], "all") == 0) {
+ if (strcmp(a->argv[3], "all") == 0) {
strncat(cmdline, ",n", sizeof(cmdline) - strlen(cmdline) - 1);
} else {
strncat(cmdline, ",m,", sizeof(cmdline) - strlen(cmdline) - 1);
- strncat(cmdline, argv[3], sizeof(cmdline) - strlen(cmdline) - 1);
+ strncat(cmdline, a->argv[3], sizeof(cmdline) - strlen(cmdline) - 1);
}
}
- } else if (strcmp(argv[1], "kick") == 0) {
- if (argc < 4)
- return RESULT_SHOWUSAGE;
- if (strcmp(argv[3], "all") == 0) {
+ } else if (strcmp(a->argv[1], "kick") == 0) {
+ if (a->argc < 4)
+ return CLI_SHOWUSAGE;
+ if (strcmp(a->argv[3], "all") == 0) {
/* Kick all */
strncat(cmdline, ",K", sizeof(cmdline) - strlen(cmdline) - 1);
} else {
/* Kick a single user */
strncat(cmdline, ",k,", sizeof(cmdline) - strlen(cmdline) - 1);
- strncat(cmdline, argv[3], sizeof(cmdline) - strlen(cmdline) - 1);
+ strncat(cmdline, a->argv[3], sizeof(cmdline) - strlen(cmdline) - 1);
}
- } else if(strcmp(argv[1], "list") == 0) {
- int concise = ( 4 == argc && ( !strcasecmp(argv[3], "concise") ) );
+ } else if(strcmp(a->argv[1], "list") == 0) {
+ int concise = ( 4 == a->argc && ( !strcasecmp(a->argv[3], "concise") ) );
/* List all the users in a conference */
if (AST_LIST_EMPTY(&confs)) {
if ( !concise )
- ast_cli(fd, "No active conferences.\n");
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "No active conferences.\n");
+ return CLI_SUCCESS;
}
/* Find the right conference */
AST_LIST_LOCK(&confs);
AST_LIST_TRAVERSE(&confs, cnf, list) {
- if (strcmp(cnf->confno, argv[2]) == 0)
+ if (strcmp(cnf->confno, a->argv[2]) == 0)
break;
}
if (!cnf) {
if ( !concise )
- ast_cli(fd, "No such conference: %s.\n",argv[2]);
+ ast_cli(a->fd, "No such conference: %s.\n",a->argv[2]);
AST_LIST_UNLOCK(&confs);
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
}
/* Show all the users */
time(&now);
@@ -960,7 +1034,7 @@ static int meetme_cmd(int fd, int argc, char **argv)
min = ((now - user->jointime) % 3600) / 60;
sec = (now - user->jointime) % 60;
if ( !concise )
- ast_cli(fd, "User #: %-2.2d %12.12s %-20.20s Channel: %s %s %s %s %s %02d:%02d:%02d\n",
+ ast_cli(a->fd, "User #: %-2.2d %12.12s %-20.20s Channel: %s %s %s %s %s %02d:%02d:%02d\n",
user->user_no,
S_OR(user->chan->cid.cid_num, "<unknown>"),
S_OR(user->chan->cid.cid_name, "<no name>"),
@@ -970,7 +1044,7 @@ static int meetme_cmd(int fd, int argc, char **argv)
user->adminflags & ADMINFLAG_MUTED ? "(Admin Muted)" : user->adminflags & ADMINFLAG_SELFMUTED ? "(Muted)" : "",
istalking(user->talking), hr, min, sec);
else
- ast_cli(fd, "%d!%s!%s!%s!%s!%s!%s!%d!%02d:%02d:%02d\n",
+ ast_cli(a->fd, "%d!%s!%s!%s!%s!%s!%s!%d!%02d:%02d:%02d\n",
user->user_no,
S_OR(user->chan->cid.cid_num, ""),
S_OR(user->chan->cid.cid_name, ""),
@@ -982,84 +1056,18 @@ static int meetme_cmd(int fd, int argc, char **argv)
}
if ( !concise )
- ast_cli(fd,"%d users in that conference.\n",cnf->users);
+ ast_cli(a->fd,"%d users in that conference.\n",cnf->users);
AST_LIST_UNLOCK(&confs);
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
} else
- return RESULT_SHOWUSAGE;
+ return CLI_SHOWUSAGE;
ast_debug(1, "Cmdline: %s\n", cmdline);
admin_exec(NULL, cmdline);
- return 0;
-}
-
-static char *complete_meetmecmd(const char *line, const char *word, int pos, int state)
-{
- static char *cmds[] = {"lock", "unlock", "mute", "unmute", "kick", "list", NULL};
-
- int len = strlen(word);
- int which = 0;
- struct ast_conference *cnf = NULL;
- struct ast_conf_user *usr = NULL;
- char *confno = NULL;
- char usrno[50] = "";
- char *myline, *ret = NULL;
-
- if (pos == 1) { /* Command */
- return ast_cli_complete(word, cmds, state);
- } else if (pos == 2) { /* Conference Number */
- AST_LIST_LOCK(&confs);
- AST_LIST_TRAVERSE(&confs, cnf, list) {
- if (!strncasecmp(word, cnf->confno, len) && ++which > state) {
- ret = cnf->confno;
- break;
- }
- }
- ret = ast_strdup(ret); /* dup before releasing the lock */
- AST_LIST_UNLOCK(&confs);
- return ret;
- } else if (pos == 3) {
- /* User Number || Conf Command option*/
- if (strstr(line, "mute") || strstr(line, "kick")) {
- if (state == 0 && (strstr(line, "kick") || strstr(line,"mute")) && !strncasecmp(word, "all", len))
- return ast_strdup("all");
- which++;
- AST_LIST_LOCK(&confs);
-
- /* TODO: Find the conf number from the cmdline (ignore spaces) <- test this and make it fail-safe! */
- myline = ast_strdupa(line);
- if (strsep(&myline, " ") && strsep(&myline, " ") && !confno) {
- while((confno = strsep(&myline, " ")) && (strcmp(confno, " ") == 0))
- ;
- }
-
- AST_LIST_TRAVERSE(&confs, cnf, list) {
- if (!strcmp(confno, cnf->confno))
- break;
- }
-
- if (cnf) {
- /* Search for the user */
- AST_LIST_TRAVERSE(&cnf->userlist, usr, list) {
- snprintf(usrno, sizeof(usrno), "%d", usr->user_no);
- if (!strncasecmp(word, usrno, len) && ++which > state)
- break;
- }
- }
- AST_LIST_UNLOCK(&confs);
- return usr ? ast_strdup(usrno) : NULL;
- } else if ( strstr(line, "list") && ( 0 == state ) )
- return ast_strdup("concise");
- }
-
- return NULL;
+ return CLI_SUCCESS;
}
-
-static const char meetme_usage[] =
-"Usage: meetme (un)lock|(un)mute|kick|list [concise] <confno> <usernumber>\n"
-" Executes a command for the conference or on a conferee\n";
static const char *sla_hold_str(unsigned int hold_access)
{
@@ -1078,11 +1086,22 @@ static const char *sla_hold_str(unsigned int hold_access)
return hold;
}
-static int sla_show_trunks(int fd, int argc, char **argv)
+static char *sla_show_trunks(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
const struct sla_trunk *trunk;
- ast_cli(fd, "\n"
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "sla show trunks";
+ e->usage =
+ "Usage: sla show trunks\n"
+ " This will list all trunks defined in sla.conf\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ ast_cli(a->fd, "\n"
"=============================================================\n"
"=== Configured SLA Trunks ===================================\n"
"=============================================================\n"
@@ -1093,7 +1112,7 @@ static int sla_show_trunks(int fd, int argc, char **argv)
char ring_timeout[16] = "(none)";
if (trunk->ring_timeout)
snprintf(ring_timeout, sizeof(ring_timeout), "%u Seconds", trunk->ring_timeout);
- ast_cli(fd, "=== ---------------------------------------------------------\n"
+ ast_cli(a->fd, "=== ---------------------------------------------------------\n"
"=== Trunk Name: %s\n"
"=== ==> Device: %s\n"
"=== ==> AutoContext: %s\n"
@@ -1108,16 +1127,14 @@ static int sla_show_trunks(int fd, int argc, char **argv)
sla_hold_str(trunk->hold_access));
AST_RWLIST_RDLOCK(&sla_stations);
AST_LIST_TRAVERSE(&trunk->stations, station_ref, entry)
- ast_cli(fd, "=== ==> Station name: %s\n", station_ref->station->name);
+ ast_cli(a->fd, "=== ==> Station name: %s\n", station_ref->station->name);
AST_RWLIST_UNLOCK(&sla_stations);
- ast_cli(fd, "=== ---------------------------------------------------------\n"
- "===\n");
+ ast_cli(a->fd, "=== ---------------------------------------------------------\n===\n");
}
AST_RWLIST_UNLOCK(&sla_trunks);
- ast_cli(fd, "=============================================================\n"
- "\n");
+ ast_cli(a->fd, "=============================================================\n\n");
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
}
static const char *trunkstate2str(enum sla_trunk_state state)
@@ -1134,15 +1151,22 @@ static const char *trunkstate2str(enum sla_trunk_state state)
#undef S
}
-static const char sla_show_trunks_usage[] =
-"Usage: sla show trunks\n"
-" This will list all trunks defined in sla.conf\n";
-
-static int sla_show_stations(int fd, int argc, char **argv)
+static char *sla_show_stations(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
const struct sla_station *station;
- ast_cli(fd, "\n"
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "sla show stations";
+ e->usage =
+ "Usage: sla show stations\n"
+ " This will list all stations defined in sla.conf\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ ast_cli(a->fd, "\n"
"=============================================================\n"
"=== Configured SLA Stations =================================\n"
"=============================================================\n"
@@ -1160,7 +1184,7 @@ static int sla_show_stations(int fd, int argc, char **argv)
snprintf(ring_delay, sizeof(ring_delay),
"%u", station->ring_delay);
}
- ast_cli(fd, "=== ---------------------------------------------------------\n"
+ ast_cli(a->fd, "=== ---------------------------------------------------------\n"
"=== Station Name: %s\n"
"=== ==> Device: %s\n"
"=== ==> AutoContext: %s\n"
@@ -1184,7 +1208,7 @@ static int sla_show_stations(int fd, int argc, char **argv)
"%u", trunk_ref->ring_delay);
} else
strcpy(ring_delay, "(none)");
- ast_cli(fd, "=== ==> Trunk Name: %s\n"
+ ast_cli(a->fd, "=== ==> Trunk Name: %s\n"
"=== ==> State: %s\n"
"=== ==> RingTimeout: %s\n"
"=== ==> RingDelay: %s\n",
@@ -1193,32 +1217,20 @@ static int sla_show_stations(int fd, int argc, char **argv)
ring_timeout, ring_delay);
}
AST_RWLIST_UNLOCK(&sla_trunks);
- ast_cli(fd, "=== ---------------------------------------------------------\n"
+ ast_cli(a->fd, "=== ---------------------------------------------------------\n"
"===\n");
}
AST_RWLIST_UNLOCK(&sla_stations);
- ast_cli(fd, "============================================================\n"
+ ast_cli(a->fd, "============================================================\n"
"\n");
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
}
-static const char sla_show_stations_usage[] =
-"Usage: sla show stations\n"
-" This will list all stations defined in sla.conf\n";
-
static struct ast_cli_entry cli_meetme[] = {
- { { "meetme", NULL, NULL },
- meetme_cmd, "Execute a command on a conference or conferee",
- meetme_usage, complete_meetmecmd },
-
- { { "sla", "show", "trunks", NULL },
- sla_show_trunks, "Show SLA Trunks",
- sla_show_trunks_usage, NULL },
-
- { { "sla", "show", "stations", NULL },
- sla_show_stations, "Show SLA Stations",
- sla_show_stations_usage, NULL },
+ NEW_CLI(meetme_cmd, "Execute a command on a conference or conferee"),
+ NEW_CLI(sla_show_trunks, "Show SLA Trunks"),
+ NEW_CLI(sla_show_stations, "Show SLA Stations"),
};
static void conf_flush(int fd, struct ast_channel *chan)
diff --git a/apps/app_queue.c b/apps/app_queue.c
index d5f1e48ac..1db2fc273 100644
--- a/apps/app_queue.c
+++ b/apps/app_queue.c
@@ -4248,7 +4248,7 @@ static void do_print(struct mansession *s, int fd, const char *str)
ast_cli(fd, "%s\n", str);
}
-static int __queues_show(struct mansession *s, int fd, int argc, char **argv)
+static char *__queues_show(struct mansession *s, int fd, int argc, char **argv)
{
struct call_queue *q;
struct ast_str *out = ast_str_alloca(240);
@@ -4257,7 +4257,7 @@ static int __queues_show(struct mansession *s, int fd, int argc, char **argv)
struct ao2_iterator mem_iter;
if (argc != 2 && argc != 3)
- return RESULT_SHOWUSAGE;
+ return CLI_SHOWUSAGE;
/* We only want to load realtime queues when a specific queue is asked for. */
if (argc == 3) /* specific queue */
@@ -4338,12 +4338,7 @@ static int __queues_show(struct mansession *s, int fd, int argc, char **argv)
ast_str_set(&out, 0, "No queues.");
do_print(s, fd, out->str);
}
- return RESULT_SUCCESS;
-}
-
-static int queue_show(int fd, int argc, char **argv)
-{
- return __queues_show(NULL, fd, argc, argv);
+ return CLI_SUCCESS;
}
static char *complete_queue(const char *line, const char *word, int pos, int state)
@@ -4352,11 +4347,11 @@ static char *complete_queue(const char *line, const char *word, int pos, int sta
char *ret = NULL;
int which = 0;
int wordlen = strlen(word);
-
+
AST_LIST_LOCK(&queues);
AST_LIST_TRAVERSE(&queues, q, list) {
if (!strncasecmp(word, q->name, wordlen) && ++which > state) {
- ret = ast_strdup(q->name);
+ ret = ast_strdup(q->name);
break;
}
}
@@ -4372,6 +4367,22 @@ static char *complete_queue_show(const char *line, const char *word, int pos, in
return NULL;
}
+static char *queue_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+ switch ( cmd ) {
+ case CLI_INIT:
+ e->command = "queue show";
+ e->usage =
+ "Usage: queue show\n"
+ " Provides summary information on a specified queue.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return complete_queue_show(a->line, a->word, a->pos, a->n);
+ }
+
+ return __queues_show(NULL, a->fd, a->argc, a->argv);
+}
+
/*!\brief callback to display queues status in manager
\addtogroup Group_AMI
*/
@@ -4667,74 +4678,20 @@ static int manager_queue_log_custom(struct mansession *s, const struct message *
return 0;
}
-static int handle_queue_add_member(int fd, int argc, char *argv[])
-{
- char *queuename, *interface, *membername = NULL;
- int penalty;
-
- if ((argc != 6) && (argc != 8) && (argc != 10)) {
- return RESULT_SHOWUSAGE;
- } else if (strcmp(argv[4], "to")) {
- return RESULT_SHOWUSAGE;
- } else if ((argc == 8) && strcmp(argv[6], "penalty")) {
- return RESULT_SHOWUSAGE;
- } else if ((argc == 10) && strcmp(argv[8], "as")) {
- return RESULT_SHOWUSAGE;
- }
-
- queuename = argv[5];
- interface = argv[3];
- if (argc >= 8) {
- if (sscanf(argv[7], "%d", &penalty) == 1) {
- if (penalty < 0) {
- ast_cli(fd, "Penalty must be >= 0\n");
- penalty = 0;
- }
- } else {
- ast_cli(fd, "Penalty must be an integer >= 0\n");
- penalty = 0;
- }
- } else {
- penalty = 0;
- }
-
- if (argc >= 10) {
- membername = argv[9];
- }
-
- switch (add_to_queue(queuename, interface, membername, penalty, 0, queue_persistent_members)) {
- case RES_OKAY:
- ast_queue_log(queuename, "CLI", interface, "ADDMEMBER", "%s", "");
- ast_cli(fd, "Added interface '%s' to queue '%s'\n", interface, queuename);
- return RESULT_SUCCESS;
- case RES_EXISTS:
- ast_cli(fd, "Unable to add interface '%s' to queue '%s': Already there\n", interface, queuename);
- return RESULT_FAILURE;
- case RES_NOSUCHQUEUE:
- ast_cli(fd, "Unable to add interface to queue '%s': No such queue\n", queuename);
- return RESULT_FAILURE;
- case RES_OUTOFMEMORY:
- ast_cli(fd, "Out of memory\n");
- return RESULT_FAILURE;
- default:
- return RESULT_FAILURE;
- }
-}
-
static char *complete_queue_add_member(const char *line, const char *word, int pos, int state)
{
/* 0 - queue; 1 - add; 2 - member; 3 - <interface>; 4 - to; 5 - <queue>; 6 - penalty; 7 - <penalty>; 8 - as; 9 - <membername> */
switch (pos) {
- case 3: /* Don't attempt to complete name of interface (infinite possibilities) */
+ case 3: /* Don't attempt to complete name of interface (infinite possibilities) */
return NULL;
- case 4: /* only one possible match, "to" */
+ case 4: /* only one possible match, "to" */
return state == 0 ? ast_strdup("to") : NULL;
- case 5: /* <queue> */
+ case 5: /* <queue> */
return complete_queue(line, word, pos, state);
case 6: /* only one possible match, "penalty" */
return state == 0 ? ast_strdup("penalty") : NULL;
case 7:
- if (state < 100) { /* 0-99 */
+ if (state < 100) { /* 0-99 */
char *num;
if ((num = ast_malloc(3))) {
sprintf(num, "%d", state);
@@ -4745,42 +4702,74 @@ static char *complete_queue_add_member(const char *line, const char *word, int p
}
case 8: /* only one possible match, "as" */
return state == 0 ? ast_strdup("as") : NULL;
- case 9: /* Don't attempt to complete name of member (infinite possibilities) */
+ case 9: /* Don't attempt to complete name of member (infinite possibilities) */
return NULL;
default:
return NULL;
}
}
-static int handle_queue_remove_member(int fd, int argc, char *argv[])
+static char *handle_queue_add_member(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
- char *queuename, *interface;
+ char *queuename, *interface, *membername = NULL;
+ int penalty;
- if (argc != 6) {
- return RESULT_SHOWUSAGE;
- } else if (strcmp(argv[4], "from")) {
- return RESULT_SHOWUSAGE;
+ switch ( cmd ) {
+ case CLI_INIT:
+ e->command = "queue add member";
+ e->usage =
+ "Usage: queue add member <channel> to <queue> [penalty <penalty>]\n";
+ return NULL;
+ case CLI_GENERATE:
+ return complete_queue_add_member(a->line, a->word, a->pos, a->n);
}
- queuename = argv[5];
- interface = argv[3];
+ if ((a->argc != 6) && (a->argc != 8) && (a->argc != 10)) {
+ return CLI_SHOWUSAGE;
+ } else if (strcmp(a->argv[4], "to")) {
+ return CLI_SHOWUSAGE;
+ } else if ((a->argc == 8) && strcmp(a->argv[6], "penalty")) {
+ return CLI_SHOWUSAGE;
+ } else if ((a->argc == 10) && strcmp(a->argv[8], "as")) {
+ return CLI_SHOWUSAGE;
+ }
- switch (remove_from_queue(queuename, interface)) {
+ queuename = a->argv[5];
+ interface = a->argv[3];
+ if (a->argc >= 8) {
+ if (sscanf(a->argv[7], "%d", &penalty) == 1) {
+ if (penalty < 0) {
+ ast_cli(a->fd, "Penalty must be >= 0\n");
+ penalty = 0;
+ }
+ } else {
+ ast_cli(a->fd, "Penalty must be an integer >= 0\n");
+ penalty = 0;
+ }
+ } else {
+ penalty = 0;
+ }
+
+ if (a->argc >= 10) {
+ membername = a->argv[9];
+ }
+
+ switch (add_to_queue(queuename, interface, membername, penalty, 0, queue_persistent_members)) {
case RES_OKAY:
- ast_queue_log(queuename, "CLI", interface, "REMOVEMEMBER", "%s", "");
- ast_cli(fd, "Removed interface '%s' from queue '%s'\n", interface, queuename);
- return RESULT_SUCCESS;
+ ast_queue_log(queuename, "CLI", interface, "ADDMEMBER", "%s", "");
+ ast_cli(a->fd, "Added interface '%s' to queue '%s'\n", interface, queuename);
+ return CLI_SUCCESS;
case RES_EXISTS:
- ast_cli(fd, "Unable to remove interface '%s' from queue '%s': Not there\n", interface, queuename);
- return RESULT_FAILURE;
+ ast_cli(a->fd, "Unable to add interface '%s' to queue '%s': Already there\n", interface, queuename);
+ return CLI_FAILURE;
case RES_NOSUCHQUEUE:
- ast_cli(fd, "Unable to remove interface from queue '%s': No such queue\n", queuename);
- return RESULT_FAILURE;
+ ast_cli(a->fd, "Unable to add interface to queue '%s': No such queue\n", queuename);
+ return CLI_FAILURE;
case RES_OUTOFMEMORY:
- ast_cli(fd, "Out of memory\n");
- return RESULT_FAILURE;
+ ast_cli(a->fd, "Out of memory\n");
+ return CLI_FAILURE;
default:
- return RESULT_FAILURE;
+ return CLI_FAILURE;
}
}
@@ -4790,14 +4779,15 @@ static char *complete_queue_remove_member(const char *line, const char *word, in
struct call_queue *q;
struct member *m;
struct ao2_iterator mem_iter;
+ int wordlen = strlen(word);
/* 0 - queue; 1 - remove; 2 - member; 3 - <member>; 4 - from; 5 - <queue> */
if (pos > 5 || pos < 3)
return NULL;
- if (pos == 4) /* only one possible match, 'from' */
- return state == 0 ? ast_strdup("from") : NULL;
+ if (pos == 4) /* only one possible match, 'from' */
+ return (state == 0 ? ast_strdup("from") : NULL);
- if (pos == 5) /* No need to duplicate code */
+ if (pos == 5) /* No need to duplicate code */
return complete_queue(line, word, pos, state);
/* here is the case for 3, <member> */
@@ -4806,7 +4796,7 @@ static char *complete_queue_remove_member(const char *line, const char *word, in
ast_mutex_lock(&q->lock);
mem_iter = ao2_iterator_init(q->members, 0);
while ((m = ao2_iterator_next(&mem_iter))) {
- if (++which > state) {
+ if (!strncasecmp(word, m->membername, wordlen) && ++which > state) {
char *tmp;
ast_mutex_unlock(&q->lock);
tmp = m->membername;
@@ -4822,6 +4812,47 @@ static char *complete_queue_remove_member(const char *line, const char *word, in
return NULL;
}
+static char *handle_queue_remove_member(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+ char *queuename, *interface;
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "queue remove member";
+ e->usage = "Usage: queue remove member <channel> from <queue>\n";
+ return NULL;
+ case CLI_GENERATE:
+ return complete_queue_remove_member(a->line, a->word, a->pos, a->n);
+ }
+
+ if (a->argc != 6) {
+ return CLI_SHOWUSAGE;
+ } else if (strcmp(a->argv[4], "from")) {
+ return CLI_SHOWUSAGE;
+ }
+
+ queuename = a->argv[5];
+ interface = a->argv[3];
+
+ switch (remove_from_queue(queuename, interface)) {
+ case RES_OKAY:
+ ast_queue_log(queuename, "CLI", interface, "REMOVEMEMBER", "%s", "");
+ ast_cli(a->fd, "Removed interface '%s' from queue '%s'\n", interface, queuename);
+ return CLI_SUCCESS;
+ case RES_EXISTS:
+ ast_cli(a->fd, "Unable to remove interface '%s' from queue '%s': Not there\n", interface, queuename);
+ return CLI_FAILURE;
+ case RES_NOSUCHQUEUE:
+ ast_cli(a->fd, "Unable to remove interface from queue '%s': No such queue\n", queuename);
+ return CLI_FAILURE;
+ case RES_OUTOFMEMORY:
+ ast_cli(a->fd, "Out of memory\n");
+ return CLI_FAILURE;
+ default:
+ return CLI_FAILURE;
+ }
+}
+
static char *complete_queue_pause_member(const char *line, const char *word, int pos, int state)
{
/* 0 - queue; 1 - pause; 2 - member; 3 - <interface>; 4 - queue; 5 - <queue>; 6 - reason; 7 - <reason> */
@@ -4892,16 +4923,6 @@ static char *handle_queue_pause_member(struct ast_cli_entry *e, int cmd, struct
}
}
-static const char queue_show_usage[] =
-"Usage: queue show\n"
-" Provides summary information on a specified queue.\n";
-
-static const char qam_cmd_usage[] =
-"Usage: queue add member <channel> to <queue> [penalty <penalty>]\n";
-
-static const char qrm_cmd_usage[] =
-"Usage: queue remove member <channel> from <queue>\n";
-
static const char qpm_cmd_usage[] =
"Usage: queue pause member <channel> in <queue> reason <reason>\n";
@@ -4909,18 +4930,9 @@ static const char qum_cmd_usage[] =
"Usage: queue unpause member <channel> in <queue> reason <reason>\n";
static struct ast_cli_entry cli_queue[] = {
- { { "queue", "show", NULL },
- queue_show, "Show status of a specified queue",
- queue_show_usage, complete_queue_show, NULL },
-
- { { "queue", "add", "member", NULL },
- handle_queue_add_member, "Add a channel to a specified queue",
- qam_cmd_usage, complete_queue_add_member, NULL },
-
- { { "queue", "remove", "member", NULL },
- handle_queue_remove_member, "Removes a channel from a specified queue",
- qrm_cmd_usage, complete_queue_remove_member, NULL },
-
+ NEW_CLI(queue_show, "Show status of a specified queue"),
+ NEW_CLI(handle_queue_add_member, "Add a channel to a specified queue"),
+ NEW_CLI(handle_queue_remove_member, "Removes a channel from a specified queue"),
NEW_CLI(handle_queue_pause_member, "Pause or unpause a queue member"),
};
diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c
index 934deb9c1..c4dd7fd27 100644
--- a/apps/app_voicemail.c
+++ b/apps/app_voicemail.c
@@ -7570,22 +7570,14 @@ static int vmauthenticate(struct ast_channel *chan, void *data)
return res;
}
-static const char voicemail_show_users_help[] =
-"Usage: voicemail show users [for <context>]\n"
-" Lists all mailboxes currently set up\n";
-
-static const char voicemail_show_zones_help[] =
-"Usage: voicemail show zones\n"
-" Lists zone message formats\n";
-
-static int show_users_realtime(int fd, const char *context)
+static char *show_users_realtime(int fd, const char *context)
{
struct ast_config *cfg;
const char *cat = NULL;
if (!(cfg = ast_load_realtime_multientry("voicemail",
"context", context, NULL))) {
- return RESULT_FAILURE;
+ return CLI_FAILURE;
}
ast_cli(fd, "\n"
@@ -7608,41 +7600,76 @@ static int show_users_realtime(int fd, const char *context)
ast_cli(fd, "=============================================================\n"
"\n");
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
+}
+
+static char *complete_voicemail_show_users(const char *line, const char *word, int pos, int state)
+{
+ int which = 0;
+ int wordlen;
+ struct ast_vm_user *vmu;
+ const char *context = "";
+
+ /* 0 - show; 1 - voicemail; 2 - users; 3 - for; 4 - <context> */
+ if (pos > 4)
+ return NULL;
+ if (pos == 3)
+ return (state == 0) ? ast_strdup("for") : NULL;
+ wordlen = strlen(word);
+ AST_LIST_TRAVERSE(&users, vmu, list) {
+ if (!strncasecmp(word, vmu->context, wordlen)) {
+ if (context && strcmp(context, vmu->context) && ++which > state)
+ return ast_strdup(vmu->context);
+ /* ignore repeated contexts ? */
+ context = vmu->context;
+ }
+ }
+ return NULL;
}
/*! \brief Show a list of voicemail users in the CLI */
-static int handle_voicemail_show_users(int fd, int argc, char *argv[])
+static char *handle_voicemail_show_users(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct ast_vm_user *vmu;
char *output_format = "%-10s %-5s %-25s %-10s %6s\n";
const char *context = NULL;
int users_counter = 0;
- if ((argc < 3) || (argc > 5) || (argc == 4))
- return RESULT_SHOWUSAGE;
- if (argc == 5) {
- if (strcmp(argv[3],"for"))
- return RESULT_SHOWUSAGE;
- context = argv[4];
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "voicemail show users";
+ e->usage =
+ "Usage: voicemail show users [for <context>]\n"
+ " Lists all mailboxes currently set up\n";
+ return NULL;
+ case CLI_GENERATE:
+ return complete_voicemail_show_users(a->line, a->word, a->pos, a->n);
+ }
+
+ if ((a->argc < 3) || (a->argc > 5) || (a->argc == 4))
+ return CLI_SHOWUSAGE;
+ if (a->argc == 5) {
+ if (strcmp(a->argv[3],"for"))
+ return CLI_SHOWUSAGE;
+ context = a->argv[4];
}
if (ast_check_realtime("voicemail")) {
if (!context) {
- ast_cli(fd, "You must specify a specific context to show users from realtime!\n");
- return RESULT_SHOWUSAGE;
+ ast_cli(a->fd, "You must specify a specific context to show users from realtime!\n");
+ return CLI_SHOWUSAGE;
}
- return show_users_realtime(fd, context);
+ return show_users_realtime(a->fd, context);
}
AST_LIST_LOCK(&users);
if (AST_LIST_EMPTY(&users)) {
- ast_cli(fd, "There are no voicemail users currently defined\n");
+ ast_cli(a->fd, "There are no voicemail users currently defined\n");
AST_LIST_UNLOCK(&users);
- return RESULT_FAILURE;
+ return CLI_FAILURE;
}
- if (argc == 3)
- ast_cli(fd, output_format, "Context", "Mbox", "User", "Zone", "NewMsg");
+ if (a->argc == 3)
+ ast_cli(a->fd, output_format, "Context", "Mbox", "User", "Zone", "NewMsg");
else {
int count = 0;
AST_LIST_TRAVERSE(&users, vmu, list) {
@@ -7650,87 +7677,69 @@ static int handle_voicemail_show_users(int fd, int argc, char *argv[])
count++;
}
if (count) {
- ast_cli(fd, output_format, "Context", "Mbox", "User", "Zone", "NewMsg");
+ ast_cli(a->fd, output_format, "Context", "Mbox", "User", "Zone", "NewMsg");
} else {
- ast_cli(fd, "No such voicemail context \"%s\"\n", context);
+ ast_cli(a->fd, "No such voicemail context \"%s\"\n", context);
AST_LIST_UNLOCK(&users);
- return RESULT_FAILURE;
+ return CLI_FAILURE;
}
}
AST_LIST_TRAVERSE(&users, vmu, list) {
int newmsgs = 0, oldmsgs = 0;
char count[12], tmp[256] = "";
- if ((argc == 3) || ((argc == 5) && !strcmp(context, vmu->context))) {
+ if ((a->argc == 3) || ((a->argc == 5) && !strcmp(context, vmu->context))) {
snprintf(tmp, sizeof(tmp), "%s@%s", vmu->mailbox, ast_strlen_zero(vmu->context) ? "default" : vmu->context);
inboxcount(tmp, &newmsgs, &oldmsgs);
snprintf(count,sizeof(count),"%d",newmsgs);
- ast_cli(fd, output_format, vmu->context, vmu->mailbox, vmu->fullname, vmu->zonetag, count);
+ ast_cli(a->fd, output_format, vmu->context, vmu->mailbox, vmu->fullname, vmu->zonetag, count);
users_counter++;
}
}
AST_LIST_UNLOCK(&users);
- ast_cli(fd, "%d voicemail users configured.\n", users_counter);
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "%d voicemail users configured.\n", users_counter);
+ return CLI_SUCCESS;
}
/*! \brief Show a list of voicemail zones in the CLI */
-static int handle_voicemail_show_zones(int fd, int argc, char *argv[])
+static char *handle_voicemail_show_zones(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct vm_zone *zone;
char *output_format = "%-15s %-20s %-45s\n";
- int res = RESULT_SUCCESS;
+ char *res = CLI_SUCCESS;
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "voicemail show zones";
+ e->usage =
+ "Usage: voicemail show zones\n"
+ " Lists zone message formats\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
- if (argc != 3)
- return RESULT_SHOWUSAGE;
+ if (a->argc != 3)
+ return CLI_SHOWUSAGE;
AST_LIST_LOCK(&zones);
if (!AST_LIST_EMPTY(&zones)) {
- ast_cli(fd, output_format, "Zone", "Timezone", "Message Format");
+ ast_cli(a->fd, output_format, "Zone", "Timezone", "Message Format");
AST_LIST_TRAVERSE(&zones, zone, list) {
- ast_cli(fd, output_format, zone->name, zone->timezone, zone->msg_format);
+ ast_cli(a->fd, output_format, zone->name, zone->timezone, zone->msg_format);
}
} else {
- ast_cli(fd, "There are no voicemail zones currently defined\n");
- res = RESULT_FAILURE;
+ ast_cli(a->fd, "There are no voicemail zones currently defined\n");
+ res = CLI_FAILURE;
}
AST_LIST_UNLOCK(&zones);
return res;
}
-static char *complete_voicemail_show_users(const char *line, const char *word, int pos, int state)
-{
- int which = 0;
- int wordlen;
- struct ast_vm_user *vmu;
- const char *context = "";
-
- /* 0 - show; 1 - voicemail; 2 - users; 3 - for; 4 - <context> */
- if (pos > 4)
- return NULL;
- if (pos == 3)
- return (state == 0) ? ast_strdup("for") : NULL;
- wordlen = strlen(word);
- AST_LIST_TRAVERSE(&users, vmu, list) {
- if (!strncasecmp(word, vmu->context, wordlen)) {
- if (context && strcmp(context, vmu->context) && ++which > state)
- return ast_strdup(vmu->context);
- /* ignore repeated contexts ? */
- context = vmu->context;
- }
- }
- return NULL;
-}
-
static struct ast_cli_entry cli_voicemail[] = {
- { { "voicemail", "show", "users", NULL },
- handle_voicemail_show_users, "List defined voicemail boxes",
- voicemail_show_users_help, complete_voicemail_show_users, NULL },
-
- { { "voicemail", "show", "zones", NULL },
- handle_voicemail_show_zones, "List zone message formats",
- voicemail_show_zones_help, NULL, NULL },
+ NEW_CLI(handle_voicemail_show_users, "List defined voicemail boxes"),
+ NEW_CLI(handle_voicemail_show_zones, "List zone message formats"),
};
static void poll_subscribed_mailboxes(void)
diff --git a/channels/chan_zap.c b/channels/chan_zap.c
index e770db2d1..d7b21e158 100644
--- a/channels/chan_zap.c
+++ b/channels/chan_zap.c
@@ -10463,61 +10463,88 @@ static char *complete_span_5(const char *line, const char *word, int pos, int st
return complete_span_helper(line,word,pos,state,4);
}
-static int handle_pri_set_debug_file(int fd, int argc, char **argv)
+static char *handle_pri_unset_debug_file(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "pri unset debug file";
+ e->usage = "Usage: pri unset debug file\n"
+ " Stop sending debug output to the previously \n"
+ " specified file\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+ /* Assume it is unset */
+ ast_mutex_lock(&pridebugfdlock);
+ close(pridebugfd);
+ pridebugfd = -1;
+ ast_cli(a->fd, "PRI debug output to file disabled\n");
+ ast_mutex_unlock(&pridebugfdlock);
+ return CLI_SUCCESS;
+}
+
+static char *handle_pri_set_debug_file(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
int myfd;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "pri set debug file";
+ e->usage = "Usage: pri set debug file [output-file]\n"
+ " Sends PRI debug output to the specified output file\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+ if (a->argc < 5)
+ return CLI_SHOWUSAGE;
- if (!strncasecmp(argv[1], "set", 3)) {
- if (argc < 5)
- return RESULT_SHOWUSAGE;
-
- if (ast_strlen_zero(argv[4]))
- return RESULT_SHOWUSAGE;
-
- myfd = open(argv[4], O_CREAT|O_WRONLY, AST_FILE_MODE);
- if (myfd < 0) {
- ast_cli(fd, "Unable to open '%s' for writing\n", argv[4]);
- return RESULT_SUCCESS;
- }
-
- ast_mutex_lock(&pridebugfdlock);
+ if (ast_strlen_zero(a->argv[4]))
+ return CLI_SHOWUSAGE;
- if (pridebugfd >= 0)
- close(pridebugfd);
+ myfd = open(a->argv[4], O_CREAT|O_WRONLY, AST_FILE_MODE);
+ if (myfd < 0) {
+ ast_cli(a->fd, "Unable to open '%s' for writing\n", a->argv[4]);
+ return CLI_SUCCESS;
+ }
- pridebugfd = myfd;
- ast_copy_string(pridebugfilename,argv[4],sizeof(pridebugfilename));
-
- ast_mutex_unlock(&pridebugfdlock);
+ ast_mutex_lock(&pridebugfdlock);
- ast_cli(fd, "PRI debug output will be sent to '%s'\n", argv[4]);
- } else {
- /* Assume it is unset */
- ast_mutex_lock(&pridebugfdlock);
+ if (pridebugfd >= 0)
close(pridebugfd);
- pridebugfd = -1;
- ast_cli(fd, "PRI debug output to file disabled\n");
- ast_mutex_unlock(&pridebugfdlock);
- }
- return RESULT_SUCCESS;
+ pridebugfd = myfd;
+ ast_copy_string(pridebugfilename,a->argv[4],sizeof(pridebugfilename));
+ ast_mutex_unlock(&pridebugfdlock);
+ ast_cli(a->fd, "PRI debug output will be sent to '%s'\n", a->argv[4]);
+ return CLI_SUCCESS;
}
-static int handle_pri_debug(int fd, int argc, char *argv[])
+static char *handle_pri_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
int span;
int x;
- if (argc < 4) {
- return RESULT_SHOWUSAGE;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "pri debug span";
+ e->usage =
+ "Usage: pri debug span <span>\n"
+ " Enables debugging on a given PRI span\n";
+ return NULL;
+ case CLI_GENERATE:
+ return complete_span_4(a->line, a->word, a->pos, a->n);
}
- span = atoi(argv[3]);
+ if (a->argc < 4) {
+ return CLI_SHOWUSAGE;
+ }
+ span = atoi(a->argv[3]);
if ((span < 1) || (span > NUM_SPANS)) {
- ast_cli(fd, "Invalid span %s. Should be a number %d to %d\n", argv[3], 1, NUM_SPANS);
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "Invalid span %s. Should be a number %d to %d\n", a->argv[3], 1, NUM_SPANS);
+ return CLI_SUCCESS;
}
if (!pris[span-1].pri) {
- ast_cli(fd, "No PRI running on span %d\n", span);
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "No PRI running on span %d\n", span);
+ return CLI_SUCCESS;
}
for (x = 0; x < NUM_DCHANS; x++) {
if (pris[span-1].dchans[x])
@@ -10525,49 +10552,71 @@ static int handle_pri_debug(int fd, int argc, char *argv[])
PRI_DEBUG_Q931_DUMP | PRI_DEBUG_Q931_STATE |
PRI_DEBUG_Q921_STATE);
}
- ast_cli(fd, "Enabled debugging on span %d\n", span);
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "Enabled debugging on span %d\n", span);
+ return CLI_SUCCESS;
}
-static int handle_pri_no_debug(int fd, int argc, char *argv[])
+static char *handle_pri_no_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
int span;
int x;
- if (argc < 5)
- return RESULT_SHOWUSAGE;
- span = atoi(argv[4]);
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "pri no debug span";
+ e->usage =
+ "Usage: pri no debug span <span>\n"
+ " Disables debugging on a given PRI span\n";
+ return NULL;
+ case CLI_GENERATE:
+ return complete_span_5(a->line, a->word, a->pos, a->n);
+ }
+ if (a->argc < 5)
+ return CLI_SHOWUSAGE;
+
+ span = atoi(a->argv[4]);
if ((span < 1) || (span > NUM_SPANS)) {
- ast_cli(fd, "Invalid span %s. Should be a number %d to %d\n", argv[4], 1, NUM_SPANS);
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "Invalid span %s. Should be a number %d to %d\n", a->argv[4], 1, NUM_SPANS);
+ return CLI_SUCCESS;
}
if (!pris[span-1].pri) {
- ast_cli(fd, "No PRI running on span %d\n", span);
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "No PRI running on span %d\n", span);
+ return CLI_SUCCESS;
}
for (x = 0; x < NUM_DCHANS; x++) {
if (pris[span-1].dchans[x])
pri_set_debug(pris[span-1].dchans[x], 0);
}
- ast_cli(fd, "Disabled debugging on span %d\n", span);
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "Disabled debugging on span %d\n", span);
+ return CLI_SUCCESS;
}
-static int handle_pri_really_debug(int fd, int argc, char *argv[])
+static char *handle_pri_really_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
int span;
int x;
- if (argc < 5)
- return RESULT_SHOWUSAGE;
- span = atoi(argv[4]);
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "pri intensive debug span";
+ e->usage =
+ "Usage: pri intensive debug span <span>\n"
+ " Enables debugging down to the Q.921 level\n";
+ return NULL;
+ case CLI_GENERATE:
+ return complete_span_5(a->line, a->word, a->pos, a->n);
+ }
+
+ if (a->argc < 5)
+ return CLI_SHOWUSAGE;
+ span = atoi(a->argv[4]);
if ((span < 1) || (span > NUM_SPANS)) {
- ast_cli(fd, "Invalid span %s. Should be a number %d to %d\n", argv[4], 1, NUM_SPANS);
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "Invalid span %s. Should be a number %d to %d\n", a->argv[4], 1, NUM_SPANS);
+ return CLI_SUCCESS;
}
if (!pris[span-1].pri) {
- ast_cli(fd, "No PRI running on span %d\n", span);
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "No PRI running on span %d\n", span);
+ return CLI_SUCCESS;
}
for (x = 0; x < NUM_DCHANS; x++) {
if (pris[span-1].dchans[x])
@@ -10575,8 +10624,8 @@ static int handle_pri_really_debug(int fd, int argc, char *argv[])
PRI_DEBUG_Q931_DUMP | PRI_DEBUG_Q931_STATE |
PRI_DEBUG_Q921_RAW | PRI_DEBUG_Q921_DUMP | PRI_DEBUG_Q921_STATE);
}
- ast_cli(fd, "Enabled EXTENSIVE debugging on span %d\n", span);
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "Enabled EXTENSIVE debugging on span %d\n", span);
+ return CLI_SUCCESS;
}
static void build_status(char *s, size_t len, int status, int active)
@@ -10600,80 +10649,111 @@ static void build_status(char *s, size_t len, int status, int active)
s[len - 1] = '\0';
}
-static int handle_pri_show_spans(int fd, int argc, char *argv[])
+static char *handle_pri_show_spans(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
int span;
int x;
char status[256];
- if (argc != 3)
- return RESULT_SHOWUSAGE;
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "pri show spans";
+ e->usage =
+ "Usage: pri show spans\n"
+ " Displays PRI Information\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if (a->argc != 3)
+ return CLI_SHOWUSAGE;
for (span = 0; span < NUM_SPANS; span++) {
if (pris[span].pri) {
for (x = 0; x < NUM_DCHANS; x++) {
if (pris[span].dchannels[x]) {
build_status(status, sizeof(status), pris[span].dchanavail[x], pris[span].dchans[x] == pris[span].pri);
- ast_cli(fd, "PRI span %d/%d: %s\n", span + 1, x, status);
+ ast_cli(a->fd, "PRI span %d/%d: %s\n", span + 1, x, status);
}
}
}
}
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
}
-static int handle_pri_show_span(int fd, int argc, char *argv[])
+static char *handle_pri_show_span(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
int span;
int x;
char status[256];
- if (argc < 4)
- return RESULT_SHOWUSAGE;
- span = atoi(argv[3]);
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "pri show span";
+ e->usage =
+ "Usage: pri show span <span>\n"
+ " Displays PRI Information on a given PRI span\n";
+ return NULL;
+ case CLI_GENERATE:
+ return complete_span_4(a->line, a->word, a->pos, a->n);
+ }
+
+ if (a->argc < 4)
+ return CLI_SHOWUSAGE;
+ span = atoi(a->argv[3]);
if ((span < 1) || (span > NUM_SPANS)) {
- ast_cli(fd, "Invalid span '%s'. Should be a number from %d to %d\n", argv[3], 1, NUM_SPANS);
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "Invalid span '%s'. Should be a number from %d to %d\n", a->argv[3], 1, NUM_SPANS);
+ return CLI_SUCCESS;
}
if (!pris[span-1].pri) {
- ast_cli(fd, "No PRI running on span %d\n", span);
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "No PRI running on span %d\n", span);
+ return CLI_SUCCESS;
}
for (x = 0; x < NUM_DCHANS; x++) {
if (pris[span-1].dchannels[x]) {
#ifdef PRI_DUMP_INFO_STR
char *info_str = NULL;
#endif
- ast_cli(fd, "%s D-channel: %d\n", pri_order(x), pris[span-1].dchannels[x]);
+ ast_cli(a->fd, "%s D-channel: %d\n", pri_order(x), pris[span-1].dchannels[x]);
build_status(status, sizeof(status), pris[span-1].dchanavail[x], pris[span-1].dchans[x] == pris[span-1].pri);
- ast_cli(fd, "Status: %s\n", status);
+ ast_cli(a->fd, "Status: %s\n", status);
#ifdef PRI_DUMP_INFO_STR
info_str = pri_dump_info_str(pris[span-1].pri);
if (info_str) {
- ast_cli(fd, "%s", info_str);
+ ast_cli(a->fd, "%s", info_str);
ast_free(info_str);
}
#else
pri_dump_info(pris[span-1].pri);
#endif
- ast_cli(fd, "Overlap Recv: %s\n\n", (pris[span-1].overlapdial & ZAP_OVERLAPDIAL_INCOMING)?"Yes":"No");
+ ast_cli(a->fd, "Overlap Recv: %s\n\n", (pris[span-1].overlapdial & ZAP_OVERLAPDIAL_INCOMING)?"Yes":"No");
}
}
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
}
-static int handle_pri_show_debug(int fd, int argc, char *argv[])
+static char *handle_pri_show_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
int x;
int span;
int count=0;
int debug=0;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "pri show debug";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
for (span = 0; span < NUM_SPANS; span++) {
if (pris[span].pri) {
for (x = 0; x < NUM_DCHANS; x++) {
debug = 0;
if (pris[span].dchans[x]) {
debug = pri_get_debug(pris[span].dchans[x]);
- ast_cli(fd, "Span %d: Debug: %s\tIntense: %s\n", span+1, (debug&PRI_DEBUG_Q931_STATE)? "Yes" : "No" ,(debug&PRI_DEBUG_Q921_RAW)? "Yes" : "No" );
+ ast_cli(a->fd, "Span %d: Debug: %s\tIntense: %s\n", span+1, (debug&PRI_DEBUG_Q931_STATE)? "Yes" : "No" ,(debug&PRI_DEBUG_Q921_RAW)? "Yes" : "No" );
count++;
}
}
@@ -10682,77 +10762,47 @@ static int handle_pri_show_debug(int fd, int argc, char *argv[])
}
ast_mutex_lock(&pridebugfdlock);
if (pridebugfd >= 0)
- ast_cli(fd, "Logging PRI debug to file %s\n", pridebugfilename);
+ ast_cli(a->fd, "Logging PRI debug to file %s\n", pridebugfilename);
ast_mutex_unlock(&pridebugfdlock);
if (!count)
- ast_cli(fd, "No debug set or no PRI running\n");
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "No debug set or no PRI running\n");
+ return CLI_SUCCESS;
}
-static const char pri_debug_help[] =
- "Usage: pri debug span <span>\n"
- " Enables debugging on a given PRI span\n";
-
-static const char pri_no_debug_help[] =
- "Usage: pri no debug span <span>\n"
- " Disables debugging on a given PRI span\n";
-
-static const char pri_really_debug_help[] =
- "Usage: pri intensive debug span <span>\n"
- " Enables debugging down to the Q.921 level\n";
-
-static const char pri_show_span_help[] =
- "Usage: pri show span <span>\n"
- " Displays PRI Information on a given PRI span\n";
-
-static const char pri_show_spans_help[] =
- "Usage: pri show spans\n"
- " Displays PRI Information\n";
-
static struct ast_cli_entry zap_pri_cli[] = {
- { { "pri", "debug", "span", NULL },
- handle_pri_debug, "Enables PRI debugging on a span",
- pri_debug_help, complete_span_4 },
-
- { { "pri", "no", "debug", "span", NULL },
- handle_pri_no_debug, "Disables PRI debugging on a span",
- pri_no_debug_help, complete_span_5 },
-
- { { "pri", "intense", "debug", "span", NULL },
- handle_pri_really_debug, "Enables REALLY INTENSE PRI debugging",
- pri_really_debug_help, complete_span_5 },
-
- { { "pri", "show", "spans", NULL },
- handle_pri_show_spans, "Displays PRI Information",
- pri_show_spans_help },
-
- { { "pri", "show", "span", NULL },
- handle_pri_show_span, "Displays PRI Information",
- pri_show_span_help, complete_span_4 },
-
- { { "pri", "show", "debug", NULL },
- handle_pri_show_debug, "Displays current PRI debug settings" },
-
- { { "pri", "set", "debug", "file", NULL },
- handle_pri_set_debug_file, "Sends PRI debug output to the specified file" },
-
- { { "pri", "unset", "debug", "file", NULL },
- handle_pri_set_debug_file, "Ends PRI debug output to file" },
+ NEW_CLI(handle_pri_debug, "Enables PRI debugging on a span"),
+ NEW_CLI(handle_pri_no_debug, "Disables PRI debugging on a span"),
+ NEW_CLI(handle_pri_really_debug, "Enables REALLY INTENSE PRI debugging"),
+ NEW_CLI(handle_pri_show_spans, "Displays PRI Information"),
+ NEW_CLI(handle_pri_show_span, "Displays PRI Information"),
+ NEW_CLI(handle_pri_show_debug, "Displays current PRI debug settings"),
+ NEW_CLI(handle_pri_set_debug_file, "Sends PRI debug output to the specified file"),
+ NEW_CLI(handle_pri_unset_debug_file, "Ends PRI debug output to file"),
};
#endif /* HAVE_PRI */
-static int zap_destroy_channel(int fd, int argc, char **argv)
+static char *zap_destroy_channel(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
int channel;
+ int ret;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "zap destroy channel";
+ e->usage =
+ "Usage: zap destroy channel <chan num>\n"
+ " DON'T USE THIS UNLESS YOU KNOW WHAT YOU ARE DOING. Immediately removes a given channel, whether it is in use or not\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+ if (a->argc != 4)
+ return CLI_SHOWUSAGE;
- if (argc != 4)
- return RESULT_SHOWUSAGE;
-
- channel = atoi(argv[3]);
-
- return zap_destroy_channel_bynum(channel);
+ channel = atoi(a->argv[3]);
+ ret = zap_destroy_channel_bynum(channel);
+ return ( RESULT_SUCCESS == ret ) ? CLI_SUCCESS : CLI_FAILURE;
}
static int setup_zap(int reload);
@@ -10772,15 +10822,25 @@ static int zap_restart(void)
return 0;
}
-static int zap_restart_cmd(int fd, int argc, char **argv)
+static char *zap_restart_cmd(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 = "zap restart";
+ e->usage =
+ "Usage: zap restart\n"
+ " Restarts the zaptel channels: destroys them all and then\n"
+ " re-reads them from zapata.conf.\n"
+ " Note that this will STOP any running CALL on zaptel channels.\n"
+ "";
+ return NULL;
}
+ if (a->argc != 2)
+ return CLI_SHOWUSAGE;
if (zap_restart() != 0)
- return RESULT_FAILURE;
- return RESULT_SUCCESS;
+ return CLI_FAILURE;
+ return CLI_SUCCESS;
}
static int action_zaprestart(struct mansession *s, const struct message *m)
@@ -10793,7 +10853,7 @@ static int action_zaprestart(struct mansession *s, const struct message *m)
return 0;
}
-static int zap_show_channels(int fd, int argc, char **argv)
+static char *zap_show_channels(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
#define FORMAT "%7s %-10.10s %-15.15s %-10.10s %-20.20s %-10.10s %-10.10s\n"
#define FORMAT2 "%7s %-10.10s %-15.15s %-10.10s %-20.20s %-10.10s %-10.10s\n"
@@ -10810,21 +10870,32 @@ static int zap_show_channels(int fd, int argc, char **argv)
struct zt_pri *pri = NULL;
int x;
#endif
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "zap show channels [trunkgroup|group|context]";
+ e->usage =
+ "Usage: zap show channels [ trunkgroup <trunkgroup> | group <group> | context <context> ]\n"
+ " Shows a list of available channels with optional filtering\n"
+ " <group> must be a number between 0 and 63\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
lock = &iflock;
start = iflist;
/* syntax: zap show channels [ group <group> | context <context> | trunkgroup <trunkgroup> ] */
- if (!((argc == 3) || (argc == 5)))
- return RESULT_SHOWUSAGE;
+ if (!((a->argc == 3) || (a->argc == 5)))
+ return CLI_SHOWUSAGE;
- if (argc == 5) {
+ if (a->argc == 5) {
#ifdef HAVE_PRI
- if (!strcasecmp(argv[3], "trunkgroup")) {
+ if (!strcasecmp(a->argv[3], "trunkgroup")) {
/* this option requires no special handling, so leave filtertype to zero */
- if ((trunkgroup = atoi(argv[4])) < 1)
- return RESULT_SHOWUSAGE;
+ if ((trunkgroup = atoi(a->argv[4])) < 1)
+ return CLI_SHOWUSAGE;
for (x = 0; x < NUM_SPANS; x++) {
if (pris[x].trunkgroup == trunkgroup) {
pri = pris + x;
@@ -10835,27 +10906,27 @@ static int zap_show_channels(int fd, int argc, char **argv)
start = pri->crvs;
lock = &pri->lock;
} else {
- ast_cli(fd, "No such trunk group %d\n", trunkgroup);
- return RESULT_FAILURE;
+ ast_cli(a->fd, "No such trunk group %d\n", trunkgroup);
+ return CLI_FAILURE;
}
} else
#endif
- if (!strcasecmp(argv[3], "group")) {
- targetnum = atoi(argv[4]);
+ if (!strcasecmp(a->argv[3], "group")) {
+ targetnum = atoi(a->argv[4]);
if ((targetnum < 0) || (targetnum > 63))
- return RESULT_SHOWUSAGE;
+ return CLI_SHOWUSAGE;
targetnum = 1 << targetnum;
filtertype = 1;
- } else if (!strcasecmp(argv[3], "context")) {
+ } else if (!strcasecmp(a->argv[3], "context")) {
filtertype = 2;
}
}
ast_mutex_lock(lock);
#ifdef HAVE_PRI
- ast_cli(fd, FORMAT2, pri ? "CRV" : "Chan", "Extension", "Context", "Language", "MOH Interpret", "Blocked", "State");
+ ast_cli(a->fd, FORMAT2, pri ? "CRV" : "Chan", "Extension", "Context", "Language", "MOH Interpret", "Blocked", "State");
#else
- ast_cli(fd, FORMAT2, "Chan", "Extension", "Context", "Language", "MOH Interpret", "Blocked", "State");
+ ast_cli(a->fd, FORMAT2, "Chan", "Extension", "Context", "Language", "MOH Interpret", "Blocked", "State");
#endif
tmp = start;
@@ -10869,7 +10940,7 @@ static int zap_show_channels(int fd, int argc, char **argv)
}
break;
case 2: /* zap show channels context <context> */
- if (strcasecmp(tmp->context, argv[4])) {
+ if (strcasecmp(tmp->context, a->argv[4])) {
tmp = tmp->next;
continue;
}
@@ -10897,16 +10968,16 @@ static int zap_show_channels(int fd, int argc, char **argv)
snprintf(statestr, sizeof(statestr), "%s", tmp->inservice ? "In Service" : "Out of Service");
- ast_cli(fd, FORMAT, tmps, tmp->exten, tmp->context, tmp->language, tmp->mohinterpret, blockstr, statestr);
+ ast_cli(a->fd, FORMAT, tmps, tmp->exten, tmp->context, tmp->language, tmp->mohinterpret, blockstr, statestr);
tmp = tmp->next;
}
ast_mutex_unlock(lock);
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
#undef FORMAT
#undef FORMAT2
}
-static int zap_show_channel(int fd, int argc, char **argv)
+static char *zap_show_channel(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
int channel;
struct zt_pvt *tmp = NULL;
@@ -10920,18 +10991,28 @@ static int zap_show_channel(int fd, int argc, char **argv)
int trunkgroup;
struct zt_pri *pri=NULL;
#endif
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "zap show channel";
+ e->usage =
+ "Usage: zap show channel <chan num>\n"
+ " Detailed information about a given channel\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
lock = &iflock;
start = iflist;
- if (argc != 4)
- return RESULT_SHOWUSAGE;
+ if (a->argc != 4)
+ return CLI_SHOWUSAGE;
#ifdef HAVE_PRI
- if ((c = strchr(argv[3], ':'))) {
- if (sscanf(argv[3], "%d:%d", &trunkgroup, &channel) != 2)
- return RESULT_SHOWUSAGE;
+ if ((c = strchr(a->argv[3], ':'))) {
+ if (sscanf(a->argv[3], "%d:%d", &trunkgroup, &channel) != 2)
+ return CLI_SHOWUSAGE;
if ((trunkgroup < 1) || (channel < 1))
- return RESULT_SHOWUSAGE;
+ return CLI_SHOWUSAGE;
for (x = 0; x < NUM_SPANS; x++) {
if (pris[x].trunkgroup == trunkgroup) {
pri = pris + x;
@@ -10942,12 +11023,12 @@ static int zap_show_channel(int fd, int argc, char **argv)
start = pri->crvs;
lock = &pri->lock;
} else {
- ast_cli(fd, "No such trunk group %d\n", trunkgroup);
- return RESULT_FAILURE;
+ ast_cli(a->fd, "No such trunk group %d\n", trunkgroup);
+ return CLI_FAILURE;
}
} else
#endif
- channel = atoi(argv[3]);
+ channel = atoi(a->argv[3]);
ast_mutex_lock(lock);
tmp = start;
@@ -10955,68 +11036,68 @@ static int zap_show_channel(int fd, int argc, char **argv)
if (tmp->channel == channel) {
#ifdef HAVE_PRI
if (pri)
- ast_cli(fd, "Trunk/CRV: %d/%d\n", trunkgroup, tmp->channel);
+ ast_cli(a->fd, "Trunk/CRV: %d/%d\n", trunkgroup, tmp->channel);
else
#endif
- ast_cli(fd, "Channel: %d\n", tmp->channel);
- ast_cli(fd, "File Descriptor: %d\n", tmp->subs[SUB_REAL].zfd);
- ast_cli(fd, "Span: %d\n", tmp->span);
- ast_cli(fd, "Extension: %s\n", tmp->exten);
- ast_cli(fd, "Dialing: %s\n", tmp->dialing ? "yes" : "no");
- ast_cli(fd, "Context: %s\n", tmp->context);
- ast_cli(fd, "Caller ID: %s\n", tmp->cid_num);
- ast_cli(fd, "Calling TON: %d\n", tmp->cid_ton);
- ast_cli(fd, "Caller ID name: %s\n", tmp->cid_name);
+ ast_cli(a->fd, "Channel: %d\n", tmp->channel);
+ ast_cli(a->fd, "File Descriptor: %d\n", tmp->subs[SUB_REAL].zfd);
+ ast_cli(a->fd, "Span: %d\n", tmp->span);
+ ast_cli(a->fd, "Extension: %s\n", tmp->exten);
+ ast_cli(a->fd, "Dialing: %s\n", tmp->dialing ? "yes" : "no");
+ ast_cli(a->fd, "Context: %s\n", tmp->context);
+ ast_cli(a->fd, "Caller ID: %s\n", tmp->cid_num);
+ ast_cli(a->fd, "Calling TON: %d\n", tmp->cid_ton);
+ ast_cli(a->fd, "Caller ID name: %s\n", tmp->cid_name);
if (tmp->vars) {
struct ast_variable *v;
- ast_cli(fd, "Variables:\n");
+ ast_cli(a->fd, "Variables:\n");
for (v = tmp->vars ; v ; v = v->next)
- ast_cli(fd, " %s = %s\n", v->name, v->value);
- }
- ast_cli(fd, "Destroy: %d\n", tmp->destroy);
- ast_cli(fd, "InAlarm: %d\n", tmp->inalarm);
- ast_cli(fd, "Signalling Type: %s\n", sig2str(tmp->sig));
- ast_cli(fd, "Radio: %d\n", tmp->radio);
- ast_cli(fd, "Owner: %s\n", tmp->owner ? tmp->owner->name : "<None>");
- ast_cli(fd, "Real: %s%s%s\n", tmp->subs[SUB_REAL].owner ? tmp->subs[SUB_REAL].owner->name : "<None>", tmp->subs[SUB_REAL].inthreeway ? " (Confed)" : "", tmp->subs[SUB_REAL].linear ? " (Linear)" : "");
- ast_cli(fd, "Callwait: %s%s%s\n", tmp->subs[SUB_CALLWAIT].owner ? tmp->subs[SUB_CALLWAIT].owner->name : "<None>", tmp->subs[SUB_CALLWAIT].inthreeway ? " (Confed)" : "", tmp->subs[SUB_CALLWAIT].linear ? " (Linear)" : "");
- ast_cli(fd, "Threeway: %s%s%s\n", tmp->subs[SUB_THREEWAY].owner ? tmp->subs[SUB_THREEWAY].owner->name : "<None>", tmp->subs[SUB_THREEWAY].inthreeway ? " (Confed)" : "", tmp->subs[SUB_THREEWAY].linear ? " (Linear)" : "");
- ast_cli(fd, "Confno: %d\n", tmp->confno);
- ast_cli(fd, "Propagated Conference: %d\n", tmp->propconfno);
- ast_cli(fd, "Real in conference: %d\n", tmp->inconference);
- ast_cli(fd, "DSP: %s\n", tmp->dsp ? "yes" : "no");
- ast_cli(fd, "TDD: %s\n", tmp->tdd ? "yes" : "no");
- ast_cli(fd, "Relax DTMF: %s\n", tmp->dtmfrelax ? "yes" : "no");
- ast_cli(fd, "Dialing/CallwaitCAS: %d/%d\n", tmp->dialing, tmp->callwaitcas);
- ast_cli(fd, "Default law: %s\n", tmp->law == ZT_LAW_MULAW ? "ulaw" : tmp->law == ZT_LAW_ALAW ? "alaw" : "unknown");
- ast_cli(fd, "Fax Handled: %s\n", tmp->faxhandled ? "yes" : "no");
- ast_cli(fd, "Pulse phone: %s\n", tmp->pulsedial ? "yes" : "no");
- ast_cli(fd, "Echo Cancellation: %d taps%s, currently %s\n", tmp->echocancel, tmp->echocanbridged ? "" : " unless TDM bridged", tmp->echocanon ? "ON" : "OFF");
+ ast_cli(a->fd, " %s = %s\n", v->name, v->value);
+ }
+ ast_cli(a->fd, "Destroy: %d\n", tmp->destroy);
+ ast_cli(a->fd, "InAlarm: %d\n", tmp->inalarm);
+ ast_cli(a->fd, "Signalling Type: %s\n", sig2str(tmp->sig));
+ ast_cli(a->fd, "Radio: %d\n", tmp->radio);
+ ast_cli(a->fd, "Owner: %s\n", tmp->owner ? tmp->owner->name : "<None>");
+ ast_cli(a->fd, "Real: %s%s%s\n", tmp->subs[SUB_REAL].owner ? tmp->subs[SUB_REAL].owner->name : "<None>", tmp->subs[SUB_REAL].inthreeway ? " (Confed)" : "", tmp->subs[SUB_REAL].linear ? " (Linear)" : "");
+ ast_cli(a->fd, "Callwait: %s%s%s\n", tmp->subs[SUB_CALLWAIT].owner ? tmp->subs[SUB_CALLWAIT].owner->name : "<None>", tmp->subs[SUB_CALLWAIT].inthreeway ? " (Confed)" : "", tmp->subs[SUB_CALLWAIT].linear ? " (Linear)" : "");
+ ast_cli(a->fd, "Threeway: %s%s%s\n", tmp->subs[SUB_THREEWAY].owner ? tmp->subs[SUB_THREEWAY].owner->name : "<None>", tmp->subs[SUB_THREEWAY].inthreeway ? " (Confed)" : "", tmp->subs[SUB_THREEWAY].linear ? " (Linear)" : "");
+ ast_cli(a->fd, "Confno: %d\n", tmp->confno);
+ ast_cli(a->fd, "Propagated Conference: %d\n", tmp->propconfno);
+ ast_cli(a->fd, "Real in conference: %d\n", tmp->inconference);
+ ast_cli(a->fd, "DSP: %s\n", tmp->dsp ? "yes" : "no");
+ ast_cli(a->fd, "TDD: %s\n", tmp->tdd ? "yes" : "no");
+ ast_cli(a->fd, "Relax DTMF: %s\n", tmp->dtmfrelax ? "yes" : "no");
+ ast_cli(a->fd, "Dialing/CallwaitCAS: %d/%d\n", tmp->dialing, tmp->callwaitcas);
+ ast_cli(a->fd, "Default law: %s\n", tmp->law == ZT_LAW_MULAW ? "ulaw" : tmp->law == ZT_LAW_ALAW ? "alaw" : "unknown");
+ ast_cli(a->fd, "Fax Handled: %s\n", tmp->faxhandled ? "yes" : "no");
+ ast_cli(a->fd, "Pulse phone: %s\n", tmp->pulsedial ? "yes" : "no");
+ ast_cli(a->fd, "Echo Cancellation: %d taps%s, currently %s\n", tmp->echocancel, tmp->echocanbridged ? "" : " unless TDM bridged", tmp->echocanon ? "ON" : "OFF");
if (tmp->master)
- ast_cli(fd, "Master Channel: %d\n", tmp->master->channel);
+ ast_cli(a->fd, "Master Channel: %d\n", tmp->master->channel);
for (x = 0; x < MAX_SLAVES; x++) {
if (tmp->slaves[x])
- ast_cli(fd, "Slave Channel: %d\n", tmp->slaves[x]->channel);
+ ast_cli(a->fd, "Slave Channel: %d\n", tmp->slaves[x]->channel);
}
#ifdef HAVE_SS7
if (tmp->ss7) {
- ast_cli(fd, "CIC: %d\n", tmp->cic);
+ ast_cli(a->fd, "CIC: %d\n", tmp->cic);
}
#endif
#ifdef HAVE_PRI
if (tmp->pri) {
- ast_cli(fd, "PRI Flags: ");
+ ast_cli(a->fd, "PRI Flags: ");
if (tmp->resetting)
- ast_cli(fd, "Resetting ");
+ ast_cli(a->fd, "Resetting ");
if (tmp->call)
- ast_cli(fd, "Call ");
+ ast_cli(a->fd, "Call ");
if (tmp->bearer)
- ast_cli(fd, "Bearer ");
- ast_cli(fd, "\n");
+ ast_cli(a->fd, "Bearer ");
+ ast_cli(a->fd, "\n");
if (tmp->logicalspan)
- ast_cli(fd, "PRI Logical Span: %d\n", tmp->logicalspan);
+ ast_cli(a->fd, "PRI Logical Span: %d\n", tmp->logicalspan);
else
- ast_cli(fd, "PRI Logical Span: Implicit\n");
+ ast_cli(a->fd, "PRI Logical Span: Implicit\n");
}
#endif
@@ -11024,37 +11105,43 @@ static int zap_show_channel(int fd, int argc, char **argv)
ps.channo = tmp->channel;
if (tmp->subs[SUB_REAL].zfd > -1) {
if (!ioctl(tmp->subs[SUB_REAL].zfd, ZT_GETCONF, &ci)) {
- ast_cli(fd, "Actual Confinfo: Num/%d, Mode/0x%04x\n", ci.confno, ci.confmode);
+ ast_cli(a->fd, "Actual Confinfo: Num/%d, Mode/0x%04x\n", ci.confno, ci.confmode);
}
#ifdef ZT_GETCONFMUTE
if (!ioctl(tmp->subs[SUB_REAL].zfd, ZT_GETCONFMUTE, &x)) {
- ast_cli(fd, "Actual Confmute: %s\n", x ? "Yes" : "No");
+ ast_cli(a->fd, "Actual Confmute: %s\n", x ? "Yes" : "No");
}
#endif
if (ioctl(tmp->subs[SUB_REAL].zfd, ZT_GET_PARAMS, &ps) < 0) {
ast_log(LOG_WARNING, "Failed to get parameters on channel %d\n", tmp->channel);
} else {
- ast_cli(fd, "Hookstate (FXS only): %s\n", ps.rxisoffhook ? "Offhook" : "Onhook");
+ ast_cli(a->fd, "Hookstate (FXS only): %s\n", ps.rxisoffhook ? "Offhook" : "Onhook");
}
}
ast_mutex_unlock(lock);
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
}
tmp = tmp->next;
}
- ast_cli(fd, "Unable to find given channel %d\n", channel);
+ ast_cli(a->fd, "Unable to find given channel %d\n", channel);
ast_mutex_unlock(lock);
- return RESULT_FAILURE;
+ return CLI_FAILURE;
}
-static char zap_show_cadences_help[] =
-"Usage: zap show cadences\n"
-" Shows all cadences currently defined\n";
-
-static int handle_zap_show_cadences(int fd, int argc, char *argv[])
+static char *handle_zap_show_cadences(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
int i, j;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "zap show cadences";
+ e->usage =
+ "Usage: zap show cadences\n"
+ " Shows all cadences currently defined\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
for (i = 0; i < num_cadence; i++) {
char output[1024];
char tmp[16], tmp2[64];
@@ -11073,13 +11160,14 @@ static int handle_zap_show_cadences(int fd, int argc, char *argv[])
strncat(output, ",", sizeof(output) - strlen(output) - 1);
strncat(output, tmp2, sizeof(output) - strlen(output) - 1);
}
- ast_cli(fd,"%s\n",output);
+ ast_cli(a->fd,"%s\n",output);
}
- return 0;
+ return CLI_SUCCESS;
}
/* Based on irqmiss.c */
-static int zap_show_status(int fd, int argc, char *argv[]) {
+static char *zap_show_status(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
#ifdef ZT_SPANINFO_HAS_LINECONFIG
#define FORMAT "%-40.40s %-7.7s %-6d %-6d %-6d %-3.3s %-4.4s %-8.8s %s\n"
#define FORMAT2 "%-40.40s %-7.7s %-6.6s %-6.6s %-6.6s %-3.3s %-4.4s %-8.8s %s\n"
@@ -11087,7 +11175,6 @@ static int zap_show_status(int fd, int argc, char *argv[]) {
#define FORMAT "%-40.40s %-10.10s %-10d %-10d %-10d\n"
#define FORMAT2 "%-40.40s %-10.10s %-10.10s %-10.10s %-10.10s\n"
#endif
-
int span;
int res;
char alarms[50];
@@ -11095,13 +11182,22 @@ static int zap_show_status(int fd, int argc, char *argv[]) {
int ctl;
ZT_SPANINFO s;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "zap show status";
+ e->usage =
+ "Usage: zap show status\n"
+ " Shows a list of Zaptel cards with status\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
ctl = open("/dev/zap/ctl", O_RDWR);
if (ctl < 0) {
- ast_log(LOG_WARNING, "Unable to open /dev/zap/ctl: %s\n", strerror(errno));
- ast_cli(fd, "No Zaptel interface found.\n");
- return RESULT_FAILURE;
+ ast_cli(a->fd, "No Zaptel interface found. Unable to open /dev/zap/ctl: %s\n", strerror(errno));
+ return CLI_FAILURE;
}
- ast_cli(fd, FORMAT2, "Description", "Alarms", "IRQ", "bpviol", "CRC4"
+ ast_cli(a->fd, FORMAT2, "Description", "Alarms", "IRQ", "bpviol", "CRC4"
#ifdef ZT_SPANINFO_HAS_LINECONFIG
, "Framing", "Coding", "Options", "LBO"
#endif
@@ -11140,7 +11236,7 @@ static int zap_show_status(int fd, int argc, char *argv[]) {
strcpy(alarms, "UNCONFIGURED");
}
- ast_cli(fd, FORMAT, s.desc, alarms, s.irqmisses, s.bpvcount, s.crc4count
+ ast_cli(a->fd, FORMAT, s.desc, alarms, s.irqmisses, s.bpvcount, s.crc4count
#ifdef ZT_SPANINFO_HAS_LINECONFIG
, s.lineconfig & ZT_CONFIG_D4 ? "D4" :
s.lineconfig & ZT_CONFIG_ESF ? "ESF" :
@@ -11158,90 +11254,52 @@ static int zap_show_status(int fd, int argc, char *argv[]) {
}
close(ctl);
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
#undef FORMAT
#undef FORMAT2
}
-static int zap_show_version(int fd, int argc, char *argv[])
+static char *zap_show_version(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
int pseudo_fd = -1;
struct zt_versioninfo vi;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "zap show version";
+ e->usage =
+ "Usage: zap show version\n"
+ " Shows the Zaptel version in use\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
if ((pseudo_fd = open("/dev/zap/ctl", O_RDONLY)) < 0) {
- ast_cli(fd, "Failed to open control file to get version.\n");
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "Failed to open control file to get version.\n");
+ return CLI_SUCCESS;
}
strcpy(vi.version, "Unknown");
strcpy(vi.echo_canceller, "Unknown");
if (ioctl(pseudo_fd, ZT_GETVERSION, &vi))
- ast_cli(fd, "Failed to get version from control file.\n");
+ ast_cli(a->fd, "Failed to get version from control file.\n");
else
- ast_cli(fd, "Zaptel Version: %s Echo Canceller: %s\n", vi.version, vi.echo_canceller);
+ ast_cli(a->fd, "Zaptel Version: %s Echo Canceller: %s\n", vi.version, vi.echo_canceller);
close(pseudo_fd);
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
}
-static const char show_channels_usage[] =
- "Usage: zap show channels [ trunkgroup <trunkgroup> | group <group> | context <context> ]\n"
- " Shows a list of available channels with optional filtering\n"
- " <group> must be a number between 0 and 63\n";
-
-static const char show_channel_usage[] =
- "Usage: zap show channel <chan num>\n"
- " Detailed information about a given channel\n";
-
-static const char zap_show_status_usage[] =
- "Usage: zap show status\n"
- " Shows a list of Zaptel cards with status\n";
-
-static const char destroy_channel_usage[] =
- "Usage: zap destroy channel <chan num>\n"
- " DON'T USE THIS UNLESS YOU KNOW WHAT YOU ARE DOING. Immediately removes a given channel, whether it is in use or not\n";
-
-static const char zap_restart_usage[] =
- "Usage: zap restart\n"
- " Restarts the zaptel channels: destroys them all and then\n"
- " re-reads them from zapata.conf.\n"
- " Note that this will STOP any running CALL on zaptel channels.\n"
- "";
-
-static char zap_show_version_usage[] =
- "Usage: zap show version\n"
- " Shows the Zaptel version in use\n";
-
static struct ast_cli_entry zap_cli[] = {
- { { "zap", "show", "cadences", NULL },
- handle_zap_show_cadences, "List cadences",
- zap_show_cadences_help },
-
- { { "zap", "show", "channels", NULL},
- zap_show_channels, "Show active zapata channels",
- show_channels_usage },
-
- { { "zap", "show", "channel", NULL},
- zap_show_channel, "Show information on a channel",
- show_channel_usage },
-
- { { "zap", "destroy", "channel", NULL},
- zap_destroy_channel, "Destroy a channel",
- destroy_channel_usage },
-
- { { "zap", "restart", NULL},
- zap_restart_cmd, "Fully restart zaptel channels",
- zap_restart_usage },
-
- { { "zap", "show", "status", NULL},
- zap_show_status, "Show all Zaptel cards status",
- zap_show_status_usage },
-
- { { "zap", "show", "version", NULL},
- zap_show_version, "Show the Zaptel version in use",
- zap_show_version_usage },
+ NEW_CLI(handle_zap_show_cadences, "List cadences"),
+ NEW_CLI(zap_show_channels, "Show active zapata channels"),
+ NEW_CLI(zap_show_channel, "Show information on a channel"),
+ NEW_CLI(zap_destroy_channel, "Destroy a channel"),
+ NEW_CLI(zap_restart_cmd, "Fully restart zaptel channels"),
+ NEW_CLI(zap_show_status, "Show all Zaptel cards status"),
+ NEW_CLI(zap_show_version, "Show the Zaptel version in use"),
};
#define TRANSFER 0
@@ -11625,72 +11683,102 @@ static int linkset_addsigchan(int sigchan)
return 0;
}
-static int handle_ss7_no_debug(int fd, int argc, char *argv[])
+static char *handle_ss7_no_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
int span;
- if (argc < 5)
- return RESULT_SHOWUSAGE;
- span = atoi(argv[4]);
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "ss7 no debug linkset";
+ e->usage =
+ "Usage: ss7 no debug linkset <span>\n"
+ " Disables debugging on a given SS7 linkset\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+ if (a->argc < 5)
+ return CLI_SHOWUSAGE;
+ span = atoi(a->argv[4]);
if ((span < 1) || (span > NUM_SPANS)) {
- ast_cli(fd, "Invalid linkset %s. Should be a number %d to %d\n", argv[4], 1, NUM_SPANS);
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "Invalid linkset %s. Should be a number from %d to %d\n", a->argv[4], 1, NUM_SPANS);
+ return CLI_SUCCESS;
}
if (!linksets[span-1].ss7) {
- ast_cli(fd, "No SS7 running on linkset %d\n", span);
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "No SS7 running on linkset %d\n", span);
+ return CLI_SUCCESS;
}
if (linksets[span-1].ss7)
ss7_set_debug(linksets[span-1].ss7, 0);
- ast_cli(fd, "Disabled debugging on linkset %d\n", span);
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "Disabled debugging on linkset %d\n", span);
+ return CLI_SUCCESS;
}
-static int handle_ss7_debug(int fd, int argc, char *argv[])
+static char *handle_ss7_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
int span;
- if (argc < 4)
- return RESULT_SHOWUSAGE;
- span = atoi(argv[3]);
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "ss7 debug linkset";
+ e->usage =
+ "Usage: ss7 debug linkset <linkset>\n"
+ " Enables debugging on a given SS7 linkset\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+ if (a->argc < 4)
+ return CLI_SHOWUSAGE;
+ span = atoi(a->argv[3]);
if ((span < 1) || (span > NUM_SPANS)) {
- ast_cli(fd, "Invalid linkset %s. Should be a number %d to %d\n", argv[4], 1, NUM_SPANS);
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "Invalid linkset %s. Should be a number from %d to %d\n", a->argv[3], 1, NUM_SPANS);
+ return CLI_SUCCESS;
}
if (!linksets[span-1].ss7) {
- ast_cli(fd, "No SS7 running on linkset %d\n", span);
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "No SS7 running on linkset %d\n", span);
+ return CLI_SUCCESS;
}
if (linksets[span-1].ss7)
ss7_set_debug(linksets[span-1].ss7, SS7_DEBUG_MTP2 | SS7_DEBUG_MTP3 | SS7_DEBUG_ISUP);
- ast_cli(fd, "Enabled debugging on linkset %d\n", span);
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "Enabled debugging on linkset %d\n", span);
+ return CLI_SUCCESS;
}
-static int handle_ss7_block_cic(int fd, int argc, char *argv[])
+static char *handle_ss7_block_cic(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
int linkset, cic;
int blocked = -1, i;
- if (argc == 5)
- linkset = atoi(argv[3]);
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "ss7 block cic";
+ e->usage =
+ "Usage: ss7 block cic <linkset> <CIC>\n"
+ " Sends a remote blocking request for the given CIC on the specified linkset\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+ if (a->argc == 5)
+ linkset = atoi(a->argv[3]);
else
- return RESULT_SHOWUSAGE;
+ return CLI_SHOWUSAGE;
if ((linkset < 1) || (linkset > NUM_SPANS)) {
- ast_cli(fd, "Invalid linkset %s. Should be a number %d to %d\n", argv[3], 1, NUM_SPANS);
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "Invalid linkset %s. Should be a number %d to %d\n", a->argv[3], 1, NUM_SPANS);
+ return CLI_SUCCESS;
}
if (!linksets[linkset-1].ss7) {
- ast_cli(fd, "No SS7 running on linkset %d\n", linkset);
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "No SS7 running on linkset %d\n", linkset);
+ return CLI_SUCCESS;
}
- cic = atoi(argv[4]);
+ cic = atoi(a->argv[4]);
if (cic < 1) {
- ast_cli(fd, "Invalid CIC specified!\n");
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "Invalid CIC specified!\n");
+ return CLI_SUCCESS;
}
for (i = 0; i < linksets[linkset-1].numchans; i++) {
@@ -11708,42 +11796,53 @@ static int handle_ss7_block_cic(int fd, int argc, char *argv[])
}
if (blocked < 0) {
- ast_cli(fd, "Invalid CIC specified!\n");
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "Invalid CIC specified!\n");
+ return CLI_SUCCESS;
}
if (!blocked)
- ast_cli(fd, "Sent blocking request for linkset %d on CIC %d\n", linkset, cic);
+ ast_cli(a->fd, "Sent blocking request for linkset %d on CIC %d\n", linkset, cic);
else
- ast_cli(fd, "CIC %d already locally blocked\n", cic);
+ ast_cli(a->fd, "CIC %d already locally blocked\n", cic);
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
}
static int handle_ss7_unblock_cic(int fd, int argc, char *argv[])
{
int linkset, cic;
int i, blocked = -1;
- if (argc == 5)
- linkset = atoi(argv[3]);
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "ss7 unblock cic";
+ e->usage =
+ "Usage: ss7 unblock cic <linkset> <CIC>\n"
+ " Sends a remote unblocking request for the given CIC on the specified linkset\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if (a->argc == 5)
+ linkset = atoi(a->argv[3]);
else
- return RESULT_SHOWUSAGE;
+ return CLI_SHOWUSAGE;
if ((linkset < 1) || (linkset > NUM_SPANS)) {
- ast_cli(fd, "Invalid linkset %s. Should be a number %d to %d\n", argv[3], 1, NUM_SPANS);
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "Invalid linkset %s. Should be a number %d to %d\n", a->argv[3], 1, NUM_SPANS);
+ return CLI_SUCCESS;
}
if (!linksets[linkset-1].ss7) {
- ast_cli(fd, "No SS7 running on linkset %d\n", linkset);
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "No SS7 running on linkset %d\n", linkset);
+ return CLI_SUCCESS;
}
- cic = atoi(argv[4]);
+ cic = atoi(a->argv[4]);
if (cic < 1) {
- ast_cli(fd, "Invalid CIC specified!\n");
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "Invalid CIC specified!\n");
+ return CLI_SUCCESS;
}
for (i = 0; i < linksets[linkset-1].numchans; i++) {
@@ -11761,64 +11860,50 @@ static int handle_ss7_unblock_cic(int fd, int argc, char *argv[])
}
if (blocked > 0)
- ast_cli(fd, "Sent unblocking request for linkset %d on CIC %d\n", linkset, cic);
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "Sent unblocking request for linkset %d on CIC %d\n", linkset, cic);
+ return CLI_SUCCESS;
}
-static int handle_ss7_show_linkset(int fd, int argc, char *argv[])
+static char *handle_ss7_show_linkset(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
int linkset;
struct zt_ss7 *ss7;
- if (argc < 4)
- return RESULT_SHOWUSAGE;
- linkset = atoi(argv[3]);
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "ss7 show linkset";
+ e->usage =
+ "Usage: ss7 show linkset <span>\n"
+ " Shows the status of an SS7 linkset.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if (a->argc < 4)
+ return CLI_SHOWUSAGE;
+ linkset = atoi(a->argv[3]);
if ((linkset < 1) || (linkset > NUM_SPANS)) {
- ast_cli(fd, "Invalid linkset %s. Should be a number %d to %d\n", argv[4], 1, NUM_SPANS);
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "Invalid linkset %s. Should be a number %d to %d\n", a->argv[3], 1, NUM_SPANS);
+ return CLI_SUCCESS;
}
if (!linksets[linkset-1].ss7) {
ast_cli(fd, "No SS7 running on linkset %d\n", linkset);
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
}
if (linksets[linkset-1].ss7)
ss7 = &linksets[linkset-1];
- ast_cli(fd, "SS7 linkset %d status: %s\n", linkset, (ss7->state == LINKSET_STATE_UP) ? "Up" : "Down");
+ ast_cli(a->fd, "SS7 linkset %d status: %s\n", linkset, (ss7->state == LINKSET_STATE_UP) ? "Up" : "Down");
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
}
-static char ss7_debug_help[] =
- "Usage: ss7 debug linkset <linkset>\n"
- " Enables debugging on a given SS7 linkset\n";
-
-static char ss7_no_debug_help[] =
- "Usage: ss7 no debug linkset <span>\n"
- " Disables debugging on a given SS7 linkset\n";
-
-static char ss7_block_cic_help[] =
- "Usage: ss7 block cic <linkset> <CIC>\n"
- " Sends a remote blocking request for the given CIC on the specified linkset\n";
-
-static char ss7_unblock_cic_help[] =
- "Usage: ss7 unblock cic <linkset> <CIC>\n"
- " Sends a remote unblocking request for the given CIC on the specified linkset\n";
-
-static char ss7_show_linkset_help[] =
- "Usage: ss7 show linkset <span>\n"
- " Shows the status of an SS7 linkset.\n";
-
static struct ast_cli_entry zap_ss7_cli[] = {
- { { "ss7", "debug", "linkset", NULL }, handle_ss7_debug,
- "Enables SS7 debugging on a linkset", ss7_debug_help, NULL },
- { { "ss7", "no", "debug", "linkset", NULL }, handle_ss7_no_debug,
- "Disables SS7 debugging on a linkset", ss7_no_debug_help, NULL },
- { { "ss7", "block", "cic", NULL }, handle_ss7_block_cic,
- "Disables SS7 debugging on a linkset", ss7_block_cic_help, NULL },
- { { "ss7", "unblock", "cic", NULL }, handle_ss7_unblock_cic,
- "Disables SS7 debugging on a linkset", ss7_unblock_cic_help, NULL },
- { { "ss7", "show", "linkset", NULL }, handle_ss7_show_linkset,
- "Shows the status of a linkset", ss7_show_linkset_help, NULL },
+ NEW_CLI(handle_ss7_debug, "Enables SS7 debugging on a linkset"),
+ NEW_CLI(handle_ss7_no_debug, "Disables SS7 debugging on a linkset"),
+ NEW_CLI(handle_ss7_block_cic, "Disables SS7 debugging on a linkset"),
+ NEW_CLI(handle_ss7_unblock_cic, "Disables SS7 debugging on a linkset")
+ NEW_CLI(handle_ss7_show_linkset, "Shows the status of a linkset"),
};
#endif /* HAVE_SS7 */