<p>N A has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/20056">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">pbx_dundi: Add PJSIP support.<br><br>Adds PJSIP as a supported technology to DUNDi.<br><br>To facilitate this, we now allow an endpoint to be specified<br>for outgoing PJSIP calls. We also allow users to force a specific<br>channel technology for outgoing SIP-protocol calls.<br><br>ASTERISK-28109 #close<br>ASTERISK-28233 #close<br><br>Change-Id: I2e28e5a5d007bd49e3df113ad567b011103899bf<br>---<br>M configs/samples/dundi.conf.sample<br>A doc/CHANGES-staging/dundi.txt<br>M include/asterisk/dundi.h<br>M pbx/dundi-parser.c<br>M pbx/pbx_dundi.c<br>5 files changed, 91 insertions(+), 8 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/56/20056/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/configs/samples/dundi.conf.sample b/configs/samples/dundi.conf.sample</span><br><span>index 3e8da2d..2f28f45 100644</span><br><span>--- a/configs/samples/dundi.conf.sample</span><br><span>+++ b/configs/samples/dundi.conf.sample</span><br><span>@@ -75,6 +75,18 @@</span><br><span> ; off by default due to performance impacts.</span><br><span> ;</span><br><span> ;storehistory=yes</span><br><span style="color: hsl(120, 100%, 40%);">+;</span><br><span style="color: hsl(120, 100%, 40%);">+; Channel technology to use for outgoing calls using SIP (Session Initiation Protocol).</span><br><span style="color: hsl(120, 100%, 40%);">+; Options are 'SIP' for chan_sip and 'PJSIP' for chan_pjsip. Default is 'PJSIP'.</span><br><span style="color: hsl(120, 100%, 40%);">+; If specified, all outgoing SIP calls using DUNDi will use the specified channel tech.</span><br><span style="color: hsl(120, 100%, 40%);">+;</span><br><span style="color: hsl(120, 100%, 40%);">+;outgoing_sip_tech=pjsip</span><br><span style="color: hsl(120, 100%, 40%);">+;</span><br><span style="color: hsl(120, 100%, 40%);">+; Name of endpoint from pjsip.conf to use for outgoing calls from this system,</span><br><span style="color: hsl(120, 100%, 40%);">+; when using the PJSIP technology to complete a call to a SIP-based destination.</span><br><span style="color: hsl(120, 100%, 40%);">+; (Required for PJSIP, since PJSIP calls must specify an endpoint explicitly).</span><br><span style="color: hsl(120, 100%, 40%);">+;</span><br><span style="color: hsl(120, 100%, 40%);">+;pjsip_outgoing_endpoint=outgoing</span><br><span> </span><br><span> [mappings]</span><br><span> ;</span><br><span>diff --git a/doc/CHANGES-staging/dundi.txt b/doc/CHANGES-staging/dundi.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..e71f726</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/dundi.txt</span><br><span>@@ -0,0 +1,5 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: DUNDi</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+DUNDi now supports chan_pjsip. Outgoing calls using</span><br><span style="color: hsl(120, 100%, 40%);">+PJSIP require the pjsip_outgoing_endpoint option</span><br><span style="color: hsl(120, 100%, 40%);">+to be set in dundi.conf.</span><br><span>diff --git a/include/asterisk/dundi.h b/include/asterisk/dundi.h</span><br><span>index 3f73c19..ed12001 100644</span><br><span>--- a/include/asterisk/dundi.h</span><br><span>+++ b/include/asterisk/dundi.h</span><br><span>@@ -59,6 +59,8 @@</span><br><span>   DUNDI_PROTO_SIP  = 2,</span><br><span>        /*! ITU H.323 */</span><br><span>     DUNDI_PROTO_H323 = 3,</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! PJSIP */</span><br><span style="color: hsl(120, 100%, 40%);">+  DUNDI_PROTO_PJSIP = 4,</span><br><span> };</span><br><span> </span><br><span> enum {</span><br><span>diff --git a/pbx/dundi-parser.c b/pbx/dundi-parser.c</span><br><span>index bbfc760..5be8f4c 100644</span><br><span>--- a/pbx/dundi-parser.c</span><br><span>+++ b/pbx/dundi-parser.c</span><br><span>@@ -236,6 +236,8 @@</span><br><span>        case DUNDI_PROTO_H323:</span><br><span>               strncpy(buf, "H.323", bufsiz - 1);</span><br><span>                 break;</span><br><span style="color: hsl(120, 100%, 40%);">+        case DUNDI_PROTO_PJSIP:</span><br><span style="color: hsl(120, 100%, 40%);">+               strncpy(buf, "PJSIP", bufsiz - 1);</span><br><span>         default:</span><br><span>             snprintf(buf, bufsiz, "Unknown Proto(%d)", proto);</span><br><span>         }</span><br><span>diff --git a/pbx/pbx_dundi.c b/pbx/pbx_dundi.c</span><br><span>index 9c0f2fa..c4e76b7 100644</span><br><span>--- a/pbx/pbx_dundi.c</span><br><span>+++ b/pbx/pbx_dundi.c</span><br><span>@@ -208,6 +208,8 @@</span><br><span> static char secretpath[80];</span><br><span> static char cursecret[80];</span><br><span> static char ipaddr[80];</span><br><span style="color: hsl(120, 100%, 40%);">+static int outgoing_sip_tech;</span><br><span style="color: hsl(120, 100%, 40%);">+static char pjsip_outgoing_endpoint[80];</span><br><span> static time_t rotatetime;</span><br><span> static dundi_eid empty_eid = { { 0, 0, 0, 0, 0, 0 } };</span><br><span> static int dundi_shutdown = 0;</span><br><span>@@ -388,12 +390,14 @@</span><br><span>           return "SIP";</span><br><span>      case DUNDI_PROTO_H323:</span><br><span>               return "H323";</span><br><span style="color: hsl(120, 100%, 40%);">+      case DUNDI_PROTO_PJSIP:</span><br><span style="color: hsl(120, 100%, 40%);">+               return "PJSIP";</span><br><span>    default:</span><br><span>             return "Unknown";</span><br><span>  }</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-static int str2tech(char *str)</span><br><span style="color: hsl(120, 100%, 40%);">+static int str2tech(const char *str)</span><br><span> {</span><br><span>  if (!strcasecmp(str, "IAX") || !strcasecmp(str, "IAX2"))</span><br><span>                 return DUNDI_PROTO_IAX;</span><br><span>@@ -401,6 +405,8 @@</span><br><span>                return DUNDI_PROTO_SIP;</span><br><span>      else if (!strcasecmp(str, "H323"))</span><br><span>                 return DUNDI_PROTO_H323;</span><br><span style="color: hsl(120, 100%, 40%);">+      else if (!strcasecmp(str, "PJSIP"))</span><br><span style="color: hsl(120, 100%, 40%);">+         return DUNDI_PROTO_PJSIP;</span><br><span>    else</span><br><span>                 return -1;</span><br><span> }</span><br><span>@@ -4836,7 +4842,6 @@</span><br><span>      int x=0;</span><br><span>     char req[1024];</span><br><span>      const char *dundiargs;</span><br><span style="color: hsl(0, 100%, 40%);">-  struct ast_app *dial;</span><br><span> </span><br><span>    if (!strncasecmp(context, "macro-", 6)) {</span><br><span>          if (!chan) {</span><br><span>@@ -4874,13 +4879,42 @@</span><br><span>       if (x < res) {</span><br><span>            /* Got a hit! */</span><br><span>             dundiargs = pbx_builtin_getvar_helper(chan, "DUNDIDIALARGS");</span><br><span style="color: hsl(0, 100%, 40%);">-         snprintf(req, sizeof(req), "%s/%s,,%s", results[x].tech, results[x].dest,</span><br><span style="color: hsl(0, 100%, 40%);">-                     S_OR(dundiargs, ""));</span><br><span style="color: hsl(0, 100%, 40%);">-         dial = pbx_findapp("Dial");</span><br><span style="color: hsl(0, 100%, 40%);">-           if (dial)</span><br><span style="color: hsl(0, 100%, 40%);">-                       res = pbx_exec(chan, dial, req);</span><br><span style="color: hsl(0, 100%, 40%);">-        } else</span><br><span style="color: hsl(120, 100%, 40%);">+                /* Backwards compatibility with lookups using chan_sip even if we don't have it anymore:</span><br><span style="color: hsl(120, 100%, 40%);">+           * At a protocol level, "SIP" will always be specified, but depending on our configuration,</span><br><span style="color: hsl(120, 100%, 40%);">+          * we will use the user-specified channel driver (from dundi.conf) to complete the call.</span><br><span style="color: hsl(120, 100%, 40%);">+               */</span><br><span style="color: hsl(120, 100%, 40%);">+           if (!strcasecmp(results[x].tech, "SIP") || !strcasecmp(results[x].tech, "PJSIP")) {</span><br><span style="color: hsl(120, 100%, 40%);">+                       /* Only "SIP" is a valid technology for a DUNDi peer to communicate.</span><br><span style="color: hsl(120, 100%, 40%);">+                         * But if they tell use to use "PJSIP" instead, just interpret it as if they said "SIP" instead. */</span><br><span style="color: hsl(120, 100%, 40%);">+                       if (strcasecmp(results[x].tech, "SIP")) {</span><br><span style="color: hsl(120, 100%, 40%);">+                           ast_log(LOG_WARNING, "%s cannot be specified by DUNDi peers (peer should use SIP for DUNDi lookups instead)\n", results[x].tech);</span><br><span style="color: hsl(120, 100%, 40%);">+                   }</span><br><span style="color: hsl(120, 100%, 40%);">+                     /* Use whatever we're configured to use for SIP protocol calls. */</span><br><span style="color: hsl(120, 100%, 40%);">+                        results[x].techint = outgoing_sip_tech;</span><br><span style="color: hsl(120, 100%, 40%);">+                       ast_copy_string(results[x].tech, tech2str(outgoing_sip_tech), sizeof(results[x].tech));</span><br><span style="color: hsl(120, 100%, 40%);">+               }</span><br><span style="color: hsl(120, 100%, 40%);">+             /* PJSIP requires an endpoint to be specified explicitly. */</span><br><span style="color: hsl(120, 100%, 40%);">+          if (outgoing_sip_tech == DUNDI_PROTO_PJSIP) {</span><br><span style="color: hsl(120, 100%, 40%);">+                 char *number, *ip = ast_strdupa(results[x].dest);</span><br><span style="color: hsl(120, 100%, 40%);">+                     if (!ast_strlen_zero(pjsip_outgoing_endpoint)) {</span><br><span style="color: hsl(120, 100%, 40%);">+                              ast_log(LOG_WARNING, "PJSIP calls require an endpoint to be specified explicitly (use the pjsip_outgoing_endpoint option in dundi.conf)\n");</span><br><span style="color: hsl(120, 100%, 40%);">+                                return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+                    }</span><br><span style="color: hsl(120, 100%, 40%);">+                     /* Take IP/number and turn it into sip:number@IP */</span><br><span style="color: hsl(120, 100%, 40%);">+                   if (ast_strlen_zero(ip)) {</span><br><span style="color: hsl(120, 100%, 40%);">+                            ast_log(LOG_WARNING, "PJSIP destination is empty?\n");</span><br><span style="color: hsl(120, 100%, 40%);">+                              return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+                    }</span><br><span style="color: hsl(120, 100%, 40%);">+                     number = strsep(&ip, "/");</span><br><span style="color: hsl(120, 100%, 40%);">+                      snprintf(req, sizeof(req), "%s/%s/sip:%s@%s,,%s", results[x].tech, pjsip_outgoing_endpoint, S_OR(number, ""), ip, S_OR(dundiargs, ""));</span><br><span style="color: hsl(120, 100%, 40%);">+                 ast_debug(1, "Finalized PJSIP Dial: %s\n", req);</span><br><span style="color: hsl(120, 100%, 40%);">+            } else { /* SIP, or something else. */</span><br><span style="color: hsl(120, 100%, 40%);">+                        snprintf(req, sizeof(req), "%s/%s,,%s", results[x].tech, results[x].dest, S_OR(dundiargs, ""));</span><br><span style="color: hsl(120, 100%, 40%);">+           }</span><br><span style="color: hsl(120, 100%, 40%);">+             res = ast_pbx_exec_application(chan, "Dial", req);</span><br><span style="color: hsl(120, 100%, 40%);">+  } else {</span><br><span>             res = -1;</span><br><span style="color: hsl(120, 100%, 40%);">+     }</span><br><span>    return res;</span><br><span> }</span><br><span> </span><br><span>@@ -4956,6 +4990,7 @@</span><br><span>         dundi_ttl = DUNDI_DEFAULT_TTL;</span><br><span>       dundi_cache_time = DUNDI_DEFAULT_CACHE_TIME;</span><br><span>         any_peer = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+      outgoing_sip_tech = DUNDI_PROTO_PJSIP; /* Default for new versions */</span><br><span> </span><br><span>    AST_LIST_LOCK(&peers);</span><br><span> </span><br><span>@@ -5026,6 +5061,15 @@</span><br><span>                      ast_copy_string(phone, v->value, sizeof(phone));</span><br><span>          } else if (!strcasecmp(v->name, "storehistory")) {</span><br><span>                      global_storehistory = ast_true(v->value);</span><br><span style="color: hsl(120, 100%, 40%);">+          } else if (!strcasecmp(v->name, "outgoing_sip_tech")) {</span><br><span style="color: hsl(120, 100%, 40%);">+                  int outgoing_tech = str2tech(v->value);</span><br><span style="color: hsl(120, 100%, 40%);">+                    if (outgoing_tech != DUNDI_PROTO_SIP && outgoing_tech != DUNDI_PROTO_PJSIP) {</span><br><span style="color: hsl(120, 100%, 40%);">+                         ast_log(LOG_WARNING, "outgoing_sip_tech must be SIP or PJSIP\n");</span><br><span style="color: hsl(120, 100%, 40%);">+                   } else {</span><br><span style="color: hsl(120, 100%, 40%);">+                              outgoing_sip_tech = outgoing_tech;</span><br><span style="color: hsl(120, 100%, 40%);">+                    }</span><br><span style="color: hsl(120, 100%, 40%);">+             } else if (!strcasecmp(v->name, "pjsip_outgoing_endpoint")) {</span><br><span style="color: hsl(120, 100%, 40%);">+                    ast_copy_string(pjsip_outgoing_endpoint, v->value, sizeof(pjsip_outgoing_endpoint));</span><br><span>              } else if (!strcasecmp(v->name, "cachetime")) {</span><br><span>                         if ((sscanf(v->value, "%30d", &x) == 1)) {</span><br><span>                          dundi_cache_time = x;</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/20056">change 20056</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/+/20056"/><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: I2e28e5a5d007bd49e3df113ad567b011103899bf </div>
<div style="display:none"> Gerrit-Change-Number: 20056 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: N A <asterisk@phreaknet.org> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>