From 646a5609a19416a4d0203a0e2d8395ed128b8dfc Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 8 Sep 2010 22:53:57 -0500 Subject: [PATCH] edge cases for sofia recover --- src/mod/endpoints/mod_sofia/mod_sofia.c | 2 ++ src/mod/endpoints/mod_sofia/mod_sofia.h | 1 + src/mod/endpoints/mod_sofia/sofia.c | 35 +++++++++++++++++++++++- src/mod/endpoints/mod_sofia/sofia_glue.c | 6 ++++ 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 799cf4f2af..3d330dab55 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -721,6 +721,7 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session) TAG_IF(sticky, NUTAG_PROXY(tech_pvt->record_route)), TAG_IF(cid, SIPTAG_HEADER_STR(cid)), NUTAG_SESSION_TIMER(session_timeout), + TAG_IF(session_timeout, NUTAG_SESSION_REFRESHER(nua_remote_refresher)), SIPTAG_CONTACT_STR(tech_pvt->reply_contact), SIPTAG_CALL_INFO_STR(switch_channel_get_variable(tech_pvt->channel, SOFIA_SIP_HEADER_PREFIX "call_info")), SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str), @@ -736,6 +737,7 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session) TAG_IF(sticky, NUTAG_PROXY(tech_pvt->record_route)), TAG_IF(cid, SIPTAG_HEADER_STR(cid)), NUTAG_SESSION_TIMER(session_timeout), + TAG_IF(session_timeout, NUTAG_SESSION_REFRESHER(nua_remote_refresher)), SIPTAG_CONTACT_STR(tech_pvt->reply_contact), SIPTAG_CALL_INFO_STR(switch_channel_get_variable(tech_pvt->channel, SOFIA_SIP_HEADER_PREFIX "call_info")), SIPTAG_CONTENT_TYPE_STR("application/sdp"), diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index 4cdb1a2912..4d51e4b573 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -106,6 +106,7 @@ typedef struct private_object private_object_t; #define SOFIA_CRYPTO_MANDATORY_VARIABLE "sip_crypto_mandatory" #define FREESWITCH_SUPPORT "update_display" +#include #include #include #include diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 258be0ed59..4d9ce9eea5 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -4518,7 +4518,20 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, } break; case nua_callstate_completing: - nua_ack(nh, TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)), TAG_END()); + { + if (sofia_test_pflag(profile, PFLAG_TRACK_CALLS)) { + const char *invite_full_via = switch_channel_get_variable(tech_pvt->channel, "sip_invite_full_via"); + const char *invite_route_uri = switch_channel_get_variable(tech_pvt->channel, "sip_invite_route_uri"); + + nua_ack(nh, + TAG_IF(!zstr(invite_full_via), SIPTAG_VIA_STR(invite_full_via)), + TAG_IF(!zstr(invite_route_uri), SIPTAG_ROUTE_STR(invite_route_uri)), + TAG_END()); + + } else { + nua_ack(nh, TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)), TAG_END()); + } + } goto done; case nua_callstate_received: if (!sofia_test_flag(tech_pvt, TFLAG_SDP)) { @@ -5898,6 +5911,26 @@ void sofia_handle_sip_i_reinvite(switch_core_session_t *session, { char *call_info = NULL; + if (session && profile && sip && sofia_test_pflag(profile, PFLAG_TRACK_CALLS)) { + switch_channel_t *channel = switch_core_session_get_channel(session); + private_object_t *tech_pvt = (private_object_t *) switch_core_session_get_private(session); + char network_ip[80]; + int network_port = 0; + char via_space[2048]; + char branch[16] = ""; + + sofia_glue_get_addr(nua_current_request(nua), network_ip, sizeof(network_ip), &network_port); + switch_stun_random_string(branch, sizeof(branch) - 1, "0123456789abcdef"); + + switch_snprintf(via_space, sizeof(via_space), "SIP/2.0/UDP %s;rport=%d;branch=%s", network_ip, network_port, branch); + switch_channel_set_variable(channel, "sip_full_via", via_space); + switch_channel_set_variable_printf(channel, "sip_network_port", "%d", network_port); + switch_channel_set_variable_printf(channel, "sip_recieved_port", "%d", network_port); + switch_channel_set_variable_printf(channel, "sip_via_rport", "%d", network_port); + + sofia_glue_tech_track(tech_pvt->profile, session); + } + if (sofia_test_pflag(profile, PFLAG_MANAGE_SHARED_APPEARANCE)) { switch_channel_t *channel = switch_core_session_get_channel(session); if (channel && sip->sip_call_info) { diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index 45364cdac2..473dfb9aca 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -2055,10 +2055,15 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session) sofia_clear_flag(tech_pvt, TFLAG_ENABLE_SOA); } + if (sofia_test_flag(tech_pvt, TFLAG_RECOVERED)) { + session_timeout = 0; + } + if (sofia_use_soa(tech_pvt)) { nua_invite(tech_pvt->nh, NUTAG_AUTOANSWER(0), NUTAG_SESSION_TIMER(session_timeout), + TAG_IF(session_timeout, NUTAG_SESSION_REFRESHER(nua_remote_refresher)), TAG_IF(sofia_test_flag(tech_pvt, TFLAG_RECOVERED), NUTAG_INVITE_TIMER(UINT_MAX)), TAG_IF(invite_full_from, SIPTAG_FROM_STR(invite_full_from)), TAG_IF(invite_full_to, SIPTAG_TO_STR(invite_full_to)), @@ -2088,6 +2093,7 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session) nua_invite(tech_pvt->nh, NUTAG_AUTOANSWER(0), NUTAG_SESSION_TIMER(session_timeout), + TAG_IF(session_timeout, NUTAG_SESSION_REFRESHER(nua_remote_refresher)), TAG_IF(sofia_test_flag(tech_pvt, TFLAG_RECOVERED), NUTAG_INVITE_TIMER(UINT_MAX)), TAG_IF(invite_full_from, SIPTAG_FROM_STR(invite_full_from)), TAG_IF(invite_full_to, SIPTAG_TO_STR(invite_full_to)),