From 06de953fbc258431f0f161cba3026cb3a33e242b Mon Sep 17 00:00:00 2001
From: "Kevin P. Fleming" <kpfleming@digium.com>
Date: Fri, 22 Apr 2005 02:55:14 +0000
Subject: [PATCH] add ability to send transferring party to a dialplan target
 after they blind transfer another party (bug #4056, with mods)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@5495 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 doc/README.variables |  6 +++++-
 pbx.c                |  3 +--
 res/res_features.c   | 35 +++++++++++++++++++++++++++++++++++
 3 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/doc/README.variables b/doc/README.variables
index 050bd1285d..e84d937574 100755
--- a/doc/README.variables
+++ b/doc/README.variables
@@ -319,7 +319,7 @@ only read in the dialplan.  Writes to such variables are silently
 ignored.
 
 ${ACCOUNTCODE} 	 	* Account code (if specified)
-${BLINDTRANSFER} 	The name of the channel on the other side a blind transfer
+${BLINDTRANSFER} 	The name of the channel on the other side of a blind transfer
 ${BRIDGEPEER}	 	Bridged peer
 ${CALLERANI}	 	* Caller ANI (PRI channels)
 ${CALLERID}	 	* Caller ID
@@ -336,6 +336,10 @@ ${DNID}          	* Dialed Number Identifier
 ${EPOCH}	 	* Current unix style epoch
 ${EXTEN}	 	* Current extension
 ${ENV(VAR)}	 	* Environmental variable VAR
+${GOTO_ON_BLINDXFR}	Transfer to the specified context/extension/priority
+			after a blind transfer (use ^ characters in place of
+			| to separate context/extension/priority when setting
+			this variable from the dialplan)
 ${HANGUPCAUSE}	 	* Asterisk cause of hangup (inbound/outbound)
 ${HINT}          	* Channel hints for this extension
 ${HINTNAME}      	* Suggested Caller*ID name for this extension
diff --git a/pbx.c b/pbx.c
index 68b55e126e..2d1c42951c 100755
--- a/pbx.c
+++ b/pbx.c
@@ -6271,8 +6271,7 @@ int ast_parseable_goto(struct ast_channel *chan, const char *goto_string)
 	if (mode) 
 		ipri = chan->priority + (ipri * mode);
 
-	/* This channel is currently in the PBX */
-	ast_explicit_goto(chan, context, exten, ipri - 1);
+	ast_explicit_goto(chan, context, exten, chan->pbx ? ipri - 1 : ipri);
 	ast_cdr_update(chan);
 	return 0;
 
diff --git a/res/res_features.c b/res/res_features.c
index b177549d9f..6f404ca252 100755
--- a/res/res_features.c
+++ b/res/res_features.c
@@ -144,6 +144,40 @@ struct ast_bridge_thread_obj
 	struct ast_channel *peer;
 };
 
+static void check_goto_on_transfer(struct ast_channel *chan) 
+{
+	struct ast_channel *xferchan;
+	char *goto_on_transfer;
+
+	goto_on_transfer = pbx_builtin_getvar_helper(chan, "GOTO_ON_BLINDXFR");
+
+	if (goto_on_transfer && !ast_strlen_zero(goto_on_transfer) && (xferchan = ast_channel_alloc(0))) {
+		char *x;
+		struct ast_frame *f;
+		
+		for (x = goto_on_transfer; x && *x; x++)
+			if (*x == '^')
+				*x = '|';
+
+		strcpy(xferchan->name, chan->name);
+		/* Make formats okay */
+		xferchan->readformat = chan->readformat;
+		xferchan->writeformat = chan->writeformat;
+		ast_channel_masquerade(xferchan, chan);
+		ast_parseable_goto(xferchan, goto_on_transfer);
+		xferchan->_state = AST_STATE_UP;
+		ast_clear_flag(xferchan, AST_FLAGS_ALL);	
+		xferchan->_softhangup = 0;
+		if ((f = ast_read(xferchan))) {
+			ast_frfree(f);
+			f = NULL;
+			ast_pbx_start(xferchan);
+		} else {
+			ast_hangup(xferchan);
+		}
+	}
+}
+
 static void *ast_bridge_call_thread(void *data) 
 {
 	struct ast_bridge_thread_obj *tobj = data;
@@ -550,6 +584,7 @@ static int builtin_blindtransfer(struct ast_channel *chan, struct ast_channel *p
 			strncpy(transferee->context, transferer_real_context, sizeof(transferee->context)-1);
 			transferee->priority = 0;
 		}
+		check_goto_on_transfer(transferer);
 		return res;
 	} else {
 		if (option_verbose > 2)	
-- 
GitLab