Revision
15125
Author
anthm
Date
2009-10-08 19:52:25 -0500 (Thu, 08 Oct 2009)

Log Message

omfg

Modified Paths

Diff

Modified: freeswitch/trunk/src/mod/endpoints/mod_loopback/mod_loopback.c (15124 => 15125)


--- freeswitch/trunk/src/mod/endpoints/mod_loopback/mod_loopback.c	2009-10-09 00:49:50 UTC (rev 15124)
+++ freeswitch/trunk/src/mod/endpoints/mod_loopback/mod_loopback.c	2009-10-09 00:52:25 UTC (rev 15125)
@@ -314,6 +314,7 @@
 {
 	switch_channel_t *channel = NULL;
 	private_t *tech_pvt = NULL;
+	const char *app, *arg;
 
 	channel = switch_core_session_get_channel(session);
 	assert(channel != NULL);
@@ -324,6 +325,21 @@
 	do_reset(tech_pvt);
 
 	switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s CHANNEL ROUTING\n", switch_channel_get_name(channel));
+
+
+	if (!switch_test_flag(tech_pvt, TFLAG_OUTBOUND) && (app = switch_channel_get_variable(channel, "loopback_app"))) {
+		switch_caller_extension_t *extension = NULL;
+		arg = switch_channel_get_variable(channel, "loopback_app_arg");
+		extension = switch_caller_extension_new(session, app, app);
+		switch_caller_extension_add_application(session, extension, "pre_answer", NULL);
+		switch_caller_extension_add_application(session, extension, app, arg);
+		
+		switch_channel_set_caller_extension(channel, extension);
+		switch_channel_set_state(channel, CS_EXECUTE);
+		return SWITCH_STATUS_FALSE;
+	}
+
+
 	
 	return SWITCH_STATUS_SUCCESS;
 }
@@ -555,6 +571,7 @@
 		if (tech_pvt->write_frame) {
 			switch_frame_free(&tech_pvt->write_frame);
 		}
+
 		tech_pvt->write_frame = (switch_frame_t *) pop;
 		tech_pvt->write_frame->codec = &tech_pvt->read_codec;
 		*frame = tech_pvt->write_frame;
@@ -571,6 +588,7 @@
 		*frame = &tech_pvt->cng_frame;
 		tech_pvt->cng_frame.codec = &tech_pvt->read_codec;
 		tech_pvt->cng_frame.datalen = tech_pvt->read_codec.implementation->decoded_bytes_per_packet;
+
 		memset(tech_pvt->cng_frame.data, 0, tech_pvt->cng_frame.datalen);
 		memset(&data, 0, sizeof(data));
 
@@ -797,6 +815,23 @@
 
 			caller_profile = switch_caller_profile_clone(*new_session, outbound_profile);
 			caller_profile->source = switch_core_strdup(caller_profile->pool, modname);
