diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index 4cbeac14a8..6053cd1903 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -616,10 +616,8 @@ char *sofia_overcome_sip_uri_weakness(switch_core_session_t *session, const char switch_status_t sofia_glue_do_invite(switch_core_session_t *session) { char *alert_info = NULL; - char *max_forwards = NULL; + const char *max_forwards = NULL; const char *alertbuf; - const char *forwardbuf; - int forwardval; private_object_t *tech_pvt; switch_channel_t *channel = NULL; switch_caller_profile_t *caller_profile; @@ -664,10 +662,7 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session) alert_info = switch_core_session_sprintf(tech_pvt->session, "Alert-Info: %s", alertbuf); } - if ((forwardbuf = switch_channel_get_variable(channel, SWITCH_MAX_FORWARDS_VARIABLE))) { - forwardval = atoi(forwardbuf) - 1; - max_forwards = switch_core_session_sprintf(tech_pvt->session, "%d", forwardval); - } + max_forwards = switch_channel_get_variable(channel, SWITCH_MAX_FORWARDS_VARIABLE); if ((status = sofia_glue_tech_choose_port(tech_pvt)) != SWITCH_STATUS_SUCCESS) { return status; diff --git a/src/switch_core_session.c b/src/switch_core_session.c index b57318411a..1af01d8032 100644 --- a/src/switch_core_session.c +++ b/src/switch_core_session.c @@ -288,8 +288,14 @@ SWITCH_DECLARE(switch_call_cause_t) switch_core_session_outgoing_channel(switch_ switch_channel_set_variable(peer_channel, SWITCH_B_SDP_VARIABLE, val); } - if ((val = switch_channel_get_variable(channel, SWITCH_MAX_FORWARDS_VARIABLE))) { - switch_channel_set_variable(peer_channel, SWITCH_MAX_FORWARDS_VARIABLE, val); + val = switch_channel_get_variable(channel, SWITCH_MAX_FORWARDS_VARIABLE); + + if (!switch_strlen_zero(val)) { + int forwardval = atoi(val) - 1; + const char *max_forwards = switch_core_session_sprintf(session, "%d", forwardval); + switch_channel_set_variable(peer_channel, SWITCH_MAX_FORWARDS_VARIABLE, max_forwards); + } else { + switch_channel_set_variable(peer_channel, SWITCH_MAX_FORWARDS_VARIABLE, "70"); } if (switch_channel_test_flag(channel, CF_BYPASS_MEDIA)) {