<p>Yang Chen has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/15727">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res/res_pjsip_messaging.c: Fix: unstable domain filed in To header<br><br>This issue happens when client IP address changed like from wifi to 4G.<br>The domain filed in To header should be a fix string, this patch provide<br>a method of rewriting to a predefined domian string.<br><br>Usage: append ';x-to_domain=mydomain.com' to the end of full uri<br>which usually retrieved from ${PJSIP_DIAL_CONTACTS(${EXTEN})}<br>e.g.:<br>same => n,Set(ToContacts=${PJSIP_DIAL_CONTACTS(${EXTEN})})<br>same => n,While($["${SET(ToContact=${SHIFT(ToContacts,&):6})}" != ""])<br>same => n,Set(TOURI=pjsip:${ToContact}\;x-to_domain=mydomain.com)<br>same => n,MessageSend(${TOURI},${MESSAGE(from)})<br><br>ASTERISK-28928<br>ASTERISK-28513<br>Reported-by: Yang Chen <yang.chen@linuxe.org><br>Reported-by: Brian J. Murrell <brian@interlinx.bc.ca><br><br>Change-Id: Ib164d5274ffe73db15811d4decfc50e6eddcf80c<br>Signed-off-by: Yang Chen <yang.chen@linuxe.org><br>---<br>M res/res_pjsip_messaging.c<br>1 file changed, 24 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/27/15727/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/res/res_pjsip_messaging.c b/res/res_pjsip_messaging.c</span><br><span>index 5378b8c..c240150 100644</span><br><span>--- a/res/res_pjsip_messaging.c</span><br><span>+++ b/res/res_pjsip_messaging.c</span><br><span>@@ -227,6 +227,9 @@</span><br><span> static void update_to(pjsip_tx_data *tdata, char *to)</span><br><span> {</span><br><span> pjsip_name_addr *parsed_name_addr;</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_sip_uri *uri;</span><br><span style="color: hsl(120, 100%, 40%);">+ char *domain_start, *domain_end, *tmp_ptr;</span><br><span style="color: hsl(120, 100%, 40%);">+ int domain_len;</span><br><span> </span><br><span> parsed_name_addr = (pjsip_name_addr *) pjsip_parse_uri(tdata->pool, to, strlen(to),</span><br><span> PJSIP_PARSE_URI_AS_NAMEADDR);</span><br><span>@@ -238,6 +241,27 @@</span><br><span> pj_strdup(tdata->pool, &name_addr->display, &parsed_name_addr->display);</span><br><span> }</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Usage: append ';x-to_domain=mydomain.com' to the end of full uri,</span><br><span style="color: hsl(120, 100%, 40%);">+ * which usually retrieved from ${PJSIP_DIAL_CONTACTS(${EXTEN})}</span><br><span style="color: hsl(120, 100%, 40%);">+ * e.g.: pjsip:endpoint/sip:user@ip;transport=udp;x-to_domain=domain.com</span><br><span style="color: hsl(120, 100%, 40%);">+ * */</span><br><span style="color: hsl(120, 100%, 40%);">+ domain_start = strstr(to, "x-to_domain");</span><br><span style="color: hsl(120, 100%, 40%);">+ if(domain_start) {</span><br><span style="color: hsl(120, 100%, 40%);">+ domain_start += 12; /* 12 is sizeof("x-to_domain") */</span><br><span style="color: hsl(120, 100%, 40%);">+ uri = pjsip_uri_get_uri((pjsip_name_addr *) PJSIP_MSG_TO_HDR(tdata->msg)->uri);</span><br><span style="color: hsl(120, 100%, 40%);">+ domain_end = strchr(domain_start, ';');</span><br><span style="color: hsl(120, 100%, 40%);">+ if(domain_end){</span><br><span style="color: hsl(120, 100%, 40%);">+ domain_len = domain_end - domain_start;</span><br><span style="color: hsl(120, 100%, 40%);">+ tmp_ptr = (char *)ast_malloc(domain_len + 1);</span><br><span style="color: hsl(120, 100%, 40%);">+ strncpy(tmp_ptr, domain_start, domain_len);</span><br><span style="color: hsl(120, 100%, 40%);">+ tmp_ptr[domain_len + 1]= '\0';</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_strdup2(tdata->pool, &uri->host, tmp_ptr);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(tmp_ptr);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_strdup2(tdata->pool, &uri->host, domain_start);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> }</span><br><span> </span><br><span> /*!</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/15727">change 15727</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/15727"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 18 </div>
<div style="display:none"> Gerrit-Change-Id: Ib164d5274ffe73db15811d4decfc50e6eddcf80c </div>
<div style="display:none"> Gerrit-Change-Number: 15727 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Yang Chen <yang.chen@linuxe.org> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>