[asterisk-dev] SIP Missed Calls when calling SIP phones parallel

Gunnar Schaller linux at nowin.de
Thu Jun 21 11:23:03 CDT 2007


Hello,
This should work:

--- asterisk-1.2.18-orig/include/asterisk/channel.h     2007-06-12 08:40:01.000000000 +0200
+++ asterisk-1.2.18/include/asterisk/channel.h  2007-06-12 14:15:10.000000000 +0200
@@ -446,6 +446,8 @@
                                                */
 #define AST_FLAG_NOTNEW        (1 << 10)       /*!< see bug:7855 incorrect Newchannel event generation */
 /* @} */
+#define AST_FLAG_ANSWERED_ELSEWHERE (1 << 15)  /*!< Flag to show channels that this call is hangup due to the fact that
+                                                   the call was indeed answered, but in another channel    */
 
 #define AST_FEATURE_PLAY_WARNING       (1 << 0)
 #define AST_FEATURE_REDIRECT           (1 << 1)
--- asterisk-1.2.18-orig/apps/app_dial.c        2007-06-12 08:40:01.000000000 +0200
+++ asterisk-1.2.18/apps/app_dial.c     2007-06-12 08:52:11.000000000 +0200
@@ -289,14 +289,17 @@
 
 LOCAL_USER_DECL;
 
-static void hanguptree(struct localuser *outgoing, struct ast_channel *exception)
+static void hanguptree(struct localuser *outgoing, struct ast_channel *exception, int answered_elsewhere)
 {
        /* Hang up a tree of stuff */
        struct localuser *oo;
        while (outgoing) {
                /* Hangup any existing lines we have open */
-               if (outgoing->chan && (outgoing->chan != exception))
+               if (outgoing->chan && (outgoing->chan != exception)) {
+                       if (answered_elsewhere)
+                           ast_set_flag(outgoing->chan, AST_FLAG_ANSWERED_ELSEWHERE);
                        ast_hangup(outgoing->chan);
+               }
                oo = outgoing;
                outgoing=outgoing->next;
                free(oo);
@@ -1270,7 +1273,7 @@
                /* Ah ha!  Someone answered within the desired timeframe.  Of course after this
                   we will always return with -1 so that it is hung up properly after the 
                   conversation.  */
-               hanguptree(outgoing, peer);
+               hanguptree(outgoing, peer, 1);
                outgoing = NULL;
                /* If appropriate, log that we have a destination channel */
                if (chan->cdr)
@@ -1504,7 +1507,7 @@
                        ast_parseable_goto(peer, opt_args[OPT_ARG_GOTO]);
                        peer->priority++;
                        ast_pbx_start(peer);
-                       hanguptree(outgoing, NULL);
+                       hanguptree(outgoing, NULL, 0);
                        LOCAL_USER_REMOVE(u);
                        if (continue_exec)
                                *continue_exec = 1;
@@ -1684,7 +1687,7 @@
                sentringing = 0;
                ast_indicate(chan, -1);
        }
-       hanguptree(outgoing, NULL);
+       hanguptree(outgoing, NULL, 0);
        pbx_builtin_setvar_helper(chan, "DIALSTATUS", status);
        ast_log(LOG_DEBUG, "Exiting with DIALSTATUS=%s.\n", status);
        
--- asterisk-1.2.18-orig/channels/chan_sip.c    2007-06-12 08:40:01.000000000 +0200
+++ asterisk-1.2.18/channels/chan_sip.c 2007-06-12 14:39:17.000000000 +0200
@@ -564,6 +564,7 @@
 #define SIP_OSPAUTH_PROXY      (2 << 26)
 #define SIP_OSPAUTH_EXCLUSIVE  (3 << 26)
 /* Call states */
+#define SIP_ANSWEREDELSEWHERE  (1 << 27)
 #define SIP_CALL_ONHOLD                (1 << 28)        
 #define SIP_CALL_LIMIT         (1 << 29)
 /* Remote Party-ID Support */
@@ -2441,6 +2442,13 @@
        if (option_debug)
                ast_log(LOG_DEBUG, "Hangup call %s, SIP callid %s)\n", ast->name, p->callid);
 
+       if (ast_test_flag(ast, AST_FLAG_ANSWERED_ELSEWHERE)) {
+           if(option_debug)
+               ast_log(LOG_DEBUG, "This call was answered elsewhere\n");
+           append_history(p, "Cancel", "Call answered elsewhere");
+           ast_set_flag(p, SIP_ANSWEREDELSEWHERE);
+       }
+       
        ast_mutex_lock(&p->lock);
 #ifdef OSP_SUPPORT
        if ((p->osphandle > -1) && (ast->_state == AST_STATE_UP)) {
@@ -5875,6 +5883,9 @@
 {
        struct sip_request resp;
        reqprep(&resp, p, sipmethod, seqno, newbranch);
+       if (sipmethod == SIP_CANCEL && ast_test_flag(p, SIP_ANSWEREDELSEWHERE))
+           add_header(&resp, "Reason", "SIP;cause=200;text=\"Call completed elsewhere\"");
+       
        add_header_contentLength(&resp, 0);
        add_blank_header(&resp);
        return send_request(p, &resp, reliable, seqno ? seqno : p->ocseq);




More information about the asterisk-dev mailing list