From 789e1481edcc7842ce9efaa651813df4101fdbfe Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 1 Oct 2014 13:03:50 -0500 Subject: [PATCH] FS-6880 #resolve #comment I would think that in real life once the call agreed on a codec it would only offer the negotiated codecs but we can fix this to always filter for good measure. I am not sure what the ramifications are of filtering responses but I think this patch will do so as well. --- src/include/switch_core_media.h | 2 +- src/mod/endpoints/mod_sofia/sofia.c | 12 +++++++ src/switch_channel.c | 46 +++------------------------ src/switch_core_media.c | 49 +++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 42 deletions(-) diff --git a/src/include/switch_core_media.h b/src/include/switch_core_media.h index e956905e60..2256814d01 100644 --- a/src/include/switch_core_media.h +++ b/src/include/switch_core_media.h @@ -276,7 +276,7 @@ SWITCH_DECLARE(switch_rtp_crypto_key_type_t) switch_core_media_crypto_str2type(c SWITCH_DECLARE(const char *) switch_core_media_crypto_type2str(switch_rtp_crypto_key_type_t type); SWITCH_DECLARE(int) switch_core_media_crypto_keylen(switch_rtp_crypto_key_type_t type); SWITCH_DECLARE(char *) switch_core_media_filter_sdp(const char *sdp, const char *cmd, const char *arg); - +SWITCH_DECLARE(char *) switch_core_media_process_sdp_filter(const char *sdp, const char *cmd_buf, switch_core_session_t *session); SWITCH_END_EXTERN_C #endif /* For Emacs: diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 5550e78d9e..dcf485de72 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -6348,6 +6348,7 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, int is_dup_sdp = 0; switch_event_t *s_event = NULL; char *p; + char *patched_sdp = NULL; tl_gets(tags, NUTAG_CALLSTATE_REF(ss_state), @@ -6373,6 +6374,16 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, 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 ((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))) { @@ -7319,6 +7330,7 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, done: + switch_safe_free(patched_sdp); if ((enum nua_callstate) ss_state == nua_callstate_ready && channel && session && tech_pvt) { sofia_set_flag(tech_pvt, TFLAG_SIMPLIFY); diff --git a/src/switch_channel.c b/src/switch_channel.c index 0a34ab2a61..eb38298e37 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -5222,57 +5222,21 @@ SWITCH_DECLARE(switch_status_t) switch_channel_unbind_device_state_handler(switc SWITCH_DECLARE(switch_status_t) switch_channel_pass_sdp(switch_channel_t *from_channel, switch_channel_t *to_channel, const char *sdp) { + switch_status_t status = SWITCH_STATUS_FALSE; char *use_sdp = (char *) sdp; char *patched_sdp = NULL; - switch_status_t status = SWITCH_STATUS_FALSE; if (!switch_channel_get_variable(to_channel, SWITCH_B_SDP_VARIABLE)) { const char *var; if ((var = switch_channel_get_variable(from_channel, "bypass_media_sdp_filter"))) { - char *cmd = switch_core_session_strdup(from_channel->session, var); - int argc = 0; - char *argv[50]; - int x = 0; - argc = switch_split(cmd, '|', argv); - - for (x = 0; x < argc; x++) { - char *command = argv[x]; - char *arg = strchr(command, '('); - - if (arg) { - char *e = switch_find_end_paren(arg, '(', ')'); - *arg++ = '\0'; - if (e) *e = '\0'; - } - - if (zstr(command) || zstr(arg)) { - switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(from_channel), SWITCH_LOG_WARNING, "%s SDP FILTER PARSE ERROR\n", from_channel->name); - } else { - char *tmp_sdp = NULL; - - 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); - } - - - switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(from_channel), SWITCH_LOG_DEBUG, - "Filter command %s(%s)\nFROM:\n==========\n%s\nTO:\n==========\n%s\n\n", - command, arg, patched_sdp ? patched_sdp : use_sdp, tmp_sdp); - - - if (tmp_sdp) { - switch_safe_free(patched_sdp); - patched_sdp = use_sdp = tmp_sdp; - } - } + if ((patched_sdp = switch_core_media_process_sdp_filter(use_sdp, var, from_channel->session))) { + use_sdp = patched_sdp; } - } - switch_channel_set_variable(to_channel, SWITCH_B_SDP_VARIABLE, use_sdp); + switch_channel_set_variable(to_channel, SWITCH_B_SDP_VARIABLE, use_sdp); + } } switch_safe_free(patched_sdp); diff --git a/src/switch_core_media.c b/src/switch_core_media.c index e4e810b6dd..ffb54a7448 100644 --- a/src/switch_core_media.c +++ b/src/switch_core_media.c @@ -9067,7 +9067,56 @@ SWITCH_DECLARE(char *) switch_core_media_filter_sdp(const char *sdp_str, const c return new_sdp; } +SWITCH_DECLARE(char *) switch_core_media_process_sdp_filter(const char *sdp, const char *cmd_buf, switch_core_session_t *session) +{ + switch_channel_t *channel = switch_core_session_get_channel(session); + char *cmd = switch_core_session_strdup(session, cmd_buf); + int argc = 0; + char *argv[50]; + int x = 0; + char *use_sdp = (char *) sdp; + char *patched_sdp = NULL; + argc = switch_split(cmd, '|', argv); + + for (x = 0; x < argc; x++) { + char *command = argv[x]; + char *arg = strchr(command, '('); + + if (arg) { + char *e = switch_find_end_paren(arg, '(', ')'); + *arg++ = '\0'; + if (e) *e = '\0'; + } + + if (zstr(command) || zstr(arg)) { + switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_WARNING, "%s SDP FILTER PARSE ERROR\n", switch_channel_get_name(channel)); + } else { + char *tmp_sdp = NULL; + + 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); + } + + + 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); + + + if (tmp_sdp) { + switch_safe_free(patched_sdp); + patched_sdp = use_sdp = tmp_sdp; + } + } + } + + return patched_sdp; + +} /* For Emacs: * Local Variables: