--- app_minivm.c.orig 2008-11-21 14:50:55.000000000 -0500 +++ app_minivm.c 2008-11-21 14:50:42.000000000 -0500 @@ -170,6 +170,7 @@ #include "asterisk/utils.h" #include "asterisk/linkedlists.h" #include "asterisk/callerid.h" +#include "asterisk/event.h" #ifndef TRUE #define TRUE 1 @@ -220,6 +221,14 @@ static char *app_minivm_notify = "MinivmNotify"; /* Notify about voicemail by using one of several methods */ static char *app_minivm_delete = "MinivmDelete"; /* Notify about voicemail by using one of several methods */ static char *app_minivm_accmess = "MinivmAccMess"; /* Record personal voicemail messages */ +static char *app_minivm_mwi = "MinivmMWI"; + +static char *synopsis_minivm_mwi = "Send Message Waiting Notification to subscriber(s) of mailbox"; +static char *descrip_minivm_mwi = + " MinivmMWI(mailbox@context,urgent,new,old):\n" + "This application is part of the Mini-Voicemail system, configured in minivm.conf.\n" + "MinivmMWI is used to send message waiting indication to any devices whose channels have subscribed to the mailbox passed in the first parameter.\n" + "\n"; static char *synopsis_minivm_record = "Receive Mini-Voicemail and forward via e-mail"; static char *descrip_minivm_record = @@ -1616,6 +1625,74 @@ return res; } +/*! \brief Queue a message waiting event */ +static void queue_mwi_event(const char *mbx, const char *ctx, int urgent, int new, int old) +{ + struct ast_event *event; + char *mailbox, *context; + + mailbox = ast_strdupa(mbx); + context = ast_strdupa(ctx); + if (ast_strlen_zero(context)) { + context = "default"; + } + + if (!(event = ast_event_new(AST_EVENT_MWI, + AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox, + AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, context, + AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_UINT, (new+urgent), + AST_EVENT_IE_OLDMSGS, AST_EVENT_IE_PLTYPE_UINT, old, + AST_EVENT_IE_END))) { + return; + } + + ast_event_queue_and_cache(event, + AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, + AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, + AST_EVENT_IE_END); +} + +/*! \brief Send MWI using interal Asterisk event subsystem */ +static int minivm_mwi_exec(struct ast_channel *chan, void *data) +{ + int argc; + char *argv[4]; + int res = 0; + char *tmpptr; + char tmp[PATH_MAX]; + char *mailbox; + char *domain; + if (ast_strlen_zero(data)) { + ast_log(LOG_ERROR, "Minivm needs at least an account argument \n"); + return -1; + } + tmpptr = ast_strdupa((char *)data); + if (!tmpptr) { + ast_log(LOG_ERROR, "Out of memory\n"); + return -1; + } + argc = ast_app_separate_args(tmpptr, ',', argv, ARRAY_LEN(argv)); + if (argc < 4) { + ast_log(LOG_ERROR, "%d arguments passed to MiniVM_MWI, need 4.\n", argc); + return -1; + } + ast_copy_string(tmp, argv[0], sizeof(tmp)); + mailbox = tmp; + domain = strchr(tmp, '@'); + if (domain) { + *domain = '\0'; + domain++; + } + if (ast_strlen_zero(domain) || ast_strlen_zero(mailbox)) { + ast_log(LOG_ERROR, "Need mailbox@context as argument. Sorry. Argument 0 %s\n", argv[0]); + return -1; + } + queue_mwi_event(mailbox, domain, atoi(argv[1]), atoi(argv[2]), atoi(argv[3])); + + return res; +} + + /*! \brief Notify voicemail account owners - either generic template or user specific */ static int minivm_notify_exec(struct ast_channel *chan, void *data) { @@ -3057,6 +3134,7 @@ res = ast_register_application(app_minivm_notify, minivm_notify_exec, synopsis_minivm_notify, descrip_minivm_notify); res = ast_register_application(app_minivm_delete, minivm_delete_exec, synopsis_minivm_delete, descrip_minivm_delete); res = ast_register_application(app_minivm_accmess, minivm_accmess_exec, synopsis_minivm_accmess, descrip_minivm_accmess); + res = ast_register_application(app_minivm_mwi, minivm_mwi_exec, synopsis_minivm_mwi, descrip_minivm_mwi); ast_custom_function_register(&minivm_account_function); ast_custom_function_register(&minivm_counter_function);