Make monitor merge application settable via variable, allow setting of variables via manager interface, allow mix flag to be set via manager (bug #1268)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@3137 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Mark Spencer
2004-06-03 15:42:36 +00:00
parent 8f5498177e
commit 799b876aa0
2 changed files with 119 additions and 14 deletions

View File

@@ -475,6 +475,81 @@ static int action_hangup(struct mansession *s, struct message *m)
return 0; return 0;
} }
static int action_setvar(struct mansession *s, struct message *m)
{
struct ast_channel *c = NULL;
char *name = astman_get_header(m, "Channel");
char *varname = astman_get_header(m, "Variable");
char *varval = astman_get_header(m, "Value");
if (!strlen(name)) {
astman_send_error(s, m, "No channel specified");
return 0;
}
if (!strlen(varname)) {
astman_send_error(s, m, "No variable specified");
return 0;
}
c = ast_channel_walk_locked(NULL);
while(c) {
if (!strcasecmp(c->name, name)) {
break;
}
ast_mutex_unlock(&c->lock);
c = ast_channel_walk_locked(c);
}
if (!c) {
astman_send_error(s, m, "No such channel");
return 0;
}
pbx_builtin_setvar_helper(c,varname,varval);
ast_mutex_unlock(&c->lock);
astman_send_ack(s, m, "Variable Set");
return 0;
}
static int action_getvar(struct mansession *s, struct message *m)
{
struct ast_channel *c = NULL;
char *name = astman_get_header(m, "Channel");
char *varname = astman_get_header(m, "Variable");
char *varval;
if (!strlen(name)) {
astman_send_error(s, m, "No channel specified");
return 0;
}
if (!strlen(varname)) {
astman_send_error(s, m, "No variable specified");
return 0;
}
c = ast_channel_walk_locked(NULL);
while(c) {
if (!strcasecmp(c->name, name)) {
break;
}
ast_mutex_unlock(&c->lock);
c = ast_channel_walk_locked(c);
}
if (!c) {
astman_send_error(s, m, "No such channel");
return 0;
}
varval=pbx_builtin_getvar_helper(c,varname);
ast_mutex_unlock(&c->lock);
ast_cli(s->fd, "Response: Success\r\n"
"%s: %s",varname,varval);
return 0;
}
static int action_status(struct mansession *s, struct message *m) static int action_status(struct mansession *s, struct message *m)
{ {
char *id = astman_get_header(m,"ActionID"); char *id = astman_get_header(m,"ActionID");
@@ -1157,6 +1232,8 @@ int init_manager(void)
ast_manager_register( "Logoff", 0, action_logoff, "Logoff Manager" ); ast_manager_register( "Logoff", 0, action_logoff, "Logoff Manager" );
ast_manager_register( "Hangup", EVENT_FLAG_CALL, action_hangup, "Hangup Channel" ); ast_manager_register( "Hangup", EVENT_FLAG_CALL, action_hangup, "Hangup Channel" );
ast_manager_register( "Status", EVENT_FLAG_CALL, action_status, "Status" ); ast_manager_register( "Status", EVENT_FLAG_CALL, action_status, "Status" );
ast_manager_register( "Setvar", EVENT_FLAG_CALL, action_setvar, "Set Channel Variable" );
ast_manager_register( "Getvar", EVENT_FLAG_CALL, action_getvar, "Gets a Channel Variable" );
ast_manager_register( "Redirect", EVENT_FLAG_CALL, action_redirect, "Redirect" ); ast_manager_register( "Redirect", EVENT_FLAG_CALL, action_redirect, "Redirect" );
ast_manager_register2("Originate", EVENT_FLAG_CALL, action_originate, "Originate Call", mandescr_originate); ast_manager_register2("Originate", EVENT_FLAG_CALL, action_originate, "Originate Call", mandescr_originate);
ast_manager_register( "MailboxStatus", EVENT_FLAG_CALL, action_mailboxstatus, "Check Mailbox" ); ast_manager_register( "MailboxStatus", EVENT_FLAG_CALL, action_mailboxstatus, "Check Mailbox" );

View File

@@ -15,6 +15,8 @@
#include <asterisk/manager.h> #include <asterisk/manager.h>
#include <asterisk/cli.h> #include <asterisk/cli.h>
#include <asterisk/monitor.h> #include <asterisk/monitor.h>
#include <asterisk/app.h>
#include <asterisk/utils.h>
#include "../asterisk.h" #include "../asterisk.h"
#include "../astconf.h" #include "../astconf.h"
@@ -27,13 +29,21 @@ static unsigned long seq = 0;
static char *monitor_synopsis = "Monitor a channel"; static char *monitor_synopsis = "Monitor a channel";
static char *monitor_descrip = "Monitor([file_format|[fname_base]|[options]]):\n" static char *monitor_descrip = "Monitor([file_format|[fname_base]|[options]]):\n"
"Used to start monitoring a channel. The channel's input and output\n" "Used to start monitoring a channel. The channel's input and output\n"
"voice packets are logged to files until the channel hangs up or\n" "voice packets are logged to files until the channel hangs up or\n"
"monitoring is stopped by the StopMonitor application.\n" "monitoring is stopped by the StopMonitor application.\n"
" file_format -- optional, if not set, defaults to \"wav\"\n" " file_format -- optional, if not set, defaults to \"wav\"\n"
" fname_base -- if set, changes the filename used to the one specified.\n" " fname_base -- if set, changes the filename used to the one specified.\n"
" options:\n" " options:\n"
" 'm' - when the recording ends mix the two leg files into one using 'soxmix' utility which has to be installed on the system.\n"; " 'm' - when the recording ends mix the two leg files into one and\n"
" delete the two leg files. If MONITOR_EXEC is set, the\n"
" application refernced in it will be executed instead of\n"
" soxmix and the raw leg files will NOT be deleted automatically.\n"
" soxmix or MONITOR_EXEC is handed 3 arguments, the two leg files\n"
" and a target mixed file name which is the same as the leg file names\n"
" only without the in/out designator.\n\n"
" Both MONITOR_EXEC and the Mix flag can be set from the\n"
" administrator interface\n";
static char *stopmonitor_synopsis = "Stop monitoring a channel"; static char *stopmonitor_synopsis = "Stop monitoring a channel";
@@ -161,6 +171,8 @@ int ast_monitor_start( struct ast_channel *chan, const char *format_spec,
/* Stop monitoring a channel */ /* Stop monitoring a channel */
int ast_monitor_stop( struct ast_channel *chan, int need_lock ) int ast_monitor_stop( struct ast_channel *chan, int need_lock )
{ {
char *execute=NULL;
int soxmix =0;
if(need_lock) { if(need_lock) {
if(ast_mutex_lock(&chan->lock)) { if(ast_mutex_lock(&chan->lock)) {
ast_log(LOG_WARNING, "Unable to lock channel\n"); ast_log(LOG_WARNING, "Unable to lock channel\n");
@@ -205,19 +217,29 @@ int ast_monitor_stop( struct ast_channel *chan, int need_lock )
chan->monitor->write_filename ); chan->monitor->write_filename );
} }
} }
if (chan->monitor->joinfiles && strlen(chan->monitor->filename_base)) {
if (chan->monitor->joinfiles && !ast_strlen_zero(execute) && strlen(chan->monitor->filename_base)) {
char tmp[1024]; char tmp[1024];
char tmp2[1024];
char *format = !strcasecmp(chan->monitor->format,"wav49") ? "WAV" : chan->monitor->format; char *format = !strcasecmp(chan->monitor->format,"wav49") ? "WAV" : chan->monitor->format;
char *name = chan->monitor->filename_base; char *name = chan->monitor->filename_base;
int directory = strchr(name, '/') ? 1 : 0; int directory = strchr(name, '/') ? 1 : 0;
char *dir = directory ? "" : AST_MONITOR_DIR; char *dir = directory ? "" : AST_MONITOR_DIR;
snprintf(tmp, sizeof(tmp), "nice -n 19 soxmix %s/%s-in.%s %s/%s-out.%s %s/%s.%s && rm -rf %s/%s-* &", dir, name, format, dir, name, format, dir, name, format, dir, name);
#if 0 /* Set the execute application */
ast_verbose("executing %s\n",tmp); execute=pbx_builtin_getvar_helper(chan,"MONITOR_EXEC");
#endif if (!execute || ast_strlen_zero(execute)) {
if (system(tmp) == -1) execute = "nice -n 19 soxmix";
ast_log(LOG_WARNING, "You might not have the soxmix installed and available in the path, please check.\n"); soxmix = 1;
} }
snprintf(tmp, sizeof(tmp), "%s %s/%s-in.%s %s/%s-out.%s %s/%s.%s &", execute, dir, name, format, dir, name, format, dir, name, format);
if (soxmix)
snprintf(tmp2,sizeof(tmp2), "%s& rm -f %s/%s-* &",tmp, dir ,name); /* remove legs when done mixing */
ast_verbose("monitor executing %s\n",tmp);
if (ast_safe_system(tmp) == -1)
ast_log(LOG_WARNING, "Execute of %s failed.\n",tmp);
}
free( chan->monitor->format ); free( chan->monitor->format );
free( chan->monitor ); free( chan->monitor );
chan->monitor = NULL; chan->monitor = NULL;
@@ -329,6 +351,7 @@ static int start_monitor_action(struct mansession *s, struct message *m)
char *name = astman_get_header(m, "Channel"); char *name = astman_get_header(m, "Channel");
char *fname = astman_get_header(m, "File"); char *fname = astman_get_header(m, "File");
char *format = astman_get_header(m, "Format"); char *format = astman_get_header(m, "Format");
char *mix = astman_get_header(m, "Mix");
char *d; char *d;
if((!name)||(!strlen(name))) { if((!name)||(!strlen(name))) {
@@ -363,6 +386,11 @@ static int start_monitor_action(struct mansession *s, struct message *m)
return 0; return 0;
} }
} }
if(ast_true(mix)) {
ast_monitor_setjoinfiles( c, 1);
}
ast_mutex_unlock(&c->lock); ast_mutex_unlock(&c->lock);
astman_send_ack(s, m, "Started monitoring channel"); astman_send_ack(s, m, "Started monitoring channel");
return 0; return 0;