--- include/asterisk/channel.h	2006-07-26 00:55:55.000000000 -0400
+++ include/asterisk/channel.h.orig	2006-07-26 00:53:37.000000000 -0400
@@ -458,6 +458,8 @@
 	char *warning_sound;
 	char *end_sound;
 	char *start_sound;
+	char *limit_exit_caller;
+	char *limit_exit_callee;
 	int firstpass;
 	unsigned int flags;
 };
--- channel.c	2006-07-26 00:55:48.000000000 -0400
+++ channel.c.orig	2006-07-26 01:02:27.000000000 -0400
@@ -202,20 +202,20 @@
 /*--- ast_check_hangup: Checks to see if a channel is needing hang up */
 int ast_check_hangup(struct ast_channel *chan)
 {
-	time_t	myt;
+	time_t  myt;
 
 	/* if soft hangup flag, return true */
-	if (chan->_softhangup) 
+	if (chan->_softhangup)
 		return 1;
 	/* if no technology private data, return true */
-	if (!chan->tech_pvt) 
+	if (!chan->tech_pvt)
 		return 1;
 	/* if no hangup scheduled, just return here */
-	if (!chan->whentohangup) 
+	if (!chan->whentohangup)
 		return 0;
 	time(&myt); /* get current time */
 	/* return, if not yet */
-	if (chan->whentohangup > myt) 
+	if (chan->whentohangup > myt)
 		return 0;
 	chan->_softhangup |= AST_SOFTHANGUP_TIMEOUT;
 	return 1;
@@ -3373,6 +3373,8 @@
 	struct timeval nexteventts = { 0, };
 	char caller_warning = 0;
 	char callee_warning = 0;
+	char *limit_exit_caller = NULL;
+	char *limit_exit_callee = NULL;
 	int to;
 
 	if (c0->_bridge) {
@@ -3388,9 +3390,9 @@
 	
 	/* Stop if we're a zombie or need a soft hangup */
 	if (ast_test_flag(c0, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c0) ||
-	    ast_test_flag(c1, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c1)) 
+	    ast_test_flag(c1, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c1))
 		return -1;
-
+	
 	*fo = NULL;
 	firstpass = config->firstpass;
 	config->firstpass = 0;
@@ -3401,7 +3403,7 @@
 
 	caller_warning = ast_test_flag(&config->features_caller, AST_FEATURE_PLAY_WARNING);
 	callee_warning = ast_test_flag(&config->features_callee, AST_FEATURE_PLAY_WARNING);
-
+	
 	if (config->start_sound && firstpass) {
 		if (caller_warning)
 			bridge_playfile(c0, c1, config->start_sound, time_left_ms / 1000);
@@ -3431,6 +3433,15 @@
 			nexteventts = ast_tvsub(nexteventts, ast_samp2tv(config->play_warning, 1000));
 	}
 
+	if ( config->limit_exit_caller) {
+		limit_exit_caller = config->limit_exit_caller;
+		config->limit_exit_caller = NULL;
+	}
+	
+	if ( config->limit_exit_callee) {
+		limit_exit_callee = config->limit_exit_callee;
+		config->limit_exit_callee = NULL;
+	}
 	for (/* ever */;;) {
 		to = -1;
 		if (config->timelimit) {
@@ -3448,9 +3459,20 @@
 					bridge_playfile(c0, c1, config->end_sound, 0);
 				if (callee_warning && config->end_sound)
 					bridge_playfile(c1, c0, config->end_sound, 0);
+		
+				/* Since timeout occured, setting the backuped lecs to struct */			
+				if ( limit_exit_caller )				
+					config->limit_exit_caller = limit_exit_caller;
+				if ( limit_exit_callee )
+					config->limit_exit_callee = limit_exit_callee;
+					
 				*fo = NULL;
 				if (who) 
 					*rc = who;
+				
+				caller_warning = ast_test_flag(&config->features_caller, AST_FEATURE_PLAY_WARNING);
+				callee_warning = ast_test_flag(&config->features_callee, AST_FEATURE_PLAY_WARNING);
+				
 				res = 0;
 				break;
 			}
--- res/res_features.c	2006-07-26 00:55:53.000000000 -0400
+++ res/res_features.c.orig	2006-07-26 00:53:13.000000000 -0400
@@ -1324,7 +1324,6 @@
 			start = ast_tvnow();
 
 		res = ast_channel_bridge(chan, peer, config, &f, &who);
-
 		if (config->feature_timer) {
 			/* Update time limit for next pass */
 			diff = ast_tvdiff_ms(ast_tvnow(), start);
@@ -1468,6 +1467,8 @@
 					config->end_sound = NULL;
 					config->start_sound = NULL;
 					config->firstpass = 0;
+					config->limit_exit_caller = NULL;
+					config->limit_exit_callee = NULL;
 				}
 				config->feature_timer = featuredigittimeout;
 				ast_log(LOG_DEBUG, "Set time limit to %ld\n", config->feature_timer);
--- apps/app_dial.c	2006-07-26 00:55:59.000000000 -0400
+++ apps/app_dial.c.orig	2006-07-26 01:05:01.000000000 -0400
@@ -127,6 +127,8 @@
 "           * LIMIT_CONNECT_FILE       File to play when call begins.\n"
 "           * LIMIT_WARNING_FILE       File to play as warning if 'y' is defined.\n"
 "                                      The default is to say the time remaining.\n"
+"	    * LIMIT_EXIT_CALLER		CEP to call for the caller when limit is achieved\n"
+"	    * LIMIT_EXIT_CALLEE		CEP to call for the callee when limit is achieved\n"
 "    m([class]) - Provide hold music to the calling party until a requested\n"
 "           channel answers. A specific MusicOnHold class can be\n"
 "           specified.\n"
@@ -756,6 +758,8 @@
 	char *warning_sound=NULL;
 	char *end_sound=NULL;
 	char *start_sound=NULL;
+	char *limit_exit_caller=NULL;
+	char *limit_exit_callee=NULL;
 	char *dtmfcalled=NULL, *dtmfcalling=NULL;
 	char *var;
 	char status[256];
@@ -869,6 +873,12 @@
 		var = pbx_builtin_getvar_helper(chan,"LIMIT_CONNECT_FILE");
 		start_sound = var ? var : NULL;
 
+		var = pbx_builtin_getvar_helper(chan,"LIMIT_EXIT_CALLER");
+		limit_exit_caller = var ? var : NULL;
+	
+		var = pbx_builtin_getvar_helper(chan,"LIMIT_EXIT_CALLEE");
+		limit_exit_callee = var ? var : NULL;
+		
 		/* undo effect of S(x) in case they are both used */
 		calldurationlimit = 0; 
 		/* more efficient do it like S(x) does since no advanced opts*/
@@ -885,6 +895,8 @@
 			ast_verbose(VERBOSE_PREFIX_3 "- start_sound   = %s\n", start_sound ? start_sound : "UNDEF");
 			ast_verbose(VERBOSE_PREFIX_3 "- warning_sound = %s\n", warning_sound ? warning_sound : "UNDEF");
 			ast_verbose(VERBOSE_PREFIX_3 "- end_sound     = %s\n", end_sound ? end_sound : "UNDEF");
+			ast_verbose(VERBOSE_PREFIX_3 "- limit_exit_callee = %s\n", limit_exit_callee ? limit_exit_callee : "UNDEF");
+			ast_verbose(VERBOSE_PREFIX_3 "- limit_exit_caller = %s\n", limit_exit_caller ? limit_exit_caller : "UNDEF");
 		}
 	}
 
