From 7b8a36c2a98281e2c31db1c908842a327d2cfdca Mon Sep 17 00:00:00 2001 From: surendrasignalwire Date: Thu, 13 Aug 2020 14:49:47 +0400 Subject: [PATCH] [mod_sofia] Fix recovery reinvite issue --- src/mod/endpoints/mod_sofia/sofia.c | 9 +++++++++ src/mod/endpoints/mod_sofia/sofia_glue.c | 11 +++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 7f7b0c2b75..4975ca8feb 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -1733,6 +1733,10 @@ static void our_sofia_event_callback(nua_event_t event, switch_channel_set_variable(channel, "sip_call_id", sip->sip_call_id->i_id); } + if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND) { + switch_channel_set_variable(channel, "dlg_req_swap_direction", "true"); + } + extract_header_vars(profile, sip, session, nh); switch_core_recovery_track(session); sofia_set_flag(tech_pvt, TFLAG_GOT_ACK); @@ -7111,8 +7115,13 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE); } + if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_INBOUND) { + switch_channel_set_variable(channel, "dlg_req_swap_direction", "true"); + } + extract_header_vars(profile, sip, session, nh); extract_vars(profile, sip, session); + switch_core_recovery_track(session); switch_channel_clear_flag(tech_pvt->channel, CF_RECOVERING); } diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index a49bd998a9..2eea09bd5e 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -2235,7 +2235,7 @@ int sofia_recover_callback(switch_core_session_t *session) const char *rr; int r = 0; const char *profile_name = switch_channel_get_variable_dup(channel, "recovery_profile_name", SWITCH_FALSE, -1); - + int swap = switch_channel_var_true(channel, "dlg_req_swap_direction"); if (zstr(profile_name)) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "Missing profile\n"); @@ -2275,10 +2275,9 @@ int sofia_recover_callback(switch_core_session_t *session) rr = switch_channel_get_variable(channel, "sip_invite_record_route"); if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND) { - int break_rfc = switch_true(switch_channel_get_variable(channel, "sip_recovery_break_rfc")); tech_pvt->dest = switch_core_session_sprintf(session, "sip:%s", switch_channel_get_variable(channel, "sip_req_uri")); - switch_channel_set_variable(channel, "sip_handle_full_from", switch_channel_get_variable(channel, break_rfc ? "sip_full_to" : "sip_full_from")); - switch_channel_set_variable(channel, "sip_handle_full_to", switch_channel_get_variable(channel, break_rfc ? "sip_full_from" : "sip_full_to")); + switch_channel_set_variable(channel, "sip_handle_full_from", switch_channel_get_variable(channel, swap ? "sip_full_to" : "sip_full_from")); + switch_channel_set_variable(channel, "sip_handle_full_to", switch_channel_get_variable(channel, swap ? "sip_full_from" : "sip_full_to")); } else { const char *contact_params = switch_channel_get_variable(channel, "sip_contact_params"); const char *contact_uri = switch_channel_get_variable(channel, "sip_contact_uri"); @@ -2297,11 +2296,11 @@ int sofia_recover_callback(switch_core_session_t *session) tech_pvt->dest = switch_core_session_sprintf(session, "sip:%s", switch_channel_get_variable(channel, "sip_from_uri")); if (!switch_channel_get_variable_dup(channel, "sip_handle_full_from", SWITCH_FALSE, -1)) { - switch_channel_set_variable(channel, "sip_handle_full_from", switch_channel_get_variable(channel, "sip_full_to")); + switch_channel_set_variable(channel, "sip_handle_full_from", switch_channel_get_variable(channel, swap ? "sip_full_from" :"sip_full_to")); } if (!switch_channel_get_variable_dup(channel, "sip_handle_full_to", SWITCH_FALSE, -1)) { - switch_channel_set_variable(channel, "sip_handle_full_to", switch_channel_get_variable(channel, "sip_full_from")); + switch_channel_set_variable(channel, "sip_handle_full_to", switch_channel_get_variable(channel, swap ? "sip_full_to" : "sip_full_from")); } }