<p>Friendly Automation <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/17797">View Change</a></p><div style="white-space:pre-wrap">Approvals:
George Joseph: Looks good to me, approved; Verified
Friendly Automation: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip: Make message_filter and session multipart aware<br><br>Neither pjsip_message_filter's filter_on_tx_message() nor<br>res_pjsip_session's session_outgoing_nat_hook() were multipart<br>aware and just assumed that an SDP would be the only thing in<br>a message body. Both were changed to use the new<br>pjsip_get_sdp_info() function which searches for an sdp in<br>both single- and multi- part message bodies.<br><br>ASTERISK-29813<br><br>Change-Id: I8f5b8cfdc27f1d4bd3e7491ea9090951a4525c56<br>---<br>M res/res_pjsip/pjsip_message_filter.c<br>M res/res_pjsip_session.c<br>2 files changed, 31 insertions(+), 10 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/res/res_pjsip/pjsip_message_filter.c b/res/res_pjsip/pjsip_message_filter.c</span><br><span>index 2e3efcd..ceb8913 100644</span><br><span>--- a/res/res_pjsip/pjsip_message_filter.c</span><br><span>+++ b/res/res_pjsip/pjsip_message_filter.c</span><br><span>@@ -230,6 +230,8 @@</span><br><span> pjsip_via_hdr *via;</span><br><span> pjsip_fromto_hdr *from;</span><br><span> pjsip_tpselector sel;</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_sdp_info *sdp_info;</span><br><span style="color: hsl(120, 100%, 40%);">+ pjmedia_sdp_session *sdp;</span><br><span> </span><br><span> sanitize_tdata(tdata);</span><br><span> </span><br><span>@@ -325,10 +327,23 @@</span><br><span> }</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- /* Update the SDP if it is present */</span><br><span style="color: hsl(0, 100%, 40%);">- if (tdata->msg->body && ast_sip_is_content_type(&tdata->msg->body->content_type, "application", "sdp") &&</span><br><span style="color: hsl(0, 100%, 40%);">- multihomed_rewrite_sdp(tdata->msg->body->data)) {</span><br><span style="color: hsl(0, 100%, 40%);">- struct pjmedia_sdp_session *sdp = tdata->msg->body->data;</span><br><span style="color: hsl(120, 100%, 40%);">+ /* If there's no body in the tdata we can just return here. */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!tdata->msg->body) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return PJ_SUCCESS;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /*</span><br><span style="color: hsl(120, 100%, 40%);">+ * pjsip_get_sdp_info will search for an SDP even if it's in</span><br><span style="color: hsl(120, 100%, 40%);">+ * a multipart message body.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ sdp_info = pjsip_get_sdp_info(tdata->pool, tdata->msg->body, NULL, &pjsip_media_type_application_sdp);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (sdp_info->sdp_err != PJ_SUCCESS || !sdp_info->sdp) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return PJ_SUCCESS;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ sdp = sdp_info->sdp;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (multihomed_rewrite_sdp(sdp)) {</span><br><span> static const pj_str_t STR_IP4 = { "IP4", 3 };</span><br><span> static const pj_str_t STR_IP6 = { "IP6", 3 };</span><br><span> pj_str_t STR_IP;</span><br><span>diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c</span><br><span>index 0306886..3c55af7 100644</span><br><span>--- a/res/res_pjsip_session.c</span><br><span>+++ b/res/res_pjsip_session.c</span><br><span>@@ -5418,19 +5418,25 @@</span><br><span> RAII_VAR(struct ast_sip_transport_state *, transport_state, ast_sip_get_transport_state(ast_sorcery_object_get_id(transport)), ao2_cleanup);</span><br><span> struct ast_sip_nat_hook *hook = ast_sip_mod_data_get(</span><br><span> tdata->mod_data, session_module.id, MOD_DATA_NAT_HOOK);</span><br><span style="color: hsl(0, 100%, 40%);">- struct pjmedia_sdp_session *sdp;</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_sdp_info *sdp_info;</span><br><span style="color: hsl(120, 100%, 40%);">+ pjmedia_sdp_session *sdp;</span><br><span> pjsip_dialog *dlg = pjsip_tdata_get_dlg(tdata);</span><br><span> RAII_VAR(struct ast_sip_session *, session, dlg ? ast_sip_dialog_get_session(dlg) : NULL, ao2_cleanup);</span><br><span> int stream;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- /* SDP produced by us directly will never be multipart */</span><br><span style="color: hsl(0, 100%, 40%);">- if (!transport_state || hook || !tdata->msg->body ||</span><br><span style="color: hsl(0, 100%, 40%);">- !ast_sip_are_media_types_equal(&tdata->msg->body->content_type, &pjsip_media_type_application_sdp) ||</span><br><span style="color: hsl(0, 100%, 40%);">- ast_strlen_zero(transport->external_media_address)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /*</span><br><span style="color: hsl(120, 100%, 40%);">+ * If there's no transport_state or body, or the hook</span><br><span style="color: hsl(120, 100%, 40%);">+ * has already been run, just return.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_strlen_zero(transport->external_media_address) || !transport_state || hook || !tdata->msg->body) {</span><br><span> return;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- sdp = tdata->msg->body->data;</span><br><span style="color: hsl(120, 100%, 40%);">+ sdp_info = pjsip_get_sdp_info(tdata->pool, tdata->msg->body, NULL, &pjsip_media_type_application_sdp);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (sdp_info->sdp_err != PJ_SUCCESS || !sdp_info->sdp) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ sdp = sdp_info->sdp;</span><br><span> </span><br><span> if (sdp->conn) {</span><br><span> char host[NI_MAXHOST];</span><br><span></span><br></pre><div style="white-space:pre-wrap"></div><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/17797">change 17797</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/17797"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-Change-Id: I8f5b8cfdc27f1d4bd3e7491ea9090951a4525c56 </div>
<div style="display:none"> Gerrit-Change-Number: 17797 </div>
<div style="display:none"> Gerrit-PatchSet: 5 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-Reviewer: Michael Bradeen <mbradeen@sangoma.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>