From 348f009793437f90ba71bc295ce6b1c099964511 Mon Sep 17 00:00:00 2001 From: Jakub Adam Date: Thu, 19 Oct 2017 16:26:48 +0200 Subject: [PATCH] media: fix multpart SDP processing of phone call on SfB User has observed a phone gateway in SfB environment that tags the SDP part of its initial SIP INVITE with "ms-proxy-2007fallback" although it is the only SDP payload in the message and is in RFC 5245 format. Since apparently ms-proxy-2007fallback label can't be relied upon, detect the SDP protocol version from the contents of the message body. --- src/core/sipe-incoming.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/core/sipe-incoming.c b/src/core/sipe-incoming.c index 9feb8019..a16cba78 100644 --- a/src/core/sipe-incoming.c +++ b/src/core/sipe-incoming.c @@ -267,22 +267,27 @@ static gboolean sipe_process_incoming_x_msmsgsinvite(struct sipe_core_private *s static void sipe_invite_mime_cb(gpointer user_data, const GSList *fields, const gchar *body, gsize length) { - const gchar *type = sipe_utils_nameval_find(fields, "Content-Type"); - const gchar *cd = sipe_utils_nameval_find(fields, "Content-Disposition"); - - if (!g_str_has_prefix(type, "application/sdp")) + struct sipmsg *msg = user_data; + const gchar *type; + gchar *body_lcase; + + if (g_str_has_prefix(sipmsg_find_header(msg, "Content-Type"), + "application/sdp")) { + /* We have already found suitable alternative and set message's body + * and Content-Type accordingly. */ return; + } - if (!cd || !strstr(cd, "ms-proxy-2007fallback")) { - struct sipmsg *msg = user_data; - const gchar* msg_ct = sipmsg_find_header(msg, "Content-Type"); + type = sipe_utils_nameval_find(fields, "Content-Type"); - if (g_str_has_prefix(msg_ct, "application/sdp")) { - /* We have already found suitable alternative and set message's body - * and Content-Type accordingly */ - return; - } + if (!body || !g_str_has_prefix(type, "application/sdp")) + return; + + body_lcase = g_ascii_strdown(body, length); + if (strstr(body_lcase, " typ host") || strstr(body_lcase, " typ relay") || + strstr(body_lcase, " typ srflx") || strstr(body_lcase, " typ prflx")) { + /* RFC 5245 SDP body */ sipmsg_remove_header_now(msg, "Content-Type"); sipmsg_add_header_now(msg, "Content-Type", type); @@ -292,6 +297,8 @@ static void sipe_invite_mime_cb(gpointer user_data, const GSList *fields, msg->body = g_strndup(body, length); msg->bodylen = length; } + + g_free(body_lcase); } #endif -- 2.11.4.GIT