<p>Joshua Colp <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/7461">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Richard Mudgett: Looks good to me, but someone else must approve
Corey Farrell: Looks good to me, but someone else must approve
Joshua Colp: Looks good to me, approved; Approved for Submit
</div><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.<br><br>ASTERISK-27461<br><br>Change-Id: I5797ded4752acd966db6b13971284db684cc5ab4<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;">diff --git a/channels/chan_sip.c b/channels/chan_sip.c<br>index a829e20..689975f 100644<br>--- a/channels/chan_sip.c<br>+++ b/channels/chan_sip.c<br>@@ -593,6 +593,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>@@ -15591,11 +15594,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>@@ -15603,23 +15608,46 @@<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>- }<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, 0))) {<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>@@ -15636,14 +15664,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/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: merged </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: 6 </div>
<div style="display:none"> Gerrit-Owner: Yasuhiko Kamata <yasuhiko.kamata@nxtg.co.jp> </div>
<div style="display:none"> Gerrit-Reviewer: Corey Farrell <git@cfware.com> </div>
<div style="display:none"> Gerrit-Reviewer: Ivan Poddubny <ivan.poddubny@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Richard Mudgett <rmudgett@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Yasuhiko Kamata <yasuhiko.kamata@nxtg.co.jp> </div>