|
|
|
|
@ -42,6 +42,7 @@
|
|
|
|
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
|
|
|
|
|
|
#include "asterisk/paths.h" /* use ast_config_AST_MONITOR_DIR */
|
|
|
|
|
#include "asterisk/stringfields.h"
|
|
|
|
|
#include "asterisk/file.h"
|
|
|
|
|
#include "asterisk/audiohook.h"
|
|
|
|
|
#include "asterisk/pbx.h"
|
|
|
|
|
@ -51,6 +52,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
|
#include "asterisk/channel.h"
|
|
|
|
|
#include "asterisk/autochan.h"
|
|
|
|
|
#include "asterisk/manager.h"
|
|
|
|
|
#include "asterisk/callerid.h"
|
|
|
|
|
#include "asterisk/mod_format.h"
|
|
|
|
|
|
|
|
|
|
/*** DOCUMENTATION
|
|
|
|
|
@ -107,6 +109,12 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
|
Like with the basic filename argument, if an absolute path isn't given, it will create
|
|
|
|
|
the file in the configured monitoring directory.</para>
|
|
|
|
|
</option>
|
|
|
|
|
<option name="m">
|
|
|
|
|
<argument name="mailbox" required="true" />
|
|
|
|
|
<para>Create a copy of the recording as a voicemail in each indicated <emphasis>mailbox</emphasis>
|
|
|
|
|
separated by commas eg. m(1111@default,2222@default,...)</para>
|
|
|
|
|
<note><para>The recording will be deleted once all the copies are made.</para></note>
|
|
|
|
|
</option>
|
|
|
|
|
</optionlist>
|
|
|
|
|
</parameter>
|
|
|
|
|
<parameter name="command">
|
|
|
|
|
@ -176,6 +184,16 @@ static const char * const stop_app = "StopMixMonitor";
|
|
|
|
|
|
|
|
|
|
static const char * const mixmonitor_spy_type = "MixMonitor";
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \internal
|
|
|
|
|
* \brief This struct is a list item holds data needed to find a vm_recipient within voicemail
|
|
|
|
|
*/
|
|
|
|
|
struct vm_recipient {
|
|
|
|
|
char mailbox[AST_MAX_CONTEXT];
|
|
|
|
|
char context[AST_MAX_EXTENSION];
|
|
|
|
|
AST_LIST_ENTRY(vm_recipient) list;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct mixmonitor {
|
|
|
|
|
struct ast_audiohook audiohook;
|
|
|
|
|
char *filename;
|
|
|
|
|
@ -186,6 +204,20 @@ struct mixmonitor {
|
|
|
|
|
unsigned int flags;
|
|
|
|
|
struct ast_autochan *autochan;
|
|
|
|
|
struct mixmonitor_ds *mixmonitor_ds;
|
|
|
|
|
|
|
|
|
|
/* the below string fields describe data used for creating voicemails from the recording */
|
|
|
|
|
AST_DECLARE_STRING_FIELDS(
|
|
|
|
|
AST_STRING_FIELD(call_context);
|
|
|
|
|
AST_STRING_FIELD(call_macrocontext);
|
|
|
|
|
AST_STRING_FIELD(call_extension);
|
|
|
|
|
AST_STRING_FIELD(call_callerchan);
|
|
|
|
|
AST_STRING_FIELD(call_callerid);
|
|
|
|
|
);
|
|
|
|
|
int call_priority;
|
|
|
|
|
|
|
|
|
|
/* FUTURE DEVELOPMENT NOTICE
|
|
|
|
|
* recipient_list will need locks if we make it editable after the monitor is started */
|
|
|
|
|
AST_LIST_HEAD_NOLOCK(, vm_recipient) recipient_list;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum mixmonitor_flags {
|
|
|
|
|
@ -197,6 +229,7 @@ enum mixmonitor_flags {
|
|
|
|
|
MUXFLAG_READ = (1 << 6),
|
|
|
|
|
MUXFLAG_WRITE = (1 << 7),
|
|
|
|
|
MUXFLAG_COMBINED = (1 << 8),
|
|
|
|
|
MUXFLAG_VMRECIPIENTS = (1 << 6),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum mixmonitor_args {
|
|
|
|
|
@ -205,6 +238,7 @@ enum mixmonitor_args {
|
|
|
|
|
OPT_ARG_VOLUME,
|
|
|
|
|
OPT_ARG_WRITENAME,
|
|
|
|
|
OPT_ARG_READNAME,
|
|
|
|
|
OPT_ARG_VMRECIPIENTS,
|
|
|
|
|
OPT_ARG_ARRAY_SIZE, /* Always last element of the enum */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
@ -216,6 +250,7 @@ AST_APP_OPTIONS(mixmonitor_opts, {
|
|
|
|
|
AST_APP_OPTION_ARG('W', MUXFLAG_VOLUME, OPT_ARG_VOLUME),
|
|
|
|
|
AST_APP_OPTION_ARG('r', MUXFLAG_READ, OPT_ARG_READNAME),
|
|
|
|
|
AST_APP_OPTION_ARG('t', MUXFLAG_WRITE, OPT_ARG_WRITENAME),
|
|
|
|
|
AST_APP_OPTION_ARG('m', MUXFLAG_VMRECIPIENTS, OPT_ARG_VMRECIPIENTS),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
struct mixmonitor_ds {
|
|
|
|
|
@ -316,6 +351,64 @@ static int startmon(struct ast_channel *chan, struct ast_audiohook *audiohook)
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \internal
|
|
|
|
|
* \brief adds recipients to a mixmonitor's recipient list
|
|
|
|
|
* \param mixmonitor mixmonitor being affected
|
|
|
|
|
* \param vm_recipients string containing the desired recipients to add
|
|
|
|
|
*/
|
|
|
|
|
static void add_vm_recipients_from_string(struct mixmonitor *mixmonitor, const char *vm_recipients)
|
|
|
|
|
{
|
|
|
|
|
/* recipients are in a single string with a format format resembling "mailbox@context,mailbox2@context2, mailbox3@context3" */
|
|
|
|
|
char *cur_mailbox = ast_strdupa(vm_recipients);
|
|
|
|
|
char *cur_context;
|
|
|
|
|
char *next;
|
|
|
|
|
int elements_processed = 0;
|
|
|
|
|
|
|
|
|
|
while (!ast_strlen_zero(cur_mailbox)) {
|
|
|
|
|
ast_debug(3, "attempting to add next element %d from %s\n", elements_processed, cur_mailbox);
|
|
|
|
|
if ((next = strchr(cur_mailbox, ',')) || (next = strchr(cur_mailbox, '&'))) {
|
|
|
|
|
*(next++) = '\0';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((cur_context = strchr(cur_mailbox, '@'))) {
|
|
|
|
|
*(cur_context++) = '\0';
|
|
|
|
|
} else {
|
|
|
|
|
cur_context = "default";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!ast_strlen_zero(cur_mailbox) && !ast_strlen_zero(cur_context)) {
|
|
|
|
|
|
|
|
|
|
struct vm_recipient *recipient;
|
|
|
|
|
if (!(recipient = ast_malloc(sizeof(*recipient)))) {
|
|
|
|
|
ast_log(LOG_ERROR, "Failed to allocate recipient. Aborting function.\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ast_copy_string(recipient->context, cur_context, sizeof(recipient->context));
|
|
|
|
|
ast_copy_string(recipient->mailbox, cur_mailbox, sizeof(recipient->mailbox));
|
|
|
|
|
|
|
|
|
|
/* Add to list */
|
|
|
|
|
ast_verb(5, "Adding %s@%s to recipient list\n", recipient->mailbox, recipient->context);
|
|
|
|
|
AST_LIST_INSERT_HEAD(&mixmonitor->recipient_list, recipient, list);
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
ast_log(LOG_ERROR, "Failed to properly parse extension and/or context from element %d of recipient string: %s\n", elements_processed, vm_recipients);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cur_mailbox = next;
|
|
|
|
|
elements_processed++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void clear_mixmonitor_recipient_list(struct mixmonitor *mixmonitor)
|
|
|
|
|
{
|
|
|
|
|
struct vm_recipient *current;
|
|
|
|
|
while ((current = AST_LIST_REMOVE_HEAD(&mixmonitor->recipient_list, list))) {
|
|
|
|
|
/* Clear list element data */
|
|
|
|
|
ast_free(current);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define SAMPLES_PER_FRAME 160
|
|
|
|
|
|
|
|
|
|
static void mixmonitor_free(struct mixmonitor *mixmonitor)
|
|
|
|
|
@ -330,6 +423,13 @@ static void mixmonitor_free(struct mixmonitor *mixmonitor)
|
|
|
|
|
ast_free(mixmonitor->name);
|
|
|
|
|
ast_free(mixmonitor->post_process);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Free everything in the recipient list */
|
|
|
|
|
clear_mixmonitor_recipient_list(mixmonitor);
|
|
|
|
|
|
|
|
|
|
/* clean stringfields */
|
|
|
|
|
ast_string_field_free_memory(mixmonitor);
|
|
|
|
|
|
|
|
|
|
ast_free(mixmonitor);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -363,9 +463,59 @@ static void mixmonitor_save_prep(struct mixmonitor *mixmonitor, char *filename,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \internal
|
|
|
|
|
* \brief Copies the mixmonitor to all voicemail recipients
|
|
|
|
|
* \param mixmonitor The mixmonitor that needs to forward its file to recipients
|
|
|
|
|
* \param ext Format of the file that was saved
|
|
|
|
|
*/
|
|
|
|
|
static void copy_to_voicemail(struct mixmonitor *mixmonitor, char *ext)
|
|
|
|
|
{
|
|
|
|
|
struct vm_recipient *recipient = NULL;
|
|
|
|
|
struct ast_vm_recording_data recording_data;
|
|
|
|
|
char filename[PATH_MAX];
|
|
|
|
|
|
|
|
|
|
if (ast_string_field_init(&recording_data, 512)) {
|
|
|
|
|
ast_log(LOG_ERROR, "Failed to string_field_init, skipping copy_to_voicemail\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Copy strings to stringfields that will be used for all recipients */
|
|
|
|
|
ast_string_field_set(&recording_data, recording_file, mixmonitor->filename);
|
|
|
|
|
ast_string_field_set(&recording_data, recording_ext, ext);
|
|
|
|
|
ast_string_field_set(&recording_data, call_context, mixmonitor->call_context);
|
|
|
|
|
ast_string_field_set(&recording_data, call_macrocontext, mixmonitor->call_macrocontext);
|
|
|
|
|
ast_string_field_set(&recording_data, call_extension, mixmonitor->call_extension);
|
|
|
|
|
ast_string_field_set(&recording_data, call_callerchan, mixmonitor->call_callerchan);
|
|
|
|
|
ast_string_field_set(&recording_data, call_callerid, mixmonitor->call_callerid);
|
|
|
|
|
/* and call_priority gets copied too */
|
|
|
|
|
recording_data.call_priority = mixmonitor->call_priority;
|
|
|
|
|
|
|
|
|
|
AST_LIST_TRAVERSE(&mixmonitor->recipient_list, recipient, list) {
|
|
|
|
|
/* context and mailbox need to be set per recipient */
|
|
|
|
|
ast_string_field_set(&recording_data, context, recipient->context);
|
|
|
|
|
ast_string_field_set(&recording_data, mailbox, recipient->mailbox);
|
|
|
|
|
ast_verb(4, "MixMonitor attempting to send voicemail copy to %s@%s\n", recording_data.mailbox,
|
|
|
|
|
recording_data.context);
|
|
|
|
|
ast_app_copy_recording_to_vm(&recording_data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Delete the source file */
|
|
|
|
|
snprintf(filename, sizeof(filename), "%s.%s", mixmonitor->filename, ext);
|
|
|
|
|
if (remove(filename)) {
|
|
|
|
|
ast_log(LOG_ERROR, "Failed to delete recording source file %s\n", filename);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Free the string fields for recording_data before exiting the function. */
|
|
|
|
|
ast_string_field_free_memory(&recording_data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void *mixmonitor_thread(void *obj)
|
|
|
|
|
{
|
|
|
|
|
struct mixmonitor *mixmonitor = obj;
|
|
|
|
|
char *fs_ext = "";
|
|
|
|
|
char *fs_read_ext = "";
|
|
|
|
|
char *fs_write_ext = "";
|
|
|
|
|
|
|
|
|
|
struct ast_filestream **fs = NULL;
|
|
|
|
|
struct ast_filestream **fs_read = NULL;
|
|
|
|
|
@ -479,6 +629,27 @@ static void *mixmonitor_thread(void *obj)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ast_verb(2, "End MixMonitor Recording %s\n", mixmonitor->name);
|
|
|
|
|
|
|
|
|
|
if (!AST_LIST_EMPTY(&mixmonitor->recipient_list)) {
|
|
|
|
|
if (ast_strlen_zero(fs_ext)) {
|
|
|
|
|
ast_log(LOG_ERROR, "No file extension set for Mixmonitor %s. Skipping copy to voicemail.\n",
|
|
|
|
|
mixmonitor -> name);
|
|
|
|
|
} else {
|
|
|
|
|
ast_verb(3, "Copying recordings for Mixmonitor %s to voicemail recipients\n", mixmonitor->name);
|
|
|
|
|
copy_to_voicemail(mixmonitor, fs_ext, mixmonitor->filename);
|
|
|
|
|
}
|
|
|
|
|
if (!ast_strlen_zero(fs_read_ext)) {
|
|
|
|
|
ast_verb(3, "Copying read recording for Mixmonitor %s to voicemail recipients\n", mixmonitor->name);
|
|
|
|
|
copy_to_voicemail(mixmonitor, fs_read_ext, mixmonitor->filename_read);
|
|
|
|
|
}
|
|
|
|
|
if (!ast_strlen_zero(fs_write_ext)) {
|
|
|
|
|
ast_verb(3, "Copying write recording for Mixmonitor %s to voicemail recipients\n", mixmonitor->name);
|
|
|
|
|
copy_to_voicemail(mixmonitor, fs_write_ext, mixmonitor->filename_write);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
ast_debug(3, "No recipients to forward monitor to, moving on.\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mixmonitor_free(mixmonitor);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
@ -518,7 +689,7 @@ static int setup_mixmonitor_ds(struct mixmonitor *mixmonitor, struct ast_channel
|
|
|
|
|
static void launch_monitor_thread(struct ast_channel *chan, const char *filename,
|
|
|
|
|
unsigned int flags, int readvol, int writevol,
|
|
|
|
|
const char *post_process, const char *filename_write,
|
|
|
|
|
const char *filename_read)
|
|
|
|
|
const char *filename_read, const char *recipients)
|
|
|
|
|
{
|
|
|
|
|
pthread_t thread;
|
|
|
|
|
struct mixmonitor *mixmonitor;
|
|
|
|
|
@ -543,6 +714,12 @@ static void launch_monitor_thread(struct ast_channel *chan, const char *filename
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Now that the struct has been calloced, go ahead and initialize the string fields. */
|
|
|
|
|
if (ast_string_field_init(mixmonitor, 512)) {
|
|
|
|
|
mixmonitor_free(mixmonitor);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Setup the actual spy before creating our thread */
|
|
|
|
|
if (ast_audiohook_init(&mixmonitor->audiohook, AST_AUDIOHOOK_TYPE_SPY, mixmonitor_spy_type, 0)) {
|
|
|
|
|
mixmonitor_free(mixmonitor);
|
|
|
|
|
@ -580,6 +757,32 @@ static void launch_monitor_thread(struct ast_channel *chan, const char *filename
|
|
|
|
|
mixmonitor->filename_read = ast_strdup(filename_read);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!ast_strlen_zero(recipients)) {
|
|
|
|
|
char callerid[256];
|
|
|
|
|
|
|
|
|
|
ast_channel_lock(chan);
|
|
|
|
|
|
|
|
|
|
/* We use the connected line of the invoking channel for caller ID. */
|
|
|
|
|
ast_debug(3, "Connected Line CID = %d - %s : %d - %s\n", chan->connected.id.name.valid,
|
|
|
|
|
chan->connected.id.name.str, chan->connected.id.number.valid,
|
|
|
|
|
chan->connected.id.number.str);
|
|
|
|
|
ast_callerid_merge(callerid, sizeof(callerid),
|
|
|
|
|
S_COR(chan->connected.id.name.valid, chan->connected.id.name.str, NULL),
|
|
|
|
|
S_COR(chan->connected.id.number.valid, chan->connected.id.number.str, NULL),
|
|
|
|
|
"Unknown");
|
|
|
|
|
|
|
|
|
|
ast_string_field_set(mixmonitor, call_context, chan->context);
|
|
|
|
|
ast_string_field_set(mixmonitor, call_macrocontext, chan->macrocontext);
|
|
|
|
|
ast_string_field_set(mixmonitor, call_extension, chan->exten);
|
|
|
|
|
ast_string_field_set(mixmonitor, call_callerchan, chan->name);
|
|
|
|
|
ast_string_field_set(mixmonitor, call_callerid, callerid);
|
|
|
|
|
mixmonitor->call_priority = chan->priority;
|
|
|
|
|
|
|
|
|
|
ast_channel_unlock(chan);
|
|
|
|
|
|
|
|
|
|
add_vm_recipients_from_string(mixmonitor, recipients);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ast_set_flag(&mixmonitor->audiohook, AST_AUDIOHOOK_TRIGGER_SYNC);
|
|
|
|
|
|
|
|
|
|
if (readvol)
|
|
|
|
|
@ -630,6 +833,7 @@ static int mixmonitor_exec(struct ast_channel *chan, const char *data)
|
|
|
|
|
char filename_buffer[1024] = "";
|
|
|
|
|
|
|
|
|
|
struct ast_flags flags = { 0 };
|
|
|
|
|
char *recipients = NULL;
|
|
|
|
|
char *parse;
|
|
|
|
|
AST_DECLARE_APP_ARGS(args,
|
|
|
|
|
AST_APP_ARG(filename);
|
|
|
|
|
@ -688,6 +892,15 @@ static int mixmonitor_exec(struct ast_channel *chan, const char *data)
|
|
|
|
|
if (ast_test_flag(&flags, MUXFLAG_READ)) {
|
|
|
|
|
filename_read = ast_strdupa(filename_parse(opts[OPT_ARG_READNAME], filename_buffer, sizeof(filename_buffer)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ast_test_flag(&flags, MUXFLAG_VMRECIPIENTS)) {
|
|
|
|
|
if (ast_strlen_zero(opts[OPT_ARG_VMRECIPIENTS])) {
|
|
|
|
|
ast_log(LOG_WARNING, "No voicemail recipients were specified for the vm copy ('m') option.\n");
|
|
|
|
|
} else {
|
|
|
|
|
recipients = ast_strdupa(opts[OPT_ARG_VMRECIPIENTS]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If there are no file writing arguments/options for the mix monitor, send a warning message and return -1 */
|
|
|
|
|
@ -703,7 +916,7 @@ static int mixmonitor_exec(struct ast_channel *chan, const char *data)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pbx_builtin_setvar_helper(chan, "MIXMONITOR_FILENAME", args.filename);
|
|
|
|
|
launch_monitor_thread(chan, args.filename, flags.flags, readvol, writevol, args.post_process, filename_write, filename_read);
|
|
|
|
|
launch_monitor_thread(chan, args.filename, flags.flags, readvol, writevol, args.post_process, filename_write, filename_read, recipients);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|