From fabaa4a28ebbc49a8622a57bdd73b31c2afd93bb Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 18 Jun 2010 17:09:26 -0500 Subject: [PATCH] MODSOFIA-77 --- src/mod/endpoints/mod_sofia/mod_sofia.c | 36 +------------ src/mod/endpoints/mod_sofia/mod_sofia.h | 1 + src/mod/endpoints/mod_sofia/sofia.c | 6 +++ src/mod/endpoints/mod_sofia/sofia_glue.c | 65 ++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 35 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index d1f7d4cc1c..c23f4b69c3 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -1341,42 +1341,8 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi case SWITCH_MESSAGE_INDICATE_BRIDGE: { - const char *network_addr_a, *network_addr_b, *simplify_a, *simplify_b; - int s_ok = 0; - int do_s = 0; - simplify_a = switch_channel_get_variable(channel, "sip_auto_simplify"); - simplify_b = switch_channel_get_variable_partner(channel, "sip_auto_simplify"); - - if (switch_true(simplify_a)) { - if (switch_true(simplify_b) && !switch_channel_test_flag(channel, CF_BRIDGE_ORIGINATOR)) { - s_ok = 0; - } else { - s_ok = 1; - } - } - - if (s_ok) { - network_addr_a = switch_channel_get_variable(channel, "network_addr"); - network_addr_b = switch_channel_get_variable_partner(channel, "network_addr"); - - if (!zstr(network_addr_a) && !zstr(network_addr_b) && !strcmp(network_addr_a, network_addr_b)) { - if (strcmp(network_addr_a, switch_str_nil(tech_pvt->profile->sipip)) && - strcmp(network_addr_a, switch_str_nil(tech_pvt->profile->extsipip))) { - switch_core_session_message_t smsg = { 0 }; - - smsg.message_id = SWITCH_MESSAGE_INDICATE_SIMPLIFY; - smsg.from = __FILE__; - - status = switch_core_session_receive_message(session, &smsg); - do_s = 1; - } - } - } - - if (!do_s) { - sofia_glue_tech_track(tech_pvt->profile, session); - } + sofia_glue_tech_simplify(tech_pvt); if (switch_rtp_ready(tech_pvt->rtp_session)) { const char *val; diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index e6a857875e..6c986cc223 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -998,3 +998,4 @@ void sofia_reg_fire_custom_gateway_state_event(sofia_gateway_t *gateway, int sta void sofia_glue_copy_t38_options(switch_t38_options_t *t38_options, switch_core_session_t *session); switch_t38_options_t *sofia_glue_extract_t38_options(switch_core_session_t *session, const char *r_sdp); char *sofia_glue_get_multipart(switch_core_session_t *session, const char *prefix, const char *sdp, char **mp_type); +void sofia_glue_tech_simplify(private_object_t *tech_pvt); diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 3cab0edb3d..e2675a4c87 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -4925,6 +4925,12 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, } done: + + if ((enum nua_callstate) ss_state == nua_callstate_ready && channel && session && tech_pvt) { + sofia_glue_tech_simplify(tech_pvt); + } + + return; } diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index 83aeda2a3d..35d3c5d2ce 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -5457,6 +5457,71 @@ switch_status_t sofia_glue_send_notify(sofia_profile_t *profile, const char *use return SWITCH_STATUS_SUCCESS; } + +void sofia_glue_tech_simplify(private_object_t *tech_pvt) +{ + const char *uuid, *network_addr_a, *network_addr_b, *simplify, *simplify_other_channel; + switch_channel_t *other_channel = NULL, *inbound_channel = NULL; + switch_core_session_t *other_session = NULL, *inbound_session = NULL; + uint8_t did_simplify = 0; + + if (!switch_channel_test_flag(tech_pvt->channel, CF_ANSWERED)) { + return; + } + + if ((uuid = switch_channel_get_variable(tech_pvt->channel, SWITCH_SIGNAL_BOND_VARIABLE)) + && (other_session = switch_core_session_locate(uuid))) { + + other_channel = switch_core_session_get_channel(other_session); + + if (switch_channel_test_flag(other_channel, CF_ANSWERED)) { /* Check if the other channel is answered */ + simplify = switch_channel_get_variable(tech_pvt->channel, "sip_auto_simplify"); + simplify_other_channel = switch_channel_get_variable(other_channel, "sip_auto_simplify"); + + if (switch_true(simplify) && !switch_channel_test_flag(tech_pvt->channel, CF_BRIDGE_ORIGINATOR)) { + network_addr_a = switch_channel_get_variable(tech_pvt->channel, "network_addr"); + network_addr_b = switch_channel_get_variable(other_channel, "network_addr"); + inbound_session = other_session; + inbound_channel = other_channel; + } else if (switch_true(simplify_other_channel) && !switch_channel_test_flag(other_channel, CF_BRIDGE_ORIGINATOR)) { + network_addr_a = switch_channel_get_variable(other_channel, "network_addr"); + network_addr_b = switch_channel_get_variable(tech_pvt->channel, "network_addr"); + inbound_session = tech_pvt->session; + inbound_channel = tech_pvt->channel; + } + + if (inbound_channel && inbound_session && !zstr(network_addr_a) && !zstr(network_addr_b) && !strcmp(network_addr_a, network_addr_b)) { + if (strcmp(network_addr_a, switch_str_nil(tech_pvt->profile->sipip)) && strcmp(network_addr_a, switch_str_nil(tech_pvt->profile->extsipip))) { + + switch_core_session_message_t *msg; + + switch_log_printf(SWITCH_CHANNEL_ID_LOG, __FILE__, __SWITCH_FUNC__, __LINE__, switch_channel_get_uuid(inbound_channel), SWITCH_LOG_NOTICE, + "Will simplify channel [%s]\n", switch_channel_get_name(inbound_channel)); + + msg = switch_core_session_alloc(inbound_session, sizeof(*msg)); + MESSAGE_STAMP_FFL(msg); + msg->message_id = SWITCH_MESSAGE_INDICATE_SIMPLIFY; + msg->from = __FILE__; + switch_core_session_receive_message(inbound_session, msg); + + did_simplify = 1; + + sofia_glue_tech_track(tech_pvt->profile, inbound_session); + } + } + + if (!did_simplify && inbound_channel) { + switch_log_printf(SWITCH_CHANNEL_ID_LOG, __FILE__, __SWITCH_FUNC__, __LINE__, switch_channel_get_uuid(inbound_channel), SWITCH_LOG_NOTICE, + "Could not simplify channel [%s]\n", switch_channel_get_name(inbound_channel)); + } + } + + switch_core_session_rwunlock(other_session); + } +} + + + /* For Emacs: * Local Variables: * mode:c