summaryrefslogtreecommitdiff
path: root/apps/app_voicemail.c
diff options
context:
space:
mode:
authorMalcolm Davenport <malcolmd@digium.com>2004-03-19 22:39:02 +0000
committerMalcolm Davenport <malcolmd@digium.com>2004-03-19 22:39:02 +0000
commit5191a04055a3564af6456030600298e5f114052d (patch)
treec3aa8bd6018576322f7b36c7d6ae21a0c0ac8161 /apps/app_voicemail.c
parent9ef542b3cbd7ef17a43ee9fa94ede35eaff9fed8 (diff)
Bug # 1088: Add MailboxExists, conditionally branches to priority n+101
if specified mailbox exists (in the config). Thanks Tilghman git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@2482 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'apps/app_voicemail.c')
-rwxr-xr-xapps/app_voicemail.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c
index 8382d1e19..ca43f8290 100755
--- a/apps/app_voicemail.c
+++ b/apps/app_voicemail.c
@@ -170,6 +170,14 @@ static char *descrip_vmain =
"a context is specified, logins are considered in that context only.\n"
"Returns -1 if the user hangs up or 0 otherwise.\n";
+static char *synopsis_vm_box_exists =
+"Check if vmbox exists";
+
+static char *descrip_vm_box_exists =
+" MailboxExists(mailbox[@context]): Conditionally branches to priority n+101\n"
+"if the specified voice mailbox exists.\n";
+
+
/* Leave a message */
static char *capp = "VoiceMail2";
static char *app = "VoiceMail";
@@ -178,6 +186,8 @@ static char *app = "VoiceMail";
static char *capp2 = "VoiceMailMain2";
static char *app2 = "VoiceMailMain";
+static char *app3 = "MailboxExists";
+
static ast_mutex_t vmlock = AST_MUTEX_INITIALIZER;
struct ast_vm_user *users;
struct ast_vm_user *usersl;
@@ -3051,6 +3061,47 @@ static int append_mailbox(char *context, char *mbox, char *data)
return 0;
}
+static int vm_box_exists(struct ast_channel *chan, void *data) {
+ struct localuser *u;
+ struct ast_vm_user *user;
+ char *context, *box;
+ int branch=0;
+
+ if (!data) {
+ ast_log(LOG_ERROR, "MailboxExists requires an argument: (vmbox[@context])\n");
+ return -1;
+ }
+
+ LOCAL_USER_ADD(u);
+ context = ast_strdupa(data);
+ if (index(context, '@')) {
+ box = strsep(&context, "@");
+ } else {
+ box = context;
+ context = "default";
+ }
+
+ ast_mutex_lock(&vmlock);
+ user = users;
+ while (user) {
+ if ((!strcmp(box,user->mailbox)) && (!strcmp(context,user->context))) {
+ branch = 1;
+ break;
+ }
+ }
+ ast_mutex_unlock(&vmlock);
+
+ if (branch) {
+ if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->callerid)) {
+ chan->priority += 100;
+ } else
+ ast_log(LOG_WARNING, "VM box %s@%s exists, but extension %s, priority %d doesn't exist\n", box, context, chan->exten, chan->priority + 101);
+ }
+ LOCAL_USER_REMOVE(u);
+ return 0;
+}
+
+
#ifndef USEMYSQLVM
/* XXX TL Bug 690 */
static char show_voicemail_users_help[] =
@@ -3426,6 +3477,7 @@ int unload_module(void)
res |= ast_unregister_application(capp);
res |= ast_unregister_application(app2);
res |= ast_unregister_application(capp2);
+ res |= ast_unregister_application(app3);
sql_close();
#ifndef USEMYSQLVM
ast_cli_unregister(&show_voicemail_users_cli);
@@ -3441,6 +3493,7 @@ int load_module(void)
res |= ast_register_application(capp, vm_exec, synopsis_vm, descrip_vm);
res |= ast_register_application(app2, vm_execmain, synopsis_vmain, descrip_vmain);
res |= ast_register_application(capp2, vm_execmain, synopsis_vmain, descrip_vmain);
+ res |= ast_register_application(app3, vm_box_exists, synopsis_vm_box_exists, descrip_vm_box_exists);
if (res)
return(res);