summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorJason Parker <jparker@digium.com>2007-09-19 23:16:51 +0000
committerJason Parker <jparker@digium.com>2007-09-19 23:16:51 +0000
commitac5332c67483d6442c81cfe2b65bf0daf86ca6b8 (patch)
tree61ab10502e5eb1c8290496cd125473dc3b78cc13 /apps
parent2f0dba3010b0056c62737f99161359fa95b6f6ed (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: https://origsvn.digium.com/svn/asterisk/trunk@83213 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'apps')
-rw-r--r--apps/app_meetme.c304
-rw-r--r--apps/app_queue.c240
-rw-r--r--apps/app_voicemail.c151
3 files changed, 364 insertions, 331 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)