Index: res/res_monitor.c
===================================================================
RCS file: /usr/cvsroot/asterisk/res/res_monitor.c,v
retrieving revision 1.19
diff -u -r1.19 res_monitor.c
--- res/res_monitor.c	29 Jun 2004 04:42:19 -0000	1.19
+++ res/res_monitor.c	5 Sep 2004 17:24:23 -0000
@@ -42,9 +42,14 @@
 "                    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"
+"                    only without the in/out designator.\n"
+"                    If MONITOR_EXEC_ARGS is set, the contents will be passed on as\n"
+"                    additional arguements to MONITOR_EXEC\n"
 "                    Both MONITOR_EXEC and the Mix flag can be set from the\n"
-"                    administrator interface\n";
+"                    administrator interface\n\n"
+"\n"
+"              'b' - Don't begin recording unless a call is bridged to another channel\n"
+;
 
 static char *stopmonitor_synopsis = "Stop monitoring a channel";
 
@@ -172,8 +177,8 @@
 /* Stop monitoring a channel */
 int ast_monitor_stop( struct ast_channel *chan, int need_lock )
 {
-	char *execute;
-	int soxmix =0;
+	char *execute,*execute_args;
+	int delfiles =0;
 
 	if (need_lock) {
 		if (ast_mutex_lock(&chan->lock)) {
@@ -226,10 +231,15 @@
 			execute=pbx_builtin_getvar_helper(chan,"MONITOR_EXEC");
 			if (!execute || ast_strlen_zero(execute)) { 
 				execute = "nice -n 19 soxmix"; 
-				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) {
+				delfiles = 1;
+			} 
+			execute_args = pbx_builtin_getvar_helper(chan,"MONITOR_EXEC_ARGS");
+			if (!execute_args || ast_strlen_zero(execute_args)) {
+				execute_args = "";
+			}
+			
+			snprintf(tmp, sizeof(tmp), "%s %s/%s-in.%s %s/%s-out.%s %s/%s.%s %s &", execute, dir, name, format, dir, name, format, dir, name, format,execute_args);
+			if (delfiles) {
 				snprintf(tmp2,sizeof(tmp2), "( %s& rm -f %s/%s-* ) &",tmp, dir ,name); /* remove legs when done mixing */
 				strncpy(tmp, tmp2, sizeof(tmp) - 1);
 			}
@@ -291,12 +301,14 @@
 	char *format = NULL;
 	char *fname_base = NULL;
 	char *options = NULL;
+	char *delay = NULL;
 	int joinfiles = 0;
-	int res;
+	int waitforbridge = 0;
+	int res = 0;
 	
 	/* Parse arguments. */
 	if (data && strlen((char*)data)) {
-		arg = strdup((char*)data);
+		arg = ast_strdupa((char*)data);
 		format = arg;
 		fname_base = strchr(arg, '|');
 		if (fname_base) {
@@ -307,18 +319,21 @@
 				options++;
 				if (strchr(options, 'm'))
 					joinfiles = 1;
+				if (strchr(options, 'b'))
+                    waitforbridge = 1;
 			}
 		}
-		
 	}
-
+	if(waitforbridge) {
+		delay = ast_strdupa((char*)data);
+		snprintf(delay,strlen(delay),"%s|%s%s",format,fname_base,joinfiles ? "|m" : "");
+		pbx_builtin_setvar_helper(chan,"AUTO_MONITOR",delay);
+		return 0;
+	}
 	res = ast_monitor_start(chan, format, fname_base, 1);
 	if (res < 0)
 		res = ast_monitor_change_fname( chan, fname_base, 1 );
 	ast_monitor_setjoinfiles(chan, joinfiles);
-
-	if (arg)
-		free( arg );
 
 	return res;
 }
Index: res/res_features.c
===================================================================
RCS file: /usr/cvsroot/asterisk/res/res_features.c,v
retrieving revision 1.11
diff -u -r1.11 res_features.c
--- res/res_features.c	1 Sep 2004 19:51:19 -0000	1.11
+++ res/res_features.c	5 Sep 2004 17:24:24 -0000
@@ -87,6 +87,9 @@
 "into the dialplan, although you should include the 'parkedcalls'\n"
 "context.\n";
 
+static struct ast_app *monitor_app=NULL;
+static int monitor_ok=1;
+
 struct parkeduser {
 	struct ast_channel *chan;
 	struct timeval start;
@@ -272,7 +275,18 @@
 	struct timeval start, end;
 	char *transferer_real_context;
 	int allowdisconnect_in,allowdisconnect_out,allowredirect_in,allowredirect_out;
+	char *monitor_exec;
 
+	if(monitor_ok) {
+		if(!monitor_app) 
+			if(!(monitor_app = pbx_findapp("Monitor")))
+				monitor_ok=0;
+		if((monitor_exec = pbx_builtin_getvar_helper(chan,"AUTO_MONITOR"))) 
+			pbx_exec(chan, monitor_app, monitor_exec, 1);
+		else if((monitor_exec = pbx_builtin_getvar_helper(peer,"AUTO_MONITOR")))
+			pbx_exec(peer, monitor_app, monitor_exec, 1);
+	}
+	
 	allowdisconnect_in = config->allowdisconnect_in;
 	allowdisconnect_out = config->allowdisconnect_out;
 	allowredirect_in = config->allowredirect_in;
