<p>Yasuhiko Kamata has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/7461">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">chan_sip: 3PCC patch for AMI "SIPnotify"<br><br>A patch for sending in-dialog SIP NOTIFY message<br>with "SIPnotify" AMI action for latest (14.x and 15.x) asterisk.<br><br>ASTERISK-27461<br><br>Change-Id: I5797ded4752acd966db6b13971284db684cc5ab4<br>---<br>M channels/chan_sip.c<br>1 file changed, 62 insertions(+), 19 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/61/7461/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/channels/chan_sip.c b/channels/chan_sip.c<br>index a829e20..3c6b4f4 100644<br>--- a/channels/chan_sip.c<br>+++ b/channels/chan_sip.c<br>@@ -15591,8 +15591,9 @@<br> {<br>      const char *channame = astman_get_header(m, "Channel");<br>     struct ast_variable *vars = astman_get_variables_order(m, ORDER_NATURAL);<br>-    struct sip_pvt *p;<br>+   struct sip_pvt *p = NULL;<br>     struct ast_variable *header, *var;<br>+   char indialog = 0;<br> <br>         if (ast_strlen_zero(channame)) {<br>              astman_send_error(s, m, "SIPNotify requires a channel name");<br>@@ -15603,25 +15604,61 @@<br>            channame += 4;<br>        }<br> <br>- if (!(p = sip_alloc(NULL, NULL, 0, SIP_NOTIFY, NULL, 0))) {<br>-          astman_send_error(s, m, "Unable to build sip pvt data for notify (memory/socket error)");<br>-          return 0;<br>+        // check if Call-ID variable is set<br>+        for (var = vars; var; var = var->next) {<br>+          if (!strcasecmp(var->name, "Call-ID")) {<br>+            struct sip_pvt tmp_dialog = {<br>+              .callid = var->value,<br>+            };<br>+<br>+            p = ao2_find(dialogs, &tmp_dialog, OBJ_POINTER);<br>+            if (!p) {<br>+              astman_send_error(s, m, "Call-ID not found");<br>+              return 0;<br>+            }<br>+            indialog = 1;<br>+          }<br>+        }<br>+<br>+        if (!indialog) {<br>+            if (!(p = sip_alloc(NULL, NULL, 0, SIP_NOTIFY, NULL, 0))) {<br>+                  astman_send_error(s, m, "Unable to build sip pvt data for notify (memory/socket error)");<br>+                  return 0;<br>+            }<br>+<br>+         if (create_addr(p, channame, NULL, 0)) {<br>+                     /* Maybe they're not registered, etc. */<br>+                 dialog_unlink_all(p);<br>+                        dialog_unref(p, "unref dialog inside for loop" );<br>+                  /* sip_destroy(p); */<br>+                        astman_send_error(s, m, "Could not create address");<br>+                       return 0;<br>+            }<br>+<br>+         /* Notify is outgoing call */<br>+                ast_set_flag(&p->flags[0], SIP_OUTGOING);<br>+             sip_notify_alloc(p);<br>+<br>+              p->notify->headers = header = ast_variable_new("Subscription-State", "terminated", "");<br>+        } else {<br>+          if (!(p->notify)) {<br>+        sip_notify_alloc(p);<br>+          } else {<br>+            ast_variables_destroy(p->notify->headers);<br>+          }<br>+<br>+          p->notify->headers = header = ast_variable_new("Subscription-State", "terminated", "");<br>         }<br> <br>- if (create_addr(p, channame, NULL, 0)) {<br>-             /* Maybe they're not registered, etc. */<br>-         dialog_unlink_all(p);<br>-                dialog_unref(p, "unref dialog inside for loop" );<br>-          /* sip_destroy(p); */<br>-                astman_send_error(s, m, "Could not create address");<br>-               return 0;<br>-    }<br>-<br>- /* Notify is outgoing call */<br>-        ast_set_flag(&p->flags[0], SIP_OUTGOING);<br>-     sip_notify_alloc(p);<br>-<br>-      p->notify->headers = header = ast_variable_new("Subscription-State", "terminated", "");<br>+        /* if (pref) {<br>+          ast_string_field_set(p, callid, pref->callid);<br>+          ast_string_field_set(p, fromuser, pref->fromuser);<br>+          ast_string_field_set(p, fromname, pref->fromname);<br>+          ast_string_field_set(p, tag, pref->tag);<br>+          ast_string_field_set(p, theirtag, pref->theirtag);<br>+          p->ocseq = pref->ocseq;<br>+          (pref->ocseq)++;<br>+        } */<br> <br>  for (var = vars; var; var = var->next) {<br>           if (!strcasecmp(var->name, "Content")) {<br>@@ -15630,21 +15667,27 @@<br>                      ast_str_append(&p->notify->content, 0, "%s", var->value);<br>              } else if (!strcasecmp(var->name, "Content-Length")) {<br>                   ast_log(LOG_WARNING, "it is not necessary to specify Content-Length, ignoring\n");<br>+         } else if (!strcasecmp(var->name, "Call-ID")) {<br>+                  // do nothing here<br>           } else {<br>                      header->next = ast_variable_new(var->name, var->value, "");<br>                        header = header->next;<br>             }<br>     }<br> <br>+        if (!indialog) {<br>       /* Now that we have the peer's address, set our ip and change callid */<br>   ast_sip_ouraddrfor(&p->sa, &p->ourip, p);<br>       build_via(p);<br> <br>-     change_callid_pvt(p, NULL);<br>+        change_callid_pvt(p, NULL);<br> <br>  sip_scheddestroy(p, SIP_TRANS_TIMEOUT);<br>       transmit_invite(p, SIP_NOTIFY, 0, 2, NULL);<br>   dialog_unref(p, "bump down the count of p since we're done with it.");<br>+        } else {<br>+          transmit_invite(p, SIP_NOTIFY, 0, 1, NULL);<br>+        }<br> <br>        astman_send_ack(s, m, "Notify Sent");<br>       ast_variables_destroy(vars);<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/7461">change 7461</a>. To unsubscribe, 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/7461"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I5797ded4752acd966db6b13971284db684cc5ab4 </div>
<div style="display:none"> Gerrit-Change-Number: 7461 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Yasuhiko Kamata <yasuhiko.kamata@nxtg.co.jp> </div>