From dfd5fc5605bf4732dc433582fc50e414be3d5c7c Mon Sep 17 00:00:00 2001
From: "Kevin P. Fleming" <kpfleming@digium.com>
Date: Thu, 1 Jun 2006 20:53:17 +0000
Subject: [PATCH] Merged revisions 31520 via svnmerge from
 https://origsvn.digium.com/svn/asterisk/branches/1.2

........
r31520 | kpfleming | 2006-06-01 15:27:50 -0500 (Thu, 01 Jun 2006) | 2 lines

handle Zap transfers behind chan_agent properly so the agent doesn't get stuck waiting for the call to hang up

........


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@31522 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 channel.c                  | 8 ++++++++
 include/asterisk/channel.h | 5 +++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/channel.c b/channel.c
index 545e00231c..65dcf2f4fa 100644
--- a/channel.c
+++ b/channel.c
@@ -2829,6 +2829,14 @@ int ast_channel_masquerade(struct ast_channel *original, struct ast_channel *clo
 {
 	int res = -1;
 
+	/* each of these channels may be sitting behind a channel proxy (i.e. chan_agent)
+	   and if so, we don't really want to masquerade it, but its proxy */
+	if (original->_bridge && (original->_bridge != ast_bridged_channel(original)))
+		original = original->_bridge;
+
+	if (clone->_bridge && (clone->_bridge != ast_bridged_channel(clone)))
+		clone = clone->_bridge;
+
 	if (original == clone) {
 		ast_log(LOG_WARNING, "Can't masquerade channel '%s' into itself!\n", original->name);
 		return -1;
diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h
index 9d38dff5b4..a36949932b 100644
--- a/include/asterisk/channel.h
+++ b/include/asterisk/channel.h
@@ -311,8 +311,9 @@ struct ast_channel {
 	/*! Current active data generator */
 	struct ast_generator *generator;
 
-	/*! Who are we bridged to, if we're bridged  Do not access directly,
-	    use ast_bridged_channel(chan) */
+	/*! Who are we bridged to, if we're bridged. Who is proxying for us,
+	  if we are proxied (i.e. chan_agent).
+	  Do not access directly, use ast_bridged_channel(chan) */
 	struct ast_channel *_bridge;
 	/*! Channel that will masquerade as us */
 	struct ast_channel *masq;		
-- 
GitLab