summaryrefslogtreecommitdiff
path: root/main/app.c
diff options
context:
space:
mode:
authorRichard Mudgett <rmudgett@digium.com>2014-06-20 17:06:42 +0000
committerRichard Mudgett <rmudgett@digium.com>2014-06-20 17:06:42 +0000
commit86e8ab5ed47bccf0ee80acfd711eb81b0991522c (patch)
treefcd846af640f5a6dd9b91d732907729ae7ccb6a8 /main/app.c
parent577632dec957bfec258918a381133a3c41411b37 (diff)
voicemail API callbacks: Extract the sayname API call to its own registerd callback.
* Extract the sayname API call to its own registerd callback. This allows the app_directory and app_chanspy applications to say a mailbox owner's name using an alternate provider when app_voicemail is not available because you are using res_mwi_external. app_directory still uses the voicemail.conf file. AFS-64 #close Reported by: Mark Michelson git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@416830 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/app.c')
-rw-r--r--main/app.c88
1 files changed, 85 insertions, 3 deletions
diff --git a/main/app.c b/main/app.c
index 3c2f33c51..822fe6c45 100644
--- a/main/app.c
+++ b/main/app.c
@@ -519,6 +519,66 @@ void ast_vm_unregister(const char *module_name)
ao2_cleanup(table);
}
+/*! \brief The container for the voicemail greeter provider */
+static AO2_GLOBAL_OBJ_STATIC(vm_greeter_provider);
+
+/*! Voicemail greeter not registered warning */
+static int vm_greeter_warnings;
+
+int ast_vm_greeter_is_registered(void)
+{
+ struct ast_vm_greeter_functions *table;
+ int is_registered;
+
+ table = ao2_global_obj_ref(vm_greeter_provider);
+ is_registered = table ? 1 : 0;
+ ao2_cleanup(table);
+ return is_registered;
+}
+
+int __ast_vm_greeter_register(const struct ast_vm_greeter_functions *vm_table, struct ast_module *module)
+{
+ RAII_VAR(struct ast_vm_greeter_functions *, table, NULL, ao2_cleanup);
+
+ if (!vm_table->module_name) {
+ ast_log(LOG_ERROR, "Voicemail greeter provider missing required information.\n");
+ return -1;
+ }
+ if (vm_table->module_version != VM_GREETER_MODULE_VERSION) {
+ ast_log(LOG_ERROR, "Voicemail greeter provider '%s' has incorrect version\n",
+ vm_table->module_name);
+ return -1;
+ }
+
+ table = ao2_global_obj_ref(vm_greeter_provider);
+ if (table) {
+ ast_log(LOG_WARNING, "Voicemail greeter provider already registered by %s.\n",
+ table->module_name);
+ return -1;
+ }
+
+ table = ao2_alloc_options(sizeof(*table), NULL, AO2_ALLOC_OPT_LOCK_NOLOCK);
+ if (!table) {
+ return -1;
+ }
+ *table = *vm_table;
+ table->module = module;
+
+ ao2_global_obj_replace_unref(vm_greeter_provider, table);
+ return 0;
+}
+
+void ast_vm_greeter_unregister(const char *module_name)
+{
+ struct ast_vm_greeter_functions *table;
+
+ table = ao2_global_obj_ref(vm_greeter_provider);
+ if (table && !strcmp(table->module_name, module_name)) {
+ ao2_global_obj_release(vm_greeter_provider);
+ }
+ ao2_cleanup(table);
+}
+
#ifdef TEST_FRAMEWORK
static ast_vm_test_create_user_fn *ast_vm_test_create_user_func = NULL;
static ast_vm_test_destroy_user_fn *ast_vm_test_destroy_user_func = NULL;
@@ -546,7 +606,8 @@ static void vm_warn_no_provider(void)
#define VM_API_CALL(res, api_call, api_parms) \
do { \
- struct ast_vm_functions *table = ao2_global_obj_ref(vm_provider); \
+ struct ast_vm_functions *table; \
+ table = ao2_global_obj_ref(vm_provider); \
if (!table) { \
vm_warn_no_provider(); \
} else if (table->api_call) { \
@@ -557,6 +618,27 @@ static void vm_warn_no_provider(void)
ao2_cleanup(table); \
} while (0)
+static void vm_greeter_warn_no_provider(void)
+{
+ if (vm_greeter_warnings++ % 10 == 0) {
+ ast_verb(3, "No voicemail greeter provider registered.\n");
+ }
+}
+
+#define VM_GREETER_API_CALL(res, api_call, api_parms) \
+ do { \
+ struct ast_vm_greeter_functions *table; \
+ table = ao2_global_obj_ref(vm_greeter_provider); \
+ if (!table) { \
+ vm_greeter_warn_no_provider(); \
+ } else if (table->api_call) { \
+ ast_module_ref(table->module); \
+ (res) = table->api_call api_parms; \
+ ast_module_unref(table->module); \
+ } \
+ ao2_cleanup(table); \
+ } while (0)
+
int ast_app_has_voicemail(const char *mailboxes, const char *folder)
{
int res = 0;
@@ -612,11 +694,11 @@ int ast_app_inboxcount2(const char *mailboxes, int *urgentmsgs, int *newmsgs, in
return res;
}
-int ast_app_sayname(struct ast_channel *chan, const char *mailbox, const char *context)
+int ast_app_sayname(struct ast_channel *chan, const char *mailbox_id)
{
int res = -1;
- VM_API_CALL(res, sayname, (chan, mailbox, context));
+ VM_GREETER_API_CALL(res, sayname, (chan, mailbox_id));
return res;
}