]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
MODSOFIA-77
authorAnthony Minessale <anthm@freeswitch.org>
Fri, 18 Jun 2010 22:09:26 +0000 (17:09 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Fri, 18 Jun 2010 22:09:26 +0000 (17:09 -0500)
src/mod/endpoints/mod_sofia/mod_sofia.c
src/mod/endpoints/mod_sofia/mod_sofia.h
src/mod/endpoints/mod_sofia/sofia.c
src/mod/endpoints/mod_sofia/sofia_glue.c

index d1f7d4cc1c671fce44ab12ddd50129d6c2afc1e8..c23f4b69c3157bfbe7f7590bfc38a422e270d71f 100644 (file)
@@ -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;
index e6a857875e91a43e90e4654709d015ce7af1e6df..6c986cc223af0192313571b7275c06c5be7aa288 100644 (file)
@@ -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);
index 3cab0edb3d46ec220a031e8d3b2b44d9d8d55232..e2675a4c8758df38426b7f078f54565c0e572ca5 100644 (file)
@@ -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;
 }
 
index 83aeda2a3d22c3a5a5c04e40a453fb783f903874..35d3c5d2ce975ac77bb2099d3ff67cce75e46314 100644 (file)
@@ -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