+			if (!strncasecmp(caller_profile->destination_number, "app=", 4)) {
+				char *dest = switch_core_session_strdup(*new_session, caller_profile->destination_number);
+				char *app = dest + 4;
+				char *arg = NULL;
+
+				if ((arg = strchr(app, ':'))) {
+					*arg++ = '\0';
+				}
+
+				switch_channel_set_variable(channel, "loopback_app", app);
+				if (arg) {
+					switch_channel_set_variable(channel, "loopback_app_arg", arg);
+				}
+
+				caller_profile->destination_number = switch_core_strdup(caller_profile->pool, app);
+			}
+
 			if ((context = strchr(caller_profile->destination_number, '/'))) {
 				*context++ = '\0';
 				

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c (15124 => 15125)


--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c	2009-10-09 00:49:50 UTC (rev 15124)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c	2009-10-09 00:52:25 UTC (rev 15125)
@@ -4271,7 +4271,11 @@
 
 							switch_channel_set_variable(channel_b, SWITCH_HOLDING_UUID_VARIABLE, br_a);
 							switch_channel_set_flag(channel_b, CF_XFER_ZOMBIE);
+							switch_channel_set_flag(channel_b, CF_TRANSFER);
 
+							//switch_channel_set_variable(channel_b, "park_timeout", "2");
+							//switch_channel_set_state(channel_b, CS_PARK);
+							
 							if ((a_session = switch_core_session_locate(br_a))) {
 								const char *moh = profile->hold_music;
 								switch_channel_t *a_channel = switch_core_session_get_channel(a_session);
@@ -4284,21 +4288,40 @@
 								if (!strcasecmp(moh, "silence")) {
 									moh = NULL;
 								}
-
+								
 								//switch_channel_set_variable(a_channel, SWITCH_PARK_AFTER_BRIDGE_VARIABLE, "true");
+								
 								if (moh) {
-									switch_channel_set_variable_printf(a_channel, SWITCH_TRANSFER_AFTER_BRIDGE_VARIABLE, 
-																	   "'endless_playback:%s',park:inline", moh);
+									char *xdest;
+									//switch_channel_set_variable_printf(a_channel, SWITCH_TRANSFER_AFTER_BRIDGE_VARIABLE, 
+									//							   "'endless_playback:%s,park':inline", moh);
+									xdest = switch_core_session_sprintf(a_session, "endless_playback:%s,park", moh);
+									switch_ivr_session_transfer(a_session, xdest, "inline", NULL);
 								} else {
-									switch_channel_set_variable(a_channel, SWITCH_TRANSFER_AFTER_BRIDGE_VARIABLE, "park:inline");
+									//switch_channel_set_variable(a_channel, SWITCH_TRANSFER_AFTER_BRIDGE_VARIABLE, "park:inline");
+									switch_ivr_session_transfer(a_session, "park", "inline", NULL);
 								}
 								//switch_channel_set_variable_printf(a_channel, "park_command", "moh");
 								switch_core_session_rwunlock(a_session);
+
+								nua_notify(tech_pvt->nh, NUTAG_NEWSUB(1), SIPTAG_CONTENT_TYPE_STR("message/sipfrag"),
+										   NUTAG_SUBSTATE(nua_substate_terminated), SIPTAG_PAYLOAD_STR("SIP/2.0 200 OK"), SIPTAG_EVENT_STR(etmp), TAG_END());
+
+
+								if (0 && b_tech_pvt) {
+									sofia_set_flag_locked(b_tech_pvt, TFLAG_BYE);
+									nua_bye(b_tech_pvt->nh, 
+											SIPTAG_REASON_STR("Q.850;cause=16;text=\"normal_clearing\""),
+											TAG_IF(!switch_strlen_zero(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)),
+											TAG_END());
+								}
+							} else {
+								nua_notify(tech_pvt->nh, NUTAG_NEWSUB(1), SIPTAG_CONTENT_TYPE_STR("message/sipfrag"),
+										   NUTAG_SUBSTATE(nua_substate_terminated),
+										   SIPTAG_PAYLOAD_STR("SIP/2.0 403 Forbidden"), SIPTAG_EVENT_STR(etmp), TAG_END());
 							}
 
-							nua_notify(tech_pvt->nh, NUTAG_NEWSUB(1), SIPTAG_CONTENT_TYPE_STR("message/sipfrag"),
-									   NUTAG_SUBSTATE(nua_substate_terminated), SIPTAG_PAYLOAD_STR("SIP/2.0 200 OK"), SIPTAG_EVENT_STR(etmp), TAG_END());
-
+							
 							//switch_channel_set_variable(channel_b, "park_timeout", "2");
 							//switch_channel_set_state(channel_b, CS_PARK);
 							

Modified: freeswitch/trunk/src/switch_ivr.c (15124 => 15125)


--- freeswitch/trunk/src/switch_ivr.c	2009-10-09 00:49:50 UTC (rev 15124)
+++ freeswitch/trunk/src/switch_ivr.c	2009-10-09 00:52:25 UTC (rev 15125)
@@ -1283,6 +1283,9 @@
 		
 		if (switch_strlen_zero(dialplan)) {
 			dialplan = profile->dialplan;
+			if (!switch_strlen_zero(dialplan) && !strcasecmp(dialplan, "inline")) {
+				dialplan = NULL;
+			}
 		}
 
 		if (switch_strlen_zero(context)) {

Modified: freeswitch/trunk/src/switch_ivr_originate.c (15124 => 15125)


--- freeswitch/trunk/src/switch_ivr_originate.c	2009-10-09 00:49:50 UTC (rev 15124)
+++ freeswitch/trunk/src/switch_ivr_originate.c	2009-10-09 00:52:25 UTC (rev 15125)
@@ -364,6 +364,9 @@
 
 	if (oglobals->session) {
 		caller_channel = switch_core_session_get_channel(oglobals->session);
+		if (switch_channel_test_flag(caller_channel, CF_XFER_ZOMBIE)) {
+			caller_channel = NULL;
+		}
 	}
 	
 
@@ -1997,8 +2000,8 @@
 				}
 
 				if (caller_channel && switch_channel_get_state(caller_channel) != wait_state && !switch_channel_test_flag(caller_channel, CF_XFER_ZOMBIE)) {
-					oglobals.idx = IDX_NADA;
-                    goto notready;
+					//oglobals.idx = IDX_NADA;
+                    //goto notready;
 				}
 
 				if (!oglobals.sent_ring && !oglobals.progress && (progress_timelimit_sec && elapsed > (time_t) progress_timelimit_sec)) {
@@ -2162,10 +2165,6 @@
 				switch_core_session_reset(oglobals.session, SWITCH_FALSE, SWITCH_TRUE);
 			}
 
-			if ((oglobals.idx == IDX_TIMEOUT || oglobals.idx == IDX_KEY_CANCEL) && (caller_channel && switch_channel_ready(caller_channel))) {
-				holding = NULL;
-			}
-
 			if (holding) {
 				if (oglobals.idx > IDX_NADA) {
 					peer_session = originate_status[oglobals.idx].peer_session;
@@ -2202,26 +2201,62 @@
 
 			end_search:
 
+				if (peer_channel && (oglobals.idx == IDX_TIMEOUT || to || oglobals.idx == IDX_KEY_CANCEL || oglobals.idx == IDX_CANCEL)) {
+					const char *dest = switch_channel_get_variable(peer_channel, "destination_number");
+					const char *context = switch_channel_get_variable(peer_channel, "context");
+					const char *dialplan = switch_channel_get_variable(peer_channel, "dialplan");
+					switch_core_session_t *holding_session;
 
-				if (peer_channel && switch_channel_ready(peer_channel)) {
-					force_reason = SWITCH_CAUSE_ATTENDED_TRANSFER;
-					switch_ivr_uuid_bridge(holding, switch_core_session_get_uuid(peer_session));
-					oglobals.idx = IDX_NADA;
 					if (caller_channel) {
-						switch_channel_hangup(caller_channel, SWITCH_CAUSE_ATTENDED_TRANSFER);
+						if (switch_strlen_zero(context)) {
+							context = switch_channel_get_variable(caller_channel, "context"); 
+						}
+						if (switch_strlen_zero(dialplan)) {
+							dialplan = switch_channel_get_variable(caller_channel, "dialplan"); 
+						}
 					}
+					
+					if (switch_strlen_zero(context)) {
+						context = "default";
+					}
+
+					if (switch_strlen_zero(context)) {
+						dialplan = "XML";
+					}
+
+					if ((holding_session = switch_core_session_locate(holding))) {
+						switch_ivr_session_transfer(holding_session, dest, dialplan, context);
+						switch_core_session_rwunlock(holding_session);
+						holding = NULL;
+						holding_session = NULL;
+					}
+
+					switch_channel_hangup(peer_channel, SWITCH_CAUSE_ATTENDED_TRANSFER);
 					switch_core_session_rwunlock(peer_session);
 				} else {
-					switch_core_session_t *holding_session;
+					if (peer_channel && switch_channel_ready(peer_channel)) {
+						force_reason = SWITCH_CAUSE_ATTENDED_TRANSFER;
+						switch_ivr_uuid_bridge(holding, switch_core_session_get_uuid(peer_session));
+						oglobals.idx = IDX_NADA;
+						if (caller_channel && switch_channel_up(caller_channel)) {
+							switch_channel_hangup(caller_channel, SWITCH_CAUSE_ATTENDED_TRANSFER);
+						}
+						caller_channel = NULL;
+						oglobals.session = NULL;
+						session = NULL;
+						switch_core_session_rwunlock(peer_session);
+					} else {
+						switch_core_session_t *holding_session;
 
-					if ((holding_session = switch_core_session_locate(holding))) {
-						switch_channel_t *holding_channel = switch_core_session_get_channel(holding_session);
-						if (caller_channel && switch_channel_ready(caller_channel)) {
-							switch_ivr_uuid_bridge(holding, switch_core_session_get_uuid(session));
-						} else {
-							switch_channel_hangup(holding_channel, SWITCH_CAUSE_NORMAL_UNSPECIFIED);
+						if ((holding_session = switch_core_session_locate(holding))) {
+							switch_channel_t *holding_channel = switch_core_session_get_channel(holding_session);
+							if (caller_channel && switch_channel_ready(caller_channel)) {
+								switch_ivr_uuid_bridge(holding, switch_core_session_get_uuid(session));
+							} else {
+								switch_channel_hangup(holding_channel, SWITCH_CAUSE_NORMAL_UNSPECIFIED);
+							}
+							switch_core_session_rwunlock(holding_session);
 						}
-						switch_core_session_rwunlock(holding_session);
 					}
 				}
 
@@ -2229,8 +2264,7 @@
 				peer_channel = NULL;
 				
 			}
-
-
+			
 			for (i = 0; i < and_argc; i++) {
 				if (!peer_eligible(originate_status[i].peer_channel)) {
 					continue;