Send more accurate identification information in dialog-info SIP NOTIFYs.
authorMark Michelson <mmichelson@digium.com>
Tue, 8 May 2012 15:57:14 +0000 (15:57 +0000)
committerMark Michelson <mmichelson@digium.com>
Tue, 8 May 2012 15:57:14 +0000 (15:57 +0000)
This uses the calling channel's caller ID and connected line information
to populate the remote and local identities in the dialog-info NOTIFY when
an extension is ringing.

There is a bit of an oddity here, and that is that we seed the remote target
with the To header of the outbound call rather than the from header. This
is because it was reported that seeding with the from header caused hints
to be broken with certain SNOM devices. A comment has been added to the code
to explain this.

(closes issue ASTERISK-16735)
reported by Maciej Krajewski
patches:
    local_remote_hint2.diff uploaded by Mark Michelson (license #5049)
16735_tweak1.diff uploaded by Mark Michelson (license #5049)
Tested by Niccolo Belli
........

Merged revisions 365574 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 365575 from http://svn.asterisk.org/svn/asterisk/branches/10

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@365576 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_sip.c

index 71ca637..17ef07e 100644 (file)
@@ -13098,6 +13098,16 @@ static void state_notify_build_xml(int state, int full, const char *exten, const
                if ((state & AST_EXTENSION_RINGING) && sip_cfg.notifyringing) {
                        const char *local_display = exten;
                        char *local_target = ast_strdupa(mto);
+                       const char *remote_display = exten;
+                       /* It may seem odd to base the remote_target on the To header here,
+                        * but testing by reporters on issue ASTERISK-16735 found that basing
+                        * on the From header would cause ringing state hints to not work
+                        * properly on certain SNOM devices. If you are using notifycid properly
+                        * (i.e. in the same extension and context as the dialed call) then this
+                        * should not be an issue since the data will be overwritten shortly
+                        * with channel caller ID
+                        */
+                       char *remote_target = ast_strdupa(mto);
 
                        /* There are some limitations to how this works.  The primary one is that the
                           callee must be dialing the same extension that is being monitored.  Simply dialing
@@ -13107,16 +13117,28 @@ static void state_notify_build_xml(int state, int full, const char *exten, const
 
                                if ((caller = ast_channel_callback(find_calling_channel, NULL, p, 0))) {
                                        char *cid_num;
+                                       char *connected_num;
                                        int need;
 
                                        ast_channel_lock(caller);
                                        cid_num = S_COR(ast_channel_caller(caller)->id.number.valid,
                                                ast_channel_caller(caller)->id.number.str, "");
                                        need = strlen(cid_num) + strlen(p->fromdomain) + sizeof("sip:@");
-                                       local_target = alloca(need);
-                                       snprintf(local_target, need, "sip:%s@%s", cid_num, p->fromdomain);
-                                       local_display = ast_strdupa(S_COR(ast_channel_caller(caller)->id.name.valid,
+                                       remote_target = alloca(need);
+                                       snprintf(remote_target, need, "sip:%s@%s", cid_num, p->fromdomain);
+
+                                       remote_display = ast_strdupa(S_COR(ast_channel_caller(caller)->id.name.valid,
                                                ast_channel_caller(caller)->id.name.str, ""));
+
+                                       connected_num = S_COR(ast_channel_connected(caller)->id.number.valid,
+                                               ast_channel_connected(caller)->id.number.str, "");
+                                       need = strlen(connected_num) + strlen(p->fromdomain) + sizeof("sip:@");
+                                       local_target = alloca(need);
+                                       snprintf(local_target, need, "sip:%s@%s", connected_num, p->fromdomain);
+
+                                       local_display = ast_strdupa(S_COR(ast_channel_connected(caller)->id.name.valid,
+                                               ast_channel_connected(caller)->id.name.str, ""));
+
                                        ast_channel_unlock(caller);
                                        caller = ast_channel_unref(caller);
                                }
@@ -13138,10 +13160,10 @@ static void state_notify_build_xml(int state, int full, const char *exten, const
                                                "<target uri=\"%s\"/>\n"
                                                "</remote>\n"
                                                "<local>\n"
-                                               "<identity>%s</identity>\n"
+                                               "<identity display=\"%s\">%s</identity>\n"
                                                "<target uri=\"%s\"/>\n"
                                                "</local>\n",
-                                               local_display, local_target, local_target, mto, mto);
+                                               remote_display, remote_target, remote_target, local_display, local_target, local_target);
                        } else {
                                ast_str_append(tmp, 0, "<dialog id=\"%s\" direction=\"recipient\">\n", exten);
                        }