From 2f950634ab0835752b916c89274b97fcc410f45f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 16 Jul 2011 02:33:39 -0500 Subject: [PATCH] fix sip auto_simplify --- src/include/switch_types.h | 2 ++ src/mod/endpoints/mod_sofia/mod_sofia.c | 11 +++++++++-- src/mod/endpoints/mod_sofia/mod_sofia.h | 3 ++- src/mod/endpoints/mod_sofia/sofia.c | 5 ++++- src/mod/endpoints/mod_sofia/sofia_glue.c | 11 ++++++++--- src/switch_ivr.c | 10 ++++++++++ 6 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 2f5646e54e..f6183e6018 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -1114,6 +1114,8 @@ typedef enum { CF_CNG_PLC, CF_ATTENDED_TRANSFER, CF_LAZY_ATTENDED_TRANSFER, + CF_SIGNAL_DATA, + CF_SIMPLIFY, /* WARNING: DO NOT ADD ANY FLAGS BELOW THIS LINE */ CF_FLAG_MAX } switch_channel_flag_t; diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index accc14657d..24f2828d35 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -968,6 +968,12 @@ static switch_status_t sofia_read_frame(switch_core_session_t *session, switch_f switch_assert(tech_pvt->rtp_session != NULL); tech_pvt->read_frame.datalen = 0; + + if (sofia_test_flag(tech_pvt, TFLAG_SIMPLIFY) && sofia_test_flag(tech_pvt, TFLAG_GOT_ACK)) { + sofia_glue_tech_simplify(tech_pvt); + sofia_clear_flag(tech_pvt, TFLAG_SIMPLIFY); + } + while (sofia_test_flag(tech_pvt, TFLAG_IO) && tech_pvt->read_frame.datalen == 0) { tech_pvt->read_frame.flags = SFF_NONE; @@ -1518,8 +1524,9 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi case SWITCH_MESSAGE_INDICATE_BRIDGE: { sofia_glue_tech_track(tech_pvt->profile, session); - - sofia_glue_tech_simplify(tech_pvt); + + sofia_set_flag(tech_pvt, TFLAG_SIMPLIFY); + 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 0e1a70e11d..ec60df275d 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -288,7 +288,7 @@ typedef enum { TFLAG_NOHUP, TFLAG_NOSDP_REINVITE, TFLAG_NAT, - TFLAG_USEME, + TFLAG_SIMPLIFY, TFLAG_SIP_HOLD, TFLAG_INB_NOMEDIA, TFLAG_LATE_NEGOTIATION, @@ -313,6 +313,7 @@ typedef enum { TFLAG_3PCC_INVITE, TFLAG_NOREPLY, TFLAG_LIBERAL_DTMF, + TFLAG_GOT_ACK, /* No new flags below this line */ TFLAG_MAX } TFLAGS; diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 33fe189f94..a97d3a0b47 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -945,6 +945,7 @@ static void our_sofia_event_callback(nua_event_t event, extract_header_vars(profile, sip, session, nh); sofia_glue_tech_track(tech_pvt->profile, session); + sofia_set_flag(tech_pvt, TFLAG_GOT_ACK); } } case nua_r_ack: @@ -5827,7 +5828,7 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, if ((enum nua_callstate) ss_state == nua_callstate_ready && channel && session && tech_pvt) { - sofia_glue_tech_simplify(tech_pvt); + sofia_set_flag(tech_pvt, TFLAG_SIMPLIFY); } @@ -6804,6 +6805,8 @@ void sofia_handle_sip_i_reinvite(switch_core_session_t *session, char via_space[2048]; char branch[16] = ""; + sofia_clear_flag(tech_pvt, TFLAG_GOT_ACK); + sofia_glue_get_addr(de->data->e_msg, network_ip, sizeof(network_ip), &network_port); switch_stun_random_string(branch, sizeof(branch) - 1, "0123456789abcdef"); diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index 2b77f82af7..4da775d683 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -6352,10 +6352,12 @@ void sofia_glue_tech_simplify(private_object_t *tech_pvt) 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)) { + if (!switch_channel_test_flag(tech_pvt->channel, CF_ANSWERED) || switch_channel_test_flag(tech_pvt->channel, CF_SIMPLIFY)) { return; } + + if ((uuid = switch_channel_get_variable(tech_pvt->channel, SWITCH_SIGNAL_BOND_VARIABLE)) && (other_session = switch_core_session_locate(uuid))) { @@ -6382,10 +6384,10 @@ void sofia_glue_tech_simplify(private_object_t *tech_pvt) && 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; @@ -6395,6 +6397,9 @@ void sofia_glue_tech_simplify(private_object_t *tech_pvt) did_simplify = 1; sofia_glue_tech_track(tech_pvt->profile, inbound_session); + + switch_channel_set_flag(inbound_channel, CF_SIMPLIFY); + } } diff --git a/src/switch_ivr.c b/src/switch_ivr.c index 967e86626e..84e077f27b 100644 --- a/src/switch_ivr.c +++ b/src/switch_ivr.c @@ -716,6 +716,14 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_parse_all_signal_data(switch_core_ses void *data; switch_core_session_message_t msg = { 0 }; int i = 0; + switch_channel_t *channel = switch_core_session_get_channel(session); + + + if (switch_channel_test_flag(channel, CF_SIGNAL_DATA)) { + return SWITCH_STATUS_FALSE; + } + + switch_channel_set_flag(channel, CF_SIGNAL_DATA); msg.message_id = SWITCH_MESSAGE_INDICATE_SIGNAL_DATA; msg.from = __FILE__; @@ -730,6 +738,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_parse_all_signal_data(switch_core_ses } + switch_channel_clear_flag(channel, CF_SIGNAL_DATA); + return i ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE; }