[Asterisk-code-review] res_pjsip_nat.c: remove x-ast-orig-host from request URI and To header (asterisk[16])

nappsoft asteriskteam at digium.com
Wed May 13 07:10:54 CDT 2020


nappsoft has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/14406 )


Change subject: res_pjsip_nat.c: remove x-ast-orig-host from request URI and To header
......................................................................

res_pjsip_nat.c: remove x-ast-orig-host from request URI and To header

While asterisk is filtering out the x-ast-orig-host parameter from the
contact on response messages, it is not filtering it out from the
request URI and the to header on SIP requests (for example INVITE).

ASTERISK-28884 #close

Change-Id: Id032b33098a1befea9b243ca994184baecccc59e
---
M res/res_pjsip_nat.c
1 file changed, 27 insertions(+), 2 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/06/14406/1

diff --git a/res/res_pjsip_nat.c b/res/res_pjsip_nat.c
index 01ce139..9dab32a 100644
--- a/res/res_pjsip_nat.c
+++ b/res/res_pjsip_nat.c
@@ -37,6 +37,9 @@
 #define AST_SIP_X_AST_ORIG_HOST "x-ast-orig-host"
 #define AST_SIP_X_AST_ORIG_HOST_LEN 15
 
+#define is_sip_uri(uri) \
+	(PJSIP_URI_SCHEME_IS_SIP(uri) || PJSIP_URI_SCHEME_IS_SIPS(uri))
+
 static void save_orig_contact_host(pjsip_rx_data *rdata, pjsip_sip_uri *uri)
 {
 	pjsip_param *x_orig_host;
@@ -303,6 +306,29 @@
 static void restore_orig_contact_host(pjsip_tx_data *tdata)
 {
 	pjsip_contact_hdr *contact;
+	pj_str_t x_name = { AST_SIP_X_AST_ORIG_HOST, AST_SIP_X_AST_ORIG_HOST_LEN };
+	pjsip_param *x_orig_host;
+	pjsip_sip_uri *uri;
+	pjsip_hdr *hdr;
+
+	if (tdata->msg->type == PJSIP_REQUEST_MSG) {
+		if (is_sip_uri(tdata->msg->line.req.uri)) {
+			uri = pjsip_uri_get_uri(tdata->msg->line.req.uri);
+			while ((x_orig_host = pjsip_param_find(&uri->other_param, &x_name))) {
+				pj_list_erase(x_orig_host);
+			}
+		}
+		for (hdr = tdata->msg->hdr.next; hdr != &tdata->msg->hdr; hdr = hdr->next) {
+			if (hdr->type == PJSIP_H_TO) {
+				if (is_sip_uri(((pjsip_fromto_hdr *) hdr)->uri)) {
+					uri = pjsip_uri_get_uri(((pjsip_fromto_hdr *) hdr)->uri);
+					while ((x_orig_host = pjsip_param_find(&uri->other_param, &x_name))) {
+						pj_list_erase(x_orig_host);
+					}
+				}
+			}
+		}
+	}
 
 	if (tdata->msg->type != PJSIP_RESPONSE_MSG) {
 		return;
@@ -311,8 +337,7 @@
 	contact = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CONTACT, NULL);
 	while (contact) {
 		pjsip_sip_uri *contact_uri = pjsip_uri_get_uri(contact->uri);
-		pj_str_t x_name = { AST_SIP_X_AST_ORIG_HOST, AST_SIP_X_AST_ORIG_HOST_LEN };
-		pjsip_param *x_orig_host = pjsip_param_find(&contact_uri->other_param, &x_name);
+		x_orig_host = pjsip_param_find(&contact_uri->other_param, &x_name);
 
 		if (x_orig_host) {
 			char host_port[x_orig_host->value.slen + 1];

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

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: Id032b33098a1befea9b243ca994184baecccc59e
Gerrit-Change-Number: 14406
Gerrit-PatchSet: 1
Gerrit-Owner: nappsoft <infos at nappsoft.ch>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200513/f2f94ca1/attachment.html>


More information about the asterisk-code-review mailing list