]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
more cleanup from refactor of originate code
authorAnthony Minessale <anthony.minessale@gmail.com>
Mon, 19 Jan 2009 19:32:44 +0000 (19:32 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Mon, 19 Jan 2009 19:32:44 +0000 (19:32 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@11289 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/endpoints/mod_loopback/mod_loopback.c
src/switch_ivr_originate.c

index 639f6a1ae2ac35f6023ba8cef3d55ee0652f7a40..0e463b858bffda262a1db04ec075f18e6e08ef86 100644 (file)
@@ -50,7 +50,8 @@ typedef enum {
        TFLAG_WRITE = (1 << 2),
        TFLAG_CNG = (1 << 3),
        TFLAG_BRIDGE = (1 << 4),
-       TFLAG_BOWOUT = (1 << 5)
+       TFLAG_BOWOUT = (1 << 5),
+       TFLAG_BLEG = (1 << 6)
 } TFLAGS;
 
 struct private_object {
@@ -210,8 +211,8 @@ static switch_status_t channel_on_init(switch_core_session_t *session)
 
        channel = switch_core_session_get_channel(session);
        switch_assert(channel != NULL);
-
-       if (!switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) {
+       
+       if (switch_test_flag(tech_pvt, TFLAG_OUTBOUND) && !switch_test_flag(tech_pvt, TFLAG_BLEG)) {
                
                if (!(b_session = switch_core_session_request(loopback_endpoint_interface, NULL))) {
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failure.\n");
@@ -247,7 +248,8 @@ static switch_status_t channel_on_init(switch_core_session_t *session)
                
                switch_set_flag_locked(tech_pvt, TFLAG_LINKED);
                switch_set_flag_locked(b_tech_pvt, TFLAG_LINKED);
-               switch_set_flag_locked(b_tech_pvt, TFLAG_OUTBOUND);
+               switch_set_flag_locked(b_tech_pvt, TFLAG_BLEG);
+
                
                switch_channel_set_flag(channel, CF_ACCEPT_CNG);        
                //switch_ivr_transfer_variable(session, tech_pvt->other_session, "process_cdr");
@@ -608,17 +610,13 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s
        
        switch (msg->message_id) {
        case SWITCH_MESSAGE_INDICATE_ANSWER:
-               if (tech_pvt->other_channel) {
-                       if (switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) {
-                               switch_channel_mark_answered(tech_pvt->other_channel);
-                       }
+               if (tech_pvt->other_channel && !switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) {
+                       switch_channel_mark_answered(tech_pvt->other_channel);
                }
                break;
        case SWITCH_MESSAGE_INDICATE_PROGRESS:
-               if (tech_pvt->other_channel) {
-                       if (switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) {
-                               switch_channel_mark_pre_answered(tech_pvt->other_channel);
-                       }
+               if (tech_pvt->other_channel && !switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) {
+                       switch_channel_mark_pre_answered(tech_pvt->other_channel);
                }
                break;
        case SWITCH_MESSAGE_INDICATE_BRIDGE:
@@ -703,7 +701,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi
                        switch_snprintf(name, sizeof(name), "loopback/%s-a", caller_profile->destination_number);
                        switch_channel_set_name(channel, name);
                        switch_channel_set_flag(channel, CF_OUTBOUND);
-
+                       switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
                        switch_channel_set_caller_profile(channel, caller_profile);
                        tech_pvt->caller_profile = caller_profile;
                } else {
index 3138d1aae36e14b2eeb38f3811b2fe3bfc4b1edd..4f1de65e4de6737530cfccd05c1db891b9762faf 100644 (file)
@@ -560,7 +560,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_wait_for_answer(switch_core_session_t
                                message = NULL;
                        }
                }
-
+               
                if (switch_channel_media_ready(caller_channel)) {
                        status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
                        if (!SWITCH_READ_ACCEPTABLE(status)) {
@@ -569,8 +569,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_wait_for_answer(switch_core_session_t
                } else {
                        read_frame = NULL;
                }
-
+               
                if (read_frame && !pass) {
+
                        if (ringback.fh) {
                                switch_size_t mlen, olen;
                                unsigned int pos = 0;
@@ -711,7 +712,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
        switch_event_t *var_event = NULL;
        uint8_t fail_on_single_reject = 0;
        char *fail_on_single_reject_var = NULL;
-       uint8_t ring_ready = 0;
        char *loop_data = NULL;
        uint32_t progress_timelimit_sec = 0;
        uint32_t per_channel_timelimit_sec[MAX_PEERS] = { 0 };
@@ -941,7 +941,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
        }
 
        if ((var_val = switch_event_get_header(var_event, "ring_ready")) && switch_true(var_val)) {
-               ring_ready = 1;
+               oglobals.ring_ready = 1;
        }
 
        if ((var_val = switch_event_get_header(var_event, "originate_timeout"))) {
@@ -1471,7 +1471,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
 
                        while ((!caller_channel || switch_channel_ready(caller_channel)) && check_channel_status(&oglobals, originate_status, and_argc)) {
                                time_t elapsed = switch_timestamp(NULL) - start;
-                               if (caller_channel && !oglobals.sent_ring && ring_ready && !oglobals.return_ring_ready) {
+                               if (caller_channel && !oglobals.sent_ring && oglobals.ring_ready && !oglobals.return_ring_ready) {
                                        switch_channel_ring_ready(caller_channel);
                                        oglobals.sent_ring = 1;
                                }
@@ -1519,7 +1519,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
 
                                if (originate_status[0].peer_session
                                        && switch_core_session_dequeue_message(originate_status[0].peer_session, &message) == SWITCH_STATUS_SUCCESS) {
-                                       if (oglobals.session && !ringback_data && or_argc == 1 && and_argc == 1) {      /* when there is only 1 channel to call and bridge and no ringback */
+                                       if (oglobals.session && !ringback_data && or_argc == 1 && and_argc == 1) {      
+                                               /* when there is only 1 channel to call and bridge and no ringback */
                                                switch_core_session_receive_message(oglobals.session, message);
                                        }
 
@@ -1542,15 +1543,14 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
 
                                        if (switch_channel_media_ready(caller_channel)) {
                                                tstatus = switch_core_session_read_frame(oglobals.session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
-
                                                if (!SWITCH_READ_ACCEPTABLE(tstatus)) {
                                                        break;
                                                }
                                        } else {
                                                read_frame = NULL;
                                        }
-
-                                       if (ring_ready && read_frame && !pass) {
+                                       
+                                       if (oglobals.ring_ready && read_frame && !pass) {
                                                if (ringback.fh) {
                                                        switch_size_t mlen, olen;
                                                        unsigned int pos = 0;