chan_sip: 3PCC patch for AMI "SIPnotify"

A patch for sending in-dialog SIP NOTIFY message
with "SIPnotify" AMI action.

ASTERISK-27461

(created patch for 13 branch manually due to merge conflict)

Change-Id: I255067f02e2ce22c4b244f12134b9a48d210c22a
This commit is contained in:
Yasuhiko Kamata
2018-01-15 16:41:44 +09:00
parent e79e8c557b
commit c0a4a939cc

View File

@@ -546,6 +546,9 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
<para>At least one variable pair must be specified. <para>At least one variable pair must be specified.
<replaceable>name</replaceable>=<replaceable>value</replaceable></para> <replaceable>name</replaceable>=<replaceable>value</replaceable></para>
</parameter> </parameter>
<parameter name="Call-ID" required="false">
<para>When specified, SIP notity will be sent as a part of an existing dialog.</para>
</parameter>
</syntax> </syntax>
<description> <description>
<para>Sends a SIP Notify event.</para> <para>Sends a SIP Notify event.</para>
@@ -15526,11 +15529,13 @@ static int manager_sipnotify(struct mansession *s, const struct message *m)
{ {
const char *channame = astman_get_header(m, "Channel"); const char *channame = astman_get_header(m, "Channel");
struct ast_variable *vars = astman_get_variables_order(m, ORDER_NATURAL); struct ast_variable *vars = astman_get_variables_order(m, ORDER_NATURAL);
const char *callid = astman_get_header(m, "Call-ID");
struct sip_pvt *p; struct sip_pvt *p;
struct ast_variable *header, *var; struct ast_variable *header, *var;
if (ast_strlen_zero(channame)) { if (ast_strlen_zero(channame)) {
astman_send_error(s, m, "SIPNotify requires a channel name"); astman_send_error(s, m, "SIPNotify requires a channel name");
ast_variables_destroy(vars);
return 0; return 0;
} }
@@ -15538,8 +15543,28 @@ static int manager_sipnotify(struct mansession *s, const struct message *m)
channame += 4; channame += 4;
} }
/* check if Call-ID header is set */
if (!ast_strlen_zero(callid)) {
struct sip_pvt tmp_dialog = {
.callid = callid,
};
p = ao2_find(dialogs, &tmp_dialog, OBJ_SEARCH_OBJECT);
if (!p) {
astman_send_error(s, m, "Call-ID not found");
ast_variables_destroy(vars);
return 0;
}
if (!(p->notify)) {
sip_notify_alloc(p);
} else {
ast_variables_destroy(p->notify->headers);
}
} else {
if (!(p = sip_alloc(NULL, NULL, 0, SIP_NOTIFY, NULL, NULL))) { if (!(p = sip_alloc(NULL, NULL, 0, SIP_NOTIFY, NULL, NULL))) {
astman_send_error(s, m, "Unable to build sip pvt data for notify (memory/socket error)"); astman_send_error(s, m, "Unable to build sip pvt data for notify (memory/socket error)");
ast_variables_destroy(vars);
return 0; return 0;
} }
@@ -15549,6 +15574,7 @@ static int manager_sipnotify(struct mansession *s, const struct message *m)
dialog_unref(p, "unref dialog inside for loop" ); dialog_unref(p, "unref dialog inside for loop" );
/* sip_destroy(p); */ /* sip_destroy(p); */
astman_send_error(s, m, "Could not create address"); astman_send_error(s, m, "Could not create address");
ast_variables_destroy(vars);
return 0; return 0;
} }
@@ -15556,6 +15582,8 @@ static int manager_sipnotify(struct mansession *s, const struct message *m)
ast_set_flag(&p->flags[0], SIP_OUTGOING); ast_set_flag(&p->flags[0], SIP_OUTGOING);
sip_notify_alloc(p); sip_notify_alloc(p);
}
p->notify->headers = header = ast_variable_new("Subscription-State", "terminated", ""); p->notify->headers = header = ast_variable_new("Subscription-State", "terminated", "");
for (var = vars; var; var = var->next) { for (var = vars; var; var = var->next) {
@@ -15571,6 +15599,7 @@ static int manager_sipnotify(struct mansession *s, const struct message *m)
} }
} }
if (ast_strlen_zero(callid)) {
/* Now that we have the peer's address, set our ip and change callid */ /* Now that we have the peer's address, set our ip and change callid */
ast_sip_ouraddrfor(&p->sa, &p->ourip, p); ast_sip_ouraddrfor(&p->sa, &p->ourip, p);
build_via(p); build_via(p);
@@ -15579,6 +15608,10 @@ static int manager_sipnotify(struct mansession *s, const struct message *m)
sip_scheddestroy(p, SIP_TRANS_TIMEOUT); sip_scheddestroy(p, SIP_TRANS_TIMEOUT);
transmit_invite(p, SIP_NOTIFY, 0, 2, NULL); transmit_invite(p, SIP_NOTIFY, 0, 2, NULL);
} else {
sip_scheddestroy(p, SIP_TRANS_TIMEOUT);
transmit_invite(p, SIP_NOTIFY, 0, 1, NULL);
}
dialog_unref(p, "bump down the count of p since we're done with it."); dialog_unref(p, "bump down the count of p since we're done with it.");
astman_send_ack(s, m, "Notify Sent"); astman_send_ack(s, m, "Notify Sent");