[Asterisk-code-review] res/res_pjsip_messaging.c: Fix: unstable domain filed in To header (asterisk[18])

Yang Chen asteriskteam at digium.com
Wed Apr 7 05:10:14 CDT 2021


Yang Chen has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/15727 )


Change subject: res/res_pjsip_messaging.c: Fix: unstable domain filed in To header
......................................................................

res/res_pjsip_messaging.c: Fix: unstable domain filed in To header

This issue happens when client IP address changed like from wifi to 4G.
The domain filed in To header should be a fix string, this patch provide
a method of rewriting to a predefined domian string.

Usage: append ';x-to_domain=mydomain.com' to the end of full uri
which usually retrieved from ${PJSIP_DIAL_CONTACTS(${EXTEN})}
e.g.:
same => n,Set(ToContacts=${PJSIP_DIAL_CONTACTS(${EXTEN})})
same => n,While($["${SET(ToContact=${SHIFT(ToContacts,&):6})}" != ""])
same => n,Set(TOURI=pjsip:${ToContact}\;x-to_domain=mydomain.com)
same => n,MessageSend(${TOURI},${MESSAGE(from)})

ASTERISK-28928
ASTERISK-28513
Reported-by: Yang Chen <yang.chen at linuxe.org>
Reported-by: Brian J. Murrell <brian at interlinx.bc.ca>

Change-Id: Ib164d5274ffe73db15811d4decfc50e6eddcf80c
Signed-off-by: Yang Chen <yang.chen at linuxe.org>
---
M res/res_pjsip_messaging.c
1 file changed, 24 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/27/15727/1

diff --git a/res/res_pjsip_messaging.c b/res/res_pjsip_messaging.c
index 5378b8c..c240150 100644
--- a/res/res_pjsip_messaging.c
+++ b/res/res_pjsip_messaging.c
@@ -227,6 +227,9 @@
 static void update_to(pjsip_tx_data *tdata, char *to)
 {
 	pjsip_name_addr *parsed_name_addr;
+	pjsip_sip_uri *uri;
+	char *domain_start, *domain_end, *tmp_ptr;
+	int domain_len;
 
 	parsed_name_addr = (pjsip_name_addr *) pjsip_parse_uri(tdata->pool, to, strlen(to),
 		PJSIP_PARSE_URI_AS_NAMEADDR);
@@ -238,6 +241,27 @@
 			pj_strdup(tdata->pool, &name_addr->display, &parsed_name_addr->display);
 		}
 	}
+
+	/* Usage: append ';x-to_domain=mydomain.com' to the end of full uri,
+	 * which usually retrieved from ${PJSIP_DIAL_CONTACTS(${EXTEN})}
+	 * e.g.: pjsip:endpoint/sip:user at ip;transport=udp;x-to_domain=domain.com
+	 * */
+	domain_start = strstr(to, "x-to_domain");
+	if(domain_start) {
+		domain_start += 12; /* 12 is sizeof("x-to_domain") */
+		uri = pjsip_uri_get_uri((pjsip_name_addr *) PJSIP_MSG_TO_HDR(tdata->msg)->uri);
+		domain_end = strchr(domain_start, ';');
+		if(domain_end){
+			domain_len = domain_end - domain_start;
+			tmp_ptr = (char *)ast_malloc(domain_len + 1);
+			strncpy(tmp_ptr, domain_start, domain_len);
+			tmp_ptr[domain_len + 1]= '\0';
+			pj_strdup2(tdata->pool, &uri->host, tmp_ptr);
+			ast_free(tmp_ptr);
+		} else {
+			pj_strdup2(tdata->pool, &uri->host, domain_start);
+		}
+	}
 }
 
 /*!

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

Gerrit-Project: asterisk
Gerrit-Branch: 18
Gerrit-Change-Id: Ib164d5274ffe73db15811d4decfc50e6eddcf80c
Gerrit-Change-Number: 15727
Gerrit-PatchSet: 1
Gerrit-Owner: Yang Chen <yang.chen at linuxe.org>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210407/b2102f1c/attachment.html>


More information about the asterisk-code-review mailing list