diff --git a/Makefile.am b/Makefile.am
index 4f6f4c2bdd..f1e98e05e1 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -202,6 +202,7 @@ library_include_HEADERS = \
 	src/include/switch_xml_config.h \
 	src/include/switch_cpp.h \
 	src/include/switch_json.h \
+	libs/stfu/stfu.h \
 	libs/libteletone/src/libteletone_detect.h \
 	libs/libteletone/src/libteletone_generate.h \
 	libs/libteletone/src/libteletone.h \
diff --git a/conf/vanilla/autoload_configs/java.conf.xml b/conf/vanilla/autoload_configs/java.conf.xml
index 3d1a3b5e5b..5f71553e30 100644
--- a/conf/vanilla/autoload_configs/java.conf.xml
+++ b/conf/vanilla/autoload_configs/java.conf.xml
@@ -1,13 +1,8 @@
 <configuration name="java.conf" description="Java Plug-Ins">
-  <!-- Path to the Java 1.6 virtual machine to use -->
-  <javavm path="/usr/java/jdk1.6.0/jre/lib/i386/client/libjvm.so"/>
-  <!-- Options to pass to Java -->
+  <javavm path="/opt/jdk1.6.0_04/jre/lib/amd64/server/libjvm.so"/>
   <options>
-    <!-- Your class path (make sure freeswitch.jar is on it) -->
-    <option value="-Djava.class.path=$${base_dir}/scripts/freeswitch.jar"/>
-    <!-- Enable remote debugging -->
-    <option value="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=127.0.0.1:8000"/>
+    <option value="-Djava.class.path=$${base_dir}/scripts/freeswitch.jar:$${base_dir}/scripts/example.jar"/>
+    <option value="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:8000"/>
   </options>
-  <startup class="net/cog/fs/system/Control" method="startup" arg="start up arg"/>
-  <shutdown class="net/cog/fs/system/Control" method="shutdown" arg="shutdown arg"/>
+  <startup class="org/freeswitch/example/ApplicationLauncher" method="startup"/>
 </configuration>
diff --git a/configure.in b/configure.in
index 44b3ad3635..b2f62e53ed 100644
--- a/configure.in
+++ b/configure.in
@@ -155,8 +155,8 @@ fi
 AX_PATH_LIBGNUTLS()
 
 # set defaults for use on all platforms
-SWITCH_AM_CFLAGS="-I${switch_srcdir}/src/include -I${switch_builddir}/src/include -I${switch_srcdir}/libs/libteletone/src"
-SWITCH_AM_CXXFLAGS="-I${switch_srcdir}/src/include -I${switch_builddir}/src/include -I${switch_srcdir}/libs/libteletone/src"
+SWITCH_AM_CFLAGS="-I${switch_srcdir}/src/include -I${switch_builddir}/src/include -I${switch_srcdir}/libs/libteletone/src -I${switch_srcdir}/libs/stfu"
+SWITCH_AM_CXXFLAGS="-I${switch_srcdir}/src/include -I${switch_builddir}/src/include -I${switch_srcdir}/libs/libteletone/src -I${switch_srcdir}/libs/stfu"
 SWITCH_AM_LDFLAGS="-lm"
 
 #set SOLINK variable based on compiler and host
@@ -164,7 +164,7 @@ if test "x${ax_cv_c_compiler_vendor}"  =  "xsun" ; then
     SOLINK="-Bdynamic -dy -G"
 elif test "x${ax_cv_c_compiler_vendor}" = "xgnu" ; then
     case "$host" in
-        *darwin10.*)
+        *darwin12.*|*darwin10.*)
             SOLINK="-dynamic -force-flat-namespace"
         ;;
         *darwin*)
@@ -248,7 +248,7 @@ elif test "x${ax_cv_c_compiler_vendor}" = "xgnu" ; then
     APR_ADDTO(SWITCH_AM_CFLAGS, -Werror)
     if test "${enable_64}" = "yes"; then
 	case "$host" in
-             *darwin10.*|*darwin9.*|*darwin8.*)
+             *darwin12.*|*darwin10.*|*darwin9.*|*darwin8.*)
 		APR_ADDTO(CFLAGS, -arch x86_64)
        		APR_ADDTO(LDFLAGS, -arch x86_64)
        		APR_ADDTO(CXXFLAGS, -arch x86_64)
@@ -425,6 +425,13 @@ fi
 
 fi
 
+AC_ARG_ENABLE(deprecated-core-db-events,
+	[AS_HELP_STRING([--enable-deprecated-core-db-events], [Keep deprecated core db events])],,[enable_deprecated_core_db_events="no"])
+
+if test x"$enable_deprecated_core_db_events" = x"yes" ; then
+        AC_DEFINE([SWITCH_DEPRECATED_CORE_DB], [1], [Define to 1 to enable deprecated core db events])
+fi
+
 AC_ARG_ENABLE(timerfd-wrapper,
 [AC_HELP_STRING([--enable-timerfd-wrapper],[timerfd is in the kernel but not in your libc])],[enable_timer_fd_wrapper="$enableval"],[enable_timer_fd_wrapper="no"])
 AM_CONDITIONAL([ENABLE_TIMERFD_WRAPPER],[test "x$enable_timer_fd_wrapper" != "xno"])
@@ -447,6 +454,17 @@ PLATFORM_CORE_LDFLAGS=
 PLATFORM_CORE_LIBS=
 # tweak platform specific flags
 case "$host" in
+    *darwin12.*)
+        APR_ADDTO(SWITCH_AM_CFLAGS, -DMACOSX)
+        APR_ADDTO(CFLAGS, -pipe -no-cpp-precomp -Wno-deprecated-declarations)
+        APR_ADDTO(LDFLAGS, -pipe -bind_at_load)
+        APR_ADDTO(CXXFLAGS, -pipe)
+        APR_REMOVEFROM(SWITCH_AM_CFLAGS, -fPIC)
+	if test "x$enable_core_odbc_support" != "xno"; then
+	        APR_ADDTO([PLATFORM_CORE_LDFLAGS], [--framework CoreFoundation])
+	fi
+	APR_ADDTO([PLATFORM_CORE_LIBS], [-ldl])
+    ;;
     *darwin10.*)
         APR_ADDTO(SWITCH_AM_CFLAGS, -DMACOSX)
         APR_ADDTO(CFLAGS, -pipe -no-cpp-precomp)
diff --git a/debian/bootstrap.sh b/debian/bootstrap.sh
index 9b3e9687fd..5307b25573 100755
--- a/debian/bootstrap.sh
+++ b/debian/bootstrap.sh
@@ -176,7 +176,7 @@ Build-Depends:
  wget, pkg-config,
 # configure options
  libssl-dev, unixodbc-dev,
- libncurses5-dev, libjpeg62-dev,
+ libncurses5-dev, libjpeg62-dev | libjpeg8-dev,
  python-dev, erlang-dev,
 # documentation
  doxygen,
diff --git a/debian/control-modules b/debian/control-modules
index b9f0a5772a..1787a81389 100644
--- a/debian/control-modules
+++ b/debian/control-modules
@@ -384,7 +384,7 @@ Build-Depends: libx11-dev
 Module: endpoints/mod_h323
 Description: mod_h323
  Adds mod_h323.
-Build-Depends: libopenh323-dev, libpt-dev
+Build-Depends: libopenh323-dev | libh323plus-dev, libpt-dev
 
 Module: endpoints/mod_html5
 Description: HTML5 endpoint module
diff --git a/docs/phrase/phrase_en.xml b/docs/phrase/phrase_en.xml
index c9fa47ec59..cb25bcb141 100644
--- a/docs/phrase/phrase_en.xml
+++ b/docs/phrase/phrase_en.xml
@@ -511,7 +511,7 @@
       <prompt phrase="There is..." filename="ivr-there_is.wav"/>
       <prompt phrase="That number is on the Do Not Call list." filename="ivr-do_not_call_list.wav"/>
       <prompt phrase="The call attempt has been aborted." filename="ivr-call_attempt_aborted.wav"/>
-      <prompt phrase="To wait for the next available representative, please stay on the line." filename="ivr_to_wait_stay_on_the_line.wav"/>
+      <prompt phrase="To wait for the next available representative, please stay on the line." filename="ivr-to_wait_stay_on_the_line.wav"/>
       <prompt phrase="If you would like us to call you back, press..." filename="ivr-if_you_would_like_us_to_call_back.wav"/>
       <prompt phrase="It appears that your phone number is..." filename="ivr-it_appears_that_your_phone_number_is.wav"/>
       <prompt phrase="Would you like to receive a call at this number?" filename="ivr-would_you_like_to_receive_a_call_at_this_number.wav"/>
diff --git a/libs/freetdm/src/ftdm_io.c b/libs/freetdm/src/ftdm_io.c
index 932ce30aa7..8e6db56af4 100644
--- a/libs/freetdm/src/ftdm_io.c
+++ b/libs/freetdm/src/ftdm_io.c
@@ -6093,7 +6093,7 @@ FT_DECLARE(ftdm_status_t) ftdm_span_send_signal(ftdm_span_t *span, ftdm_sigmsg_t
 
 	case FTDM_SIGEVENT_START:
 		{
-			ftdm_assert(!ftdm_test_flag(fchan, FTDM_CHANNEL_CALL_STARTED), "Started call twice!");
+			ftdm_assert(!ftdm_test_flag(fchan, FTDM_CHANNEL_CALL_STARTED), "Started call twice!\n");
 
 			if (ftdm_test_flag(fchan, FTDM_CHANNEL_OUTBOUND)) {
 				ftdm_log_chan_msg(fchan, FTDM_LOG_WARNING, "Inbound call taking over outbound channel\n");
diff --git a/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.c b/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.c
index 3b819df718..2f1a5ff9ed 100644
--- a/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.c
+++ b/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.c
@@ -974,7 +974,13 @@ static ftdm_status_t state_advance(ftdm_channel_t *chan)
 					ftdm_set_state_locked(chan, FTDM_CHANNEL_STATE_HANGUP);
 				}
 			} else if (call) {
-				pri_progress(isdn_data->spri.pri, call, ftdm_channel_get_id(chan), 0);
+				/*
+				 * Even if we have no media, sending progress without PI is forbidden
+				 * by Q.931 3.1.8, so a protocol error will be issued from libpri
+				 * and from remote equipment.
+				 * So just pretend we have PI.
+				 */
+				pri_progress(isdn_data->spri.pri, call, ftdm_channel_get_id(chan), 1);
 			} else {
 				ftdm_set_state_locked(chan, FTDM_CHANNEL_STATE_RESTART);
 			}
diff --git a/libs/freetdm/src/ftmod/ftmod_pritap/ftmod_pritap.c b/libs/freetdm/src/ftmod/ftmod_pritap/ftmod_pritap.c
index f136d59d9c..75d8b2a81c 100644
--- a/libs/freetdm/src/ftmod/ftmod_pritap/ftmod_pritap.c
+++ b/libs/freetdm/src/ftmod/ftmod_pritap/ftmod_pritap.c
@@ -38,8 +38,11 @@
 #define PRI_SPAN(p) (((p) >> 8) & 0xff)
 #define PRI_CHANNEL(p) ((p) & 0xff)
 
+#define PRITAP_NETWORK_ANSWER 0x1
+
 typedef enum {
 	PRITAP_RUNNING = (1 << 0),
+	PRITAP_MASTER = (1 << 1),
 } pritap_flags_t;
 
 typedef struct {
@@ -49,10 +52,16 @@ typedef struct {
 	ftdm_number_t callednum;
 	ftdm_channel_t *fchan;
 	char callingname[80];
-	int proceeding:1;
-	int inuse:1;
+	uint8_t proceeding;
+	uint8_t inuse;
 } passive_call_t;
 
+typedef enum pritap_iface {
+	PRITAP_IFACE_UNKNOWN = 0,
+	PRITAP_IFACE_CPE = 1,
+	PRITAP_IFACE_NET = 2,
+} pritap_iface_t;
+
 typedef struct pritap {
 	int32_t flags;
 	struct pri *pri;
@@ -63,6 +72,7 @@ typedef struct pritap {
 	ftdm_span_t *peerspan;
 	ftdm_mutex_t *pcalls_lock;
 	passive_call_t pcalls[FTDM_MAX_CHANNELS_PHYSICAL_SPAN];
+	pritap_iface_t iface;
 } pritap_t;
 
 static FIO_IO_UNLOAD_FUNCTION(ftdm_pritap_unload)
@@ -266,11 +276,14 @@ static ftdm_state_map_t pritap_state_map = {
 	}
 };
 
+#define PRITAP_GET_INTERFACE(iface) iface == PRITAP_IFACE_CPE ? "CPE" :  \
+                                    iface == PRITAP_IFACE_NET ? "NET" : "UNKNOWN"
 static ftdm_status_t state_advance(ftdm_channel_t *ftdmchan)
 {
 	ftdm_status_t status;
 	ftdm_sigmsg_t sig;
-	ftdm_channel_t *peerchan = ftdmchan->call_data;
+	pritap_t *pritap = ftdmchan->span->signal_data;
+	pritap_t *peer_pritap = pritap->peerspan->signal_data;
 	
 	ftdm_log_chan(ftdmchan, FTDM_LOG_DEBUG, "processing state %s\n", ftdm_channel_state2str(ftdmchan->state));
 
@@ -279,28 +292,56 @@ static ftdm_status_t state_advance(ftdm_channel_t *ftdmchan)
 	sig.span_id = ftdmchan->span_id;
 	sig.channel = ftdmchan;
 
-        ftdm_channel_complete_state(ftdmchan);
+	ftdm_channel_complete_state(ftdmchan);
 
 	switch (ftdmchan->state) {
 	case FTDM_CHANNEL_STATE_DOWN:
 		{			
-			ftdmchan->call_data = NULL;
-			ftdm_channel_close(&ftdmchan);
+			ftdm_channel_t *fchan = ftdmchan;
 
-			peerchan->call_data = NULL;
-			ftdm_channel_close(&peerchan);
+			/* Destroy the peer data first */
+			if (fchan->call_data) {
+				ftdm_channel_t *peerchan = fchan->call_data;
+				ftdm_channel_t *pchan = peerchan;
+
+				ftdm_channel_lock(peerchan);
+
+				pchan->call_data = NULL;
+				pchan->pflags = 0;
+				ftdm_channel_close(&pchan);
+
+				ftdm_channel_unlock(peerchan);
+			} else {
+				ftdm_log_chan_msg(ftdmchan, FTDM_LOG_CRIT, "No call data?\n");
+			}
+
+			ftdmchan->call_data = NULL;
+			ftdmchan->pflags = 0;
+			ftdm_channel_close(&fchan);
 		}
 		break;
 
 	case FTDM_CHANNEL_STATE_PROGRESS:
 	case FTDM_CHANNEL_STATE_PROGRESS_MEDIA:
-	case FTDM_CHANNEL_STATE_UP:
 	case FTDM_CHANNEL_STATE_HANGUP:
 		break;
 
+	case FTDM_CHANNEL_STATE_UP:
+		{
+			if (ftdm_test_pflag(ftdmchan, PRITAP_NETWORK_ANSWER)) {
+				ftdm_clear_pflag(ftdmchan, PRITAP_NETWORK_ANSWER);
+				sig.event_id = FTDM_SIGEVENT_UP;
+				ftdm_span_send_signal(ftdmchan->span, &sig);
+			}
+		}
+		break;
+
 	case FTDM_CHANNEL_STATE_RING:
 		{
 			sig.event_id = FTDM_SIGEVENT_START;
+			/* The ring interface (where the setup was received) is the peer, since we RING the channel
+			 * where PROCEED/PROGRESS is received */
+			ftdm_sigmsg_add_var(&sig, "pritap_ring_interface", PRITAP_GET_INTERFACE(peer_pritap->iface));
 			if ((status = ftdm_span_send_signal(ftdmchan->span, &sig) != FTDM_SUCCESS)) {
 				ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP);
 			}
@@ -333,9 +374,9 @@ static __inline__ void pritap_check_state(ftdm_span_t *span)
 		uint32_t j;
 		ftdm_clear_flag_locked(span, FTDM_SPAN_STATE_CHANGE);
 		for(j = 1; j <= span->chan_count; j++) {
-			ftdm_mutex_lock(span->channels[j]->mutex);
+			ftdm_channel_lock(span->channels[j]);
 			ftdm_channel_advance_states(span->channels[j]);
-			ftdm_mutex_unlock(span->channels[j]->mutex);
+			ftdm_channel_unlock(span->channels[j]);
 		}
 	}
 }
@@ -397,23 +438,47 @@ static passive_call_t *tap_pri_get_pcall_bycrv(pritap_t *pritap, int crv)
 	for (i = 0; i < ftdm_array_len(pritap->pcalls); i++) {
 		tstcrv = pritap->pcalls[i].callref ? tap_pri_get_crv(pritap->pri, pritap->pcalls[i].callref) : 0;
 		if (pritap->pcalls[i].callref && tstcrv == crv) {
-			if (!pritap->pcalls[i].inuse) {
-				ftdm_log(FTDM_LOG_ERROR, "Found crv %d in slot %d of span %s with call %p but is no longer in use!\n", 
-						crv, i, pritap->span->name, pritap->pcalls[i].callref);
-				continue;
+			if (pritap->pcalls[i].inuse) {
+				ftdm_mutex_unlock(pritap->pcalls_lock);
+				return &pritap->pcalls[i];
 			}
-
-			ftdm_mutex_unlock(pritap->pcalls_lock);
-
-			return &pritap->pcalls[i];
+			/* This just means the crv is being re-used in another call before this one was destroyed */
+			ftdm_log(FTDM_LOG_DEBUG, "Found crv %d in slot %d of span %s with call %p but is no longer in use\n",
+					crv, i, pritap->span->name, pritap->pcalls[i].callref);
 		}
 	}
 
+	ftdm_log(FTDM_LOG_DEBUG, "crv %d was not found active in span %s\n", crv, pritap->span->name);
+
 	ftdm_mutex_unlock(pritap->pcalls_lock);
 
 	return NULL;
 }
 
+/*
+ * This is a tricky function with some side effects, some explanation needed ...
+ *
+ * The libpri stack process HDLC frames, then finds Q921 frames and Q931 events, each time
+ * it finds a new Q931 event, checks if the crv of that event matches a known call in the internal
+ * list found in the PRI control block (for us, one control block per span), if it does not find
+ * the call, allocates a new one and then sends the event up to the user (us, ftmod_pritap in this case)
+ *
+ * The user is then expected to destroy the call when done with it (on hangup), but things get tricky here
+ * because in ftmod_pritap we do not destroy the call right away to be sure we only destroy it when no one
+ * else needs that pointer, therefore we decide to delay the destruction of the call pointer until later
+ * when a new call comes which triggers the garbage collecting code in this function
+ *
+ * Now, what happens if a new call arrives right away with the same crv than the last call? the pri stack
+ * does *not* allocate a new call pointer because is still a known call and we must therefore re-use the
+ * same call pointer
+ *
+ * This function accepts a pointer to a callref, even a NULL one. When callref is NULL we search for an
+ * available slot so the caller of this function can use it to store a new callref pointer. In the process
+ * we also scan for slots that still have a callref pointer but are no longer in use (inuse=0) and we
+ * destroy that callref and clear the slot (memset). The trick is, we only do this if the callref to
+ * be garbage collected is NOT the one provided by the parameter callref, of course! otherwise we may
+ * be freeing a pointer to a callref for a new call that used an old (recycled) callref!
+ */
 static passive_call_t *tap_pri_get_pcall(pritap_t *pritap, void *callref)
 {
 	int i;
@@ -422,7 +487,11 @@ static passive_call_t *tap_pri_get_pcall(pritap_t *pritap, void *callref)
 	ftdm_mutex_lock(pritap->pcalls_lock);
 
 	for (i = 0; i < ftdm_array_len(pritap->pcalls); i++) {
-		if (pritap->pcalls[i].callref && !pritap->pcalls[i].inuse) {
+		/* If this slot has a call reference
+		 * and it is different than the *callref provided to us
+		 * and is no longer in use,
+		 * then it is time to garbage collect it ... */
+		if (pritap->pcalls[i].callref  && callref != pritap->pcalls[i].callref && !pritap->pcalls[i].inuse) {
 			crv = tap_pri_get_crv(pritap->pri, pritap->pcalls[i].callref);
 			/* garbage collection */
 			ftdm_log(FTDM_LOG_DEBUG, "Garbage collecting callref %d/%p from span %s in slot %d\n", 
@@ -431,7 +500,17 @@ static passive_call_t *tap_pri_get_pcall(pritap_t *pritap, void *callref)
 			memset(&pritap->pcalls[i], 0, sizeof(pritap->pcalls[0]));
 		}
 		if (callref == pritap->pcalls[i].callref) {
-			pritap->pcalls[i].inuse = 1;
+			if (callref == NULL) {
+				pritap->pcalls[i].inuse = 1;
+				ftdm_log(FTDM_LOG_DEBUG, "Enabling callref slot %d in span %s\n", i, pritap->span->name);
+			} else if (!pritap->pcalls[i].inuse) {
+				crv = tap_pri_get_crv(pritap->pri, callref);
+				ftdm_log(FTDM_LOG_DEBUG, "Recyclying callref slot %d in span %s for callref %d/%p\n",
+						i, pritap->span->name, crv, callref);
+				memset(&pritap->pcalls[i], 0, sizeof(pritap->pcalls[0]));
+				pritap->pcalls[i].callref = callref;
+				pritap->pcalls[i].inuse = 1;
+			}
 
 			ftdm_mutex_unlock(pritap->pcalls_lock);
 
@@ -464,13 +543,11 @@ static void tap_pri_put_pcall(pritap_t *pritap, void *callref)
 		}
 		tstcrv = tap_pri_get_crv(pritap->pri, pritap->pcalls[i].callref);
 		if (tstcrv == crv) {
-			ftdm_log(FTDM_LOG_DEBUG, "releasing slot %d in span %s used by callref %d/%p\n", i, 
-					pritap->span->name, crv, pritap->pcalls[i].callref);
-			if (!pritap->pcalls[i].inuse) {
-				ftdm_log(FTDM_LOG_ERROR, "slot %d in span %s used by callref %d/%p was released already?\n", 
-						i, pritap->span->name, crv, pritap->pcalls[i].callref);
+			if (pritap->pcalls[i].inuse) {
+				ftdm_log(FTDM_LOG_DEBUG, "releasing slot %d in span %s used by callref %d/%p\n", i,
+						pritap->span->name, crv, pritap->pcalls[i].callref);
+				pritap->pcalls[i].inuse = 0;
 			}
-			pritap->pcalls[i].inuse = 0;
 		}
 	}
 
@@ -480,6 +557,7 @@ static void tap_pri_put_pcall(pritap_t *pritap, void *callref)
 static __inline__ ftdm_channel_t *tap_pri_get_fchan(pritap_t *pritap, passive_call_t *pcall, int channel)
 {
 	ftdm_channel_t *fchan = NULL;
+	int err = 0;
 	int chanpos = PRI_CHANNEL(channel);
 	if (!chanpos || chanpos > pritap->span->chan_count) {
 		ftdm_log(FTDM_LOG_CRIT, "Invalid pri tap channel %d requested in span %s\n", channel, pritap->span->name);
@@ -487,14 +565,19 @@ static __inline__ ftdm_channel_t *tap_pri_get_fchan(pritap_t *pritap, passive_ca
 	}
 
 	fchan = pritap->span->channels[PRI_CHANNEL(channel)];
+
+	ftdm_channel_lock(fchan);
+
 	if (ftdm_test_flag(fchan, FTDM_CHANNEL_INUSE)) {
 		ftdm_log(FTDM_LOG_ERROR, "Channel %d requested in span %s is already in use!\n", channel, pritap->span->name);
-		return NULL;
+		err = 1;
+		goto done;
 	}
 
 	if (ftdm_channel_open_chan(fchan) != FTDM_SUCCESS) {
 		ftdm_log(FTDM_LOG_ERROR, "Could not open tap channel %d requested in span %s\n", channel, pritap->span->name);
-		return NULL;
+		err = 1;
+		goto done;
 	}
 
 	memset(&fchan->caller_data, 0, sizeof(fchan->caller_data));
@@ -508,6 +591,15 @@ static __inline__ ftdm_channel_t *tap_pri_get_fchan(pritap_t *pritap, passive_ca
 	ftdm_set_string(fchan->caller_data.ani.digits, pcall->callingani.digits);
 	ftdm_set_string(fchan->caller_data.dnis.digits, pcall->callednum.digits);
 
+done:
+	if (fchan) {
+		ftdm_channel_unlock(fchan);
+	}
+
+	if (err) {
+		return NULL;
+	}
+
 	return fchan;
 }
 
@@ -534,10 +626,17 @@ static void handle_pri_passive_event(pritap_t *pritap, pri_event *e)
 			ftdm_log(FTDM_LOG_WARNING, "There is a call with callref %d already, ignoring duplicated ring event\n", crv);
 			break;
 		}
-		pcall = tap_pri_get_pcall(pritap, NULL);
+
+		/* Try to get a recycled call (ie, e->ring.call is a call that the PRI stack allocated previously and then
+		 * re-used for the next RING event because we did not destroy it fast enough) */
+		pcall = tap_pri_get_pcall(pritap, e->ring.call);
 		if (!pcall) {
-			ftdm_log(FTDM_LOG_ERROR, "Failed to get a free passive PRI call slot for callref %d, this is a bug!\n", crv);
-			break;
+			/* ok so the call is really not known to us, let's get a new one */
+			pcall = tap_pri_get_pcall(pritap, NULL);
+			if (!pcall) {
+				ftdm_log(FTDM_LOG_ERROR, "Failed to get a free passive PRI call slot for callref %d, this is a bug!\n", crv);
+				break;
+			}
 		}
 		pcall->callref = e->ring.call;
 		ftdm_set_string(pcall->callingnum.digits, e->ring.callingnum);
@@ -562,7 +661,7 @@ static void handle_pri_passive_event(pritap_t *pritap, pri_event *e)
 		/* check that we already know about this call in the peer PRI (which was the one receiving the PRI_EVENT_RING event) */
 		if (!(pcall = tap_pri_get_pcall_bycrv(peertap, crv))) {
 			ftdm_log(FTDM_LOG_DEBUG, 
-				"ignoring proceeding in channel %s:%d:%d for callref %d since we don't know about it",
+				"ignoring proceeding in channel %s:%d:%d for callref %d since we don't know about it\n",
 				pritap->span->name, PRI_SPAN(e->proceeding.channel), PRI_CHANNEL(e->proceeding.channel), crv);
 			break;
 		}
@@ -570,13 +669,27 @@ static void handle_pri_passive_event(pritap_t *pritap, pri_event *e)
 			ftdm_log(FTDM_LOG_DEBUG, "Ignoring duplicated proceeding with callref %d\n", crv);
 			break;
 		}
-		peerpcall = tap_pri_get_pcall(pritap, NULL);
-		if (!peerpcall) {
-			ftdm_log(FTDM_LOG_ERROR, "Failed to get a free peer PRI passive call slot for callref %d in span %s, this is a bug!\n", 
-					crv, pritap->span->name);
+		pcall->proceeding = 1;
+
+		/* This call should not be known to this PRI yet ... */
+		if ((peerpcall = tap_pri_get_pcall_bycrv(pritap, crv))) {
+			ftdm_log(FTDM_LOG_ERROR,
+				"ignoring proceeding in channel %s:%d:%d for callref %d, dup???\n",
+				pritap->span->name, PRI_SPAN(e->proceeding.channel), PRI_CHANNEL(e->proceeding.channel), crv);
 			break;
 		}
-		peerpcall->callref = e->proceeding.call;
+
+		/* Check if the call pointer is being recycled */
+		peerpcall = tap_pri_get_pcall(pritap, e->proceeding.call);
+		if (!peerpcall) {
+			peerpcall = tap_pri_get_pcall(pritap, NULL);
+			if (!peerpcall) {
+				ftdm_log(FTDM_LOG_ERROR, "Failed to get a free peer PRI passive call slot for callref %d in span %s, this is a bug!\n", 
+						crv, pritap->span->name);
+				break;
+			}
+			peerpcall->callref = e->proceeding.call;
+		}
 
 		/* check that the layer 1 and trans capability are supported */
 		layer1 = pri_get_layer1(peertap->pri, pcall->callref);
@@ -598,7 +711,6 @@ static void handle_pri_passive_event(pritap_t *pritap, pri_event *e)
 				pritap->span->name, PRI_SPAN(e->proceeding.channel), PRI_CHANNEL(e->proceeding.channel), crv);
 			break;
 		}
-		pcall->fchan = fchan;
 
 		peerfchan = tap_pri_get_fchan(peertap, pcall, e->proceeding.channel);
 		if (!peerfchan) {
@@ -606,12 +718,20 @@ static void handle_pri_passive_event(pritap_t *pritap, pri_event *e)
 				peertap->span->name, PRI_SPAN(e->proceeding.channel), PRI_CHANNEL(e->proceeding.channel), crv);
 			break;
 		}
+		pcall->fchan = fchan;
 		peerpcall->fchan = fchan;
 
-		fchan->call_data = peerfchan;
-		peerfchan->call_data = fchan;
+		ftdm_log_chan(fchan, FTDM_LOG_NOTICE, "Starting new tapped call with callref %d\n", crv);
+
+		ftdm_channel_lock(fchan);
+		fchan->call_data = peerfchan;
+		ftdm_set_state(fchan, FTDM_CHANNEL_STATE_RING);
+		ftdm_channel_unlock(fchan);
+
+		ftdm_channel_lock(peerfchan);
+		peerfchan->call_data = fchan;
+		ftdm_channel_unlock(peerfchan);
 
-		ftdm_set_state_locked(fchan, FTDM_CHANNEL_STATE_RING);
 		break;
 
 	case PRI_EVENT_ANSWER:
@@ -620,33 +740,54 @@ static void handle_pri_passive_event(pritap_t *pritap, pri_event *e)
 				pritap->span->name, PRI_SPAN(e->answer.channel), PRI_CHANNEL(e->answer.channel), crv);
 		if (!(pcall = tap_pri_get_pcall_bycrv(pritap, crv))) {
 			ftdm_log(FTDM_LOG_DEBUG, 
-				"ignoring answer in channel %s:%d:%d for callref %d since we don't know about it",
-				pritap->span->name, PRI_SPAN(e->proceeding.channel), PRI_CHANNEL(e->proceeding.channel), crv);
+				"ignoring answer in channel %s:%d:%d for callref %d since we don't know about it\n",
+				pritap->span->name, PRI_SPAN(e->answer.channel), PRI_CHANNEL(e->proceeding.channel), crv);
 			break;
 		}
+		if (!pcall->fchan) {
+			ftdm_log(FTDM_LOG_ERROR,
+				"Received answer in channel %s:%d:%d for callref %d but we never got a channel\n",
+				pritap->span->name, PRI_SPAN(e->answer.channel), PRI_CHANNEL(e->answer.channel), crv);
+			break;
+		}
+		ftdm_channel_lock(pcall->fchan);
 		ftdm_log_chan(pcall->fchan, FTDM_LOG_NOTICE, "Tapped call was answered in state %s\n", ftdm_channel_state2str(pcall->fchan->state));
+		ftdm_set_pflag(pcall->fchan, PRITAP_NETWORK_ANSWER);
+		ftdm_set_state(pcall->fchan, FTDM_CHANNEL_STATE_UP);
+		ftdm_channel_unlock(pcall->fchan);
 		break;
 
 	case PRI_EVENT_HANGUP_REQ:
 		crv = tap_pri_get_crv(pritap->pri, e->hangup.call);
-		ftdm_log(FTDM_LOG_DEBUG, "Hangup on channel %s:%d:%d with callref %d\n", 
-				pritap->span->name, PRI_SPAN(e->answer.channel), PRI_CHANNEL(e->answer.channel), crv);
+
+		ftdm_log(FTDM_LOG_DEBUG, "Hangup on channel %s:%d:%d with callref %d\n",
+				pritap->span->name, PRI_SPAN(e->hangup.channel), PRI_CHANNEL(e->hangup.channel), crv);
 
 		if (!(pcall = tap_pri_get_pcall_bycrv(pritap, crv))) {
 			ftdm_log(FTDM_LOG_DEBUG, 
 				"ignoring hangup in channel %s:%d:%d for callref %d since we don't know about it",
-				pritap->span->name, PRI_SPAN(e->proceeding.channel), PRI_CHANNEL(e->proceeding.channel), crv);
+				pritap->span->name, PRI_SPAN(e->hangup.channel), PRI_CHANNEL(e->hangup.channel), crv);
 			break;
 		}
 
-		fchan = pcall->fchan;
-		ftdm_set_state_locked(fchan, FTDM_CHANNEL_STATE_TERMINATING);
+		if (pcall->fchan) {
+			fchan = pcall->fchan;
+			ftdm_channel_lock(fchan);
+			if (fchan->state < FTDM_CHANNEL_STATE_TERMINATING) {
+				ftdm_set_state(fchan, FTDM_CHANNEL_STATE_TERMINATING);
+			}
+			pcall->fchan = NULL; /* after this event we're not supposed to need to do anything with the channel anymore */
+			ftdm_channel_unlock(fchan);
+		}
+
+		tap_pri_put_pcall(pritap, e->hangup.call);
+		tap_pri_put_pcall(peertap, e->hangup.call);
 		break;
 
 	case PRI_EVENT_HANGUP_ACK:
 		crv = tap_pri_get_crv(pritap->pri, e->hangup.call);
 		ftdm_log(FTDM_LOG_DEBUG, "Hangup ack on channel %s:%d:%d with callref %d\n", 
-				pritap->span->name, PRI_SPAN(e->answer.channel), PRI_CHANNEL(e->answer.channel), crv);
+				pritap->span->name, PRI_SPAN(e->hangup.channel), PRI_CHANNEL(e->hangup.channel), crv);
 		tap_pri_put_pcall(pritap, e->hangup.call);
 		tap_pri_put_pcall(peertap, e->hangup.call);
 		break;
@@ -661,12 +802,14 @@ static void handle_pri_passive_event(pritap_t *pritap, pri_event *e)
 static void *ftdm_pritap_run(ftdm_thread_t *me, void *obj)
 {
 	ftdm_span_t *span = (ftdm_span_t *) obj;
+	ftdm_span_t *peer = NULL;
 	pritap_t *pritap = span->signal_data;
+	pritap_t *p_pritap = NULL;
 	pri_event *event = NULL;
-	struct pollfd dpoll = { 0, 0, 0 };
+	struct pollfd dpoll[2];
 	int rc = 0;
 
-	ftdm_log(FTDM_LOG_DEBUG, "Tapping PRI thread started on span %d\n", span->span_id);
+	ftdm_log(FTDM_LOG_DEBUG, "Tapping PRI thread started on span %s\n", span->name);
 	
 	pritap->span = span;
 
@@ -684,48 +827,80 @@ static void *ftdm_pritap_run(ftdm_thread_t *me, void *obj)
 		goto done;
 	}
 
-	dpoll.fd = pritap->dchan->sockfd;
+	/* The last span starting runs the show ...
+	 * This simplifies locking and avoid races by having multiple threads for a single tapped link
+	 * Since both threads really handle a single tapped link there is no benefit on multi-threading, just complications ... */
+	peer = pritap->peerspan;
+	p_pritap = peer->signal_data;
+	if (!ftdm_test_flag(pritap, PRITAP_MASTER)) {
+		ftdm_log(FTDM_LOG_DEBUG, "Running dummy thread on span %s\n", span->name);
+		while (ftdm_running() && !ftdm_test_flag(span, FTDM_SPAN_STOP_THREAD)) {
+			poll(NULL, 0, 100);
+		}
+	} else {
+		memset(&dpoll, 0, sizeof(dpoll));
+		dpoll[0].fd = pritap->dchan->sockfd;
+		dpoll[1].fd = p_pritap->dchan->sockfd;
 
-	while (ftdm_running() && !ftdm_test_flag(span, FTDM_SPAN_STOP_THREAD)) {
+		ftdm_log(FTDM_LOG_DEBUG, "Master tapping thread on span %s (fd1=%d, fd2=%d)\n", span->name,
+				pritap->dchan->sockfd, p_pritap->dchan->sockfd);
 
+		while (ftdm_running() && !ftdm_test_flag(span, FTDM_SPAN_STOP_THREAD)) {
 
-		pritap_check_state(span);
+			pritap_check_state(span);
+			pritap_check_state(peer);
 
-		dpoll.revents = 0;
-		dpoll.events = POLLIN;
+			dpoll[0].revents = 0;
+			dpoll[0].events = POLLIN;
 
-		rc = poll(&dpoll, 1, 10);
+			dpoll[1].revents = 0;
+			dpoll[1].events = POLLIN;
 
-		if (rc < 0) {
-			if (errno == EINTR) {
-				ftdm_log(FTDM_LOG_DEBUG, "D-channel waiting interrupted, continuing ...\n");
+			rc = poll(&dpoll[0], 2, 10);
+
+			if (rc < 0) {
+				if (errno == EINTR) {
+					ftdm_log(FTDM_LOG_DEBUG, "D-channel waiting interrupted, continuing ...\n");
+					continue;
+				}
+				ftdm_log(FTDM_LOG_ERROR, "poll failed: %s\n", strerror(errno));
 				continue;
 			}
-			ftdm_log(FTDM_LOG_ERROR, "poll failed: %s\n", strerror(errno));
-			continue;
-		}
 
-		pri_schedule_run(pritap->pri);
+			pri_schedule_run(pritap->pri);
+			pri_schedule_run(p_pritap->pri);
 
-		if (rc) {
-			if (dpoll.revents & POLLIN) {
-				event = pri_read_event(pritap->pri);
-				if (event) {
-					handle_pri_passive_event(pritap, event);
+			pritap_check_state(span);
+			pritap_check_state(peer);
+
+			if (rc) {
+				if (dpoll[0].revents & POLLIN) {
+					event = pri_read_event(pritap->pri);
+					if (event) {
+						handle_pri_passive_event(pritap, event);
+						pritap_check_state(span);
+					}
 				}
-			} else {
-				ftdm_log(FTDM_LOG_WARNING, "nothing to read?\n");
-			}
-		}
 
-		pritap_check_state(span);
+				if (dpoll[1].revents & POLLIN) {
+					event = pri_read_event(p_pritap->pri);
+					if (event) {
+						handle_pri_passive_event(p_pritap, event);
+						pritap_check_state(peer);
+					}
+				}
+			}
+
+		}
 	}
 
+
 done:
-	ftdm_log(FTDM_LOG_DEBUG, "Tapping PRI thread ended on span %d\n", span->span_id);
+	ftdm_log(FTDM_LOG_DEBUG, "Tapping PRI thread ended on span %s\n", span->name);
 
 	ftdm_clear_flag(span, FTDM_SPAN_IN_THREAD);
 	ftdm_clear_flag(pritap, PRITAP_RUNNING);
+	ftdm_clear_flag(pritap, PRITAP_MASTER);
 
 	return NULL;
 }
@@ -811,6 +986,7 @@ static ftdm_status_t ftdm_pritap_start(ftdm_span_t *span)
 {
 	ftdm_status_t ret;
 	pritap_t *pritap = span->signal_data;
+	pritap_t *p_pritap = pritap->peerspan->signal_data;
 
 	if (ftdm_test_flag(pritap, PRITAP_RUNNING)) {
 		return FTDM_FAIL;
@@ -822,6 +998,10 @@ static ftdm_status_t ftdm_pritap_start(ftdm_span_t *span)
 	ftdm_clear_flag(span, FTDM_SPAN_IN_THREAD);
 
 	ftdm_set_flag(pritap, PRITAP_RUNNING);
+	if (p_pritap && ftdm_test_flag(p_pritap, PRITAP_RUNNING)) {
+		/* our peer already started, we're the master */
+		ftdm_set_flag(pritap, PRITAP_MASTER);
+	}
 	ret = ftdm_thread_create_detached(ftdm_pritap_run, span);
 
 	if (ret != FTDM_SUCCESS) {
@@ -840,6 +1020,7 @@ static FIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(ftdm_pritap_configure_span)
 	ftdm_channel_t *dchan = NULL;
 	pritap_t *pritap = NULL;
 	ftdm_span_t *peerspan = NULL;
+	pritap_iface_t iface = PRITAP_IFACE_UNKNOWN;
 	unsigned paramindex = 0;
 
 	if (span->trunk_type >= FTDM_TRUNK_NONE) {
@@ -867,6 +1048,14 @@ static FIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(ftdm_pritap_configure_span)
 			debug = val;
 		} else if (!strcasecmp(var, "mixaudio")) {
 			mixaudio = ftdm_true(val);
+		} else if (!strcasecmp(var, "interface")) {
+			if (!strcasecmp(val, "cpe")) {
+				iface = PRITAP_IFACE_CPE;
+			} else if (!strcasecmp(val, "net")) {
+				iface = PRITAP_IFACE_NET;
+			} else {
+				ftdm_log(FTDM_LOG_WARNING, "Ignoring invalid tapping interface type %s\n", val);
+			}
 		} else if (!strcasecmp(var, "peerspan")) {
 			if (ftdm_span_find_by_name(val, &peerspan) != FTDM_SUCCESS) {
 				ftdm_log(FTDM_LOG_ERROR, "Invalid tapping peer span %s\n", val);
@@ -891,6 +1080,7 @@ static FIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(ftdm_pritap_configure_span)
 	pritap->dchan = dchan;
 	pritap->peerspan = peerspan;
 	pritap->mixaudio = mixaudio;
+	pritap->iface = iface;
 
 	span->start = ftdm_pritap_start;
 	span->stop = ftdm_pritap_stop;
diff --git a/libs/js/nsprpub/configure.in b/libs/js/nsprpub/configure.in
index 93d3bd9f85..7ac45ed9fc 100644
--- a/libs/js/nsprpub/configure.in
+++ b/libs/js/nsprpub/configure.in
@@ -425,7 +425,7 @@ if test "$target" != "$host"; then
     LDFLAGS=$_SAVE_LDFLAGS
 
     case "$build:$target" in 
-      powerpc-apple-darwin8*:i?86-apple-darwin*)
+      powerpc-apple-darwin8*:*86-apple-darwin*)
         dnl The Darwin cross compiler doesn't necessarily point itself at a
         dnl root that has libraries for the proper architecture, it defaults
         dnl to the system root.  The libraries in the system root on current
@@ -446,7 +446,7 @@ if test "$target" != "$host"; then
     AC_PROG_CXX
 
     case "$build:$target" in
-      powerpc-apple-darwin8*:i?86-apple-darwin*)
+      powerpc-apple-darwin8*:*86-apple-darwin*)
         dnl Revert the changes made above.  From this point on, the target
         dnl compiler will never be used without applying the SDK to CFLAGS
         dnl (see --with-macos-sdk below).
@@ -496,7 +496,7 @@ fi
 rm -f a.out
 
 case "$build:$target" in
-    i?86-apple-darwin*:powerpc-apple-darwin*)
+    *86-apple-darwin*:powerpc-apple-darwin*)
         dnl cross_compiling will have erroneously been set to "no" in this
         dnl case, because the x86 build host is able to run ppc code in a
         dnl translated environment, making a cross compiler appear native.
@@ -975,7 +975,7 @@ case "$target" in
     AC_DEFINE(HAVE_BSD_FLOCK)
     CFLAGS="$CFLAGS -Wmost -fno-common"
     case "${target_cpu}" in
-        i*86*)
+        *86*)
             AC_DEFINE(i386)
             CPU_ARCH=i386
             PR_MD_ASFILES=os_Darwin_x86.s
@@ -1014,7 +1014,7 @@ case "$target" in
                     dnl Architecture minimum 10.1
                     export MACOSX_DEPLOYMENT_TARGET=10.1
                     ;;
-                i*86*)
+                *86*)
                     dnl Architecture minimum 10.4
                     export MACOSX_DEPLOYMENT_TARGET=10.4
                     ;;
diff --git a/libs/libdingaling/src/libdingaling.c b/libs/libdingaling/src/libdingaling.c
index e2b32a0637..9457663681 100644
--- a/libs/libdingaling/src/libdingaling.c
+++ b/libs/libdingaling/src/libdingaling.c
@@ -623,7 +623,7 @@ static ldl_status parse_jingle_code(ldl_handle_t *handle, iks *xml, char *to, ch
 	}
 
 
-	if (!(id && action)) {
+	if (!(id && action && from)) {
 		globals.logger(DL_LOG_CRIT, "missing required params\n");  
 		return LDL_STATUS_FALSE;
 	}
@@ -820,6 +820,9 @@ static ldl_status parse_jingle_code(ldl_handle_t *handle, iks *xml, char *to, ch
 										break;
 									}
 								}
+							} else {
+								globals.logger(DL_LOG_WARNING, "No preference specified");
+								continue; 
 							}
 						
 							if (index < 0) {
diff --git a/libs/sofia-sip/.update b/libs/sofia-sip/.update
index 22f5eeb029..e5cf1e495d 100644
--- a/libs/sofia-sip/.update
+++ b/libs/sofia-sip/.update
@@ -1 +1 @@
-Tue Oct 23 13:13:35 EDT 2012
+Fri Oct 26 14:14:41 CDT 2012
diff --git a/libs/sofia-sip/libsofia-sip-ua/iptsec/auth_module.c b/libs/sofia-sip/libsofia-sip-ua/iptsec/auth_module.c
index 087810ebc7..9c1ca218b5 100644
--- a/libs/sofia-sip/libsofia-sip-ua/iptsec/auth_module.c
+++ b/libs/sofia-sip/libsofia-sip-ua/iptsec/auth_module.c
@@ -744,7 +744,7 @@ void auth_check_digest(auth_mod_t *am,
       auth_challenge_digest(am, as, ach);
       as->as_blacklist = am->am_blacklist;
     }
-    SU_DEBUG_5(("auth_method_digest: response did not match\n"));
+    SU_DEBUG_5(("auth_method_digest: response did not match\n" VA_NONE));
 
     return;
   }
@@ -761,7 +761,7 @@ void auth_check_digest(auth_mod_t *am,
   if (am->am_challenge)
     auth_challenge_digest(am, as, ach);
 
-  SU_DEBUG_7(("auth_method_digest: successful authentication\n"));
+  SU_DEBUG_7(("auth_method_digest: successful authentication\n" VA_NONE));
 
   as->as_status = 0;	/* Successful authentication! */
   as->as_phrase = "";
@@ -1412,11 +1412,11 @@ int auth_validate_digest_nonce(auth_mod_t *am,
 
   /* Check nonce */
   if (!ar->ar_nonce) {
-    SU_DEBUG_5(("auth_method_digest: no nonce\n"));
+    SU_DEBUG_5(("auth_method_digest: no nonce\n" VA_NONE));
     return -1;
   }
   if (base64_d((void*)nonce, (sizeof nonce), ar->ar_nonce) != (sizeof nonce)) {
-    SU_DEBUG_5(("auth_method_digest: too short nonce\n"));
+    SU_DEBUG_5(("auth_method_digest: too short nonce\n" VA_NONE));
     return -1;
   }
 
@@ -1426,7 +1426,7 @@ int auth_validate_digest_nonce(auth_mod_t *am,
   auth_md5_hmac_digest(am, md5, hmac, sizeof hmac);
 
   if (memcmp(nonce->digest, hmac, sizeof nonce->digest)) {
-    SU_DEBUG_5(("auth_method_digest: bad nonce\n"));
+    SU_DEBUG_5(("auth_method_digest: bad nonce\n" VA_NONE));
     return -1;
   }
 
diff --git a/libs/sofia-sip/libsofia-sip-ua/nea/nea_server.c b/libs/sofia-sip/libsofia-sip-ua/nea/nea_server.c
index bd1e63b478..42539cf82d 100644
--- a/libs/sofia-sip/libsofia-sip-ua/nea/nea_server.c
+++ b/libs/sofia-sip/libsofia-sip-ua/nea/nea_server.c
@@ -424,12 +424,12 @@ nea_server_t *nea_server_create(nta_agent_t *agent,
     throttle = min_throttle;
 
   if (!url) {
-    SU_DEBUG_5(("nea_server_create(): invalid url\n"));
+    SU_DEBUG_5(("nea_server_create(): invalid url\n" VA_NONE));
     return NULL;
   }
 
   if (min_expires > expires || expires > max_expires) {
-    SU_DEBUG_5(("nea_server_create(): invalid expiration range\n"));
+    SU_DEBUG_5(("nea_server_create(): invalid expiration range\n" VA_NONE));
     return NULL;
   }
 
diff --git a/libs/sofia-sip/libsofia-sip-ua/nta/nta.c b/libs/sofia-sip/libsofia-sip-ua/nta/nta.c
index e690b424e7..709e678d86 100644
--- a/libs/sofia-sip/libsofia-sip-ua/nta/nta.c
+++ b/libs/sofia-sip/libsofia-sip-ua/nta/nta.c
@@ -1276,7 +1276,7 @@ void agent_timer(su_root_magic_t *rm, su_timer_t *timer, nta_agent_t *agent)
 
   if (next == latest) {
     /* Do not set timer? */
-    SU_DEBUG_9(("nta: timer not set\n"));
+    SU_DEBUG_9(("nta: timer not set\n" VA_NONE));
     assert(!agent->sa_out.completed->q_head);
     assert(!agent->sa_out.trying->q_head);
     assert(!agent->sa_out.inv_calling->q_head);
@@ -2162,7 +2162,7 @@ int nta_agent_add_tport(nta_agent_t *self,
     if (url_string_p(uri))
       SU_DEBUG_1(("nta: %s: invalid bind URL\n", uri->us_str));
     else
-      SU_DEBUG_1(("nta: invalid bind URL\n"));
+      SU_DEBUG_1(("nta: invalid bind URL\n" VA_NONE));
     su_seterrno(EINVAL);
     return -1;
   }
@@ -2249,19 +2249,19 @@ int nta_agent_add_tport(nta_agent_t *self,
   /* XXX - when to use maddr? */
   if ((agent_init_via(self, tport_primaries(self->sa_tports), 0)) < 0) {
     error = su_errno();
-    SU_DEBUG_1(("nta: cannot create Via headers\n"));
+    SU_DEBUG_1(("nta: cannot create Via headers\n" VA_NONE));
     goto error;
   }
   else
-    SU_DEBUG_9(("nta: Via fields initialized\n"));
+    SU_DEBUG_9(("nta: Via fields initialized\n" VA_NONE));
 
   if ((agent_init_contact(self)) < 0) {
     error = su_errno();
-    SU_DEBUG_1(("nta: cannot create Contact header\n"));
+    SU_DEBUG_1(("nta: cannot create Contact header\n" VA_NONE));
     goto error;
   }
   else
-    SU_DEBUG_9(("nta: Contact header created\n"));
+    SU_DEBUG_9(("nta: Contact header created\n" VA_NONE));
 
   su_free(self->sa_home, url);
   ta_end(ta);
@@ -2286,7 +2286,7 @@ int agent_create_master_transport(nta_agent_t *self, tagi_t *tags)
   if (!self->sa_tports)
     return -1;
 
-  SU_DEBUG_9(("nta: master transport created\n"));
+  SU_DEBUG_9(("nta: master transport created\n" VA_NONE));
 
   return 0;
 }
@@ -7713,7 +7713,7 @@ nta_outgoing_t *outgoing_create(nta_agent_t *agent,
   home = msg_home(msg);
 
   if (!sip->sip_request || sip_complete_message(msg) < 0) {
-    SU_DEBUG_3(("nta: outgoing_create: incomplete request\n"));
+    SU_DEBUG_3(("nta: outgoing_create: incomplete request\n" VA_NONE));
     return NULL;
   }
 
@@ -7900,7 +7900,7 @@ nta_outgoing_t *outgoing_create(nta_agent_t *agent,
 	}
       }
       else {
-	SU_DEBUG_1(("outgoing_create: ACK without INVITE\n"));
+	SU_DEBUG_1(("outgoing_create: ACK without INVITE\n" VA_NONE));
 	assert(!"INVITE found for ACK");
       }
     }
@@ -7987,11 +7987,11 @@ outgoing_prepare_send(nta_outgoing_t *orq)
     outgoing_send_via(orq, tp);
   }
   else if (orq->orq_sips) {
-    SU_DEBUG_3(("nta outgoing create: no secure transport\n"));
+    SU_DEBUG_3(("nta outgoing create: no secure transport\n" VA_NONE));
     outgoing_reply(orq, SIP_416_UNSUPPORTED_URI, 1);
   }
   else {
-    SU_DEBUG_3(("nta outgoing create: no transport protocol\n"));
+    SU_DEBUG_3(("nta outgoing create: no transport protocol\n" VA_NONE));
     outgoing_reply(orq, 503, "No transport", 1);
   }
 }
@@ -8013,7 +8013,7 @@ outgoing_send_via(nta_outgoing_t *orq, tport_t *tp)
   if (old_tp) tport_unref(old_tp);
 
   if (outgoing_insert_via(orq, agent_tport_via(tp)) < 0) {
-    SU_DEBUG_3(("nta outgoing create: cannot insert Via line\n"));
+    SU_DEBUG_3(("nta outgoing create: cannot insert Via line\n" VA_NONE));
     outgoing_reply(orq, 503, "Cannot insert Via", 1);
     return;
   }
@@ -9211,7 +9211,7 @@ int outgoing_recv(nta_outgoing_t *_orq,
     if (orq->orq_destroyed && 200 <= status && status < 300) {
       if (orq->orq_uas && su_strcasecmp(sip->sip_to->a_tag, orq->orq_tag) != 0) {
         /* Orphan 200 Ok to INVITE. ACK and BYE it */
-        SU_DEBUG_5(("nta: Orphan 200 Ok send ACK&BYE\n"));
+        SU_DEBUG_5(("nta: Orphan 200 Ok send ACK&BYE\n" VA_NONE));
         return nta_msg_ackbye(sa, msg);
       }
       return -1;  /* Proxy statelessly (RFC3261 section 16.11) */
@@ -9273,7 +9273,7 @@ int outgoing_recv(nta_outgoing_t *_orq,
 	    return outgoing_duplicate(orq, msg, sip);
 
           /* Orphan 200 Ok to INVITE. ACK and BYE it */
-          SU_DEBUG_5(("nta: Orphan 200 Ok send ACK&BYE"));
+          SU_DEBUG_5(("nta: Orphan 200 Ok send ACK&BYE" VA_NONE));
           return nta_msg_ackbye(sa, msg);
 	}
       }
diff --git a/libs/sofia-sip/libsofia-sip-ua/nth/nth_client.c b/libs/sofia-sip/libsofia-sip-ua/nth/nth_client.c
index 96442454fb..6a2cd5f80b 100644
--- a/libs/sofia-sip/libsofia-sip-ua/nth/nth_client.c
+++ b/libs/sofia-sip/libsofia-sip-ua/nth/nth_client.c
@@ -911,7 +911,7 @@ int hc_resolve_and_send(nth_client_t * hc)
 
   if (msg_serialize(msg, http) < 0) {
     assert(hc->hc_tport);
-    SU_DEBUG_3(("nth client create: invalid message"));
+    SU_DEBUG_3(("nth client create: invalid message" VA_NONE));
     return -1;
   }
 
diff --git a/libs/sofia-sip/libsofia-sip-ua/nth/nth_server.c b/libs/sofia-sip/libsofia-sip-ua/nth/nth_server.c
index 4daed06520..0c9b6182dc 100644
--- a/libs/sofia-sip/libsofia-sip-ua/nth/nth_server.c
+++ b/libs/sofia-sip/libsofia-sip-ua/nth/nth_server.c
@@ -312,20 +312,20 @@ nth_site_t *nth_site_create(nth_site_t *parent,
   is_path = url->url_path != NULL;
 
   if (is_host && is_path) {
-    SU_DEBUG_3(("nth_site_create(): virtual host and path simultanously\n"));
+    SU_DEBUG_3(("nth_site_create(): virtual host and path simultanously\n" VA_NONE));
     errno = EINVAL;
     goto error;
   }
 
   if (!parent && !is_host) {
-    SU_DEBUG_3(("nth_site_create(): host is required\n"));
+    SU_DEBUG_3(("nth_site_create(): host is required\n" VA_NONE));
     errno = EINVAL;
     goto error;
   }
 
   if (parent) {
     if (!parent->site_isdir) {
-      SU_DEBUG_3(("nth_site_create(): invalid parent resource \n"));
+      SU_DEBUG_3(("nth_site_create(): invalid parent resource \n" VA_NONE));
       errno = EINVAL;
       goto error;
     }
@@ -995,7 +995,7 @@ static void server_reply(server_t *srv, tport_t *tport,
   if (tport_tqsend(tport, response, NULL,
 		   TPTAG_CLOSE_AFTER(close),
 		   TAG_END()) == -1) {
-    SU_DEBUG_3(("server_reply(): cannot queue response\n"));
+    SU_DEBUG_3(("server_reply(): cannot queue response\n" VA_NONE));
     tport_shutdown(tport, 2);
   }
 
diff --git a/libs/sofia-sip/libsofia-sip-ua/nua/nua_register.c b/libs/sofia-sip/libsofia-sip-ua/nua/nua_register.c
index a0dcbb1c4e..a4ec4246af 100644
--- a/libs/sofia-sip/libsofia-sip-ua/nua/nua_register.c
+++ b/libs/sofia-sip/libsofia-sip-ua/nua/nua_register.c
@@ -967,7 +967,7 @@ static int nua_register_client_response(nua_client_request_t *cr,
     if (tport && tport != nr->nr_tport) {
       if (nr->nr_error_report_id) {
 	if (tport_release(nr->nr_tport, nr->nr_error_report_id, NULL, NULL, nr, 0) < 0)
-	  SU_DEBUG_1(("nua_register: tport_release() failed\n"));
+	  SU_DEBUG_1(("nua_register: tport_release() failed\n" VA_NONE));
 	nr->nr_error_report_id = 0;
       }
       tport_unref(nr->nr_tport);
@@ -996,7 +996,7 @@ static int nua_register_client_response(nua_client_request_t *cr,
     if (nr->nr_tport) {
       if (nr->nr_error_report_id) {
 	if (tport_release(nr->nr_tport, nr->nr_error_report_id, NULL, NULL, nr, 0) < 0)
-	  SU_DEBUG_1(("nua_register: tport_release() failed\n"));
+	  SU_DEBUG_1(("nua_register: tport_release() failed\n" VA_NONE));
 	nr->nr_error_report_id = 0;
       }
 
@@ -1028,7 +1028,7 @@ void nua_register_connection_closed(tp_stack_t *sip_stack,
   pending = nr->nr_error_report_id;
 
   if (tport_release(tport, pending, NULL, NULL, nr, 0) < 0)
-    SU_DEBUG_1(("nua_register: tport_release() failed\n"));
+    SU_DEBUG_1(("nua_register: tport_release() failed\n" VA_NONE));
   nr->nr_error_report_id = 0;
 
   tpn = tport_name(nr->nr_tport);
diff --git a/libs/sofia-sip/libsofia-sip-ua/nua/nua_session.c b/libs/sofia-sip/libsofia-sip-ua/nua/nua_session.c
index c17b7b9bb0..3316d535c3 100644
--- a/libs/sofia-sip/libsofia-sip-ua/nua/nua_session.c
+++ b/libs/sofia-sip/libsofia-sip-ua/nua/nua_session.c
@@ -3039,11 +3039,11 @@ nh_referral_check(nua_handle_t *nh, tagi_t const *tags)
     ref->ref_event = sip_event_dup(nh->nh_home, event);
 
   if (!nh_validate(nh->nh_nua, ref_handle)) {
-    SU_DEBUG_3(("nua: invalid NOTIFY_REFER handle\n"));
+    SU_DEBUG_3(("nua: invalid NOTIFY_REFER handle\n" VA_NONE));
     return -1;
   }
   else if (!ref->ref_event) {
-    SU_DEBUG_3(("nua: NOTIFY event missing\n"));
+    SU_DEBUG_3(("nua: NOTIFY event missing\n" VA_NONE));
     return -1;
   }
 
diff --git a/libs/sofia-sip/libsofia-sip-ua/nua/nua_stack.c b/libs/sofia-sip/libsofia-sip-ua/nua/nua_stack.c
index 5fe5d221d1..85f1647d3e 100644
--- a/libs/sofia-sip/libsofia-sip-ua/nua/nua_stack.c
+++ b/libs/sofia-sip/libsofia-sip-ua/nua/nua_stack.c
@@ -192,7 +192,7 @@ int nua_stack_init(su_root_t *root, nua_t *nua)
       dnh->nh_ds->ds_leg == NULL ||
       nta_agent_set_params(nua->nua_nta, NTATAG_UA(1), TAG_END()) < 0 ||
       nua_stack_init_transport(nua, nua->nua_args) < 0) {
-    SU_DEBUG_1(("nua: initializing SIP stack failed\n"));
+    SU_DEBUG_1(("nua: initializing SIP stack failed\n" VA_NONE));
     return -1;
   }
 
diff --git a/libs/sofia-sip/libsofia-sip-ua/sresolv/sres.c b/libs/sofia-sip/libsofia-sip-ua/sresolv/sres.c
index 009ba80695..88a7fd389b 100644
--- a/libs/sofia-sip/libsofia-sip-ua/sresolv/sres.c
+++ b/libs/sofia-sip/libsofia-sip-ua/sresolv/sres.c
@@ -3596,7 +3596,7 @@ sres_decode_msg(sres_resolver_t *res,
   m->m_offset = sizeof(m->m_packet.mp_header);
 
   if (m->m_size < m->m_offset) {
-    SU_DEBUG_5(("sres_decode_msg: truncated message\n"));
+    SU_DEBUG_5(("sres_decode_msg: truncated message\n" VA_NONE));
     return -1;
   }
 
diff --git a/libs/sofia-sip/libsofia-sip-ua/sresolv/sresolv.c b/libs/sofia-sip/libsofia-sip-ua/sresolv/sresolv.c
index fba22de731..0720265926 100644
--- a/libs/sofia-sip/libsofia-sip-ua/sresolv/sresolv.c
+++ b/libs/sofia-sip/libsofia-sip-ua/sresolv/sresolv.c
@@ -132,13 +132,13 @@ sres_resolver_create(su_root_t *root,
     srs->srs_timer = t;
 
     if (!srs->srs_timer)
-      SU_DEBUG_3(("sres: cannot create timer\n"));
+      SU_DEBUG_3(("sres: cannot create timer\n" VA_NONE));
 #if nomore
     else if (su_timer_set_for_ever(t, sres_sofia_timer, srs) < 0)
-      SU_DEBUG_3(("sres: cannot set timer\n"));
+      SU_DEBUG_3(("sres: cannot set timer\n" VA_NONE));
 #else
     else if (sres_resolver_set_timer_cb(res, sres_sofia_set_timer, srs) < 0)
-      SU_DEBUG_3(("sres: cannot set timer cb\n"));
+      SU_DEBUG_3(("sres: cannot set timer cb\n" VA_NONE));
 #endif
     else
       return res;		/* Success! */
diff --git a/libs/sofia-sip/libsofia-sip-ua/su/sofia-sip/su_debug.h b/libs/sofia-sip/libsofia-sip-ua/su/sofia-sip/su_debug.h
index 3764fbd9c7..3881a67701 100644
--- a/libs/sofia-sip/libsofia-sip-ua/su/sofia-sip/su_debug.h
+++ b/libs/sofia-sip/libsofia-sip-ua/su/sofia-sip/su_debug.h
@@ -73,13 +73,17 @@ SOFIA_BEGIN_DECLS
 SOFIAPUBVAR su_log_t SU_LOG[];
 #endif
 
+#define VA_NONE "%s",""
+
 #define SU_DEBUG_DEF(level) \
   su_inline void su_debug_##level(char const *fmt, ...) \
     __attribute__ ((__format__ (printf, 1, 2))); \
   su_inline void su_debug_##level(char const *fmt, ...) \
-    { va_list ap; va_start(ap, fmt); su_vllog(SU_LOG, level, fmt, ap); va_end(ap); }
+  { va_list ap; va_start(ap, fmt); su_vllog(SU_LOG, level, fmt, ap); va_end(ap); }
+
+//SU_DEBUG_DEF(0)
+#define su_debug_0(_f, ...) su_llog(SU_LOG, 0, _f, __VA_ARGS__) 
 
-SU_DEBUG_DEF(0)
 /** Log messages at level 0.
  *
  * Fatal errors and panic messages should be logged at level 0.
@@ -100,7 +104,10 @@ SU_DEBUG_DEF(0)
 #endif
 
 #if SU_DEBUG_MAX >= 1
-SU_DEBUG_DEF(1)
+//SU_DEBUG_DEF(1)
+#define su_debug_1(_f, ...) su_llog(SU_LOG, 1, _f, __VA_ARGS__) 
+
+
 /**Log messages at level 1.
  *
  * Critical errors and minimal progress at subsystem level should be logged
@@ -114,7 +121,8 @@ SU_DEBUG_DEF(1)
 #endif
 
 #if SU_DEBUG_MAX >= 2
-SU_DEBUG_DEF(2)
+//SU_DEBUG_DEF(2)
+#define su_debug_2(_f, ...) su_llog(SU_LOG, 2, _f, __VA_ARGS__) 
 /**Log messages at level 2.
  *
  * Non-critical errors should be logged at level 2.
@@ -127,7 +135,8 @@ SU_DEBUG_DEF(2)
 #endif
 
 #if SU_DEBUG_MAX >= 3
-SU_DEBUG_DEF(3)
+//SU_DEBUG_DEF(3)
+#define su_debug_3(_f, ...) su_llog(SU_LOG, 3, _f, __VA_ARGS__) 
 /** Log messages at level 3.
  *
  * Warnings and progress messages should be logged at level 3.
@@ -140,7 +149,8 @@ SU_DEBUG_DEF(3)
 #endif
 
 #if SU_DEBUG_MAX >= 4
-SU_DEBUG_DEF(4)
+//SU_DEBUG_DEF(4)
+#define su_debug_4(_f, ...) su_llog(SU_LOG, 4, _f, __VA_ARGS__) 
 /** Log messages at level 4. */
 #define SU_DEBUG_4(x) (SU_LOG_LEVEL >= 4 ? (su_debug_4 x) : (void)0)
 #else
@@ -148,7 +158,8 @@ SU_DEBUG_DEF(4)
 #endif
 
 #if SU_DEBUG_MAX >= 5
-SU_DEBUG_DEF(5)
+//SU_DEBUG_DEF(5)
+#define su_debug_5(_f, ...) su_llog(SU_LOG, 5, _f, __VA_ARGS__) 
 /** Log messages at level 5.
  *
  * Signaling protocol actions (incoming packets, etc.) should be logged
@@ -162,7 +173,8 @@ SU_DEBUG_DEF(5)
 #endif
 
 #if SU_DEBUG_MAX >= 6
-SU_DEBUG_DEF(6)
+//SU_DEBUG_DEF(6)
+#define su_debug_6(_f, ...) su_llog(SU_LOG, 6, _f, __VA_ARGS__) 
 /** Log messages at level 6. */
 #define SU_DEBUG_6(x) (SU_LOG_LEVEL >= 6 ? (su_debug_6 x) : (void)0)
 #else
@@ -170,7 +182,8 @@ SU_DEBUG_DEF(6)
 #endif
 
 #if SU_DEBUG_MAX >= 7
-SU_DEBUG_DEF(7)
+//SU_DEBUG_DEF(7)
+#define su_debug_7(_f, ...) su_llog(SU_LOG, 7, _f, __VA_ARGS__) 
 /** Log messages at level 7.
  *
  * Media protocol actions (incoming packets, etc) should be logged at level 7.
@@ -183,7 +196,8 @@ SU_DEBUG_DEF(7)
 #endif
 
 #if SU_DEBUG_MAX >= 8
-SU_DEBUG_DEF(8)
+//SU_DEBUG_DEF(8)
+#define su_debug_8(_f, ...) su_llog(SU_LOG, 8, _f, __VA_ARGS__) 
 /** Log messages at level 8. */
 #define SU_DEBUG_8(x) (SU_LOG_LEVEL >= 8 ? (su_debug_8 x) : (void)0)
 #else
@@ -191,7 +205,8 @@ SU_DEBUG_DEF(8)
 #endif
 
 #if SU_DEBUG_MAX >= 9
-SU_DEBUG_DEF(9)
+//SU_DEBUG_DEF(9)
+#define su_debug_9(_f, ...) su_llog(SU_LOG, 9, _f, __VA_ARGS__) 
 /** Log messages at level 9.
  *
  * Entering/exiting functions, very verbatim progress should be logged at
diff --git a/libs/sofia-sip/libsofia-sip-ua/su/sofia-sip/su_log.h b/libs/sofia-sip/libsofia-sip-ua/su/sofia-sip/su_log.h
index 128bf7aa76..d2916b2564 100644
--- a/libs/sofia-sip/libsofia-sip-ua/su/sofia-sip/su_log.h
+++ b/libs/sofia-sip/libsofia-sip-ua/su/sofia-sip/su_log.h
@@ -52,6 +52,15 @@ typedef struct su_log_s su_log_t;
 
 SOFIA_BEGIN_DECLS
 
+#ifdef _MSC_VER
+#define __SOFIA_FUNC__ __FUNCTION__
+#else
+#define __SOFIA_FUNC__ (const char *)__func__
+#endif
+
+
+
+
 /** Prototype for logging function */
 typedef void (su_logger_f)(void *stream, char const *fmt, va_list ap);
 
@@ -77,9 +86,9 @@ enum { SU_LOG_MAX = 9 };
 SOFIAPUBFUN void su_log(char const *fmt, ...)
   __attribute__ ((__format__ (printf, 1, 2)));
 
-SOFIAPUBFUN void su_llog(su_log_t *log, unsigned level, char const *fmt, ...)
-  __attribute__ ((__format__ (printf, 3, 4)));
-SOFIAPUBFUN void su_vllog(su_log_t *log, unsigned level,
+SOFIAPUBFUN void _su_llog(su_log_t *log, unsigned level, const char *file, const char *func, int line, char const *fmt, ...)
+  __attribute__ ((__format__ (printf, 6, 7)));
+SOFIAPUBFUN void _su_vllog(su_log_t *log, unsigned level, const char *file, const char *func, int line,
 			  char const *fmt, va_list ap);
 SOFIAPUBFUN void su_log_redirect(su_log_t *log, su_logger_f *f, void *stream);
 SOFIAPUBFUN void su_log_set_level(su_log_t *log, unsigned level);
@@ -92,6 +101,9 @@ SOFIAPUBVAR su_log_t su_log_global[];
 /** Log the latest su error message */
 SOFIAPUBFUN void su_perror(char const *s);
 
+#define su_llog(_l, _ll, _f, ...) _su_llog(_l, _ll, __FILE__, __SOFIA_FUNC__, __LINE__, _f, __VA_ARGS__)
+#define su_vllog(_l, _ll, _f, ...) _su_vllog(_l, _ll, __FILE__, __SOFIA_FUNC__, __LINE__, _f, __VA_ARGS__)
+
 /** Log the su error message. */
 SOFIAPUBFUN void su_perror2(char const *s, int errcode);
 
diff --git a/libs/sofia-sip/libsofia-sip-ua/su/su_localinfo.c b/libs/sofia-sip/libsofia-sip-ua/su/su_localinfo.c
index c1c4fd23df..2261ff6bac 100644
--- a/libs/sofia-sip/libsofia-sip-ua/su/su_localinfo.c
+++ b/libs/sofia-sip/libsofia-sip-ua/su/su_localinfo.c
@@ -1260,7 +1260,7 @@ int bsd_localinfo(su_localinfo_t const hints[1],
 	flags |= LI_NUMERIC;
 
     if (!(li = calloc(1, sizeof(*li) + sulen + ifnamelen))) {
-      SU_DEBUG_1(("su_getlocalinfo: memory exhausted\n"));
+		SU_DEBUG_1(("su_getlocalinfo: memory exhausted\n" VA_NONE));
       error = ELI_MEMORY;
       break;
     }
@@ -1629,7 +1629,7 @@ int li_name(su_localinfo_t const *hints,
     if (error) {
       if ((flags & LI_NAMEREQD) == LI_NAMEREQD)
 	return 1;
-      SU_DEBUG_7(("li_name: getnameinfo() failed\n"));
+      SU_DEBUG_7(("li_name: getnameinfo() failed\n" VA_NONE));
       if (!su_inet_ntop(su->su_family, SU_ADDR(su), name, sizeof name))
 	return ELI_RESOLVER;
     }
diff --git a/libs/sofia-sip/libsofia-sip-ua/su/su_log.c b/libs/sofia-sip/libsofia-sip-ua/su/su_log.c
index ad977312bb..f56998f7c0 100644
--- a/libs/sofia-sip/libsofia-sip-ua/su/su_log.c
+++ b/libs/sofia-sip/libsofia-sip-ua/su/su_log.c
@@ -100,17 +100,23 @@ void su_log(char const *fmt, ...)
  *
  * @note This function is used mainly by SU_DEBUG_n() macros.
  */
-void su_llog(su_log_t *log, unsigned level, char const *fmt, ...)
+void _su_llog(su_log_t *log, unsigned level, const char *file, const char *func, int line,
+			 char const *fmt, ...)
 {
   va_list ap;
-
+  char buf[512];
   va_start(ap, fmt);
-  su_vllog(log, level, fmt, ap);
+
+
+  snprintf(buf, sizeof(buf), "%s:%d %s() %s", file, line, func, fmt);
+
+  _su_vllog(log, level, file, func, line, buf, ap);
   va_end(ap);
 }
 
 /** Log a message with level (stdarg version). */
-void su_vllog(su_log_t *log, unsigned level, char const *fmt, va_list ap)
+void _su_vllog(su_log_t *log, unsigned level, const char *file, const char *func, int line,
+			  char const *fmt, va_list ap)
 {
   su_logger_f *logger;
   void *stream;
@@ -133,8 +139,9 @@ void su_vllog(su_log_t *log, unsigned level, char const *fmt, va_list ap)
     stream = su_log_default->log_stream;
   }
 
-  if (logger)
-    logger(stream, fmt, ap);
+  if (logger) {
+	  logger(stream, fmt, ap);
+  }
 }
 
 static char const not_initialized[1];
diff --git a/libs/sofia-sip/libsofia-sip-ua/su/su_os_nw.c b/libs/sofia-sip/libsofia-sip-ua/su/su_os_nw.c
index 3dc882dd1e..d9ef55f2e9 100644
--- a/libs/sofia-sip/libsofia-sip-ua/su/su_os_nw.c
+++ b/libs/sofia-sip/libsofia-sip-ua/su/su_os_nw.c
@@ -105,7 +105,7 @@ void nw_changed_cb(SCDynamicStoreRef store,
   su_network_changed_t *snc2;
   su_msg_r rmsg = SU_MSG_R_INIT;
 
-  SU_DEBUG_7(("nw_changed_cb: entering.\n"));
+  SU_DEBUG_7(("nw_changed_cb: entering.\n" VA_NONE));
 
   if (su_msg_create(rmsg,
 		    su_root_task(snc->su_root),
diff --git a/libs/sofia-sip/libsofia-sip-ua/tport/tport.c b/libs/sofia-sip/libsofia-sip-ua/tport/tport.c
index cc94cf4681..eb79deba50 100644
--- a/libs/sofia-sip/libsofia-sip-ua/tport/tport.c
+++ b/libs/sofia-sip/libsofia-sip-ua/tport/tport.c
@@ -3350,7 +3350,7 @@ tport_t *tport_tsend(tport_t *self,
 
       if (!self) {
 	msg_set_errno(msg, su_errno());
-        SU_DEBUG_9(("tport_socket failed in tsend\n"));
+        SU_DEBUG_9(("tport_socket failed in tsend\n" VA_NONE));
 	return NULL;
       }
 
@@ -3406,7 +3406,7 @@ int tport_prepare_and_send(tport_t *self, msg_t *msg,
       /* ...or we are connecting */
       (self->tp_events & (SU_WAIT_CONNECT | SU_WAIT_OUT))) {
     if (tport_queue(self, msg) < 0) {
-      SU_DEBUG_9(("tport_queue failed in tsend\n"));
+      SU_DEBUG_9(("tport_queue failed in tsend\n" VA_NONE));
       return -1;
     }
     return 0;
diff --git a/libs/sofia-sip/libsofia-sip-ua/tport/tport_type_connect.c b/libs/sofia-sip/libsofia-sip-ua/tport/tport_type_connect.c
index 72b212f728..42679d1675 100644
--- a/libs/sofia-sip/libsofia-sip-ua/tport/tport_type_connect.c
+++ b/libs/sofia-sip/libsofia-sip-ua/tport/tport_type_connect.c
@@ -201,7 +201,7 @@ static tport_t *tport_http_connect(tport_primary_t *pri, su_addrinfo_t *ai,
   msg_set_next(response, thci->thci_stackmsg = tport_msg_alloc(tport, 512));
 
   if (tport_send_msg(tport, msg, tpn, NULL) < 0) {
-    SU_DEBUG_9(("tport_send_msg failed in tpot_http_connect\n"));
+    SU_DEBUG_9(("tport_send_msg failed in tpot_http_connect\n" VA_NONE));
     msg_destroy(msg);
     tport_zap_secondary(tport);
     return NULL;
diff --git a/libs/spandsp/src/gsm0610_rpe.c b/libs/spandsp/src/gsm0610_rpe.c
index 28b1a72e79..c62d892ce7 100644
--- a/libs/spandsp/src/gsm0610_rpe.c
+++ b/libs/spandsp/src/gsm0610_rpe.c
@@ -59,7 +59,7 @@
 static void weighting_filter(int16_t x[40],
                              const int16_t *e)      // signal [-5..0.39.44] IN)
 {
-#if defined(__GNUC__)  &&  defined(SPANDSP_USE_MMX)  &&  defined(__x86_64__)
+#if defined(__GNUC__)  &&  defined(SPANDSP_USE_MMX)  &&  defined(__x86_64__) && !(defined(__APPLE_CC__)  && __APPLE_CC__ >= 5448)
     /* Table 4.4   Coefficients of the weighting filter */
     /* This must be padded to a multiple of 4 for MMX to work */
     static const union
diff --git a/libs/stfu/stfu.c b/libs/stfu/stfu.c
index 7ca036fc64..f02219cd9e 100644
--- a/libs/stfu/stfu.c
+++ b/libs/stfu/stfu.c
@@ -69,6 +69,7 @@ struct stfu_instance {
 	struct stfu_queue *old_queue;
     struct stfu_frame *last_frame;
 	uint32_t cur_ts;
+	uint16_t cur_seq;
 	uint32_t last_wr_ts;
 	uint32_t last_rd_ts;
 	uint32_t samples_per_packet;
@@ -361,6 +362,7 @@ void stfu_n_reset(stfu_instance_t *i)
     stfu_n_sync(i, 1);
     
     i->cur_ts = 0;
+    i->cur_seq = 0;
 	i->last_wr_ts = 0;
 	i->last_rd_ts = 0;
 	i->miss_count = 0;	
@@ -650,6 +652,7 @@ stfu_frame_t *stfu_n_read_a_frame(stfu_instance_t *i)
         for (x = 0; x < i->out_queue->array_len; x++) {
             if (!i->out_queue->array[x].was_read) {
                 i->cur_ts = i->out_queue->array[x].ts;
+                i->cur_ts = i->out_queue->array[x].seq;
                 break;
             }
             if (i->cur_ts == 0) {
@@ -661,6 +664,7 @@ stfu_frame_t *stfu_n_read_a_frame(stfu_instance_t *i)
         }
     } else {
         i->cur_ts = i->cur_ts + i->samples_per_packet;
+        i->cur_seq++;
     }
     
     found = stfu_n_find_frame(i, i->out_queue, i->last_wr_ts, i->cur_ts, &rframe);
@@ -679,12 +683,14 @@ stfu_frame_t *stfu_n_read_a_frame(stfu_instance_t *i)
 
     if (found) {
         i->cur_ts = rframe->ts;
+        i->cur_seq = rframe->seq;
     }
 
     if (i->sync_out) {
         if (!found) {
             if ((found = stfu_n_find_any_frame(i, i->out_queue, &rframe))) {
                 i->cur_ts = rframe->ts;
+                i->cur_seq = rframe->seq;
             }
             
             if (stfu_log != null_logger && i->debug) {
@@ -783,6 +789,7 @@ stfu_frame_t *stfu_n_read_a_frame(stfu_instance_t *i)
         rframe->dlen = i->plc_len;
         rframe->pt = i->plc_pt;
         rframe->ts = i->cur_ts;
+        rframe->seq = i->cur_seq;
         i->miss_count++;
         
         if (stfu_log != null_logger && i->debug) {
@@ -799,6 +806,38 @@ stfu_frame_t *stfu_n_read_a_frame(stfu_instance_t *i)
     return rframe;
 }
 
+int32_t stfu_n_copy_next_frame(stfu_instance_t *jb, uint32_t timestamp, uint16_t seq, uint16_t distance, stfu_frame_t *next_frame)
+{
+	uint32_t i = 0, j = 0;
+	stfu_queue_t *queues[] = { jb->out_queue, jb->in_queue, jb->old_queue};
+	stfu_queue_t *queue = NULL;
+	stfu_frame_t *frame = NULL;
+
+	uint32_t target_ts = 0;
+
+	if (!next_frame) return 0;
+
+	target_ts = timestamp + (distance - 1) * jb->samples_per_packet;
+
+	for (i = 0; i < sizeof(queues)/sizeof(queues[0]); i++) {
+		queue = queues[i];
+
+		if (!queue) continue;
+
+		for(j = 0; j < queue->array_size; j++) {
+			frame = &queue->array[j];
+			/* FIXME: ts rollover happened? bad luck */
+			if (frame->ts > target_ts) {
+				memcpy(next_frame, frame, sizeof(stfu_frame_t));
+				return 1;
+			}
+		}
+	}
+
+	return 0;
+}
+
+
 #ifdef WIN32
 #ifndef vsnprintf
 #define vsnprintf _vsnprintf
@@ -927,7 +966,6 @@ static void default_logger(const char *file, const char *func, int line, int lev
 
 }
 
-
 /* For Emacs:
  * Local Variables:
  * mode:c
diff --git a/libs/stfu/stfu.h b/libs/stfu/stfu.h
index e3d05bcbc1..bc3dd519ba 100644
--- a/libs/stfu/stfu.h
+++ b/libs/stfu/stfu.h
@@ -191,6 +191,7 @@ stfu_instance_t *stfu_n_init(uint32_t qlen, uint32_t max_qlen, uint32_t samples_
 stfu_status_t stfu_n_resize(stfu_instance_t *i, uint32_t qlen);
 stfu_status_t stfu_n_add_data(stfu_instance_t *i, uint32_t ts, uint16_t seq, uint32_t pt, void *data, size_t datalen, uint32_t timer_ts, int last);
 stfu_frame_t *stfu_n_read_a_frame(stfu_instance_t *i);
+int32_t stfu_n_copy_next_frame(stfu_instance_t *jb, uint32_t timestamp, uint16_t seq, uint16_t distance, stfu_frame_t *next_frame);
 void stfu_n_reset(stfu_instance_t *i);
 stfu_status_t stfu_n_sync(stfu_instance_t *i, uint32_t packets);
 void stfu_n_call_me(stfu_instance_t *i, stfu_n_call_me_t callback, void *udata);
diff --git a/src/include/private/switch_core_pvt.h b/src/include/private/switch_core_pvt.h
index b7d5f75868..40f51ba61a 100644
--- a/src/include/private/switch_core_pvt.h
+++ b/src/include/private/switch_core_pvt.h
@@ -256,8 +256,6 @@ struct switch_runtime {
 	switch_profile_timer_t *profile_timer;
 	double profile_time;
 	double min_idle_time;
-	int sql_buffer_len;
-	int max_sql_buffer_len;
 	switch_dbtype_t odbc_dbtype;
 	char hostname[256];
 	char *switchname;
diff --git a/src/include/switch.h b/src/include/switch.h
index 3cfa271be4..c7ea7b0218 100644
--- a/src/include/switch.h
+++ b/src/include/switch.h
@@ -106,7 +106,11 @@
 #include <signal.h>
 #include <errno.h>
 
+#ifndef WIN32
+#include "stfu.h"
+#else
 #include "../../../libs/stfu/stfu.h"
+#endif
 #include "switch_platform.h"
 #include "switch_types.h"
 #include "switch_apr.h"
diff --git a/src/include/switch_core.h b/src/include/switch_core.h
index a3898d9d64..ead85fdf4a 100644
--- a/src/include/switch_core.h
+++ b/src/include/switch_core.h
@@ -70,6 +70,12 @@ typedef struct switch_hold_record_s {
 } switch_hold_record_t;
 
 
+typedef struct switch_thread_data_s {
+	switch_thread_start_t func;
+	void *obj;
+	int alloc;
+} switch_thread_data_t;
+
 
 #define MESSAGE_STAMP_FFL(_m) _m->_file = __FILE__; _m->_func = __SWITCH_FUNC__; _m->_line = __LINE__
 
@@ -703,6 +709,7 @@ SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request_by_name(_In_
 SWITCH_DECLARE(switch_status_t) switch_core_session_thread_launch(_In_ switch_core_session_t *session);
 
 
+SWITCH_DECLARE(switch_status_t) switch_thread_pool_launch_thread(switch_thread_data_t **tdp);
 SWITCH_DECLARE(switch_status_t) switch_core_session_thread_pool_launch(switch_core_session_t *session);
 
 /*! 
@@ -818,14 +825,22 @@ SWITCH_DECLARE(void) switch_core_dump_variables(_In_ switch_stream_handle_t *str
 */
 SWITCH_DECLARE(void) switch_core_session_hupall(_In_ switch_call_cause_t cause);
 
+typedef enum {
+	SHT_NONE = 0,
+	SHT_UNANSWERED = (1 << 0),
+	SHT_ANSWERED = (1 << 1)
+} switch_hup_type_t;
+
 /*! 
   \brief Hangup all sessions which match a specific channel variable
   \param var_name The variable name to look for
   \param var_val The value to look for 
   \param cause the hangup cause to apply to the hungup channels
 */
-SWITCH_DECLARE(void) switch_core_session_hupall_matching_var(_In_ const char *var_name, _In_ const char *var_val, _In_ switch_call_cause_t cause);
+SWITCH_DECLARE(uint32_t) switch_core_session_hupall_matching_var_ans(_In_ const char *var_name, _In_ const char *var_val, _In_ 
+																	 switch_call_cause_t cause, switch_hup_type_t type);
 SWITCH_DECLARE(switch_console_callback_match_t *) switch_core_session_findall_matching_var(const char *var_name, const char *var_val);
+#define switch_core_session_hupall_matching_var(_vn, _vv, _c) switch_core_session_hupall_matching_var_ans(_vn, _vv, _c, SHT_UNANSWERED | SHT_ANSWERED)
 
 /*! 
   \brief Hangup all sessions that belong to an endpoint
@@ -2198,8 +2213,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_chat_send(const char *dest_proto, sw
 SWITCH_DECLARE(switch_status_t) switch_core_chat_deliver(const char *dest_proto, switch_event_t **message_event);
 
 SWITCH_DECLARE(switch_status_t) switch_ivr_preprocess_session(switch_core_session_t *session, const char *cmds);
-SWITCH_DECLARE(void) switch_core_sqldb_stop_thread(void);
-SWITCH_DECLARE(void) switch_core_sqldb_start_thread(void);
+SWITCH_DECLARE(void) switch_core_sqldb_pause(void);
+SWITCH_DECLARE(void) switch_core_sqldb_resume(void);
+
 
 ///\}
 
@@ -2418,17 +2434,22 @@ SWITCH_DECLARE(void) switch_core_recovery_untrack(switch_core_session_t *session
 SWITCH_DECLARE(void) switch_core_recovery_track(switch_core_session_t *session);
 SWITCH_DECLARE(void) switch_core_recovery_flush(const char *technology, const char *profile_name);
 
-SWITCH_DECLARE(switch_status_t) switch_switch_sql_queue_manager_push(switch_sql_queue_manager_t *qm, const char *sql, uint32_t pos, switch_bool_t dup);
-SWITCH_DECLARE(switch_status_t) switch_switch_sql_queue_manager_destroy(switch_sql_queue_manager_t **qmp);
-SWITCH_DECLARE(switch_status_t) switch_switch_sql_queue_manager_init(switch_sql_queue_manager_t **qmp, 
-																	 uint32_t numq, const char *dsn,
-																	 const char *pre_trans_execute,
-																	 const char *post_trans_execute,
-																	 const char *inner_pre_trans_execute,
-																	 const char *inner_post_trans_execute);
+SWITCH_DECLARE(int) switch_sql_queue_manager_size(switch_sql_queue_manager_t *qm, uint32_t index);
+SWITCH_DECLARE(switch_status_t) switch_sql_queue_manager_push_confirm(switch_sql_queue_manager_t *qm, const char *sql, uint32_t pos, switch_bool_t dup);
+SWITCH_DECLARE(switch_status_t) switch_sql_queue_manager_push(switch_sql_queue_manager_t *qm, const char *sql, uint32_t pos, switch_bool_t dup);
+SWITCH_DECLARE(switch_status_t) switch_sql_queue_manager_destroy(switch_sql_queue_manager_t **qmp);
+SWITCH_DECLARE(switch_status_t) switch_sql_queue_manager_init_name(const char *name,
+																   switch_sql_queue_manager_t **qmp, 
+																   uint32_t numq, const char *dsn, uint32_t max_trans,
+																   const char *pre_trans_execute,
+																   const char *post_trans_execute,
+																   const char *inner_pre_trans_execute,
+																   const char *inner_post_trans_execute);
 
-SWITCH_DECLARE(switch_status_t) switch_switch_sql_queue_manager_start(switch_sql_queue_manager_t *qm);
-SWITCH_DECLARE(switch_status_t) switch_switch_sql_queue_manager_stop(switch_sql_queue_manager_t *qm);
+#define switch_sql_queue_manager_init(_q, _n, _d, _m, _p1, _p2, _ip1, _ip2) switch_sql_queue_manager_init_name(__FILE__, _q, _n, _d, _m, _p1, _p2, _ip1, _ip2)
+
+SWITCH_DECLARE(switch_status_t) switch_sql_queue_manager_start(switch_sql_queue_manager_t *qm);
+SWITCH_DECLARE(switch_status_t) switch_sql_queue_manager_stop(switch_sql_queue_manager_t *qm);
 SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql_event_callback(switch_cache_db_handle_t *dbh,
 																		   const char *sql, switch_db_event_callback_func_t callback, void *pdata, char **err);
 							
diff --git a/src/include/switch_ivr.h b/src/include/switch_ivr.h
index 9299c584d9..06679f53d3 100644
--- a/src/include/switch_ivr.h
+++ b/src/include/switch_ivr.h
@@ -927,6 +927,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_set_user(switch_core_session_t *sessi
 SWITCH_DECLARE(switch_status_t) switch_ivr_sound_test(switch_core_session_t *session);
 SWITCH_DECLARE(void) switch_process_import(switch_core_session_t *session, switch_channel_t *peer_channel, const char *varname, const char *prefix);
 SWITCH_DECLARE(switch_bool_t) switch_ivr_uuid_exists(const char *uuid);
+SWITCH_DECLARE(switch_bool_t) switch_ivr_uuid_force_exists(const char *uuid);
 
 
 
diff --git a/src/include/switch_module_interfaces.h b/src/include/switch_module_interfaces.h
index deb96e4d47..d9fa1b2abf 100644
--- a/src/include/switch_module_interfaces.h
+++ b/src/include/switch_module_interfaces.h
@@ -618,6 +618,7 @@ struct switch_codec {
 	switch_mutex_t *mutex;
 	struct switch_codec *next;
 	switch_core_session_t *session;
+	switch_frame_t *cur_frame;
 };
 
 /*! \brief A table of settings and callbacks that define a paticular implementation of a codec */
diff --git a/src/include/switch_types.h b/src/include/switch_types.h
index b766d1db40..d7d96b5aaf 100644
--- a/src/include/switch_types.h
+++ b/src/include/switch_types.h
@@ -146,6 +146,7 @@ SWITCH_BEGIN_EXTERN_C
 #define SWITCH_CHANNEL_EXECUTE_ON_TONE_DETECT_VARIABLE "execute_on_tone_detect"
 #define SWITCH_CHANNEL_EXECUTE_ON_ORIGINATE_VARIABLE "execute_on_originate"
 #define SWITCH_CHANNEL_EXECUTE_ON_POST_ORIGINATE_VARIABLE "execute_on_post_originate"
+#define SWITCH_CHANNEL_EXECUTE_ON_PRE_ORIGINATE_VARIABLE "execute_on_pre_originate"
 
 #define SWITCH_CHANNEL_API_ON_ANSWER_VARIABLE "api_on_answer"
 #define SWITCH_CHANNEL_API_ON_PRE_ANSWER_VARIABLE "api_on_pre_answer"
@@ -154,6 +155,7 @@ SWITCH_BEGIN_EXTERN_C
 #define SWITCH_CHANNEL_API_ON_TONE_DETECT_VARIABLE "api_on_tone_detect"
 #define SWITCH_CHANNEL_API_ON_ORIGINATE_VARIABLE "api_on_originate"
 #define SWITCH_CHANNEL_API_ON_POST_ORIGINATE_VARIABLE "api_on_post_originate"
+#define SWITCH_CHANNEL_API_ON_PRE_ORIGINATE_VARIABLE "api_on_pre_originate"
 
 #define SWITCH_CALL_TIMEOUT_VARIABLE "call_timeout"
 #define SWITCH_HOLDING_UUID_VARIABLE "holding_uuid"
@@ -213,6 +215,7 @@ SWITCH_BEGIN_EXTERN_C
 #define SWITCH_BITS_PER_BYTE 8
 #define SWITCH_DEFAULT_FILE_BUFFER_LEN 65536
 #define SWITCH_DTMF_LOG_LEN 1000
+#define SWITCH_MAX_TRANS 2000
 typedef uint8_t switch_byte_t;
 
 /*!
@@ -463,6 +466,7 @@ typedef struct {
 struct switch_directories {
 	char *base_dir;
 	char *mod_dir;
+	char *lib_dir;
 	char *conf_dir;
 	char *log_dir;
 	char *run_dir;
@@ -1169,6 +1173,7 @@ typedef enum {
 	CF_OUTBOUND,
 	CF_EARLY_MEDIA,
 	CF_BRIDGE_ORIGINATOR,
+	CF_UUID_BRIDGE_ORIGINATOR,
 	CF_TRANSFER,
 	CF_ACCEPT_CNG,
 	CF_REDIRECT,
@@ -1299,7 +1304,8 @@ typedef enum {
 	SAF_SUPPORT_NOMEDIA = (1 << 0),
 	SAF_ROUTING_EXEC = (1 << 1),
 	SAF_MEDIA_TAP = (1 << 2),
-	SAF_ZOMBIE_EXEC = (1 << 3)
+	SAF_ZOMBIE_EXEC = (1 << 3),
+	SAF_NO_LOOPBACK = (1 << 4)
 } switch_application_flag_enum_t;
 typedef uint32_t switch_application_flag_t;
 
diff --git a/src/include/switch_xml.h b/src/include/switch_xml.h
index a29250ad49..173981e5b2 100644
--- a/src/include/switch_xml.h
+++ b/src/include/switch_xml.h
@@ -423,7 +423,7 @@ SWITCH_DECLARE(switch_status_t) switch_xml_unbind_search_function_ptr(_In_ switc
 ///\return the section mask
 SWITCH_DECLARE(switch_xml_section_t) switch_xml_parse_section_string(_In_opt_z_ const char *str);
 
-SWITCH_DECLARE(int) switch_xml_std_datetime_check(switch_xml_t xcond, int *offset);
+SWITCH_DECLARE(int) switch_xml_std_datetime_check(switch_xml_t xcond, int *offset, const char *tzname);
 
 SWITCH_DECLARE(switch_status_t) switch_xml_locate_language(switch_xml_t *root, switch_xml_t *node, switch_event_t *params, switch_xml_t *language, switch_xml_t *phrases, switch_xml_t *macros, const char *str_language);
 
diff --git a/src/mod/applications/mod_conference/mod_conference.c b/src/mod/applications/mod_conference/mod_conference.c
index 57e0636647..d5ea7e702a 100644
--- a/src/mod/applications/mod_conference/mod_conference.c
+++ b/src/mod/applications/mod_conference/mod_conference.c
@@ -8539,11 +8539,13 @@ static void conference_send_presence(conference_obj_t *conference)
 	}
 	
 }
-
-static void kickall_matching_var(conference_obj_t *conference, const char *var, const char *val)
+#if 0
+static uint32_t kickall_matching_var(conference_obj_t *conference, const char *var, const char *val)
 {
 	conference_member_t *member = NULL;
 	const char *vval = NULL;
+	uint32_t r = 0;
+
 	switch_mutex_lock(conference->mutex);
 	switch_mutex_lock(conference->member_mutex);
 
@@ -8560,14 +8562,18 @@ static void kickall_matching_var(conference_obj_t *conference, const char *var,
 		if (vval && !strcmp(vval, val)) {
 			switch_set_flag_locked(member, MFLAG_KICKED);
 			switch_clear_flag_locked(member, MFLAG_RUNNING);
-			switch_core_session_kill_channel(member->session, SWITCH_SIG_BREAK);			
+			switch_core_session_kill_channel(member->session, SWITCH_SIG_BREAK);
+			r++;
 		}
 
 	}	
 
 	switch_mutex_unlock(conference->member_mutex);
 	switch_mutex_unlock(conference->mutex);
+
+	return r;
 }
+#endif
 
 static void call_setup_event_handler(switch_event_t *event)
 {
@@ -8631,8 +8637,11 @@ static void call_setup_event_handler(switch_event_t *event)
 				}
 				
 			} else if (!strcasecmp(action, "end")) {
-				//switch_core_session_hupall_matching_var("conference_call_key", key, SWITCH_CAUSE_NORMAL_CLEARING);
-				kickall_matching_var(conference, "conference_call_key", key);
+				if (switch_core_session_hupall_matching_var("conference_call_key", key, SWITCH_CAUSE_NORMAL_CLEARING)) {
+					send_conference_notify(conference, "SIP/2.0 200 OK\r\n", call_id, SWITCH_TRUE);
+				} else {
+					send_conference_notify(conference, "SIP/2.0 481 Failure\r\n", call_id, SWITCH_TRUE);
+				}
 				status = SWITCH_STATUS_SUCCESS;
 			}
 
diff --git a/src/mod/applications/mod_dptools/mod_dptools.c b/src/mod/applications/mod_dptools/mod_dptools.c
index 158413b9e0..5e6a732841 100755
--- a/src/mod/applications/mod_dptools/mod_dptools.c
+++ b/src/mod/applications/mod_dptools/mod_dptools.c
@@ -1176,6 +1176,15 @@ SWITCH_STANDARD_APP(answer_function)
 	switch_channel_answer(channel);
 }
 
+SWITCH_STANDARD_APP(wait_for_answer_function)
+{
+	switch_channel_t *channel = switch_core_session_get_channel(session);
+	switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Waiting for answer\n");
+	while (!switch_channel_test_flag(channel, CF_ANSWERED) && switch_channel_ready(channel)) {
+		switch_ivr_sleep(session, 100, SWITCH_TRUE, NULL);
+	}
+}
+
 SWITCH_STANDARD_APP(presence_function)
 {
 	char *argv[6] = { 0 };
@@ -5083,6 +5092,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_dptools_load)
 				   zombie_function, "", SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC);
 	SWITCH_ADD_APP(app_interface, "pre_answer", "Pre-Answer the call", "Pre-Answer the call for a channel.", pre_answer_function, "", SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "answer", "Answer the call", "Answer the call for a channel.", answer_function, "", SAF_SUPPORT_NOMEDIA);
+	SWITCH_ADD_APP(app_interface, "wait_for_answer", "Wait for call to be answered", "Wait for call to be answered.", wait_for_answer_function, "", SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "hangup", "Hangup the call", "Hangup the call for a channel.", hangup_function, "[<cause>]", SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "set_name", "Name the channel", "Name the channel", set_name_function, "<name>", SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "presence", "Send Presence", "Send Presence.", presence_function, "<rpid> <status> [<id>]",
diff --git a/src/mod/applications/mod_sms/mod_sms.c b/src/mod/applications/mod_sms/mod_sms.c
index 8b747cb015..34b2971333 100644
--- a/src/mod/applications/mod_sms/mod_sms.c
+++ b/src/mod/applications/mod_sms/mod_sms.c
@@ -64,6 +64,16 @@ typedef enum {
 } break_t;
 
 
+#define check_tz() tzoff = switch_event_get_header(event, "tod_tz_offset"); \
+	tzname = switch_event_get_header(event, "timezone");			\
+	do {																\
+		if (!zstr(tzoff) && switch_is_number(tzoff)) {					\
+			offset = atoi(tzoff);										\
+		} else {														\
+			tzoff = NULL;												\
+		}																\
+		break;															\
+	} while(tzoff)														
 
 static int parse_exten(switch_event_t *event, switch_xml_t xexten, switch_event_t **extension)
 {
@@ -73,6 +83,10 @@ static int parse_exten(switch_event_t *event, switch_xml_t xexten, switch_event_
 	char *expression_expanded = NULL, *field_expanded = NULL;
 	switch_regex_t *re = NULL;
 	const char *to = switch_event_get_header(event, "to");
+	const char *tzoff = NULL, *tzname = NULL;
+	int offset = 0;
+
+	check_tz();
 
 	if (!to) {
 		to = "nobody";
@@ -90,8 +104,10 @@ static int parse_exten(switch_event_t *event, switch_xml_t xexten, switch_event_
 		int ovector[30];
 		switch_bool_t anti_action = SWITCH_TRUE;
 		break_t do_break_i = BREAK_ON_FALSE;
+		int time_match;
 
-		int time_match = switch_xml_std_datetime_check(xcond, NULL);
+		check_tz();
+		time_match = switch_xml_std_datetime_check(xcond, tzoff ? &offset : NULL, tzname);
 
 		switch_safe_free(field_expanded);
 		switch_safe_free(expression_expanded);
diff --git a/src/mod/applications/mod_spandsp/mod_spandsp.c b/src/mod/applications/mod_spandsp/mod_spandsp.c
index 6ee395770f..fa7a0da79a 100644
--- a/src/mod/applications/mod_spandsp/mod_spandsp.c
+++ b/src/mod/applications/mod_spandsp/mod_spandsp.c
@@ -714,9 +714,9 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_spandsp_init)
 				   t38_gateway_function, "", SAF_MEDIA_TAP);
 
 	SWITCH_ADD_APP(app_interface, "rxfax", "FAX Receive Application", "FAX Receive Application", spanfax_rx_function, SPANFAX_RX_USAGE,
-				   SAF_SUPPORT_NOMEDIA);
+				   SAF_SUPPORT_NOMEDIA | SAF_NO_LOOPBACK);
 	SWITCH_ADD_APP(app_interface, "txfax", "FAX Transmit Application", "FAX Transmit Application", spanfax_tx_function, SPANFAX_TX_USAGE,
-				   SAF_SUPPORT_NOMEDIA);
+				   SAF_SUPPORT_NOMEDIA | SAF_NO_LOOPBACK);
 
 	SWITCH_ADD_APP(app_interface, "spandsp_stop_dtmf", "stop inband dtmf", "Stop detecting inband dtmf.", stop_dtmf_session_function, "", SAF_NONE);
 	SWITCH_ADD_APP(app_interface, "spandsp_start_dtmf", "Detect dtmf", "Detect inband dtmf on the session", dtmf_session_function, "", SAF_MEDIA_TAP);
diff --git a/src/mod/applications/mod_voicemail/mod_voicemail.c b/src/mod/applications/mod_voicemail/mod_voicemail.c
index 8e58bfbac5..e6ce3aecf0 100644
--- a/src/mod/applications/mod_voicemail/mod_voicemail.c
+++ b/src/mod/applications/mod_voicemail/mod_voicemail.c
@@ -1604,7 +1604,18 @@ static switch_status_t listen_file(switch_core_session_t *session, vm_profile_t
 				*cc.buf = '\0';
 				goto play_file;
 			} else if (!strcmp(input, profile->callback_key)) {
-				switch_core_session_execute_exten(session, cbt->cid_number, profile->callback_dialplan, profile->callback_context);
+				const char *callback_dialplan;
+				const char *callback_context;
+
+				if (!(callback_dialplan = switch_channel_get_variable(channel, "voicemail_callback_dialplan"))) {
+					callback_dialplan = profile->callback_dialplan;
+				}
+
+				if (!(callback_context = switch_channel_get_variable(channel, "voicemail_callback_context"))) {
+					callback_context = profile->callback_context;
+				}
+
+				switch_core_session_execute_exten(session, cbt->cid_number, callback_dialplan, callback_context);
 			} else if (!strcmp(input, profile->forward_key)) {
 				char *cmd = NULL;
 				char *new_file_path = NULL;
diff --git a/src/mod/codecs/mod_silk/Makefile b/src/mod/codecs/mod_silk/Makefile
index 68ea756954..23d7811ee7 100644
--- a/src/mod/codecs/mod_silk/Makefile
+++ b/src/mod/codecs/mod_silk/Makefile
@@ -4,6 +4,7 @@ SILK_BUILDDIR=$(switch_builddir)/libs/silk
 LOCAL_CFLAGS=-I$(SILK_DIR)/src  -I$(SILK_DIR)/interface
 SILK_LA=$(SILK_BUILDDIR)/.libs/libSKP_SILK_SDK.la
 LOCAL_LIBADD=$(SILK_LA)
+LOCAL_OBJS=$(BASE)/libs/stfu/stfu.o
 include $(BASE)/build/modmake.rules
 
 $(SILK_LA): $(SILK_DIR)/.update	
diff --git a/src/mod/codecs/mod_silk/mod_silk.c b/src/mod/codecs/mod_silk/mod_silk.c
index af32332de2..922c86d06b 100644
--- a/src/mod/codecs/mod_silk/mod_silk.c
+++ b/src/mod/codecs/mod_silk/mod_silk.c
@@ -31,6 +31,7 @@
  */
 
 #include "switch.h"
+#include "stfu.h"
 #include "SKP_Silk_SDK_API.h"
 
 SWITCH_MODULE_LOAD_FUNCTION(mod_silk_load);
@@ -321,23 +322,43 @@ static switch_status_t switch_silk_decode(switch_codec_t *codec,
 	SKP_int16 ret, len; 
 	int16_t *target = decoded_data;
 	switch_core_session_t *session = codec->session;
-	stfu_instance_t *jb;
+	stfu_instance_t *jb = NULL;
+
+	SKP_int lost_flag = (*flag & SFF_PLC);
+	stfu_frame_t next_frame;
+
+	SKP_uint8 recbuff[STFU_DATALEN];
+	SKP_int16 reclen;
+	int32_t found_frame;
+	switch_bool_t did_lbrr = SWITCH_FALSE;
 
 	*decoded_data_len = 0;
 
-	if (session) {
-		jb = switch_core_session_get_jb(session, SWITCH_MEDIA_TYPE_AUDIO);
-	}
-
-	if (jb) {
-		/* to allow compile */
-		jb = NULL;
+	if (lost_flag) {
+		if (session) {
+			jb = switch_core_session_get_jb(session, SWITCH_MEDIA_TYPE_AUDIO);
+		}
+		if (jb && codec && codec->cur_frame) {
+			for (int i = 1; i <= MAX_LBRR_DELAY; i++) {
+				found_frame = stfu_n_copy_next_frame(jb, codec->cur_frame->timestamp, codec->cur_frame->seq, i, &next_frame);
+				if (found_frame) {
+					SKP_Silk_SDK_search_for_LBRR(next_frame.data, next_frame.dlen, i, (SKP_uint8*) &recbuff, &reclen);
+					if (reclen) {
+						encoded_data = &recbuff;
+						encoded_data_len = reclen;
+						lost_flag = SKP_FALSE;
+						did_lbrr = SWITCH_TRUE;
+						break;
+					}
+				}
+			}
+		}
 	}
 
 	do {
 		ret = SKP_Silk_SDK_Decode(context->dec_state,
 								  &context->decoder_object,
-								  ((*flag & SFF_PLC)),
+								  lost_flag,
 								  encoded_data,
 								  encoded_data_len,
 								  target,
@@ -345,6 +366,8 @@ static switch_status_t switch_silk_decode(switch_codec_t *codec,
 		if (ret){
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SKP_Silk_Decode returned %d!\n", ret);
 			printSilkError(ret);
+			/* if FEC was activated, we can ignore bit errors*/
+			if (! (ret == SKP_SILK_DEC_PAYLOAD_ERROR && did_lbrr))
 			return SWITCH_STATUS_FALSE;
 		}
 
diff --git a/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c b/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c
index 6b685d547d..ac1500c4f5 100644
--- a/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c
+++ b/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c
@@ -81,6 +81,7 @@ static switch_status_t exec_app(switch_core_session_t *session, const char *app,
 
 
 #define check_tz() tzoff = switch_channel_get_variable(channel, "tod_tz_offset"); \
+	tzname = switch_channel_get_variable(channel, "timezone");			\
 	do {																\
 		if (!zstr(tzoff) && switch_is_number(tzoff)) {					\
 			offset = atoi(tzoff);										\
@@ -99,7 +100,7 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t *
 	char *expression_expanded = NULL, *field_expanded = NULL;
 	switch_regex_t *re = NULL, *save_re = NULL;
 	int offset = 0;
-	const char *tzoff;
+	const char *tzoff = NULL, *tzname = NULL;
 
 	check_tz();
 
@@ -120,7 +121,7 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t *
 		int time_match;
 
 		check_tz();
-		time_match = switch_xml_std_datetime_check(xcond, tzoff ? &offset : NULL);
+		time_match = switch_xml_std_datetime_check(xcond, tzoff ? &offset : NULL, tzname);
 
 
 		switch_safe_free(field_expanded);
@@ -173,7 +174,7 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t *
 
 			for (xregex = switch_xml_child(xcond, "regex"); xregex; xregex = xregex->next) {
 				check_tz();
-				time_match = switch_xml_std_datetime_check(xregex, tzoff ? &offset : NULL);
+				time_match = switch_xml_std_datetime_check(xregex, tzoff ? &offset : NULL, tzname);
 				
 				if (time_match == 1) {
 					switch_log_printf(SWITCH_CHANNEL_SESSION_LOG_CLEAN(session), SWITCH_LOG_DEBUG,
diff --git a/src/mod/endpoints/mod_dingaling/mod_dingaling.c b/src/mod/endpoints/mod_dingaling/mod_dingaling.c
index 78ee260d05..f8f233aa87 100644
--- a/src/mod/endpoints/mod_dingaling/mod_dingaling.c
+++ b/src/mod/endpoints/mod_dingaling/mod_dingaling.c
@@ -1167,6 +1167,8 @@ static int activate_audio_rtp(struct private_object *tech_pvt)
 			r = 0;
 			goto end;
 		}
+		tech_pvt->transports[LDL_TPORT_RTP].read_codec.session = tech_pvt->session;
+
 		tech_pvt->transports[LDL_TPORT_RTP].read_frame.rate = tech_pvt->transports[LDL_TPORT_RTP].read_codec.implementation->samples_per_second;
 		tech_pvt->transports[LDL_TPORT_RTP].read_frame.codec = &tech_pvt->transports[LDL_TPORT_RTP].read_codec;
 
@@ -1186,6 +1188,7 @@ static int activate_audio_rtp(struct private_object *tech_pvt)
 			r = 0;
 			goto end;
 		}
+		tech_pvt->transports[LDL_TPORT_RTP].write_codec.session = tech_pvt->session;
 		switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG, "Set Write Codec to %s@%d\n",
 						  tech_pvt->transports[LDL_TPORT_RTP].codec_name, (int) tech_pvt->transports[LDL_TPORT_RTP].write_codec.implementation->samples_per_second);
 		
@@ -1511,8 +1514,14 @@ static int do_tport_candidates(struct private_object *tech_pvt, ldl_transport_ty
 	}
 	address = advip;
 
-	if(address && !strncasecmp(address, "host:", 5)) {
-		address = address + 5;
+	if (address && !strncasecmp(address, "host:", 5)) {
+		char *lookup = switch_stun_host_lookup(address + 5, switch_core_session_get_pool(tech_pvt->session));
+
+		if (zstr(lookup)) {
+			address = address + 5;
+		} else {
+			address = lookup;
+		}
 	}
 
 	memset(cand, 0, sizeof(*cand));
@@ -4177,7 +4186,7 @@ static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsessi
 				tech_pvt->them = switch_core_session_strdup(session, ldl_session_get_callee(dlsession));
 				tech_pvt->us = switch_core_session_strdup(session, ldl_session_get_caller(dlsession));
 
-				if ((tmp = strdup(tech_pvt->us))) {
+				if (tech_pvt->us && (tmp = strdup(tech_pvt->us))) {
 					char *p, *q;
 
 					if ((p = strchr(tmp, '@'))) {
diff --git a/src/mod/endpoints/mod_loopback/mod_loopback.c b/src/mod/endpoints/mod_loopback/mod_loopback.c
index 8835cc05a1..e711622d34 100644
--- a/src/mod/endpoints/mod_loopback/mod_loopback.c
+++ b/src/mod/endpoints/mod_loopback/mod_loopback.c
@@ -42,6 +42,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_loopback_load);
 SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_loopback_shutdown);
 SWITCH_MODULE_DEFINITION(mod_loopback, mod_loopback_load, mod_loopback_shutdown, NULL);
 
+static switch_status_t find_non_loopback_bridge(switch_core_session_t *session, switch_core_session_t **br_session, const char **br_uuid);
+
 static switch_endpoint_interface_t *loopback_endpoint_interface = NULL;
 
 typedef enum {
@@ -409,6 +411,8 @@ static switch_status_t channel_on_execute(switch_core_session_t *session)
 {
 	switch_channel_t *channel = NULL;
 	private_t *tech_pvt = NULL;
+	switch_caller_extension_t *exten;
+	int bow = 0;
 
 	channel = switch_core_session_get_channel(session);
 	assert(channel != NULL);
@@ -418,6 +422,37 @@ static switch_status_t channel_on_execute(switch_core_session_t *session)
 
 	switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s CHANNEL EXECUTE\n", switch_channel_get_name(channel));
 
+
+	if ((exten = switch_channel_get_caller_extension(channel))) {
+		switch_caller_application_t *app_p;
+
+		for (app_p = exten->applications; app_p; app_p = app_p->next) {
+			int32_t flags;
+
+			switch_core_session_get_app_flags(app_p->application_name, &flags);
+
+			if ((flags & SAF_NO_LOOPBACK)) {
+				bow = 1;
+				break;
+			}
+		}
+	}
+
+	if (bow) {
+		switch_core_session_t *other_session;
+		const char *other_uuid;
+
+		if ((find_non_loopback_bridge(tech_pvt->other_session, &other_session, &other_uuid) == SWITCH_STATUS_SUCCESS)) {
+			switch_caller_extension_t *extension;
+			switch_channel_t *other_channel = switch_core_session_get_channel(other_session);
+			switch_caller_extension_clone(&extension, exten, switch_core_session_get_pool(other_session));
+			switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_INFO, "BOWOUT Transfering current extension to non-loopback leg.\n");
+			switch_channel_transfer_to_extension(other_channel, extension);
+			switch_core_session_rwunlock(other_session);
+		}
+
+	}
+
 	return SWITCH_STATUS_SUCCESS;
 }
 
@@ -1126,8 +1161,11 @@ static switch_io_routines_t channel_io_routines = {
 	/*.receive_message */ channel_receive_message
 };
 
+SWITCH_STANDARD_APP(unloop_function) { /* NOOP */}
+
 SWITCH_MODULE_LOAD_FUNCTION(mod_loopback_load)
 {
+	switch_application_interface_t *app_interface;
 
 	memset(&globals, 0, sizeof(globals));
 
@@ -1138,6 +1176,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_loopback_load)
 	loopback_endpoint_interface->io_routines = &channel_io_routines;
 	loopback_endpoint_interface->state_handler = &channel_event_handlers;
 
+	SWITCH_ADD_APP(app_interface, "unloop", "Tell loopback to unfold", "Tell loopback to unfold", unloop_function, "", SAF_NO_LOOPBACK);
+
 	/* indicate that the module should continue to be loaded */
 	return SWITCH_STATUS_SUCCESS;
 }
diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c
index 14d501489c..c11d37c42f 100644
--- a/src/mod/endpoints/mod_sofia/mod_sofia.c
+++ b/src/mod/endpoints/mod_sofia/mod_sofia.c
@@ -1511,6 +1511,10 @@ static switch_status_t sofia_send_dtmf(switch_core_session_t *session, const swi
 	tech_pvt = (private_object_t *) switch_core_session_get_private(session);
 	switch_assert(tech_pvt != NULL);
 
+	if (sofia_test_flag(tech_pvt, TFLAG_DROP_DTMF)) {
+		return SWITCH_STATUS_SUCCESS;
+	}
+
 	dtmf_type = tech_pvt->dtmf_type;
 
 	/* We only can send INFO when we have no media */
@@ -2015,16 +2019,30 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
 							  switch_channel_get_name(channel), msg->string_arg);
 			sofia_glue_tech_set_local_sdp(tech_pvt, msg->string_arg, SWITCH_TRUE);
 
-			if(zstr(tech_pvt->local_sdp_str)) {
-				sofia_set_flag(tech_pvt, TFLAG_3PCC_INVITE);
+			if (msg->numeric_arg) { // ACK
+				switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "3PCC-PROXY nomedia - sending ack\n");
+				nua_ack(tech_pvt->nh,
+						TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)),
+						SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
+						SOATAG_USER_SDP_STR(msg->string_arg),
+						SOATAG_REUSE_REJECTED(1),
+						SOATAG_RTP_SELECT(1), SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"),
+						TAG_IF(sofia_test_pflag(tech_pvt->profile, PFLAG_DISABLE_100REL), NUTAG_INCLUDE_EXTRA_SDP(1)),
+						TAG_END());
+				sofia_clear_flag(tech_pvt, TFLAG_3PCC_INVITE);
+				
+			} else {
+				if(zstr(tech_pvt->local_sdp_str)) {
+					sofia_set_flag(tech_pvt, TFLAG_3PCC_INVITE);
+				}
+				
+				sofia_set_flag_locked(tech_pvt, TFLAG_SENT_UPDATE);
+				
+				if (!switch_channel_test_flag(channel, CF_PROXY_MEDIA)) {
+					switch_channel_set_flag(channel, CF_REQ_MEDIA);
+				}
+				sofia_glue_do_invite(session);
 			}
-
-			sofia_set_flag_locked(tech_pvt, TFLAG_SENT_UPDATE);
-
-			if (!switch_channel_test_flag(channel, CF_PROXY_MEDIA)) {
-				switch_channel_set_flag(channel, CF_REQ_MEDIA);
-			}
-			sofia_glue_do_invite(session);
 		}
 		break;
 
@@ -3636,7 +3654,7 @@ static switch_status_t cmd_profile(char **argv, int argc, switch_stream_handle_t
 		switch_xml_reload(&err);
 		stream->write_function(stream, "Reload XML [%s]\n", err);
 
-		if (config_sofia(1, argv[0]) == SWITCH_STATUS_SUCCESS) {
+		if (config_sofia(SOFIA_CONFIG_RESCAN, argv[0]) == SWITCH_STATUS_SUCCESS) {
 			stream->write_function(stream, "%s started successfully\n", argv[0]);
 		} else {
 			stream->write_function(stream, "Failure starting %s\n", argv[0]);
@@ -3713,7 +3731,7 @@ static switch_status_t cmd_profile(char **argv, int argc, switch_stream_handle_t
 		switch_xml_reload(&err);
 		stream->write_function(stream, "Reload XML [%s]\n", err);
 
-		if (reconfig_sofia(profile) == SWITCH_STATUS_SUCCESS) {
+		if (config_sofia(SOFIA_CONFIG_RESCAN, profile->name) == SWITCH_STATUS_SUCCESS) {
 			stream->write_function(stream, "+OK scan complete\n");
 		} else {
 			stream->write_function(stream, "-ERR cannot find config for profile %s\n", profile->name);
@@ -4900,8 +4918,7 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
 		sql = switch_mprintf("insert into sip_dialogs (uuid,presence_id,presence_data,profile_name,hostname,rcd,call_info_state) "
 							 "values ('%q', '%q', '%q', '%q', '%q', %ld, '')", switch_core_session_get_uuid(nsession),
 							 switch_str_nil(presence_id), switch_str_nil(presence_data), profile->name, mod_sofia_globals.hostname, (long) now);
-		sofia_glue_actually_execute_sql(profile, sql, profile->ireg_mutex);
-		switch_safe_free(sql);
+		sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
 	}
 #endif
 
@@ -5708,8 +5725,13 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sofia_load)
 	/* start one message thread */
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Starting initial message thread.\n");
 	sofia_msg_thread_start(0);
+	
 
-	if (config_sofia(0, NULL) != SWITCH_STATUS_SUCCESS) {
+	if (sofia_init() != SWITCH_STATUS_SUCCESS) {
+		return SWITCH_STATUS_GENERR;
+	}
+	
+	if (config_sofia(SOFIA_CONFIG_LOAD, NULL) != SWITCH_STATUS_SUCCESS) {
 		mod_sofia_globals.running = 0;
 		return SWITCH_STATUS_GENERR;
 	}
diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h
index ecb2d1c149..864d3a1e6f 100644
--- a/src/mod/endpoints/mod_sofia/mod_sofia.h
+++ b/src/mod/endpoints/mod_sofia/mod_sofia.h
@@ -138,6 +138,12 @@ typedef struct private_object private_object_t;
 #include <sofia-sip/msg.h>
 #include <sofia-sip/uniqueid.h>
 
+typedef enum {
+	SOFIA_CONFIG_LOAD = 0,
+	SOFIA_CONFIG_RESCAN,
+	SOFIA_CONFIG_RESPAWN
+} sofia_config_t;
+
 typedef enum {
 	DTMF_2833,
 	DTMF_INFO,
@@ -241,7 +247,7 @@ typedef enum {
 	PFLAG_DISABLE_HOLD,
 	PFLAG_AUTO_NAT,
 	PFLAG_SIPCOMPACT,
-	PFLAG_SQL_IN_TRANS,
+	PFLAG_USE_ME,
 	PFLAG_PRESENCE_PRIVACY,
 	PFLAG_PASS_CALLEE_ID,
 	PFLAG_LOG_AUTH_FAIL,
@@ -273,6 +279,7 @@ typedef enum {
 	PFLAG_MWI_USE_REG_CALLID,
 	PFLAG_FIRE_MESSAGE_EVENTS,
 	PFLAG_SEND_DISPLAY_UPDATE,
+	PFLAG_RUNNING_TRANS,
 	/* No new flags below this line */
 	PFLAG_MAX
 } PFLAGS;
@@ -345,6 +352,7 @@ typedef enum {
 	TFLAG_SLA_BARGING,
 	TFLAG_PASS_ACK,
 	TFLAG_CRYPTO_RECOVER,
+	TFLAG_DROP_DTMF,
 	/* No new flags below this line */
 	TFLAG_MAX
 } TFLAGS;
@@ -632,7 +640,7 @@ struct sofia_profile {
 	char *post_trans_execute;
 	char *inner_pre_trans_execute;
 	char *inner_post_trans_execute;	
-	switch_queue_t *sql_queue;
+	switch_sql_queue_manager_t *qm;
 	char *acl[SOFIA_MAX_ACL];
 	char *acl_pass_context[SOFIA_MAX_ACL];
 	char *acl_fail_context[SOFIA_MAX_ACL];
@@ -965,7 +973,7 @@ void sofia_presence_event_handler(switch_event_t *event);
 
 
 void sofia_presence_cancel(void);
-switch_status_t config_sofia(int reload, char *profile_name);
+switch_status_t config_sofia(sofia_config_t reload, char *profile_name);
 void sofia_reg_auth_challenge(sofia_profile_t *profile, nua_handle_t *nh, sofia_dispatch_event_t *de,
 							  sofia_regtype_t regtype, const char *realm, int stale);
 auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t const *authorization,
@@ -1117,7 +1125,6 @@ switch_status_t sofia_glue_tech_choose_video_port(private_object_t *tech_pvt, in
 switch_status_t sofia_glue_tech_set_video_codec(private_object_t *tech_pvt, int force);
 char *sofia_glue_get_register_host(const char *uri);
 const char *sofia_glue_strip_proto(const char *uri);
-switch_status_t reconfig_sofia(sofia_profile_t *profile);
 void sofia_glue_del_gateway(sofia_gateway_t *gp);
 void sofia_glue_gateway_list(sofia_profile_t *profile, switch_stream_handle_t *stream, int up);
 void sofia_glue_del_every_gateway(sofia_profile_t *profile);
@@ -1198,6 +1205,7 @@ void crtp_init(switch_loadable_module_interface_t *module_interface);
 int sofia_recover_callback(switch_core_session_t *session);
 void sofia_glue_set_name(private_object_t *tech_pvt, const char *channame);
 private_object_t *sofia_glue_new_pvt(switch_core_session_t *session);
+switch_status_t sofia_init(void);
 
 /* For Emacs:
  * Local Variables:
diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c
index 979e185781..4a074088fc 100644
--- a/src/mod/endpoints/mod_sofia/sofia.c
+++ b/src/mod/endpoints/mod_sofia/sofia.c
@@ -1133,6 +1133,8 @@ static void our_sofia_event_callback(nua_event_t event,
 	case nua_i_ack:
 		{
 			if (channel && sip) {
+				char *r_sdp = NULL;
+
 				if (sip->sip_to && sip->sip_to->a_tag) {
 					switch_channel_set_variable(channel, "sip_to_tag", sip->sip_to->a_tag);
 				}
@@ -1155,6 +1157,35 @@ static void our_sofia_event_callback(nua_event_t event,
 				switch_core_recovery_track(session);
 				sofia_set_flag(tech_pvt, TFLAG_GOT_ACK);
 
+				if (sip->sip_payload && sip->sip_payload->pl_data && sip->sip_content_type && 
+					sip->sip_content_type->c_subtype && switch_stristr("sdp", sip->sip_content_type->c_subtype)) {
+					r_sdp = sip->sip_payload->pl_data;
+				}
+
+				if (!zstr(r_sdp) && (sofia_test_flag(tech_pvt, TFLAG_3PCC_INVITE) || switch_channel_test_flag(tech_pvt->channel, CF_PROXY_MODE))) {
+					switch_core_session_t *other_session;
+					sofia_set_flag(tech_pvt, TFLAG_SDP);
+					if (switch_core_session_get_partner(session, &other_session) == SWITCH_STATUS_SUCCESS) {
+						switch_core_session_message_t *msg;
+						switch_channel_t *other_channel = switch_core_session_get_channel(other_session);
+						
+						if (!switch_channel_get_variable(other_channel, SWITCH_B_SDP_VARIABLE)) {
+							switch_channel_set_variable(other_channel, SWITCH_B_SDP_VARIABLE, r_sdp);
+						}
+						
+						msg = switch_core_session_alloc(other_session, sizeof(*msg));
+						msg->message_id = SWITCH_MESSAGE_INDICATE_MEDIA_REDIRECT;
+						msg->from = __FILE__;
+						msg->string_arg = switch_core_session_strdup(other_session, r_sdp);
+						msg->numeric_arg = 1; // send ack
+						switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Passing SDP ACK to other leg.\n%s\n", r_sdp);
+						
+						switch_core_session_queue_message(other_session, msg);
+						
+						switch_core_session_rwunlock(other_session);
+					}
+				}
+
 				if (sofia_test_flag(tech_pvt, TFLAG_PASS_ACK)) {
 					switch_core_session_t *other_session;
 					
@@ -1520,6 +1551,28 @@ void *SWITCH_THREAD_FUNC sofia_msg_thread_run_once(switch_thread_t *thread, void
 	return NULL;
 }
 
+void sofia_process_dispatch_event_in_thread(sofia_dispatch_event_t **dep)
+{
+	sofia_dispatch_event_t *de = *dep; 
+	switch_memory_pool_t *pool;
+	sofia_profile_t *profile = (*dep)->profile;
+	switch_thread_data_t *td;
+
+	switch_core_new_memory_pool(&pool);
+
+	*dep = NULL;
+	de->pool = pool;
+
+	td = switch_core_alloc(pool, sizeof(*td));
+	td->func = sofia_msg_thread_run_once;
+	td->obj = de;
+
+	switch_mutex_lock(profile->ireg_mutex);
+	switch_thread_pool_launch_thread(&td);
+	switch_mutex_unlock(profile->ireg_mutex);
+}
+
+#if 0
 void sofia_process_dispatch_event_in_thread(sofia_dispatch_event_t **dep)
 {
 	sofia_dispatch_event_t *de = *dep; 
@@ -1551,6 +1604,7 @@ void sofia_process_dispatch_event_in_thread(sofia_dispatch_event_t **dep)
 		sofia_process_dispatch_event(&de);
 	}
 }
+#endif
 
 void sofia_process_dispatch_event(sofia_dispatch_event_t **dep)
 {
@@ -1615,7 +1669,6 @@ void *SWITCH_THREAD_FUNC sofia_msg_thread_run(switch_thread_t *thread, void *obj
 		if (pop) {
 			sofia_dispatch_event_t *de = (sofia_dispatch_event_t *) pop;
 			sofia_process_dispatch_event(&de);
-			switch_os_yield();
 		} else {
 			break;
 		}
@@ -1936,13 +1989,6 @@ void sofia_event_callback(nua_event_t event,
 
  end:
 
-	if (profile->pres_type) {
-		switch_cond_next();
-	} else {
-		switch_os_yield();
-	}
-
-
 	return;
 }
 
@@ -2158,153 +2204,63 @@ void *SWITCH_THREAD_FUNC sofia_profile_worker_thread_run(switch_thread_t *thread
 	sofia_profile_t *profile = (sofia_profile_t *) obj;
 	uint32_t ireg_loops = profile->ireg_seconds;					/* Number of loop iterations done when we haven't checked for registrations */
 	uint32_t gateway_loops = GATEWAY_SECONDS;			/* Number of loop iterations done when we haven't checked for gateways */
-	void *pop = NULL;					/* queue_pop placeholder */
-	switch_size_t sql_len = 1024 * 32;	/* length of sqlbuf */
-	char *tmp, *sqlbuf = NULL;			/* Buffer for SQL statements */
-	char *sql = NULL;					/* Current SQL statement */
-	switch_time_t last_commit;			/* Last time we committed stuff to the DB */
-	switch_time_t last_check;			/* Last time we did the second-resolution loop that checks various stuff */
-	switch_size_t len = 0;				/* Current length of sqlbuf */
-	uint32_t statements = 0;			/* Number of statements in the current sql buffer */
-	
-	last_commit = last_check = switch_micro_time_now();
-	
-	if (sofia_test_pflag(profile, PFLAG_SQL_IN_TRANS)) {
-		sqlbuf = (char *) malloc(sql_len);
-	}
 
 	sofia_set_pflag_locked(profile, PFLAG_WORKER_RUNNING);
 
-	switch_queue_create(&profile->sql_queue, SOFIA_QUEUE_SIZE, profile->pool);
-
-	/* While we're running, or there is a pending sql statment that we haven't appended to sqlbuf yet, because of a lack of buffer space */
-	while ((mod_sofia_globals.running == 1 && sofia_test_pflag(profile, PFLAG_RUNNING)) || sql) {
-
-		if (sofia_test_pflag(profile, PFLAG_SQL_IN_TRANS)) {
-			/* Do we have enough statements or is the timeout expired */
-			while (sql || (sofia_test_pflag(profile, PFLAG_RUNNING) && mod_sofia_globals.running == 1 &&
-						switch_micro_time_now() - last_check < 1000000 &&
-				    	(statements == 0 || (statements <= 1024 && (switch_micro_time_now() - last_commit)/1000 < profile->trans_timeout)))) {
+	while ((mod_sofia_globals.running == 1 && sofia_test_pflag(profile, PFLAG_RUNNING))) {
+		
+		if (profile->watchdog_enabled) {
+			uint32_t event_diff = 0, step_diff = 0, event_fail = 0, step_fail = 0;
+			
+			if (profile->step_timeout) {
+				step_diff = (uint32_t) ((switch_time_now() - profile->last_root_step) / 1000);
 				
-				switch_interval_time_t sleepy_time = !statements ? 1000000 : switch_micro_time_now() - last_commit - profile->trans_timeout*1000;
-
-				if (sleepy_time < 1000 || sleepy_time > 1000000) {
-					sleepy_time = 1000;
-				}
-				
-				if (sql || (switch_queue_pop_timeout(profile->sql_queue, &pop, sleepy_time) == SWITCH_STATUS_SUCCESS && pop)) {
-					switch_size_t newlen;
-					
-					if (!sql) sql = (char *) pop;
-
-					newlen = strlen(sql) + 2 /* strlen(";\n") */ ;
-
-					if (len + newlen + 10 > sql_len) {
-						switch_size_t new_mlen = len + newlen + 10 + 10240;
-						
-						if (new_mlen < SQLLEN) {
-							sql_len = new_mlen;
-							
-							if (!(tmp = realloc(sqlbuf, sql_len))) {
-								abort();
-								break;
-							}
-							sqlbuf = tmp;
-						} else {
-							break;
-						}
-					}
-
-					sprintf(sqlbuf + len, "%s;\n", sql);
-					len += newlen;
-					free(sql);
-					sql = NULL;
-					
-					statements++;
+				if (step_diff > profile->step_timeout) {
+					step_fail = 1;
 				}
 			}
 			
-			/* Execute here */
-			last_commit = switch_micro_time_now();
-			
-			if (len) {
-				//printf("TRANS:\n%s\n", sqlbuf);
-				switch_mutex_lock(profile->ireg_mutex);
-				sofia_glue_actually_execute_sql_trans(profile, sqlbuf, NULL);
-				//sofia_glue_actually_execute_sql(profile, "commit;\n", NULL);
-				switch_mutex_unlock(profile->ireg_mutex);
-				statements = 0;
-				len = 0;
+			if (profile->event_timeout) {
+				event_diff = (uint32_t) ((switch_time_now() - profile->last_sip_event) / 1000);
+				
+				if (event_diff > profile->event_timeout) {
+					event_fail = 1;
+				}
 			}
-
-		} else {
-			if (switch_queue_pop_timeout(profile->sql_queue, &pop, 1000000) == SWITCH_STATUS_SUCCESS && pop) {
-				sofia_glue_actually_execute_sql(profile, (char *) pop, profile->ireg_mutex);
-				free(pop);
+			
+			if (step_fail && profile->event_timeout && !event_fail) {
+				step_fail = 0;
+			}
+			
+			if (event_fail || step_fail) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Profile %s: SIP STACK FAILURE DETECTED BY WATCHDOG!\n"
+								  "GOODBYE CRUEL WORLD, I'M LEAVING YOU TODAY....GOODBYE, GOODBYE, GOOD BYE\n", profile->name);
+				switch_yield(2000000);
+				watchdog_triggered_abort();
 			}
 		}
 
-		if (switch_micro_time_now() - last_check >= 1000000) {
-			if (profile->watchdog_enabled) {
-				uint32_t event_diff = 0, step_diff = 0, event_fail = 0, step_fail = 0;
-				
-				if (profile->step_timeout) {
-					step_diff = (uint32_t) ((switch_time_now() - profile->last_root_step) / 1000);
 
-					if (step_diff > profile->step_timeout) {
-						step_fail = 1;
-					}
-				}
-
-				if (profile->event_timeout) {
-					event_diff = (uint32_t) ((switch_time_now() - profile->last_sip_event) / 1000);
-
-					if (event_diff > profile->event_timeout) {
-						event_fail = 1;
-					}
-				}
-
-				if (step_fail && profile->event_timeout && !event_fail) {
-					step_fail = 0;
-				}
-
-				if (event_fail || step_fail) {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Profile %s: SIP STACK FAILURE DETECTED BY WATCHDOG!\n"
-									  "GOODBYE CRUEL WORLD, I'M LEAVING YOU TODAY....GOODBYE, GOODBYE, GOOD BYE\n", profile->name);
-					switch_yield(2000000);
-					watchdog_triggered_abort();
-				}
-			}
-
-
-			if (!sofia_test_pflag(profile, PFLAG_STANDBY)) {
-				if (++ireg_loops >= IREG_SECONDS) {
-					time_t now = switch_epoch_time_now(NULL);
-					sofia_reg_check_expire(profile, now, 0);
-					ireg_loops = 0;
-				}
-
-				if (++gateway_loops >= GATEWAY_SECONDS) {
-					sofia_reg_check_gateway(profile, switch_epoch_time_now(NULL));
-					gateway_loops = 0;
-				}
-			
-				sofia_sub_check_gateway(profile, time(NULL));
+		if (!sofia_test_pflag(profile, PFLAG_STANDBY)) {
+			if (++ireg_loops >= IREG_SECONDS) {
+				time_t now = switch_epoch_time_now(NULL);
+				sofia_reg_check_expire(profile, now, 0);
+				ireg_loops = 0;
 			}
 			
-			last_check = switch_micro_time_now();
+			if (++gateway_loops >= GATEWAY_SECONDS) {
+				sofia_reg_check_gateway(profile, switch_epoch_time_now(NULL));
+				gateway_loops = 0;
+			}
+			
+			sofia_sub_check_gateway(profile, time(NULL));
 		}
-	}
 
-	switch_mutex_lock(profile->ireg_mutex);
-	while (switch_queue_trypop(profile->sql_queue, &pop) == SWITCH_STATUS_SUCCESS && pop) {
-		sofia_glue_actually_execute_sql(profile, (char *) pop, NULL);
-		free(pop);
+		switch_yield(1000000);
+		
 	}
-	switch_mutex_unlock(profile->ireg_mutex);
 
 	sofia_clear_pflag_locked(profile, PFLAG_WORKER_RUNNING);
-	switch_safe_free(sqlbuf);
 
 	return NULL;
 }
@@ -2409,6 +2365,7 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void
 	int sanity;
 	switch_thread_t *worker_thread;
 	switch_status_t st;
+	char qname [128] = "";
 
 	switch_mutex_lock(mod_sofia_globals.mutex);
 	mod_sofia_globals.threads++;
@@ -2596,6 +2553,18 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void
 	switch_mutex_init(&profile->ireg_mutex, SWITCH_MUTEX_NESTED, profile->pool);
 	switch_mutex_init(&profile->gateway_mutex, SWITCH_MUTEX_NESTED, profile->pool);
 
+	switch_snprintf(qname, sizeof(qname), "sofia:%s", profile->name);
+	switch_sql_queue_manager_init_name(qname,
+									   &profile->qm,
+									   1,
+									   profile->odbc_dsn ? profile->odbc_dsn : profile->dbname,
+									   SWITCH_MAX_TRANS,
+									   profile->pre_trans_execute,
+									   profile->post_trans_execute,
+									   profile->inner_pre_trans_execute,
+									   profile->inner_post_trans_execute);
+	switch_sql_queue_manager_start(profile->qm);
+
 	if (switch_event_create(&s_event, SWITCH_EVENT_PUBLISH) == SWITCH_STATUS_SUCCESS) {
 		switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "service", "_sip._udp,_sip._tcp,_sip._sctp%s",
 								(sofia_test_pflag(profile, PFLAG_TLS)) ? ",_sips._tcp" : "");
@@ -2682,6 +2651,8 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void
 	switch_mutex_lock(profile->flag_mutex);
 	switch_mutex_unlock(profile->flag_mutex);
 
+	switch_sql_queue_manager_destroy(&profile->qm);
+
 	if (switch_event_create(&s_event, SWITCH_EVENT_UNPUBLISH) == SWITCH_STATUS_SUCCESS) {
 		switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "service", "_sip._udp,_sip._tcp,_sip._sctp%s",
 								(sofia_test_pflag(profile, PFLAG_TLS)) ? ",_sips._tcp" : "");
@@ -2725,7 +2696,7 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write unlock %s\n", profile->name);
 
 	if (sofia_test_pflag(profile, PFLAG_RESPAWN)) {
-		config_sofia(1, profile->name);
+		config_sofia(SOFIA_CONFIG_RESPAWN, profile->name);
 	}
 	
 	sofia_profile_destroy(profile);
@@ -3442,799 +3413,34 @@ static void config_sofia_profile_urls(sofia_profile_t * profile)
 	}
 }
 
-switch_status_t reconfig_sofia(sofia_profile_t *profile)
+switch_status_t sofia_init(void)
 {
-	switch_xml_t cfg, xml = NULL, xprofile, profiles, gateways_tag, domain_tag, domains_tag, aliases_tag, alias_tag, settings, param;
-	char *cf = "sofia.conf";
-	switch_event_t *params = NULL;
-	switch_status_t status = SWITCH_STATUS_FALSE;
-
-	switch_event_create(&params, SWITCH_EVENT_REQUEST_PARAMS);
-	switch_assert(params);
-	switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "profile", profile->name);
-	switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "reconfig", "true");
-
-	if (!(xml = switch_xml_open_cfg(cf, &cfg, params))) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", cf);
-		status = SWITCH_STATUS_FALSE;
-		goto done;
+	su_init();
+	if (sip_update_default_mclass(sip_extend_mclass(NULL)) < 0) {
+		su_deinit();
+		return SWITCH_STATUS_GENERR;
 	}
 
-	if ((settings = switch_xml_child(cfg, "global_settings"))) {
-		for (param = switch_xml_child(settings, "param"); param; param = param->next) {
-			char *var = (char *) switch_xml_attr_soft(param, "name");
-			char *val = (char *) switch_xml_attr_soft(param, "value");
-			if (!strcasecmp(var, "log-level")) {
-				su_log_set_level(NULL, atoi(val));
-			} else if (!strcasecmp(var, "tracelevel")) {
-				mod_sofia_globals.tracelevel = switch_log_str2level(val);
-			} else if (!strcasecmp(var, "debug-presence")) {
-				mod_sofia_globals.debug_presence = atoi(val);
-			} else if (!strcasecmp(var, "debug-sla")) {
-				mod_sofia_globals.debug_sla = atoi(val);
-			} else if (!strcasecmp(var, "auto-restart")) {
-				mod_sofia_globals.auto_restart = switch_true(val);
-			} else if (!strcasecmp(var, "reg-deny-binding-fetch-and-no-lookup")) {          /* backwards compatibility */
-				mod_sofia_globals.reg_deny_binding_fetch_and_no_lookup = switch_true(val);  /* remove when noone complains about the extra lookup */
-				if (switch_true(val)) {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Enabling reg-deny-binding-fetch-and-no-lookup - this functionality is "
-					                                         "deprecated and will be removed - let FS devs know if you think it should stay\n");
-				}
-			} else if (!strcasecmp(var, "rewrite-multicasted-fs-path")) {
-				if( (!strcasecmp(val, "to_host")) || (!strcasecmp(val, "1")) ) {
-					/* old behaviour */
-                                	mod_sofia_globals.rewrite_multicasted_fs_path = 1;
-				} else if (!strcasecmp(val, "original_server_host")) {
-                                	mod_sofia_globals.rewrite_multicasted_fs_path = 2;
-				} else if (!strcasecmp(val, "original_hostname")) {
-                                	mod_sofia_globals.rewrite_multicasted_fs_path = 3;
-				} else {
-					mod_sofia_globals.rewrite_multicasted_fs_path = SWITCH_FALSE;
-				}
-			}
-			else if (!strcasecmp(var, "capture-server")) {
-                                 mod_sofia_globals.capture_server = switch_core_strdup(mod_sofia_globals.pool, val);
-                        }
-		}
-	}
-
-	if ((profiles = switch_xml_child(cfg, "profiles"))) {
-		for (xprofile = switch_xml_child(profiles, "profile"); xprofile; xprofile = xprofile->next) {
-			char *xprofilename = (char *) switch_xml_attr_soft(xprofile, "name");
-			char *xprofiledomain = (char *) switch_xml_attr(xprofile, "domain");
-
-			if (strcasecmp(profile->name, xprofilename)) {
-				continue;
-			}
-
-			/* you could change profile->foo here if it was a minor change like context or dialplan ... */
-			profile->acl_count = 0;
-			profile->nat_acl_count = 0;
-			profile->reg_acl_count = 0;
-			profile->proxy_acl_count = 0;
-			sofia_set_pflag(profile, PFLAG_STUN_ENABLED);
-			sofia_set_pflag(profile, PFLAG_PASS_CALLEE_ID);
-			profile->ib_calls = 0;
-			profile->ob_calls = 0;
-			profile->ib_failed_calls = 0;
-			profile->ob_failed_calls = 0;
-			profile->shutdown_type = "false";
-
-			if (xprofiledomain) {
-				profile->domain_name = switch_core_strdup(profile->pool, xprofiledomain);
-			}
-
-			if ((settings = switch_xml_child(xprofile, "settings"))) {
-				for (param = switch_xml_child(settings, "param"); param; param = param->next) {
-					char *var = (char *) switch_xml_attr_soft(param, "name");
-					char *val = (char *) switch_xml_attr_soft(param, "value");
-					if (!strcasecmp(var, "debug")) {
-						profile->debug = atoi(val);
-					} else if (!strcasecmp(var, "shutdown-on-fail")) {
-						profile->shutdown_type = switch_core_strdup(profile->pool, val);
-					} else if (!strcasecmp(var, "pass-callee-id")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_PASS_CALLEE_ID);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_PASS_CALLEE_ID);
-						}
-					} else if (!strcasecmp(var, "rtp-digit-delay")) {
-						int delay = val ? atoi(val) : 0;
-						
-						if (delay < 0) delay = 0;
-
-						profile->rtp_digit_delay = (uint32_t) delay;
-					} else if (!strcasecmp(var, "watchdog-enabled")) {
-						profile->watchdog_enabled = switch_true(val);
-					} else if (!strcasecmp(var, "watchdog-step-timeout")) {
-						profile->step_timeout = (unsigned long) atol(val);
-					} else if (!strcasecmp(var, "watchdog-event-timeout")) {
-						profile->event_timeout = (unsigned long) atol(val);
-					} else if (!strcasecmp(var, "in-dialog-chat")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_IN_DIALOG_CHAT);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_IN_DIALOG_CHAT);
-						}
-					} else if (!strcasecmp(var, "fire-message-events")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_FIRE_MESSAGE_EVENTS);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_FIRE_MESSAGE_EVENTS);
-						}
-					} else if (!strcasecmp(var, "disable-hold")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_DISABLE_HOLD);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_DISABLE_HOLD);
-						}
-					} else if (!strcasecmp(var, "auto-jitterbuffer-msec")) {
-						int msec = atoi(val);
-						if (msec > 19) {
-							profile->jb_msec = switch_core_strdup(profile->pool, val);
-						}
-					} else if (!strcasecmp(var, "sip-trace")) {
-						if (switch_true(val)) {
-							sofia_set_flag(profile, TFLAG_TPORT_LOG);
-						} else {
-							sofia_clear_flag(profile, TFLAG_TPORT_LOG);
-						}
-						nua_set_params(profile->nua, TPTAG_LOG(sofia_test_flag(profile, TFLAG_TPORT_LOG)), TAG_END());
-                                        } else if (!strcasecmp(var, "sip-capture")) {
-                                                if (switch_true(val)) {
-                                                        sofia_set_flag(profile, TFLAG_CAPTURE);
-                                                } else {
-                                                        sofia_clear_flag(profile, TFLAG_CAPTURE);
-                                                }
-                                                nua_set_params(profile->nua, TPTAG_CAPT(sofia_test_flag(profile, TFLAG_CAPTURE) ? mod_sofia_globals.capture_server : NULL), TAG_END());						
-					} else if (!strcasecmp(var, "send-message-query-on-register")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_MESSAGE_QUERY_ON_REGISTER);
-						} else if (!strcasecmp(val, "first-only")) {
-							sofia_clear_pflag(profile, PFLAG_MESSAGE_QUERY_ON_REGISTER);
-							sofia_set_pflag(profile, PFLAG_MESSAGE_QUERY_ON_FIRST_REGISTER);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_MESSAGE_QUERY_ON_REGISTER);
-							sofia_clear_pflag(profile, PFLAG_MESSAGE_QUERY_ON_FIRST_REGISTER);
-						}
-					} else if (!strcasecmp(var, "auto-rtp-bugs")) {
-						sofia_glue_parse_rtp_bugs(&profile->auto_rtp_bugs, val);
-					} else if (!strcasecmp(var, "manual-rtp-bugs")) {
-						sofia_glue_parse_rtp_bugs(&profile->manual_rtp_bugs, val);
-					} else if (!strcasecmp(var, "registration-thread-frequency")) {
-						profile->ireg_seconds = atoi(val);
-						if (profile->ireg_seconds < 0) {
-							profile->ireg_seconds = IREG_SECONDS;
-						}
-					} else if (!strcasecmp(var, "user-agent-string")) {
-						profile->user_agent = switch_core_strdup(profile->pool, val);
-					} else if (!strcasecmp(var, "auto-restart")) {
-						profile->auto_restart = switch_true(val);
-					} else if (!strcasecmp(var, "log-auth-failures")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_LOG_AUTH_FAIL);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_LOG_AUTH_FAIL);
-						}
-					} else if (!strcasecmp(var, "confirm-blind-transfer")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_CONFIRM_BLIND_TRANSFER);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_CONFIRM_BLIND_TRANSFER);
-						}
-					} else if (!strcasecmp(var, "send-display-update")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_SEND_DISPLAY_UPDATE);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_SEND_DISPLAY_UPDATE);
-						}
-					} else if (!strcasecmp(var, "mwi-use-reg-callid")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_MWI_USE_REG_CALLID);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_MWI_USE_REG_CALLID);
-						}
-					} else if (!strcasecmp(var, "presence-proto-lookup")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_PRESENCE_MAP);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_PRESENCE_MAP);
-						}
-					} else if (!strcasecmp(var, "profile-standby")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_STANDBY);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_STANDBY);
-						}
-					} else if (!strcasecmp(var, "liberal-dtmf")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_LIBERAL_DTMF);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_LIBERAL_DTMF);
-						}
-					} else if (!strcasecmp(var, "forward-unsolicited-mwi-notify")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_FORWARD_MWI_NOTIFY);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_FORWARD_MWI_NOTIFY);
-						}
-					} else if (!strcasecmp(var, "t38-passthru")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_T38_PASSTHRU);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_T38_PASSTHRU);
-						}
-					} else if (!strcasecmp(var, "presence-disable-early")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_PRESENCE_DISABLE_EARLY);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_PRESENCE_DISABLE_EARLY);
-						}
-					} else if (!strcasecmp(var, "ignore-183nosdp")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_IGNORE_183NOSDP);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_IGNORE_183NOSDP);
-						}
-					} else if (!strcasecmp(var, "renegotiate-codec-on-hold")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_RENEG_ON_HOLD);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_RENEG_ON_HOLD);
-						}
-					} else if (!strcasecmp(var, "renegotiate-codec-on-reinvite")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_RENEG_ON_REINVITE);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_RENEG_ON_REINVITE);
-						}
-					} else if (!strcasecmp(var, "presence-probe-on-register")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_PRESENCE_PROBE_ON_REGISTER);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_PRESENCE_PROBE_ON_REGISTER);
-						}
-
-					} else if (!strcasecmp(var, "send-presence-on-register")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_PRESENCE_ON_REGISTER);
-						} else if (!strcasecmp(val, "first-only")) {
-							sofia_clear_pflag(profile, PFLAG_PRESENCE_ON_REGISTER);
-							sofia_set_pflag(profile, PFLAG_PRESENCE_ON_FIRST_REGISTER);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_PRESENCE_ON_REGISTER);
-							sofia_clear_pflag(profile, PFLAG_PRESENCE_ON_FIRST_REGISTER);
-						}
-					} else if (!strcasecmp(var, "cid-in-1xx")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_CID_IN_1XX);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_CID_IN_1XX);
-						}
-					} else if (!strcasecmp(var, "dtmf-type")) {
-						if (!strcasecmp(val, "rfc2833")) {
-							profile->dtmf_type = DTMF_2833;
-						} else if (!strcasecmp(val, "info")) {
-							profile->dtmf_type = DTMF_INFO;
-						} else {
-							profile->dtmf_type = DTMF_NONE;
-						}
-					} else if (!strcasecmp(var, "caller-id-type")) {
-						profile->cid_type = sofia_cid_name2type(val);
-					} else if (!strcasecmp(var, "record-template")) {
-						profile->record_template = switch_core_strdup(profile->pool, val);
-					} else if (!strcasecmp(var, "record-path")) {
-						profile->record_path = switch_core_strdup(profile->pool, val);
-					} else if ((!strcasecmp(var, "inbound-no-media") || !strcasecmp(var, "inbound-bypass-media"))) {
-						if (switch_true(val)) {
-							sofia_set_flag(profile, TFLAG_INB_NOMEDIA);
-						} else {
-							sofia_clear_flag(profile, TFLAG_INB_NOMEDIA);
-						}
-					} else if (!strcasecmp(var, "force-subscription-expires")) {
-						int tmp = atoi(val);
-						if (tmp > 0) {
-							profile->force_subscription_expires = tmp;
-						}
-					} else if (!strcasecmp(var, "force-publish-expires")) {
-						int tmp = atoi(val);
-						if (tmp > 0) {
-							profile->force_publish_expires = tmp;
-						}
-					} else if (!strcasecmp(var, "inbound-late-negotiation")) {
-						if (switch_true(val)) {
-							sofia_set_flag(profile, TFLAG_LATE_NEGOTIATION);
-						} else {
-							sofia_clear_flag(profile, TFLAG_LATE_NEGOTIATION);
-						}
-					} else if (!strcasecmp(var, "inbound-proxy-media")) {
-						if (switch_true(val)) {
-							sofia_set_flag(profile, TFLAG_PROXY_MEDIA);
-						} else {
-							sofia_clear_flag(profile, TFLAG_PROXY_MEDIA);
-						}
-					} else if (!strcasecmp(var, "inbound-zrtp-passthru")) {
-						if (switch_true(val)) {
-							sofia_set_flag(profile, TFLAG_ZRTP_PASSTHRU);
-						} else {
-							sofia_clear_flag(profile, TFLAG_ZRTP_PASSTHRU);
-						}
-					} else if (!strcasecmp(var, "inbound-use-callid-as-uuid")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_CALLID_AS_UUID);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_CALLID_AS_UUID);
-						}
-					} else if (!strcasecmp(var, "inbound-reg-in-new-thread")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_THREAD_PER_REG);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_THREAD_PER_REG);
-						}
-					} else if (!strcasecmp(var, "rtp-autoflush-during-bridge")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_RTP_AUTOFLUSH_DURING_BRIDGE);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_RTP_AUTOFLUSH_DURING_BRIDGE);
-						}
-					} else if (!strcasecmp(var, "rtp-notimer-during-bridge")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_RTP_NOTIMER_DURING_BRIDGE);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_RTP_NOTIMER_DURING_BRIDGE);
-						}
-					} else if (!strcasecmp(var, "manual-redirect")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_MANUAL_REDIRECT);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_MANUAL_REDIRECT);
-						}
-					} else if (!strcasecmp(var, "outbound-use-uuid-as-callid")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_UUID_AS_CALLID);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_UUID_AS_CALLID);
-						}
-					} else if (!strcasecmp(var, "NDLB-received-in-nat-reg-contact")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_RECIEVED_IN_NAT_REG_CONTACT);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_RECIEVED_IN_NAT_REG_CONTACT);
-						}
-					} else if (!strcasecmp(var, "NDLB-allow-bad-iananame")) {
-						if (switch_true(val)) {
-							profile->ndlb |= PFLAG_NDLB_ALLOW_BAD_IANANAME;
-						} else {
-							profile->ndlb &= ~PFLAG_NDLB_ALLOW_BAD_IANANAME;
-						}
-					} else if (!strcasecmp(var, "NDLB-expires-in-register-response")) {
-						if (switch_true(val)) {
-							profile->ndlb |= PFLAG_NDLB_EXPIRES_IN_REGISTER_RESPONSE;
-						} else {
-							profile->ndlb &= ~PFLAG_NDLB_EXPIRES_IN_REGISTER_RESPONSE;
-						}
-					} else if (!strcasecmp(var, "NDLB-allow-crypto-in-avp")) {
-						if (switch_true(val)) {
-							profile->ndlb |= PFLAG_NDLB_ALLOW_CRYPTO_IN_AVP;
-						} else {
-							profile->ndlb &= ~PFLAG_NDLB_ALLOW_CRYPTO_IN_AVP;
-						}
-					} else if (!strcasecmp(var, "NDLB-allow-nondup-sdp")) {
-						if (switch_true(val)) {
-							profile->ndlb |= PFLAG_NDLB_ALLOW_NONDUP_SDP;
-						} else {
-							profile->ndlb &= ~PFLAG_NDLB_ALLOW_NONDUP_SDP;
-						}
-					} else if (!strcasecmp(var, "aggressive-nat-detection")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_AGGRESSIVE_NAT_DETECTION);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_AGGRESSIVE_NAT_DETECTION);
-						}
-					} else if (!strcasecmp(var, "disable-rtp-auto-adjust")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_DISABLE_RTP_AUTOADJ);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_DISABLE_RTP_AUTOADJ);
-						}
-					} else if (!strcasecmp(var, "NDLB-support-asterisk-missing-srtp-auth")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_DISABLE_SRTP_AUTH);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_DISABLE_SRTP_AUTH);
-						}
-					} else if (!strcasecmp(var, "NDLB-funny-stun")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_FUNNY_STUN);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_FUNNY_STUN);
-						}
-					} else if (!strcasecmp(var, "stun-enabled")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_STUN_ENABLED);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_STUN_ENABLED);
-						}
-					} else if (!strcasecmp(var, "stun-auto-disable")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_STUN_AUTO_DISABLE);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_STUN_AUTO_DISABLE);
-						}
-					} else if (!strcasecmp(var, "apply-nat-acl")) {
-						if (profile->nat_acl_count < SOFIA_MAX_ACL) {
-							if (!profile->extsipip && switch_check_network_list_ip(profile->sipip, val)) {
-								switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Not adding acl %s because it's the local network\n", val);
-							} else {
-								profile->nat_acl[profile->nat_acl_count++] = switch_core_strdup(profile->pool, val);
-							}
-						} else {
-							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Max acl records of %d reached\n", SOFIA_MAX_ACL);
-						}
-					} else if (!strcasecmp(var, "apply-inbound-acl")) {
-						if (profile->acl_count < SOFIA_MAX_ACL) {
-							char *list, *pass = NULL, *fail = NULL;
-
-							list = switch_core_strdup(profile->pool, val);
-
-							if ((pass = strchr(list, ':'))) {
-								*pass++ = '\0';
-								if ((fail = strchr(pass, ':'))) {
-									*fail++ = '\0';
-								}
-
-								if (zstr(pass)) pass = NULL;
-								if (zstr(fail)) fail = NULL;
-
-								profile->acl_pass_context[profile->acl_count] = pass;
-								profile->acl_fail_context[profile->acl_count] = fail;
-							}
-
-							profile->acl[profile->acl_count++] = list;
-
-						} else {
-							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Max acl records of %d reached\n", SOFIA_MAX_ACL);
-						}
-					} else if (!strcasecmp(var, "apply-proxy-acl")) {
-						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "apply proxy acl [%s]\n", val);
-						if (profile->proxy_acl_count < SOFIA_MAX_ACL) {
-							profile->proxy_acl[profile->proxy_acl_count++] = switch_core_strdup(profile->pool, val);
-						} else {
-							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Max acl records of %d reached\n", SOFIA_MAX_ACL);
-						}
-					} else if (!strcasecmp(var, "apply-register-acl")) {
-						if (profile->reg_acl_count < SOFIA_MAX_ACL) {
-							profile->reg_acl[profile->reg_acl_count++] = switch_core_strdup(profile->pool, val);
-						} else {
-							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Max acl records of %d reached\n", SOFIA_MAX_ACL);
-						}
-					} else if (!strcasecmp(var, "user-agent-filter")) {
-						profile->user_agent_filter = switch_core_strdup(profile->pool, val);
-					} else if (!strcasecmp(var, "max-registrations-per-extension")) {
-						profile->max_registrations_perext = atoi(val);
-					} else if (!strcasecmp(var,"presence-privacy")) {
-						profile->presence_privacy = switch_core_strdup(profile->pool, val);
-					} else if (!strcasecmp(var, "rfc2833-pt")) {
-						profile->te = (switch_payload_t) atoi(val);
-					} else if (!strcasecmp(var, "cng-pt") && !(sofia_test_pflag(profile, PFLAG_SUPPRESS_CNG))) {
-						profile->cng_pt = (switch_payload_t) atoi(val);
-					} else if (!strcasecmp(var, "vad")) {
-						if (!strcasecmp(val, "in")) {
-							sofia_set_flag(profile, TFLAG_VAD_IN);
-						} else if (!strcasecmp(val, "out")) {
-							sofia_set_flag(profile, TFLAG_VAD_OUT);
-						} else if (!strcasecmp(val, "both")) {
-							sofia_set_flag(profile, TFLAG_VAD_IN);
-							sofia_set_flag(profile, TFLAG_VAD_OUT);
-						} else if (strcasecmp(val, "none")) {
-							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid option %s for VAD\n", val);
-						}
-					} else if (!strcasecmp(var, "unregister-on-options-fail")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_UNREG_OPTIONS_FAIL);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_UNREG_OPTIONS_FAIL);
-						}
-					} else if (!strcasecmp(var, "require-secure-rtp")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_SECURE);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_SECURE);
-						}
-					} else if (!strcasecmp(var, "multiple-registrations")) {
-						if (!strcasecmp(val, "call-id")) {
-							sofia_set_pflag(profile, PFLAG_MULTIREG);
-						} else if (!strcasecmp(val, "contact") || switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_MULTIREG);
-							sofia_set_pflag(profile, PFLAG_MULTIREG_CONTACT);
-						} else if (switch_true(val)) {
-							sofia_clear_pflag(profile, PFLAG_MULTIREG);
-							//sofia_clear_pflag(profile, PFLAG_MULTIREG_CONTACT);
-						}
-					} else if (!strcasecmp(var, "supress-cng") || !strcasecmp(var, "suppress-cng")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_SUPPRESS_CNG);
-							profile->cng_pt = 0;
-						} else {
-							sofia_clear_pflag(profile, PFLAG_SUPPRESS_CNG);
-						}
-					} else if (!strcasecmp(var, "NDLB-broken-auth-hash")) {
-						if (switch_true(val)) {
-							profile->ndlb |= PFLAG_NDLB_BROKEN_AUTH_HASH;
-						} else {
-							profile->ndlb &= ~PFLAG_NDLB_BROKEN_AUTH_HASH;
-						}
-					} else if (!strcasecmp(var, "NDLB-sendrecv-in-session")) {
-						if (switch_true(val)) {
-							profile->ndlb |= PFLAG_NDLB_SENDRECV_IN_SESSION;
-						} else {
-							profile->ndlb &= ~PFLAG_NDLB_SENDRECV_IN_SESSION;
-						}
-					} else if (!strcasecmp(var, "pass-rfc2833")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_PASS_RFC2833);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_PASS_RFC2833);
-						}
-					} else if (!strcasecmp(var, "rtp-autoflush")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_AUTOFLUSH);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_AUTOFLUSH);
-						}
-					} else if (!strcasecmp(var, "rtp-autofix-timing")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_AUTOFIX_TIMING);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_AUTOFIX_TIMING);
-						}
-					} else if (!strcasecmp(var, "nat-options-ping")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_NAT_OPTIONS_PING);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_NAT_OPTIONS_PING);
-						}
-					} else if (!strcasecmp(var, "all-reg-options-ping")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_ALL_REG_OPTIONS_PING);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_ALL_REG_OPTIONS_PING);
-						}
-					} else if (!strcasecmp(var, "inbound-codec-negotiation")) {
-						if (!strcasecmp(val, "greedy")) {
-							sofia_set_pflag(profile, PFLAG_GREEDY);
-						} else if (!strcasecmp(val, "scrooge")) {
-							sofia_set_pflag(profile, PFLAG_GREEDY);
-							sofia_set_pflag(profile, PFLAG_SCROOGE);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_SCROOGE);
-							sofia_clear_pflag(profile, PFLAG_GREEDY);
-						}
-					} else if (!strcasecmp(var, "disable-transcoding")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_DISABLE_TRANSCODING);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_DISABLE_TRANSCODING);
-						}
-					} else if (!strcasecmp(var, "rtp-rewrite-timestamps")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_REWRITE_TIMESTAMPS);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_REWRITE_TIMESTAMPS);
-						}
-					} else if (!strcasecmp(var, "auth-calls")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_AUTH_CALLS);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_AUTH_CALLS);
-						}
-					} else if (!strcasecmp(var, "extended-info-parsing")) {
-						if (switch_true(val)) {
-							sofia_set_pflag(profile, PFLAG_EXTENDED_INFO_PARSING);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_EXTENDED_INFO_PARSING);
-						}
-					} else if (!strcasecmp(var, "context")) {
-						profile->context = switch_core_strdup(profile->pool, val);
-					} else if (!strcasecmp(var, "local-network-acl")) {
-						if (!strcasecmp(val, "none")) {
-							profile->local_network = NULL;
-						} else {
-							profile->local_network = switch_core_strdup(profile->pool, val);
-						}
-					} else if (!strcasecmp(var, "force-register-domain")) {
-						profile->reg_domain = switch_core_strdup(profile->pool, val);
-					} else if (!strcasecmp(var, "force-subscription-domain")) {
-						profile->sub_domain = switch_core_strdup(profile->pool, val);
-					} else if (!strcasecmp(var, "force-register-db-domain")) {
-						profile->reg_db_domain = switch_core_strdup(profile->pool, val);
-					} else if (!strcasecmp(var, "hold-music")) {
-						profile->hold_music = switch_core_strdup(profile->pool, val);
-					} else if (!strcasecmp(var, "outbound-proxy")) {
-						profile->outbound_proxy = switch_core_strdup(profile->pool, val);
-					} else if (!strcasecmp(var, "rtcp-audio-interval-msec")) {
-						profile->rtcp_audio_interval_msec = switch_core_strdup(profile->pool, val);
-					} else if (!strcasecmp(var, "rtcp-video-interval-msec")) {
-						profile->rtcp_video_interval_msec = switch_core_strdup(profile->pool, val);
-					} else if (!strcasecmp(var, "session-timeout")) {
-						int v_session_timeout = atoi(val);
-						if (v_session_timeout >= 0) {
-							profile->session_timeout = v_session_timeout;
-						}
-					} else if (!strcasecmp(var, "rtp-timeout-sec")) {
-						int v = atoi(val);
-						if (v >= 0) {
-							profile->rtp_timeout_sec = v;
-						}
-					} else if (!strcasecmp(var, "rtp-hold-timeout-sec")) {
-						int v = atoi(val);
-						if (v >= 0) {
-							profile->rtp_hold_timeout_sec = v;
-						}
-					} else if (!strcasecmp(var, "nonce-ttl")) {
-						profile->nonce_ttl = atoi(val);
-					} else if (!strcasecmp(var, "dialplan")) {
-						profile->dialplan = switch_core_strdup(profile->pool, val);
-					} else if (!strcasecmp(var, "max-calls")) {
-						profile->max_calls = atoi(val);
-					} else if (!strcasecmp(var, "codec-prefs")) {
-						profile->inbound_codec_string = switch_core_strdup(profile->pool, val);
-						profile->outbound_codec_string = switch_core_strdup(profile->pool, val);
-					} else if (!strcasecmp(var, "inbound-codec-prefs")) {
-						profile->inbound_codec_string = switch_core_strdup(profile->pool, val);
-					} else if (!strcasecmp(var, "outbound-codec-prefs")) {
-						profile->outbound_codec_string = switch_core_strdup(profile->pool, val);
-					} else if (!strcasecmp(var, "challenge-realm")) {
-						profile->challenge_realm = switch_core_strdup(profile->pool, val);
-					} else if (!strcasecmp(var, "dtmf-duration")) {
-						uint32_t dur = atoi(val);
-						if (dur >= switch_core_min_dtmf_duration(0) && dur <= switch_core_max_dtmf_duration(0)) {
-							profile->dtmf_duration = dur;
-						} else {
-							profile->dtmf_duration = SWITCH_DEFAULT_DTMF_DURATION;
-							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Duration out of bounds, using default of %d!\n",
-											  SWITCH_DEFAULT_DTMF_DURATION);
-						}
-					} else if (!strcasecmp(var, "timer-T1")) {
-						int v = atoi(val);
-						if (v > 0) {
-							profile->timer_t1 = v;
-						} else {
-							profile->timer_t1 = 500;
-						}
-						nua_set_params(profile->nua, NTATAG_SIP_T1(profile->timer_t1), TAG_END());
-					} else if (!strcasecmp(var, "timer-T1X64")) {
-						int v = atoi(val);
-						if (v > 0) {
-							profile->timer_t1x64 = v;
-						} else {
-							profile->timer_t1x64 = 32000;
-						}
-						nua_set_params(profile->nua, NTATAG_SIP_T1X64(profile->timer_t1x64), TAG_END());
-					} else if (!strcasecmp(var, "timer-T2")) {
-						int v = atoi(val);
-						if (v > 0) {
-							profile->timer_t2 = v;
-						} else {
-							profile->timer_t2 = 4000;
-						}
-						nua_set_params(profile->nua, NTATAG_SIP_T2(profile->timer_t2), TAG_END());
-					} else if (!strcasecmp(var, "timer-T4")) {
-						int v = atoi(val);
-						if (v > 0) {
-							profile->timer_t4 = v;
-						} else {
-							profile->timer_t4 = 4000;
-						}
-						nua_set_params(profile->nua, NTATAG_SIP_T4(profile->timer_t4), TAG_END());
-					} else if (!strcasecmp(var, "sip-options-respond-503-on-busy")) {
-                                                if (switch_true(val)) {
-                                                        sofia_set_pflag(profile, PFLAG_OPTIONS_RESPOND_503_ON_BUSY);
-                                                } else {
-                                                        sofia_clear_pflag(profile, PFLAG_OPTIONS_RESPOND_503_ON_BUSY);
-                                                }
-					} else if (!strcasecmp(var, "sip-force-expires")) {
-						int32_t sip_force_expires = atoi(val);
-						if (sip_force_expires >= 0) {
-							profile->sip_force_expires = sip_force_expires;
-						} else {
-							profile->sip_force_expires = 0;
-						}
-					} else if (!strcasecmp(var, "sip-expires-max-deviation")) {
-						int32_t sip_expires_max_deviation = atoi(val);
-						if (sip_expires_max_deviation >= 0) {
-							profile->sip_expires_max_deviation = sip_expires_max_deviation;
-						} else {
-							profile->sip_expires_max_deviation = 0;
-						}
-					} else if (!strcasecmp(var, "p-asserted-id-parse")) {
-						if (!strncasecmp(val, "default", 7)) {
-							profile->paid_type = PAID_DEFAULT;
-						} else if (!strncasecmp(val, "user-only", 9)) {
-							profile->paid_type = PAID_USER;
-						} else if (!strncasecmp(val, "user-domain", 11)) {
-							profile->paid_type = PAID_USER_DOMAIN;
-						} else if (!strncasecmp(val, "verbatim", 8)) {
-							profile->paid_type = PAID_VERBATIM;
-						} else {
-							profile->paid_type = PAID_DEFAULT;
-						}
-					}
-				}
-			}
-
-			if (sofia_test_flag(profile, TFLAG_ZRTP_PASSTHRU)) {
-				sofia_set_flag(profile, TFLAG_LATE_NEGOTIATION);
-			}
-
-			if ((gateways_tag = switch_xml_child(xprofile, "gateways"))) {
-				parse_gateways(profile, gateways_tag);
-			}
-
-			status = SWITCH_STATUS_SUCCESS;
-
-			if ((domains_tag = switch_xml_child(xprofile, "domains"))) {
-				switch_event_t *xml_params;
-				switch_event_create(&xml_params, SWITCH_EVENT_REQUEST_PARAMS);
-				switch_assert(xml_params);
-				switch_event_add_header_string(xml_params, SWITCH_STACK_BOTTOM, "purpose", "gateways");
-				switch_event_add_header_string(xml_params, SWITCH_STACK_BOTTOM, "profile", profile->name);
-
-				for (domain_tag = switch_xml_child(domains_tag, "domain"); domain_tag; domain_tag = domain_tag->next) {
-					switch_xml_t droot, x_domain_tag;
-					const char *dname = switch_xml_attr_soft(domain_tag, "name");
-					const char *parse = switch_xml_attr_soft(domain_tag, "parse");
-					const char *alias = switch_xml_attr_soft(domain_tag, "alias");
-
-					if (!zstr(dname)) {
-						if (!strcasecmp(dname, "all")) {
-							switch_xml_t xml_root, x_domains;
-							if (switch_xml_locate("directory", NULL, NULL, NULL, &xml_root, &x_domains, xml_params, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS) {
-								for (x_domain_tag = switch_xml_child(x_domains, "domain"); x_domain_tag; x_domain_tag = x_domain_tag->next) {
-									dname = switch_xml_attr_soft(x_domain_tag, "name");
-									parse_domain_tag(profile, x_domain_tag, dname, parse, alias);
-								}
-								switch_xml_free(xml_root);
-							}
-						} else if (switch_xml_locate_domain(dname, xml_params, &droot, &x_domain_tag) == SWITCH_STATUS_SUCCESS) {
-							parse_domain_tag(profile, x_domain_tag, dname, parse, alias);
-							switch_xml_free(droot);
-						}
-					}
-				}
-
-				switch_event_destroy(&xml_params);
-			}
-
-			if ((aliases_tag = switch_xml_child(xprofile, "aliases"))) {
-				for (alias_tag = switch_xml_child(aliases_tag, "alias"); alias_tag; alias_tag = alias_tag->next) {
-					char *aname = (char *) switch_xml_attr_soft(alias_tag, "name");
-					if (!zstr(aname)) {
-
-						if (sofia_glue_add_profile(switch_core_strdup(profile->pool, aname), profile) == SWITCH_STATUS_SUCCESS) {
-							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Adding Alias [%s] for profile [%s]\n", aname, profile->name);
-						} else {
-							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Alias [%s] for profile [%s] (already exists)\n",
-											  aname, profile->name);
-						}
-					}
-				}
-			}
-		}
-	}
-
-  done:
-
-	if (xml) {
-		switch_xml_free(xml);
-	}
-
-	switch_event_destroy(&params);
-
-	return status;
+	/* Redirect loggers in sofia */
+	su_log_redirect(su_log_default, logger, NULL);
+	su_log_redirect(tport_log, logger, NULL);
+	su_log_redirect(iptsec_log, logger, NULL);
+	su_log_redirect(nea_log, logger, NULL);
+	su_log_redirect(nta_log, logger, NULL);
+	su_log_redirect(nth_client_log, logger, NULL);
+	su_log_redirect(nth_server_log, logger, NULL);
+	su_log_redirect(nua_log, logger, NULL);
+	su_log_redirect(soa_log, logger, NULL);
+	su_log_redirect(sresolv_log, logger, NULL);
+#ifdef HAVE_SOFIA_STUN
+	su_log_redirect(stun_log, logger, NULL);
+#endif
+	
+	return SWITCH_STATUS_SUCCESS;
 }
 
-switch_status_t config_sofia(int reload, char *profile_name)
+
+switch_status_t config_sofia(sofia_config_t reload, char *profile_name)
 {
 	char *cf = "sofia.conf";
 	switch_xml_t cfg, xml = NULL, xprofile, param, settings, profiles;
@@ -4243,40 +3449,25 @@ switch_status_t config_sofia(int reload, char *profile_name)
 	char url[512] = "";
 	int profile_found = 0;
 	switch_event_t *params = NULL;
+	sofia_profile_t *profile_already_started = NULL;
 
-	if (!reload) {
-		su_init();
-		if (sip_update_default_mclass(sip_extend_mclass(NULL)) < 0) {
-			su_deinit();
-			return SWITCH_STATUS_FALSE;
-		}
-
-		/* Redirect loggers in sofia */
-		su_log_redirect(su_log_default, logger, NULL);
-		su_log_redirect(tport_log, logger, NULL);
-		su_log_redirect(iptsec_log, logger, NULL);
-		su_log_redirect(nea_log, logger, NULL);
-		su_log_redirect(nta_log, logger, NULL);
-		su_log_redirect(nth_client_log, logger, NULL);
-		su_log_redirect(nth_server_log, logger, NULL);
-		su_log_redirect(nua_log, logger, NULL);
-		su_log_redirect(soa_log, logger, NULL);
-		su_log_redirect(sresolv_log, logger, NULL);
-#ifdef HAVE_SOFIA_STUN
-		su_log_redirect(stun_log, logger, NULL);
-#endif
-	}
-	
 	if (!zstr(profile_name) && (profile = sofia_glue_find_profile(profile_name))) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Profile [%s] Already exists.\n", switch_str_nil(profile_name));
-		status = SWITCH_STATUS_FALSE;
-		sofia_glue_release_profile(profile);
-		return status;
+		if (reload == SOFIA_CONFIG_RESCAN) {
+			profile_already_started = profile;
+		} else {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Profile [%s] Already exists.\n", switch_str_nil(profile_name));
+			status = SWITCH_STATUS_FALSE;
+			sofia_glue_release_profile(profile);
+			return status;
+		}
 	}
 
 	switch_event_create(&params, SWITCH_EVENT_REQUEST_PARAMS);
 	switch_assert(params);
 	switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "profile", profile_name);
+	if (reload == SOFIA_CONFIG_RESCAN) {
+		switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "reconfig", "true");
+	}
 
 	if (!(xml = switch_xml_open_cfg(cf, &cfg, params))) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", cf);
@@ -4347,81 +3538,103 @@ switch_status_t config_sofia(int reload, char *profile_name)
 						profile_found = 1;
 					}
 				}
+				
+				if (!profile_already_started) {
 
-				/* Setup the pool */
-				if ((status = switch_core_new_memory_pool(&pool)) != SWITCH_STATUS_SUCCESS) {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
-					sofia_profile_start_failure(NULL, xprofilename);
-					goto done;
+					/* Setup the pool */
+					if ((status = switch_core_new_memory_pool(&pool)) != SWITCH_STATUS_SUCCESS) {
+						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
+						sofia_profile_start_failure(NULL, xprofilename);
+						goto done;
+					}
+						
+					if (!(profile = (sofia_profile_t *) switch_core_alloc(pool, sizeof(*profile)))) {
+						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error!\n");
+						sofia_profile_start_failure(NULL, xprofilename);
+						goto done;
+					}
+					
+					profile->tls_verify_policy = TPTLS_VERIFY_NONE;
+					/* lib default */
+					profile->tls_verify_depth = 2;
+
+
+					switch_mutex_init(&profile->gw_mutex, SWITCH_MUTEX_NESTED, pool);
+
+					profile->trans_timeout = 100;
+
+					profile->auto_rtp_bugs = RTP_BUG_CISCO_SKIP_MARK_BIT_2833;// | RTP_BUG_SONUS_SEND_INVALID_TIMESTAMP_2833;
+
+					profile->pool = pool;
+					profile->user_agent = SOFIA_USER_AGENT;
+
+					profile->name = switch_core_strdup(profile->pool, xprofilename);
+					switch_snprintf(url, sizeof(url), "sofia_reg_%s", xprofilename);
+
+					if (xprofiledomain) {
+						profile->domain_name = switch_core_strdup(profile->pool, xprofiledomain);
+					}
+
+					profile->dbname = switch_core_strdup(profile->pool, url);
+					switch_core_hash_init(&profile->chat_hash, profile->pool);
+					switch_core_hash_init(&profile->mwi_debounce_hash, profile->pool);
+					switch_thread_rwlock_create(&profile->rwlock, profile->pool);
+					switch_mutex_init(&profile->flag_mutex, SWITCH_MUTEX_NESTED, profile->pool);
+					profile->dtmf_duration = 100;
+					profile->rtp_digit_delay = 40;
+					profile->sip_force_expires = 0;
+					profile->sip_expires_max_deviation = 0;
+					profile->tls_version = 0;
+					profile->tls_timeout = 300;
+					profile->mflags = MFLAG_REFER | MFLAG_REGISTER;
+					profile->server_rport_level = 1;
+					profile->client_rport_level = 1;
+					sofia_set_pflag(profile, PFLAG_STUN_ENABLED);
+					sofia_set_pflag(profile, PFLAG_DISABLE_100REL);
+					profile->auto_restart = 1;
+					sofia_set_pflag(profile, PFLAG_AUTOFIX_TIMING);
+					sofia_set_pflag(profile, PFLAG_RTP_AUTOFLUSH_DURING_BRIDGE);
+					profile->contact_user = SOFIA_DEFAULT_CONTACT_USER;
+					sofia_set_pflag(profile, PFLAG_PASS_CALLEE_ID);
+					sofia_set_pflag(profile, PFLAG_SEND_DISPLAY_UPDATE);
+					sofia_set_pflag(profile, PFLAG_MESSAGE_QUERY_ON_FIRST_REGISTER);
+					//sofia_set_pflag(profile, PFLAG_PRESENCE_ON_FIRST_REGISTER);		
+
+					profile->shutdown_type = "false";
+					profile->local_network = "localnet.auto";
+					sofia_set_flag(profile, TFLAG_ENABLE_SOA);
+					sofia_set_pflag(profile, PFLAG_CID_IN_1XX);
+					profile->ndlb |= PFLAG_NDLB_ALLOW_NONDUP_SDP;
+					profile->te = 101;
+					profile->ireg_seconds = IREG_SECONDS;
+					profile->paid_type = PAID_DEFAULT;
+
+
+					profile->tls_verify_policy = TPTLS_VERIFY_NONE;
+					/* lib default */
+					profile->tls_verify_depth = 2;
+					profile->tls_verify_date = SWITCH_TRUE;
+				} else {
+
+					/* you could change profile->foo here if it was a minor change like context or dialplan ... */
+					profile->acl_count = 0;
+					profile->nat_acl_count = 0;
+					profile->reg_acl_count = 0;
+					profile->proxy_acl_count = 0;
+					sofia_set_pflag(profile, PFLAG_STUN_ENABLED);
+					sofia_set_pflag(profile, PFLAG_PASS_CALLEE_ID);
+					profile->ib_calls = 0;
+					profile->ob_calls = 0;
+					profile->ib_failed_calls = 0;
+					profile->ob_failed_calls = 0;
+					profile->shutdown_type = "false";
+					profile->rtpip_index = 0;
+
+					if (xprofiledomain) {
+						profile->domain_name = switch_core_strdup(profile->pool, xprofiledomain);
+					}
 				}
 
-				if (!(profile = (sofia_profile_t *) switch_core_alloc(pool, sizeof(*profile)))) {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error!\n");
-					sofia_profile_start_failure(NULL, xprofilename);
-					goto done;
-				}
-				profile->tls_verify_policy = TPTLS_VERIFY_NONE;
-				/* lib default */
-				profile->tls_verify_depth = 2;
-
-
-				switch_mutex_init(&profile->gw_mutex, SWITCH_MUTEX_NESTED, pool);
-
-				profile->trans_timeout = 100;
-
-				profile->auto_rtp_bugs = RTP_BUG_CISCO_SKIP_MARK_BIT_2833;// | RTP_BUG_SONUS_SEND_INVALID_TIMESTAMP_2833;
-
-				profile->pool = pool;
-				profile->user_agent = SOFIA_USER_AGENT;
-
-				profile->name = switch_core_strdup(profile->pool, xprofilename);
-				switch_snprintf(url, sizeof(url), "sofia_reg_%s", xprofilename);
-
-				if (xprofiledomain) {
-					profile->domain_name = switch_core_strdup(profile->pool, xprofiledomain);
-				}
-
-				profile->dbname = switch_core_strdup(profile->pool, url);
-				switch_core_hash_init(&profile->chat_hash, profile->pool);
-				switch_core_hash_init(&profile->mwi_debounce_hash, profile->pool);
-				switch_thread_rwlock_create(&profile->rwlock, profile->pool);
-				switch_mutex_init(&profile->flag_mutex, SWITCH_MUTEX_NESTED, profile->pool);
-				profile->dtmf_duration = 100;
-				profile->rtp_digit_delay = 40;
-				profile->sip_force_expires = 0;
-				profile->sip_expires_max_deviation = 0;
-				profile->tls_version = 0;
-				profile->tls_timeout = 300;
-				profile->mflags = MFLAG_REFER | MFLAG_REGISTER;
-				profile->server_rport_level = 1;
-				profile->client_rport_level = 1;
-				sofia_set_pflag(profile, PFLAG_STUN_ENABLED);
-				sofia_set_pflag(profile, PFLAG_DISABLE_100REL);
-				profile->auto_restart = 1;
-				sofia_set_pflag(profile, PFLAG_AUTOFIX_TIMING);
-				sofia_set_pflag(profile, PFLAG_RTP_AUTOFLUSH_DURING_BRIDGE);
-				profile->contact_user = SOFIA_DEFAULT_CONTACT_USER;
-				sofia_set_pflag(profile, PFLAG_PASS_CALLEE_ID);
-				sofia_set_pflag(profile, PFLAG_SEND_DISPLAY_UPDATE);
-				sofia_set_pflag(profile, PFLAG_MESSAGE_QUERY_ON_FIRST_REGISTER);
-				//sofia_set_pflag(profile, PFLAG_PRESENCE_ON_FIRST_REGISTER);		
-				sofia_set_pflag(profile, PFLAG_SQL_IN_TRANS);
-
-				profile->shutdown_type = "false";
-				profile->local_network = "localnet.auto";
-				sofia_set_flag(profile, TFLAG_ENABLE_SOA);
-				sofia_set_pflag(profile, PFLAG_CID_IN_1XX);
-				profile->ndlb |= PFLAG_NDLB_ALLOW_NONDUP_SDP;
-				profile->te = 101;
-				profile->ireg_seconds = IREG_SECONDS;
-				profile->paid_type = PAID_DEFAULT;
-
-
-                                profile->tls_verify_policy = TPTLS_VERIFY_NONE;
-                                /* lib default */
-                                profile->tls_verify_depth = 2;
-				profile->tls_verify_date = SWITCH_TRUE;
-
 				for (param = switch_xml_child(settings, "param"); param; param = param->next) {
 					char *var = (char *) switch_xml_attr_soft(param, "name");
 					char *val = (char *) switch_xml_attr_soft(param, "value");
@@ -5107,20 +4320,6 @@ switch_status_t config_sofia(int reload, char *profile_name)
 						} else {
 							sofia_clear_pflag(profile, PFLAG_PASS_CALLEE_ID);
 						}
-					} else if (!strcasecmp(var, "sql-in-transactions")) {
-						int tmp = atoi(val);
-
-						if (switch_true(val)) {
-							tmp = 500;
-						}
-
-						if (tmp > 0) {
-							profile->trans_timeout = tmp;
-							sofia_set_pflag(profile, PFLAG_SQL_IN_TRANS);
-						} else {
-							sofia_clear_pflag(profile, PFLAG_SQL_IN_TRANS);
-						}
-
 					} else if (!strcasecmp(var, "enable-soa")) {
 						if (switch_true(val)) {
 							sofia_set_flag(profile, TFLAG_ENABLE_SOA);
@@ -5411,45 +4610,113 @@ switch_status_t config_sofia(int reload, char *profile_name)
 				}
 
 			}
+
 			if (profile) {
-				switch_xml_t aliases_tag, alias_tag;
+				if (profile_already_started) {
+					switch_xml_t gateways_tag, domain_tag, domains_tag, aliases_tag, alias_tag;
 
-				if ((aliases_tag = switch_xml_child(xprofile, "aliases"))) {
-					for (alias_tag = switch_xml_child(aliases_tag, "alias"); alias_tag; alias_tag = alias_tag->next) {
-						char *aname = (char *) switch_xml_attr_soft(alias_tag, "name");
-						if (!zstr(aname)) {
+					if (sofia_test_flag(profile, TFLAG_ZRTP_PASSTHRU)) {
+						sofia_set_flag(profile, TFLAG_LATE_NEGOTIATION);
+					}
 
-							if (sofia_glue_add_profile(switch_core_strdup(profile->pool, aname), profile) == SWITCH_STATUS_SUCCESS) {
-								switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Adding Alias [%s] for profile [%s]\n", aname, profile->name);
-							} else {
-								switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Adding Alias [%s] for profile [%s] (name in use)\n",
-												  aname, profile->name);
+					if ((gateways_tag = switch_xml_child(xprofile, "gateways"))) {
+						parse_gateways(profile, gateways_tag);
+					}
+
+					status = SWITCH_STATUS_SUCCESS;
+
+					if ((domains_tag = switch_xml_child(xprofile, "domains"))) {
+						switch_event_t *xml_params;
+						switch_event_create(&xml_params, SWITCH_EVENT_REQUEST_PARAMS);
+						switch_assert(xml_params);
+						switch_event_add_header_string(xml_params, SWITCH_STACK_BOTTOM, "purpose", "gateways");
+						switch_event_add_header_string(xml_params, SWITCH_STACK_BOTTOM, "profile", profile->name);
+
+						for (domain_tag = switch_xml_child(domains_tag, "domain"); domain_tag; domain_tag = domain_tag->next) {
+							switch_xml_t droot, x_domain_tag;
+							const char *dname = switch_xml_attr_soft(domain_tag, "name");
+							const char *parse = switch_xml_attr_soft(domain_tag, "parse");
+							const char *alias = switch_xml_attr_soft(domain_tag, "alias");
+
+							if (!zstr(dname)) {
+								if (!strcasecmp(dname, "all")) {
+									switch_xml_t xml_root, x_domains;
+									if (switch_xml_locate("directory", NULL, NULL, NULL, &xml_root, &x_domains, xml_params, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS) {
+										for (x_domain_tag = switch_xml_child(x_domains, "domain"); x_domain_tag; x_domain_tag = x_domain_tag->next) {
+											dname = switch_xml_attr_soft(x_domain_tag, "name");
+											parse_domain_tag(profile, x_domain_tag, dname, parse, alias);
+										}
+										switch_xml_free(xml_root);
+									}
+								} else if (switch_xml_locate_domain(dname, xml_params, &droot, &x_domain_tag) == SWITCH_STATUS_SUCCESS) {
+									parse_domain_tag(profile, x_domain_tag, dname, parse, alias);
+									switch_xml_free(droot);
+								}
+							}
+						}
+
+						switch_event_destroy(&xml_params);
+					}
+
+					if ((aliases_tag = switch_xml_child(xprofile, "aliases"))) {
+						for (alias_tag = switch_xml_child(aliases_tag, "alias"); alias_tag; alias_tag = alias_tag->next) {
+							char *aname = (char *) switch_xml_attr_soft(alias_tag, "name");
+							if (!zstr(aname)) {
+
+								if (sofia_glue_add_profile(switch_core_strdup(profile->pool, aname), profile) == SWITCH_STATUS_SUCCESS) {
+									switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Adding Alias [%s] for profile [%s]\n", aname, profile->name);
+								} else {
+									switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Alias [%s] for profile [%s] (already exists)\n",
+													  aname, profile->name);
+								}
 							}
 						}
 					}
-				}
-
-				if (profile->sipip) {
-					launch_sofia_profile_thread(profile);
-					if (profile->odbc_dsn) {
-						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Connecting ODBC Profile %s [%s]\n", profile->name, url);
-						switch_yield(1000000);
-					} else {
-						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Started Profile %s [%s]\n", profile->name, url);
-					}
+					
 				} else {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Unable to start Profile %s due to no configured sip-ip\n", profile->name);
-					sofia_profile_start_failure(profile, profile->name);
+					switch_xml_t aliases_tag, alias_tag;
+
+					if ((aliases_tag = switch_xml_child(xprofile, "aliases"))) {
+						for (alias_tag = switch_xml_child(aliases_tag, "alias"); alias_tag; alias_tag = alias_tag->next) {
+							char *aname = (char *) switch_xml_attr_soft(alias_tag, "name");
+							if (!zstr(aname)) {
+
+								if (sofia_glue_add_profile(switch_core_strdup(profile->pool, aname), profile) == SWITCH_STATUS_SUCCESS) {
+									switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Adding Alias [%s] for profile [%s]\n", aname, profile->name);
+								} else {
+									switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Adding Alias [%s] for profile [%s] (name in use)\n",
+													  aname, profile->name);
+								}
+							}
+						}
+					}
+
+					if (profile->sipip) {
+						launch_sofia_profile_thread(profile);
+						if (profile->odbc_dsn) {
+							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Connecting ODBC Profile %s [%s]\n", profile->name, url);
+							switch_yield(1000000);
+						} else {
+							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Started Profile %s [%s]\n", profile->name, url);
+						}
+					} else {
+						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Unable to start Profile %s due to no configured sip-ip\n", profile->name);
+						sofia_profile_start_failure(profile, profile->name);
+					}
+					profile = NULL;
+				}
+				if (profile_found) {
+					break;
 				}
-				profile = NULL;
-			}
-			if (profile_found) {
-				break;
 			}
 		}
 	}
   done:
 
+	if (profile_already_started) {
+		sofia_glue_release_profile(profile_already_started);
+	}
+
 	switch_event_destroy(&params);
 
 	if (xml) {
@@ -6102,8 +5369,7 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status
 										 switch_str_nil(presence_id), switch_str_nil(presence_data), switch_str_nil(p), (long) now);
 					switch_assert(sql);
 
-					sofia_glue_actually_execute_sql(profile, sql, profile->ireg_mutex);
-					switch_safe_free(sql);
+					sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
 
 				}
 			} else if (status == 200 && (profile->pres_type)) {
@@ -6512,22 +5778,6 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status,
 				}
 			}
 
-			if (r_sdp && sofia_test_flag(tech_pvt, TFLAG_3PCC_INVITE) && !sofia_test_flag(tech_pvt, TFLAG_SDP)) {
-				sofia_set_flag(tech_pvt, TFLAG_SDP);
-				if (switch_core_session_get_partner(session, &other_session) == SWITCH_STATUS_SUCCESS) {
-					other_channel = switch_core_session_get_channel(other_session);
-					//other_tech_pvt = switch_core_session_get_private(other_session);
-
-					if (!switch_channel_get_variable(other_channel, SWITCH_B_SDP_VARIABLE)) {
-						switch_channel_set_variable(other_channel, SWITCH_B_SDP_VARIABLE, r_sdp);
-					}
-					switch_core_session_queue_indication(other_session, SWITCH_MESSAGE_INDICATE_ANSWER);
-					switch_core_session_rwunlock(other_session);
-				}
-				goto done;
-
-			}
-
 			if (send_ack) {
 				tech_send_ack(nh, tech_pvt);
 			} else {
@@ -9406,9 +8656,7 @@ void sofia_handle_sip_i_invite(switch_core_session_t *session, nua_t *nua, sofia
 
 		switch_assert(sql);
 
-		sofia_glue_actually_execute_sql(profile, sql, profile->ireg_mutex);
-		switch_safe_free(sql);
-
+		sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
 	}
 
 	if (is_nat) {
diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c
index 10ce4deba1..bbaa9ae347 100644
--- a/src/mod/endpoints/mod_sofia/sofia_glue.c
+++ b/src/mod/endpoints/mod_sofia/sofia_glue.c
@@ -486,6 +486,10 @@ void sofia_glue_set_local_sdp(private_object_t *tech_pvt, const char *ip, switch
 		tech_pvt->session_id = tech_pvt->owner_id;
 	}
 
+	if (switch_true(switch_channel_get_variable_dup(tech_pvt->channel, "drop_dtmf", SWITCH_FALSE, -1))) {
+		sofia_set_flag(tech_pvt, TFLAG_DROP_DTMF);
+	}
+
 	tech_pvt->session_id++;
 
 	if ((tech_pvt->profile->ndlb & PFLAG_NDLB_SENDRECV_IN_SESSION) ||
@@ -969,6 +973,7 @@ void sofia_glue_attach_private(switch_core_session_t *session, sofia_profile_t *
 
 	switch_core_session_set_private(session, tech_pvt);
 
+
 	if (channame) {
 		sofia_glue_set_name(tech_pvt, channame);
 	}
@@ -3032,6 +3037,9 @@ switch_status_t sofia_glue_tech_set_codec(private_object_t *tech_pvt, int force)
 		switch_channel_hangup(tech_pvt->channel, SWITCH_CAUSE_INCOMPATIBLE_DESTINATION);
 		switch_goto_status(SWITCH_STATUS_FALSE, end);
 	}
+	
+	tech_pvt->read_codec.session = tech_pvt->session;
+
 
 	if (switch_core_codec_init_with_bitrate(&tech_pvt->write_codec,
 							   tech_pvt->iananame,
@@ -3047,6 +3055,8 @@ switch_status_t sofia_glue_tech_set_codec(private_object_t *tech_pvt, int force)
 		switch_goto_status(SWITCH_STATUS_FALSE, end);
 	}
 
+	tech_pvt->write_codec.session = tech_pvt->session;
+
 	switch_channel_set_variable(tech_pvt->channel, "sip_use_codec_name", tech_pvt->iananame);
 	switch_channel_set_variable(tech_pvt->channel, "sip_use_codec_fmtp", tech_pvt->rm_fmtp);
 	switch_channel_set_variable_printf(tech_pvt->channel, "sip_use_codec_rate", "%d", tech_pvt->rm_rate);
@@ -3214,7 +3224,7 @@ switch_status_t sofia_glue_activate_rtp(private_object_t *tech_pvt, switch_rtp_f
 	const char *err = NULL;
 	const char *val = NULL;
 	switch_rtp_flag_t flags;
-	switch_status_t status;
+	switch_status_t status = SWITCH_STATUS_SUCCESS;
 	char tmp[50];
 	uint32_t rtp_timeout_sec = tech_pvt->profile->rtp_timeout_sec;
 	uint32_t rtp_hold_timeout_sec = tech_pvt->profile->rtp_hold_timeout_sec;
@@ -3243,10 +3253,15 @@ switch_status_t sofia_glue_activate_rtp(private_object_t *tech_pvt, switch_rtp_f
 		goto end;
 	}
 
-	if (switch_rtp_ready(tech_pvt->rtp_session) && 
-		(!sofia_test_flag(tech_pvt, TFLAG_VIDEO) || switch_rtp_ready(tech_pvt->video_rtp_session)) && !sofia_test_flag(tech_pvt, TFLAG_REINVITE)) {
-		status = SWITCH_STATUS_SUCCESS;
-		goto end;
+
+	if (!sofia_test_flag(tech_pvt, TFLAG_REINVITE)) {
+		if (switch_rtp_ready(tech_pvt->rtp_session)) {
+			if (sofia_test_flag(tech_pvt, TFLAG_VIDEO) && !switch_rtp_ready(tech_pvt->video_rtp_session)) {
+				goto video;
+			} else {
+				goto end;
+			}
+		}
 	}
 
 	if ((status = sofia_glue_tech_set_codec(tech_pvt, 0)) != SWITCH_STATUS_SUCCESS) {
@@ -5128,7 +5143,13 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, const char *r_s
 					}
 
 					if (match && bit_rate && map_bit_rate && map_bit_rate != bit_rate && strcasecmp(map->rm_encoding, "ilbc")) {
-						/* nevermind */
+						/* if a bit rate is specified and doesn't match, this is not a codec match, except for ILBC */
+						match = 0;
+					}
+
+					if (match && map->rm_rate && codec_rate && map->rm_rate != codec_rate && (!strcasecmp(map->rm_encoding, "pcma") || !strcasecmp(map->rm_encoding, "pcmu"))) {
+						/* if the sampling rate is specified and doesn't match, this is not a codec match for G.711 */
+						switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "sampling rates have to match for G.711\n");
 						match = 0;
 					}
 					
@@ -5147,8 +5168,6 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, const char *r_s
 						}
 						mimp = imp;
 						break;
-					} else {
-						match = 0;
 					}
 				}
 
@@ -6269,7 +6288,8 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
 	};
 		
 	switch_cache_db_handle_t *dbh = sofia_glue_get_db_handle(profile);
-		
+	char *test2;
+
 	if (!dbh) {
 		return 0;
 	}
@@ -6283,20 +6303,22 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
 
 
 	switch_cache_db_test_reactive(dbh, test_sql, "drop table sip_registrations", reg_sql);
-
-
-	if (sofia_test_pflag(profile, PFLAG_SQL_IN_TRANS)) {
-		char *test2 = switch_mprintf("%s;%s", test_sql, test_sql);
+	
+	test2 = switch_mprintf("%s;%s", test_sql, test_sql);
 			
-		if (switch_cache_db_execute_sql(dbh, test2, NULL) != SWITCH_STATUS_SUCCESS) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "GREAT SCOTT!!! Cannot execute batched statements!\n"
-							  "If you are using mysql, make sure you are using MYODBC 3.51.18 or higher and enable FLAG_MULTI_STATEMENTS\n");
-			sofia_clear_pflag(profile, PFLAG_SQL_IN_TRANS);
-
-		}
+	if (switch_cache_db_execute_sql(dbh, test2, NULL) != SWITCH_STATUS_SUCCESS) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "GREAT SCOTT!!! Cannot execute batched statements!\n"
+						  "If you are using mysql, make sure you are using MYODBC 3.51.18 or higher and enable FLAG_MULTI_STATEMENTS\n");
+		
+		switch_cache_db_release_db_handle(&dbh);
 		free(test2);
+		free(test_sql);
+		return 0;
 	}
 
+	free(test2);
+
+
 	free(test_sql);
 
 	test_sql = switch_mprintf("delete from sip_subscriptions where hostname='%q' and full_to='XXX'", mod_sofia_globals.hostname);
@@ -6346,45 +6368,31 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
 
 void sofia_glue_execute_sql(sofia_profile_t *profile, char **sqlp, switch_bool_t sql_already_dynamic)
 {
-	switch_status_t status = SWITCH_STATUS_FALSE;
-	char *d_sql = NULL, *sql;
+	char *sql;
 
 	switch_assert(sqlp && *sqlp);
-	sql = *sqlp;
+	sql = *sqlp;	
 
-	if (profile->sql_queue) {
-		if (sql_already_dynamic) {
-			d_sql = sql;
-		} else {
-			d_sql = strdup(sql);
-		}
-
-		switch_assert(d_sql);
-		if ((status = switch_queue_trypush(profile->sql_queue, d_sql)) == SWITCH_STATUS_SUCCESS) {
-			d_sql = NULL;
-		}
-	} else if (sql_already_dynamic) {
-		d_sql = sql;
-	}
-
-	if (status != SWITCH_STATUS_SUCCESS) {
-		sofia_glue_actually_execute_sql(profile, sql, profile->ireg_mutex);
-	}
-
-	switch_safe_free(d_sql);
+	switch_sql_queue_manager_push(profile->qm, sql, 0, !sql_already_dynamic);
 
 	if (sql_already_dynamic) {
 		*sqlp = NULL;
 	}
 }
 
+
 void sofia_glue_execute_sql_now(sofia_profile_t *profile, char **sqlp, switch_bool_t sql_already_dynamic)
 {
-	sofia_glue_actually_execute_sql(profile, *sqlp, profile->ireg_mutex);
+	char *sql;
+
+	switch_assert(sqlp && *sqlp);
+	sql = *sqlp;	
+
+	switch_sql_queue_manager_push_confirm(profile->qm, sql, 0, !sql_already_dynamic);
+
 	if (sql_already_dynamic) {
-		switch_safe_free(*sqlp);
+		*sqlp = NULL;
 	}
-	*sqlp = NULL;
 }
 
 
diff --git a/src/mod/endpoints/mod_sofia/sofia_presence.c b/src/mod/endpoints/mod_sofia/sofia_presence.c
index f03584f1c3..17ab6b6efa 100644
--- a/src/mod/endpoints/mod_sofia/sofia_presence.c
+++ b/src/mod/endpoints/mod_sofia/sofia_presence.c
@@ -620,9 +620,15 @@ static int sofia_presence_dialog_callback(void *pArg, int argc, char **argv, cha
 
 	if (argc >= 4) {
 
+		if (argc == 5 && !zstr(argv[4])) {
+			if (!switch_ivr_uuid_exists(argv[4])) {
+				return 0;
+			}
+		}
+
 		if (mod_sofia_globals.debug_presence > 0) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "CHECK DIALOG state[%s] status[%s] rpid[%s] pres[%s]\n", 
-							  argv[0], argv[1], argv[2], argv[3]);
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "CHECK DIALOG state[%s] status[%s] rpid[%s] pres[%s] uuid[%s]\n", 
+							  argv[0], argv[1], argv[2], argv[3], argv[4]);
 		}
 
 		if (!helper->hits) {
@@ -668,7 +674,7 @@ static void do_normal_probe(switch_event_t *event)
 	}
 
 	if (probe_euser && probe_host && (profile = sofia_glue_find_profile(probe_host))) {
-		sql = switch_mprintf("select state,status,rpid,presence_id from sip_dialogs "
+		sql = switch_mprintf("select state,status,rpid,presence_id,uuid from sip_dialogs "
 							 "where hostname='%q' and profile_name='%q' and call_info_state != 'seized' and "
 							 "((sip_from_user='%q' and sip_from_host='%q') or presence_id='%q@%q') order by rcd desc", 
 							 mod_sofia_globals.hostname, profile->name, probe_euser, probe_host, probe_euser, probe_host);
@@ -1061,7 +1067,12 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
 		status = NULL;
 	}
 
-	if (status && switch_stristr("CS_HANGUP", status)) {
+	if (!zstr(uuid) && !switch_ivr_uuid_exists(uuid)) {
+		status = "CS_HANGUP";
+	}
+
+
+	if ((status && switch_stristr("CS_HANGUP", status)) || (!zstr(uuid) && !switch_ivr_uuid_exists(uuid))) {
 		status = "Available";
 		hup = 1;
 	}
@@ -1279,12 +1290,12 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
 
 				if (zstr(uuid)) {
 				
-					sql = switch_mprintf("select state,status,rpid,presence_id from sip_dialogs "
+					sql = switch_mprintf("select state,status,rpid,presence_id,uuid from sip_dialogs "
 										 "where call_info_state != 'seized' and hostname='%q' and profile_name='%q' and "
 										 "((sip_from_user='%q' and sip_from_host='%q') or presence_id='%q@%q') order by rcd desc", 
 										 mod_sofia_globals.hostname, profile->name, euser, host, euser, host);
 				} else {
-					sql = switch_mprintf("select state,status,rpid,presence_id from sip_dialogs "
+					sql = switch_mprintf("select state,status,rpid,presence_id,uuid from sip_dialogs "
 										 "where uuid != '%q' and call_info_state != 'seized' and hostname='%q' and profile_name='%q' and "
 										 "((sip_from_user='%q' and sip_from_host='%q') or presence_id='%q@%q') order by rcd desc", 
 										 uuid, mod_sofia_globals.hostname, profile->name, euser, host, euser, host);
@@ -3619,9 +3630,7 @@ void sofia_presence_handle_sip_i_subscribe(int status,
 			}
 			
 			switch_assert(sql != NULL);
-			sofia_glue_actually_execute_sql(profile, sql, profile->ireg_mutex);
-			switch_safe_free(sql);
-			
+			sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
 			sstr = switch_mprintf("terminated;reason=noresource");
 
 		} else {
@@ -4123,7 +4132,6 @@ void sofia_presence_handle_sip_i_publish(nua_t *nua, sofia_profile_t *profile, n
 	char *pd_dup = NULL;
 	int count = 1, sub_count = 1;
 	char *contact_str;
-	int open = 1;
 	sofia_nat_parse_t np = { { 0 } };
 
 	if (!sip) {
@@ -4190,11 +4198,10 @@ void sofia_presence_handle_sip_i_publish(nua_t *nua, sofia_profile_t *profile, n
 
 			if (!strcasecmp(open_closed, "closed")) {
 				rpid = note_txt = "Unregistered";
-			}
-
-			if (sofia_test_pflag(profile, PFLAG_MULTIREG) && !open) {
-				count = sofia_reg_reg_count(profile, from_user, from_host);
-				sub_count = sofia_presence_contact_count(profile, contact_str);
+				if (sofia_test_pflag(profile, PFLAG_MULTIREG)) {
+					count = sofia_reg_reg_count(profile, from_user, from_host);
+					sub_count = sofia_presence_contact_count(profile, contact_str);
+				}
 			}
 
 			/* if (count > 1) let's not and say we did or all the clients who subscribe to their own presence will think they selves is offline */
@@ -4522,8 +4529,7 @@ void sofia_presence_check_subscriptions(sofia_profile_t *profile, time_t now)
 								  "sub del sql: %s\n", sql);		
 			}
 
-			sofia_glue_actually_execute_sql(profile, sql, profile->ireg_mutex);
-			switch_safe_free(sql);
+			sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
 		}
 	}
 
diff --git a/src/mod/endpoints/mod_sofia/sofia_reg.c b/src/mod/endpoints/mod_sofia/sofia_reg.c
index ca2ff0f5c5..3e0e3965fe 100644
--- a/src/mod/endpoints/mod_sofia/sofia_reg.c
+++ b/src/mod/endpoints/mod_sofia/sofia_reg.c
@@ -695,7 +695,7 @@ void sofia_reg_expire_call_id(sofia_profile_t *profile, const char *call_id, int
 	switch_safe_free(sql);
 
 	sql = switch_mprintf("delete from sip_registrations where call_id='%q' %s", call_id, sqlextra);
-	sofia_glue_execute_sql_now(profile, &sql, SWITCH_FALSE);
+	sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
 
 	switch_safe_free(sqlextra);
 	switch_safe_free(sql);
@@ -705,84 +705,86 @@ void sofia_reg_expire_call_id(sofia_profile_t *profile, const char *call_id, int
 
 void sofia_reg_check_expire(sofia_profile_t *profile, time_t now, int reboot)
 {
-	char sql[1024];
-
-
+	char *sql;
 
 	if (now) {
-		switch_snprintf(sql, sizeof(sql), "select call_id,sip_user,sip_host,contact,status,rpid,expires"
+		sql = switch_mprintf("select call_id,sip_user,sip_host,contact,status,rpid,expires"
 						",user_agent,server_user,server_host,profile_name,network_ip"
 						",%d from sip_registrations where expires > 0 and expires <= %ld", reboot, (long) now);
 	} else {
-		switch_snprintf(sql, sizeof(sql), "select call_id,sip_user,sip_host,contact,status,rpid,expires"
+		sql = switch_mprintf("select call_id,sip_user,sip_host,contact,status,rpid,expires"
 						",user_agent,server_user,server_host,profile_name,network_ip" ",%d from sip_registrations where expires > 0", reboot);
 	}
 
 	sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_reg_del_callback, profile);
+	free(sql);
+
 	if (now) {
-		switch_snprintfv(sql, sizeof(sql), "delete from sip_registrations where expires > 0 and expires <= %ld and hostname='%q'",
+		sql = switch_mprintf("delete from sip_registrations where expires > 0 and expires <= %ld and hostname='%q'",
 						(long) now, mod_sofia_globals.hostname);
 	} else {
-		switch_snprintfv(sql, sizeof(sql), "delete from sip_registrations where expires > 0 and hostname='%q'", mod_sofia_globals.hostname);
+		sql = switch_mprintf("delete from sip_registrations where expires > 0 and hostname='%q'", mod_sofia_globals.hostname);
 	}
-
-	sofia_glue_actually_execute_sql(profile, sql, profile->ireg_mutex);
+	sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
+	
 
 
 
 	if (now) {
-		switch_snprintfv(sql, sizeof(sql), "select call_id from sip_shared_appearance_dialogs where hostname='%q' "
+		sql = switch_mprintf("select call_id from sip_shared_appearance_dialogs where hostname='%q' "
 						"and profile_name='%s' and expires <= %ld", mod_sofia_globals.hostname, profile->name, (long) now);
 
 		sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_sla_dialog_del_callback, profile);
-		switch_snprintfv(sql, sizeof(sql), "delete from sip_shared_appearance_dialogs where expires > 0 and hostname='%q' and expires <= %ld",
+		free(sql);
+
+		sql = switch_mprintf("delete from sip_shared_appearance_dialogs where expires > 0 and hostname='%q' and expires <= %ld",
 						mod_sofia_globals.hostname, (long) now);
 
 
-		sofia_glue_actually_execute_sql(profile, sql, profile->ireg_mutex);
+		sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
 	}
 
 
 	if (now) {
-		switch_snprintfv(sql, sizeof(sql), "delete from sip_presence where expires > 0 and expires <= %ld and hostname='%q'",
+		sql = switch_mprintf("delete from sip_presence where expires > 0 and expires <= %ld and hostname='%q'",
 						(long) now, mod_sofia_globals.hostname);
 	} else {
-		switch_snprintfv(sql, sizeof(sql), "delete from sip_presence where expires > 0 and hostname='%q'", mod_sofia_globals.hostname);
+		sql = switch_mprintf("delete from sip_presence where expires > 0 and hostname='%q'", mod_sofia_globals.hostname);
 	}
 
-	sofia_glue_actually_execute_sql(profile, sql, profile->ireg_mutex);
+	sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
 
 	if (now) {
-		switch_snprintfv(sql, sizeof(sql), "delete from sip_authentication where expires > 0 and expires <= %ld and hostname='%q'",
+		sql = switch_mprintf("delete from sip_authentication where expires > 0 and expires <= %ld and hostname='%q'",
 						(long) now, mod_sofia_globals.hostname);
 	} else {
-		switch_snprintfv(sql, sizeof(sql), "delete from sip_authentication where expires > 0 and hostname='%q'", mod_sofia_globals.hostname);
+		sql = switch_mprintf("delete from sip_authentication where expires > 0 and hostname='%q'", mod_sofia_globals.hostname);
 	}
 
-	sofia_glue_actually_execute_sql(profile, sql, profile->ireg_mutex);
-	
+	sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
+
 	sofia_presence_check_subscriptions(profile, now);
 
 	if (now) {
-		switch_snprintfv(sql, sizeof(sql), "delete from sip_dialogs where (expires = -1 or (expires > 0 and expires <= %ld)) and hostname='%q'",
+		sql = switch_mprintf("delete from sip_dialogs where (expires = -1 or (expires > 0 and expires <= %ld)) and hostname='%q'",
 						(long) now, mod_sofia_globals.hostname);
 	} else {
-		switch_snprintfv(sql, sizeof(sql), "delete from sip_dialogs where expires >= -1 and hostname='%q'", mod_sofia_globals.hostname);
+		sql = switch_mprintf("delete from sip_dialogs where expires >= -1 and hostname='%q'", mod_sofia_globals.hostname);
 	}
 
-	sofia_glue_actually_execute_sql(profile, sql, profile->ireg_mutex);
+	sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
 
 
 	if (now) {
 		if (sofia_test_pflag(profile, PFLAG_ALL_REG_OPTIONS_PING)) {
-			switch_snprintf(sql, sizeof(sql), "select call_id,sip_user,sip_host,contact,status,rpid,"
+			sql = switch_mprintf("select call_id,sip_user,sip_host,contact,status,rpid,"
 							"expires,user_agent,server_user,server_host,profile_name"
  " from sip_registrations where hostname='%s' and " 
  "profile_name='%s'", mod_sofia_globals.hostname, profile->name); 
 			
 			sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_reg_nat_callback, profile);
 		} else if (sofia_test_pflag(profile, PFLAG_NAT_OPTIONS_PING)) {
-			switch_snprintf(sql, sizeof(sql), "select call_id,sip_user,sip_host,contact,status,rpid,"
+			sql = switch_mprintf("select call_id,sip_user,sip_host,contact,status,rpid,"
 							"expires,user_agent,server_user,server_host,profile_name"
 							" from sip_registrations where (status like '%%NAT%%' "
  "or contact like '%%fs_nat=yes%%') and hostname='%s' " 
@@ -846,37 +848,36 @@ void sofia_reg_check_call_id(sofia_profile_t *profile, const char *call_id)
 
 void sofia_reg_check_sync(sofia_profile_t *profile)
 {
-	char sql[1024];
+	char *sql;
 
-
-	switch_snprintf(sql, sizeof(sql), "select call_id,sip_user,sip_host,contact,status,rpid,expires"
+	sql = switch_mprintf("select call_id,sip_user,sip_host,contact,status,rpid,expires"
 					",user_agent,server_user,server_host,profile_name,network_ip" 
 					" from sip_registrations where expires > 0");
 
 
 	sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_reg_del_callback, profile);
-	switch_snprintfv(sql, sizeof(sql), "delete from sip_registrations where expires > 0 and hostname='%q'", mod_sofia_globals.hostname);
-	sofia_glue_actually_execute_sql(profile, sql, profile->ireg_mutex);
+	sql = switch_mprintf("delete from sip_registrations where expires > 0 and hostname='%q'", mod_sofia_globals.hostname);
+	sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
 
 
-	switch_snprintfv(sql, sizeof(sql), "delete from sip_presence where expires > 0 and hostname='%q'", mod_sofia_globals.hostname);
-	sofia_glue_actually_execute_sql(profile, sql, profile->ireg_mutex);
+	sql = switch_mprintf("delete from sip_presence where expires > 0 and hostname='%q'", mod_sofia_globals.hostname);
+	sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
 
-	switch_snprintfv(sql, sizeof(sql), "delete from sip_authentication where expires > 0 and hostname='%q'", mod_sofia_globals.hostname);
-	sofia_glue_actually_execute_sql(profile, sql, profile->ireg_mutex);
+	sql = switch_mprintf("delete from sip_authentication where expires > 0 and hostname='%q'", mod_sofia_globals.hostname);
+	sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
 	
-	switch_snprintfv(sql, sizeof(sql), "delete from sip_subscriptions where expires >= -1 and hostname='%q'", mod_sofia_globals.hostname);
-	sofia_glue_actually_execute_sql(profile, sql, profile->ireg_mutex);
+	sql = switch_mprintf("delete from sip_subscriptions where expires >= -1 and hostname='%q'", mod_sofia_globals.hostname);
+	sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
 
-	switch_snprintfv(sql, sizeof(sql), "delete from sip_dialogs where expires >= -1 and hostname='%q'", mod_sofia_globals.hostname);
-	sofia_glue_actually_execute_sql(profile, sql, profile->ireg_mutex);
+	sql = switch_mprintf("delete from sip_dialogs where expires >= -1 and hostname='%q'", mod_sofia_globals.hostname);
+	sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
 
 }
 
 char *sofia_reg_find_reg_url(sofia_profile_t *profile, const char *user, const char *host, char *val, switch_size_t len)
 {
 	struct callback_t cbt = { 0 };
-	char sql[512] = "";
+	char *sql;
 
 	if (!user) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Called with null user!\n");
@@ -887,10 +888,10 @@ char *sofia_reg_find_reg_url(sofia_profile_t *profile, const char *user, const c
 	cbt.len = len;
 
 	if (host) {
-		switch_snprintfv(sql, sizeof(sql), "select contact from sip_registrations where sip_user='%q' and (sip_host='%q' or presence_hosts like '%%%q%%')",
+		sql = switch_mprintf("select contact from sip_registrations where sip_user='%q' and (sip_host='%q' or presence_hosts like '%%%q%%')",
 						user, host, host);
 	} else {
-		switch_snprintfv(sql, sizeof(sql), "select contact from sip_registrations where sip_user='%q'", user);
+		sql = switch_mprintf("select contact from sip_registrations where sip_user='%q'", user);
 	}
 
 
@@ -908,7 +909,7 @@ char *sofia_reg_find_reg_url(sofia_profile_t *profile, const char *user, const c
 switch_console_callback_match_t *sofia_reg_find_reg_url_multi(sofia_profile_t *profile, const char *user, const char *host)
 {
 	struct callback_t cbt = { 0 };
-	char sql[512] = "";
+	char *sql;
 
 	if (!user) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Called with null user!\n");
@@ -916,10 +917,10 @@ switch_console_callback_match_t *sofia_reg_find_reg_url_multi(sofia_profile_t *p
 	}
 
 	if (host) {
-		switch_snprintfv(sql, sizeof(sql), "select contact from sip_registrations where sip_user='%q' and (sip_host='%q' or presence_hosts like '%%%q%%')",
+		sql = switch_mprintf("select contact from sip_registrations where sip_user='%q' and (sip_host='%q' or presence_hosts like '%%%q%%')",
 						user, host, host);
 	} else {
-		switch_snprintfv(sql, sizeof(sql), "select contact from sip_registrations where sip_user='%q'", user);
+		sql = switch_mprintf("select contact from sip_registrations where sip_user='%q'", user);
 	}
 
 
@@ -932,7 +933,7 @@ switch_console_callback_match_t *sofia_reg_find_reg_url_multi(sofia_profile_t *p
 switch_console_callback_match_t *sofia_reg_find_reg_url_with_positive_expires_multi(sofia_profile_t *profile, const char *user, const char *host)
 {
 	struct callback_t cbt = { 0 };
-	char sql[512] = "";
+	char *sql;
 
 	if (!user) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Called with null user!\n");
@@ -940,13 +941,14 @@ switch_console_callback_match_t *sofia_reg_find_reg_url_with_positive_expires_mu
 	}
 
 	if (host) {
-		switch_snprintfv(sql, sizeof(sql), "select contact,expires from sip_registrations where sip_user='%q' and (sip_host='%q' or presence_hosts like '%%%q%%')",
+		sql = switch_mprintf("select contact,expires from sip_registrations where sip_user='%q' and (sip_host='%q' or presence_hosts like '%%%q%%')",
 						user, host, host);
 	} else {
-		switch_snprintfv(sql, sizeof(sql), "select contact,expires from sip_registrations where sip_user='%q'", user);
+		sql = switch_mprintf("select contact,expires from sip_registrations where sip_user='%q'", user);
 	}
 
 	sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_reg_find_reg_with_positive_expires_callback, &cbt);
+	free(sql);
 
 	return cbt.list;
 }
@@ -973,8 +975,7 @@ void sofia_reg_auth_challenge(sofia_profile_t *profile, nua_handle_t *nh, sofia_
 						 (long) switch_epoch_time_now(NULL) + (profile->nonce_ttl ? profile->nonce_ttl : DEFAULT_NONCE_TTL),
 						 profile->name, mod_sofia_globals.hostname);
 	switch_assert(sql != NULL);
-	sofia_glue_actually_execute_sql(profile, sql, profile->ireg_mutex);
-	switch_safe_free(sql);
+	sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
 
 	auth_str = switch_mprintf("Digest realm=\"%q\", nonce=\"%q\",%s algorithm=MD5, qop=\"auth\"", realm, uuid_str, stale ? " stale=true," : "");
 
@@ -2802,8 +2803,7 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile,
 							 switch_epoch_time_now(NULL) + (profile->nonce_ttl ? profile->nonce_ttl : exptime + 10), ncl, nonce);
 
 		switch_assert(sql != NULL);
-		sofia_glue_actually_execute_sql(profile, sql, profile->ireg_mutex);
-		switch_safe_free(sql);
+		sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
 
 		if (ret == AUTH_OK)
 			ret = AUTH_RENEWED;
diff --git a/src/mod/event_handlers/mod_event_socket/mod_event_socket.c b/src/mod/event_handlers/mod_event_socket/mod_event_socket.c
index 371ce62b3a..f970a1c63e 100644
--- a/src/mod/event_handlers/mod_event_socket/mod_event_socket.c
+++ b/src/mod/event_handlers/mod_event_socket/mod_event_socket.c
@@ -366,7 +366,7 @@ static void event_handler(switch_event_t *event)
 
 		if (send && switch_test_flag(l, LFLAG_MYEVENTS)) {
 			char *uuid = switch_event_get_header(event, "unique-id");
-			if (!uuid || strcmp(uuid, switch_core_session_get_uuid(l->session))) {
+			if (!uuid || (l->session && strcmp(uuid, switch_core_session_get_uuid(l->session)))) {
 				send = 0;
 			}
 		}
diff --git a/src/mod/formats/mod_vlc/mod_vlc.c b/src/mod/formats/mod_vlc/mod_vlc.c
index d5b5ec336d..4984601618 100644
--- a/src/mod/formats/mod_vlc/mod_vlc.c
+++ b/src/mod/formats/mod_vlc/mod_vlc.c
@@ -45,6 +45,7 @@
 #include <switch.h>
 #include <vlc/vlc.h>
 #include <vlc/libvlc_media_player.h>
+#include <vlc/libvlc_events.h>
 
 #define VLC_BUFFER_SIZE 65536
 
@@ -83,6 +84,29 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_vlc_shutdown);
 SWITCH_MODULE_LOAD_FUNCTION(mod_vlc_load);
 SWITCH_MODULE_DEFINITION(mod_vlc, mod_vlc_load, mod_vlc_shutdown, NULL);
 
+static void vlc_mediaplayer_error_callback(const libvlc_event_t * event, void * data)
+{
+        vlc_file_context_t *context = (vlc_file_context_t *) data;
+        int status = libvlc_media_get_state(context->m);
+        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Got a libvlc_MediaPlayerEncounteredError callback. mediaPlayer Status: %d\n", status);
+        if (status == libvlc_Error) {
+               context->err = 1;
+               switch_thread_cond_signal(context->started);
+	     }
+}
+static void vlc_media_state_callback(const libvlc_event_t * event, void * data)
+{
+        vlc_file_context_t *context = (vlc_file_context_t *) data;
+        int new_state = event->u.media_state_changed.new_state;
+
+        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Got a libvlc_MediaStateChanged callback. New state: %d\n", new_state);
+        if (new_state == libvlc_Ended || new_state == libvlc_Error) {
+                switch_thread_cond_signal(context->started);
+        }
+}
+
+
+
 void vlc_auto_play_callback(void *data, const void *samples, unsigned count, int64_t pts) {
 
 	vlc_file_context_t *context = (vlc_file_context_t *) data;
@@ -145,6 +169,7 @@ void vlc_imem_release_callback(void *data, const char *cookie, size_t size, void
 static switch_status_t vlc_file_open(switch_file_handle_t *handle, const char *path)
 {
 	vlc_file_context_t *context;
+	libvlc_event_manager_t *mp_event_manager, *m_event_manager;
 	
 	context = switch_core_alloc(handle->memory_pool, sizeof(*context));
 	context->pool = handle->memory_pool;
@@ -192,6 +217,12 @@ static switch_status_t vlc_file_open(switch_file_handle_t *handle, const char *p
 		
 		libvlc_audio_set_format(context->mp, "S16N", context->samplerate, 1);
 		
+		m_event_manager = libvlc_media_event_manager(context->m);
+		libvlc_event_attach(m_event_manager, libvlc_MediaStateChanged, vlc_media_state_callback, (void *) context);
+
+		mp_event_manager = libvlc_media_player_event_manager(context->mp);
+		libvlc_event_attach(mp_event_manager, libvlc_MediaPlayerEncounteredError, vlc_mediaplayer_error_callback, (void *) context);
+		
 		libvlc_audio_set_callbacks(context->mp, vlc_auto_play_callback, NULL,NULL,NULL,NULL, (void *) context);
 
 		libvlc_media_player_play(context->mp);
@@ -258,21 +289,29 @@ static switch_status_t vlc_file_read(switch_file_handle_t *handle, void *data, s
 
 	status = libvlc_media_get_state(context->m);
 	
-	if (status == 7) {
+	if (status == libvlc_Error) {
 		return SWITCH_STATUS_GENERR;
 	}
 
 	switch_mutex_lock(context->audio_mutex); 
-	while (context->playing == 0) {
+	while (context->playing == 0 && status != libvlc_Ended && status != libvlc_Error) {
 		switch_thread_cond_wait(context->started, context->audio_mutex);		
+		status = libvlc_media_get_state(context->m);
 	}
+
+	if (context->err == 1) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "VLC error\n");
+		return SWITCH_STATUS_FALSE;
+	}
+
 	switch_mutex_unlock(context->audio_mutex);
 	
 	switch_mutex_lock(context->audio_mutex);
 	read = switch_buffer_read(context->audio_buffer, data, bytes);
 	switch_mutex_unlock(context->audio_mutex);
 	
-	if (!read && (status == 5 || status == 6)) {
+        status = libvlc_media_get_state(context->m);
+	if (!read && (status == libvlc_Stopped || status == libvlc_Ended || status == libvlc_Error)) {
 		return SWITCH_STATUS_FALSE;
 	} else if (!read) {
 		read = 2;
@@ -301,19 +340,29 @@ static switch_status_t vlc_file_write(switch_file_handle_t *handle, void *data,
 static switch_status_t vlc_file_close(switch_file_handle_t *handle)
 {
 	vlc_file_context_t *context = handle->private_info;
+	int sanity = 0;	
 	
 	context->playing = 0;
 	
 	/* The clients need to empty the last of the audio buffer */
 	while ( switch_buffer_inuse(context->audio_buffer) > 0 ) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "VLC waiting to close the files: %d \n", (int) switch_buffer_inuse(context->audio_buffer));
-		sleep(1);
+		switch_yield(500000);
+		if (++sanity > 10) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Giving up waiting for client to empty the audio buffer\n");
+			break;
+		}
 	}
 
 	/* Let the clients get the last of the audio stream */
+	sanity = 0;
 	while ( 3 == libvlc_media_get_state(context->m) ) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "VLC waiting for clients: %d \n", libvlc_media_get_state(context->m));
-		sleep(1);
+		switch_yield(500000); 
+                if (++sanity > 10) {
+                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Giving up waiting for client to get the last of the audio stream\n");
+                        break;
+		}
 	}
 
 	if( context->mp ) 
diff --git a/src/mod/languages/mod_java/freeswitch_java.cpp b/src/mod/languages/mod_java/freeswitch_java.cpp
index d8390b2ade..d8508e145c 100644
--- a/src/mod/languages/mod_java/freeswitch_java.cpp
+++ b/src/mod/languages/mod_java/freeswitch_java.cpp
@@ -1,5 +1,35 @@
 #include "freeswitch_java.h"
 
+jobject originate_state_handler;
+
+SWITCH_DECLARE(void) setOriginateStateHandler(jobject stateHandler)
+{
+        JNIEnv *env = NULL;
+        jint envStatus = javaVM->GetEnv((void**)&env, JNI_VERSION_1_4);
+        if ( envStatus != JNI_OK ) {
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error getting JNIEnv!\n");
+                return;
+        }
+
+        if ( stateHandler != NULL && originate_state_handler != NULL ) {
+                const char* errorMessage = "Originate state handler is already registered";
+                jclass exceptionClass = env->FindClass("java/util/TooManyListenersException");
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, errorMessage);
+                env->ThrowNew(exceptionClass, errorMessage);
+        } else if ( stateHandler == NULL && originate_state_handler != NULL ) {
+                env->DeleteGlobalRef(originate_state_handler);
+                originate_state_handler = NULL;
+        } else {
+                originate_state_handler = env->NewGlobalRef(stateHandler);
+                if ( originate_state_handler == NULL ) {
+                        const char* errorMessage = "Unable to create global reference for state handler";
+                        jclass exceptionClass = env->FindClass("java/lang/OutOfMemoryError");
+                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, errorMessage);
+                        env->ThrowNew(exceptionClass, errorMessage);
+                }
+        }
+}
+
 JavaSession::JavaSession() : CoreSession()
 {
 }
@@ -328,3 +358,152 @@ done:
     return status;
 }
 
+switch_status_t originate_handler_method(switch_core_session_t *session, const char* method) {
+	if ( originate_state_handler != NULL ) {
+		JNIEnv *env = NULL;
+		bool needDetach = false;
+
+		jint envStatus = javaVM->GetEnv((void**)&env, JNI_VERSION_1_4);
+		if ( envStatus == JNI_EDETACHED ) {
+			envStatus = javaVM->AttachCurrentThread((void**)&env, NULL);
+			if ( envStatus == JNI_OK ) needDetach = true;
+		}
+
+		if ( envStatus != JNI_OK ) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error getting JNIEnv!\n");
+			return SWITCH_STATUS_FALSE;
+		}
+
+		jclass handlerClass = env->GetObjectClass(originate_state_handler);
+		if ( handlerClass == NULL ) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error getting handler class!\n");
+			if ( needDetach ) javaVM->DetachCurrentThread();
+			return SWITCH_STATUS_FALSE;
+		}
+
+		jint result = SWITCH_STATUS_FALSE;
+		jmethodID handlerMethod = env->GetMethodID(handlerClass, method, "(Ljava/lang/String;)I");
+		if ( handlerMethod != NULL ) {
+			char *uuid = switch_core_session_get_uuid(session);
+			jstring javaUuid = env->NewStringUTF(uuid);
+			result = env->CallIntMethod(originate_state_handler, handlerMethod, javaUuid);
+			env->DeleteLocalRef(javaUuid);
+		}
+
+		env->DeleteLocalRef(handlerClass);
+		if ( needDetach ) javaVM->DetachCurrentThread();
+		return (switch_status_t)result;
+	}
+
+	return SWITCH_STATUS_FALSE;
+}
+
+switch_status_t originate_on_init(switch_core_session_t *session) {
+	return originate_handler_method(session, "onInit");
+}
+
+switch_status_t originate_on_routing(switch_core_session_t *session) {
+	return originate_handler_method(session, "onRouting");
+}
+
+switch_status_t originate_on_execute(switch_core_session_t *session) {
+	return originate_handler_method(session, "onExecute");
+}
+
+switch_status_t originate_on_hangup(switch_core_session_t *session) {
+	if ( originate_state_handler != NULL ) {
+		JNIEnv *env = NULL;
+		bool needDetach = false;
+
+		jint envStatus = javaVM->GetEnv((void**)&env, JNI_VERSION_1_4);
+		if ( envStatus == JNI_EDETACHED ) {
+			envStatus = javaVM->AttachCurrentThread((void**)&env, NULL);
+			if ( envStatus == JNI_OK ) needDetach = true;
+                }
+
+		if ( envStatus != JNI_OK ) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error getting JNIEnv!\n");
+			return SWITCH_STATUS_FALSE;
+		}
+
+		jclass handlerClass = env->GetObjectClass(originate_state_handler);
+		if ( handlerClass == NULL ) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error getting handler class!\n");
+			if ( needDetach ) javaVM->DetachCurrentThread();
+			return SWITCH_STATUS_FALSE;
+		}
+
+		jint result = SWITCH_STATUS_FALSE;
+		jmethodID handlerMethod = env->GetMethodID(handlerClass, "onHangup", "(Ljava/lang/String;Ljava/lang/String;)I");
+		if ( handlerMethod != NULL ) {
+			switch_channel_t *channel = switch_core_session_get_channel(session);
+			const char *uuid = switch_core_session_get_uuid(session);
+			const char *cause = switch_channel_cause2str(switch_channel_get_cause(channel));
+			jstring javaUuid = env->NewStringUTF(uuid);
+			jstring javaCause = env->NewStringUTF(cause);
+			result = env->CallIntMethod(originate_state_handler, handlerMethod, javaUuid, javaCause);
+			env->DeleteLocalRef(javaUuid);
+			env->DeleteLocalRef(javaCause);
+		}
+
+		env->DeleteLocalRef(handlerClass);
+		if ( needDetach ) javaVM->DetachCurrentThread();
+		return (switch_status_t)result;
+	}
+
+	return SWITCH_STATUS_FALSE;
+}
+
+switch_status_t originate_on_exchange_media(switch_core_session_t *session) {
+	return originate_handler_method(session, "onExchangeMedia");
+}
+
+switch_status_t originate_on_soft_execute(switch_core_session_t *session) {
+	return originate_handler_method(session, "onSoftExecute");
+}
+
+switch_status_t originate_on_consume_media(switch_core_session_t *session) {
+	return originate_handler_method(session, "onConsumeMedia");
+}
+
+switch_status_t originate_on_hibernate(switch_core_session_t *session) {
+	return originate_handler_method(session, "onHibernate");
+}
+
+switch_status_t originate_on_reset(switch_core_session_t *session) {
+	return originate_handler_method(session, "onReset");
+}
+
+switch_status_t originate_on_park(switch_core_session_t *session) {
+	return originate_handler_method(session, "onPark");
+}
+
+switch_status_t originate_on_reporting(switch_core_session_t *session) {
+	return originate_handler_method(session, "onReporting");
+}
+
+switch_status_t originate_on_destroy(switch_core_session_t *session) {
+	return originate_handler_method(session, "onDestroy");
+}
+
+switch_state_handler_table_t originate_state_handlers = {
+	/*.on_init */ &originate_on_init,
+	/*.on_routing */ &originate_on_routing,
+	/*.on_execute */ &originate_on_execute,
+	/*.on_hangup */ &originate_on_hangup,
+	/*.on_exchange_media */ &originate_on_exchange_media,
+	/*.on_soft_execute */ &originate_on_soft_execute,
+	/*.on_consume_media */ &originate_on_consume_media,
+	/*.on_hibernate */ &originate_on_hibernate,
+	/*.on_reset */ &originate_on_reset,
+	/*.on_park */ &originate_on_park,
+	/*.on_reporting */ &originate_on_reporting,
+	/*.on_destroy */ &originate_on_destroy
+};
+
+int JavaSession::originate(JavaSession* aleg, char* destination, int timeout) {
+	switch_state_handler_table_t *stateHandlers = NULL;
+	if ( originate_state_handler != NULL ) stateHandlers = &originate_state_handlers;
+	return CoreSession::originate(aleg, destination, timeout, stateHandlers);
+}
+
diff --git a/src/mod/languages/mod_java/freeswitch_java.h b/src/mod/languages/mod_java/freeswitch_java.h
index e87b5928f0..5d6d138168 100644
--- a/src/mod/languages/mod_java/freeswitch_java.h
+++ b/src/mod/languages/mod_java/freeswitch_java.h
@@ -6,6 +6,16 @@
 
 extern JavaVM *javaVM;
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+SWITCH_DECLARE(void) setOriginateStateHandler(jobject stateHandler);
+
+#ifdef __cplusplus
+}
+#endif
+
 class JavaSession:public CoreSession {
   public:
 	JavaSession();
@@ -19,6 +29,7 @@ class JavaSession:public CoreSession {
 	void setHangupHook(jobject hangupHook);
 	virtual void check_hangup_hook();
 	virtual switch_status_t run_dtmf_callback(void *input, switch_input_type_t itype);
+	int originate(JavaSession* aleg, char* destination, int timeout);
 };
 
 #endif
diff --git a/src/mod/languages/mod_java/mod_java.i b/src/mod/languages/mod_java/mod_java.i
index 42527fd541..858dac8d08 100644
--- a/src/mod/languages/mod_java/mod_java.i
+++ b/src/mod/languages/mod_java/mod_java.i
@@ -2,6 +2,7 @@
 %include ../../../../swig_common.i
 /** insert the following includes into generated code so it compiles */
 %{
+#include "switch.h"
 #include "switch_cpp.h"
 #include "freeswitch_java.h"
 %}
@@ -53,7 +54,11 @@
 %typemap(javain) char *terminator "$javainput"
 %typemap(freearg) char *terminator ""
 
-
+#define SWITCH_DECLARE(type) type
+%javamethodmodifiers CoreSession::originate(CoreSession *, char *, int, switch_state_handler_table_t *) "protected";
+%javaexception ("java.util.TooManyListenersException") setOriginateStateHandler(jobject);
+%typemap(jtype) jobject stateHandler "org.freeswitch.StateHandler"
+%typemap(jstype) jobject stateHandler "org.freeswitch.StateHandler"
 
 %include "enums.swg"
 %include switch_swigable_cpp.h
diff --git a/src/mod/languages/mod_java/modjava.c b/src/mod/languages/mod_java/modjava.c
index 98bf5f9ac8..428a9095be 100644
--- a/src/mod/languages/mod_java/modjava.c
+++ b/src/mod/languages/mod_java/modjava.c
@@ -38,7 +38,7 @@ static switch_memory_pool_t *memoryPool = NULL;
 static switch_dso_handle_t *javaVMHandle = NULL;
 
 JavaVM *javaVM = NULL;
-
+jclass launcherClass = NULL;
 
 SWITCH_MODULE_LOAD_FUNCTION(mod_java_load);
 SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_java_shutdown);
@@ -62,19 +62,16 @@ static vm_control_t  vmControl;
 
 static void launch_java(switch_core_session_t *session, const char *data, JNIEnv *env)
 {
-    jclass Launcher = NULL;
     jmethodID launch = NULL;
     jstring uuid = NULL;
     jstring args = NULL;
 
-    Launcher = (*env)->FindClass(env, "org/freeswitch/Launcher");
-    if (Launcher == NULL)
+    if (launcherClass == NULL)
     {
-        (*env)->ExceptionDescribe(env);
         goto done;
     }
 
-    launch = (*env)->GetStaticMethodID(env, Launcher, "launch", "(Ljava/lang/String;Ljava/lang/String;)V");
+    launch = (*env)->GetStaticMethodID(env, launcherClass, "launch", "(Ljava/lang/String;Ljava/lang/String;)V");
     if (launch == NULL)
     {
         (*env)->ExceptionDescribe(env);
@@ -95,7 +92,7 @@ static void launch_java(switch_core_session_t *session, const char *data, JNIEnv
         goto done;
     }
 
-    (*env)->CallStaticVoidMethod(env, Launcher, launch, uuid, args);
+    (*env)->CallStaticVoidMethod(env, launcherClass, launch, uuid, args);
     if ((*env)->ExceptionOccurred(env))
         (*env)->ExceptionDescribe(env);
 
@@ -104,8 +101,6 @@ done:
         (*env)->DeleteLocalRef(env, args);
     if (uuid != NULL)
         (*env)->DeleteLocalRef(env, uuid);
-    if (Launcher != NULL)
-        (*env)->DeleteLocalRef(env, Launcher);
 }
 
 static switch_status_t exec_user_method(user_method_t * userMethod) {
@@ -145,12 +140,14 @@ static switch_status_t exec_user_method(user_method_t * userMethod) {
         goto done;
     }
 
-    arg = (*env)->NewStringUTF(env, userMethod->arg);
+    if (userMethod->arg != NULL) {
+        arg = (*env)->NewStringUTF(env, userMethod->arg);
 
-    if (arg == NULL) {
-        (*env)->ExceptionDescribe(env);
-        status =  SWITCH_STATUS_FALSE;
-        goto done;
+        if (arg == NULL) {
+            (*env)->ExceptionDescribe(env);
+            status =  SWITCH_STATUS_FALSE;
+            goto done;
+        }
     }
 
     (*env)->CallStaticVoidMethod(env, class, method, arg);
@@ -311,8 +308,31 @@ static switch_status_t create_java_vm(JavaVMOption *options, int optionCount, vm
         res = pJNI_CreateJavaVM(&javaVM, (void*) &env, &initArgs);
         if (res == JNI_OK)
         {
+        	// call FindClass here already so that the Java VM executes the static
+        	// initializer (@see org.freeswitch.Launcher) which loads the jni library
+        	// so we can use jni functions right away (for example in the startup method)
+        	launcherClass = (*env)->FindClass(env, "org/freeswitch/Launcher");
+        	if ( launcherClass == NULL )
+        	{
+        		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to find 'org.freeswitch.Launcher' class!\n");
+        		(*env)->ExceptionDescribe(env);
+        		status = SWITCH_STATUS_FALSE;
+        	}
+
+        	// store a global reference for use in the launch_java() function
+            launcherClass = (*env)->NewGlobalRef(env, launcherClass);
+        	if ( launcherClass == NULL )
+        	{
+        		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory!\n");
+        		(*env)->ExceptionDescribe(env);
+        		status = SWITCH_STATUS_FALSE;
+        	}
+        	else
+        	{
+        		status = SWITCH_STATUS_SUCCESS;
+        	}
+
             (*javaVM)->DetachCurrentThread(javaVM);
-            status = SWITCH_STATUS_SUCCESS;
         }
         else
         {
diff --git a/src/mod/languages/mod_java/src/org/freeswitch/ApplicationLauncher.java b/src/mod/languages/mod_java/src/org/freeswitch/ApplicationLauncher.java
new file mode 100644
index 0000000000..0e7ad0abe0
--- /dev/null
+++ b/src/mod/languages/mod_java/src/org/freeswitch/ApplicationLauncher.java
@@ -0,0 +1,15 @@
+package org.freeswitch.example;
+
+import org.freeswitch.swig.freeswitch;
+
+public class ApplicationLauncher {
+
+	public static final void startup(String arg) {
+		try {
+			freeswitch.setOriginateStateHandler(OriginateStateHandler.getInstance());
+		} catch (Exception e) {
+			freeswitch.console_log("err", "Error registering originate state handler");
+		}
+	}
+
+}
diff --git a/src/mod/languages/mod_java/src/org/freeswitch/OriginateStateHandler.java b/src/mod/languages/mod_java/src/org/freeswitch/OriginateStateHandler.java
new file mode 100644
index 0000000000..dd59515828
--- /dev/null
+++ b/src/mod/languages/mod_java/src/org/freeswitch/OriginateStateHandler.java
@@ -0,0 +1,22 @@
+package org.freeswitch.example;
+
+import org.freeswitch.StateHandler.OnHangupHandler;
+
+public class OriginateStateHandler implements OnHangupHandler {
+
+	private static OriginateStateHandler instance = null;
+
+	public static final OriginateStateHandler getInstance() {
+		if ( instance == null ) instance = new OriginateStateHandler();
+		return instance;
+	}
+
+	private OriginateStateHandler() {
+		// hide constructor
+	}
+
+	public int onHangup(String uuid, String cause) {
+		return 1; // SWITCH_STATUS_FALSE
+	}
+
+}
\ No newline at end of file
diff --git a/src/mod/languages/mod_java/src/org/freeswitch/StateHandler.java b/src/mod/languages/mod_java/src/org/freeswitch/StateHandler.java
new file mode 100644
index 0000000000..b5f9ba2648
--- /dev/null
+++ b/src/mod/languages/mod_java/src/org/freeswitch/StateHandler.java
@@ -0,0 +1,54 @@
+package org.freeswitch;
+
+public interface StateHandler {
+
+	public interface OnInitHandler extends StateHandler {
+		public int onInit(String uuid);
+	}
+
+	public static interface OnRoutingHandler extends StateHandler {
+		public int onRouting(String uuid);
+	}
+
+	public static interface OnExecuteHandler extends StateHandler {
+		public int onExecute(String uuid);
+	}
+
+	public static interface OnHangupHandler extends StateHandler {
+		public int onHangup(String uuid, String cause);
+	}
+
+	public static interface OnExchangeMediaHandler extends StateHandler {
+		public int onExchangeMedia(String uuid);
+	}
+
+	public static interface OnSoftExecuteHandler extends StateHandler {
+		public int onSoftExecute(String uuid);
+	}
+
+	public static interface OnConsumeMediaHandler extends StateHandler {
+		public int onConsumeMedia(String uuid);
+	}
+
+	public static interface OnHibernateHandler extends StateHandler {
+		public int onHibernate(String uuid);
+	}
+
+	public static interface OnResetHandler extends StateHandler {
+		public int onReset(String uuid);
+	}
+
+	public static interface OnParkHandler extends StateHandler {
+		public int onPark(String uuid);
+	}
+
+	public static interface OnReportingHandler extends StateHandler {
+		public int onReporting(String uuid);
+	}
+
+	public static interface OnDestroyHandler extends StateHandler {
+		public int onDestroy(String uuid);
+	}
+
+}
+
diff --git a/src/mod/languages/mod_managed/freeswitch_wrap.2010.cxx b/src/mod/languages/mod_managed/freeswitch_wrap.2010.cxx
index 40aab99e82..8d09ec6b03 100644
--- a/src/mod/languages/mod_managed/freeswitch_wrap.2010.cxx
+++ b/src/mod/languages/mod_managed/freeswitch_wrap.2010.cxx
@@ -1190,6 +1190,16 @@ SWIGEXPORT char * SWIGSTDCALL CSharp_SWITCH_CHANNEL_EXECUTE_ON_POST_ORIGINATE_VA
 }
 
 
+SWIGEXPORT char * SWIGSTDCALL CSharp_SWITCH_CHANNEL_EXECUTE_ON_PRE_ORIGINATE_VARIABLE_get() {
+  char * jresult ;
+  char *result = 0 ;
+  
+  result = (char *)("execute_on_pre_originate");
+  jresult = SWIG_csharp_string_callback((const char *)result); 
+  return jresult;
+}
+
+
 SWIGEXPORT char * SWIGSTDCALL CSharp_SWITCH_CHANNEL_API_ON_ANSWER_VARIABLE_get() {
   char * jresult ;
   char *result = 0 ;
@@ -1260,6 +1270,16 @@ SWIGEXPORT char * SWIGSTDCALL CSharp_SWITCH_CHANNEL_API_ON_POST_ORIGINATE_VARIAB
 }
 
 
+SWIGEXPORT char * SWIGSTDCALL CSharp_SWITCH_CHANNEL_API_ON_PRE_ORIGINATE_VARIABLE_get() {
+  char * jresult ;
+  char *result = 0 ;
+  
+  result = (char *)("api_on_pre_originate");
+  jresult = SWIG_csharp_string_callback((const char *)result); 
+  return jresult;
+}
+
+
 SWIGEXPORT char * SWIGSTDCALL CSharp_SWITCH_CALL_TIMEOUT_VARIABLE_get() {
   char * jresult ;
   char *result = 0 ;
@@ -1840,6 +1860,16 @@ SWIGEXPORT int SWIGSTDCALL CSharp_SWITCH_DTMF_LOG_LEN_get() {
 }
 
 
+SWIGEXPORT int SWIGSTDCALL CSharp_SWITCH_MAX_TRANS_get() {
+  int jresult ;
+  int result;
+  
+  result = (int)(2000);
+  jresult = result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_dtmf_t_digit_set(void * jarg1, char jarg2) {
   switch_dtmf_t *arg1 = (switch_dtmf_t *) 0 ;
   char arg2 ;
@@ -2310,6 +2340,36 @@ SWIGEXPORT char * SWIGSTDCALL CSharp_switch_directories_mod_dir_get(void * jarg1
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_directories_lib_dir_set(void * jarg1, char * jarg2) {
+  switch_directories *arg1 = (switch_directories *) 0 ;
+  char *arg2 = (char *) 0 ;
+  
+  arg1 = (switch_directories *)jarg1; 
+  arg2 = (char *)jarg2; 
+  {
+    if (arg1->lib_dir) delete [] arg1->lib_dir;
+    if (arg2) {
+      arg1->lib_dir = (char *) (new char[strlen((const char *)arg2)+1]);
+      strcpy((char *)arg1->lib_dir, (const char *)arg2);
+    } else {
+      arg1->lib_dir = 0;
+    }
+  }
+}
+
+
+SWIGEXPORT char * SWIGSTDCALL CSharp_switch_directories_lib_dir_get(void * jarg1) {
+  char * jresult ;
+  switch_directories *arg1 = (switch_directories *) 0 ;
+  char *result = 0 ;
+  
+  arg1 = (switch_directories *)jarg1; 
+  result = (char *) ((arg1)->lib_dir);
+  jresult = SWIG_csharp_string_callback((const char *)result); 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_directories_conf_dir_set(void * jarg1, char * jarg2) {
   switch_directories *arg1 = (switch_directories *) 0 ;
   char *arg2 = (char *) 0 ;
@@ -6040,6 +6100,96 @@ SWIGEXPORT void SWIGSTDCALL CSharp_delete_switch_hold_record_t(void * jarg1) {
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_thread_data_t_func_set(void * jarg1, void * jarg2) {
+  switch_thread_data_t *arg1 = (switch_thread_data_t *) 0 ;
+  switch_thread_start_t arg2 ;
+  switch_thread_start_t *argp2 ;
+  
+  arg1 = (switch_thread_data_t *)jarg1; 
+  argp2 = (switch_thread_start_t *)jarg2; 
+  if (!argp2) {
+    SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null switch_thread_start_t", 0);
+    return ;
+  }
+  arg2 = *argp2; 
+  if (arg1) (arg1)->func = arg2;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_thread_data_t_func_get(void * jarg1) {
+  void * jresult ;
+  switch_thread_data_t *arg1 = (switch_thread_data_t *) 0 ;
+  switch_thread_start_t result;
+  
+  arg1 = (switch_thread_data_t *)jarg1; 
+  result =  ((arg1)->func);
+  jresult = new switch_thread_start_t((const switch_thread_start_t &)result); 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_thread_data_t_obj_set(void * jarg1, void * jarg2) {
+  switch_thread_data_t *arg1 = (switch_thread_data_t *) 0 ;
+  void *arg2 = (void *) 0 ;
+  
+  arg1 = (switch_thread_data_t *)jarg1; 
+  arg2 = (void *)jarg2; 
+  if (arg1) (arg1)->obj = arg2;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_thread_data_t_obj_get(void * jarg1) {
+  void * jresult ;
+  switch_thread_data_t *arg1 = (switch_thread_data_t *) 0 ;
+  void *result = 0 ;
+  
+  arg1 = (switch_thread_data_t *)jarg1; 
+  result = (void *) ((arg1)->obj);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_thread_data_t_alloc_set(void * jarg1, int jarg2) {
+  switch_thread_data_t *arg1 = (switch_thread_data_t *) 0 ;
+  int arg2 ;
+  
+  arg1 = (switch_thread_data_t *)jarg1; 
+  arg2 = (int)jarg2; 
+  if (arg1) (arg1)->alloc = arg2;
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_thread_data_t_alloc_get(void * jarg1) {
+  int jresult ;
+  switch_thread_data_t *arg1 = (switch_thread_data_t *) 0 ;
+  int result;
+  
+  arg1 = (switch_thread_data_t *)jarg1; 
+  result = (int) ((arg1)->alloc);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_new_switch_thread_data_t() {
+  void * jresult ;
+  switch_thread_data_t *result = 0 ;
+  
+  result = (switch_thread_data_t *)new switch_thread_data_t();
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_delete_switch_thread_data_t(void * jarg1) {
+  switch_thread_data_t *arg1 = (switch_thread_data_t *) 0 ;
+  
+  arg1 = (switch_thread_data_t *)jarg1; 
+  delete arg1;
+}
+
+
 SWIGEXPORT int SWIGSTDCALL CSharp_MESSAGE_STRING_ARG_MAX_get() {
   int jresult ;
   int result;
@@ -7785,6 +7935,18 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_session_thread_launch(void * jarg1
 }
 
 
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_thread_pool_launch_thread(void * jarg1) {
+  int jresult ;
+  switch_thread_data_t **arg1 = (switch_thread_data_t **) 0 ;
+  switch_status_t result;
+  
+  arg1 = (switch_thread_data_t **)jarg1; 
+  result = (switch_status_t)switch_thread_pool_launch_thread(arg1);
+  jresult = result; 
+  return jresult;
+}
+
+
 SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_session_thread_pool_launch(void * jarg1) {
   int jresult ;
   switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
@@ -10962,13 +11124,13 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_ivr_preprocess_session(void * jarg1, ch
 }
 
 
-SWIGEXPORT void SWIGSTDCALL CSharp_switch_core_sqldb_stop_thread() {
-  switch_core_sqldb_stop_thread();
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_core_sqldb_pause() {
+  switch_core_sqldb_pause();
 }
 
 
-SWIGEXPORT void SWIGSTDCALL CSharp_switch_core_sqldb_start_thread() {
-  switch_core_sqldb_start_thread();
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_core_sqldb_resume() {
+  switch_core_sqldb_resume();
 }
 
 
@@ -11884,7 +12046,21 @@ SWIGEXPORT void SWIGSTDCALL CSharp_switch_core_recovery_flush(char * jarg1, char
 }
 
 
-SWIGEXPORT int SWIGSTDCALL CSharp_switch_switch_sql_queue_manager_push(void * jarg1, char * jarg2, unsigned long jarg3, int jarg4) {
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_sql_queue_manager_size(void * jarg1, unsigned long jarg2) {
+  int jresult ;
+  switch_sql_queue_manager_t *arg1 = (switch_sql_queue_manager_t *) 0 ;
+  uint32_t arg2 ;
+  int result;
+  
+  arg1 = (switch_sql_queue_manager_t *)jarg1; 
+  arg2 = (uint32_t)jarg2; 
+  result = (int)switch_sql_queue_manager_size(arg1,arg2);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_sql_queue_manager_push_confirm(void * jarg1, char * jarg2, unsigned long jarg3, int jarg4) {
   int jresult ;
   switch_sql_queue_manager_t *arg1 = (switch_sql_queue_manager_t *) 0 ;
   char *arg2 = (char *) 0 ;
@@ -11896,67 +12072,89 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_switch_sql_queue_manager_push(void * ja
   arg2 = (char *)jarg2; 
   arg3 = (uint32_t)jarg3; 
   arg4 = (switch_bool_t)jarg4; 
-  result = (switch_status_t)switch_switch_sql_queue_manager_push(arg1,(char const *)arg2,arg3,arg4);
+  result = (switch_status_t)switch_sql_queue_manager_push_confirm(arg1,(char const *)arg2,arg3,arg4);
   jresult = result; 
   return jresult;
 }
 
 
-SWIGEXPORT int SWIGSTDCALL CSharp_switch_switch_sql_queue_manager_destroy(void * jarg1) {
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_sql_queue_manager_push(void * jarg1, char * jarg2, unsigned long jarg3, int jarg4) {
+  int jresult ;
+  switch_sql_queue_manager_t *arg1 = (switch_sql_queue_manager_t *) 0 ;
+  char *arg2 = (char *) 0 ;
+  uint32_t arg3 ;
+  switch_bool_t arg4 ;
+  switch_status_t result;
+  
+  arg1 = (switch_sql_queue_manager_t *)jarg1; 
+  arg2 = (char *)jarg2; 
+  arg3 = (uint32_t)jarg3; 
+  arg4 = (switch_bool_t)jarg4; 
+  result = (switch_status_t)switch_sql_queue_manager_push(arg1,(char const *)arg2,arg3,arg4);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_sql_queue_manager_destroy(void * jarg1) {
   int jresult ;
   switch_sql_queue_manager_t **arg1 = (switch_sql_queue_manager_t **) 0 ;
   switch_status_t result;
   
   arg1 = (switch_sql_queue_manager_t **)jarg1; 
-  result = (switch_status_t)switch_switch_sql_queue_manager_destroy(arg1);
+  result = (switch_status_t)switch_sql_queue_manager_destroy(arg1);
   jresult = result; 
   return jresult;
 }
 
 
-SWIGEXPORT int SWIGSTDCALL CSharp_switch_switch_sql_queue_manager_init(void * jarg1, unsigned long jarg2, char * jarg3, char * jarg4, char * jarg5, char * jarg6, char * jarg7) {
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_sql_queue_manager_init_name(char * jarg1, void * jarg2, unsigned long jarg3, char * jarg4, unsigned long jarg5, char * jarg6, char * jarg7, char * jarg8, char * jarg9) {
   int jresult ;
-  switch_sql_queue_manager_t **arg1 = (switch_sql_queue_manager_t **) 0 ;
-  uint32_t arg2 ;
-  char *arg3 = (char *) 0 ;
+  char *arg1 = (char *) 0 ;
+  switch_sql_queue_manager_t **arg2 = (switch_sql_queue_manager_t **) 0 ;
+  uint32_t arg3 ;
   char *arg4 = (char *) 0 ;
-  char *arg5 = (char *) 0 ;
+  uint32_t arg5 ;
   char *arg6 = (char *) 0 ;
   char *arg7 = (char *) 0 ;
+  char *arg8 = (char *) 0 ;
+  char *arg9 = (char *) 0 ;
   switch_status_t result;
   
-  arg1 = (switch_sql_queue_manager_t **)jarg1; 
-  arg2 = (uint32_t)jarg2; 
-  arg3 = (char *)jarg3; 
+  arg1 = (char *)jarg1; 
+  arg2 = (switch_sql_queue_manager_t **)jarg2; 
+  arg3 = (uint32_t)jarg3; 
   arg4 = (char *)jarg4; 
-  arg5 = (char *)jarg5; 
+  arg5 = (uint32_t)jarg5; 
   arg6 = (char *)jarg6; 
   arg7 = (char *)jarg7; 
-  result = (switch_status_t)switch_switch_sql_queue_manager_init(arg1,arg2,(char const *)arg3,(char const *)arg4,(char const *)arg5,(char const *)arg6,(char const *)arg7);
+  arg8 = (char *)jarg8; 
+  arg9 = (char *)jarg9; 
+  result = (switch_status_t)switch_sql_queue_manager_init_name((char const *)arg1,arg2,arg3,(char const *)arg4,arg5,(char const *)arg6,(char const *)arg7,(char const *)arg8,(char const *)arg9);
   jresult = result; 
   return jresult;
 }
 
 
-SWIGEXPORT int SWIGSTDCALL CSharp_switch_switch_sql_queue_manager_start(void * jarg1) {
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_sql_queue_manager_start(void * jarg1) {
   int jresult ;
   switch_sql_queue_manager_t *arg1 = (switch_sql_queue_manager_t *) 0 ;
   switch_status_t result;
   
   arg1 = (switch_sql_queue_manager_t *)jarg1; 
-  result = (switch_status_t)switch_switch_sql_queue_manager_start(arg1);
+  result = (switch_status_t)switch_sql_queue_manager_start(arg1);
   jresult = result; 
   return jresult;
 }
 
 
-SWIGEXPORT int SWIGSTDCALL CSharp_switch_switch_sql_queue_manager_stop(void * jarg1) {
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_sql_queue_manager_stop(void * jarg1) {
   int jresult ;
   switch_sql_queue_manager_t *arg1 = (switch_sql_queue_manager_t *) 0 ;
   switch_status_t result;
   
   arg1 = (switch_sql_queue_manager_t *)jarg1; 
-  result = (switch_status_t)switch_switch_sql_queue_manager_stop(arg1);
+  result = (switch_status_t)switch_sql_queue_manager_stop(arg1);
   jresult = result; 
   return jresult;
 }
@@ -23190,6 +23388,28 @@ SWIGEXPORT void * SWIGSTDCALL CSharp_switch_codec_session_get(void * jarg1) {
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_codec_cur_frame_set(void * jarg1, void * jarg2) {
+  switch_codec *arg1 = (switch_codec *) 0 ;
+  switch_frame_t *arg2 = (switch_frame_t *) 0 ;
+  
+  arg1 = (switch_codec *)jarg1; 
+  arg2 = (switch_frame_t *)jarg2; 
+  if (arg1) (arg1)->cur_frame = arg2;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_codec_cur_frame_get(void * jarg1) {
+  void * jresult ;
+  switch_codec *arg1 = (switch_codec *) 0 ;
+  switch_frame_t *result = 0 ;
+  
+  arg1 = (switch_codec *)jarg1; 
+  result = (switch_frame_t *) ((arg1)->cur_frame);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void * SWIGSTDCALL CSharp_new_switch_codec() {
   void * jresult ;
   switch_codec *result = 0 ;
@@ -31260,6 +31480,18 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_ivr_uuid_exists(char * jarg1) {
 }
 
 
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_ivr_uuid_force_exists(char * jarg1) {
+  int jresult ;
+  char *arg1 = (char *) 0 ;
+  switch_bool_t result;
+  
+  arg1 = (char *)jarg1; 
+  result = (switch_bool_t)switch_ivr_uuid_force_exists((char const *)arg1);
+  jresult = result; 
+  return jresult;
+}
+
+
 SWIGEXPORT int SWIGSTDCALL CSharp_switch_ivr_dmachine_last_ping(void * jarg1) {
   int jresult ;
   switch_ivr_dmachine_t *arg1 = (switch_ivr_dmachine_t *) 0 ;
@@ -34201,15 +34433,17 @@ SWIGEXPORT unsigned long SWIGSTDCALL CSharp_switch_xml_parse_section_string(char
 }
 
 
-SWIGEXPORT int SWIGSTDCALL CSharp_switch_xml_std_datetime_check(void * jarg1, void * jarg2) {
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_xml_std_datetime_check(void * jarg1, void * jarg2, char * jarg3) {
   int jresult ;
   switch_xml_t arg1 = (switch_xml_t) 0 ;
   int *arg2 = (int *) 0 ;
+  char *arg3 = (char *) 0 ;
   int result;
   
   arg1 = (switch_xml_t)jarg1; 
   arg2 = (int *)jarg2; 
-  result = (int)switch_xml_std_datetime_check(arg1,arg2);
+  arg3 = (char *)jarg3; 
+  result = (int)switch_xml_std_datetime_check(arg1,arg2,(char const *)arg3);
   jresult = result; 
   return jresult;
 }
diff --git a/src/mod/languages/mod_managed/freeswitch_wrap.cxx b/src/mod/languages/mod_managed/freeswitch_wrap.cxx
index bab4805383..a1fed17362 100644
--- a/src/mod/languages/mod_managed/freeswitch_wrap.cxx
+++ b/src/mod/languages/mod_managed/freeswitch_wrap.cxx
@@ -926,6 +926,17 @@ SWIGEXPORT char * SWIGSTDCALL CSharp_SWITCH_DEFAULT_CLID_NAME_get() {
 }
 
 
+SWIGEXPORT char * SWIGSTDCALL CSharp_SWITCH_DEFAULT_CLID_NUMBER_get() {
+  char * jresult ;
+  char *result = 0 ;
+  
+  result = (char *) "0000000000";
+  
+  jresult = SWIG_csharp_string_callback((const char *)result); 
+  return jresult;
+}
+
+
 SWIGEXPORT int SWIGSTDCALL CSharp_SWITCH_DEFAULT_DTMF_DURATION_get() {
   int jresult ;
   int result;
@@ -1421,6 +1432,17 @@ SWIGEXPORT char * SWIGSTDCALL CSharp_SWITCH_PROCESS_CDR_VARIABLE_get() {
 }
 
 
+SWIGEXPORT char * SWIGSTDCALL CSharp_SWITCH_SKIP_CDR_CAUSES_VARIABLE_get() {
+  char * jresult ;
+  char *result = 0 ;
+  
+  result = (char *) "skip_cdr_causes";
+  
+  jresult = SWIG_csharp_string_callback((const char *)result); 
+  return jresult;
+}
+
+
 SWIGEXPORT char * SWIGSTDCALL CSharp_SWITCH_FORCE_PROCESS_CDR_VARIABLE_get() {
   char * jresult ;
   char *result = 0 ;
@@ -6191,6 +6213,230 @@ SWIGEXPORT void SWIGSTDCALL CSharp_delete_switch_app_log(void * jarg1) {
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_hold_record_t_on_set(void * jarg1, void * jarg2) {
+  switch_hold_record_t *arg1 = (switch_hold_record_t *) 0 ;
+  switch_time_t arg2 ;
+  switch_time_t *argp2 ;
+  
+  arg1 = (switch_hold_record_t *)jarg1; 
+  argp2 = (switch_time_t *)jarg2; 
+  if (!argp2) {
+    SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null switch_time_t", 0);
+    return ;
+  }
+  arg2 = *argp2; 
+  if (arg1) (arg1)->on = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_hold_record_t_on_get(void * jarg1) {
+  void * jresult ;
+  switch_hold_record_t *arg1 = (switch_hold_record_t *) 0 ;
+  switch_time_t result;
+  
+  arg1 = (switch_hold_record_t *)jarg1; 
+  result =  ((arg1)->on);
+  jresult = new switch_time_t((switch_time_t &)result); 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_hold_record_t_off_set(void * jarg1, void * jarg2) {
+  switch_hold_record_t *arg1 = (switch_hold_record_t *) 0 ;
+  switch_time_t arg2 ;
+  switch_time_t *argp2 ;
+  
+  arg1 = (switch_hold_record_t *)jarg1; 
+  argp2 = (switch_time_t *)jarg2; 
+  if (!argp2) {
+    SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null switch_time_t", 0);
+    return ;
+  }
+  arg2 = *argp2; 
+  if (arg1) (arg1)->off = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_hold_record_t_off_get(void * jarg1) {
+  void * jresult ;
+  switch_hold_record_t *arg1 = (switch_hold_record_t *) 0 ;
+  switch_time_t result;
+  
+  arg1 = (switch_hold_record_t *)jarg1; 
+  result =  ((arg1)->off);
+  jresult = new switch_time_t((switch_time_t &)result); 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_hold_record_t_uuid_set(void * jarg1, char * jarg2) {
+  switch_hold_record_t *arg1 = (switch_hold_record_t *) 0 ;
+  char *arg2 = (char *) 0 ;
+  
+  arg1 = (switch_hold_record_t *)jarg1; 
+  arg2 = (char *)jarg2; 
+  {
+    if (arg1->uuid) delete [] arg1->uuid;
+    if (arg2) {
+      arg1->uuid = (char *) (new char[strlen((const char *)arg2)+1]);
+      strcpy((char *)arg1->uuid, (const char *)arg2);
+    } else {
+      arg1->uuid = 0;
+    }
+  }
+}
+
+
+SWIGEXPORT char * SWIGSTDCALL CSharp_switch_hold_record_t_uuid_get(void * jarg1) {
+  char * jresult ;
+  switch_hold_record_t *arg1 = (switch_hold_record_t *) 0 ;
+  char *result = 0 ;
+  
+  arg1 = (switch_hold_record_t *)jarg1; 
+  result = (char *) ((arg1)->uuid);
+  jresult = SWIG_csharp_string_callback((const char *)result); 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_hold_record_t_next_set(void * jarg1, void * jarg2) {
+  switch_hold_record_t *arg1 = (switch_hold_record_t *) 0 ;
+  switch_hold_record_s *arg2 = (switch_hold_record_s *) 0 ;
+  
+  arg1 = (switch_hold_record_t *)jarg1; 
+  arg2 = (switch_hold_record_s *)jarg2; 
+  if (arg1) (arg1)->next = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_hold_record_t_next_get(void * jarg1) {
+  void * jresult ;
+  switch_hold_record_t *arg1 = (switch_hold_record_t *) 0 ;
+  switch_hold_record_s *result = 0 ;
+  
+  arg1 = (switch_hold_record_t *)jarg1; 
+  result = (switch_hold_record_s *) ((arg1)->next);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_new_switch_hold_record_t() {
+  void * jresult ;
+  switch_hold_record_t *result = 0 ;
+  
+  result = (switch_hold_record_t *)new switch_hold_record_t();
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_delete_switch_hold_record_t(void * jarg1) {
+  switch_hold_record_t *arg1 = (switch_hold_record_t *) 0 ;
+  
+  arg1 = (switch_hold_record_t *)jarg1; 
+  delete arg1;
+  
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_thread_data_t_func_set(void * jarg1, void * jarg2) {
+  switch_thread_data_t *arg1 = (switch_thread_data_t *) 0 ;
+  switch_thread_start_t arg2 ;
+  switch_thread_start_t *argp2 ;
+  
+  arg1 = (switch_thread_data_t *)jarg1; 
+  argp2 = (switch_thread_start_t *)jarg2; 
+  if (!argp2) {
+    SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null switch_thread_start_t", 0);
+    return ;
+  }
+  arg2 = *argp2; 
+  if (arg1) (arg1)->func = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_thread_data_t_func_get(void * jarg1) {
+  void * jresult ;
+  switch_thread_data_t *arg1 = (switch_thread_data_t *) 0 ;
+  switch_thread_start_t result;
+  
+  arg1 = (switch_thread_data_t *)jarg1; 
+  result =  ((arg1)->func);
+  jresult = new switch_thread_start_t((switch_thread_start_t &)result); 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_thread_data_t_obj_set(void * jarg1, void * jarg2) {
+  switch_thread_data_t *arg1 = (switch_thread_data_t *) 0 ;
+  void *arg2 = (void *) 0 ;
+  
+  arg1 = (switch_thread_data_t *)jarg1; 
+  arg2 = (void *)jarg2; 
+  if (arg1) (arg1)->obj = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_thread_data_t_obj_get(void * jarg1) {
+  void * jresult ;
+  switch_thread_data_t *arg1 = (switch_thread_data_t *) 0 ;
+  void *result = 0 ;
+  
+  arg1 = (switch_thread_data_t *)jarg1; 
+  result = (void *) ((arg1)->obj);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_thread_data_t_alloc_set(void * jarg1, int jarg2) {
+  switch_thread_data_t *arg1 = (switch_thread_data_t *) 0 ;
+  int arg2 ;
+  
+  arg1 = (switch_thread_data_t *)jarg1; 
+  arg2 = (int)jarg2; 
+  if (arg1) (arg1)->alloc = arg2;
+  
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_thread_data_t_alloc_get(void * jarg1) {
+  int jresult ;
+  switch_thread_data_t *arg1 = (switch_thread_data_t *) 0 ;
+  int result;
+  
+  arg1 = (switch_thread_data_t *)jarg1; 
+  result = (int) ((arg1)->alloc);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_new_switch_thread_data_t() {
+  void * jresult ;
+  switch_thread_data_t *result = 0 ;
+  
+  result = (switch_thread_data_t *)new switch_thread_data_t();
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_delete_switch_thread_data_t(void * jarg1) {
+  switch_thread_data_t *arg1 = (switch_thread_data_t *) 0 ;
+  
+  arg1 = (switch_thread_data_t *)jarg1; 
+  delete arg1;
+  
+}
+
+
 SWIGEXPORT int SWIGSTDCALL CSharp_MESSAGE_STRING_ARG_MAX_get() {
   int jresult ;
   int result;
@@ -6837,6 +7083,16 @@ SWIGEXPORT void SWIGSTDCALL CSharp_delete_switch_core_thread_session(void * jarg
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_core_screen_size(void * jarg1, void * jarg2) {
+  int *arg1 = (int *) 0 ;
+  int *arg2 = (int *) 0 ;
+  
+  arg1 = (int *)jarg1; 
+  arg2 = (int *)jarg2; 
+  switch_core_screen_size(arg1,arg2);
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_core_session_sched_heartbeat(void * jarg1, unsigned long jarg2) {
   switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
   uint32_t arg2 ;
@@ -7945,6 +8201,18 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_session_thread_launch(void * jarg1
 }
 
 
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_thread_pool_launch_thread(void * jarg1) {
+  int jresult ;
+  switch_thread_data_t **arg1 = (switch_thread_data_t **) 0 ;
+  switch_status_t result;
+  
+  arg1 = (switch_thread_data_t **)jarg1; 
+  result = (switch_status_t)switch_thread_pool_launch_thread(arg1);
+  jresult = result; 
+  return jresult;
+}
+
+
 SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_session_thread_pool_launch(void * jarg1) {
   int jresult ;
   switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
@@ -8027,6 +8295,20 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_session_get_loglevel(void * jarg1)
 }
 
 
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_core_session_get_jb(void * jarg1, int jarg2) {
+  void * jresult ;
+  switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
+  switch_media_type_t arg2 ;
+  stfu_instance_t *result = 0 ;
+  
+  arg1 = (switch_core_session_t *)jarg1; 
+  arg2 = (switch_media_type_t)jarg2; 
+  result = (stfu_instance_t *)switch_core_session_get_jb(arg1,arg2);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_core_session_soft_lock(void * jarg1, unsigned long jarg2) {
   switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
   uint32_t arg2 ;
@@ -8265,6 +8547,20 @@ SWIGEXPORT void SWIGSTDCALL CSharp_switch_core_session_hupall_matching_var(char
 }
 
 
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_core_session_findall_matching_var(char * jarg1, char * jarg2) {
+  void * jresult ;
+  char *arg1 = (char *) 0 ;
+  char *arg2 = (char *) 0 ;
+  switch_console_callback_match_t *result = 0 ;
+  
+  arg1 = (char *)jarg1; 
+  arg2 = (char *)jarg2; 
+  result = (switch_console_callback_match_t *)switch_core_session_findall_matching_var((char const *)arg1,(char const *)arg2);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_core_session_hupall_endpoint(void * jarg1, int jarg2) {
   switch_endpoint_interface_t *arg1 = (switch_endpoint_interface_t *) 0 ;
   switch_call_cause_t arg2 ;
@@ -9177,6 +9473,44 @@ SWIGEXPORT void * SWIGSTDCALL CSharp_switch_core_hash_find_rdlock(void * jarg1,
 }
 
 
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_core_hash_first(void * jarg1) {
+  void * jresult ;
+  switch_hash_t *arg1 = (switch_hash_t *) 0 ;
+  switch_hash_index_t *result = 0 ;
+  
+  arg1 = (switch_hash_t *)jarg1; 
+  result = (switch_hash_index_t *)switch_core_hash_first(arg1);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_core_hash_next(void * jarg1) {
+  void * jresult ;
+  switch_hash_index_t *arg1 = (switch_hash_index_t *) 0 ;
+  switch_hash_index_t *result = 0 ;
+  
+  arg1 = (switch_hash_index_t *)jarg1; 
+  result = (switch_hash_index_t *)switch_core_hash_next(arg1);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_core_hash_this(void * jarg1, void * jarg2, void * jarg3, void * jarg4) {
+  switch_hash_index_t *arg1 = (switch_hash_index_t *) 0 ;
+  void **arg2 = (void **) 0 ;
+  switch_ssize_t *arg3 = (switch_ssize_t *) 0 ;
+  void **arg4 = (void **) 0 ;
+  
+  arg1 = (switch_hash_index_t *)jarg1; 
+  arg2 = (void **)jarg2; 
+  arg3 = (switch_ssize_t *)jarg3; 
+  arg4 = (void **)jarg4; 
+  switch_core_hash_this(arg1,(void const **)arg2,arg3,arg4);
+}
+
+
 SWIGEXPORT void * SWIGSTDCALL CSharp_switch_hash_first(char * jarg1, void * jarg2) {
   void * jresult ;
   char *arg1 = (char *) 0 ;
@@ -11123,6 +11457,29 @@ SWIGEXPORT void * SWIGSTDCALL CSharp_switch_cache_db_native_handle_t_odbc_dbh_ge
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_cache_db_native_handle_t_pgsql_dbh_set(void * jarg1, void * jarg2) {
+  switch_cache_db_native_handle_t *arg1 = (switch_cache_db_native_handle_t *) 0 ;
+  switch_pgsql_handle_t *arg2 = (switch_pgsql_handle_t *) 0 ;
+  
+  arg1 = (switch_cache_db_native_handle_t *)jarg1; 
+  arg2 = (switch_pgsql_handle_t *)jarg2; 
+  if (arg1) (arg1)->pgsql_dbh = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_cache_db_native_handle_t_pgsql_dbh_get(void * jarg1) {
+  void * jresult ;
+  switch_cache_db_native_handle_t *arg1 = (switch_cache_db_native_handle_t *) 0 ;
+  switch_pgsql_handle_t *result = 0 ;
+  
+  arg1 = (switch_cache_db_native_handle_t *)jarg1; 
+  result = (switch_pgsql_handle_t *) ((arg1)->pgsql_dbh);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void * SWIGSTDCALL CSharp_new_switch_cache_db_native_handle_t() {
   void * jresult ;
   switch_cache_db_native_handle_t *result = 0 ;
@@ -11300,6 +11657,55 @@ SWIGEXPORT void SWIGSTDCALL CSharp_delete_switch_cache_db_odbc_options_t(void *
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_cache_db_pgsql_options_t_dsn_set(void * jarg1, char * jarg2) {
+  switch_cache_db_pgsql_options_t *arg1 = (switch_cache_db_pgsql_options_t *) 0 ;
+  char *arg2 = (char *) 0 ;
+  
+  arg1 = (switch_cache_db_pgsql_options_t *)jarg1; 
+  arg2 = (char *)jarg2; 
+  {
+    if (arg1->dsn) delete [] arg1->dsn;
+    if (arg2) {
+      arg1->dsn = (char *) (new char[strlen((const char *)arg2)+1]);
+      strcpy((char *)arg1->dsn, (const char *)arg2);
+    } else {
+      arg1->dsn = 0;
+    }
+  }
+}
+
+
+SWIGEXPORT char * SWIGSTDCALL CSharp_switch_cache_db_pgsql_options_t_dsn_get(void * jarg1) {
+  char * jresult ;
+  switch_cache_db_pgsql_options_t *arg1 = (switch_cache_db_pgsql_options_t *) 0 ;
+  char *result = 0 ;
+  
+  arg1 = (switch_cache_db_pgsql_options_t *)jarg1; 
+  result = (char *) ((arg1)->dsn);
+  jresult = SWIG_csharp_string_callback((const char *)result); 
+  return jresult;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_new_switch_cache_db_pgsql_options_t() {
+  void * jresult ;
+  switch_cache_db_pgsql_options_t *result = 0 ;
+  
+  result = (switch_cache_db_pgsql_options_t *)new switch_cache_db_pgsql_options_t();
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_delete_switch_cache_db_pgsql_options_t(void * jarg1) {
+  switch_cache_db_pgsql_options_t *arg1 = (switch_cache_db_pgsql_options_t *) 0 ;
+  
+  arg1 = (switch_cache_db_pgsql_options_t *)jarg1; 
+  delete arg1;
+  
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_cache_db_connection_options_t_core_db_options_set(void * jarg1, void * jarg2) {
   switch_cache_db_connection_options_t *arg1 = (switch_cache_db_connection_options_t *) 0 ;
   switch_cache_db_core_db_options_t *arg2 = (switch_cache_db_core_db_options_t *) 0 ;
@@ -11346,6 +11752,29 @@ SWIGEXPORT void * SWIGSTDCALL CSharp_switch_cache_db_connection_options_t_odbc_o
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_cache_db_connection_options_t_pgsql_options_set(void * jarg1, void * jarg2) {
+  switch_cache_db_connection_options_t *arg1 = (switch_cache_db_connection_options_t *) 0 ;
+  switch_cache_db_pgsql_options_t *arg2 = (switch_cache_db_pgsql_options_t *) 0 ;
+  
+  arg1 = (switch_cache_db_connection_options_t *)jarg1; 
+  arg2 = (switch_cache_db_pgsql_options_t *)jarg2; 
+  if (arg1) (arg1)->pgsql_options = *arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_cache_db_connection_options_t_pgsql_options_get(void * jarg1) {
+  void * jresult ;
+  switch_cache_db_connection_options_t *arg1 = (switch_cache_db_connection_options_t *) 0 ;
+  switch_cache_db_pgsql_options_t *result = 0 ;
+  
+  arg1 = (switch_cache_db_connection_options_t *)jarg1; 
+  result = (switch_cache_db_pgsql_options_t *)& ((arg1)->pgsql_options);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void * SWIGSTDCALL CSharp_new_switch_cache_db_connection_options_t() {
   void * jresult ;
   switch_cache_db_connection_options_t *result = 0 ;
@@ -11427,6 +11856,26 @@ SWIGEXPORT int SWIGSTDCALL CSharp__switch_cache_db_get_db_handle(void * jarg1, i
 }
 
 
+SWIGEXPORT int SWIGSTDCALL CSharp__switch_cache_db_get_db_handle_dsn(void * jarg1, char * jarg2, char * jarg3, char * jarg4, int jarg5) {
+  int jresult ;
+  switch_cache_db_handle_t **arg1 = (switch_cache_db_handle_t **) 0 ;
+  char *arg2 = (char *) 0 ;
+  char *arg3 = (char *) 0 ;
+  char *arg4 = (char *) 0 ;
+  int arg5 ;
+  switch_status_t result;
+  
+  arg1 = (switch_cache_db_handle_t **)jarg1; 
+  arg2 = (char *)jarg2; 
+  arg3 = (char *)jarg3; 
+  arg4 = (char *)jarg4; 
+  arg5 = (int)jarg5; 
+  result = (switch_status_t)_switch_cache_db_get_db_handle_dsn(arg1,(char const *)arg2,(char const *)arg3,(char const *)arg4,arg5);
+  jresult = result; 
+  return jresult;
+}
+
+
 SWIGEXPORT char * SWIGSTDCALL CSharp_switch_cache_db_execute_sql2str(void * jarg1, char * jarg2, char * jarg3, unsigned long jarg4, void * jarg5) {
   char * jresult ;
   switch_cache_db_handle_t *arg1 = (switch_cache_db_handle_t *) 0 ;
@@ -11521,24 +11970,6 @@ SWIGEXPORT int SWIGSTDCALL CSharp__switch_core_db_handle(void * jarg1, char * ja
 }
 
 
-SWIGEXPORT int SWIGSTDCALL CSharp__switch_core_recovery_db_handle(void * jarg1, char * jarg2, char * jarg3, int jarg4) {
-  int jresult ;
-  switch_cache_db_handle_t **arg1 = (switch_cache_db_handle_t **) 0 ;
-  char *arg2 = (char *) 0 ;
-  char *arg3 = (char *) 0 ;
-  int arg4 ;
-  switch_status_t result;
-  
-  arg1 = (switch_cache_db_handle_t **)jarg1; 
-  arg2 = (char *)jarg2; 
-  arg3 = (char *)jarg3; 
-  arg4 = (int)jarg4; 
-  result = (switch_status_t)_switch_core_recovery_db_handle(arg1,(char const *)arg2,(char const *)arg3,arg4);
-  jresult = result; 
-  return jresult;
-}
-
-
 SWIGEXPORT int SWIGSTDCALL CSharp_switch_cache_db_test_reactive(void * jarg1, char * jarg2, char * jarg3, char * jarg4) {
   int jresult ;
   switch_cache_db_handle_t *arg1 = (switch_cache_db_handle_t *) 0 ;
@@ -11573,17 +12004,25 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_cache_db_persistant_execute(void * jarg
 }
 
 
-SWIGEXPORT int SWIGSTDCALL CSharp_switch_cache_db_persistant_execute_trans(void * jarg1, char * jarg2, unsigned long jarg3) {
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_cache_db_persistant_execute_trans_full(void * jarg1, char * jarg2, unsigned long jarg3, char * jarg4, char * jarg5, char * jarg6, char * jarg7) {
   int jresult ;
   switch_cache_db_handle_t *arg1 = (switch_cache_db_handle_t *) 0 ;
   char *arg2 = (char *) 0 ;
   uint32_t arg3 ;
+  char *arg4 = (char *) 0 ;
+  char *arg5 = (char *) 0 ;
+  char *arg6 = (char *) 0 ;
+  char *arg7 = (char *) 0 ;
   switch_status_t result;
   
   arg1 = (switch_cache_db_handle_t *)jarg1; 
   arg2 = (char *)jarg2; 
   arg3 = (uint32_t)jarg3; 
-  result = (switch_status_t)switch_cache_db_persistant_execute_trans(arg1,arg2,arg3);
+  arg4 = (char *)jarg4; 
+  arg5 = (char *)jarg5; 
+  arg6 = (char *)jarg6; 
+  arg7 = (char *)jarg7; 
+  result = (switch_status_t)switch_cache_db_persistant_execute_trans_full(arg1,arg2,arg3,(char const *)arg4,(char const *)arg5,(char const *)arg6,(char const *)arg7);
   jresult = result; 
   return jresult;
 }
@@ -11825,6 +12264,24 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_get_stacksizes(void * jarg1, void
 }
 
 
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_dbtype() {
+  int jresult ;
+  switch_cache_db_handle_type_t result;
+  
+  result = (switch_cache_db_handle_type_t)switch_core_dbtype();
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_core_sql_exec(char * jarg1) {
+  char *arg1 = (char *) 0 ;
+  
+  arg1 = (char *)jarg1; 
+  switch_core_sql_exec((char const *)arg1);
+}
+
+
 SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_recovery_recover(char * jarg1, char * jarg2) {
   int jresult ;
   char *arg1 = (char *) 0 ;
@@ -11867,6 +12324,134 @@ SWIGEXPORT void SWIGSTDCALL CSharp_switch_core_recovery_flush(char * jarg1, char
 }
 
 
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_sql_queue_manager_push_confirm(void * jarg1, char * jarg2, unsigned long jarg3, int jarg4) {
+  int jresult ;
+  switch_sql_queue_manager_t *arg1 = (switch_sql_queue_manager_t *) 0 ;
+  char *arg2 = (char *) 0 ;
+  uint32_t arg3 ;
+  switch_bool_t arg4 ;
+  switch_status_t result;
+  
+  arg1 = (switch_sql_queue_manager_t *)jarg1; 
+  arg2 = (char *)jarg2; 
+  arg3 = (uint32_t)jarg3; 
+  arg4 = (switch_bool_t)jarg4; 
+  result = (switch_status_t)switch_sql_queue_manager_push_confirm(arg1,(char const *)arg2,arg3,arg4);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_sql_queue_manager_push(void * jarg1, char * jarg2, unsigned long jarg3, int jarg4) {
+  int jresult ;
+  switch_sql_queue_manager_t *arg1 = (switch_sql_queue_manager_t *) 0 ;
+  char *arg2 = (char *) 0 ;
+  uint32_t arg3 ;
+  switch_bool_t arg4 ;
+  switch_status_t result;
+  
+  arg1 = (switch_sql_queue_manager_t *)jarg1; 
+  arg2 = (char *)jarg2; 
+  arg3 = (uint32_t)jarg3; 
+  arg4 = (switch_bool_t)jarg4; 
+  result = (switch_status_t)switch_sql_queue_manager_push(arg1,(char const *)arg2,arg3,arg4);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_sql_queue_manager_destroy(void * jarg1) {
+  int jresult ;
+  switch_sql_queue_manager_t **arg1 = (switch_sql_queue_manager_t **) 0 ;
+  switch_status_t result;
+  
+  arg1 = (switch_sql_queue_manager_t **)jarg1; 
+  result = (switch_status_t)switch_sql_queue_manager_destroy(arg1);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_sql_queue_manager_init_name(char * jarg1, void * jarg2, unsigned long jarg3, char * jarg4, char * jarg5, char * jarg6, char * jarg7, char * jarg8) {
+  int jresult ;
+  char *arg1 = (char *) 0 ;
+  switch_sql_queue_manager_t **arg2 = (switch_sql_queue_manager_t **) 0 ;
+  uint32_t arg3 ;
+  char *arg4 = (char *) 0 ;
+  char *arg5 = (char *) 0 ;
+  char *arg6 = (char *) 0 ;
+  char *arg7 = (char *) 0 ;
+  char *arg8 = (char *) 0 ;
+  switch_status_t result;
+  
+  arg1 = (char *)jarg1; 
+  arg2 = (switch_sql_queue_manager_t **)jarg2; 
+  arg3 = (uint32_t)jarg3; 
+  arg4 = (char *)jarg4; 
+  arg5 = (char *)jarg5; 
+  arg6 = (char *)jarg6; 
+  arg7 = (char *)jarg7; 
+  arg8 = (char *)jarg8; 
+  result = (switch_status_t)switch_sql_queue_manager_init_name((char const *)arg1,arg2,arg3,(char const *)arg4,(char const *)arg5,(char const *)arg6,(char const *)arg7,(char const *)arg8);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_sql_queue_manager_start(void * jarg1) {
+  int jresult ;
+  switch_sql_queue_manager_t *arg1 = (switch_sql_queue_manager_t *) 0 ;
+  switch_status_t result;
+  
+  arg1 = (switch_sql_queue_manager_t *)jarg1; 
+  result = (switch_status_t)switch_sql_queue_manager_start(arg1);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_sql_queue_manager_stop(void * jarg1) {
+  int jresult ;
+  switch_sql_queue_manager_t *arg1 = (switch_sql_queue_manager_t *) 0 ;
+  switch_status_t result;
+  
+  arg1 = (switch_sql_queue_manager_t *)jarg1; 
+  result = (switch_status_t)switch_sql_queue_manager_stop(arg1);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_cache_db_execute_sql_event_callback(void * jarg1, char * jarg2, void * jarg3, void * jarg4, void * jarg5) {
+  int jresult ;
+  switch_cache_db_handle_t *arg1 = (switch_cache_db_handle_t *) 0 ;
+  char *arg2 = (char *) 0 ;
+  switch_db_event_callback_func_t arg3 = (switch_db_event_callback_func_t) 0 ;
+  void *arg4 = (void *) 0 ;
+  char **arg5 = (char **) 0 ;
+  switch_status_t result;
+  
+  arg1 = (switch_cache_db_handle_t *)jarg1; 
+  arg2 = (char *)jarg2; 
+  arg3 = (switch_db_event_callback_func_t)jarg3; 
+  arg4 = (void *)jarg4; 
+  arg5 = (char **)jarg5; 
+  result = (switch_status_t)switch_cache_db_execute_sql_event_callback(arg1,(char const *)arg2,arg3,arg4,arg5);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_fork() {
+  void * jresult ;
+  pid_t result;
+  
+  result = switch_fork();
+  jresult = new pid_t((pid_t &)result); 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_loadable_module_interface_module_name_set(void * jarg1, char * jarg2) {
   switch_loadable_module_interface *arg1 = (switch_loadable_module_interface *) 0 ;
   char *arg2 = (char *) 0 ;
@@ -13466,6 +14051,38 @@ SWIGEXPORT void * SWIGSTDCALL CSharp_switch_fd_read_line(int jarg1, char * jarg2
 }
 
 
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_fd_read_dline(int jarg1, void * jarg2, void * jarg3) {
+  void * jresult ;
+  int arg1 ;
+  char **arg2 = (char **) 0 ;
+  switch_size_t *arg3 = (switch_size_t *) 0 ;
+  switch_size_t result;
+  
+  arg1 = (int)jarg1; 
+  arg2 = (char **)jarg2; 
+  arg3 = (switch_size_t *)jarg3; 
+  result = switch_fd_read_dline(arg1,arg2,arg3);
+  jresult = new switch_size_t((switch_size_t &)result); 
+  return jresult;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_fp_read_dline(void * jarg1, void * jarg2, void * jarg3) {
+  void * jresult ;
+  FILE *arg1 = (FILE *) 0 ;
+  char **arg2 = (char **) 0 ;
+  switch_size_t *arg3 = (switch_size_t *) 0 ;
+  switch_size_t result;
+  
+  arg1 = (FILE *)jarg1; 
+  arg2 = (char **)jarg2; 
+  arg3 = (switch_size_t *)jarg3; 
+  result = switch_fp_read_dline(arg1,arg2,arg3);
+  jresult = new switch_size_t((switch_size_t &)result); 
+  return jresult;
+}
+
+
 SWIGEXPORT int SWIGSTDCALL CSharp_switch_frame_alloc(void * jarg1, void * jarg2) {
   int jresult ;
   switch_frame_t **arg1 = (switch_frame_t **) 0 ;
@@ -15497,6 +16114,29 @@ SWIGEXPORT void * SWIGSTDCALL CSharp_switch_caller_profile_times_get(void * jarg
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_caller_profile_old_times_set(void * jarg1, void * jarg2) {
+  switch_caller_profile *arg1 = (switch_caller_profile *) 0 ;
+  switch_channel_timetable *arg2 = (switch_channel_timetable *) 0 ;
+  
+  arg1 = (switch_caller_profile *)jarg1; 
+  arg2 = (switch_channel_timetable *)jarg2; 
+  if (arg1) (arg1)->old_times = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_caller_profile_old_times_get(void * jarg1) {
+  void * jresult ;
+  switch_caller_profile *arg1 = (switch_caller_profile *) 0 ;
+  switch_channel_timetable *result = 0 ;
+  
+  arg1 = (switch_caller_profile *)jarg1; 
+  result = (switch_channel_timetable *) ((arg1)->old_times);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_caller_profile_caller_extension_set(void * jarg1, void * jarg2) {
   switch_caller_profile *arg1 = (switch_caller_profile *) 0 ;
   switch_caller_extension *arg2 = (switch_caller_extension *) 0 ;
@@ -16569,6 +17209,29 @@ SWIGEXPORT unsigned long SWIGSTDCALL CSharp_switch_frame_flags_get(void * jarg1)
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_frame_user_data_set(void * jarg1, void * jarg2) {
+  switch_frame *arg1 = (switch_frame *) 0 ;
+  void *arg2 = (void *) 0 ;
+  
+  arg1 = (switch_frame *)jarg1; 
+  arg2 = (void *)jarg2; 
+  if (arg1) (arg1)->user_data = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_frame_user_data_get(void * jarg1) {
+  void * jresult ;
+  switch_frame *arg1 = (switch_frame *) 0 ;
+  void *result = 0 ;
+  
+  arg1 = (switch_frame *)jarg1; 
+  result = (void *) ((arg1)->user_data);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void * SWIGSTDCALL CSharp_new_switch_frame() {
   void * jresult ;
   switch_frame *result = 0 ;
@@ -17435,6 +18098,29 @@ SWIGEXPORT void * SWIGSTDCALL CSharp_switch_io_routines_state_run_get(void * jar
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_io_routines_get_jb_set(void * jarg1, void * jarg2) {
+  switch_io_routines *arg1 = (switch_io_routines *) 0 ;
+  switch_io_get_jb_t arg2 = (switch_io_get_jb_t) 0 ;
+  
+  arg1 = (switch_io_routines *)jarg1; 
+  arg2 = (switch_io_get_jb_t)jarg2; 
+  if (arg1) (arg1)->get_jb = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_io_routines_get_jb_get(void * jarg1) {
+  void * jresult ;
+  switch_io_routines *arg1 = (switch_io_routines *) 0 ;
+  switch_io_get_jb_t result;
+  
+  arg1 = (switch_io_routines *)jarg1; 
+  result = (switch_io_get_jb_t) ((arg1)->get_jb);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_io_routines_padding_set(void * jarg1, void * jarg2) {
   switch_io_routines *arg1 = (switch_io_routines *) 0 ;
   void **arg2 ;
@@ -20627,6 +21313,150 @@ SWIGEXPORT void * SWIGSTDCALL CSharp_switch_asr_handle_memory_pool_get(void * ja
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_asr_handle_buffer_set(void * jarg1, void * jarg2) {
+  switch_asr_handle *arg1 = (switch_asr_handle *) 0 ;
+  switch_buffer_t *arg2 = (switch_buffer_t *) 0 ;
+  
+  arg1 = (switch_asr_handle *)jarg1; 
+  arg2 = (switch_buffer_t *)jarg2; 
+  if (arg1) (arg1)->buffer = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_asr_handle_buffer_get(void * jarg1) {
+  void * jresult ;
+  switch_asr_handle *arg1 = (switch_asr_handle *) 0 ;
+  switch_buffer_t *result = 0 ;
+  
+  arg1 = (switch_asr_handle *)jarg1; 
+  result = (switch_buffer_t *) ((arg1)->buffer);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_asr_handle_dbuf_set(void * jarg1, void * jarg2) {
+  switch_asr_handle *arg1 = (switch_asr_handle *) 0 ;
+  switch_byte_t *arg2 = (switch_byte_t *) 0 ;
+  
+  arg1 = (switch_asr_handle *)jarg1; 
+  arg2 = (switch_byte_t *)jarg2; 
+  if (arg1) (arg1)->dbuf = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_asr_handle_dbuf_get(void * jarg1) {
+  void * jresult ;
+  switch_asr_handle *arg1 = (switch_asr_handle *) 0 ;
+  switch_byte_t *result = 0 ;
+  
+  arg1 = (switch_asr_handle *)jarg1; 
+  result = (switch_byte_t *) ((arg1)->dbuf);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_asr_handle_dbuflen_set(void * jarg1, void * jarg2) {
+  switch_asr_handle *arg1 = (switch_asr_handle *) 0 ;
+  switch_size_t arg2 ;
+  switch_size_t *argp2 ;
+  
+  arg1 = (switch_asr_handle *)jarg1; 
+  argp2 = (switch_size_t *)jarg2; 
+  if (!argp2) {
+    SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null switch_size_t", 0);
+    return ;
+  }
+  arg2 = *argp2; 
+  if (arg1) (arg1)->dbuflen = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_asr_handle_dbuflen_get(void * jarg1) {
+  void * jresult ;
+  switch_asr_handle *arg1 = (switch_asr_handle *) 0 ;
+  switch_size_t result;
+  
+  arg1 = (switch_asr_handle *)jarg1; 
+  result =  ((arg1)->dbuflen);
+  jresult = new switch_size_t((switch_size_t &)result); 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_asr_handle_resampler_set(void * jarg1, void * jarg2) {
+  switch_asr_handle *arg1 = (switch_asr_handle *) 0 ;
+  switch_audio_resampler_t *arg2 = (switch_audio_resampler_t *) 0 ;
+  
+  arg1 = (switch_asr_handle *)jarg1; 
+  arg2 = (switch_audio_resampler_t *)jarg2; 
+  if (arg1) (arg1)->resampler = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_asr_handle_resampler_get(void * jarg1) {
+  void * jresult ;
+  switch_asr_handle *arg1 = (switch_asr_handle *) 0 ;
+  switch_audio_resampler_t *result = 0 ;
+  
+  arg1 = (switch_asr_handle *)jarg1; 
+  result = (switch_audio_resampler_t *) ((arg1)->resampler);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_asr_handle_samplerate_set(void * jarg1, unsigned long jarg2) {
+  switch_asr_handle *arg1 = (switch_asr_handle *) 0 ;
+  uint32_t arg2 ;
+  
+  arg1 = (switch_asr_handle *)jarg1; 
+  arg2 = (uint32_t)jarg2; 
+  if (arg1) (arg1)->samplerate = arg2;
+  
+}
+
+
+SWIGEXPORT unsigned long SWIGSTDCALL CSharp_switch_asr_handle_samplerate_get(void * jarg1) {
+  unsigned long jresult ;
+  switch_asr_handle *arg1 = (switch_asr_handle *) 0 ;
+  uint32_t result;
+  
+  arg1 = (switch_asr_handle *)jarg1; 
+  result = (uint32_t) ((arg1)->samplerate);
+  jresult = (unsigned long)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_asr_handle_native_rate_set(void * jarg1, unsigned long jarg2) {
+  switch_asr_handle *arg1 = (switch_asr_handle *) 0 ;
+  uint32_t arg2 ;
+  
+  arg1 = (switch_asr_handle *)jarg1; 
+  arg2 = (uint32_t)jarg2; 
+  if (arg1) (arg1)->native_rate = arg2;
+  
+}
+
+
+SWIGEXPORT unsigned long SWIGSTDCALL CSharp_switch_asr_handle_native_rate_get(void * jarg1) {
+  unsigned long jresult ;
+  switch_asr_handle *arg1 = (switch_asr_handle *) 0 ;
+  uint32_t result;
+  
+  arg1 = (switch_asr_handle *)jarg1; 
+  result = (uint32_t) ((arg1)->native_rate);
+  jresult = (unsigned long)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_asr_handle_private_info_set(void * jarg1, void * jarg2) {
   switch_asr_handle *arg1 = (switch_asr_handle *) 0 ;
   void *arg2 = (void *) 0 ;
@@ -23123,6 +23953,29 @@ SWIGEXPORT void * SWIGSTDCALL CSharp_switch_codec_next_get(void * jarg1) {
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_codec_session_set(void * jarg1, void * jarg2) {
+  switch_codec *arg1 = (switch_codec *) 0 ;
+  switch_core_session_t *arg2 = (switch_core_session_t *) 0 ;
+  
+  arg1 = (switch_codec *)jarg1; 
+  arg2 = (switch_core_session_t *)jarg2; 
+  if (arg1) (arg1)->session = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_codec_session_get(void * jarg1) {
+  void * jresult ;
+  switch_codec *arg1 = (switch_codec *) 0 ;
+  switch_core_session_t *result = 0 ;
+  
+  arg1 = (switch_codec *)jarg1; 
+  result = (switch_core_session_t *) ((arg1)->session);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void * SWIGSTDCALL CSharp_new_switch_codec() {
   void * jresult ;
   switch_codec *result = 0 ;
@@ -26745,10 +27598,10 @@ SWIGEXPORT char * SWIGSTDCALL CSharp_switch_channel_callstate2str(int jarg1) {
 SWIGEXPORT int SWIGSTDCALL CSharp_switch_channel_str2callstate(char * jarg1) {
   int jresult ;
   char *arg1 = (char *) 0 ;
-  switch_call_cause_t result;
+  switch_channel_callstate_t result;
   
   arg1 = (char *)jarg1; 
-  result = (switch_call_cause_t)switch_channel_str2callstate((char const *)arg1);
+  result = (switch_channel_callstate_t)switch_channel_str2callstate((char const *)arg1);
   jresult = result; 
   return jresult;
 }
@@ -26826,6 +27679,18 @@ SWIGEXPORT char * SWIGSTDCALL CSharp_switch_channel_get_partner_uuid(void * jarg
 }
 
 
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_channel_get_hold_record(void * jarg1) {
+  void * jresult ;
+  switch_channel_t *arg1 = (switch_channel_t *) 0 ;
+  switch_hold_record_t *result = 0 ;
+  
+  arg1 = (switch_channel_t *)jarg1; 
+  result = (switch_hold_record_t *)switch_channel_get_hold_record(arg1);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT int SWIGSTDCALL CSharp_switch_buffer_create(void * jarg1, void * jarg2, void * jarg3) {
   int jresult ;
   switch_memory_pool_t *arg1 = (switch_memory_pool_t *) 0 ;
@@ -27637,6 +28502,263 @@ SWIGEXPORT void SWIGSTDCALL CSharp_delete_switch_event(void * jarg1) {
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_serial_event_t_event_id_set(void * jarg1, int jarg2) {
+  switch_serial_event_t *arg1 = (switch_serial_event_t *) 0 ;
+  int arg2 ;
+  
+  arg1 = (switch_serial_event_t *)jarg1; 
+  arg2 = (int)jarg2; 
+  if (arg1) (arg1)->event_id = arg2;
+  
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_serial_event_t_event_id_get(void * jarg1) {
+  int jresult ;
+  switch_serial_event_t *arg1 = (switch_serial_event_t *) 0 ;
+  int result;
+  
+  arg1 = (switch_serial_event_t *)jarg1; 
+  result = (int) ((arg1)->event_id);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_serial_event_t_priority_set(void * jarg1, int jarg2) {
+  switch_serial_event_t *arg1 = (switch_serial_event_t *) 0 ;
+  int arg2 ;
+  
+  arg1 = (switch_serial_event_t *)jarg1; 
+  arg2 = (int)jarg2; 
+  if (arg1) (arg1)->priority = arg2;
+  
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_serial_event_t_priority_get(void * jarg1) {
+  int jresult ;
+  switch_serial_event_t *arg1 = (switch_serial_event_t *) 0 ;
+  int result;
+  
+  arg1 = (switch_serial_event_t *)jarg1; 
+  result = (int) ((arg1)->priority);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_serial_event_t_flags_set(void * jarg1, int jarg2) {
+  switch_serial_event_t *arg1 = (switch_serial_event_t *) 0 ;
+  int arg2 ;
+  
+  arg1 = (switch_serial_event_t *)jarg1; 
+  arg2 = (int)jarg2; 
+  if (arg1) (arg1)->flags = arg2;
+  
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_serial_event_t_flags_get(void * jarg1) {
+  int jresult ;
+  switch_serial_event_t *arg1 = (switch_serial_event_t *) 0 ;
+  int result;
+  
+  arg1 = (switch_serial_event_t *)jarg1; 
+  result = (int) ((arg1)->flags);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_serial_event_t_owner_set(void * jarg1, char * jarg2) {
+  switch_serial_event_t *arg1 = (switch_serial_event_t *) 0 ;
+  char *arg2 = (char *) 0 ;
+  
+  arg1 = (switch_serial_event_t *)jarg1; 
+  arg2 = (char *)jarg2; 
+  {
+    if (arg1->owner) delete [] arg1->owner;
+    if (arg2) {
+      arg1->owner = (char *) (new char[strlen((const char *)arg2)+1]);
+      strcpy((char *)arg1->owner, (const char *)arg2);
+    } else {
+      arg1->owner = 0;
+    }
+  }
+}
+
+
+SWIGEXPORT char * SWIGSTDCALL CSharp_switch_serial_event_t_owner_get(void * jarg1) {
+  char * jresult ;
+  switch_serial_event_t *arg1 = (switch_serial_event_t *) 0 ;
+  char *result = 0 ;
+  
+  arg1 = (switch_serial_event_t *)jarg1; 
+  result = (char *) ((arg1)->owner);
+  jresult = SWIG_csharp_string_callback((const char *)result); 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_serial_event_t_subclass_name_set(void * jarg1, char * jarg2) {
+  switch_serial_event_t *arg1 = (switch_serial_event_t *) 0 ;
+  char *arg2 = (char *) 0 ;
+  
+  arg1 = (switch_serial_event_t *)jarg1; 
+  arg2 = (char *)jarg2; 
+  {
+    if (arg1->subclass_name) delete [] arg1->subclass_name;
+    if (arg2) {
+      arg1->subclass_name = (char *) (new char[strlen((const char *)arg2)+1]);
+      strcpy((char *)arg1->subclass_name, (const char *)arg2);
+    } else {
+      arg1->subclass_name = 0;
+    }
+  }
+}
+
+
+SWIGEXPORT char * SWIGSTDCALL CSharp_switch_serial_event_t_subclass_name_get(void * jarg1) {
+  char * jresult ;
+  switch_serial_event_t *arg1 = (switch_serial_event_t *) 0 ;
+  char *result = 0 ;
+  
+  arg1 = (switch_serial_event_t *)jarg1; 
+  result = (char *) ((arg1)->subclass_name);
+  jresult = SWIG_csharp_string_callback((const char *)result); 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_serial_event_t_body_set(void * jarg1, char * jarg2) {
+  switch_serial_event_t *arg1 = (switch_serial_event_t *) 0 ;
+  char *arg2 = (char *) 0 ;
+  
+  arg1 = (switch_serial_event_t *)jarg1; 
+  arg2 = (char *)jarg2; 
+  {
+    if (arg1->body) delete [] arg1->body;
+    if (arg2) {
+      arg1->body = (char *) (new char[strlen((const char *)arg2)+1]);
+      strcpy((char *)arg1->body, (const char *)arg2);
+    } else {
+      arg1->body = 0;
+    }
+  }
+}
+
+
+SWIGEXPORT char * SWIGSTDCALL CSharp_switch_serial_event_t_body_get(void * jarg1) {
+  char * jresult ;
+  switch_serial_event_t *arg1 = (switch_serial_event_t *) 0 ;
+  char *result = 0 ;
+  
+  arg1 = (switch_serial_event_t *)jarg1; 
+  result = (char *) ((arg1)->body);
+  jresult = SWIG_csharp_string_callback((const char *)result); 
+  return jresult;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_new_switch_serial_event_t() {
+  void * jresult ;
+  switch_serial_event_t *result = 0 ;
+  
+  result = (switch_serial_event_t *)new switch_serial_event_t();
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_delete_switch_serial_event_t(void * jarg1) {
+  switch_serial_event_t *arg1 = (switch_serial_event_t *) 0 ;
+  
+  arg1 = (switch_serial_event_t *)jarg1; 
+  delete arg1;
+  
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_serial_event_header_t_name_set(void * jarg1, char * jarg2) {
+  switch_serial_event_header_t *arg1 = (switch_serial_event_header_t *) 0 ;
+  char *arg2 = (char *) 0 ;
+  
+  arg1 = (switch_serial_event_header_t *)jarg1; 
+  arg2 = (char *)jarg2; 
+  {
+    if (arg1->name) delete [] arg1->name;
+    if (arg2) {
+      arg1->name = (char *) (new char[strlen((const char *)arg2)+1]);
+      strcpy((char *)arg1->name, (const char *)arg2);
+    } else {
+      arg1->name = 0;
+    }
+  }
+}
+
+
+SWIGEXPORT char * SWIGSTDCALL CSharp_switch_serial_event_header_t_name_get(void * jarg1) {
+  char * jresult ;
+  switch_serial_event_header_t *arg1 = (switch_serial_event_header_t *) 0 ;
+  char *result = 0 ;
+  
+  arg1 = (switch_serial_event_header_t *)jarg1; 
+  result = (char *) ((arg1)->name);
+  jresult = SWIG_csharp_string_callback((const char *)result); 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_serial_event_header_t_value_set(void * jarg1, char * jarg2) {
+  switch_serial_event_header_t *arg1 = (switch_serial_event_header_t *) 0 ;
+  char *arg2 = (char *) 0 ;
+  
+  arg1 = (switch_serial_event_header_t *)jarg1; 
+  arg2 = (char *)jarg2; 
+  {
+    if (arg1->value) delete [] arg1->value;
+    if (arg2) {
+      arg1->value = (char *) (new char[strlen((const char *)arg2)+1]);
+      strcpy((char *)arg1->value, (const char *)arg2);
+    } else {
+      arg1->value = 0;
+    }
+  }
+}
+
+
+SWIGEXPORT char * SWIGSTDCALL CSharp_switch_serial_event_header_t_value_get(void * jarg1) {
+  char * jresult ;
+  switch_serial_event_header_t *arg1 = (switch_serial_event_header_t *) 0 ;
+  char *result = 0 ;
+  
+  arg1 = (switch_serial_event_header_t *)jarg1; 
+  result = (char *) ((arg1)->value);
+  jresult = SWIG_csharp_string_callback((const char *)result); 
+  return jresult;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_new_switch_serial_event_header_t() {
+  void * jresult ;
+  switch_serial_event_header_t *result = 0 ;
+  
+  result = (switch_serial_event_header_t *)new switch_serial_event_header_t();
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_delete_switch_serial_event_header_t(void * jarg1) {
+  switch_serial_event_header_t *arg1 = (switch_serial_event_header_t *) 0 ;
+  
+  arg1 = (switch_serial_event_header_t *)jarg1; 
+  delete arg1;
+  
+}
+
+
 SWIGEXPORT int SWIGSTDCALL CSharp_switch_event_init(void * jarg1) {
   int jresult ;
   switch_memory_pool_t *arg1 = (switch_memory_pool_t *) 0 ;
@@ -28017,6 +29139,46 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_event_free_subclass_detailed(char * jar
 }
 
 
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_event_binary_deserialize(void * jarg1, void * jarg2, void * jarg3, int jarg4) {
+  int jresult ;
+  switch_event_t **arg1 = (switch_event_t **) 0 ;
+  void **arg2 = (void **) 0 ;
+  switch_size_t arg3 ;
+  switch_bool_t arg4 ;
+  switch_status_t result;
+  switch_size_t *argp3 ;
+  
+  arg1 = (switch_event_t **)jarg1; 
+  arg2 = (void **)jarg2; 
+  argp3 = (switch_size_t *)jarg3; 
+  if (!argp3) {
+    SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null switch_size_t", 0);
+    return 0;
+  }
+  arg3 = *argp3; 
+  arg4 = (switch_bool_t)jarg4; 
+  result = (switch_status_t)switch_event_binary_deserialize(arg1,arg2,arg3,arg4);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_event_binary_serialize(void * jarg1, void * jarg2, void * jarg3) {
+  int jresult ;
+  switch_event_t *arg1 = (switch_event_t *) 0 ;
+  void **arg2 = (void **) 0 ;
+  switch_size_t *arg3 = (switch_size_t *) 0 ;
+  switch_status_t result;
+  
+  arg1 = (switch_event_t *)jarg1; 
+  arg2 = (void **)jarg2; 
+  arg3 = (switch_size_t *)jarg3; 
+  result = (switch_status_t)switch_event_binary_serialize(arg1,arg2,arg3);
+  jresult = result; 
+  return jresult;
+}
+
+
 SWIGEXPORT int SWIGSTDCALL CSharp_switch_event_serialize(void * jarg1, void * jarg2, int jarg3) {
   int jresult ;
   switch_event_t *arg1 = (switch_event_t *) 0 ;
@@ -28085,6 +29247,24 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_event_create_brackets(char * jarg1, cha
 }
 
 
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_event_create_array_pair(void * jarg1, void * jarg2, void * jarg3, int jarg4) {
+  int jresult ;
+  switch_event_t **arg1 = (switch_event_t **) 0 ;
+  char **arg2 = (char **) 0 ;
+  char **arg3 = (char **) 0 ;
+  int arg4 ;
+  switch_status_t result;
+  
+  arg1 = (switch_event_t **)jarg1; 
+  arg2 = (char **)jarg2; 
+  arg3 = (char **)jarg3; 
+  arg4 = (int)jarg4; 
+  result = (switch_status_t)switch_event_create_array_pair(arg1,arg2,arg3,arg4);
+  jresult = result; 
+  return jresult;
+}
+
+
 SWIGEXPORT int SWIGSTDCALL CSharp_switch_event_running() {
   int jresult ;
   switch_status_t result;
@@ -31977,6 +33157,18 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_rtp_pause_jitter_buffer(void * jarg1, i
 }
 
 
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_rtp_get_jitter_buffer(void * jarg1) {
+  void * jresult ;
+  switch_rtp_t *arg1 = (switch_rtp_t *) 0 ;
+  stfu_instance_t *result = 0 ;
+  
+  arg1 = (switch_rtp_t *)jarg1; 
+  result = (stfu_instance_t *)switch_rtp_get_jitter_buffer(arg1);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_rtp_set_flag(void * jarg1, unsigned long jarg2) {
   switch_rtp_t *arg1 = (switch_rtp_t *) 0 ;
   switch_rtp_flag_t arg2 ;
@@ -32659,6 +33851,29 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_log_node_t_channel_get(void * jarg1) {
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_log_node_t_slevel_set(void * jarg1, int jarg2) {
+  switch_log_node_t *arg1 = (switch_log_node_t *) 0 ;
+  switch_log_level_t arg2 ;
+  
+  arg1 = (switch_log_node_t *)jarg1; 
+  arg2 = (switch_log_level_t)jarg2; 
+  if (arg1) (arg1)->slevel = arg2;
+  
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_log_node_t_slevel_get(void * jarg1) {
+  int jresult ;
+  switch_log_node_t *arg1 = (switch_log_node_t *) 0 ;
+  switch_log_level_t result;
+  
+  arg1 = (switch_log_node_t *)jarg1; 
+  result = (switch_log_level_t) ((arg1)->slevel);
+  jresult = result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void * SWIGSTDCALL CSharp_new_switch_log_node_t() {
   void * jresult ;
   switch_log_node_t *result = 0 ;
@@ -33340,6 +34555,20 @@ SWIGEXPORT char * SWIGSTDCALL CSharp_switch_xml_toxml_nolock(void * jarg1, int j
 }
 
 
+SWIGEXPORT char * SWIGSTDCALL CSharp_switch_xml_tohtml(void * jarg1, int jarg2) {
+  char * jresult ;
+  switch_xml_t arg1 = (switch_xml_t) 0 ;
+  switch_bool_t arg2 ;
+  char *result = 0 ;
+  
+  arg1 = (switch_xml_t)jarg1; 
+  arg2 = (switch_bool_t)jarg2; 
+  result = (char *)switch_xml_tohtml(arg1,arg2);
+  jresult = SWIG_csharp_string_callback((const char *)result); 
+  return jresult;
+}
+
+
 SWIGEXPORT char * SWIGSTDCALL CSharp_switch_xml_toxml_buf(void * jarg1, char * jarg2, void * jarg3, void * jarg4, int jarg5) {
   char * jresult ;
   switch_xml_t arg1 = (switch_xml_t) 0 ;
diff --git a/src/mod/languages/mod_managed/managed/swig.2010.cs b/src/mod/languages/mod_managed/managed/swig.2010.cs
index 031eda1f37..25a99cdf69 100644
--- a/src/mod/languages/mod_managed/managed/swig.2010.cs
+++ b/src/mod/languages/mod_managed/managed/swig.2010.cs
@@ -1469,6 +1469,11 @@ public class freeswitch {
     return ret;
   }
 
+  public static switch_status_t switch_thread_pool_launch_thread(SWIGTYPE_p_p_switch_thread_data_s tdp) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_thread_pool_launch_thread(SWIGTYPE_p_p_switch_thread_data_s.getCPtr(tdp));
+    return ret;
+  }
+
   public static switch_status_t switch_core_session_thread_pool_launch(SWIGTYPE_p_switch_core_session session) {
     switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_core_session_thread_pool_launch(SWIGTYPE_p_switch_core_session.getCPtr(session));
     return ret;
@@ -2637,12 +2642,12 @@ public class freeswitch {
     return ret;
   }
 
-  public static void switch_core_sqldb_stop_thread() {
-    freeswitchPINVOKE.switch_core_sqldb_stop_thread();
+  public static void switch_core_sqldb_pause() {
+    freeswitchPINVOKE.switch_core_sqldb_pause();
   }
 
-  public static void switch_core_sqldb_start_thread() {
-    freeswitchPINVOKE.switch_core_sqldb_start_thread();
+  public static void switch_core_sqldb_resume() {
+    freeswitchPINVOKE.switch_core_sqldb_resume();
   }
 
   public static string switch_cache_db_type_name(switch_cache_db_handle_type_t type) {
@@ -2837,28 +2842,38 @@ public class freeswitch {
     freeswitchPINVOKE.switch_core_recovery_flush(technology, profile_name);
   }
 
-  public static switch_status_t switch_switch_sql_queue_manager_push(SWIGTYPE_p_switch_sql_queue_manager qm, string sql, uint pos, switch_bool_t dup) {
-    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_switch_sql_queue_manager_push(SWIGTYPE_p_switch_sql_queue_manager.getCPtr(qm), sql, pos, (int)dup);
+  public static int switch_sql_queue_manager_size(SWIGTYPE_p_switch_sql_queue_manager qm, uint index) {
+    int ret = freeswitchPINVOKE.switch_sql_queue_manager_size(SWIGTYPE_p_switch_sql_queue_manager.getCPtr(qm), index);
     return ret;
   }
 
-  public static switch_status_t switch_switch_sql_queue_manager_destroy(SWIGTYPE_p_p_switch_sql_queue_manager qmp) {
-    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_switch_sql_queue_manager_destroy(SWIGTYPE_p_p_switch_sql_queue_manager.getCPtr(qmp));
+  public static switch_status_t switch_sql_queue_manager_push_confirm(SWIGTYPE_p_switch_sql_queue_manager qm, string sql, uint pos, switch_bool_t dup) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_sql_queue_manager_push_confirm(SWIGTYPE_p_switch_sql_queue_manager.getCPtr(qm), sql, pos, (int)dup);
     return ret;
   }
 
-  public static switch_status_t switch_switch_sql_queue_manager_init(SWIGTYPE_p_p_switch_sql_queue_manager qmp, uint numq, string dsn, string pre_trans_execute, string post_trans_execute, string inner_pre_trans_execute, string inner_post_trans_execute) {
-    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_switch_sql_queue_manager_init(SWIGTYPE_p_p_switch_sql_queue_manager.getCPtr(qmp), numq, dsn, pre_trans_execute, post_trans_execute, inner_pre_trans_execute, inner_post_trans_execute);
+  public static switch_status_t switch_sql_queue_manager_push(SWIGTYPE_p_switch_sql_queue_manager qm, string sql, uint pos, switch_bool_t dup) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_sql_queue_manager_push(SWIGTYPE_p_switch_sql_queue_manager.getCPtr(qm), sql, pos, (int)dup);
     return ret;
   }
 
-  public static switch_status_t switch_switch_sql_queue_manager_start(SWIGTYPE_p_switch_sql_queue_manager qm) {
-    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_switch_sql_queue_manager_start(SWIGTYPE_p_switch_sql_queue_manager.getCPtr(qm));
+  public static switch_status_t switch_sql_queue_manager_destroy(SWIGTYPE_p_p_switch_sql_queue_manager qmp) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_sql_queue_manager_destroy(SWIGTYPE_p_p_switch_sql_queue_manager.getCPtr(qmp));
     return ret;
   }
 
-  public static switch_status_t switch_switch_sql_queue_manager_stop(SWIGTYPE_p_switch_sql_queue_manager qm) {
-    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_switch_sql_queue_manager_stop(SWIGTYPE_p_switch_sql_queue_manager.getCPtr(qm));
+  public static switch_status_t switch_sql_queue_manager_init_name(string name, SWIGTYPE_p_p_switch_sql_queue_manager qmp, uint numq, string dsn, uint max_trans, string pre_trans_execute, string post_trans_execute, string inner_pre_trans_execute, string inner_post_trans_execute) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_sql_queue_manager_init_name(name, SWIGTYPE_p_p_switch_sql_queue_manager.getCPtr(qmp), numq, dsn, max_trans, pre_trans_execute, post_trans_execute, inner_pre_trans_execute, inner_post_trans_execute);
+    return ret;
+  }
+
+  public static switch_status_t switch_sql_queue_manager_start(SWIGTYPE_p_switch_sql_queue_manager qm) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_sql_queue_manager_start(SWIGTYPE_p_switch_sql_queue_manager.getCPtr(qm));
+    return ret;
+  }
+
+  public static switch_status_t switch_sql_queue_manager_stop(SWIGTYPE_p_switch_sql_queue_manager qm) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_sql_queue_manager_stop(SWIGTYPE_p_switch_sql_queue_manager.getCPtr(qm));
     return ret;
   }
 
@@ -5230,6 +5245,11 @@ public class freeswitch {
     return ret;
   }
 
+  public static switch_bool_t switch_ivr_uuid_force_exists(string uuid) {
+    switch_bool_t ret = (switch_bool_t)freeswitchPINVOKE.switch_ivr_uuid_force_exists(uuid);
+    return ret;
+  }
+
   public static switch_status_t switch_ivr_dmachine_last_ping(SWIGTYPE_p_switch_ivr_dmachine dmachine) {
     switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_ivr_dmachine_last_ping(SWIGTYPE_p_switch_ivr_dmachine.getCPtr(dmachine));
     return ret;
@@ -5986,8 +6006,8 @@ public class freeswitch {
     return ret;
   }
 
-  public static int switch_xml_std_datetime_check(switch_xml xcond, SWIGTYPE_p_int offset) {
-    int ret = freeswitchPINVOKE.switch_xml_std_datetime_check(switch_xml.getCPtr(xcond), SWIGTYPE_p_int.getCPtr(offset));
+  public static int switch_xml_std_datetime_check(switch_xml xcond, SWIGTYPE_p_int offset, string tzname) {
+    int ret = freeswitchPINVOKE.switch_xml_std_datetime_check(switch_xml.getCPtr(xcond), SWIGTYPE_p_int.getCPtr(offset), tzname);
     return ret;
   }
 
@@ -6291,6 +6311,7 @@ public class freeswitch {
   public static readonly string SWITCH_CHANNEL_EXECUTE_ON_TONE_DETECT_VARIABLE = freeswitchPINVOKE.SWITCH_CHANNEL_EXECUTE_ON_TONE_DETECT_VARIABLE_get();
   public static readonly string SWITCH_CHANNEL_EXECUTE_ON_ORIGINATE_VARIABLE = freeswitchPINVOKE.SWITCH_CHANNEL_EXECUTE_ON_ORIGINATE_VARIABLE_get();
   public static readonly string SWITCH_CHANNEL_EXECUTE_ON_POST_ORIGINATE_VARIABLE = freeswitchPINVOKE.SWITCH_CHANNEL_EXECUTE_ON_POST_ORIGINATE_VARIABLE_get();
+  public static readonly string SWITCH_CHANNEL_EXECUTE_ON_PRE_ORIGINATE_VARIABLE = freeswitchPINVOKE.SWITCH_CHANNEL_EXECUTE_ON_PRE_ORIGINATE_VARIABLE_get();
   public static readonly string SWITCH_CHANNEL_API_ON_ANSWER_VARIABLE = freeswitchPINVOKE.SWITCH_CHANNEL_API_ON_ANSWER_VARIABLE_get();
   public static readonly string SWITCH_CHANNEL_API_ON_PRE_ANSWER_VARIABLE = freeswitchPINVOKE.SWITCH_CHANNEL_API_ON_PRE_ANSWER_VARIABLE_get();
   public static readonly string SWITCH_CHANNEL_API_ON_MEDIA_VARIABLE = freeswitchPINVOKE.SWITCH_CHANNEL_API_ON_MEDIA_VARIABLE_get();
@@ -6298,6 +6319,7 @@ public class freeswitch {
   public static readonly string SWITCH_CHANNEL_API_ON_TONE_DETECT_VARIABLE = freeswitchPINVOKE.SWITCH_CHANNEL_API_ON_TONE_DETECT_VARIABLE_get();
   public static readonly string SWITCH_CHANNEL_API_ON_ORIGINATE_VARIABLE = freeswitchPINVOKE.SWITCH_CHANNEL_API_ON_ORIGINATE_VARIABLE_get();
   public static readonly string SWITCH_CHANNEL_API_ON_POST_ORIGINATE_VARIABLE = freeswitchPINVOKE.SWITCH_CHANNEL_API_ON_POST_ORIGINATE_VARIABLE_get();
+  public static readonly string SWITCH_CHANNEL_API_ON_PRE_ORIGINATE_VARIABLE = freeswitchPINVOKE.SWITCH_CHANNEL_API_ON_PRE_ORIGINATE_VARIABLE_get();
   public static readonly string SWITCH_CALL_TIMEOUT_VARIABLE = freeswitchPINVOKE.SWITCH_CALL_TIMEOUT_VARIABLE_get();
   public static readonly string SWITCH_HOLDING_UUID_VARIABLE = freeswitchPINVOKE.SWITCH_HOLDING_UUID_VARIABLE_get();
   public static readonly string SWITCH_SOFT_HOLDING_UUID_VARIABLE = freeswitchPINVOKE.SWITCH_SOFT_HOLDING_UUID_VARIABLE_get();
@@ -6356,6 +6378,7 @@ public class freeswitch {
   public static readonly int SWITCH_BITS_PER_BYTE = freeswitchPINVOKE.SWITCH_BITS_PER_BYTE_get();
   public static readonly int SWITCH_DEFAULT_FILE_BUFFER_LEN = freeswitchPINVOKE.SWITCH_DEFAULT_FILE_BUFFER_LEN_get();
   public static readonly int SWITCH_DTMF_LOG_LEN = freeswitchPINVOKE.SWITCH_DTMF_LOG_LEN_get();
+  public static readonly int SWITCH_MAX_TRANS = freeswitchPINVOKE.SWITCH_MAX_TRANS_get();
   public static readonly int SWITCH_MAX_STACKS = freeswitchPINVOKE.SWITCH_MAX_STACKS_get();
   public static readonly int SWITCH_THREAD_STACKSIZE = freeswitchPINVOKE.SWITCH_THREAD_STACKSIZE_get();
   public static readonly int SWITCH_SYSTEM_THREAD_STACKSIZE = freeswitchPINVOKE.SWITCH_SYSTEM_THREAD_STACKSIZE_get();
@@ -6874,6 +6897,9 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp_SWITCH_CHANNEL_EXECUTE_ON_POST_ORIGINATE_VARIABLE_get")]
   public static extern string SWITCH_CHANNEL_EXECUTE_ON_POST_ORIGINATE_VARIABLE_get();
 
+  [DllImport("mod_managed", EntryPoint="CSharp_SWITCH_CHANNEL_EXECUTE_ON_PRE_ORIGINATE_VARIABLE_get")]
+  public static extern string SWITCH_CHANNEL_EXECUTE_ON_PRE_ORIGINATE_VARIABLE_get();
+
   [DllImport("mod_managed", EntryPoint="CSharp_SWITCH_CHANNEL_API_ON_ANSWER_VARIABLE_get")]
   public static extern string SWITCH_CHANNEL_API_ON_ANSWER_VARIABLE_get();
 
@@ -6895,6 +6921,9 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp_SWITCH_CHANNEL_API_ON_POST_ORIGINATE_VARIABLE_get")]
   public static extern string SWITCH_CHANNEL_API_ON_POST_ORIGINATE_VARIABLE_get();
 
+  [DllImport("mod_managed", EntryPoint="CSharp_SWITCH_CHANNEL_API_ON_PRE_ORIGINATE_VARIABLE_get")]
+  public static extern string SWITCH_CHANNEL_API_ON_PRE_ORIGINATE_VARIABLE_get();
+
   [DllImport("mod_managed", EntryPoint="CSharp_SWITCH_CALL_TIMEOUT_VARIABLE_get")]
   public static extern string SWITCH_CALL_TIMEOUT_VARIABLE_get();
 
@@ -7069,6 +7098,9 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp_SWITCH_DTMF_LOG_LEN_get")]
   public static extern int SWITCH_DTMF_LOG_LEN_get();
 
+  [DllImport("mod_managed", EntryPoint="CSharp_SWITCH_MAX_TRANS_get")]
+  public static extern int SWITCH_MAX_TRANS_get();
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_dtmf_t_digit_set")]
   public static extern void switch_dtmf_t_digit_set(HandleRef jarg1, char jarg2);
 
@@ -7195,6 +7227,12 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp_switch_directories_mod_dir_get")]
   public static extern string switch_directories_mod_dir_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_directories_lib_dir_set")]
+  public static extern void switch_directories_lib_dir_set(HandleRef jarg1, string jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_directories_lib_dir_get")]
+  public static extern string switch_directories_lib_dir_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_directories_conf_dir_set")]
   public static extern void switch_directories_conf_dir_set(HandleRef jarg1, string jarg2);
 
@@ -8140,6 +8178,30 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp_delete_switch_hold_record_t")]
   public static extern void delete_switch_hold_record_t(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_thread_data_t_func_set")]
+  public static extern void switch_thread_data_t_func_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_thread_data_t_func_get")]
+  public static extern IntPtr switch_thread_data_t_func_get(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_thread_data_t_obj_set")]
+  public static extern void switch_thread_data_t_obj_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_thread_data_t_obj_get")]
+  public static extern IntPtr switch_thread_data_t_obj_get(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_thread_data_t_alloc_set")]
+  public static extern void switch_thread_data_t_alloc_set(HandleRef jarg1, int jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_thread_data_t_alloc_get")]
+  public static extern int switch_thread_data_t_alloc_get(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_new_switch_thread_data_t")]
+  public static extern IntPtr new_switch_thread_data_t();
+
+  [DllImport("mod_managed", EntryPoint="CSharp_delete_switch_thread_data_t")]
+  public static extern void delete_switch_thread_data_t(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_MESSAGE_STRING_ARG_MAX_get")]
   public static extern int MESSAGE_STRING_ARG_MAX_get();
 
@@ -8548,6 +8610,9 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp_switch_core_session_thread_launch")]
   public static extern int switch_core_session_thread_launch(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_thread_pool_launch_thread")]
+  public static extern int switch_thread_pool_launch_thread(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_core_session_thread_pool_launch")]
   public static extern int switch_core_session_thread_pool_launch(HandleRef jarg1);
 
@@ -9259,11 +9324,11 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp_switch_ivr_preprocess_session")]
   public static extern int switch_ivr_preprocess_session(HandleRef jarg1, string jarg2);
 
-  [DllImport("mod_managed", EntryPoint="CSharp_switch_core_sqldb_stop_thread")]
-  public static extern void switch_core_sqldb_stop_thread();
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_core_sqldb_pause")]
+  public static extern void switch_core_sqldb_pause();
 
-  [DllImport("mod_managed", EntryPoint="CSharp_switch_core_sqldb_start_thread")]
-  public static extern void switch_core_sqldb_start_thread();
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_core_sqldb_resume")]
+  public static extern void switch_core_sqldb_resume();
 
   [DllImport("mod_managed", EntryPoint="CSharp_CACHE_DB_LEN_get")]
   public static extern int CACHE_DB_LEN_get();
@@ -9487,20 +9552,26 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp_switch_core_recovery_flush")]
   public static extern void switch_core_recovery_flush(string jarg1, string jarg2);
 
-  [DllImport("mod_managed", EntryPoint="CSharp_switch_switch_sql_queue_manager_push")]
-  public static extern int switch_switch_sql_queue_manager_push(HandleRef jarg1, string jarg2, uint jarg3, int jarg4);
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_sql_queue_manager_size")]
+  public static extern int switch_sql_queue_manager_size(HandleRef jarg1, uint jarg2);
 
-  [DllImport("mod_managed", EntryPoint="CSharp_switch_switch_sql_queue_manager_destroy")]
-  public static extern int switch_switch_sql_queue_manager_destroy(HandleRef jarg1);
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_sql_queue_manager_push_confirm")]
+  public static extern int switch_sql_queue_manager_push_confirm(HandleRef jarg1, string jarg2, uint jarg3, int jarg4);
 
-  [DllImport("mod_managed", EntryPoint="CSharp_switch_switch_sql_queue_manager_init")]
-  public static extern int switch_switch_sql_queue_manager_init(HandleRef jarg1, uint jarg2, string jarg3, string jarg4, string jarg5, string jarg6, string jarg7);
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_sql_queue_manager_push")]
+  public static extern int switch_sql_queue_manager_push(HandleRef jarg1, string jarg2, uint jarg3, int jarg4);
 
-  [DllImport("mod_managed", EntryPoint="CSharp_switch_switch_sql_queue_manager_start")]
-  public static extern int switch_switch_sql_queue_manager_start(HandleRef jarg1);
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_sql_queue_manager_destroy")]
+  public static extern int switch_sql_queue_manager_destroy(HandleRef jarg1);
 
-  [DllImport("mod_managed", EntryPoint="CSharp_switch_switch_sql_queue_manager_stop")]
-  public static extern int switch_switch_sql_queue_manager_stop(HandleRef jarg1);
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_sql_queue_manager_init_name")]
+  public static extern int switch_sql_queue_manager_init_name(string jarg1, HandleRef jarg2, uint jarg3, string jarg4, uint jarg5, string jarg6, string jarg7, string jarg8, string jarg9);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_sql_queue_manager_start")]
+  public static extern int switch_sql_queue_manager_start(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_sql_queue_manager_stop")]
+  public static extern int switch_sql_queue_manager_stop(HandleRef jarg1);
 
   [DllImport("mod_managed", EntryPoint="CSharp_switch_cache_db_execute_sql_event_callback")]
   public static extern int switch_cache_db_execute_sql_event_callback(HandleRef jarg1, string jarg2, HandleRef jarg3, HandleRef jarg4, ref string jarg5);
@@ -12289,6 +12360,12 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp_switch_codec_session_get")]
   public static extern IntPtr switch_codec_session_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_codec_cur_frame_set")]
+  public static extern void switch_codec_cur_frame_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_codec_cur_frame_get")]
+  public static extern IntPtr switch_codec_cur_frame_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_new_switch_codec")]
   public static extern IntPtr new_switch_codec();
 
@@ -14077,6 +14154,9 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp_switch_ivr_uuid_exists")]
   public static extern int switch_ivr_uuid_exists(string jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_ivr_uuid_force_exists")]
+  public static extern int switch_ivr_uuid_force_exists(string jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_ivr_dmachine_last_ping")]
   public static extern int switch_ivr_dmachine_last_ping(HandleRef jarg1);
 
@@ -14738,7 +14818,7 @@ class freeswitchPINVOKE {
   public static extern uint switch_xml_parse_section_string(string jarg1);
 
   [DllImport("mod_managed", EntryPoint="CSharp_switch_xml_std_datetime_check")]
-  public static extern int switch_xml_std_datetime_check(HandleRef jarg1, HandleRef jarg2);
+  public static extern int switch_xml_std_datetime_check(HandleRef jarg1, HandleRef jarg2, string jarg3);
 
   [DllImport("mod_managed", EntryPoint="CSharp_switch_xml_locate_language")]
   public static extern int switch_xml_locate_language(HandleRef jarg1, HandleRef jarg2, HandleRef jarg3, HandleRef jarg4, HandleRef jarg5, HandleRef jarg6, string jarg7);
@@ -19939,6 +20019,36 @@ namespace FreeSWITCH.Native {
 using System;
 using System.Runtime.InteropServices;
 
+public class SWIGTYPE_p_p_switch_thread_data_s {
+  private HandleRef swigCPtr;
+
+  internal SWIGTYPE_p_p_switch_thread_data_s(IntPtr cPtr, bool futureUse) {
+    swigCPtr = new HandleRef(this, cPtr);
+  }
+
+  protected SWIGTYPE_p_p_switch_thread_data_s() {
+    swigCPtr = new HandleRef(null, IntPtr.Zero);
+  }
+
+  internal static HandleRef getCPtr(SWIGTYPE_p_p_switch_thread_data_s obj) {
+    return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
+  }
+}
+
+}
+/* ----------------------------------------------------------------------------
+ * This file was automatically generated by SWIG (http://www.swig.org).
+ * Version 2.0.1
+ *
+ * Do not make changes to this file unless you know what you are doing--modify
+ * the SWIG interface file instead.
+ * ----------------------------------------------------------------------------- */
+
+namespace FreeSWITCH.Native {
+
+using System;
+using System.Runtime.InteropServices;
+
 public class SWIGTYPE_p_p_switch_xml {
   private HandleRef swigCPtr;
 
@@ -21229,6 +21339,36 @@ namespace FreeSWITCH.Native {
 using System;
 using System.Runtime.InteropServices;
 
+public class SWIGTYPE_p_switch_thread_start_t {
+  private HandleRef swigCPtr;
+
+  internal SWIGTYPE_p_switch_thread_start_t(IntPtr cPtr, bool futureUse) {
+    swigCPtr = new HandleRef(this, cPtr);
+  }
+
+  protected SWIGTYPE_p_switch_thread_start_t() {
+    swigCPtr = new HandleRef(null, IntPtr.Zero);
+  }
+
+  internal static HandleRef getCPtr(SWIGTYPE_p_switch_thread_start_t obj) {
+    return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
+  }
+}
+
+}
+/* ----------------------------------------------------------------------------
+ * This file was automatically generated by SWIG (http://www.swig.org).
+ * Version 2.0.1
+ *
+ * Do not make changes to this file unless you know what you are doing--modify
+ * the SWIG interface file instead.
+ * ----------------------------------------------------------------------------- */
+
+namespace FreeSWITCH.Native {
+
+using System;
+using System.Runtime.InteropServices;
+
 public class SWIGTYPE_p_switch_time_exp_t {
   private HandleRef swigCPtr;
 
@@ -21666,7 +21806,8 @@ namespace FreeSWITCH.Native {
   SAF_SUPPORT_NOMEDIA = (1 << 0),
   SAF_ROUTING_EXEC = (1 << 1),
   SAF_MEDIA_TAP = (1 << 2),
-  SAF_ZOMBIE_EXEC = (1 << 3)
+  SAF_ZOMBIE_EXEC = (1 << 3),
+  SAF_NO_LOOPBACK = (1 << 4)
 }
 
 }
@@ -24074,6 +24215,7 @@ public enum switch_channel_flag_t {
   CF_OUTBOUND,
   CF_EARLY_MEDIA,
   CF_BRIDGE_ORIGINATOR,
+  CF_UUID_BRIDGE_ORIGINATOR,
   CF_TRANSFER,
   CF_ACCEPT_CNG,
   CF_REDIRECT,
@@ -24842,6 +24984,17 @@ public class switch_codec : IDisposable {
     } 
   }
 
+  public switch_frame cur_frame {
+    set {
+      freeswitchPINVOKE.switch_codec_cur_frame_set(swigCPtr, switch_frame.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_codec_cur_frame_get(swigCPtr);
+      switch_frame ret = (cPtr == IntPtr.Zero) ? null : new switch_frame(cPtr, false);
+      return ret;
+    } 
+  }
+
   public switch_codec() : this(freeswitchPINVOKE.new_switch_codec(), true) {
   }
 
@@ -26519,6 +26672,16 @@ public class switch_directories : IDisposable {
     } 
   }
 
+  public string lib_dir {
+    set {
+      freeswitchPINVOKE.switch_directories_lib_dir_set(swigCPtr, value);
+    } 
+    get {
+      string ret = freeswitchPINVOKE.switch_directories_lib_dir_get(swigCPtr);
+      return ret;
+    } 
+  }
+
   public string conf_dir {
     set {
       freeswitchPINVOKE.switch_directories_conf_dir_set(swigCPtr, value);
@@ -33981,6 +34144,88 @@ public enum switch_text_channel_t {
 
 namespace FreeSWITCH.Native {
 
+using System;
+using System.Runtime.InteropServices;
+
+public class switch_thread_data_t : IDisposable {
+  private HandleRef swigCPtr;
+  protected bool swigCMemOwn;
+
+  internal switch_thread_data_t(IntPtr cPtr, bool cMemoryOwn) {
+    swigCMemOwn = cMemoryOwn;
+    swigCPtr = new HandleRef(this, cPtr);
+  }
+
+  internal static HandleRef getCPtr(switch_thread_data_t obj) {
+    return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
+  }
+
+  ~switch_thread_data_t() {
+    Dispose();
+  }
+
+  public virtual void Dispose() {
+    lock(this) {
+      if (swigCPtr.Handle != IntPtr.Zero) {
+        if (swigCMemOwn) {
+          swigCMemOwn = false;
+          freeswitchPINVOKE.delete_switch_thread_data_t(swigCPtr);
+        }
+        swigCPtr = new HandleRef(null, IntPtr.Zero);
+      }
+      GC.SuppressFinalize(this);
+    }
+  }
+
+  public SWIGTYPE_p_switch_thread_start_t func {
+    set {
+      freeswitchPINVOKE.switch_thread_data_t_func_set(swigCPtr, SWIGTYPE_p_switch_thread_start_t.getCPtr(value));
+      if (freeswitchPINVOKE.SWIGPendingException.Pending) throw freeswitchPINVOKE.SWIGPendingException.Retrieve();
+    } 
+    get {
+      SWIGTYPE_p_switch_thread_start_t ret = new SWIGTYPE_p_switch_thread_start_t(freeswitchPINVOKE.switch_thread_data_t_func_get(swigCPtr), true);
+      if (freeswitchPINVOKE.SWIGPendingException.Pending) throw freeswitchPINVOKE.SWIGPendingException.Retrieve();
+      return ret;
+    } 
+  }
+
+  public SWIGTYPE_p_void obj {
+    set {
+      freeswitchPINVOKE.switch_thread_data_t_obj_set(swigCPtr, SWIGTYPE_p_void.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_thread_data_t_obj_get(swigCPtr);
+      SWIGTYPE_p_void ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_void(cPtr, false);
+      return ret;
+    } 
+  }
+
+  public int alloc {
+    set {
+      freeswitchPINVOKE.switch_thread_data_t_alloc_set(swigCPtr, value);
+    } 
+    get {
+      int ret = freeswitchPINVOKE.switch_thread_data_t_alloc_get(swigCPtr);
+      return ret;
+    } 
+  }
+
+  public switch_thread_data_t() : this(freeswitchPINVOKE.new_switch_thread_data_t(), true) {
+  }
+
+}
+
+}
+/* ----------------------------------------------------------------------------
+ * This file was automatically generated by SWIG (http://www.swig.org).
+ * Version 2.0.1
+ *
+ * Do not make changes to this file unless you know what you are doing--modify
+ * the SWIG interface file instead.
+ * ----------------------------------------------------------------------------- */
+
+namespace FreeSWITCH.Native {
+
 public enum switch_thread_priority_t {
   SWITCH_PRI_LOW = 1,
   SWITCH_PRI_NORMAL = 10,
diff --git a/src/mod/languages/mod_managed/managed/swig.cs b/src/mod/languages/mod_managed/managed/swig.cs
index ead2b8b2a4..e3eea0582d 100644
--- a/src/mod/languages/mod_managed/managed/swig.cs
+++ b/src/mod/languages/mod_managed/managed/swig.cs
@@ -1038,6 +1038,10 @@ public class freeswitch {
     freeswitchPINVOKE.switch_regex_set_event_header_callback(var, val, SWIGTYPE_p_void.getCPtr(user_data));
   }
 
+  public static void switch_core_screen_size(SWIGTYPE_p_int x, SWIGTYPE_p_int y) {
+    freeswitchPINVOKE.switch_core_screen_size(SWIGTYPE_p_int.getCPtr(x), SWIGTYPE_p_int.getCPtr(y));
+  }
+
   public static void switch_core_session_sched_heartbeat(SWIGTYPE_p_switch_core_session session, uint seconds) {
     freeswitchPINVOKE.switch_core_session_sched_heartbeat(SWIGTYPE_p_switch_core_session.getCPtr(session), seconds);
   }
@@ -1453,6 +1457,11 @@ public class freeswitch {
     return ret;
   }
 
+  public static switch_status_t switch_thread_pool_launch_thread(SWIGTYPE_p_p_switch_thread_data_s tdp) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_thread_pool_launch_thread(SWIGTYPE_p_p_switch_thread_data_s.getCPtr(tdp));
+    return ret;
+  }
+
   public static switch_status_t switch_core_session_thread_pool_launch(SWIGTYPE_p_switch_core_session session) {
     switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_core_session_thread_pool_launch(SWIGTYPE_p_switch_core_session.getCPtr(session));
     return ret;
@@ -1488,6 +1497,12 @@ public class freeswitch {
     return ret;
   }
 
+  public static SWIGTYPE_p_stfu_instance_t switch_core_session_get_jb(SWIGTYPE_p_switch_core_session session, switch_media_type_t type) {
+    IntPtr cPtr = freeswitchPINVOKE.switch_core_session_get_jb(SWIGTYPE_p_switch_core_session.getCPtr(session), (int)type);
+    SWIGTYPE_p_stfu_instance_t ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_stfu_instance_t(cPtr, false);
+    return ret;
+  }
+
   public static void switch_core_session_soft_lock(SWIGTYPE_p_switch_core_session session, uint sec) {
     freeswitchPINVOKE.switch_core_session_soft_lock(SWIGTYPE_p_switch_core_session.getCPtr(session), sec);
   }
@@ -1583,6 +1598,12 @@ public class freeswitch {
     freeswitchPINVOKE.switch_core_session_hupall_matching_var(var_name, var_val, (int)cause);
   }
 
+  public static switch_console_callback_match switch_core_session_findall_matching_var(string var_name, string var_val) {
+    IntPtr cPtr = freeswitchPINVOKE.switch_core_session_findall_matching_var(var_name, var_val);
+    switch_console_callback_match ret = (cPtr == IntPtr.Zero) ? null : new switch_console_callback_match(cPtr, false);
+    return ret;
+  }
+
   public static void switch_core_session_hupall_endpoint(switch_endpoint_interface endpoint_interface, switch_call_cause_t cause) {
     freeswitchPINVOKE.switch_core_session_hupall_endpoint(switch_endpoint_interface.getCPtr(endpoint_interface), (int)cause);
   }
@@ -1893,6 +1914,22 @@ public class freeswitch {
     return ret;
   }
 
+  public static SWIGTYPE_p_HashElem switch_core_hash_first(SWIGTYPE_p_switch_hash hash) {
+    IntPtr cPtr = freeswitchPINVOKE.switch_core_hash_first(SWIGTYPE_p_switch_hash.getCPtr(hash));
+    SWIGTYPE_p_HashElem ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_HashElem(cPtr, false);
+    return ret;
+  }
+
+  public static SWIGTYPE_p_HashElem switch_core_hash_next(SWIGTYPE_p_HashElem hi) {
+    IntPtr cPtr = freeswitchPINVOKE.switch_core_hash_next(SWIGTYPE_p_HashElem.getCPtr(hi));
+    SWIGTYPE_p_HashElem ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_HashElem(cPtr, false);
+    return ret;
+  }
+
+  public static void switch_core_hash_this(SWIGTYPE_p_HashElem hi, SWIGTYPE_p_p_void key, SWIGTYPE_p_switch_ssize_t klen, SWIGTYPE_p_p_void val) {
+    freeswitchPINVOKE.switch_core_hash_this(SWIGTYPE_p_HashElem.getCPtr(hi), SWIGTYPE_p_p_void.getCPtr(key), SWIGTYPE_p_switch_ssize_t.getCPtr(klen), SWIGTYPE_p_p_void.getCPtr(val));
+  }
+
   public static SWIGTYPE_p_HashElem switch_hash_first(string deprecate_me, SWIGTYPE_p_switch_hash hash) {
     IntPtr cPtr = freeswitchPINVOKE.switch_hash_first(deprecate_me, SWIGTYPE_p_switch_hash.getCPtr(hash));
     SWIGTYPE_p_HashElem ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_HashElem(cPtr, false);
@@ -2624,6 +2661,11 @@ public class freeswitch {
     return ret;
   }
 
+  public static switch_status_t _switch_cache_db_get_db_handle_dsn(SWIGTYPE_p_p_switch_cache_db_handle dbh, string dsn, string file, string func, int line) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE._switch_cache_db_get_db_handle_dsn(SWIGTYPE_p_p_switch_cache_db_handle.getCPtr(dbh), dsn, file, func, line);
+    return ret;
+  }
+
   public static string switch_cache_db_execute_sql2str(SWIGTYPE_p_switch_cache_db_handle dbh, string sql, string str, uint len, ref string err) {
     string ret = freeswitchPINVOKE.switch_cache_db_execute_sql2str(SWIGTYPE_p_switch_cache_db_handle.getCPtr(dbh), sql, str, len, ref err);
     return ret;
@@ -2653,11 +2695,6 @@ public class freeswitch {
     return ret;
   }
 
-  public static switch_status_t _switch_core_recovery_db_handle(SWIGTYPE_p_p_switch_cache_db_handle dbh, string file, string func, int line) {
-    switch_status_t ret = (switch_status_t)freeswitchPINVOKE._switch_core_recovery_db_handle(SWIGTYPE_p_p_switch_cache_db_handle.getCPtr(dbh), file, func, line);
-    return ret;
-  }
-
   public static switch_bool_t switch_cache_db_test_reactive(SWIGTYPE_p_switch_cache_db_handle db, string test_sql, string drop_sql, string reactive_sql) {
     switch_bool_t ret = (switch_bool_t)freeswitchPINVOKE.switch_cache_db_test_reactive(SWIGTYPE_p_switch_cache_db_handle.getCPtr(db), test_sql, drop_sql, reactive_sql);
     return ret;
@@ -2668,8 +2705,8 @@ public class freeswitch {
     return ret;
   }
 
-  public static switch_status_t switch_cache_db_persistant_execute_trans(SWIGTYPE_p_switch_cache_db_handle dbh, string sql, uint retries) {
-    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_cache_db_persistant_execute_trans(SWIGTYPE_p_switch_cache_db_handle.getCPtr(dbh), sql, retries);
+  public static switch_status_t switch_cache_db_persistant_execute_trans_full(SWIGTYPE_p_switch_cache_db_handle dbh, string sql, uint retries, string pre_trans_execute, string post_trans_execute, string inner_pre_trans_execute, string inner_post_trans_execute) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_cache_db_persistant_execute_trans_full(SWIGTYPE_p_switch_cache_db_handle.getCPtr(dbh), sql, retries, pre_trans_execute, post_trans_execute, inner_pre_trans_execute, inner_post_trans_execute);
     return ret;
   }
 
@@ -2767,6 +2804,15 @@ public class freeswitch {
     return ret;
   }
 
+  public static switch_cache_db_handle_type_t switch_core_dbtype() {
+    switch_cache_db_handle_type_t ret = (switch_cache_db_handle_type_t)freeswitchPINVOKE.switch_core_dbtype();
+    return ret;
+  }
+
+  public static void switch_core_sql_exec(string sql) {
+    freeswitchPINVOKE.switch_core_sql_exec(sql);
+  }
+
   public static int switch_core_recovery_recover(string technology, string profile_name) {
     int ret = freeswitchPINVOKE.switch_core_recovery_recover(technology, profile_name);
     return ret;
@@ -2784,6 +2830,46 @@ public class freeswitch {
     freeswitchPINVOKE.switch_core_recovery_flush(technology, profile_name);
   }
 
+  public static switch_status_t switch_sql_queue_manager_push_confirm(SWIGTYPE_p_switch_sql_queue_manager qm, string sql, uint pos, switch_bool_t dup) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_sql_queue_manager_push_confirm(SWIGTYPE_p_switch_sql_queue_manager.getCPtr(qm), sql, pos, (int)dup);
+    return ret;
+  }
+
+  public static switch_status_t switch_sql_queue_manager_push(SWIGTYPE_p_switch_sql_queue_manager qm, string sql, uint pos, switch_bool_t dup) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_sql_queue_manager_push(SWIGTYPE_p_switch_sql_queue_manager.getCPtr(qm), sql, pos, (int)dup);
+    return ret;
+  }
+
+  public static switch_status_t switch_sql_queue_manager_destroy(SWIGTYPE_p_p_switch_sql_queue_manager qmp) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_sql_queue_manager_destroy(SWIGTYPE_p_p_switch_sql_queue_manager.getCPtr(qmp));
+    return ret;
+  }
+
+  public static switch_status_t switch_sql_queue_manager_init_name(string name, SWIGTYPE_p_p_switch_sql_queue_manager qmp, uint numq, string dsn, string pre_trans_execute, string post_trans_execute, string inner_pre_trans_execute, string inner_post_trans_execute) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_sql_queue_manager_init_name(name, SWIGTYPE_p_p_switch_sql_queue_manager.getCPtr(qmp), numq, dsn, pre_trans_execute, post_trans_execute, inner_pre_trans_execute, inner_post_trans_execute);
+    return ret;
+  }
+
+  public static switch_status_t switch_sql_queue_manager_start(SWIGTYPE_p_switch_sql_queue_manager qm) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_sql_queue_manager_start(SWIGTYPE_p_switch_sql_queue_manager.getCPtr(qm));
+    return ret;
+  }
+
+  public static switch_status_t switch_sql_queue_manager_stop(SWIGTYPE_p_switch_sql_queue_manager qm) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_sql_queue_manager_stop(SWIGTYPE_p_switch_sql_queue_manager.getCPtr(qm));
+    return ret;
+  }
+
+  public static switch_status_t switch_cache_db_execute_sql_event_callback(SWIGTYPE_p_switch_cache_db_handle dbh, string sql, SWIGTYPE_p_f_p_void_p_switch_event__int callback, SWIGTYPE_p_void pdata, ref string err) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_cache_db_execute_sql_event_callback(SWIGTYPE_p_switch_cache_db_handle.getCPtr(dbh), sql, SWIGTYPE_p_f_p_void_p_switch_event__int.getCPtr(callback), SWIGTYPE_p_void.getCPtr(pdata), ref err);
+    return ret;
+  }
+
+  public static SWIGTYPE_p_pid_t switch_fork() {
+    SWIGTYPE_p_pid_t ret = new SWIGTYPE_p_pid_t(freeswitchPINVOKE.switch_fork(), true);
+    return ret;
+  }
+
   public static switch_status_t switch_loadable_module_init(switch_bool_t autoload) {
     switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_loadable_module_init((int)autoload);
     return ret;
@@ -3163,6 +3249,16 @@ public class freeswitch {
     return ret;
   }
 
+  public static SWIGTYPE_p_switch_size_t switch_fd_read_dline(int fd, ref string buf, SWIGTYPE_p_switch_size_t len) {
+    SWIGTYPE_p_switch_size_t ret = new SWIGTYPE_p_switch_size_t(freeswitchPINVOKE.switch_fd_read_dline(fd, ref buf, SWIGTYPE_p_switch_size_t.getCPtr(len)), true);
+    return ret;
+  }
+
+  public static SWIGTYPE_p_switch_size_t switch_fp_read_dline(SWIGTYPE_p_FILE fd, ref string buf, SWIGTYPE_p_switch_size_t len) {
+    SWIGTYPE_p_switch_size_t ret = new SWIGTYPE_p_switch_size_t(freeswitchPINVOKE.switch_fp_read_dline(SWIGTYPE_p_FILE.getCPtr(fd), ref buf, SWIGTYPE_p_switch_size_t.getCPtr(len)), true);
+    return ret;
+  }
+
   public static switch_status_t switch_frame_alloc(SWIGTYPE_p_p_switch_frame frame, SWIGTYPE_p_switch_size_t size) {
     switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_frame_alloc(SWIGTYPE_p_p_switch_frame.getCPtr(frame), SWIGTYPE_p_switch_size_t.getCPtr(size));
     if (freeswitchPINVOKE.SWIGPendingException.Pending) throw freeswitchPINVOKE.SWIGPendingException.Retrieve();
@@ -4147,8 +4243,8 @@ public class freeswitch {
     return ret;
   }
 
-  public static switch_call_cause_t switch_channel_str2callstate(string str) {
-    switch_call_cause_t ret = (switch_call_cause_t)freeswitchPINVOKE.switch_channel_str2callstate(str);
+  public static switch_channel_callstate_t switch_channel_str2callstate(string str) {
+    switch_channel_callstate_t ret = (switch_channel_callstate_t)freeswitchPINVOKE.switch_channel_str2callstate(str);
     return ret;
   }
 
@@ -4181,6 +4277,12 @@ public class freeswitch {
     return ret;
   }
 
+  public static switch_hold_record_t switch_channel_get_hold_record(SWIGTYPE_p_switch_channel channel) {
+    IntPtr cPtr = freeswitchPINVOKE.switch_channel_get_hold_record(SWIGTYPE_p_switch_channel.getCPtr(channel));
+    switch_hold_record_t ret = (cPtr == IntPtr.Zero) ? null : new switch_hold_record_t(cPtr, false);
+    return ret;
+  }
+
   public static switch_status_t switch_buffer_create(SWIGTYPE_p_apr_pool_t pool, SWIGTYPE_p_p_switch_buffer buffer, SWIGTYPE_p_switch_size_t max_len) {
     switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_buffer_create(SWIGTYPE_p_apr_pool_t.getCPtr(pool), SWIGTYPE_p_p_switch_buffer.getCPtr(buffer), SWIGTYPE_p_switch_size_t.getCPtr(max_len));
     if (freeswitchPINVOKE.SWIGPendingException.Pending) throw freeswitchPINVOKE.SWIGPendingException.Retrieve();
@@ -4412,6 +4514,17 @@ public class freeswitch {
     return ret;
   }
 
+  public static switch_status_t switch_event_binary_deserialize(SWIGTYPE_p_p_switch_event eventp, SWIGTYPE_p_p_void data, SWIGTYPE_p_switch_size_t len, switch_bool_t destroy) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_event_binary_deserialize(SWIGTYPE_p_p_switch_event.getCPtr(eventp), SWIGTYPE_p_p_void.getCPtr(data), SWIGTYPE_p_switch_size_t.getCPtr(len), (int)destroy);
+    if (freeswitchPINVOKE.SWIGPendingException.Pending) throw freeswitchPINVOKE.SWIGPendingException.Retrieve();
+    return ret;
+  }
+
+  public static switch_status_t switch_event_binary_serialize(switch_event arg0, SWIGTYPE_p_p_void data, SWIGTYPE_p_switch_size_t len) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_event_binary_serialize(switch_event.getCPtr(arg0), SWIGTYPE_p_p_void.getCPtr(data), SWIGTYPE_p_switch_size_t.getCPtr(len));
+    return ret;
+  }
+
   public static switch_status_t switch_event_serialize(switch_event arg0, ref string str, switch_bool_t encode) {
     switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_event_serialize(switch_event.getCPtr(arg0), ref str, (int)encode);
     return ret;
@@ -4432,6 +4545,11 @@ public class freeswitch {
     return ret;
   }
 
+  public static switch_status_t switch_event_create_array_pair(SWIGTYPE_p_p_switch_event arg0, ref string names, ref string vals, int len) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_event_create_array_pair(SWIGTYPE_p_p_switch_event.getCPtr(arg0), ref names, ref vals, len);
+    return ret;
+  }
+
   public static switch_status_t switch_event_running() {
     switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_event_running();
     return ret;
@@ -5379,6 +5497,12 @@ public class freeswitch {
     return ret;
   }
 
+  public static SWIGTYPE_p_stfu_instance_t switch_rtp_get_jitter_buffer(SWIGTYPE_p_switch_rtp rtp_session) {
+    IntPtr cPtr = freeswitchPINVOKE.switch_rtp_get_jitter_buffer(SWIGTYPE_p_switch_rtp.getCPtr(rtp_session));
+    SWIGTYPE_p_stfu_instance_t ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_stfu_instance_t(cPtr, false);
+    return ret;
+  }
+
   public static void switch_rtp_set_flag(SWIGTYPE_p_switch_rtp rtp_session, uint flags) {
     freeswitchPINVOKE.switch_rtp_set_flag(SWIGTYPE_p_switch_rtp.getCPtr(rtp_session), flags);
   }
@@ -5665,6 +5789,11 @@ public class freeswitch {
     return ret;
   }
 
+  public static string switch_xml_tohtml(switch_xml xml, switch_bool_t prn_header) {
+    string ret = freeswitchPINVOKE.switch_xml_tohtml(switch_xml.getCPtr(xml), (int)prn_header);
+    return ret;
+  }
+
   public static string switch_xml_toxml_buf(switch_xml xml, string buf, SWIGTYPE_p_switch_size_t buflen, SWIGTYPE_p_switch_size_t offset, switch_bool_t prn_header) {
     string ret = freeswitchPINVOKE.switch_xml_toxml_buf(switch_xml.getCPtr(xml), buf, SWIGTYPE_p_switch_size_t.getCPtr(buflen), SWIGTYPE_p_switch_size_t.getCPtr(offset), (int)prn_header);
     if (freeswitchPINVOKE.SWIGPendingException.Pending) throw freeswitchPINVOKE.SWIGPendingException.Retrieve();
@@ -6129,6 +6258,7 @@ public class freeswitch {
   public static readonly string SWITCH_SEQ_CLEARLINEEND = freeswitchPINVOKE.SWITCH_SEQ_CLEARLINEEND_get();
   public static readonly string SWITCH_SEQ_CLEARSCR = freeswitchPINVOKE.SWITCH_SEQ_CLEARSCR_get();
   public static readonly string SWITCH_DEFAULT_CLID_NAME = freeswitchPINVOKE.SWITCH_DEFAULT_CLID_NAME_get();
+  public static readonly string SWITCH_DEFAULT_CLID_NUMBER = freeswitchPINVOKE.SWITCH_DEFAULT_CLID_NUMBER_get();
   public static readonly int SWITCH_DEFAULT_DTMF_DURATION = freeswitchPINVOKE.SWITCH_DEFAULT_DTMF_DURATION_get();
   public static readonly int SWITCH_MIN_DTMF_DURATION = freeswitchPINVOKE.SWITCH_MIN_DTMF_DURATION_get();
   public static readonly int SWITCH_MAX_DTMF_DURATION = freeswitchPINVOKE.SWITCH_MAX_DTMF_DURATION_get();
@@ -6174,6 +6304,7 @@ public class freeswitch {
   public static readonly string SWITCH_API_REPORTING_HOOK_VARIABLE = freeswitchPINVOKE.SWITCH_API_REPORTING_HOOK_VARIABLE_get();
   public static readonly string SWITCH_SESSION_IN_HANGUP_HOOK_VARIABLE = freeswitchPINVOKE.SWITCH_SESSION_IN_HANGUP_HOOK_VARIABLE_get();
   public static readonly string SWITCH_PROCESS_CDR_VARIABLE = freeswitchPINVOKE.SWITCH_PROCESS_CDR_VARIABLE_get();
+  public static readonly string SWITCH_SKIP_CDR_CAUSES_VARIABLE = freeswitchPINVOKE.SWITCH_SKIP_CDR_CAUSES_VARIABLE_get();
   public static readonly string SWITCH_FORCE_PROCESS_CDR_VARIABLE = freeswitchPINVOKE.SWITCH_FORCE_PROCESS_CDR_VARIABLE_get();
   public static readonly string SWITCH_BRIDGE_CHANNEL_VARIABLE = freeswitchPINVOKE.SWITCH_BRIDGE_CHANNEL_VARIABLE_get();
   public static readonly string SWITCH_CHANNEL_NAME_VARIABLE = freeswitchPINVOKE.SWITCH_CHANNEL_NAME_VARIABLE_get();
@@ -6644,6 +6775,9 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp_SWITCH_DEFAULT_CLID_NAME_get")]
   public static extern string SWITCH_DEFAULT_CLID_NAME_get();
 
+  [DllImport("mod_managed", EntryPoint="CSharp_SWITCH_DEFAULT_CLID_NUMBER_get")]
+  public static extern string SWITCH_DEFAULT_CLID_NUMBER_get();
+
   [DllImport("mod_managed", EntryPoint="CSharp_SWITCH_DEFAULT_DTMF_DURATION_get")]
   public static extern int SWITCH_DEFAULT_DTMF_DURATION_get();
 
@@ -6779,6 +6913,9 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp_SWITCH_PROCESS_CDR_VARIABLE_get")]
   public static extern string SWITCH_PROCESS_CDR_VARIABLE_get();
 
+  [DllImport("mod_managed", EntryPoint="CSharp_SWITCH_SKIP_CDR_CAUSES_VARIABLE_get")]
+  public static extern string SWITCH_SKIP_CDR_CAUSES_VARIABLE_get();
+
   [DllImport("mod_managed", EntryPoint="CSharp_SWITCH_FORCE_PROCESS_CDR_VARIABLE_get")]
   public static extern string SWITCH_FORCE_PROCESS_CDR_VARIABLE_get();
 
@@ -7967,6 +8104,60 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp_delete_switch_app_log")]
   public static extern void delete_switch_app_log(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_hold_record_t_on_set")]
+  public static extern void switch_hold_record_t_on_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_hold_record_t_on_get")]
+  public static extern IntPtr switch_hold_record_t_on_get(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_hold_record_t_off_set")]
+  public static extern void switch_hold_record_t_off_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_hold_record_t_off_get")]
+  public static extern IntPtr switch_hold_record_t_off_get(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_hold_record_t_uuid_set")]
+  public static extern void switch_hold_record_t_uuid_set(HandleRef jarg1, string jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_hold_record_t_uuid_get")]
+  public static extern string switch_hold_record_t_uuid_get(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_hold_record_t_next_set")]
+  public static extern void switch_hold_record_t_next_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_hold_record_t_next_get")]
+  public static extern IntPtr switch_hold_record_t_next_get(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_new_switch_hold_record_t")]
+  public static extern IntPtr new_switch_hold_record_t();
+
+  [DllImport("mod_managed", EntryPoint="CSharp_delete_switch_hold_record_t")]
+  public static extern void delete_switch_hold_record_t(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_thread_data_t_func_set")]
+  public static extern void switch_thread_data_t_func_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_thread_data_t_func_get")]
+  public static extern IntPtr switch_thread_data_t_func_get(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_thread_data_t_obj_set")]
+  public static extern void switch_thread_data_t_obj_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_thread_data_t_obj_get")]
+  public static extern IntPtr switch_thread_data_t_obj_get(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_thread_data_t_alloc_set")]
+  public static extern void switch_thread_data_t_alloc_set(HandleRef jarg1, int jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_thread_data_t_alloc_get")]
+  public static extern int switch_thread_data_t_alloc_get(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_new_switch_thread_data_t")]
+  public static extern IntPtr new_switch_thread_data_t();
+
+  [DllImport("mod_managed", EntryPoint="CSharp_delete_switch_thread_data_t")]
+  public static extern void delete_switch_thread_data_t(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_MESSAGE_STRING_ARG_MAX_get")]
   public static extern int MESSAGE_STRING_ARG_MAX_get();
 
@@ -8120,6 +8311,9 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp_delete_switch_core_thread_session")]
   public static extern void delete_switch_core_thread_session(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_core_screen_size")]
+  public static extern void switch_core_screen_size(HandleRef jarg1, HandleRef jarg2);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_core_session_sched_heartbeat")]
   public static extern void switch_core_session_sched_heartbeat(HandleRef jarg1, uint jarg2);
 
@@ -8372,6 +8566,9 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp_switch_core_session_thread_launch")]
   public static extern int switch_core_session_thread_launch(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_thread_pool_launch_thread")]
+  public static extern int switch_thread_pool_launch_thread(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_core_session_thread_pool_launch")]
   public static extern int switch_core_session_thread_pool_launch(HandleRef jarg1);
 
@@ -8393,6 +8590,9 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp_switch_core_session_get_loglevel")]
   public static extern int switch_core_session_get_loglevel(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_core_session_get_jb")]
+  public static extern IntPtr switch_core_session_get_jb(HandleRef jarg1, int jarg2);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_core_session_soft_lock")]
   public static extern void switch_core_session_soft_lock(HandleRef jarg1, uint jarg2);
 
@@ -8453,6 +8653,9 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp_switch_core_session_hupall_matching_var")]
   public static extern void switch_core_session_hupall_matching_var(string jarg1, string jarg2, int jarg3);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_core_session_findall_matching_var")]
+  public static extern IntPtr switch_core_session_findall_matching_var(string jarg1, string jarg2);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_core_session_hupall_endpoint")]
   public static extern void switch_core_session_hupall_endpoint(HandleRef jarg1, int jarg2);
 
@@ -8639,6 +8842,15 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp_switch_core_hash_find_rdlock")]
   public static extern IntPtr switch_core_hash_find_rdlock(HandleRef jarg1, string jarg2, HandleRef jarg3);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_core_hash_first")]
+  public static extern IntPtr switch_core_hash_first(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_core_hash_next")]
+  public static extern IntPtr switch_core_hash_next(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_core_hash_this")]
+  public static extern void switch_core_hash_this(HandleRef jarg1, HandleRef jarg2, HandleRef jarg3, HandleRef jarg4);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_hash_first")]
   public static extern IntPtr switch_hash_first(string jarg1, HandleRef jarg2);
 
@@ -9089,6 +9301,12 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp_switch_cache_db_native_handle_t_odbc_dbh_get")]
   public static extern IntPtr switch_cache_db_native_handle_t_odbc_dbh_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_cache_db_native_handle_t_pgsql_dbh_set")]
+  public static extern void switch_cache_db_native_handle_t_pgsql_dbh_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_cache_db_native_handle_t_pgsql_dbh_get")]
+  public static extern IntPtr switch_cache_db_native_handle_t_pgsql_dbh_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_new_switch_cache_db_native_handle_t")]
   public static extern IntPtr new_switch_cache_db_native_handle_t();
 
@@ -9131,6 +9349,18 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp_delete_switch_cache_db_odbc_options_t")]
   public static extern void delete_switch_cache_db_odbc_options_t(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_cache_db_pgsql_options_t_dsn_set")]
+  public static extern void switch_cache_db_pgsql_options_t_dsn_set(HandleRef jarg1, string jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_cache_db_pgsql_options_t_dsn_get")]
+  public static extern string switch_cache_db_pgsql_options_t_dsn_get(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_new_switch_cache_db_pgsql_options_t")]
+  public static extern IntPtr new_switch_cache_db_pgsql_options_t();
+
+  [DllImport("mod_managed", EntryPoint="CSharp_delete_switch_cache_db_pgsql_options_t")]
+  public static extern void delete_switch_cache_db_pgsql_options_t(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_cache_db_connection_options_t_core_db_options_set")]
   public static extern void switch_cache_db_connection_options_t_core_db_options_set(HandleRef jarg1, HandleRef jarg2);
 
@@ -9143,6 +9373,12 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp_switch_cache_db_connection_options_t_odbc_options_get")]
   public static extern IntPtr switch_cache_db_connection_options_t_odbc_options_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_cache_db_connection_options_t_pgsql_options_set")]
+  public static extern void switch_cache_db_connection_options_t_pgsql_options_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_cache_db_connection_options_t_pgsql_options_get")]
+  public static extern IntPtr switch_cache_db_connection_options_t_pgsql_options_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_new_switch_cache_db_connection_options_t")]
   public static extern IntPtr new_switch_cache_db_connection_options_t();
 
@@ -9164,6 +9400,9 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp__switch_cache_db_get_db_handle")]
   public static extern int _switch_cache_db_get_db_handle(HandleRef jarg1, int jarg2, HandleRef jarg3, string jarg4, string jarg5, int jarg6);
 
+  [DllImport("mod_managed", EntryPoint="CSharp__switch_cache_db_get_db_handle_dsn")]
+  public static extern int _switch_cache_db_get_db_handle_dsn(HandleRef jarg1, string jarg2, string jarg3, string jarg4, int jarg5);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_cache_db_execute_sql2str")]
   public static extern string switch_cache_db_execute_sql2str(HandleRef jarg1, string jarg2, string jarg3, uint jarg4, ref string jarg5);
 
@@ -9182,17 +9421,14 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp__switch_core_db_handle")]
   public static extern int _switch_core_db_handle(HandleRef jarg1, string jarg2, string jarg3, int jarg4);
 
-  [DllImport("mod_managed", EntryPoint="CSharp__switch_core_recovery_db_handle")]
-  public static extern int _switch_core_recovery_db_handle(HandleRef jarg1, string jarg2, string jarg3, int jarg4);
-
   [DllImport("mod_managed", EntryPoint="CSharp_switch_cache_db_test_reactive")]
   public static extern int switch_cache_db_test_reactive(HandleRef jarg1, string jarg2, string jarg3, string jarg4);
 
   [DllImport("mod_managed", EntryPoint="CSharp_switch_cache_db_persistant_execute")]
   public static extern int switch_cache_db_persistant_execute(HandleRef jarg1, string jarg2, uint jarg3);
 
-  [DllImport("mod_managed", EntryPoint="CSharp_switch_cache_db_persistant_execute_trans")]
-  public static extern int switch_cache_db_persistant_execute_trans(HandleRef jarg1, string jarg2, uint jarg3);
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_cache_db_persistant_execute_trans_full")]
+  public static extern int switch_cache_db_persistant_execute_trans_full(HandleRef jarg1, string jarg2, uint jarg3, string jarg4, string jarg5, string jarg6, string jarg7);
 
   [DllImport("mod_managed", EntryPoint="CSharp_switch_core_set_signal_handlers")]
   public static extern void switch_core_set_signal_handlers();
@@ -9254,6 +9490,12 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp_switch_core_get_stacksizes")]
   public static extern int switch_core_get_stacksizes(HandleRef jarg1, HandleRef jarg2);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_core_dbtype")]
+  public static extern int switch_core_dbtype();
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_core_sql_exec")]
+  public static extern void switch_core_sql_exec(string jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_core_recovery_recover")]
   public static extern int switch_core_recovery_recover(string jarg1, string jarg2);
 
@@ -9266,6 +9508,30 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp_switch_core_recovery_flush")]
   public static extern void switch_core_recovery_flush(string jarg1, string jarg2);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_sql_queue_manager_push_confirm")]
+  public static extern int switch_sql_queue_manager_push_confirm(HandleRef jarg1, string jarg2, uint jarg3, int jarg4);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_sql_queue_manager_push")]
+  public static extern int switch_sql_queue_manager_push(HandleRef jarg1, string jarg2, uint jarg3, int jarg4);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_sql_queue_manager_destroy")]
+  public static extern int switch_sql_queue_manager_destroy(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_sql_queue_manager_init_name")]
+  public static extern int switch_sql_queue_manager_init_name(string jarg1, HandleRef jarg2, uint jarg3, string jarg4, string jarg5, string jarg6, string jarg7, string jarg8);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_sql_queue_manager_start")]
+  public static extern int switch_sql_queue_manager_start(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_sql_queue_manager_stop")]
+  public static extern int switch_sql_queue_manager_stop(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_cache_db_execute_sql_event_callback")]
+  public static extern int switch_cache_db_execute_sql_event_callback(HandleRef jarg1, string jarg2, HandleRef jarg3, HandleRef jarg4, ref string jarg5);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_fork")]
+  public static extern IntPtr switch_fork();
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_loadable_module_interface_module_name_set")]
   public static extern void switch_loadable_module_interface_module_name_set(HandleRef jarg1, string jarg2);
 
@@ -9632,6 +9898,12 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp_switch_fd_read_line")]
   public static extern IntPtr switch_fd_read_line(int jarg1, string jarg2, HandleRef jarg3);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_fd_read_dline")]
+  public static extern IntPtr switch_fd_read_dline(int jarg1, ref string jarg2, HandleRef jarg3);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_fp_read_dline")]
+  public static extern IntPtr switch_fp_read_dline(HandleRef jarg1, ref string jarg2, HandleRef jarg3);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_frame_alloc")]
   public static extern int switch_frame_alloc(HandleRef jarg1, HandleRef jarg2);
 
@@ -10058,6 +10330,12 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp_switch_caller_profile_times_get")]
   public static extern IntPtr switch_caller_profile_times_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_caller_profile_old_times_set")]
+  public static extern void switch_caller_profile_old_times_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_caller_profile_old_times_get")]
+  public static extern IntPtr switch_caller_profile_old_times_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_caller_profile_caller_extension_set")]
   public static extern void switch_caller_profile_caller_extension_set(HandleRef jarg1, HandleRef jarg2);
 
@@ -10313,6 +10591,12 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp_switch_frame_flags_get")]
   public static extern uint switch_frame_flags_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_frame_user_data_set")]
+  public static extern void switch_frame_user_data_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_frame_user_data_get")]
+  public static extern IntPtr switch_frame_user_data_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_new_switch_frame")]
   public static extern IntPtr new_switch_frame();
 
@@ -10535,6 +10819,12 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp_switch_io_routines_state_run_get")]
   public static extern IntPtr switch_io_routines_state_run_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_io_routines_get_jb_set")]
+  public static extern void switch_io_routines_get_jb_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_io_routines_get_jb_get")]
+  public static extern IntPtr switch_io_routines_get_jb_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_io_routines_padding_set")]
   public static extern void switch_io_routines_padding_set(HandleRef jarg1, HandleRef jarg2);
 
@@ -11339,6 +11629,42 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp_switch_asr_handle_memory_pool_get")]
   public static extern IntPtr switch_asr_handle_memory_pool_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_asr_handle_buffer_set")]
+  public static extern void switch_asr_handle_buffer_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_asr_handle_buffer_get")]
+  public static extern IntPtr switch_asr_handle_buffer_get(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_asr_handle_dbuf_set")]
+  public static extern void switch_asr_handle_dbuf_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_asr_handle_dbuf_get")]
+  public static extern IntPtr switch_asr_handle_dbuf_get(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_asr_handle_dbuflen_set")]
+  public static extern void switch_asr_handle_dbuflen_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_asr_handle_dbuflen_get")]
+  public static extern IntPtr switch_asr_handle_dbuflen_get(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_asr_handle_resampler_set")]
+  public static extern void switch_asr_handle_resampler_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_asr_handle_resampler_get")]
+  public static extern IntPtr switch_asr_handle_resampler_get(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_asr_handle_samplerate_set")]
+  public static extern void switch_asr_handle_samplerate_set(HandleRef jarg1, uint jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_asr_handle_samplerate_get")]
+  public static extern uint switch_asr_handle_samplerate_get(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_asr_handle_native_rate_set")]
+  public static extern void switch_asr_handle_native_rate_set(HandleRef jarg1, uint jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_asr_handle_native_rate_get")]
+  public static extern uint switch_asr_handle_native_rate_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_asr_handle_private_info_set")]
   public static extern void switch_asr_handle_private_info_set(HandleRef jarg1, HandleRef jarg2);
 
@@ -11981,6 +12307,12 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp_switch_codec_next_get")]
   public static extern IntPtr switch_codec_next_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_codec_session_set")]
+  public static extern void switch_codec_session_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_codec_session_get")]
+  public static extern IntPtr switch_codec_session_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_new_switch_codec")]
   public static extern IntPtr new_switch_codec();
 
@@ -12857,6 +13189,9 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp_switch_channel_get_partner_uuid")]
   public static extern string switch_channel_get_partner_uuid(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_channel_get_hold_record")]
+  public static extern IntPtr switch_channel_get_hold_record(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_buffer_create")]
   public static extern int switch_buffer_create(HandleRef jarg1, HandleRef jarg2, HandleRef jarg3);
 
@@ -13037,6 +13372,66 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp_delete_switch_event")]
   public static extern void delete_switch_event(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_serial_event_t_event_id_set")]
+  public static extern void switch_serial_event_t_event_id_set(HandleRef jarg1, int jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_serial_event_t_event_id_get")]
+  public static extern int switch_serial_event_t_event_id_get(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_serial_event_t_priority_set")]
+  public static extern void switch_serial_event_t_priority_set(HandleRef jarg1, int jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_serial_event_t_priority_get")]
+  public static extern int switch_serial_event_t_priority_get(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_serial_event_t_flags_set")]
+  public static extern void switch_serial_event_t_flags_set(HandleRef jarg1, int jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_serial_event_t_flags_get")]
+  public static extern int switch_serial_event_t_flags_get(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_serial_event_t_owner_set")]
+  public static extern void switch_serial_event_t_owner_set(HandleRef jarg1, string jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_serial_event_t_owner_get")]
+  public static extern string switch_serial_event_t_owner_get(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_serial_event_t_subclass_name_set")]
+  public static extern void switch_serial_event_t_subclass_name_set(HandleRef jarg1, string jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_serial_event_t_subclass_name_get")]
+  public static extern string switch_serial_event_t_subclass_name_get(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_serial_event_t_body_set")]
+  public static extern void switch_serial_event_t_body_set(HandleRef jarg1, string jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_serial_event_t_body_get")]
+  public static extern string switch_serial_event_t_body_get(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_new_switch_serial_event_t")]
+  public static extern IntPtr new_switch_serial_event_t();
+
+  [DllImport("mod_managed", EntryPoint="CSharp_delete_switch_serial_event_t")]
+  public static extern void delete_switch_serial_event_t(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_serial_event_header_t_name_set")]
+  public static extern void switch_serial_event_header_t_name_set(HandleRef jarg1, string jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_serial_event_header_t_name_get")]
+  public static extern string switch_serial_event_header_t_name_get(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_serial_event_header_t_value_set")]
+  public static extern void switch_serial_event_header_t_value_set(HandleRef jarg1, string jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_serial_event_header_t_value_get")]
+  public static extern string switch_serial_event_header_t_value_get(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_new_switch_serial_event_header_t")]
+  public static extern IntPtr new_switch_serial_event_header_t();
+
+  [DllImport("mod_managed", EntryPoint="CSharp_delete_switch_serial_event_header_t")]
+  public static extern void delete_switch_serial_event_header_t(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_event_init")]
   public static extern int switch_event_init(HandleRef jarg1);
 
@@ -13115,6 +13510,12 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp_switch_event_free_subclass_detailed")]
   public static extern int switch_event_free_subclass_detailed(string jarg1, string jarg2);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_event_binary_deserialize")]
+  public static extern int switch_event_binary_deserialize(HandleRef jarg1, HandleRef jarg2, HandleRef jarg3, int jarg4);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_event_binary_serialize")]
+  public static extern int switch_event_binary_serialize(HandleRef jarg1, HandleRef jarg2, HandleRef jarg3);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_event_serialize")]
   public static extern int switch_event_serialize(HandleRef jarg1, ref string jarg2, int jarg3);
 
@@ -13127,6 +13528,9 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp_switch_event_create_brackets")]
   public static extern int switch_event_create_brackets(string jarg1, char jarg2, char jarg3, char jarg4, HandleRef jarg5, ref string jarg6, int jarg7);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_event_create_array_pair")]
+  public static extern int switch_event_create_array_pair(HandleRef jarg1, ref string jarg2, ref string jarg3, int jarg4);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_event_running")]
   public static extern int switch_event_running();
 
@@ -13919,6 +14323,9 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp_switch_rtp_pause_jitter_buffer")]
   public static extern int switch_rtp_pause_jitter_buffer(HandleRef jarg1, int jarg2);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_rtp_get_jitter_buffer")]
+  public static extern IntPtr switch_rtp_get_jitter_buffer(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_rtp_set_flag")]
   public static extern void switch_rtp_set_flag(HandleRef jarg1, uint jarg2);
 
@@ -14075,6 +14482,12 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp_switch_log_node_t_channel_get")]
   public static extern int switch_log_node_t_channel_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_log_node_t_slevel_set")]
+  public static extern void switch_log_node_t_slevel_set(HandleRef jarg1, int jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_log_node_t_slevel_get")]
+  public static extern int switch_log_node_t_slevel_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_new_switch_log_node_t")]
   public static extern IntPtr new_switch_log_node_t();
 
@@ -14237,6 +14650,9 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp_switch_xml_toxml_nolock")]
   public static extern string switch_xml_toxml_nolock(HandleRef jarg1, int jarg2);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_xml_tohtml")]
+  public static extern string switch_xml_tohtml(HandleRef jarg1, int jarg2);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_xml_toxml_buf")]
   public static extern string switch_xml_toxml_buf(HandleRef jarg1, string jarg2, HandleRef jarg3, HandleRef jarg4, int jarg5);
 
@@ -16565,6 +16981,36 @@ namespace FreeSWITCH.Native {
 using System;
 using System.Runtime.InteropServices;
 
+public class SWIGTYPE_p_f_p_switch_core_session_enum_switch_media_type_t__p_stfu_instance_t {
+  private HandleRef swigCPtr;
+
+  internal SWIGTYPE_p_f_p_switch_core_session_enum_switch_media_type_t__p_stfu_instance_t(IntPtr cPtr, bool futureUse) {
+    swigCPtr = new HandleRef(this, cPtr);
+  }
+
+  protected SWIGTYPE_p_f_p_switch_core_session_enum_switch_media_type_t__p_stfu_instance_t() {
+    swigCPtr = new HandleRef(null, IntPtr.Zero);
+  }
+
+  internal static HandleRef getCPtr(SWIGTYPE_p_f_p_switch_core_session_enum_switch_media_type_t__p_stfu_instance_t obj) {
+    return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
+  }
+}
+
+}
+/* ----------------------------------------------------------------------------
+ * This file was automatically generated by SWIG (http://www.swig.org).
+ * Version 1.3.35
+ *
+ * Do not make changes to this file unless you know what you are doing--modify
+ * the SWIG interface file instead.
+ * ----------------------------------------------------------------------------- */
+
+namespace FreeSWITCH.Native {
+
+using System;
+using System.Runtime.InteropServices;
+
 public class SWIGTYPE_p_f_p_switch_core_session__int {
   private HandleRef swigCPtr;
 
@@ -18185,6 +18631,36 @@ namespace FreeSWITCH.Native {
 using System;
 using System.Runtime.InteropServices;
 
+public class SWIGTYPE_p_f_p_void_p_switch_event__int {
+  private HandleRef swigCPtr;
+
+  internal SWIGTYPE_p_f_p_void_p_switch_event__int(IntPtr cPtr, bool futureUse) {
+    swigCPtr = new HandleRef(this, cPtr);
+  }
+
+  protected SWIGTYPE_p_f_p_void_p_switch_event__int() {
+    swigCPtr = new HandleRef(null, IntPtr.Zero);
+  }
+
+  internal static HandleRef getCPtr(SWIGTYPE_p_f_p_void_p_switch_event__int obj) {
+    return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
+  }
+}
+
+}
+/* ----------------------------------------------------------------------------
+ * This file was automatically generated by SWIG (http://www.swig.org).
+ * Version 1.3.35
+ *
+ * Do not make changes to this file unless you know what you are doing--modify
+ * the SWIG interface file instead.
+ * ----------------------------------------------------------------------------- */
+
+namespace FreeSWITCH.Native {
+
+using System;
+using System.Runtime.InteropServices;
+
 public class SWIGTYPE_p_f_p_void__void {
   private HandleRef swigCPtr;
 
@@ -18485,6 +18961,36 @@ namespace FreeSWITCH.Native {
 using System;
 using System.Runtime.InteropServices;
 
+public class SWIGTYPE_p_pid_t {
+  private HandleRef swigCPtr;
+
+  internal SWIGTYPE_p_pid_t(IntPtr cPtr, bool futureUse) {
+    swigCPtr = new HandleRef(this, cPtr);
+  }
+
+  protected SWIGTYPE_p_pid_t() {
+    swigCPtr = new HandleRef(null, IntPtr.Zero);
+  }
+
+  internal static HandleRef getCPtr(SWIGTYPE_p_pid_t obj) {
+    return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
+  }
+}
+
+}
+/* ----------------------------------------------------------------------------
+ * This file was automatically generated by SWIG (http://www.swig.org).
+ * Version 1.3.35
+ *
+ * Do not make changes to this file unless you know what you are doing--modify
+ * the SWIG interface file instead.
+ * ----------------------------------------------------------------------------- */
+
+namespace FreeSWITCH.Native {
+
+using System;
+using System.Runtime.InteropServices;
+
 public class SWIGTYPE_p_p_p_char {
   private HandleRef swigCPtr;
 
@@ -19385,6 +19891,66 @@ namespace FreeSWITCH.Native {
 using System;
 using System.Runtime.InteropServices;
 
+public class SWIGTYPE_p_p_switch_sql_queue_manager {
+  private HandleRef swigCPtr;
+
+  internal SWIGTYPE_p_p_switch_sql_queue_manager(IntPtr cPtr, bool futureUse) {
+    swigCPtr = new HandleRef(this, cPtr);
+  }
+
+  protected SWIGTYPE_p_p_switch_sql_queue_manager() {
+    swigCPtr = new HandleRef(null, IntPtr.Zero);
+  }
+
+  internal static HandleRef getCPtr(SWIGTYPE_p_p_switch_sql_queue_manager obj) {
+    return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
+  }
+}
+
+}
+/* ----------------------------------------------------------------------------
+ * This file was automatically generated by SWIG (http://www.swig.org).
+ * Version 1.3.35
+ *
+ * Do not make changes to this file unless you know what you are doing--modify
+ * the SWIG interface file instead.
+ * ----------------------------------------------------------------------------- */
+
+namespace FreeSWITCH.Native {
+
+using System;
+using System.Runtime.InteropServices;
+
+public class SWIGTYPE_p_p_switch_thread_data_s {
+  private HandleRef swigCPtr;
+
+  internal SWIGTYPE_p_p_switch_thread_data_s(IntPtr cPtr, bool futureUse) {
+    swigCPtr = new HandleRef(this, cPtr);
+  }
+
+  protected SWIGTYPE_p_p_switch_thread_data_s() {
+    swigCPtr = new HandleRef(null, IntPtr.Zero);
+  }
+
+  internal static HandleRef getCPtr(SWIGTYPE_p_p_switch_thread_data_s obj) {
+    return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
+  }
+}
+
+}
+/* ----------------------------------------------------------------------------
+ * This file was automatically generated by SWIG (http://www.swig.org).
+ * Version 1.3.35
+ *
+ * Do not make changes to this file unless you know what you are doing--modify
+ * the SWIG interface file instead.
+ * ----------------------------------------------------------------------------- */
+
+namespace FreeSWITCH.Native {
+
+using System;
+using System.Runtime.InteropServices;
+
 public class SWIGTYPE_p_p_switch_xml_binding {
   private HandleRef swigCPtr;
 
@@ -19685,6 +20251,36 @@ namespace FreeSWITCH.Native {
 using System;
 using System.Runtime.InteropServices;
 
+public class SWIGTYPE_p_stfu_instance_t {
+  private HandleRef swigCPtr;
+
+  internal SWIGTYPE_p_stfu_instance_t(IntPtr cPtr, bool futureUse) {
+    swigCPtr = new HandleRef(this, cPtr);
+  }
+
+  protected SWIGTYPE_p_stfu_instance_t() {
+    swigCPtr = new HandleRef(null, IntPtr.Zero);
+  }
+
+  internal static HandleRef getCPtr(SWIGTYPE_p_stfu_instance_t obj) {
+    return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
+  }
+}
+
+}
+/* ----------------------------------------------------------------------------
+ * This file was automatically generated by SWIG (http://www.swig.org).
+ * Version 1.3.35
+ *
+ * Do not make changes to this file unless you know what you are doing--modify
+ * the SWIG interface file instead.
+ * ----------------------------------------------------------------------------- */
+
+namespace FreeSWITCH.Native {
+
+using System;
+using System.Runtime.InteropServices;
+
 public class SWIGTYPE_p_switch_buffer {
   private HandleRef swigCPtr;
 
@@ -20315,6 +20911,36 @@ namespace FreeSWITCH.Native {
 using System;
 using System.Runtime.InteropServices;
 
+public class SWIGTYPE_p_switch_pgsql_handle {
+  private HandleRef swigCPtr;
+
+  internal SWIGTYPE_p_switch_pgsql_handle(IntPtr cPtr, bool futureUse) {
+    swigCPtr = new HandleRef(this, cPtr);
+  }
+
+  protected SWIGTYPE_p_switch_pgsql_handle() {
+    swigCPtr = new HandleRef(null, IntPtr.Zero);
+  }
+
+  internal static HandleRef getCPtr(SWIGTYPE_p_switch_pgsql_handle obj) {
+    return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
+  }
+}
+
+}
+/* ----------------------------------------------------------------------------
+ * This file was automatically generated by SWIG (http://www.swig.org).
+ * Version 1.3.35
+ *
+ * Do not make changes to this file unless you know what you are doing--modify
+ * the SWIG interface file instead.
+ * ----------------------------------------------------------------------------- */
+
+namespace FreeSWITCH.Native {
+
+using System;
+using System.Runtime.InteropServices;
+
 public class SWIGTYPE_p_switch_pollfd_t {
   private HandleRef swigCPtr;
 
@@ -20555,6 +21181,36 @@ namespace FreeSWITCH.Native {
 using System;
 using System.Runtime.InteropServices;
 
+public class SWIGTYPE_p_switch_sql_queue_manager {
+  private HandleRef swigCPtr;
+
+  internal SWIGTYPE_p_switch_sql_queue_manager(IntPtr cPtr, bool futureUse) {
+    swigCPtr = new HandleRef(this, cPtr);
+  }
+
+  protected SWIGTYPE_p_switch_sql_queue_manager() {
+    swigCPtr = new HandleRef(null, IntPtr.Zero);
+  }
+
+  internal static HandleRef getCPtr(SWIGTYPE_p_switch_sql_queue_manager obj) {
+    return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
+  }
+}
+
+}
+/* ----------------------------------------------------------------------------
+ * This file was automatically generated by SWIG (http://www.swig.org).
+ * Version 1.3.35
+ *
+ * Do not make changes to this file unless you know what you are doing--modify
+ * the SWIG interface file instead.
+ * ----------------------------------------------------------------------------- */
+
+namespace FreeSWITCH.Native {
+
+using System;
+using System.Runtime.InteropServices;
+
 public class SWIGTYPE_p_switch_ssize_t {
   private HandleRef swigCPtr;
 
@@ -20615,6 +21271,36 @@ namespace FreeSWITCH.Native {
 using System;
 using System.Runtime.InteropServices;
 
+public class SWIGTYPE_p_switch_thread_start_t {
+  private HandleRef swigCPtr;
+
+  internal SWIGTYPE_p_switch_thread_start_t(IntPtr cPtr, bool futureUse) {
+    swigCPtr = new HandleRef(this, cPtr);
+  }
+
+  protected SWIGTYPE_p_switch_thread_start_t() {
+    swigCPtr = new HandleRef(null, IntPtr.Zero);
+  }
+
+  internal static HandleRef getCPtr(SWIGTYPE_p_switch_thread_start_t obj) {
+    return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
+  }
+}
+
+}
+/* ----------------------------------------------------------------------------
+ * This file was automatically generated by SWIG (http://www.swig.org).
+ * Version 1.3.35
+ *
+ * Do not make changes to this file unless you know what you are doing--modify
+ * the SWIG interface file instead.
+ * ----------------------------------------------------------------------------- */
+
+namespace FreeSWITCH.Native {
+
+using System;
+using System.Runtime.InteropServices;
+
 public class SWIGTYPE_p_switch_time_exp_t {
   private HandleRef swigCPtr;
 
@@ -21449,6 +22135,71 @@ public class switch_asr_handle : IDisposable {
     } 
   }
 
+  public SWIGTYPE_p_switch_buffer buffer {
+    set {
+      freeswitchPINVOKE.switch_asr_handle_buffer_set(swigCPtr, SWIGTYPE_p_switch_buffer.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_asr_handle_buffer_get(swigCPtr);
+      SWIGTYPE_p_switch_buffer ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_switch_buffer(cPtr, false);
+      return ret;
+    } 
+  }
+
+  public SWIGTYPE_p_unsigned_char dbuf {
+    set {
+      freeswitchPINVOKE.switch_asr_handle_dbuf_set(swigCPtr, SWIGTYPE_p_unsigned_char.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_asr_handle_dbuf_get(swigCPtr);
+      SWIGTYPE_p_unsigned_char ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_unsigned_char(cPtr, false);
+      return ret;
+    } 
+  }
+
+  public SWIGTYPE_p_switch_size_t dbuflen {
+    set {
+      freeswitchPINVOKE.switch_asr_handle_dbuflen_set(swigCPtr, SWIGTYPE_p_switch_size_t.getCPtr(value));
+      if (freeswitchPINVOKE.SWIGPendingException.Pending) throw freeswitchPINVOKE.SWIGPendingException.Retrieve();
+    } 
+    get {
+      SWIGTYPE_p_switch_size_t ret = new SWIGTYPE_p_switch_size_t(freeswitchPINVOKE.switch_asr_handle_dbuflen_get(swigCPtr), true);
+      if (freeswitchPINVOKE.SWIGPendingException.Pending) throw freeswitchPINVOKE.SWIGPendingException.Retrieve();
+      return ret;
+    } 
+  }
+
+  public switch_audio_resampler_t resampler {
+    set {
+      freeswitchPINVOKE.switch_asr_handle_resampler_set(swigCPtr, switch_audio_resampler_t.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_asr_handle_resampler_get(swigCPtr);
+      switch_audio_resampler_t ret = (cPtr == IntPtr.Zero) ? null : new switch_audio_resampler_t(cPtr, false);
+      return ret;
+    } 
+  }
+
+  public uint samplerate {
+    set {
+      freeswitchPINVOKE.switch_asr_handle_samplerate_set(swigCPtr, value);
+    } 
+    get {
+      uint ret = freeswitchPINVOKE.switch_asr_handle_samplerate_get(swigCPtr);
+      return ret;
+    } 
+  }
+
+  public uint native_rate {
+    set {
+      freeswitchPINVOKE.switch_asr_handle_native_rate_set(swigCPtr, value);
+    } 
+    get {
+      uint ret = freeswitchPINVOKE.switch_asr_handle_native_rate_get(swigCPtr);
+      return ret;
+    } 
+  }
+
   public SWIGTYPE_p_void private_info {
     set {
       freeswitchPINVOKE.switch_asr_handle_private_info_set(swigCPtr, SWIGTYPE_p_void.getCPtr(value));
@@ -22209,6 +22960,17 @@ public class switch_cache_db_connection_options_t : IDisposable {
     } 
   }
 
+  public switch_cache_db_pgsql_options_t pgsql_options {
+    set {
+      freeswitchPINVOKE.switch_cache_db_connection_options_t_pgsql_options_set(swigCPtr, switch_cache_db_pgsql_options_t.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_cache_db_connection_options_t_pgsql_options_get(swigCPtr);
+      switch_cache_db_pgsql_options_t ret = (cPtr == IntPtr.Zero) ? null : new switch_cache_db_pgsql_options_t(cPtr, false);
+      return ret;
+    } 
+  }
+
   public switch_cache_db_connection_options_t() : this(freeswitchPINVOKE.new_switch_cache_db_connection_options_t(), true) {
   }
 
@@ -22284,7 +23046,8 @@ namespace FreeSWITCH.Native {
 
 public enum switch_cache_db_handle_type_t {
   SCDB_TYPE_CORE_DB,
-  SCDB_TYPE_ODBC
+  SCDB_TYPE_ODBC,
+  SCDB_TYPE_PGSQL
 }
 
 }
@@ -22351,6 +23114,17 @@ public class switch_cache_db_native_handle_t : IDisposable {
     } 
   }
 
+  public SWIGTYPE_p_switch_pgsql_handle pgsql_dbh {
+    set {
+      freeswitchPINVOKE.switch_cache_db_native_handle_t_pgsql_dbh_set(swigCPtr, SWIGTYPE_p_switch_pgsql_handle.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_cache_db_native_handle_t_pgsql_dbh_get(swigCPtr);
+      SWIGTYPE_p_switch_pgsql_handle ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_switch_pgsql_handle(cPtr, false);
+      return ret;
+    } 
+  }
+
   public switch_cache_db_native_handle_t() : this(freeswitchPINVOKE.new_switch_cache_db_native_handle_t(), true) {
   }
 
@@ -22444,6 +23218,63 @@ public class switch_cache_db_odbc_options_t : IDisposable {
 
 namespace FreeSWITCH.Native {
 
+using System;
+using System.Runtime.InteropServices;
+
+public class switch_cache_db_pgsql_options_t : IDisposable {
+  private HandleRef swigCPtr;
+  protected bool swigCMemOwn;
+
+  internal switch_cache_db_pgsql_options_t(IntPtr cPtr, bool cMemoryOwn) {
+    swigCMemOwn = cMemoryOwn;
+    swigCPtr = new HandleRef(this, cPtr);
+  }
+
+  internal static HandleRef getCPtr(switch_cache_db_pgsql_options_t obj) {
+    return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
+  }
+
+  ~switch_cache_db_pgsql_options_t() {
+    Dispose();
+  }
+
+  public virtual void Dispose() {
+    lock(this) {
+      if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwn) {
+        swigCMemOwn = false;
+        freeswitchPINVOKE.delete_switch_cache_db_pgsql_options_t(swigCPtr);
+      }
+      swigCPtr = new HandleRef(null, IntPtr.Zero);
+      GC.SuppressFinalize(this);
+    }
+  }
+
+  public string dsn {
+    set {
+      freeswitchPINVOKE.switch_cache_db_pgsql_options_t_dsn_set(swigCPtr, value);
+    } 
+    get {
+      string ret = freeswitchPINVOKE.switch_cache_db_pgsql_options_t_dsn_get(swigCPtr);
+      return ret;
+    } 
+  }
+
+  public switch_cache_db_pgsql_options_t() : this(freeswitchPINVOKE.new_switch_cache_db_pgsql_options_t(), true) {
+  }
+
+}
+
+}
+/* ----------------------------------------------------------------------------
+ * This file was automatically generated by SWIG (http://www.swig.org).
+ * Version 1.3.35
+ *
+ * Do not make changes to this file unless you know what you are doing--modify
+ * the SWIG interface file instead.
+ * ----------------------------------------------------------------------------- */
+
+namespace FreeSWITCH.Native {
+
 public enum switch_call_cause_t {
   SWITCH_CAUSE_NONE = 0,
   SWITCH_CAUSE_UNALLOCATED_NUMBER = 1,
@@ -22512,7 +23343,8 @@ public enum switch_call_cause_t {
   SWITCH_CAUSE_INVALID_GATEWAY = 608,
   SWITCH_CAUSE_GATEWAY_DOWN = 609,
   SWITCH_CAUSE_INVALID_URL = 610,
-  SWITCH_CAUSE_INVALID_PROFILE = 611
+  SWITCH_CAUSE_INVALID_PROFILE = 611,
+  SWITCH_CAUSE_NO_PICKUP = 612
 }
 
 }
@@ -23089,6 +23921,17 @@ public class switch_caller_profile : IDisposable {
     } 
   }
 
+  public switch_channel_timetable old_times {
+    set {
+      freeswitchPINVOKE.switch_caller_profile_old_times_set(swigCPtr, switch_channel_timetable.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_caller_profile_old_times_get(swigCPtr);
+      switch_channel_timetable ret = (cPtr == IntPtr.Zero) ? null : new switch_channel_timetable(cPtr, false);
+      return ret;
+    } 
+  }
+
   public switch_caller_extension caller_extension {
     set {
       freeswitchPINVOKE.switch_caller_profile_caller_extension_set(swigCPtr, switch_caller_extension.getCPtr(value));
@@ -23353,6 +24196,7 @@ public enum switch_channel_flag_t {
   CF_TRACKABLE,
   CF_NO_CDR,
   CF_EARLY_OK,
+  CF_MEDIA_TRANS,
   CF_FLAG_MAX
 }
 
@@ -24021,6 +24865,17 @@ public class switch_codec : IDisposable {
     } 
   }
 
+  public SWIGTYPE_p_switch_core_session session {
+    set {
+      freeswitchPINVOKE.switch_codec_session_set(swigCPtr, SWIGTYPE_p_switch_core_session.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_codec_session_get(swigCPtr);
+      SWIGTYPE_p_switch_core_session ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_switch_core_session(cPtr, false);
+      return ret;
+    } 
+  }
+
   public switch_codec() : this(freeswitchPINVOKE.new_switch_codec(), true) {
   }
 
@@ -24936,7 +25791,7 @@ namespace FreeSWITCH.Native {
   SCF_CLEAR_SQL = (1 << 17),
   SCF_THREADED_SYSTEM_EXEC = (1 << 18),
   SCF_SYNC_CLOCK_REQUESTED = (1 << 19),
-  SCF_CORE_ODBC_REQ = (1 << 20),
+  SCF_CORE_NON_SQLITE_DB_REQ = (1 << 20),
   SCF_DEBUG_SQL = (1 << 21),
   SCF_API_EXPANSION = (1 << 22),
   SCF_SESSION_THREAD_POOL = (1 << 23)
@@ -25251,6 +26106,7 @@ public enum switch_core_session_message_types_t {
   SWITCH_MESSAGE_INDICATE_AUDIO_DATA,
   SWITCH_MESSAGE_INDICATE_BLIND_TRANSFER_RESPONSE,
   SWITCH_MESSAGE_INDICATE_STUN_ERROR,
+  SWITCH_MESSAGE_INDICATE_MEDIA_RENEG,
   SWITCH_MESSAGE_INVALID
 }
 
@@ -27678,6 +28534,17 @@ public class switch_frame : IDisposable {
     } 
   }
 
+  public SWIGTYPE_p_void user_data {
+    set {
+      freeswitchPINVOKE.switch_frame_user_data_set(swigCPtr, SWIGTYPE_p_void.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_frame_user_data_get(swigCPtr);
+      SWIGTYPE_p_void ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_void(cPtr, false);
+      return ret;
+    } 
+  }
+
   public switch_frame() : this(freeswitchPINVOKE.new_switch_frame(), true) {
   }
 
@@ -27722,6 +28589,98 @@ namespace FreeSWITCH.Native {
 using System;
 using System.Runtime.InteropServices;
 
+public class switch_hold_record_t : IDisposable {
+  private HandleRef swigCPtr;
+  protected bool swigCMemOwn;
+
+  internal switch_hold_record_t(IntPtr cPtr, bool cMemoryOwn) {
+    swigCMemOwn = cMemoryOwn;
+    swigCPtr = new HandleRef(this, cPtr);
+  }
+
+  internal static HandleRef getCPtr(switch_hold_record_t obj) {
+    return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
+  }
+
+  ~switch_hold_record_t() {
+    Dispose();
+  }
+
+  public virtual void Dispose() {
+    lock(this) {
+      if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwn) {
+        swigCMemOwn = false;
+        freeswitchPINVOKE.delete_switch_hold_record_t(swigCPtr);
+      }
+      swigCPtr = new HandleRef(null, IntPtr.Zero);
+      GC.SuppressFinalize(this);
+    }
+  }
+
+  public SWIGTYPE_p_switch_time_t on {
+    set {
+      freeswitchPINVOKE.switch_hold_record_t_on_set(swigCPtr, SWIGTYPE_p_switch_time_t.getCPtr(value));
+      if (freeswitchPINVOKE.SWIGPendingException.Pending) throw freeswitchPINVOKE.SWIGPendingException.Retrieve();
+    } 
+    get {
+      SWIGTYPE_p_switch_time_t ret = new SWIGTYPE_p_switch_time_t(freeswitchPINVOKE.switch_hold_record_t_on_get(swigCPtr), true);
+      if (freeswitchPINVOKE.SWIGPendingException.Pending) throw freeswitchPINVOKE.SWIGPendingException.Retrieve();
+      return ret;
+    } 
+  }
+
+  public SWIGTYPE_p_switch_time_t off {
+    set {
+      freeswitchPINVOKE.switch_hold_record_t_off_set(swigCPtr, SWIGTYPE_p_switch_time_t.getCPtr(value));
+      if (freeswitchPINVOKE.SWIGPendingException.Pending) throw freeswitchPINVOKE.SWIGPendingException.Retrieve();
+    } 
+    get {
+      SWIGTYPE_p_switch_time_t ret = new SWIGTYPE_p_switch_time_t(freeswitchPINVOKE.switch_hold_record_t_off_get(swigCPtr), true);
+      if (freeswitchPINVOKE.SWIGPendingException.Pending) throw freeswitchPINVOKE.SWIGPendingException.Retrieve();
+      return ret;
+    } 
+  }
+
+  public string uuid {
+    set {
+      freeswitchPINVOKE.switch_hold_record_t_uuid_set(swigCPtr, value);
+    } 
+    get {
+      string ret = freeswitchPINVOKE.switch_hold_record_t_uuid_get(swigCPtr);
+      return ret;
+    } 
+  }
+
+  public switch_hold_record_t next {
+    set {
+      freeswitchPINVOKE.switch_hold_record_t_next_set(swigCPtr, switch_hold_record_t.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_hold_record_t_next_get(swigCPtr);
+      switch_hold_record_t ret = (cPtr == IntPtr.Zero) ? null : new switch_hold_record_t(cPtr, false);
+      return ret;
+    } 
+  }
+
+  public switch_hold_record_t() : this(freeswitchPINVOKE.new_switch_hold_record_t(), true) {
+  }
+
+}
+
+}
+/* ----------------------------------------------------------------------------
+ * This file was automatically generated by SWIG (http://www.swig.org).
+ * Version 1.3.35
+ *
+ * Do not make changes to this file unless you know what you are doing--modify
+ * the SWIG interface file instead.
+ * ----------------------------------------------------------------------------- */
+
+namespace FreeSWITCH.Native {
+
+using System;
+using System.Runtime.InteropServices;
+
 public class switch_input_args_t : IDisposable {
   private HandleRef swigCPtr;
   protected bool swigCMemOwn;
@@ -28881,7 +29840,8 @@ public enum switch_io_routine_name_t {
   SWITCH_IO_RECEIVE_EVENT,
   SWITCH_IO_STATE_CHANGE,
   SWITCH_IO_READ_VIDEO_FRAME,
-  SWITCH_IO_WRITE_VIDEO_FRAME
+  SWITCH_IO_WRITE_VIDEO_FRAME,
+  SWITCH_IO_GET_JB
 }
 
 }
@@ -29047,6 +30007,17 @@ public class switch_io_routines : IDisposable {
     } 
   }
 
+  public SWIGTYPE_p_f_p_switch_core_session_enum_switch_media_type_t__p_stfu_instance_t get_jb {
+    set {
+      freeswitchPINVOKE.switch_io_routines_get_jb_set(swigCPtr, SWIGTYPE_p_f_p_switch_core_session_enum_switch_media_type_t__p_stfu_instance_t.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_io_routines_get_jb_get(swigCPtr);
+      SWIGTYPE_p_f_p_switch_core_session_enum_switch_media_type_t__p_stfu_instance_t ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_f_p_switch_core_session_enum_switch_media_type_t__p_stfu_instance_t(cPtr, false);
+      return ret;
+    } 
+  }
+
   public SWIGTYPE_p_p_void padding {
     set {
       freeswitchPINVOKE.switch_io_routines_padding_set(swigCPtr, SWIGTYPE_p_p_void.getCPtr(value));
@@ -29778,7 +30749,8 @@ public enum switch_log_level_t {
   SWITCH_LOG_CRIT = 2,
   SWITCH_LOG_ALERT = 1,
   SWITCH_LOG_CONSOLE = 0,
-  SWITCH_LOG_INVALID = 64
+  SWITCH_LOG_INVALID = 64,
+  SWITCH_LOG_UNINIT = 1000
 }
 
 }
@@ -29915,6 +30887,16 @@ public class switch_log_node_t : IDisposable {
     } 
   }
 
+  public switch_log_level_t slevel {
+    set {
+      freeswitchPINVOKE.switch_log_node_t_slevel_set(swigCPtr, (int)value);
+    } 
+    get {
+      switch_log_level_t ret = (switch_log_level_t)freeswitchPINVOKE.switch_log_node_t_slevel_get(swigCPtr);
+      return ret;
+    } 
+  }
+
   public switch_log_node_t() : this(freeswitchPINVOKE.new_switch_log_node_t(), true) {
   }
 
@@ -30121,6 +31103,22 @@ namespace FreeSWITCH.Native {
 
 namespace FreeSWITCH.Native {
 
+public enum switch_media_type_t {
+  SWITCH_MEDIA_TYPE_AUDIO,
+  SWITCH_MEDIA_TYPE_VIDEO
+}
+
+}
+/* ----------------------------------------------------------------------------
+ * This file was automatically generated by SWIG (http://www.swig.org).
+ * Version 1.3.35
+ *
+ * Do not make changes to this file unless you know what you are doing--modify
+ * the SWIG interface file instead.
+ * ----------------------------------------------------------------------------- */
+
+namespace FreeSWITCH.Native {
+
 public enum switch_module_flag_enum_t {
   SMODF_NONE = 0,
   SMODF_GLOBAL_SYMBOLS = (1 << 0)
@@ -31455,6 +32453,180 @@ public class switch_scheduler_task : IDisposable {
 
 namespace FreeSWITCH.Native {
 
+using System;
+using System.Runtime.InteropServices;
+
+public class switch_serial_event_header_t : IDisposable {
+  private HandleRef swigCPtr;
+  protected bool swigCMemOwn;
+
+  internal switch_serial_event_header_t(IntPtr cPtr, bool cMemoryOwn) {
+    swigCMemOwn = cMemoryOwn;
+    swigCPtr = new HandleRef(this, cPtr);
+  }
+
+  internal static HandleRef getCPtr(switch_serial_event_header_t obj) {
+    return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
+  }
+
+  ~switch_serial_event_header_t() {
+    Dispose();
+  }
+
+  public virtual void Dispose() {
+    lock(this) {
+      if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwn) {
+        swigCMemOwn = false;
+        freeswitchPINVOKE.delete_switch_serial_event_header_t(swigCPtr);
+      }
+      swigCPtr = new HandleRef(null, IntPtr.Zero);
+      GC.SuppressFinalize(this);
+    }
+  }
+
+  public string name {
+    set {
+      freeswitchPINVOKE.switch_serial_event_header_t_name_set(swigCPtr, value);
+    } 
+    get {
+      string ret = freeswitchPINVOKE.switch_serial_event_header_t_name_get(swigCPtr);
+      return ret;
+    } 
+  }
+
+  public string value {
+    set {
+      freeswitchPINVOKE.switch_serial_event_header_t_value_set(swigCPtr, value);
+    } 
+    get {
+      string ret = freeswitchPINVOKE.switch_serial_event_header_t_value_get(swigCPtr);
+      return ret;
+    } 
+  }
+
+  public switch_serial_event_header_t() : this(freeswitchPINVOKE.new_switch_serial_event_header_t(), true) {
+  }
+
+}
+
+}
+/* ----------------------------------------------------------------------------
+ * This file was automatically generated by SWIG (http://www.swig.org).
+ * Version 1.3.35
+ *
+ * Do not make changes to this file unless you know what you are doing--modify
+ * the SWIG interface file instead.
+ * ----------------------------------------------------------------------------- */
+
+namespace FreeSWITCH.Native {
+
+using System;
+using System.Runtime.InteropServices;
+
+public class switch_serial_event_t : IDisposable {
+  private HandleRef swigCPtr;
+  protected bool swigCMemOwn;
+
+  internal switch_serial_event_t(IntPtr cPtr, bool cMemoryOwn) {
+    swigCMemOwn = cMemoryOwn;
+    swigCPtr = new HandleRef(this, cPtr);
+  }
+
+  internal static HandleRef getCPtr(switch_serial_event_t obj) {
+    return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
+  }
+
+  ~switch_serial_event_t() {
+    Dispose();
+  }
+
+  public virtual void Dispose() {
+    lock(this) {
+      if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwn) {
+        swigCMemOwn = false;
+        freeswitchPINVOKE.delete_switch_serial_event_t(swigCPtr);
+      }
+      swigCPtr = new HandleRef(null, IntPtr.Zero);
+      GC.SuppressFinalize(this);
+    }
+  }
+
+  public int event_id {
+    set {
+      freeswitchPINVOKE.switch_serial_event_t_event_id_set(swigCPtr, value);
+    } 
+    get {
+      int ret = freeswitchPINVOKE.switch_serial_event_t_event_id_get(swigCPtr);
+      return ret;
+    } 
+  }
+
+  public int priority {
+    set {
+      freeswitchPINVOKE.switch_serial_event_t_priority_set(swigCPtr, value);
+    } 
+    get {
+      int ret = freeswitchPINVOKE.switch_serial_event_t_priority_get(swigCPtr);
+      return ret;
+    } 
+  }
+
+  public int flags {
+    set {
+      freeswitchPINVOKE.switch_serial_event_t_flags_set(swigCPtr, value);
+    } 
+    get {
+      int ret = freeswitchPINVOKE.switch_serial_event_t_flags_get(swigCPtr);
+      return ret;
+    } 
+  }
+
+  public string owner {
+    set {
+      freeswitchPINVOKE.switch_serial_event_t_owner_set(swigCPtr, value);
+    } 
+    get {
+      string ret = freeswitchPINVOKE.switch_serial_event_t_owner_get(swigCPtr);
+      return ret;
+    } 
+  }
+
+  public string subclass_name {
+    set {
+      freeswitchPINVOKE.switch_serial_event_t_subclass_name_set(swigCPtr, value);
+    } 
+    get {
+      string ret = freeswitchPINVOKE.switch_serial_event_t_subclass_name_get(swigCPtr);
+      return ret;
+    } 
+  }
+
+  public string body {
+    set {
+      freeswitchPINVOKE.switch_serial_event_t_body_set(swigCPtr, value);
+    } 
+    get {
+      string ret = freeswitchPINVOKE.switch_serial_event_t_body_get(swigCPtr);
+      return ret;
+    } 
+  }
+
+  public switch_serial_event_t() : this(freeswitchPINVOKE.new_switch_serial_event_t(), true) {
+  }
+
+}
+
+}
+/* ----------------------------------------------------------------------------
+ * This file was automatically generated by SWIG (http://www.swig.org).
+ * Version 1.3.35
+ *
+ * Do not make changes to this file unless you know what you are doing--modify
+ * the SWIG interface file instead.
+ * ----------------------------------------------------------------------------- */
+
+namespace FreeSWITCH.Native {
+
 public enum switch_session_ctl_t {
   SCSC_PAUSE_INBOUND,
   SCSC_PAUSE_OUTBOUND,
@@ -32726,6 +33898,104 @@ namespace FreeSWITCH.Native {
 using System;
 using System.Runtime.InteropServices;
 
+public class switch_thread_data_t : IDisposable {
+  private HandleRef swigCPtr;
+  protected bool swigCMemOwn;
+
+  internal switch_thread_data_t(IntPtr cPtr, bool cMemoryOwn) {
+    swigCMemOwn = cMemoryOwn;
+    swigCPtr = new HandleRef(this, cPtr);
+  }
+
+  internal static HandleRef getCPtr(switch_thread_data_t obj) {
+    return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
+  }
+
+  ~switch_thread_data_t() {
+    Dispose();
+  }
+
+  public virtual void Dispose() {
+    lock(this) {
+      if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwn) {
+        swigCMemOwn = false;
+        freeswitchPINVOKE.delete_switch_thread_data_t(swigCPtr);
+      }
+      swigCPtr = new HandleRef(null, IntPtr.Zero);
+      GC.SuppressFinalize(this);
+    }
+  }
+
+  public SWIGTYPE_p_switch_thread_start_t func {
+    set {
+      freeswitchPINVOKE.switch_thread_data_t_func_set(swigCPtr, SWIGTYPE_p_switch_thread_start_t.getCPtr(value));
+      if (freeswitchPINVOKE.SWIGPendingException.Pending) throw freeswitchPINVOKE.SWIGPendingException.Retrieve();
+    } 
+    get {
+      SWIGTYPE_p_switch_thread_start_t ret = new SWIGTYPE_p_switch_thread_start_t(freeswitchPINVOKE.switch_thread_data_t_func_get(swigCPtr), true);
+      if (freeswitchPINVOKE.SWIGPendingException.Pending) throw freeswitchPINVOKE.SWIGPendingException.Retrieve();
+      return ret;
+    } 
+  }
+
+  public SWIGTYPE_p_void obj {
+    set {
+      freeswitchPINVOKE.switch_thread_data_t_obj_set(swigCPtr, SWIGTYPE_p_void.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_thread_data_t_obj_get(swigCPtr);
+      SWIGTYPE_p_void ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_void(cPtr, false);
+      return ret;
+    } 
+  }
+
+  public int alloc {
+    set {
+      freeswitchPINVOKE.switch_thread_data_t_alloc_set(swigCPtr, value);
+    } 
+    get {
+      int ret = freeswitchPINVOKE.switch_thread_data_t_alloc_get(swigCPtr);
+      return ret;
+    } 
+  }
+
+  public switch_thread_data_t() : this(freeswitchPINVOKE.new_switch_thread_data_t(), true) {
+  }
+
+}
+
+}
+/* ----------------------------------------------------------------------------
+ * This file was automatically generated by SWIG (http://www.swig.org).
+ * Version 1.3.35
+ *
+ * Do not make changes to this file unless you know what you are doing--modify
+ * the SWIG interface file instead.
+ * ----------------------------------------------------------------------------- */
+
+namespace FreeSWITCH.Native {
+
+public enum switch_thread_priority_t {
+  SWITCH_PRI_LOW = 1,
+  SWITCH_PRI_NORMAL = 10,
+  SWITCH_PRI_IMPORTANT = 50,
+  SWITCH_PRI_REALTIME = 99
+}
+
+}
+/* ----------------------------------------------------------------------------
+ * This file was automatically generated by SWIG (http://www.swig.org).
+ * Version 1.3.35
+ *
+ * Do not make changes to this file unless you know what you are doing--modify
+ * the SWIG interface file instead.
+ * ----------------------------------------------------------------------------- */
+
+namespace FreeSWITCH.Native {
+
+using System;
+using System.Runtime.InteropServices;
+
 public class switch_timer : IDisposable {
   private HandleRef swigCPtr;
   protected bool swigCMemOwn;
diff --git a/src/mod/xml_int/mod_xml_radius/mod_xml_radius.c b/src/mod/xml_int/mod_xml_radius/mod_xml_radius.c
index d80e9e7d54..0b99166f98 100644
--- a/src/mod/xml_int/mod_xml_radius/mod_xml_radius.c
+++ b/src/mod/xml_int/mod_xml_radius/mod_xml_radius.c
@@ -838,7 +838,9 @@ switch_status_t mod_xml_radius_check_conditions(switch_channel_t *channel, switc
 	switch_xml_t condition, param;
 	char *channel_var = NULL;
 	char *regex = NULL;
+	char *anti = NULL;
 	int all_matched = 1;
+	int result = 0;
 	
 	if ( (condition = switch_xml_child(conditions, "condition")) == NULL) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to locate a condition under the conditions section\n");
@@ -856,14 +858,19 @@ switch_status_t mod_xml_radius_check_conditions(switch_channel_t *channel, switc
 		for (; param && all_matched; param = param->next) {
 			channel_var = (char *) switch_xml_attr(param, "var");
 			regex = (char *) switch_xml_attr(param, "regex");
+			anti = (char *) switch_xml_attr(param, "anti");
 			
 			if ( channel_var == NULL || regex == NULL ) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Improperly constructed mod_radius condition: %s %s\n", channel_var, regex);
 			}
 			
-			if ( switch_regex_match( switch_channel_get_variable(channel, channel_var), regex) != SWITCH_STATUS_SUCCESS) {
+			result = ( switch_regex_match( switch_channel_get_variable(channel, channel_var), regex) != SWITCH_STATUS_SUCCESS);
+			if (( anti == NULL && result ) || ( anti != NULL && !result ) ){
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Didn't match: %s == %s \n", switch_channel_get_variable(channel, channel_var), regex);
 				all_matched = 0;
+			} else {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Result of %s match: %s == %s \n", 
+								  anti, switch_channel_get_variable(channel, channel_var), regex);
 			}
 		}
 
diff --git a/src/switch_apr.c b/src/switch_apr.c
index aeb10185a9..d4db415280 100644
--- a/src/switch_apr.c
+++ b/src/switch_apr.c
@@ -1050,7 +1050,13 @@ SWITCH_DECLARE(unsigned int) switch_queue_size(switch_queue_t *queue)
 
 SWITCH_DECLARE(switch_status_t) switch_queue_pop(switch_queue_t *queue, void **data)
 {
-	return apr_queue_pop(queue, data);
+	apr_status_t s;
+
+	do {
+		s = apr_queue_pop(queue, data);
+	} while (s == APR_EINTR);
+
+	return s;
 }
 
 SWITCH_DECLARE(switch_status_t) switch_queue_pop_timeout(switch_queue_t *queue, void **data, switch_interval_time_t timeout)
@@ -1072,7 +1078,14 @@ SWITCH_DECLARE(switch_status_t) switch_queue_push(switch_queue_t *queue, void *d
 
 SWITCH_DECLARE(switch_status_t) switch_queue_trypop(switch_queue_t *queue, void **data)
 {
-	return apr_queue_trypop(queue, data);
+	apr_status_t s;
+
+	do {
+		s = apr_queue_trypop(queue, data);
+	} while (s == APR_EINTR);
+
+	return s;
+	
 }
 
 SWITCH_DECLARE(switch_status_t) switch_queue_interrupt_all(switch_queue_t *queue)
diff --git a/src/switch_core.c b/src/switch_core.c
index 8f0895fb9b..4682d3c002 100644
--- a/src/switch_core.c
+++ b/src/switch_core.c
@@ -575,6 +575,14 @@ SWITCH_DECLARE(void) switch_core_set_globals(void)
 #endif
 	}
 
+	if (!SWITCH_GLOBAL_dirs.lib_dir && (SWITCH_GLOBAL_dirs.lib_dir = (char *) malloc(BUFSIZE))) {
+#ifdef SWITCH_LIB_DIR
+		switch_snprintf(SWITCH_GLOBAL_dirs.lib_dir, BUFSIZE, "%s", SWITCH_LIB_DIR);
+#else
+		switch_snprintf(SWITCH_GLOBAL_dirs.lib_dir, BUFSIZE, "%s%slib", base_dir, SWITCH_PATH_SEPARATOR);
+#endif
+	}
+
 	if (!SWITCH_GLOBAL_dirs.conf_dir && (SWITCH_GLOBAL_dirs.conf_dir = (char *) malloc(BUFSIZE))) {
 #ifdef SWITCH_CONF_DIR
 		switch_snprintf(SWITCH_GLOBAL_dirs.conf_dir, BUFSIZE, "%s", SWITCH_CONF_DIR);
@@ -671,6 +679,7 @@ SWITCH_DECLARE(void) switch_core_set_globals(void)
 
 	switch_assert(SWITCH_GLOBAL_dirs.base_dir);
 	switch_assert(SWITCH_GLOBAL_dirs.mod_dir);
+	switch_assert(SWITCH_GLOBAL_dirs.lib_dir);
 	switch_assert(SWITCH_GLOBAL_dirs.conf_dir);
 	switch_assert(SWITCH_GLOBAL_dirs.log_dir);
 	switch_assert(SWITCH_GLOBAL_dirs.run_dir);
@@ -1470,11 +1479,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc
 	runtime.db_handle_timeout = 5000000;
 	
 	runtime.runlevel++;
-	runtime.sql_buffer_len = 1024 * 32;
-	runtime.max_sql_buffer_len = 1024 * 1024 * 10;
 	runtime.dummy_cng_frame.data = runtime.dummy_data;
 	runtime.dummy_cng_frame.datalen = sizeof(runtime.dummy_data);
 	runtime.dummy_cng_frame.buflen = sizeof(runtime.dummy_data);
+	runtime.dbname = "core";
 	switch_set_flag((&runtime.dummy_cng_frame), SFF_CNG);
 	switch_set_flag((&runtime), SCF_AUTO_SCHEMAS);
 	switch_set_flag((&runtime), SCF_CLEAR_SQL);
@@ -1754,37 +1762,6 @@ static void switch_load_core_config(const char *file)
 					
 				} else if (!strcasecmp(var, "multiple-registrations")) {
 					runtime.multiple_registrations = switch_true(val);
-				} else if (!strcasecmp(var, "sql-buffer-len")) {
-					int tmp = atoi(val);
-
-					if (end_of(val) == 'k') {
-						tmp *= 1024;
-					} else if (end_of(val) == 'm') {
-						tmp *= (1024 * 1024);
-					}
-
-					if (tmp >= 32000 && tmp < 10500000) {
-						runtime.sql_buffer_len = tmp;
-					} else {
-						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "sql-buffer-len: Value is not within rage 32k to 10m\n");
-					}
-				} else if (!strcasecmp(var, "max-sql-buffer-len")) {
-					int tmp = atoi(val);
-
-					if (end_of(val) == 'k') {
-						tmp *= 1024;
-					} else if (end_of(val) == 'm') {
-						tmp *= (1024 * 1024);
-					}
-
-					if (tmp < runtime.sql_buffer_len) {
-						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Value is not larger than sql-buffer-len\n");
-					} else if (tmp >= 32000 && tmp < 10500000) {
-						runtime.sql_buffer_len = tmp;
-					} else {
-						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "max-sql-buffer-len: Value is not within rage 32k to 10m\n");
-					}
-
 				} else if (!strcasecmp(var, "auto-create-schemas")) {
 					if (switch_true(val)) {
 						switch_set_flag((&runtime), SCF_AUTO_SCHEMAS);
@@ -2256,9 +2233,9 @@ SWITCH_DECLARE(int32_t) switch_core_session_ctl(switch_session_ctl_t cmd, void *
 		break;
 	case SCSC_SQL:
 		if (oldintval) {
-			switch_core_sqldb_start_thread();
+			switch_core_sqldb_resume();
 		} else {
-			switch_core_sqldb_stop_thread();
+			switch_core_sqldb_pause();
 		}
 		break;
 	case SCSC_PAUSE_ALL:
diff --git a/src/switch_core_io.c b/src/switch_core_io.c
index 7dbfdb2ac8..ba4874d81f 100644
--- a/src/switch_core_io.c
+++ b/src/switch_core_io.c
@@ -375,7 +375,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
 				} else {
 					switch_codec_t *codec = use_codec->implementation?use_codec:read_frame->codec;
 					switch_thread_rwlock_rdlock(session->bug_rwlock);
-					codec->session = session;
+					codec->cur_frame = read_frame;
+					session->read_codec->cur_frame = read_frame;
 					status = switch_core_codec_decode(codec,
 													  session->read_codec,
 													  read_frame->data,
@@ -383,7 +384,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
 													  session->read_impl.actual_samples_per_second,
 													  session->raw_read_frame.data, &session->raw_read_frame.datalen, &session->raw_read_frame.rate, 
 													  &read_frame->flags);
-					codec->session = NULL;
+					codec->cur_frame = NULL;
+					session->read_codec->cur_frame = NULL;
 					switch_thread_rwlock_unlock(session->bug_rwlock);
 
 				}
@@ -626,14 +628,16 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
 				switch_assert(session->read_codec != NULL);
 				switch_assert(enc_frame != NULL);
 				switch_assert(enc_frame->data != NULL);
-				session->read_codec->session = session;
+				session->read_codec->cur_frame = enc_frame;
+				enc_frame->codec->cur_frame = enc_frame;
 				status = switch_core_codec_encode(session->read_codec,
 												  enc_frame->codec,
 												  enc_frame->data,
 												  enc_frame->datalen,
 												  session->read_impl.actual_samples_per_second,
 												  session->enc_read_frame.data, &session->enc_read_frame.datalen, &session->enc_read_frame.rate, &flag);
-				session->read_codec->session = NULL;
+				session->read_codec->cur_frame = NULL;
+				enc_frame->codec->cur_frame = NULL;
 				switch (status) {
 				case SWITCH_STATUS_RESAMPLE:
 					switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Fixme 1\n");
@@ -907,15 +911,16 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
 
 	if (frame->codec) {
 		session->raw_write_frame.datalen = session->raw_write_frame.buflen;
-		frame->codec->session = session;
+		frame->codec->cur_frame = frame;
+		session->write_codec->cur_frame = frame;
 		status = switch_core_codec_decode(frame->codec,
 										  session->write_codec,
 										  frame->data,
 										  frame->datalen,
 										  session->write_impl.actual_samples_per_second,
 										  session->raw_write_frame.data, &session->raw_write_frame.datalen, &session->raw_write_frame.rate, &frame->flags);
-		frame->codec->session = NULL;
-
+		frame->codec->cur_frame = NULL;
+		session->write_codec->cur_frame = NULL;
 		if (do_resample && status == SWITCH_STATUS_SUCCESS) {
 			status = SWITCH_STATUS_RESAMPLE;
 		}
@@ -1094,17 +1099,17 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
 
 			enc_frame = write_frame;
 			session->enc_write_frame.datalen = session->enc_write_frame.buflen;
-			session->write_codec->session = session;
+			session->write_codec->cur_frame = frame;
+			frame->codec->cur_frame = frame;
 			status = switch_core_codec_encode(session->write_codec,
 											  frame->codec,
 											  enc_frame->data,
 											  enc_frame->datalen,
 											  session->write_impl.actual_samples_per_second,
 											  session->enc_write_frame.data, &session->enc_write_frame.datalen, &session->enc_write_frame.rate, &flag);
-			session->write_codec->session = NULL;
-
-
 
+			session->write_codec->cur_frame = NULL;
+			frame->codec->cur_frame = NULL;
 			switch (status) {
 			case SWITCH_STATUS_RESAMPLE:
 				resample++;
@@ -1198,15 +1203,18 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
 				} else {
 					rate = session->write_impl.actual_samples_per_second;
 				}
-				session->write_codec->session = session;
+
+				session->write_codec->cur_frame = frame;
+				frame->codec->cur_frame = frame;
 				status = switch_core_codec_encode(session->write_codec,
 												  frame->codec,
 												  enc_frame->data,
 												  enc_frame->datalen,
 												  rate,
 												  session->enc_write_frame.data, &session->enc_write_frame.datalen, &session->enc_write_frame.rate, &flag);
-				session->write_codec->session = NULL;
 
+				session->write_codec->cur_frame = NULL;
+				frame->codec->cur_frame = NULL;
 				switch (status) {
 				case SWITCH_STATUS_RESAMPLE:
 					resample++;
diff --git a/src/switch_core_media_bug.c b/src/switch_core_media_bug.c
index f5c57721ad..b8b83da6bd 100644
--- a/src/switch_core_media_bug.c
+++ b/src/switch_core_media_bug.c
@@ -251,7 +251,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_read(switch_media_bug_t *b
 					}					
 				} else {
 					if (read_impl.decoded_bytes_per_packet > other_read_impl.decoded_bytes_per_packet) {
-						frame_size = other_read_impl.decoded_bytes_per_packet;
+						frame_size = read_impl.decoded_bytes_per_packet;
 					}
 				}
 			}
diff --git a/src/switch_core_session.c b/src/switch_core_session.c
index 4c16fadc51..cf7daaac16 100644
--- a/src/switch_core_session.c
+++ b/src/switch_core_session.c
@@ -204,18 +204,20 @@ struct str_node {
 	struct str_node *next;
 };
 
-SWITCH_DECLARE(void) switch_core_session_hupall_matching_var(const char *var_name, const char *var_val, switch_call_cause_t cause)
+SWITCH_DECLARE(uint32_t) switch_core_session_hupall_matching_var_ans(const char *var_name, const char *var_val, switch_call_cause_t cause, 
+																	 switch_hup_type_t type)
 {
 	switch_hash_index_t *hi;
 	void *val;
 	switch_core_session_t *session;
 	switch_memory_pool_t *pool;
 	struct str_node *head = NULL, *np;
+	uint32_t r = 0;
 
 	switch_core_new_memory_pool(&pool);
 
 	if (!var_val)
-		return;
+		return r;
 
 	switch_mutex_lock(runtime.session_hash_mutex);
 	for (hi = switch_hash_first(NULL, session_manager.session_table); hi; hi = switch_hash_next(hi)) {
@@ -223,10 +225,13 @@ SWITCH_DECLARE(void) switch_core_session_hupall_matching_var(const char *var_nam
 		if (val) {
 			session = (switch_core_session_t *) val;
 			if (switch_core_session_read_lock(session) == SWITCH_STATUS_SUCCESS) {
-				np = switch_core_alloc(pool, sizeof(*np));
-				np->str = switch_core_strdup(pool, session->uuid_str);
-				np->next = head;
-				head = np;
+				int ans = switch_channel_test_flag(switch_core_session_get_channel(session), CF_ANSWERED);
+				if ((ans && (type & SHT_ANSWERED)) || (!ans && (type & SHT_UNANSWERED))) {
+					np = switch_core_alloc(pool, sizeof(*np));
+					np->str = switch_core_strdup(pool, session->uuid_str);
+					np->next = head;
+					head = np;
+				}
 				switch_core_session_rwunlock(session);
 			}
 		}
@@ -239,6 +244,7 @@ SWITCH_DECLARE(void) switch_core_session_hupall_matching_var(const char *var_nam
 			if (switch_channel_up_nosig(session->channel) &&
 				(this_val = switch_channel_get_variable(session->channel, var_name)) && (!strcmp(this_val, var_val))) {			
 				switch_channel_hangup(session->channel, cause);
+				r++;
 			}
 			switch_core_session_rwunlock(session);
 		}
@@ -246,6 +252,7 @@ SWITCH_DECLARE(void) switch_core_session_hupall_matching_var(const char *var_nam
 
 	switch_core_destroy_memory_pool(&pool);
 
+	return r;
 }
 
 
@@ -1530,25 +1537,25 @@ static void *SWITCH_THREAD_FUNC switch_core_session_thread_pool_worker(switch_th
 		}
 
 		if (check_status == SWITCH_STATUS_SUCCESS) {
-			switch_core_session_t *session = (switch_core_session_t *) pop;
-			switch_size_t id;
+			switch_thread_data_t *td = (switch_thread_data_t *) pop;
 			
-			if (!session) break;
+			if (!td) break;
 
-			id = session->id;
-			
 			switch_mutex_lock(session_manager.mutex);
 			session_manager.busy++;
 			switch_mutex_unlock(session_manager.mutex);
 			
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG10, "Worker Thread %ld Processing session %"SWITCH_SIZE_T_FMT" %s\n",
-							  (long) thread, id, switch_core_session_get_name(session));
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG10, "Worker Thread %ld Processing\n", (long) thread);
 
-			switch_core_session_thread(thread, (void *) session);
+
+			td->func(thread, td->obj);
+
+			if (td->alloc) {
+				free(td);
+			}
+			
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG10, "Worker Thread %ld Done Processing\n", (long) thread);
 			
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG10, "Worker Thread %ld Done Processing session %"SWITCH_SIZE_T_FMT"\n",
-							  (long) thread, id);
-
 			switch_mutex_lock(session_manager.mutex);
 			session_manager.busy--;
 			switch_mutex_unlock(session_manager.mutex);
@@ -1656,11 +1663,27 @@ static void *SWITCH_THREAD_FUNC switch_core_session_thread_pool_manager(switch_t
 	return NULL;
 }
 
+SWITCH_DECLARE(switch_status_t) switch_thread_pool_launch_thread(switch_thread_data_t **tdp)
+{
+	switch_status_t status = SWITCH_STATUS_SUCCESS;
+	switch_thread_data_t *td;
+
+	switch_assert(tdp);
+
+	td = *tdp;
+	*tdp = NULL;
+
+	switch_queue_push(session_manager.thread_queue, td);
+	check_queue();
+
+	return status;	
+}
 
 SWITCH_DECLARE(switch_status_t) switch_core_session_thread_pool_launch(switch_core_session_t *session)
 {
 	switch_status_t status = SWITCH_STATUS_INUSE;
-	
+	switch_thread_data_t *td;
+
 	switch_mutex_lock(session->mutex);
 	if (switch_test_flag(session, SSF_THREAD_RUNNING)) {
 		switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "Cannot double-launch thread!\n");
@@ -1670,7 +1693,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_thread_pool_launch(switch_co
 		status = SWITCH_STATUS_SUCCESS;
 		switch_set_flag(session, SSF_THREAD_RUNNING);
 		switch_set_flag(session, SSF_THREAD_STARTED);
-		switch_queue_push(session_manager.thread_queue, session);
+		td = switch_core_session_alloc(session, sizeof(*td));
+		td->obj = session;
+		td->func = switch_core_session_thread;
+		switch_queue_push(session_manager.thread_queue, td);
 		check_queue();
 	}
 	switch_mutex_unlock(session->mutex);
diff --git a/src/switch_core_sqldb.c b/src/switch_core_sqldb.c
index 80ab68c110..ac32d7d146 100644
--- a/src/switch_core_sqldb.c
+++ b/src/switch_core_sqldb.c
@@ -56,26 +56,25 @@ struct switch_cache_db_handle {
 };
 
 static struct {
-	switch_cache_db_handle_t *event_db;
-	switch_queue_t *sql_queue[4];
 	switch_memory_pool_t *memory_pool;
-	switch_thread_t *thread;
 	switch_thread_t *db_thread;
-	int thread_running;
 	int db_thread_running;
 	switch_bool_t manage;
 	switch_mutex_t *io_mutex;
 	switch_mutex_t *dbh_mutex;
 	switch_mutex_t *ctl_mutex;
 	switch_cache_db_handle_t *handle_pool;
-	switch_thread_cond_t *cond;
-	switch_mutex_t *cond_mutex;
 	uint32_t total_handles;
 	uint32_t total_used_handles;
 	switch_cache_db_handle_t *dbh;
+	switch_sql_queue_manager_t *qm;
+	int paused;
 } sql_manager;
 
 
+static void switch_core_sqldb_start_thread(void);
+static void switch_core_sqldb_stop_thread(void);
+
 static switch_cache_db_handle_t *create_handle(switch_cache_db_handle_type_t type)
 {
 	switch_cache_db_handle_t *new_dbh = NULL;
@@ -210,6 +209,7 @@ static void sql_close(time_t prune)
 {
 	switch_cache_db_handle_t *dbh = NULL;
 	int locked = 0;
+	int sanity = 10000;
 
 	switch_mutex_lock(sql_manager.dbh_mutex);
  top:
@@ -255,7 +255,12 @@ static void sql_close(time_t prune)
 
 		} else {
 			if (!prune) {
-				locked++;
+				if (!sanity) {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "SANITY CHECK FAILED!  Handle %s (%s;%s) was not properly released.\n", 
+									  dbh->name, dbh->creator, dbh->last_user);
+				} else {
+					locked++;
+				}
 			}
 			continue;
 		}
@@ -263,6 +268,10 @@ static void sql_close(time_t prune)
 	}
 
 	if (locked) {
+		if (!prune) {
+			switch_cond_next();
+			if (sanity) sanity--;
+		}
 		goto top;
 	}
 
@@ -575,19 +584,6 @@ static switch_status_t switch_cache_db_execute_sql_real(switch_cache_db_handle_t
 	return status;
 }
 
-static void wake_thread(int force)
-{
-	if (force) {
-		switch_thread_cond_signal(sql_manager.cond);
-		return;
-	}
-
-	if (switch_mutex_trylock(sql_manager.cond_mutex) == SWITCH_STATUS_SUCCESS) {
-		switch_thread_cond_signal(sql_manager.cond);
-		switch_mutex_unlock(sql_manager.cond_mutex);
-	}
-}
-
 /**
    OMFG you cruel bastards.  Who chooses 64k as a max buffer len for a sql statement, have you ever heard of transactions?
 **/
@@ -1195,7 +1191,6 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_db_thread(switch_thread_t *threa
 	while (sql_manager.db_thread_running == 1) {
 		if (++sec == SQL_CACHE_TIMEOUT) {
 			sql_close(switch_epoch_time_now(NULL));		
-			wake_thread(0);
 			sec = 0;
 		}
 
@@ -1214,27 +1209,35 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_db_thread(switch_thread_t *threa
 static void *SWITCH_THREAD_FUNC switch_user_sql_thread(switch_thread_t *thread, void *obj);
 
 struct switch_sql_queue_manager {
+	const char *name;
 	switch_cache_db_handle_t *event_db;
 	switch_queue_t **sql_queue;
+	uint32_t *pre_written;
+	uint32_t *written;
 	uint32_t numq;
 	char *dsn;
 	switch_thread_t *thread;
 	int thread_running;
 	switch_thread_cond_t *cond;
 	switch_mutex_t *cond_mutex;
+	switch_mutex_t *mutex;
 	char *pre_trans_execute;
 	char *post_trans_execute;
 	char *inner_pre_trans_execute;
 	char *inner_post_trans_execute;
 	switch_memory_pool_t *pool;
+	uint32_t max_trans;
 };
 
-static void qm_wake(switch_sql_queue_manager_t *qm)
+static int qm_wake(switch_sql_queue_manager_t *qm)
 {
 	if (switch_mutex_trylock(qm->cond_mutex) == SWITCH_STATUS_SUCCESS) {
 		switch_thread_cond_signal(qm->cond);
 		switch_mutex_unlock(qm->cond_mutex);
+		return 1;
 	}
+
+	return 0;
 }
 
 static uint32_t qm_ttl(switch_sql_queue_manager_t *qm)
@@ -1249,8 +1252,20 @@ static uint32_t qm_ttl(switch_sql_queue_manager_t *qm)
 	return ttl;
 }
 
+SWITCH_DECLARE(int) switch_sql_queue_manager_size(switch_sql_queue_manager_t *qm, uint32_t index)
+{
+	int size = 0;
 
-SWITCH_DECLARE(switch_status_t) switch_switch_sql_queue_manager_stop(switch_sql_queue_manager_t *qm)
+	switch_mutex_lock(qm->mutex);
+	if (index < qm->numq) {
+		size = switch_queue_size(qm->sql_queue[index]);
+	}
+	switch_mutex_unlock(qm->mutex);
+
+	return size;
+}
+
+SWITCH_DECLARE(switch_status_t) switch_sql_queue_manager_stop(switch_sql_queue_manager_t *qm)
 {
 	switch_status_t status = SWITCH_STATUS_FALSE;
 
@@ -1262,6 +1277,7 @@ SWITCH_DECLARE(switch_status_t) switch_switch_sql_queue_manager_stop(switch_sql_
 	}
 
 	if (qm->thread) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s Stopping SQL thread.\n", qm->name);
 		switch_thread_join(&status, qm->thread);
 		qm->thread = NULL;
 		status = SWITCH_STATUS_SUCCESS;
@@ -1270,12 +1286,12 @@ SWITCH_DECLARE(switch_status_t) switch_switch_sql_queue_manager_stop(switch_sql_
 	return status;
 }
 
-SWITCH_DECLARE(switch_status_t) switch_switch_sql_queue_manager_start(switch_sql_queue_manager_t *qm)
+SWITCH_DECLARE(switch_status_t) switch_sql_queue_manager_start(switch_sql_queue_manager_t *qm)
 {
 	switch_threadattr_t *thd_attr;
 
 	if (!qm->thread_running) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Starting SQL thread.\n");
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s Starting SQL thread.\n", qm->name);
 		switch_threadattr_create(&thd_attr, qm->pool);
 		switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
 		switch_threadattr_priority_set(thd_attr, SWITCH_PRI_NORMAL);
@@ -1287,24 +1303,40 @@ SWITCH_DECLARE(switch_status_t) switch_switch_sql_queue_manager_start(switch_sql
 }
 
 
-SWITCH_DECLARE(switch_status_t) switch_switch_sql_queue_manager_destroy(switch_sql_queue_manager_t **qmp)
+static void do_flush(switch_queue_t *q, switch_cache_db_handle_t *dbh)
+{
+	void *pop = NULL;
+	
+	while (switch_queue_trypop(q, &pop) == SWITCH_STATUS_SUCCESS) {
+		if (pop) {
+			if (dbh) {
+				switch_cache_db_execute_sql(dbh, (char *) pop, NULL);
+			}
+			free(pop);
+		}
+	}
+
+}
+
+SWITCH_DECLARE(switch_status_t) switch_sql_queue_manager_destroy(switch_sql_queue_manager_t **qmp)
 {
 	switch_sql_queue_manager_t *qm;
 	switch_status_t status = SWITCH_STATUS_SUCCESS;
 	switch_memory_pool_t *pool;
-	void *pop;
 	uint32_t i;
 
 	switch_assert(qmp);
 	qm = *qmp;
 	*qmp = NULL;
 
-	switch_switch_sql_queue_manager_stop(qm);
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s Destroying SQL queue.\n", qm->name);
+
+	switch_sql_queue_manager_stop(qm);
+
+
 
 	for(i = 0; i < qm->numq; i++) {
-		while (switch_queue_trypop(qm->sql_queue[i], &pop) == SWITCH_STATUS_SUCCESS) {
-			switch_safe_free(pop);
-		}
+		do_flush(qm->sql_queue[i], NULL);
 	}
 
 	pool = qm->pool;
@@ -1313,37 +1345,89 @@ SWITCH_DECLARE(switch_status_t) switch_switch_sql_queue_manager_destroy(switch_s
 	return status;
 }
 
-SWITCH_DECLARE(switch_status_t) switch_switch_sql_queue_manager_push(switch_sql_queue_manager_t *qm, const char *sql, uint32_t pos, switch_bool_t dup)
+SWITCH_DECLARE(switch_status_t) switch_sql_queue_manager_push(switch_sql_queue_manager_t *qm, const char *sql, uint32_t pos, switch_bool_t dup)
 {
 
+	if (sql_manager.paused) {
+		if (!dup) free((char *)sql);
+		qm_wake(qm);
+		return SWITCH_STATUS_SUCCESS;
+	}
+
 	if (!qm->thread_running) {
+		if (!dup) free((char *)sql);
 		return SWITCH_STATUS_FALSE;
 	}
 
-	if (sql_manager.thread_running != 1) {
-		return SWITCH_STATUS_FALSE;
-	}
-	
 	if (pos > qm->numq - 1) {
 		pos = 0;
 	}
-	
+
+	switch_mutex_lock(qm->mutex);
 	switch_queue_push(qm->sql_queue[pos], dup ? strdup(sql) : (char *)sql);
+	switch_mutex_unlock(qm->mutex);
+
 	qm_wake(qm);
 
 	return SWITCH_STATUS_SUCCESS;
 }
 
 
+SWITCH_DECLARE(switch_status_t) switch_sql_queue_manager_push_confirm(switch_sql_queue_manager_t *qm, const char *sql, uint32_t pos, switch_bool_t dup)
+{
+	int size, x = 0, sanity = 0;
+	uint32_t written, want;
+
+	if (sql_manager.paused) {
+		if (!dup) free((char *)sql);
+		qm_wake(qm);
+		return SWITCH_STATUS_SUCCESS;
+	}
+
+	if (!qm->thread_running) {
+		if (!dup) free((char *)sql);
+		return SWITCH_STATUS_FALSE;
+	}
+
+	if (pos > qm->numq - 1) {
+		pos = 0;
+	}
+
+	switch_mutex_lock(qm->mutex);
+	switch_queue_push(qm->sql_queue[pos], dup ? strdup(sql) : (char *)sql);
+	written = qm->written[pos];
+	size = switch_sql_queue_manager_size(qm, pos);
+	want = written + size;
+	switch_mutex_unlock(qm->mutex);
+
+	qm_wake(qm);
+
+	while((qm->written[pos] < want) || (qm->written[pos] >= written && want < written && qm->written[pos] > want)) {
+		switch_yield(5000);
+
+		if (++x == 200) {
+			qm_wake(qm);
+			x = 0;
+			if (++sanity == 20) {
+				break;
+			}
+		}
+	}
+
+	return SWITCH_STATUS_SUCCESS;
+}
+
+
 
 
 
-SWITCH_DECLARE(switch_status_t) switch_switch_sql_queue_manager_init(switch_sql_queue_manager_t **qmp, 
-																	 uint32_t numq, const char *dsn,
-																	 const char *pre_trans_execute,
-																	 const char *post_trans_execute,
-																	 const char *inner_pre_trans_execute,
-																	 const char *inner_post_trans_execute)
+SWITCH_DECLARE(switch_status_t) switch_sql_queue_manager_init_name(const char *name,
+																   switch_sql_queue_manager_t **qmp, 
+																   uint32_t numq, const char *dsn, uint32_t max_trans,
+																   const char *pre_trans_execute,
+																   const char *post_trans_execute,
+																   const char *inner_pre_trans_execute,
+																   const char *inner_post_trans_execute)
 {
 	switch_memory_pool_t *pool;
 	switch_sql_queue_manager_t *qm;
@@ -1357,11 +1441,16 @@ SWITCH_DECLARE(switch_status_t) switch_switch_sql_queue_manager_init(switch_sql_
 	qm->pool = pool;
 	qm->numq = numq;
 	qm->dsn = switch_core_strdup(qm->pool, dsn);
+	qm->name = switch_core_strdup(qm->pool, name);
+	qm->max_trans = max_trans;
 
 	switch_mutex_init(&qm->cond_mutex, SWITCH_MUTEX_NESTED, qm->pool);
+	switch_mutex_init(&qm->mutex, SWITCH_MUTEX_NESTED, qm->pool);
 	switch_thread_cond_create(&qm->cond, qm->pool);
 	
 	qm->sql_queue = switch_core_alloc(qm->pool, sizeof(switch_queue_t *) * numq);
+	qm->written = switch_core_alloc(qm->pool, sizeof(uint32_t) * numq);
+	qm->pre_written = switch_core_alloc(qm->pool, sizeof(uint32_t) * numq);
 
 	for (i = 0; i < qm->numq; i++) {
 		switch_queue_create(&qm->sql_queue[i], SWITCH_SQL_QUEUE_LEN, qm->pool);
@@ -1379,34 +1468,172 @@ SWITCH_DECLARE(switch_status_t) switch_switch_sql_queue_manager_init(switch_sql_
 	return SWITCH_STATUS_SUCCESS;
 
 }
-static void *SWITCH_THREAD_FUNC switch_user_sql_thread(switch_thread_t *thread, void *obj)
+
+static uint32_t do_trans(switch_sql_queue_manager_t *qm)
 {
-	void *pop = NULL;
-	uint32_t iterations = 0;
-	uint8_t trans = 0;
-	uint32_t target = 20000;
-	switch_size_t len = 0, sql_len = runtime.sql_buffer_len;
-	char *tmp, *sqlbuf = (char *) malloc(sql_len);
-	char *sql = NULL, *save_sql = NULL;
-	switch_size_t newlen;
-	int lc = 0, wrote = 0, do_sleep = 1;
-	uint32_t sanity = 120;
-	int auto_pause = 0;
-	switch_sql_queue_manager_t *qm = (switch_sql_queue_manager_t *) obj;
+	char *errmsg = NULL;
+	void *pop;
+	switch_status_t status;
+	uint32_t ttl = 0;
+	switch_mutex_t *io_mutex = qm->event_db->io_mutex;
 	uint32_t i;
 
-	switch_assert(sqlbuf);
+	if (io_mutex) switch_mutex_lock(io_mutex);
+
+	switch_mutex_lock(qm->mutex);
+	for (i = 0; i < qm->numq; i++) {
+		qm->pre_written[i] = 0;
+	}
+	switch_mutex_unlock(qm->mutex);
+
+	if (!zstr(qm->pre_trans_execute)) {
+		switch_cache_db_execute_sql_real(qm->event_db, qm->pre_trans_execute, &errmsg);
+		if (errmsg) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "SQL PRE TRANS EXEC %s [%s]\n", qm->pre_trans_execute, errmsg);
+			free(errmsg);
+		}
+	}
+
+	switch(qm->event_db->type) {
+	case SCDB_TYPE_CORE_DB:
+		{
+			switch_cache_db_execute_sql_real(qm->event_db, "BEGIN", &errmsg);
+		}
+		break;
+	case SCDB_TYPE_ODBC:
+		{
+			switch_odbc_status_t result;
+			
+			if ((result = switch_odbc_SQLSetAutoCommitAttr(qm->event_db->native_handle.odbc_dbh, 0)) != SWITCH_ODBC_SUCCESS) {
+				char tmp[100];
+				switch_snprintfv(tmp, sizeof(tmp), "%q-%i", "Unable to Set AutoCommit Off", result);
+				errmsg = strdup(tmp);
+			}
+		}
+		break;
+	case SCDB_TYPE_PGSQL:
+		{
+			switch_pgsql_status_t result;
+			
+			if ((result = switch_pgsql_SQLSetAutoCommitAttr(qm->event_db->native_handle.pgsql_dbh, 0)) != SWITCH_PGSQL_SUCCESS) {
+				char tmp[100];
+				switch_snprintfv(tmp, sizeof(tmp), "%q-%i", "Unable to Set AutoCommit Off", result);
+				errmsg = strdup(tmp);
+			}
+		}
+		break;
+	}
+
+	if (errmsg) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "ERROR [%s]\n", errmsg);
+		free(errmsg);
+		goto end;
+	}
+
+
+	if (!zstr(qm->inner_pre_trans_execute)) {
+		switch_cache_db_execute_sql_real(qm->event_db, qm->inner_pre_trans_execute, &errmsg);
+		if (errmsg) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "SQL PRE TRANS EXEC %s [%s]\n", qm->inner_pre_trans_execute, errmsg);
+			free(errmsg);
+		}
+	}
+
+
+	while(qm->max_trans == 0 || ttl <= qm->max_trans) {
+		pop = NULL;
+
+		for (i = 0; (qm->max_trans == 0 || ttl <= qm->max_trans) && (i < qm->numq); i++) {
+			switch_mutex_lock(qm->mutex);
+			switch_queue_trypop(qm->sql_queue[i], &pop);
+			switch_mutex_unlock(qm->mutex);
+			if (pop) break;
+		}
+
+		if (pop) {
+			if ((status = switch_cache_db_execute_sql(qm->event_db, (char *) pop, NULL)) == SWITCH_STATUS_SUCCESS) {
+				qm->pre_written[i]++;
+				ttl++;
+			}
+			free(pop);
+			pop = NULL;
+			if (status != SWITCH_STATUS_SUCCESS) break;
+		} else {
+			break;
+		}
+	}
+
+	if (!zstr(qm->inner_post_trans_execute)) {
+		switch_cache_db_execute_sql_real(qm->event_db, qm->inner_post_trans_execute, &errmsg);
+		if (errmsg) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "SQL POST TRANS EXEC %s [%s]\n", qm->inner_post_trans_execute, errmsg);
+			free(errmsg);
+		}
+	}
+
+
+ end:
+
+	switch(qm->event_db->type) {
+	case SCDB_TYPE_CORE_DB:
+		{
+			switch_cache_db_execute_sql_real(qm->event_db, "COMMIT", NULL);
+		}
+		break;
+	case SCDB_TYPE_ODBC:
+		{
+			switch_odbc_SQLEndTran(qm->event_db->native_handle.odbc_dbh, 1);
+			switch_odbc_SQLSetAutoCommitAttr(qm->event_db->native_handle.odbc_dbh, 1);
+		}
+		break;
+	case SCDB_TYPE_PGSQL:
+		{
+			switch_pgsql_SQLEndTran(qm->event_db->native_handle.pgsql_dbh, 1);
+			switch_pgsql_SQLSetAutoCommitAttr(qm->event_db->native_handle.pgsql_dbh, 1);
+			switch_pgsql_finish_results(qm->event_db->native_handle.pgsql_dbh);
+		}
+		break;
+	}
+
+
+	if (!zstr(qm->post_trans_execute)) {
+		switch_cache_db_execute_sql_real(qm->event_db, qm->post_trans_execute, &errmsg);
+		if (errmsg) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "SQL POST TRANS EXEC %s [%s]\n", qm->post_trans_execute, errmsg);
+			free(errmsg);
+		}
+	}
+
+
+	switch_mutex_lock(qm->mutex);
+	for (i = 0; i < qm->numq; i++) {
+		qm->written[i] += qm->pre_written[i];
+	}
+	switch_mutex_unlock(qm->mutex);
+
+
+	if (io_mutex) switch_mutex_unlock(io_mutex);
+
+	return ttl;
+}
+
+static void *SWITCH_THREAD_FUNC switch_user_sql_thread(switch_thread_t *thread, void *obj)
+{
+
+	uint32_t sanity = 120;
+	switch_sql_queue_manager_t *qm = (switch_sql_queue_manager_t *) obj;
+	uint32_t i, countdown = 0;
 
 	while (!qm->event_db) {
 		if (switch_cache_db_get_db_handle_dsn(&qm->event_db, qm->dsn) == SWITCH_STATUS_SUCCESS && qm->event_db)
 			break;
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Error getting core db, Retrying\n");
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "%s Error getting db handle, Retrying\n", qm->name);
 		switch_yield(500000);
 		sanity--;
 	}
 
 	if (!qm->event_db) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error getting core db\n");
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "%s Error getting db handle\n", qm->name);
 		return NULL;
 	}
 
@@ -1429,393 +1656,67 @@ static void *SWITCH_THREAD_FUNC switch_user_sql_thread(switch_thread_t *thread,
 		break;
 	}
 
-	while (qm->thread_running == 1) {
-		int proceed = !!save_sql;
 
-		if (!proceed) {
+	while (qm->thread_running == 1) {
+		uint32_t i, lc;
+		uint32_t written, iterations = 0;
+
+		if (sql_manager.paused) {
 			for (i = 0; i < qm->numq; i++) {
-				if (switch_queue_trypop(qm->sql_queue[i], &pop) == SWITCH_STATUS_SUCCESS) {
-					if (sql_manager.thread_running != 1) {
-						free(pop);
-						pop = NULL;
-					} else {
-						proceed = 1;
-						break;
-					}
-				}
+				do_flush(qm->sql_queue[i], NULL);
 			}
+			goto check;
 		}
 
-		if (proceed) {
-
-			if (save_sql) {
-				sql = save_sql;
-				save_sql = NULL;
-			} else if ((sql = (char *) pop)) {
-				pop = NULL;
+		do {
+			written = do_trans(qm);
+			iterations += written;
+		} while(written == qm->max_trans);
+		
+		if (switch_test_flag((&runtime), SCF_DEBUG_SQL)) {
+			char line[128] = "";
+			int l;
+			
+			switch_snprintf(line, sizeof(line), "%s RUN QUEUE [", qm->name);
+			
+			for (i = 0; i < qm->numq; i++) {
+				l = strlen(line);
+				switch_snprintf(line + l, sizeof(line) - l, "%d%s", switch_queue_size(qm->sql_queue[i]), i == qm->numq - 1 ? "" : "|");
 			}
 			
-			if (sql) {
-				newlen = strlen(sql) + 2;
+			l = strlen(line);
+			switch_snprintf(line + l, sizeof(line) - l, "]--[%d]\n", iterations);
+			
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "%s", line);
+			
+		}
 
-				if (iterations == 0) {
-					trans = 1;
-				}
+	check:
 
-				if (len + newlen + 1 > sql_len) {
-					int new_mlen = len + newlen + 10240;
-					
-					if (new_mlen < runtime.max_sql_buffer_len) {
-						sql_len = new_mlen;
-						if (switch_test_flag((&runtime), SCF_DEBUG_SQL)) {
-														for (i = 0; i < qm->numq; i++) {
-								switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, 
-												  "REALLOC QUEUE %ld %d %d\n", 
-												  (long int)sql_len,
-												  i,
-												  switch_queue_size(qm->sql_queue[i]));
-								
-							}
-						}
-						if (!(tmp = realloc(sqlbuf, sql_len))) {
-							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "SQL thread ending on mem err\n");
-							abort();
-							break;
-						}
-						sqlbuf = tmp;
-					} else {
-						if (switch_test_flag((&runtime), SCF_DEBUG_SQL)) {
-							for (i = 0; i < qm->numq; i++) {
-								switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, 
-												  "SAVE QUEUE %d %d\n", 
-												  i,
-												  switch_queue_size(qm->sql_queue[i]));
-								
-							}
-						}
-						save_sql = sql;
-						sql = NULL;
-						lc = 0;
-						goto skip;
-					}
-				}
+		countdown = 40;
 
-				iterations++;				
-				sprintf(sqlbuf + len, "%s;\n", sql);
-				len += newlen;
-				free(sql);
-				sql = NULL;
-			} else {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "SQL thread ending\n");
+		while (--countdown && (lc = qm_ttl(qm)) < qm->max_trans / 4) {
+			if (lc == 0) {
+				switch_thread_cond_wait(qm->cond, qm->cond_mutex);					
 				break;
 			}
-		}
-
-		lc = qm_ttl(qm);
-		
-
-		if (lc > SWITCH_SQL_QUEUE_PAUSE_LEN) {
-			if (!auto_pause) {
-				auto_pause = 1;
-				switch_core_session_ctl(SCSC_PAUSE_INBOUND, &auto_pause);
-				auto_pause = 1;
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "SQL Queue overflowing [%d], Pausing calls.\n", lc);
-			}
-		} else {
-			if (auto_pause && lc < 1000) {
-				auto_pause = 0;
-				switch_core_session_ctl(SCSC_PAUSE_INBOUND, &auto_pause);
-				auto_pause = 0;
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "SQL Queue back to normal size, resuming..\n");
-			}
-		}
-	
-	skip:
-		
-		wrote = 0;
-
-		if (trans && iterations && (iterations > target || !lc)) {
-			if (switch_test_flag((&runtime), SCF_DEBUG_SQL)) {
-				for (i = 0; i < qm->numq; i++) {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, 
-									  "RUN QUEUE %d %d %d\n", 
-									  i,
-									  switch_queue_size(qm->sql_queue[i]), 
-									  iterations);
-				}
-			}
-			if (switch_cache_db_persistant_execute_trans_full(qm->event_db, sqlbuf, 1,
-															  qm->pre_trans_execute,
-															  qm->post_trans_execute,
-															  qm->inner_pre_trans_execute,
-															  qm->inner_post_trans_execute
-															  ) != SWITCH_STATUS_SUCCESS) {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "SQL thread unable to commit transaction, records lost!\n");
-			}
-			if (switch_test_flag((&runtime), SCF_DEBUG_SQL)) { 
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "DONE\n");
-			}
-
-
-			iterations = 0;
-			trans = 0;
-			len = 0;
-			*sqlbuf = '\0';
-			lc = 0;
-			if (do_sleep) {
-				switch_yield(200000);
-			} else {
-				switch_yield(1000);
-			}
-			wrote = 1;
-		}
-
-		lc = qm_ttl(qm);
-		
-		if (!lc) {
-			switch_thread_cond_wait(qm->cond, qm->cond_mutex);
-		} else if (wrote) {
-			if (lc > 2000) {
-				do_sleep = 0;
-			} else {
-				do_sleep = 1;
-			}
+			switch_yield(5000);
 		}
 	}
 
 	switch_mutex_unlock(qm->cond_mutex);
 
 	for(i = 0; i < qm->numq; i++) {
-		while (switch_queue_trypop(qm->sql_queue[i], &pop) == SWITCH_STATUS_SUCCESS) {
-			switch_safe_free(pop);
-		}
+		do_flush(qm->sql_queue[i], qm->event_db);
 	}
 
-	free(sqlbuf);
-
 	qm->thread_running = 0;
 
 	switch_cache_db_release_db_handle(&qm->event_db);
-
+	
 	return NULL;
 }
 
-static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread, void *obj)
-{
-	void *pop = NULL;
-	uint32_t iterations = 0;
-	uint8_t trans = 0;
-	uint32_t target = 20000;
-	switch_size_t len = 0, sql_len = runtime.sql_buffer_len;
-	char *tmp, *sqlbuf = (char *) malloc(sql_len);
-	char *sql = NULL, *save_sql = NULL;
-	switch_size_t newlen;
-	int lc = 0, wrote = 0, do_sleep = 1;
-	uint32_t sanity = 120;
-	int auto_pause = 0;
-
-	switch_assert(sqlbuf);
-
-	while (!sql_manager.event_db) {
-		if (switch_core_db_handle(&sql_manager.event_db) == SWITCH_STATUS_SUCCESS && sql_manager.event_db)
-			break;
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Error getting core db, Retrying\n");
-		switch_yield(500000);
-		sanity--;
-	}
-
-	if (!sql_manager.event_db) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error getting core db Disabling core sql functionality\n");
-		return NULL;
-	}
-
-	sql_manager.thread_running = 1;
-
-	switch_mutex_lock(sql_manager.cond_mutex);
-
-	switch (sql_manager.event_db->type) {
-	case SCDB_TYPE_PGSQL:
-		break;
-	case SCDB_TYPE_ODBC:
-		break;
-	case SCDB_TYPE_CORE_DB:
-		{
-			switch_cache_db_execute_sql(sql_manager.event_db, "PRAGMA synchronous=OFF;", NULL);
-			switch_cache_db_execute_sql(sql_manager.event_db, "PRAGMA count_changes=OFF;", NULL);
-			switch_cache_db_execute_sql(sql_manager.event_db, "PRAGMA temp_store=MEMORY;", NULL);
-			switch_cache_db_execute_sql(sql_manager.event_db, "PRAGMA journal_mode=OFF;", NULL);
-		}
-		break;
-	}
-
-	while (sql_manager.thread_running == 1) {
-		if (save_sql || 
-			switch_queue_trypop(sql_manager.sql_queue[0], &pop) == SWITCH_STATUS_SUCCESS ||
-			switch_queue_trypop(sql_manager.sql_queue[1], &pop) == SWITCH_STATUS_SUCCESS ||
-			switch_queue_trypop(sql_manager.sql_queue[2], &pop) == SWITCH_STATUS_SUCCESS ||
-			switch_queue_trypop(sql_manager.sql_queue[3], &pop) == SWITCH_STATUS_SUCCESS 
-			) {
-
-			if (save_sql) {
-				sql = save_sql;
-				save_sql = NULL;
-			} else if ((sql = (char *) pop)) {
-				pop = NULL;
-			}
-			
-			if (sql) {
-				newlen = strlen(sql) + 2;
-
-				if (iterations == 0) {
-					trans = 1;
-				}
-
-				if (len + newlen + 1 > sql_len) {
-					int new_mlen = len + newlen + 10240;
-					
-					if (new_mlen < runtime.max_sql_buffer_len) {
-						sql_len = new_mlen;
-						if (switch_test_flag((&runtime), SCF_DEBUG_SQL)) {
-							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, 
-											  "REALLOC %ld %d %d\n", (long int)sql_len, switch_queue_size(sql_manager.sql_queue[0]), 
-											  switch_queue_size(sql_manager.sql_queue[1]));
-						}
-						if (!(tmp = realloc(sqlbuf, sql_len))) {
-							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "SQL thread ending on mem err\n");
-							abort();
-							break;
-						}
-						sqlbuf = tmp;
-					} else {
-						if (switch_test_flag((&runtime), SCF_DEBUG_SQL)) {
-							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, 
-											  "SAVE %d %d %d %d\n", 
-											  switch_queue_size(sql_manager.sql_queue[0]), 
-											  switch_queue_size(sql_manager.sql_queue[1]),
-											  switch_queue_size(sql_manager.sql_queue[2]), 
-											  switch_queue_size(sql_manager.sql_queue[3])
-											  );
-						}
-						save_sql = sql;
-						sql = NULL;
-						lc = 0;
-						goto skip;
-					}
-				}
-
-				iterations++;				
-				sprintf(sqlbuf + len, "%s;\n", sql);
-				len += newlen;
-				free(sql);
-				sql = NULL;
-			} else {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "SQL thread ending\n");
-				break;
-			}
-		}
-
-		lc = switch_queue_size(sql_manager.sql_queue[0]) + switch_queue_size(sql_manager.sql_queue[1]) + 
-			switch_queue_size(sql_manager.sql_queue[2]) + switch_queue_size(sql_manager.sql_queue[3]);
-
-
-		if (lc > SWITCH_SQL_QUEUE_PAUSE_LEN) {
-			if (!auto_pause) {
-				auto_pause = 1;
-				switch_core_session_ctl(SCSC_PAUSE_INBOUND, &auto_pause);
-				auto_pause = 1;
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "SQL Queue overflowing [%d], Pausing calls.\n", lc);
-			}
-		} else {
-			if (auto_pause && lc < 1000) {
-				auto_pause = 0;
-				switch_core_session_ctl(SCSC_PAUSE_INBOUND, &auto_pause);
-				auto_pause = 0;
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "SQL Queue back to normal size, resuming..\n");
-			}
-		}
-
-	skip:
-		
-		wrote = 0;
-
-		if (trans && iterations && (iterations > target || !lc)) {
-			if (switch_test_flag((&runtime), SCF_DEBUG_SQL)) {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, 
-								  "RUN %d %d %d %d %d\n", 
-								  switch_queue_size(sql_manager.sql_queue[0]), 
-								  switch_queue_size(sql_manager.sql_queue[1]), 
-								  switch_queue_size(sql_manager.sql_queue[2]), 
-								  switch_queue_size(sql_manager.sql_queue[3]), 
-								  iterations);
-			}
-			if (switch_cache_db_persistant_execute_trans_full(sql_manager.event_db, sqlbuf, 1,
-															  runtime.core_db_pre_trans_execute,
-															  runtime.core_db_post_trans_execute,
-															  runtime.core_db_inner_pre_trans_execute,
-															  runtime.core_db_inner_post_trans_execute
-															  ) != SWITCH_STATUS_SUCCESS) {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "SQL thread unable to commit transaction, records lost!\n");
-			}
-			if (switch_test_flag((&runtime), SCF_DEBUG_SQL)) { 
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "DONE\n");
-			}
-
-
-			iterations = 0;
-			trans = 0;
-			len = 0;
-			*sqlbuf = '\0';
-			lc = 0;
-			if (do_sleep) {
-				switch_yield(200000);
-			} else {
-				switch_yield(1000);
-			}
-			wrote = 1;
-		}
-
-		lc = switch_queue_size(sql_manager.sql_queue[0]) + switch_queue_size(sql_manager.sql_queue[1]) +
-			switch_queue_size(sql_manager.sql_queue[2]) + switch_queue_size(sql_manager.sql_queue[3]);
-		
-		if (!lc) {
-			switch_thread_cond_wait(sql_manager.cond, sql_manager.cond_mutex);
-		} else if (wrote) {
-			if (lc > 2000) {
-				do_sleep = 0;
-			} else {
-				do_sleep = 1;
-			}
-		}
-		
-		
-	}
-
-	switch_mutex_unlock(sql_manager.cond_mutex);
-
-	while (switch_queue_trypop(sql_manager.sql_queue[0], &pop) == SWITCH_STATUS_SUCCESS) {
-		free(pop);
-	}
-
-	while (switch_queue_trypop(sql_manager.sql_queue[1], &pop) == SWITCH_STATUS_SUCCESS) {
-		free(pop);
-	}
-
-	while (switch_queue_trypop(sql_manager.sql_queue[2], &pop) == SWITCH_STATUS_SUCCESS) {
-		free(pop);
-	}
-
-	while (switch_queue_trypop(sql_manager.sql_queue[3], &pop) == SWITCH_STATUS_SUCCESS) {
-		free(pop);
-	}
-
-	free(sqlbuf);
-
-	sql_manager.thread_running = 0;
-
-	switch_cache_db_release_db_handle(&sql_manager.event_db);
-
-	return NULL;
-}
 
 static char *parse_presence_data_cols(switch_event_t *event)
 {
@@ -1864,16 +1765,44 @@ static char *parse_presence_data_cols(switch_event_t *event)
 
 
 #define MAX_SQL 5
-#define new_sql() switch_assert(sql_idx+1 < MAX_SQL); sql[sql_idx++]
+#define new_sql()   switch_assert(sql_idx+1 < MAX_SQL); if (exists) sql[sql_idx++]
+#define new_sql_a() switch_assert(sql_idx+1 < MAX_SQL); sql[sql_idx++]
 
 static void core_event_handler(switch_event_t *event)
 {
 	char *sql[MAX_SQL] = { 0 };
 	int sql_idx = 0;
 	char *extra_cols;
+	int exists = 1;
+	char *uuid = NULL;
 
 	switch_assert(event);
 
+	switch (event->event_id) {
+	case SWITCH_EVENT_CHANNEL_UUID:
+	case SWITCH_EVENT_CHANNEL_CREATE:
+	case SWITCH_EVENT_CHANNEL_ANSWER:
+	case SWITCH_EVENT_CHANNEL_PROGRESS_MEDIA:
+	case SWITCH_EVENT_CHANNEL_HOLD:
+	case SWITCH_EVENT_CHANNEL_UNHOLD:
+	case SWITCH_EVENT_CHANNEL_EXECUTE:
+	case SWITCH_EVENT_CHANNEL_ORIGINATE:
+	case SWITCH_EVENT_CALL_UPDATE:
+	case SWITCH_EVENT_CHANNEL_CALLSTATE:
+	case SWITCH_EVENT_CHANNEL_STATE:
+	case SWITCH_EVENT_CHANNEL_BRIDGE:
+	case SWITCH_EVENT_CHANNEL_UNBRIDGE:
+	case SWITCH_EVENT_CALL_SECURE:
+		{
+			if ((uuid = switch_event_get_header(event, "unique-id"))) {
+				exists = switch_ivr_uuid_exists(uuid);
+			}
+		}
+		break;
+	default:
+		break;
+	}
+
 	switch (event->event_id) {
 	case SWITCH_EVENT_ADD_SCHEDULE:
 		{
@@ -1948,7 +1877,8 @@ static void core_event_handler(switch_event_t *event)
 								   switch_event_get_header_nil(event, "caller-context"), switch_core_get_switchname()
 								   );
 		break;
-	case SWITCH_EVENT_CODEC:
+	case SWITCH_EVENT_CHANNEL_ANSWER:
+	case SWITCH_EVENT_CHANNEL_PROGRESS_MEDIA:
 
 		new_sql() =
 			switch_mprintf
@@ -2053,7 +1983,18 @@ static void core_event_handler(switch_event_t *event)
 			case CS_NEW:
 			case CS_DESTROY:
 			case CS_REPORTING:
+#ifndef SWITCH_DEPRECATED_CORE_DB
+			case CS_HANGUP: /* marked for deprication */
+#endif
+			case CS_INIT:
 				break;
+#ifdef SWITCH_DEPRECATED_CORE_DB
+			case CS_HANGUP: /* marked for deprication */
+				new_sql_a() = switch_mprintf("update channels set state='%s' where uuid='%s'",
+											 switch_event_get_header_nil(event, "channel-state"),
+											 switch_event_get_header_nil(event, "unique-id"));
+				break;
+#endif
 			case CS_EXECUTE:
 				if ((extra_cols = parse_presence_data_cols(event))) {
 					new_sql() = switch_mprintf("update channels set state='%s',%s where uuid='%q'",
@@ -2254,12 +2195,11 @@ static void core_event_handler(switch_event_t *event)
 
 		for (i = 0; i < sql_idx; i++) {
 			if (switch_stristr("update channels", sql[i]) || switch_stristr("delete from channels", sql[i])) {
-				switch_queue_push(sql_manager.sql_queue[1], sql[i]);
+				switch_sql_queue_manager_push(sql_manager.qm, sql[i], 1, SWITCH_FALSE);
 			} else {
-				switch_queue_push(sql_manager.sql_queue[0], sql[i]);
+				switch_sql_queue_manager_push(sql_manager.qm, sql[i], 0, SWITCH_FALSE);
 			}
 			sql[i] = NULL;
-			wake_thread(0);
 		}
 	}
 }
@@ -2636,6 +2576,11 @@ SWITCH_DECLARE(int) switch_core_recovery_recover(const char *technology, const c
 	switch_cache_db_handle_t *dbh;
 	int r = 0;
 
+	if (!sql_manager.manage) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "DATABASE NOT AVAIALBLE, REVCOVERY NOT POSSIBLE\n");
+		return 0;
+	}
+
 	if (switch_core_db_handle(&dbh) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB!\n");
 		return 0;
@@ -2705,16 +2650,29 @@ SWITCH_DECLARE(int) switch_core_recovery_recover(const char *technology, const c
 
 SWITCH_DECLARE(switch_cache_db_handle_type_t) switch_core_dbtype(void)
 {
-	return sql_manager.event_db->type;
+	switch_cache_db_handle_type_t type = SCDB_TYPE_CORE_DB;
+
+	switch_mutex_lock(sql_manager.ctl_mutex);
+	if (sql_manager.qm && sql_manager.qm->event_db) {
+		type = sql_manager.qm->event_db->type;
+	}
+	switch_mutex_unlock(sql_manager.ctl_mutex);
+
+	return type;
 }
 
 SWITCH_DECLARE(void) switch_core_sql_exec(const char *sql)
 {
+	if (!sql_manager.manage) {
+		return;
+	}
+
 	if (!switch_test_flag((&runtime), SCF_USE_SQL)) {
 		return;
 	}
 
-	switch_queue_push(sql_manager.sql_queue[3], strdup(sql));
+
+	switch_sql_queue_manager_push(sql_manager.qm, sql, 3, SWITCH_TRUE);
 }
 
 SWITCH_DECLARE(void) switch_core_recovery_untrack(switch_core_session_t *session, switch_bool_t force)
@@ -2722,6 +2680,10 @@ SWITCH_DECLARE(void) switch_core_recovery_untrack(switch_core_session_t *session
 	char *sql = NULL;
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 
+	if (!sql_manager.manage) {
+		return;
+	}
+
 	if (!switch_channel_test_flag(channel, CF_ANSWERED) || switch_channel_get_state(channel) < CS_SOFT_EXECUTE) {
 		return;
 	}
@@ -2744,7 +2706,7 @@ SWITCH_DECLARE(void) switch_core_recovery_untrack(switch_core_session_t *session
 								 switch_core_get_uuid(), switch_core_session_get_uuid(session));
 		}
 
-		switch_queue_push(sql_manager.sql_queue[3], sql);
+		switch_sql_queue_manager_push(sql_manager.qm, sql, 3, SWITCH_FALSE);
 		
 		switch_channel_clear_flag(channel, CF_TRACKED);
 	}
@@ -2760,6 +2722,9 @@ SWITCH_DECLARE(void) switch_core_recovery_track(switch_core_session_t *session)
 	const char *profile_name;
 	const char *technology;
 
+	if (!sql_manager.manage) {
+		return;
+	}
 
 	if (!switch_channel_test_flag(channel, CF_ANSWERED) || switch_channel_get_state(channel) < CS_SOFT_EXECUTE) {
 		return;
@@ -2787,7 +2752,7 @@ SWITCH_DECLARE(void) switch_core_recovery_track(switch_core_session_t *session)
 								 switch_str_nil(profile_name), switch_core_get_hostname(), switch_core_session_get_uuid(session), xml_cdr_text);
 		}
 
-		switch_queue_push(sql_manager.sql_queue[2], sql);
+		switch_sql_queue_manager_push(sql_manager.qm, sql, 2, SWITCH_FALSE);
 
 		free(xml_cdr_text);
 		switch_channel_set_flag(channel, CF_TRACKED);
@@ -2816,7 +2781,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_add_registration(const char *user, c
 							 user, realm, switch_core_get_switchname());
 	}
 
-	switch_queue_push(sql_manager.sql_queue[0], sql);
+	switch_sql_queue_manager_push(sql_manager.qm, sql, 0, SWITCH_FALSE);
 
 	if ( !zstr(metadata) ) {
 		sql = switch_mprintf("insert into registrations (reg_user,realm,token,url,expires,network_ip,network_port,network_proto,hostname,metadata) "
@@ -2848,7 +2813,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_add_registration(const char *user, c
 	}
 
 	
-	switch_queue_push(sql_manager.sql_queue[0], sql);
+	switch_sql_queue_manager_push(sql_manager.qm, sql, 0, SWITCH_FALSE);
 	
 	return SWITCH_STATUS_SUCCESS;
 }
@@ -2868,7 +2833,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_del_registration(const char *user, c
 		sql = switch_mprintf("delete from registrations where reg_user='%q' and realm='%q' and hostname='%q'", user, realm, switch_core_get_switchname());
 	}
 
-	switch_queue_push(sql_manager.sql_queue[0], sql);
+	switch_sql_queue_manager_push(sql_manager.qm, sql, 0, SWITCH_FALSE);
+
 
 	return SWITCH_STATUS_SUCCESS;
 }
@@ -2891,7 +2857,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_expire_registration(int force)
 		sql = switch_mprintf("delete from registrations where expires > 0 and expires <= %ld and hostname='%q'", now, switch_core_get_switchname());
 	}
 
-	switch_queue_push(sql_manager.sql_queue[0], sql);
+	switch_sql_queue_manager_push(sql_manager.qm, sql, 0, SWITCH_FALSE);
 
 	return SWITCH_STATUS_SUCCESS;
 
@@ -2900,20 +2866,14 @@ SWITCH_DECLARE(switch_status_t) switch_core_expire_registration(int force)
 switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_t manage)
 {
 	switch_threadattr_t *thd_attr;
-	uint32_t sanity = 400;
 
 	sql_manager.memory_pool = pool;
 	sql_manager.manage = manage;
 
 	switch_mutex_init(&sql_manager.dbh_mutex, SWITCH_MUTEX_NESTED, sql_manager.memory_pool);
 	switch_mutex_init(&sql_manager.io_mutex, SWITCH_MUTEX_NESTED, sql_manager.memory_pool);
-	switch_mutex_init(&sql_manager.cond_mutex, SWITCH_MUTEX_NESTED, sql_manager.memory_pool);
 	switch_mutex_init(&sql_manager.ctl_mutex, SWITCH_MUTEX_NESTED, sql_manager.memory_pool);
 
-	switch_thread_cond_create(&sql_manager.cond, sql_manager.memory_pool);
-
-
-
 	if (!sql_manager.manage) goto skip;
 
  top:	
@@ -2983,6 +2943,15 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_
 	switch_cache_db_test_reactive(sql_manager.dbh, "select metadata from registrations", NULL, "ALTER TABLE registrations ADD COLUMN metadata VARCHAR(256)");
 
 
+	switch_cache_db_test_reactive(sql_manager.dbh, "select hostname from recovery", "DROP TABLE recovery", recovery_sql);
+	switch_cache_db_execute_sql(sql_manager.dbh, "create index recovery1 on recovery(technology)", NULL);
+	switch_cache_db_execute_sql(sql_manager.dbh, "create index recovery2 on recovery(profile_name)", NULL);
+	switch_cache_db_execute_sql(sql_manager.dbh, "create index recovery3 on recovery(uuid)", NULL);
+	switch_cache_db_execute_sql(sql_manager.dbh, "create index recovery3 on recovery(runtime_uuid)", NULL);
+
+
+
+
 	switch (sql_manager.dbh->type) {
 	case SCDB_TYPE_PGSQL:
 	case SCDB_TYPE_ODBC:
@@ -3074,7 +3043,8 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_
 		switch_event_bind("core_db", SWITCH_EVENT_CHANNEL_DESTROY, SWITCH_EVENT_SUBCLASS_ANY, core_event_handler, NULL);
 		switch_event_bind("core_db", SWITCH_EVENT_CHANNEL_UUID, SWITCH_EVENT_SUBCLASS_ANY, core_event_handler, NULL);
 		switch_event_bind("core_db", SWITCH_EVENT_CHANNEL_CREATE, SWITCH_EVENT_SUBCLASS_ANY, core_event_handler, NULL);
-		switch_event_bind("core_db", SWITCH_EVENT_CODEC, SWITCH_EVENT_SUBCLASS_ANY, core_event_handler, NULL);
+		switch_event_bind("core_db", SWITCH_EVENT_CHANNEL_ANSWER, SWITCH_EVENT_SUBCLASS_ANY, core_event_handler, NULL);
+		switch_event_bind("core_db", SWITCH_EVENT_CHANNEL_PROGRESS_MEDIA, SWITCH_EVENT_SUBCLASS_ANY, core_event_handler, NULL);
 		switch_event_bind("core_db", SWITCH_EVENT_CHANNEL_HOLD, SWITCH_EVENT_SUBCLASS_ANY, core_event_handler, NULL);
 		switch_event_bind("core_db", SWITCH_EVENT_CHANNEL_UNHOLD, SWITCH_EVENT_SUBCLASS_ANY, core_event_handler, NULL);
 		switch_event_bind("core_db", SWITCH_EVENT_CHANNEL_EXECUTE, SWITCH_EVENT_SUBCLASS_ANY, core_event_handler, NULL);
@@ -3092,126 +3062,77 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_
 		switch_event_bind("core_db", SWITCH_EVENT_NAT, SWITCH_EVENT_SUBCLASS_ANY, core_event_handler, NULL);
 #endif	
 
-		switch_queue_create(&sql_manager.sql_queue[0], SWITCH_SQL_QUEUE_LEN, sql_manager.memory_pool);
-		switch_queue_create(&sql_manager.sql_queue[1], SWITCH_SQL_QUEUE_LEN, sql_manager.memory_pool);
-		switch_queue_create(&sql_manager.sql_queue[2], SWITCH_SQL_QUEUE_LEN, sql_manager.memory_pool);
-		switch_queue_create(&sql_manager.sql_queue[3], SWITCH_SQL_QUEUE_LEN, sql_manager.memory_pool);
-
 		switch_threadattr_create(&thd_attr, sql_manager.memory_pool);
 		switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
 		switch_threadattr_priority_set(thd_attr, SWITCH_PRI_REALTIME);
 		switch_core_sqldb_start_thread();
 		switch_thread_create(&sql_manager.db_thread, thd_attr, switch_core_sql_db_thread, NULL, sql_manager.memory_pool);
 
-		while (sql_manager.manage && !sql_manager.thread_running && --sanity) {
-			switch_yield(10000);
-		}
 	}
 	return SWITCH_STATUS_SUCCESS;
 }
 
-
-SWITCH_DECLARE(void) switch_core_sqldb_stop_thread(void)
+SWITCH_DECLARE(void) switch_core_sqldb_pause(void)
 {
-	switch_mutex_lock(sql_manager.ctl_mutex);
-	if (sql_manager.thread && sql_manager.thread_running) {
-		switch_status_t st;
-
-		if (sql_manager.manage) {
-			switch_queue_push(sql_manager.sql_queue[0], NULL);
-			switch_queue_push(sql_manager.sql_queue[1], NULL);
-			switch_queue_push(sql_manager.sql_queue[2], NULL);
-			switch_queue_push(sql_manager.sql_queue[3], NULL);
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Waiting for unfinished SQL transactions\n");
-			wake_thread(0);
-			sql_manager.thread_running = -1;
-			switch_thread_join(&st, sql_manager.thread);
-			sql_manager.thread = NULL;
-			switch_cache_db_release_db_handle(&sql_manager.dbh);
-			sql_manager.dbh = NULL;
-		} else {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL is not enabled\n");
-		}
-	} else {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL thread is not running\n");
+	if (sql_manager.paused) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "SQL is already paused.\n");
 	}
-	switch_mutex_unlock(sql_manager.ctl_mutex);
+	sql_manager.paused = 1;
 }
 
-SWITCH_DECLARE(void) switch_core_sqldb_start_thread(void)
+SWITCH_DECLARE(void) switch_core_sqldb_resume(void)
 {
-	switch_cache_db_handle_t *dbh;
-
-	switch_mutex_lock(sql_manager.ctl_mutex);
-
-	if (switch_core_db_handle(&dbh) != SWITCH_STATUS_SUCCESS) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB!\n");
-			
-		if (switch_test_flag((&runtime), SCF_CORE_NON_SQLITE_DB_REQ)) {
-			int arg = 1;
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failure! ODBC OR PGSQL IS REQUIRED!\n");
-			switch_core_session_ctl(SCSC_SHUTDOWN_NOW, &arg);
-		}
-			
-		
-	} else {
-		switch_cache_db_test_reactive(dbh, "select hostname from recovery", "DROP TABLE recovery", recovery_sql);
-		switch_cache_db_execute_sql(dbh, "create index recovery1 on recovery(technology)", NULL);
-		switch_cache_db_execute_sql(dbh, "create index recovery2 on recovery(profile_name)", NULL);
-		switch_cache_db_execute_sql(dbh, "create index recovery3 on recovery(uuid)", NULL);
-		switch_cache_db_execute_sql(dbh, "create index recovery3 on recovery(runtime_uuid)", NULL);
-		switch_cache_db_release_db_handle(&dbh);
+	if (!sql_manager.paused) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "SQL is already running.\n");
 	}
+	sql_manager.paused = 0;
+}
 
 
+static void switch_core_sqldb_stop_thread(void)
+{
+	switch_mutex_lock(sql_manager.ctl_mutex);
 	if (sql_manager.manage) {
-
-	top:
-
-		if (!sql_manager.dbh) {
-			/* Activate SQL database */
-			if (switch_core_db_handle(&sql_manager.dbh) != SWITCH_STATUS_SUCCESS) {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB!\n");
-				
-				if (switch_test_flag((&runtime), SCF_CORE_NON_SQLITE_DB_REQ)) {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failure! ODBC OR PGSQL IS REQUIRED!\n");
-					goto end;
-				}
-				
-				if (runtime.odbc_dsn) {
-					runtime.odbc_dsn = NULL;
-					runtime.odbc_dbtype = DBTYPE_DEFAULT;
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Falling back to core_db.\n");
-					sql_manager.dbh = NULL;
-					goto top;
-				}
-
-
-				switch_clear_flag((&runtime), SCF_USE_SQL);
-				goto end;
-			}
-
-			switch_cache_db_execute_sql(sql_manager.dbh, "delete from channels", NULL);
-			switch_cache_db_execute_sql(sql_manager.dbh, "delete from calls", NULL);
-		}
-
-
-		if (!sql_manager.thread) {
-			switch_threadattr_t *thd_attr;
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Starting SQL thread.\n");
-			switch_threadattr_create(&thd_attr, sql_manager.memory_pool);
-			switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
-			switch_threadattr_priority_set(thd_attr, SWITCH_PRI_REALTIME);
-			switch_thread_create(&sql_manager.thread, thd_attr, switch_core_sql_thread, NULL, sql_manager.memory_pool);
-		} else {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL thread is already running\n");
+		if (sql_manager.qm) {
+			switch_sql_queue_manager_destroy(&sql_manager.qm);
 		}
 	} else {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL is not enabled\n");
 	}
+	
+	switch_mutex_unlock(sql_manager.ctl_mutex);
+}
 
- end:
+static void switch_core_sqldb_start_thread(void)
+{
 
+	switch_mutex_lock(sql_manager.ctl_mutex);
+	if (sql_manager.manage) {
+		if (!sql_manager.qm) {
+			char *dbname = runtime.odbc_dsn;
+
+			if (zstr(dbname)) {
+				dbname = runtime.dbname;
+				if (zstr(dbname)) {
+					dbname = "core";
+				}
+			}
+
+			switch_sql_queue_manager_init_name("CORE",
+											   &sql_manager.qm,
+											   4,
+											   dbname,
+											   SWITCH_MAX_TRANS,
+											   runtime.core_db_pre_trans_execute,
+											   runtime.core_db_post_trans_execute,
+											   runtime.core_db_inner_pre_trans_execute,
+											   runtime.core_db_inner_post_trans_execute);
+
+		}
+		switch_sql_queue_manager_start(sql_manager.qm);
+	} else {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL is not enabled\n");
+	}
 	switch_mutex_unlock(sql_manager.ctl_mutex);
 }
 
diff --git a/src/switch_core_state_machine.c b/src/switch_core_state_machine.c
index ad9af6ca5e..87b8a32a20 100644
--- a/src/switch_core_state_machine.c
+++ b/src/switch_core_state_machine.c
@@ -457,6 +457,13 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session)
 						switch_channel_event_set_data(session->channel, event);
 						switch_event_fire(&event);
 					}
+
+					if (switch_channel_direction(session->channel) == SWITCH_CALL_DIRECTION_OUTBOUND) {
+						if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_ORIGINATE) == SWITCH_STATUS_SUCCESS) {
+							switch_channel_event_set_data(session->channel, event);
+							switch_event_fire(&event);
+						}
+					}
 				}
 				break;
 			case CS_ROUTING:	/* Look for a dialplan and find something to do */
diff --git a/src/switch_ivr.c b/src/switch_ivr.c
index df5af62391..eb8d4ab9e6 100644
--- a/src/switch_ivr.c
+++ b/src/switch_ivr.c
@@ -3209,6 +3209,19 @@ SWITCH_DECLARE(switch_bool_t) switch_ivr_uuid_exists(const char *uuid)
 	return exists;
 }
 
+SWITCH_DECLARE(switch_bool_t) switch_ivr_uuid_force_exists(const char *uuid)
+{
+	switch_bool_t exists = SWITCH_FALSE;
+	switch_core_session_t *psession = NULL;
+
+	if ((psession = switch_core_session_force_locate(uuid))) {
+		switch_core_session_rwunlock(psession);
+		exists = 1;
+	}
+
+	return exists;
+}
+
 SWITCH_DECLARE(switch_status_t) switch_ivr_process_fh(switch_core_session_t *session, const char *cmd, switch_file_handle_t *fhp)
 {
     if (zstr(cmd)) {
diff --git a/src/switch_ivr_bridge.c b/src/switch_ivr_bridge.c
index 24e18f6b58..b286ab5918 100644
--- a/src/switch_ivr_bridge.c
+++ b/src/switch_ivr_bridge.c
@@ -745,7 +745,7 @@ static switch_status_t uuid_bridge_on_reset(switch_core_session_t *session)
 
 	cleanup_proxy_mode_b(session);
 
-	if (switch_channel_test_flag(channel, CF_BRIDGE_ORIGINATOR)) {
+	if (switch_channel_test_flag(channel, CF_UUID_BRIDGE_ORIGINATOR)) {
 		switch_channel_set_state(channel, CS_SOFT_EXECUTE);
 	}
 
@@ -767,7 +767,7 @@ static switch_status_t uuid_bridge_on_soft_execute(switch_core_session_t *sessio
 	switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s CUSTOM SOFT_EXECUTE\n", switch_channel_get_name(channel));
 	switch_channel_clear_state_handler(channel, &uuid_bridge_state_handlers);
 
-	if (!switch_channel_test_flag(channel, CF_BRIDGE_ORIGINATOR)) {
+	if (!switch_channel_test_flag(channel, CF_UUID_BRIDGE_ORIGINATOR)) {
 		return SWITCH_STATUS_SUCCESS;
 	}
 
@@ -801,7 +801,7 @@ static switch_status_t uuid_bridge_on_soft_execute(switch_core_session_t *sessio
 
 				if (running_state == CS_SOFT_EXECUTE) {
 
-					if (switch_channel_test_flag(other_channel, CF_BRIDGE_ORIGINATOR)) {
+					if (switch_channel_test_flag(other_channel, CF_UUID_BRIDGE_ORIGINATOR)) {
 						goto done;
 					} else {
 						break;
@@ -878,7 +878,7 @@ static switch_status_t uuid_bridge_on_soft_execute(switch_core_session_t *sessio
 		other_session = NULL;
 	}
 
-	switch_channel_clear_flag_recursive(channel, CF_BRIDGE_ORIGINATOR);
+	switch_channel_clear_flag(channel, CF_UUID_BRIDGE_ORIGINATOR);
 
 	return SWITCH_STATUS_FALSE;
 }
@@ -1663,10 +1663,16 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_uuid_bridge(const char *originator_uu
 			//switch_channel_set_variable(originatee_channel, SWITCH_PARK_AFTER_BRIDGE_VARIABLE, NULL);
 			switch_channel_clear_state_handler(originator_channel, NULL);
 			switch_channel_clear_state_handler(originatee_channel, NULL);
-			switch_channel_clear_flag_recursive(originator_channel, CF_BRIDGE_ORIGINATOR);
-			switch_channel_clear_flag_recursive(originatee_channel, CF_BRIDGE_ORIGINATOR);
-			switch_channel_set_state_flag(originator_channel, CF_BRIDGE_ORIGINATOR);
+
+
+
+			switch_channel_clear_state_flag(originator_channel, CF_BRIDGE_ORIGINATOR);
 			switch_channel_clear_state_flag(originatee_channel, CF_BRIDGE_ORIGINATOR);
+
+			switch_channel_clear_flag(originator_channel, CF_UUID_BRIDGE_ORIGINATOR);
+			switch_channel_clear_flag(originatee_channel, CF_UUID_BRIDGE_ORIGINATOR);
+			switch_channel_set_state_flag(originator_channel, CF_UUID_BRIDGE_ORIGINATOR);
+
 			switch_channel_add_state_handler(originator_channel, &uuid_bridge_state_handlers);
 			switch_channel_add_state_handler(originatee_channel, &uuid_bridge_state_handlers);
 
diff --git a/src/switch_ivr_originate.c b/src/switch_ivr_originate.c
index 17f1ad19e2..d8a555c512 100644
--- a/src/switch_ivr_originate.c
+++ b/src/switch_ivr_originate.c
@@ -1888,6 +1888,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
 		switch_channel_set_flag(caller_channel, CF_ORIGINATOR);
 		oglobals.session = session;
 
+		switch_channel_execute_on(caller_channel, SWITCH_CHANNEL_EXECUTE_ON_PRE_ORIGINATE_VARIABLE);
+		switch_channel_api_on(caller_channel, SWITCH_CHANNEL_API_ON_PRE_ORIGINATE_VARIABLE);
+
 		switch_core_session_get_read_impl(session, &read_impl);
 
 		if ((to_var = switch_channel_get_variable(caller_channel, SWITCH_CALL_TIMEOUT_VARIABLE))) {
@@ -2420,7 +2423,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
 
 			for (i = 0; i < and_argc; i++) {
 				const char *current_variable;
-				switch_event_t *local_var_event = NULL, *originate_var_event = NULL, *event = NULL;
+				switch_event_t *local_var_event = NULL, *originate_var_event = NULL;
 
 				end = NULL;
 				
@@ -2686,11 +2689,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
 					}
 				}
 
-				switch_event_create(&event, SWITCH_EVENT_CHANNEL_ORIGINATE);
-				switch_assert(event);
-				switch_channel_event_set_data(originate_status[i].peer_channel, event);
-				switch_event_fire(&event);
-
 				if (originate_status[i].peer_channel) {
 					const char *vvar;
 
@@ -3732,6 +3730,10 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
 	switch_safe_free(fail_on_single_reject_var);
 
 	if (caller_channel) {
+
+		switch_channel_execute_on(caller_channel, SWITCH_CHANNEL_EXECUTE_ON_POST_ORIGINATE_VARIABLE);
+		switch_channel_api_on(caller_channel, SWITCH_CHANNEL_API_ON_POST_ORIGINATE_VARIABLE);
+
 		switch_channel_clear_flag(caller_channel, CF_ORIGINATOR);
 		switch_channel_clear_flag(caller_channel, CF_XFER_ZOMBIE);
 	}
diff --git a/src/switch_loadable_module.c b/src/switch_loadable_module.c
index 3a79c3e024..d87d37f7fc 100644
--- a/src/switch_loadable_module.c
+++ b/src/switch_loadable_module.c
@@ -1219,7 +1219,11 @@ static switch_status_t switch_loadable_module_load_file(char *path, char *filena
 #ifdef WIN32
 	dso = switch_dso_open("FreeSwitch.dll", load_global, &derr);
 #elif defined (MACOSX) || defined(DARWIN)
-	dso = switch_dso_open(SWITCH_PREFIX_DIR "/lib/libfreeswitch.dylib", load_global, &derr);
+	{
+		char *lib_path = switch_mprintf("%s/libfreeswitch.dylib", SWITCH_GLOBAL_dirs.lib_dir);
+		dso = switch_dso_open(lib_path, load_global, &derr);
+		switch_safe_free(lib_path);
+	}
 #else
 	dso = switch_dso_open(NULL, load_global, &derr);
 #endif
diff --git a/src/switch_odbc.c b/src/switch_odbc.c
index bba4b4cbe6..babf05b3a1 100644
--- a/src/switch_odbc.c
+++ b/src/switch_odbc.c
@@ -444,7 +444,7 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec(switch_odbc_handle_
 #ifdef SWITCH_HAVE_ODBC
 	SQLHSTMT stmt = NULL;
 	int result;
-	char *err_str = NULL;
+	char *err_str = NULL, *err2 = NULL;
 	SQLLEN m = 0;
 
 	handle->affected_rows = 0;
@@ -454,16 +454,32 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec(switch_odbc_handle_
 	}
 
 	if (SQLAllocHandle(SQL_HANDLE_STMT, handle->con, &stmt) != SQL_SUCCESS) {
+		err2 = "SQLAllocHandle failed.";
 		goto error;
 	}
 
 	if (SQLPrepare(stmt, (unsigned char *) sql, SQL_NTS) != SQL_SUCCESS) {
+		err2 = "SQLPrepare failed.";
 		goto error;
 	}
 
 	result = SQLExecute(stmt);
 
-	if (result != SQL_SUCCESS && result != SQL_SUCCESS_WITH_INFO && result != SQL_NO_DATA) {
+	switch (result) {
+	case SQL_SUCCESS:
+	case SQL_SUCCESS_WITH_INFO:
+	case SQL_NO_DATA:
+		break;
+	case SQL_ERROR:
+		err2 = "SQLExecute returned SQL_ERROR.";
+		goto error;
+		break;
+	case SQL_NEED_DATA:
+		err2 = "SQLExecute returned SQL_NEED_DATA.";
+		goto error;
+		break;
+	default:
+		err2 = "SQLExecute returned unknown result code.";
 		goto error;
 	}
 
@@ -486,7 +502,11 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec(switch_odbc_handle_
 	}
 
 	if (zstr(err_str)) {
-		err_str = strdup((char *)"SQL ERROR!");
+		if (err2) {
+			err_str = strdup(err2);
+		} else {
+			err_str = strdup((char *)"SQL ERROR!");
+		}
 	}
 	
 	if (err_str) {
diff --git a/src/switch_rtp.c b/src/switch_rtp.c
index 1b5925c23b..8f9fc955a7 100644
--- a/src/switch_rtp.c
+++ b/src/switch_rtp.c
@@ -3054,6 +3054,7 @@ static switch_status_t read_rtp_packet(switch_rtp_t *rtp_session, switch_size_t
 			*bytes = jb_frame->dlen + rtp_header_len;
 			rtp_session->recv_msg.header.ts = htonl(jb_frame->ts);
 			rtp_session->recv_msg.header.pt = jb_frame->pt;
+			rtp_session->recv_msg.header.seq = htons(jb_frame->seq);
 			status = SWITCH_STATUS_SUCCESS;
 		}
 	}
diff --git a/src/switch_xml.c b/src/switch_xml.c
index 237873e15d..e0f3e3d37d 100644
--- a/src/switch_xml.c
+++ b/src/switch_xml.c
@@ -2883,7 +2883,7 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_cut(switch_xml_t xml)
 	return xml;
 }
 
-SWITCH_DECLARE(int) switch_xml_std_datetime_check(switch_xml_t xcond, int *offset) 
+SWITCH_DECLARE(int) switch_xml_std_datetime_check(switch_xml_t xcond, int *offset, const char *tzname) 
 {
 
 	const char *xdt = switch_xml_attr(xcond, "date-time");
@@ -2920,7 +2920,9 @@ SWITCH_DECLARE(int) switch_xml_std_datetime_check(switch_xml_t xcond, int *offse
 
 	if (offset) {
 		eoffset = *offset;
-		switch_time_exp_tz(&tm, ts, *offset);
+		switch_time_exp_tz(&tm, ts, *offset * 3600);
+	} else if (!zstr(tzname)) {
+		switch_time_exp_tz_name(tzname, &tm, ts);
 	} else {
 		tm = tm2;
 	}