From 23bb963d17848d1f21b2934073b3e8c4f12a0880 Mon Sep 17 00:00:00 2001
From: Anthony Minessale <anthm@freeswitch.org>
Date: Wed, 31 Oct 2012 08:51:55 -0500
Subject: [PATCH] FS-4779 I don't have this labbed up to try so can you try
 this patch and repost logs if it doesn't work

---
 src/mod/endpoints/mod_sofia/mod_sofia.c | 32 ++++++++++++++++++-------
 src/mod/endpoints/mod_sofia/sofia.c     | 15 ++++++++++--
 2 files changed, 36 insertions(+), 11 deletions(-)

diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c
index ddf0b5dccf..c11d37c42f 100644
--- a/src/mod/endpoints/mod_sofia/mod_sofia.c
+++ b/src/mod/endpoints/mod_sofia/mod_sofia.c
@@ -2019,16 +2019,30 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
 							  switch_channel_get_name(channel), msg->string_arg);
 			sofia_glue_tech_set_local_sdp(tech_pvt, msg->string_arg, SWITCH_TRUE);
 
-			if(zstr(tech_pvt->local_sdp_str)) {
-				sofia_set_flag(tech_pvt, TFLAG_3PCC_INVITE);
+			if (msg->numeric_arg) { // ACK
+				switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "3PCC-PROXY nomedia - sending ack\n");
+				nua_ack(tech_pvt->nh,
+						TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)),
+						SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
+						SOATAG_USER_SDP_STR(msg->string_arg),
+						SOATAG_REUSE_REJECTED(1),
+						SOATAG_RTP_SELECT(1), SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"),
+						TAG_IF(sofia_test_pflag(tech_pvt->profile, PFLAG_DISABLE_100REL), NUTAG_INCLUDE_EXTRA_SDP(1)),
+						TAG_END());
+				sofia_clear_flag(tech_pvt, TFLAG_3PCC_INVITE);
+				
+			} else {
+				if(zstr(tech_pvt->local_sdp_str)) {
+					sofia_set_flag(tech_pvt, TFLAG_3PCC_INVITE);
+				}
+				
+				sofia_set_flag_locked(tech_pvt, TFLAG_SENT_UPDATE);
+				
+				if (!switch_channel_test_flag(channel, CF_PROXY_MEDIA)) {
+					switch_channel_set_flag(channel, CF_REQ_MEDIA);
+				}
+				sofia_glue_do_invite(session);
 			}
-
-			sofia_set_flag_locked(tech_pvt, TFLAG_SENT_UPDATE);
-
-			if (!switch_channel_test_flag(channel, CF_PROXY_MEDIA)) {
-				switch_channel_set_flag(channel, CF_REQ_MEDIA);
-			}
-			sofia_glue_do_invite(session);
 		}
 		break;
 
diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c
index 9118c874e2..679fcd52c9 100644
--- a/src/mod/endpoints/mod_sofia/sofia.c
+++ b/src/mod/endpoints/mod_sofia/sofia.c
@@ -1155,6 +1155,7 @@ static void our_sofia_event_callback(nua_event_t event,
 				switch_core_recovery_track(session);
 				sofia_set_flag(tech_pvt, TFLAG_GOT_ACK);
 
+
 				if (sofia_test_flag(tech_pvt, TFLAG_PASS_ACK)) {
 					switch_core_session_t *other_session;
 					
@@ -5750,13 +5751,23 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status,
 			if (r_sdp && sofia_test_flag(tech_pvt, TFLAG_3PCC_INVITE) && !sofia_test_flag(tech_pvt, TFLAG_SDP)) {
 				sofia_set_flag(tech_pvt, TFLAG_SDP);
 				if (switch_core_session_get_partner(session, &other_session) == SWITCH_STATUS_SUCCESS) {
+					switch_core_session_message_t *msg;
+
 					other_channel = switch_core_session_get_channel(other_session);
-					//other_tech_pvt = switch_core_session_get_private(other_session);
 
 					if (!switch_channel_get_variable(other_channel, SWITCH_B_SDP_VARIABLE)) {
 						switch_channel_set_variable(other_channel, SWITCH_B_SDP_VARIABLE, r_sdp);
 					}
-					switch_core_session_queue_indication(other_session, SWITCH_MESSAGE_INDICATE_ANSWER);
+
+					msg = switch_core_session_alloc(other_session, sizeof(*msg));
+					msg->message_id = SWITCH_MESSAGE_INDICATE_MEDIA_REDIRECT;
+					msg->from = __FILE__;
+					msg->string_arg = switch_core_session_strdup(other_session, r_sdp);
+					msg->numeric_arg = 1; // send ack
+					switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Passing SDP ACK to other leg.\n%s\n", r_sdp);
+
+					switch_core_session_queue_message(other_session, msg);
+
 					switch_core_session_rwunlock(other_session);
 				}
 				goto done;