]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
consolidate code in conference into todays changes
authorAnthony Minessale <anthony.minessale@gmail.com>
Wed, 16 Aug 2006 00:35:02 +0000 (00:35 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Wed, 16 Aug 2006 00:35:02 +0000 (00:35 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@2303 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_ivr.h
src/mod/applications/mod_bridgecall/mod_bridgecall.c
src/mod/applications/mod_conference/mod_conference.c
src/switch_ivr.c

index b7ae95afd89aabde2f28bddb49e245b2e87bfc12..72840a4a4e94abbdda1b5e3a4e686ea42fd88d0c 100644 (file)
@@ -169,11 +169,17 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_speak_text(switch_core_session_t *ses
   \param session originating session
   \param bleg B leg session
   \param bridgeto the desired remote callstring
+  \param table optional state handler table to install on the channel
+  \param cid_name_override override the caller id name
+  \param cid_num_override override the caller id number
   \return SWITCH_STATUS_SUCCESS if bleg is a running session.
 */
-SWITCH_DECLARE(switch_status_t) switch_ivr_outcall(switch_core_session_t *session,
-                                                   switch_core_session_t **bleg,
-                                                   char *bridgeto);
+SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *session,
+                                                                                                        switch_core_session_t **bleg,
+                                                                                                        char *bridgeto,
+                                                                                                        const switch_state_handler_table_t *table,
+                                                                                                        char *cid_name_override,
+                                                                                                        char *cid_num_override);
 
 /*!
   \brief Bridge Audio from one session to another
index 3c8729b541155bcd52179645fba383af22a6e99f..c1e2f76a738caf492cf79121cadb300be164e751 100644 (file)
@@ -45,7 +45,7 @@ static void audio_bridge_function(switch_core_session_t *session, char *data)
        caller_channel = switch_core_session_get_channel(session);
        assert(caller_channel != NULL);
 
-       if (switch_ivr_outcall(session, &peer_session, data) != SWITCH_STATUS_SUCCESS) {
+       if (switch_ivr_originate(session, &peer_session, data, NULL, NULL, NULL) != SWITCH_STATUS_SUCCESS) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Create Outgoing Channel!\n");
                switch_channel_hangup(caller_channel, SWITCH_CAUSE_REQUESTED_CHAN_UNAVAIL);
                return;
index 3f61c5a9d3bb4e46951b8370c85510d1c830ace7..aeb0d74bd411b6b71cd83d1e00f619ea72a81d67 100644 (file)
@@ -1974,148 +1974,32 @@ static const switch_state_handler_table_t audio_bridge_peer_state_handlers = {
 static switch_status_t conference_outcall(conference_obj_t *conference, switch_core_session_t *session, char *bridgeto, char *cid_name, char *cid_num)
 {
        switch_core_session_t *peer_session;
-       switch_caller_profile_t *caller_profile, *caller_caller_profile;
-       char *chan_type, *chan_data;
-       unsigned int timelimit = 60;
        switch_channel_t *peer_channel;
-       time_t start;
-       switch_frame_t *read_frame = NULL;
        switch_status_t status = SWITCH_STATUS_SUCCESS;
        switch_channel_t *caller_channel = NULL;
 
-       chan_type = strdup(bridgeto);
-               
-       if ((chan_data = strchr(chan_type, '/')) != 0) {
-               *chan_data = '\0';
-               chan_data++;
-       }
-       
-       if (session) {
-               caller_channel = switch_core_session_get_channel(session);
-               assert(caller_channel != NULL);
-               caller_caller_profile = switch_channel_get_caller_profile(caller_channel);
-
-               if (!cid_name) {
-                       cid_name = caller_caller_profile->caller_id_name;
-               }
-
-               if (!cid_num) {
-                       cid_num = caller_caller_profile->caller_id_number;
-               }
-               
-               caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
-                                                                                                  caller_caller_profile->username,
-                                                                                                  caller_caller_profile->dialplan,
-                                                                                                  cid_name,
-                                                                                                  cid_num,
-                                                                                                  caller_caller_profile->network_addr, 
-                                                                                                  NULL, 
-                                                                                                  NULL, 
-                                                                                                  caller_caller_profile->rdnis,
-                                                                                                  caller_caller_profile->source,
-                                                                                                  caller_caller_profile->context,
-                                                                                                  chan_data);
-       } else {
 
-               if (!cid_name) {
-                       cid_name = conference->caller_id_name;
-               }
-
-               if (!cid_num) {
-                       cid_num = conference->caller_id_number;
-               }
-
-               caller_profile = switch_caller_profile_new(conference->pool,
-                                                                                                  NULL,
-                                                                                                  NULL,
-                                                                                                  cid_name,
-                                                                                                  cid_num,
-                                                                                                  NULL,
-                                                                                                  NULL, 
-                                                                                                  NULL, 
-                                                                                                  NULL,
-                                                                                                  (char *) global_app_name,
-                                                                                                  NULL,
-                                                                                                  chan_data);
-       }
-
-
-
-       if (switch_core_session_outgoing_channel(session, chan_type, caller_profile, &peer_session, NULL) !=
-               SWITCH_STATUS_SUCCESS) {
+       if (switch_ivr_originate(session, &peer_session, bridgeto, &audio_bridge_peer_state_handlers, cid_name, cid_num) != SWITCH_STATUS_SUCCESS) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Create Outgoing Channel!\n");
-               if (caller_channel) {
+               if (session) {
+                       caller_channel = switch_core_session_get_channel(session);
                        switch_channel_hangup(caller_channel, SWITCH_CAUSE_REQUESTED_CHAN_UNAVAIL);
                }
-               status = SWITCH_STATUS_FALSE;
                goto done;
        } 
 
+
+       switch_core_session_rwunlock(peer_session);
        peer_channel = switch_core_session_get_channel(peer_session);
        assert(peer_channel != NULL);
-               
-       switch_channel_add_state_handler(peer_channel, &audio_bridge_peer_state_handlers);
-
-       if (switch_core_session_runing(peer_session)) {
-               switch_channel_set_state(peer_channel, CS_RING);
-       } else {
-               switch_core_session_thread_launch(peer_session);
-       }
-
-       time(&start);
-
-       for (;;) {
-               int state = switch_channel_get_state(peer_channel);
-               if (state >= CS_RING) {
-                       break;
-               }
-               
-               if (caller_channel && !switch_channel_ready(caller_channel)) {
-                       break;
-               }
-               
-               if ((time(NULL) - start) > (time_t)timelimit) {
-                       break;
-               }
-               switch_yield(1000);
-       }
-
-       if (caller_channel) {
-               switch_channel_pre_answer(caller_channel);
-       }
-
-       while ((!caller_channel || switch_channel_ready(caller_channel)) &&
-                  !switch_channel_test_flag(peer_channel, CF_ANSWERED) &&
-                  !switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA) &&
-                  ((time(NULL) - start) < (time_t)timelimit)) {
-               
-               /* read from the channel while we wait if the audio is up on it */
-               if (session && (switch_channel_test_flag(caller_channel, CF_ANSWERED) || switch_channel_test_flag(caller_channel, CF_EARLY_MEDIA))) {
-                       switch_status_t status = switch_core_session_read_frame(session, &read_frame, 1000, 0);
-                       
-                       if (!SWITCH_READ_ACCEPTABLE(status)) {
-                               break;
-                       }
-                       if (read_frame) {
-                               if (switch_core_session_write_frame(session, read_frame, 1000, 0) != SWITCH_STATUS_SUCCESS) {
-                                       break;
-                               }
-                       }
-
-               } else {
-                       switch_yield(1000);
-               }
-
-       }
-
+       
        if (caller_channel && switch_channel_test_flag(peer_channel, CF_ANSWERED)) {
                switch_channel_answer(caller_channel);
        }
 
        if (switch_channel_test_flag(peer_channel, CF_ANSWERED) || switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA)) {
                switch_caller_extension_t *extension = NULL;
-               if ((extension = switch_caller_extension_new(peer_session, caller_profile->destination_number,
-                                                                                                        caller_profile->destination_number)) == 0) {
+               if ((extension = switch_caller_extension_new(peer_session, conference->name, conference->name)) == 0) {
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "memory error!\n");
                        status = SWITCH_STATUS_MEMERR;
                        goto done;
@@ -2132,7 +2016,6 @@ static switch_status_t conference_outcall(conference_obj_t *conference, switch_c
        }
 
  done:
-       free(chan_type);
        return status;
 }
 
index 80b2aacf0e7db0eb314f77cc61880ef354b815f2..cbb449d1def3a37059e5fe1cdf4be9c2c9e952c4 100644 (file)
@@ -1142,9 +1142,12 @@ static const switch_state_handler_table_t audio_bridge_peer_state_handlers = {
 
 
 
-SWITCH_DECLARE(switch_status_t) switch_ivr_outcall(switch_core_session_t *session,
-                                                                                                  switch_core_session_t **bleg,
-                                                                                                  char *bridgeto)
+SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *session,
+                                                                                                        switch_core_session_t **bleg,
+                                                                                                        char *bridgeto,
+                                                                                                        const switch_state_handler_table_t *table,
+                                                                                                        char *cid_name_override,
+                                                                                                        char *cid_num_override)
                                                                                  
 {
        switch_core_session_t *peer_session;
@@ -1170,12 +1173,18 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_outcall(switch_core_session_t *sessio
                assert(caller_channel != NULL);
                caller_caller_profile = switch_channel_get_caller_profile(caller_channel);
 
+               if (!cid_name_override) {
+                       cid_name_override = caller_caller_profile->caller_id_name;
+               }
+               if (!cid_num_override) {
+                       cid_num_override = caller_caller_profile->caller_id_number;
+               }
 
                caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
                                                                                                   caller_caller_profile->username,
                                                                                                   caller_caller_profile->dialplan,
-                                                                                                  caller_caller_profile->caller_id_name,
-                                                                                                  caller_caller_profile->caller_id_number,
+                                                                                                  cid_name_override,
+                                                                                                  cid_num_override,
                                                                                                   caller_caller_profile->network_addr, 
                                                                                                   NULL,
                                                                                                   NULL, 
@@ -1184,12 +1193,17 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_outcall(switch_core_session_t *sessio
                                                                                                   caller_caller_profile->context,
                                                                                                   chan_data);
        } else {
-
+               if (!cid_name_override) {
+                       cid_name_override = "FreeSWITCH";
+               }
+               if (!cid_num_override) {
+                       cid_num_override = "0000000000";
+               }
                caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
                                                                                                   NULL,
                                                                                                   NULL,
-                                                                                                  "FreeSWITCH",
-                                                                                                  "0000000000",
+                                                                                                  cid_name_override,
+                                                                                                  cid_num_override,
                                                                                                   NULL,
                                                                                                   NULL, 
                                                                                                   NULL, 
@@ -1212,7 +1226,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_outcall(switch_core_session_t *sessio
        peer_channel = switch_core_session_get_channel(peer_session);
        assert(peer_channel != NULL);
                
-       switch_channel_add_state_handler(peer_channel, &audio_bridge_peer_state_handlers);
+       if (!table) {
+               table = &audio_bridge_peer_state_handlers;
+       }
+
+       switch_channel_add_state_handler(peer_channel, table);
 
        if (switch_core_session_runing(peer_session)) {
                switch_channel_set_state(peer_channel, CS_RING);
@@ -1246,7 +1264,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_outcall(switch_core_session_t *sessio
                   !switch_channel_test_flag(peer_channel, CF_ANSWERED) &&
                   !switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA) &&
                   ((time(NULL) - start) < (time_t)timelimit)) {
-               
+
                /* read from the channel while we wait if the audio is up on it */
                if (session && (switch_channel_test_flag(caller_channel, CF_ANSWERED) || switch_channel_test_flag(caller_channel, CF_EARLY_MEDIA))) {
                        switch_status_t status = switch_core_session_read_frame(session, &read_frame, 1000, 0);
@@ -1263,7 +1281,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_outcall(switch_core_session_t *sessio
                } else {
                        switch_yield(1000);
                }
-
+               
        }
 
        if (caller_channel && switch_channel_test_flag(peer_channel, CF_ANSWERED)) {
@@ -1278,6 +1296,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_outcall(switch_core_session_t *sessio
                status = SWITCH_STATUS_FALSE;
        }
 
+
  done:
        free(chan_type);
        return status;