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.


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@403643 65c4cc65-6c06-0410-ace0-fbb531ad65f3
changes/97/197/1
Richard Mudgett 12 years ago
parent ce423d2ea4
commit 8183bba99a

@ -14225,6 +14225,25 @@ AST_TEST_DEFINE(test_voicemail_vm_info)
} }
#endif /* defined(TEST_FRAMEWORK) */ #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) static int reload(void)
{ {
return load_config(1); return load_config(1);
@ -14254,7 +14273,7 @@ static int unload_module(void)
res |= AST_TEST_UNREGISTER(test_voicemail_vm_info); res |= AST_TEST_UNREGISTER(test_voicemail_vm_info);
#endif #endif
ast_cli_unregister_multiple(cli_voicemail, ARRAY_LEN(cli_voicemail)); ast_cli_unregister_multiple(cli_voicemail, ARRAY_LEN(cli_voicemail));
ast_uninstall_vm_functions(); ast_vm_unregister(vm_table.module_name);
#ifdef TEST_FRAMEWORK #ifdef TEST_FRAMEWORK
ast_uninstall_vm_test_functions(); ast_uninstall_vm_test_functions();
#endif #endif
@ -14321,17 +14340,13 @@ static int load_module(void)
res |= AST_TEST_REGISTER(test_voicemail_vm_info); res |= AST_TEST_REGISTER(test_voicemail_vm_info);
#endif #endif
res |= ast_vm_register(&vm_table);
if (res) if (res)
return res; return res;
ast_cli_register_multiple(cli_voicemail, ARRAY_LEN(cli_voicemail)); ast_cli_register_multiple(cli_voicemail, ARRAY_LEN(cli_voicemail));
ast_data_register_multiple(vm_data_providers, ARRAY_LEN(vm_data_providers)); 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 #ifdef TEST_FRAMEWORK
ast_install_vm_test_functions(vm_test_create_user, vm_test_destroy_user); ast_install_vm_test_functions(vm_test_create_user, vm_test_destroy_user);
#endif #endif

@ -334,19 +334,19 @@ typedef void (ast_vm_msg_play_cb)(struct ast_channel *chan, const char *playfile
/*! /*!
* \brief Determines if the given folder has messages. * \brief Determines if the given folder has messages.
* *
* \param mailbox Comma or & delimited list of mailboxes (user@context). * \param mailboxes Comma or & delimited list of mailboxes (user@context).
* If no context is found, uses 'default' for the context. * If no context is found, uses 'default' for the context.
* \param folder The folder to look in. Default is INBOX if not provided. * \param folder The folder to look in. Default is INBOX if not provided.
* *
* \retval 1 if the folder has one or more messages. * \retval 1 if the folder has one or more messages.
* \retval 0 otherwise. * \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. * \brief Gets the number of messages that exist for the mailbox list.
* *
* \param mailbox Comma or space delimited list of mailboxes (user@context). * \param mailboxes Comma or space delimited list of mailboxes (user@context).
* If no context is found, uses 'default' for the 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 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) * \param oldmsgs Where to put the count of old messages. (Can be NULL)
@ -358,12 +358,12 @@ typedef int (ast_has_voicemail_fn)(const char *mailbox, const char *folder);
* \retval 0 on success * \retval 0 on success
* \retval -1 on failure * \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. * \brief Gets the number of messages that exist for the mailbox list.
* *
* \param mailbox Comma or space delimited list of mailboxes (user@context). * \param mailboxes Comma or space delimited list of mailboxes (user@context).
* If no context is found, uses 'default' for the 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 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) * \param newmsgs Where to put the count of new messages. (Can be NULL)
@ -377,13 +377,13 @@ typedef int (ast_inboxcount_fn)(const char *mailbox, int *newmsgs, int *oldmsgs)
* \retval 0 on success * \retval 0 on success
* \retval -1 on failure * \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. * \brief Gets the number of messages that exist in a mailbox folder.
* *
* \param context The context part of user@context. Uses 'default' if not provided. * \param context The context part of user@context. Uses 'default' if not provided.
* \param mailbox The user part of user@context. * \param user The user part of user@context.
* \param folder The folder to look in. Default is INBOX if not provided. * \param folder The folder to look in. Default is INBOX if not provided.
* *
* \note If requesting INBOX then the returned count is INBOX + * \note If requesting INBOX then the returned count is INBOX +
@ -391,20 +391,20 @@ typedef int (ast_inboxcount2_fn)(const char *mailbox, int *urgentmsgs, int *newm
* *
* \return The number of messages in this mailbox folder (zero or more). * \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. * \brief Play a recorded user name for the mailbox.
* *
* \param chan Where to play the recorded name file. * \param chan Where to play the recorded name file.
* \param mailbox The user part of user@context. * \param user The user part of user@context.
* \param context The context part of user@context. Must be explicit. * \param context The context part of user@context. Must be explicit.
* *
* \retval 0 Name played without interruption * \retval 0 Name played without interruption
* \retval dtmf ASCII value of the DTMF which interrupted playback * \retval dtmf ASCII value of the DTMF which interrupted playback
* \retval -1 on failure * \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. * \brief Creates a voicemail based on a specified file to a mailbox.
@ -430,7 +430,7 @@ typedef const char *(ast_vm_index_to_foldername_fn)(int id);
/*! /*!
* \brief Create a snapshot of a mailbox which contains information about every msg. * \brief Create a snapshot of a mailbox which contains information about every msg.
* *
* \param mailbox The user part of user@context. * \param user The user part of user@context.
* \param context The context part of user@context. Must be explicit. * \param context The context part of user@context. Must be explicit.
* \param folder When not NULL only msgs from the specified folder will be included. * \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. * \param descending list the msgs in descending order rather than ascending order.
@ -444,7 +444,7 @@ typedef const char *(ast_vm_index_to_foldername_fn)(int id);
* \retval snapshot on success * \retval snapshot on success
* \retval NULL on failure * \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, const char *context, const char *folder, int descending,
enum ast_vm_snapshot_sort_val sort_val, int combine_INBOX_and_OLD); enum ast_vm_snapshot_sort_val sort_val, int combine_INBOX_and_OLD);
@ -536,45 +536,63 @@ typedef int (ast_vm_msg_forward_fn)(const char *from_mailbox, const char *from_c
typedef int (ast_vm_msg_play_fn)(struct ast_channel *chan, const char *mailbox, 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); 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 * \brief Set voicemail function callbacks
* *
* \param has_voicemail_func set function pointer * \param vm_table Voicemail function table to install.
* \param inboxcount_func set function pointer * \param module Pointer to the module implementing the interface
* \param inboxcount2_func set function pointer *
* \param messagecount_func set function pointer * \retval 0 on success.
* \param sayname_func set function pointer * \retval -1 on error.
* \param copy_recording_to_vm_func set function pointer */
* \param vm_index_to_foldername_func set function pointer int __ast_vm_register(const struct ast_vm_functions *vm_table, struct ast_module *module);
* \param vm_mailbox_snapshot_create_func set function pointer
* \param vm_mailbox_snapshot_destroy_func set function pointer /*! \brief See \ref __ast_vm_register() */
* \param vm_msg_move_func set function pointer #define ast_vm_register(vm_table) __ast_vm_register(vm_table, ast_module_info ? ast_module_info->self : NULL)
* \param vm_msg_remove_func set function pointer
* \param vm_msg_forward_func set function pointer /*!
* \param vm_msg_play_func set function pointer * \brief Unregister the specified voicemail provider
* *
* \version 1.6.1 Added inboxcount2_func, sayname_func * \param The module name of the provider to unregister
*/ *
void ast_install_vm_functions(ast_has_voicemail_fn *has_voicemail_func, * \return Nothing
ast_inboxcount_fn *inboxcount_func, */
ast_inboxcount2_fn *inboxcount2_func, void ast_vm_unregister(const char *module_name);
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);
#ifdef TEST_FRAMEWORK #ifdef TEST_FRAMEWORK
typedef int (ast_vm_test_create_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 *mailbox); 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, 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); ast_vm_test_destroy_user_fn *vm_test_destroy_user_func);
@ -599,12 +617,12 @@ int ast_app_copy_recording_to_vm(struct ast_vm_recording_data *vm_rec_data);
* \retval -1 Failure * \retval -1 Failure
* \since 1.0 * \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 * \brief Determine number of new/old messages in a mailbox
* \since 1.0 * \since 1.0
* \param[in] mailbox Mailbox specification in the format * \param[in] mailboxes Mailbox specification in the format
* /code * /code
* mbox[\@context][&mbox2[\@context2]][...] * mbox[\@context][&mbox2[\@context2]][...]
* /code * /code
@ -613,18 +631,18 @@ int ast_app_has_voicemail(const char *mailbox, const char *folder);
* \retval 0 Success * \retval 0 Success
* \retval -1 Failure * \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 * \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] urgentmsgs the urgent message count
* \param[out] newmsgs the new message count * \param[out] newmsgs the new message count
* \param[out] oldmsgs the old message count * \param[out] oldmsgs the old message count
* \return Returns 0 for success, negative upon error * \return Returns 0 for success, negative upon error
* \since 1.6.1 * \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 * \brief Given a mailbox and context, play that mailbox owner's name to the channel specified

@ -99,7 +99,6 @@
* \page AstAPIChanges Asterisk API Changes * \page AstAPIChanges Asterisk API Changes
* *
* \section Changes161 Version 1.6.1 * \section Changes161 Version 1.6.1
* \li ast_install_vm_functions()
* \li vmwi_generate() * \li vmwi_generate()
* \li ast_channel_datastore_alloc() * \li ast_channel_datastore_alloc()
* \li ast_channel_datastore_free() * \li ast_channel_datastore_free()

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

Loading…
Cancel
Save