@@ -1580,6 +1592,8 @@
 			config.warning_sound = warning_sound;
 			config.end_sound = end_sound;
 			config.start_sound = start_sound;
+			config.limit_exit_caller = limit_exit_caller;
+			config.limit_exit_callee = limit_exit_callee;
 			if (moh) {
 				moh = 0;
 				ast_moh_stop(chan);
@@ -1601,7 +1615,17 @@
 			time(&end_time);
 			snprintf(toast, sizeof(toast), "%ld", (long)(end_time - answer_time));
 			pbx_builtin_setvar_helper(chan, "ANSWEREDTIME", toast);
-			
+	                if ( config.limit_exit_callee ) {
+				peer->priority=1;
+				strcpy(peer->exten, config.limit_exit_callee);
+				ast_pbx_start(peer);
+				res = AST_PBX_NO_HANGUP_PEER;
+			}
+			if ( config.limit_exit_caller ) {
+				ast_set_flag(peerflags, OPT_GO_ON);
+				ast_log(LOG_NOTICE, "Pitch the CALLER to (exten %s)\n",config.limit_exit_caller); 
+				ast_goto_if_exists(chan, chan->context, config.limit_exit_caller, 1);
+			}
 		} else {
 			time(&end_time);
 			res = -1;
@@ -1630,8 +1654,7 @@
 	if ((ast_test_flag(peerflags, OPT_GO_ON)) && (!chan->_softhangup) && (res != AST_PBX_KEEPALIVE))
 		res=0;
 	
-	LOCAL_USER_REMOVE(u);    
-	
+	LOCAL_USER_REMOVE(u);   	
 	return res;
 }
 
