<p>Friendly Automation <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/13982">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Joshua Colp: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved
Friendly Automation: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip_session: implement processing of Content-Disposition<br><br>RFC5621 requires any content type with a Content-Disposition<br>with handling=required to be rejected with a 415 response<br><br>ASTERISK-28782 #close<br><br>Change-Id: Iad969df75936730254b95c1a8bc3b48497070bb4<br>---<br>M res/res_pjsip_session.c<br>1 file changed, 65 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c</span><br><span>index f511c01..83ba6f5 100644</span><br><span>--- a/res/res_pjsip_session.c</span><br><span>+++ b/res/res_pjsip_session.c</span><br><span>@@ -3111,6 +3111,62 @@</span><br><span> pjsip_rx_data *rdata;</span><br><span> };</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static int check_sdp_content_type_supported(pjsip_media_type *content_type)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_media_type app_sdp;</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_media_type_init2(&app_sdp, "application", "sdp");</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!pjsip_media_type_cmp(content_type, &app_sdp, 0)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return 1;</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%);">+ return 0;</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%);">+static int check_content_disposition_in_multipart(pjsip_multipart_part *part)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_hdr *hdr = part->hdr.next;</span><br><span style="color: hsl(120, 100%, 40%);">+ static const pj_str_t str_handling_required = {"handling=required", 16};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ while (hdr != &part->hdr) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (hdr->type == PJSIP_H_OTHER) {</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_generic_string_hdr *generic_hdr = (pjsip_generic_string_hdr*)hdr;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!pj_stricmp2(&hdr->name, "Content-Disposition") &&</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_stristr(&generic_hdr->hvalue, &str_handling_required) &&</span><br><span style="color: hsl(120, 100%, 40%);">+ !check_sdp_content_type_supported(&part->body->content_type)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return 1;</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%);">+ hdr = hdr->next;</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%);">+ return 0;</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%);">+ * if there is required media we don't understand, return 1</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+static int check_content_disposition(pjsip_rx_data *rdata)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_msg_body *body = rdata->msg_info.msg->body;</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_ctype_hdr *ctype_hdr = rdata->msg_info.ctype;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (body && ctype_hdr &&</span><br><span style="color: hsl(120, 100%, 40%);">+ !pj_stricmp2(&ctype_hdr->media.type, "multipart") &&</span><br><span style="color: hsl(120, 100%, 40%);">+ (!pj_stricmp2(&ctype_hdr->media.subtype, "mixed") ||</span><br><span style="color: hsl(120, 100%, 40%);">+ !pj_stricmp2(&ctype_hdr->media.subtype, "alternative"))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_multipart_part *part = pjsip_multipart_get_first_part(body);</span><br><span style="color: hsl(120, 100%, 40%);">+ while (part != NULL) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (check_content_disposition_in_multipart(part)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ part = pjsip_multipart_get_next_part(body, part);</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%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static int new_invite(struct new_invite *invite)</span><br><span> {</span><br><span> pjsip_tx_data *tdata = NULL;</span><br><span>@@ -3174,6 +3230,15 @@</span><br><span> goto end;</span><br><span> };</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ if (check_content_disposition(invite->rdata)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (pjsip_inv_initial_answer(invite->session->inv_session, invite->rdata, 415, NULL, NULL, &tdata) == PJ_SUCCESS) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sip_session_send_response(invite->session, tdata);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_inv_terminate(invite->session->inv_session, 415, PJ_TRUE);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ goto end;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> pjsip_timer_setting_default(&timer);</span><br><span> timer.min_se = invite->session->endpoint->extensions.timer.min_se;</span><br><span> timer.sess_expires = invite->session->endpoint->extensions.timer.sess_expires;</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/13982">change 13982</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/+/13982"/><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: Iad969df75936730254b95c1a8bc3b48497070bb4 </div>
<div style="display:none"> Gerrit-Change-Number: 13982 </div>
<div style="display:none"> Gerrit-PatchSet: 4 </div>
<div style="display:none"> Gerrit-Owner: Torrey Searle <tsearle@gmail.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-MessageType: merged </div>