[Freeswitch-branches] [commit] r10428 - in freeswitch/branches/gmaruzz: . conf conf/autoload_configs conf/dialplan conf/sip_profiles libs/apr/include/arch/win32 libs/apr/locks/win32 libs/sofia-sip libs/sofia-sip/libsofia-sip-ua/nua libs/sofia-sip/libsofia-sip-ua/sip libs/spandsp libs/xmlrpc-c/lib/abyss/src scripts/contrib/mrene scripts/contrib/mrene/mod_limit src src/include src/include/private src/mod/applications/mod_commands src/mod/applications/mod_conference src/mod/applications/mod_dptools src/mod/applications/mod_enum src/mod/applications/mod_fifo src/mod/applications/mod_fsv src/mod/applications/mod_limit src/mod/applications/mod_skel src/mod/applications/mod_stress src/mod/applications/mod_voicemail src/mod/asr_tts/mod_cepstral src/mod/codecs/mod_speex src/mod/codecs/mod_voipcodecs src/mod/dialplans/mod_dialplan_asterisk src/mod/endpoints/mod_dingaling src/mod/endpoints/mod_iax src/mod/endpoints/mod_loopback src/mod/endpoints/mod_portaudio src/mod/endpoints/mod_reference src/mod/endpoints/mod_sofia src/mod/endpoints/mod_unicall src/mod/endpoints/mod_woomera src/mod/event_handlers/mod_erlang_event src/mod/event_handlers/mod_event_multicast src/mod/event_handlers/mod_event_socket src/mod/event_handlers/mod_radius_cdr src/mod/event_handlers/mod_zeroconf src/mod/formats/mod_local_stream src/mod/formats/mod_shout src/mod/languages/mod_lua src/mod/languages/mod_managed src/mod/languages/mod_managed/managed src/mod/languages/mod_perl src/mod/languages/mod_python src/mod/languages/mod_spidermonkey src/mod/languages/mod_spidermonkey_curl w32/Library

FreeSWITCH SVN gmaruzz at freeswitch.org
Mon Nov 17 11:18:33 PST 2008


Author: gmaruzz
Date: Mon Nov 17 14:18:32 2008
New Revision: 10428

Log:
merged trunk 10229:10427 into gmaruzz branch, this time for real (the 10229:10423 merging was reverted before commit?)

Added:
   freeswitch/branches/gmaruzz/conf/autoload_configs/fifo.conf.xml
      - copied unchanged from r10427, /freeswitch/trunk/conf/autoload_configs/fifo.conf.xml
   freeswitch/branches/gmaruzz/scripts/contrib/mrene/
      - copied from r10427, /freeswitch/trunk/scripts/contrib/mrene/
   freeswitch/branches/gmaruzz/scripts/contrib/mrene/mod_limit/   (props changed)
      - copied from r10427, /freeswitch/trunk/scripts/contrib/mrene/mod_limit/
   freeswitch/branches/gmaruzz/scripts/contrib/mrene/mod_limit/mod_limit.c
      - copied unchanged from r10427, /freeswitch/trunk/scripts/contrib/mrene/mod_limit/mod_limit.c
   freeswitch/branches/gmaruzz/src/mod/event_handlers/mod_erlang_event/
      - copied from r10427, /freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/
   freeswitch/branches/gmaruzz/src/mod/event_handlers/mod_erlang_event/Makefile
      - copied unchanged from r10427, /freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/Makefile
   freeswitch/branches/gmaruzz/src/mod/event_handlers/mod_erlang_event/erlang_event.conf.xml
      - copied unchanged from r10427, /freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/erlang_event.conf.xml
   freeswitch/branches/gmaruzz/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c
      - copied unchanged from r10427, /freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c
Modified:
   freeswitch/branches/gmaruzz/Makefile.am
   freeswitch/branches/gmaruzz/conf/autoload_configs/cdr_csv.conf.xml
   freeswitch/branches/gmaruzz/conf/dialplan/default.xml
   freeswitch/branches/gmaruzz/conf/dialplan/features.xml
   freeswitch/branches/gmaruzz/conf/sip_profiles/external.xml
   freeswitch/branches/gmaruzz/conf/sip_profiles/internal.xml
   freeswitch/branches/gmaruzz/conf/vars.xml
   freeswitch/branches/gmaruzz/libs/apr/include/arch/win32/apr_arch_thread_cond.h
   freeswitch/branches/gmaruzz/libs/apr/locks/win32/thread_cond.c
   freeswitch/branches/gmaruzz/libs/sofia-sip/.update
   freeswitch/branches/gmaruzz/libs/sofia-sip/libsofia-sip-ua/nua/check_register.c
   freeswitch/branches/gmaruzz/libs/sofia-sip/libsofia-sip-ua/nua/check_session.c
   freeswitch/branches/gmaruzz/libs/sofia-sip/libsofia-sip-ua/nua/outbound.c
   freeswitch/branches/gmaruzz/libs/sofia-sip/libsofia-sip-ua/sip/sip_bad_mask
   freeswitch/branches/gmaruzz/libs/spandsp/   (props changed)
   freeswitch/branches/gmaruzz/libs/xmlrpc-c/lib/abyss/src/socket_unix.c
   freeswitch/branches/gmaruzz/src/include/g711.h
   freeswitch/branches/gmaruzz/src/include/private/switch_core_pvt.h
   freeswitch/branches/gmaruzz/src/include/switch.h
   freeswitch/branches/gmaruzz/src/include/switch_apr.h
   freeswitch/branches/gmaruzz/src/include/switch_core.h
   freeswitch/branches/gmaruzz/src/include/switch_dso.h
   freeswitch/branches/gmaruzz/src/include/switch_ivr.h
   freeswitch/branches/gmaruzz/src/include/switch_loadable_module.h
   freeswitch/branches/gmaruzz/src/include/switch_module_interfaces.h
   freeswitch/branches/gmaruzz/src/include/switch_rtp.h
   freeswitch/branches/gmaruzz/src/include/switch_types.h
   freeswitch/branches/gmaruzz/src/include/switch_utils.h
   freeswitch/branches/gmaruzz/src/include/switch_xml.h
   freeswitch/branches/gmaruzz/src/mod/applications/mod_commands/mod_commands.c
   freeswitch/branches/gmaruzz/src/mod/applications/mod_conference/mod_conference.c
   freeswitch/branches/gmaruzz/src/mod/applications/mod_dptools/mod_dptools.c
   freeswitch/branches/gmaruzz/src/mod/applications/mod_enum/mod_enum.c
   freeswitch/branches/gmaruzz/src/mod/applications/mod_fifo/mod_fifo.c
   freeswitch/branches/gmaruzz/src/mod/applications/mod_fsv/mod_fsv.c
   freeswitch/branches/gmaruzz/src/mod/applications/mod_limit/mod_limit.c
   freeswitch/branches/gmaruzz/src/mod/applications/mod_skel/mod_skel.c
   freeswitch/branches/gmaruzz/src/mod/applications/mod_stress/   (props changed)
   freeswitch/branches/gmaruzz/src/mod/applications/mod_voicemail/mod_voicemail.c
   freeswitch/branches/gmaruzz/src/mod/asr_tts/mod_cepstral/mod_cepstral.c
   freeswitch/branches/gmaruzz/src/mod/codecs/mod_speex/mod_speex.c
   freeswitch/branches/gmaruzz/src/mod/codecs/mod_voipcodecs/mod_voipcodecs.c
   freeswitch/branches/gmaruzz/src/mod/dialplans/mod_dialplan_asterisk/mod_dialplan_asterisk.c
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_dingaling/mod_dingaling.c
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_iax/mod_iax.c
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_loopback/   (props changed)
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_loopback/mod_loopback.c
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_portaudio/pablio.c
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_reference/mod_reference.c
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/mod_sofia.c
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/mod_sofia.h
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/sofia.c
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/sofia_glue.c
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/sofia_presence.c
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/sofia_reg.c
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_unicall/mod_unicall.c
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_woomera/mod_woomera.c
   freeswitch/branches/gmaruzz/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c
   freeswitch/branches/gmaruzz/src/mod/event_handlers/mod_event_socket/mod_event_socket.c
   freeswitch/branches/gmaruzz/src/mod/event_handlers/mod_radius_cdr/mod_radius_cdr.c
   freeswitch/branches/gmaruzz/src/mod/event_handlers/mod_zeroconf/mod_zeroconf.c
   freeswitch/branches/gmaruzz/src/mod/formats/mod_local_stream/mod_local_stream.c
   freeswitch/branches/gmaruzz/src/mod/formats/mod_shout/mod_shout.c
   freeswitch/branches/gmaruzz/src/mod/languages/mod_lua/   (props changed)
   freeswitch/branches/gmaruzz/src/mod/languages/mod_lua/mod_lua.cpp
   freeswitch/branches/gmaruzz/src/mod/languages/mod_managed/Makefile
   freeswitch/branches/gmaruzz/src/mod/languages/mod_managed/freeswitch_wrap.cxx
   freeswitch/branches/gmaruzz/src/mod/languages/mod_managed/managed/Makefile
   freeswitch/branches/gmaruzz/src/mod/languages/mod_managed/managed/swig.cs
   freeswitch/branches/gmaruzz/src/mod/languages/mod_perl/   (props changed)
   freeswitch/branches/gmaruzz/src/mod/languages/mod_perl/mod_perl.c
   freeswitch/branches/gmaruzz/src/mod/languages/mod_python/   (props changed)
   freeswitch/branches/gmaruzz/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
   freeswitch/branches/gmaruzz/src/mod/languages/mod_spidermonkey_curl/   (props changed)
   freeswitch/branches/gmaruzz/src/switch.c
   freeswitch/branches/gmaruzz/src/switch_apr.c
   freeswitch/branches/gmaruzz/src/switch_channel.c
   freeswitch/branches/gmaruzz/src/switch_console.c
   freeswitch/branches/gmaruzz/src/switch_core.c
   freeswitch/branches/gmaruzz/src/switch_core_asr.c
   freeswitch/branches/gmaruzz/src/switch_core_codec.c
   freeswitch/branches/gmaruzz/src/switch_core_directory.c
   freeswitch/branches/gmaruzz/src/switch_core_file.c
   freeswitch/branches/gmaruzz/src/switch_core_hash.c
   freeswitch/branches/gmaruzz/src/switch_core_io.c
   freeswitch/branches/gmaruzz/src/switch_core_media_bug.c
   freeswitch/branches/gmaruzz/src/switch_core_memory.c
   freeswitch/branches/gmaruzz/src/switch_core_session.c
   freeswitch/branches/gmaruzz/src/switch_core_speech.c
   freeswitch/branches/gmaruzz/src/switch_core_sqldb.c
   freeswitch/branches/gmaruzz/src/switch_core_state_machine.c
   freeswitch/branches/gmaruzz/src/switch_core_timer.c
   freeswitch/branches/gmaruzz/src/switch_dso.c
   freeswitch/branches/gmaruzz/src/switch_event.c
   freeswitch/branches/gmaruzz/src/switch_ivr.c
   freeswitch/branches/gmaruzz/src/switch_ivr_async.c
   freeswitch/branches/gmaruzz/src/switch_ivr_bridge.c
   freeswitch/branches/gmaruzz/src/switch_ivr_menu.c
   freeswitch/branches/gmaruzz/src/switch_ivr_originate.c
   freeswitch/branches/gmaruzz/src/switch_ivr_play_say.c
   freeswitch/branches/gmaruzz/src/switch_loadable_module.c
   freeswitch/branches/gmaruzz/src/switch_log.c
   freeswitch/branches/gmaruzz/src/switch_odbc.c
   freeswitch/branches/gmaruzz/src/switch_pcm.c
   freeswitch/branches/gmaruzz/src/switch_rtp.c
   freeswitch/branches/gmaruzz/src/switch_stun.c
   freeswitch/branches/gmaruzz/src/switch_time.c
   freeswitch/branches/gmaruzz/src/switch_xml.c
   freeswitch/branches/gmaruzz/w32/Library/FreeSwitchCore.vcproj

Modified: freeswitch/branches/gmaruzz/Makefile.am
==============================================================================
--- freeswitch/branches/gmaruzz/Makefile.am	(original)
+++ freeswitch/branches/gmaruzz/Makefile.am	Mon Nov 17 14:18:32 2008
@@ -70,6 +70,7 @@
 src/switch_core.c \
 src/switch_scheduler.c \
 src/switch_core_db.c\
+src/switch_dso.c\
 src/switch_loadable_module.c \
 src/switch_utils.c \
 src/switch_event.c \
@@ -114,6 +115,7 @@
 src/include/switch_event.h\
 src/include/switch_frame.h\
 src/include/switch_ivr.h\
+src/include/switch_dso.h\
 src/include/switch_loadable_module.h\
 src/include/switch_module_interfaces.h\
 src/include/switch_platform.h\

Modified: freeswitch/branches/gmaruzz/conf/autoload_configs/cdr_csv.conf.xml
==============================================================================
--- freeswitch/branches/gmaruzz/conf/autoload_configs/cdr_csv.conf.xml	(original)
+++ freeswitch/branches/gmaruzz/conf/autoload_configs/cdr_csv.conf.xml	Mon Nov 17 14:18:32 2008
@@ -11,7 +11,7 @@
   </settings>
   <templates>
     <template name="sql">INSERT INTO cdr VALUES ("${caller_id_name}","${caller_id_number}","${destination_number}","${context}","${start_stamp}","${answer_stamp}","${end_stamp}","${duration}","${billsec}","${hangup_cause}","${uuid}","${bleg_uuid}", "${accountcode}");</template>
-    <template name="example">"${caller_id_name}","${caller_id_number}","${destination_number}","${context}","${start_stamp}","${answer_stamp}","${end_stamp}","${duration}","${billsec}","${hangup_cause}","${uuid}","${bleg_uuid}", "${accountcode}","${read_codec}","${write_codec}"</template>
+    <template name="example">"${caller_id_name}","${caller_id_number}","${destination_number}","${context}","${start_stamp}","${answer_stamp}","${end_stamp}","${duration}","${billsec}","${hangup_cause}","${uuid}","${bleg_uuid}","${accountcode}","${read_codec}","${write_codec}"</template>
     <template name="snom">"${caller_id_name}","${caller_id_number}","${destination_number}","${context}","${start_stamp}","${answer_stamp}","${end_stamp}","${duration}","${billsec}","${hangup_cause}","${uuid}","${bleg_uuid}", "${accountcode}","${read_codec}","${write_codec}","${sip_user_agent}","${call_clientcode}","${sip_rtp_rxstat}","${sip_rtp_txstat}","${sofia_record_file}"</template>
     <template name="linksys">"${caller_id_name}","${caller_id_number}","${destination_number}","${context}","${start_stamp}","${answer_stamp}","${end_stamp}","${duration}","${billsec}","${hangup_cause}","${uuid}","${bleg_uuid}","${accountcode}","${read_codec}","${write_codec}","${sip_user_agent}","${sip_p_rtp_stat}"</template>
     <template name="asterisk">"${accountcode}","${caller_id_number}","${destination_number}","${context}","${caller_id}","${channel_name}","${bridge_channel}","${last_app}","${last_arg}","${start_stamp}","${answer_stamp}","${end_stamp}","${duration}","${billsec}","${hangup_cause}","${amaflags}","${uuid}","${userfield}"</template>

Modified: freeswitch/branches/gmaruzz/conf/dialplan/default.xml
==============================================================================
--- freeswitch/branches/gmaruzz/conf/dialplan/default.xml	(original)
+++ freeswitch/branches/gmaruzz/conf/dialplan/default.xml	Mon Nov 17 14:18:32 2008
@@ -27,9 +27,9 @@
 
     -->
     <extension name="set_domain" continue="true">
-      <condition field="${domain_name}" expression="^$" break="never"/>
-      <condition field="source" expression="mod_sofia" break="never"/>
-      <condition field="${sip_auth_realm}" expression="^$" break="never">
+      <condition field="${domain_name}" expression="^$"/>
+      <condition field="source" expression="mod_sofia"/>
+      <condition field="${sip_auth_realm}" expression="^$">
 	<action application="set" data="domain_name=$${domain}"/>
 	<anti-action application="set" data="domain_name=${sip_auth_realm}"/>
       </condition>
@@ -99,6 +99,7 @@
     </extension>
 
     <!-- If sip_req_host is not a local domain then this has to be an external sip uri -->
+    <!--
     <extension name="external_sip_uri" continue="true">
       <condition field="source" expression="mod_sofia"/>
       <condition field="${outside_call}" expression="^$"/>
@@ -106,7 +107,7 @@
 	<anti-action application="bridge" data="sofia/${use_profile}/${sip_to_uri}"/>
       </condition>
     </extension>
-
+    -->
     <!--
 	snom button demo, call 9000 to make button 2 mapped to transfer the current call to a conference
     -->
@@ -222,7 +223,7 @@
 	<anti-action application="db" data="insert/${domain_name}-call_return/${dialed_extension}/${caller_id_number}"/>
 	<anti-action application="db" data="insert/${domain_name}-last_dial_ext/${dialed_extension}/${uuid}"/>
 	<anti-action application="set" data="called_party_callgroup=${user_data(${dialed_extension}@${domain_name} var callgroup)}"/>
-	<anti-action application="export" data="nolocal:sip_secure_media=${user_data(${dialed_extension}@${domain_name} var sip_secure_media)}"/>
+	<!--<anti-action application="export" data="nolocal:sip_secure_media=${user_data(${dialed_extension}@${domain_name} var sip_secure_media)}"/>-->
 	<anti-action application="db" data="insert/${domain_name}-last_dial/${called_party_callgroup}/${uuid}"/>
 	<anti-action application="bridge" data="user/${dialed_extension}@${domain_name}"/>
 	<anti-action application="answer"/>

Modified: freeswitch/branches/gmaruzz/conf/dialplan/features.xml
==============================================================================
--- freeswitch/branches/gmaruzz/conf/dialplan/features.xml	(original)
+++ freeswitch/branches/gmaruzz/conf/dialplan/features.xml	Mon Nov 17 14:18:32 2008
@@ -23,7 +23,7 @@
     <extension name="cf">
       <condition field="destination_number" expression="^cf$">
 	<action application="answer"/>
-	<action application="transfer" data="-both 30${dialed_ext:2} XML default"/>
+	<action application="transfer" data="-both 30${dialed_extension:2} XML default"/>
       </condition>
     </extension>
 

Modified: freeswitch/branches/gmaruzz/conf/sip_profiles/external.xml
==============================================================================
--- freeswitch/branches/gmaruzz/conf/sip_profiles/external.xml	(original)
+++ freeswitch/branches/gmaruzz/conf/sip_profiles/external.xml	Mon Nov 17 14:18:32 2008
@@ -26,6 +26,7 @@
     <param name="hold-music" value="$${hold_music}"/>
     <param name="use-rtp-timer" value="true"/>
     <param name="rtp-timer-name" value="soft"/>
+    <!--<param name="enable-100rel" value="true"/>-->
     <!-- This could be set to "passive" -->
     <param name="manage-presence" value="false"/>
 

Modified: freeswitch/branches/gmaruzz/conf/sip_profiles/internal.xml
==============================================================================
--- freeswitch/branches/gmaruzz/conf/sip_profiles/internal.xml	(original)
+++ freeswitch/branches/gmaruzz/conf/sip_profiles/internal.xml	Mon Nov 17 14:18:32 2008
@@ -55,13 +55,13 @@
     <!--<param name="apply-nat-acl" value="rfc1918"/>-->
     <!--<param name="aggressive-nat-detection" value="true"/>-->
     <!--<param name="enable-timer" value="false"/>-->
-    <!--<param name="enable-100rel" value="false"/>-->
+    <!--<param name="enable-100rel" value="true"/>-->
     <!--<param name="minimum-session-expires" value="120"/>-->
     <param name="apply-inbound-acl" value="domains"/>
     <!--<param name="apply-register-acl" value="domains"/>-->
     <!--<param name="dtmf-type" value="info"/>-->
     <param name="record-template" value="$${base_dir}/recordings/${caller_id_number}.${target_domain}.${strftime(%Y-%m-%d-%H-%M-%S)}.wav"/>
-    <!--enable to use presence and mwi -->
+    <!--enable to use presence -->
     <param name="manage-presence" value="true"/>
 
     <!-- used to share presence info across sofia profiles -->
@@ -76,7 +76,8 @@
     <!--<param name="max-proceeding" value="1000"/>-->
     <!--session timers for all call to expire after the specified seconds -->
     <!--<param name="session-timeout" value="120"/>-->
-    <!--<param name="multiple-registrations" value="true"/>-->
+    <!-- Can be 'true' or 'contact' -->
+    <!--<param name="multiple-registrations" value="contact"/>-->
     <!--set to 'greedy' if you want your codec list to take precedence -->
     <param name="inbound-codec-negotiation" value="generous"/>
     <!-- if you want to send any special bind params of your own -->
@@ -176,6 +177,10 @@
     -->
     <param name="challenge-realm" value="auto_from"/>
     <!--<param name="disable-rtp-auto-adjust" value="true"/>-->
+    <!-- on inbound calls make the uuid of the session equal to the sip call id of that call -->
+    <!--<param name="inbound-use-callid-as-uuid" value="true"/>-->
+    <!-- on outbound calls set the callid to match the uuid of the session -->
+    <!--<param name="outbound-use-uuid-as-callid" value="true"/>-->
   </settings>
 </profile>
 

Modified: freeswitch/branches/gmaruzz/conf/vars.xml
==============================================================================
--- freeswitch/branches/gmaruzz/conf/vars.xml	(original)
+++ freeswitch/branches/gmaruzz/conf/vars.xml	Mon Nov 17 14:18:32 2008
@@ -121,7 +121,6 @@
       Below are some values that should work in most cases.
       
       These are for conf/directory/default/example.com.xml
-
   -->
   <X-PRE-PROCESS cmd="set" data="default_provider=example.com"/>
   <X-PRE-PROCESS cmd="set" data="default_provider_username=joeuser"/>

Modified: freeswitch/branches/gmaruzz/libs/apr/include/arch/win32/apr_arch_thread_cond.h
==============================================================================
--- freeswitch/branches/gmaruzz/libs/apr/include/arch/win32/apr_arch_thread_cond.h	(original)
+++ freeswitch/branches/gmaruzz/libs/apr/include/arch/win32/apr_arch_thread_cond.h	Mon Nov 17 14:18:32 2008
@@ -21,10 +21,11 @@
 
 struct apr_thread_cond_t {
     apr_pool_t *pool;
-    HANDLE event;
-    int signal_all;
-    int num_waiting;
-    int signalled;
+    HANDLE semaphore;
+    CRITICAL_SECTION csection;
+    unsigned long num_waiting;
+    unsigned long num_wake;
+    unsigned long generation;
 };
 
 #endif  /* THREAD_COND_H */

Modified: freeswitch/branches/gmaruzz/libs/apr/locks/win32/thread_cond.c
==============================================================================
--- freeswitch/branches/gmaruzz/libs/apr/locks/win32/thread_cond.c	(original)
+++ freeswitch/branches/gmaruzz/libs/apr/locks/win32/thread_cond.c	Mon Nov 17 14:18:32 2008
@@ -18,67 +18,98 @@
 #include "apr_private.h"
 #include "apr_general.h"
 #include "apr_strings.h"
-#include "win32/apr_arch_thread_mutex.h"
-#include "win32/apr_arch_thread_cond.h"
+#include "apr_arch_thread_mutex.h"
+#include "apr_arch_thread_cond.h"
 #include "apr_portable.h"
 
+#include <limits.h>
+
 static apr_status_t thread_cond_cleanup(void *data)
 {
     apr_thread_cond_t *cond = data;
-    CloseHandle(cond->event);
+    CloseHandle(cond->semaphore);
+    DeleteCriticalSection(&cond->csection);
     return APR_SUCCESS;
 }
 
 APR_DECLARE(apr_status_t) apr_thread_cond_create(apr_thread_cond_t **cond,
                                                  apr_pool_t *pool)
 {
-    *cond = apr_palloc(pool, sizeof(**cond));
-    (*cond)->pool = pool;
-    (*cond)->event = CreateEvent(NULL, TRUE, FALSE, NULL);
-    (*cond)->signal_all = 0;
-    (*cond)->num_waiting = 0;
+    apr_thread_cond_t *cv;
+
+    cv = apr_pcalloc(pool, sizeof(**cond));
+    if (cv == NULL) {
+        return APR_ENOMEM;
+    }
+
+    cv->semaphore = CreateSemaphore(NULL, 0, LONG_MAX, NULL);
+    if (cv->semaphore == NULL) {
+        return apr_get_os_error();
+    }
 
-	apr_pool_cleanup_register(pool, *cond, thread_cond_cleanup,
-                          apr_pool_cleanup_null);
+    *cond = cv;
+    cv->pool = pool;
+    InitializeCriticalSection(&cv->csection);
+    apr_pool_cleanup_register(cv->pool, cv, thread_cond_cleanup,
+                              apr_pool_cleanup_null);
 
     return APR_SUCCESS;
 }
 
+APR_DECLARE(apr_status_t) apr_thread_cond_destroy(apr_thread_cond_t *cond)
+{
+    return apr_pool_cleanup_run(cond->pool, cond, thread_cond_cleanup);
+}
+
 static APR_INLINE apr_status_t _thread_cond_timedwait(apr_thread_cond_t *cond,
                                                       apr_thread_mutex_t *mutex,
                                                       DWORD timeout_ms )
 {
     DWORD res;
-
-    while (1) {
-        cond->num_waiting++;
-
-        apr_thread_mutex_unlock(mutex);
-        res = WaitForSingleObject(cond->event, timeout_ms);
-        apr_thread_mutex_lock(mutex);
-        cond->num_waiting--;
-        if (res != WAIT_OBJECT_0) {
-            apr_status_t rv = apr_get_os_error();
-            if (res == WAIT_TIMEOUT) {
-                return APR_TIMEUP;
+    apr_status_t rv;
+    unsigned int wake = 0;
+    unsigned long generation;
+
+    EnterCriticalSection(&cond->csection);
+    cond->num_waiting++;
+    generation = cond->generation;
+    LeaveCriticalSection(&cond->csection);
+
+    apr_thread_mutex_unlock(mutex);
+
+    do {
+        res = WaitForSingleObject(cond->semaphore, timeout_ms);
+
+        EnterCriticalSection(&cond->csection);
+
+        if (cond->num_wake) {
+            if (cond->generation != generation) {
+                cond->num_wake--;
+                cond->num_waiting--;
+                rv = APR_SUCCESS;
+                break;
+            } else {
+                wake = 1;
             }
-            return apr_get_os_error();
         }
-        if (cond->signal_all) {
-            if (cond->num_waiting == 0) {
-                cond->signal_all = 0;
-                cond->signalled = 0;
-                ResetEvent(cond->event);
-            }
+        else if (res != WAIT_OBJECT_0) {
+            cond->num_waiting--;
+            rv = APR_TIMEUP;
             break;
         }
-        else if (cond->signalled) {
-            cond->signalled = 0;
-            ResetEvent(cond->event);
-            break;
+
+        LeaveCriticalSection(&cond->csection);
+
+        if (wake) {
+            wake = 0;
+            ReleaseSemaphore(cond->semaphore, 1, NULL);
         }
-    }
-    return APR_SUCCESS;
+    } while (1);
+
+    LeaveCriticalSection(&cond->csection);
+    apr_thread_mutex_lock(mutex);
+
+    return rv;
 }
 
 APR_DECLARE(apr_status_t) apr_thread_cond_wait(apr_thread_cond_t *cond,
@@ -98,35 +129,40 @@
 
 APR_DECLARE(apr_status_t) apr_thread_cond_signal(apr_thread_cond_t *cond)
 {
-    apr_status_t rv = APR_SUCCESS;
-    DWORD res;
+    unsigned int wake = 0;
 
-    cond->signalled = 1;
-    res = SetEvent(cond->event);
-    if (res == 0) {
-        rv = apr_get_os_error();
+    EnterCriticalSection(&cond->csection);
+    if (cond->num_waiting > cond->num_wake) {
+        wake = 1;
+        cond->num_wake++;
+        cond->generation++;
     }
-    return rv;
+    LeaveCriticalSection(&cond->csection);
+
+    if (wake) {
+        ReleaseSemaphore(cond->semaphore, 1, NULL);
+    }
+
+    return APR_SUCCESS;
 }
 
 APR_DECLARE(apr_status_t) apr_thread_cond_broadcast(apr_thread_cond_t *cond)
 {
-    apr_status_t rv = APR_SUCCESS;
-    DWORD res;
+    unsigned long num_wake = 0;
 
-    cond->signalled = 1;
-    cond->signal_all = 1;
-    res = SetEvent(cond->event);
-    if (res == 0) {
-        rv = apr_get_os_error();
+    EnterCriticalSection(&cond->csection);
+    if (cond->num_waiting > cond->num_wake) {
+        num_wake = cond->num_waiting - cond->num_wake;
+        cond->num_wake = cond->num_waiting;
+        cond->generation++;
     }
-    return rv;
-}
+    LeaveCriticalSection(&cond->csection);
 
-APR_DECLARE(apr_status_t) apr_thread_cond_destroy(apr_thread_cond_t *cond)
-{
-    return apr_pool_cleanup_run(cond->pool, cond, thread_cond_cleanup);
+    if (num_wake) {
+        ReleaseSemaphore(cond->semaphore, num_wake, NULL);
+    }
+
+    return APR_SUCCESS;
 }
 
 APR_POOL_IMPLEMENT_ACCESSOR(thread_cond)
-

Modified: freeswitch/branches/gmaruzz/libs/sofia-sip/.update
==============================================================================
--- freeswitch/branches/gmaruzz/libs/sofia-sip/.update	(original)
+++ freeswitch/branches/gmaruzz/libs/sofia-sip/.update	Mon Nov 17 14:18:32 2008
@@ -1 +1 @@
-Mon Oct  6 17:52:55 EDT 2008
+Wed Nov 12 11:28:12 EST 2008

Modified: freeswitch/branches/gmaruzz/libs/sofia-sip/libsofia-sip-ua/nua/check_register.c
==============================================================================
--- freeswitch/branches/gmaruzz/libs/sofia-sip/libsofia-sip-ua/nua/check_register.c	(original)
+++ freeswitch/branches/gmaruzz/libs/sofia-sip/libsofia-sip-ua/nua/check_register.c	Mon Nov 17 14:18:32 2008
@@ -717,7 +717,7 @@
     tcase_add_test(tc, register_1_3_2_1);
     tcase_add_test(tc, register_1_3_2_2);
   }
-  tcase_set_timeout(tc, 5);
+  tcase_set_timeout(tc, 10);
   return tc;
 }
 
@@ -729,7 +729,7 @@
   {
     tcase_add_test(tc, register_1_3_3_1);
   }
-  tcase_set_timeout(tc, 5);
+  tcase_set_timeout(tc, 10);
   return tc;
 }
 

Modified: freeswitch/branches/gmaruzz/libs/sofia-sip/libsofia-sip-ua/nua/check_session.c
==============================================================================
--- freeswitch/branches/gmaruzz/libs/sofia-sip/libsofia-sip-ua/nua/check_session.c	(original)
+++ freeswitch/branches/gmaruzz/libs/sofia-sip/libsofia-sip-ua/nua/check_session.c	Mon Nov 17 14:18:32 2008
@@ -64,6 +64,7 @@
   s2_case("0.1.1", "Setup for Call Tests", "");
 
   nua = s2_nua_setup(SIPTAG_ORGANIZATION_STR("Pussy Galore's Flying Circus"),
+                     NUTAG_OUTBOUND("no-options-keepalive, no-validate"),
 		     TAG_END());
 
   soa = soa_create(NULL, s2->root, NULL);

Modified: freeswitch/branches/gmaruzz/libs/sofia-sip/libsofia-sip-ua/nua/outbound.c
==============================================================================
--- freeswitch/branches/gmaruzz/libs/sofia-sip/libsofia-sip-ua/nua/outbound.c	(original)
+++ freeswitch/branches/gmaruzz/libs/sofia-sip/libsofia-sip-ua/nua/outbound.c	Mon Nov 17 14:18:32 2008
@@ -669,7 +669,7 @@
 
   udp = ob->ob_via && ob->ob_via->v_protocol == sip_transport_udp;
 
-  if (ob->ob_prefs.natify &&
+  if (/* ob->ob_prefs.natify && */
       /* On UDP, use OPTIONS keepalive by default */
       (udp ? ob->ob_prefs.okeepalive != 0
        /* Otherwise, only if requested */
@@ -677,7 +677,7 @@
     interval = ob->ob_prefs.interval;
   need_to_validate = ob->ob_prefs.validate && !ob->ob_validated;
 
-  if (!ob->ob_nat_detected || !register_transaction ||
+  if (!register_transaction ||
       !(need_to_validate || interval != 0)) {
     outbound_stop_keepalive(ob);
     return;

Modified: freeswitch/branches/gmaruzz/libs/sofia-sip/libsofia-sip-ua/sip/sip_bad_mask
==============================================================================
--- freeswitch/branches/gmaruzz/libs/sofia-sip/libsofia-sip-ua/sip/sip_bad_mask	(original)
+++ freeswitch/branches/gmaruzz/libs/sofia-sip/libsofia-sip-ua/sip/sip_bad_mask	Mon Nov 17 14:18:32 2008
@@ -55,13 +55,16 @@
 
 #
 # Headers that must be valid in UA, proxy or registrar
-#
+# 
 Contact = sip_mask_ua | sip_mask_proxy | sip_mask_registrar
 Require = sip_mask_ua | sip_mask_registrar | sip_mask_timer
 Record-Route = sip_mask_ua | sip_mask_proxy
 
 Expires = sip_mask_registrar | sip_mask_events
 
+# Nothing bad can happen if something looks like it is not Supported
+# Supported = sip_mask_ua | sip_mask_proxy | sip_mask_registrar
+
 #
 # 100rel headers
 #

Modified: freeswitch/branches/gmaruzz/libs/xmlrpc-c/lib/abyss/src/socket_unix.c
==============================================================================
--- freeswitch/branches/gmaruzz/libs/xmlrpc-c/lib/abyss/src/socket_unix.c	(original)
+++ freeswitch/branches/gmaruzz/libs/xmlrpc-c/lib/abyss/src/socket_unix.c	Mon Nov 17 14:18:32 2008
@@ -77,6 +77,10 @@
 static void
 termInterruptPipe(interruptPipe *pipeP) {
 	if (pipeP->inuse) {
+        int x = 0;
+        write(pipeP->interruptorFd, &x, sizeof(x));
+		usleep(500);
+		shutdown(pipeP->interrupteeFd, 2);
 		sane_close(pipeP->interruptorFd);
 		sane_close(pipeP->interrupteeFd);
 	}
@@ -310,6 +314,7 @@
     rc = poll(pollfds, ARRAY_SIZE(pollfds),
               timeoutMs == TIME_INFINITE ? -1 : timeoutMs);
 
+
     if (rc < 0) {
         if (errno == EINTR) {
             failed       = FALSE;

Modified: freeswitch/branches/gmaruzz/src/include/g711.h
==============================================================================
--- freeswitch/branches/gmaruzz/src/include/g711.h	(original)
+++ freeswitch/branches/gmaruzz/src/include/g711.h	Mon Nov 17 14:18:32 2008
@@ -32,7 +32,7 @@
 seem so bad :(
 
 Feel free to submit patches to add fast "find the first 1" support for your own
-favourite processor.
+favorite processor.
 
 Look up tables are used for transcoding between A-law and u-law, since it is
 difficult to achieve the precise transcoding procedure laid down in the G.711

Modified: freeswitch/branches/gmaruzz/src/include/private/switch_core_pvt.h
==============================================================================
--- freeswitch/branches/gmaruzz/src/include/private/switch_core_pvt.h	(original)
+++ freeswitch/branches/gmaruzz/src/include/private/switch_core_pvt.h	Mon Nov 17 14:18:32 2008
@@ -52,9 +52,6 @@
 #include <apr_general.h>
 
 #include <apr_portable.h>
-typedef apr_os_thread_t switch_thread_id_t;
-#define switch_thread_self apr_os_thread_current
-
 
 #ifdef HAVE_MLOCKALL
 #include <sys/mman.h>
@@ -97,7 +94,7 @@
 struct switch_core_session {
 	switch_memory_pool_t *pool;
 	switch_thread_t *thread;
-	const switch_endpoint_interface_t *endpoint_interface;
+	switch_endpoint_interface_t *endpoint_interface;
 	switch_size_t id;
 	switch_session_flag_t flags;
 	int thread_running;

Modified: freeswitch/branches/gmaruzz/src/include/switch.h
==============================================================================
--- freeswitch/branches/gmaruzz/src/include/switch.h	(original)
+++ freeswitch/branches/gmaruzz/src/include/switch.h	Mon Nov 17 14:18:32 2008
@@ -98,6 +98,7 @@
 #include "switch_apr.h"
 
 #include "switch_core_db.h"
+#include "switch_dso.h"
 #include "switch_regex.h"
 #include "switch_core.h"
 #include "switch_loadable_module.h"

Modified: freeswitch/branches/gmaruzz/src/include/switch_apr.h
==============================================================================
--- freeswitch/branches/gmaruzz/src/include/switch_apr.h	(original)
+++ freeswitch/branches/gmaruzz/src/include/switch_apr.h	Mon Nov 17 14:18:32 2008
@@ -40,6 +40,17 @@
 #define SWITCH_APR_H
 
 SWITCH_BEGIN_EXTERN_C
+
+#ifdef WIN32
+typedef HANDLE                switch_thread_id_t;
+#else
+#include <pthread.h>
+typedef pthread_t             switch_thread_id_t;
+#endif
+
+SWITCH_DECLARE(switch_thread_id_t) switch_thread_self(void);
+
+
 /*
    The pieces of apr we allow ppl to pass around between modules we typedef into our namespace and wrap all the functions
    any other apr code should be as hidden as possible.
@@ -327,6 +338,7 @@
  * @warning May sleep for longer than the specified time. 
  */
 SWITCH_DECLARE(void) switch_sleep(switch_interval_time_t t);
+SWITCH_DECLARE(void) switch_micro_sleep(switch_interval_time_t t);
 
 /** @} */
 

Modified: freeswitch/branches/gmaruzz/src/include/switch_core.h
==============================================================================
--- freeswitch/branches/gmaruzz/src/include/switch_core.h	(original)
+++ freeswitch/branches/gmaruzz/src/include/switch_core.h	Mon Nov 17 14:18:32 2008
@@ -89,6 +89,9 @@
 	switch_size_t pointer_reply_size;
 	/*! message flags */
 	switch_core_session_message_flag_t flags;
+	const char *_file;
+	const char *_func;
+	int _line;
 };
 
 /*! \brief A generic object to pass as a thread's session object to allow mutiple arguements and a pool */
@@ -209,6 +212,9 @@
 */
 SWITCH_DECLARE(switch_status_t) switch_core_media_bug_read(_In_ switch_media_bug_t *bug, _In_ switch_frame_t *frame);
 
+SWITCH_DECLARE(void) switch_core_media_bug_flush(_In_ switch_media_bug_t *bug);
+SWITCH_DECLARE(switch_status_t) switch_core_media_bug_flush_all(_In_ switch_core_session_t *session);
+
 ///\}
 
 ///\defgroup pa1 Port Allocation
@@ -502,9 +508,11 @@
   \param pool the pool to use for the allocation (a new one will be used if NULL)
   \return the newly created session
 */
-SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request(_In_ const switch_endpoint_interface_t *endpoint_interface,
-																	_Inout_opt_ switch_memory_pool_t **pool);
+SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request_uuid(_In_ switch_endpoint_interface_t *endpoint_interface,
+																		 _Inout_opt_ switch_memory_pool_t **pool, _In_opt_z_ const char *use_uuid);
+#define switch_core_session_request(_ep, _p) switch_core_session_request_uuid(_ep, _p, NULL)
 
+SWITCH_DECLARE(switch_status_t) switch_core_session_set_uuid(switch_core_session_t *session, const char *use_uuid);
 
 SWITCH_DECLARE(void) switch_core_session_perform_destroy(_Inout_ switch_core_session_t **session,
 														 _In_z_ const char *file, _In_z_ const char *func, _In_ int line);
@@ -775,7 +783,11 @@
   \param message the message to recieve
   \return the status returned by the message handler
 */
-SWITCH_DECLARE(switch_status_t) switch_core_session_receive_message(_In_ switch_core_session_t *session, _In_ switch_core_session_message_t *message);
+SWITCH_DECLARE(switch_status_t) switch_core_session_perform_receive_message(_In_ switch_core_session_t *session, 
+																			_In_ switch_core_session_message_t *message,
+																			const char *file, const char *func, int line);
+#define switch_core_session_receive_message(_session, _message) switch_core_session_perform_receive_message(_session, _message, \
+																											__FILE__, __SWITCH_FUNC__, __LINE__)
 
 /*! 
   \brief Queue an event on a given session
@@ -925,7 +937,11 @@
   \param pool the pool to use for the new hash
   \return SWITCH_STATUS_SUCCESS if the hash is created
 */
-SWITCH_DECLARE(switch_status_t) switch_core_hash_init(_Out_ switch_hash_t **hash, _In_ switch_memory_pool_t *pool);
+SWITCH_DECLARE(switch_status_t) switch_core_hash_init_case(_Out_ switch_hash_t **hash, _In_ switch_memory_pool_t *pool, switch_bool_t case_sensitive);
+#define switch_core_hash_init(_hash, _pool) switch_core_hash_init_case(_hash, _pool, SWITCH_TRUE)
+#define switch_core_hash_init_nocase(_hash, _pool) switch_core_hash_init_case(_hash, _pool, SWITCH_FALSE)
+
+
 
 /*! 
   \brief Destroy an existing hash table
@@ -1665,9 +1681,9 @@
 SWITCH_DECLARE(uint32_t) switch_core_default_dtmf_duration(uint32_t duration);
 SWITCH_DECLARE(switch_status_t) switch_console_set_complete(const char *string);
 SWITCH_DECLARE(switch_status_t) switch_console_set_alias(const char *string);
-
 SWITCH_DECLARE(int) switch_system(const char *cmd, switch_bool_t wait);
-
+SWITCH_DECLARE(void) switch_cond_yield(switch_interval_time_t t);
+SWITCH_DECLARE(void) switch_cond_next(void);
 ///\}
 
 /*!

Modified: freeswitch/branches/gmaruzz/src/include/switch_dso.h
==============================================================================
--- freeswitch/branches/gmaruzz/src/include/switch_dso.h	(original)
+++ freeswitch/branches/gmaruzz/src/include/switch_dso.h	Mon Nov 17 14:18:32 2008
@@ -21,21 +21,19 @@
 #ifndef _SWITCH_DSO_H
 #define _SWITCH_DSO_H
 
-typedef void (*switch_func_ptr_t) (void);
+typedef int (*switch_dso_func_t) (void);
 #ifdef WIN32
 typedef HINSTANCE switch_dso_lib_t;
 #else
 typedef void * switch_dso_lib_t;
 #endif
-#ifdef WIN32
-typedef FARPROC switch_dso_func_t;
-#else
-typedef void * switch_dso_func_t;
-#endif
+
+typedef void * switch_dso_data_t;
 
 void switch_dso_destroy(switch_dso_lib_t *lib);
 switch_dso_lib_t switch_dso_open(const char *path, int global, char **err);
 switch_dso_func_t switch_dso_func_sym(switch_dso_lib_t lib, const char *sym, char **err);
+void *switch_dso_data_sym(switch_dso_lib_t lib, const char *sym, char **err);
 
 
 #endif

Modified: freeswitch/branches/gmaruzz/src/include/switch_ivr.h
==============================================================================
--- freeswitch/branches/gmaruzz/src/include/switch_ivr.h	(original)
+++ freeswitch/branches/gmaruzz/src/include/switch_ivr.h	Mon Nov 17 14:18:32 2008
@@ -355,7 +355,7 @@
 														   uint32_t timeout,
 														   char *valid_terminators,
 														   char *audio_file,
-														   char *bad_input_audio_file, void *digit_buffer, uint32_t digit_buffer_length,
+														   char *bad_input_audio_file, char *digit_buffer, uint32_t digit_buffer_length,
 														   char *digits_regex);
 
 SWITCH_DECLARE(switch_status_t) switch_ivr_speak_text_handle(switch_core_session_t *session,

Modified: freeswitch/branches/gmaruzz/src/include/switch_loadable_module.h
==============================================================================
--- freeswitch/branches/gmaruzz/src/include/switch_loadable_module.h	(original)
+++ freeswitch/branches/gmaruzz/src/include/switch_loadable_module.h	Mon Nov 17 14:18:32 2008
@@ -80,6 +80,8 @@
 	switch_asr_interface_t *asr_interface;
 	/*! the table of management interfaces the module has implmented */
 	switch_management_interface_t *management_interface;
+	switch_thread_rwlock_t *rwlock;
+	int refs;
 	switch_memory_pool_t *pool;
 };
 
@@ -255,7 +257,7 @@
   \param err pointer to error message
   \return the status
 */
-SWITCH_DECLARE(switch_status_t) switch_loadable_module_unload_module(char *dir, char *fname, const char **err);
+SWITCH_DECLARE(switch_status_t) switch_loadable_module_unload_module(char *dir, char *fname, switch_bool_t force, const char **err);
 
 /* Prototypes of module interface functions */
 
@@ -348,7 +350,7 @@
 															 uint32_t encoded_bytes_per_packet,
 															 /*! number of channels represented */
 															 uint8_t number_of_channels,
-															 /*! number of frames to send in one netowrk packet */
+															 /*! number of frames to send in one network packet */
 															 int codec_frames_per_packet,
 															 /*! function to initialize a codec handle using this implementation */
 															 switch_core_codec_init_func_t init,
@@ -391,6 +393,10 @@
 	}
 
 
+
+
+
+
 SWITCH_END_EXTERN_C
 #endif
 /* For Emacs:

Modified: freeswitch/branches/gmaruzz/src/include/switch_module_interfaces.h
==============================================================================
--- freeswitch/branches/gmaruzz/src/include/switch_module_interfaces.h	(original)
+++ freeswitch/branches/gmaruzz/src/include/switch_module_interfaces.h	Mon Nov 17 14:18:32 2008
@@ -30,10 +30,10 @@
  *
  */
 /*! \file switch_module_interfaces.h
-    \brief Module Interface Definitions
+  \brief Module Interface Definitions
 
-	This module holds the definition of data abstractions used to implement various pluggable 
-	interfaces and pluggable event handlers.
+  This module holds the definition of data abstractions used to implement various pluggable 
+  interfaces and pluggable event handlers.
 
 */
 #ifndef SWITCH_MODULE_INTERFACES_H
@@ -44,8 +44,8 @@
 
 SWITCH_BEGIN_EXTERN_C
 /*! \brief A table of functions to execute at various states 
-*/
-	typedef enum {
+ */
+typedef enum {
 	SWITCH_SHN_ON_INIT,
 	SWITCH_SHN_ON_ROUTING,
 	SWITCH_SHN_ON_EXECUTE,
@@ -99,31 +99,7 @@
 
 
 typedef switch_call_cause_t (*switch_io_outgoing_channel_t)
- 
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	    (switch_core_session_t *, switch_event_t *, switch_caller_profile_t *, switch_core_session_t **, switch_memory_pool_t **, switch_originate_flag_t);
+(switch_core_session_t *, switch_event_t *, switch_caller_profile_t *, switch_core_session_t **, switch_memory_pool_t **, switch_originate_flag_t);
 typedef switch_status_t (*switch_io_read_frame_t) (switch_core_session_t *, switch_frame_t **, switch_io_flag_t, int);
 typedef switch_status_t (*switch_io_write_frame_t) (switch_core_session_t *, switch_frame_t *, switch_io_flag_t, int);
 typedef switch_status_t (*switch_io_kill_channel_t) (switch_core_session_t *, int);
@@ -196,7 +172,10 @@
 	void *private_info;
 
 	switch_thread_rwlock_t *rwlock;
+	int refs;
 
+	/* parent */
+	switch_loadable_module_interface_t *parent;
 	/* to facilitate linking */
 	struct switch_endpoint_interface *next;
 };
@@ -248,6 +227,8 @@
 	/*! function to deallocate the timer */
 	switch_status_t (*timer_destroy) (switch_timer_t *);
 	switch_thread_rwlock_t *rwlock;
+	int refs;
+	switch_loadable_module_interface_t *parent;
 	struct switch_timer_interface *next;
 };
 
@@ -258,6 +239,8 @@
 	/*! the function to read an extension and set a channels dialpan */
 	switch_dialplan_hunt_function_t hunt_function;
 	switch_thread_rwlock_t *rwlock;
+	int refs;
+	switch_loadable_module_interface_t *parent;
 	struct switch_dialplan_interface *next;
 };
 
@@ -282,13 +265,15 @@
 	/*! list of supported file extensions */
 	char **extens;
 	switch_thread_rwlock_t *rwlock;
+	int refs;
+	switch_loadable_module_interface_t *parent;
 	struct switch_file_interface *next;
 };
 
 /*! an abstract representation of a file handle (some parameters based on compat with libsndfile) */
 struct switch_file_handle {
 	/*! the interface of the module that implemented the current file type */
-	const switch_file_interface_t *file_interface;
+	switch_file_interface_t *file_interface;
 	/*! flags to control behaviour */
 	uint32_t flags;
 	/*! a file descriptor if neceessary */
@@ -359,13 +344,15 @@
 	/*! function to read results from the ASR */
 	switch_status_t (*asr_get_results) (switch_asr_handle_t *ah, char **xmlstr, switch_asr_flag_t *flags);
 	switch_thread_rwlock_t *rwlock;
+	int refs;
+	switch_loadable_module_interface_t *parent;
 	struct switch_asr_interface *next;
 };
 
 /*! an abstract representation of an asr speech interface. */
 struct switch_asr_handle {
 	/*! the interface of the module that implemented the current speech interface */
-	const switch_asr_interface_t *asr_interface;
+	switch_asr_interface_t *asr_interface;
 	/*! flags to control behaviour */
 	uint32_t flags;
 	/*! The Name */
@@ -400,6 +387,8 @@
 	void (*speech_numeric_param_tts) (switch_speech_handle_t *sh, char *param, int val);
 	void (*speech_float_param_tts) (switch_speech_handle_t *sh, char *param, double val);
 	switch_thread_rwlock_t *rwlock;
+	int refs;
+	switch_loadable_module_interface_t *parent;
 	struct switch_speech_interface *next;
 };
 
@@ -407,7 +396,7 @@
 /*! an abstract representation of a asr/tts speech interface. */
 struct switch_speech_handle {
 	/*! the interface of the module that implemented the current speech interface */
-	const switch_speech_interface_t *speech_interface;
+	switch_speech_interface_t *speech_interface;
 	/*! flags to control behaviour */
 	uint32_t flags;
 	/*! The Name */
@@ -433,6 +422,8 @@
 	/*! function to pass down to the module */
 	switch_say_callback_t say_function;
 	switch_thread_rwlock_t *rwlock;
+	int refs;
+	switch_loadable_module_interface_t *parent;
 	struct switch_say_interface *next;
 };
 
@@ -443,6 +434,8 @@
 	/*! function to open the directory interface */
 	switch_status_t (*chat_send) (char *proto, char *from, char *to, char *subject, char *body, char *hint);
 	switch_thread_rwlock_t *rwlock;
+	int refs;
+	switch_loadable_module_interface_t *parent;
 	struct switch_chat_interface *next;
 };
 
@@ -453,6 +446,8 @@
 	/*! function to open the directory interface */
 	switch_status_t (*management_function) (char *relative_oid, switch_management_action_t action, char *data, switch_size_t datalen);
 	switch_thread_rwlock_t *rwlock;
+	int refs;
+	switch_loadable_module_interface_t *parent;
 	struct switch_management_interface *next;
 };
 
@@ -471,13 +466,15 @@
 	/*! function to advance to the next name/value pair in the current record */
 	switch_status_t (*directory_next_pair) (switch_directory_handle_t *dh, char **var, char **val);
 	switch_thread_rwlock_t *rwlock;
+	int refs;
+	switch_loadable_module_interface_t *parent;
 	struct switch_directory_interface *next;
 };
 
 /*! an abstract representation of a directory interface. */
 struct switch_directory_handle {
 	/*! the interface of the module that implemented the current directory interface */
-	const switch_directory_interface_t *directory_interface;
+	switch_directory_interface_t *directory_interface;
 	/*! flags to control behaviour */
 	uint32_t flags;
 
@@ -528,7 +525,7 @@
 /*! an abstract handle to a codec module */
 struct switch_codec {
 	/*! the codec interface table this handle uses */
-	const switch_codec_interface_t *codec_interface;
+	switch_codec_interface_t *codec_interface;
 	/*! the specific implementation of the above codec */
 	const switch_codec_implementation_t *implementation;
 	/*! fmtp line from remote sdp */
@@ -544,6 +541,7 @@
 	/*! private data for the codec module to store handle specific info */
 	void *private_info;
 	switch_payload_t agreed_pt;
+	switch_mutex_t *mutex;
 };
 
 /*! \brief A table of settings and callbacks that define a paticular implementation of a codec */
@@ -594,6 +592,8 @@
 	switch_codec_implementation_t *implementations;
 	uint32_t codec_id;
 	switch_thread_rwlock_t *rwlock;
+	int refs;
+	switch_loadable_module_interface_t *parent;
 	struct switch_codec_interface *next;
 };
 
@@ -612,6 +612,8 @@
 	/*! flags to control behaviour */
 	uint32_t flags;
 	switch_thread_rwlock_t *rwlock;
+	int refs;
+	switch_loadable_module_interface_t *parent;
 	struct switch_application_interface *next;
 };
 
@@ -626,9 +628,14 @@
 	/*! an example of the api syntax */
 	const char *syntax;
 	switch_thread_rwlock_t *rwlock;
+	int refs;
+	switch_loadable_module_interface_t *parent;
 	struct switch_api_interface *next;
 };
 
+#define PROTECT_INTERFACE(_it) if (_it && !_it->refs) {switch_thread_rwlock_rdlock(_it->parent->rwlock); switch_thread_rwlock_rdlock(_it->rwlock); _it->refs++; _it->parent->refs++;} //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "+++++++++++LOCK\n");
+#define UNPROTECT_INTERFACE(_it) if (_it && _it->refs) {switch_thread_rwlock_unlock(_it->rwlock); switch_thread_rwlock_unlock(_it->parent->rwlock); _it->refs--; _it->parent->refs--; _it = NULL;} //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "-----------UNLOCK\n");
+
 SWITCH_END_EXTERN_C
 #endif
 /* For Emacs:

Modified: freeswitch/branches/gmaruzz/src/include/switch_rtp.h
==============================================================================
--- freeswitch/branches/gmaruzz/src/include/switch_rtp.h	(original)
+++ freeswitch/branches/gmaruzz/src/include/switch_rtp.h	Mon Nov 17 14:18:32 2008
@@ -110,6 +110,8 @@
 */
 SWITCH_DECLARE(switch_port_t) switch_rtp_request_port(const char *ip);
 SWITCH_DECLARE(void) switch_rtp_release_port(const char *ip, switch_port_t port);
+
+SWITCH_DECLARE(void) switch_rtp_change_interval(switch_rtp_t *rtp_session, uint32_t ms_per_packet, uint32_t samples_per_interval);
 /*! 
   \brief create a new RTP session handle
   \param new_rtp_session a poiter to aim at the new session
@@ -250,7 +252,7 @@
   \param rtp_session the RTP session to set the samples per interval on
   \param samples_per_interval the new default samples per interval 
 */
-SWITCH_DECLARE(void) switch_rtp_set_default_samples_per_interval(switch_rtp_t *rtp_session, uint16_t samples_per_interval);
+SWITCH_DECLARE(void) switch_rtp_set_default_samples_per_interval(switch_rtp_t *rtp_session, uint32_t samples_per_interval);
 
 /*! 
   \brief Get the default samples per interval for a given RTP session

Modified: freeswitch/branches/gmaruzz/src/include/switch_types.h
==============================================================================
--- freeswitch/branches/gmaruzz/src/include/switch_types.h	(original)
+++ freeswitch/branches/gmaruzz/src/include/switch_types.h	Mon Nov 17 14:18:32 2008
@@ -153,6 +153,7 @@
 #define SWITCH_LOCAL_VIDEO_IP_VARIABLE "local_video_ip"
 #define SWITCH_LOCAL_VIDEO_PORT_VARIABLE "local_video_port"
 #define SWITCH_HANGUP_AFTER_BRIDGE_VARIABLE "hangup_after_bridge"
+#define SWITCH_PARK_AFTER_BRIDGE_VARIABLE "park_after_bridge"
 #define SWITCH_EXEC_AFTER_BRIDGE_APP_VARIABLE "exec_after_bridge_app"
 #define SWITCH_EXEC_AFTER_BRIDGE_ARG_VARIABLE "exec_after_bridge_arg"
 #define SWITCH_MAX_FORWARDS_VARIABLE "max_forwards"
@@ -565,7 +566,8 @@
 	SWITCH_MESSAGE_INDICATE_DEFLECT,
 	SWITCH_MESSAGE_INDICATE_VIDEO_REFRESH_REQ,
 	SWITCH_MESSAGE_INDICATE_DISPLAY,
-	SWITCH_MESSAGE_INDICATE_TRANSCODING_NECESSARY
+	SWITCH_MESSAGE_INDICATE_TRANSCODING_NECESSARY,
+	SWITCH_MESSAGE_INVALID
 } switch_core_session_message_types_t;
 
 
@@ -624,6 +626,7 @@
 	SWITCH_STATUS_UNLOAD,
 	SWITCH_STATUS_NOUNLOAD,
 	SWITCH_STATUS_IGNORE,
+	SWITCH_STATUS_TOO_SMALL,
 	SWITCH_STATUS_NOT_INITALIZED
 } switch_status_t;
 
@@ -1038,6 +1041,7 @@
 	SWITCH_EVENT_CHANNEL_UNPARK 	- A channel has been unparked
 	SWITCH_EVENT_CHANNEL_APPLICATION- A channel has called and event from an application
 	SWITCH_EVENT_CHANNEL_ORIGINATE  - A channel has been originated
+	SWITCH_EVENT_CHANNEL_UUID       - A channel has changed uuid
     SWITCH_EVENT_API				- An API call has been executed
     SWITCH_EVENT_LOG				- A LOG event has been triggered
     SWITCH_EVENT_INBOUND_CHAN		- A new inbound channel has been created
@@ -1095,6 +1099,7 @@
 	SWITCH_EVENT_CHANNEL_UNPARK,
 	SWITCH_EVENT_CHANNEL_APPLICATION,
 	SWITCH_EVENT_CHANNEL_ORIGINATE,
+	SWITCH_EVENT_CHANNEL_UUID,
 	SWITCH_EVENT_API,
 	SWITCH_EVENT_LOG,
 	SWITCH_EVENT_INBOUND_CHAN,
@@ -1351,7 +1356,7 @@
 typedef struct switch_network_list switch_network_list_t;
 
 
-#define SWITCH_API_VERSION 1
+#define SWITCH_API_VERSION 3
 #define SWITCH_MODULE_LOAD_ARGS (switch_loadable_module_interface_t **module_interface, switch_memory_pool_t *pool)
 #define SWITCH_MODULE_RUNTIME_ARGS (void)
 #define SWITCH_MODULE_SHUTDOWN_ARGS (void)
@@ -1362,22 +1367,32 @@
 #define SWITCH_MODULE_RUNTIME_FUNCTION(name) switch_status_t name SWITCH_MODULE_RUNTIME_ARGS
 #define SWITCH_MODULE_SHUTDOWN_FUNCTION(name) switch_status_t name SWITCH_MODULE_SHUTDOWN_ARGS
 
+typedef enum {
+	SMODF_NONE = 0,
+	SMODF_GLOBAL_SYMBOLS = (1 << 0)
+} switch_module_flag_enum_t;
+typedef uint32_t switch_module_flag_t;
+
 typedef struct switch_loadable_module_function_table {
 	int switch_api_version;
 	switch_module_load_t load;
 	switch_module_shutdown_t shutdown;
 	switch_module_runtime_t runtime;
+	switch_module_flag_t flags;
 } switch_loadable_module_function_table_t;
 
-#define SWITCH_MODULE_DEFINITION(name, load, shutdown, runtime)								\
+#define SWITCH_MODULE_DEFINITION_EX(name, load, shutdown, runtime, flags)					\
 static const char modname[] =  #name ;														\
 SWITCH_MOD_DECLARE_DATA switch_loadable_module_function_table_t name##_module_interface = {	\
 	SWITCH_API_VERSION,																		\
 	load,																					\
 	shutdown,																				\
-	runtime																					\
+	runtime,																				\
+	flags																					\
 }
 
+#define SWITCH_MODULE_DEFINITION(name, load, shutdown, runtime)								\
+		SWITCH_MODULE_DEFINITION_EX(name, load, shutdown, runtime, SMODF_NONE)
 
 /* things we don't deserve to know about */
 /*! \brief A channel */

Modified: freeswitch/branches/gmaruzz/src/include/switch_utils.h
==============================================================================
--- freeswitch/branches/gmaruzz/src/include/switch_utils.h	(original)
+++ freeswitch/branches/gmaruzz/src/include/switch_utils.h	Mon Nov 17 14:18:32 2008
@@ -303,7 +303,7 @@
 	if (it) {
 		dup = strdup(it);
 		for(p = dup; p && *p; p++) {
-			*p = tolower(*p);
+			*p = (char) tolower(*p);
 		}
 		return dup;
 	}
@@ -320,7 +320,7 @@
 	if (it) {
 		dup = strdup(it);
 		for(p = dup; p && *p; p++) {
-			*p = toupper(*p);
+			*p = (char) toupper(*p);
 		}
 		return dup;
 	}
@@ -404,6 +404,7 @@
   \return the epoch time in usec
 */
 SWITCH_DECLARE(switch_time_t) switch_str_time(const char *in);
+#define switch_time_from_sec(sec)   ((switch_time_t)(sec) * 1000000)
 
 /*!
   \brief Declares a function designed to set a dymaic global string

Modified: freeswitch/branches/gmaruzz/src/include/switch_xml.h
==============================================================================
--- freeswitch/branches/gmaruzz/src/include/switch_xml.h	(original)
+++ freeswitch/branches/gmaruzz/src/include/switch_xml.h	Mon Nov 17 14:18:32 2008
@@ -353,7 +353,15 @@
 ///\param user_data a pointer to private data to be used during the callback
 ///\return SWITCH_STATUS_SUCCESS if successful
 ///\note gateway functions will be executed in the order they were binded until a success is found else the root registry will be used
-SWITCH_DECLARE(switch_status_t) switch_xml_bind_search_function(switch_xml_search_function_t function, switch_xml_section_t sections, void *user_data);
+
+SWITCH_DECLARE(void) switch_xml_set_binding_sections(switch_xml_binding_t *binding, switch_xml_section_t sections);
+SWITCH_DECLARE(void) switch_xml_set_binding_user_data(switch_xml_binding_t *binding, void *user_data);
+SWITCH_DECLARE(switch_xml_section_t) switch_xml_get_binding_sections(switch_xml_binding_t *binding);
+SWITCH_DECLARE(void *) switch_xml_get_binding_user_data(switch_xml_binding_t *binding);
+
+SWITCH_DECLARE(switch_status_t) switch_xml_bind_search_function_ret(switch_xml_search_function_t function, switch_xml_section_t sections, void *user_data, switch_xml_binding_t **ret_binding);
+#define switch_xml_bind_search_function(_f, _s, _u) switch_xml_bind_search_function_ret(_f, _s, _u, NULL)
+
 
 SWITCH_DECLARE(switch_status_t) switch_xml_unbind_search_function(switch_xml_binding_t **binding);
 SWITCH_DECLARE(switch_status_t) switch_xml_unbind_search_function_ptr(switch_xml_search_function_t function);

Modified: freeswitch/branches/gmaruzz/src/mod/applications/mod_commands/mod_commands.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/applications/mod_commands/mod_commands.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/applications/mod_commands/mod_commands.c	Mon Nov 17 14:18:32 2008
@@ -42,6 +42,41 @@
 SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load);
 SWITCH_MODULE_DEFINITION(mod_commands, mod_commands_load, NULL, NULL);
 
+SWITCH_STANDARD_API(time_test_function)
+{
+	switch_time_t now, then;
+	int x;
+	long mss;
+	uint32_t total = 0;
+	int diff;
+	int max = 10;
+	char *p;
+	if (switch_strlen_zero(cmd)){
+		stream->write_function(stream, "parameter missing\n");
+		return SWITCH_STATUS_SUCCESS;
+	}
+	mss = atol(cmd);
+
+	if ((p = strchr(cmd, ' '))) {
+		max = atoi(p+1);
+		if (max < 0) {
+			max = 10;
+		}
+	}
+
+	for (x = 0; x < max; x++) {
+		then = switch_time_now();
+		switch_yield(mss);
+		now = switch_time_now();
+		diff = (int) (now - then);
+		stream->write_function(stream, "test %d sleep %ld %d\n", x+1, mss, diff);
+		total += diff;
+	}
+	stream->write_function(stream, "avg %d\n", total / x);
+
+	return SWITCH_STATUS_SUCCESS;
+}
+
 SWITCH_STANDARD_API(user_data_function)
 {
 	switch_xml_t x_domain, xml = NULL, x_user = NULL, x_param, x_params;
@@ -77,6 +112,12 @@
 	switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "key", key);
 
 	if (key && type && switch_xml_locate_user("id", user, domain, NULL, &xml, &x_domain, &x_user, params) == SWITCH_STATUS_SUCCESS) {
+		if (!strcmp(type, "attr")) {
+			const char *attr = switch_xml_attr_soft(x_user, key);
+			stream->write_function(stream, "%s", attr);
+			goto end;
+		}
+
 		if (!strcmp(type, "var")) {
 			container = "variables";
 			elem = "variable";
@@ -853,20 +894,47 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
+#define UNLOAD_SYNTAX "[-f] <mod_name>"
 SWITCH_STANDARD_API(unload_function)
 {
 	const char *err;
+	switch_bool_t force = SWITCH_FALSE;
+	const char *p = cmd;
 
 	if (session) {
 		return SWITCH_STATUS_FALSE;
 	}
 
 	if (switch_strlen_zero(cmd)) {
-		stream->write_function(stream, "-USAGE: %s\n", LOAD_SYNTAX);
+		stream->write_function(stream, "-USAGE: %s\n", UNLOAD_SYNTAX);
+		return SWITCH_STATUS_SUCCESS;
+	}
+
+
+	if (*p == '-') {
+		p++;
+		while(p && *p) {
+			switch (*p) {
+			case ' ':
+				cmd = p+1;
+				goto end;
+			case 'f':
+				force = SWITCH_TRUE;
+				break;
+			default:
+				break;
+			}
+			p++;
+		}
+	}
+ end:
+
+	if (switch_strlen_zero(cmd)) {
+		stream->write_function(stream, "-USAGE: %s\n", UNLOAD_SYNTAX);
 		return SWITCH_STATUS_SUCCESS;
 	}
 
-	if (switch_loadable_module_unload_module((char *) SWITCH_GLOBAL_dirs.mod_dir, (char *) cmd, &err) == SWITCH_STATUS_SUCCESS) {
+	if (switch_loadable_module_unload_module((char *) SWITCH_GLOBAL_dirs.mod_dir, (char *) cmd, force, &err) == SWITCH_STATUS_SUCCESS) {
 		stream->write_function(stream, "+OK\n");
 	} else {
 		stream->write_function(stream, "-ERR [%s]\n", err);
@@ -878,20 +946,46 @@
 SWITCH_STANDARD_API(reload_function)
 {
 	const char *err;
+	switch_bool_t force = SWITCH_FALSE;
+	const char *p = cmd;
 
 	if (session) {
 		return SWITCH_STATUS_FALSE;
 	}
 
 	if (switch_strlen_zero(cmd)) {
-		stream->write_function(stream, "-USAGE: %s\n", LOAD_SYNTAX);
+		stream->write_function(stream, "-USAGE: %s\n", UNLOAD_SYNTAX);
 		return SWITCH_STATUS_SUCCESS;
 	}
 
-	if (switch_loadable_module_unload_module((char *) SWITCH_GLOBAL_dirs.mod_dir, (char *) cmd, &err) == SWITCH_STATUS_SUCCESS) {
+	if (*p == '-') {
+		p++;
+		while(p && *p) {
+			switch (*p) {
+			case ' ':
+				cmd = p+1;
+				goto end;
+			case 'f':
+				force = SWITCH_TRUE;
+				break;
+			default:
+				break;
+			}
+			p++;
+		}
+	}
+ end:
+
+	if (switch_strlen_zero(cmd)) {
+		stream->write_function(stream, "-USAGE: %s\n", UNLOAD_SYNTAX);
+		return SWITCH_STATUS_SUCCESS;
+	}
+
+	if (switch_loadable_module_unload_module((char *) SWITCH_GLOBAL_dirs.mod_dir, (char *) cmd, force, &err) == SWITCH_STATUS_SUCCESS) {
 		stream->write_function(stream, "+OK module unloaded\n");
 	} else {
 		stream->write_function(stream, "-ERR unloading module [%s]\n", err);
+		return SWITCH_STATUS_SUCCESS;
 	}
 
 	if (switch_loadable_module_load_module((char *) SWITCH_GLOBAL_dirs.mod_dir, (char *) cmd, SWITCH_TRUE, &err) == SWITCH_STATUS_SUCCESS) {
@@ -921,26 +1015,39 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-#define KILL_SYNTAX "<uuid>"
+#define KILL_SYNTAX "<uuid> [cause]"
 SWITCH_STANDARD_API(kill_function)
 {
 	switch_core_session_t *ksession = NULL;
+	char *mycmd = NULL, *kcause = NULL;
+	switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING;
 
 	if (session) {
 		return SWITCH_STATUS_FALSE;
 	}
 
-	if (!cmd) {
+	if (switch_strlen_zero(cmd) || !(mycmd = strdup(cmd))) {
 		stream->write_function(stream, "-USAGE: %s\n", KILL_SYNTAX);
-	} else if ((ksession = switch_core_session_locate(cmd))) {
+		return SWITCH_STATUS_SUCCESS;
+	}
+
+	if ((kcause = strchr(mycmd, ' '))) {
+		*kcause++ = '\0';
+	}
+
+	if (switch_strlen_zero(mycmd) || !(ksession = switch_core_session_locate(mycmd))) {
+		stream->write_function(stream, "-ERR No Such Channel!\n");
+	} else {
 		switch_channel_t *channel = switch_core_session_get_channel(ksession);
-		switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
+		if (!switch_strlen_zero(kcause)){
+			cause = switch_channel_str2cause(kcause);
+		}  
+		switch_channel_hangup(channel, cause);
 		switch_core_session_rwunlock(ksession);
 		stream->write_function(stream, "+OK\n");
-	} else {
-		stream->write_function(stream, "-ERR No Such Channel!\n");
 	}
 
+	switch_safe_free(mycmd);
 	return SWITCH_STATUS_SUCCESS;
 }
 
@@ -2477,7 +2584,22 @@
 
 }
 
-#define SETVAR_SYNTAX "<uuid> <var> <value>"
+SWITCH_STANDARD_API(uuid_flush_dtmf_function)
+{
+	switch_core_session_t *fsession;
+
+	if (!switch_strlen_zero(cmd) && (fsession = switch_core_session_locate(cmd))) {
+		switch_channel_flush_dtmf(switch_core_session_get_channel(fsession));
+		switch_core_session_rwunlock(fsession);
+		stream->write_function(stream, "+OK\n");
+	} else {
+		stream->write_function(stream, "-ERR no such session\n");
+	}
+
+	return SWITCH_STATUS_SUCCESS;
+}
+
+#define SETVAR_SYNTAX "<uuid> <var> [value]"
 SWITCH_STANDARD_API(uuid_setvar_function)
 {
 	switch_core_session_t *psession = NULL;
@@ -2490,10 +2612,14 @@
 
 	if (!switch_strlen_zero(cmd) && (mycmd = strdup(cmd))) {
 		argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
-		if (argc == 3 && !switch_strlen_zero(argv[0])) {
+		if ((argc == 2 || argc == 3) && !switch_strlen_zero(argv[0])) {
 			char *uuid = argv[0];
 			char *var_name = argv[1];
-			char *var_value = argv[2];
+			char *var_value = NULL;
+
+			if (argc == 3) {
+				var_value =	argv[2];
+			}
 
 			if ((psession = switch_core_session_locate(uuid))) {
 				switch_channel_t *channel;
@@ -2523,6 +2649,62 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
+
+#define SETVAR_MULTI_SYNTAX "<uuid> <var>=<value>;<var>=<value>..."
+SWITCH_STANDARD_API(uuid_setvar_multi_function)
+{
+	switch_core_session_t *psession = NULL;
+	char *mycmd = NULL, *vars, *argv[2] = { 0 };
+	int argc = 0;
+	char *var_name, *var_value;
+
+	if (session) {
+		return SWITCH_STATUS_FALSE;
+	}
+
+	if (!switch_strlen_zero(cmd) && (mycmd = strdup(cmd))) {
+		char *uuid = mycmd;
+		if (!(vars = strchr(uuid, ' '))) {
+			goto done;
+		}
+		*vars++ = '\0';
+
+		if ((psession = switch_core_session_locate(uuid))) {
+			switch_channel_t *channel = switch_core_session_get_channel(psession);
+			int x, y = 0;		
+			argc = switch_separate_string(vars, ';', argv, (sizeof(argv) / sizeof(argv[0])));
+
+			for (x = 0 ; x < argc; x++) {
+				var_name = argv[x];
+				if (var_name && (var_value = strchr(var_name, '='))) {
+					*var_value++ = '\0';
+				}
+				if (switch_strlen_zero(var_name)) {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No variable name specified.\n");
+					stream->write_function(stream, "-ERR No variable specified\n");
+				} else {
+					switch_channel_set_variable(channel, var_name, var_value);
+					y++;
+				}
+			}
+			
+			switch_core_session_rwunlock(psession);
+			if (y) {
+				stream->write_function(stream, "+OK\n");
+				goto done;
+			}
+		} else {
+			stream->write_function(stream, "-ERR No Such Channel!\n");
+		}
+	}
+	
+	stream->write_function(stream, "-USAGE: %s\n", SETVAR_SYNTAX);
+
+  done:
+	switch_safe_free(mycmd);
+	return SWITCH_STATUS_SUCCESS;
+}
+
 #define GETVAR_SYNTAX "<uuid> <var>"
 SWITCH_STANDARD_API(uuid_getvar_function)
 {
@@ -2815,6 +2997,7 @@
 	switch_api_interface_t *commands_api_interface;
 	*module_interface = switch_loadable_module_create_module_interface(pool, modname);
 
+	SWITCH_ADD_API(commands_api_interface, "uuid_flush_dtmf", "Flush dtmf on a given uuid", uuid_flush_dtmf_function, "<uuid>");
 	SWITCH_ADD_API(commands_api_interface, "md5", "md5", md5_function, "<data>");
 	SWITCH_ADD_API(commands_api_interface, "hupall", "hupall", hupall_api_function, "<cause> [<var> <value>]");
 	SWITCH_ADD_API(commands_api_interface, "strftime_tz", "strftime_tz", strftime_tz_api_function, "<Timezone_name> [format string]");
@@ -2825,8 +3008,8 @@
 	SWITCH_ADD_API(commands_api_interface, "reloadacl", "Reload ACL", reload_acl_function, "[reloadxml]");
 	switch_console_set_complete("add reloadacl reloadxml");
 	SWITCH_ADD_API(commands_api_interface, "reloadxml", "Reload XML", reload_xml_function, "");
-	SWITCH_ADD_API(commands_api_interface, "unload", "Unload Module", unload_function, LOAD_SYNTAX);
-	SWITCH_ADD_API(commands_api_interface, "reload", "Reload Module", reload_function, LOAD_SYNTAX);
+	SWITCH_ADD_API(commands_api_interface, "unload", "Unload Module", unload_function, UNLOAD_SYNTAX);
+	SWITCH_ADD_API(commands_api_interface, "reload", "Reload Module", reload_function, UNLOAD_SYNTAX);
 	SWITCH_ADD_API(commands_api_interface, "load", "Load Module", load_function, LOAD_SYNTAX);
 	SWITCH_ADD_API(commands_api_interface, "uuid_transfer", "Transfer a session", transfer_function, TRANSFER_SYNTAX);
 	SWITCH_ADD_API(commands_api_interface, "pause", "Pause", pause_function, PAUSE_SYNTAX);
@@ -2853,6 +3036,7 @@
 	SWITCH_ADD_API(commands_api_interface, "uuid_session_heartbeat", "uuid_session_heartbeat", uuid_session_heartbeat_function, HEARTBEAT_SYNTAX);
 	SWITCH_ADD_API(commands_api_interface, "uuid_bridge", "uuid_bridge", uuid_bridge_function, "");
 	SWITCH_ADD_API(commands_api_interface, "uuid_setvar", "uuid_setvar", uuid_setvar_function, SETVAR_SYNTAX);
+	SWITCH_ADD_API(commands_api_interface, "uuid_setvar_multi", "uuid_setvar_multi", uuid_setvar_multi_function, SETVAR_MULTI_SYNTAX);
 	SWITCH_ADD_API(commands_api_interface, "uuid_getvar", "uuid_getvar", uuid_getvar_function, GETVAR_SYNTAX);
 	SWITCH_ADD_API(commands_api_interface, "uuid_dump", "uuid_dump", uuid_dump_function, DUMP_SYNTAX);
 	SWITCH_ADD_API(commands_api_interface, "global_setvar", "global_setvar", global_setvar_function, GLOBAL_SETVAR_SYNTAX);
@@ -2902,7 +3086,7 @@
 	SWITCH_ADD_API(commands_api_interface, "find_user_xml", "find a user", find_user_function, "<key> <user> <domain>");
 	SWITCH_ADD_API(commands_api_interface, "user_exists", "find a user", user_exists_function, "<key> <user> <domain>");
 	SWITCH_ADD_API(commands_api_interface, "xml_locate", "find some xml", xml_locate_function, "[root | <section> <tag> <tag_attr_name> <tag_attr_val>]");
-	SWITCH_ADD_API(commands_api_interface, "user_data", "find user data", user_data_function, "<user>@<domain> [var|param] <name>");
+	SWITCH_ADD_API(commands_api_interface, "user_data", "find user data", user_data_function, "<user>@<domain> [var|param|attr] <name>");
 	SWITCH_ADD_API(commands_api_interface, "url_encode", "url encode a string", url_encode_function, "<string>");
 	SWITCH_ADD_API(commands_api_interface, "url_decode", "url decode a string", url_decode_function, "<string>");
 	SWITCH_ADD_API(commands_api_interface, "module_exists", "check if module exists", module_exists_function, "<module>");
@@ -2910,6 +3094,7 @@
 	SWITCH_ADD_API(commands_api_interface, "uuid_send_dtmf", "send dtmf digits", uuid_send_dtmf_function, UUID_SEND_DTMF_SYNTAX);
 	SWITCH_ADD_API(commands_api_interface, "eval", "eval (noop)", eval_function, "<expression>");
 	SWITCH_ADD_API(commands_api_interface, "system", "Execute a system command", system_function, SYSTEM_SYNTAX);
+	SWITCH_ADD_API(commands_api_interface, "time_test", "time_test", time_test_function, "<mss>");
 
 	/* indicate that the module should continue to be loaded */
 	return SWITCH_STATUS_NOUNLOAD;

Modified: freeswitch/branches/gmaruzz/src/mod/applications/mod_conference/mod_conference.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/applications/mod_conference/mod_conference.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/applications/mod_conference/mod_conference.c	Mon Nov 17 14:18:32 2008
@@ -790,7 +790,6 @@
 
 		if (switch_channel_test_flag(switch_core_session_get_channel(conference->floor_holder->session), CF_VIDEO)) {
 			status = switch_core_session_read_video_frame(conference->floor_holder->session, &vid_frame, SWITCH_IO_FLAG_NONE, 0);
-
 			if (!SWITCH_READ_ACCEPTABLE(status)) {
 				conference->floor_holder = NULL;
 				req_iframe = 0;
@@ -817,7 +816,8 @@
 #endif
 
 				if (vid_frame->codec->implementation->ianacode == 34) {	/* h.263 */
-					iframe = (*((int16_t *) vid_frame->data) >> 12 == 6);
+					//iframe = (*((int16_t *) vid_frame->data) >> 12 == 6);
+					iframe = 1;			
 				} else if (vid_frame->codec->implementation->ianacode == 115) {	/* h.263-1998 */
 					int y = *((int8_t *) vid_frame->data + 2) & 0xfe;
 					iframe = (y == 0x80 || y == 0x82);
@@ -1195,7 +1195,7 @@
 	if (conference->video_running == 1) {
 		conference->video_running = -1;
 		while (conference->video_running) {
-			switch_yield(1000);
+			switch_cond_next();
 		}
 	}
 
@@ -2010,7 +2010,7 @@
 		if (use_timer) {
 			switch_core_timer_next(&timer);
 		} else {
-			switch_yield(1000);
+			switch_cond_next();
 		}
 
 	}							/* Rinse ... Repeat */
@@ -2032,7 +2032,7 @@
 
 	/* Wait for the input thread to end */
 	while (switch_test_flag(member, MFLAG_ITHREAD)) {
-		switch_yield(1000);
+		switch_cond_next();
 	}
 }
 
@@ -2259,6 +2259,7 @@
 	switch_memory_pool_t *pool;
 	uint32_t count;
 	char *dfile = NULL, *expanded = NULL;
+	int say = 0;
 
 	switch_assert(conference != NULL);
 
@@ -2279,13 +2280,17 @@
 		}
 	}
 
-	if (!async && !strncasecmp(file, "say:", 4)) {
+	if (!strncasecmp(file, "say:", 4)) {
+		say = 1;
+	}
+
+	if (!async && say) {
 		status = conference_say(conference, file + 4, leadin);
 		goto done;
 	}
 
 	if (!switch_is_file_path(file)) {
-		if (conference->sound_prefix) {
+		if (!say && conference->sound_prefix) {
 			if (!(dfile = switch_mprintf("%s%s%s", conference->sound_prefix, SWITCH_PATH_SEPARATOR, file))) {
 				goto done;
 			}
@@ -4583,16 +4588,22 @@
 		char *toplay = NULL;
 		char *dfile = NULL;
 
-		if (conference->sound_prefix) {
-			dfile = switch_mprintf("%s%s%s", conference->sound_prefix, SWITCH_PATH_SEPARATOR, conference->kicked_sound);
-			switch_assert(dfile);
-			toplay = dfile;
+		if (!strncasecmp(conference->kicked_sound, "say:", 4)) {
+			if (conference->tts_engine && conference->tts_voice) {
+				switch_ivr_speak_text(session, conference->tts_engine, conference->tts_voice, conference->kicked_sound + 4, NULL);
+			}
 		} else {
-			toplay = conference->kicked_sound;
-		}
+			if (conference->sound_prefix) {
+				dfile = switch_mprintf("%s%s%s", conference->sound_prefix, SWITCH_PATH_SEPARATOR, conference->kicked_sound);
+				switch_assert(dfile);
+				toplay = dfile;
+			} else {
+				toplay = conference->kicked_sound;
+			}
 
-		switch_ivr_play_file(session, NULL, toplay, NULL);
-		switch_safe_free(dfile);
+			switch_ivr_play_file(session, NULL, toplay, NULL);
+			switch_safe_free(dfile);
+		}
 	}
 
 	switch_core_session_reset(session, SWITCH_TRUE);
@@ -4630,6 +4641,7 @@
 	switch_threadattr_detach_set(thd_attr, 1);
 	switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
 	switch_thread_create(&thread, thd_attr, conference_video_thread_run, conference, conference->pool);
+	conference->video_running = 1;
 }
 
 static void launch_conference_record_thread(conference_obj_t *conference, char *path)

Modified: freeswitch/branches/gmaruzz/src/mod/applications/mod_dptools/mod_dptools.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/applications/mod_dptools/mod_dptools.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/applications/mod_dptools/mod_dptools.c	Mon Nov 17 14:18:32 2008
@@ -411,6 +411,11 @@
 
 }
 
+SWITCH_STANDARD_APP(flush_dtmf_function)
+{
+	switch_channel_flush_dtmf(switch_core_session_get_channel(session));
+}
+
 SWITCH_STANDARD_APP(transfer_function)
 {
 	int argc;
@@ -1951,6 +1956,8 @@
 		cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
 	}
 
+	UNPROTECT_INTERFACE(error_endpoint_interface);
+
 	return cause;
 }
 
@@ -2111,6 +2118,8 @@
 
   done:
 
+	UNPROTECT_INTERFACE(user_endpoint_interface);
+
 	if (xml) {
 		switch_xml_free(xml);
 	}
@@ -2262,11 +2271,11 @@
 	*module_interface = switch_loadable_module_create_module_interface(pool, modname);
 
 	error_endpoint_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE);
-	error_endpoint_interface->interface_name = "ERROR";
+	error_endpoint_interface->interface_name = "error";
 	error_endpoint_interface->io_routines = &error_io_routines;
 
 	user_endpoint_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE);
-	user_endpoint_interface->interface_name = "USER";
+	user_endpoint_interface->interface_name = "user";
 	user_endpoint_interface->io_routines = &user_io_routines;
 
 	SWITCH_ADD_CHAT(chat_interface, "event", event_chat_send);
@@ -2279,6 +2288,7 @@
 	SWITCH_ADD_APP(app_interface, "privacy", "Set privacy on calls", "Set caller privacy on calls.", privacy_function, "off|on|name|full|number",
 				   SAF_SUPPORT_NOMEDIA);
 
+	SWITCH_ADD_APP(app_interface, "flush_dtmf", "flush any queued dtmf", "flush any queued dtmf", flush_dtmf_function, "", SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "hold", "Send a hold message", "Send a hold message", hold_function, HOLD_SYNTAX, SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "unhold", "Send a un-hold message", "Send a un-hold message", unhold_function, UNHOLD_SYNTAX, SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "transfer", "Transfer a channel", TRANSFER_LONG_DESC, transfer_function, "<exten> [<dialplan> <context>]",

Modified: freeswitch/branches/gmaruzz/src/mod/applications/mod_enum/mod_enum.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/applications/mod_enum/mod_enum.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/applications/mod_enum/mod_enum.c	Mon Nov 17 14:18:32 2008
@@ -461,6 +461,8 @@
 	struct dns_ctx *nctx = NULL;
 	char *num, *mnum = NULL, *mroot = NULL, *p;
 
+	*results = NULL;
+
 	mnum = switch_mprintf("%s%s", *in == '+' ? "" : "+", in);
 
 	if ((p = strchr(mnum, '*'))) {
@@ -563,7 +565,7 @@
 SWITCH_STANDARD_DIALPLAN(enum_dialplan_hunt)
 {
 	switch_caller_extension_t *extension = NULL;
-	enum_record_t *results, *rp;
+	enum_record_t *results = NULL, *rp;
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 	char *dp = (char *) arg;
 

Modified: freeswitch/branches/gmaruzz/src/mod/applications/mod_fifo/mod_fifo.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/applications/mod_fifo/mod_fifo.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/applications/mod_fifo/mod_fifo.c	Mon Nov 17 14:18:32 2008
@@ -29,6 +29,9 @@
  *
  */
 #include <switch.h>
+#ifdef SWITCH_HAVE_ODBC
+#include <switch_odbc.h>
+#endif
 
 SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_fifo_shutdown);
 SWITCH_MODULE_LOAD_FUNCTION(mod_fifo_load);
@@ -36,8 +39,10 @@
 
 #define FIFO_EVENT "fifo::info"
 
+static switch_status_t load_config(int reload, int del_all);
 #define MAX_PRI 10
 
+
 struct fifo_node {
 	char *name;
 	switch_mutex_t *mutex;
@@ -48,6 +53,10 @@
 	int consumer_count;
 	switch_time_t start_waiting;
 	uint32_t importance;
+	switch_thread_rwlock_t *rwlock;
+	switch_memory_pool_t *pool;
+	int has_outbound;
+	int ready;
 };
 
 typedef struct fifo_node fifo_node_t;
@@ -240,11 +249,116 @@
 static struct {
 	switch_hash_t *fifo_hash;
 	switch_mutex_t *mutex;
+	switch_mutex_t *sql_mutex;
 	switch_memory_pool_t *pool;
 	int running;
 	switch_event_node_t *node;
+	char hostname[256];
+	char *dbname;
+	char *odbc_dsn;
+	int node_thread_running;
+	
+#ifdef SWITCH_HAVE_ODBC
+	switch_odbc_handle_t *master_odbc;
+#else
+	void *filler1;
+#endif
 } globals;
 
+
+static switch_status_t fifo_execute_sql(char *sql, switch_mutex_t *mutex)
+{
+	switch_core_db_t *db;
+	switch_status_t status = SWITCH_STATUS_SUCCESS;
+	char *err_str;
+
+	if (mutex) {
+		switch_mutex_lock(mutex);
+	}
+#ifdef SWITCH_HAVE_ODBC
+	if (globals.odbc_dsn) {
+		SQLHSTMT stmt;
+		if (switch_odbc_handle_exec(globals.master_odbc, sql, &stmt) != SWITCH_ODBC_SUCCESS) {
+			
+			err_str = switch_odbc_handle_get_error(globals.master_odbc, stmt);
+			if (!switch_strlen_zero(err_str)) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ERR: [%s]\n[%s]\n", sql, switch_str_nil(err_str));
+			}
+			switch_safe_free(err_str);
+			status = SWITCH_STATUS_FALSE;
+		}
+		SQLFreeHandle(SQL_HANDLE_STMT, stmt);
+	} else {
+#endif
+		if (!(db = switch_core_db_open_file(globals.dbname))) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", globals.dbname);
+			status = SWITCH_STATUS_FALSE;
+			goto end;
+		}
+
+		err_str = NULL;
+		switch_core_db_exec(db, sql, NULL, NULL, &err_str);
+		if (err_str) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error [%s]\n[%s]\n", sql, err_str);
+			free(err_str);
+		}
+
+		switch_core_db_close(db);
+
+#ifdef SWITCH_HAVE_ODBC
+	}
+#endif
+
+  end:
+	if (mutex) {
+		switch_mutex_unlock(mutex);
+	}
+
+	return status;
+}
+
+static switch_bool_t fifo_execute_sql_callback(switch_mutex_t *mutex, char *sql, switch_core_db_callback_func_t callback, void *pdata)
+{
+	switch_bool_t ret = SWITCH_FALSE;
+	switch_core_db_t *db;
+	char *errmsg = NULL;
+
+	if (mutex) {
+		switch_mutex_lock(mutex);
+	}
+
+#ifdef SWITCH_HAVE_ODBC
+	if (globals.odbc_dsn) {
+		switch_odbc_handle_callback_exec(globals.master_odbc, sql, callback, pdata);
+	} else {
+#endif
+		if (!(db = switch_core_db_open_file(globals.dbname))) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", globals.dbname);
+			goto end;
+		}
+
+		switch_core_db_exec(db, sql, callback, pdata, &errmsg);
+
+		if (errmsg) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg);
+			free(errmsg);
+		}
+
+		if (db) {
+			switch_core_db_close(db);
+		}
+#ifdef SWITCH_HAVE_ODBC
+	}
+#endif
+
+  end:
+	if (mutex) {
+		switch_mutex_unlock(mutex);
+	}
+
+	return ret;
+}
+
 static fifo_node_t *create_node(const char *name, uint32_t importance)
 {
 	fifo_node_t *node;
@@ -255,20 +369,222 @@
 	}
 
 	node = switch_core_alloc(globals.pool, sizeof(*node));
-	node->name = switch_core_strdup(globals.pool, name);
+	node->pool = globals.pool;
+
+	node->name = switch_core_strdup(node->pool, name);
 	for (x = 0; x < MAX_PRI; x++) {
-		switch_queue_create(&node->fifo_list[x], SWITCH_CORE_QUEUE_LEN, globals.pool);
+		switch_queue_create(&node->fifo_list[x], SWITCH_CORE_QUEUE_LEN, node->pool);
 		switch_assert(node->fifo_list[x]);
 	}
-	switch_core_hash_init(&node->caller_hash, globals.pool);
-	switch_core_hash_init(&node->consumer_hash, globals.pool);
-
-	switch_mutex_init(&node->mutex, SWITCH_MUTEX_NESTED, globals.pool);
+	switch_core_hash_init(&node->caller_hash, node->pool);
+	switch_core_hash_init(&node->consumer_hash, node->pool);
+	switch_thread_rwlock_create(&node->rwlock, node->pool);
+	switch_mutex_init(&node->mutex, SWITCH_MUTEX_NESTED, node->pool);
+	node->importance = importance;
 	switch_core_hash_insert(globals.fifo_hash, name, node);
+	return node;
+}
 
-	node->importance = importance;
+static int node_idle_consumers(fifo_node_t *node)
+{
+	switch_hash_index_t *hi;
+	void *val;
+    const void *var;
+	switch_core_session_t *session;
+    switch_channel_t *channel;
+	int total = 0;
 
-	return node;
+	switch_mutex_lock(node->mutex);
+	for (hi = switch_hash_first(NULL, node->consumer_hash); hi; hi = switch_hash_next(hi)) {
+		switch_hash_this(hi, &var, NULL, &val);
+		session = (switch_core_session_t *) val;
+        channel = switch_core_session_get_channel(session);
+		if (!switch_channel_test_flag(channel, CF_BRIDGED)) {
+			total++;
+		}
+	}
+	switch_mutex_unlock(node->mutex);
+
+	return total;
+	
+}
+
+static switch_status_t hanguphook(switch_core_session_t *session)
+{
+	switch_channel_t *channel = switch_core_session_get_channel(session);
+	switch_channel_state_t state = switch_channel_get_state(channel);
+	const char *uuid = NULL;
+	char sql[256] = "";
+
+	if (state == CS_HANGUP || state == CS_ROUTING) {
+		if ((uuid = switch_channel_get_variable(channel, "fifo_outbound_uuid"))) {
+			switch_snprintf(sql, sizeof(sql), "update fifo_outbound set use_count=use_count-1, outbound_call_count=outbound_call_count+1, next_avail=%ld + lag where uuid='%s'", 
+							(long)switch_timestamp(NULL), uuid);
+							
+			fifo_execute_sql(sql, globals.sql_mutex);
+		}
+		switch_core_event_hook_remove_state_change(session, hanguphook);
+	}
+	return SWITCH_STATUS_SUCCESS;
+}
+
+struct call_helper {
+	char *uuid;
+	char *node_name;
+	char *originate_string;
+	int timeout;
+	switch_memory_pool_t *pool;
+};
+
+static void *SWITCH_THREAD_FUNC o_thread_run(switch_thread_t *thread, void *obj)
+{
+	struct call_helper *h = (struct call_helper *) obj;
+
+	switch_core_session_t *session = NULL;
+	switch_channel_t *channel;
+	switch_call_cause_t cause = SWITCH_CAUSE_NONE;
+	switch_caller_extension_t *extension = NULL;
+	char *app_name, *arg = NULL;
+	char sql[256] = "";
+
+	switch_snprintf(sql, sizeof(sql), "update fifo_outbound set use_count=use_count+1 where uuid='%s'", h->uuid);
+	fifo_execute_sql(sql, globals.sql_mutex);
+	
+	if (switch_ivr_originate(NULL, &session, &cause, h->originate_string, h->timeout, NULL, NULL, NULL, NULL, SOF_NONE) != SWITCH_STATUS_SUCCESS) {
+		switch_snprintf(sql, sizeof(sql), "update fifo_outbound set use_count=use_count-1, outbound_fail_count=outbound_fail_count+1, next_avail=%ld + lag where uuid='%s'", 
+						(long)switch_timestamp(NULL), h->uuid);
+		fifo_execute_sql(sql, globals.sql_mutex);
+		goto end;
+	}
+	
+
+	channel = switch_core_session_get_channel(session);
+	switch_channel_set_variable(channel, "fifo_outbound_uuid", h->uuid);
+	switch_core_event_hook_add_state_change(session, hanguphook);
+	app_name = "fifo";
+	arg = switch_core_session_sprintf(session, "%s out wait", h->node_name);
+	extension = switch_caller_extension_new(session, app_name, arg);
+	switch_caller_extension_add_application(session, extension, app_name, arg);
+	switch_channel_set_caller_extension(channel, extension);
+	switch_channel_set_state(channel, CS_EXECUTE);
+	switch_core_session_rwunlock(session);
+
+ end:
+
+	switch_core_destroy_memory_pool(&h->pool);
+
+	return NULL;
+}
+
+static int place_call_callback(void *pArg, int argc, char **argv, char **columnNames)
+{
+
+	int *need = (int *) pArg;
+
+	switch_thread_t *thread;
+	switch_threadattr_t *thd_attr = NULL;
+	switch_memory_pool_t *pool;
+	struct call_helper *h;
+	
+	switch_core_new_memory_pool(&pool);
+	h = switch_core_alloc(pool, sizeof(*h));
+	h->pool = pool;
+	h->uuid = switch_core_strdup(h->pool, argv[0]);
+	h->node_name = switch_core_strdup(h->pool, argv[1]);
+	h->originate_string = switch_core_strdup(h->pool, argv[2]);
+	h->timeout = atoi(argv[5]);
+
+
+	switch_threadattr_create(&thd_attr, h->pool);
+	switch_threadattr_detach_set(thd_attr, 1);
+	switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
+	switch_thread_create(&thread, thd_attr, o_thread_run, h, h->pool);
+
+	(*need)--;
+	
+	return *need ? 0 : -1;
+}
+
+static void find_consumers(fifo_node_t *node)
+{
+	int need = node_consumer_wait_count(node);
+	char *sql;
+
+	sql = switch_mprintf("select uuid, fifo_name, originate_string, simo_count, use_count, timeout, lag, "
+						 "next_avail, expires, static, outbound_call_count, outbound_fail_count, hostname "
+						 "from fifo_outbound where (use_count < simo_count) and (next_avail = 0 or next_avail <= %ld) order by outbound_call_count", 
+						 (long) switch_timestamp(NULL));
+	switch_assert(sql);
+	fifo_execute_sql_callback(globals.sql_mutex, sql, place_call_callback, &need);
+	free(sql);
+}
+
+static void *SWITCH_THREAD_FUNC node_thread_run(switch_thread_t *thread, void *obj)
+{
+	fifo_node_t *node;
+	
+	globals.node_thread_running = 1;
+
+	while(globals.node_thread_running == 1) {
+		switch_hash_index_t *hi;
+		void *val;
+		const void *var;
+		int ppl_waiting, consumer_total, idle_consumers;
+
+		switch_mutex_lock(globals.mutex);
+		for (hi = switch_hash_first(NULL, globals.fifo_hash); hi; hi = switch_hash_next(hi)) {
+			switch_hash_this(hi, &var, NULL, &val);
+			if ((node = (fifo_node_t *) val) && node->has_outbound && node->ready) {
+				switch_mutex_lock(node->mutex);
+				ppl_waiting = node_consumer_wait_count(node);
+				consumer_total = node->consumer_count;
+				idle_consumers = node_idle_consumers(node);
+
+				//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, 
+				//"%s waiting %d consumer_total %d idle_consumers %d\n", node->name, ppl_waiting, consumer_total, idle_consumers);
+		
+				if (ppl_waiting && (!consumer_total || !idle_consumers)) {
+					find_consumers(node);
+				}
+				switch_mutex_unlock(node->mutex);
+			}
+		}
+		switch_mutex_unlock(globals.mutex);
+
+		switch_yield(1000000);
+	}
+
+	globals.node_thread_running = 0;
+	
+	return NULL;
+}
+
+static void start_node_thread(switch_memory_pool_t *pool)
+{
+	switch_thread_t *thread;
+	switch_threadattr_t *thd_attr = NULL;
+
+	switch_threadattr_create(&thd_attr, pool);
+	switch_threadattr_detach_set(thd_attr, 1);
+	switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
+	switch_thread_create(&thread, thd_attr, node_thread_run, pool, pool);
+}
+
+static int stop_node_thread(void)
+{
+	int sanity = 20;
+
+	if (globals.node_thread_running) {
+		globals.node_thread_running = -1;
+		while(globals.node_thread_running) {
+			switch_yield(500000);
+			if (!--sanity) {
+				return -1;
+			}
+		}
+	}
+
+	return 0;
 }
 
 static void send_presence(fifo_node_t *node)
@@ -509,6 +825,14 @@
 			node->start_waiting = switch_timestamp_now();
 		}
 
+		if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) {
+			switch_channel_event_set_data(channel, event);
+			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", argv[0]);
+			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "push");
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Slot", "%d", p);
+			switch_event_fire(&event);
+		}
+		
 		switch_queue_push(node->fifo_list[p], (void *) strdup(uuid));
 
 		if (!pri) {
@@ -524,14 +848,6 @@
 		switch_channel_set_variable(channel, "fifo_status", "WAITING");
 		switch_channel_set_variable(channel, "fifo_timestamp", date);
 
-		if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) {
-			switch_channel_event_set_data(channel, event);
-			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", argv[0]);
-			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "push");
-			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Slot", "%d", p);
-			switch_event_fire(&event);
-		}
-
 		switch_channel_set_flag(channel, CF_TAGGED);
 
 		if (chime_list) {
@@ -610,6 +926,7 @@
 
 		if (!aborted && switch_channel_ready(channel)) {
 			switch_channel_set_state(channel, CS_HIBERNATE);
+			return;
 		} else {
 			ts = switch_timestamp_now();
 			switch_time_exp_lt(&tm, ts);
@@ -866,7 +1183,26 @@
 				}
 
 				if (!(switch_channel_ready(channel))) {
-					switch_channel_hangup(other_channel, SWITCH_CAUSE_NORMAL_CLEARING);
+					const char *app = switch_channel_get_variable(other_channel, "current_application");
+					const char *arg = switch_channel_get_variable(other_channel, "current_application_data");
+					switch_caller_extension_t *extension = NULL;
+					
+					switch_mutex_lock(node->mutex);
+					node->caller_count--;
+					switch_core_hash_delete(node->caller_hash, uuid);
+					switch_mutex_unlock(node->mutex);
+					send_presence(node);
+					
+
+					if (app) {
+						extension = switch_caller_extension_new(other_session, app, arg);
+						switch_caller_extension_add_application(other_session, extension, app, arg);
+						switch_channel_set_caller_extension(other_channel, extension);
+						switch_channel_set_state(other_channel, CS_EXECUTE);
+					} else {
+						switch_channel_hangup(other_channel, SWITCH_CAUSE_NORMAL_CLEARING);
+					}
+
 					switch_core_session_rwunlock(other_session);
 					break;
 				}
@@ -933,7 +1269,10 @@
 				sfifo_consumer_wrapup_time = switch_channel_get_variable(channel, "fifo_consumer_wrapup_time");
 				if (!switch_strlen_zero(sfifo_consumer_wrapup_time)){
 					fifo_consumer_wrapup_time = atoi(sfifo_consumer_wrapup_time);
+				} else {
+					fifo_consumer_wrapup_time = 5000;
 				}
+
 				memset(buf, 0, sizeof(buf));
 
 				if (fifo_consumer_wrapup_time || !switch_strlen_zero(fifo_consumer_wrapup_key)) {
@@ -976,7 +1315,7 @@
 						}
 
 					}
-				} else if (fifo_consumer_wrapup_time && !strcmp(buf, fifo_consumer_wrapup_key)) {
+				} else if (fifo_consumer_wrapup_time && (switch_strlen_zero(fifo_consumer_wrapup_key) || !strcmp(buf, fifo_consumer_wrapup_key))) {
 					while(switch_channel_ready(channel)) {
 						wrapup_time_elapsed = (switch_timestamp_now() - wrapup_time_started) / 1000;
 						if (wrapup_time_elapsed > fifo_consumer_wrapup_time) {
@@ -1025,6 +1364,68 @@
 	}
 }
 
+struct xml_helper {
+	switch_xml_t xml;
+	fifo_node_t *node;
+	char *container;
+	char *tag;
+	int cc_off;
+	int verbose;
+};
+
+static int xml_callback(void *pArg, int argc, char **argv, char **columnNames)
+{
+	struct xml_helper *h = (struct xml_helper *) pArg;
+	switch_xml_t x_tmp, x_out;
+	int c_off = 0;
+	char exp_buf[128] = "";
+	switch_time_exp_t tm;
+	switch_time_t etime = 0;
+	char *expires = exp_buf;
+
+	if (argv[7]) {
+		if ((etime = atol(argv[7]))) {
+			switch_size_t retsize;
+
+			switch_time_exp_lt(&tm, switch_time_from_sec(etime));
+			switch_strftime_nocheck(exp_buf, &retsize, sizeof(exp_buf), "%Y-%m-%d %T", &tm);
+		} else {
+			switch_set_string(exp_buf, "now");
+		}
+	}
+
+	x_tmp = switch_xml_add_child_d(h->xml, h->container, h->cc_off++);
+
+	x_out = switch_xml_add_child_d(x_tmp, h->tag, c_off++);
+	switch_xml_set_attr_d(x_out, "timeout", argv[5]);
+	switch_xml_set_attr_d(x_out, "simo", argv[3]);
+	switch_xml_set_attr_d(x_out, "lag", argv[6]);
+	switch_xml_set_attr_d(x_out, "outbound-call-count", argv[10]);
+	switch_xml_set_attr_d(x_out, "outbound-fail-count", argv[11]);
+	switch_xml_set_attr_d(x_out, "next-available", expires);
+	
+	switch_xml_set_txt_d(x_out, argv[2]);
+
+	return 0;
+}
+
+static int xml_outbound(switch_xml_t xml, fifo_node_t *node, char *container, char *tag, int cc_off, int verbose)
+{
+	struct xml_helper h;
+	char *sql = "select uuid, fifo_name, originate_string, simo_count, use_count, timeout, lag, next_avail, expires, static, outbound_call_count, outbound_fail_count, hostname from fifo_outbound";
+
+	h.xml = xml;
+	h.node = node;
+	h.container = container;
+	h.tag = tag;
+	h.cc_off = cc_off;
+	h.verbose = verbose;
+
+	fifo_execute_sql_callback(globals.sql_mutex, sql, xml_callback, &h);
+	
+	return h.cc_off;
+}
+
 static int xml_hash(switch_xml_t xml, switch_hash_t *hash, char *container, char *tag, int cc_off, int verbose)
 {
 	switch_xml_t x_tmp, x_caller, x_cp, variables;
@@ -1098,12 +1499,13 @@
 	switch_xml_set_attr_d(x_fifo, "waiting_count", tmp);
 	switch_snprintf(tmp, sizeof(buffer), "%u", node->importance);
 	switch_xml_set_attr_d(x_fifo, "importance", tmp);
-
+	
+	cc_off = xml_outbound(x_fifo, node, "outbound", "member", cc_off, verbose);
 	cc_off = xml_hash(x_fifo, node->caller_hash, "callers", "caller", cc_off, verbose);
 	cc_off = xml_hash(x_fifo, node->consumer_hash, "consumers", "consumer", cc_off, verbose);
 }
 
-#define FIFO_API_SYNTAX "list|list_verbose|count|importance [<fifo name>]"
+#define FIFO_API_SYNTAX "list|list_verbose|count|importance [<fifo name>]|reparse [del_all]"
 SWITCH_STANDARD_API(fifo_api_function)
 {
 	int len = 0;
@@ -1133,6 +1535,11 @@
 	switch_mutex_lock(globals.mutex);
 	verbose = !strcasecmp(argv[0], "list_verbose");
 
+	if (!strcasecmp(argv[0], "reparse")) {
+		load_config(1, argv[1] && !strcasecmp(argv[1], "del_all"));
+		goto done;
+	}
+
 	if (!strcasecmp(argv[0], "list") || verbose) {
 		char *xml_text = NULL;
 		switch_xml_t x_report = switch_xml_new("fifo_report");
@@ -1196,10 +1603,368 @@
 		} else {
 			stream->write_function(stream, "none\n");
 		}
+	} else {
+		stream->write_function(stream, "-ERR Usage: %s\n", FIFO_API_SYNTAX);
+	}
+
+ done:
+
+	switch_mutex_unlock(globals.mutex);
+	return SWITCH_STATUS_SUCCESS;
+}
+
+
+const char outbound_sql[] = 
+	"create table fifo_outbound (\n"
+	" uuid varchar(255),\n"
+	" fifo_name varchar(255),\n"
+	" originate_string varchar(255),\n"
+	" simo_count integer,\n"
+	" use_count integer,\n"
+	" timeout integer,\n"
+	" lag integer,\n"
+	" next_avail integer,\n"
+	" expires integer,\n"
+	" static integer,\n"
+	" outbound_call_count integer,"
+	" outbound_fail_count integer,"
+	" hostname varchar(255)\n"
+	");\n";
+
+
+static switch_status_t load_config(int reload, int del_all)
+{
+	char *cf = "fifo.conf";
+	switch_xml_t cfg, xml, fifo, fifos, member, settings, param;
+	char *odbc_user = NULL;
+	char *odbc_pass = NULL;
+	switch_core_db_t *db;
+	switch_status_t status = SWITCH_STATUS_SUCCESS;	
+	char *sql;
+
+	gethostname(globals.hostname, sizeof(globals.hostname));
+
+	if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", cf);
+		return SWITCH_STATUS_TERM;
+	}
+
+	if ((settings = switch_xml_child(cfg, "settings"))) {
+		for (param = switch_xml_child(settings, "param"); param; param = param->next) {
+			char *var = NULL;
+			char *val = NULL;
+
+			var = (char *) switch_xml_attr_soft(param, "name");
+			val = (char *) switch_xml_attr_soft(param, "value");
+
+			if (!strcasecmp(var, "odbc-dsn") && !switch_strlen_zero(val)) {
+#ifdef SWITCH_HAVE_ODBC
+				globals.odbc_dsn = switch_core_strdup(globals.pool, val);
+				if ((odbc_user = strchr(globals.odbc_dsn, ':'))) {
+					*odbc_user++ = '\0';
+					if ((odbc_pass = strchr(odbc_user, ':'))) {
+						*odbc_pass++ = '\0';
+					}
+				}
+#else
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n");
+#endif
+			}
+		}
+	}
+
+
+	if (switch_strlen_zero(globals.odbc_dsn) || switch_strlen_zero(odbc_user) || switch_strlen_zero(odbc_pass)) {
+		globals.dbname = "fifo";
+	}
+
+#ifdef SWITCH_HAVE_ODBC
+	if (globals.odbc_dsn) {
+		if (!(globals.master_odbc = switch_odbc_handle_new(globals.odbc_dsn, odbc_user, odbc_pass))) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open ODBC Database!\n");
+			status = SWITCH_STATUS_FALSE;
+			goto done;
+		}
+		if (switch_odbc_handle_connect(globals.master_odbc) != SWITCH_ODBC_SUCCESS) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open ODBC Database!\n");
+			status = SWITCH_STATUS_FALSE;
+			goto done;
+		}
+
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Connected ODBC DSN: %s\n", globals.odbc_dsn);
+		if (switch_odbc_handle_exec(globals.master_odbc, "delete from fifo_outbound", NULL) != SWITCH_STATUS_SUCCESS) {
+			if (switch_odbc_handle_exec(globals.master_odbc, (char *)outbound_sql, NULL) != SWITCH_STATUS_SUCCESS) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Create SQL Database!\n");
+			}
+		}
+	} else {
+#endif
+		if ((db = switch_core_db_open_file(globals.dbname))) {
+			switch_core_db_test_reactive(db, "delete from fifo_outbound", NULL, (char *)outbound_sql);
+		} else {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open SQL Database!\n");
+			status = SWITCH_STATUS_FALSE;
+			goto done;
+		}
+		switch_core_db_close(db);
+#ifdef SWITCH_HAVE_ODBC
+	}
+#endif
+
+	if (reload) {
+		switch_hash_index_t *hi;
+		fifo_node_t *node;
+		void *val;
+		for (hi = switch_hash_first(NULL, globals.fifo_hash); hi; hi = switch_hash_next(hi)) {
+			switch_hash_this(hi, NULL, NULL, &val);
+			if ((node = (fifo_node_t *) val)) {
+				node->ready = 0;
+			}
+		}
+	}
+
+	if (del_all) {
+		sql = switch_mprintf("delete from fifo_outbound where hostname='%q'", globals.hostname);
+	} else {
+		sql = switch_mprintf("delete from fifo_outbound where static=1 and hostname='%q'", globals.hostname);
+	}
+	
+	fifo_execute_sql(sql, globals.sql_mutex);
+	switch_safe_free(sql);
+
+
+
+	if ((fifos = switch_xml_child(cfg, "fifos"))) {
+		for (fifo = switch_xml_child(fifos, "fifo"); fifo; fifo = fifo->next) {
+			const char *name;
+			const char *importance;
+			int imp = 0;
+			int simo_i = 1;
+			int timeout_i = 60;
+			int lag_i = 10;
+			fifo_node_t *node;
+			
+			name = switch_xml_attr(fifo, "name");
+			
+			if ((importance = switch_xml_attr(fifo, "importance"))) {
+				if ((imp = atoi(importance)) < 0) {
+					imp = 0;
+				}
+			}				
+
+			if (!name) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "fifo has no name!\n");
+				continue;
+			}
+
+			switch_mutex_lock(globals.mutex);
+			if (!(node = switch_core_hash_find(globals.fifo_hash, name))) {
+				node = create_node(name, imp);
+			}
+			switch_mutex_unlock(globals.mutex);
+			
+			switch_assert(node);
+			
+			switch_mutex_lock(node->mutex);
+			
+			for (member = switch_xml_child(fifo, "member"); member; member = member->next) {
+				const char *simo = switch_xml_attr_soft(member, "simo");
+				const char *lag = switch_xml_attr_soft(member, "lag");
+				const char *timeout = switch_xml_attr_soft(member, "timeout");
+				char digest[SWITCH_MD5_DIGEST_STRING_SIZE] = { 0 };
+				switch_md5_string(digest, (void *) member->txt, strlen(member->txt));
+
+				if (simo) {
+					simo_i = atoi(simo);
+				}
+
+				if (timeout) {
+					if ((timeout_i = atoi(timeout)) < 10) {
+						timeout_i = 60;
+					}
+
+				}
+
+				if (lag) {
+					if ((lag_i = atoi(lag)) < 0) {
+						lag_i = 10;
+					}
+				}
+				
+				
+				sql = switch_mprintf("insert into fifo_outbound "
+									 "(uuid, fifo_name, originate_string, simo_count, use_count, timeout, lag, "
+									 "next_avail, expires, static, outbound_call_count, outbound_fail_count, hostname) "
+									 "values ('%q','%q','%q',%d,%d,%d,%d,0,0,1,0,0,'%q')",
+									 digest, node->name, member->txt, simo_i, 0, timeout_i, lag_i, globals.hostname
+									 );
+				switch_assert(sql);
+				fifo_execute_sql(sql, globals.sql_mutex);
+				free(sql);
+				
+				node->has_outbound = 1;
+				
+			}
+			node->ready = 1;
+			switch_mutex_unlock(node->mutex);
+			
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s configured\n", node->name);
+		
+		}
+	}
+	switch_xml_free(xml);
+
+ done:
+
+	if (reload) {
+		switch_hash_index_t *hi;
+		void *val, *pop;
+		fifo_node_t *node;
+		for (hi = switch_hash_first(NULL, globals.fifo_hash); hi; hi = switch_hash_next(hi)) {
+			int x = 0;
+			switch_hash_this(hi, NULL, NULL, &val);
+			if (!(node = (fifo_node_t *) val) || node->ready) {
+				continue;
+			}
+
+
+			if (node_consumer_wait_count(node) || node->consumer_count || node_idle_consumers(node)) {
+				node->ready = 1;
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "%s not removed, still in use.\n", node->name);
+			} else {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "%s removed.\n", node->name);
+				switch_thread_rwlock_wrlock(node->rwlock);
+				for (x = 0; x < MAX_PRI; x++) {
+					while (switch_queue_trypop(node->fifo_list[x], &pop) == SWITCH_STATUS_SUCCESS) {
+						free(pop);
+					}
+				}
+			
+				switch_core_hash_destroy(&node->caller_hash);
+				switch_core_hash_destroy(&node->consumer_hash);
+				switch_thread_rwlock_unlock(node->rwlock);
+			}
+		}
 	}
 
+
+
+	return status;
+}
+
+
+static void fifo_member_add(char *fifo_name, char *originate_string, int simo_count, int timeout, int lag, time_t expires)
+{
+	char digest[SWITCH_MD5_DIGEST_STRING_SIZE] = { 0 };
+	char *sql;
+	fifo_node_t *node = NULL;
+	
+	switch_md5_string(digest, (void *) originate_string, strlen(originate_string));
+	
+	sql = switch_mprintf("delete from fifo_outbound where fifo_name='%q' and uuid = '%q'", fifo_name, digest);
+	switch_assert(sql);
+    fifo_execute_sql(sql, globals.sql_mutex);
+    free(sql);
+	
+	
+	switch_mutex_lock(globals.mutex);
+	if (!(node = switch_core_hash_find(globals.fifo_hash, fifo_name))) {
+		node = create_node(fifo_name, 0);
+	}
 	switch_mutex_unlock(globals.mutex);
+
+	node->has_outbound = 1;	
+
+	sql = switch_mprintf("insert into fifo_outbound "
+						 "(uuid, fifo_name, originate_string, simo_count, use_count, timeout, lag, next_avail, expires, static, outbound_call_count, outbound_fail_count, hostname) "
+						 "values ('%q','%q','%q',%d,%d,%d,%d,%d,%ld,0,0,0,'%q')",
+						 digest, fifo_name, originate_string, simo_count, 0, timeout, lag, 0, (long)expires, globals.hostname
+						 );
+	switch_assert(sql);
+	fifo_execute_sql(sql, globals.sql_mutex);
+	free(sql);
+	
+}
+
+static void fifo_member_del(char *fifo_name, char *originate_string)
+{
+	char digest[SWITCH_MD5_DIGEST_STRING_SIZE] = { 0 };
+	char *sql;
+
+	switch_md5_string(digest, (void *) originate_string, strlen(originate_string));
+	
+	sql = switch_mprintf("delete from fifo_outbound where fifo_name='%q' and uuid = '%q' and hostname='%q'", fifo_name, digest, globals.hostname);
+	switch_assert(sql);
+    fifo_execute_sql(sql, globals.sql_mutex);
+    free(sql);
+}
+
+#define FIFO_MEMBER_API_SYNTAX "[add <fifo_name> <originate_string> [<simo_count>] [<timeout>] [<lag>] | del <fifo_name> <originate_string>]"
+SWITCH_STANDARD_API(fifo_member_api_function)
+{
+	char *fifo_name;
+	char *originate_string;
+	int simo_count = 1;
+	int timeout = 60;
+	int lag = 5;
+	char *action;
+	char *mydata = NULL, *argv[8] = { 0 };
+	int argc;
+	time_t expires = 0;
+
+	mydata = strdup(cmd);
+	switch_assert(mydata);
+
+	argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
+
+	if (argc < 3) {
+		stream->write_function(stream, "%s", "-ERR Invalid!\n");
+		goto done;
+	}
+	
+	action = argv[0];
+	fifo_name = argv[1];
+	originate_string = argv[2];
+	
+	if (action && !strcasecmp(action, "add")) {
+		if (argc > 3) {
+			simo_count = atoi(argv[3]);
+		}
+		if (argc > 4) {
+			timeout = atoi(argv[4]);
+		}
+		if (argc > 5) {
+			lag = atoi(argv[5]);
+		}
+		if (argc > 6) {
+			expires = switch_timestamp(NULL) + atoi(argv[6]);
+		}
+		if (simo_count < 0) {
+			simo_count = 1;
+		}
+		if (timeout < 0) {
+			timeout = 60;
+		}
+		if (lag < 0) {
+			lag = 5;
+		}
+		
+		fifo_member_add(fifo_name, originate_string, simo_count, timeout, lag, expires);
+		stream->write_function(stream, "%s", "+OK\n");
+	} else if (action && !strcasecmp(action, "del")) {
+		fifo_member_del(fifo_name, originate_string);
+		stream->write_function(stream, "%s", "+OK\n");
+	} else {
+		stream->write_function(stream, "%s", "-ERR Invalid!\n");
+        goto done;
+	}
+
+ done:
+
+	free(mydata);
+
 	return SWITCH_STATUS_SUCCESS;
+
 }
 
 SWITCH_MODULE_LOAD_FUNCTION(mod_fifo_load)
@@ -1223,11 +1988,13 @@
 	switch_core_new_memory_pool(&globals.pool);
 	switch_core_hash_init(&globals.fifo_hash, globals.pool);
 	switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, globals.pool);
+	switch_mutex_init(&globals.sql_mutex, SWITCH_MUTEX_NESTED, globals.pool);
 
 	/* connect my internal structure to the blank pointer passed to me */
 	*module_interface = switch_loadable_module_create_module_interface(pool, modname);
 	SWITCH_ADD_APP(app_interface, "fifo", "Park with FIFO", FIFO_DESC, fifo_function, FIFO_USAGE, SAF_NONE);
 	SWITCH_ADD_API(commands_api_interface, "fifo", "Return data about a fifo", fifo_api_function, FIFO_API_SYNTAX);
+	SWITCH_ADD_API(commands_api_interface, "fifo_member", "Add members to a fifo", fifo_member_api_function, FIFO_MEMBER_API_SYNTAX);
 	switch_console_set_complete("add fifo list");
 	switch_console_set_complete("add fifo list_verbose");
 	switch_console_set_complete("add fifo count");
@@ -1235,6 +2002,9 @@
 
 	globals.running = 1;
 
+	load_config(0,1);
+	start_node_thread(globals.pool);
+
 	return SWITCH_STATUS_SUCCESS;
 }
 
@@ -1256,10 +2026,18 @@
 
 	globals.running = 0;
 	/* Cleanup */
+	
+	if (globals.node_thread_running) {
+		stop_node_thread();
+	}
+		
+
 	for (hi = switch_hash_first(NULL, globals.fifo_hash); hi; hi = switch_hash_next(hi)) {
 		int x = 0;
 		switch_hash_this(hi, NULL, NULL, &val);
 		node = (fifo_node_t *) val;
+		
+		switch_thread_rwlock_wrlock(node->rwlock);
 		for (x = 0; x < MAX_PRI; x++) {
 			while (switch_queue_trypop(node->fifo_list[x], &pop) == SWITCH_STATUS_SUCCESS) {
 				free(pop);
@@ -1268,6 +2046,7 @@
 
 		switch_core_hash_destroy(&node->caller_hash);
 		switch_core_hash_destroy(&node->consumer_hash);
+		switch_thread_rwlock_unlock(node->rwlock);
 	}
 	switch_core_hash_destroy(&globals.fifo_hash);
 	memset(&globals, 0, sizeof(globals));

Modified: freeswitch/branches/gmaruzz/src/mod/applications/mod_fsv/mod_fsv.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/applications/mod_fsv/mod_fsv.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/applications/mod_fsv/mod_fsv.c	Mon Nov 17 14:18:32 2008
@@ -203,7 +203,7 @@
 
 	if (eh.up) {
 		while (eh.up) {
-			switch_yield(1000);
+			switch_cond_next();
 		}
 	}
 
@@ -320,7 +320,7 @@
 				switch_core_session_write_video_frame(session, &vid_frame, SWITCH_IO_FLAG_NONE, 0);
 			}
 			if (ts && last && last != ts) {
-				switch_yield(1000);
+				switch_cond_next();
 			}
 			last = ts;
 		} else {

Modified: freeswitch/branches/gmaruzz/src/mod/applications/mod_limit/mod_limit.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/applications/mod_limit/mod_limit.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/applications/mod_limit/mod_limit.c	Mon Nov 17 14:18:32 2008
@@ -258,8 +258,8 @@
 	if (state == CS_HANGUP || state == CS_ROUTING) {
 		id = switch_channel_get_variable(channel, "limit_id");
 		realm = switch_channel_get_variable(channel, "limit_realm");
-		sql = switch_mprintf("delete from limit_data where uuid='%q' and hostname='%q' and realm='%q'and id='%q';",
-							 switch_core_session_get_uuid(session), globals.hostname, realm, id);
+		sql = switch_mprintf("delete from limit_data where uuid='%q'",
+							 switch_core_session_get_uuid(session));
 		limit_execute_sql(sql, globals.mutex);
 		switch_safe_free(sql);
 		switch_core_event_hook_remove_state_change(session, hanguphook);
@@ -547,7 +547,7 @@
 	id = argv[1];
 	max = atoi(argv[2]);
 
-	if (argc == 4) {
+	if (argc >= 4) {
 		xfer_exten = argv[3];
 	} else {
 		xfer_exten = limit_def_xfer_exten;
@@ -568,7 +568,7 @@
 	got = atoi(buf);
 
 	if (got + 1 > max) {
-		switch_ivr_session_transfer(session, xfer_exten, NULL, NULL);
+		switch_ivr_session_transfer(session, xfer_exten, argv[4], argv[5]);
 		goto done;
 	}
 

Modified: freeswitch/branches/gmaruzz/src/mod/applications/mod_skel/mod_skel.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/applications/mod_skel/mod_skel.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/applications/mod_skel/mod_skel.c	Mon Nov 17 14:18:32 2008
@@ -64,7 +64,7 @@
 {
 	while(looping)
 	{
-		switch_yield(1000);
+		switch_cond_next();
 	}
 	return SWITCH_STATUS_TERM;
 }

Modified: freeswitch/branches/gmaruzz/src/mod/applications/mod_voicemail/mod_voicemail.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/applications/mod_voicemail/mod_voicemail.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/applications/mod_voicemail/mod_voicemail.c	Mon Nov 17 14:18:32 2008
@@ -2090,7 +2090,7 @@
 						if (!switch_strlen_zero(vm_storage_dir)) {
 							dir_path = switch_core_session_sprintf(session, "%s%s%s", vm_storage_dir, SWITCH_PATH_SEPARATOR, myid);
 						} else if ( !switch_strlen_zero(profile->storage_dir) ) {
-							dir_path = switch_core_session_sprintf(session, "%s%s%s", profile->storage_dir, SWITCH_PATH_SEPARATOR, myid);
+							dir_path = switch_core_session_sprintf(session, "%s%s%s%s%s", profile->storage_dir, SWITCH_PATH_SEPARATOR, domain_name, SWITCH_PATH_SEPARATOR, myid);
 						} else {
 							dir_path = switch_core_session_sprintf(session, "%s%svoicemail%s%s%s%s%s%s", SWITCH_GLOBAL_dirs.storage_dir,
 																   SWITCH_PATH_SEPARATOR,
@@ -2244,7 +2244,7 @@
 	if (!switch_strlen_zero(vm_storage_dir)) {
 		dir_path = switch_mprintf("%s%s%s", vm_storage_dir, SWITCH_PATH_SEPARATOR, myid);
 	} else if (!switch_strlen_zero(profile->storage_dir)) {
-		dir_path = switch_mprintf("%s%s%s", profile->storage_dir, SWITCH_PATH_SEPARATOR, myid);
+		dir_path = switch_mprintf("%s%s%s%s%s", profile->storage_dir, SWITCH_PATH_SEPARATOR, domain_name, SWITCH_PATH_SEPARATOR, myid);
 	} else {
 		dir_path = switch_mprintf("%s%svoicemail%s%s%s%s%s%s", SWITCH_GLOBAL_dirs.storage_dir,
 								  SWITCH_PATH_SEPARATOR,
@@ -2724,7 +2724,7 @@
 	if (!switch_strlen_zero(vm_storage_dir)) {
 		dir_path = switch_core_session_sprintf(session, "%s%s%s", vm_storage_dir, SWITCH_PATH_SEPARATOR, id);
 	} else if (!switch_strlen_zero(profile->storage_dir)) {
-		dir_path = switch_core_session_sprintf(session, "%s%s%s", profile->storage_dir, SWITCH_PATH_SEPARATOR, id);
+		dir_path = switch_core_session_sprintf(session, "%s%s%s%s%s", profile->storage_dir, SWITCH_PATH_SEPARATOR, domain_name, SWITCH_PATH_SEPARATOR, id);
 	} else {
 		dir_path = switch_core_session_sprintf(session, "%s%svoicemail%s%s%s%s%s%s", SWITCH_GLOBAL_dirs.storage_dir,
 											   SWITCH_PATH_SEPARATOR,

Modified: freeswitch/branches/gmaruzz/src/mod/asr_tts/mod_cepstral/mod_cepstral.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/asr_tts/mod_cepstral/mod_cepstral.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/asr_tts/mod_cepstral/mod_cepstral.c	Mon Nov 17 14:18:32 2008
@@ -52,7 +52,7 @@
 #define SWIFT_FAILED(r) ((void *)(r) < (void *)0)
 
 SWITCH_MODULE_LOAD_FUNCTION(mod_cepstral_load);
-SWITCH_MODULE_DEFINITION(mod_cepstral, mod_cepstral_load, NULL, NULL);
+SWITCH_MODULE_DEFINITION_EX(mod_cepstral, mod_cepstral_load, NULL, NULL, SMODF_GLOBAL_SYMBOLS);
 
 static swift_engine *engine;
 
@@ -302,7 +302,7 @@
 				status = SWITCH_STATUS_SUCCESS;
 				break;
 			}
-			switch_yield(1000);
+			switch_cond_next();
 			continue;
 		}
 

Modified: freeswitch/branches/gmaruzz/src/mod/codecs/mod_speex/mod_speex.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/codecs/mod_speex/mod_speex.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/codecs/mod_speex/mod_speex.c	Mon Nov 17 14:18:32 2008
@@ -264,7 +264,7 @@
 SWITCH_MODULE_LOAD_FUNCTION(mod_speex_load)
 {
 	switch_codec_interface_t *codec_interface;
-	int mpf = 20000, spf = 160, bpf = 320, ebpf = 0, rate = 8000, counta, countb;
+	int mpf = 20000, spf = 160, bpf = 320, rate = 8000, counta, countb;
 	switch_payload_t ianacode[4] = { 0, 98, 99, 103 };
 	int bps[4] = { 0, 24600, 42200, 44000 };
 	/* connect my internal structure to the blank pointer passed to me */
@@ -272,15 +272,29 @@
 	SWITCH_ADD_CODEC(codec_interface, "Speex");
 	for (counta = 1; counta <= 3; counta++) {
 		for (countb = 1; countb > 0; countb--) {
-			switch_core_codec_add_implementation(pool, codec_interface,
-												 SWITCH_CODEC_TYPE_AUDIO, ianacode[counta], "SPEEX", NULL, rate, rate, bps[counta],
-												 mpf * countb, spf * countb, bpf * countb, ebpf * countb, 1, 1,
-												 switch_speex_init, switch_speex_encode, switch_speex_decode, switch_speex_destroy);
+			switch_core_codec_add_implementation(pool,
+												 codec_interface,
+												 SWITCH_CODEC_TYPE_AUDIO,	/* enumeration defining the type of the codec */
+												 ianacode[counta],			/* the IANA code number */
+												 "SPEEX",					/* the IANA code name */
+												 NULL,						/* default fmtp to send (can be overridden by the init function) */
+												 rate,						/* samples transferred per second */
+												 rate,						/* actual samples transferred per second */
+												 bps[counta],				/* bits transferred per second */
+												 mpf * countb,				/* number of microseconds per frame */
+												 spf * countb,				/* number of samples per frame */
+												 bpf * countb,				/* number of bytes per frame decompressed */
+												 0,							/* number of bytes per frame compressed */
+												 1,							/* number of channels represented */
+												 1,							/* number of frames per network packet */
+												 switch_speex_init,			/* function to initialize a codec handle using this implementation */
+												 switch_speex_encode,		/* function to encode raw data into encoded data */
+												 switch_speex_decode,		/* function to decode encoded data into raw data */
+												 switch_speex_destroy);		/* deinitalize a codec handle using this implementation */
 		}
 		rate = rate * 2;
 		spf = spf * 2;
 		bpf = bpf * 2;
-		ebpf = ebpf * 2;
 	}
 
 

Modified: freeswitch/branches/gmaruzz/src/mod/codecs/mod_voipcodecs/mod_voipcodecs.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/codecs/mod_voipcodecs/mod_voipcodecs.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/codecs/mod_voipcodecs/mod_voipcodecs.c	Mon Nov 17 14:18:32 2008
@@ -567,95 +567,240 @@
 	mpf = 10000, spf = 80, bpf = 160, ebpf = 80;
 	SWITCH_ADD_CODEC(codec_interface, "ADPCM (IMA)");
 	for (count = 12; count > 0; count--) {
-		switch_core_codec_add_implementation(pool, codec_interface,
-											 SWITCH_CODEC_TYPE_AUDIO, 5, "DVI4", NULL, 8000, 8000, 32000,
-											 mpf * count, spf * count, bpf * count, (ebpf * count) + 4, 1, spf * count,
-											 switch_adpcm_init, switch_adpcm_encode, switch_adpcm_decode, switch_adpcm_destroy);
+		switch_core_codec_add_implementation(pool,
+											 codec_interface,
+											 SWITCH_CODEC_TYPE_AUDIO,	/* enumeration defining the type of the codec */
+											 5,							/* the IANA code number */
+											 "DVI4",					/* the IANA code name */
+											 NULL,						/* default fmtp to send (can be overridden by the init function) */
+											 8000,						/* samples transferred per second */
+											 8000,						/* actual samples transferred per second */
+											 32000,						/* bits transferred per second */
+											 mpf * count,				/* number of microseconds per frame */
+											 spf * count,				/* number of samples per frame */
+											 bpf * count,				/* number of bytes per frame decompressed */
+											 (ebpf * count) + 4,		/* number of bytes per frame compressed */
+											 1,							/* number of channels represented */
+											 spf * count,				/* number of frames per network packet */
+											 switch_adpcm_init,			/* function to initialize a codec handle using this implementation */
+											 switch_adpcm_encode,		/* function to encode raw data into encoded data */
+											 switch_adpcm_decode,		/* function to decode encoded data into raw data */
+											 switch_adpcm_destroy);		/* deinitalize a codec handle using this implementation */
 	}
 	mpf = 10000, spf = 160, bpf = 320, ebpf = 160;
 	for (count = 12; count > 0; count--) {
-		switch_core_codec_add_implementation(pool, codec_interface,
-											 SWITCH_CODEC_TYPE_AUDIO, 6, "DVI4", NULL, 16000, 16000, 64000,
-											 mpf * count, spf * count, bpf * count, (ebpf * count) + 4, 1, spf * count,
-											 switch_adpcm_init, switch_adpcm_encode, switch_adpcm_decode, switch_adpcm_destroy);
+		switch_core_codec_add_implementation(pool,
+											 codec_interface,
+											 SWITCH_CODEC_TYPE_AUDIO,	/* enumeration defining the type of the codec */
+											 6,							/* the IANA code number */
+											 "DVI4",					/* the IANA code name */
+											 NULL,						/* default fmtp to send (can be overridden by the init function) */
+											 16000,						/* samples transferred per second */
+											 16000,						/* actual samples transferred per second */
+											 64000,						/* bits transferred per second */
+											 mpf * count,				/* number of microseconds per frame */
+											 spf * count,				/* number of samples per frame */
+											 bpf * count,				/* number of bytes per frame decompressed */
+											 (ebpf * count) + 4,		/* number of bytes per frame compressed */
+											 1,							/* number of channels represented */
+											 spf * count,				/* number of frames per network packet */
+											 switch_adpcm_init,			/* function to initialize a codec handle using this implementation */
+											 switch_adpcm_encode,		/* function to encode raw data into encoded data */
+											 switch_adpcm_decode,		/* function to decode encoded data into raw data */
+											 switch_adpcm_destroy);		/* deinitalize a codec handle using this implementation */
 	}
 
 	/* G726 */
 	mpf = 10000, spf = 80, bpf = 160, ebpf = 20;
 	SWITCH_ADD_CODEC(codec_interface, "G.726 16k (AAL2)");
 	for (count = 12; count > 0; count--) {
-		switch_core_codec_add_implementation(pool, codec_interface,
-											 SWITCH_CODEC_TYPE_AUDIO, 124, "AAL2-G726-16", NULL, 8000, 8000, 16000,
-											 mpf * count, spf * count, bpf * count, ebpf * count, 1, count * 10,
-											 switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
+		switch_core_codec_add_implementation(pool,
+											 codec_interface,
+											 SWITCH_CODEC_TYPE_AUDIO,	/* enumeration defining the type of the codec */
+											 124,						/* the IANA code number */
+											 "AAL2-G726-16",			/* the IANA code name */
+											 NULL,						/* default fmtp to send (can be overridden by the init function) */
+											 8000,						/* samples transferred per second */
+											 8000,						/* actual samples transferred per second */
+											 16000,						/* bits transferred per second */
+											 mpf * count,				/* number of microseconds per frame */
+											 spf * count,				/* number of samples per frame */
+											 bpf * count,				/* number of bytes per frame decompressed */
+											 ebpf * count,				/* number of bytes per frame compressed */
+											 1,							/* number of channels represented */
+											 count * 10,				/* number of frames per network packet */
+											 switch_g726_init,			/* function to initialize a codec handle using this implementation */
+											 switch_g726_encode,		/* function to encode raw data into encoded data */
+											 switch_g726_decode,		/* function to decode encoded data into raw data */
+											 switch_g726_destroy);		/* deinitalize a codec handle using this implementation */
 	}
 	SWITCH_ADD_CODEC(codec_interface, "G.726 16k");
 	for (count = 12; count > 0; count--) {
-		switch_core_codec_add_implementation(pool, codec_interface,
-											 SWITCH_CODEC_TYPE_AUDIO, 127, "G726-16", NULL, 8000, 8000, 16000,
-											 mpf * count, spf * count, bpf * count, ebpf * count, 1, count * 10,
-											 switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
+		switch_core_codec_add_implementation(pool,
+											 codec_interface,
+											 SWITCH_CODEC_TYPE_AUDIO,	/* enumeration defining the type of the codec */
+											 127,						/* the IANA code number */
+											 "G726-16",					/* the IANA code name */
+											 NULL,						/* default fmtp to send (can be overridden by the init function) */
+											 8000,						/* samples transferred per second */
+											 8000,						/* actual samples transferred per second */
+											 16000,						/* bits transferred per second */
+											 mpf * count,				/* number of microseconds per frame */
+											 spf * count,				/* number of samples per frame */
+											 bpf * count,				/* number of bytes per frame decompressed */
+											 ebpf * count,				/* number of bytes per frame compressed */
+											 1,							/* number of channels represented */
+											 count * 10,				/* number of frames per network packet */
+											 switch_g726_init,			/* function to initialize a codec handle using this implementation */
+											 switch_g726_encode,		/* function to encode raw data into encoded data */
+											 switch_g726_decode,		/* function to decode encoded data into raw data */
+											 switch_g726_destroy);		/* deinitalize a codec handle using this implementation */
 	}
 	/* Increase encoded bytes per frame by 10 */
 	ebpf = ebpf + 10;
 
 	SWITCH_ADD_CODEC(codec_interface, "G.726 24k (AAL2)");
 	for (count = 12; count > 0; count--) {
-		switch_core_codec_add_implementation(pool, codec_interface,
-											 SWITCH_CODEC_TYPE_AUDIO, 123, "AAL2-G726-24", NULL, 8000, 8000, 24000,
-											 mpf * count, spf * count, bpf * count, ebpf * count, 1, count * 10,
-											 switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
+		switch_core_codec_add_implementation(pool,
+											 codec_interface,
+											 SWITCH_CODEC_TYPE_AUDIO,	/* enumeration defining the type of the codec */
+											 123,						/* the IANA code number */
+											 "AAL2-G726-24",			/* the IANA code name */
+											 NULL,						/* default fmtp to send (can be overridden by the init function) */
+											 8000,						/* samples transferred per second */
+											 8000,						/* actual samples transferred per second */
+											 24000,						/* bits transferred per second */
+											 mpf * count,				/* number of microseconds per frame */
+											 spf * count,				/* number of samples per frame */
+											 bpf * count,				/* number of bytes per frame decompressed */
+											 ebpf * count,				/* number of bytes per frame compressed */
+											 1,							/* number of channels represented */
+											 count * 10,				/* number of frames per network packet */
+											 switch_g726_init,			/* function to initialize a codec handle using this implementation */
+											 switch_g726_encode,		/* function to encode raw data into encoded data */
+											 switch_g726_decode,		/* function to decode encoded data into raw data */
+											 switch_g726_destroy);		/* deinitalize a codec handle using this implementation */
 	}
 	SWITCH_ADD_CODEC(codec_interface, "G.726 24k");
 	for (count = 12; count > 0; count--) {
-		switch_core_codec_add_implementation(pool, codec_interface,
-											 SWITCH_CODEC_TYPE_AUDIO, 126, "G726-24", NULL, 8000, 8000, 24000,
-											 mpf * count, spf * count, bpf * count, ebpf * count, 1, count * 10,
-											 switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
 	}
 	/* Increase encoded bytes per frame by 10 */
 	ebpf = ebpf + 10;
 
 	SWITCH_ADD_CODEC(codec_interface, "G.726 32k (AAL2)");
 	for (count = 12; count > 0; count--) {
-		switch_core_codec_add_implementation(pool, codec_interface,
-											 SWITCH_CODEC_TYPE_AUDIO, 2, "AAL2-G726-32", NULL, 8000, 8000, 32000,
-											 mpf * count, spf * count, bpf * count, ebpf * count, 1, count * 10,
-											 switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
+		switch_core_codec_add_implementation(pool,
+											 codec_interface,
+											 SWITCH_CODEC_TYPE_AUDIO,	/* enumeration defining the type of the codec */
+											 2,							/* the IANA code number */
+											 "AAL2-G726-32",			/* the IANA code name */
+											 NULL,						/* default fmtp to send (can be overridden by the init function) */
+											 8000,						/* samples transferred per second */
+											 8000,						/* actual samples transferred per second */
+											 32000,						/* bits transferred per second */
+											 mpf * count,				/* number of microseconds per frame */
+											 spf * count,				/* number of samples per frame */
+											 bpf * count,				/* number of bytes per frame decompressed */
+											 ebpf * count,				/* number of bytes per frame compressed */
+											 1,							/* number of channels represented */
+											 count * 10,				/* number of frames per network packet */
+											 switch_g726_init,			/* function to initialize a codec handle using this implementation */
+											 switch_g726_encode,		/* function to encode raw data into encoded data */
+											 switch_g726_decode,		/* function to decode encoded data into raw data */
+											 switch_g726_destroy);		/* deinitalize a codec handle using this implementation */
 	}
 	SWITCH_ADD_CODEC(codec_interface, "G.726 32k");
 	for (count = 12; count > 0; count--) {
-		switch_core_codec_add_implementation(pool, codec_interface,
-											 SWITCH_CODEC_TYPE_AUDIO, 2, "G726-32", NULL, 8000, 8000, 32000,
-											 mpf * count, spf * count, bpf * count, ebpf * count, 1, count * 10,
-											 switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
+		switch_core_codec_add_implementation(pool,
+											 codec_interface,
+											 SWITCH_CODEC_TYPE_AUDIO,	/* enumeration defining the type of the codec */
+											 2,							/* the IANA code number */
+											 "G726-32",					/* the IANA code name */
+											 NULL,						/* default fmtp to send (can be overridden by the init function) */
+											 8000,						/* samples transferred per second */
+											 8000,						/* actual samples transferred per second */
+											 32000,						/* bits transferred per second */
+											 mpf * count,				/* number of microseconds per frame */
+											 spf * count,				/* number of samples per frame */
+											 bpf * count,				/* number of bytes per frame decompressed */
+											 ebpf * count,				/* number of bytes per frame compressed */
+											 1,							/* number of channels represented */
+											 count * 10,				/* number of frames per network packet */
+											 switch_g726_init,			/* function to initialize a codec handle using this implementation */
+											 switch_g726_encode,		/* function to encode raw data into encoded data */
+											 switch_g726_decode,		/* function to decode encoded data into raw data */
+											 switch_g726_destroy);		/* deinitalize a codec handle using this implementation */
 	}
 	/* Increase encoded bytes per frame by 10 */
 	ebpf = ebpf + 10;
 
 	SWITCH_ADD_CODEC(codec_interface, "G.726 40k (AAL2)");
 	for (count = 12; count > 0; count--) {
-		switch_core_codec_add_implementation(pool, codec_interface,
-											 SWITCH_CODEC_TYPE_AUDIO, 122, "AAL2-G726-40", NULL, 8000, 8000, 40000,
-											 mpf * count, spf * count, bpf * count, ebpf * count, 1, count * 10,
-											 switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
+		switch_core_codec_add_implementation(pool,
+											 codec_interface,
+											 SWITCH_CODEC_TYPE_AUDIO,	/* enumeration defining the type of the codec */
+											 122,						/* the IANA code number */
+											 "AAL2-G726-40",			/* the IANA code name */
+											 NULL,						/* default fmtp to send (can be overridden by the init function) */
+											 8000,						/* samples transferred per second */
+											 8000,						/* actual samples transferred per second */
+											 40000,						/* bits transferred per second */
+											 mpf * count,				/* number of microseconds per frame */
+											 spf * count,				/* number of samples per frame */
+											 bpf * count,				/* number of bytes per frame decompressed */
+											 ebpf * count,				/* number of bytes per frame compressed */
+											 1,							/* number of channels represented */
+											 count * 10,				/* number of frames per network packet */
+											 switch_g726_init,			/* function to initialize a codec handle using this implementation */
+											 switch_g726_encode,		/* function to encode raw data into encoded data */
+											 switch_g726_decode,		/* function to decode encoded data into raw data */
+											 switch_g726_destroy);		/* deinitalize a codec handle using this implementation */
 	}
 	SWITCH_ADD_CODEC(codec_interface, "G.726 40k");
 	for (count = 12; count > 0; count--) {
-		switch_core_codec_add_implementation(pool, codec_interface,
-											 SWITCH_CODEC_TYPE_AUDIO, 125, "G726-40", NULL, 8000, 8000, 40000,
-											 mpf * count, spf * count, bpf * count, ebpf * count, 1, count * 10,
-											 switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
+		switch_core_codec_add_implementation(pool,
+											 codec_interface,
+											 SWITCH_CODEC_TYPE_AUDIO,	/* enumeration defining the type of the codec */
+											 125,						/* the IANA code number */
+											 "G726-40",					/* the IANA code name */
+											 NULL,						/* default fmtp to send (can be overridden by the init function) */
+											 8000,						/* samples transferred per second */
+											 8000,						/* actual samples transferred per second */
+											 40000,						/* bits transferred per second */
+											 mpf * count,				/* number of microseconds per frame */
+											 spf * count,				/* number of samples per frame */
+											 bpf * count,				/* number of bytes per frame decompressed */
+											 ebpf * count,				/* number of bytes per frame compressed */
+											 1,							/* number of channels represented */
+											 count * 10,				/* number of frames per network packet */
+											 switch_g726_init,			/* function to initialize a codec handle using this implementation */
+											 switch_g726_encode,		/* function to encode raw data into encoded data */
+											 switch_g726_decode,		/* function to decode encoded data into raw data */
+											 switch_g726_destroy);		/* deinitalize a codec handle using this implementation */
 	}
-
 	/* G722 */
 	mpf = 10000, spf = 80, bpf = 320, ebpf = 80;
 	SWITCH_ADD_CODEC(codec_interface, "G.722");
 	for (count = 12; count > 0; count--) {
-		switch_core_codec_add_implementation(pool, codec_interface,
-											 SWITCH_CODEC_TYPE_AUDIO, 9, "G722", NULL, 8000, 16000, 64000,
-											 mpf * count, spf * count, bpf * count, ebpf * count, 1, spf * count,
-											 switch_g722_init, switch_g722_encode, switch_g722_decode, switch_g722_destroy);
+		switch_core_codec_add_implementation(pool,
+											 codec_interface,
+											 SWITCH_CODEC_TYPE_AUDIO,	/* enumeration defining the type of the codec */
+											 9,							/* the IANA code number */
+											 "G722",					/* the IANA code name */
+											 NULL,						/* default fmtp to send (can be overridden by the init function) */
+											 8000,						/* samples transferred per second */
+											 16000,						/* actual samples transferred per second */
+											 64000,						/* bits transferred per second */
+											 mpf * count,				/* number of microseconds per frame */
+											 spf * count,				/* number of samples per frame */
+											 bpf * count,				/* number of bytes per frame decompressed */
+											 ebpf * count,				/* number of bytes per frame compressed */
+											 1,							/* number of channels represented */
+											 spf * count,				/* number of frames per network packet */
+											 switch_g722_init,			/* function to initialize a codec handle using this implementation */
+											 switch_g722_encode,		/* function to encode raw data into encoded data */
+											 switch_g722_decode,		/* function to decode encoded data into raw data */
+											 switch_g722_destroy);		/* deinitalize a codec handle using this implementation */
 	}
 
 #ifdef ENABLE_G711
@@ -663,18 +808,48 @@
 	mpf = 10000, spf = 80, bpf = 160, ebpf = 80;
 	SWITCH_ADD_CODEC(codec_interface, "G.711 ulaw");
 	for (count = 12; count > 0; count--) {
-		switch_core_codec_add_implementation(pool, codec_interface,
-											 SWITCH_CODEC_TYPE_AUDIO, 0, "PCMU", NULL, 8000, 8000, 64000,
-											 mpf * count, spf * count, bpf * count, ebpf * count, 1, spf * count,
-											 switch_g711u_init, switch_g711u_encode, switch_g711u_decode, switch_g711u_destroy);
+		switch_core_codec_add_implementation(pool,
+											 codec_interface,
+											 SWITCH_CODEC_TYPE_AUDIO,	/* enumeration defining the type of the codec */
+											 0,							/* the IANA code number */
+											 "PCMU",					/* the IANA code name */
+											 NULL,						/* default fmtp to send (can be overridden by the init function) */
+											 8000,						/* samples transferred per second */
+											 8000,						/* actual samples transferred per second */
+											 64000,						/* bits transferred per second */
+											 mpf * count,				/* number of microseconds per frame */
+											 spf * count,				/* number of samples per frame */
+											 bpf * count,				/* number of bytes per frame decompressed */
+											 ebpf * count,				/* number of bytes per frame compressed */
+											 1,							/* number of channels represented */
+											 spf * count,				/* number of frames per network packet */
+											 switch_g711u_init,			/* function to initialize a codec handle using this implementation */
+											 switch_g711u_encode,		/* function to encode raw data into encoded data */
+											 switch_g711u_decode,		/* function to decode encoded data into raw data */
+											 switch_g711u_destroy);		/* deinitalize a codec handle using this implementation */
 	}
 
 	SWITCH_ADD_CODEC(codec_interface, "G.711 alaw");
 	for (count = 12; count > 0; count--) {
-		switch_core_codec_add_implementation(pool, codec_interface,
-											 SWITCH_CODEC_TYPE_AUDIO, 8, "PCMA", NULL, 8000, 8000, 64000,
-											 mpf * count, spf * count, bpf * count, ebpf * count, 1, spf * count,
-											 switch_g711a_init, switch_g711a_encode, switch_g711a_decode, switch_g711a_destroy);
+		switch_core_codec_add_implementation(pool,
+											 codec_interface,
+											 SWITCH_CODEC_TYPE_AUDIO,	/* enumeration defining the type of the codec */
+											 8,							/* the IANA code number */
+											 "PCMA",					/* the IANA code name */
+											 NULL,						/* default fmtp to send (can be overridden by the init function) */
+											 8000,						/* samples transferred per second */
+											 8000,						/* actual samples transferred per second */
+											 64000,						/* bits transferred per second */
+											 mpf * count,				/* number of microseconds per frame */
+											 spf * count,				/* number of samples per frame */
+											 bpf * count,				/* number of bytes per frame decompressed */
+											 ebpf * count,				/* number of bytes per frame compressed */
+											 1,							/* number of channels represented */
+											 spf * count,				/* number of frames per network packet */
+											 switch_g711a_init,			/* function to initialize a codec handle using this implementation */
+											 switch_g711a_encode,		/* function to encode raw data into encoded data */
+											 switch_g711a_decode,		/* function to decode encoded data into raw data */
+											 switch_g711a_destroy);		/* deinitalize a codec handle using this implementation */
 	}
 #endif
 
@@ -682,10 +857,25 @@
 	mpf = 20000, spf = 160, bpf = 320, ebpf = 33;
 	SWITCH_ADD_CODEC(codec_interface, "GSM");
 	for (count = 6; count > 0; count--) {
-		switch_core_codec_add_implementation(pool, codec_interface,
-											 SWITCH_CODEC_TYPE_AUDIO, 3, "GSM", NULL, 8000, 8000, 13200,
-											 mpf * count, spf * count, bpf * count, ebpf * count, 1, count,
-											 switch_gsm_init, switch_gsm_encode, switch_gsm_decode, switch_gsm_destroy);
+		switch_core_codec_add_implementation(pool,
+											 codec_interface,
+											 SWITCH_CODEC_TYPE_AUDIO,	/* enumeration defining the type of the codec */
+											 3,							/* the IANA code number */
+											 "GSM",						/* the IANA code name */
+											 NULL,						/* default fmtp to send (can be overridden by the init function) */
+											 8000,						/* samples transferred per second */
+											 8000,						/* actual samples transferred per second */
+											 13200,						/* bits transferred per second */
+											 mpf * count,				/* number of microseconds per frame */
+											 spf * count,				/* number of samples per frame */
+											 bpf * count,				/* number of bytes per frame decompressed */
+											 ebpf * count,				/* number of bytes per frame compressed */
+											 1,							/* number of channels represented */
+											 count,						/* number of frames per network packet */
+											 switch_gsm_init,			/* function to initialize a codec handle using this implementation */
+											 switch_gsm_encode,			/* function to encode raw data into encoded data */
+											 switch_gsm_decode,			/* function to decode encoded data into raw data */
+											 switch_gsm_destroy);		/* deinitalize a codec handle using this implementation */
 	}
 	/* LPC10 */
 #if SWITCH_MAX_INTERVAL >= 90

Modified: freeswitch/branches/gmaruzz/src/mod/dialplans/mod_dialplan_asterisk/mod_dialplan_asterisk.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/dialplans/mod_dialplan_asterisk/mod_dialplan_asterisk.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/dialplans/mod_dialplan_asterisk/mod_dialplan_asterisk.c	Mon Nov 17 14:18:32 2008
@@ -38,13 +38,15 @@
 
 static switch_status_t exec_app(switch_core_session_t *session, char *app, char *arg)
 {
-	const switch_application_interface_t *application_interface;
+	switch_application_interface_t *application_interface;
+	switch_status_t status = SWITCH_STATUS_FALSE;
 
 	if ((application_interface = switch_loadable_module_get_application_interface(app))) {
-		return switch_core_session_exec(session, application_interface, arg);
+		status = switch_core_session_exec(session, application_interface, arg);
+		UNPROTECT_INTERFACE(application_interface);
 	}
 
-	return SWITCH_STATUS_FALSE;
+	return status;
 }
 
 SWITCH_STANDARD_APP(dial_function)
@@ -316,6 +318,9 @@
 	}
 
 	outbound_profile->destination_number = switch_core_sprintf(outbound_profile->pool, "%s/%s", profile, outbound_profile->destination_number);
+
+	UNPROTECT_INTERFACE(sip_endpoint_interface);
+
 	return switch_core_session_outgoing_channel(session, var_event, "sofia", outbound_profile, new_session, pool, SOF_NONE);
 }
 
@@ -335,6 +340,8 @@
 												 switch_caller_profile_t *outbound_profile,
 												 switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags)
 {
+	UNPROTECT_INTERFACE(iax2_endpoint_interface);
+
 	return switch_core_session_outgoing_channel(session, var_event, "iax", outbound_profile, new_session, pool, SOF_NONE);
 }
 

Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_dingaling/mod_dingaling.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_dingaling/mod_dingaling.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_dingaling/mod_dingaling.c	Mon Nov 17 14:18:32 2008
@@ -1112,7 +1112,7 @@
 		if (switch_test_flag(tech_pvt, TFLAG_BYE) || !switch_test_flag(tech_pvt, TFLAG_IO)) {
 			goto done;
 		}
-		switch_yield(1000);
+		switch_cond_next();
 	}
 
 	if (switch_channel_get_state(channel) >= CS_HANGUP || switch_test_flag(tech_pvt, TFLAG_BYE)) {

Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_iax/mod_iax.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_iax/mod_iax.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_iax/mod_iax.c	Mon Nov 17 14:18:32 2008
@@ -583,7 +583,7 @@
 	while (switch_test_flag(tech_pvt, TFLAG_IO)) {
 
 		if (!switch_test_flag(tech_pvt, TFLAG_CODEC)) {
-			switch_yield(1000);
+			switch_cond_next();
 			continue;
 		}
 		if (switch_test_flag(tech_pvt, TFLAG_BREAK)) {
@@ -615,7 +615,7 @@
 			return SWITCH_STATUS_SUCCESS;
 		}
 
-		switch_yield(1000);
+		switch_cond_next();
 		if (++ms_count >= 30000) {
 			break;
 		}

Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_loopback/mod_loopback.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_loopback/mod_loopback.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_loopback/mod_loopback.c	Mon Nov 17 14:18:32 2008
@@ -491,7 +491,7 @@
 			break;
 		}
 
-		switch_yield(1000);
+		switch_cond_next();
 	}
 
 	if (switch_test_flag(tech_pvt, TFLAG_LINKED)) {

Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_portaudio/pablio.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_portaudio/pablio.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_portaudio/pablio.c	Mon Nov 17 14:18:32 2008
@@ -131,7 +131,7 @@
 				PaUtil_FlushRingBuffer(&aStream->outFIFO);
 				return 0;
 			}
-			switch_yield(1000);
+			switch_cond_next();
 		}
 	}
 	return numFrames;
@@ -169,7 +169,7 @@
 		if (bytesRead) {
 			p += bytesRead;
 		} else {
-			switch_yield(1000);
+			switch_cond_next();
 		}
 	}
 

Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_reference/mod_reference.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_reference/mod_reference.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_reference/mod_reference.c	Mon Nov 17 14:18:32 2008
@@ -309,7 +309,7 @@
 			return SWITCH_STATUS_SUCCESS;
 		}
 
-		switch_yield(1000);
+		switch_cond_next();
 	}
 
 

Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/mod_sofia.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/mod_sofia.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/mod_sofia.c	Mon Nov 17 14:18:32 2008
@@ -331,7 +331,7 @@
 		
 		if (cause > 0 && cause < 128) {
 			switch_snprintf(reason, sizeof(reason), "Q.850;cause=%d;text=\"%s\"", cause, switch_channel_cause2str(cause));
-		} else if (cause == SWITCH_CAUSE_PICKED_OFF) {
+		} else if (cause == SWITCH_CAUSE_PICKED_OFF || cause == SWITCH_CAUSE_LOSE_RACE) {
 			switch_snprintf(reason, sizeof(reason), "SIP;cause=200;text=\"Call completed elsewhere\"");
 		} else {
 			switch_snprintf(reason, sizeof(reason), "FreeSWITCH;cause=%d;text=\"%s\"", cause, switch_channel_cause2str(cause));
@@ -373,6 +373,17 @@
 		switch_safe_free(stream.data);
 	}
 
+	if (tech_pvt->read_codec.implementation) {
+		switch_core_codec_destroy(&tech_pvt->read_codec);
+	}
+
+	if (tech_pvt->write_codec.implementation) {
+		switch_core_codec_destroy(&tech_pvt->write_codec);
+	}
+
+	switch_core_session_unset_read_codec(session);
+	switch_core_session_unset_write_codec(session);
+
 	switch_mutex_lock(tech_pvt->profile->flag_mutex);
 	switch_clear_flag(tech_pvt, TFLAG_IO);
 	tech_pvt->profile->inuse--;
@@ -442,7 +453,7 @@
 			// Maybe we should timeout?
 			
 			while(switch_channel_ready(channel) && !switch_test_flag(tech_pvt, TFLAG_3PCC_HAS_ACK)) {
-				switch_yield(1000);
+				switch_cond_next();
 			}
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "3PCC-PROXY, Done waiting for ACK\n");
 		}
@@ -686,6 +697,41 @@
 						*frame = NULL;
 						return SWITCH_STATUS_GENERR;
 					}
+
+
+					if (tech_pvt->check_frames < MAX_CODEC_CHECK_FRAMES) {
+						if (tech_pvt->last_ts && tech_pvt->read_frame.datalen != tech_pvt->read_codec.implementation->encoded_bytes_per_packet) {
+							switch_size_t codec_ms = (int)(tech_pvt->read_frame.timestamp - 
+														   tech_pvt->last_ts) / (tech_pvt->read_codec.implementation->samples_per_second / 1000);
+							
+							if ((codec_ms % 10) != 0) {
+								tech_pvt->check_frames = MAX_CODEC_CHECK_FRAMES;
+							} else {
+								if (switch_rtp_ready(tech_pvt->rtp_session) && codec_ms != tech_pvt->codec_ms) {
+									tech_pvt->codec_ms = codec_ms;
+									switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, 
+													  "Changing codec ptime to %d. I bet you have a linksys/sipura =D\n", tech_pvt->codec_ms);
+									switch_core_codec_destroy(&tech_pvt->read_codec);
+									switch_core_codec_destroy(&tech_pvt->write_codec);
+									if (sofia_glue_tech_set_codec(tech_pvt, 2) != SWITCH_STATUS_SUCCESS) {
+										*frame = NULL;
+										return SWITCH_STATUS_GENERR;
+									}
+
+									switch_rtp_change_interval(tech_pvt->rtp_session, 
+															   tech_pvt->read_codec.implementation->samples_per_packet,
+															   tech_pvt->codec_ms * 1000);
+
+									tech_pvt->check_frames = MAX_CODEC_CHECK_FRAMES;
+								}
+							
+							}
+							tech_pvt->check_frames++;
+
+						}
+						tech_pvt->last_ts = tech_pvt->read_frame.timestamp;
+					}
+					
 					if ((bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_packet)) {
 						frames = (tech_pvt->read_frame.datalen / bytes);
 					}
@@ -868,9 +914,15 @@
 	default:
 		break;
 	}
-
+	
 	/* ones that do need to lock sofia mutex */
 	switch_mutex_lock(tech_pvt->sofia_mutex);
+
+	if (switch_channel_get_state(channel) >= CS_HANGUP || !tech_pvt) {
+		status = SWITCH_STATUS_FALSE;
+		goto end_lock;
+	}
+
 	switch (msg->message_id) {
 	case SWITCH_MESSAGE_INDICATE_VIDEO_REFRESH_REQ:
 		{
@@ -958,7 +1010,7 @@
 					if (sofia_glue_tech_media(tech_pvt, r_sdp) != SWITCH_STATUS_SUCCESS) {
 						switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "CODEC NEGOTIATION ERROR");
 						status = SWITCH_STATUS_FALSE;
-						goto end;
+						goto end_lock;
 					}
 					send_invite = 0;
 				}
@@ -968,7 +1020,7 @@
 				sofia_glue_tech_prepare_codecs(tech_pvt);
 				if ((status = sofia_glue_tech_choose_port(tech_pvt, 0)) != SWITCH_STATUS_SUCCESS) {
 					switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-					goto end;
+					goto end_lock;
 				}
 			}
 			sofia_glue_set_local_sdp(tech_pvt, NULL, 0, NULL, 1);
@@ -1098,7 +1150,7 @@
 				msg->message_id = SWITCH_MESSAGE_INDICATE_REDIRECT;
 				msg->string_arg = p;
 				switch_core_session_receive_message(session, msg);
-				goto end;
+				goto end_lock;
 			} else {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Responding with %d [%s]\n", code, reason);
 
@@ -1152,7 +1204,7 @@
 						sofia_glue_tech_patch_sdp(tech_pvt);
 						if (sofia_glue_activate_rtp(tech_pvt, 0) != SWITCH_STATUS_SUCCESS) {
 							status = SWITCH_STATUS_FALSE;
-							goto end;
+							goto end_lock;
 						}
 					}
 				} else {
@@ -1165,18 +1217,16 @@
 							sofia_glue_tech_prepare_codecs(tech_pvt);
 							if (sofia_glue_tech_media(tech_pvt, r_sdp) != SWITCH_STATUS_SUCCESS) {
 								switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "CODEC NEGOTIATION ERROR");
-								//switch_mutex_lock(tech_pvt->sofia_mutex);
 								//nua_respond(tech_pvt->nh, SIP_488_NOT_ACCEPTABLE, TAG_END());
-								//switch_mutex_unlock(tech_pvt->sofia_mutex);
 								status = SWITCH_STATUS_FALSE;
-								goto end;
+								goto end_lock;
 							}
 						}
 					}
 
 					if ((status = sofia_glue_tech_choose_port(tech_pvt, 0)) != SWITCH_STATUS_SUCCESS) {
 						switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-						goto end;
+						goto end_lock;
 					}
 					sofia_glue_set_local_sdp(tech_pvt, NULL, 0, NULL, 0);
 					if (sofia_glue_activate_rtp(tech_pvt, 0) != SWITCH_STATUS_SUCCESS) {
@@ -1212,6 +1262,9 @@
 	default:
 		break;
 	}
+
+ end_lock:
+
 	switch_mutex_unlock(tech_pvt->sofia_mutex);
 
   end:
@@ -1269,7 +1322,7 @@
 	switch_stream_handle_t *stream;
 };
 
-#define switch_time_from_sec(sec)   ((switch_time_t)(sec) * 1000000)
+
 
 static int show_reg_callback(void *pArg, int argc, char **argv, char **columnNames)
 {
@@ -1707,7 +1760,7 @@
 	char *contact;
 
 	if (!switch_strlen_zero(argv[0]) && (contact = sofia_glue_get_url_from_contact(argv[0], 1)) ) {
-		cb->stream->write_function(cb->stream, "%ssofia/%s/%s,", argv[2], argv[1], sofia_glue_strip_proto(contact));
+		cb->stream->write_function(cb->stream, "%ssofia/%s/sip:%s,", argv[2], argv[1], sofia_glue_strip_proto(contact));
 		free(contact);
 	}
 
@@ -2499,12 +2552,13 @@
 	switch_event_unbind_callback(general_event_handler);
 	
 	while (mod_sofia_globals.threads) {
-		switch_yield(1000);
+		switch_cond_next();
 		if (++sanity >= 10000) {
 			break;
 		}
 	}
 
+	switch_yield(1000000);
 	su_deinit();
 
 	switch_mutex_lock(mod_sofia_globals.hash_mutex);

Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/mod_sofia.h
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/mod_sofia.h	(original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/mod_sofia.h	Mon Nov 17 14:18:32 2008
@@ -53,6 +53,7 @@
 #define HAVE_FUNC 1
 #endif
 
+#define MAX_CODEC_CHECK_FRAMES 50
 #define MODNAME "mod_sofia"
 static const switch_state_handler_table_t noop_state_handler = { 0 };
 struct sofia_gateway;
@@ -164,7 +165,9 @@
 	PFLAG_FUNNY_STUN = (1 << 26),
 	PFLAG_STUN_ENABLED = (1 << 27),
 	PFLAG_STUN_AUTO_DISABLE = (1 << 28),
-	PFLAG_3PCC_PROXY = (1 << 29)
+	PFLAG_3PCC_PROXY = (1 << 29),
+	PFLAG_CALLID_AS_UUID = (1 << 30),
+	PFLAG_UUID_AS_CALLID = (1 << 31)
 } PFLAGS;
 
 typedef enum {
@@ -198,7 +201,7 @@
 	TFLAG_REINVITE = (1 << 16),
 	TFLAG_REFER = (1 << 17),
 	TFLAG_NOHUP = (1 << 18),
-	TFLAG_XFER = (1 << 19),
+	TFLAG_NOSDP_REINVITE = (1 << 19),
 	TFLAG_NAT = (1 << 20),
 	TFLAG_BUGGY_2833 = (1 << 21),
 	TFLAG_SIP_HOLD = (1 << 22),
@@ -299,6 +302,7 @@
 	switch_memory_pool_t *pool;
 	int deleted;
 	switch_event_t *vars;
+	char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
 	struct sofia_gateway *next;
 };
 
@@ -504,6 +508,9 @@
 	int remote_port;
 	int got_bye;
 	int hold_laps;
+	switch_thread_id_t locker;
+	switch_size_t last_ts;
+	uint32_t check_frames;
 };
 
 struct callback_t {
@@ -707,3 +714,4 @@
 void sofia_glue_restart_all_profiles(void);
 void sofia_glue_toggle_hold(private_object_t *tech_pvt, int sendonly);
 const char * sofia_state_string(int state);
+switch_status_t sofia_glue_tech_set_codec(private_object_t *tech_pvt, int force);

Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/sofia.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/sofia.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/sofia.c	Mon Nov 17 14:18:32 2008
@@ -170,6 +170,7 @@
 	switch_core_session_t *session = NULL;
 	switch_channel_t *channel = NULL;
 	sofia_gateway_t *gateway = NULL;
+	int locked = 0;
 
 	if (sofia_private && sofia_private != &mod_sofia_globals.destroy_private && sofia_private != &mod_sofia_globals.keep_private) {
 		if ((gateway = sofia_private->gateway)) {
@@ -203,12 +204,15 @@
 	}
 
 	if (session) {
-		switch_mutex_lock(tech_pvt->sofia_mutex);
-
 		if (channel && switch_channel_get_state(channel) >= CS_HANGUP) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Channel is already hungup.\n");
 			goto done;
 		}
+
+		if (tech_pvt) {
+			switch_mutex_lock(tech_pvt->sofia_mutex);
+			locked = 1;
+		}
 	} else if (sofia_private && sofia_private->is_call) {
 		sofia_private->destroy_me = 22;
 	}
@@ -360,9 +364,12 @@
 	}
 
 	if (session) {
-		switch_mutex_unlock(tech_pvt->sofia_mutex);
 		switch_core_session_rwunlock(session);
 	}
+
+	if (tech_pvt && locked) {
+		switch_mutex_unlock(tech_pvt->sofia_mutex);
+	}
 }
 
 void event_handler(switch_event_t *event)
@@ -792,9 +799,13 @@
 				*expire_seconds = "3600",
 				*retry_seconds = "30",
 				*from_user = "", *from_domain = "", *register_proxy = NULL, *contact_params = NULL, *params = NULL, *register_transport = NULL;
-
+			
 			uint32_t ping_freq = 0;
-
+			switch_uuid_t uuid;
+			
+			switch_uuid_get(&uuid);
+			switch_uuid_format(gateway->uuid_str, &uuid);
+			
 			gateway->register_transport = SOFIA_TRANSPORT_UDP;
 			gateway->pool = profile->pool;
 			gateway->profile = profile;
@@ -1064,6 +1075,18 @@
 						} else {
 							switch_clear_flag(profile, TFLAG_PROXY_MEDIA);
 						}
+					} else if (!strcasecmp(var, "inbound-use-callid-as-uuid")) {
+						if (switch_true(val)) {
+							profile->pflags |= PFLAG_CALLID_AS_UUID;
+						} else {
+							profile->pflags &= ~PFLAG_CALLID_AS_UUID;
+						}
+					} else if (!strcasecmp(var, "outbound-use-uuid-as-callid")) {
+						if (switch_true(val)) {
+							profile->pflags |= PFLAG_UUID_AS_CALLID;
+						} else {
+							profile->pflags &= ~PFLAG_UUID_AS_CALLID;
+						}
 					} else if (!strcasecmp(var, "NDLB-received-in-nat-reg-contact")) {
 						if (switch_true(val)) {
 							profile->pflags |= PFLAG_RECIEVED_IN_NAT_REG_CONTACT;
@@ -1156,13 +1179,14 @@
 							profile->pflags &= ~PFLAG_SECURE;
 						}
 					} else if (!strcasecmp(var, "multiple-registrations")) {
-						if (!strcasecmp(val, "contact")) {
+						if (!strcasecmp(val, "call-id")) {
+							profile->pflags |= PFLAG_MULTIREG;
+						} else if (!strcasecmp(val, "contact") || switch_true(val)) {
 							profile->pflags |= PFLAG_MULTIREG;
 							profile->pflags |= PFLAG_MULTIREG_CONTACT;
 						} else if (switch_true(val)) {
-							profile->pflags |= PFLAG_MULTIREG;
-						} else {
 							profile->pflags &= ~PFLAG_MULTIREG;
+							//profile->pflags &= ~PFLAG_MULTIREG_CONTACT;
 						}
 					} else if (!strcasecmp(var, "supress-cng") || !strcasecmp(var, "suppress-cng")) {
 						if (switch_true(val)) {
@@ -1414,6 +1438,7 @@
 				profile->mflags = MFLAG_REFER | MFLAG_REGISTER;
 				profile->rport_level = 1;
 				profile->pflags |= PFLAG_STUN_ENABLED;
+				profile->pflags |= PFLAG_DISABLE_100REL;
 				
 				for (param = switch_xml_child(settings, "param"); param; param = param->next) {
 					char *var = (char *) switch_xml_attr_soft(param, "name");
@@ -1461,6 +1486,18 @@
 						switch_set_flag(profile, TFLAG_LATE_NEGOTIATION);
 					} else if (!strcasecmp(var, "inbound-proxy-media") && switch_true(val)) {
 						switch_set_flag(profile, TFLAG_PROXY_MEDIA);
+					} else if (!strcasecmp(var, "inbound-use-callid-as-uuid")) {
+						if (switch_true(val)) {
+							profile->pflags |= PFLAG_CALLID_AS_UUID;
+						} else {
+							profile->pflags &= ~PFLAG_CALLID_AS_UUID;
+						}
+					} else if (!strcasecmp(var, "outbound-use-uuid-as-callid")) {
+						if (switch_true(val)) {
+							profile->pflags |= PFLAG_UUID_AS_CALLID;
+						} else {
+							profile->pflags &= ~PFLAG_UUID_AS_CALLID;
+						}
 					} else if (!strcasecmp(var, "NDLB-received-in-nat-reg-contact") && switch_true(val)) {
 						profile->pflags |= PFLAG_RECIEVED_IN_NAT_REG_CONTACT;
 					} else if (!strcasecmp(var, "aggressive-nat-detection") && switch_true(val)) {
@@ -1615,13 +1652,14 @@
 							profile->pflags |= PFLAG_SECURE;
 						}
 					} else if (!strcasecmp(var, "multiple-registrations")) {
-						if (!strcasecmp(val, "contact")) {
+						if (!strcasecmp(val, "call-id")) {
+							profile->pflags |= PFLAG_MULTIREG;
+						} else if (!strcasecmp(val, "contact") || switch_true(val)) {
 							profile->pflags |= PFLAG_MULTIREG;
 							profile->pflags |= PFLAG_MULTIREG_CONTACT;
 						} else if (switch_true(val)) {
-							profile->pflags |= PFLAG_MULTIREG;
-						} else {
 							profile->pflags &= ~PFLAG_MULTIREG;
+							//profile->pflags &= ~PFLAG_MULTIREG_CONTACT;
 						}
 					} else if (!strcasecmp(var, "supress-cng") || !strcasecmp(var, "suppress-cng")) {
 						if (switch_true(val)) {
@@ -1696,8 +1734,8 @@
 							profile->minimum_session_expires = 90;
 						}
 					} else if (!strcasecmp(var, "enable-100rel")) {
-						if (!switch_true(val)) {
-							profile->pflags |= PFLAG_DISABLE_100REL;
+						if (switch_true(val)) {
+							profile->pflags &= ~PFLAG_DISABLE_100REL;
 						}
 					} else if (!strcasecmp(var, "bitpacking")) {
 						if (!strcasecmp(val, "aal2")) {
@@ -2037,7 +2075,7 @@
 
 		/* dirty hack to avoid race condition in the library */
 		if (status == 200 || status == 183) {
-			switch_yield(1);// printf("Avoiding Segfault!!!\n");
+			switch_yield(100);// printf("Avoiding Segfault!!!\n");
 		}
 
 		if (switch_channel_test_flag(channel, CF_PROXY_MODE) || switch_channel_test_flag(channel, CF_PROXY_MEDIA)) {
@@ -2497,6 +2535,7 @@
 
 		} else if (tech_pvt && switch_test_flag(tech_pvt, TFLAG_SDP) && !r_sdp) {
 			nua_respond(tech_pvt->nh, SIP_200_OK, TAG_END());
+			switch_set_flag_locked(tech_pvt, TFLAG_NOSDP_REINVITE);
 			goto done;
 		} else {
 			ss_state = nua_callstate_completed;
@@ -2635,6 +2674,45 @@
 		}
 		break;
 	case nua_callstate_ready:
+
+		if (r_sdp && switch_test_flag(tech_pvt, TFLAG_NOSDP_REINVITE)) {
+			sdp_parser_t *parser;
+			sdp_session_t *sdp;
+			uint8_t match = 0;
+			int is_ok = 1;
+			
+			switch_clear_flag_locked(tech_pvt, TFLAG_NOSDP_REINVITE);
+
+			if (tech_pvt->num_codecs) {
+				if ((parser = sdp_parse(NULL, r_sdp, (int) strlen(r_sdp), 0))) {
+					if ((sdp = sdp_session(parser))) {
+						match = sofia_glue_negotiate_sdp(session, sdp);
+					}
+					sdp_parser_free(parser);
+				}
+			}
+
+			if (match) {
+				switch_set_flag_locked(tech_pvt, TFLAG_REINVITE);
+				if (sofia_glue_activate_rtp(tech_pvt, 0) != SWITCH_STATUS_SUCCESS) {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "RTP Error!\n");
+					switch_channel_set_variable(tech_pvt->channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "RTP ERROR");
+					is_ok = 0;
+				}
+				switch_clear_flag_locked(tech_pvt, TFLAG_REINVITE);
+			} else {
+				switch_channel_set_variable(tech_pvt->channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "CODEC NEGOTIATION ERROR");
+				is_ok = 0;
+			}
+
+			if (!is_ok) {
+				nua_respond(nh, SIP_488_NOT_ACCEPTABLE, TAG_END());
+				switch_channel_hangup(tech_pvt->channel, SWITCH_CAUSE_INCOMPATIBLE_DESTINATION);
+			}
+
+			goto done;
+		}
+
 		if (channel) {
 			switch_channel_clear_flag(channel, CF_REQ_MEDIA);
 		}
@@ -2976,6 +3054,7 @@
 
 							switch_clear_flag_locked(b_tech_pvt, TFLAG_SIP_HOLD);
 							switch_clear_flag_locked(tech_pvt, TFLAG_HOLD_LOCK);
+							switch_channel_set_variable(switch_core_session_get_channel(b_session), "park_timeout", "2");
 							switch_channel_set_state(switch_core_session_get_channel(b_session), CS_PARK);
 
 							new_b_session = switch_core_session_locate(br_b);
@@ -3482,7 +3561,15 @@
 		return;
 	}
 
-	if (!sofia_endpoint_interface || !(session = switch_core_session_request(sofia_endpoint_interface, NULL))) {
+	if (sofia_endpoint_interface) {
+		if (profile->pflags & PFLAG_CALLID_AS_UUID) {
+			session = switch_core_session_request_uuid(sofia_endpoint_interface, NULL, sip->sip_call_id->i_id);
+		} else {
+			session = switch_core_session_request(sofia_endpoint_interface, NULL);
+		}
+	}
+
+	if (!session) {
 		nua_respond(nh, 503, "Maximum Calls In Progress", SIPTAG_RETRY_AFTER_STR("300"), TAG_END());
 		return;
 	}

Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/sofia_glue.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/sofia_glue.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/sofia_glue.c	Mon Nov 17 14:18:32 2008
@@ -91,10 +91,10 @@
 					"o=FreeSWITCH %010u %010u IN %s %s\n"
 					"s=FreeSWITCH\n"
 					"c=IN %s %s\n" "t=0 0\n"
-					"a=%s\n"
-					"m=audio %d RTP/%sAVP", tech_pvt->owner_id, tech_pvt->session_id, family, ip, family, ip, sr, port,
-					(!switch_strlen_zero(tech_pvt->local_crypto_key) && switch_test_flag(tech_pvt, TFLAG_SECURE)) ? "S" : "");
-
+					"m=audio %d RTP/%sAVP", 
+					tech_pvt->owner_id, tech_pvt->session_id, family, ip, family, ip, port,
+					(!switch_strlen_zero(tech_pvt->local_crypto_key) 
+					&& switch_test_flag(tech_pvt,TFLAG_SECURE)) ? "S" : "");
 
 	if (tech_pvt->rm_encoding) {
 		switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " %d", tech_pvt->pt);
@@ -182,10 +182,14 @@
 	} else {
 		switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=silenceSupp:off - - - -\n");
 	}
+
 	if (ptime) {
 		switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=ptime:%d\n", ptime);
 	}
 
+	if (sr) {
+		switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=%s\n", sr);
+	} 
 
 	if (!switch_strlen_zero(tech_pvt->local_crypto_key) && switch_test_flag(tech_pvt, TFLAG_SECURE)) {
 		switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=crypto:%s\n", tech_pvt->local_crypto_key);
@@ -1085,6 +1089,7 @@
 		const char *priv = "off";
 		const char *screen = "no";
 		const char *invite_params = switch_channel_get_variable(tech_pvt->channel, "sip_invite_params");
+		const char *from_var = switch_channel_get_variable(tech_pvt->channel, "sip_from_uri");
 
 		if (switch_strlen_zero(tech_pvt->dest)) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "URL Error!\n");
@@ -1099,7 +1104,13 @@
 
 		url_str = url;
 
-		if (!switch_strlen_zero(tech_pvt->gateway_from_str)) {
+		if (from_var) {
+			if (strncasecmp(from_var, "sip:", 4) || strncasecmp(from_var, "sips:", 5)) {
+				use_from_str = switch_core_session_strdup(tech_pvt->session, from_var);
+			} else {
+				use_from_str = switch_core_session_sprintf(tech_pvt->session, "sip:%s", from_var);
+			}
+		} else if (!switch_strlen_zero(tech_pvt->gateway_from_str)) {
 			use_from_str = tech_pvt->gateway_from_str;
 		} else {
 			use_from_str = tech_pvt->from_str;
@@ -1177,9 +1188,15 @@
 		use_from_str = from_str;
 		from_str = switch_core_session_sprintf(session, "\"%s\" <%s>", tech_pvt->caller_profile->caller_id_name, use_from_str);
 		
-
+		if (!(call_id = switch_channel_get_variable(channel, "sip_outgoing_call_id"))) {
+			if (tech_pvt->profile->pflags & PFLAG_UUID_AS_CALLID) {
+				call_id = switch_core_session_get_uuid(session);
+			}
+		}
+		
 		tech_pvt->nh = nua_handle(tech_pvt->profile->nua, NULL,
 								  NUTAG_URL(url_str),
+								  TAG_IF(call_id, SIPTAG_CALL_ID_STR(call_id)),
 								  SIPTAG_TO_STR(to_str), 
 								  SIPTAG_FROM_STR(from_str),
 								  SIPTAG_CONTACT_STR(invite_contact),
@@ -1290,8 +1307,6 @@
 		sofia_glue_tech_patch_sdp(tech_pvt);
 	}
 
-	call_id = switch_channel_get_variable(channel, "sip_outgoing_call_id");
-
 	if (tech_pvt->dest && (route = strstr(tech_pvt->dest, ";fs_path="))) {
 		char *p;
 
@@ -1330,7 +1345,6 @@
 			   TAG_IF(!switch_strlen_zero(alert_info), SIPTAG_HEADER_STR(alert_info)),
 			   TAG_IF(!switch_strlen_zero(extra_headers), SIPTAG_HEADER_STR(extra_headers)),
 			   TAG_IF(!switch_strlen_zero(max_forwards), SIPTAG_MAX_FORWARDS_STR(max_forwards)),
-			   TAG_IF(call_id, SIPTAG_CALL_ID_STR(call_id)),
 			   TAG_IF(route_uri, NUTAG_PROXY(route_uri)),
 			   TAG_IF(route, SIPTAG_ROUTE_STR(route)),
 			   SOATAG_ADDRESS(tech_pvt->adv_sdp_audio_ip),
@@ -1535,7 +1549,7 @@
 			return SWITCH_STATUS_SUCCESS;
 		}
 	}
-
+	
 	if (switch_core_codec_init(&tech_pvt->read_codec,
 							   tech_pvt->iananame,
 							   tech_pvt->rm_fmtp,
@@ -1560,6 +1574,11 @@
 		return SWITCH_STATUS_FALSE;
 	}
 
+	if (switch_rtp_ready(tech_pvt->rtp_session)) {
+		switch_assert(tech_pvt->read_codec.implementation);
+		switch_rtp_set_default_samples_per_interval(tech_pvt->rtp_session, tech_pvt->read_codec.implementation->samples_per_packet);
+	}
+
 	tech_pvt->read_frame.rate = tech_pvt->rm_rate;
 	ms = tech_pvt->write_codec.implementation->microseconds_per_packet / 1000;
 
@@ -1576,8 +1595,11 @@
 	tech_pvt->write_codec.agreed_pt = tech_pvt->agreed_pt;
 	tech_pvt->read_codec.agreed_pt = tech_pvt->agreed_pt;
 
-	switch_core_session_set_read_codec(tech_pvt->session, &tech_pvt->read_codec);
-	switch_core_session_set_write_codec(tech_pvt->session, &tech_pvt->write_codec);
+	if (force != 2) {
+		switch_core_session_set_read_codec(tech_pvt->session, &tech_pvt->read_codec);
+		switch_core_session_set_write_codec(tech_pvt->session, &tech_pvt->write_codec);
+	}
+
 	tech_pvt->fmtp_out = switch_core_session_strdup(tech_pvt->session, tech_pvt->write_codec.fmtp_out);
 
 	if (switch_rtp_ready(tech_pvt->rtp_session)) {
@@ -2858,10 +2880,15 @@
 
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Connected ODBC DSN: %s\n", profile->odbc_dsn);
 		
-		if (switch_odbc_handle_exec(profile->master_odbc, "select hostname from sip_registrations", NULL) != SWITCH_ODBC_SUCCESS) {
+		test_sql = switch_mprintf("delete from sip_registrations where (contact like '%%TCP%%' "
+								  "or status like '%%TCP%%' or status like '%%TLS%%') and hostname='%q'", 
+								  mod_sofia_globals.hostname);
+
+		if (switch_odbc_handle_exec(profile->master_odbc, test_sql, NULL) != SWITCH_ODBC_SUCCESS) {
 			switch_odbc_handle_exec(profile->master_odbc, "DROP TABLE sip_registrations", NULL);
 			switch_odbc_handle_exec(profile->master_odbc, reg_sql, NULL);
 		}
+		free(test_sql);
 
 
 		test_sql = switch_mprintf("delete from sip_subscriptions where hostname='%q'", mod_sofia_globals.hostname);
@@ -2891,13 +2918,18 @@
 #else
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n");
 #endif
-	} else {
+	} else {		
 		if (!(profile->master_db = switch_core_db_open_file(profile->dbname))) {
 			return 0;
 		}
 
-		switch_core_db_test_reactive(profile->master_db, "select hostname from sip_registrations", "DROP TABLE sip_registrations", reg_sql);
+		test_sql = switch_mprintf("delete from sip_registrations where (contact like '%%TCP%%' "
+								  "or status like '%%TCP%%' or status like '%%TLS%%') and hostname='%q'", 
+								  mod_sofia_globals.hostname);
 		
+		switch_core_db_test_reactive(profile->master_db, test_sql, "DROP TABLE sip_registrations", reg_sql);
+		free(test_sql);
+
 		test_sql = switch_mprintf("delete from sip_subscriptions where hostname='%q'", mod_sofia_globals.hostname);
 		switch_core_db_test_reactive(profile->master_db, test_sql, "DROP TABLE sip_subscriptions", sub_sql);
 		free(test_sql);
@@ -3130,7 +3162,7 @@
 				break;
 			} else if (result == SWITCH_CORE_DB_BUSY) {
 				running++;
-				switch_yield(1000);
+				switch_cond_next();
 				continue;
 			}
 			break;

Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/sofia_presence.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/sofia_presence.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/sofia_presence.c	Mon Nov 17 14:18:32 2008
@@ -1152,7 +1152,9 @@
 	}
 	
 	if (!(nh = nua_handle_by_call_id(h->profile->nua, call_id))) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Cannot find handle for %s\n", call_id);
+		if (profile->debug) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Cannot find handle for %s\n", call_id);
+		}
 		goto end;
 	}
 

Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/sofia_reg.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/sofia_reg.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/sofia_reg.c	Mon Nov 17 14:18:32 2008
@@ -152,6 +152,7 @@
 			sofia_reg_kill_reg(gateway_ptr, 0);
 
 			if ((gateway_ptr->nh = nua_handle(gateway_ptr->profile->nua, NULL,
+											  SIPTAG_CALL_ID_STR(gateway_ptr->uuid_str),
 											  NUTAG_URL(gateway_ptr->register_proxy),
 											  SIPTAG_TO_STR(gateway_ptr->register_to),
 											  NUTAG_CALLSTATE_REF(ss_state), SIPTAG_FROM_STR(gateway_ptr->register_from), TAG_END()))) {
@@ -345,15 +346,15 @@
 	}
 
 	switch_snprintf(sql, sizeof(sql), "select call_id,sip_user,sip_host,contact,status,rpid,expires,user_agent,server_user,server_host,profile_name"
-					",%d from sip_registrations where call_id='%s' or (sip_user='%s' and sip_host='%s') and hostname='%s'", 
-					reboot, call_id, user, host, mod_sofia_globals.hostname);
+					",%d from sip_registrations where call_id='%s' or (sip_user='%s' and sip_host='%s')", 
+					reboot, call_id, user, host);
 	
 	switch_mutex_lock(profile->ireg_mutex);
 	sofia_glue_execute_sql_callback(profile, SWITCH_TRUE, NULL, sql, sofia_reg_del_callback, profile);
 	switch_mutex_unlock(profile->ireg_mutex);
 
-	switch_snprintf(sql, sizeof(sql), "delete from sip_registrations where call_id='%s' or (sip_user='%s' and sip_host='%s') and hostname='%s'", 
-					call_id, user, host, mod_sofia_globals.hostname);
+	switch_snprintf(sql, sizeof(sql), "delete from sip_registrations where call_id='%s' or (sip_user='%s' and sip_host='%s')", 
+					call_id, user, host);
 	sofia_glue_execute_sql(profile, &psql, SWITCH_FALSE);
 
 	switch_safe_free(user);
@@ -800,8 +801,8 @@
 				sql = switch_mprintf("delete from sip_registrations where call_id='%q'", call_id);
 			}
 		} else {
-			sql = switch_mprintf("delete from sip_registrations where sip_user='%q' and sip_host='%q' and hostname='%q'", 
-								 to_user, reg_host, mod_sofia_globals.hostname);
+			sql = switch_mprintf("delete from sip_registrations where sip_user='%q' and sip_host='%q'", 
+								 to_user, reg_host);
 		}
 		switch_mutex_lock(profile->ireg_mutex);
 		sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
@@ -880,13 +881,11 @@
 
 			switch_safe_free(icontact);
 		} else {
-			if ((sql = switch_mprintf("delete from sip_subscriptions where sip_user='%q' and sip_host='%q' and hostname='%q'", to_user, reg_host, 
-									  mod_sofia_globals.hostname))) {
+			if ((sql = switch_mprintf("delete from sip_subscriptions where sip_user='%q' and sip_host='%q'", to_user, reg_host))) {
 				sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
 			}
 
-			if ((sql = switch_mprintf("delete from sip_registrations where sip_user='%q' and sip_host='%q' and hostname='%q'", to_user, reg_host,
-									  mod_sofia_globals.hostname))) {
+			if ((sql = switch_mprintf("delete from sip_registrations where sip_user='%q' and sip_host='%q'", to_user, reg_host))) {
 				sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
 			}
 		}

Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_unicall/mod_unicall.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_unicall/mod_unicall.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_unicall/mod_unicall.c	Mon Nov 17 14:18:32 2008
@@ -1052,7 +1052,7 @@
             return SWITCH_STATUS_SUCCESS;
         }
 
-        switch_yield(1000);
+        switch_cond_next();
     }
 
     return SWITCH_STATUS_FALSE;

Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_woomera/mod_woomera.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_woomera/mod_woomera.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_woomera/mod_woomera.c	Mon Nov 17 14:18:32 2008
@@ -338,7 +338,7 @@
 		if (switch_test_flag(tech_pvt, TFLAG_MEDIA)) {
 			break;
 		}
-		switch_yield(1000);
+		switch_cond_next();
 	}
 
 	if (!tech_pvt->udp_socket) {

Modified: freeswitch/branches/gmaruzz/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c	Mon Nov 17 14:18:32 2008
@@ -253,7 +253,7 @@
 		globals.running = -1;
 		while (x < 100000 && globals.running) {
 			x++;
-			switch_yield(1000);
+			switch_cond_next();
 		}
 	}
 

Modified: freeswitch/branches/gmaruzz/src/mod/event_handlers/mod_event_socket/mod_event_socket.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/event_handlers/mod_event_socket/mod_event_socket.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/event_handlers/mod_event_socket/mod_event_socket.c	Mon Nov 17 14:18:32 2008
@@ -87,8 +87,12 @@
 typedef struct listener listener_t;
 
 static struct {
+	switch_mutex_t *listener_mutex;	
+	switch_event_node_t *node;
+} globals;
+
+static struct {
 	switch_socket_t *sock;
-	switch_mutex_t *mutex;
 	switch_mutex_t *sock_mutex;
 	listener_t *listeners;
 	uint8_t ready;
@@ -114,9 +118,9 @@
 static uint32_t next_id(void)
 {
 	uint32_t id;
-	switch_mutex_lock(listen_list.mutex);
+	switch_mutex_lock(globals.listener_mutex);
     id = ++prefs.id;
-    switch_mutex_unlock(listen_list.mutex);
+    switch_mutex_unlock(globals.listener_mutex);
 	return id;
 }
 
@@ -126,16 +130,11 @@
 static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t *thread, void *obj);
 static void launch_listener_thread(listener_t *listener);
 
-static struct {
-	switch_event_node_t *node;
-} globals;
-
-
 static switch_status_t socket_logger(const switch_log_node_t *node, switch_log_level_t level)
 {
 	listener_t *l;
 
-	switch_mutex_lock(listen_list.mutex);
+	switch_mutex_lock(globals.listener_mutex);
 	for (l = listen_list.listeners; l; l = l->next) {
 		if (switch_test_flag(l, LFLAG_LOG) && l->level >= node->level) {
 			char *data = strdup(node->data);
@@ -160,7 +159,7 @@
 			}
 		}
 	}
-	switch_mutex_unlock(listen_list.mutex);
+	switch_mutex_unlock(globals.listener_mutex);
 
 	return SWITCH_STATUS_SUCCESS;
 }
@@ -212,7 +211,7 @@
 
 	lp = listen_list.listeners;
 
-	switch_mutex_lock(listen_list.mutex);
+	switch_mutex_lock(globals.listener_mutex);
 	while(lp) {
 		int send = 0;
 		
@@ -321,7 +320,7 @@
 		}
 
 	}
-	switch_mutex_unlock(listen_list.mutex);
+	switch_mutex_unlock(globals.listener_mutex);
 }
 
 SWITCH_STANDARD_APP(socket_function)
@@ -415,12 +414,15 @@
 	if (switch_test_flag(listener, LFLAG_ASYNC)) {
 		launch_listener_thread(listener);
 		switch_ivr_park(session, NULL);
+		return;
 	} else {
 		listener_run(NULL, (void *) listener);
 	}
 
-	while (switch_test_flag(listener, LFLAG_SESSION)) {
-		switch_yield(100000);
+	if (switch_channel_get_state(channel) >= CS_HANGUP) {
+		while (switch_test_flag(listener, LFLAG_SESSION)) {
+			switch_yield(100000);
+		}
 	}
 
 }
@@ -456,11 +458,11 @@
 	}
 	switch_event_unbind(&globals.node);
 
-	switch_mutex_lock(listen_list.mutex);
+	switch_mutex_lock(globals.listener_mutex);
 	for (l = listen_list.listeners; l; l = l->next) {
 		close_socket(&l->sock);
 	}
-	switch_mutex_unlock(listen_list.mutex);
+	switch_mutex_unlock(globals.listener_mutex);
 
 
 
@@ -470,17 +472,17 @@
 static void add_listener(listener_t *listener)
 {
 	/* add me to the listeners so I get events */
-	switch_mutex_lock(listen_list.mutex);
+	switch_mutex_lock(globals.listener_mutex);
 	listener->next = listen_list.listeners;
 	listen_list.listeners = listener;
-	switch_mutex_unlock(listen_list.mutex);
+	switch_mutex_unlock(globals.listener_mutex);
 }
 
 static void remove_listener(listener_t *listener)
 {
 	listener_t *l, *last = NULL;
 
-	switch_mutex_lock(listen_list.mutex);
+	switch_mutex_lock(globals.listener_mutex);
 	for (l = listen_list.listeners; l; l = l->next) {
 		if (l == listener) {
 			if (last) {
@@ -491,7 +493,7 @@
 		}
 		last = l;
 	}
-	switch_mutex_unlock(listen_list.mutex);
+	switch_mutex_unlock(globals.listener_mutex);
 }
 
 
@@ -499,7 +501,7 @@
 {
 	listener_t *l, *r = NULL;
 
-	switch_mutex_lock(listen_list.mutex);
+	switch_mutex_lock(globals.listener_mutex);
 	for (l = listen_list.listeners; l; l = l->next) {
 		if (l->id && l->id == id) {
 			if (switch_thread_rwlock_tryrdlock(l->rwlock) == SWITCH_STATUS_SUCCESS) {
@@ -508,7 +510,7 @@
 			break;
 		}
 	}
-	switch_mutex_unlock(listen_list.mutex);
+	switch_mutex_unlock(globals.listener_mutex);
 	return r;
 }
 
@@ -530,7 +532,7 @@
 	stream->write_function(stream, " </listener>\n");
 }
 
-SWITCH_STANDARD_API(event_manager_function)
+SWITCH_STANDARD_API(event_sink_function)
 {
 	char *http = NULL;
 	char *wcmd = NULL;
@@ -561,9 +563,62 @@
 		format = "xml";
 	}
 
-	
-	
-	if (!strcasecmp(wcmd, "create-listener")) {
+
+	if (!strcasecmp(wcmd, "filter")) {
+		char *action = switch_event_get_header(stream->param_event, "action");
+		char *header_name = switch_event_get_header(stream->param_event, "header-name");
+		char *header_val = switch_event_get_header(stream->param_event, "header-val");
+		char *id = switch_event_get_header(stream->param_event, "listen-id");
+		uint32_t idl = 0;
+
+		if (id) {
+			idl = (uint32_t) atol(id);
+		}
+
+		if (!(listener = find_listener(idl))) {
+			stream->write_function(stream, "<data><reply type=\"error\">Invalid Listen-ID</reply></data>\n");
+            goto end;
+		}
+
+		if (switch_strlen_zero(action)) {
+			stream->write_function(stream, "<data><reply type=\"error\">Invalid Syntax</reply></data>\n");
+            goto end;
+		}
+
+		switch_mutex_lock(listener->filter_mutex);		
+		if (!listener->filters) {
+			switch_event_create(&listener->filters, SWITCH_EVENT_CHANNEL_DATA);
+		}
+
+		if (!strcasecmp(action, "delete")) {
+			if (switch_strlen_zero(header_val)) {
+				stream->write_function(stream, "<data><reply type=\"error\">Invalid Syntax</reply></data>\n");
+				goto filter_end;
+			}
+
+			if (!strcasecmp(header_val, "all")) {
+				switch_event_destroy(&listener->filters);
+				switch_event_create(&listener->filters, SWITCH_EVENT_CHANNEL_DATA);
+			} else {
+				switch_event_del_header(listener->filters, header_val);
+			}
+			stream->write_function(stream, "<data>\n <reply type=\"success\">filter deleted.</reply>\n<api-command>\n");
+		} else if (!strcasecmp(action, "add")) {
+			if (switch_strlen_zero(header_name) || switch_strlen_zero(header_val)) {
+				stream->write_function(stream, "<data><reply type=\"error\">Invalid Syntax</reply></data>\n");
+				goto filter_end;
+			}
+			switch_event_add_header_string(listener->filters, SWITCH_STACK_BOTTOM, header_name, header_val);
+			stream->write_function(stream, "<data>\n <reply type=\"success\">filter added.</reply>\n<api-command>\n");
+		} else {
+			stream->write_function(stream, "<data><reply type=\"error\">Invalid Syntax</reply></data>\n");
+		}
+
+	filter_end:
+
+		switch_mutex_unlock(listener->filter_mutex);
+
+	} else if (!strcasecmp(wcmd, "create-listener")) {
 		char *events = switch_event_get_header(stream->param_event, "events");
 		switch_memory_pool_t *pool;
 		char *next, *cur;
@@ -755,10 +810,19 @@
 	switch_application_interface_t *app_interface;
 	switch_api_interface_t *api_interface;
 
+	switch_mutex_init(&globals.listener_mutex, SWITCH_MUTEX_NESTED, pool);
+
+	if (switch_event_bind_removable(modname, SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL, &globals.node) != SWITCH_STATUS_SUCCESS) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
+		return SWITCH_STATUS_GENERR;
+	}
+	
+	switch_log_bind_logger(socket_logger, SWITCH_LOG_DEBUG, SWITCH_FALSE);
+
 	/* connect my internal structure to the blank pointer passed to me */
 	*module_interface = switch_loadable_module_create_module_interface(pool, modname);
 	SWITCH_ADD_APP(app_interface, "socket", "Connect to a socket", "Connect to a socket", socket_function, "<ip>[:<port>]", SAF_SUPPORT_NOMEDIA);
-	SWITCH_ADD_API(api_interface, "event_manager", "event_manager", event_manager_function, "<web data>");
+	SWITCH_ADD_API(api_interface, "event_sink", "event_sink", event_sink_function, "<web data>");
 
 	/* indicate that the module should continue to be loaded */
 	return SWITCH_STATUS_SUCCESS;
@@ -985,7 +1049,7 @@
 			}
 		}
 		if (do_sleep) {
-			switch_yield(1000);
+			switch_cond_next();
 		}
 	}
 
@@ -1250,6 +1314,7 @@
 			listener->event_list[SWITCH_EVENT_CHANNEL_EXECUTE_COMPLETE] = 1;
 			listener->event_list[SWITCH_EVENT_CHANNEL_HANGUP] = 1;
 			listener->event_list[SWITCH_EVENT_CHANNEL_ORIGINATE] = 1;
+			listener->event_list[SWITCH_EVENT_CHANNEL_UUID] = 1;
 			listener->event_list[SWITCH_EVENT_CHANNEL_OUTGOING] = 1;
 			listener->event_list[SWITCH_EVENT_CHANNEL_PARK] = 1;
 			listener->event_list[SWITCH_EVENT_CHANNEL_PROGRESS] = 1;
@@ -1590,11 +1655,16 @@
 	switch_channel_t *channel = NULL;
 	switch_event_t *revent = NULL;
 
-	switch_mutex_lock(listen_list.mutex);
+	switch_mutex_lock(globals.listener_mutex);
 	prefs.threads++;
-	switch_mutex_unlock(listen_list.mutex);
-
+	switch_mutex_unlock(globals.listener_mutex);
+	
 	switch_assert(listener != NULL);
+	
+	if ((session = listener->session)) {
+		channel = switch_core_session_get_channel(session);
+		switch_core_session_read_lock(session);
+	}
 
 	if (prefs.acl_count && listener->sa && !switch_strlen_zero(listener->remote_ip)) {
 		uint32_t x = 0;
@@ -1615,13 +1685,7 @@
 			}
 		}
 	}
-
-
-	if ((session = listener->session)) {
-		channel = switch_core_session_get_channel(session);
-		switch_core_session_read_lock(session);
-	}
-
+	
 	if (switch_strlen_zero(listener->remote_ip)) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connection Open\n");
 	} else {
@@ -1784,9 +1848,9 @@
 		switch_core_destroy_memory_pool(&pool);
 	}
 
-	switch_mutex_lock(listen_list.mutex);
+	switch_mutex_lock(globals.listener_mutex);
 	prefs.threads--;
-	switch_mutex_unlock(listen_list.mutex);
+	switch_mutex_unlock(globals.listener_mutex);
 
 	return NULL;
 }
@@ -1870,7 +1934,7 @@
 		return SWITCH_STATUS_TERM;
 	}
 
-	switch_mutex_init(&listen_list.mutex, SWITCH_MUTEX_NESTED, pool);
+
 	switch_mutex_init(&listen_list.sock_mutex, SWITCH_MUTEX_NESTED, pool);
 
 
@@ -1899,13 +1963,6 @@
 
 	listen_list.ready = 1;
 
-	if (switch_event_bind_removable(modname, SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL, &globals.node) != SWITCH_STATUS_SUCCESS) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
-		return SWITCH_STATUS_GENERR;
-	}
-
-	switch_log_bind_logger(socket_logger, SWITCH_LOG_DEBUG, SWITCH_FALSE);
-
 
 	for (;;) {
 		if (switch_core_new_memory_pool(&listener_pool) != SWITCH_STATUS_SUCCESS) {

Modified: freeswitch/branches/gmaruzz/src/mod/event_handlers/mod_radius_cdr/mod_radius_cdr.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/event_handlers/mod_radius_cdr/mod_radius_cdr.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/event_handlers/mod_radius_cdr/mod_radius_cdr.c	Mon Nov 17 14:18:32 2008
@@ -36,7 +36,13 @@
 #include "mod_radius_cdr.h"
 
 SWITCH_MODULE_LOAD_FUNCTION(mod_radius_cdr_load);
-SWITCH_MODULE_DEFINITION(mod_radius_cdr, mod_radius_cdr_load, NULL, NULL);
+SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_radius_cdr_shutdown);
+SWITCH_MODULE_DEFINITION(mod_radius_cdr, mod_radius_cdr_load, mod_radius_cdr_shutdown, NULL);
+
+static struct {
+	int shutdown;
+	switch_thread_rwlock_t *rwlock;
+} globals = { 0 };
 
 static char cf[] = "mod_radius_cdr.conf";
 static char my_dictionary[PATH_MAX];
@@ -129,7 +135,7 @@
 	switch_xml_t cdr;
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 	rc_handle *rad_config;
-	int retval = 0;
+	switch_status_t retval = SWITCH_STATUS_TERM;
 	VALUE_PAIR *send = NULL;
 	uint32_t client_port = 0;
 	uint32_t status_type = PW_STATUS_START;
@@ -145,18 +151,24 @@
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "[mod_radius_cdr] Entering my_on_routing\n");
 
+	if (globals.shutdown) {
+		return SWITCH_STATUS_FALSE;
+	}
+
+	switch_thread_rwlock_rdlock(globals.rwlock);
+
 	rad_config = my_radius_init();
 
 	if (rad_config == NULL) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[mod_radius_cdr] Error initializing radius, Start packet not logged.\n");
-		return SWITCH_STATUS_TERM;
+		goto end;
 	}
 
 	if (switch_ivr_generate_xml_cdr(session, &cdr) == SWITCH_STATUS_SUCCESS) {
 		uuid_str = switch_core_session_get_uuid(session);
 	} else {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[mod_radius_cdr] Error Generating Data!\n");
-		return SWITCH_STATUS_TERM;
+		goto end;
 	}
 
 	/* Create the radius packet */
@@ -165,13 +177,13 @@
 	if (rc_avpair_add(rad_config, &send, PW_ACCT_STATUS_TYPE, &status_type, -1, 0) == NULL) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[mod_radius_cdr] Failed setting Acct-Status-Type: Start\n");
 		rc_destroy(rad_config);
-		return SWITCH_STATUS_TERM;
+		goto end;
 	}
 
 	if (rc_avpair_add(rad_config, &send, PW_ACCT_SESSION_ID, uuid_str, -1, 0) == NULL) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[mod_radius_cdr] Failed adding Acct-Session-ID: %s\n", uuid_str);
 		rc_destroy(rad_config);
-		return SWITCH_STATUS_TERM;
+		goto end;
 	}
 
 	/* Add VSAs */
@@ -202,77 +214,77 @@
 				if (rc_avpair_add(rad_config, &send, PW_USER_NAME, (void *) profile->username, -1, 0) == NULL) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding User-Name: %s\n", profile->username);
 					rc_destroy(rad_config);
-					return SWITCH_STATUS_TERM;
+					goto end;
 				}
 			}
 			if (profile->caller_id_number) {
 				if (rc_avpair_add(rad_config, &send, PW_FS_SRC, (void *) profile->caller_id_number, -1, PW_FS_PEC) == NULL) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Src: %s\n", profile->caller_id_number);
 					rc_destroy(rad_config);
-					return SWITCH_STATUS_TERM;
+					goto end;
 				}
 			}
 			if (profile->caller_id_name) {
 				if (rc_avpair_add(rad_config, &send, PW_FS_CLID, (void *) profile->caller_id_name, -1, PW_FS_PEC) == NULL) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-CLID: %s\n", profile->caller_id_name);
 					rc_destroy(rad_config);
-					return SWITCH_STATUS_TERM;
+					goto end;
 				}
 			}
 			if (profile->destination_number) {
 				if (rc_avpair_add(rad_config, &send, PW_FS_DST, (void *) profile->destination_number, -1, PW_FS_PEC) == NULL) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Dst: %s\n", profile->destination_number);
 					rc_destroy(rad_config);
-					return SWITCH_STATUS_TERM;
+					goto end;
 				}
 			}
 			if (profile->dialplan) {
 				if (rc_avpair_add(rad_config, &send, PW_FS_DIALPLAN, (void *) profile->dialplan, -1, PW_FS_PEC) == NULL) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Dialplan: %s\n", profile->dialplan);
 					rc_destroy(rad_config);
-					return SWITCH_STATUS_TERM;
+					goto end;
 				}
 			}
 			if (profile->network_addr) {
 				if (rc_avpair_add(rad_config, &send, PW_FRAMED_IP_ADDRESS, (void *) profile->network_addr, -1, 0) == NULL) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Framed-IP-Address: %s\n", profile->network_addr);
 					rc_destroy(rad_config);
-					return SWITCH_STATUS_TERM;
+					goto end;
 				}
 			}
 			if (profile->rdnis) {
 				if (rc_avpair_add(rad_config, &send, PW_FS_RDNIS, (void *) profile->rdnis, -1, PW_FS_PEC) == NULL) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-RDNIS: %s\n", profile->rdnis);
 					rc_destroy(rad_config);
-					return SWITCH_STATUS_TERM;
+					goto end;
 				}
 			}
 			if (profile->context) {
 				if (rc_avpair_add(rad_config, &send, PW_FS_CONTEXT, (void *) profile->context, -1, PW_FS_PEC) == NULL) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Context: %s\n", profile->context);
 					rc_destroy(rad_config);
-					return SWITCH_STATUS_TERM;
+					goto end;
 				}
 			}
 			if (profile->ani) {
 				if (rc_avpair_add(rad_config, &send, PW_FS_ANI, (void *) profile->ani, -1, PW_FS_PEC) == NULL) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-ANI: %s\n", profile->ani);
 					rc_destroy(rad_config);
-					return SWITCH_STATUS_TERM;
+					goto end;
 				}
 			}
 			if (profile->aniii) {
 				if (rc_avpair_add(rad_config, &send, PW_FS_ANIII, (void *) profile->aniii, -1, PW_FS_PEC) == NULL) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-ANIII: %s\n", profile->aniii);
 					rc_destroy(rad_config);
-					return SWITCH_STATUS_TERM;
+					goto end;
 				}
 			}
 			if (profile->source) {
 				if (rc_avpair_add(rad_config, &send, PW_FS_SOURCE, (void *) profile->source, -1, PW_FS_PEC) == NULL) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Source: %s\n", profile->source);
 					rc_destroy(rad_config);
-					return SWITCH_STATUS_TERM;
+					goto end;
 				}
 			}
 			if (callstartdate > 0) {
@@ -283,7 +295,7 @@
 				if (rc_avpair_add(rad_config, &send, PW_FS_CALLSTARTDATE, &buffer, -1, PW_FS_PEC) == NULL) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Callstartdate: %s\n", buffer);
 					rc_destroy(rad_config);
-					return SWITCH_STATUS_TERM;
+					goto end;
 				}
 			}
 
@@ -295,7 +307,7 @@
 				if (rc_avpair_add(rad_config, &send, PW_FS_CALLANSWERDATE, &buffer, -1, PW_FS_PEC) == NULL) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Callanswerdate: %s\n", buffer);
 					rc_destroy(rad_config);
-					return SWITCH_STATUS_TERM;
+					goto end;
 				}
 			}
 
@@ -307,7 +319,7 @@
 				if (rc_avpair_add(rad_config, &send, PW_FS_CALLTRANSFERDATE, &buffer, -1, PW_FS_PEC) == NULL) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Calltransferdate: %s\n", buffer);
 					rc_destroy(rad_config);
-					return SWITCH_STATUS_TERM;
+					goto end;
 				}
 			}
 
@@ -319,7 +331,7 @@
 				if (rc_avpair_add(rad_config, &send, PW_FS_CALLENDDATE, &buffer, -1, PW_FS_PEC) == NULL) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Callenddate: %s\n", buffer);
 					rc_destroy(rad_config);
-					return SWITCH_STATUS_TERM;
+					goto end;
 				}
 			}
 
@@ -328,7 +340,7 @@
 								  (void *) profile->caller_extension->last_application->application_name, -1, PW_FS_PEC) == NULL) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Lastapp: %s\n", profile->source);
 					rc_destroy(rad_config);
-					return SWITCH_STATUS_TERM;
+					goto end;
 				}
 			}
 		} else {
@@ -344,7 +356,8 @@
 		retval = SWITCH_STATUS_TERM;
 	}
 	rc_avpair_free(send);
-
+ end:
+	switch_thread_rwlock_unlock(globals.rwlock);
 	return (retval);
 }
 
@@ -353,7 +366,7 @@
 	switch_xml_t cdr;
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 	rc_handle *rad_config;
-	int retval = 0;
+	switch_status_t retval = SWITCH_STATUS_TERM;
 	VALUE_PAIR *send = NULL;
 	uint32_t client_port = 0;
 	uint32_t status_type = PW_STATUS_STOP;
@@ -368,20 +381,26 @@
 	switch_time_exp_t tm;
 	char buffer[32] = "";
 
+	if (globals.shutdown) {
+		return SWITCH_STATUS_FALSE;
+	}
+
+	switch_thread_rwlock_rdlock(globals.rwlock);
+
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "[mod_radius_cdr] Entering my_on_hangup\n");
 
 	rad_config = my_radius_init();
 
 	if (rad_config == NULL) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[mod_radius_cdr] Error initializing radius, session not logged.\n");
-		return SWITCH_STATUS_TERM;
+		goto end;
 	}
 
 	if (switch_ivr_generate_xml_cdr(session, &cdr) == SWITCH_STATUS_SUCCESS) {
 		uuid_str = switch_core_session_get_uuid(session);
 	} else {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[mod_radius_cdr] Error Generating Data!\n");
-		return SWITCH_STATUS_TERM;
+		goto end;
 	}
 
 	/* Create the radius packet */
@@ -390,13 +409,13 @@
 	if (rc_avpair_add(rad_config, &send, PW_ACCT_STATUS_TYPE, &status_type, -1, 0) == NULL) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Acct-Session-ID: %s\n", uuid_str);
 		rc_destroy(rad_config);
-		return SWITCH_STATUS_TERM;
+		goto end;
 	}
 
 	if (rc_avpair_add(rad_config, &send, PW_ACCT_SESSION_ID, uuid_str, -1, 0) == NULL) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Acct-Session-ID: %s\n", uuid_str);
 		rc_destroy(rad_config);
-		return SWITCH_STATUS_TERM;
+		goto end;
 	}
 
 	/* Add VSAs */
@@ -409,7 +428,7 @@
 		if (rc_avpair_add(rad_config, &send, PW_FS_HANGUPCAUSE, &cause, -1, PW_FS_PEC) == NULL) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Hangupcause: %d\n", cause);
 			rc_destroy(rad_config);
-			return SWITCH_STATUS_TERM;
+			goto end;
 		}
 
 		profile = switch_channel_get_caller_profile(channel);
@@ -443,77 +462,77 @@
 				if (rc_avpair_add(rad_config, &send, PW_USER_NAME, (void *) profile->username, -1, 0) == NULL) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding User-Name: %s\n", profile->username);
 					rc_destroy(rad_config);
-					return SWITCH_STATUS_TERM;
+					goto end;
 				}
 			}
 			if (profile->caller_id_number) {
 				if (rc_avpair_add(rad_config, &send, PW_FS_SRC, (void *) profile->caller_id_number, -1, PW_FS_PEC) == NULL) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Src: %s\n", profile->caller_id_number);
 					rc_destroy(rad_config);
-					return SWITCH_STATUS_TERM;
+					goto end;
 				}
 			}
 			if (profile->caller_id_name) {
 				if (rc_avpair_add(rad_config, &send, PW_FS_CLID, (void *) profile->caller_id_name, -1, PW_FS_PEC) == NULL) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-CLID: %s\n", profile->caller_id_name);
 					rc_destroy(rad_config);
-					return SWITCH_STATUS_TERM;
+					goto end;
 				}
 			}
 			if (profile->destination_number) {
 				if (rc_avpair_add(rad_config, &send, PW_FS_DST, (void *) profile->destination_number, -1, PW_FS_PEC) == NULL) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Dst: %s\n", profile->destination_number);
 					rc_destroy(rad_config);
-					return SWITCH_STATUS_TERM;
+					goto end;
 				}
 			}
 			if (profile->dialplan) {
 				if (rc_avpair_add(rad_config, &send, PW_FS_DIALPLAN, (void *) profile->dialplan, -1, PW_FS_PEC) == NULL) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Dialplan: %s\n", profile->dialplan);
 					rc_destroy(rad_config);
-					return SWITCH_STATUS_TERM;
+					goto end;
 				}
 			}
 			if (profile->network_addr) {
 				if (rc_avpair_add(rad_config, &send, PW_FRAMED_IP_ADDRESS, (void *) profile->network_addr, -1, 0) == NULL) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Framed-IP-Address: %s\n", profile->network_addr);
 					rc_destroy(rad_config);
-					return SWITCH_STATUS_TERM;
+					goto end;
 				}
 			}
 			if (profile->rdnis) {
 				if (rc_avpair_add(rad_config, &send, PW_FS_RDNIS, (void *) profile->rdnis, -1, PW_FS_PEC) == NULL) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-RDNIS: %s\n", profile->rdnis);
 					rc_destroy(rad_config);
-					return SWITCH_STATUS_TERM;
+					goto end;
 				}
 			}
 			if (profile->context) {
 				if (rc_avpair_add(rad_config, &send, PW_FS_CONTEXT, (void *) profile->context, -1, PW_FS_PEC) == NULL) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Context: %s\n", profile->context);
 					rc_destroy(rad_config);
-					return SWITCH_STATUS_TERM;
+					goto end;
 				}
 			}
 			if (profile->ani) {
 				if (rc_avpair_add(rad_config, &send, PW_FS_ANI, (void *) profile->ani, -1, PW_FS_PEC) == NULL) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-ANI: %s\n", profile->ani);
 					rc_destroy(rad_config);
-					return SWITCH_STATUS_TERM;
+					goto end;
 				}
 			}
 			if (profile->aniii) {
 				if (rc_avpair_add(rad_config, &send, PW_FS_ANIII, (void *) profile->aniii, -1, PW_FS_PEC) == NULL) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-ANIII: %s\n", profile->aniii);
 					rc_destroy(rad_config);
-					return SWITCH_STATUS_TERM;
+					goto end;
 				}
 			}
 			if (profile->source) {
 				if (rc_avpair_add(rad_config, &send, PW_FS_SOURCE, (void *) profile->source, -1, PW_FS_PEC) == NULL) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Source: %s\n", profile->source);
 					rc_destroy(rad_config);
-					return SWITCH_STATUS_TERM;
+					goto end;
 				}
 			}
 			if (profile->caller_extension && profile->caller_extension->last_application->application_name) {
@@ -521,13 +540,13 @@
 								  (void *) profile->caller_extension->last_application->application_name, -1, PW_FS_PEC) == NULL) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Lastapp: %s\n", profile->source);
 					rc_destroy(rad_config);
-					return SWITCH_STATUS_TERM;
+					goto end;
 				}
 			}
 			if (rc_avpair_add(rad_config, &send, PW_FS_BILLUSEC, &billusec, -1, PW_FS_PEC) == NULL) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Billusec: %u\n", (uint32_t) billusec);
 				rc_destroy(rad_config);
-				return SWITCH_STATUS_TERM;
+				goto end;
 			}
 
 			if (callstartdate > 0) {
@@ -538,7 +557,7 @@
 				if (rc_avpair_add(rad_config, &send, PW_FS_CALLSTARTDATE, &buffer, -1, PW_FS_PEC) == NULL) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Callstartdate: %s\n", buffer);
 					rc_destroy(rad_config);
-					return SWITCH_STATUS_TERM;
+					goto end;
 				}
 			}
 
@@ -550,7 +569,7 @@
 				if (rc_avpair_add(rad_config, &send, PW_FS_CALLANSWERDATE, &buffer, -1, PW_FS_PEC) == NULL) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Callanswerdate: %s\n", buffer);
 					rc_destroy(rad_config);
-					return SWITCH_STATUS_TERM;
+					goto end;
 				}
 			}
 
@@ -562,7 +581,7 @@
 				if (rc_avpair_add(rad_config, &send, PW_FS_CALLTRANSFERDATE, &buffer, -1, PW_FS_PEC) == NULL) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Calltransferdate: %s\n", buffer);
 					rc_destroy(rad_config);
-					return SWITCH_STATUS_TERM;
+					goto end;
 				}
 			}
 
@@ -574,14 +593,14 @@
 				if (rc_avpair_add(rad_config, &send, PW_FS_CALLENDDATE, &buffer, -1, PW_FS_PEC) == NULL) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Callenddate: %s\n", buffer);
 					rc_destroy(rad_config);
-					return SWITCH_STATUS_TERM;
+					goto end;
 				}
 			}
 
 			if (rc_avpair_add(rad_config, &send, PW_ACCT_SESSION_TIME, &billsec, -1, 0) == NULL) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Acct-Session-Time: %u\n", billsec);
 				rc_destroy(rad_config);
-				return SWITCH_STATUS_TERM;
+				goto end;
 			}
 		} else {				/* no profile, can't create data to send */
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "profile == NULL\n");
@@ -597,6 +616,8 @@
 	}
 	rc_avpair_free(send);
 
+ end:
+	switch_thread_rwlock_unlock(globals.rwlock);
 	return (retval);
 }
 
@@ -671,6 +692,9 @@
 
 SWITCH_MODULE_LOAD_FUNCTION(mod_radius_cdr_load)
 {
+
+	switch_thread_rwlock_create(&globals.rwlock, pool);
+
 	if (load_config() != SWITCH_STATUS_SUCCESS) {
 		return SWITCH_STATUS_TERM;
 	}
@@ -684,6 +708,18 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
+
+SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_radius_cdr_shutdown)
+{
+
+	globals.shutdown = 1;
+	switch_core_remove_state_handler(&state_handlers);
+	switch_thread_rwlock_wrlock(globals.rwlock);
+	switch_thread_rwlock_unlock(globals.rwlock);
+
+	return SWITCH_STATUS_SUCCESS;
+}
+
 /* For Emacs:
  * Local Variables:
  * mode:c

Modified: freeswitch/branches/gmaruzz/src/mod/event_handlers/mod_zeroconf/mod_zeroconf.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/event_handlers/mod_zeroconf/mod_zeroconf.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/event_handlers/mod_zeroconf/mod_zeroconf.c	Mon Nov 17 14:18:32 2008
@@ -303,7 +303,7 @@
 		sw_uint32 ms;
 		ms = 100;
 		sw_discovery_step(globals.discovery, &ms);
-		switch_yield(1000);
+		switch_cond_next();
 	}
 	RUNNING = 0;
 	return SWITCH_STATUS_TERM;

Modified: freeswitch/branches/gmaruzz/src/mod/formats/mod_local_stream/mod_local_stream.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/formats/mod_local_stream/mod_local_stream.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/formats/mod_local_stream/mod_local_stream.c	Mon Nov 17 14:18:32 2008
@@ -32,7 +32,7 @@
  */
 #include <switch.h>
 /* for apr_pstrcat */
-#define DEFAULT_PREBUFFER_SIZE 1024 * 16
+#define DEFAULT_PREBUFFER_SIZE 1024 * 32
 
 SWITCH_MODULE_LOAD_FUNCTION(mod_local_stream_load);
 SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_local_stream_shutdown);
@@ -249,6 +249,11 @@
 	}
 
  done:
+
+	if (fh.file_interface) {
+		switch_core_file_close(&fh);
+	}
+
 	source->ready = 0;
 	switch_mutex_lock(globals.mutex);
 	switch_core_hash_delete(globals.source_hash, source->name);

Modified: freeswitch/branches/gmaruzz/src/mod/formats/mod_shout/mod_shout.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/formats/mod_shout/mod_shout.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/formats/mod_shout/mod_shout.c	Mon Nov 17 14:18:32 2008
@@ -1195,7 +1195,7 @@
 				switch_buffer_unlock(buffer);
 			} else {
 				if (!bytes) {
-					switch_yield(1000);
+					switch_cond_next();
 					continue;
 				}
 				memset(buf, 0, bytes);

Modified: freeswitch/branches/gmaruzz/src/mod/languages/mod_lua/mod_lua.cpp
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/languages/mod_lua/mod_lua.cpp	(original)
+++ freeswitch/branches/gmaruzz/src/mod/languages/mod_lua/mod_lua.cpp	Mon Nov 17 14:18:32 2008
@@ -40,8 +40,7 @@
 SWITCH_MODULE_LOAD_FUNCTION(mod_lua_load);
 SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_lua_shutdown);
 
-SWITCH_MODULE_DEFINITION(mod_lua, mod_lua_load, mod_lua_shutdown, NULL);
-
+SWITCH_MODULE_DEFINITION_EX(mod_lua, mod_lua_load, mod_lua_shutdown, NULL, SMODF_GLOBAL_SYMBOLS);
 static struct {
 	switch_memory_pool_t *pool;
 	char *xml_handler;

Modified: freeswitch/branches/gmaruzz/src/mod/languages/mod_managed/Makefile
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/languages/mod_managed/Makefile	(original)
+++ freeswitch/branches/gmaruzz/src/mod/languages/mod_managed/Makefile	Mon Nov 17 14:18:32 2008
@@ -20,8 +20,8 @@
 local_depend:
 	cd managed && $(MAKE)
 
-local_install: $(MODINSTDIR)/mod_managed.so 
-	cd managed && $(MAKE) INSTALL="$(LTINSTALL)" MODINSTDIR=$(MODINSTDIR) install
+local_install: $(DESTDIR)$(MODINSTDIR)/mod_managed.so 
+	cd managed && $(MAKE) INSTALL="$(LTINSTALL)" MODINSTDIR=$(MODINSTDIR) DESTDIR=$(DESTDIR) install
 
 local_uninstall:
 	rm -fr $(MODINSTDIR)/mod_managed.so

Modified: freeswitch/branches/gmaruzz/src/mod/languages/mod_managed/freeswitch_wrap.cxx
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/languages/mod_managed/freeswitch_wrap.cxx	(original)
+++ freeswitch/branches/gmaruzz/src/mod/languages/mod_managed/freeswitch_wrap.cxx	Mon Nov 17 14:18:32 2008
@@ -1378,6 +1378,17 @@
 }
 
 
+SWIGEXPORT char * SWIGSTDCALL CSharp_SWITCH_PARK_AFTER_BRIDGE_VARIABLE_get() {
+  char * jresult ;
+  char *result = 0 ;
+  
+  result = (char *) "park_after_bridge";
+  
+  jresult = SWIG_csharp_string_callback((const char *)result); 
+  return jresult;
+}
+
+
 SWIGEXPORT char * SWIGSTDCALL CSharp_SWITCH_EXEC_AFTER_BRIDGE_APP_VARIABLE_get() {
   char * jresult ;
   char *result = 0 ;
@@ -2683,7 +2694,7 @@
   int jresult ;
   int result;
   
-  result = (int) 1;
+  result = (int) 3;
   
   jresult = result; 
   return jresult;
@@ -2782,6 +2793,29 @@
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_loadable_module_function_table_t_flags_set(void * jarg1, unsigned long jarg2) {
+  switch_loadable_module_function_table_t *arg1 = (switch_loadable_module_function_table_t *) 0 ;
+  switch_module_flag_t arg2 ;
+  
+  arg1 = (switch_loadable_module_function_table_t *)jarg1; 
+  arg2 = (switch_module_flag_t)jarg2; 
+  if (arg1) (arg1)->flags = arg2;
+  
+}
+
+
+SWIGEXPORT unsigned long SWIGSTDCALL CSharp_switch_loadable_module_function_table_t_flags_get(void * jarg1) {
+  unsigned long jresult ;
+  switch_loadable_module_function_table_t *arg1 = (switch_loadable_module_function_table_t *) 0 ;
+  switch_module_flag_t result;
+  
+  arg1 = (switch_loadable_module_function_table_t *)jarg1; 
+  result = (switch_module_flag_t) ((arg1)->flags);
+  jresult = (unsigned long)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void * SWIGSTDCALL CSharp_new_switch_loadable_module_function_table_t() {
   void * jresult ;
   switch_loadable_module_function_table_t *result = 0 ;
@@ -4190,6 +4224,87 @@
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_core_session_message__file_set(void * jarg1, char * jarg2) {
+  switch_core_session_message *arg1 = (switch_core_session_message *) 0 ;
+  char *arg2 = (char *) 0 ;
+  
+  arg1 = (switch_core_session_message *)jarg1; 
+  arg2 = (char *)jarg2; 
+  {
+    if (arg2) {
+      arg1->_file = (char const *) (new char[strlen((const char *)arg2)+1]);
+      strcpy((char *)arg1->_file, (const char *)arg2);
+    } else {
+      arg1->_file = 0;
+    }
+  }
+}
+
+
+SWIGEXPORT char * SWIGSTDCALL CSharp_switch_core_session_message__file_get(void * jarg1) {
+  char * jresult ;
+  switch_core_session_message *arg1 = (switch_core_session_message *) 0 ;
+  char *result = 0 ;
+  
+  arg1 = (switch_core_session_message *)jarg1; 
+  result = (char *) ((arg1)->_file);
+  jresult = SWIG_csharp_string_callback((const char *)result); 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_core_session_message__func_set(void * jarg1, char * jarg2) {
+  switch_core_session_message *arg1 = (switch_core_session_message *) 0 ;
+  char *arg2 = (char *) 0 ;
+  
+  arg1 = (switch_core_session_message *)jarg1; 
+  arg2 = (char *)jarg2; 
+  {
+    if (arg2) {
+      arg1->_func = (char const *) (new char[strlen((const char *)arg2)+1]);
+      strcpy((char *)arg1->_func, (const char *)arg2);
+    } else {
+      arg1->_func = 0;
+    }
+  }
+}
+
+
+SWIGEXPORT char * SWIGSTDCALL CSharp_switch_core_session_message__func_get(void * jarg1) {
+  char * jresult ;
+  switch_core_session_message *arg1 = (switch_core_session_message *) 0 ;
+  char *result = 0 ;
+  
+  arg1 = (switch_core_session_message *)jarg1; 
+  result = (char *) ((arg1)->_func);
+  jresult = SWIG_csharp_string_callback((const char *)result); 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_core_session_message__line_set(void * jarg1, int jarg2) {
+  switch_core_session_message *arg1 = (switch_core_session_message *) 0 ;
+  int arg2 ;
+  
+  arg1 = (switch_core_session_message *)jarg1; 
+  arg2 = (int)jarg2; 
+  if (arg1) (arg1)->_line = arg2;
+  
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_session_message__line_get(void * jarg1) {
+  int jresult ;
+  switch_core_session_message *arg1 = (switch_core_session_message *) 0 ;
+  int result;
+  
+  arg1 = (switch_core_session_message *)jarg1; 
+  result = (int) ((arg1)->_line);
+  jresult = result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void * SWIGSTDCALL CSharp_new_switch_core_session_message() {
   void * jresult ;
   switch_core_session_message *result = 0 ;
@@ -4544,6 +4659,26 @@
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_core_media_bug_flush(void * jarg1) {
+  switch_media_bug_t *arg1 = (switch_media_bug_t *) 0 ;
+  
+  arg1 = (switch_media_bug_t *)jarg1; 
+  switch_core_media_bug_flush(arg1);
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_media_bug_flush_all(void * jarg1) {
+  int jresult ;
+  switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
+  switch_status_t result;
+  
+  arg1 = (switch_core_session_t *)jarg1; 
+  result = (switch_status_t)switch_core_media_bug_flush_all(arg1);
+  jresult = result; 
+  return jresult;
+}
+
+
 SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_port_allocator_new(unsigned short jarg1, unsigned short jarg2, unsigned long jarg3, void * jarg4) {
   int jresult ;
   switch_port_t arg1 ;
@@ -4966,20 +5101,36 @@
 }
 
 
-SWIGEXPORT void * SWIGSTDCALL CSharp_switch_core_session_request(void * jarg1, void * jarg2) {
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_core_session_request_uuid(void * jarg1, void * jarg2, char * jarg3) {
   void * jresult ;
   switch_endpoint_interface_t *arg1 = (switch_endpoint_interface_t *) 0 ;
   switch_memory_pool_t **arg2 = (switch_memory_pool_t **) 0 ;
+  char *arg3 = (char *) 0 ;
   switch_core_session_t *result = 0 ;
   
   arg1 = (switch_endpoint_interface_t *)jarg1; 
   arg2 = (switch_memory_pool_t **)jarg2; 
-  result = (switch_core_session_t *)switch_core_session_request((switch_endpoint_interface const *)arg1,arg2);
+  arg3 = (char *)jarg3; 
+  result = (switch_core_session_t *)switch_core_session_request_uuid(arg1,arg2,(char const *)arg3);
   jresult = (void *)result; 
   return jresult;
 }
 
 
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_session_set_uuid(void * jarg1, char * jarg2) {
+  int jresult ;
+  switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
+  char *arg2 = (char *) 0 ;
+  switch_status_t result;
+  
+  arg1 = (switch_core_session_t *)jarg1; 
+  arg2 = (char *)jarg2; 
+  result = (switch_status_t)switch_core_session_set_uuid(arg1,(char const *)arg2);
+  jresult = result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_core_session_perform_destroy(void * jarg1, char * jarg2, char * jarg3, int jarg4) {
   switch_core_session_t **arg1 = (switch_core_session_t **) 0 ;
   char *arg2 = (char *) 0 ;
@@ -5474,15 +5625,21 @@
 }
 
 
-SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_session_receive_message(void * jarg1, void * jarg2) {
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_session_perform_receive_message(void * jarg1, void * jarg2, char * jarg3, char * jarg4, int jarg5) {
   int jresult ;
   switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
   switch_core_session_message_t *arg2 = (switch_core_session_message_t *) 0 ;
+  char *arg3 = (char *) 0 ;
+  char *arg4 = (char *) 0 ;
+  int arg5 ;
   switch_status_t result;
   
   arg1 = (switch_core_session_t *)jarg1; 
   arg2 = (switch_core_session_message_t *)jarg2; 
-  result = (switch_status_t)switch_core_session_receive_message(arg1,arg2);
+  arg3 = (char *)jarg3; 
+  arg4 = (char *)jarg4; 
+  arg5 = (int)jarg5; 
+  result = (switch_status_t)switch_core_session_perform_receive_message(arg1,arg2,(char const *)arg3,(char const *)arg4,arg5);
   jresult = result; 
   return jresult;
 }
@@ -5724,15 +5881,17 @@
 }
 
 
-SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_hash_init(void * jarg1, void * jarg2) {
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_hash_init_case(void * jarg1, void * jarg2, int jarg3) {
   int jresult ;
   switch_hash_t **arg1 = (switch_hash_t **) 0 ;
   switch_memory_pool_t *arg2 = (switch_memory_pool_t *) 0 ;
+  switch_bool_t arg3 ;
   switch_status_t result;
   
   arg1 = (switch_hash_t **)jarg1; 
   arg2 = (switch_memory_pool_t *)jarg2; 
-  result = (switch_status_t)switch_core_hash_init(arg1,arg2);
+  arg3 = (switch_bool_t)jarg3; 
+  result = (switch_status_t)switch_core_hash_init_case(arg1,arg2,arg3);
   jresult = result; 
   return jresult;
 }
@@ -7242,6 +7401,25 @@
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_cond_yield(void * jarg1) {
+  switch_interval_time_t arg1 ;
+  switch_interval_time_t *argp1 ;
+  
+  argp1 = (switch_interval_time_t *)jarg1; 
+  if (!argp1) {
+    SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null switch_interval_time_t", 0);
+    return ;
+  }
+  arg1 = *argp1; 
+  switch_cond_yield(arg1);
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_cond_next() {
+  switch_cond_next();
+}
+
+
 SWIGEXPORT int SWIGSTDCALL CSharp_SWITCH_CMD_CHUNK_LEN_get() {
   int jresult ;
   int result;
@@ -7568,6 +7746,30 @@
 }
 
 
+SWIGEXPORT char * SWIGSTDCALL CSharp_switch_lc_strdup(char * jarg1) {
+  char * jresult ;
+  char *arg1 = (char *) 0 ;
+  char *result = 0 ;
+  
+  arg1 = (char *)jarg1; 
+  result = (char *)switch_lc_strdup((char const *)arg1);
+  jresult = SWIG_csharp_string_callback((const char *)result); 
+  return jresult;
+}
+
+
+SWIGEXPORT char * SWIGSTDCALL CSharp_switch_uc_strdup(char * jarg1) {
+  char * jresult ;
+  char *arg1 = (char *) 0 ;
+  char *result = 0 ;
+  
+  arg1 = (char *)jarg1; 
+  result = (char *)switch_uc_strdup((char const *)arg1);
+  jresult = SWIG_csharp_string_callback((const char *)result); 
+  return jresult;
+}
+
+
 SWIGEXPORT int SWIGSTDCALL CSharp_switch_strstr(char * jarg1, char * jarg2) {
   int jresult ;
   char *arg1 = (char *) 0 ;
@@ -10482,6 +10684,52 @@
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_endpoint_interface_refs_set(void * jarg1, int jarg2) {
+  switch_endpoint_interface *arg1 = (switch_endpoint_interface *) 0 ;
+  int arg2 ;
+  
+  arg1 = (switch_endpoint_interface *)jarg1; 
+  arg2 = (int)jarg2; 
+  if (arg1) (arg1)->refs = arg2;
+  
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_endpoint_interface_refs_get(void * jarg1) {
+  int jresult ;
+  switch_endpoint_interface *arg1 = (switch_endpoint_interface *) 0 ;
+  int result;
+  
+  arg1 = (switch_endpoint_interface *)jarg1; 
+  result = (int) ((arg1)->refs);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_endpoint_interface_parent_set(void * jarg1, void * jarg2) {
+  switch_endpoint_interface *arg1 = (switch_endpoint_interface *) 0 ;
+  switch_loadable_module_interface_t *arg2 = (switch_loadable_module_interface_t *) 0 ;
+  
+  arg1 = (switch_endpoint_interface *)jarg1; 
+  arg2 = (switch_loadable_module_interface_t *)jarg2; 
+  if (arg1) (arg1)->parent = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_endpoint_interface_parent_get(void * jarg1) {
+  void * jresult ;
+  switch_endpoint_interface *arg1 = (switch_endpoint_interface *) 0 ;
+  switch_loadable_module_interface_t *result = 0 ;
+  
+  arg1 = (switch_endpoint_interface *)jarg1; 
+  result = (switch_loadable_module_interface_t *) ((arg1)->parent);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_endpoint_interface_next_set(void * jarg1, void * jarg2) {
   switch_endpoint_interface *arg1 = (switch_endpoint_interface *) 0 ;
   switch_endpoint_interface *arg2 = (switch_endpoint_interface *) 0 ;
@@ -10952,6 +11200,52 @@
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_timer_interface_refs_set(void * jarg1, int jarg2) {
+  switch_timer_interface *arg1 = (switch_timer_interface *) 0 ;
+  int arg2 ;
+  
+  arg1 = (switch_timer_interface *)jarg1; 
+  arg2 = (int)jarg2; 
+  if (arg1) (arg1)->refs = arg2;
+  
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_timer_interface_refs_get(void * jarg1) {
+  int jresult ;
+  switch_timer_interface *arg1 = (switch_timer_interface *) 0 ;
+  int result;
+  
+  arg1 = (switch_timer_interface *)jarg1; 
+  result = (int) ((arg1)->refs);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_timer_interface_parent_set(void * jarg1, void * jarg2) {
+  switch_timer_interface *arg1 = (switch_timer_interface *) 0 ;
+  switch_loadable_module_interface_t *arg2 = (switch_loadable_module_interface_t *) 0 ;
+  
+  arg1 = (switch_timer_interface *)jarg1; 
+  arg2 = (switch_loadable_module_interface_t *)jarg2; 
+  if (arg1) (arg1)->parent = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_timer_interface_parent_get(void * jarg1) {
+  void * jresult ;
+  switch_timer_interface *arg1 = (switch_timer_interface *) 0 ;
+  switch_loadable_module_interface_t *result = 0 ;
+  
+  arg1 = (switch_timer_interface *)jarg1; 
+  result = (switch_loadable_module_interface_t *) ((arg1)->parent);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_timer_interface_next_set(void * jarg1, void * jarg2) {
   switch_timer_interface *arg1 = (switch_timer_interface *) 0 ;
   switch_timer_interface *arg2 = (switch_timer_interface *) 0 ;
@@ -11069,35 +11363,81 @@
 }
 
 
-SWIGEXPORT void SWIGSTDCALL CSharp_switch_dialplan_interface_next_set(void * jarg1, void * jarg2) {
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_dialplan_interface_refs_set(void * jarg1, int jarg2) {
   switch_dialplan_interface *arg1 = (switch_dialplan_interface *) 0 ;
-  switch_dialplan_interface *arg2 = (switch_dialplan_interface *) 0 ;
+  int arg2 ;
   
   arg1 = (switch_dialplan_interface *)jarg1; 
-  arg2 = (switch_dialplan_interface *)jarg2; 
-  if (arg1) (arg1)->next = arg2;
+  arg2 = (int)jarg2; 
+  if (arg1) (arg1)->refs = arg2;
   
 }
 
 
-SWIGEXPORT void * SWIGSTDCALL CSharp_switch_dialplan_interface_next_get(void * jarg1) {
-  void * jresult ;
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_dialplan_interface_refs_get(void * jarg1) {
+  int jresult ;
   switch_dialplan_interface *arg1 = (switch_dialplan_interface *) 0 ;
-  switch_dialplan_interface *result = 0 ;
+  int result;
   
   arg1 = (switch_dialplan_interface *)jarg1; 
-  result = (switch_dialplan_interface *) ((arg1)->next);
-  jresult = (void *)result; 
+  result = (int) ((arg1)->refs);
+  jresult = result; 
   return jresult;
 }
 
 
-SWIGEXPORT void * SWIGSTDCALL CSharp_new_switch_dialplan_interface() {
-  void * jresult ;
-  switch_dialplan_interface *result = 0 ;
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_dialplan_interface_parent_set(void * jarg1, void * jarg2) {
+  switch_dialplan_interface *arg1 = (switch_dialplan_interface *) 0 ;
+  switch_loadable_module_interface_t *arg2 = (switch_loadable_module_interface_t *) 0 ;
   
-  result = (switch_dialplan_interface *)new switch_dialplan_interface();
-  jresult = (void *)result; 
+  arg1 = (switch_dialplan_interface *)jarg1; 
+  arg2 = (switch_loadable_module_interface_t *)jarg2; 
+  if (arg1) (arg1)->parent = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_dialplan_interface_parent_get(void * jarg1) {
+  void * jresult ;
+  switch_dialplan_interface *arg1 = (switch_dialplan_interface *) 0 ;
+  switch_loadable_module_interface_t *result = 0 ;
+  
+  arg1 = (switch_dialplan_interface *)jarg1; 
+  result = (switch_loadable_module_interface_t *) ((arg1)->parent);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_dialplan_interface_next_set(void * jarg1, void * jarg2) {
+  switch_dialplan_interface *arg1 = (switch_dialplan_interface *) 0 ;
+  switch_dialplan_interface *arg2 = (switch_dialplan_interface *) 0 ;
+  
+  arg1 = (switch_dialplan_interface *)jarg1; 
+  arg2 = (switch_dialplan_interface *)jarg2; 
+  if (arg1) (arg1)->next = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_dialplan_interface_next_get(void * jarg1) {
+  void * jresult ;
+  switch_dialplan_interface *arg1 = (switch_dialplan_interface *) 0 ;
+  switch_dialplan_interface *result = 0 ;
+  
+  arg1 = (switch_dialplan_interface *)jarg1; 
+  result = (switch_dialplan_interface *) ((arg1)->next);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_new_switch_dialplan_interface() {
+  void * jresult ;
+  switch_dialplan_interface *result = 0 ;
+  
+  result = (switch_dialplan_interface *)new switch_dialplan_interface();
+  jresult = (void *)result; 
   return jresult;
 }
 
@@ -11347,6 +11687,52 @@
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_file_interface_refs_set(void * jarg1, int jarg2) {
+  switch_file_interface *arg1 = (switch_file_interface *) 0 ;
+  int arg2 ;
+  
+  arg1 = (switch_file_interface *)jarg1; 
+  arg2 = (int)jarg2; 
+  if (arg1) (arg1)->refs = arg2;
+  
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_file_interface_refs_get(void * jarg1) {
+  int jresult ;
+  switch_file_interface *arg1 = (switch_file_interface *) 0 ;
+  int result;
+  
+  arg1 = (switch_file_interface *)jarg1; 
+  result = (int) ((arg1)->refs);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_file_interface_parent_set(void * jarg1, void * jarg2) {
+  switch_file_interface *arg1 = (switch_file_interface *) 0 ;
+  switch_loadable_module_interface_t *arg2 = (switch_loadable_module_interface_t *) 0 ;
+  
+  arg1 = (switch_file_interface *)jarg1; 
+  arg2 = (switch_loadable_module_interface_t *)jarg2; 
+  if (arg1) (arg1)->parent = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_file_interface_parent_get(void * jarg1) {
+  void * jresult ;
+  switch_file_interface *arg1 = (switch_file_interface *) 0 ;
+  switch_loadable_module_interface_t *result = 0 ;
+  
+  arg1 = (switch_file_interface *)jarg1; 
+  result = (switch_loadable_module_interface_t *) ((arg1)->parent);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_file_interface_next_set(void * jarg1, void * jarg2) {
   switch_file_interface *arg1 = (switch_file_interface *) 0 ;
   switch_file_interface *arg2 = (switch_file_interface *) 0 ;
@@ -11395,7 +11781,7 @@
   
   arg1 = (switch_file_handle *)jarg1; 
   arg2 = (switch_file_interface_t *)jarg2; 
-  if (arg1) (arg1)->file_interface = (switch_file_interface_t const *)arg2;
+  if (arg1) (arg1)->file_interface = arg2;
   
 }
 
@@ -12434,6 +12820,52 @@
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_asr_interface_refs_set(void * jarg1, int jarg2) {
+  switch_asr_interface *arg1 = (switch_asr_interface *) 0 ;
+  int arg2 ;
+  
+  arg1 = (switch_asr_interface *)jarg1; 
+  arg2 = (int)jarg2; 
+  if (arg1) (arg1)->refs = arg2;
+  
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_asr_interface_refs_get(void * jarg1) {
+  int jresult ;
+  switch_asr_interface *arg1 = (switch_asr_interface *) 0 ;
+  int result;
+  
+  arg1 = (switch_asr_interface *)jarg1; 
+  result = (int) ((arg1)->refs);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_asr_interface_parent_set(void * jarg1, void * jarg2) {
+  switch_asr_interface *arg1 = (switch_asr_interface *) 0 ;
+  switch_loadable_module_interface_t *arg2 = (switch_loadable_module_interface_t *) 0 ;
+  
+  arg1 = (switch_asr_interface *)jarg1; 
+  arg2 = (switch_loadable_module_interface_t *)jarg2; 
+  if (arg1) (arg1)->parent = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_asr_interface_parent_get(void * jarg1) {
+  void * jresult ;
+  switch_asr_interface *arg1 = (switch_asr_interface *) 0 ;
+  switch_loadable_module_interface_t *result = 0 ;
+  
+  arg1 = (switch_asr_interface *)jarg1; 
+  result = (switch_loadable_module_interface_t *) ((arg1)->parent);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_asr_interface_next_set(void * jarg1, void * jarg2) {
   switch_asr_interface *arg1 = (switch_asr_interface *) 0 ;
   switch_asr_interface *arg2 = (switch_asr_interface *) 0 ;
@@ -12482,7 +12914,7 @@
   
   arg1 = (switch_asr_handle *)jarg1; 
   arg2 = (switch_asr_interface_t *)jarg2; 
-  if (arg1) (arg1)->asr_interface = (switch_asr_interface_t const *)arg2;
+  if (arg1) (arg1)->asr_interface = arg2;
   
 }
 
@@ -12966,6 +13398,52 @@
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_speech_interface_refs_set(void * jarg1, int jarg2) {
+  switch_speech_interface *arg1 = (switch_speech_interface *) 0 ;
+  int arg2 ;
+  
+  arg1 = (switch_speech_interface *)jarg1; 
+  arg2 = (int)jarg2; 
+  if (arg1) (arg1)->refs = arg2;
+  
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_speech_interface_refs_get(void * jarg1) {
+  int jresult ;
+  switch_speech_interface *arg1 = (switch_speech_interface *) 0 ;
+  int result;
+  
+  arg1 = (switch_speech_interface *)jarg1; 
+  result = (int) ((arg1)->refs);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_speech_interface_parent_set(void * jarg1, void * jarg2) {
+  switch_speech_interface *arg1 = (switch_speech_interface *) 0 ;
+  switch_loadable_module_interface_t *arg2 = (switch_loadable_module_interface_t *) 0 ;
+  
+  arg1 = (switch_speech_interface *)jarg1; 
+  arg2 = (switch_loadable_module_interface_t *)jarg2; 
+  if (arg1) (arg1)->parent = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_speech_interface_parent_get(void * jarg1) {
+  void * jresult ;
+  switch_speech_interface *arg1 = (switch_speech_interface *) 0 ;
+  switch_loadable_module_interface_t *result = 0 ;
+  
+  arg1 = (switch_speech_interface *)jarg1; 
+  result = (switch_loadable_module_interface_t *) ((arg1)->parent);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_speech_interface_next_set(void * jarg1, void * jarg2) {
   switch_speech_interface *arg1 = (switch_speech_interface *) 0 ;
   switch_speech_interface *arg2 = (switch_speech_interface *) 0 ;
@@ -13014,7 +13492,7 @@
   
   arg1 = (switch_speech_handle *)jarg1; 
   arg2 = (switch_speech_interface_t *)jarg2; 
-  if (arg1) (arg1)->speech_interface = (switch_speech_interface_t const *)arg2;
+  if (arg1) (arg1)->speech_interface = arg2;
   
 }
 
@@ -13378,6 +13856,52 @@
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_say_interface_refs_set(void * jarg1, int jarg2) {
+  switch_say_interface *arg1 = (switch_say_interface *) 0 ;
+  int arg2 ;
+  
+  arg1 = (switch_say_interface *)jarg1; 
+  arg2 = (int)jarg2; 
+  if (arg1) (arg1)->refs = arg2;
+  
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_say_interface_refs_get(void * jarg1) {
+  int jresult ;
+  switch_say_interface *arg1 = (switch_say_interface *) 0 ;
+  int result;
+  
+  arg1 = (switch_say_interface *)jarg1; 
+  result = (int) ((arg1)->refs);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_say_interface_parent_set(void * jarg1, void * jarg2) {
+  switch_say_interface *arg1 = (switch_say_interface *) 0 ;
+  switch_loadable_module_interface_t *arg2 = (switch_loadable_module_interface_t *) 0 ;
+  
+  arg1 = (switch_say_interface *)jarg1; 
+  arg2 = (switch_loadable_module_interface_t *)jarg2; 
+  if (arg1) (arg1)->parent = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_say_interface_parent_get(void * jarg1) {
+  void * jresult ;
+  switch_say_interface *arg1 = (switch_say_interface *) 0 ;
+  switch_loadable_module_interface_t *result = 0 ;
+  
+  arg1 = (switch_say_interface *)jarg1; 
+  result = (switch_loadable_module_interface_t *) ((arg1)->parent);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_say_interface_next_set(void * jarg1, void * jarg2) {
   switch_say_interface *arg1 = (switch_say_interface *) 0 ;
   switch_say_interface *arg2 = (switch_say_interface *) 0 ;
@@ -13495,6 +14019,52 @@
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_chat_interface_refs_set(void * jarg1, int jarg2) {
+  switch_chat_interface *arg1 = (switch_chat_interface *) 0 ;
+  int arg2 ;
+  
+  arg1 = (switch_chat_interface *)jarg1; 
+  arg2 = (int)jarg2; 
+  if (arg1) (arg1)->refs = arg2;
+  
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_chat_interface_refs_get(void * jarg1) {
+  int jresult ;
+  switch_chat_interface *arg1 = (switch_chat_interface *) 0 ;
+  int result;
+  
+  arg1 = (switch_chat_interface *)jarg1; 
+  result = (int) ((arg1)->refs);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_chat_interface_parent_set(void * jarg1, void * jarg2) {
+  switch_chat_interface *arg1 = (switch_chat_interface *) 0 ;
+  switch_loadable_module_interface_t *arg2 = (switch_loadable_module_interface_t *) 0 ;
+  
+  arg1 = (switch_chat_interface *)jarg1; 
+  arg2 = (switch_loadable_module_interface_t *)jarg2; 
+  if (arg1) (arg1)->parent = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_chat_interface_parent_get(void * jarg1) {
+  void * jresult ;
+  switch_chat_interface *arg1 = (switch_chat_interface *) 0 ;
+  switch_loadable_module_interface_t *result = 0 ;
+  
+  arg1 = (switch_chat_interface *)jarg1; 
+  result = (switch_loadable_module_interface_t *) ((arg1)->parent);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_chat_interface_next_set(void * jarg1, void * jarg2) {
   switch_chat_interface *arg1 = (switch_chat_interface *) 0 ;
   switch_chat_interface *arg2 = (switch_chat_interface *) 0 ;
@@ -13612,6 +14182,52 @@
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_management_interface_refs_set(void * jarg1, int jarg2) {
+  switch_management_interface *arg1 = (switch_management_interface *) 0 ;
+  int arg2 ;
+  
+  arg1 = (switch_management_interface *)jarg1; 
+  arg2 = (int)jarg2; 
+  if (arg1) (arg1)->refs = arg2;
+  
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_management_interface_refs_get(void * jarg1) {
+  int jresult ;
+  switch_management_interface *arg1 = (switch_management_interface *) 0 ;
+  int result;
+  
+  arg1 = (switch_management_interface *)jarg1; 
+  result = (int) ((arg1)->refs);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_management_interface_parent_set(void * jarg1, void * jarg2) {
+  switch_management_interface *arg1 = (switch_management_interface *) 0 ;
+  switch_loadable_module_interface_t *arg2 = (switch_loadable_module_interface_t *) 0 ;
+  
+  arg1 = (switch_management_interface *)jarg1; 
+  arg2 = (switch_loadable_module_interface_t *)jarg2; 
+  if (arg1) (arg1)->parent = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_management_interface_parent_get(void * jarg1) {
+  void * jresult ;
+  switch_management_interface *arg1 = (switch_management_interface *) 0 ;
+  switch_loadable_module_interface_t *result = 0 ;
+  
+  arg1 = (switch_management_interface *)jarg1; 
+  result = (switch_loadable_module_interface_t *) ((arg1)->parent);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_management_interface_next_set(void * jarg1, void * jarg2) {
   switch_management_interface *arg1 = (switch_management_interface *) 0 ;
   switch_management_interface *arg2 = (switch_management_interface *) 0 ;
@@ -13821,6 +14437,52 @@
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_directory_interface_refs_set(void * jarg1, int jarg2) {
+  switch_directory_interface *arg1 = (switch_directory_interface *) 0 ;
+  int arg2 ;
+  
+  arg1 = (switch_directory_interface *)jarg1; 
+  arg2 = (int)jarg2; 
+  if (arg1) (arg1)->refs = arg2;
+  
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_directory_interface_refs_get(void * jarg1) {
+  int jresult ;
+  switch_directory_interface *arg1 = (switch_directory_interface *) 0 ;
+  int result;
+  
+  arg1 = (switch_directory_interface *)jarg1; 
+  result = (int) ((arg1)->refs);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_directory_interface_parent_set(void * jarg1, void * jarg2) {
+  switch_directory_interface *arg1 = (switch_directory_interface *) 0 ;
+  switch_loadable_module_interface_t *arg2 = (switch_loadable_module_interface_t *) 0 ;
+  
+  arg1 = (switch_directory_interface *)jarg1; 
+  arg2 = (switch_loadable_module_interface_t *)jarg2; 
+  if (arg1) (arg1)->parent = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_directory_interface_parent_get(void * jarg1) {
+  void * jresult ;
+  switch_directory_interface *arg1 = (switch_directory_interface *) 0 ;
+  switch_loadable_module_interface_t *result = 0 ;
+  
+  arg1 = (switch_directory_interface *)jarg1; 
+  result = (switch_loadable_module_interface_t *) ((arg1)->parent);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_directory_interface_next_set(void * jarg1, void * jarg2) {
   switch_directory_interface *arg1 = (switch_directory_interface *) 0 ;
   switch_directory_interface *arg2 = (switch_directory_interface *) 0 ;
@@ -13869,7 +14531,7 @@
   
   arg1 = (switch_directory_handle *)jarg1; 
   arg2 = (switch_directory_interface_t *)jarg2; 
-  if (arg1) (arg1)->directory_interface = (switch_directory_interface_t const *)arg2;
+  if (arg1) (arg1)->directory_interface = arg2;
   
 }
 
@@ -14367,7 +15029,7 @@
   
   arg1 = (switch_codec *)jarg1; 
   arg2 = (switch_codec_interface_t *)jarg2; 
-  if (arg1) (arg1)->codec_interface = (switch_codec_interface_t const *)arg2;
+  if (arg1) (arg1)->codec_interface = arg2;
   
 }
 
@@ -14582,6 +15244,29 @@
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_codec_mutex_set(void * jarg1, void * jarg2) {
+  switch_codec *arg1 = (switch_codec *) 0 ;
+  switch_mutex_t *arg2 = (switch_mutex_t *) 0 ;
+  
+  arg1 = (switch_codec *)jarg1; 
+  arg2 = (switch_mutex_t *)jarg2; 
+  if (arg1) (arg1)->mutex = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_codec_mutex_get(void * jarg1) {
+  void * jresult ;
+  switch_codec *arg1 = (switch_codec *) 0 ;
+  switch_mutex_t *result = 0 ;
+  
+  arg1 = (switch_codec *)jarg1; 
+  result = (switch_mutex_t *) ((arg1)->mutex);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void * SWIGSTDCALL CSharp_new_switch_codec() {
   void * jresult ;
   switch_codec *result = 0 ;
@@ -15169,6 +15854,52 @@
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_codec_interface_refs_set(void * jarg1, int jarg2) {
+  switch_codec_interface *arg1 = (switch_codec_interface *) 0 ;
+  int arg2 ;
+  
+  arg1 = (switch_codec_interface *)jarg1; 
+  arg2 = (int)jarg2; 
+  if (arg1) (arg1)->refs = arg2;
+  
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_codec_interface_refs_get(void * jarg1) {
+  int jresult ;
+  switch_codec_interface *arg1 = (switch_codec_interface *) 0 ;
+  int result;
+  
+  arg1 = (switch_codec_interface *)jarg1; 
+  result = (int) ((arg1)->refs);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_codec_interface_parent_set(void * jarg1, void * jarg2) {
+  switch_codec_interface *arg1 = (switch_codec_interface *) 0 ;
+  switch_loadable_module_interface_t *arg2 = (switch_loadable_module_interface_t *) 0 ;
+  
+  arg1 = (switch_codec_interface *)jarg1; 
+  arg2 = (switch_loadable_module_interface_t *)jarg2; 
+  if (arg1) (arg1)->parent = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_codec_interface_parent_get(void * jarg1) {
+  void * jresult ;
+  switch_codec_interface *arg1 = (switch_codec_interface *) 0 ;
+  switch_loadable_module_interface_t *result = 0 ;
+  
+  arg1 = (switch_codec_interface *)jarg1; 
+  result = (switch_loadable_module_interface_t *) ((arg1)->parent);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_codec_interface_next_set(void * jarg1, void * jarg2) {
   switch_codec_interface *arg1 = (switch_codec_interface *) 0 ;
   switch_codec_interface *arg2 = (switch_codec_interface *) 0 ;
@@ -15396,6 +16127,52 @@
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_application_interface_refs_set(void * jarg1, int jarg2) {
+  switch_application_interface *arg1 = (switch_application_interface *) 0 ;
+  int arg2 ;
+  
+  arg1 = (switch_application_interface *)jarg1; 
+  arg2 = (int)jarg2; 
+  if (arg1) (arg1)->refs = arg2;
+  
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_application_interface_refs_get(void * jarg1) {
+  int jresult ;
+  switch_application_interface *arg1 = (switch_application_interface *) 0 ;
+  int result;
+  
+  arg1 = (switch_application_interface *)jarg1; 
+  result = (int) ((arg1)->refs);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_application_interface_parent_set(void * jarg1, void * jarg2) {
+  switch_application_interface *arg1 = (switch_application_interface *) 0 ;
+  switch_loadable_module_interface_t *arg2 = (switch_loadable_module_interface_t *) 0 ;
+  
+  arg1 = (switch_application_interface *)jarg1; 
+  arg2 = (switch_loadable_module_interface_t *)jarg2; 
+  if (arg1) (arg1)->parent = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_application_interface_parent_get(void * jarg1) {
+  void * jresult ;
+  switch_application_interface *arg1 = (switch_application_interface *) 0 ;
+  switch_loadable_module_interface_t *result = 0 ;
+  
+  arg1 = (switch_application_interface *)jarg1; 
+  result = (switch_loadable_module_interface_t *) ((arg1)->parent);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_application_interface_next_set(void * jarg1, void * jarg2) {
   switch_application_interface *arg1 = (switch_application_interface *) 0 ;
   switch_application_interface *arg2 = (switch_application_interface *) 0 ;
@@ -15571,6 +16348,52 @@
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_api_interface_refs_set(void * jarg1, int jarg2) {
+  switch_api_interface *arg1 = (switch_api_interface *) 0 ;
+  int arg2 ;
+  
+  arg1 = (switch_api_interface *)jarg1; 
+  arg2 = (int)jarg2; 
+  if (arg1) (arg1)->refs = arg2;
+  
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_api_interface_refs_get(void * jarg1) {
+  int jresult ;
+  switch_api_interface *arg1 = (switch_api_interface *) 0 ;
+  int result;
+  
+  arg1 = (switch_api_interface *)jarg1; 
+  result = (int) ((arg1)->refs);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_api_interface_parent_set(void * jarg1, void * jarg2) {
+  switch_api_interface *arg1 = (switch_api_interface *) 0 ;
+  switch_loadable_module_interface_t *arg2 = (switch_loadable_module_interface_t *) 0 ;
+  
+  arg1 = (switch_api_interface *)jarg1; 
+  arg2 = (switch_loadable_module_interface_t *)jarg2; 
+  if (arg1) (arg1)->parent = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_api_interface_parent_get(void * jarg1) {
+  void * jresult ;
+  switch_api_interface *arg1 = (switch_api_interface *) 0 ;
+  switch_loadable_module_interface_t *result = 0 ;
+  
+  arg1 = (switch_api_interface *)jarg1; 
+  result = (switch_loadable_module_interface_t *) ((arg1)->parent);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_api_interface_next_set(void * jarg1, void * jarg2) {
   switch_api_interface *arg1 = (switch_api_interface *) 0 ;
   switch_api_interface *arg2 = (switch_api_interface *) 0 ;
@@ -17083,6 +17906,29 @@
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_event_header_hash_set(void * jarg1, unsigned long jarg2) {
+  switch_event_header *arg1 = (switch_event_header *) 0 ;
+  unsigned long arg2 ;
+  
+  arg1 = (switch_event_header *)jarg1; 
+  arg2 = (unsigned long)jarg2; 
+  if (arg1) (arg1)->hash = arg2;
+  
+}
+
+
+SWIGEXPORT unsigned long SWIGSTDCALL CSharp_switch_event_header_hash_get(void * jarg1) {
+  unsigned long jresult ;
+  switch_event_header *arg1 = (switch_event_header *) 0 ;
+  unsigned long result;
+  
+  arg1 = (switch_event_header *)jarg1; 
+  result = (unsigned long) ((arg1)->hash);
+  jresult = (unsigned long)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_event_header_next_set(void * jarg1, void * jarg2) {
   switch_event_header *arg1 = (switch_event_header *) 0 ;
   switch_event_header *arg2 = (switch_event_header *) 0 ;
@@ -19212,7 +20058,7 @@
 }
 
 
-SWIGEXPORT int SWIGSTDCALL CSharp_switch_play_and_get_digits(void * jarg1, unsigned long jarg2, unsigned long jarg3, unsigned long jarg4, unsigned long jarg5, char * jarg6, char * jarg7, char * jarg8, void * jarg9, unsigned long jarg10, char * jarg11) {
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_play_and_get_digits(void * jarg1, unsigned long jarg2, unsigned long jarg3, unsigned long jarg4, unsigned long jarg5, char * jarg6, char * jarg7, char * jarg8, char * jarg9, unsigned long jarg10, char * jarg11) {
   int jresult ;
   switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
   uint32_t arg2 ;
@@ -19222,7 +20068,7 @@
   char *arg6 = (char *) 0 ;
   char *arg7 = (char *) 0 ;
   char *arg8 = (char *) 0 ;
-  void *arg9 = (void *) 0 ;
+  char *arg9 = (char *) 0 ;
   uint32_t arg10 ;
   char *arg11 = (char *) 0 ;
   switch_status_t result;
@@ -19235,7 +20081,7 @@
   arg6 = (char *)jarg6; 
   arg7 = (char *)jarg7; 
   arg8 = (char *)jarg8; 
-  arg9 = (void *)jarg9; 
+  arg9 = (char *)jarg9; 
   arg10 = (uint32_t)jarg10; 
   arg11 = (char *)jarg11; 
   result = (switch_status_t)switch_play_and_get_digits(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11);
@@ -20397,6 +21243,18 @@
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_rtp_change_interval(void * jarg1, unsigned long jarg2, unsigned long jarg3) {
+  switch_rtp_t *arg1 = (switch_rtp_t *) 0 ;
+  uint32_t arg2 ;
+  uint32_t arg3 ;
+  
+  arg1 = (switch_rtp_t *)jarg1; 
+  arg2 = (uint32_t)jarg2; 
+  arg3 = (uint32_t)jarg3; 
+  switch_rtp_change_interval(arg1,arg2,arg3);
+}
+
+
 SWIGEXPORT int SWIGSTDCALL CSharp_switch_rtp_create(void * jarg1, unsigned char jarg2, unsigned long jarg3, unsigned long jarg4, unsigned long jarg5, char * jarg6, void * jarg7, void * jarg8) {
   int jresult ;
   switch_rtp_t **arg1 = (switch_rtp_t **) 0 ;
@@ -20639,12 +21497,12 @@
 }
 
 
-SWIGEXPORT void SWIGSTDCALL CSharp_switch_rtp_set_default_samples_per_interval(void * jarg1, unsigned short jarg2) {
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_rtp_set_default_samples_per_interval(void * jarg1, unsigned long jarg2) {
   switch_rtp_t *arg1 = (switch_rtp_t *) 0 ;
-  uint16_t arg2 ;
+  uint32_t arg2 ;
   
   arg1 = (switch_rtp_t *)jarg1; 
-  arg2 = (uint16_t)jarg2; 
+  arg2 = (uint32_t)jarg2; 
   switch_rtp_set_default_samples_per_interval(arg1,arg2);
 }
 
@@ -22041,17 +22899,63 @@
 }
 
 
-SWIGEXPORT int SWIGSTDCALL CSharp_switch_xml_bind_search_function(void * jarg1, unsigned long jarg2, void * jarg3) {
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_xml_set_binding_sections(void * jarg1, unsigned long jarg2) {
+  switch_xml_binding_t *arg1 = (switch_xml_binding_t *) 0 ;
+  switch_xml_section_t arg2 ;
+  
+  arg1 = (switch_xml_binding_t *)jarg1; 
+  arg2 = (switch_xml_section_t)jarg2; 
+  switch_xml_set_binding_sections(arg1,arg2);
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_xml_set_binding_user_data(void * jarg1, void * jarg2) {
+  switch_xml_binding_t *arg1 = (switch_xml_binding_t *) 0 ;
+  void *arg2 = (void *) 0 ;
+  
+  arg1 = (switch_xml_binding_t *)jarg1; 
+  arg2 = (void *)jarg2; 
+  switch_xml_set_binding_user_data(arg1,arg2);
+}
+
+
+SWIGEXPORT unsigned long SWIGSTDCALL CSharp_switch_xml_get_binding_sections(void * jarg1) {
+  unsigned long jresult ;
+  switch_xml_binding_t *arg1 = (switch_xml_binding_t *) 0 ;
+  switch_xml_section_t result;
+  
+  arg1 = (switch_xml_binding_t *)jarg1; 
+  result = (switch_xml_section_t)switch_xml_get_binding_sections(arg1);
+  jresult = (unsigned long)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_xml_get_binding_user_data(void * jarg1) {
+  void * jresult ;
+  switch_xml_binding_t *arg1 = (switch_xml_binding_t *) 0 ;
+  void *result = 0 ;
+  
+  arg1 = (switch_xml_binding_t *)jarg1; 
+  result = (void *)switch_xml_get_binding_user_data(arg1);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_xml_bind_search_function_ret(void * jarg1, unsigned long jarg2, void * jarg3, void * jarg4) {
   int jresult ;
   switch_xml_search_function_t arg1 = (switch_xml_search_function_t) 0 ;
   switch_xml_section_t arg2 ;
   void *arg3 = (void *) 0 ;
+  switch_xml_binding_t **arg4 = (switch_xml_binding_t **) 0 ;
   switch_status_t result;
   
   arg1 = (switch_xml_search_function_t)jarg1; 
   arg2 = (switch_xml_section_t)jarg2; 
   arg3 = (void *)jarg3; 
-  result = (switch_status_t)switch_xml_bind_search_function(arg1,arg2,arg3);
+  arg4 = (switch_xml_binding_t **)jarg4; 
+  result = (switch_status_t)switch_xml_bind_search_function_ret(arg1,arg2,arg3,arg4);
   jresult = result; 
   return jresult;
 }

Modified: freeswitch/branches/gmaruzz/src/mod/languages/mod_managed/managed/Makefile
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/languages/mod_managed/managed/Makefile	(original)
+++ freeswitch/branches/gmaruzz/src/mod/languages/mod_managed/managed/Makefile	Mon Nov 17 14:18:32 2008
@@ -7,7 +7,7 @@
 	gmcs -target:library -out:mod_managed_lib.dll -d:DEBUG Loader.cs ManagedSession.cs ApiFunction.cs AppFunction.cs Extensions.cs Log.cs Demo.cs swig.cs
 
 install: mod_managed_lib.dll
-	$(INSTALL) mod_managed_lib.dll $(MODINSTDIR)
+	$(INSTALL) mod_managed_lib.dll $(DESTDIR)$(MODINSTDIR)
 
 uninstall:
 	$(UNINSTALL) $(MODINSTDIR)/mod_managed_lib.dll

Modified: freeswitch/branches/gmaruzz/src/mod/languages/mod_managed/managed/swig.cs
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/languages/mod_managed/managed/swig.cs	(original)
+++ freeswitch/branches/gmaruzz/src/mod/languages/mod_managed/managed/swig.cs	Mon Nov 17 14:18:32 2008
@@ -926,6 +926,15 @@
     return ret;
   }
 
+  public static void switch_core_media_bug_flush(SWIGTYPE_p_switch_media_bug bug) {
+    freeswitchPINVOKE.switch_core_media_bug_flush(SWIGTYPE_p_switch_media_bug.getCPtr(bug));
+  }
+
+  public static switch_status_t switch_core_media_bug_flush_all(SWIGTYPE_p_switch_core_session session) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_core_media_bug_flush_all(SWIGTYPE_p_switch_core_session.getCPtr(session));
+    return ret;
+  }
+
   public static switch_status_t switch_core_port_allocator_new(ushort start, ushort end, uint flags, SWIGTYPE_p_p_switch_core_port_allocator new_allocator) {
     switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_core_port_allocator_new(start, end, flags, SWIGTYPE_p_p_switch_core_port_allocator.getCPtr(new_allocator));
     return ret;
@@ -1073,12 +1082,17 @@
     return ret;
   }
 
-  public static SWIGTYPE_p_switch_core_session switch_core_session_request(switch_endpoint_interface endpoint_interface, SWIGTYPE_p_p_apr_pool_t pool) {
-    IntPtr cPtr = freeswitchPINVOKE.switch_core_session_request(switch_endpoint_interface.getCPtr(endpoint_interface), SWIGTYPE_p_p_apr_pool_t.getCPtr(pool));
+  public static SWIGTYPE_p_switch_core_session switch_core_session_request_uuid(switch_endpoint_interface endpoint_interface, SWIGTYPE_p_p_apr_pool_t pool, string use_uuid) {
+    IntPtr cPtr = freeswitchPINVOKE.switch_core_session_request_uuid(switch_endpoint_interface.getCPtr(endpoint_interface), SWIGTYPE_p_p_apr_pool_t.getCPtr(pool), use_uuid);
     SWIGTYPE_p_switch_core_session ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_switch_core_session(cPtr, false);
     return ret;
   }
 
+  public static switch_status_t switch_core_session_set_uuid(SWIGTYPE_p_switch_core_session session, string use_uuid) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_core_session_set_uuid(SWIGTYPE_p_switch_core_session.getCPtr(session), use_uuid);
+    return ret;
+  }
+
   public static void switch_core_session_perform_destroy(SWIGTYPE_p_p_switch_core_session session, string file, string func, int line) {
     freeswitchPINVOKE.switch_core_session_perform_destroy(SWIGTYPE_p_p_switch_core_session.getCPtr(session), file, func, line);
   }
@@ -1270,8 +1284,8 @@
     return ret;
   }
 
-  public static switch_status_t switch_core_session_receive_message(SWIGTYPE_p_switch_core_session session, switch_core_session_message message) {
-    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_core_session_receive_message(SWIGTYPE_p_switch_core_session.getCPtr(session), switch_core_session_message.getCPtr(message));
+  public static switch_status_t switch_core_session_perform_receive_message(SWIGTYPE_p_switch_core_session session, switch_core_session_message message, string file, string func, int line) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_core_session_perform_receive_message(SWIGTYPE_p_switch_core_session.getCPtr(session), switch_core_session_message.getCPtr(message), file, func, line);
     return ret;
   }
 
@@ -1354,8 +1368,8 @@
     return ret;
   }
 
-  public static switch_status_t switch_core_hash_init(SWIGTYPE_p_p_switch_hash hash, SWIGTYPE_p_apr_pool_t pool) {
-    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_core_hash_init(SWIGTYPE_p_p_switch_hash.getCPtr(hash), SWIGTYPE_p_apr_pool_t.getCPtr(pool));
+  public static switch_status_t switch_core_hash_init_case(SWIGTYPE_p_p_switch_hash hash, SWIGTYPE_p_apr_pool_t pool, switch_bool_t case_sensitive) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_core_hash_init_case(SWIGTYPE_p_p_switch_hash.getCPtr(hash), SWIGTYPE_p_apr_pool_t.getCPtr(pool), (int)case_sensitive);
     return ret;
   }
 
@@ -1899,6 +1913,15 @@
     return ret;
   }
 
+  public static void switch_cond_yield(SWIGTYPE_p_switch_interval_time_t t) {
+    freeswitchPINVOKE.switch_cond_yield(SWIGTYPE_p_switch_interval_time_t.getCPtr(t));
+    if (freeswitchPINVOKE.SWIGPendingException.Pending) throw freeswitchPINVOKE.SWIGPendingException.Retrieve();
+  }
+
+  public static void switch_cond_next() {
+    freeswitchPINVOKE.switch_cond_next();
+  }
+
   public static void switch_console_loop() {
     freeswitchPINVOKE.switch_console_loop();
   }
@@ -1990,6 +2013,16 @@
     return ret;
   }
 
+  public static string switch_lc_strdup(string it) {
+    string ret = freeswitchPINVOKE.switch_lc_strdup(it);
+    return ret;
+  }
+
+  public static string switch_uc_strdup(string it) {
+    string ret = freeswitchPINVOKE.switch_uc_strdup(it);
+    return ret;
+  }
+
   public static switch_bool_t switch_strstr(string s, string q) {
     switch_bool_t ret = (switch_bool_t)freeswitchPINVOKE.switch_strstr(s, q);
     return ret;
@@ -2910,8 +2943,8 @@
     return ret;
   }
 
-  public static switch_status_t switch_play_and_get_digits(SWIGTYPE_p_switch_core_session session, uint min_digits, uint max_digits, uint max_tries, uint timeout, string valid_terminators, string audio_file, string bad_input_audio_file, SWIGTYPE_p_void digit_buffer, uint digit_buffer_length, string digits_regex) {
-    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_play_and_get_digits(SWIGTYPE_p_switch_core_session.getCPtr(session), min_digits, max_digits, max_tries, timeout, valid_terminators, audio_file, bad_input_audio_file, SWIGTYPE_p_void.getCPtr(digit_buffer), digit_buffer_length, digits_regex);
+  public static switch_status_t switch_play_and_get_digits(SWIGTYPE_p_switch_core_session session, uint min_digits, uint max_digits, uint max_tries, uint timeout, string valid_terminators, string audio_file, string bad_input_audio_file, string digit_buffer, uint digit_buffer_length, string digits_regex) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_play_and_get_digits(SWIGTYPE_p_switch_core_session.getCPtr(session), min_digits, max_digits, max_tries, timeout, valid_terminators, audio_file, bad_input_audio_file, digit_buffer, digit_buffer_length, digits_regex);
     return ret;
   }
 
@@ -3209,6 +3242,10 @@
     freeswitchPINVOKE.switch_rtp_release_port(ip, port);
   }
 
+  public static void switch_rtp_change_interval(SWIGTYPE_p_switch_rtp rtp_session, uint ms_per_packet, uint samples_per_interval) {
+    freeswitchPINVOKE.switch_rtp_change_interval(SWIGTYPE_p_switch_rtp.getCPtr(rtp_session), ms_per_packet, samples_per_interval);
+  }
+
   public static switch_status_t switch_rtp_create(SWIGTYPE_p_p_switch_rtp new_rtp_session, byte payload, uint samples_per_interval, uint ms_per_packet, uint flags, string timer_name, ref string err, SWIGTYPE_p_apr_pool_t pool) {
     switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_rtp_create(SWIGTYPE_p_p_switch_rtp.getCPtr(new_rtp_session), payload, samples_per_interval, ms_per_packet, flags, timer_name, ref err, SWIGTYPE_p_apr_pool_t.getCPtr(pool));
     return ret;
@@ -3290,7 +3327,7 @@
     return ret;
   }
 
-  public static void switch_rtp_set_default_samples_per_interval(SWIGTYPE_p_switch_rtp rtp_session, ushort samples_per_interval) {
+  public static void switch_rtp_set_default_samples_per_interval(SWIGTYPE_p_switch_rtp rtp_session, uint samples_per_interval) {
     freeswitchPINVOKE.switch_rtp_set_default_samples_per_interval(SWIGTYPE_p_switch_rtp.getCPtr(rtp_session), samples_per_interval);
   }
 
@@ -3600,8 +3637,27 @@
     return ret;
   }
 
-  public static switch_status_t switch_xml_bind_search_function(SWIGTYPE_p_f_p_q_const__char_p_q_const__char_p_q_const__char_p_q_const__char_p_switch_event_t_p_void__p_switch_xml function, uint sections, SWIGTYPE_p_void user_data) {
-    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_xml_bind_search_function(SWIGTYPE_p_f_p_q_const__char_p_q_const__char_p_q_const__char_p_q_const__char_p_switch_event_t_p_void__p_switch_xml.getCPtr(function), sections, SWIGTYPE_p_void.getCPtr(user_data));
+  public static void switch_xml_set_binding_sections(SWIGTYPE_p_switch_xml_binding binding, uint sections) {
+    freeswitchPINVOKE.switch_xml_set_binding_sections(SWIGTYPE_p_switch_xml_binding.getCPtr(binding), sections);
+  }
+
+  public static void switch_xml_set_binding_user_data(SWIGTYPE_p_switch_xml_binding binding, SWIGTYPE_p_void user_data) {
+    freeswitchPINVOKE.switch_xml_set_binding_user_data(SWIGTYPE_p_switch_xml_binding.getCPtr(binding), SWIGTYPE_p_void.getCPtr(user_data));
+  }
+
+  public static uint switch_xml_get_binding_sections(SWIGTYPE_p_switch_xml_binding binding) {
+    uint ret = freeswitchPINVOKE.switch_xml_get_binding_sections(SWIGTYPE_p_switch_xml_binding.getCPtr(binding));
+    return ret;
+  }
+
+  public static SWIGTYPE_p_void switch_xml_get_binding_user_data(SWIGTYPE_p_switch_xml_binding binding) {
+    IntPtr cPtr = freeswitchPINVOKE.switch_xml_get_binding_user_data(SWIGTYPE_p_switch_xml_binding.getCPtr(binding));
+    SWIGTYPE_p_void ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_void(cPtr, false);
+    return ret;
+  }
+
+  public static switch_status_t switch_xml_bind_search_function_ret(SWIGTYPE_p_f_p_q_const__char_p_q_const__char_p_q_const__char_p_q_const__char_p_switch_event_t_p_void__p_switch_xml function, uint sections, SWIGTYPE_p_void user_data, SWIGTYPE_p_p_switch_xml_binding ret_binding) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_xml_bind_search_function_ret(SWIGTYPE_p_f_p_q_const__char_p_q_const__char_p_q_const__char_p_q_const__char_p_switch_event_t_p_void__p_switch_xml.getCPtr(function), sections, SWIGTYPE_p_void.getCPtr(user_data), SWIGTYPE_p_p_switch_xml_binding.getCPtr(ret_binding));
     return ret;
   }
 
@@ -3909,6 +3965,7 @@
   public static readonly string SWITCH_LOCAL_VIDEO_IP_VARIABLE = freeswitchPINVOKE.SWITCH_LOCAL_VIDEO_IP_VARIABLE_get();
   public static readonly string SWITCH_LOCAL_VIDEO_PORT_VARIABLE = freeswitchPINVOKE.SWITCH_LOCAL_VIDEO_PORT_VARIABLE_get();
   public static readonly string SWITCH_HANGUP_AFTER_BRIDGE_VARIABLE = freeswitchPINVOKE.SWITCH_HANGUP_AFTER_BRIDGE_VARIABLE_get();
+  public static readonly string SWITCH_PARK_AFTER_BRIDGE_VARIABLE = freeswitchPINVOKE.SWITCH_PARK_AFTER_BRIDGE_VARIABLE_get();
   public static readonly string SWITCH_EXEC_AFTER_BRIDGE_APP_VARIABLE = freeswitchPINVOKE.SWITCH_EXEC_AFTER_BRIDGE_APP_VARIABLE_get();
   public static readonly string SWITCH_EXEC_AFTER_BRIDGE_ARG_VARIABLE = freeswitchPINVOKE.SWITCH_EXEC_AFTER_BRIDGE_ARG_VARIABLE_get();
   public static readonly string SWITCH_MAX_FORWARDS_VARIABLE = freeswitchPINVOKE.SWITCH_MAX_FORWARDS_VARIABLE_get();
@@ -4461,6 +4518,9 @@
   [DllImport("mod_managed", EntryPoint="CSharp_SWITCH_HANGUP_AFTER_BRIDGE_VARIABLE_get")]
   public static extern string SWITCH_HANGUP_AFTER_BRIDGE_VARIABLE_get();
 
+  [DllImport("mod_managed", EntryPoint="CSharp_SWITCH_PARK_AFTER_BRIDGE_VARIABLE_get")]
+  public static extern string SWITCH_PARK_AFTER_BRIDGE_VARIABLE_get();
+
   [DllImport("mod_managed", EntryPoint="CSharp_SWITCH_EXEC_AFTER_BRIDGE_APP_VARIABLE_get")]
   public static extern string SWITCH_EXEC_AFTER_BRIDGE_APP_VARIABLE_get();
 
@@ -4818,6 +4878,12 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_loadable_module_function_table_t_runtime_get")]
   public static extern IntPtr switch_loadable_module_function_table_t_runtime_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_loadable_module_function_table_t_flags_set")]
+  public static extern void switch_loadable_module_function_table_t_flags_set(HandleRef jarg1, uint jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_loadable_module_function_table_t_flags_get")]
+  public static extern uint switch_loadable_module_function_table_t_flags_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_new_switch_loadable_module_function_table_t")]
   public static extern IntPtr new_switch_loadable_module_function_table_t();
 
@@ -5151,6 +5217,24 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_core_session_message_flags_get")]
   public static extern uint switch_core_session_message_flags_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_core_session_message__file_set")]
+  public static extern void switch_core_session_message__file_set(HandleRef jarg1, string jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_core_session_message__file_get")]
+  public static extern string switch_core_session_message__file_get(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_core_session_message__func_set")]
+  public static extern void switch_core_session_message__func_set(HandleRef jarg1, string jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_core_session_message__func_get")]
+  public static extern string switch_core_session_message__func_get(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_core_session_message__line_set")]
+  public static extern void switch_core_session_message__line_set(HandleRef jarg1, int jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_core_session_message__line_get")]
+  public static extern int switch_core_session_message__line_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_new_switch_core_session_message")]
   public static extern IntPtr new_switch_core_session_message();
 
@@ -5241,6 +5325,12 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_core_media_bug_read")]
   public static extern int switch_core_media_bug_read(HandleRef jarg1, HandleRef jarg2);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_core_media_bug_flush")]
+  public static extern void switch_core_media_bug_flush(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_core_media_bug_flush_all")]
+  public static extern int switch_core_media_bug_flush_all(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_core_port_allocator_new")]
   public static extern int switch_core_port_allocator_new(ushort jarg1, ushort jarg2, uint jarg3, HandleRef jarg4);
 
@@ -5328,8 +5418,11 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_core_session_get_pool")]
   public static extern IntPtr switch_core_session_get_pool(HandleRef jarg1);
 
-  [DllImport("mod_managed", EntryPoint="CSharp_switch_core_session_request")]
-  public static extern IntPtr switch_core_session_request(HandleRef jarg1, HandleRef jarg2);
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_core_session_request_uuid")]
+  public static extern IntPtr switch_core_session_request_uuid(HandleRef jarg1, HandleRef jarg2, string jarg3);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_core_session_set_uuid")]
+  public static extern int switch_core_session_set_uuid(HandleRef jarg1, string jarg2);
 
   [DllImport("mod_managed", EntryPoint="CSharp_switch_core_session_perform_destroy")]
   public static extern void switch_core_session_perform_destroy(HandleRef jarg1, string jarg2, string jarg3, int jarg4);
@@ -5448,8 +5541,8 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_core_session_resurrect_channel")]
   public static extern int switch_core_session_resurrect_channel(string jarg1, HandleRef jarg2, HandleRef jarg3, HandleRef jarg4);
 
-  [DllImport("mod_managed", EntryPoint="CSharp_switch_core_session_receive_message")]
-  public static extern int switch_core_session_receive_message(HandleRef jarg1, HandleRef jarg2);
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_core_session_perform_receive_message")]
+  public static extern int switch_core_session_perform_receive_message(HandleRef jarg1, HandleRef jarg2, string jarg3, string jarg4, int jarg5);
 
   [DllImport("mod_managed", EntryPoint="CSharp_switch_core_session_queue_event")]
   public static extern int switch_core_session_queue_event(HandleRef jarg1, HandleRef jarg2);
@@ -5499,8 +5592,8 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_core_session_recv_dtmf")]
   public static extern int switch_core_session_recv_dtmf(HandleRef jarg1, HandleRef jarg2);
 
-  [DllImport("mod_managed", EntryPoint="CSharp_switch_core_hash_init")]
-  public static extern int switch_core_hash_init(HandleRef jarg1, HandleRef jarg2);
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_core_hash_init_case")]
+  public static extern int switch_core_hash_init_case(HandleRef jarg1, HandleRef jarg2, int jarg3);
 
   [DllImport("mod_managed", EntryPoint="CSharp_switch_core_hash_destroy")]
   public static extern int switch_core_hash_destroy(HandleRef jarg1);
@@ -5829,6 +5922,12 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_system")]
   public static extern int switch_system(string jarg1, int jarg2);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_cond_yield")]
+  public static extern void switch_cond_yield(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_cond_next")]
+  public static extern void switch_cond_next();
+
   [DllImport("mod_managed", EntryPoint="CSharp_SWITCH_CMD_CHUNK_LEN_get")]
   public static extern int SWITCH_CMD_CHUNK_LEN_get();
 
@@ -5889,6 +5988,12 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_safe_strdup")]
   public static extern string switch_safe_strdup(string jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_lc_strdup")]
+  public static extern string switch_lc_strdup(string jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_uc_strdup")]
+  public static extern string switch_uc_strdup(string jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_strstr")]
   public static extern int switch_strstr(string jarg1, string jarg2);
 
@@ -6579,6 +6684,18 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_endpoint_interface_rwlock_get")]
   public static extern IntPtr switch_endpoint_interface_rwlock_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_endpoint_interface_refs_set")]
+  public static extern void switch_endpoint_interface_refs_set(HandleRef jarg1, int jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_endpoint_interface_refs_get")]
+  public static extern int switch_endpoint_interface_refs_get(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_endpoint_interface_parent_set")]
+  public static extern void switch_endpoint_interface_parent_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_endpoint_interface_parent_get")]
+  public static extern IntPtr switch_endpoint_interface_parent_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_endpoint_interface_next_set")]
   public static extern void switch_endpoint_interface_next_set(HandleRef jarg1, HandleRef jarg2);
 
@@ -6699,6 +6816,18 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_timer_interface_rwlock_get")]
   public static extern IntPtr switch_timer_interface_rwlock_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_timer_interface_refs_set")]
+  public static extern void switch_timer_interface_refs_set(HandleRef jarg1, int jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_timer_interface_refs_get")]
+  public static extern int switch_timer_interface_refs_get(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_timer_interface_parent_set")]
+  public static extern void switch_timer_interface_parent_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_timer_interface_parent_get")]
+  public static extern IntPtr switch_timer_interface_parent_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_timer_interface_next_set")]
   public static extern void switch_timer_interface_next_set(HandleRef jarg1, HandleRef jarg2);
 
@@ -6729,6 +6858,18 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_dialplan_interface_rwlock_get")]
   public static extern IntPtr switch_dialplan_interface_rwlock_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_dialplan_interface_refs_set")]
+  public static extern void switch_dialplan_interface_refs_set(HandleRef jarg1, int jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_dialplan_interface_refs_get")]
+  public static extern int switch_dialplan_interface_refs_get(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_dialplan_interface_parent_set")]
+  public static extern void switch_dialplan_interface_parent_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_dialplan_interface_parent_get")]
+  public static extern IntPtr switch_dialplan_interface_parent_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_dialplan_interface_next_set")]
   public static extern void switch_dialplan_interface_next_set(HandleRef jarg1, HandleRef jarg2);
 
@@ -6801,6 +6942,18 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_file_interface_rwlock_get")]
   public static extern IntPtr switch_file_interface_rwlock_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_file_interface_refs_set")]
+  public static extern void switch_file_interface_refs_set(HandleRef jarg1, int jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_file_interface_refs_get")]
+  public static extern int switch_file_interface_refs_get(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_file_interface_parent_set")]
+  public static extern void switch_file_interface_parent_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_file_interface_parent_get")]
+  public static extern IntPtr switch_file_interface_parent_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_file_interface_next_set")]
   public static extern void switch_file_interface_next_set(HandleRef jarg1, HandleRef jarg2);
 
@@ -7077,6 +7230,18 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_asr_interface_rwlock_get")]
   public static extern IntPtr switch_asr_interface_rwlock_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_asr_interface_refs_set")]
+  public static extern void switch_asr_interface_refs_set(HandleRef jarg1, int jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_asr_interface_refs_get")]
+  public static extern int switch_asr_interface_refs_get(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_asr_interface_parent_set")]
+  public static extern void switch_asr_interface_parent_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_asr_interface_parent_get")]
+  public static extern IntPtr switch_asr_interface_parent_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_asr_interface_next_set")]
   public static extern void switch_asr_interface_next_set(HandleRef jarg1, HandleRef jarg2);
 
@@ -7209,6 +7374,18 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_speech_interface_rwlock_get")]
   public static extern IntPtr switch_speech_interface_rwlock_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_speech_interface_refs_set")]
+  public static extern void switch_speech_interface_refs_set(HandleRef jarg1, int jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_speech_interface_refs_get")]
+  public static extern int switch_speech_interface_refs_get(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_speech_interface_parent_set")]
+  public static extern void switch_speech_interface_parent_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_speech_interface_parent_get")]
+  public static extern IntPtr switch_speech_interface_parent_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_speech_interface_next_set")]
   public static extern void switch_speech_interface_next_set(HandleRef jarg1, HandleRef jarg2);
 
@@ -7311,6 +7488,18 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_say_interface_rwlock_get")]
   public static extern IntPtr switch_say_interface_rwlock_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_say_interface_refs_set")]
+  public static extern void switch_say_interface_refs_set(HandleRef jarg1, int jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_say_interface_refs_get")]
+  public static extern int switch_say_interface_refs_get(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_say_interface_parent_set")]
+  public static extern void switch_say_interface_parent_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_say_interface_parent_get")]
+  public static extern IntPtr switch_say_interface_parent_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_say_interface_next_set")]
   public static extern void switch_say_interface_next_set(HandleRef jarg1, HandleRef jarg2);
 
@@ -7341,6 +7530,18 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_chat_interface_rwlock_get")]
   public static extern IntPtr switch_chat_interface_rwlock_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_chat_interface_refs_set")]
+  public static extern void switch_chat_interface_refs_set(HandleRef jarg1, int jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_chat_interface_refs_get")]
+  public static extern int switch_chat_interface_refs_get(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_chat_interface_parent_set")]
+  public static extern void switch_chat_interface_parent_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_chat_interface_parent_get")]
+  public static extern IntPtr switch_chat_interface_parent_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_chat_interface_next_set")]
   public static extern void switch_chat_interface_next_set(HandleRef jarg1, HandleRef jarg2);
 
@@ -7371,6 +7572,18 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_management_interface_rwlock_get")]
   public static extern IntPtr switch_management_interface_rwlock_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_management_interface_refs_set")]
+  public static extern void switch_management_interface_refs_set(HandleRef jarg1, int jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_management_interface_refs_get")]
+  public static extern int switch_management_interface_refs_get(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_management_interface_parent_set")]
+  public static extern void switch_management_interface_parent_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_management_interface_parent_get")]
+  public static extern IntPtr switch_management_interface_parent_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_management_interface_next_set")]
   public static extern void switch_management_interface_next_set(HandleRef jarg1, HandleRef jarg2);
 
@@ -7425,6 +7638,18 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_directory_interface_rwlock_get")]
   public static extern IntPtr switch_directory_interface_rwlock_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_directory_interface_refs_set")]
+  public static extern void switch_directory_interface_refs_set(HandleRef jarg1, int jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_directory_interface_refs_get")]
+  public static extern int switch_directory_interface_refs_get(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_directory_interface_parent_set")]
+  public static extern void switch_directory_interface_parent_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_directory_interface_parent_get")]
+  public static extern IntPtr switch_directory_interface_parent_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_directory_interface_next_set")]
   public static extern void switch_directory_interface_next_set(HandleRef jarg1, HandleRef jarg2);
 
@@ -7623,6 +7848,12 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_codec_agreed_pt_get")]
   public static extern byte switch_codec_agreed_pt_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_codec_mutex_set")]
+  public static extern void switch_codec_mutex_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_codec_mutex_get")]
+  public static extern IntPtr switch_codec_mutex_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_new_switch_codec")]
   public static extern IntPtr new_switch_codec();
 
@@ -7773,6 +8004,18 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_codec_interface_rwlock_get")]
   public static extern IntPtr switch_codec_interface_rwlock_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_codec_interface_refs_set")]
+  public static extern void switch_codec_interface_refs_set(HandleRef jarg1, int jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_codec_interface_refs_get")]
+  public static extern int switch_codec_interface_refs_get(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_codec_interface_parent_set")]
+  public static extern void switch_codec_interface_parent_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_codec_interface_parent_get")]
+  public static extern IntPtr switch_codec_interface_parent_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_codec_interface_next_set")]
   public static extern void switch_codec_interface_next_set(HandleRef jarg1, HandleRef jarg2);
 
@@ -7827,6 +8070,18 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_application_interface_rwlock_get")]
   public static extern IntPtr switch_application_interface_rwlock_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_application_interface_refs_set")]
+  public static extern void switch_application_interface_refs_set(HandleRef jarg1, int jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_application_interface_refs_get")]
+  public static extern int switch_application_interface_refs_get(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_application_interface_parent_set")]
+  public static extern void switch_application_interface_parent_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_application_interface_parent_get")]
+  public static extern IntPtr switch_application_interface_parent_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_application_interface_next_set")]
   public static extern void switch_application_interface_next_set(HandleRef jarg1, HandleRef jarg2);
 
@@ -7869,6 +8124,18 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_api_interface_rwlock_get")]
   public static extern IntPtr switch_api_interface_rwlock_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_api_interface_refs_set")]
+  public static extern void switch_api_interface_refs_set(HandleRef jarg1, int jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_api_interface_refs_get")]
+  public static extern int switch_api_interface_refs_get(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_api_interface_parent_set")]
+  public static extern void switch_api_interface_parent_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_api_interface_parent_get")]
+  public static extern IntPtr switch_api_interface_parent_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_api_interface_next_set")]
   public static extern void switch_api_interface_next_set(HandleRef jarg1, HandleRef jarg2);
 
@@ -8196,6 +8463,12 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_event_header_value_get")]
   public static extern string switch_event_header_value_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_event_header_hash_set")]
+  public static extern void switch_event_header_hash_set(HandleRef jarg1, uint jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_event_header_hash_get")]
+  public static extern uint switch_event_header_hash_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_event_header_next_set")]
   public static extern void switch_event_header_next_set(HandleRef jarg1, HandleRef jarg2);
 
@@ -8665,7 +8938,7 @@
   public static extern int switch_ivr_record_file(HandleRef jarg1, HandleRef jarg2, string jarg3, HandleRef jarg4, uint jarg5);
 
   [DllImport("mod_managed", EntryPoint="CSharp_switch_play_and_get_digits")]
-  public static extern int switch_play_and_get_digits(HandleRef jarg1, uint jarg2, uint jarg3, uint jarg4, uint jarg5, string jarg6, string jarg7, string jarg8, HandleRef jarg9, uint jarg10, string jarg11);
+  public static extern int switch_play_and_get_digits(HandleRef jarg1, uint jarg2, uint jarg3, uint jarg4, uint jarg5, string jarg6, string jarg7, string jarg8, string jarg9, uint jarg10, string jarg11);
 
   [DllImport("mod_managed", EntryPoint="CSharp_switch_ivr_speak_text_handle")]
   public static extern int switch_ivr_speak_text_handle(HandleRef jarg1, HandleRef jarg2, HandleRef jarg3, HandleRef jarg4, string jarg5, HandleRef jarg6);
@@ -8895,6 +9168,9 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_rtp_release_port")]
   public static extern void switch_rtp_release_port(string jarg1, ushort jarg2);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_rtp_change_interval")]
+  public static extern void switch_rtp_change_interval(HandleRef jarg1, uint jarg2, uint jarg3);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_rtp_create")]
   public static extern int switch_rtp_create(HandleRef jarg1, byte jarg2, uint jarg3, uint jarg4, uint jarg5, string jarg6, ref string jarg7, HandleRef jarg8);
 
@@ -8947,7 +9223,7 @@
   public static extern IntPtr switch_rtp_get_rtp_socket(HandleRef jarg1);
 
   [DllImport("mod_managed", EntryPoint="CSharp_switch_rtp_set_default_samples_per_interval")]
-  public static extern void switch_rtp_set_default_samples_per_interval(HandleRef jarg1, ushort jarg2);
+  public static extern void switch_rtp_set_default_samples_per_interval(HandleRef jarg1, uint jarg2);
 
   [DllImport("mod_managed", EntryPoint="CSharp_switch_rtp_get_default_samples_per_interval")]
   public static extern uint switch_rtp_get_default_samples_per_interval(HandleRef jarg1);
@@ -9252,8 +9528,20 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_xml_open_cfg")]
   public static extern IntPtr switch_xml_open_cfg(string jarg1, HandleRef jarg2, HandleRef jarg3);
 
-  [DllImport("mod_managed", EntryPoint="CSharp_switch_xml_bind_search_function")]
-  public static extern int switch_xml_bind_search_function(HandleRef jarg1, uint jarg2, HandleRef jarg3);
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_xml_set_binding_sections")]
+  public static extern void switch_xml_set_binding_sections(HandleRef jarg1, uint jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_xml_set_binding_user_data")]
+  public static extern void switch_xml_set_binding_user_data(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_xml_get_binding_sections")]
+  public static extern uint switch_xml_get_binding_sections(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_xml_get_binding_user_data")]
+  public static extern IntPtr switch_xml_get_binding_user_data(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_xml_bind_search_function_ret")]
+  public static extern int switch_xml_bind_search_function_ret(HandleRef jarg1, uint jarg2, HandleRef jarg3, HandleRef jarg4);
 
   [DllImport("mod_managed", EntryPoint="CSharp_switch_xml_unbind_search_function")]
   public static extern int switch_xml_unbind_search_function(HandleRef jarg1);
@@ -13710,6 +13998,36 @@
 using System;
 using System.Runtime.InteropServices;
 
+public class SWIGTYPE_p_switch_interval_time_t {
+  private HandleRef swigCPtr;
+
+  internal SWIGTYPE_p_switch_interval_time_t(IntPtr cPtr, bool futureUse) {
+    swigCPtr = new HandleRef(this, cPtr);
+  }
+
+  protected SWIGTYPE_p_switch_interval_time_t() {
+    swigCPtr = new HandleRef(null, IntPtr.Zero);
+  }
+
+  internal static HandleRef getCPtr(SWIGTYPE_p_switch_interval_time_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_ivr_action_t {
   private HandleRef swigCPtr;
 
@@ -14310,6 +14628,36 @@
 using System;
 using System.Runtime.InteropServices;
 
+public class SWIGTYPE_p_switch_xml_binding {
+  private HandleRef swigCPtr;
+
+  internal SWIGTYPE_p_switch_xml_binding(IntPtr cPtr, bool futureUse) {
+    swigCPtr = new HandleRef(this, cPtr);
+  }
+
+  protected SWIGTYPE_p_switch_xml_binding() {
+    swigCPtr = new HandleRef(null, IntPtr.Zero);
+  }
+
+  internal static HandleRef getCPtr(SWIGTYPE_p_switch_xml_binding 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_time_t {
   private HandleRef swigCPtr;
 
@@ -14591,6 +14939,27 @@
     } 
   }
 
+  public int refs {
+    set {
+      freeswitchPINVOKE.switch_api_interface_refs_set(swigCPtr, value);
+    } 
+    get {
+      int ret = freeswitchPINVOKE.switch_api_interface_refs_get(swigCPtr);
+      return ret;
+    } 
+  }
+
+  public SWIGTYPE_p_switch_loadable_module_interface parent {
+    set {
+      freeswitchPINVOKE.switch_api_interface_parent_set(swigCPtr, SWIGTYPE_p_switch_loadable_module_interface.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_api_interface_parent_get(swigCPtr);
+      SWIGTYPE_p_switch_loadable_module_interface ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_switch_loadable_module_interface(cPtr, false);
+      return ret;
+    } 
+  }
+
   public switch_api_interface next {
     set {
       freeswitchPINVOKE.switch_api_interface_next_set(swigCPtr, switch_api_interface.getCPtr(value));
@@ -14737,6 +15106,27 @@
     } 
   }
 
+  public int refs {
+    set {
+      freeswitchPINVOKE.switch_application_interface_refs_set(swigCPtr, value);
+    } 
+    get {
+      int ret = freeswitchPINVOKE.switch_application_interface_refs_get(swigCPtr);
+      return ret;
+    } 
+  }
+
+  public SWIGTYPE_p_switch_loadable_module_interface parent {
+    set {
+      freeswitchPINVOKE.switch_application_interface_parent_set(swigCPtr, SWIGTYPE_p_switch_loadable_module_interface.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_application_interface_parent_get(swigCPtr);
+      SWIGTYPE_p_switch_loadable_module_interface ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_switch_loadable_module_interface(cPtr, false);
+      return ret;
+    } 
+  }
+
   public switch_application_interface next {
     set {
       freeswitchPINVOKE.switch_application_interface_next_set(swigCPtr, switch_application_interface.getCPtr(value));
@@ -15153,6 +15543,27 @@
     } 
   }
 
+  public int refs {
+    set {
+      freeswitchPINVOKE.switch_asr_interface_refs_set(swigCPtr, value);
+    } 
+    get {
+      int ret = freeswitchPINVOKE.switch_asr_interface_refs_get(swigCPtr);
+      return ret;
+    } 
+  }
+
+  public SWIGTYPE_p_switch_loadable_module_interface parent {
+    set {
+      freeswitchPINVOKE.switch_asr_interface_parent_set(swigCPtr, SWIGTYPE_p_switch_loadable_module_interface.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_asr_interface_parent_get(swigCPtr);
+      SWIGTYPE_p_switch_loadable_module_interface ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_switch_loadable_module_interface(cPtr, false);
+      return ret;
+    } 
+  }
+
   public switch_asr_interface next {
     set {
       freeswitchPINVOKE.switch_asr_interface_next_set(swigCPtr, switch_asr_interface.getCPtr(value));
@@ -16519,6 +16930,27 @@
     } 
   }
 
+  public int refs {
+    set {
+      freeswitchPINVOKE.switch_chat_interface_refs_set(swigCPtr, value);
+    } 
+    get {
+      int ret = freeswitchPINVOKE.switch_chat_interface_refs_get(swigCPtr);
+      return ret;
+    } 
+  }
+
+  public SWIGTYPE_p_switch_loadable_module_interface parent {
+    set {
+      freeswitchPINVOKE.switch_chat_interface_parent_set(swigCPtr, SWIGTYPE_p_switch_loadable_module_interface.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_chat_interface_parent_get(swigCPtr);
+      SWIGTYPE_p_switch_loadable_module_interface ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_switch_loadable_module_interface(cPtr, false);
+      return ret;
+    } 
+  }
+
   public switch_chat_interface next {
     set {
       freeswitchPINVOKE.switch_chat_interface_next_set(swigCPtr, switch_chat_interface.getCPtr(value));
@@ -16672,6 +17104,17 @@
     } 
   }
 
+  public SWIGTYPE_p_switch_mutex_t mutex {
+    set {
+      freeswitchPINVOKE.switch_codec_mutex_set(swigCPtr, SWIGTYPE_p_switch_mutex_t.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_codec_mutex_get(swigCPtr);
+      SWIGTYPE_p_switch_mutex_t ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_switch_mutex_t(cPtr, false);
+      return ret;
+    } 
+  }
+
   public switch_codec() : this(freeswitchPINVOKE.new_switch_codec(), true) {
   }
 
@@ -17025,6 +17468,27 @@
     } 
   }
 
+  public int refs {
+    set {
+      freeswitchPINVOKE.switch_codec_interface_refs_set(swigCPtr, value);
+    } 
+    get {
+      int ret = freeswitchPINVOKE.switch_codec_interface_refs_get(swigCPtr);
+      return ret;
+    } 
+  }
+
+  public SWIGTYPE_p_switch_loadable_module_interface parent {
+    set {
+      freeswitchPINVOKE.switch_codec_interface_parent_set(swigCPtr, SWIGTYPE_p_switch_loadable_module_interface.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_codec_interface_parent_get(swigCPtr);
+      SWIGTYPE_p_switch_loadable_module_interface ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_switch_loadable_module_interface(cPtr, false);
+      return ret;
+    } 
+  }
+
   public switch_codec_interface next {
     set {
       freeswitchPINVOKE.switch_codec_interface_next_set(swigCPtr, switch_codec_interface.getCPtr(value));
@@ -17608,6 +18072,36 @@
     } 
   }
 
+  public string _file {
+    set {
+      freeswitchPINVOKE.switch_core_session_message__file_set(swigCPtr, value);
+    } 
+    get {
+      string ret = freeswitchPINVOKE.switch_core_session_message__file_get(swigCPtr);
+      return ret;
+    } 
+  }
+
+  public string _func {
+    set {
+      freeswitchPINVOKE.switch_core_session_message__func_set(swigCPtr, value);
+    } 
+    get {
+      string ret = freeswitchPINVOKE.switch_core_session_message__func_get(swigCPtr);
+      return ret;
+    } 
+  }
+
+  public int _line {
+    set {
+      freeswitchPINVOKE.switch_core_session_message__line_set(swigCPtr, value);
+    } 
+    get {
+      int ret = freeswitchPINVOKE.switch_core_session_message__line_get(swigCPtr);
+      return ret;
+    } 
+  }
+
   public switch_core_session_message() : this(freeswitchPINVOKE.new_switch_core_session_message(), true) {
   }
 
@@ -17659,7 +18153,8 @@
   SWITCH_MESSAGE_INDICATE_DEFLECT,
   SWITCH_MESSAGE_INDICATE_VIDEO_REFRESH_REQ,
   SWITCH_MESSAGE_INDICATE_DISPLAY,
-  SWITCH_MESSAGE_INDICATE_TRANSCODING_NECESSARY
+  SWITCH_MESSAGE_INDICATE_TRANSCODING_NECESSARY,
+  SWITCH_MESSAGE_INVALID
 }
 
 }
@@ -17954,6 +18449,27 @@
     } 
   }
 
+  public int refs {
+    set {
+      freeswitchPINVOKE.switch_dialplan_interface_refs_set(swigCPtr, value);
+    } 
+    get {
+      int ret = freeswitchPINVOKE.switch_dialplan_interface_refs_get(swigCPtr);
+      return ret;
+    } 
+  }
+
+  public SWIGTYPE_p_switch_loadable_module_interface parent {
+    set {
+      freeswitchPINVOKE.switch_dialplan_interface_parent_set(swigCPtr, SWIGTYPE_p_switch_loadable_module_interface.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_dialplan_interface_parent_get(swigCPtr);
+      SWIGTYPE_p_switch_loadable_module_interface ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_switch_loadable_module_interface(cPtr, false);
+      return ret;
+    } 
+  }
+
   public switch_dialplan_interface next {
     set {
       freeswitchPINVOKE.switch_dialplan_interface_next_set(swigCPtr, switch_dialplan_interface.getCPtr(value));
@@ -18340,6 +18856,27 @@
     } 
   }
 
+  public int refs {
+    set {
+      freeswitchPINVOKE.switch_directory_interface_refs_set(swigCPtr, value);
+    } 
+    get {
+      int ret = freeswitchPINVOKE.switch_directory_interface_refs_get(swigCPtr);
+      return ret;
+    } 
+  }
+
+  public SWIGTYPE_p_switch_loadable_module_interface parent {
+    set {
+      freeswitchPINVOKE.switch_directory_interface_parent_set(swigCPtr, SWIGTYPE_p_switch_loadable_module_interface.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_directory_interface_parent_get(swigCPtr);
+      SWIGTYPE_p_switch_loadable_module_interface ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_switch_loadable_module_interface(cPtr, false);
+      return ret;
+    } 
+  }
+
   public switch_directory_interface next {
     set {
       freeswitchPINVOKE.switch_directory_interface_next_set(swigCPtr, switch_directory_interface.getCPtr(value));
@@ -18552,6 +19089,27 @@
     } 
   }
 
+  public int refs {
+    set {
+      freeswitchPINVOKE.switch_endpoint_interface_refs_set(swigCPtr, value);
+    } 
+    get {
+      int ret = freeswitchPINVOKE.switch_endpoint_interface_refs_get(swigCPtr);
+      return ret;
+    } 
+  }
+
+  public SWIGTYPE_p_switch_loadable_module_interface parent {
+    set {
+      freeswitchPINVOKE.switch_endpoint_interface_parent_set(swigCPtr, SWIGTYPE_p_switch_loadable_module_interface.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_endpoint_interface_parent_get(swigCPtr);
+      SWIGTYPE_p_switch_loadable_module_interface ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_switch_loadable_module_interface(cPtr, false);
+      return ret;
+    } 
+  }
+
   public switch_endpoint_interface next {
     set {
       freeswitchPINVOKE.switch_endpoint_interface_next_set(swigCPtr, switch_endpoint_interface.getCPtr(value));
@@ -18792,6 +19350,16 @@
     } 
   }
 
+  public uint hash {
+    set {
+      freeswitchPINVOKE.switch_event_header_hash_set(swigCPtr, value);
+    } 
+    get {
+      uint ret = freeswitchPINVOKE.switch_event_header_hash_get(swigCPtr);
+      return ret;
+    } 
+  }
+
   public switch_event_header next {
     set {
       freeswitchPINVOKE.switch_event_header_next_set(swigCPtr, switch_event_header.getCPtr(value));
@@ -18837,6 +19405,7 @@
   SWITCH_EVENT_CHANNEL_UNPARK,
   SWITCH_EVENT_CHANNEL_APPLICATION,
   SWITCH_EVENT_CHANNEL_ORIGINATE,
+  SWITCH_EVENT_CHANNEL_UUID,
   SWITCH_EVENT_API,
   SWITCH_EVENT_LOG,
   SWITCH_EVENT_INBOUND_CHAN,
@@ -19437,6 +20006,27 @@
     } 
   }
 
+  public int refs {
+    set {
+      freeswitchPINVOKE.switch_file_interface_refs_set(swigCPtr, value);
+    } 
+    get {
+      int ret = freeswitchPINVOKE.switch_file_interface_refs_get(swigCPtr);
+      return ret;
+    } 
+  }
+
+  public SWIGTYPE_p_switch_loadable_module_interface parent {
+    set {
+      freeswitchPINVOKE.switch_file_interface_parent_set(swigCPtr, SWIGTYPE_p_switch_loadable_module_interface.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_file_interface_parent_get(swigCPtr);
+      SWIGTYPE_p_switch_loadable_module_interface ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_switch_loadable_module_interface(cPtr, false);
+      return ret;
+    } 
+  }
+
   public switch_file_interface next {
     set {
       freeswitchPINVOKE.switch_file_interface_next_set(swigCPtr, switch_file_interface.getCPtr(value));
@@ -21160,6 +21750,16 @@
     } 
   }
 
+  public uint flags {
+    set {
+      freeswitchPINVOKE.switch_loadable_module_function_table_t_flags_set(swigCPtr, value);
+    } 
+    get {
+      uint ret = freeswitchPINVOKE.switch_loadable_module_function_table_t_flags_get(swigCPtr);
+      return ret;
+    } 
+  }
+
   public switch_loadable_module_function_table_t() : this(freeswitchPINVOKE.new_switch_loadable_module_function_table_t(), true) {
   }
 
@@ -21408,6 +22008,27 @@
     } 
   }
 
+  public int refs {
+    set {
+      freeswitchPINVOKE.switch_management_interface_refs_set(swigCPtr, value);
+    } 
+    get {
+      int ret = freeswitchPINVOKE.switch_management_interface_refs_get(swigCPtr);
+      return ret;
+    } 
+  }
+
+  public SWIGTYPE_p_switch_loadable_module_interface parent {
+    set {
+      freeswitchPINVOKE.switch_management_interface_parent_set(swigCPtr, SWIGTYPE_p_switch_loadable_module_interface.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_management_interface_parent_get(swigCPtr);
+      SWIGTYPE_p_switch_loadable_module_interface ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_switch_loadable_module_interface(cPtr, false);
+      return ret;
+    } 
+  }
+
   public switch_management_interface next {
     set {
       freeswitchPINVOKE.switch_management_interface_next_set(swigCPtr, switch_management_interface.getCPtr(value));
@@ -21480,6 +22101,22 @@
 
 namespace FreeSWITCH.Native {
 
+public enum switch_module_flag_enum_t {
+  SMODF_NONE = 0,
+  SMODF_GLOBAL_SYMBOLS = (1 << 0)
+}
+
+}
+/* ----------------------------------------------------------------------------
+ * 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_interface_name_t {
   SWITCH_ENDPOINT_INTERFACE,
   SWITCH_TIMER_INTERFACE,
@@ -21930,6 +22567,27 @@
     } 
   }
 
+  public int refs {
+    set {
+      freeswitchPINVOKE.switch_say_interface_refs_set(swigCPtr, value);
+    } 
+    get {
+      int ret = freeswitchPINVOKE.switch_say_interface_refs_get(swigCPtr);
+      return ret;
+    } 
+  }
+
+  public SWIGTYPE_p_switch_loadable_module_interface parent {
+    set {
+      freeswitchPINVOKE.switch_say_interface_parent_set(swigCPtr, SWIGTYPE_p_switch_loadable_module_interface.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_say_interface_parent_get(swigCPtr);
+      SWIGTYPE_p_switch_loadable_module_interface ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_switch_loadable_module_interface(cPtr, false);
+      return ret;
+    } 
+  }
+
   public switch_say_interface next {
     set {
       freeswitchPINVOKE.switch_say_interface_next_set(swigCPtr, switch_say_interface.getCPtr(value));
@@ -22501,6 +23159,27 @@
     } 
   }
 
+  public int refs {
+    set {
+      freeswitchPINVOKE.switch_speech_interface_refs_set(swigCPtr, value);
+    } 
+    get {
+      int ret = freeswitchPINVOKE.switch_speech_interface_refs_get(swigCPtr);
+      return ret;
+    } 
+  }
+
+  public SWIGTYPE_p_switch_loadable_module_interface parent {
+    set {
+      freeswitchPINVOKE.switch_speech_interface_parent_set(swigCPtr, SWIGTYPE_p_switch_loadable_module_interface.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_speech_interface_parent_get(swigCPtr);
+      SWIGTYPE_p_switch_loadable_module_interface ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_switch_loadable_module_interface(cPtr, false);
+      return ret;
+    } 
+  }
+
   public switch_speech_interface next {
     set {
       freeswitchPINVOKE.switch_speech_interface_next_set(swigCPtr, switch_speech_interface.getCPtr(value));
@@ -22755,6 +23434,7 @@
   SWITCH_STATUS_UNLOAD,
   SWITCH_STATUS_NOUNLOAD,
   SWITCH_STATUS_IGNORE,
+  SWITCH_STATUS_TOO_SMALL,
   SWITCH_STATUS_NOT_INITALIZED
 }
 
@@ -23233,6 +23913,27 @@
     } 
   }
 
+  public int refs {
+    set {
+      freeswitchPINVOKE.switch_timer_interface_refs_set(swigCPtr, value);
+    } 
+    get {
+      int ret = freeswitchPINVOKE.switch_timer_interface_refs_get(swigCPtr);
+      return ret;
+    } 
+  }
+
+  public SWIGTYPE_p_switch_loadable_module_interface parent {
+    set {
+      freeswitchPINVOKE.switch_timer_interface_parent_set(swigCPtr, SWIGTYPE_p_switch_loadable_module_interface.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_timer_interface_parent_get(swigCPtr);
+      SWIGTYPE_p_switch_loadable_module_interface ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_switch_loadable_module_interface(cPtr, false);
+      return ret;
+    } 
+  }
+
   public switch_timer_interface next {
     set {
       freeswitchPINVOKE.switch_timer_interface_next_set(swigCPtr, switch_timer_interface.getCPtr(value));

Modified: freeswitch/branches/gmaruzz/src/mod/languages/mod_perl/mod_perl.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/languages/mod_perl/mod_perl.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/languages/mod_perl/mod_perl.c	Mon Nov 17 14:18:32 2008
@@ -46,7 +46,7 @@
 
 SWITCH_MODULE_LOAD_FUNCTION(mod_perl_load);
 SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_perl_shutdown);
-SWITCH_MODULE_DEFINITION(mod_perl, mod_perl_load, mod_perl_shutdown, NULL);
+SWITCH_MODULE_DEFINITION_EX(mod_perl, mod_perl_load, mod_perl_shutdown, NULL, SMODF_GLOBAL_SYMBOLS);
 
 static STRLEN n_a;
 

Modified: freeswitch/branches/gmaruzz/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c	Mon Nov 17 14:18:32 2008
@@ -2135,7 +2135,7 @@
 			break;
 		}
 
-		switch_yield(1000);
+		switch_cond_next();
 	}
 	JS_ResumeRequest(cx, saveDepth);
 	check_hangup_hook(jss, &ret);
@@ -2179,7 +2179,7 @@
 			break;
 		}
 
-		switch_yield(1000);
+		switch_cond_next();
 	}
 	JS_ResumeRequest(cx, saveDepth);
 	check_hangup_hook(jss, &ret);
@@ -2199,7 +2199,7 @@
 	/* you can execute some apps before you answer  CHANNEL_SANITY_CHECK(); */
 
 	if (argc > 0) {
-		const switch_application_interface_t *application_interface;
+		switch_application_interface_t *application_interface;
 		char *app_name = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
 		char *app_arg = NULL;
 		jsrefcount saveDepth;
@@ -2222,6 +2222,7 @@
 				check_hangup_hook(jss, &ret);
 				retval = JS_TRUE;
 			}
+			UNPROTECT_INTERFACE(application_interface);
 		}
 	}
 
@@ -3316,7 +3317,6 @@
 		char *arg = NULL;
 		switch_core_session_t *session = NULL;
 		switch_stream_handle_t stream = { 0 };
-		char retbuf[2048] = "";
 
 		if (!strcasecmp(cmd, "jsapi")) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid API Call!\n");
@@ -3338,13 +3338,12 @@
 			}
 		}
 
-		stream.data = retbuf;
-		stream.end = stream.data;
-		stream.data_size = sizeof(retbuf);
-		stream.write_function = switch_console_stream_write;
+		SWITCH_STANDARD_STREAM(stream);
 		switch_api_execute(cmd, arg, session, &stream);
 
-		*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, retbuf));
+		*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, switch_str_nil((char *)stream.data)));
+		switch_safe_free(stream.data);
+
 	} else {
 		*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, ""));
 	}

Modified: freeswitch/branches/gmaruzz/src/switch.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch.c	Mon Nov 17 14:18:32 2008
@@ -123,7 +123,7 @@
 		}
 #else
 		/* for unix, send the signal to kill. */
-		kill(pid, SIGILL);
+		kill(pid, SIGTERM);
 #endif
 	}
 
@@ -566,6 +566,7 @@
 	}
 
 	signal(SIGILL, handle_SIGILL);
+	signal(SIGTERM, handle_SIGILL);
 
 	if (nc) {
 #ifdef WIN32

Modified: freeswitch/branches/gmaruzz/src/switch_apr.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_apr.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_apr.c	Mon Nov 17 14:18:32 2008
@@ -69,6 +69,11 @@
 
 /* Memory Pools */
 
+SWITCH_DECLARE(switch_thread_id_t) switch_thread_self(void)
+{
+	return apr_os_thread_current();
+}
+
 SWITCH_DECLARE(void) switch_pool_clear(switch_memory_pool_t *p)
 {
 	apr_pool_clear(p);
@@ -678,7 +683,7 @@
 				status = SWITCH_STATUS_FALSE;
 				break;
 			}
-			switch_yield(1000);
+			switch_cond_next();
 		} else {
 			to_count = 0;
 		}

Modified: freeswitch/branches/gmaruzz/src/switch_channel.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_channel.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_channel.c	Mon Nov 17 14:18:32 2008
@@ -683,7 +683,7 @@
 		if (mystate != ostate || state >= CS_HANGUP || state == want_state) {
 			break;
 		}
-		switch_yield(1000);
+		switch_cond_next();
 	}
 }
 
@@ -709,7 +709,7 @@
 			}
 		}
 
-		switch_yield(1000);
+		switch_cond_next();
 
 		if (super_channel && !switch_channel_ready(super_channel)) {
 			return SWITCH_STATUS_FALSE;
@@ -1150,6 +1150,7 @@
 
 	if (switch_test_flag(channel, CF_VERBOSE_EVENTS) || 
 		event->event_id == SWITCH_EVENT_CHANNEL_ORIGINATE ||
+		event->event_id == SWITCH_EVENT_CHANNEL_UUID ||
 		event->event_id == SWITCH_EVENT_CHANNEL_ANSWER ||
 		event->event_id == SWITCH_EVENT_CHANNEL_PROGRESS ||
 		event->event_id == SWITCH_EVENT_CHANNEL_PROGRESS_MEDIA ||

Modified: freeswitch/branches/gmaruzz/src/switch_console.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_console.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_console.c	Mon Nov 17 14:18:32 2008
@@ -449,7 +449,7 @@
 				free(cmd);
 			}
 		}
-		switch_yield(1000);
+		switch_cond_next();
 	}
 
 	switch_core_destroy_memory_pool(&pool);

Modified: freeswitch/branches/gmaruzz/src/switch_core.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_core.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_core.c	Mon Nov 17 14:18:32 2008
@@ -104,7 +104,7 @@
 	} else {
 		if (!(ok6 = !strcmp(main_ip6, guess_ip6))) {
 			switch_set_string(main_ip6, guess_ip6);
-			switch_core_set_variable("local_ip_v4", guess_ip6);
+			switch_core_set_variable("local_ip_v6", guess_ip6);
 		}
 	}
 	
@@ -360,6 +360,7 @@
 		}
 		ts->objs[0] = obj;
 		switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
+		switch_threadattr_priority_increase(thd_attr);
 		switch_thread_create(&thread, thd_attr, func, ts, pool);
 	}
 }

Modified: freeswitch/branches/gmaruzz/src/switch_core_asr.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_core_asr.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_core_asr.c	Mon Nov 17 14:18:32 2008
@@ -64,6 +64,7 @@
 		ah->memory_pool = pool;
 	} else {
 		if ((status = switch_core_new_memory_pool(&ah->memory_pool)) != SWITCH_STATUS_SUCCESS) {
+			UNPROTECT_INTERFACE(ah->asr_interface);
 			return status;
 		}
 		switch_set_flag(ah, SWITCH_ASR_FLAG_FREE_POOL);
@@ -127,6 +128,7 @@
 	switch_assert(ah != NULL);
 
 	status = ah->asr_interface->asr_close(ah, flags);
+	UNPROTECT_INTERFACE(ah->asr_interface);
 
 	if (switch_test_flag(ah, SWITCH_ASR_FLAG_FREE_POOL)) {
 		switch_core_destroy_memory_pool(&ah->memory_pool);

Modified: freeswitch/branches/gmaruzz/src/switch_core_codec.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_core_codec.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_core_codec.c	Mon Nov 17 14:18:32 2008
@@ -378,7 +378,7 @@
 													   uint32_t rate, int ms, int channels, uint32_t flags,
 													   const switch_codec_settings_t *codec_settings, switch_memory_pool_t *pool)
 {
-	const switch_codec_interface_t *codec_interface;
+	switch_codec_interface_t *codec_interface;
 	const switch_codec_implementation_t *iptr, *implementation = NULL;
 	const char *mode = fmtp;
 
@@ -450,13 +450,16 @@
 		}
 
 		implementation->init(codec, flags, codec_settings);
-
+		switch_mutex_init(&codec->mutex, SWITCH_MUTEX_NESTED, codec->memory_pool);
+		
 		return SWITCH_STATUS_SUCCESS;
 	} else {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Codec %s Exists but not at the desired implementation. %dhz %dms\n", codec_name, rate,
 						  ms);
 	}
 
+	UNPROTECT_INTERFACE(codec_interface);
+
 	return SWITCH_STATUS_NOTIMPL;
 }
 
@@ -467,6 +470,8 @@
 														 uint32_t decoded_rate,
 														 void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate, unsigned int *flag)
 {
+	switch_status_t status;
+
 	switch_assert(codec != NULL);
 	switch_assert(encoded_data != NULL);
 	switch_assert(decoded_data != NULL);
@@ -481,8 +486,13 @@
 		return SWITCH_STATUS_NOT_INITALIZED;
 	}
 
-	return codec->implementation->encode(codec, other_codec, decoded_data, decoded_data_len, decoded_rate, encoded_data, encoded_data_len, encoded_rate,
-										 flag);
+	if (codec->mutex) switch_mutex_lock(codec->mutex);
+	status = codec->implementation->encode(codec, other_codec, decoded_data, decoded_data_len, 
+										   decoded_rate, encoded_data, encoded_data_len, encoded_rate, flag);
+	if (codec->mutex) switch_mutex_unlock(codec->mutex);
+
+	return status;
+										   
 }
 
 SWITCH_DECLARE(switch_status_t) switch_core_codec_decode(switch_codec_t *codec,
@@ -492,6 +502,8 @@
 														 uint32_t encoded_rate,
 														 void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate, unsigned int *flag)
 {
+	switch_status_t status;
+
 	switch_assert(codec != NULL);
 	switch_assert(encoded_data != NULL);
 	switch_assert(decoded_data != NULL);
@@ -506,26 +518,42 @@
 		return SWITCH_STATUS_NOT_INITALIZED;
 	}
 
-	return codec->implementation->decode(codec, other_codec, encoded_data, encoded_data_len, encoded_rate, decoded_data, decoded_data_len, decoded_rate,
-										 flag);
+	if (codec->mutex) switch_mutex_lock(codec->mutex);
+	status = codec->implementation->decode(codec, other_codec, encoded_data, encoded_data_len, encoded_rate, 
+										   decoded_data, decoded_data_len, decoded_rate, flag);
+	if (codec->mutex) switch_mutex_unlock(codec->mutex);
+
+	return status;
 }
 
 SWITCH_DECLARE(switch_status_t) switch_core_codec_destroy(switch_codec_t *codec)
 {
-	switch_assert(codec != NULL);
+	switch_mutex_t *mutex;
+	switch_memory_pool_t *pool;
 
+	switch_assert(codec != NULL);	
+	
 	if (!codec->implementation) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Codec is not initialized!\n");
 		return SWITCH_STATUS_NOT_INITALIZED;
 	}
 
+	pool = codec->memory_pool;
+	mutex = codec->mutex;
+
+	if (mutex) switch_mutex_lock(mutex);
+
 	codec->implementation->destroy(codec);
 
-	if (switch_test_flag(codec, SWITCH_CODEC_FLAG_FREE_POOL)) {
-		switch_core_destroy_memory_pool(&codec->memory_pool);
-	}
+	UNPROTECT_INTERFACE(codec->codec_interface);
 
 	memset(codec, 0, sizeof(*codec));
+	
+	if (mutex) switch_mutex_unlock(mutex);
+
+	if (switch_test_flag(codec, SWITCH_CODEC_FLAG_FREE_POOL)) {
+		switch_core_destroy_memory_pool(&pool);
+	}
 
 	return SWITCH_STATUS_SUCCESS;
 }

Modified: freeswitch/branches/gmaruzz/src/switch_core_directory.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_core_directory.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_core_directory.c	Mon Nov 17 14:18:32 2008
@@ -49,6 +49,7 @@
 		dh->memory_pool = pool;
 	} else {
 		if ((status = switch_core_new_memory_pool(&dh->memory_pool)) != SWITCH_STATUS_SUCCESS) {
+			UNPROTECT_INTERFACE(dh->directory_interface);
 			return status;
 		}
 		switch_set_flag(dh, SWITCH_DIRECTORY_FLAG_FREE_POOL);
@@ -77,6 +78,7 @@
 	switch_status_t status;
 
 	status = dh->directory_interface->directory_close(dh);
+	UNPROTECT_INTERFACE(dh->directory_interface);
 
 	if (switch_test_flag(dh, SWITCH_DIRECTORY_FLAG_FREE_POOL)) {
 		switch_core_destroy_memory_pool(&dh->memory_pool);

Modified: freeswitch/branches/gmaruzz/src/switch_core_file.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_core_file.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_core_file.c	Mon Nov 17 14:18:32 2008
@@ -56,7 +56,7 @@
 		file_path = rhs + 3;
 	} else {
 		if ((ext = strrchr(file_path, '.')) == 0) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Format\n");
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unknown file Format [%s]\n", file_path);
 			return SWITCH_STATUS_FALSE;
 		}
 		ext++;
@@ -76,6 +76,7 @@
 		fh->memory_pool = pool;
 	} else {
 		if ((status = switch_core_new_memory_pool(&fh->memory_pool)) != SWITCH_STATUS_SUCCESS) {
+			UNPROTECT_INTERFACE(fh->file_interface);
 			return status;
 		}
 		switch_set_flag(fh, SWITCH_FILE_FLAG_FREE_POOL);
@@ -98,9 +99,11 @@
 	}
 
 	if ((status = fh->file_interface->file_open(fh, file_path)) != SWITCH_STATUS_SUCCESS) {
+		UNPROTECT_INTERFACE(fh->file_interface);
 		return status;
 	}
 
+
 	if ((flags & SWITCH_FILE_FLAG_READ)) {
 		fh->native_rate = fh->samplerate;
 	} else {
@@ -281,6 +284,8 @@
 
 	switch_resample_destroy(&fh->resampler);
 
+	UNPROTECT_INTERFACE(fh->file_interface);
+
 	if (switch_test_flag(fh, SWITCH_FILE_FLAG_FREE_POOL)) {
 		switch_core_destroy_memory_pool(&fh->memory_pool);
 	}

Modified: freeswitch/branches/gmaruzz/src/switch_core_hash.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_core_hash.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_core_hash.c	Mon Nov 17 14:18:32 2008
@@ -41,14 +41,14 @@
 	Hash table;
 };
 
-SWITCH_DECLARE(switch_status_t) switch_core_hash_init(switch_hash_t **hash, switch_memory_pool_t *pool)
+SWITCH_DECLARE(switch_status_t) switch_core_hash_init_case(switch_hash_t **hash, switch_memory_pool_t *pool, switch_bool_t case_sensitive)
 {
 	switch_hash_t *newhash;
 
 	newhash = switch_core_alloc(pool, sizeof(*newhash));
 	switch_assert(newhash);
 
-	sqlite3HashInit(&newhash->table, SQLITE_HASH_STRING, 1);
+	sqlite3HashInit(&newhash->table, case_sensitive ? SQLITE_HASH_BINARY : SQLITE_HASH_STRING, 1);
 	*hash = newhash;
 
 	return SWITCH_STATUS_SUCCESS;

Modified: freeswitch/branches/gmaruzz/src/switch_core_io.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_core_io.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_core_io.c	Mon Nov 17 14:18:32 2008
@@ -266,7 +266,11 @@
 			case SWITCH_STATUS_SUCCESS:
 				session->raw_read_frame.samples = session->raw_read_frame.datalen / sizeof(int16_t);
 				session->raw_read_frame.rate = read_frame->rate;
-				session->raw_read_frame.timestamp = read_frame->timestamp;
+				if (read_frame->codec->implementation->samples_per_packet != session->read_codec->implementation->samples_per_packet) {
+					session->raw_read_frame.timestamp = 0;
+				} else {
+					session->raw_read_frame.timestamp = read_frame->timestamp;
+				}
 				session->raw_read_frame.ssrc = read_frame->ssrc;
 				session->raw_read_frame.seq = read_frame->seq;
 				session->raw_read_frame.m = read_frame->m;
@@ -421,7 +425,11 @@
 				case SWITCH_STATUS_SUCCESS:
 					session->enc_read_frame.samples = session->read_codec->implementation->decoded_bytes_per_packet / sizeof(int16_t);
 					if (perfect) {
-						session->enc_read_frame.timestamp = read_frame->timestamp;
+						if (enc_frame->codec->implementation->samples_per_packet != session->read_codec->implementation->samples_per_packet) {
+							session->enc_read_frame.timestamp = 0;
+						} else {
+							session->enc_read_frame.timestamp = read_frame->timestamp;
+						}
 						session->enc_read_frame.rate = read_frame->rate;
 						session->enc_read_frame.ssrc = read_frame->ssrc;
 						session->enc_read_frame.seq = read_frame->seq;
@@ -793,7 +801,11 @@
 				case SWITCH_STATUS_SUCCESS:
 					session->enc_write_frame.codec = session->write_codec;
 					session->enc_write_frame.samples = enc_frame->datalen / sizeof(int16_t);
-					session->enc_write_frame.timestamp = frame->timestamp;
+					if (frame->codec->implementation->samples_per_packet != session->write_codec->implementation->samples_per_packet) {
+						session->enc_write_frame.timestamp = 0;
+					} else {
+						session->enc_write_frame.timestamp = frame->timestamp;
+					}
 					session->enc_write_frame.payload = session->write_codec->implementation->ianacode;
 					session->enc_write_frame.m = frame->m;
 					session->enc_write_frame.ssrc = frame->ssrc;

Modified: freeswitch/branches/gmaruzz/src/switch_core_media_bug.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_core_media_bug.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_core_media_bug.c	Mon Nov 17 14:18:32 2008
@@ -76,6 +76,17 @@
 	return bug->user_data;
 }
 
+SWITCH_DECLARE(void) switch_core_media_bug_flush(switch_media_bug_t *bug)
+{
+	if (bug->raw_read_buffer) {
+		switch_buffer_zero(bug->raw_read_buffer);
+	}
+
+	if (bug->raw_write_buffer) {
+		switch_buffer_zero(bug->raw_write_buffer);
+	}
+}
+
 SWITCH_DECLARE(switch_status_t) switch_core_media_bug_read(switch_media_bug_t *bug, switch_frame_t *frame)
 {
 	uint32_t bytes = 0;
@@ -265,9 +276,27 @@
 }
 
 
+SWITCH_DECLARE(switch_status_t) switch_core_media_bug_flush_all(switch_core_session_t *session)
+{
+	switch_media_bug_t *bp;
+
+	if (session->bugs) {
+		switch_thread_rwlock_wrlock(session->bug_rwlock);
+		for (bp = session->bugs; bp; bp = bp->next) {
+			switch_core_media_bug_flush(bp);
+		}
+		switch_thread_rwlock_unlock(session->bug_rwlock);
+		return SWITCH_STATUS_SUCCESS;
+	}
+
+	return SWITCH_STATUS_FALSE;
+}
+
+
 SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove_all(switch_core_session_t *session)
 {
 	switch_media_bug_t *bp;
+	switch_status_t status = SWITCH_STATUS_FALSE;
 
 	if (session->bugs) {
 		switch_thread_rwlock_wrlock(session->bug_rwlock);
@@ -285,7 +314,7 @@
 		}
 		session->bugs = NULL;
 		switch_thread_rwlock_unlock(session->bug_rwlock);
-		return SWITCH_STATUS_SUCCESS;
+		status = SWITCH_STATUS_SUCCESS;
 	}
 
 	if (session->bug_codec.implementation) {
@@ -293,7 +322,7 @@
 		memset(&session->bug_codec, 0, sizeof(session->bug_codec));
 	}
 
-	return SWITCH_STATUS_FALSE;
+	return status;
 }
 
 SWITCH_DECLARE(switch_status_t) switch_core_media_bug_close(switch_media_bug_t **bug)

Modified: freeswitch/branches/gmaruzz/src/switch_core_memory.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_core_memory.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_core_memory.c	Mon Nov 17 14:18:32 2008
@@ -444,7 +444,7 @@
 #ifndef INSTANTLY_DESTROY_POOLS
 	memory_manager.pool_thread_running = -1;
 	while (memory_manager.pool_thread_running) {
-		switch_yield(1000);
+		switch_cond_next();
 	}
 #endif
 }
@@ -503,7 +503,7 @@
 	switch_thread_create(&thread, thd_attr, pool_thread, NULL, memory_manager.memory_pool);
 
 	while (!memory_manager.pool_thread_running) {
-		switch_yield(1000);
+		switch_cond_next();
 	}
 #endif
 

Modified: freeswitch/branches/gmaruzz/src/switch_core_session.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_core_session.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_core_session.c	Mon Nov 17 14:18:32 2008
@@ -79,17 +79,21 @@
 	void *val;
 	switch_core_session_t *session;
 
+	if (!var_val) return;
+
 	switch_mutex_lock(runtime.throttle_mutex);
 	for (hi = switch_hash_first(NULL, session_manager.session_table); hi; hi = switch_hash_next(hi)) {
 		switch_hash_this(hi, NULL, NULL, &val);
 		if (val) {
 			const char *this_val;
 			session = (switch_core_session_t *) val;
-			switch_core_session_read_lock(session);
-			if ((this_val = switch_channel_get_variable(session->channel, var_name)) && (!strcmp(this_val, var_val))) {
-				switch_channel_hangup(switch_core_session_get_channel(session), cause);
+			if (switch_core_session_read_lock(session) == SWITCH_STATUS_SUCCESS) {
+				if (switch_channel_get_state(session->channel) < CS_HANGUP &&
+					(this_val = switch_channel_get_variable(session->channel, var_name)) && (!strcmp(this_val, var_val))) {
+					switch_channel_hangup(session->channel, cause);
+				}
+				switch_core_session_rwunlock(session);
 			}
-			switch_core_session_rwunlock(session);
 		}
 	}
 	switch_mutex_unlock(runtime.throttle_mutex);
@@ -316,11 +320,21 @@
 		switch_caller_profile_t *profile = NULL, *peer_profile = NULL, *cloned_profile = NULL;
 		switch_event_t *event;
 		switch_channel_t *peer_channel = switch_core_session_get_channel(*new_session);
+		const char *use_uuid;
 
 		switch_assert(peer_channel);
 
 		peer_profile = switch_channel_get_caller_profile(peer_channel);
-
+		
+		if ((use_uuid = switch_event_get_header(var_event, "origination_uuid"))) {
+			if (switch_core_session_set_uuid(*new_session, use_uuid) == SWITCH_STATUS_SUCCESS) {
+				switch_event_del_header(var_event, "origination_uuid");
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s set UUID=%s\n", switch_channel_get_name(peer_channel), use_uuid);
+			} else {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "%s set UUID=%s FAILED\n", switch_channel_get_name(peer_channel), use_uuid);
+			}
+		}
+		
 		if (channel) {
 			const char *export_vars, *val;
 			switch_codec_t *read_codec = switch_core_session_get_read_codec(session);
@@ -403,7 +417,33 @@
 	return cause;
 }
 
-SWITCH_DECLARE(switch_status_t) switch_core_session_receive_message(switch_core_session_t *session, switch_core_session_message_t *message)
+static const char *message_names[] = {
+	"SWITCH_MESSAGE_REDIRECT_AUDIO",
+	"SWITCH_MESSAGE_TRANSMIT_TEXT",
+	"SWITCH_MESSAGE_INDICATE_ANSWER",
+	"SWITCH_MESSAGE_INDICATE_PROGRESS",
+	"SWITCH_MESSAGE_INDICATE_BRIDGE",
+	"SWITCH_MESSAGE_INDICATE_UNBRIDGE",
+	"SWITCH_MESSAGE_INDICATE_TRANSFER",
+	"SWITCH_MESSAGE_INDICATE_RINGING",
+	"SWITCH_MESSAGE_INDICATE_MEDIA",
+	"SWITCH_MESSAGE_INDICATE_NOMEDIA",
+	"SWITCH_MESSAGE_INDICATE_HOLD",
+	"SWITCH_MESSAGE_INDICATE_UNHOLD",
+	"SWITCH_MESSAGE_INDICATE_REDIRECT",
+	"SWITCH_MESSAGE_INDICATE_RESPOND",
+	"SWITCH_MESSAGE_INDICATE_BROADCAST",
+	"SWITCH_MESSAGE_INDICATE_MEDIA_REDIRECT",
+	"SWITCH_MESSAGE_INDICATE_DEFLECT",
+	"SWITCH_MESSAGE_INDICATE_VIDEO_REFRESH_REQ",
+	"SWITCH_MESSAGE_INDICATE_DISPLAY",
+	"SWITCH_MESSAGE_INDICATE_TRANSCODING_NECESSARY",
+	"SWITCH_MESSAGE_INVALID"
+};
+
+SWITCH_DECLARE(switch_status_t) switch_core_session_perform_receive_message(switch_core_session_t *session, 
+																			switch_core_session_message_t *message,
+																			const char *file, const char *func, int line)
 {
 	switch_io_event_hook_receive_message_t *ptr;
 	switch_status_t status = SWITCH_STATUS_SUCCESS;
@@ -418,6 +458,17 @@
 		return status;
 	}
 
+	message->_file = file;
+	message->_func = func;
+	message->_line = line;
+
+	if (message->message_id > SWITCH_MESSAGE_INVALID) {
+		message->message_id = SWITCH_MESSAGE_INVALID;
+	}
+
+	switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_DEBUG, "%s receive message [%s]\n",
+					  switch_channel_get_name(session->channel), message_names[message->message_id]);
+	
 	if (session->endpoint_interface->io_routines->receive_message) {
 		status = session->endpoint_interface->io_routines->receive_message(session, message);
 	}
@@ -430,6 +481,11 @@
 		}
 	}
 
+	message->_file = NULL;
+	message->_func = NULL;
+	message->_line = 0;
+	
+
 	switch_core_session_kill_channel(session, SWITCH_SIG_BREAK);
 	switch_core_session_rwunlock(session);
 
@@ -688,6 +744,7 @@
 	switch_clear_flag(session, SSF_WARN_TRANSCODE);
 	switch_ivr_deactivate_unicast(session);
 	switch_channel_clear_flag(channel, CF_BREAK);
+	switch_core_media_bug_flush_all(session);
 }
 
 
@@ -732,7 +789,7 @@
 {
 	switch_memory_pool_t *pool;
 	switch_event_t *event;
-	const switch_endpoint_interface_t *endpoint_interface = (*session)->endpoint_interface;
+	switch_endpoint_interface_t *endpoint_interface = (*session)->endpoint_interface;
 
 
 	switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_NOTICE, "Close Channel %s [%s]\n",
@@ -771,8 +828,7 @@
 	*session = NULL;
 	switch_core_destroy_memory_pool(&pool);
 
-	switch_thread_rwlock_unlock(endpoint_interface->rwlock);
-
+	UNPROTECT_INTERFACE(endpoint_interface);
 }
 
 SWITCH_STANDARD_SCHED_FUNC(sch_heartbeat_callback)
@@ -917,8 +973,33 @@
 
 }
 
-SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request(const switch_endpoint_interface_t
-																	*endpoint_interface, switch_memory_pool_t **pool)
+SWITCH_DECLARE(switch_status_t) switch_core_session_set_uuid(switch_core_session_t *session, const char *use_uuid)
+{
+	switch_event_t *event;
+
+	switch_assert(use_uuid);
+
+	if (switch_core_hash_find(session_manager.session_table, use_uuid)) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Duplicate UUID!\n");
+        return SWITCH_STATUS_FALSE;
+	}
+
+	switch_event_create(&event, SWITCH_EVENT_CHANNEL_UUID);
+	switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Old-Unique-ID", session->uuid_str);
+	switch_mutex_lock(runtime.throttle_mutex);
+	switch_core_hash_delete(session_manager.session_table, session->uuid_str);
+	switch_set_string(session->uuid_str, use_uuid);
+	switch_core_hash_insert(session_manager.session_table, session->uuid_str, session);
+	switch_mutex_unlock(runtime.throttle_mutex);
+	switch_channel_event_set_data(session->channel, event);
+	switch_event_fire(&event);
+	
+
+	return SWITCH_STATUS_SUCCESS;
+}
+
+SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request_uuid(switch_endpoint_interface_t
+																		 *endpoint_interface, switch_memory_pool_t **pool, const char *use_uuid)
 {
 	switch_memory_pool_t *usepool;
 	switch_core_session_t *session;
@@ -926,11 +1007,19 @@
 	uint32_t count = 0;
 	int32_t sps = 0;
 
+
+	if (use_uuid && switch_core_hash_find(session_manager.session_table, use_uuid)) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Duplicate UUID!\n");
+        return NULL;
+	}
+
 	if (!switch_core_ready() || endpoint_interface == NULL) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "The system cannot create any sessions at this time.\n");
 		return NULL;
 	}
 
+	PROTECT_INTERFACE(endpoint_interface);
+
 	switch_mutex_lock(runtime.throttle_mutex);
 	count = session_manager.session_count;
 	sps = --runtime.sps;
@@ -938,16 +1027,16 @@
 
 	if (sps <= 0) {
 		//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Throttle Error!\n");
+		UNPROTECT_INTERFACE(endpoint_interface);
 		return NULL;
 	}
 
 	if ((count + 1) > session_manager.session_limit) {
 		//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Over Session Limit!\n");
+		UNPROTECT_INTERFACE(endpoint_interface);
 		return NULL;
 	}
 
-	switch_thread_rwlock_rdlock(endpoint_interface->rwlock);
-
 	if (pool && *pool) {
 		usepool = *pool;
 		*pool = NULL;
@@ -957,7 +1046,7 @@
 
 	session = switch_core_alloc(usepool, sizeof(*session));
 	session->pool = usepool;
-
+	
 	if (switch_channel_alloc(&session->channel, session->pool) != SWITCH_STATUS_SUCCESS) {
 		abort();
 	}
@@ -967,8 +1056,13 @@
 	/* The session *IS* the pool you may not alter it because you have no idea how
 	   its all private it will be passed to the thread run function */
 
-	switch_uuid_get(&uuid);
-	switch_uuid_format(session->uuid_str, &uuid);
+	if (use_uuid) {
+		switch_set_string(session->uuid_str, use_uuid);
+	} else {
+		switch_uuid_get(&uuid);
+		switch_uuid_format(session->uuid_str, &uuid);
+	}
+
 	session->endpoint_interface = endpoint_interface;
 	session->raw_write_frame.data = session->raw_write_buf;
 	session->raw_write_frame.buflen = sizeof(session->raw_write_buf);
@@ -1016,7 +1110,7 @@
 
 SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request_by_name(const char *endpoint_name, switch_memory_pool_t **pool)
 {
-	const switch_endpoint_interface_t *endpoint_interface;
+	switch_endpoint_interface_t *endpoint_interface;
 
 	if ((endpoint_interface = switch_loadable_module_get_endpoint_interface(endpoint_name)) == 0) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not locate channel type %s\n", endpoint_name);
@@ -1024,6 +1118,7 @@
 	}
 
 	return switch_core_session_request(endpoint_interface, pool);
+
 }
 
 #ifndef SWITCH_PREFIX_DIR
@@ -1091,7 +1186,7 @@
 
 SWITCH_DECLARE(switch_status_t) switch_core_session_execute_application(switch_core_session_t *session, const char *app, const char *arg)
 {
-	const switch_application_interface_t *application_interface;
+	switch_application_interface_t *application_interface;
 	char *expanded = NULL;
 	const char *var;
 
@@ -1104,6 +1199,7 @@
 	if (!application_interface->application_function) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Function for %s\n", app);
 		switch_channel_hangup(session->channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+		UNPROTECT_INTERFACE(application_interface);
 		return SWITCH_STATUS_FALSE;
 	}
 
@@ -1145,6 +1241,8 @@
 		switch_safe_free(expanded);
 	}
 
+	UNPROTECT_INTERFACE(application_interface);
+	
 	return SWITCH_STATUS_SUCCESS;
 }
 
@@ -1154,6 +1252,7 @@
 	switch_app_log_t *log, *lp;
 	switch_event_t *event;
 	const char *var;
+	switch_channel_t *channel = switch_core_session_get_channel(session);
 
 	if (!arg) {
 		arg = "";
@@ -1173,6 +1272,9 @@
 			session->app_log = log;
 		}
 	}
+	
+	switch_channel_set_variable(channel, "current_application", application_interface->interface_name);
+	switch_channel_set_variable(channel, "current_application_data", arg);
 
 	if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_EXECUTE) == SWITCH_STATUS_SUCCESS) {
 		switch_channel_event_set_data(session->channel, event);
@@ -1187,9 +1289,7 @@
 
 	switch_channel_set_variable(session->channel, SWITCH_CURRENT_APPLICATION_VARIABLE, application_interface->interface_name);
 
-	switch_thread_rwlock_rdlock(application_interface->rwlock);
 	application_interface->application_function(session, arg);
-	switch_thread_rwlock_unlock(application_interface->rwlock);
 	
 	if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_EXECUTE_COMPLETE) == SWITCH_STATUS_SUCCESS) {
 		switch_channel_event_set_data(session->channel, event);

Modified: freeswitch/branches/gmaruzz/src/switch_core_speech.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_core_speech.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_core_speech.c	Mon Nov 17 14:18:32 2008
@@ -66,6 +66,7 @@
 		sh->memory_pool = pool;
 	} else {
 		if ((status = switch_core_new_memory_pool(&sh->memory_pool)) != SWITCH_STATUS_SUCCESS) {
+			UNPROTECT_INTERFACE(sh->speech_interface);
 			return status;
 		}
 		switch_set_flag(sh, SWITCH_SPEECH_FLAG_FREE_POOL);
@@ -139,6 +140,8 @@
 {
 	switch_status_t status = sh->speech_interface->speech_close(sh, flags);
 
+	UNPROTECT_INTERFACE(sh->speech_interface);
+
 	if (switch_test_flag(sh, SWITCH_SPEECH_FLAG_FREE_POOL)) {
 		switch_core_destroy_memory_pool(&sh->memory_pool);
 	}

Modified: freeswitch/branches/gmaruzz/src/switch_core_sqldb.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_core_sqldb.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_core_sqldb.c	Mon Nov 17 14:18:32 2008
@@ -220,7 +220,7 @@
 		}
 
 		if (nothing_in_queue) {
-			switch_yield(1000);
+			switch_cond_next();
 		}
 	}
 
@@ -258,6 +258,21 @@
 	case SWITCH_EVENT_CHANNEL_DESTROY:
 		sql = switch_mprintf("delete from channels where uuid='%q'", switch_event_get_header_nil(event, "unique-id"));
 		break;
+	case SWITCH_EVENT_CHANNEL_UUID:
+		{
+			sql = switch_mprintf(
+								 "update channels set uuid='%q' where uuid='%q';"
+								 "update calls set caller_uuid='%q' where caller_uuid='%q';"
+								 "update calls set callee_uuid='%q' where callee_uuid='%q'",
+								 switch_event_get_header_nil(event, "unique-id"),
+								 switch_event_get_header_nil(event, "old-unique-id"),
+								 switch_event_get_header_nil(event, "unique-id"),
+								 switch_event_get_header_nil(event, "old-unique-id"),
+								 switch_event_get_header_nil(event, "unique-id"),
+								 switch_event_get_header_nil(event, "old-unique-id")
+								 );
+			break;
+		}
 	case SWITCH_EVENT_CHANNEL_CREATE:
 		sql = switch_mprintf("insert into channels (uuid,created,created_epoch, name,state,dialplan,context) values('%q','%q','%ld','%q','%q','%q','%q')",
 							 switch_event_get_header_nil(event, "unique-id"),

Modified: freeswitch/branches/gmaruzz/src/switch_core_state_machine.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_core_state_machine.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_core_state_machine.c	Mon Nov 17 14:18:32 2008
@@ -91,8 +91,11 @@
 					}
 					
 					count++;
-
-					if ((extension = dialplan_interface->hunt_function(session, dparg, NULL)) != 0) {
+					
+					extension = dialplan_interface->hunt_function(session, dparg, NULL);
+					UNPROTECT_INTERFACE(dialplan_interface);
+					
+					if (extension) {
 						switch_channel_set_caller_extension(session->channel, extension);
 						switch_channel_set_state(session->channel, CS_EXECUTE);
 						goto end;
@@ -459,7 +462,7 @@
 
 		if (endstate == switch_channel_get_running_state(session->channel)) {
 			if (endstate == CS_NEW) {
-				switch_yield(1000);
+				switch_cond_next();
 			} else {
 				switch_thread_cond_wait(session->cond, session->mutex);
 			}

Modified: freeswitch/branches/gmaruzz/src/switch_core_timer.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_core_timer.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_core_timer.c	Mon Nov 17 14:18:32 2008
@@ -55,6 +55,7 @@
 		timer->memory_pool = pool;
 	} else {
 		if ((status = switch_core_new_memory_pool(&timer->memory_pool)) != SWITCH_STATUS_SUCCESS) {
+			UNPROTECT_INTERFACE(timer->timer_interface);
 			return status;
 		}
 		switch_set_flag(timer, SWITCH_TIMER_FLAG_FREE_POOL);
@@ -120,6 +121,7 @@
 	}
 
 	timer->timer_interface->timer_destroy(timer);
+	UNPROTECT_INTERFACE(timer->timer_interface);
 
 	if (switch_test_flag(timer, SWITCH_TIMER_FLAG_FREE_POOL)) {
 		switch_core_destroy_memory_pool(&timer->memory_pool);

Modified: freeswitch/branches/gmaruzz/src/switch_dso.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_dso.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_dso.c	Mon Nov 17 14:18:32 2008
@@ -1,114 +1,133 @@
-/* 
- * Cross Platform dso/dll load abstraction
- * Copyright(C) 2008 Michael Jerris
- *
- * You may opt to use, copy, modify, merge, publish, distribute and/or sell
- * copies of the Software, and permit persons to whom the Software is
- * furnished to do so.
- *
- * This work is provided under this license on an "as is" basis, without warranty of any kind,
- * either expressed or implied, including, without limitation, warranties that the covered code
- * is free of defects, merchantable, fit for a particular purpose or non-infringing. The entire
- * risk as to the quality and performance of the covered code is with you. Should any covered
- * code prove defective in any respect, you (not the initial developer or any other contributor)
- * assume the cost of any necessary servicing, repair or correction. This disclaimer of warranty
- * constitutes an essential part of this license. No use of any covered code is authorized hereunder
- * except under this disclaimer. 
- *
- */
-
-#include <switch.h>
-#include "switch_dso.h"
-#include <stdlib.h>
-#include <string.h>
-
-#ifdef WIN32
-
-void switch_dso_destroy(switch_dso_lib_t *lib) {
-	if (lib && *lib) {
-		FreeLibrary(*lib);
-		*lib = NULL;
-	}
-}
-
-switch_dso_lib_t switch_dso_open(const char *path, int global, char **err) {
+/* 
+ * Cross Platform dso/dll load abstraction
+ * Copyright(C) 2008 Michael Jerris
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so.
+ *
+ * This work is provided under this license on an "as is" basis, without warranty of any kind,
+ * either expressed or implied, including, without limitation, warranties that the covered code
+ * is free of defects, merchantable, fit for a particular purpose or non-infringing. The entire
+ * risk as to the quality and performance of the covered code is with you. Should any covered
+ * code prove defective in any respect, you (not the initial developer or any other contributor)
+ * assume the cost of any necessary servicing, repair or correction. This disclaimer of warranty
+ * constitutes an essential part of this license. No use of any covered code is authorized hereunder
+ * except under this disclaimer. 
+ *
+ */
+
+#include <switch.h>
+#include "switch_dso.h"
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef WIN32
+
+void switch_dso_destroy(switch_dso_lib_t *lib) {
+	if (lib && *lib) {
+		FreeLibrary(*lib);
+		*lib = NULL;
+	}
+}
+
+switch_dso_lib_t switch_dso_open(const char *path, int global, char **err) {
     HINSTANCE lib;
-	
-	lib = LoadLibraryEx(path, NULL, 0);
-
-	if (!lib) {
-		LoadLibraryEx(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
-	}
-
-	if (!lib) {
-		DWORD error = GetLastError();
-		*err = switch_mprintf("dll open error [%ul]\n", error);
-	}
-
-	return lib;
-}
-
-switch_dso_func_t switch_dso_func_sym(switch_dso_lib_t lib, const char *sym, char **err) {
-	FARPROC func = GetProcAddress(lib, sym);
-	if (!func) {
-		DWORD error = GetLastError();
-		*err = switch_mprintf("dll sym error [%ul]\n", error);
-	}
-	return func;
-}
-
-#else
-/*
-** {========================================================================
-** This is an implementation of loadlib based on the dlfcn interface.
-** The dlfcn interface is available in Linux, SunOS, Solaris, IRIX, FreeBSD,
-** NetBSD, AIX 4.2, HPUX 11, and  probably most other Unix flavors, at least
-** as an emulation layer on top of native functions.
-** =========================================================================
-*/
-
-
-#include <dlfcn.h>
-
-void switch_dso_destroy(switch_dso_lib_t *lib) {
-	if (lib && *lib) {
-		dlclose(*lib);
-		*lib = NULL;
-	}
-}
-
-switch_dso_lib_t switch_dso_open(const char *path, int global, char **err) {
-	void *lib;
-	
-	if (global) {
-		lib = dlopen(path, RTLD_NOW | RTLD_GLOBAL);
-	} else {
-		lib = dlopen(path, RTLD_NOW | RTLD_LOCAL);
-	}
-
-	if (lib == NULL) {
-		*err = strdup(dlerror());
-	}
-	return lib;
-}
-
-void *switch_dso_func_sym(switch_dso_lib_t lib, const char *sym, char **err) {
-	void *func = dlsym(lib, sym);
-	if (!func) {
-		*err = strdup(dlerror());
-	}
-	return func;
-}
-#endif
-/* }====================================================== */
-
-/* For Emacs:
- * Local Variables:
- * mode:c
- * indent-tabs-mode:t
- * tab-width:4
- * c-basic-offset:4
- * End:
- * For VIM:
- * vim:set softtabstop=4 shiftwidth=4 tabstop=4
- */
+	
+	lib = LoadLibraryEx(path, NULL, 0);
+
+	if (!lib) {
+		LoadLibraryEx(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
+	}
+
+	if (!lib) {
+		DWORD error = GetLastError();
+		*err = switch_mprintf("dll open error [%ul]\n", error);
+	}
+
+	return lib;
+}
+
+switch_dso_func_t switch_dso_func_sym(switch_dso_lib_t lib, const char *sym, char **err) {
+	FARPROC func = GetProcAddress(lib, sym);
+	if (!func) {
+		DWORD error = GetLastError();
+		*err = switch_mprintf("dll sym error [%ul]\n", error);
+	}
+	return (switch_dso_func_t)func;
+}
+
+void *switch_dso_data_sym(switch_dso_lib_t lib, const char *sym, char **err) {
+	FARPROC addr = GetProcAddress(lib, sym);
+	if (!addr) {
+		DWORD error = GetLastError();
+		*err = switch_mprintf("dll sym error [%ul]\n", error);
+	}
+	return (void *)(intptr_t)addr;
+}
+
+
+#else
+/*
+** {========================================================================
+** This is an implementation of loadlib based on the dlfcn interface.
+** The dlfcn interface is available in Linux, SunOS, Solaris, IRIX, FreeBSD,
+** NetBSD, AIX 4.2, HPUX 11, and  probably most other Unix flavors, at least
+** as an emulation layer on top of native functions.
+** =========================================================================
+*/
+
+
+#include <dlfcn.h>
+
+void switch_dso_destroy(switch_dso_lib_t *lib) {
+	if (lib && *lib) {
+		dlclose(*lib);
+		*lib = NULL;
+	}
+}
+
+switch_dso_lib_t switch_dso_open(const char *path, int global, char **err) {
+	void *lib;
+	
+	if (global) {
+		lib = dlopen(path, RTLD_NOW | RTLD_GLOBAL);
+	} else {
+		lib = dlopen(path, RTLD_NOW | RTLD_LOCAL);
+	}
+
+	if (lib == NULL) {
+		*err = strdup(dlerror());
+	}
+	return lib;
+}
+
+switch_dso_func_t switch_dso_func_sym(switch_dso_lib_t lib, const char *sym, char **err) {
+	void *func = dlsym(lib, sym);
+	if (!func) {
+		*err = strdup(dlerror());
+	}
+	return (switch_dso_func_t)(intptr_t)func;
+}
+
+void *switch_dso_data_sym(switch_dso_lib_t lib, const char *sym, char **err) {
+	void *addr = dlsym(lib, sym);
+	if (!addr) {
+		*err = strdup(dlerror());
+	}
+	return addr;
+}
+
+#endif
+/* }====================================================== */
+
+/* For Emacs:
+ * Local Variables:
+ * mode:c
+ * indent-tabs-mode:t
+ * tab-width:4
+ * c-basic-offset:4
+ * End:
+ * For VIM:
+ * vim:set softtabstop=4 shiftwidth=4 tabstop=4
+ */

Modified: freeswitch/branches/gmaruzz/src/switch_event.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_event.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_event.c	Mon Nov 17 14:18:32 2008
@@ -125,6 +125,7 @@
 	"CHANNEL_UNPARK",
 	"CHANNEL_APPLICATION",
 	"CHANNEL_ORIGINATE",
+	"CHANNEL_UUID",
 	"API",
 	"LOG",
 	"INBOUND_CHAN",
@@ -445,7 +446,7 @@
 	}
 
 	while (x < 10000 && THREAD_COUNT) {
-		switch_yield(1000);
+		switch_cond_next();
 		if (THREAD_COUNT == last) {
 			x++;
 		}
@@ -536,7 +537,7 @@
 	switch_thread_create(&thread, thd_attr, switch_event_thread, EVENT_QUEUE[2], RUNTIME_POOL);
 
 	while (!THREAD_COUNT) {
-		switch_yield(1000);
+		switch_cond_next();
 	}
 
 

Modified: freeswitch/branches/gmaruzz/src/switch_ivr.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_ivr.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_ivr.c	Mon Nov 17 14:18:32 2008
@@ -112,13 +112,13 @@
 		}
 
 		if (switch_channel_test_flag(channel, CF_PROXY_MODE)) {
-			switch_yield(1000);
+			switch_cond_next();
 			continue;
 		}
 
 		if (switch_channel_test_flag(channel, CF_SERVICE) ||
 			(!switch_channel_test_flag(channel, CF_ANSWERED) && !switch_channel_test_flag(channel, CF_EARLY_MEDIA))) {
-			switch_yield(1000);
+			switch_cond_next();
 		} else {
 			status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
 			if (!SWITCH_READ_ACCEPTABLE(status)) {
@@ -344,7 +344,7 @@
 	}
 
 	if (cmd_hash == CMD_EXECUTE) {
-		const switch_application_interface_t *application_interface;
+		switch_application_interface_t *application_interface;
 		char *app_name = switch_event_get_header(event, "execute-app-name");
 		char *app_arg = switch_event_get_header(event, "execute-app-arg");
 		char *loop_h = switch_event_get_header(event, "loops");
@@ -409,6 +409,7 @@
 
 					switch_channel_clear_flag(channel, CF_BROADCAST);
 				}
+				UNPROTECT_INTERFACE(application_interface);
 			}
 		}
 	} else if (cmd_hash == CMD_UNICAST) {
@@ -493,6 +494,9 @@
 	switch_codec_t *read_codec;
 	uint32_t rate;
 	uint32_t bpf;
+	const char *to;
+	int timeout = 0;
+	time_t expires = 0;
 
 	if (switch_channel_test_flag(channel, CF_CONTROLLED)) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot park channels that are under control already.\n");
@@ -521,6 +525,14 @@
 	rate = read_codec->implementation->actual_samples_per_second;
 	bpf = read_codec->implementation->decoded_bytes_per_packet;
 
+	if ((to = switch_channel_get_variable(channel, "park_timeout"))) {
+		if ((timeout = atoi(to)) < 0) {
+			timeout = 0;
+		} else {
+			expires = switch_timestamp(NULL) + timeout;
+		}
+	}
+
 	switch_channel_set_flag(channel, CF_CONTROLLED);
 	if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_PARK) == SWITCH_STATUS_SUCCESS) {
 		switch_channel_event_set_data(channel, event);
@@ -534,6 +546,11 @@
 				break;
 			}
 
+			if (expires && switch_timestamp(NULL) >= expires) {
+				switch_channel_hangup(channel, SWITCH_CAUSE_RECOVERY_ON_TIMER_EXPIRE);
+				break;
+			}
+
 			if (switch_channel_test_flag(channel, CF_UNICAST)) {
 				if (!conninfo) {
 					if (!(conninfo = switch_channel_get_private(channel, "unicast"))) {
@@ -692,7 +709,7 @@
 		}
 
 		if (switch_channel_test_flag(channel, CF_SERVICE)) {
-			switch_yield(1000);
+			switch_cond_next();
 		} else {
 			status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
 		}
@@ -807,7 +824,7 @@
 		}
 
 		if (switch_channel_test_flag(channel, CF_SERVICE)) {
-			switch_yield(1000);
+			switch_cond_next();
 		} else {
 			status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
 			if (!SWITCH_READ_ACCEPTABLE(status)) {

Modified: freeswitch/branches/gmaruzz/src/switch_ivr_async.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_ivr_async.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_ivr_async.c	Mon Nov 17 14:18:32 2008
@@ -157,7 +157,7 @@
 #ifdef SWITCH_VIDEO_IN_THREADS
 	if (eh.up) {
 		while (eh.up) {
-			switch_yield(1000);
+			switch_cond_next();
 		}
 	}
 #endif
@@ -913,22 +913,18 @@
 static switch_bool_t inband_dtmf_callback(switch_media_bug_t *bug, void *user_data, switch_abc_type_t type)
 {
 	switch_inband_dtmf_t *pvt = (switch_inband_dtmf_t *) user_data;
-	uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE];
-	switch_frame_t frame = { 0 };
+	switch_frame_t *frame = NULL;
 	char digit_str[80];
 	switch_channel_t *channel = switch_core_session_get_channel(pvt->session);
 
-	frame.data = data;
-	frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE;
-
 	switch (type) {
 	case SWITCH_ABC_TYPE_INIT:
 		break;
 	case SWITCH_ABC_TYPE_CLOSE:
 		break;
-	case SWITCH_ABC_TYPE_READ:
-		if (switch_core_media_bug_read(bug, &frame) == SWITCH_STATUS_SUCCESS) {
-			teletone_dtmf_detect(&pvt->dtmf_detect, frame.data, frame.samples);
+	case SWITCH_ABC_TYPE_READ_REPLACE:
+		if ((frame = switch_core_media_bug_get_read_replace_frame(bug))) {
+			teletone_dtmf_detect(&pvt->dtmf_detect, frame->data, frame->samples);
 			teletone_dtmf_get(&pvt->dtmf_detect, digit_str, sizeof(digit_str));
 			if (digit_str[0]) {
 				char *p = digit_str;
@@ -941,6 +937,7 @@
 				}
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "DTMF DETECTED: [%s]\n", digit_str);
 			}
+			switch_core_media_bug_set_read_replace_frame(bug, frame);
 		}
 		break;
 	case SWITCH_ABC_TYPE_WRITE:
@@ -984,7 +981,7 @@
 
 	switch_channel_pre_answer(channel);
 
-	if ((status = switch_core_media_bug_add(session, inband_dtmf_callback, pvt, 0, SMBF_READ_STREAM, &bug)) != SWITCH_STATUS_SUCCESS) {
+	if ((status = switch_core_media_bug_add(session, inband_dtmf_callback, pvt, 0, SMBF_READ_REPLACE, &bug)) != SWITCH_STATUS_SUCCESS) {
 		return status;
 	}
 
@@ -1580,6 +1577,10 @@
 		char *xmlstr = NULL;
 
 		switch_thread_cond_wait(sth->cond, sth->mutex);
+
+		if(switch_test_flag(sth->ah, SWITCH_ASR_FLAG_CLOSED))
+			break;
+
 		if (switch_core_asr_check_results(sth->ah, &flags) == SWITCH_STATUS_SUCCESS) {
 			switch_event_t *event;
 

Modified: freeswitch/branches/gmaruzz/src/switch_ivr_bridge.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_ivr_bridge.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_ivr_bridge.c	Mon Nov 17 14:18:32 2008
@@ -463,6 +463,10 @@
 
 	state = switch_channel_get_state(channel);
 
+	if (state < CS_HANGUP && switch_true(switch_channel_get_variable(channel, SWITCH_PARK_AFTER_BRIDGE_VARIABLE))) {
+		switch_ivr_park_session(session);
+	}
+
 	if (!switch_channel_test_flag(channel, CF_TRANSFER) && bd && !bd->clean_exit && state != CS_PARK && 
 		state != CS_ROUTING && !switch_channel_test_flag(channel, CF_INNER_BRIDGE)) {
 		switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
@@ -909,7 +913,7 @@
 			}
 
 			while (switch_channel_get_state(peer_channel) == CS_EXCHANGE_MEDIA) {
-				switch_yield(1000);
+				switch_cond_next();
 			}
 
 			switch_core_session_rwunlock(peer_session);
@@ -939,9 +943,12 @@
 
 	if (!switch_channel_test_flag(caller_channel, CF_TRANSFER) && !a_leg->clean_exit && !inner_bridge) {
 		if ((state != CS_EXECUTE && state != CS_SOFT_EXECUTE && state != CS_PARK && state != CS_ROUTING) ||
-			(switch_channel_test_flag(peer_channel, CF_ANSWERED) && state < CS_HANGUP &&
-			 switch_true(switch_channel_get_variable(caller_channel, SWITCH_HANGUP_AFTER_BRIDGE_VARIABLE)))) {
-			switch_channel_hangup(caller_channel, switch_channel_get_cause(peer_channel));
+			(switch_channel_test_flag(peer_channel, CF_ANSWERED) && state < CS_HANGUP)) {
+			if (switch_true(switch_channel_get_variable(caller_channel, SWITCH_HANGUP_AFTER_BRIDGE_VARIABLE))) {
+				switch_channel_hangup(caller_channel, switch_channel_get_cause(peer_channel));
+			} else if (switch_true(switch_channel_get_variable(caller_channel, SWITCH_PARK_AFTER_BRIDGE_VARIABLE))) {
+				switch_ivr_park_session(session);
+			}
 		}
 	}
 
@@ -1152,8 +1159,9 @@
 	switch_channel_pre_answer(channel);
 
 	if ((buuid = switch_channel_get_variable(rchannel, SWITCH_SIGNAL_BOND_VARIABLE))) {
-		bsession = switch_core_session_locate(buuid);
-		bchannel = switch_core_session_get_channel(bsession);
+		if ((bsession = switch_core_session_locate(buuid))) {
+			bchannel = switch_core_session_get_channel(bsession);
+		}
 	}
 
 	if (!switch_channel_test_flag(rchannel, CF_ANSWERED)) {

Modified: freeswitch/branches/gmaruzz/src/switch_ivr_menu.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_ivr_menu.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_ivr_menu.c	Mon Nov 17 14:18:32 2008
@@ -463,7 +463,7 @@
 						break;
 					case SWITCH_IVR_ACTION_EXECAPP:
 						{
-							const switch_application_interface_t *application_interface;
+							switch_application_interface_t *application_interface;
 							char *app_name;
 							char *app_arg = NULL;
 
@@ -477,6 +477,7 @@
 
 								if ((application_interface = switch_loadable_module_get_application_interface(app_name))) {
 									switch_core_session_exec(session, application_interface, app_arg);
+									UNPROTECT_INTERFACE(application_interface);
 									status = SWITCH_STATUS_SUCCESS;
 								}
 							}

Modified: freeswitch/branches/gmaruzz/src/switch_ivr_originate.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_ivr_originate.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_ivr_originate.c	Mon Nov 17 14:18:32 2008
@@ -99,7 +99,7 @@
 	
 	if (!strcasecmp(collect->key, "exec")) {
 		char *data;
-		const switch_application_interface_t *application_interface;
+		switch_application_interface_t *application_interface;
 		char *app_name, *app_data;
 
 		if (!(data = collect->file)) {
@@ -115,6 +115,7 @@
 		if ((application_interface = switch_loadable_module_get_application_interface(app_name)) == 0) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Application %s\n", app_name);
 			switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+			UNPROTECT_INTERFACE(application_interface);
 			goto wbreak;
 		}
 
@@ -496,7 +497,7 @@
 				}
 			}
 		} else {
-			switch_yield(1000);
+			switch_cond_next();
 		}
 	}
 
@@ -1043,6 +1044,19 @@
 					myflags |= SOF_NO_EFFECTIVE_CID_NAME;
 				}
 
+				if (vdata && (var_begin = switch_stristr("origination_uuid=", vdata))) {
+					char tmp[512] = "";
+					var_begin += strlen("origination_uuid=");
+					var_end = strchr(var_begin, '|');
+					if (var_end) {
+						strncpy(tmp, var_begin, var_end-var_begin);
+					} else {
+						strncpy(tmp, var_begin, strlen(var_begin));
+					}
+					new_profile->caller_id_name = switch_core_strdup(new_profile->pool, tmp);
+					switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, "origination_uuid", tmp);
+				}
+				
 				switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, "originate_early_media", early_ok ? "true" : "false");
 				
 
@@ -1185,7 +1199,7 @@
 						goto notready;
 					}
 					
-					switch_yield(10000);
+					switch_yield(100000);
 				}
 
 				check_per_channel_timeouts(peer_channels, per_channel_timelimit_sec, per_channel_progress_timelimit_sec, and_argc, start);
@@ -1418,7 +1432,7 @@
 					}
 
 				} else {
-					switch_yield(10000);
+					switch_yield(100000);
 				}
 				
 			}
@@ -1625,16 +1639,21 @@
 			}
 
 			for (i = 0; i < and_argc; i++) {
+				switch_channel_state_t state;
+
 				if (!peer_channels[i]) {
 					continue;
 				}
+				
 				switch_channel_clear_flag(peer_channels[i], CF_ORIGINATING);
 				if (status == SWITCH_STATUS_SUCCESS) { 
 					if (bleg && *bleg && *bleg == peer_sessions[i]) {
 						continue;
 					}
-				} else if (switch_channel_get_state(switch_core_session_get_channel(peer_sessions[i])) < CS_HANGUP) {
-					switch_channel_hangup(switch_core_session_get_channel(peer_sessions[i]), *cause);
+				} else if ((state=switch_channel_get_state(peer_channels[i])) < CS_HANGUP) {
+					if (!(state == CS_RESET || switch_channel_test_flag(peer_channels[i], CF_TRANSFER))) {
+						switch_channel_hangup(peer_channels[i], *cause);
+					}
 				}
 
 				switch_core_session_rwunlock(peer_sessions[i]);

Modified: freeswitch/branches/gmaruzz/src/switch_ivr_play_say.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_ivr_play_say.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_ivr_play_say.c	Mon Nov 17 14:18:32 2008
@@ -293,6 +293,7 @@
 
 						if ((app = switch_loadable_module_get_application_interface(cmd)) != NULL) {
 							status = switch_core_session_exec(session, app, cmd_args);
+							UNPROTECT_INTERFACE(app);
 						} else {
 							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Application %s\n", cmd);
 						}
@@ -1379,7 +1380,10 @@
 												uint32_t max_digits,
 												const char *prompt_audio_file,
 												const char *var_name,
-												char *digit_buffer, switch_size_t digit_buffer_length, uint32_t timeout, const char *valid_terminators)
+												char *digit_buffer, 
+												switch_size_t digit_buffer_length, 
+												uint32_t timeout, 
+												const char *valid_terminators)
 {
 	switch_channel_t *channel;
 	switch_input_args_t args = { 0 };
@@ -1389,6 +1393,12 @@
 
 	switch_assert(session);
 
+	if (max_digits < min_digits) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, 
+						  "Max digits %u is less than Min %u, forcing Max to %u\n", max_digits, min_digits, min_digits);
+		max_digits = min_digits;
+	}
+
 	channel = switch_core_session_get_channel(session);
 	switch_channel_set_variable(channel, SWITCH_READ_RESULT_VARIABLE, NULL);
 
@@ -1404,7 +1414,9 @@
 	args.buflen = (uint32_t) digit_buffer_length;
 
 	if (!switch_strlen_zero(prompt_audio_file) && strcasecmp(prompt_audio_file, "silence")) {
-		status = switch_ivr_play_file(session, NULL, prompt_audio_file, &args);
+		if ((status = switch_ivr_play_file(session, NULL, prompt_audio_file, &args)) == SWITCH_STATUS_BREAK) {
+			status = SWITCH_STATUS_SUCCESS;
+		}
 	}
 
 	if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
@@ -1413,23 +1425,31 @@
 
 	len = strlen(digit_buffer);
 
-
 	if ((min_digits && len < min_digits) || len < max_digits) {
 		args.buf = digit_buffer + len;
 		args.buflen = (uint32_t) (digit_buffer_length - len);
 		status = switch_ivr_collect_digits_count(session, digit_buffer, digit_buffer_length, max_digits, valid_terminators, &terminator, timeout, 0, 0);
 	}
 
-	if (status == SWITCH_STATUS_SUCCESS) {
+	len = strlen(digit_buffer);
+	if ((min_digits && len < min_digits)) {
+		status = SWITCH_STATUS_TOO_SMALL;
+	}
+
+	switch (status) {
+	case SWITCH_STATUS_SUCCESS:
 		switch_channel_set_variable(channel, SWITCH_READ_RESULT_VARIABLE, "success");
-	} else if (status == SWITCH_STATUS_TIMEOUT) {
+		break;
+	case SWITCH_STATUS_TIMEOUT:
 		switch_channel_set_variable(channel, SWITCH_READ_RESULT_VARIABLE, "timeout");
-	} else {
+		break;
+	default:
 		switch_channel_set_variable(channel, SWITCH_READ_RESULT_VARIABLE, "failure");
+		break;
+		
 	}
-
-
-  end:
+	
+ end:
 
 	if (var_name && !switch_strlen_zero(digit_buffer)) {
 		switch_channel_set_variable(channel, var_name, digit_buffer);
@@ -1439,7 +1459,6 @@
 
 }
 
-
 SWITCH_DECLARE(switch_status_t) switch_play_and_get_digits(switch_core_session_t *session,
 														   uint32_t min_digits,
 														   uint32_t max_digits,
@@ -1447,114 +1466,47 @@
 														   uint32_t timeout,
 														   char *valid_terminators,
 														   char *prompt_audio_file,
-														   char *bad_input_audio_file, void *digit_buffer, uint32_t digit_buffer_length,
+														   char *bad_input_audio_file, 
+														   char *digit_buffer, 
+														   uint32_t digit_buffer_length,
 														   char *digits_regex)
 {
+	switch_channel_t *channel = switch_core_session_get_channel(session);
 
-	char terminator;			                                          /* used to hold terminator recieved from */
-	switch_channel_t *channel = switch_core_session_get_channel(session); /* the channel contained in session */
-	switch_status_t status;		                                          /* used to recieve state out of called functions */
-
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
-					  "switch_play_and_get_digits(session, %d, %d, %d, %d, %s, %s, %s, digit_buffer, %d, %s)\n",
-					  min_digits, max_digits, max_tries, timeout, valid_terminators, prompt_audio_file,
-					  bad_input_audio_file, digit_buffer_length, digits_regex);
-
-	/* Answer the channel if it hasn't already been answered */
-	switch_channel_pre_answer(channel);
-
-	/* Start pestering the user for input */
-	for (; switch_channel_ready(channel) && max_tries > 0; max_tries--) {
-		switch_input_args_t args = { 0 };
-		/* make the buffer so fresh and so clean clean */
+	while(switch_channel_ready(channel) && max_tries) {
+		switch_status_t status;
+		
 		memset(digit_buffer, 0, digit_buffer_length);
-
-		args.buf = digit_buffer;
-		args.buflen = digit_buffer_length;
-		/* Play the file */
-		status = switch_ivr_play_file(session, NULL, prompt_audio_file, &args);
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "play gave up %s\n", (char *) digit_buffer);
-
-		/* Make sure we made it out alive */
-		if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
-			goto done;
-		}
-		/* we only get one digit out of playback, see if thats all we needed and what we got */
-		if (max_digits == 1 && status == SWITCH_STATUS_BREAK) {
-			/* Check the digit if we have a regex */
-			if (digits_regex != NULL) {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Checking regex [%s] on [%s]\n", digits_regex, (char *) digit_buffer);
-
-				/* Make sure the digit is allowed */
-				if (switch_regex_match(digit_buffer, digits_regex) == SWITCH_STATUS_SUCCESS) {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Match found!\n");
-					/* jobs done */
-					break;
-				} else {
-					/* See if a bad input prompt was specified, if so, play it */
-					if (strlen(bad_input_audio_file) > 0) {
-						status = switch_ivr_play_file(session, NULL, bad_input_audio_file, NULL);
-
-						/* Make sure we made it out alive */
-						if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
-							goto done;
-						}
-					}
-				}
-			} else {
-				/* jobs done */
-				break;
-			}
-		}
-
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Calling more digits try %d\n", max_tries);
-
-		/* Try to grab some more digits for the timeout period */
-		status = switch_ivr_collect_digits_count(session, digit_buffer, digit_buffer_length, max_digits, valid_terminators, &terminator, timeout, 0, 0);
-		if (status == SWITCH_STATUS_TIMEOUT) {
+		switch_channel_flush_dtmf(channel);
+		status = switch_ivr_read(session, min_digits, max_digits, prompt_audio_file, NULL, 
+												 digit_buffer, digit_buffer_length, timeout, valid_terminators);
+		if (status == SWITCH_STATUS_TIMEOUT && strlen(digit_buffer) >= min_digits) {
 			status = SWITCH_STATUS_SUCCESS;
 		}
-		
-		/* Make sure we made it out alive */
-		if (status != SWITCH_STATUS_SUCCESS) {
-			/* Bail */
-			goto done;
-		}
-		/* see if we got enough */
-		if (min_digits <= strlen(digit_buffer)) {
-			/* See if we need to test a regex */
-			if (digits_regex != NULL) {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Checking regex [%s] on [%s]\n", digits_regex, (char *) digit_buffer);
-				/* Test the regex */
+
+		if (status == SWITCH_STATUS_SUCCESS) {
+			if (!switch_strlen_zero(digit_buffer)) {
+				if (switch_strlen_zero(digits_regex)) {
+					return SWITCH_STATUS_SUCCESS;
+				}
 				if (switch_regex_match(digit_buffer, digits_regex) == SWITCH_STATUS_SUCCESS) {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Match found!\n");
-					/* Jobs done */
 					return SWITCH_STATUS_SUCCESS;
-				} else {
-					/* See if a bad input prompt was specified, if so, play it */
-					if (strlen(bad_input_audio_file) > 0) {
-						status = switch_ivr_play_file(session, NULL, bad_input_audio_file, NULL);
-
-						/* Make sure we made it out alive */
-						if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
-							goto done;
-						}
-					}
 				}
-			} else {
-				/* Jobs done */
-				return SWITCH_STATUS_SUCCESS;
 			}
 		}
+
+		if (!switch_channel_ready(channel)) {
+			break;
+		}
+
+		switch_ivr_play_file(session, NULL, bad_input_audio_file, NULL);
+		max_tries--;
 	}
 
-  done:
-	/* if we got here, we got no digits or lost the channel */
-	digit_buffer = "\0";
+	memset(digit_buffer, 0, digit_buffer_length);
 	return SWITCH_STATUS_FALSE;
 }
 
-
 SWITCH_DECLARE(switch_status_t) switch_ivr_speak_text_handle(switch_core_session_t *session,
 															 switch_speech_handle_t *sh,
 															 switch_codec_t *codec, switch_timer_t *timer, char *text, switch_input_args_t *args)

Modified: freeswitch/branches/gmaruzz/src/switch_loadable_module.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_loadable_module.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_loadable_module.c	Mon Nov 17 14:18:32 2008
@@ -46,7 +46,7 @@
 	char *filename;
 	int perm;
 	switch_loadable_module_interface_t *module_interface;
-	void *lib;
+	switch_dso_lib_t lib;
 	switch_module_load_t switch_module_load;
 	switch_module_runtime_t switch_module_runtime;
 	switch_module_shutdown_t switch_module_shutdown;
@@ -74,7 +74,8 @@
 };
 
 static struct switch_loadable_module_container loadable_modules;
-static void do_shutdown(switch_loadable_module_t *module, switch_bool_t shutdown, switch_bool_t unload);
+static switch_status_t do_shutdown(switch_loadable_module_t *module, switch_bool_t shutdown, switch_bool_t unload, switch_bool_t fail_if_busy, const char **err);
+static switch_status_t switch_loadable_module_load_module_ex(char *dir, char *fname, switch_bool_t runtime, switch_bool_t global, const char **err);
 
 static void *switch_loadable_module_exec(switch_thread_t *thread, void *obj)
 {
@@ -415,14 +416,14 @@
 	switch_event_t *event;
 
 	switch_mutex_lock(loadable_modules.mutex);
-
+	
 	if (old_module->module_interface->endpoint_interface) {
 		const switch_endpoint_interface_t *ptr;
 
 		for (ptr = old_module->module_interface->endpoint_interface; ptr; ptr = ptr->next) {
 			if (ptr->interface_name) {
 
-				switch_core_session_hupall_endpoint(ptr, SWITCH_CAUSE_SYSTEM_SHUTDOWN);
+				switch_core_session_hupall_endpoint(ptr, SWITCH_CAUSE_MANAGER_REQUEST);
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write lock interface '%s' to wait for existing references.\n", ptr->interface_name);
 				if (switch_thread_rwlock_trywrlock_timeout(ptr->rwlock, 10) == SWITCH_STATUS_SUCCESS) {
                     switch_thread_rwlock_unlock(ptr->rwlock);
@@ -454,6 +455,8 @@
 						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE,
 										  "Deleting Codec '%s' (%s) %dhz %dms\n",
 										  impl->iananame, ptr->interface_name, impl->actual_samples_per_second, impl->microseconds_per_packet / 1000);
+						switch_core_session_hupall_matching_var("read_codec", impl->iananame, SWITCH_CAUSE_MANAGER_REQUEST);
+						switch_core_session_hupall_matching_var("write_codec", impl->iananame, SWITCH_CAUSE_MANAGER_REQUEST);
 						if (switch_core_hash_find(loadable_modules.codec_hash, impl->iananame)) {
 							switch_core_hash_delete(loadable_modules.codec_hash, impl->iananame);
 						}
@@ -505,7 +508,7 @@
 		for (ptr = old_module->module_interface->application_interface; ptr; ptr = ptr->next) {
 			if (ptr->interface_name) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Deleting Application '%s'\n", ptr->interface_name);
-				switch_core_session_hupall_matching_var(SWITCH_CURRENT_APPLICATION_VARIABLE, ptr->interface_name, SWITCH_CAUSE_SYSTEM_SHUTDOWN);
+				switch_core_session_hupall_matching_var(SWITCH_CURRENT_APPLICATION_VARIABLE, ptr->interface_name, SWITCH_CAUSE_MANAGER_REQUEST);
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write lock interface '%s' to wait for existing references.\n", ptr->interface_name);
 				if (switch_thread_rwlock_trywrlock_timeout(ptr->rwlock, 10) == SWITCH_STATUS_SUCCESS) {
 					switch_thread_rwlock_unlock(ptr->rwlock);
@@ -559,6 +562,15 @@
 		for (ptr = old_module->module_interface->file_interface; ptr; ptr = ptr->next) {
 			if (ptr->interface_name) {
 				int i;
+
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write lock interface '%s' to wait for existing references.\n", ptr->interface_name);
+				
+				if (switch_thread_rwlock_trywrlock_timeout(ptr->rwlock, 10) == SWITCH_STATUS_SUCCESS) {
+					switch_thread_rwlock_unlock(ptr->rwlock);
+				} else {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Giving up waiting for existing references.\n");
+				}
+
 				for (i = 0; ptr->extens[i]; i++) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Deleting File Format '%s'\n", ptr->extens[i]);
 					if (switch_event_create(&event, SWITCH_EVENT_MODULE_UNLOAD) == SWITCH_STATUS_SUCCESS) {
@@ -576,7 +588,17 @@
 		const switch_speech_interface_t *ptr;
 
 		for (ptr = old_module->module_interface->speech_interface; ptr; ptr = ptr->next) {
+
 			if (ptr->interface_name) {
+
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write lock interface '%s' to wait for existing references.\n", ptr->interface_name);
+				
+				if (switch_thread_rwlock_trywrlock_timeout(ptr->rwlock, 10) == SWITCH_STATUS_SUCCESS) {
+					switch_thread_rwlock_unlock(ptr->rwlock);
+				} else {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Giving up waiting for existing references.\n");
+				}
+
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Deleting Speech interface '%s'\n", ptr->interface_name);
 				if (switch_event_create(&event, SWITCH_EVENT_MODULE_UNLOAD) == SWITCH_STATUS_SUCCESS) {
 					switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "type", "speech");
@@ -593,6 +615,15 @@
 
 		for (ptr = old_module->module_interface->asr_interface; ptr; ptr = ptr->next) {
 			if (ptr->interface_name) {
+
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write lock interface '%s' to wait for existing references.\n", ptr->interface_name);
+				
+				if (switch_thread_rwlock_trywrlock_timeout(ptr->rwlock, 10) == SWITCH_STATUS_SUCCESS) {
+					switch_thread_rwlock_unlock(ptr->rwlock);
+				} else {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Giving up waiting for existing references.\n");
+				}
+
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Deleting Asr interface '%s'\n", ptr->interface_name);
 				if (switch_event_create(&event, SWITCH_EVENT_MODULE_UNLOAD) == SWITCH_STATUS_SUCCESS) {
 					switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "type", "asr");
@@ -609,6 +640,15 @@
 
 		for (ptr = old_module->module_interface->directory_interface; ptr; ptr = ptr->next) {
 			if (ptr->interface_name) {
+
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write lock interface '%s' to wait for existing references.\n", ptr->interface_name);
+				
+				if (switch_thread_rwlock_trywrlock_timeout(ptr->rwlock, 10) == SWITCH_STATUS_SUCCESS) {
+					switch_thread_rwlock_unlock(ptr->rwlock);
+				} else {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Giving up waiting for existing references.\n");
+				}
+
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Deleting Directory interface '%s'\n", ptr->interface_name);
 				if (switch_event_create(&event, SWITCH_EVENT_MODULE_UNLOAD) == SWITCH_STATUS_SUCCESS) {
 					switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "type", "directory");
@@ -626,6 +666,14 @@
 
 		for (ptr = old_module->module_interface->chat_interface; ptr; ptr = ptr->next) {
 			if (ptr->interface_name) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write lock interface '%s' to wait for existing references.\n", ptr->interface_name);
+				
+				if (switch_thread_rwlock_trywrlock_timeout(ptr->rwlock, 10) == SWITCH_STATUS_SUCCESS) {
+					switch_thread_rwlock_unlock(ptr->rwlock);
+				} else {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Giving up waiting for existing references.\n");
+				}
+
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Deleting Chat interface '%s'\n", ptr->interface_name);
 				if (switch_event_create(&event, SWITCH_EVENT_MODULE_UNLOAD) == SWITCH_STATUS_SUCCESS) {
 					switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "type", "chat");
@@ -642,6 +690,13 @@
 
 		for (ptr = old_module->module_interface->say_interface; ptr; ptr = ptr->next) {
 			if (ptr->interface_name) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write lock interface '%s' to wait for existing references.\n", ptr->interface_name);
+				
+				if (switch_thread_rwlock_trywrlock_timeout(ptr->rwlock, 10) == SWITCH_STATUS_SUCCESS) {
+					switch_thread_rwlock_unlock(ptr->rwlock);
+				} else {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Giving up waiting for existing references.\n");
+				}
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Deleting Say interface '%s'\n", ptr->interface_name);
 				if (switch_event_create(&event, SWITCH_EVENT_MODULE_UNLOAD) == SWITCH_STATUS_SUCCESS) {
 					switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "type", "say");
@@ -669,6 +724,7 @@
 			}
 		}
 	}
+
 	switch_mutex_unlock(loadable_modules.mutex);
 
 	return SWITCH_STATUS_SUCCESS;
@@ -676,23 +732,21 @@
 }
 
 
-static switch_status_t switch_loadable_module_load_file(char *path, char *filename, switch_loadable_module_t **new_module)
+static switch_status_t switch_loadable_module_load_file(char *path, char *filename, switch_bool_t global, switch_loadable_module_t **new_module)
 {
 	switch_loadable_module_t *module = NULL;
-	switch_dso_handle_t *dso = NULL;
+	switch_dso_lib_t dso = NULL;
 	apr_status_t status = SWITCH_STATUS_SUCCESS;
-	switch_dso_handle_sym_t interface_struct_handle = NULL;
+	switch_loadable_module_function_table_t *interface_struct_handle = NULL;
 	switch_loadable_module_function_table_t *mod_interface_functions = NULL;
 	char *struct_name = NULL;
-	switch_dso_handle_sym_t load_function_handle = NULL;
-	switch_dso_handle_sym_t shutdown_function_handle = NULL;
-	switch_dso_handle_sym_t runtime_function_handle = NULL;
 	switch_module_load_t load_func_ptr = NULL;
 	int loading = 1;
-	const char *err = NULL;
 	switch_loadable_module_interface_t *module_interface = NULL;
-	char derr[512] = "";
+	char *derr = NULL;
+	const char *err = NULL;
 	switch_memory_pool_t *pool;
+	switch_bool_t load_global = global;
 
 	switch_assert(path != NULL);
 
@@ -702,36 +756,54 @@
 	struct_name = switch_core_sprintf(pool, "%s_module_interface", filename);
 
 #ifdef WIN32
-	status = switch_dso_load(&dso, "FreeSwitch.dll", loadable_modules.pool);
+	dso = switch_dso_open("FreeSwitch.dll", load_global, &derr);
 #elif defined (MACOSX) || defined(DARWIN)
-	status = switch_dso_load(&dso, SWITCH_PREFIX_DIR "/lib/libfreeswitch.dylib", loadable_modules.pool);
+	dso = switch_dso_open(SWITCH_PREFIX_DIR "/lib/libfreeswitch.dylib", load_global, &derr);
 #else
-	status = switch_dso_load(&dso, NULL, loadable_modules.pool);
+	dso = switch_dso_open(NULL, load_global, &derr);
 #endif
-	status = switch_dso_sym(&interface_struct_handle, dso, struct_name);
+	if (!derr && dso) {
+		interface_struct_handle = switch_dso_data_sym(dso, struct_name, &derr);
+	}
+
+	switch_safe_free(derr)
 
 	if (!interface_struct_handle) {
-		status = switch_dso_load(&dso, path, loadable_modules.pool);
+		dso = switch_dso_open(path, load_global, &derr);
 	}
 
-
 	while (loading) {
-		if (status != APR_SUCCESS) {
-			switch_dso_error(dso, derr, sizeof(derr));
+		if (derr) {
 			err = derr;
 			break;
 		}
 
 		if (!interface_struct_handle) {
-			status = switch_dso_sym(&interface_struct_handle, dso, struct_name);
+			interface_struct_handle = switch_dso_data_sym(dso, struct_name, &derr);
+		}
+
+		if (derr) {
+			err = derr;
+			break;
+		}
+
+		if (interface_struct_handle && interface_struct_handle->switch_api_version != SWITCH_API_VERSION) {
+			err = "Trying to load an out of date module, please rebuild the module.";
+			break;	
+		}
+
+		if (!load_global && interface_struct_handle && switch_test_flag(interface_struct_handle, SMODF_GLOBAL_SYMBOLS)) {
+			load_global = SWITCH_TRUE;
+			switch_dso_destroy(&dso);
+			interface_struct_handle = NULL;
+			dso = switch_dso_open(path, load_global, &derr);
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Loading module with global namespace at request of module\n");
+			continue;
 		}
 
 		if (interface_struct_handle) {
 			mod_interface_functions = interface_struct_handle;
 			load_func_ptr = mod_interface_functions->load;
-		} else {
-			status = switch_dso_sym(&load_function_handle, dso, "switch_module_load");
-			load_func_ptr = (switch_module_load_t) (intptr_t) load_function_handle;
 		}
 
 		if (load_func_ptr == NULL) {
@@ -765,6 +837,7 @@
 			switch_core_destroy_memory_pool(&pool);
 		}
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error Loading module %s\n**%s**\n", path, err);
+		switch_safe_free(derr);
 		return SWITCH_STATUS_GENERR;
 	}
 
@@ -776,11 +849,6 @@
 	if (mod_interface_functions) {
 		module->switch_module_shutdown = mod_interface_functions->shutdown;
 		module->switch_module_runtime = mod_interface_functions->runtime;
-	} else {
-		switch_dso_sym(&shutdown_function_handle, dso, "switch_module_shutdown");
-		module->switch_module_shutdown = (switch_module_shutdown_t) (intptr_t) shutdown_function_handle;
-		switch_dso_sym(&runtime_function_handle, dso, "switch_module_runtime");
-		module->switch_module_runtime = (switch_module_runtime_t) (intptr_t) runtime_function_handle;
 	}
 
 	module->lib = dso;
@@ -791,14 +859,18 @@
 	return SWITCH_STATUS_SUCCESS;
 
 }
-
 SWITCH_DECLARE(switch_status_t) switch_loadable_module_load_module(char *dir, char *fname, switch_bool_t runtime, const char **err)
 {
+	return switch_loadable_module_load_module_ex(dir, fname, runtime, SWITCH_FALSE, err);
+}
+
+static switch_status_t switch_loadable_module_load_module_ex(char *dir, char *fname, switch_bool_t runtime, switch_bool_t global, const char **err)
+{
 	switch_size_t len = 0;
 	char *path;
 	char *file, *dot;
 	switch_loadable_module_t *new_module = NULL;
-	switch_status_t status;
+	switch_status_t status = SWITCH_STATUS_SUCCESS;
 
 #ifdef WIN32
 	const char *ext = ".dll";
@@ -806,8 +878,10 @@
 	const char *ext = ".so";
 #endif
 
+	*err = "";
 
 	if ((file = switch_core_strdup(loadable_modules.pool, fname)) == 0) {
+		*err = "allocation error";
 		return SWITCH_STATUS_FALSE;
 	}
 
@@ -833,12 +907,16 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Module %s Already Loaded!\n", file);
 		*err = "Module already loaded";
 		status = SWITCH_STATUS_FALSE;
-	} else if ((status = switch_loadable_module_load_file(path, file, &new_module)) == SWITCH_STATUS_SUCCESS) {
+	} else if ((status = switch_loadable_module_load_file(path, file, global, &new_module)) == SWITCH_STATUS_SUCCESS) {
 		if ((status = switch_loadable_module_process(file, new_module)) == SWITCH_STATUS_SUCCESS && runtime) {
 			if (new_module->switch_module_runtime) {
 				switch_core_launch_thread(switch_loadable_module_exec, new_module, new_module->pool);
 			}
+		} else if (status != SWITCH_STATUS_SUCCESS) {
+			*err = "module load routine returned an error";
 		}
+	} else {
+		*err = "module load file routine returned an error";
 	}
 	switch_mutex_unlock(loadable_modules.mutex);
 
@@ -865,11 +943,15 @@
 	return status;
 }
 
-SWITCH_DECLARE(switch_status_t) switch_loadable_module_unload_module(char *dir, char *fname, const char **err)
+SWITCH_DECLARE(switch_status_t) switch_loadable_module_unload_module(char *dir, char *fname, switch_bool_t force, const char **err)
 {
 	switch_loadable_module_t *module = NULL;
 	switch_status_t status = SWITCH_STATUS_SUCCESS;
 
+	if (force) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Spin the barrel and pull the trigger.......!\n");
+	}
+
 	switch_mutex_lock(loadable_modules.mutex);
 	if ((module = switch_core_hash_find(loadable_modules.module_hash, fname))) {
 		if (module->perm) {
@@ -878,7 +960,9 @@
 			status = SWITCH_STATUS_NOUNLOAD;
 			goto end;
 		} else {
-			do_shutdown(module, SWITCH_TRUE, SWITCH_TRUE);
+			if ((status = do_shutdown(module, SWITCH_TRUE, SWITCH_TRUE, !force, err) != SWITCH_STATUS_SUCCESS)) {
+				goto end;
+			}
 		}
 		switch_core_hash_delete(loadable_modules.module_hash, fname);
 	} else {
@@ -888,6 +972,11 @@
  end:
 	switch_mutex_unlock(loadable_modules.mutex);
 
+	if (force) {
+		switch_yield(1000000);
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "PHEW!\n");
+	}
+
 	return status;
 
 }
@@ -1020,19 +1109,19 @@
 #endif
 
 	switch_core_hash_init(&loadable_modules.module_hash, loadable_modules.pool);
-	switch_core_hash_init(&loadable_modules.endpoint_hash, loadable_modules.pool);
-	switch_core_hash_init(&loadable_modules.codec_hash, loadable_modules.pool);
-	switch_core_hash_init(&loadable_modules.timer_hash, loadable_modules.pool);
-	switch_core_hash_init(&loadable_modules.application_hash, loadable_modules.pool);
-	switch_core_hash_init(&loadable_modules.api_hash, loadable_modules.pool);
+	switch_core_hash_init_nocase(&loadable_modules.endpoint_hash, loadable_modules.pool);
+	switch_core_hash_init_nocase(&loadable_modules.codec_hash, loadable_modules.pool);
+	switch_core_hash_init_nocase(&loadable_modules.timer_hash, loadable_modules.pool);
+	switch_core_hash_init_nocase(&loadable_modules.application_hash, loadable_modules.pool);
+	switch_core_hash_init_nocase(&loadable_modules.api_hash, loadable_modules.pool);
 	switch_core_hash_init(&loadable_modules.file_hash, loadable_modules.pool);
-	switch_core_hash_init(&loadable_modules.speech_hash, loadable_modules.pool);
-	switch_core_hash_init(&loadable_modules.asr_hash, loadable_modules.pool);
-	switch_core_hash_init(&loadable_modules.directory_hash, loadable_modules.pool);
-	switch_core_hash_init(&loadable_modules.chat_hash, loadable_modules.pool);
-	switch_core_hash_init(&loadable_modules.say_hash, loadable_modules.pool);
-	switch_core_hash_init(&loadable_modules.management_hash, loadable_modules.pool);
-	switch_core_hash_init(&loadable_modules.dialplan_hash, loadable_modules.pool);
+	switch_core_hash_init_nocase(&loadable_modules.speech_hash, loadable_modules.pool);
+	switch_core_hash_init_nocase(&loadable_modules.asr_hash, loadable_modules.pool);
+	switch_core_hash_init_nocase(&loadable_modules.directory_hash, loadable_modules.pool);
+	switch_core_hash_init_nocase(&loadable_modules.chat_hash, loadable_modules.pool);
+	switch_core_hash_init_nocase(&loadable_modules.say_hash, loadable_modules.pool);
+	switch_core_hash_init_nocase(&loadable_modules.management_hash, loadable_modules.pool);
+	switch_core_hash_init_nocase(&loadable_modules.dialplan_hash, loadable_modules.pool);
 	switch_mutex_init(&loadable_modules.mutex, SWITCH_MUTEX_NESTED, loadable_modules.pool);
 
 	switch_loadable_module_load_module("", "CORE_SOFTTIMER_MODULE", SWITCH_FALSE, &err);
@@ -1042,12 +1131,15 @@
 		switch_xml_t mods, ld;
 		if ((mods = switch_xml_child(cfg, "modules"))) {
 			for (ld = switch_xml_child(mods, "load"); ld; ld = ld->next) {
+				switch_bool_t global = SWITCH_FALSE;
 				const char *val = switch_xml_attr_soft(ld, "module");
+				const char *sglobal = switch_xml_attr_soft(ld, "global");
 				if (switch_strlen_zero(val) || (strchr(val, '.') && !strstr(val, ext) && !strstr(val, EXT))) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Invalid extension for %s\n", val);
 					continue;
 				}
-				switch_loadable_module_load_module((char *) SWITCH_GLOBAL_dirs.mod_dir, (char *) val, SWITCH_FALSE, &err);
+				global = switch_true(sglobal);
+				switch_loadable_module_load_module_ex((char *) SWITCH_GLOBAL_dirs.mod_dir, (char *) val, SWITCH_FALSE, global, &err);
 				count++;
 			}
 		}
@@ -1062,12 +1154,15 @@
 
 		if ((mods = switch_xml_child(cfg, "modules"))) {
 			for (ld = switch_xml_child(mods, "load"); ld; ld = ld->next) {
+				switch_bool_t global = SWITCH_FALSE;
 				const char *val = switch_xml_attr_soft(ld, "module");
+				const char *sglobal = switch_xml_attr_soft(ld, "global");
 				if (switch_strlen_zero(val) || (strchr(val, '.') && !strstr(val, ext) && !strstr(val, EXT))) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Invalid extension for %s\n", val);
 					continue;
 				}
-				switch_loadable_module_load_module((char *) SWITCH_GLOBAL_dirs.mod_dir, (char *) val, SWITCH_FALSE, &err);
+				global = switch_true(sglobal);
+				switch_loadable_module_load_module_ex((char *) SWITCH_GLOBAL_dirs.mod_dir, (char *) val, SWITCH_FALSE, global, &err);
 				count++;
 			}
 		}
@@ -1117,11 +1212,19 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static void do_shutdown(switch_loadable_module_t *module, switch_bool_t shutdown, switch_bool_t unload)
+static switch_status_t do_shutdown(switch_loadable_module_t *module, switch_bool_t shutdown, switch_bool_t unload, switch_bool_t fail_if_busy, const char **err)
 {
 	int32_t flags = switch_core_flags();
 	switch_assert(module != NULL);
 	
+	if (fail_if_busy && module->module_interface->rwlock && switch_thread_rwlock_trywrlock(module->module_interface->rwlock) != SWITCH_STATUS_SUCCESS) {
+		if (err) {
+			*err = "Module in use.";
+		}
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Module %s is in use, cannot unload.\n", module->module_interface->module_name);
+		return SWITCH_STATUS_FALSE;
+	}
+
 	if (shutdown) {
 		switch_loadable_module_unprocess(module);
 		if (module->switch_module_shutdown) {
@@ -1132,17 +1235,22 @@
 		}
 	}
 
+	if (fail_if_busy && module->module_interface->rwlock) {
+		switch_thread_rwlock_unlock(module->module_interface->rwlock);
+	}
+
 	if (unload && module->status != SWITCH_STATUS_NOUNLOAD 	&& !(flags & SCF_VG)) {
 		switch_memory_pool_t *pool;
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "%s unloaded.\n", module->module_interface->module_name);
-		switch_dso_unload(module->lib);
-		module->lib = NULL;
+		switch_dso_destroy(&module->lib);
 		if ((pool = module->pool)) {
 			module = NULL;
 			switch_core_destroy_memory_pool(&pool);
 		}
 	}
 	
+	return SWITCH_STATUS_SUCCESS;
+
 }
 
 SWITCH_DECLARE(void) switch_loadable_module_shutdown(void)
@@ -1155,7 +1263,7 @@
 		switch_hash_this(hi, NULL, NULL, &val);
 		module = (switch_loadable_module_t *) val;
 		if (!module->perm) {
-			do_shutdown(module, SWITCH_TRUE, SWITCH_FALSE);
+			do_shutdown(module, SWITCH_TRUE, SWITCH_FALSE, SWITCH_FALSE, NULL);
 		}
 	}
 
@@ -1165,7 +1273,7 @@
 		switch_hash_this(hi, NULL, NULL, &val);
 		module = (switch_loadable_module_t *) val;
 		if (!module->perm) {
-			do_shutdown(module, SWITCH_FALSE, SWITCH_TRUE);
+			do_shutdown(module, SWITCH_FALSE, SWITCH_TRUE, SWITCH_FALSE, NULL);
 		}
 	}
 
@@ -1192,8 +1300,12 @@
 
 	switch_mutex_lock(loadable_modules.mutex);
 	ptr = switch_core_hash_find(loadable_modules.endpoint_hash, name);
+	if (ptr) {
+		PROTECT_INTERFACE(ptr);
+	}
 	switch_mutex_unlock(loadable_modules.mutex);
 
+
 	return ptr;
 }
 
@@ -1216,57 +1328,41 @@
 		}
 	}
 	switch_mutex_unlock(loadable_modules.mutex);
-	return codec;
-}
-
-SWITCH_DECLARE(switch_dialplan_interface_t *) switch_loadable_module_get_dialplan_interface(const char *name)
-{
-	return switch_core_hash_find_locked(loadable_modules.dialplan_hash, name, loadable_modules.mutex);
-}
-
-SWITCH_DECLARE(switch_timer_interface_t *) switch_loadable_module_get_timer_interface(const char *name)
-{
-	return switch_core_hash_find_locked(loadable_modules.timer_hash, name, loadable_modules.mutex);
-}
-
-SWITCH_DECLARE(switch_application_interface_t *) switch_loadable_module_get_application_interface(const char *name)
-{
-	return switch_core_hash_find_locked(loadable_modules.application_hash, name, loadable_modules.mutex);
-}
-
-SWITCH_DECLARE(switch_api_interface_t *) switch_loadable_module_get_api_interface(const char *name)
-{
-	return switch_core_hash_find_locked(loadable_modules.api_hash, name, loadable_modules.mutex);
-}
 
-SWITCH_DECLARE(switch_file_interface_t *) switch_loadable_module_get_file_interface(const char *name)
-{
-	return switch_core_hash_find_locked(loadable_modules.file_hash, name, loadable_modules.mutex);
-}
+	if (codec) {
+		PROTECT_INTERFACE(codec);
+	}
 
-SWITCH_DECLARE(switch_speech_interface_t *) switch_loadable_module_get_speech_interface(const char *name)
-{
-	return switch_core_hash_find_locked(loadable_modules.speech_hash, name, loadable_modules.mutex);
+	return codec;
 }
 
-SWITCH_DECLARE(switch_asr_interface_t *) switch_loadable_module_get_asr_interface(const char *name)
-{
-	return switch_core_hash_find_locked(loadable_modules.asr_hash, name, loadable_modules.mutex);
-}
+#define HASH_FUNC(_kind_) SWITCH_DECLARE(switch_##_kind_##_interface_t *) switch_loadable_module_get_##_kind_##_interface(const char *name)	\
+	{																	\
+		switch_##_kind_##_interface_t *i;								\
+		if ((i = switch_core_hash_find_locked(loadable_modules._kind_##_hash, name, loadable_modules.mutex))) {	\
+			PROTECT_INTERFACE(i);										\
+		}																\
+		return i;														\
+	}																	
+	
+HASH_FUNC(dialplan)
+HASH_FUNC(timer)
+HASH_FUNC(application)
+HASH_FUNC(api)
+HASH_FUNC(file)
+HASH_FUNC(speech)
+HASH_FUNC(asr)
+HASH_FUNC(directory)
 
-SWITCH_DECLARE(switch_directory_interface_t *) switch_loadable_module_get_directory_interface(const char *name)
-{
-	return switch_core_hash_find_locked(loadable_modules.directory_hash, name, loadable_modules.mutex);
-}
 
 SWITCH_DECLARE(switch_chat_interface_t *) switch_loadable_module_get_chat_interface(const char *name)
 {
-	return switch_core_hash_find_locked(loadable_modules.chat_hash, name, loadable_modules.mutex);
+    return switch_core_hash_find_locked(loadable_modules.chat_hash, name, loadable_modules.mutex);
 }
 
 SWITCH_DECLARE(switch_say_interface_t *) switch_loadable_module_get_say_interface(const char *name)
 {
-	return switch_core_hash_find_locked(loadable_modules.say_hash, name, loadable_modules.mutex);
+    return switch_core_hash_find_locked(loadable_modules.say_hash, name, loadable_modules.mutex);
 }
 
 SWITCH_DECLARE(switch_management_interface_t *) switch_loadable_module_get_management_interface(const char *relative_oid)
@@ -1389,9 +1485,12 @@
 
 		  found:
 
+			UNPROTECT_INTERFACE(codec_interface);
+
 			if (i > arraylen) {
 				break;
 			}
+
 		}
 	}
 
@@ -1425,11 +1524,10 @@
 
 
 	if (cmd && (api = switch_loadable_module_get_api_interface(cmd)) != 0) {
-		switch_thread_rwlock_rdlock(api->rwlock);
 		if ((status = api->function(arg, session, stream)) != SWITCH_STATUS_SUCCESS) {
 			stream->write_function(stream, "COMMAND RETURNED ERROR!\n");
 		}
-		switch_thread_rwlock_unlock(api->rwlock);
+		UNPROTECT_INTERFACE(api);
 	} else {
 		status = SWITCH_STATUS_FALSE;
 		stream->write_function(stream, "INVALID COMMAND!\n");
@@ -1454,7 +1552,7 @@
 	mod->pool = pool;
 
 	mod->module_name = switch_core_strdup(mod->pool, name);
-
+	switch_thread_rwlock_create(&mod->rwlock, mod->pool);
 	return mod;
 }
 
@@ -1469,6 +1567,7 @@
 			mod->_TYPE_##_interface = i;								\
 		}																\
 		switch_thread_rwlock_create(&i->rwlock, mod->pool);				\
+		i->parent = mod;												\
 		return i; }
 
 

Modified: freeswitch/branches/gmaruzz/src/switch_log.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_log.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_log.c	Mon Nov 17 14:18:32 2008
@@ -402,7 +402,7 @@
 	switch_thread_create(&thread, thd_attr, log_thread, NULL, LOG_POOL);
 
 	while (!THREAD_RUNNING) {
-		switch_yield(1000);
+		switch_cond_next();
 	}
 
 	if (colorize) {
@@ -438,7 +438,7 @@
 	THREAD_RUNNING = -1;
 	switch_queue_push(LOG_QUEUE, NULL);
 	while (THREAD_RUNNING) {
-		switch_yield(1000);
+		switch_cond_next();
 	}
 	switch_core_memory_reclaim_logger();
 

Modified: freeswitch/branches/gmaruzz/src/switch_odbc.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_odbc.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_odbc.c	Mon Nov 17 14:18:32 2008
@@ -359,7 +359,8 @@
 		char **names;
 		char **vals;
 		int y = 0;
-		
+		int done = 0;
+
 		if (!(result = SQLFetch(stmt)) == SQL_SUCCESS) {
 			break;
 		}
@@ -385,7 +386,7 @@
 		}
 
 		if (callback(pdata, y, vals, names)) {
-			break;
+			done = 1;
 		}
 
 		for (x = 0; x < y; x++) {
@@ -394,6 +395,10 @@
 		}
 		free(names);
 		free(vals);
+
+		if (done) {
+			break;
+		}
 	}
 	
 	SQLFreeHandle(SQL_HANDLE_STMT, stmt);

Modified: freeswitch/branches/gmaruzz/src/switch_pcm.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_pcm.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_pcm.c	Mon Nov 17 14:18:32 2008
@@ -273,20 +273,49 @@
 
 	SWITCH_ADD_CODEC(codec_interface, "G.711 ulaw");
 	for (count = 12; count > 0; count--) {
-		switch_core_codec_add_implementation(pool, codec_interface,
-											 SWITCH_CODEC_TYPE_AUDIO, 0, "PCMU", NULL, 8000, 8000, 64000,
-											 mpf * count, spf * count, bpf * count, ebpf * count, 1, spf * count,
-											 switch_g711u_init, switch_g711u_encode, switch_g711u_decode, switch_g711u_destroy);
+		switch_core_codec_add_implementation(pool,
+											 codec_interface,
+											 SWITCH_CODEC_TYPE_AUDIO,	/* enumeration defining the type of the codec */
+											 0,							/* the IANA code number */
+											 "PCMU",					/* the IANA code name */
+											 NULL,						/* default fmtp to send (can be overridden by the init function) */
+											 8000,						/* samples transferred per second */
+											 8000,						/* actual samples transferred per second */
+											 64000,						/* bits transferred per second */
+											 mpf * count,				/* number of microseconds per frame */
+											 spf * count,				/* number of samples per frame */
+											 bpf * count,				/* number of bytes per frame decompressed */
+											 ebpf * count,				/* number of bytes per frame compressed */
+											 1,							/* number of channels represented */
+											 spf * count,				/* number of frames per network packet */
+											 switch_g711u_init,			/* function to initialize a codec handle using this implementation */
+											 switch_g711u_encode,		/* function to encode raw data into encoded data */
+											 switch_g711u_decode,		/* function to decode encoded data into raw data */
+											 switch_g711u_destroy);		/* deinitalize a codec handle using this implementation */
 	}
 
 	SWITCH_ADD_CODEC(codec_interface, "G.711 alaw");
 	for (count = 12; count > 0; count--) {
-		switch_core_codec_add_implementation(pool, codec_interface,
-											 SWITCH_CODEC_TYPE_AUDIO, 8, "PCMA", NULL, 8000, 8000, 64000,
-											 mpf * count, spf * count, bpf * count, ebpf * count, 1, spf * count,
-											 switch_g711a_init, switch_g711a_encode, switch_g711a_decode, switch_g711a_destroy);
+		switch_core_codec_add_implementation(pool,
+											 codec_interface,
+											 SWITCH_CODEC_TYPE_AUDIO,	/* enumeration defining the type of the codec */
+											 8,							/* the IANA code number */
+											 "PCMA",					/* the IANA code name */
+											 NULL,						/* default fmtp to send (can be overridden by the init function) */
+											 8000,						/* samples transferred per second */
+											 8000,						/* actual samples transferred per second */
+											 64000,						/* bits transferred per second */
+											 mpf * count,				/* number of microseconds per frame */
+											 spf * count,				/* number of samples per frame */
+											 bpf * count,				/* number of bytes per frame decompressed */
+											 ebpf * count,				/* number of bytes per frame compressed */
+											 1,							/* number of channels represented */
+											 spf * count,				/* number of frames per network packet */
+											 switch_g711a_init,			/* function to initialize a codec handle using this implementation */
+											 switch_g711a_encode,		/* function to encode raw data into encoded data */
+											 switch_g711a_decode,		/* function to decode encoded data into raw data */
+											 switch_g711a_destroy);		/* deinitalize a codec handle using this implementation */
 	}
-
 }
 
 SWITCH_MODULE_LOAD_FUNCTION(core_pcm_load)

Modified: freeswitch/branches/gmaruzz/src/switch_rtp.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_rtp.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_rtp.c	Mon Nov 17 14:18:32 2008
@@ -558,7 +558,7 @@
 		if (++x > 1000) {
 			break;
 		}
-		switch_yield(1000);
+		switch_cond_next();
 	}
 	switch_socket_opt_set(new_sock, SWITCH_SO_NONBLOCK, FALSE);
 
@@ -754,6 +754,22 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
+SWITCH_DECLARE(void) switch_rtp_change_interval(switch_rtp_t *rtp_session, uint32_t ms_per_packet, uint32_t samples_per_interval)
+{
+	rtp_session->ms_per_packet = ms_per_packet;
+	rtp_session->samples_per_interval = rtp_session->conf_samples_per_interval = samples_per_interval;
+	
+	if (rtp_session->timer_name) {
+		if (rtp_session->timer.timer_interface) {
+			switch_core_timer_destroy(&rtp_session->timer);
+		}
+		switch_core_timer_init(&rtp_session->timer, rtp_session->timer_name, ms_per_packet / 1000, samples_per_interval, rtp_session->pool);
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
+						  "RE-Starting timer [%s] %d bytes per %dms\n", rtp_session->timer_name, samples_per_interval, ms_per_packet);
+	}
+		
+}
+
 SWITCH_DECLARE(switch_status_t) switch_rtp_create(switch_rtp_t **new_rtp_session,
 												  switch_payload_t payload,
 												  uint32_t samples_per_interval,
@@ -816,14 +832,14 @@
 	rtp_session->ms_per_packet = ms_per_packet;
 	rtp_session->samples_per_interval = rtp_session->conf_samples_per_interval = samples_per_interval;
 
-	if (timer_name && !strcasecmp(timer_name, "none")) {
-		timer_name = NULL;
-	}
-
 	if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_USE_TIMER) && switch_strlen_zero(timer_name)) {
 		timer_name = "soft";
 	}
 
+	if (!switch_strlen_zero(timer_name) && !strcasecmp(timer_name, "none")) {
+		timer_name = NULL;
+	}
+
 	if (!switch_strlen_zero(timer_name)) {
 		rtp_session->timer_name = switch_core_strdup(pool, timer_name);
 		switch_set_flag_locked(rtp_session, SWITCH_RTP_FLAG_USE_TIMER);
@@ -838,6 +854,7 @@
 			switch_clear_flag_locked(rtp_session, SWITCH_RTP_FLAG_USE_TIMER);
 		}
 	} else {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Not using a timer\n");
 		switch_clear_flag_locked(rtp_session, SWITCH_RTP_FLAG_USE_TIMER);
 		switch_clear_flag_locked(rtp_session, SWITCH_RTP_FLAG_NOBLOCK);
 	}
@@ -1095,7 +1112,7 @@
 	return rtp_session->sock_input;
 }
 
-SWITCH_DECLARE(void) switch_rtp_set_default_samples_per_interval(switch_rtp_t *rtp_session, uint16_t samples_per_interval)
+SWITCH_DECLARE(void) switch_rtp_set_default_samples_per_interval(switch_rtp_t *rtp_session, uint32_t samples_per_interval)
 {
 	rtp_session->samples_per_interval = samples_per_interval;
 }
@@ -1240,7 +1257,7 @@
 {
 	switch_size_t bytes = 0;
 	switch_status_t status;
-	uint8_t check = 0;
+	int check = 0;
 	stfu_frame_t *jb_frame;
 	int ret = -1;
 	int sleep_mss = 1000;
@@ -1260,6 +1277,10 @@
 	while (switch_rtp_ready(rtp_session)) {
 		int do_cng = 0;
 
+		if (rtp_session->timer.interval) {
+			switch_core_timer_next(&rtp_session->timer);
+		}
+
 		bytes = sizeof(rtp_msg_t);
 		status = switch_socket_recvfrom(rtp_session->from_addr, rtp_session->sock_input, 0, (void *) &rtp_session->recv_msg, &bytes);
 
@@ -1268,6 +1289,8 @@
 			goto end;
 		}
 		
+		check = !bytes;
+
 		if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_BREAK)) {
 			switch_clear_flag_locked(rtp_session, SWITCH_RTP_FLAG_BREAK);
 			do_2833(rtp_session);
@@ -1319,36 +1342,22 @@
 			rtp_session->missed_count = 0;
 
 			if (rtp_session->recv_msg.header.pt && (rtp_session->recv_msg.header.pt == rtp_session->cng_pt || rtp_session->recv_msg.header.pt == 13)) {
-				if (++rtp_session->cng_count == 1) {
-					return_cng_frame();
-				} 
-				continue;
-			} else {
-				rtp_session->cng_count = 0;
-			}
+				return_cng_frame();
+			} 
 		}
 
 		if (!bytes && (io_flags & SWITCH_IO_FLAG_NOBLOCK)) {
 			return_cng_frame();
 		}
 
-
-		if (rtp_session->timer.interval) {
-			check = (uint8_t) (switch_core_timer_check(&rtp_session->timer, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS);
-			if (bytes) {
-				switch_core_timer_sync(&rtp_session->timer);
-			} else {
-				if (check && switch_test_flag(rtp_session, SWITCH_RTP_FLAG_AUTO_CNG) &&
-					rtp_session->timer.samplecount >= (rtp_session->last_write_samplecount + (rtp_session->samples_per_interval * 50))) {
-					uint8_t data[10] = { 0 };
-					switch_frame_flag_t frame_flags = SFF_NONE;
-					data[0] = 65;
-					rtp_session->cn++;
-					rtp_common_write(rtp_session, NULL, (void *) data, 2, rtp_session->cng_pt, 0, &frame_flags);
-				}
-			}
-		} else if (bytes) {
-			check++;
+		
+		if (check && switch_test_flag(rtp_session, SWITCH_RTP_FLAG_AUTO_CNG) &&
+			rtp_session->timer.samplecount >= (rtp_session->last_write_samplecount + (rtp_session->samples_per_interval * 50))) {
+			uint8_t data[10] = { 0 };
+			switch_frame_flag_t frame_flags = SFF_NONE;
+			data[0] = 65;
+			rtp_session->cn++;
+			rtp_common_write(rtp_session, NULL, (void *) data, 2, rtp_session->cng_pt, 0, &frame_flags);
 		}
 
 		if (check || bytes) {
@@ -1527,10 +1536,8 @@
 				bytes = jb_frame->dlen + rtp_header_len;
 				rtp_session->recv_msg.header.ts = htonl(jb_frame->ts);
 			} else if (!bytes && switch_test_flag(rtp_session, SWITCH_RTP_FLAG_USE_TIMER)) {	/* We're late! We're Late! */
-				
-				
 				if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_NOBLOCK) && status == SWITCH_STATUS_BREAK) {
-					switch_yield(1000);
+					switch_cond_next();
 					continue;
 				}
 				
@@ -1556,7 +1563,9 @@
 
 	  do_continue:
 		
-		switch_yield(sleep_mss);
+		if (!bytes && !rtp_session->timer.interval) {
+			switch_yield(sleep_mss);
+		}
 
 	}
 

Modified: freeswitch/branches/gmaruzz/src/switch_stun.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_stun.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_stun.c	Mon Nov 17 14:18:32 2008
@@ -518,7 +518,7 @@
 			switch_socket_close(sock);
 			return SWITCH_STATUS_TIMEOUT;
 		}
-		switch_yield(1000);
+		switch_cond_next();
 	}
 	switch_socket_close(sock);
 

Modified: freeswitch/branches/gmaruzz/src/switch_time.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_time.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_time.c	Mon Nov 17 14:18:32 2008
@@ -35,6 +35,10 @@
 #include <stdio.h>
 #include "private/switch_core_pvt.h"
 
+#if defined(DARWIN)
+#define DISABLE_1MS_COND
+#endif
+
 #ifndef UINT32_MAX
 #define UINT32_MAX 0xffffffff
 #endif
@@ -46,6 +50,7 @@
 static struct {
 	int32_t RUNNING;
 	int32_t STARTED;
+	int32_t use_cond_yield;
 	switch_mutex_t *mutex;
 } globals;
 
@@ -76,11 +81,34 @@
 	switch_size_t tick;
 	uint32_t count;
 	uint32_t roll;
+	switch_mutex_t *mutex;
+	switch_thread_cond_t *cond;
 };
 typedef struct timer_matrix timer_matrix_t;
 
 static timer_matrix_t TIMER_MATRIX[MAX_ELEMENTS + 1];
 
+static void do_sleep(switch_interval_time_t t)
+{
+#if defined(WIN32)
+	if (t < 1000) {
+		t = 1000;
+	}
+#endif
+
+#if defined(DARWIN)
+    struct timespec ts;
+    ts.tv_sec = t / APR_USEC_PER_SEC;
+    ts.tv_nsec = (t % APR_USEC_PER_SEC) * 1000;
+	
+    nanosleep(&ts, NULL);
+	sched_yield();
+#else
+	apr_sleep(t);
+#endif
+
+}
+
 SWITCH_DECLARE(switch_time_t) switch_timestamp_now(void)
 {
 	return runtime.timestamp ? runtime.timestamp : switch_time_now();
@@ -136,33 +164,63 @@
 	runtime.reference = time_now(runtime.offset);
 }
 
+SWITCH_DECLARE(void) switch_micro_sleep(switch_interval_time_t t)
+{
+	do_sleep(t);
+}
+
 SWITCH_DECLARE(void) switch_sleep(switch_interval_time_t t)
 {
 
-#if defined(HAVE_USLEEP)
-	usleep(t);
-#elif defined(WIN32)
-	Sleep((DWORD) ((t) / 1000));
-#else
-	apr_sleep(t);
-#endif
+	if (t < 1000 || t >= 10000) {
+		do_sleep(t);
+		return;
+	}
+
+#ifndef DISABLE_1MS_COND
+	if (globals.use_cond_yield == 1) {
+		switch_cond_yield(t);
+		return;
+	}
+#endif	
 
-#if 0
-#if defined(HAVE_CLOCK_NANOSLEEP) && defined(SWITCH_USE_CLOCK_FUNCS)
-	struct timespec ts;
-	ts.tv_sec = t / APR_USEC_PER_SEC;
-	ts.tv_nsec = (t % APR_USEC_PER_SEC) * 1000;
-
-	clock_nanosleep(CLOCK_REALTIME, 0, &ts, NULL);
-
-#elif defined(HAVE_USLEEP)
-	usleep(t);
-#elif defined(WIN32)
-	Sleep((DWORD) ((t) / 1000));
+	do_sleep(t);
+}
+
+
+SWITCH_DECLARE(void) switch_cond_next(void)
+{
+#ifdef DISABLE_1MS_COND
+	do_sleep(1000);
 #else
-	apr_sleep(t);
-#endif
+	if (!runtime.timestamp || globals.use_cond_yield != 1) {
+		do_sleep(1000);
+		return;
+	}
+	switch_mutex_lock(TIMER_MATRIX[1].mutex);
+	switch_thread_cond_wait(TIMER_MATRIX[1].cond, TIMER_MATRIX[1].mutex);
+	switch_mutex_unlock(TIMER_MATRIX[1].mutex);
 #endif
+}
+
+SWITCH_DECLARE(void) switch_cond_yield(switch_interval_time_t t)
+{
+	switch_time_t want;
+	if (!t) return;
+
+	if (!runtime.timestamp || globals.use_cond_yield != 1) {
+		do_sleep(t);
+		return;
+	}
+	want = runtime.timestamp + t;
+	while(globals.RUNNING == 1 && globals.use_cond_yield == 1 && runtime.timestamp < want) {
+		switch_mutex_lock(TIMER_MATRIX[1].mutex);
+		if (runtime.timestamp < want) {
+			switch_thread_cond_wait(TIMER_MATRIX[1].cond, TIMER_MATRIX[1].mutex);
+		}
+		switch_mutex_unlock(TIMER_MATRIX[1].mutex);
+	}
+
 
 }
 
@@ -172,7 +230,7 @@
 	int sanity = 0;
 
 	while (globals.STARTED == 0) {
-		switch_yield(100000);
+		do_sleep(100000);
 		if (++sanity == 10) {
 			break;
 		}
@@ -183,10 +241,11 @@
 	}
 
 	if ((private_info = switch_core_alloc(timer->memory_pool, sizeof(*private_info)))) {
-#if defined(WIN32)
-		timeBeginPeriod(1);
-#endif
 		switch_mutex_lock(globals.mutex);
+		if (!TIMER_MATRIX[timer->interval].mutex) {
+			switch_mutex_init(&TIMER_MATRIX[timer->interval].mutex, SWITCH_MUTEX_NESTED, module_pool);
+			switch_thread_cond_create(&TIMER_MATRIX[timer->interval].cond, module_pool);
+		}
 		TIMER_MATRIX[timer->interval].count++;
 		switch_mutex_unlock(globals.mutex);
 		timer->private_info = private_info;
@@ -253,13 +312,27 @@
 {
 	timer_private_t *private_info = timer->private_info;
 
-	timer_step(timer);
+#ifdef DISABLE_1MS_COND
+	int cond_index = timer->interval;
+#else
+	int cond_index = 1;
+#endif
 
+	timer_step(timer);
+	
 	while (globals.RUNNING == 1 && private_info->ready && TIMER_MATRIX[timer->interval].tick < private_info->reference) {
 		check_roll();
-		switch_yield(1000);
+		if (globals.use_cond_yield == 1) {
+			switch_mutex_lock(TIMER_MATRIX[cond_index].mutex);		
+			if (TIMER_MATRIX[timer->interval].tick < private_info->reference) {
+				switch_thread_cond_wait(TIMER_MATRIX[cond_index].cond, TIMER_MATRIX[cond_index].mutex);	
+			}
+			switch_mutex_unlock(TIMER_MATRIX[cond_index].mutex);
+		} else {
+			do_sleep(1000);
+		}
 	}
-
+	
 	if (globals.RUNNING == 1) {
 		return SWITCH_STATUS_SUCCESS;
 	}
@@ -340,7 +413,7 @@
 				runtime.initiated = runtime.reference;
 				break;
 			}
-			switch_yield(STEP_MIC);
+			do_sleep(STEP_MIC);
 			last = ts;
 		}
 	}
@@ -349,8 +422,16 @@
 	last = 0;
 	fwd_errs = rev_errs = 0;
 
+#ifndef DISABLE_1MS_COND
+	switch_mutex_init(&TIMER_MATRIX[1].mutex, SWITCH_MUTEX_NESTED, module_pool);
+	switch_thread_cond_create(&TIMER_MATRIX[1].cond, module_pool);
+#endif
+
+	globals.use_cond_yield = globals.RUNNING == 1;
+
 	while (globals.RUNNING == 1) {
 		runtime.reference += STEP_MIC;
+
 		while ((ts = time_now(runtime.offset)) < runtime.reference) {
 			if (ts < last) {
 				if (MONO) {
@@ -368,7 +449,7 @@
 			} else {
 				rev_errs = 0;
 			}
-			switch_yield(STEP_MIC);
+			do_sleep(STEP_MIC);
 			last = ts;
 		}
 
@@ -413,11 +494,29 @@
 			tick = 0;
 		}
 
+#ifndef DISABLE_1MS_COND
+		TIMER_MATRIX[1].tick++;
+		if (switch_mutex_trylock(TIMER_MATRIX[1].mutex) == SWITCH_STATUS_SUCCESS) {
+			switch_thread_cond_broadcast(TIMER_MATRIX[1].cond);
+			switch_mutex_unlock(TIMER_MATRIX[1].mutex);
+		}
+		if (TIMER_MATRIX[1].tick == MAX_TICK) {
+			TIMER_MATRIX[1].tick = 0;
+			TIMER_MATRIX[1].roll++;
+		}
+#endif
+
 		if ((current_ms % MS_PER_TICK) == 0) {
 			for (x = MS_PER_TICK; x <= MAX_ELEMENTS; x += MS_PER_TICK) {
 				if ((current_ms % x) == 0) {
 					if (TIMER_MATRIX[x].count) {
 						TIMER_MATRIX[x].tick++;
+#ifdef DISABLE_1MS_COND
+						if (TIMER_MATRIX[x].mutex && switch_mutex_trylock(TIMER_MATRIX[x].mutex) == SWITCH_STATUS_SUCCESS) {
+							switch_thread_cond_broadcast(TIMER_MATRIX[x].cond);
+							switch_mutex_unlock(TIMER_MATRIX[x].mutex);
+						}
+#endif
 						if (TIMER_MATRIX[x].tick == MAX_TICK) {
 							TIMER_MATRIX[x].tick = 0;
 							TIMER_MATRIX[x].roll++;
@@ -431,10 +530,22 @@
 		}
 	}
 
+	globals.use_cond_yield = 0;
+	
+	for (x = MS_PER_TICK; x <= MAX_ELEMENTS; x += MS_PER_TICK) {
+		if (TIMER_MATRIX[x].mutex && switch_mutex_trylock(TIMER_MATRIX[x].mutex) == SWITCH_STATUS_SUCCESS) {
+			switch_thread_cond_broadcast(TIMER_MATRIX[x].cond);
+			switch_mutex_unlock(TIMER_MATRIX[x].mutex);
+		}
+	}
+
+
 	switch_mutex_lock(globals.mutex);
 	globals.RUNNING = 0;
 	switch_mutex_unlock(globals.mutex);
 
+	
+
 	return SWITCH_STATUS_TERM;
 }
 
@@ -616,6 +727,10 @@
 	switch_timer_interface_t *timer_interface;
 	module_pool = pool;
 
+#if defined(WIN32)
+	timeBeginPeriod(1);
+#endif
+	
 	memset(&globals, 0, sizeof(globals));
 	switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, module_pool);
 
@@ -636,19 +751,20 @@
 	timer_interface->timer_destroy = timer_destroy;
 
 	/* indicate that the module should continue to be loaded */
-	return SWITCH_STATUS_SUCCESS;
+	return SWITCH_STATUS_NOUNLOAD;
 }
 
 SWITCH_MODULE_SHUTDOWN_FUNCTION(softtimer_shutdown)
 {
+	globals.use_cond_yield = 0;
 
-	if (globals.RUNNING) {
+	if (globals.RUNNING == 1) {
 		switch_mutex_lock(globals.mutex);
 		globals.RUNNING = -1;
 		switch_mutex_unlock(globals.mutex);
 
-		while (globals.RUNNING) {
-			switch_yield(10000);
+		while (globals.RUNNING == -1) {
+			do_sleep(10000);
 		}
 	}
 #if defined(WIN32)

Modified: freeswitch/branches/gmaruzz/src/switch_xml.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_xml.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_xml.c	Mon Nov 17 14:18:32 2008
@@ -228,7 +228,30 @@
 	return status;
 }
 
-SWITCH_DECLARE(switch_status_t) switch_xml_bind_search_function(switch_xml_search_function_t function, switch_xml_section_t sections, void *user_data)
+SWITCH_DECLARE(void) switch_xml_set_binding_sections(switch_xml_binding_t *binding, switch_xml_section_t sections)
+{
+	switch_assert(binding);
+	binding->sections = sections;
+}
+
+SWITCH_DECLARE(void) switch_xml_set_binding_user_data(switch_xml_binding_t *binding, void *user_data)
+{
+	switch_assert(binding);
+	binding->user_data = user_data;
+}
+
+SWITCH_DECLARE(switch_xml_section_t) switch_xml_get_binding_sections(switch_xml_binding_t *binding)
+{
+	return binding->sections;
+}
+
+SWITCH_DECLARE(void *) switch_xml_get_binding_user_data(switch_xml_binding_t *binding)
+{
+	return binding->user_data;
+}
+
+
+SWITCH_DECLARE(switch_status_t) switch_xml_bind_search_function_ret(switch_xml_search_function_t function, switch_xml_section_t sections, void *user_data, switch_xml_binding_t **ret_binding)
 {
 	switch_xml_binding_t *binding = NULL, *ptr = NULL;
 	assert(function != NULL);
@@ -249,6 +272,11 @@
 	} else {
 		BINDINGS = binding;
 	}
+
+	if (ret_binding) {
+		*ret_binding = binding;
+	}
+
 	switch_thread_rwlock_unlock(B_RWLOCK);
 
 	return SWITCH_STATUS_SUCCESS;
@@ -1069,6 +1097,53 @@
 	return ebuf;
 }
 
+static int preprocess_exec(const char *cwd, const char *command, int write_fd, int rlevel)
+{
+#ifdef WIN32
+	char message[] = "<!-- exec not implemented in windows yet -->";
+
+	if (write(write_fd, message, sizeof(message)) < 0) {
+		goto end;
+	}
+
+#else
+	int fds[2], pid = 0;
+
+	if (pipe(fds)) {
+		goto end;
+	} else { /* good to go*/
+		pid = fork();
+
+		if (pid < 0) { /* ok maybe not */
+			close(fds[0]);
+			close(fds[1]);
+			goto end;
+		} else if (pid) { /* parent */
+			char buf[1024] = "";
+			int bytes;
+			close(fds[1]);
+			while ((bytes = read(fds[0], buf, sizeof(buf))) > 0) {
+				if (write(write_fd, buf, bytes) <= 0) {
+					break;
+				}
+			}
+			close(fds[0]);
+		} else { /*  child */
+			close(fds[0]);
+			dup2(fds[1], STDOUT_FILENO);
+			system(command);
+			close(fds[1]);
+			exit(0);
+		}
+	}
+#endif
+ end:
+
+	return write_fd;
+	
+}
+
+
 static int preprocess_glob(const char *cwd, const char *pattern, int write_fd, int rlevel)
 {
 	char *full_path = NULL;
@@ -1216,6 +1291,8 @@
 				
 			} else if (!strcasecmp(tcmd, "include")) {
 				preprocess_glob(cwd, targ, write_fd, rlevel + 1);
+			} else if (!strcasecmp(tcmd, "exec")) {
+				preprocess_exec(cwd, targ, write_fd, rlevel + 1);
 			}
 
 			continue;
@@ -1272,6 +1349,8 @@
 
 				} else if (!strcasecmp(cmd, "include")) {
 					preprocess_glob(cwd, arg, write_fd, rlevel + 1);
+				} else if (!strcasecmp(cmd, "exec")) {
+					preprocess_exec(cwd, arg, write_fd, rlevel + 1);
 				}
 			}
 

Modified: freeswitch/branches/gmaruzz/w32/Library/FreeSwitchCore.vcproj
==============================================================================
--- freeswitch/branches/gmaruzz/w32/Library/FreeSwitchCore.vcproj	(original)
+++ freeswitch/branches/gmaruzz/w32/Library/FreeSwitchCore.vcproj	Mon Nov 17 14:18:32 2008
@@ -407,6 +407,10 @@
 				</FileConfiguration>
 			</File>
 			<File
+				RelativePath="..\..\src\switch_dso.c"
+				>
+			</File>
+			<File
 				RelativePath="..\..\src\switch_event.c"
 				>
 			</File>
@@ -553,11 +557,11 @@
 				>
 			</File>
 			<File
-				RelativePath="..\..\src\include\private\switch_core.h"
+				RelativePath="..\..\src\include\switch_core.h"
 				>
 			</File>
 			<File
-				RelativePath="..\..\src\include\switch_core.h"
+				RelativePath="..\..\src\include\private\switch_core.h"
 				>
 			</File>
 			<File
@@ -573,6 +577,10 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\src\include\switch_dso.h"
+				>
+			</File>
+			<File
 				RelativePath="..\..\src\include\switch_event.h"
 				>
 			</File>



More information about the Freeswitch-branches mailing list