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

Friendly Automation asteriskteam at digium.com
Mon Jan 17 12:10:37 CST 2022


Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/17797 )

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(-)

Approvals:
  George Joseph: Looks good to me, approved; Verified
  Friendly Automation: Approved for Submit



diff --git a/res/res_pjsip/pjsip_message_filter.c b/res/res_pjsip/pjsip_message_filter.c
index 2e3efcd..ceb8913 100644
--- a/res/res_pjsip/pjsip_message_filter.c
+++ b/res/res_pjsip/pjsip_message_filter.c
@@ -230,6 +230,8 @@
 	pjsip_via_hdr *via;
 	pjsip_fromto_hdr *from;
 	pjsip_tpselector sel;
+	pjsip_sdp_info *sdp_info;
+	pjmedia_sdp_session *sdp;
 
 	sanitize_tdata(tdata);
 
@@ -325,10 +327,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 0306886..3c55af7 100644
--- a/res/res_pjsip_session.c
+++ b/res/res_pjsip_session.c
@@ -5418,19 +5418,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/+/17797
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: I8f5b8cfdc27f1d4bd3e7491ea9090951a4525c56
Gerrit-Change-Number: 17797
Gerrit-PatchSet: 5
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Michael Bradeen <mbradeen at sangoma.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220117/2537504d/attachment.html>


More information about the asterisk-code-review mailing list