[Asterisk-code-review] chan sip: 3PCC patch for AMI "SIPnotify" (asterisk[master])
Yasuhiko Kamata
asteriskteam at digium.com
Wed Dec 6 21:07:21 CST 2017
Yasuhiko Kamata has uploaded this change for review. ( https://gerrit.asterisk.org/7461
Change subject: chan_sip: 3PCC patch for AMI "SIPnotify"
......................................................................
chan_sip: 3PCC patch for AMI "SIPnotify"
A patch for sending in-dialog SIP NOTIFY message
with "SIPnotify" AMI action for latest (14.x and 15.x) asterisk.
ASTERISK-27461
Change-Id: I5797ded4752acd966db6b13971284db684cc5ab4
---
M channels/chan_sip.c
1 file changed, 62 insertions(+), 19 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/61/7461/1
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index a829e20..3c6b4f4 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -15591,8 +15591,9 @@
{
const char *channame = astman_get_header(m, "Channel");
struct ast_variable *vars = astman_get_variables_order(m, ORDER_NATURAL);
- struct sip_pvt *p;
+ struct sip_pvt *p = NULL;
struct ast_variable *header, *var;
+ char indialog = 0;
if (ast_strlen_zero(channame)) {
astman_send_error(s, m, "SIPNotify requires a channel name");
@@ -15603,25 +15604,61 @@
channame += 4;
}
- if (!(p = sip_alloc(NULL, NULL, 0, SIP_NOTIFY, NULL, 0))) {
- astman_send_error(s, m, "Unable to build sip pvt data for notify (memory/socket error)");
- return 0;
+ // check if Call-ID variable is set
+ for (var = vars; var; var = var->next) {
+ if (!strcasecmp(var->name, "Call-ID")) {
+ struct sip_pvt tmp_dialog = {
+ .callid = var->value,
+ };
+
+ p = ao2_find(dialogs, &tmp_dialog, OBJ_POINTER);
+ if (!p) {
+ astman_send_error(s, m, "Call-ID not found");
+ return 0;
+ }
+ indialog = 1;
+ }
+ }
+
+ if (!indialog) {
+ if (!(p = sip_alloc(NULL, NULL, 0, SIP_NOTIFY, NULL, 0))) {
+ astman_send_error(s, m, "Unable to build sip pvt data for notify (memory/socket error)");
+ return 0;
+ }
+
+ if (create_addr(p, channame, NULL, 0)) {
+ /* Maybe they're not registered, etc. */
+ dialog_unlink_all(p);
+ dialog_unref(p, "unref dialog inside for loop" );
+ /* sip_destroy(p); */
+ astman_send_error(s, m, "Could not create address");
+ return 0;
+ }
+
+ /* Notify is outgoing call */
+ ast_set_flag(&p->flags[0], SIP_OUTGOING);
+ sip_notify_alloc(p);
+
+ p->notify->headers = header = ast_variable_new("Subscription-State", "terminated", "");
+ } else {
+ if (!(p->notify)) {
+ sip_notify_alloc(p);
+ } else {
+ ast_variables_destroy(p->notify->headers);
+ }
+
+ p->notify->headers = header = ast_variable_new("Subscription-State", "terminated", "");
}
- if (create_addr(p, channame, NULL, 0)) {
- /* Maybe they're not registered, etc. */
- dialog_unlink_all(p);
- dialog_unref(p, "unref dialog inside for loop" );
- /* sip_destroy(p); */
- astman_send_error(s, m, "Could not create address");
- return 0;
- }
-
- /* Notify is outgoing call */
- ast_set_flag(&p->flags[0], SIP_OUTGOING);
- sip_notify_alloc(p);
-
- p->notify->headers = header = ast_variable_new("Subscription-State", "terminated", "");
+ /* if (pref) {
+ ast_string_field_set(p, callid, pref->callid);
+ ast_string_field_set(p, fromuser, pref->fromuser);
+ ast_string_field_set(p, fromname, pref->fromname);
+ ast_string_field_set(p, tag, pref->tag);
+ ast_string_field_set(p, theirtag, pref->theirtag);
+ p->ocseq = pref->ocseq;
+ (pref->ocseq)++;
+ } */
for (var = vars; var; var = var->next) {
if (!strcasecmp(var->name, "Content")) {
@@ -15630,21 +15667,27 @@
ast_str_append(&p->notify->content, 0, "%s", var->value);
} else if (!strcasecmp(var->name, "Content-Length")) {
ast_log(LOG_WARNING, "it is not necessary to specify Content-Length, ignoring\n");
+ } else if (!strcasecmp(var->name, "Call-ID")) {
+ // do nothing here
} else {
header->next = ast_variable_new(var->name, var->value, "");
header = header->next;
}
}
+ if (!indialog) {
/* Now that we have the peer's address, set our ip and change callid */
ast_sip_ouraddrfor(&p->sa, &p->ourip, p);
build_via(p);
- change_callid_pvt(p, NULL);
+ change_callid_pvt(p, NULL);
sip_scheddestroy(p, SIP_TRANS_TIMEOUT);
transmit_invite(p, SIP_NOTIFY, 0, 2, NULL);
dialog_unref(p, "bump down the count of p since we're done with it.");
+ } else {
+ transmit_invite(p, SIP_NOTIFY, 0, 1, NULL);
+ }
astman_send_ack(s, m, "Notify Sent");
ast_variables_destroy(vars);
--
To view, visit https://gerrit.asterisk.org/7461
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5797ded4752acd966db6b13971284db684cc5ab4
Gerrit-Change-Number: 7461
Gerrit-PatchSet: 1
Gerrit-Owner: Yasuhiko Kamata <yasuhiko.kamata at nxtg.co.jp>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20171206/cf3da553/attachment.html>
More information about the asterisk-code-review
mailing list