[Asterisk-code-review] res_pjsip: Make message_filter and session multipart aware (asterisk[19])

George Joseph asteriskteam at digium.com
Mon Jan 17 06:36:53 CST 2022


George Joseph has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/17871 )


Change subject: res_pjsip: Make message_filter and session multipart aware
......................................................................

res_pjsip: Make message_filter and session multipart aware

Neither pjsip_message_filter's filter_on_tx_message() nor
res_pjsip_session's session_outgoing_nat_hook() were multipart
aware and just assumed that an SDP would be the only thing in
a message body.  Both were changed to use the new
pjsip_get_sdp_info() function which searches for an sdp in
both single- and multi- part message bodies.

ASTERISK-29813

Change-Id: I8f5b8cfdc27f1d4bd3e7491ea9090951a4525c56
---
M res/res_pjsip/pjsip_message_filter.c
M res/res_pjsip_session.c
2 files changed, 31 insertions(+), 10 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/71/17871/1

diff --git a/res/res_pjsip/pjsip_message_filter.c b/res/res_pjsip/pjsip_message_filter.c
index 23369dc..edac55f 100644
--- a/res/res_pjsip/pjsip_message_filter.c
+++ b/res/res_pjsip/pjsip_message_filter.c
@@ -231,6 +231,8 @@
 	pjsip_via_hdr *via;
 	pjsip_fromto_hdr *from;
 	pjsip_tpselector sel;
+	pjsip_sdp_info *sdp_info;
+	pjmedia_sdp_session *sdp;
 
 	sanitize_tdata(tdata);
 
@@ -326,10 +328,23 @@
 		}
 	}
 
-	/* Update the SDP if it is present */
-	if (tdata->msg->body && ast_sip_is_content_type(&tdata->msg->body->content_type, "application", "sdp") &&
-		multihomed_rewrite_sdp(tdata->msg->body->data)) {
-		struct pjmedia_sdp_session *sdp = tdata->msg->body->data;
+	/* If there's no body in the tdata we can just return here. */
+	if (!tdata->msg->body) {
+		return PJ_SUCCESS;
+	}
+
+	/*
+	 * pjsip_get_sdp_info will search for an SDP even if it's in
+	 * a multipart message body.
+	 */
+	sdp_info = pjsip_get_sdp_info(tdata->pool, tdata->msg->body, NULL, &pjsip_media_type_application_sdp);
+	if (sdp_info->sdp_err != PJ_SUCCESS || !sdp_info->sdp) {
+		return PJ_SUCCESS;
+	}
+
+	sdp = sdp_info->sdp;
+
+	if (multihomed_rewrite_sdp(sdp)) {
 		static const pj_str_t STR_IP4 = { "IP4", 3 };
 		static const pj_str_t STR_IP6 = { "IP6", 3 };
 		pj_str_t STR_IP;
diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c
index cfd71fb..d4a857f 100644
--- a/res/res_pjsip_session.c
+++ b/res/res_pjsip_session.c
@@ -5480,19 +5480,25 @@
 	RAII_VAR(struct ast_sip_transport_state *, transport_state, ast_sip_get_transport_state(ast_sorcery_object_get_id(transport)), ao2_cleanup);
 	struct ast_sip_nat_hook *hook = ast_sip_mod_data_get(
 		tdata->mod_data, session_module.id, MOD_DATA_NAT_HOOK);
-	struct pjmedia_sdp_session *sdp;
+	pjsip_sdp_info *sdp_info;
+	pjmedia_sdp_session *sdp;
 	pjsip_dialog *dlg = pjsip_tdata_get_dlg(tdata);
 	RAII_VAR(struct ast_sip_session *, session, dlg ? ast_sip_dialog_get_session(dlg) : NULL, ao2_cleanup);
 	int stream;
 
-	/* SDP produced by us directly will never be multipart */
-	if (!transport_state || hook || !tdata->msg->body ||
-		!ast_sip_are_media_types_equal(&tdata->msg->body->content_type, &pjsip_media_type_application_sdp) ||
-		ast_strlen_zero(transport->external_media_address)) {
+	/*
+	 * If there's no transport_state or body, or the hook
+	 * has already been run, just return.
+	 */
+	if (ast_strlen_zero(transport->external_media_address) || !transport_state || hook || !tdata->msg->body) {
 		return;
 	}
 
-	sdp = tdata->msg->body->data;
+	sdp_info = pjsip_get_sdp_info(tdata->pool, tdata->msg->body, NULL, &pjsip_media_type_application_sdp);
+	if (sdp_info->sdp_err != PJ_SUCCESS || !sdp_info->sdp) {
+		return;
+	}
+	sdp = sdp_info->sdp;
 
 	if (sdp->conn) {
 		char host[NI_MAXHOST];

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

Gerrit-Project: asterisk
Gerrit-Branch: 19
Gerrit-Change-Id: I8f5b8cfdc27f1d4bd3e7491ea9090951a4525c56
Gerrit-Change-Number: 17871
Gerrit-PatchSet: 1
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220117/e901167f/attachment-0001.html>


More information about the asterisk-code-review mailing list