<p>George Joseph <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/16068">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Joshua Colp: Looks good to me, but someone else must approve
  Kevin Harwell: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved; Approved for Submit

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip_messaging: Overwrite user in existing contact URI<br><br>When the MessageSend destination is in the form<br>PJSIP/<number>@<endpoint> and the endpoint's contact<br>URI already has a user component, that user component<br>will now be replaced with <number> when creating the<br>request URI.<br><br>ASTERISK_29404<br><br>Change-Id: I80e5910fa25c803d1440da0594a0d6b34b6b4ad5<br>---<br>M res/res_pjsip_messaging.c<br>1 file changed, 26 insertions(+), 26 deletions(-)<br><br></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 d895945..c69601c 100644</span><br><span>--- a/res/res_pjsip_messaging.c</span><br><span>+++ b/res/res_pjsip_messaging.c</span><br><span>@@ -93,7 +93,7 @@</span><br><span>           <literal>pjsip:PJSIP/8005551212@myprovider</literal>.</span><br><span>            The endpoint contact's URI will have the <literal>user</literal> inserted</span><br><span>            into it and will become the Request URI.  If the contact URI already has</span><br><span style="color: hsl(0, 100%, 40%);">-                a user specified, an error is returned.</span><br><span style="color: hsl(120, 100%, 40%);">+               a user specified, it will be replaced.</span><br><span>               </para></span><br><span>                <para></span><br><span>                 </para></span><br><span>@@ -208,15 +208,14 @@</span><br><span>  * \return -1 Fail</span><br><span>  *</span><br><span>  * \note If the contact URI found for the endpoint already has a user in</span><br><span style="color: hsl(0, 100%, 40%);">- * its URI, replacing it is probably not a good idea so an error is returned.</span><br><span style="color: hsl(120, 100%, 40%);">+ * its URI, it will be replaced.</span><br><span>  */</span><br><span> static int insert_user_in_contact_uri(const char *to, const char *endpoint_name, const char *aors,</span><br><span>    const char *user, char **uri)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">-      char *atsign = NULL;</span><br><span>         char *scheme = NULL;</span><br><span>         char *contact_uri = NULL;</span><br><span style="color: hsl(0, 100%, 40%);">-       char *colon = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+   char *after_scheme = NULL;</span><br><span>   char *host;</span><br><span>  struct ast_sip_contact *contact = NULL;</span><br><span> </span><br><span>@@ -238,37 +237,38 @@</span><br><span> </span><br><span>      ast_debug(3, "Dest: '%s' User: '%s'  Endpoint: '%s'  ContactURI: '%s'\n", to, user, endpoint_name, contact_uri);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-  atsign = strchr(contact_uri, '@');</span><br><span style="color: hsl(0, 100%, 40%);">-      if (atsign) {</span><br><span style="color: hsl(0, 100%, 40%);">-           /*</span><br><span style="color: hsl(0, 100%, 40%);">-               * If there is already a username in the contact URI</span><br><span style="color: hsl(0, 100%, 40%);">-             * messing with it is probably NOT a good thing.</span><br><span style="color: hsl(0, 100%, 40%);">-                 */</span><br><span style="color: hsl(0, 100%, 40%);">-             ast_log(LOG_WARNING, "Dest: '%s' MSG SEND FAIL: There's already a username in endpoint %s's contact URI '%s'.\n",</span><br><span style="color: hsl(0, 100%, 40%);">-                     to, endpoint_name, contact_uri);</span><br><span style="color: hsl(0, 100%, 40%);">-                return -1;</span><br><span style="color: hsl(0, 100%, 40%);">-      }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span>    /*</span><br><span>    * Contact URIs must have a scheme so we must insert the user between it and the host.</span><br><span>        */</span><br><span style="color: hsl(0, 100%, 40%);">-     colon = strchr(contact_uri, ':');</span><br><span style="color: hsl(0, 100%, 40%);">-       if (!colon) {</span><br><span style="color: hsl(120, 100%, 40%);">+ scheme = contact_uri;</span><br><span style="color: hsl(120, 100%, 40%);">+ after_scheme = strchr(contact_uri, ':');</span><br><span style="color: hsl(120, 100%, 40%);">+      if (!after_scheme) {</span><br><span>                 /* A contact URI without a scheme?  Something's wrong.  Bail */</span><br><span>          ast_log(LOG_WARNING, "Dest: '%s' MSG SEND FAIL: There was no scheme in the contact URI '%s'\n",</span><br><span>                    to, contact_uri);</span><br><span>            return -1;</span><br><span>   }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-       host = colon + 1;</span><br><span style="color: hsl(0, 100%, 40%);">-       scheme = contact_uri;</span><br><span style="color: hsl(0, 100%, 40%);">-   *uri = ast_malloc(strlen(contact_uri) + strlen(user) + 2 /* One for the @ and one for the NULL */);</span><br><span>  /*</span><br><span style="color: hsl(0, 100%, 40%);">-       * Need to set the NULL after the malloc or the length of contact_uri will be too short</span><br><span style="color: hsl(0, 100%, 40%);">-  * to hold the final result.</span><br><span style="color: hsl(120, 100%, 40%);">+   * Terminate the scheme.</span><br><span>      */</span><br><span style="color: hsl(0, 100%, 40%);">-     *colon = '\0';</span><br><span style="color: hsl(0, 100%, 40%);">-  sprintf(*uri, "%s:%s@%s", scheme, user, host);</span><br><span style="color: hsl(120, 100%, 40%);">+      *after_scheme = '\0';</span><br><span style="color: hsl(120, 100%, 40%);">+ after_scheme++;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     /*</span><br><span style="color: hsl(120, 100%, 40%);">+     * If the contact_uri already has a user, the host starts after the '@', otherwise</span><br><span style="color: hsl(120, 100%, 40%);">+     * the host is at after_scheme.</span><br><span style="color: hsl(120, 100%, 40%);">+        *</span><br><span style="color: hsl(120, 100%, 40%);">+     * We're going to ignore the existing user.</span><br><span style="color: hsl(120, 100%, 40%);">+        */</span><br><span style="color: hsl(120, 100%, 40%);">+   host = strchr(after_scheme, '@');</span><br><span style="color: hsl(120, 100%, 40%);">+     if (host) {</span><br><span style="color: hsl(120, 100%, 40%);">+           host++;</span><br><span style="color: hsl(120, 100%, 40%);">+       } else {</span><br><span style="color: hsl(120, 100%, 40%);">+              host = after_scheme;</span><br><span style="color: hsl(120, 100%, 40%);">+  }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   *uri = ast_malloc(strlen(scheme) + strlen(user) + strlen(host) + 3 /* One for the ':', '@' and terminating NULL */);</span><br><span style="color: hsl(120, 100%, 40%);">+  sprintf(*uri, "%s:%s@%s", scheme, user, host); /* Safe */</span><br><span> </span><br><span>      return 0;</span><br><span> }</span><br><span>@@ -594,7 +594,7 @@</span><br><span>  *   This form is similar to a dialstring:</span><br><span>  *      PJSIP/user@endpoint</span><br><span>  *   In this case, the user will be added to the endpoint contact's URI.</span><br><span style="color: hsl(0, 100%, 40%);">- *   If the contact URI already has a user, an error is returned.</span><br><span style="color: hsl(120, 100%, 40%);">+ *   If the contact URI already has a user, it will be replaced.</span><br><span>  *</span><br><span>  * The ones that have the sip[s] scheme are the easiest to parse.</span><br><span>  * The rest all have some issue.</span><br><span></span><br></pre><div style="white-space:pre-wrap"></div><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/16068">change 16068</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/+/16068"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-Change-Id: I80e5910fa25c803d1440da0594a0d6b34b6b4ad5 </div>
<div style="display:none"> Gerrit-Change-Number: 16068 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>