[Freeswitch-svn] [commit] r2303 - in freeswitch/trunk/src: . include mod/applications/mod_bridgecall mod/applications/mod_conference

Freeswitch SVN anthm at freeswitch.org
Tue Aug 15 20:35:03 EDT 2006


Author: anthm
Date: Tue Aug 15 20:35:02 2006
New Revision: 2303

Modified:
   freeswitch/trunk/src/include/switch_ivr.h
   freeswitch/trunk/src/mod/applications/mod_bridgecall/mod_bridgecall.c
   freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c
   freeswitch/trunk/src/switch_ivr.c

Log:
consolidate code in conference into todays changes

Modified: freeswitch/trunk/src/include/switch_ivr.h
==============================================================================
--- freeswitch/trunk/src/include/switch_ivr.h	(original)
+++ freeswitch/trunk/src/include/switch_ivr.h	Tue Aug 15 20:35:02 2006
@@ -169,11 +169,17 @@
   \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

Modified: freeswitch/trunk/src/mod/applications/mod_bridgecall/mod_bridgecall.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_bridgecall/mod_bridgecall.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_bridgecall/mod_bridgecall.c	Tue Aug 15 20:35:02 2006
@@ -45,7 +45,7 @@
 	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;

Modified: freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c	Tue Aug 15 20:35:02 2006
@@ -1974,148 +1974,32 @@
 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 @@
 	}
 
  done:
-	free(chan_type);
 	return status;
 }
 

Modified: freeswitch/trunk/src/switch_ivr.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr.c	(original)
+++ freeswitch/trunk/src/switch_ivr.c	Tue Aug 15 20:35:02 2006
@@ -1142,9 +1142,12 @@
 
 
 
-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 @@
 		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 @@
 												   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,8 +1226,12 @@
 	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);
 	} else {
@@ -1246,7 +1264,7 @@
 		   !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 @@
 		} else {
 			switch_yield(1000);
 		}
-
+		
 	}
 
 	if (caller_channel && switch_channel_test_flag(peer_channel, CF_ANSWERED)) {
@@ -1277,6 +1295,7 @@
 		switch_channel_hangup(peer_channel, SWITCH_CAUSE_NO_ANSWER);
 		status = SWITCH_STATUS_FALSE;
 	}
+
 
  done:
 	free(chan_type);



More information about the Freeswitch-svn mailing list