Index: asterisk/include/asterisk/monitor.h =================================================================== RCS file: /usr/cvsroot/asterisk/include/asterisk/monitor.h,v retrieving revision 1.2 diff -u -r1.2 monitor.h --- asterisk/include/asterisk/monitor.h 3 Feb 2004 16:57:00 -0000 1.2 +++ asterisk/include/asterisk/monitor.h 8 Apr 2004 03:57:03 -0000 @@ -18,6 +18,7 @@ int filename_changed; char *format; int joinfiles; + char execute[ FILENAME_MAX ]; int (*stop)( struct ast_channel *chan, int need_lock); }; @@ -33,5 +34,6 @@ const char *fname_base, int need_lock ); void ast_monitor_setjoinfiles(struct ast_channel *chan, int turnon); +void ast_monitor_setexecute(struct ast_channel *chan, char *execcmd); #endif /* _MONITOR_H */ Index: asterisk/res/res_monitor.c =================================================================== RCS file: /usr/cvsroot/asterisk/res/res_monitor.c,v retrieving revision 1.9 diff -u -r1.9 res_monitor.c --- asterisk/res/res_monitor.c 6 Feb 2004 05:52:03 -0000 1.9 +++ asterisk/res/res_monitor.c 8 Apr 2004 03:57:03 -0000 @@ -24,14 +24,15 @@ 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]|[executable]]):\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" "monitoring is stopped by the StopMonitor application.\n" " file_format -- optional, if not set, defaults to \"wav\"\n" " fname_base -- if set, changes the filename used to the one specified.\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 using 'soxmix' utility which has to be installed on the system.\n" + " executable -- application to execute when the monitoring stops. Asterisk hands a single file name as an argument to the application if the legs are mixed and the two leg file names as seperate parameters if the mixing option is not selected. If the mixing option is also selected soxmix is not dropped into the background, however, the executable is.\n"; static char *stopmonitor_synopsis = "Stop monitoring a channel"; @@ -82,7 +83,7 @@ char *name = strdup(fname_base); snprintf(tmp, sizeof(tmp), "mkdir -p %s",dirname(name)); free(name); - system(tmp); + ast_safe_system(tmp); } snprintf( monitor->read_filename, FILENAME_MAX, "%s/%s-in", directory ? "" : AST_MONITOR_DIR, fname_base ); @@ -209,13 +210,41 @@ char *name = chan->monitor->filename_base; int directory = strchr(name, '/') ? 1 : 0; 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); + char amp='&'; + if (strlen(chan->monitor->execute)) + amp=(char)0; + /* don't background this process if there is a script to exectute after its done */ + snprintf(tmp, sizeof(tmp), "nice -n 19 soxmix %s/%s-in.%s %s/%s-out.%s %s/%s.%s && rm -rf %s/%s-* %c", dir, name, format, dir, name, format, dir, name, format, dir, name, amp); #if 0 ast_verbose("executing %s\n",tmp); #endif - if (system(tmp) == -1) - ast_log(LOG_WARNING, "You might not have the soxmix installed and available in the path, please check.\n"); + ast_safe_system(tmp); + /* if (system(tmp) == -1) + ast_log(LOG_WARNING, "You might not have the soxmix installed and available in the path, please check.\n"); */ } + + + if (strlen(chan->monitor->execute) && strlen(chan->monitor->filename_base)) { + /*execute the custom application here */ + /*pass the filename_base, format, and mixed file as arguments to the script*/ + char tmp[1024]; + char *format = !strcasecmp(chan->monitor->format,"wav49") ? "WAV" : chan->monitor->format; + char *name = chan->monitor->filename_base; + int directory = strchr(name, '/') ? 1 : 0; + char *dir = directory ? "" : AST_MONITOR_DIR; + /* one file argument if soxmix is called, two if not */ + if(chan->monitor->joinfiles) { + snprintf(tmp, sizeof(tmp), "%s %s/%s.%s &", chan->monitor->execute, dir, name, format); + } + else { + snprintf(tmp, sizeof(tmp), "%s %s/%s-in.%s %s/%s-out.%s &", chan->monitor->execute, dir, name, format,dir, name, format); + } + ast_verbose("executing %s\n",tmp); + ast_safe_system(tmp); + /* if (system(tmp) == -1) + ast_log(LOG_WARNING, "Execute failed for \"%s\"\n",tmp); */ + } + free( chan->monitor->format ); free( chan->monitor ); chan->monitor = NULL; @@ -253,7 +282,7 @@ char *name = strdup(fname_base); snprintf(tmp, sizeof(tmp), "mkdir -p %s",dirname(name)); free(name); - system(tmp); + ast_safe_system(tmp); } snprintf( chan->monitor->filename_base, FILENAME_MAX, "%s/%s", @@ -277,6 +306,7 @@ char *format = NULL; char *fname_base = NULL; char *options = NULL; + char *exec_opt = NULL; int joinfiles = 0; int res; @@ -293,6 +323,15 @@ options++; if (strchr(options, 'm')) joinfiles = 1; + printf("looking for exec\n"); + /* after all options look for an exec */ + if ((exec_opt = strchr(options, '|'))) { + *exec_opt=0; + exec_opt++; + } + + /* end exec paramter */ + } } @@ -303,7 +342,9 @@ res = ast_monitor_change_fname( chan, fname_base, 1 ); } ast_monitor_setjoinfiles(chan, joinfiles); - + if(exec_opt) + if(strlen(exec_opt)) + ast_monitor_setexecute(chan, exec_opt); if( arg ) { free( arg ); } @@ -327,6 +368,8 @@ char *name = astman_get_header(m, "Channel"); char *fname = astman_get_header(m, "File"); char *format = astman_get_header(m, "Format"); + char *mix = astman_get_header(m, "Mix"); + char *execute = astman_get_header(m, "Execute"); char *d; if((!name)||(!strlen(name))) { @@ -360,6 +403,20 @@ return 0; } } + + // If the channels should be mixed when monitoring is done + if( strlen(mix) ){ + if( (mix[0] == '1') || (mix[0] == 'y') || mix[0] == 'Y') { + ast_monitor_setjoinfiles( c, 1); + } + } + + //What script to execute when monitoring is done. + if( strlen(execute) ) { + ast_monitor_setexecute(c, execute); + } + + astman_send_ack(s, m, "Started monitoring channel"); return 0; } @@ -396,6 +453,8 @@ struct ast_channel *c = NULL; char *name = astman_get_header(m, "Channel"); char *fname = astman_get_header(m, "File"); + + if((!name) || (!strlen(name))) { astman_send_error(s, m, "No channel specified"); return 0; @@ -427,6 +486,12 @@ { if (chan->monitor) chan->monitor->joinfiles = turnon; +} + +void ast_monitor_setexecute(struct ast_channel *chan, char *execcmd) +{ + if (chan->monitor) + strncpy(chan->monitor->execute, execcmd, sizeof(chan->monitor->execute)); } int load_module(void)