[asterisk-commits] rmudgett: branch 12 r403779 - in /branches/12: apps/ include/asterisk/ main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Dec 13 13:48:09 CST 2013


Author: rmudgett
Date: Fri Dec 13 13:48:05 2013
New Revision: 403779

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=403779
Log:
app_voicemail: Voicemail callback registration/unregistration function improvements.

* The voicemail registration/unregistration functions now take a struct of
callbacks instead of a lengthy parameter list of callbacks.

* The voicemail registration/unregistration functions now prevent a
competing module from interfering with an already registered callback
supplying module.
........

Merged revisions 403643 from http://svn.asterisk.org/svn/asterisk/trunk

Modified:
    branches/12/apps/app_voicemail.c
    branches/12/include/asterisk/app.h
    branches/12/include/asterisk/doxyref.h
    branches/12/main/app.c

Modified: branches/12/apps/app_voicemail.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/apps/app_voicemail.c?view=diff&rev=403779&r1=403778&r2=403779
==============================================================================
--- branches/12/apps/app_voicemail.c (original)
+++ branches/12/apps/app_voicemail.c Fri Dec 13 13:48:05 2013
@@ -14225,6 +14225,25 @@
 }
 #endif /* defined(TEST_FRAMEWORK) */
 
+static const struct ast_vm_functions vm_table = {
+	.module_version = VM_MODULE_VERSION,
+	.module_name = AST_MODULE,
+
+	.has_voicemail = has_voicemail,
+	.inboxcount = inboxcount,
+	.inboxcount2 = inboxcount2,
+	.messagecount = messagecount,
+	.sayname = sayname,
+	.copy_recording_to_vm = msg_create_from_file,
+	.index_to_foldername = vm_index_to_foldername,
+	.mailbox_snapshot_create = vm_mailbox_snapshot_create,
+	.mailbox_snapshot_destroy = vm_mailbox_snapshot_destroy,
+	.msg_move = vm_msg_move,
+	.msg_remove = vm_msg_remove,
+	.msg_forward = vm_msg_forward,
+	.msg_play = vm_msg_play,
+};
+
 static int reload(void)
 {
 	return load_config(1);
@@ -14254,7 +14273,7 @@
 	res |= AST_TEST_UNREGISTER(test_voicemail_vm_info);
 #endif
 	ast_cli_unregister_multiple(cli_voicemail, ARRAY_LEN(cli_voicemail));
-	ast_uninstall_vm_functions();
+	ast_vm_unregister(vm_table.module_name);
 #ifdef TEST_FRAMEWORK
 	ast_uninstall_vm_test_functions();
 #endif
@@ -14321,16 +14340,12 @@
 	res |= AST_TEST_REGISTER(test_voicemail_vm_info);
 #endif
 
+	res |= ast_vm_register(&vm_table);
 	if (res)
 		return res;
 
 	ast_cli_register_multiple(cli_voicemail, ARRAY_LEN(cli_voicemail));
 	ast_data_register_multiple(vm_data_providers, ARRAY_LEN(vm_data_providers));
-
-	ast_install_vm_functions(has_voicemail, inboxcount, inboxcount2, messagecount, sayname, msg_create_from_file,
-				 vm_index_to_foldername,
-				 vm_mailbox_snapshot_create, vm_mailbox_snapshot_destroy,
-				 vm_msg_move, vm_msg_remove, vm_msg_forward, vm_msg_play);
 
 #ifdef TEST_FRAMEWORK
 	ast_install_vm_test_functions(vm_test_create_user, vm_test_destroy_user);

Modified: branches/12/include/asterisk/app.h
URL: http://svnview.digium.com/svn/asterisk/branches/12/include/asterisk/app.h?view=diff&rev=403779&r1=403778&r2=403779
==============================================================================
--- branches/12/include/asterisk/app.h (original)
+++ branches/12/include/asterisk/app.h Fri Dec 13 13:48:05 2013
@@ -334,19 +334,19 @@
 /*!
  * \brief Determines if the given folder has messages.
  *
- * \param mailbox Comma or & delimited list of mailboxes (user at context).
+ * \param mailboxes Comma or & delimited list of mailboxes (user at context).
  *          If no context is found, uses 'default' for the context.
  * \param folder The folder to look in.  Default is INBOX if not provided.
  *
  * \retval 1 if the folder has one or more messages.
  * \retval 0 otherwise.
  */
-typedef int (ast_has_voicemail_fn)(const char *mailbox, const char *folder);
+typedef int (ast_has_voicemail_fn)(const char *mailboxes, const char *folder);
 
 /*!
  * \brief Gets the number of messages that exist for the mailbox list.
  *
- * \param mailbox Comma or space delimited list of mailboxes (user at context).
+ * \param mailboxes Comma or space delimited list of mailboxes (user at context).
  *          If no context is found, uses 'default' for the context.
  * \param newmsgs Where to put the count of new messages. (Can be NULL)
  * \param oldmsgs Where to put the count of old messages. (Can be NULL)
@@ -358,12 +358,12 @@
  * \retval 0 on success
  * \retval -1 on failure
  */
-typedef int (ast_inboxcount_fn)(const char *mailbox, int *newmsgs, int *oldmsgs);
+typedef int (ast_inboxcount_fn)(const char *mailboxes, int *newmsgs, int *oldmsgs);
 
 /*!
  * \brief Gets the number of messages that exist for the mailbox list.
  *
- * \param mailbox Comma or space delimited list of mailboxes (user at context).
+ * \param mailboxes Comma or space delimited list of mailboxes (user at context).
  *          If no context is found, uses 'default' for the context.
  * \param urgentmsgs Where to put the count of urgent messages. (Can be NULL)
  * \param newmsgs Where to put the count of new messages. (Can be NULL)
@@ -377,13 +377,13 @@
  * \retval 0 on success
  * \retval -1 on failure
  */
-typedef int (ast_inboxcount2_fn)(const char *mailbox, int *urgentmsgs, int *newmsgs, int *oldmsgs);
+typedef int (ast_inboxcount2_fn)(const char *mailboxes, int *urgentmsgs, int *newmsgs, int *oldmsgs);
 
 /*!
  * \brief Gets the number of messages that exist in a mailbox folder.
  *
  * \param context The context part of user at context.  Uses 'default' if not provided.
- * \param mailbox The user part of user at context.
+ * \param user The user part of user at context.
  * \param folder The folder to look in.  Default is INBOX if not provided.
  *
  * \note If requesting INBOX then the returned count is INBOX +
@@ -391,20 +391,20 @@
  *
  * \return The number of messages in this mailbox folder (zero or more).
  */
-typedef int (ast_messagecount_fn)(const char *context, const char *mailbox, const char *folder);
+typedef int (ast_messagecount_fn)(const char *context, const char *user, const char *folder);
 
 /*!
  * \brief Play a recorded user name for the mailbox.
  *
  * \param chan Where to play the recorded name file.
- * \param mailbox The user part of user at context.
+ * \param user The user part of user at context.
  * \param context The context part of user at context.  Must be explicit.
  *
  * \retval 0 Name played without interruption
  * \retval dtmf ASCII value of the DTMF which interrupted playback
  * \retval -1 on failure
  */
-typedef int (ast_sayname_fn)(struct ast_channel *chan, const char *mailbox, const char *context);
+typedef int (ast_sayname_fn)(struct ast_channel *chan, const char *user, const char *context);
 
 /*!
  * \brief Creates a voicemail based on a specified file to a mailbox.
@@ -430,7 +430,7 @@
 /*!
  * \brief Create a snapshot of a mailbox which contains information about every msg.
  *
- * \param mailbox The user part of user at context.
+ * \param user The user part of user at context.
  * \param context The context part of user at context.  Must be explicit.
  * \param folder When not NULL only msgs from the specified folder will be included.
  * \param descending list the msgs in descending order rather than ascending order.
@@ -444,7 +444,7 @@
  * \retval snapshot on success
  * \retval NULL on failure
  */
-typedef struct ast_vm_mailbox_snapshot *(ast_vm_mailbox_snapshot_create_fn)(const char *mailbox,
+typedef struct ast_vm_mailbox_snapshot *(ast_vm_mailbox_snapshot_create_fn)(const char *user,
 	const char *context, const char *folder, int descending,
 	enum ast_vm_snapshot_sort_val sort_val, int combine_INBOX_and_OLD);
 
@@ -536,45 +536,63 @@
 typedef int (ast_vm_msg_play_fn)(struct ast_channel *chan, const char *mailbox,
 	const char *context, const char *folder, const char *msg_num, ast_vm_msg_play_cb *cb);
 
+#define VM_MODULE_VERSION 1
+
+/*! \brief Voicemail function table definition. */
+struct ast_vm_functions {
+	/*!
+	 * \brief The version of this function table.
+	 *
+	 * \note If the ABI for this table changes, the module version
+	 * (\ref VM_MODULE_VERSION) should be incremented.
+	 */
+	unsigned int module_version;
+	/*! \brief The name of the module that provides the voicemail functionality */
+	const char *module_name;
+	/*! \brief The module for the voicemail provider */
+	struct ast_module *module;
+
+	ast_has_voicemail_fn *has_voicemail;
+	ast_inboxcount_fn *inboxcount;
+	ast_inboxcount2_fn *inboxcount2;
+	ast_messagecount_fn *messagecount;
+	ast_sayname_fn *sayname;
+	ast_copy_recording_to_vm_fn *copy_recording_to_vm;
+	ast_vm_index_to_foldername_fn *index_to_foldername;
+	ast_vm_mailbox_snapshot_create_fn *mailbox_snapshot_create;
+	ast_vm_mailbox_snapshot_destroy_fn *mailbox_snapshot_destroy;
+	ast_vm_msg_move_fn *msg_move;
+	ast_vm_msg_remove_fn *msg_remove;
+	ast_vm_msg_forward_fn *msg_forward;
+	ast_vm_msg_play_fn *msg_play;
+};
+
 /*!
  * \brief Set voicemail function callbacks
  *
- * \param has_voicemail_func set function pointer
- * \param inboxcount_func set function pointer
- * \param inboxcount2_func set function pointer
- * \param messagecount_func set function pointer
- * \param sayname_func set function pointer
- * \param copy_recording_to_vm_func set function pointer
- * \param vm_index_to_foldername_func set function pointer
- * \param vm_mailbox_snapshot_create_func set function pointer
- * \param vm_mailbox_snapshot_destroy_func set function pointer
- * \param vm_msg_move_func set function pointer
- * \param vm_msg_remove_func set function pointer
- * \param vm_msg_forward_func set function pointer
- * \param vm_msg_play_func set function pointer
- *
- * \version 1.6.1 Added inboxcount2_func, sayname_func
- */
-void ast_install_vm_functions(ast_has_voicemail_fn *has_voicemail_func,
-	ast_inboxcount_fn *inboxcount_func,
-	ast_inboxcount2_fn *inboxcount2_func,
-	ast_messagecount_fn *messagecount_func,
-	ast_sayname_fn *sayname_func,
-	ast_copy_recording_to_vm_fn *copy_recording_to_vm_func,
-	ast_vm_index_to_foldername_fn *vm_index_to_foldername_func,
-	ast_vm_mailbox_snapshot_create_fn *vm_mailbox_snapshot_create_func,
-	ast_vm_mailbox_snapshot_destroy_fn *vm_mailbox_snapshot_destroy_func,
-	ast_vm_msg_move_fn *vm_msg_move_func,
-	ast_vm_msg_remove_fn *vm_msg_remove_func,
-	ast_vm_msg_forward_fn *vm_msg_forward_func,
-	ast_vm_msg_play_fn *vm_msg_play_func);
-
-
-void ast_uninstall_vm_functions(void);
+ * \param vm_table Voicemail function table to install.
+ * \param module Pointer to the module implementing the interface
+ *
+ * \retval 0 on success.
+ * \retval -1 on error.
+ */
+int __ast_vm_register(const struct ast_vm_functions *vm_table, struct ast_module *module);
+
+/*! \brief See \ref __ast_vm_register() */
+#define ast_vm_register(vm_table) __ast_vm_register(vm_table, ast_module_info ? ast_module_info->self : NULL)
+
+/*!
+ * \brief Unregister the specified voicemail provider
+ *
+ * \param The module name of the provider to unregister
+ *
+ * \return Nothing
+ */
+void ast_vm_unregister(const char *module_name);
 
 #ifdef TEST_FRAMEWORK
-typedef int (ast_vm_test_create_user_fn)(const char *context, const char *mailbox);
-typedef int (ast_vm_test_destroy_user_fn)(const char *context, const char *mailbox);
+typedef int (ast_vm_test_create_user_fn)(const char *context, const char *user);
+typedef int (ast_vm_test_destroy_user_fn)(const char *context, const char *user);
 
 void ast_install_vm_test_functions(ast_vm_test_create_user_fn *vm_test_create_user_func,
 	ast_vm_test_destroy_user_fn *vm_test_destroy_user_func);
@@ -599,12 +617,12 @@
  * \retval -1 Failure
  * \since 1.0
  */
-int ast_app_has_voicemail(const char *mailbox, const char *folder);
+int ast_app_has_voicemail(const char *mailboxes, const char *folder);
 
 /*!
  * \brief Determine number of new/old messages in a mailbox
  * \since 1.0
- * \param[in] mailbox Mailbox specification in the format
+ * \param[in] mailboxes Mailbox specification in the format
  * 	/code
  *	 mbox[\@context][&mbox2[\@context2]][...]
  *	/code
@@ -613,18 +631,18 @@
  * \retval 0 Success
  * \retval -1 Failure
  */
-int ast_app_inboxcount(const char *mailbox, int *newmsgs, int *oldmsgs);
+int ast_app_inboxcount(const char *mailboxes, int *newmsgs, int *oldmsgs);
 
 /*!
  * \brief Determine number of urgent/new/old messages in a mailbox
- * \param[in] mailbox the mailbox context to use
+ * \param[in] mailboxes the mailbox context to use
  * \param[out] urgentmsgs the urgent message count
  * \param[out] newmsgs the new message count
  * \param[out] oldmsgs the old message count
  * \return Returns 0 for success, negative upon error
  * \since 1.6.1
  */
-int ast_app_inboxcount2(const char *mailbox, int *urgentmsgs, int *newmsgs, int *oldmsgs);
+int ast_app_inboxcount2(const char *mailboxes, int *urgentmsgs, int *newmsgs, int *oldmsgs);
 
 /*!
  * \brief Given a mailbox and context, play that mailbox owner's name to the channel specified

Modified: branches/12/include/asterisk/doxyref.h
URL: http://svnview.digium.com/svn/asterisk/branches/12/include/asterisk/doxyref.h?view=diff&rev=403779&r1=403778&r2=403779
==============================================================================
--- branches/12/include/asterisk/doxyref.h (original)
+++ branches/12/include/asterisk/doxyref.h Fri Dec 13 13:48:05 2013
@@ -99,7 +99,6 @@
  * \page AstAPIChanges Asterisk API Changes
  *
  * \section Changes161 Version 1.6.1
- * \li ast_install_vm_functions()
  * \li vmwi_generate()
  * \li ast_channel_datastore_alloc()
  * \li ast_channel_datastore_free()

Modified: branches/12/main/app.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/main/app.c?view=diff&rev=403779&r1=403778&r2=403779
==============================================================================
--- branches/12/main/app.c (original)
+++ branches/12/main/app.c Fri Dec 13 13:48:05 2013
@@ -426,64 +426,53 @@
 	return res;
 }
 
-static ast_has_voicemail_fn *ast_has_voicemail_func = NULL;
-static ast_inboxcount_fn *ast_inboxcount_func = NULL;
-static ast_inboxcount2_fn *ast_inboxcount2_func = NULL;
-static ast_sayname_fn *ast_sayname_func = NULL;
-static ast_messagecount_fn *ast_messagecount_func = NULL;
-static ast_copy_recording_to_vm_fn *ast_copy_recording_to_vm_func = NULL;
-static ast_vm_index_to_foldername_fn *ast_vm_index_to_foldername_func = NULL;
-static ast_vm_mailbox_snapshot_create_fn *ast_vm_mailbox_snapshot_create_func = NULL;
-static ast_vm_mailbox_snapshot_destroy_fn *ast_vm_mailbox_snapshot_destroy_func = NULL;
-static ast_vm_msg_move_fn *ast_vm_msg_move_func = NULL;
-static ast_vm_msg_remove_fn *ast_vm_msg_remove_func = NULL;
-static ast_vm_msg_forward_fn *ast_vm_msg_forward_func = NULL;
-static ast_vm_msg_play_fn *ast_vm_msg_play_func = NULL;
-
-void ast_install_vm_functions(ast_has_voicemail_fn *has_voicemail_func,
-	ast_inboxcount_fn *inboxcount_func,
-	ast_inboxcount2_fn *inboxcount2_func,
-	ast_messagecount_fn *messagecount_func,
-	ast_sayname_fn *sayname_func,
-	ast_copy_recording_to_vm_fn *copy_recording_to_vm_func,
-	ast_vm_index_to_foldername_fn *vm_index_to_foldername_func,
-	ast_vm_mailbox_snapshot_create_fn *vm_mailbox_snapshot_create_func,
-	ast_vm_mailbox_snapshot_destroy_fn *vm_mailbox_snapshot_destroy_func,
-	ast_vm_msg_move_fn *vm_msg_move_func,
-	ast_vm_msg_remove_fn *vm_msg_remove_func,
-	ast_vm_msg_forward_fn *vm_msg_forward_func,
-	ast_vm_msg_play_fn *vm_msg_play_func)
-{
-	ast_has_voicemail_func = has_voicemail_func;
-	ast_inboxcount_func = inboxcount_func;
-	ast_inboxcount2_func = inboxcount2_func;
-	ast_messagecount_func = messagecount_func;
-	ast_sayname_func = sayname_func;
-	ast_copy_recording_to_vm_func = copy_recording_to_vm_func;
-	ast_vm_index_to_foldername_func = vm_index_to_foldername_func;
-	ast_vm_mailbox_snapshot_create_func = vm_mailbox_snapshot_create_func;
-	ast_vm_mailbox_snapshot_destroy_func = vm_mailbox_snapshot_destroy_func;
-	ast_vm_msg_move_func = vm_msg_move_func;
-	ast_vm_msg_remove_func = vm_msg_remove_func;
-	ast_vm_msg_forward_func = vm_msg_forward_func;
-	ast_vm_msg_play_func = vm_msg_play_func;
-}
-
-void ast_uninstall_vm_functions(void)
-{
-	ast_has_voicemail_func = NULL;
-	ast_inboxcount_func = NULL;
-	ast_inboxcount2_func = NULL;
-	ast_messagecount_func = NULL;
-	ast_sayname_func = NULL;
-	ast_copy_recording_to_vm_func = NULL;
-	ast_vm_index_to_foldername_func = NULL;
-	ast_vm_mailbox_snapshot_create_func = NULL;
-	ast_vm_mailbox_snapshot_destroy_func = NULL;
-	ast_vm_msg_move_func = NULL;
-	ast_vm_msg_remove_func = NULL;
-	ast_vm_msg_forward_func = NULL;
-	ast_vm_msg_play_func = NULL;
+/*! \brief The container for the voicemail provider */
+static AO2_GLOBAL_OBJ_STATIC(vm_provider);
+
+/*! Voicemail not registered warning */
+static int vm_warnings;
+
+int __ast_vm_register(const struct ast_vm_functions *vm_table, struct ast_module *module)
+{
+	RAII_VAR(struct ast_vm_functions *, table, NULL, ao2_cleanup);
+
+	if (!vm_table->module_name) {
+		ast_log(LOG_ERROR, "Voicemail provider missing required information.\n");
+		return -1;
+	}
+	if (vm_table->module_version != VM_MODULE_VERSION) {
+		ast_log(LOG_ERROR, "Voicemail provider '%s' has incorrect version\n",
+			vm_table->module_name);
+		return -1;
+	}
+
+	table = ao2_global_obj_ref(vm_provider);
+	if (table) {
+		ast_log(LOG_WARNING, "Voicemail 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_provider, table);
+	return 0;
+}
+
+void ast_vm_unregister(const char *module_name)
+{
+	struct ast_vm_functions *table;
+
+	table = ao2_global_obj_ref(vm_provider);
+	if (table && !strcmp(table->module_name, module_name)) {
+		ao2_global_obj_release(vm_provider);
+	}
+	ao2_cleanup(table);
 }
 
 #ifdef TEST_FRAMEWORK
@@ -504,17 +493,32 @@
 }
 #endif
 
-int ast_app_has_voicemail(const char *mailbox, const char *folder)
-{
-	static int warned = 0;
-	if (ast_has_voicemail_func) {
-		return ast_has_voicemail_func(mailbox, folder);
-	}
-
-	if (warned++ % 10 == 0) {
-		ast_verb(3, "Message check requested for mailbox %s/folder %s but voicemail not loaded.\n", mailbox, folder ? folder : "INBOX");
-	}
-	return 0;
+static void vm_warn_no_provider(void)
+{
+	if (vm_warnings++ % 10 == 0) {
+		ast_verb(3, "No voicemail provider registered.\n");
+	}
+}
+
+#define VM_API_CALL(res, api_call, api_parms)								\
+	do {																	\
+		struct ast_vm_functions *table = ao2_global_obj_ref(vm_provider);	\
+		if (!table) {														\
+			vm_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;
+
+	VM_API_CALL(res, has_voicemail, (mailboxes, folder));
+	return res;
 }
 
 /*!
@@ -525,44 +529,31 @@
  */
 int ast_app_copy_recording_to_vm(struct ast_vm_recording_data *vm_rec_data)
 {
-	static int warned = 0;
-
-	if (ast_copy_recording_to_vm_func) {
-		return ast_copy_recording_to_vm_func(vm_rec_data);
-	}
-
-	if (warned++ % 10 == 0) {
-		ast_verb(3, "copy recording to voicemail called to copy %s.%s to %s@%s, but voicemail not loaded.\n",
-			vm_rec_data->recording_file, vm_rec_data->recording_ext,
-			vm_rec_data->mailbox, vm_rec_data->context);
-	}
-
-	return -1;
-}
-
-int ast_app_inboxcount(const char *mailbox, int *newmsgs, int *oldmsgs)
-{
-	static int warned = 0;
+	int res = -1;
+
+	VM_API_CALL(res, copy_recording_to_vm, (vm_rec_data));
+	return res;
+}
+
+int ast_app_inboxcount(const char *mailboxes, int *newmsgs, int *oldmsgs)
+{
+	int res = 0;
+
 	if (newmsgs) {
 		*newmsgs = 0;
 	}
 	if (oldmsgs) {
 		*oldmsgs = 0;
 	}
-	if (ast_inboxcount_func) {
-		return ast_inboxcount_func(mailbox, newmsgs, oldmsgs);
-	}
-
-	if (warned++ % 10 == 0) {
-		ast_verb(3, "Message count requested for mailbox %s but voicemail not loaded.\n", mailbox);
-	}
-
-	return 0;
-}
-
-int ast_app_inboxcount2(const char *mailbox, int *urgentmsgs, int *newmsgs, int *oldmsgs)
-{
-	static int warned = 0;
+
+	VM_API_CALL(res, inboxcount, (mailboxes, newmsgs, oldmsgs));
+	return res;
+}
+
+int ast_app_inboxcount2(const char *mailboxes, int *urgentmsgs, int *newmsgs, int *oldmsgs)
+{
+	int res = 0;
+
 	if (newmsgs) {
 		*newmsgs = 0;
 	}
@@ -572,46 +563,33 @@
 	if (urgentmsgs) {
 		*urgentmsgs = 0;
 	}
-	if (ast_inboxcount2_func) {
-		return ast_inboxcount2_func(mailbox, urgentmsgs, newmsgs, oldmsgs);
-	}
-
-	if (warned++ % 10 == 0) {
-		ast_verb(3, "Message count requested for mailbox %s but voicemail not loaded.\n", mailbox);
-	}
-
-	return 0;
+
+	VM_API_CALL(res, inboxcount2, (mailboxes, urgentmsgs, newmsgs, oldmsgs));
+	return res;
 }
 
 int ast_app_sayname(struct ast_channel *chan, const char *mailbox, const char *context)
 {
-	if (ast_sayname_func) {
-		return ast_sayname_func(chan, mailbox, context);
-	}
-	return -1;
+	int res = -1;
+
+	VM_API_CALL(res, sayname, (chan, mailbox, context));
+	return res;
 }
 
 int ast_app_messagecount(const char *context, const char *mailbox, const char *folder)
 {
-	static int warned = 0;
-	if (ast_messagecount_func) {
-		return ast_messagecount_func(context, mailbox, folder);
-	}
-
-	if (!warned) {
-		warned++;
-		ast_verb(3, "Message count requested for mailbox %s@%s/%s but voicemail not loaded.\n", mailbox, context, folder);
-	}
-
-	return 0;
+	int res = 0;
+
+	VM_API_CALL(res, messagecount, (context, mailbox, folder));
+	return res;
 }
 
 const char *ast_vm_index_to_foldername(int id)
 {
-	if (ast_vm_index_to_foldername_func) {
-		return ast_vm_index_to_foldername_func(id);
-	}
-	return NULL;
+	const char *res = NULL;
+
+	VM_API_CALL(res, index_to_foldername, (id));
+	return res;
 }
 
 struct ast_vm_mailbox_snapshot *ast_vm_mailbox_snapshot_create(const char *mailbox,
@@ -621,18 +599,19 @@
 	enum ast_vm_snapshot_sort_val sort_val,
 	int combine_INBOX_and_OLD)
 {
-	if (ast_vm_mailbox_snapshot_create_func) {
-		return ast_vm_mailbox_snapshot_create_func(mailbox, context, folder, descending, sort_val, combine_INBOX_and_OLD);
-	}
-	return NULL;
+	struct ast_vm_mailbox_snapshot *res = NULL;
+
+	VM_API_CALL(res, mailbox_snapshot_create, (mailbox, context, folder, descending,
+		sort_val, combine_INBOX_and_OLD));
+	return res;
 }
 
 struct ast_vm_mailbox_snapshot *ast_vm_mailbox_snapshot_destroy(struct ast_vm_mailbox_snapshot *mailbox_snapshot)
 {
-	if (ast_vm_mailbox_snapshot_destroy_func) {
-		return ast_vm_mailbox_snapshot_destroy_func(mailbox_snapshot);
-	}
-	return NULL;
+	struct ast_vm_mailbox_snapshot *res = NULL;
+
+	VM_API_CALL(res, mailbox_snapshot_destroy, (mailbox_snapshot));
+	return res;
 }
 
 int ast_vm_msg_move(const char *mailbox,
@@ -642,10 +621,11 @@
 	const char *old_msg_ids[],
 	const char *newfolder)
 {
-	if (ast_vm_msg_move_func) {
-		return ast_vm_msg_move_func(mailbox, context, num_msgs, oldfolder, old_msg_ids, newfolder);
-	}
-	return 0;
+	int res = 0;
+
+	VM_API_CALL(res, msg_move, (mailbox, context, num_msgs, oldfolder, old_msg_ids,
+		newfolder));
+	return res;
 }
 
 int ast_vm_msg_remove(const char *mailbox,
@@ -654,10 +634,10 @@
 	const char *folder,
 	const char *msgs[])
 {
-	if (ast_vm_msg_remove_func) {
-		return ast_vm_msg_remove_func(mailbox, context, num_msgs, folder, msgs);
-	}
-	return 0;
+	int res = 0;
+
+	VM_API_CALL(res, msg_remove, (mailbox, context, num_msgs, folder, msgs));
+	return res;
 }
 
 int ast_vm_msg_forward(const char *from_mailbox,
@@ -670,10 +650,11 @@
 	const char *msg_ids[],
 	int delete_old)
 {
-	if (ast_vm_msg_forward_func) {
-		return ast_vm_msg_forward_func(from_mailbox, from_context, from_folder, to_mailbox, to_context, to_folder, num_msgs, msg_ids, delete_old);
-	}
-	return 0;
+	int res = 0;
+
+	VM_API_CALL(res, msg_forward, (from_mailbox, from_context, from_folder, to_mailbox,
+		to_context, to_folder, num_msgs, msg_ids, delete_old));
+	return res;
 }
 
 int ast_vm_msg_play(struct ast_channel *chan,
@@ -683,10 +664,10 @@
 	const char *msg_num,
 	ast_vm_msg_play_cb *cb)
 {
-	if (ast_vm_msg_play_func) {
-		return ast_vm_msg_play_func(chan, mailbox, context, folder, msg_num, cb);
-	}
-	return 0;
+	int res = 0;
+
+	VM_API_CALL(res, msg_play, (chan, mailbox, context, folder, msg_num, cb));
+	return res;
 }
 
 #ifdef TEST_FRAMEWORK




More information about the asterisk-commits mailing list