Convert AST_FLAG_ANSWERED_ELSEWHERE usage to AST_CAUSE_ANSWERED_ELSEWHERE
authorKinsey Moore <kmoore@digium.com>
Tue, 5 Jun 2012 14:41:43 +0000 (14:41 +0000)
committerKinsey Moore <kmoore@digium.com>
Tue, 5 Jun 2012 14:41:43 +0000 (14:41 +0000)
This was essentially duplicated functionality where normal channels used
AST_CAUSE_ANSWERED_ELSEWHERE while local channels and queues used
AST_FLAG_ANSWERED_ELSEWHERE.  This removes the flag and converts that usage
into AST_CAUSE_ANSWERED_ELSEWHER usage.

Review: https://reviewboard.asterisk.org/r/1944
(closes issue ASTERISK-19865)
Patch-by: Birger Harzenetter

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

apps/app_dial.c
apps/app_queue.c
channels/chan_local.c
channels/chan_sip.c
channels/chan_unistim.c
include/asterisk/channel.h
main/channel_internal_api.c
main/features.c

index e6eebbe..1ebad34 100644 (file)
@@ -133,8 +133,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                                        <para>Reset the call detail record (CDR) for this call.</para>
                                </option>
                                <option name="c">
-                                       <para>If the Dial() application cancels this call, always set the flag to tell the channel
-                                       driver that the call is answered elsewhere.</para>
+                                       <para>If the Dial() application cancels this call, always set HANGUPCAUSE to 'answered elsewhere'</para>
                                </option>
                                <option name="d">
                                        <para>Allow the calling user to dial a 1 digit extension while waiting for
@@ -727,8 +726,6 @@ static void hanguptree(struct dial_head *out_chans, struct ast_channel *exceptio
                /* Hangup any existing lines we have open */
                if (outgoing->chan && (outgoing->chan != exception)) {
                        if (answered_elsewhere) {
-                               /* The flag is used for local channel inheritance and stuff */
-                               ast_set_flag(ast_channel_flags(outgoing->chan), AST_FLAG_ANSWERED_ELSEWHERE);
                                /* This is for the channel drivers */
                                ast_channel_hangupcause_set(outgoing->chan, AST_CAUSE_ANSWERED_ELSEWHERE);
                        }
@@ -2515,12 +2512,12 @@ static int dial_exec_full(struct ast_channel *chan, const char *data, struct ast
                if (outbound_group)
                        ast_app_group_set_channel(tc, outbound_group);
                /* If the calling channel has the ANSWERED_ELSEWHERE flag set, inherit it. This is to support local channels */
-               if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_ANSWERED_ELSEWHERE))
-                       ast_set_flag(ast_channel_flags(tc), AST_FLAG_ANSWERED_ELSEWHERE);
+               if (ast_channel_hangupcause(chan) == AST_CAUSE_ANSWERED_ELSEWHERE)
+                       ast_channel_hangupcause_set(tc, AST_CAUSE_ANSWERED_ELSEWHERE);
 
                /* Check if we're forced by configuration */
                if (ast_test_flag64(&opts, OPT_CANCEL_ELSEWHERE))
-                        ast_set_flag(ast_channel_flags(tc), AST_FLAG_ANSWERED_ELSEWHERE);
+                        ast_channel_hangupcause_set(tc, AST_CAUSE_ANSWERED_ELSEWHERE);
 
 
                /* Inherit context and extension */
@@ -3079,11 +3076,11 @@ out:
        }
 
        ast_channel_early_bridge(chan, NULL);
-       hanguptree(&out_chans, NULL, 0); /* In this case, there's no answer anywhere */
+       hanguptree(&out_chans, NULL, ast_channel_hangupcause(chan)==AST_CAUSE_ANSWERED_ELSEWHERE ? 1 : 0 ); /* forward 'answered elsewhere' if we received it */
        pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
        senddialendevent(chan, pa.status);
        ast_debug(1, "Exiting with DIALSTATUS=%s.\n", pa.status);
