[Asterisk-code-review] res_pjsip_session: implement processing of Content-Disposition (asterisk[13])

Torrey Searle asteriskteam at digium.com
Thu Mar 19 04:36:01 CDT 2020


Torrey Searle has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/13952 )


Change subject: res_pjsip_session: implement processing of Content-Disposition
......................................................................

res_pjsip_session: implement processing of Content-Disposition

RFC5261 requires any content type with a Content-Disposition
with handling=required to be rejected with a 415 response

ASTERISK-28782 #close

Change-Id: Iad969df75936730254b95c1a8bc3b48497070bb4
---
M res/res_pjsip_session.c
1 file changed, 62 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/52/13952/1

diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c
index b61b0fd..420c36c 100644
--- a/res/res_pjsip_session.c
+++ b/res/res_pjsip_session.c
@@ -2135,6 +2135,59 @@
 	pjsip_rx_data *rdata;
 };
 
+static int check_content_type_supported(pjsip_media_type *content_type) {
+	pjsip_media_type app_sdp;
+	pjsip_media_type_init2(&app_sdp, "application", "sdp");
+
+	if (!pjsip_media_type_cmp(content_type, &app_sdp, 0)) {
+		return 1;
+	}
+
+	return 0;
+}
+
+static int check_content_disposition_in_multipart(pjsip_multipart_part *part) {
+	pjsip_hdr * hdr = part->hdr.next;
+	while (hdr != &part->hdr) {
+		if (hdr->type == PJSIP_H_OTHER) {
+			pjsip_generic_string_hdr *generic_hdr = (pjsip_generic_string_hdr*) hdr;
+			if (pj_stricmp2(&hdr->name, "Content-Disposition")==0) {
+				pj_str_t substr = pj_str("handling=required");
+				if (pj_stristr(&generic_hdr->hvalue, &substr)) {
+					if(!check_content_type_supported(&part->body->content_type)) {
+						return 1;
+					}
+				}
+			}
+		}
+		hdr = hdr->next;
+	}
+	return 0;
+}
+
+/**
+ * if there is required media we don't understand, return 1
+ */
+static int check_content_disposition(pjsip_rx_data *rdata) {
+	pjsip_msg_body *body = rdata->msg_info.msg->body;
+	pjsip_ctype_hdr *ctype_hdr = rdata->msg_info.ctype;
+
+	if (body && ctype_hdr &&
+		pj_stricmp2(&ctype_hdr->media.type, "multipart")==0 &&
+		(pj_stricmp2(&ctype_hdr->media.subtype, "mixed")==0 ||
+		 pj_stricmp2(&ctype_hdr->media.subtype, "alternative")==0))
+	{
+		pjsip_multipart_part *part = pjsip_multipart_get_first_part(body);
+		while (part != NULL) {
+			if(check_content_disposition_in_multipart(part)) {
+				return 1;
+			}
+			part = pjsip_multipart_get_next_part(body,part);
+		}
+	}
+	return 0;
+}
+
 static int new_invite(struct new_invite *invite)
 {
 	pjsip_tx_data *tdata = NULL;
@@ -2198,6 +2251,15 @@
 		goto end;
 	};
 
+	if (check_content_disposition(invite->rdata)) {
+		if (pjsip_inv_initial_answer(invite->session->inv_session, invite->rdata, 415, NULL, NULL, &tdata) == PJ_SUCCESS) {
+			ast_sip_session_send_response(invite->session, tdata);
+		} else  {
+			pjsip_inv_terminate(invite->session->inv_session, 415, PJ_TRUE);
+		}
+		goto end;
+	}
+
 	pjsip_timer_setting_default(&timer);
 	timer.min_se = invite->session->endpoint->extensions.timer.min_se;
 	timer.sess_expires = invite->session->endpoint->extensions.timer.sess_expires;

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/13952
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Change-Id: Iad969df75936730254b95c1a8bc3b48497070bb4
Gerrit-Change-Number: 13952
Gerrit-PatchSet: 1
Gerrit-Owner: Torrey Searle <tsearle at gmail.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200319/2b75eae1/attachment.html>


More information about the asterisk-code-review mailing list