--- app_minivm.c.orig 2008-11-22 16:16:31.000000000 -0500
+++ app_minivm.c.new 2008-11-22 21:03:26.000000000 -0500
@@ -170,6 +170,230 @@
#include "asterisk/utils.h"
#include "asterisk/linkedlists.h"
#include "asterisk/callerid.h"
+#include "asterisk/event.h"
+
+/*** DOCUMENTATION
+
+
+ Receive Mini-Voicemail and forward via e-mail.
+
+
+
+
+ Voicemail username
+
+
+ Voicemail domain
+
+
+
+
+
+
+
+
+
+
+
+ his application is part of the Mini-Voicemail system, configured in minivm.conf
+ MiniVM records audio file in configured format and forwards message to e-mail and pager.
+ If there's no user account for that address, a temporary account will be used with default options.
+ The recorded file name and path will be stored in MINIVM_FILENAME and the duration of the message will be stored in MINIVM_DURATION
+ Note: If the caller hangs up after the recording, the only way to send the message and clean up is to execute in the h extension. The application will exit if any of the following DTMF digits are received and the requested extension exist in the current context.
+
+
+ This is the status of the record operation
+
+
+
+
+
+
+
+
+
+
+ Play Mini-Voicemail prompts.
+
+
+
+
+ Voicemail username
+
+
+ Voicemail domain
+
+
+
+
+
+
+
+
+
+
+
+ This application is part of the Mini-Voicemail system, configured in minivm.conf.
+ MinivmGreet() plays default prompts or user specific prompts for an account.
+ Busy and unavailable messages can be choosen, but will be overridden if a temporary message exists for the account.
+
+
+ This is the status of the greeting playback.
+
+
+
+
+
+
+
+
+
+
+ Notify voicemail owner about new messages.
+
+
+
+
+ Voicemail username
+
+
+ Voicemail domain
+
+
+
+
+
+
+
+
+
+ This application is part of the Mini-Voicemail system, configured in minivm.conf.
+ MiniVMnotify forwards messages about new voicemail to e-mail and pager. If there's no user account for that address, a temporary account will be used with default options (set in minivm.conf).
+ If the channel variable MVM_COUNTER is set, this will be used in the message file name and available in the template for the message.
+ If no template is given, the default email template will be used to send email and default pager template to send paging message (if the user account is configured with a paging address.
+
+
+ This is the status of the notification attempt
+
+
+
+
+
+
+
+
+
+ Delete Mini-Voicemail voicemail messages
+
+
+
+ File to delete
+
+
+
+ This application is part of the Mini-Voicemail system, configured in minivm.conf.
+ It deletes voicemail file set in MVM_FILENAME or given filename.
+
+
+ This is the status of the delete operation.
+
+
+
+
+
+
+
+
+
+ Record account specific messages.
+
+
+
+
+ Voicemail username
+
+
+ Voicemail domain
+
+
+
+
+
+
+
+
+
+
+
+
+ This application is part of the Mini-Voicemail system, configured in minivm.conf.
+ Use this application to record account specific audio/video messages for busy, unavailable and temporary messages.
+ Account specific directories will be created if they do not exist.
+
+
+ This is the result of the attempt to record the specified greeting.
+ FAILED is set if the file can't be created.
+
+
+
+
+
+
+
+
+
+ Send Message Waiting Notification to subscriber(s) of mailbox.
+
+
+
+
+ Voicemail username
+
+
+ Voicemail domain
+
+
+
+ Number of urgent messages in mailbox.
+
+
+ Number of new messages in mailbox.
+
+
+ Number of old messages in mailbox.
+
+
+
+ This application is part of the Mini-Voicemail system, configured in minivm.conf.
+ MinivmMWI is used to send message waiting indication to any devices whose channels have subscribed to the mailbox passed in the first parameter.
+
+
+***/
#ifndef TRUE
#define TRUE 1
@@ -220,94 +444,9 @@
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_record = "Receive Mini-Voicemail and forward via e-mail";
-static char *descrip_minivm_record =
- " MinivmRecord(username@domain[,options]):\n"
- "This application is part of the Mini-Voicemail system, configured in minivm.conf.\n"
- "MiniVM records audio file in configured format and forwards message to e-mail and pager.\n"
- "If there's no user account for that address, a temporary account will\n"
- "be used with default options.\n"
- "The recorded file name and path will be stored in MINIVM_FILENAME and the \n"
- "duration of the message will be stored in MINIVM_DURATION\n"
- "\nNote: If the caller hangs up after the recording, the only way to send\n"
- "the message and clean up is to execute in the \"h\" extension.\n"
- "\nThe application will exit if any of the following DTMF digits are \n"
- "received and the requested extension exist in the current context.\n"
- " 0 - Jump to the 'o' extension in the current dialplan context.\n"
- " * - Jump to the 'a' extension in the current dialplan context.\n"
- "\n"
- "Result is given in channel variable MINIVM_RECORD_STATUS\n"
- " The possible values are: SUCCESS | USEREXIT | FAILED\n\n"
- " Options:\n"
- " g(#) - Use the specified amount of gain when recording the voicemail\n"
- " message. The units are whole-number decibels (dB).\n"
- "\n";
-
-static char *synopsis_minivm_greet = "Play Mini-Voicemail prompts";
-static char *descrip_minivm_greet =
- " MinivmGreet(username@domain[,options]):\n"
- "This application is part of the Mini-Voicemail system, configured in minivm.conf.\n"
- "MinivmGreet() plays default prompts or user specific prompts for an account.\n"
- "Busy and unavailable messages can be choosen, but will be overridden if a temporary\n"
- "message exists for the account.\n"
- "\n"
- "Result is given in channel variable MINIVM_GREET_STATUS\n"
- " The possible values are: SUCCESS | USEREXIT | FAILED\n\n"
- " Options:\n"
- " b - Play the 'busy' greeting to the calling party.\n"
- " s - Skip the playback of instructions for leaving a message to the\n"
- " calling party.\n"
- " u - Play the 'unavailable greeting.\n"
- "\n";
-
-static char *synopsis_minivm_notify = "Notify voicemail owner about new messages.";
-static char *descrip_minivm_notify =
- " MinivmNotify(username@domain[,template]):\n"
- "This application is part of the Mini-Voicemail system, configured in minivm.conf.\n"
- "MiniVMnotify forwards messages about new voicemail to e-mail and pager.\n"
- "If there's no user account for that address, a temporary account will\n"
- "be used with default options (set in minivm.conf).\n"
- "The recorded file name and path will be read from MVM_FILENAME and the \n"
- "duration of the message will be accessed from MVM_DURATION (set by MinivmRecord() )\n"
- "If the channel variable MVM_COUNTER is set, this will be used in the\n"
- "message file name and available in the template for the message.\n"
- "If not template is given, the default email template will be used to send email and\n"
- "default pager template to send paging message (if the user account is configured with\n"
- "a paging address.\n"
- "\n"
- "Result is given in channel variable MINIVM_NOTIFY_STATUS\n"
- " The possible values are: SUCCESS | FAILED\n"
- "\n";
-
-static char *synopsis_minivm_delete = "Delete Mini-Voicemail voicemail messages";
-static char *descrip_minivm_delete =
- " MinivmDelete(filename):\n"
- "This application is part of the Mini-Voicemail system, configured in minivm.conf.\n"
- "It deletes voicemail file set in MVM_FILENAME or given filename.\n"
- "\n"
- "Result is given in channel variable MINIVM_DELETE_STATUS\n"
- " The possible values are: SUCCESS | FAILED\n"
- " FAILED is set if the file does not exist or can't be deleted.\n"
- "\n";
-
-static char *synopsis_minivm_accmess = "Record account specific messages";
-static char *descrip_minivm_accmess =
- " MinivmAccmess(username@domain,option):\n"
- "This application is part of the Mini-Voicemail system, configured in minivm.conf.\n"
- "Use this application to record account specific audio/video messages for\n"
- "busy, unavailable and temporary messages.\n"
- "Account specific directories will be created if they do not exist.\n"
- "\nThe option selects message to be recorded:\n"
- " u Unavailable\n"
- " b Busy\n"
- " t Temporary (overrides busy and unavailable)\n"
- " n Account name\n"
- "\n"
- "Result is given in channel variable MINIVM_ACCMESS_STATUS\n"
- " The possible values are: SUCCESS | FAILED\n"
- " FAILED is set if the file can't be created.\n"
- "\n";
enum {
OPT_SILENT = (1 << 0),
@@ -1616,6 +1755,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)
{
@@ -3052,11 +3259,12 @@
{
int res;
- res = ast_register_application(app_minivm_record, minivm_record_exec, synopsis_minivm_record, descrip_minivm_record);
- res = ast_register_application(app_minivm_greet, minivm_greet_exec, synopsis_minivm_greet, descrip_minivm_greet);
- 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_xml(app_minivm_record, minivm_record_exec);
+ res = ast_register_application_xml(app_minivm_greet, minivm_greet_exec);
+ res = ast_register_application_xml(app_minivm_notify, minivm_notify_exec);
+ res = ast_register_application_xml(app_minivm_delete, minivm_delete_exec);
+ res = ast_register_application_xml(app_minivm_accmess, minivm_accmess_exec);
+ res = ast_register_application_xml(app_minivm_mwi, minivm_mwi_exec);
ast_custom_function_register(&minivm_account_function);
ast_custom_function_register(&minivm_counter_function);