-       
+
        if ((ast_test_flag64(peerflags, OPT_GO_ON)) && !ast_check_hangup(chan) && (res != AST_PBX_INCOMPLETE)) {
                if (!ast_tvzero(calldurationlimit))
                        memset(ast_channel_whentohangup(chan), 0, sizeof(*ast_channel_whentohangup(chan)));
index cb96749..931733c 100644 (file)
@@ -3103,7 +3103,7 @@ static void hangupcalls(struct callattempt *outgoing, struct ast_channel *except
                /* Hangup any existing lines we have open */
                if (outgoing->chan && (outgoing->chan != exception)) {
                        if (exception || cancel_answered_elsewhere) {
-                               ast_set_flag(ast_channel_flags(outgoing->chan), AST_FLAG_ANSWERED_ELSEWHERE);
+                               ast_channel_hangupcause_set(outgoing->chan, AST_CAUSE_ANSWERED_ELSEWHERE);
                        }
                        ast_hangup(outgoing->chan);
                }
@@ -3357,7 +3357,7 @@ static int ring_entry(struct queue_ent *qe, struct callattempt *tmp, int *busies
        ast_channel_lock_both(tmp->chan, qe->chan);
 
        if (qe->cancel_answered_elsewhere) {
-               ast_set_flag(ast_channel_flags(tmp->chan), AST_FLAG_ANSWERED_ELSEWHERE);
+               ast_channel_hangupcause_set(tmp->chan, AST_CAUSE_ANSWERED_ELSEWHERE);
        }
        ast_channel_appl_set(tmp->chan, "AppQueue");
        ast_channel_data_set(tmp->chan, "(Outgoing Line)");
@@ -4825,10 +4825,10 @@ static int try_calling(struct queue_ent *qe, const struct ast_flags opts, char *
                qe->cancel_answered_elsewhere = 1;
        }
 
-       /* if the calling channel has the ANSWERED_ELSEWHERE flag set, make sure this is inherited. 
+       /* if the calling channel has AST_CAUSE_ANSWERED_ELSEWHERE set, make sure this is inherited.
                (this is mainly to support chan_local)
        */
-       if (ast_test_flag(ast_channel_flags(qe->chan), AST_FLAG_ANSWERED_ELSEWHERE)) {
+       if (ast_channel_hangupcause(qe->chan) == AST_CAUSE_ANSWERED_ELSEWHERE) {
                qe->cancel_answered_elsewhere = 1;
        }
 
index bed9eeb..3c5fca5 100644 (file)
@@ -37,6 +37,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include <sys/signal.h>
 
 #include "asterisk/lock.h"
+#include "asterisk/causes.h"
 #include "asterisk/channel.h"
 #include "asterisk/config.h"
 #include "asterisk/module.h"
@@ -909,9 +910,9 @@ static int local_call(struct ast_channel *ast, const char *dest, int timeout)
 
        ast_channel_cc_params_init(chan, ast_channel_get_cc_config_params(owner));
 
-       /* Make sure we inherit the ANSWERED_ELSEWHERE flag if it's set on the queue/dial call request in the dialplan */
-       if (ast_test_flag(ast_channel_flags(ast), AST_FLAG_ANSWERED_ELSEWHERE)) {
-               ast_set_flag(ast_channel_flags(chan), AST_FLAG_ANSWERED_ELSEWHERE);
+       /* Make sure we inherit the AST_CAUSE_ANSWERED_ELSEWHERE if it's set on the queue/dial call request in the dialplan */
+       if (ast_channel_hangupcause(ast) == AST_CAUSE_ANSWERED_ELSEWHERE) {
+               ast_channel_hangupcause_set(chan, AST_CAUSE_ANSWERED_ELSEWHERE);
        }
 
        /* copy the channel variables from the incoming channel to the outgoing channel */
@@ -1028,9 +1029,9 @@ static int local_hangup(struct ast_channel *ast)
 
        isoutbound = IS_OUTBOUND(ast, p); /* just comparing pointer of ast */
 
-       if (p->chan && ast_test_flag(ast_channel_flags(ast), AST_FLAG_ANSWERED_ELSEWHERE)) {
-               ast_set_flag(ast_channel_flags(p->chan), AST_FLAG_ANSWERED_ELSEWHERE);
-               ast_debug(2, "This local call has the ANSWERED_ELSEWHERE flag set.\n");
+       if (p->chan && ast_channel_hangupcause(ast) == AST_CAUSE_ANSWERED_ELSEWHERE) {
+               ast_channel_hangupcause_set(p->chan, AST_CAUSE_ANSWERED_ELSEWHERE);
+               ast_debug(2, "This local call has AST_CAUSE_ANSWERED_ELSEWHERE set.\n");
        }
 
        if (isoutbound) {
index 5ee1e4b..31064fe 100644 (file)
@@ -6369,11 +6369,8 @@ static int sip_hangup(struct ast_channel *ast)
                ast_debug(1, "Asked to hangup channel that was not connected\n");
                return 0;
        }
-       if (ast_test_flag(ast_channel_flags(ast), AST_FLAG_ANSWERED_ELSEWHERE) || ast_channel_hangupcause(ast) == AST_CAUSE_ANSWERED_ELSEWHERE) {
+       if (ast_channel_hangupcause(ast) == AST_CAUSE_ANSWERED_ELSEWHERE) {
                ast_debug(1, "This call was answered elsewhere\n");
-               if (ast_channel_hangupcause(ast) == AST_CAUSE_ANSWERED_ELSEWHERE) {
-                       ast_debug(1, "####### It's the cause code, buddy. The cause code!!!\n");
-               }
                append_history(p, "Cancel", "Call answered elsewhere");
                p->answered_elsewhere = TRUE;
        }
index 434aa0c..b143d16 100644 (file)
@@ -4856,7 +4856,7 @@ static int unistim_hangup(struct ast_channel *ast)
        refresh_all_favorite(s); /* Update favicons in case of DND keys */
        if (s->state == STATE_RINGING && sub->subtype == SUB_RING) {
                send_no_ring(s);
-               if (!ast_test_flag(ast_channel_flags(ast), AST_FLAG_ANSWERED_ELSEWHERE) && ast_channel_hangupcause(ast) != AST_CAUSE_ANSWERED_ELSEWHERE) {
+               if (ast_channel_hangupcause(ast) != AST_CAUSE_ANSWERED_ELSEWHERE) {
                        d->missed_call++;
                        write_history(s, 'i', 1);
                }
index 59008a6..da35157 100644 (file)
@@ -835,9 +835,10 @@ enum {
        /*! This is set to tell the channel not to generate DTMF begin frames, and
         *  to instead only generate END frames. */
        AST_FLAG_END_DTMF_ONLY = (1 << 14),
-       /*! Flag to show channels that this call is hangup due to the fact that the call
+       /* OBSOLETED in favor of AST_CAUSE_ANSWERED_ELSEWHERE
+       Flag to show channels that this call is hangup due to the fact that the call
            was indeed answered, but in another channel */
-       AST_FLAG_ANSWERED_ELSEWHERE = (1 << 15),
+       /* AST_FLAG_ANSWERED_ELSEWHERE = (1 << 15), */
        /*! This flag indicates that on a masquerade, an active stream should not
         *  be carried over */
        AST_FLAG_MASQ_NOSTREAM = (1 << 16),
index 3fc3277..e39ee5d 100644 (file)
@@ -250,7 +250,6 @@ static void channel_data_add_flags(struct ast_data *tree,
        ast_data_add_bool(tree, "IN_DTMF", ast_test_flag(ast_channel_flags(chan), AST_FLAG_IN_DTMF));
        ast_data_add_bool(tree, "EMULATE_DTMF", ast_test_flag(ast_channel_flags(chan), AST_FLAG_EMULATE_DTMF));
        ast_data_add_bool(tree, "END_DTMF_ONLY", ast_test_flag(ast_channel_flags(chan), AST_FLAG_END_DTMF_ONLY));
-       ast_data_add_bool(tree, "ANSWERED_ELSEWHERE", ast_test_flag(ast_channel_flags(chan), AST_FLAG_ANSWERED_ELSEWHERE));
        ast_data_add_bool(tree, "MASQ_NOSTREAM", ast_test_flag(ast_channel_flags(chan), AST_FLAG_MASQ_NOSTREAM));
        ast_data_add_bool(tree, "BRIDGE_HANGUP_RUN", ast_test_flag(ast_channel_flags(chan), AST_FLAG_BRIDGE_HANGUP_RUN));
        ast_data_add_bool(tree, "BRIDGE_HANGUP_DONT", ast_test_flag(ast_channel_flags(chan), AST_FLAG_BRIDGE_HANGUP_DONT));
index 04bc532..21d6edc 100644 (file)
@@ -7690,8 +7690,8 @@ int ast_do_pickup(struct ast_channel *chan, struct ast_channel *target)
 
        ast_channel_queue_connected_line_update(chan, &connected_caller, NULL);
 
-       /* setting this flag to generate a reason header in the cancel message to the ringing channel */
-       ast_set_flag(ast_channel_flags(chan), AST_FLAG_ANSWERED_ELSEWHERE);
+       /* setting the HANGUPCAUSE so the ringing channel knows this call was not a missed call */
+       ast_channel_hangupcause_set(chan, AST_CAUSE_ANSWERED_ELSEWHERE);
 
        if (ast_channel_masquerade(target, chan)) {
                ast_log(LOG_WARNING, "Unable to masquerade '%s' into '%s'\n", chan_name,