<p>Yasuhiko Kamata has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/7962">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">an_sip: 3PCC patch for AMI "SIPnotify"<br><br>A patch for sending in-dialog SIP NOTIFY message<br>with "SIPnotify" AMI action.<br><br>ASTERISK-27461<br><br>(created patch for 13 branch manually due to merge conflict)<br><br>Change-Id: I255067f02e2ce22c4b244f12134b9a48d210c22a<br>---<br>M channels/chan_sip.c<br>1 file changed, 54 insertions(+), 21 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/62/7962/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 ee2eee0..7a94517 100644<br>--- a/channels/chan_sip.c<br>+++ b/channels/chan_sip.c<br>@@ -546,6 +546,9 @@<br>                            <para>At least one variable pair must be specified.<br>                             <replaceable>name</replaceable>=<replaceable>value</replaceable></para><br>                         </parameter><br>+                   <parameter name="Call-ID" required="false"><br>+                                <para>When specified, SIP notity will be sent as a part of an existing dialog.</para><br>+                    </parameter><br>            </syntax><br>               <description><br>                   <para>Sends a SIP Notify event.</para><br>@@ -15526,11 +15529,13 @@<br> {<br>     const char *channame = astman_get_header(m, "Channel");<br>     struct ast_variable *vars = astman_get_variables_order(m, ORDER_NATURAL);<br>+    const char *callid = astman_get_header(m, "Call-ID");<br>       struct sip_pvt *p;<br>    struct ast_variable *header, *var;<br> <br>         if (ast_strlen_zero(channame)) {<br>              astman_send_error(s, m, "SIPNotify requires a channel name");<br>+              ast_variables_destroy(vars);<br>          return 0;<br>     }<br> <br>@@ -15538,23 +15543,46 @@<br>               channame += 4;<br>        }<br> <br>- if (!(p = sip_alloc(NULL, NULL, 0, SIP_NOTIFY, NULL, NULL))) {<br>-               astman_send_error(s, m, "Unable to build sip pvt data for notify (memory/socket error)");<br>-          return 0;<br>-    }<br>+    /* check if Call-ID header is set */<br>+ if (!ast_strlen_zero(callid)) {<br>+              struct sip_pvt tmp_dialog = {<br>+                        .callid = callid,<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>+            p = ao2_find(dialogs, &tmp_dialog, OBJ_SEARCH_OBJECT);<br>+           if (!p) {<br>+                    astman_send_error(s, m, "Call-ID not found");<br>+                      ast_variables_destroy(vars);<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>+         if (!(p->notify)) {<br>+                       sip_notify_alloc(p);<br>+         } else {<br>+                     ast_variables_destroy(p->notify->headers);<br>+             }<br>+    } else {<br>+             if (!(p = sip_alloc(NULL, NULL, 0, SIP_NOTIFY, NULL, NULL))) {<br>+                       astman_send_error(s, m, "Unable to build sip pvt data for notify (memory/socket error)");<br>+                  ast_variables_destroy(vars);<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>+                       ast_variables_destroy(vars);<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>+      }<br> <br>  p->notify->headers = header = ast_variable_new("Subscription-State", "terminated", "");<br> <br>@@ -15571,14 +15599,19 @@<br>             }<br>     }<br> <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>+        if (ast_strlen_zero(callid)) {<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>+          sip_scheddestroy(p, SIP_TRANS_TIMEOUT);<br>+              transmit_invite(p, SIP_NOTIFY, 0, 2, NULL);<br>+  } else {<br>+             sip_scheddestroy(p, SIP_TRANS_TIMEOUT);<br>+              transmit_invite(p, SIP_NOTIFY, 0, 1, NULL);<br>+  }<br>     dialog_unref(p, "bump down the count of p since we're done with it.");<br> <br>       astman_send_ack(s, m, "Notify Sent");<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/7962">change 7962</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/7962"/><meta itemprop="name" content="View Change"/></div></div>

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