aboutsummaryrefslogtreecommitdiffstats
path: root/apps/app_minivm.c
diff options
context:
space:
mode:
authorqwell <qwell@f38db490-d61c-443f-a65b-d21fe96a405b>2007-09-20 23:14:30 +0000
committerqwell <qwell@f38db490-d61c-443f-a65b-d21fe96a405b>2007-09-20 23:14:30 +0000
commite05724ff65a8b5e3b1dfb993a0726bab7b560c02 (patch)
treeb9bb698c1d4490231aa31c8c252283a03d1e1946 /apps/app_minivm.c
parent41e37ccb3586cc2caf7d592504d4ed7a52f5d397 (diff)
More NEW_CLI conversions.
(issue #10724) Patches: app_playback.c.patch uploaded by moy (license 222) app_minivm.c.patch uploaded by eliel (license 64) astmm.c.patch uploaded by eliel (license 64) git-svn-id: http://svn.digium.com/svn/asterisk/trunk@83381 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'apps/app_minivm.c')
-rw-r--r--apps/app_minivm.c300
1 files changed, 162 insertions, 138 deletions
diff --git a/apps/app_minivm.c b/apps/app_minivm.c
index c9f9fc9a3..e63de2668 100644
--- a/apps/app_minivm.c
+++ b/apps/app_minivm.c
@@ -463,7 +463,7 @@ static char *message_template_parse_filebody(char *filename);
static char *message_template_parse_emailbody(const char *body);
static int create_vmaccount(char *name, struct ast_variable *var, int realtime);
static struct minivm_account *find_user_realtime(const char *domain, const char *username);
-static int handle_minivm_reload(int fd, int argc, char *argv[]);
+static char *handle_minivm_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
/*! \brief Create message template */
static struct minivm_template *message_template_create(const char *name)
@@ -2484,50 +2484,37 @@ static int load_config(int reload)
return 0;
}
-static const char minivm_show_users_help[] =
-"Usage: minivm list accounts\n"
-" Lists all mailboxes currently set up\n";
-
-static const char minivm_show_zones_help[] =
-"Usage: minivm list zones\n"
-" Lists zone message formats\n";
-
-static const char minivm_list_templates_help[] =
-"Usage: minivm list templates\n"
-" Lists message templates for e-mail, paging and IM\n";
-
-static const char minivm_show_stats_help[] =
-"Usage: minivm show stats\n"
-" Display Mini-Voicemail counters\n";
-
-static const char minivm_show_settings_help[] =
-"Usage: minivm show settings\n"
-" Display Mini-Voicemail general settings\n";
-
-static const char minivm_reload_help[] =
-"Usage: minivm reload\n"
-" Reload mini-voicemail configuration and reset statistics\n";
-
/*! \brief CLI routine for listing templates */
-static int handle_minivm_list_templates(int fd, int argc, char *argv[])
+static char *handle_minivm_list_templates(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct minivm_template *this;
char *output_format = "%-15s %-10s %-10s %-15.15s %-50s\n";
int count = 0;
- if (argc > 3)
- return RESULT_SHOWUSAGE;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "minivm list templates";
+ e->usage =
+ "Usage: minivm list templates\n"
+ " Lists message templates for e-mail, paging and IM\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if (a->argc > 3)
+ return CLI_SHOWUSAGE;
AST_LIST_LOCK(&message_templates);
if (AST_LIST_EMPTY(&message_templates)) {
- ast_cli(fd, "There are no message templates defined\n");
+ ast_cli(a->fd, "There are no message templates defined\n");
AST_LIST_UNLOCK(&message_templates);
- return RESULT_FAILURE;
+ return CLI_FAILURE;
}
- ast_cli(fd, output_format, "Template name", "Charset", "Locale", "Attach media", "Subject");
- ast_cli(fd, output_format, "-------------", "-------", "------", "------------", "-------");
+ ast_cli(a->fd, output_format, "Template name", "Charset", "Locale", "Attach media", "Subject");
+ ast_cli(a->fd, output_format, "-------------", "-------", "------", "------------", "-------");
AST_LIST_TRAVERSE(&message_templates, this, list) {
- ast_cli(fd, output_format, this->name,
+ ast_cli(a->fd, output_format, this->name,
this->charset ? this->charset : "-",
this->locale ? this->locale : "-",
this->attachment ? "Yes" : "No",
@@ -2535,38 +2522,71 @@ static int handle_minivm_list_templates(int fd, int argc, char *argv[])
count++;
}
AST_LIST_UNLOCK(&message_templates);
- ast_cli(fd, "\n * Total: %d minivoicemail message templates\n", count);
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "\n * Total: %d minivoicemail message templates\n", count);
+ return CLI_SUCCESS;
+}
+
+static char *complete_minivm_show_users(const char *line, const char *word, int pos, int state)
+{
+ int which = 0;
+ int wordlen;
+ struct minivm_account *vmu;
+ const char *domain = "";
+
+ /* 0 - voicemail; 1 - list; 2 - accounts; 3 - for; 4 - <domain> */
+ if (pos > 4)
+ return NULL;
+ if (pos == 3)
+ return (state == 0) ? ast_strdup("for") : NULL;
+ wordlen = strlen(word);
+ AST_LIST_TRAVERSE(&minivm_accounts, vmu, list) {
+ if (!strncasecmp(word, vmu->domain, wordlen)) {
+ if (domain && strcmp(domain, vmu->domain) && ++which > state)
+ return ast_strdup(vmu->domain);
+ /* ignore repeated domains ? */
+ domain = vmu->domain;
+ }
+ }
+ return NULL;
}
/*! \brief CLI command to list voicemail accounts */
-static int handle_minivm_show_users(int fd, int argc, char *argv[])
+static char *handle_minivm_show_users(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct minivm_account *vmu;
char *output_format = "%-23s %-15s %-15s %-10s %-10s %-50s\n";
int count = 0;
- if ((argc < 3) || (argc > 5) || (argc == 4))
- return RESULT_SHOWUSAGE;
- if ((argc == 5) && strcmp(argv[3],"for"))
- return RESULT_SHOWUSAGE;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "minivm list accounts";
+ e->usage =
+ "Usage: minivm list accounts\n"
+ " Lists all mailboxes currently set up\n";
+ return NULL;
+ case CLI_GENERATE:
+ return complete_minivm_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) && strcmp(a->argv[3],"for"))
+ return CLI_SHOWUSAGE;
AST_LIST_LOCK(&minivm_accounts);
if (AST_LIST_EMPTY(&minivm_accounts)) {
- 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(&minivm_accounts);
- return RESULT_FAILURE;
+ return CLI_FAILURE;
}
- ast_cli(fd, output_format, "User", "E-Template", "P-template", "Zone", "Format", "Full name");
- ast_cli(fd, output_format, "----", "----------", "----------", "----", "------", "---------");
+ ast_cli(a->fd, output_format, "User", "E-Template", "P-template", "Zone", "Format", "Full name");
+ ast_cli(a->fd, output_format, "----", "----------", "----------", "----", "------", "---------");
AST_LIST_TRAVERSE(&minivm_accounts, vmu, list) {
char tmp[256] = "";
-
-
- if ((argc == 3) || ((argc == 5) && !strcmp(argv[4], vmu->domain))) {
+ if ((a->argc == 3) || ((a->argc == 5) && !strcmp(a->argv[4], vmu->domain))) {
count++;
snprintf(tmp, sizeof(tmp), "%s@%s", vmu->username, vmu->domain);
- ast_cli(fd, output_format, tmp, vmu->etemplate ? vmu->etemplate : "-",
+ ast_cli(a->fd, output_format, tmp, vmu->etemplate ? vmu->etemplate : "-",
vmu->ptemplate ? vmu->ptemplate : "-",
vmu->zonetag ? vmu->zonetag : "-",
vmu->attachfmt ? vmu->attachfmt : "-",
@@ -2574,108 +2594,117 @@ static int handle_minivm_show_users(int fd, int argc, char *argv[])
}
}
AST_LIST_UNLOCK(&minivm_accounts);
- ast_cli(fd, "\n * Total: %d minivoicemail accounts\n", count);
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "\n * Total: %d minivoicemail accounts\n", count);
+ return CLI_SUCCESS;
}
/*! \brief Show a list of voicemail zones in the CLI */
-static int handle_minivm_show_zones(int fd, int argc, char *argv[])
+static char *handle_minivm_show_zones(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct minivm_zone *zone;
char *output_format = "%-15s %-20s %-45s\n";
- int res = RESULT_SUCCESS;
+ char *res = CLI_SUCCESS;
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "minivm list zones";
+ e->usage =
+ "Usage: minivm list 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(&minivm_zones);
if (!AST_LIST_EMPTY(&minivm_zones)) {
- ast_cli(fd, output_format, "Zone", "Timezone", "Message Format");
- ast_cli(fd, output_format, "----", "--------", "--------------");
+ ast_cli(a->fd, output_format, "Zone", "Timezone", "Message Format");
+ ast_cli(a->fd, output_format, "----", "--------", "--------------");
AST_LIST_TRAVERSE(&minivm_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(&minivm_zones);
return res;
}
-
-static char *complete_minivm_show_users(const char *line, const char *word, int pos, int state)
+/*! \brief CLI Show settings */
+static char *handle_minivm_show_settings(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
- int which = 0;
- int wordlen;
- struct minivm_account *vmu;
- const char *domain = "";
-
- /* 0 - show; 1 - voicemail; 2 - users; 3 - for; 4 - <domain> */
- if (pos > 4)
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "minivm show settings";
+ e->usage =
+ "Usage: minivm show settings\n"
+ " Display Mini-Voicemail general settings\n";
+ return NULL;
+ case CLI_GENERATE:
return NULL;
- if (pos == 3)
- return (state == 0) ? ast_strdup("for") : NULL;
- wordlen = strlen(word);
- AST_LIST_TRAVERSE(&minivm_accounts, vmu, list) {
- if (!strncasecmp(word, vmu->domain, wordlen)) {
- if (domain && strcmp(domain, vmu->domain) && ++which > state)
- return ast_strdup(vmu->domain);
- /* ignore repeated domains ? */
- domain = vmu->domain;
- }
}
- return NULL;
-}
-/*! \brief CLI Show settings */
-static int handle_minivm_show_settings(int fd, int argc, char *argv[])
-{
- ast_cli(fd, "* Mini-Voicemail general settings\n");
- ast_cli(fd, " -------------------------------\n");
- ast_cli(fd, "\n");
- ast_cli(fd, " Mail command (shell): %s\n", global_mailcmd);
- ast_cli(fd, " Max silence: %d\n", global_maxsilence);
- ast_cli(fd, " Silence treshold: %d\n", global_silencethreshold);
- ast_cli(fd, " Max message length (secs): %d\n", global_vmmaxmessage);
- ast_cli(fd, " Min message length (secs): %d\n", global_vmminmessage);
- ast_cli(fd, " Default format: %s\n", default_vmformat);
- ast_cli(fd, " Extern notify (shell): %s\n", global_externnotify);
- ast_cli(fd, " Logfile: %s\n", global_logfile[0] ? global_logfile : "<disabled>");
- ast_cli(fd, " Operator exit: %s\n", ast_test_flag(&globalflags, MVM_OPERATOR) ? "Yes" : "No");
- ast_cli(fd, " Message review: %s\n", ast_test_flag(&globalflags, MVM_REVIEW) ? "Yes" : "No");
-
- ast_cli(fd, "\n");
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "* Mini-Voicemail general settings\n");
+ ast_cli(a->fd, " -------------------------------\n");
+ ast_cli(a->fd, "\n");
+ ast_cli(a->fd, " Mail command (shell): %s\n", global_mailcmd);
+ ast_cli(a->fd, " Max silence: %d\n", global_maxsilence);
+ ast_cli(a->fd, " Silence treshold: %d\n", global_silencethreshold);
+ ast_cli(a->fd, " Max message length (secs): %d\n", global_vmmaxmessage);
+ ast_cli(a->fd, " Min message length (secs): %d\n", global_vmminmessage);
+ ast_cli(a->fd, " Default format: %s\n", default_vmformat);
+ ast_cli(a->fd, " Extern notify (shell): %s\n", global_externnotify);
+ ast_cli(a->fd, " Logfile: %s\n", global_logfile[0] ? global_logfile : "<disabled>");
+ ast_cli(a->fd, " Operator exit: %s\n", ast_test_flag(&globalflags, MVM_OPERATOR) ? "Yes" : "No");
+ ast_cli(a->fd, " Message review: %s\n", ast_test_flag(&globalflags, MVM_REVIEW) ? "Yes" : "No");
+
+ ast_cli(a->fd, "\n");
+ return CLI_SUCCESS;
}
/*! \brief Show stats */
-static int handle_minivm_show_stats(int fd, int argc, char *argv[])
+static char *handle_minivm_show_stats(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct ast_tm time;
char buf[BUFSIZ];
- ast_cli(fd, "* Mini-Voicemail statistics\n");
- ast_cli(fd, " -------------------------\n");
- ast_cli(fd, "\n");
- ast_cli(fd, " Voicemail accounts: %5d\n", global_stats.voicemailaccounts);
- ast_cli(fd, " Templates: %5d\n", global_stats.templates);
- ast_cli(fd, " Timezones: %5d\n", global_stats.timezones);
+ switch (cmd) {
+
+ case CLI_INIT:
+ e->command = "minivm show stats";
+ e->usage =
+ "Usage: minivm show stats\n"
+ " Display Mini-Voicemail counters\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ ast_cli(a->fd, "* Mini-Voicemail statistics\n");
+ ast_cli(a->fd, " -------------------------\n");
+ ast_cli(a->fd, "\n");
+ ast_cli(a->fd, " Voicemail accounts: %5d\n", global_stats.voicemailaccounts);
+ ast_cli(a->fd, " Templates: %5d\n", global_stats.templates);
+ ast_cli(a->fd, " Timezones: %5d\n", global_stats.timezones);
if (global_stats.receivedmessages == 0) {
- ast_cli(fd, " Received messages since last reset: <none>\n");
+ ast_cli(a->fd, " Received messages since last reset: <none>\n");
} else {
- ast_cli(fd, " Received messages since last reset: %d\n", global_stats.receivedmessages);
+ ast_cli(a->fd, " Received messages since last reset: %d\n", global_stats.receivedmessages);
ast_localtime(&global_stats.lastreceived, &time, NULL);
ast_strftime(buf, sizeof(buf), "%a %b %e %r %Z %Y", &time);
- ast_cli(fd, " Last received voicemail: %s\n", buf);
+ ast_cli(a->fd, " Last received voicemail: %s\n", buf);
}
ast_localtime(&global_stats.reset, &time, NULL);
ast_strftime(buf, sizeof(buf), "%a %b %e %r %Z %Y", &time);
- ast_cli(fd, " Last reset: %s\n", buf);
+ ast_cli(a->fd, " Last reset: %s\n", buf);
- ast_cli(fd, "\n");
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "\n");
+ return CLI_SUCCESS;
}
/*! \brief ${MINIVMACCOUNT()} Dialplan function - reads account data */
@@ -2963,29 +2992,12 @@ static int minivm_counter_func_write(struct ast_channel *chan, const char *cmd,
/*! \brief CLI commands for Mini-voicemail */
static struct ast_cli_entry cli_minivm[] = {
- { { "minivm", "list", "accounts", NULL },
- handle_minivm_show_users, "List defined mini-voicemail boxes",
- minivm_show_users_help, complete_minivm_show_users, NULL },
-
- { { "minivm", "list", "zones", NULL },
- handle_minivm_show_zones, "List zone message formats",
- minivm_show_zones_help, NULL, NULL },
-
- { { "minivm", "list", "templates", NULL },
- handle_minivm_list_templates, "List message templates",
- minivm_list_templates_help, NULL, NULL },
-
- { { "minivm", "reload", NULL, NULL },
- handle_minivm_reload, "Reload Mini-voicemail configuration",
- minivm_reload_help, NULL, NULL },
-
- { { "minivm", "show", "stats", NULL },
- handle_minivm_show_stats, "Show some mini-voicemail statistics",
- minivm_show_stats_help, NULL, NULL },
-
- { { "minivm", "show", "settings", NULL },
- handle_minivm_show_settings, "Show mini-voicemail general settings",
- minivm_show_settings_help, NULL, NULL },
+ NEW_CLI(handle_minivm_show_users, "List defined mini-voicemail boxes"),
+ NEW_CLI(handle_minivm_show_zones, "List zone message formats"),
+ NEW_CLI(handle_minivm_list_templates, "List message templates"),
+ NEW_CLI(handle_minivm_reload, "Reload Mini-voicemail configuration"),
+ NEW_CLI(handle_minivm_show_stats, "Show some mini-voicemail statistics"),
+ NEW_CLI(handle_minivm_show_settings, "Show mini-voicemail general settings"),
};
static struct ast_custom_function minivm_counter_function = {
@@ -3061,11 +3073,23 @@ static int reload(void)
}
/*! \brief Reload cofiguration */
-static int handle_minivm_reload(int fd, int argc, char *argv[])
+static char *handle_minivm_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "minivm reload";
+ e->usage =
+ "Usage: minivm reload\n"
+ " Reload mini-voicemail configuration and reset statistics\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
reload();
- ast_cli(fd, "\n-- Mini voicemail re-configured \n");
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "\n-- Mini voicemail re-configured \n");
+ return CLI_SUCCESS;
}
/*! \brief Unload mini voicemail module */