diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index ea3e567b1f..789a51e223 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -6364,37 +6364,36 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, if (!tech_pvt || !tech_pvt->nh) { goto done; } - } - - if (tech_pvt) { + if ((status > 100 || switch_channel_test_flag(channel, CF_ANSWERED)) && status < 300 && !r_sdp && tech_pvt->mparams.last_sdp_str) { r_sdp = tech_pvt->mparams.last_sdp_str; } tech_pvt->mparams.last_sdp_str = NULL; - } - - if (r_sdp && (switch_channel_test_flag(channel, CF_PROXY_MODE) || switch_channel_test_flag(channel, CF_PROXY_MEDIA))) { - const char *var; - - if ((var = switch_channel_get_variable(channel, "bypass_media_sdp_filter"))) { - if ((patched_sdp = switch_core_media_process_sdp_filter(r_sdp, var, session))) { - r_sdp = patched_sdp; + + + if (r_sdp && (switch_channel_test_flag(channel, CF_PROXY_MODE) || switch_channel_test_flag(channel, CF_PROXY_MEDIA))) { + const char *var; + + if ((var = switch_channel_get_variable(channel, "bypass_media_sdp_filter"))) { + if ((patched_sdp = switch_core_media_process_sdp_filter(r_sdp, var, session))) { + r_sdp = patched_sdp; + } } } - } - if ((channel && (switch_channel_test_flag(channel, CF_PROXY_MODE) || switch_channel_test_flag(channel, CF_PROXY_MEDIA))) || - (sofia_test_flag(profile, TFLAG_INB_NOMEDIA) || sofia_test_flag(profile, TFLAG_PROXY_MEDIA))) { - - /* This marr in our code brought to you by people who can't read........ */ - if (profile->ndlb & SM_NDLB_ALLOW_BAD_IANANAME && r_sdp && (p = (char *) switch_stristr("g729a/8000", r_sdp))) { - p += 4; - *p++ = '/'; - *p++ = '8'; - *p++ = '0'; - *p++ = '0'; - *p++ = '0'; - *p++ = ' '; + if ((switch_channel_test_flag(channel, CF_PROXY_MODE) || switch_channel_test_flag(channel, CF_PROXY_MEDIA)) || + (sofia_test_flag(profile, TFLAG_INB_NOMEDIA) || sofia_test_flag(profile, TFLAG_PROXY_MEDIA))) { + + /* This marr in our code brought to you by people who can't read........ */ + if (profile->ndlb & SM_NDLB_ALLOW_BAD_IANANAME && r_sdp && (p = (char *) switch_stristr("g729a/8000", r_sdp))) { + p += 4; + *p++ = '/'; + *p++ = '8'; + *p++ = '0'; + *p++ = '0'; + *p++ = '0'; + *p++ = ' '; + } } } diff --git a/src/switch_core_media.c b/src/switch_core_media.c index 730799a5dd..852cdfc4bc 100644 --- a/src/switch_core_media.c +++ b/src/switch_core_media.c @@ -8966,7 +8966,7 @@ SWITCH_DECLARE(char *) switch_core_media_filter_sdp(const char *sdp_str, const c } - len = strlen(sdp_str); + len = strlen(sdp_str) + 1; new_sdp = malloc(len); o = new_sdp; i = sdp_str; @@ -9095,7 +9095,6 @@ SWITCH_DECLARE(char *) switch_core_media_process_sdp_filter(const char *sdp, con int argc = 0; char *argv[50]; int x = 0; - char *use_sdp = (char *) sdp; char *patched_sdp = NULL; argc = switch_split(cmd, '|', argv); @@ -9118,19 +9117,19 @@ SWITCH_DECLARE(char *) switch_core_media_process_sdp_filter(const char *sdp, con if (patched_sdp) { tmp_sdp = switch_core_media_filter_sdp(patched_sdp, command, arg); } else { - tmp_sdp = switch_core_media_filter_sdp(use_sdp, command, arg); + tmp_sdp = switch_core_media_filter_sdp(sdp, command, arg); } switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG, "%s Filter command %s(%s)\nFROM:\n==========\n%s\nTO:\n==========\n%s\n\n", switch_channel_get_name(channel), - command, arg, patched_sdp ? patched_sdp : use_sdp, tmp_sdp); - + command, arg, patched_sdp ? patched_sdp : sdp, tmp_sdp); + if (tmp_sdp) { switch_safe_free(patched_sdp); - patched_sdp = use_sdp = tmp_sdp; + patched_sdp = tmp_sdp; } } }