From 46810f58d3a3beb1c2d37ca8bfa1280ce4168b45 Mon Sep 17 00:00:00 2001
From: Anthony Minessale <anthm@freeswitch.org>
Date: Tue, 27 Mar 2012 13:08:49 -0500
Subject: [PATCH] FS-4049 try this

---
 src/include/switch_types.h |  3 ++-
 src/switch_ivr_originate.c | 10 +++++++++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/include/switch_types.h b/src/include/switch_types.h
index 004b67c727..5fd3a43a27 100644
--- a/src/include/switch_types.h
+++ b/src/include/switch_types.h
@@ -272,7 +272,8 @@ typedef enum {
 	SOF_FORKED_DIAL = (1 << 1),
 	SOF_NO_EFFECTIVE_CID_NUM = (1 << 2),
 	SOF_NO_EFFECTIVE_CID_NAME = (1 << 3),
-	SOF_NO_LIMITS = (1 << 4)
+	SOF_NO_LIMITS = (1 << 4),
+	SOF_ENTERPRISE = (1 << 5)
 } switch_originate_flag_enum_t;
 typedef uint32_t switch_originate_flag_t;
 
diff --git a/src/switch_ivr_originate.c b/src/switch_ivr_originate.c
index 6f5752641a..5e715f0ab2 100644
--- a/src/switch_ivr_originate.c
+++ b/src/switch_ivr_originate.c
@@ -1280,7 +1280,9 @@ static void *SWITCH_THREAD_FUNC enterprise_originate_thread(switch_thread_t *thr
 	enterprise_originate_handle_t *handle = (enterprise_originate_handle_t *) obj;
 
 	handle->done = 0;
-	handle->status = switch_ivr_originate(NULL, &handle->bleg, &handle->cause,
+	handle->flags |= SOF_ENTERPRISE;
+
+	handle->status = switch_ivr_originate(handle->session, &handle->bleg, &handle->cause,
 										  handle->bridgeto, handle->timelimit_sec,
 										  handle->table,
 										  handle->cid_name_override,
@@ -2709,6 +2711,12 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
 				soft_holding = switch_channel_get_variable(caller_channel, SWITCH_SOFT_HOLDING_UUID_VARIABLE);
 			}
 
+			if ((flags & SOF_ENTERPRISE)) {
+				session = oglobals.session = NULL;
+				caller_channel = NULL;
+			}
+
+
 			while ((!caller_channel || switch_channel_ready(caller_channel) || switch_channel_test_flag(caller_channel, CF_XFER_ZOMBIE)) &&
 				   check_channel_status(&oglobals, originate_status, and_argc)) {
 				time_t elapsed = switch_epoch_time_now(NULL) - start;