[Freeswitch-branches] [commit] r4806 - in freeswitch/branches/mikej/sofiasip-upgrade: . build libs/libteletone/src src src/include src/include/private src/mod/applications/mod_bridgecall src/mod/applications/mod_commands src/mod/applications/mod_conference src/mod/applications/mod_dptools src/mod/applications/mod_echo src/mod/applications/mod_enum src/mod/applications/mod_ivrtest src/mod/applications/mod_park src/mod/applications/mod_playback src/mod/applications/mod_rss src/mod/asr_tts/mod_cepstral src/mod/codecs/mod_amr src/mod/codecs/mod_g711 src/mod/codecs/mod_g722 src/mod/codecs/mod_g723_1 src/mod/codecs/mod_g726 src/mod/codecs/mod_g729 src/mod/codecs/mod_gsm src/mod/codecs/mod_ilbc src/mod/codecs/mod_l16 src/mod/codecs/mod_lpc10 src/mod/codecs/mod_speex src/mod/dialplans/mod_dialplan_directory src/mod/dialplans/mod_dialplan_xml src/mod/directories/mod_ldap src/mod/endpoints/mod_dingaling src/mod/endpoints/mod_iax src/mod/endpoints/mod_portaudio src/mod/endpoints/mod_sofia src/mod/endpoints/mod_wanpipe src/mod/endpoints/mod_wanpipe/libsangoma src/mod/endpoints/mod_woomera src/mod/event_handlers/mod_cdr src/mod/event_handlers/mod_event_multicast src/mod/event_handlers/mod_event_socket src/mod/event_handlers/mod_event_test src/mod/event_handlers/mod_xmpp_event src/mod/event_handlers/mod_zeroconf src/mod/formats/mod_native_file src/mod/formats/mod_shout src/mod/formats/mod_sndfile src/mod/languages/mod_mono src/mod/languages/mod_perl src/mod/languages/mod_python src/mod/languages/mod_spidermonkey src/mod/languages/mod_spidermonkey_core_db src/mod/languages/mod_spidermonkey_etpan src/mod/languages/mod_spidermonkey_odbc src/mod/languages/mod_spidermonkey_skel src/mod/languages/mod_spidermonkey_teletone src/mod/loggers/mod_console src/mod/loggers/mod_syslog src/mod/say/mod_say_en src/mod/timers/mod_softtimer src/mod/xml_int/mod_xml_cdr src/mod/xml_int/mod_xml_curl src/mod/xml_int/mod_xml_rpc w32/Library

Freeswitch SVN mikej at freeswitch.org
Fri Mar 30 12:19:18 EDT 2007


Author: mikej
Date: Fri Mar 30 12:19:18 2007
New Revision: 4806

Added:
   freeswitch/branches/mikej/sofiasip-upgrade/src/include/private/
      - copied from r4805, /freeswitch/trunk/src/include/private/
   freeswitch/branches/mikej/sofiasip-upgrade/src/include/private/switch_core.h
      - copied unchanged from r4805, /freeswitch/trunk/src/include/private/switch_core.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_core_event_hook.h
      - copied unchanged from r4805, /freeswitch/trunk/src/include/switch_core_event_hook.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_scheduler.h
      - copied unchanged from r4805, /freeswitch/trunk/src/include/switch_scheduler.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_core_asr.c
      - copied unchanged from r4803, /freeswitch/trunk/src/switch_core_asr.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_core_codec.c
      - copied unchanged from r4805, /freeswitch/trunk/src/switch_core_codec.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_core_directory.c
      - copied unchanged from r4805, /freeswitch/trunk/src/switch_core_directory.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_core_event_hook.c
      - copied unchanged from r4803, /freeswitch/trunk/src/switch_core_event_hook.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_core_file.c
      - copied unchanged from r4805, /freeswitch/trunk/src/switch_core_file.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_core_hash.c
      - copied unchanged from r4803, /freeswitch/trunk/src/switch_core_hash.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_core_io.c
      - copied unchanged from r4803, /freeswitch/trunk/src/switch_core_io.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_core_media_bug.c
      - copied unchanged from r4803, /freeswitch/trunk/src/switch_core_media_bug.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_core_memory.c
      - copied unchanged from r4805, /freeswitch/trunk/src/switch_core_memory.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_core_port_allocator.c
      - copied unchanged from r4805, /freeswitch/trunk/src/switch_core_port_allocator.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_core_rwlock.c
      - copied unchanged from r4805, /freeswitch/trunk/src/switch_core_rwlock.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_core_session.c
      - copied unchanged from r4803, /freeswitch/trunk/src/switch_core_session.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_core_speech.c
      - copied unchanged from r4805, /freeswitch/trunk/src/switch_core_speech.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_core_sqldb.c
      - copied unchanged from r4803, /freeswitch/trunk/src/switch_core_sqldb.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_core_state_machine.c
      - copied unchanged from r4805, /freeswitch/trunk/src/switch_core_state_machine.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_core_timer.c
      - copied unchanged from r4803, /freeswitch/trunk/src/switch_core_timer.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_ivr_async.c
      - copied unchanged from r4803, /freeswitch/trunk/src/switch_ivr_async.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_ivr_bridge.c
      - copied unchanged from r4803, /freeswitch/trunk/src/switch_ivr_bridge.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_ivr_menu.c
      - copied unchanged from r4803, /freeswitch/trunk/src/switch_ivr_menu.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_ivr_originate.c
      - copied unchanged from r4805, /freeswitch/trunk/src/switch_ivr_originate.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_ivr_play_say.c
      - copied unchanged from r4805, /freeswitch/trunk/src/switch_ivr_play_say.c
Modified:
   freeswitch/branches/mikej/sofiasip-upgrade/Makefile.am
   freeswitch/branches/mikej/sofiasip-upgrade/build/indent_options.sh
   freeswitch/branches/mikej/sofiasip-upgrade/configure.in
   freeswitch/branches/mikej/sofiasip-upgrade/libs/libteletone/src/libteletone.h
   freeswitch/branches/mikej/sofiasip-upgrade/libs/libteletone/src/libteletone_detect.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_am_config.h.in
   freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_apr.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_bitpack.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_buffer.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_caller.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_channel.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_config.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_console.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_core.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_core_db.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_event.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_frame.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_ivr.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_loadable_module.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_log.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_module_interfaces.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_platform.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_regex.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_resample.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_rtp.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_sqlite.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_stun.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_types.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_utils.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_xml.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_bridgecall/mod_bridgecall.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_commands/mod_commands.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_conference/mod_conference.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_dptools/mod_dptools.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_echo/mod_echo.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_enum/mod_enum.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_ivrtest/mod_ivrtest.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_park/mod_park.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_playback/mod_playback.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_rss/mod_rss.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/asr_tts/mod_cepstral/mod_cepstral.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_amr/mod_amr.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_g711/mod_g711.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_g722/mod_g722.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_g723_1/mod_g723_1.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_g726/mod_g726.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_g729/mod_g729.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_gsm/mod_gsm.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_ilbc/mod_ilbc.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_l16/mod_l16.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_lpc10/mod_lpc10.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_speex/mod_speex.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/dialplans/mod_dialplan_directory/mod_dialplan_directory.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/directories/mod_ldap/mod_ldap.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_dingaling/mod_dingaling.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_iax/mod_iax.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_portaudio/mod_portaudio.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_portaudio/pa_ringbuffer.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_portaudio/pa_ringbuffer.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_portaudio/pablio.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_portaudio/pablio.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/mod_sofia.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/libsangoma/g711.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/libsangoma/sangoma_pri.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/libsangoma/sangoma_pri.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/libsangoma/win_api_common.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/sigboost.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/ss7boost_client.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/ss7boost_client.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_woomera/mod_woomera.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/basecdr.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/baseregistry.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/cdrcontainer.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/csvcdr.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/curlcdr.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/mysqlcdr.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/odbccdr.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/pddcdr.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/sqlitecdr.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/xmlcdr.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_event_socket/mod_event_socket.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_event_test/mod_event_test.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_xmpp_event/mod_xmpp_event.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_zeroconf/mod_zeroconf.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_native_file/mod_native_file.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/common.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/dct64_i386.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/decode_i386.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/decode_ntom.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/huffman.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/interface.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/layer3.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/mod_shout.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/mpg123.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/mpglib.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/tabinit.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_sndfile/mod_sndfile.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_mono/mod_mono.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_perl/mod_perl.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_perl/perlxsi.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_perl/switch_swig_wrap.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_python/freeswitch_python.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_python/mod_python.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_python/switch_swig_wrap.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey/mod_spidermonkey.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey_core_db/mod_spidermonkey_core_db.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey_etpan/mod_spidermonkey_etpan.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey_odbc/mod_spidermonkey_odbc.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey_skel/mod_spidermonkey_skel.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey_teletone/mod_spidermonkey_teletone.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/loggers/mod_console/mod_console.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/loggers/mod_syslog/mod_syslog.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/say/mod_say_en/mod_say_en.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/timers/mod_softtimer/mod_softtimer.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/xml_int/mod_xml_curl/mod_xml_curl.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_apr.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_buffer.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_caller.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_channel.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_config.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_console.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_core.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_core_db.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_event.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_ivr.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_loadable_module.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_log.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_regex.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_resample.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_rtp.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_stun.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_swig.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_utils.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_xml.c
   freeswitch/branches/mikej/sofiasip-upgrade/w32/Library/FreeSwitchCore.vcproj

Log:
merged changes from trunk revisions 4788-4805.

Modified: freeswitch/branches/mikej/sofiasip-upgrade/Makefile.am
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/Makefile.am	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/Makefile.am	Fri Mar 30 12:19:18 2007
@@ -11,6 +11,7 @@
 OSARCH=`uname -s`
 
 LIBTOOL=`if test -z "$(VERBOSE)" ; then echo $(SHELL) $(switch_builddir)/quiet_libtool ;else echo $(switch_builddir)/libtool;  fi;`
+#LIBS+=> core.log || error="yes";if test -n "$(VERBOSE)" -o "$$error" = "yes";then cat core.log;fi;if test "$$error" = "yes";then exit 1;fi
 
 LTINSTALL = $(LIBTOOL) --mode=install $(INSTALL)
 TOUCH_TARGET=if test -f "$@" ; then touch "$@" ; fi ;
@@ -26,7 +27,24 @@
 src/switch_caller.c \
 src/switch_channel.c \
 src/switch_console.c \
+src/switch_core_media_bug.c \
+src/switch_core_timer.c \
+src/switch_core_asr.c \
+src/switch_core_event_hook.c \
+src/switch_core_speech.c \
+src/switch_core_memory.c \
+src/switch_core_codec.c \
+src/switch_core_file.c \
+src/switch_core_hash.c \
+src/switch_core_sqldb.c \
+src/switch_core_session.c \
+src/switch_core_directory.c \
+src/switch_core_state_machine.c \
+src/switch_core_io.c \
+src/switch_core_rwlock.c \
+src/switch_core_port_allocator.c \
 src/switch_core.c \
+src/switch_scheduler.c \
 src/switch_core_db.c\
 src/switch_loadable_module.c \
 src/switch_utils.c \
@@ -34,6 +52,11 @@
 src/switch_resample.c \
 src/switch_regex.c\
 src/switch_rtp.c\
+src/switch_ivr_bridge.c \
+src/switch_ivr_originate.c \
+src/switch_ivr_async.c \
+src/switch_ivr_play_say.c \
+src/switch_ivr_menu.c \
 src/switch_ivr.c \
 src/switch_stun.c\
 src/switch_log.c\
@@ -52,6 +75,8 @@
 src/include/switch_caller.h\
 src/include/switch_channel.h\
 src/include/switch_console.h\
+src/include/switch_core_event_hook.h\
+src/include/switch_scheduler.h\
 src/include/switch_core.h\
 src/include/switch_core_db.h\
 src/include/switch_event.h\
@@ -81,7 +106,6 @@
 CORE_CFLAGS    += -I$(switch_srcdir)/libs/srtp/include
 CORE_CFLAGS    += -I$(switch_srcdir)/libs/srtp/crypto/include
 CORE_CFLAGS    += $(RESAMPLE_CFLAGS)
-CORE_CFLAGS    += -I$(switch_srcdir)/libs/libteletone/src
 
 CORE_LIBS      = libs/apr/libapr-1.la libs/apr-util/libaprutil-1.la
 CORE_LIBS     += libs/sqlite/libsqlite3.la libs/pcre/libpcre.la

Modified: freeswitch/branches/mikej/sofiasip-upgrade/build/indent_options.sh
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/build/indent_options.sh	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/build/indent_options.sh	Fri Mar 30 12:19:18 2007
@@ -1,4 +1,4 @@
 #!/bin/bash
-echo -n "-brs -npsl -di0 -br -ce -d0 -cli0 -npcs -nfc1 -ut -i4 -ts4 -l120 -cs -T size_t " > ../.indent.pro
-grep typedef ../src/include/*.h | grep switch_ | grep -v "\*\|{"  | sed -e s/struct// | perl -ne '@l = split; $l[2] =~ s/;//g ; print "-T $l[2] "' >> ../.indent.pro
-grep "} switch_" ../src/include/*.h | perl -ne '@l = split; $l[1] =~ s/;//g ; print " -T $l[1] "' >> ../.indent.pro
+echo -n "-brs -npsl -di0 -br -ce -d0 -cli0 -npcs -nfc1 -ut -i4 -ts4 -l155 -cs -T size_t " > ./.indent.pro
+grep typedef ./src/include/*.h | grep switch_ | grep -v "\*\|{"  | sed -e s/struct// | perl -ne '@l = split; $l[2] =~ s/;//g ; print "-T $l[2] "' >> ./.indent.pro
+grep "} switch_" ./src/include/*.h | perl -ne '@l = split; $l[1] =~ s/;//g ; print " -T $l[1] "' >> ./.indent.pro

Modified: freeswitch/branches/mikej/sofiasip-upgrade/configure.in
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/configure.in	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/configure.in	Fri Mar 30 12:19:18 2007
@@ -78,8 +78,8 @@
 AM_CONDITIONAL([USE_INTREE_RESAMPLE],[test "${enable_resample}" = "yes"])
 
 # set defaults for use on all platforms
-SWITCH_AM_CFLAGS="-I${switch_srcdir}/src/include"
-SWITCH_AM_CXXFLAGS="-I${switch_srcdir}/src/include"
+SWITCH_AM_CFLAGS="-I${switch_srcdir}/src/include -I${switch_srcdir}/libs/libteletone/src"
+SWITCH_AM_CXXFLAGS="-I${switch_srcdir}/src/include -I${switch_srcdir}/libs/libteletone/src"
 SWITCH_AM_LDFLAGS="-lm -L/usr/local/lib"
 
 #set SOLINK variable based on compiler and host
@@ -171,7 +171,6 @@
 AC_CHECK_SIZEOF(long, 4)
 AC_CHECK_SIZEOF(short, 2)
 AC_CHECK_SIZEOF(long long, 8)
-AC_CHECK_SIZEOF(time_t, 4)
 AC_TYPE_SIZE_T
 AC_CHECK_TYPE(ssize_t, int)
 
@@ -247,16 +246,6 @@
     size_t_fmt='#error Can not determine the proper size for size_t'
 fi
 
-if test "$ac_cv_sizeof_time_t" = "$ac_cv_sizeof_int"; then
-   time_t_fmt='#define TIME_T_FMT "d"' 
-elif  test "$ac_cv_sizeof_time_t" = "$ac_cv_sizeof_long"; then
-   time_t_fmt='#define TIME_T_FMT "ld"'
-elif  test "$ac_cv_sizeof_time_t" = "$ac_cv_sizeof_long_long"; then
-   time_t_fmt='#define TIME_T_FMT "lld"'
-else
-    time_t_fmt='#error Can not determine the proper format specifier for time_t of size $ac_cv_sizeof_time_t'
-fi
-
 # Basically, we have tried to figure out the correct format strings
 # for SWITCH types which vary between platforms, but we don't always get 
 # it right.  If you find that we don't get it right for your platform, 
@@ -305,7 +294,6 @@
 AC_SUBST(uint64_t_fmt) 
 AC_SUBST(ssize_t_fmt) 
 AC_SUBST(size_t_fmt)
-AC_SUBST(time_t_fmt)
 
 AC_PATH_PROGS(ZCAT, gunzip gzcat gzip zcat)
 AC_PATH_PROGS(TAR, gtar tar)

Modified: freeswitch/branches/mikej/sofiasip-upgrade/libs/libteletone/src/libteletone.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/libs/libteletone/src/libteletone.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/libs/libteletone/src/libteletone.h	Fri Mar 30 12:19:18 2007
@@ -59,7 +59,7 @@
 #endif
 
 #ifdef _MSC_VER
-#define int16_t __int16
+typedef __int16 int16_t;
 #endif
 
 #include <libteletone_generate.h>

Modified: freeswitch/branches/mikej/sofiasip-upgrade/libs/libteletone/src/libteletone_detect.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/libs/libteletone/src/libteletone_detect.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/libs/libteletone/src/libteletone_detect.h	Fri Mar 30 12:19:18 2007
@@ -64,10 +64,12 @@
 	This module is responsible for tone detection specifics
 */
 
+#ifndef FALSE
 #define FALSE   0
 #ifndef TRUE
 #define TRUE    (!FALSE)
 #endif
+#endif
 
 /* Basic DTMF specs:
  *

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch.h	Fri Mar 30 12:19:18 2007
@@ -90,7 +90,9 @@
 #include <switch_stun.h>
 #include <switch_log.h>
 #include <switch_xml.h>
-
+#include <switch_core_event_hook.h>
+#include <switch_scheduler.h>
+#include <libteletone.h>
 
 /** \mainpage FreeSWITCH
  * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_am_config.h.in
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_am_config.h.in	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_am_config.h.in	Fri Mar 30 12:19:18 2007
@@ -15,6 +15,5 @@
 @size_t_fmt@
 @int64_t_fmt@
 @uint64_t_fmt@
- at time_t_fmt@
 
 #endif

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_apr.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_apr.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_apr.h	Fri Mar 30 12:19:18 2007
@@ -40,25 +40,22 @@
 #define SWITCH_APR_H
 
 SWITCH_BEGIN_EXTERN_C
-
 /*
    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.
 */
-
 /**
  * @defgroup switch_apr Brought To You By APR
  * @ingroup FREESWITCH
  * @{
- */	
-
+ */
 /**
  * @defgroup switch_memory_pool Memory Pool Functions
  * @ingroup switch_apr 
  * @{
  */
 /** The fundamental pool type */
-typedef struct apr_pool_t switch_memory_pool_t;
+	typedef struct apr_pool_t switch_memory_pool_t;
 
 
 /**
@@ -81,12 +78,12 @@
 /**
  * Structure for referencing dynamic objects
  */
-typedef struct apr_dso_handle_t       switch_dso_handle_t;
+	 typedef struct apr_dso_handle_t switch_dso_handle_t;
 
 /**
  * Structure for referencing symbols from dynamic objects
  */
-typedef void *                        switch_dso_handle_sym_t;
+	 typedef void *switch_dso_handle_sym_t;
 
 /**
  * Load a DSO library.
@@ -96,14 +93,13 @@
  * @bug We aught to provide an alternative to RTLD_GLOBAL, which
  * is the only supported method of loading DSOs today.
  */
-SWITCH_DECLARE(switch_status_t) switch_dso_load(switch_dso_handle_t **res_handle, 
-                                       const char *path, switch_memory_pool_t *ctx);
+SWITCH_DECLARE(switch_status_t) switch_dso_load(switch_dso_handle_t ** res_handle, const char *path, switch_memory_pool_t *ctx);
 
 /**
  * Close a DSO library.
  * @param handle handle to close.
  */
-SWITCH_DECLARE(switch_status_t) switch_dso_unload(switch_dso_handle_t *handle);
+SWITCH_DECLARE(switch_status_t) switch_dso_unload(switch_dso_handle_t * handle);
 
 /**
  * Load a symbol from a DSO handle.
@@ -111,9 +107,7 @@
  * @param handle handle to load the symbol from.
  * @param symname Name of the symbol to load.
  */
-SWITCH_DECLARE(switch_status_t) switch_dso_sym(switch_dso_handle_sym_t *ressym, 
-                                      switch_dso_handle_t *handle,
-                                      const char *symname);
+SWITCH_DECLARE(switch_status_t) switch_dso_sym(switch_dso_handle_sym_t * ressym, switch_dso_handle_t * handle, const char *symname);
 
 /**
  * Report more information when a DSO function fails.
@@ -121,7 +115,7 @@
  * @param buf Location to store the dso error
  * @param bufsize The size of the provided buffer
  */
-SWITCH_DECLARE(const char *) switch_dso_error(switch_dso_handle_t *dso, char *buf, size_t bufsize);
+SWITCH_DECLARE(const char *) switch_dso_error(switch_dso_handle_t * dso, char *buf, size_t bufsize);
 
 /** @} */
 
@@ -146,10 +140,10 @@
  */
 
 /** Abstract type for hash tables. */
-typedef struct apr_hash_t switch_hash_t;
+	 typedef struct apr_hash_t switch_hash_t;
 
 /** Abstract type for scanning hash tables. */
-typedef struct apr_hash_index_t switch_hash_index_t;
+	 typedef struct apr_hash_index_t switch_hash_index_t;
 
 /**
  * When passing a key to switch_hashfunc_default, this value can be
@@ -169,7 +163,7 @@
  * progress at the same time.
 
  */
-SWITCH_DECLARE(switch_hash_index_t *) switch_hash_first(switch_memory_pool_t *p, switch_hash_t *ht);
+SWITCH_DECLARE(switch_hash_index_t *) switch_hash_first(switch_memory_pool_t *p, switch_hash_t * ht);
 
 /**
  * Continue iterating over the entries in a hash table.
@@ -177,7 +171,7 @@
  * @return a pointer to the updated iteration state.  NULL if there are no more  
  *         entries.
  */
-SWITCH_DECLARE(switch_hash_index_t *) switch_hash_next(switch_hash_index_t *ht);
+SWITCH_DECLARE(switch_hash_index_t *) switch_hash_next(switch_hash_index_t * ht);
 
 /**
  * Get the current entry's details from the iteration state.
@@ -188,7 +182,7 @@
  * @remark The return pointers should point to a variable that will be set to the
  *         corresponding data, or they may be NULL if the data isn't interesting.
  */
-SWITCH_DECLARE(void) switch_hash_this(switch_hash_index_t *hi, const void **key, switch_ssize_t *klen, void **val);
+SWITCH_DECLARE(void) switch_hash_this(switch_hash_index_t * hi, const void **key, switch_ssize_t *klen, void **val);
 
 /**
  * The default hash function.
@@ -198,7 +192,7 @@
  */
 SWITCH_DECLARE(unsigned int) switch_hashfunc_default(const char *key, switch_ssize_t *klen);
 
-SWITCH_DECLARE(switch_memory_pool_t *) switch_hash_pool_get(switch_hash_t *ht);
+SWITCH_DECLARE(switch_memory_pool_t *) switch_hash_pool_get(switch_hash_t * ht);
 
 /** @} */
  /**
@@ -208,40 +202,40 @@
  */
 
  /** number of microseconds since 00:00:00 january 1, 1970 UTC */
-typedef int64_t switch_time_t;
+	 typedef int64_t switch_time_t;
 
  /** number of microseconds in the interval */
-typedef int64_t switch_interval_time_t;
+	 typedef int64_t switch_interval_time_t;
 
 /**
  * a structure similar to ANSI struct tm with the following differences:
  *  - tm_usec isn't an ANSI field
  *  - tm_gmtoff isn't an ANSI field (it's a bsdism)
  */
-typedef struct switch_time_exp_t {
-    /** microseconds past tm_sec */
-    int32_t tm_usec;
-    /** (0-61) seconds past tm_min */
-    int32_t tm_sec;
-    /** (0-59) minutes past tm_hour */
-    int32_t tm_min;
-    /** (0-23) hours past midnight */
-    int32_t tm_hour;
-    /** (1-31) day of the month */
-    int32_t tm_mday;
-    /** (0-11) month of the year */
-    int32_t tm_mon;
-    /** year since 1900 */
-    int32_t tm_year;
-    /** (0-6) days since sunday */
-    int32_t tm_wday;
-    /** (0-365) days since jan 1 */
-    int32_t tm_yday;
-    /** daylight saving time */
-    int32_t tm_isdst;
-    /** seconds east of UTC */
-    int32_t tm_gmtoff;
-} switch_time_exp_t;
+	 typedef struct switch_time_exp_t {
+	/** microseconds past tm_sec */
+		 int32_t tm_usec;
+	/** (0-61) seconds past tm_min */
+		 int32_t tm_sec;
+	/** (0-59) minutes past tm_hour */
+		 int32_t tm_min;
+	/** (0-23) hours past midnight */
+		 int32_t tm_hour;
+	/** (1-31) day of the month */
+		 int32_t tm_mday;
+	/** (0-11) month of the year */
+		 int32_t tm_mon;
+	/** year since 1900 */
+		 int32_t tm_year;
+	/** (0-6) days since sunday */
+		 int32_t tm_wday;
+	/** (0-365) days since jan 1 */
+		 int32_t tm_yday;
+	/** daylight saving time */
+		 int32_t tm_isdst;
+	/** seconds east of UTC */
+		 int32_t tm_gmtoff;
+	 } switch_time_exp_t;
 
 SWITCH_DECLARE(switch_time_t) switch_time_make(switch_time_t sec, int32_t usec);
 
@@ -256,7 +250,7 @@
  * @param result the resulting imploded time
  * @param input the input exploded time
  */
-SWITCH_DECLARE(switch_status_t) switch_time_exp_gmt_get(switch_time_t *result, switch_time_exp_t *input);
+SWITCH_DECLARE(switch_status_t) switch_time_exp_gmt_get(switch_time_t * result, switch_time_exp_t * input);
 
 /**
  * formats the exploded time according to the format specified
@@ -266,11 +260,7 @@
  * @param format The format for the time string
  * @param tm The time to convert
  */
-SWITCH_DECLARE(switch_status_t) switch_strftime(char *s,
-												switch_size_t *retsize,
-												switch_size_t max,
-												const char *format,
-												switch_time_exp_t *tm);
+SWITCH_DECLARE(switch_status_t) switch_strftime(char *s, switch_size_t *retsize, switch_size_t max, const char *format, switch_time_exp_t * tm);
 
 /**
  * switch_rfc822_date formats dates in the RFC822
@@ -287,7 +277,7 @@
  * @param result the exploded time
  * @param input the time to explode
  */
-SWITCH_DECLARE(switch_status_t) switch_time_exp_gmt(switch_time_exp_t *result, switch_time_t input);
+SWITCH_DECLARE(switch_status_t) switch_time_exp_gmt(switch_time_exp_t * result, switch_time_t input);
 
 /**
  * Convert time value from human readable format to a numeric apr_time_t 
@@ -295,14 +285,14 @@
  * @param result the resulting imploded time
  * @param input the input exploded time
  */
-SWITCH_DECLARE(switch_status_t) switch_time_exp_get(switch_time_t *result, switch_time_exp_t *input);
+SWITCH_DECLARE(switch_status_t) switch_time_exp_get(switch_time_t * result, switch_time_exp_t * input);
 
 /**
  * convert a time to its human readable components in local timezone
  * @param result the exploded time
  * @param input the time to explode
  */
-SWITCH_DECLARE(switch_status_t) switch_time_exp_lt(switch_time_exp_t *result, switch_time_t input);
+SWITCH_DECLARE(switch_status_t) switch_time_exp_lt(switch_time_exp_t * result, switch_time_t input);
 
 /**
  * Sleep for the specified number of micro-seconds.
@@ -320,7 +310,7 @@
  */
 
 /** Opaque thread-local mutex structure */
-typedef struct apr_thread_mutex_t switch_mutex_t;
+	 typedef struct apr_thread_mutex_t switch_mutex_t;
 
 /** Lock Flags */
 #define SWITCH_MUTEX_DEFAULT	0x0	/**< platform-optimal lock behavior */
@@ -343,29 +333,27 @@
  * it will behave as either a nested or an unnested lock.
  *
 */
-SWITCH_DECLARE(switch_status_t) switch_mutex_init(switch_mutex_t **lock,
-												unsigned int flags,
-												switch_memory_pool_t *pool);
+SWITCH_DECLARE(switch_status_t) switch_mutex_init(switch_mutex_t ** lock, unsigned int flags, switch_memory_pool_t *pool);
 
 
 /**
  * Destroy the mutex and free the memory associated with the lock.
  * @param lock the mutex to destroy.
  */
-SWITCH_DECLARE(switch_status_t) switch_mutex_destroy(switch_mutex_t *lock);
+SWITCH_DECLARE(switch_status_t) switch_mutex_destroy(switch_mutex_t * lock);
 
 /**
  * Acquire the lock for the given mutex. If the mutex is already locked,
  * the current thread will be put to sleep until the lock becomes available.
  * @param lock the mutex on which to acquire the lock.
  */
-SWITCH_DECLARE(switch_status_t) switch_mutex_lock(switch_mutex_t *lock);
+SWITCH_DECLARE(switch_status_t) switch_mutex_lock(switch_mutex_t * lock);
 
 /**
  * Release the lock for the given mutex.
  * @param lock the mutex from which to release the lock.
  */
-SWITCH_DECLARE(switch_status_t) switch_mutex_unlock(switch_mutex_t *lock);
+SWITCH_DECLARE(switch_status_t) switch_mutex_unlock(switch_mutex_t * lock);
 
 /**
  * Attempt to acquire the lock for the given mutex. If the mutex has already
@@ -374,7 +362,7 @@
  * if the return value was APR_EBUSY, for portability reasons.
  * @param lock the mutex on which to attempt the lock acquiring.
  */
-SWITCH_DECLARE(switch_status_t) switch_mutex_trylock(switch_mutex_t *lock);
+SWITCH_DECLARE(switch_status_t) switch_mutex_trylock(switch_mutex_t * lock);
 
 /** @} */
 
@@ -385,17 +373,16 @@
  */
 
 /** Opaque structure used for the rwlock */
-typedef struct apr_thread_rwlock_t switch_thread_rwlock_t;
+	 typedef struct apr_thread_rwlock_t switch_thread_rwlock_t;
 
-SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_create(switch_thread_rwlock_t **rwlock,
-                                                  switch_memory_pool_t *pool);
-SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_destroy(switch_thread_rwlock_t *rwlock);
-SWITCH_DECLARE(switch_memory_pool_t *) switch_thread_rwlock_pool_get(switch_thread_rwlock_t *rwlock);
-SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_rdlock(switch_thread_rwlock_t *rwlock);
-SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_tryrdlock(switch_thread_rwlock_t *rwlock);
-SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_wrlock(switch_thread_rwlock_t *rwlock);
-SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_trywrlock(switch_thread_rwlock_t *rwlock);
-SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock);
+SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_create(switch_thread_rwlock_t ** rwlock, switch_memory_pool_t *pool);
+SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_destroy(switch_thread_rwlock_t * rwlock);
+SWITCH_DECLARE(switch_memory_pool_t *) switch_thread_rwlock_pool_get(switch_thread_rwlock_t * rwlock);
+SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_rdlock(switch_thread_rwlock_t * rwlock);
+SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_tryrdlock(switch_thread_rwlock_t * rwlock);
+SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_wrlock(switch_thread_rwlock_t * rwlock);
+SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_trywrlock(switch_thread_rwlock_t * rwlock);
+SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_unlock(switch_thread_rwlock_t * rwlock);
 
 /** @} */
 
@@ -412,7 +399,7 @@
  */
 
 /** Opaque structure for thread condition variables */
-typedef struct apr_thread_cond_t switch_thread_cond_t;
+	 typedef struct apr_thread_cond_t switch_thread_cond_t;
 
 /**
  * Create and initialize a condition variable that can be used to signal
@@ -421,7 +408,7 @@
  *        will be stored.
  * @param pool the pool from which to allocate the mutex.
  */
-SWITCH_DECLARE(switch_status_t) switch_thread_cond_create(switch_thread_cond_t **cond, switch_memory_pool_t *pool);
+SWITCH_DECLARE(switch_status_t) switch_thread_cond_create(switch_thread_cond_t ** cond, switch_memory_pool_t *pool);
 
 /**
  * Put the active calling thread to sleep until signaled to wake up. Each
@@ -435,7 +422,7 @@
  *        is released while the thread is asleep, and is again acquired before
  *        returning from this function.
  */
-SWITCH_DECLARE(switch_status_t) switch_thread_cond_wait(switch_thread_cond_t *cond, switch_mutex_t *mutex);
+SWITCH_DECLARE(switch_status_t) switch_thread_cond_wait(switch_thread_cond_t * cond, switch_mutex_t * mutex);
 
 /**
  * Put the active calling thread to sleep until signaled to wake up or
@@ -453,7 +440,7 @@
  *        will wake up before this time, otherwise the error APR_TIMEUP
  *        is returned.
  */
-SWITCH_DECLARE(switch_status_t) switch_thread_cond_timedwait(switch_thread_cond_t *cond, switch_mutex_t *mutex, switch_interval_time_t timeout);
+SWITCH_DECLARE(switch_status_t) switch_thread_cond_timedwait(switch_thread_cond_t * cond, switch_mutex_t * mutex, switch_interval_time_t timeout);
 
 /**
  * Signals a single thread, if one exists, that is blocking on the given
@@ -462,7 +449,7 @@
  * is desired, that mutex must be locked while calling this function.
  * @param cond the condition variable on which to produce the signal.
  */
-SWITCH_DECLARE(switch_status_t) switch_thread_cond_signal(switch_thread_cond_t *cond);
+SWITCH_DECLARE(switch_status_t) switch_thread_cond_signal(switch_thread_cond_t * cond);
 
 /**
  * Signals all threads blocking on the given condition variable.
@@ -470,13 +457,13 @@
  * the associated mutex. This will happen in a serialized manner.
  * @param cond the condition variable on which to produce the broadcast.
  */
-SWITCH_DECLARE(switch_status_t) switch_thread_cond_broadcast(switch_thread_cond_t *cond);
+SWITCH_DECLARE(switch_status_t) switch_thread_cond_broadcast(switch_thread_cond_t * cond);
 
 /**
  * Destroy the condition variable and free the associated memory.
  * @param cond the condition variable to destroy.
  */
-SWITCH_DECLARE(switch_status_t) switch_thread_cond_destroy(switch_thread_cond_t *cond);
+SWITCH_DECLARE(switch_status_t) switch_thread_cond_destroy(switch_thread_cond_t * cond);
 
 /** @} */
 
@@ -488,9 +475,10 @@
 
 /** we represent a UUID as a block of 16 bytes. */
 
-typedef struct {
-    unsigned char data[16]; /**< the actual UUID */
-} switch_uuid_t;
+	 typedef struct {
+		 unsigned char data[16];
+							/**< the actual UUID */
+	 } switch_uuid_t;
 
 /** UUIDs are formatted as: 00112233-4455-6677-8899-AABBCCDDEEFF */
 #define SWITCH_UUID_FORMATTED_LENGTH 36
@@ -501,21 +489,21 @@
  *               be at least APR_UUID_FORMATTED_LENGTH + 1 bytes long to hold
  *               the formatted UUID and a null terminator
  * @param uuid The UUID to format
- */ 
-SWITCH_DECLARE(void) switch_uuid_format(char *buffer, const switch_uuid_t *uuid);
+ */
+SWITCH_DECLARE(void) switch_uuid_format(char *buffer, const switch_uuid_t * uuid);
 
 /**
  * Generate and return a (new) UUID
  * @param uuid The resulting UUID
- */ 
-SWITCH_DECLARE(void) switch_uuid_get(switch_uuid_t *uuid);
+ */
+SWITCH_DECLARE(void) switch_uuid_get(switch_uuid_t * uuid);
 
 /**
  * Parse a standard-format string into a UUID
  * @param uuid The resulting UUID
  * @param uuid_str The formatted UUID
- */ 
-SWITCH_DECLARE(switch_status_t) switch_uuid_parse(switch_uuid_t *uuid, const char *uuid_str);
+ */
+SWITCH_DECLARE(switch_status_t) switch_uuid_parse(switch_uuid_t * uuid, const char *uuid_str);
 
 /** @} */
 
@@ -526,7 +514,7 @@
  */
 
 /** Opaque structure used for queue API */
-typedef struct apr_queue_t switch_queue_t;
+	 typedef struct apr_queue_t switch_queue_t;
 
 /** 
  * create a FIFO queue
@@ -534,9 +522,7 @@
  * @param queue_capacity maximum size of the queue
  * @param a pool to allocate queue from
  */
-SWITCH_DECLARE(switch_status_t) switch_queue_create(switch_queue_t **queue, 
-                                           unsigned int queue_capacity, 
-                                           switch_memory_pool_t *pool);
+SWITCH_DECLARE(switch_status_t) switch_queue_create(switch_queue_t ** queue, unsigned int queue_capacity, switch_memory_pool_t *pool);
 
 /**
  * pop/get an object from the queue, blocking if the queue is already empty
@@ -547,7 +533,7 @@
  * @returns APR_EOF if the queue has been terminated
  * @returns APR_SUCCESS on a successfull pop
  */
-SWITCH_DECLARE(switch_status_t) switch_queue_pop(switch_queue_t *queue, void **data);
+SWITCH_DECLARE(switch_status_t) switch_queue_pop(switch_queue_t * queue, void **data);
 
 /**
  * push/add a object to the queue, blocking if the queue is already full
@@ -558,7 +544,7 @@
  * @returns APR_EOF the queue has been terminated
  * @returns APR_SUCCESS on a successfull push
  */
-SWITCH_DECLARE(switch_status_t) switch_queue_push(switch_queue_t *queue, void *data);
+SWITCH_DECLARE(switch_status_t) switch_queue_push(switch_queue_t * queue, void *data);
 
 /**
  * returns the size of the queue.
@@ -568,7 +554,7 @@
  * @param queue the queue
  * @returns the size of the queue
  */
-SWITCH_DECLARE(unsigned int) switch_queue_size(switch_queue_t *queue);
+SWITCH_DECLARE(unsigned int) switch_queue_size(switch_queue_t * queue);
 
 /**
  * pop/get an object to the queue, returning immediatly if the queue is empty
@@ -580,7 +566,7 @@
  * @returns APR_EOF the queue has been terminated
  * @returns APR_SUCCESS on a successfull push
  */
-SWITCH_DECLARE(switch_status_t) switch_queue_trypop(switch_queue_t *queue, void **data);
+SWITCH_DECLARE(switch_status_t) switch_queue_trypop(switch_queue_t * queue, void **data);
 
 /**
  * push/add a object to the queue, returning immediatly if the queue is full
@@ -592,7 +578,7 @@
  * @returns APR_EOF the queue has been terminated
  * @returns APR_SUCCESS on a successfull push
  */
-SWITCH_DECLARE(switch_status_t) switch_queue_trypush(switch_queue_t *queue, void *data);
+SWITCH_DECLARE(switch_status_t) switch_queue_trypush(switch_queue_t * queue, void *data);
 
 /** @} */
 
@@ -603,17 +589,17 @@
  */
 
 /** Structure for referencing files. */
-typedef struct apr_file_t switch_file_t;
+	 typedef struct apr_file_t switch_file_t;
 
-typedef int32_t switch_fileperms_t;
-typedef int     switch_seek_where_t;
+	 typedef int32_t switch_fileperms_t;
+	 typedef int switch_seek_where_t;
 
 /**
  * @defgroup switch_file_permissions File Permissions flags 
  * @ingroup switch_file_io
  * @{
  */
-    
+
 #define SWITCH_FPROT_USETID 0x8000			/**< Set user id */
 #define SWITCH_FPROT_UREAD 0x0400			/**< Read by user */
 #define SWITCH_FPROT_UWRITE 0x0200			/**< Write by user */
@@ -690,16 +676,17 @@
  * @remark If perm is SWITCH_FPROT_OS_DEFAULT and the file is being created,
  * appropriate default permissions will be used.
  */
-SWITCH_DECLARE(switch_status_t) switch_file_open(switch_file_t **newf, const char *fname, int32_t flag, switch_fileperms_t perm, switch_memory_pool_t *pool);
+SWITCH_DECLARE(switch_status_t) switch_file_open(switch_file_t ** newf, const char *fname, int32_t flag, switch_fileperms_t perm,
+												 switch_memory_pool_t *pool);
 
 
-SWITCH_DECLARE(switch_status_t) switch_file_seek(switch_file_t *thefile, switch_seek_where_t where, int64_t *offset);
+SWITCH_DECLARE(switch_status_t) switch_file_seek(switch_file_t * thefile, switch_seek_where_t where, int64_t *offset);
 
 /**
  * Close the specified file.
  * @param file The file descriptor to close.
  */
-SWITCH_DECLARE(switch_status_t) switch_file_close(switch_file_t *thefile);
+SWITCH_DECLARE(switch_status_t) switch_file_close(switch_file_t * thefile);
 
 /**
  * Delete the specified file.
@@ -727,7 +714,7 @@
  * @remark It is not possible for both bytes to be read and an APR_EOF
  * or other error to be returned.  APR_EINTR is never returned.
  */
-SWITCH_DECLARE(switch_status_t) switch_file_read(switch_file_t *thefile, void *buf, switch_size_t *nbytes);
+SWITCH_DECLARE(switch_status_t) switch_file_read(switch_file_t * thefile, void *buf, switch_size_t *nbytes);
 
 /**
  * Write data to the specified file.
@@ -744,7 +731,7 @@
  * @remark It is possible for both bytes to be written and an error to
  * be returned.  APR_EINTR is never returned.
  */
-SWITCH_DECLARE(switch_status_t) switch_file_write(switch_file_t *thefile, const void *buf, switch_size_t *nbytes);
+SWITCH_DECLARE(switch_status_t) switch_file_write(switch_file_t * thefile, const void *buf, switch_size_t *nbytes);
 
 SWITCH_DECLARE(switch_status_t) switch_file_exists(const char *filename);
 
@@ -757,33 +744,33 @@
  */
 
 /** Opaque Thread structure. */
-typedef struct apr_thread_t switch_thread_t;
+	 typedef struct apr_thread_t switch_thread_t;
 
 /** Opaque Thread attributes structure. */
-typedef struct apr_threadattr_t switch_threadattr_t;
+	 typedef struct apr_threadattr_t switch_threadattr_t;
 
 /**
  * The prototype for any APR thread worker functions.
  * typedef void *(SWITCH_THREAD_FUNC *switch_thread_start_t)(switch_thread_t*, void*);
  */
-typedef void *(SWITCH_THREAD_FUNC *switch_thread_start_t)(switch_thread_t*, void*);
+	 typedef void *(SWITCH_THREAD_FUNC * switch_thread_start_t) (switch_thread_t *, void *);
 
 //APR_DECLARE(apr_status_t) apr_threadattr_stacksize_set(apr_threadattr_t *attr, switch_size_t stacksize)
-SWITCH_DECLARE(switch_status_t) switch_threadattr_stacksize_set(switch_threadattr_t *attr, switch_size_t stacksize);
+SWITCH_DECLARE(switch_status_t) switch_threadattr_stacksize_set(switch_threadattr_t * attr, switch_size_t stacksize);
 
 /**
  * Create and initialize a new threadattr variable
  * @param new_attr The newly created threadattr.
  * @param cont The pool to use
  */
-SWITCH_DECLARE(switch_status_t) switch_threadattr_create(switch_threadattr_t **new_attr, switch_memory_pool_t *pool);
+SWITCH_DECLARE(switch_status_t) switch_threadattr_create(switch_threadattr_t ** new_attr, switch_memory_pool_t *pool);
 
 /**
  * Set if newly created threads should be created in detached state.
  * @param attr The threadattr to affect 
  * @param on Non-zero if detached threads should be created.
  */
-SWITCH_DECLARE(switch_status_t) switch_threadattr_detach_set(switch_threadattr_t *attr, int32_t on);
+SWITCH_DECLARE(switch_status_t) switch_threadattr_detach_set(switch_threadattr_t * attr, int32_t on);
 
 /**
  * Create a new thread of execution
@@ -793,7 +780,8 @@
  * @param data Any data to be passed to the starting function
  * @param cont The pool to use
  */
-SWITCH_DECLARE(switch_status_t) switch_thread_create(switch_thread_t **new_thread, switch_threadattr_t *attr, switch_thread_start_t func, void *data, switch_memory_pool_t *cont);
+SWITCH_DECLARE(switch_status_t) switch_thread_create(switch_thread_t ** new_thread, switch_threadattr_t * attr,
+													 switch_thread_start_t func, void *data, switch_memory_pool_t *cont);
 
 /** @} */
 
@@ -829,16 +817,16 @@
 #endif
 
 /** A structure to represent sockets */
-typedef struct apr_socket_t switch_socket_t;
+	 typedef struct apr_socket_t switch_socket_t;
 
 /** Freeswitch's socket address type, used to ensure protocol independence */
-typedef struct apr_sockaddr_t switch_sockaddr_t;
+	 typedef struct apr_sockaddr_t switch_sockaddr_t;
 
-typedef enum {
-    SWITCH_SHUTDOWN_READ,          /**< no longer allow read request */
-    SWITCH_SHUTDOWN_WRITE,         /**< no longer allow write requests */
-    SWITCH_SHUTDOWN_READWRITE      /**< no longer allow read or write requests */
-} switch_shutdown_how_e;
+	 typedef enum {
+		 SWITCH_SHUTDOWN_READ,	   /**< no longer allow read request */
+		 SWITCH_SHUTDOWN_WRITE,	   /**< no longer allow write requests */
+		 SWITCH_SHUTDOWN_READWRITE /**< no longer allow read or write requests */
+	 } switch_shutdown_how_e;
 
 /**
  * @defgroup IP_Proto IP Protocol Definitions for use when creating sockets
@@ -859,7 +847,7 @@
  * @param protocol The protocol of the socket (e.g., SWITCH_PROTO_TCP).
  * @param pool The pool to use
  */
-SWITCH_DECLARE(switch_status_t) switch_socket_create(switch_socket_t **new_sock, int family, int type, int protocol, switch_memory_pool_t *pool);
+SWITCH_DECLARE(switch_status_t) switch_socket_create(switch_socket_t ** new_sock, int family, int type, int protocol, switch_memory_pool_t *pool);
 
 /**
  * Shutdown either reading, writing, or both sides of a socket.
@@ -874,13 +862,13 @@
  * @remark This does not actually close the socket descriptor, it just
  *      controls which calls are still valid on the socket.
  */
-SWITCH_DECLARE(switch_status_t) switch_socket_shutdown(switch_socket_t *sock, switch_shutdown_how_e how);
+SWITCH_DECLARE(switch_status_t) switch_socket_shutdown(switch_socket_t * sock, switch_shutdown_how_e how);
 
 /**
  * Close a socket.
  * @param sock The socket to close 
  */
-SWITCH_DECLARE(switch_status_t) switch_socket_close(switch_socket_t *sock);
+SWITCH_DECLARE(switch_status_t) switch_socket_close(switch_socket_t * sock);
 
 /**
  * Bind the socket to its associated port
@@ -889,7 +877,7 @@
  * @remark This may be where we will find out if there is any other process
  *      using the selected port.
  */
-SWITCH_DECLARE(switch_status_t) switch_socket_bind(switch_socket_t *sock, switch_sockaddr_t *sa);
+SWITCH_DECLARE(switch_status_t) switch_socket_bind(switch_socket_t * sock, switch_sockaddr_t * sa);
 
 /**
  * Listen to a bound socket for connections.
@@ -898,7 +886,7 @@
  *                listen queue.  If this value is less than zero, the listen
  *                queue size is set to zero.  
  */
-SWITCH_DECLARE(switch_status_t) switch_socket_listen(switch_socket_t *sock, int32_t backlog);
+SWITCH_DECLARE(switch_status_t) switch_socket_listen(switch_socket_t * sock, int32_t backlog);
 
 /**
  * Accept a new connection request
@@ -908,7 +896,7 @@
  * @param sock The socket we are listening on.
  * @param connection_pool The pool for the new socket.
  */
-SWITCH_DECLARE(switch_status_t) switch_socket_accept(switch_socket_t **new_sock, switch_socket_t *sock, switch_memory_pool_t *pool);
+SWITCH_DECLARE(switch_status_t) switch_socket_accept(switch_socket_t ** new_sock, switch_socket_t * sock, switch_memory_pool_t *pool);
 
 /**
  * Issue a connection request to a socket either on the same machine 
@@ -916,12 +904,12 @@
  * @param sock The socket we wish to use for our side of the connection 
  * @param sa The address of the machine we wish to connect to.
  */
-SWITCH_DECLARE(switch_status_t) switch_socket_connect(switch_socket_t *sock, switch_sockaddr_t *sa);
+SWITCH_DECLARE(switch_status_t) switch_socket_connect(switch_socket_t * sock, switch_sockaddr_t * sa);
 
-SWITCH_DECLARE(uint16_t) switch_sockaddr_get_port(switch_sockaddr_t *sa);
-SWITCH_DECLARE(char *) switch_get_addr(char *buf, switch_size_t len, switch_sockaddr_t *in);
-SWITCH_DECLARE(int32_t) switch_sockaddr_get_family(switch_sockaddr_t *sa);
-SWITCH_DECLARE(switch_status_t) switch_sockaddr_ip_get(char **addr, switch_sockaddr_t *sa);
+SWITCH_DECLARE(uint16_t) switch_sockaddr_get_port(switch_sockaddr_t * sa);
+SWITCH_DECLARE(char *) switch_get_addr(char *buf, switch_size_t len, switch_sockaddr_t * in);
+SWITCH_DECLARE(int32_t) switch_sockaddr_get_family(switch_sockaddr_t * sa);
+SWITCH_DECLARE(switch_status_t) switch_sockaddr_ip_get(char **addr, switch_sockaddr_t * sa);
 
 
 /**
@@ -947,7 +935,8 @@
  * </PRE>
  * @param p The pool for the apr_sockaddr_t and associated storage.
  */
-SWITCH_DECLARE(switch_status_t) switch_sockaddr_info_get(switch_sockaddr_t **sa, const char *hostname, int32_t family, switch_port_t port, int32_t flags, switch_memory_pool_t *pool);
+SWITCH_DECLARE(switch_status_t) switch_sockaddr_info_get(switch_sockaddr_t ** sa, const char *hostname,
+														 int32_t family, switch_port_t port, int32_t flags, switch_memory_pool_t *pool);
 
 /**
  * Send data over a network.
@@ -966,7 +955,7 @@
  * APR_EINTR is never returned.
  * </PRE>
  */
-SWITCH_DECLARE(switch_status_t) switch_socket_send(switch_socket_t *sock, const char *buf, switch_size_t *len);
+SWITCH_DECLARE(switch_status_t) switch_socket_send(switch_socket_t * sock, const char *buf, switch_size_t *len);
 
 /**
  * @param sock The socket to send from
@@ -975,7 +964,8 @@
  * @param buf  The data to send
  * @param len  The length of the data to send
  */
-SWITCH_DECLARE(switch_status_t) switch_socket_sendto(switch_socket_t *sock, switch_sockaddr_t *where, int32_t flags, const char *buf, switch_size_t *len);
+SWITCH_DECLARE(switch_status_t) switch_socket_sendto(switch_socket_t * sock, switch_sockaddr_t * where, int32_t flags, const char *buf,
+													 switch_size_t *len);
 
 /**
  * @param from The apr_sockaddr_t to fill in the recipient info
@@ -985,11 +975,7 @@
  * @param len  The length of the available buffer
  *
  */
-SWITCH_DECLARE(switch_status_t) switch_socket_recvfrom(switch_sockaddr_t *from,
-													   switch_socket_t *sock,
-													   int32_t flags,
-													   char *buf,
-													   size_t *len);
+SWITCH_DECLARE(switch_status_t) switch_socket_recvfrom(switch_sockaddr_t * from, switch_socket_t * sock, int32_t flags, char *buf, size_t *len);
 
 
 /**
@@ -1011,7 +997,7 @@
  * APR_EINTR is never returned.
  * </PRE>
  */
-SWITCH_DECLARE(switch_status_t) switch_socket_recv(switch_socket_t *sock, char *buf, switch_size_t *len);
+SWITCH_DECLARE(switch_status_t) switch_socket_recv(switch_socket_t * sock, char *buf, switch_size_t *len);
 
 /**
  * Setup socket options for the specified socket
@@ -1035,7 +1021,7 @@
  * </PRE>
  * @param on Value for the option.
  */
-SWITCH_DECLARE(switch_status_t) switch_socket_opt_set(switch_socket_t *sock, int32_t opt, int32_t on);
+SWITCH_DECLARE(switch_status_t) switch_socket_opt_set(switch_socket_t * sock, int32_t opt, int32_t on);
 
 /**
  * Setup socket timeout for the specified socket
@@ -1048,7 +1034,7 @@
  *   t < 0  -- read and write calls block
  * </PRE>
  */
-SWITCH_DECLARE(switch_status_t) switch_socket_timeout_set(switch_socket_t *sock, switch_interval_time_t t);
+SWITCH_DECLARE(switch_status_t) switch_socket_timeout_set(switch_socket_t * sock, switch_interval_time_t t);
 
 /**
  * Join a Multicast Group
@@ -1059,7 +1045,7 @@
  * @param source Source Address to accept transmissions from (non-NULL 
  *               implies Source-Specific Multicast)
  */
-SWITCH_DECLARE(switch_status_t) switch_mcast_join(switch_socket_t *sock, switch_sockaddr_t *join, switch_sockaddr_t *iface, switch_sockaddr_t *source);
+SWITCH_DECLARE(switch_status_t) switch_mcast_join(switch_socket_t * sock, switch_sockaddr_t * join, switch_sockaddr_t * iface, switch_sockaddr_t * source);
 
 
 
@@ -1071,10 +1057,10 @@
  * @{
  */
 /** Poll descriptor set. */
-typedef struct apr_pollfd_t switch_pollfd_t;
+	 typedef struct apr_pollfd_t switch_pollfd_t;
 
 /** Opaque structure used for pollset API */
-typedef struct apr_pollset_t switch_pollset_t;
+	 typedef struct apr_pollset_t switch_pollset_t;
 
 /**
  * Poll options
@@ -1100,10 +1086,7 @@
  * platforms; the apr_pollset_create() call will fail with
  * APR_ENOTIMPL on platforms where it is not supported.
  */
-SWITCH_DECLARE(switch_status_t) switch_pollset_create(switch_pollset_t **pollset,
-													  uint32_t size,
-													  switch_memory_pool_t *p,
-													  uint32_t flags);
+SWITCH_DECLARE(switch_status_t) switch_pollset_create(switch_pollset_t ** pollset, uint32_t size, switch_memory_pool_t *p, uint32_t flags);
 
 /**
  * Add a socket or file descriptor to a pollset
@@ -1122,8 +1105,7 @@
  *         allowed for implementations where option (1) is impossible
  *         or impractical.
  */
-SWITCH_DECLARE(switch_status_t) switch_pollset_add(switch_pollset_t *pollset,
-												   const switch_pollfd_t *descriptor);
+SWITCH_DECLARE(switch_status_t) switch_pollset_add(switch_pollset_t * pollset, const switch_pollfd_t * descriptor);
 
 /**
  * Poll the sockets in the poll structure
@@ -1138,10 +1120,7 @@
  *         This is a blocking call, and it will not return until either a 
  *         socket has been signalled, or the timeout has expired. 
  */
-SWITCH_DECLARE(switch_status_t) switch_poll(switch_pollfd_t *aprset,
-											int32_t numsock,
-											int32_t *nsds,
-											switch_interval_time_t timeout);
+SWITCH_DECLARE(switch_status_t) switch_poll(switch_pollfd_t * aprset, int32_t numsock, int32_t *nsds, switch_interval_time_t timeout);
 
 /*!
   \brief Create a set of file descriptors to poll
@@ -1151,9 +1130,9 @@
   \param pool the memory pool to use
   \return SWITCH_STATUS_SUCCESS when successful
 */
-SWITCH_DECLARE(switch_status_t) switch_socket_create_pollfd(switch_pollfd_t **poll, switch_socket_t *sock, int16_t flags, switch_memory_pool_t *pool);
+SWITCH_DECLARE(switch_status_t) switch_socket_create_pollfd(switch_pollfd_t ** poll, switch_socket_t * sock, int16_t flags, switch_memory_pool_t *pool);
+
 
- 
  /** @} */
 
 
@@ -1163,9 +1142,7 @@
 /** @} */
 
 SWITCH_END_EXTERN_C
-
 #endif
-
 /* For Emacs:
  * Local Variables:
  * mode:c

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_bitpack.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_bitpack.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_bitpack.h	Fri Mar 30 12:19:18 2007
@@ -36,22 +36,20 @@
 #ifndef SWITCH_BITPACK_H
 #define SWITCH_BITPACK_H
 SWITCH_BEGIN_EXTERN_C
-
 #include <switch.h>
-
 #ifdef DEBUG_BITS
 static char bb[80] = "";
 static inline char *print_bits(switch_byte_t byte, char *x)
 {
 
-    int i,j = 0;
-    x[j++] = '[';
-    for (i=7;i>=0;i--) {
-        x[j++] = (byte & (1 << i)) ? '1' : '0';
-    }
-    x[j++] = ']';
-    x[j++] = '\0';
-    return x;
+	int i, j = 0;
+	x[j++] = '[';
+	for (i = 7; i >= 0; i--) {
+		x[j++] = (byte & (1 << i)) ? '1' : '0';
+	}
+	x[j++] = ']';
+	x[j++] = '\0';
+	return x;
 }
 #endif
 
@@ -63,8 +61,8 @@
   \{ 
 */
 
-static const uint8_t SWITCH_BITPACKED_MASKS[] = {0, 1, 3, 7, 15, 31, 63, 127, 255};
-static const uint8_t SWITCH_REVERSE_BITPACKED_MASKS[] = {255, 254, 252, 248, 240, 224, 192, 128};
+static const uint8_t SWITCH_BITPACKED_MASKS[] = { 0, 1, 3, 7, 15, 31, 63, 127, 255 };
+static const uint8_t SWITCH_REVERSE_BITPACKED_MASKS[] = { 255, 254, 252, 248, 240, 224, 192, 128 };
 
 /*!
   \brief Initialize a bitpack object
@@ -75,7 +73,8 @@
   \param mode RFC3551 or AAL2 mode (curse you backwards folks) 
 */
 DoxyDefine(void switch_bitpack_init(switch_bitpack_t *pack, int32_t bitlen, switch_byte_t *buf, uint32_t buflen, switch_bitpack_mode_t mode))
-static inline int8_t switch_bitpack_init(switch_bitpack_t *pack, switch_byte_t bitlen, switch_byte_t *buf, uint32_t buflen, switch_bitpack_mode_t mode)
+	 static inline int8_t switch_bitpack_init(switch_bitpack_t *pack, switch_byte_t bitlen, switch_byte_t *buf, uint32_t buflen,
+											  switch_bitpack_mode_t mode)
 {
 	if (!pack || (bitlen > SWITCH_BITS_PER_BYTE) || !buf || !buflen) {
 		return -1;
@@ -94,7 +93,7 @@
 
 static inline void pack_check_over(switch_bitpack_t *pack)
 {
-	switch_byte_t this_byte = pack->this_byte;	
+	switch_byte_t this_byte = pack->this_byte;
 
 	if (pack->over) {
 		pack->bits_cur = pack->over;
@@ -117,7 +116,7 @@
 
 		pack->bytes++;
 		pack->over = pack->under = 0;
-	}	
+	}
 }
 
 /*!
@@ -125,14 +124,14 @@
   \param pack the pack/unpack object
 */
 DoxyDefine(int8_t switch_bitpack_done(switch_bitpack_t *pack))
-static inline int8_t switch_bitpack_done(switch_bitpack_t *pack)
+	 static inline int8_t switch_bitpack_done(switch_bitpack_t *pack)
 {
 
 	if (pack->bits_cur && pack->bits_cur < SWITCH_BITS_PER_BYTE) {
 		pack->bytes++;
 		if (pack->mode == SWITCH_BITPACK_MODE_AAL2) {
-            *pack->cur <<= SWITCH_BITS_PER_BYTE - pack->bits_cur;
-        }
+			*pack->cur <<= SWITCH_BITS_PER_BYTE - pack->bits_cur;
+		}
 	}
 
 	if (pack->over) {
@@ -149,11 +148,11 @@
   \return -1 if the buffer is full otherwise 0
 */
 DoxyDefine(int8_t switch_bitpack_out(switch_bitpack_t *unpack, switch_byte_t in))
-static inline int8_t switch_bitpack_out(switch_bitpack_t *unpack, switch_byte_t in)
+	 static inline int8_t switch_bitpack_out(switch_bitpack_t *unpack, switch_byte_t in)
 {
 	switch_byte_t this_byte;
 
-	if ((uint32_t)(unpack->cur - unpack->buf) > unpack->buflen) {
+	if ((uint32_t) (unpack->cur - unpack->buf) > unpack->buflen) {
 		return -1;
 	}
 
@@ -163,7 +162,7 @@
 
 
 	pack_check_over(unpack);
-	while(unpack->bits_cur <= SWITCH_BITS_PER_BYTE) {
+	while (unpack->bits_cur <= SWITCH_BITS_PER_BYTE) {
 		switch_byte_t next = unpack->bits_cur + unpack->frame_bits;
 		switch_byte_t under_in;
 		switch_byte_t mask;
@@ -220,20 +219,20 @@
   \return -1 if the buffer is full otherwise 0
 */
 DoxyDefine(int8_t switch_bitpack_in(switch_bitpack_t *pack, switch_byte_t in))
-static inline int8_t switch_bitpack_in(switch_bitpack_t *pack, switch_byte_t in)
+	 static inline int8_t switch_bitpack_in(switch_bitpack_t *pack, switch_byte_t in)
 {
 	int next = pack->bits_cur + pack->frame_bits;
 
-	if ((uint32_t)(pack->cur - pack->buf) > pack->buflen) {
+	if ((uint32_t) (pack->cur - pack->buf) > pack->buflen) {
 		return -1;
-	} 
+	}
 
 	pack->bits_tot += pack->frame_bits;
 
 	if (next > SWITCH_BITS_PER_BYTE) {
 		switch_byte_t a = 0, b = 0, rem, nxt;
 		rem = SWITCH_BITS_PER_BYTE - pack->bits_cur;
-		nxt = pack->frame_bits - rem ;
+		nxt = pack->frame_bits - rem;
 		if (pack->mode == SWITCH_BITPACK_MODE_RFC3551) {
 			a = in & SWITCH_BITPACKED_MASKS[rem];
 			b = in >> rem;
@@ -250,7 +249,7 @@
 			pack->cur++;
 			*pack->cur |= b;
 			pack->bits_cur = nxt;
-			
+
 		}
 		pack->bytes++;
 
@@ -259,14 +258,14 @@
 		if (pack->mode == SWITCH_BITPACK_MODE_RFC3551) {
 			in <<= pack->shiftby;
 			*pack->cur |= in;
-			pack->shiftby = (switch_byte_t)(pack->shiftby + pack->frame_bits);
+			pack->shiftby = (switch_byte_t) (pack->shiftby + pack->frame_bits);
 		} else {
 			*pack->cur <<= pack->frame_bits;
 			*pack->cur |= in;
 		}
 
 		if (next == SWITCH_BITS_PER_BYTE) {
-			pack->cur++;			
+			pack->cur++;
 			pack->bytes++;
 			pack->bits_cur = pack->shiftby = 0;
 		} else {
@@ -276,11 +275,11 @@
 
 	return 0;
 }
+
 ///\}
 
 SWITCH_END_EXTERN_C
 #endif
-
 /* For Emacs:
  * Local Variables:
  * mode:c

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_buffer.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_buffer.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_buffer.h	Fri Mar 30 12:19:18 2007
@@ -41,7 +41,6 @@
 #include <switch.h>
 
 SWITCH_BEGIN_EXTERN_C
-
 /**
  * @defgroup switch_buffer Buffer Routines
  * @ingroup core1
@@ -50,8 +49,7 @@
  * and I think it can be optimized under the hood as we go using bucket brigades and/or ring buffering techniques.
  * @{
  */
-
-struct switch_buffer;
+	struct switch_buffer;
 
 
 /*! \brief Allocate a new switch_buffer 
@@ -69,9 +67,7 @@
  * \param max_len length the buffer is allowed to grow to
  * \return status
  */
-SWITCH_DECLARE(switch_status_t) switch_buffer_create_dynamic(switch_buffer_t **buffer,
-															 switch_size_t blocksize,
-															 switch_size_t start_len,
+SWITCH_DECLARE(switch_status_t) switch_buffer_create_dynamic(switch_buffer_t **buffer, switch_size_t blocksize, switch_size_t start_len,
 															 switch_size_t max_len);
 
 /*! \brief Get the length of a switch_buffer_t 
@@ -129,9 +125,7 @@
 /** @} */
 
 SWITCH_END_EXTERN_C
-
 #endif
-
 /* For Emacs:
  * Local Variables:
  * mode:c

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_caller.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_caller.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_caller.h	Fri Mar 30 12:19:18 2007
@@ -56,10 +56,9 @@
 #include <switch.h>
 
 SWITCH_BEGIN_EXTERN_C
-
 /*! \brief Call Specific Data
  */
-struct switch_caller_profile {
+	struct switch_caller_profile {
 	/*! The Call's User Name */
 	char *username;
 	/*! The name of the dialplan */
@@ -128,10 +127,7 @@
   \param extension_number extension number
   \return a new extension object allocated from the session's memory pool
 */
-SWITCH_DECLARE(switch_caller_extension_t *) switch_caller_extension_new(switch_core_session_t *session,
-																	  char *extension_name,
-																	  char *extension_number
-																	  );
+SWITCH_DECLARE(switch_caller_extension_t *) switch_caller_extension_new(switch_core_session_t *session, char *extension_name, char *extension_number);
 
 /*!
   \brief Add an application (instruction) to the given extension
@@ -141,9 +137,7 @@
   \param extra_data optional argument to the application
 */
 SWITCH_DECLARE(void) switch_caller_extension_add_application(switch_core_session_t *session,
-															 switch_caller_extension_t *caller_extension,
-															 char *application_name,
-															 char *extra_data);
+															 switch_caller_extension_t *caller_extension, char *application_name, char *extra_data);
 
 
 /*!
@@ -178,9 +172,7 @@
 																	const char *network_addr,
 																	const char *ani,
 																	const char *aniii,
-																	const char *rdnis,
-																	const char *source,
-																	const char *context,
+																	const char *rdnis, const char *source, const char *context,
 																	const char *destination_number);
 
 /*!
@@ -188,9 +180,8 @@
   \param session session associated with the profile (bound by scope)
   \param tocopy the existing profile
 */
-	
-SWITCH_DECLARE(switch_caller_profile_t *) switch_caller_profile_clone(switch_core_session_t *session,
-																	switch_caller_profile_t *tocopy);
+
+SWITCH_DECLARE(switch_caller_profile_t *) switch_caller_profile_clone(switch_core_session_t *session, switch_caller_profile_t *tocopy);
 
 /*!
   \brief Add headers to an existing event in regards to a specific profile
@@ -202,11 +193,8 @@
 SWITCH_DECLARE(void) switch_caller_profile_event_set_data(switch_caller_profile_t *caller_profile, char *prefix, switch_event_t *event);
 
 SWITCH_END_EXTERN_C
-
 /** @} */
-
 #endif
-
 /* For Emacs:
  * Local Variables:
  * mode:c

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_channel.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_channel.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_channel.h	Fri Mar 30 12:19:18 2007
@@ -40,9 +40,7 @@
 
 #include <switch.h>
 
-SWITCH_BEGIN_EXTERN_C
-
-struct switch_channel_timetable {
+SWITCH_BEGIN_EXTERN_C struct switch_channel_timetable {
 	switch_time_t created;
 	switch_time_t answered;
 	switch_time_t hungup;
@@ -76,17 +74,14 @@
 
 
 SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_set_state(switch_channel_t *channel,
-                                                                        const char *file,
-                                                                        const char *func,
-                                                                        int line,
-                                                                        switch_channel_state_t state);
+																		const char *file, const char *func, int line, switch_channel_state_t state);
 
 /*!
   \brief Set the current state of a channel
   \param channel channel to set state of
   \param state new state
   \return current state of channel after application of new state
-*/	
+*/
 #define switch_channel_set_state(channel, state) switch_channel_perform_set_state(channel, __FILE__, __SWITCH_FUNC__, __LINE__, state)
 
 /*!
@@ -132,10 +127,8 @@
   \param state the initial state of the channel
   \param flags the initial channel flags
 */
-SWITCH_DECLARE(switch_status_t) switch_channel_init(switch_channel_t *channel,
-								switch_core_session_t *session,
-								switch_channel_state_t state,
-								uint32_t flags);
+SWITCH_DECLARE(switch_status_t) switch_channel_init(switch_channel_t *channel, switch_core_session_t *session, switch_channel_state_t state,
+													uint32_t flags);
 
 /*!
   \brief Fire A presence event for the channel
@@ -279,15 +272,9 @@
 */
 SWITCH_DECLARE(void) switch_channel_clear_flag(switch_channel_t *channel, switch_channel_flag_t flags);
 
-SWITCH_DECLARE(switch_status_t) switch_channel_perform_answer(switch_channel_t *channel,
-                                                              const char *file,
-                                                              const char *func,
-                                                              int line);
-
-SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_answered(switch_channel_t *channel,
-                                                                     const char *file,
-                                                                     const char *func,
-                                                                     int line);
+SWITCH_DECLARE(switch_status_t) switch_channel_perform_answer(switch_channel_t *channel, const char *file, const char *func, int line);
+
+SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_answered(switch_channel_t *channel, const char *file, const char *func, int line);
 
 /*!
   \brief Answer a channel (initiate/acknowledge a successful connection)
@@ -310,10 +297,7 @@
 */
 #define switch_channel_mark_pre_answered(channel) switch_channel_perform_mark_pre_answered(channel, __FILE__, __SWITCH_FUNC__, __LINE__)
 
-SWITCH_DECLARE(switch_status_t) switch_channel_perform_ring_ready(switch_channel_t *channel,
-																  const char *file,
-																  const char *func,
-																  int line);
+SWITCH_DECLARE(switch_status_t) switch_channel_perform_ring_ready(switch_channel_t *channel, const char *file, const char *func, int line);
 /*!
   \brief Send Ringing message to a channel
   \param channel channel to ring
@@ -322,33 +306,24 @@
 #define switch_channel_ring_ready(channel) switch_channel_perform_ring_ready(channel, __FILE__, __SWITCH_FUNC__, __LINE__)
 
 
-SWITCH_DECLARE(switch_status_t) switch_channel_perform_pre_answer(switch_channel_t *channel,
-                                                                  const char *file,
-                                                                  const char *func,
-                                                                  int line);
-
-SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_pre_answered(switch_channel_t *channel,
-                                                                       const char *file,
-                                                                       const char *func,
-                                                                       int line);
-
-SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_ring_ready(switch_channel_t *channel,
-																	   const char *file,
-																	   const char *func,
-																	   int line);
+SWITCH_DECLARE(switch_status_t) switch_channel_perform_pre_answer(switch_channel_t *channel, const char *file, const char *func, int line);
+
+SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_pre_answered(switch_channel_t *channel, const char *file, const char *func, int line);
+
+SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_ring_ready(switch_channel_t *channel, const char *file, const char *func, int line);
 
 /*!
   \brief Indicate progress on a channel to attempt early media
   \param channel channel to pre-answer
   \return SWITCH_STATUS_SUCCESS
-*/								
+*/
 #define switch_channel_pre_answer(channel) switch_channel_perform_pre_answer(channel, __FILE__, __SWITCH_FUNC__, __LINE__)
 
 /*!
   \brief Indicate a channel is ready to provide ringback
   \param channel channel
   \return SWITCH_STATUS_SUCCESS
-*/								
+*/
 #define switch_channel_mark_ring_ready(channel) switch_channel_perform_mark_ring_ready(channel, __FILE__, __SWITCH_FUNC__, __LINE__)
 
 /*!
@@ -407,11 +382,8 @@
 SWITCH_DECLARE(char *) switch_channel_get_name(switch_channel_t *channel);
 
 
-SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_hangup(switch_channel_t *channel, 
-                                                                     const char *file,
-                                                                     const char *func,
-                                                                     int line,
-                                                                     switch_call_cause_t hangup_cause);
+SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_hangup(switch_channel_t *channel,
+																	 const char *file, const char *func, int line, switch_call_cause_t hangup_cause);
 
 /*!
   \brief Hangup a channel flagging it's state machine to end
@@ -478,9 +450,7 @@
 /** @} */
 
 SWITCH_END_EXTERN_C
-
 #endif
-
 /* For Emacs:
  * Local Variables:
  * mode:c

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_config.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_config.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_config.h	Fri Mar 30 12:19:18 2007
@@ -58,24 +58,22 @@
 
 #include <switch.h>
 
-SWITCH_BEGIN_EXTERN_C
-
-typedef struct switch_config switch_config_t;
+SWITCH_BEGIN_EXTERN_C typedef struct switch_config switch_config_t;
 
 /*! \brief A simple file handle representing an open configuration file **/
 struct switch_config {
 	/*! FILE stream buffer to the opened file */
-    FILE *file;
+	FILE *file;
 	/*! path to the file */
-    char *path;
+	char *path;
 	/*! current category */
-    char category[256];
+	char category[256];
 	/*! current section */
-    char section[256];
+	char section[256];
 	/*! buffer of current line being read */
-    char buf[1024];
+	char buf[1024];
 	/*! current line number in file */
-    int lineno;
+	int lineno;
 	/*! current category number in file */
 	int catno;
 	/*! current section number in file */
@@ -90,13 +88,13 @@
   \param file_path path to the file
   \return 1 (true) on success 0 (false) on failure
 */
-SWITCH_DECLARE(int) switch_config_open_file(switch_config_t *cfg, char *file_path);
+SWITCH_DECLARE(int) switch_config_open_file(switch_config_t * cfg, char *file_path);
 
 /*!
   \brief Close a previously opened configuration file
   \param cfg (switch_config_t *) config handle to use
 */
-SWITCH_DECLARE(void) switch_config_close_file(switch_config_t *cfg);
+SWITCH_DECLARE(void) switch_config_close_file(switch_config_t * cfg);
 
 /*!
   \brief Retrieve next name/value pair from configuration file
@@ -104,14 +102,11 @@
   \param var pointer to aim at the new variable name
   \param val pointer to aim at the new value
 */
-SWITCH_DECLARE(int) switch_config_next_pair(switch_config_t *cfg, char **var, char **val);
+SWITCH_DECLARE(int) switch_config_next_pair(switch_config_t * cfg, char **var, char **val);
 
 SWITCH_END_EXTERN_C
-
 /** @} */
-
 #endif
-
 /* For Emacs:
  * Local Variables:
  * mode:c

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_console.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_console.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_console.h	Fri Mar 30 12:19:18 2007
@@ -51,9 +51,6 @@
 		s.alloc_len = SWITCH_CMD_CHUNK_LEN;\
 		s.alloc_chunk = SWITCH_CMD_CHUNK_LEN;\
 	}
-
- 
-
 /*!
   \brief A simple comand loop that reads input from the terminal
 */
@@ -62,16 +59,15 @@
 /*!
   \brief A method akin to printf that allows you to redirect output to a specific console "channel"
 */
-SWITCH_DECLARE(void) switch_console_printf(switch_text_channel_t channel, const char *file, const char *func, int line, const char *fmt, ...) PRINTF_FUNCTION(5,6);
+SWITCH_DECLARE(void) switch_console_printf(switch_text_channel_t channel, const char *file, const char *func, int line,
+										   const char *fmt, ...) PRINTF_FUNCTION(5, 6);
 
 /*!
   \brief A method akin to printf for dealing with api streams
 */
-SWITCH_DECLARE(switch_status_t) switch_console_stream_write(switch_stream_handle_t *handle, const char *fmt, ...) PRINTF_FUNCTION(2,3);
+SWITCH_DECLARE(switch_status_t) switch_console_stream_write(switch_stream_handle_t *handle, const char *fmt, ...) PRINTF_FUNCTION(2, 3);
 SWITCH_END_EXTERN_C
-
 #endif
-
 /* For Emacs:
  * Local Variables:
  * mode:c

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_core.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_core.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_core.h	Fri Mar 30 12:19:18 2007
@@ -41,43 +41,41 @@
 #include <switch.h>
 
 SWITCH_BEGIN_EXTERN_C
-
 #define SWITCH_MAX_CORE_THREAD_SESSION_OBJS 128
 #define SWITCH_MAX_STREAMS 128
-
-struct switch_core_time_duration {
-    uint32_t mms;
-    uint32_t ms;
-    uint32_t sec;
-    uint32_t min;
-    uint32_t hr;
+	struct switch_core_time_duration {
+	uint32_t mms;
+	uint32_t ms;
+	uint32_t sec;
+	uint32_t min;
+	uint32_t hr;
 	uint32_t day;
 	uint32_t yr;
 };
 
 /*! \brief A message object designed to allow unlike technologies to exchange data */
 struct switch_core_session_message {
-	/*! uuid of the sender (for replies)*/
+	/*! uuid of the sender (for replies) */
 	char *from;
 	/*! enumeration of the type of message */
 	switch_core_session_message_types_t message_id;
 
-	/*! optional numeric arg*/
+	/*! optional numeric arg */
 	int numeric_arg;
-	/*! optional string arg*/
+	/*! optional string arg */
 	char *string_arg;
-	/*! optional string arg*/
+	/*! optional string arg */
 	switch_size_t string_arg_size;
 	/*! optional arbitrary pointer arg */
 	void *pointer_arg;
 	/*! optional arbitrary pointer arg's size */
 	switch_size_t pointer_arg_size;
 
-	/*! optional numeric reply*/
+	/*! optional numeric reply */
 	int numeric_reply;
-	/*! optional string reply*/
+	/*! optional string reply */
 	char *string_reply;
-	/*! optional string reply*/
+	/*! optional string reply */
 	switch_size_t string_reply_size;
 	/*! optional arbitrary pointer reply */
 	void *pointer_reply;
@@ -96,7 +94,7 @@
 	/*! array of void pointers to pass mutiple data objects */
 	void *objs[SWITCH_MAX_CORE_THREAD_SESSION_OBJS];
 	/*! a pointer to a memory pool if the thread has it's own pool */
-    switch_input_callback_function_t input_callback;
+	switch_input_callback_function_t input_callback;
 	switch_memory_pool_t *pool;
 };
 
@@ -104,16 +102,6 @@
 struct switch_core_runtime;
 struct switch_core_port_allocator;
 
-struct switch_core_scheduler_task {
-	time_t created;
-	time_t runtime;
-	uint32_t cmd_id;
-	char *group;
-	void *cmd_arg;
-	uint32_t task_id;
-};
-
-
 /*!
   \defgroup core1 Core Library 
   \ingroup FREESWITCH
@@ -125,47 +113,6 @@
 ///\{
 
 
-///\defgroup sched1 Scheduler
-///\ingroup core1
-///\{
-
-
-/*!
-  \brief Schedule a task in the future
-  \param runtime the time in epoch seconds to execute the task.
-  \param func the callback function to execute when the task is executed.
-  \param desc an arbitrary description of the task.
-  \param group a group id tag to link multiple tasks to a single entity.
-  \param cmd_id an arbitrary index number be used in the callback.
-  \param cmd_arg user data to be passed to the callback.
-  \param flags flags to alter behaviour 
-  \return the id of the task
-*/
-SWITCH_DECLARE(uint32_t) switch_core_scheduler_add_task(time_t task_runtime,
-														switch_core_scheduler_func_t func,
-														char *desc,
-														char *group,
-														uint32_t cmd_id,
-														void *cmd_arg,
-														switch_scheduler_flag_t flags);
-
-/*!
-  \brief Delete a scheduled task
-  \param task_id the id of the task
-  \return SWITCH_STATUS_SUCCESS if the task was deleted.
-*/
-SWITCH_DECLARE(switch_status_t) switch_core_scheduler_del_task_id(uint32_t task_id);
-
-/*!
-  \brief Delete a scheduled task based on the group name
-  \param group the group name
-  \return SWITCH_STATUS_SUCCESS if any tasks were deleted
-*/
-SWITCH_DECLARE(switch_status_t) switch_core_scheduler_del_task_group(char *group);
-
-
-///\}
-
 /*!
   \brief Add a media bug to the session
   \param session the session to add the bug to
@@ -177,9 +124,7 @@
 */
 SWITCH_DECLARE(switch_status_t) switch_core_media_bug_add(switch_core_session_t *session,
 														  switch_media_bug_callback_t callback,
-														  void *user_data,
-														  switch_media_bug_flag_t flags,
-														  switch_media_bug_t **new_bug);
+														  void *user_data, switch_media_bug_flag_t flags, switch_media_bug_t **new_bug);
 /*!
   \brief Obtain private data from a media bug
   \param bug the bug to get the data from
@@ -209,6 +154,12 @@
 SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove(switch_core_session_t *session, switch_media_bug_t **bug);
 
 /*!
+  \brief Close and destroy a media bug
+  \param bug bug to remove
+  \return SWITCH_STATUS_SUCCESS if the operation was a success
+*/
+SWITCH_DECLARE(switch_status_t) switch_core_media_bug_close(switch_media_bug_t **bug);
+/*!
   \brief Remove all media bugs from the session
   \param session the session to remove the bugs from
   \return SWITCH_STATUS_SUCCESS if the operation was a success
@@ -238,9 +189,7 @@
   \return SWITCH_STATUS_SUCCESS if the operation was a success
 */
 SWITCH_DECLARE(switch_status_t) switch_core_port_allocator_new(switch_port_t start,
-															   switch_port_t end,
-															   uint8_t inc,
-															   switch_core_port_allocator_t **new_allocator);
+															   switch_port_t end, uint8_t inc, switch_core_port_allocator_t **new_allocator);
 
 /*!
   \brief Get a port from the port allocator
@@ -295,10 +244,7 @@
 ///\{
 
 #ifdef SWITCH_DEBUG_RWLOCKS
-SWITCH_DECLARE(switch_status_t) switch_core_session_perform_read_lock(switch_core_session_t *session,
-                                                                      const char *file,
-                                                                      const char *func,
-                                                                      int line);
+SWITCH_DECLARE(switch_status_t) switch_core_session_perform_read_lock(switch_core_session_t *session, const char *file, const char *func, int line);
 #endif
 
 /*! 
@@ -314,10 +260,7 @@
 
 
 #ifdef SWITCH_DEBUG_RWLOCKS
-SWITCH_DECLARE(void) switch_core_session_perform_write_lock(switch_core_session_t *session,
-                                                            const char *file,
-                                                            const char *func,
-                                                            int line);
+SWITCH_DECLARE(void) switch_core_session_perform_write_lock(switch_core_session_t *session, const char *file, const char *func, int line);
 #endif
 
 /*! 
@@ -331,10 +274,7 @@
 #endif
 
 #ifdef SWITCH_DEBUG_RWLOCKS
-SWITCH_DECLARE(void) switch_core_session_perform_rwunlock(switch_core_session_t *session,
-                                                          const char *file,
-                                                          const char *func,
-                                                          int line);
+SWITCH_DECLARE(void) switch_core_session_perform_rwunlock(switch_core_session_t *session, const char *file, const char *func, int line);
 #endif
 
 /*! 
@@ -479,7 +419,8 @@
   \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(const switch_endpoint_interface_t *endpoint_interface, switch_memory_pool_t **pool);
+SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request(const switch_endpoint_interface_t
+																	*endpoint_interface, switch_memory_pool_t **pool);
 
 /*! 
   \brief Destroy a session and return the memory pool to the core
@@ -534,10 +475,7 @@
 SWITCH_DECLARE(char *) switch_core_get_uuid(void);
 
 #ifdef SWITCH_DEBUG_RWLOCKS
-SWITCH_DECLARE(switch_core_session_t *) switch_core_session_perform_locate(char *uuid_str,
-                                                                           const char *file,
-                                                                           const char *func,
-                                                                           int line);
+SWITCH_DECLARE(switch_core_session_t *) switch_core_session_perform_locate(char *uuid_str, const char *file, const char *func, int line);
 #endif
 
 /*! 
@@ -578,7 +516,7 @@
   \param message the switch_core_session_message_t object to send
   \return the status returned by the message handler
 */
-SWITCH_DECLARE (switch_status_t) switch_core_session_message_send(char *uuid_str, switch_core_session_message_t *message);
+SWITCH_DECLARE(switch_status_t) switch_core_session_message_send(char *uuid_str, switch_core_session_message_t *message);
 
 /*! 
   \brief Queue a message on a session
@@ -671,7 +609,7 @@
   \param func a function to execute in the thread
   \param obj an arguement
 */
-SWITCH_DECLARE(void) switch_core_session_launch_thread(switch_core_session_t *session, void *(*func)(switch_thread_t *, void *), void *obj);
+SWITCH_DECLARE(void) switch_core_session_launch_thread(switch_core_session_t *session, void *(*func) (switch_thread_t *, void *), void *obj);
 
 /*! 
   \brief Signal a thread using a thread session to terminate
@@ -699,8 +637,7 @@
 SWITCH_DECLARE(switch_call_cause_t) switch_core_session_outgoing_channel(switch_core_session_t *session,
 																		 char *endpoint_name,
 																		 switch_caller_profile_t *caller_profile,
-																		 switch_core_session_t **new_session,
-																		 switch_memory_pool_t **pool);
+																		 switch_core_session_t **new_session, switch_memory_pool_t **pool);
 
 /*! 
   \brief Answer the channel of a given session
@@ -793,11 +730,8 @@
 SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, int stream_id);
 
 
-SWITCH_DECLARE(switch_status_t) switch_core_session_perform_kill_channel(switch_core_session_t *session, 
-                                                                         const char *file, 
-                                                                         const char *func, 
-                                                                         int line, 
-                                                                         switch_signal_t sig);
+SWITCH_DECLARE(switch_status_t) switch_core_session_perform_kill_channel(switch_core_session_t *session,
+																		 const char *file, const char *func, int line, switch_signal_t sig);
 /*! 
   \brief Send a signal to a channel
   \param session session to send signal to
@@ -832,91 +766,8 @@
 */
 SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf(switch_core_session_t *session, char *dtmf);
 
-/*! 
-  \brief Add an event hook to be executed when a session requests an outgoing extension
-  \param session session to bind hook to
-  \param outgoing_channel hook to bind
-  \return SWITCH_STATUS_SUCCESS on suceess
-*/
-SWITCH_DECLARE(switch_status_t) switch_core_session_add_event_hook_outgoing(switch_core_session_t *session, switch_outgoing_channel_hook_t outgoing_channel);
 ///\}
 
-///\defgroup shooks Session Hook Callbacks
-///\ingroup core1
-///\{
-/*! 
-  \brief Add an event hook to be executed when a session answers a channel
-  \param session session to bind hook to
-  \param answer_channel hook to bind
-  \return SWITCH_STATUS_SUCCESS on suceess
-*/
-SWITCH_DECLARE(switch_status_t) switch_core_session_add_event_hook_answer_channel(switch_core_session_t *session, switch_answer_channel_hook_t answer_channel);
-
-/*! 
-  \brief Add an event hook to be executed when a session sends a message
-  \param session session to bind hook to
-  \param receive_message hook to bind
-  \return SWITCH_STATUS_SUCCESS on suceess
-*/
-SWITCH_DECLARE(switch_status_t) switch_core_session_add_event_hook_receive_message(switch_core_session_t *session, switch_receive_message_hook_t receive_message);
-
-/*! 
-  \brief Add an event hook to be executed when a session reads a frame
-  \param session session to bind hook to
-  \param  read_frame hook to bind
-  \return SWITCH_STATUS_SUCCESS on suceess
-*/
-SWITCH_DECLARE(switch_status_t) switch_core_session_add_event_hook_read_frame(switch_core_session_t *session, switch_read_frame_hook_t read_frame);
-
-/*! 
-  \brief Add an event hook to be executed when a session writes a frame
-  \param session session to bind hook to
-  \param write_frame hook to bind
-  \return SWITCH_STATUS_SUCCESS on suceess
-*/
-SWITCH_DECLARE(switch_status_t) switch_core_session_add_event_hook_write_frame(switch_core_session_t *session, switch_write_frame_hook_t write_frame);
-
-/*! 
-  \brief Add an event hook to be executed when a session kills a channel
-  \param session session to bind hook to
-  \param kill_channel hook to bind
-  \return SWITCH_STATUS_SUCCESS on suceess
-*/
-SWITCH_DECLARE(switch_status_t) switch_core_session_add_event_hook_kill_channel(switch_core_session_t *session, switch_kill_channel_hook_t kill_channel);
-
-/*! 
-  \brief Add an event hook to be executed when a session waits for a read event
-  \param session session to bind hook to
-  \param waitfor_read hook to bind
-  \return SWITCH_STATUS_SUCCESS on suceess
-*/
-SWITCH_DECLARE(switch_status_t) switch_core_session_add_event_hook_waitfor_read(switch_core_session_t *session, switch_waitfor_read_hook_t waitfor_read);
-
-/*! 
-  \brief Add an event hook to be executed when a session waits for a write event
-  \param session session to bind hook to
-  \param waitfor_write hook to bind
-  \return SWITCH_STATUS_SUCCESS on suceess
-*/
-SWITCH_DECLARE(switch_status_t) switch_core_session_add_event_hook_waitfor_write(switch_core_session_t *session, switch_waitfor_write_hook_t waitfor_write);
-
-/*! 
-  \brief Add an event hook to be executed when a session sends dtmf
-  \param session session to bind hook to
-  \param send_dtmf hook to bind
-  \return SWITCH_STATUS_SUCCESS on suceess
-*/
-SWITCH_DECLARE(switch_status_t) switch_core_session_add_event_hook_send_dtmf(switch_core_session_t *session, switch_send_dtmf_hook_t send_dtmf);
-
-/*! 
-  \brief Add an event hook to be executed when a session receives a state change signal
-  \param session session to bind hook to
-  \param state_change hook to bind
-  \return SWITCH_STATUS_SUCCESS on suceess
-*/
-SWITCH_DECLARE(switch_status_t) switch_core_session_add_event_hook_state_change(switch_core_session_t *session,
-																				switch_answer_channel_hook_t state_change);
-///\}
 
 ///\defgroup hashf Hash Functions
 ///\ingroup core1
@@ -927,14 +778,14 @@
   \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(switch_hash_t **hash, switch_memory_pool_t *pool);
+SWITCH_DECLARE(switch_status_t) switch_core_hash_init(switch_hash_t ** hash, switch_memory_pool_t *pool);
 
 /*! 
   \brief Destroy an existing hash table
   \param hash the hash to destroy
   \return SWITCH_STATUS_SUCCESS if the hash is destroyed
 */
-SWITCH_DECLARE(switch_status_t) switch_core_hash_destroy(switch_hash_t *hash);
+SWITCH_DECLARE(switch_status_t) switch_core_hash_destroy(switch_hash_t * hash);
 
 /*! 
   \brief Insert data into a hash
@@ -944,7 +795,7 @@
   \return SWITCH_STATUS_SUCCESS if the data is added
   \note the string key must be a constant or a dynamic string
 */
-SWITCH_DECLARE(switch_status_t) switch_core_hash_insert(switch_hash_t *hash, const char *key, const void *data);
+SWITCH_DECLARE(switch_status_t) switch_core_hash_insert(switch_hash_t * hash, const char *key, const void *data);
 
 /*! 
   \brief Insert data into a hash with dynamicly allocated key name
@@ -953,7 +804,7 @@
   \param data the data to add
   \return SWITCH_STATUS_SUCCESS if the data is added
 */
-SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_dup(switch_hash_t *hash, const char *key, const void *data);
+SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_dup(switch_hash_t * hash, const char *key, const void *data);
 
 /*! 
   \brief Delete data from a hash based on desired key
@@ -961,7 +812,7 @@
   \param key the key from which to delete the data
   \return SWITCH_STATUS_SUCCESS if the data is deleted
 */
-SWITCH_DECLARE(switch_status_t) switch_core_hash_delete(switch_hash_t *hash, const char *key);
+SWITCH_DECLARE(switch_status_t) switch_core_hash_delete(switch_hash_t * hash, const char *key);
 
 /*! 
   \brief Retrieve data from a given hash
@@ -969,7 +820,7 @@
   \param key the key to retrieve
   \return a pointer to the data held in the key
 */
-SWITCH_DECLARE(void *) switch_core_hash_find(switch_hash_t *hash, const char *key);
+SWITCH_DECLARE(void *) switch_core_hash_find(switch_hash_t * hash, const char *key);
 ///\}
 
 ///\defgroup timer Timer Functions
@@ -1031,15 +882,13 @@
   \param pool the memory pool to use
   \return SWITCH_STATUS_SUCCESS if the handle is allocated
 */
-SWITCH_DECLARE(switch_status_t) switch_core_codec_init(switch_codec_t *codec, 
-													   char *codec_name, 
+SWITCH_DECLARE(switch_status_t) switch_core_codec_init(switch_codec_t *codec,
+													   char *codec_name,
 													   char *fmtp,
-													   uint32_t rate, 
-													   int ms, 
-													   int channels, 
-													   uint32_t flags,
-													   const switch_codec_settings_t *codec_settings, 
-													   switch_memory_pool_t *pool);
+													   uint32_t rate,
+													   int ms,
+													   int channels,
+													   uint32_t flags, const switch_codec_settings_t *codec_settings, switch_memory_pool_t *pool);
 
 /*! 
   \brief Encode data using a codec handle
@@ -1056,14 +905,11 @@
   \note encoded_data_len will be rewritten to the in-use size of encoded_data
 */
 SWITCH_DECLARE(switch_status_t) switch_core_codec_encode(switch_codec_t *codec,
-													   switch_codec_t *other_codec,
-													   void *decoded_data,
-													   uint32_t decoded_data_len,
-													   uint32_t decoded_rate,
-													   void *encoded_data,
-													   uint32_t *encoded_data_len,
-													   uint32_t *encoded_rate,
-													   unsigned int *flag);
+														 switch_codec_t *other_codec,
+														 void *decoded_data,
+														 uint32_t decoded_data_len,
+														 uint32_t decoded_rate,
+														 void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate, unsigned int *flag);
 
 /*! 
   \brief Decode data using a codec handle
@@ -1080,14 +926,11 @@
   \note decoded_data_len will be rewritten to the in-use size of decoded_data
 */
 SWITCH_DECLARE(switch_status_t) switch_core_codec_decode(switch_codec_t *codec,
-													   switch_codec_t *other_codec,
-													   void *encoded_data,
-													   uint32_t encoded_data_len,
-													   uint32_t encoded_rate,
-													   void *decoded_data,
-													   uint32_t *decoded_data_len,
-													   uint32_t *decoded_rate,
-													   unsigned int *flag);
+														 switch_codec_t *other_codec,
+														 void *encoded_data,
+														 uint32_t encoded_data_len,
+														 uint32_t encoded_rate,
+														 void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate, unsigned int *flag);
 
 /*! 
   \brief Destroy an initalized codec handle
@@ -1177,12 +1020,8 @@
   \return SWITCH_STATUS_SUCCESS if the file is opened
   \note the loadable module used is chosen based on the file extension
 */
-SWITCH_DECLARE(switch_status_t) switch_core_file_open(switch_file_handle_t *fh, 
-													  char *file_path, 
-													  uint8_t channels,
-													  uint32_t rate,
-													  unsigned int flags,
-													  switch_memory_pool_t *pool);
+SWITCH_DECLARE(switch_status_t) switch_core_file_open(switch_file_handle_t *fh,
+													  char *file_path, uint8_t channels, uint32_t rate, unsigned int flags, switch_memory_pool_t *pool);
 /*! 
   \brief Read media from a file handle
   \param fh the file handle to read from (must be initilized by you memset all 0 for read, fill in channels and rate for write)
@@ -1251,12 +1090,9 @@
   \param pool the pool to use (NULL for new pool)
   \return SWITCH_STATUS_SUCCESS if the handle is opened
 */
-SWITCH_DECLARE(switch_status_t) switch_core_speech_open(switch_speech_handle_t *sh, 
-													  char *module_name,
-													  char *voice_name,
-													  unsigned int rate,
-													  switch_speech_flag_t *flags,
-													  switch_memory_pool_t *pool);
+SWITCH_DECLARE(switch_status_t) switch_core_speech_open(switch_speech_handle_t *sh,
+														char *module_name,
+														char *voice_name, unsigned int rate, switch_speech_flag_t *flags, switch_memory_pool_t *pool);
 /*! 
   \brief Feed text to the TTS module
   \param sh the speech handle to feed
@@ -1305,11 +1141,8 @@
   \param flags flags in/out for fine tuning
   \return SWITCH_STATUS_SUCCESS with len adjusted to the bytes written if successful
 */
-SWITCH_DECLARE(switch_status_t) switch_core_speech_read_tts(switch_speech_handle_t *sh, 
-														  void *data,
-														  switch_size_t *datalen,
-														  uint32_t *rate,
-														  switch_speech_flag_t *flags);
+SWITCH_DECLARE(switch_status_t) switch_core_speech_read_tts(switch_speech_handle_t *sh,
+															void *data, switch_size_t *datalen, uint32_t * rate, switch_speech_flag_t *flags);
 /*! 
   \brief Close an open speech handle
   \param sh the speech handle to close
@@ -1332,11 +1165,7 @@
 */
 SWITCH_DECLARE(switch_status_t) switch_core_asr_open(switch_asr_handle_t *ah,
 													 char *module_name,
-													 char *codec,
-													 int rate,
-													 char *dest,
-													 switch_asr_flag_t *flags,
-													 switch_memory_pool_t *pool);
+													 char *codec, int rate, char *dest, switch_asr_flag_t *flags, switch_memory_pool_t *pool);
 
 /*!
   \brief Close an asr handle
@@ -1420,12 +1249,8 @@
   \param pool the pool to use (NULL for new pool)
   \return SWITCH_STATUS_SUCCESS if the handle is opened
 */
-SWITCH_DECLARE(switch_status_t) switch_core_directory_open(switch_directory_handle_t *dh, 
-														 char *module_name, 
-														 char *source,
-														 char *dsn,
-														 char *passwd,
-														 switch_memory_pool_t *pool);
+SWITCH_DECLARE(switch_status_t) switch_core_directory_open(switch_directory_handle_t *dh,
+														   char *module_name, char *source, char *dsn, char *passwd, switch_memory_pool_t *pool);
 
 /*! 
   \brief Query a directory handle
@@ -1472,6 +1297,12 @@
 SWITCH_DECLARE(FILE *) switch_core_data_channel(switch_text_channel_t channel);
 
 /*! 
+  \brief Determines if the core is ready to take calls
+  \return SWITCH_TRUE or SWITCH_FALSE
+*/
+SWITCH_DECLARE(switch_bool_t) switch_core_ready(void);
+
+/*! 
   \brief Execute a management operation.
   \param relative_oid the relative oid of the operation.
   \param action the action to perform.
@@ -1479,10 +1310,7 @@
   \param datalen size in bytes of data.
   \return SUCCESS on sucess.
 */
-SWITCH_DECLARE(switch_status_t) switch_core_management_exec(char *relative_oid,
-															switch_management_action_t action,
-															char *data,
-															switch_size_t datalen);
+SWITCH_DECLARE(switch_status_t) switch_core_management_exec(char *relative_oid, switch_management_action_t action, char *data, switch_size_t datalen);
 
 
 /*! 
@@ -1522,7 +1350,7 @@
   \param val the command arguement (if needed)
   \return 0 on success nonzero on error
 */
-SWITCH_DECLARE(int32_t) switch_core_session_ctl(switch_session_ctl_t cmd, uint32_t *val);
+SWITCH_DECLARE(int32_t) switch_core_session_ctl(switch_session_ctl_t cmd, uint32_t * val);
 
 /*!
   \brief Get the output console
@@ -1532,7 +1360,7 @@
 /*! 
   \brief Launch a thread
 */
-SWITCH_DECLARE(void) switch_core_launch_thread(void *(*func)(switch_thread_t *, void*), void *obj, switch_memory_pool_t *pool);
+SWITCH_DECLARE(void) switch_core_launch_thread(void *(*func) (switch_thread_t *, void *), void *obj, switch_memory_pool_t *pool);
 
 /*!
   \brief Initiate Globals
@@ -1553,9 +1381,7 @@
 */
 
 SWITCH_END_EXTERN_C
-
 #endif
-
 /* For Emacs:
  * Local Variables:
  * mode:c

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_core_db.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_core_db.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_core_db.h	Fri Mar 30 12:19:18 2007
@@ -36,28 +36,24 @@
 #define SWITCH_CORE_DB_H
 
 SWITCH_BEGIN_EXTERN_C
-
 /**
  * @defgroup switch_sqlite_top Brought To You By SQLite
  * @ingroup FREESWITCH
  * @{
  */
-
 /**
  * @defgroup switch_core_db Database Routines
  * @ingroup switch_sqlite_top 
  * @{
  */
-
 /**
  * Each open database is represented by an instance of the
  * following opaque structure.
 */
-
-typedef struct sqlite3 switch_core_db_t;
+	typedef struct sqlite3 switch_core_db_t;
 typedef struct sqlite3_stmt switch_core_db_stmt_t;
 
-typedef int (*switch_core_db_callback_func_t)(void *pArg, int argc, char **argv, char **columnNames);
+typedef int (*switch_core_db_callback_func_t) (void *pArg, int argc, char **argv, char **columnNames);
 
 /*
 ** These are special value for the destructor that is passed in as the
@@ -71,7 +67,7 @@
 ** The typedef is necessary to work around problems in certain
 ** C++ compilers.
 */
-typedef void (*switch_core_db_destructor_type_t)(void*);
+typedef void (*switch_core_db_destructor_type_t) (void *);
 #define SWITCH_CORE_DB_STATIC      ((switch_core_db_destructor_type_t)0)
 #define SWITCH_CORE_DB_TRANSIENT   ((switch_core_db_destructor_type_t)-1)
 
@@ -144,14 +140,14 @@
  *
  *  Return the value as UTF-8 text.
  */
-SWITCH_DECLARE(const unsigned char *)switch_core_db_column_text(switch_core_db_stmt_t *stmt, int iCol);
+SWITCH_DECLARE(const unsigned char *) switch_core_db_column_text(switch_core_db_stmt_t *stmt, int iCol);
 
 /**
  * The first parameter is a compiled SQL statement. This function returns
  * the column heading for the Nth column of that statement, where N is the
  * second function parameter.  The string returned is UTF-8.
  */
-SWITCH_DECLARE(const char *)switch_core_db_column_name(switch_core_db_stmt_t *stmt, int N);
+SWITCH_DECLARE(const char *) switch_core_db_column_name(switch_core_db_stmt_t *stmt, int N);
 
 /**
  * Return the number of columns in the result set returned by the compiled
@@ -168,7 +164,7 @@
  * The string "not an error" is returned when the most recent API call was
  * successful.
  */
-SWITCH_DECLARE(const char *)switch_core_db_errmsg(switch_core_db_t *db);
+SWITCH_DECLARE(const char *) switch_core_db_errmsg(switch_core_db_t *db);
 
 /**
  * A function to executes one or more statements of SQL.
@@ -210,11 +206,7 @@
  * behavior can be modified somewhat using the sswitch_core_db_busy_handler()
  * and switch_core_db_busy_timeout() functions below.)
  */
-SWITCH_DECLARE(int) switch_core_db_exec(switch_core_db_t *db,
-										const char *sql,
-										switch_core_db_callback_func_t callback,
-										void *data,
-										char **errmsg);
+SWITCH_DECLARE(int) switch_core_db_exec(switch_core_db_t *db, const char *sql, switch_core_db_callback_func_t callback, void *data, char **errmsg);
 
 /**
  * This function is called to delete a compiled
@@ -254,11 +246,7 @@
  *
  * On success, SWITCH_CORE_DB_OK is returned.  Otherwise an error code is returned.
  */
-SWITCH_DECLARE(int) switch_core_db_prepare(switch_core_db_t *db,
-										   const char *zSql,
-										   int nBytes,
-										   switch_core_db_stmt_t **ppStmt,
-										   const char **pzTail);
+SWITCH_DECLARE(int) switch_core_db_prepare(switch_core_db_t *db, const char *zSql, int nBytes, switch_core_db_stmt_t **ppStmt, const char **pzTail);
 
 /** 
  * After an SQL query has been compiled with a call to either
@@ -451,14 +439,13 @@
  *
  * The return value of this routine is the same as from switch_core_db_exec().
  */
-SWITCH_DECLARE(int) switch_core_db_get_table(
-  switch_core_db_t *db,       /* An open database */
-  const char *sql,       /* SQL to be executed */
-  char ***resultp,       /* Result written to a char *[]  that this points to */
-  int *nrow,             /* Number of result rows written here */
-  int *ncolumn,          /* Number of result columns written here */
-  char **errmsg          /* Error msg written here */
-);
+SWITCH_DECLARE(int) switch_core_db_get_table(switch_core_db_t *db,	/* An open database */
+											 const char *sql,	/* SQL to be executed */
+											 char ***resultp,	/* Result written to a char *[]  that this points to */
+											 int *nrow,	/* Number of result rows written here */
+											 int *ncolumn,	/* Number of result columns written here */
+											 char **errmsg	/* Error msg written here */
+	);
 
 /**
  * Call this routine to free the memory that sqlite3_get_table() allocated.
@@ -471,36 +458,36 @@
 SWITCH_DECLARE(void) switch_core_db_free(char *z);
 
 /** Return values for switch_core_db_exec() and switch_core_db_step()*/
-#define SWITCH_CORE_DB_OK           0   /* Successful result */
+#define SWITCH_CORE_DB_OK           0	/* Successful result */
 /* beginning-of-error-codes */
-#define SWITCH_CORE_DB_ERROR        1   /* SQL error or missing database */
-#define SWITCH_CORE_DB_INTERNAL     2   /* NOT USED. Internal logic error in SQLite */
-#define SWITCH_CORE_DB_PERM         3   /* Access permission denied */
-#define SWITCH_CORE_DB_ABORT        4   /* Callback routine requested an abort */
-#define SWITCH_CORE_DB_BUSY         5   /* The database file is locked */
-#define SWITCH_CORE_DB_LOCKED       6   /* A table in the database is locked */
-#define SWITCH_CORE_DB_NOMEM        7   /* A malloc() failed */
-#define SWITCH_CORE_DB_READONLY     8   /* Attempt to write a readonly database */
-#define SWITCH_CORE_DB_INTERRUPT    9   /* Operation terminated by switch_core_db_interrupt()*/
-#define SWITCH_CORE_DB_IOERR       10   /* Some kind of disk I/O error occurred */
-#define SWITCH_CORE_DB_CORRUPT     11   /* The database disk image is malformed */
-#define SWITCH_CORE_DB_NOTFOUND    12   /* NOT USED. Table or record not found */
-#define SWITCH_CORE_DB_FULL        13   /* Insertion failed because database is full */
-#define SWITCH_CORE_DB_CANTOPEN    14   /* Unable to open the database file */
-#define SWITCH_CORE_DB_PROTOCOL    15   /* Database lock protocol error */
-#define SWITCH_CORE_DB_EMPTY       16   /* Database is empty */
-#define SWITCH_CORE_DB_SCHEMA      17   /* The database schema changed */
-#define SWITCH_CORE_DB_TOOBIG      18   /* NOT USED. Too much data for one row */
-#define SWITCH_CORE_DB_CONSTRAINT  19   /* Abort due to contraint violation */
-#define SWITCH_CORE_DB_MISMATCH    20   /* Data type mismatch */
-#define SWITCH_CORE_DB_MISUSE      21   /* Library used incorrectly */
-#define SWITCH_CORE_DB_NOLFS       22   /* Uses OS features not supported on host */
-#define SWITCH_CORE_DB_AUTH        23   /* Authorization denied */
-#define SWITCH_CORE_DB_FORMAT      24   /* Auxiliary database format error */
-#define SWITCH_CORE_DB_RANGE       25   /* 2nd parameter to switch_core_db_bind out of range */
-#define SWITCH_CORE_DB_NOTADB      26   /* File opened that is not a database file */
-#define SWITCH_CORE_DB_ROW         100  /* switch_core_db_step() has another row ready */
-#define SWITCH_CORE_DB_DONE        101  /* switch_core_db_step() has finished executing */
+#define SWITCH_CORE_DB_ERROR        1	/* SQL error or missing database */
+#define SWITCH_CORE_DB_INTERNAL     2	/* NOT USED. Internal logic error in SQLite */
+#define SWITCH_CORE_DB_PERM         3	/* Access permission denied */
+#define SWITCH_CORE_DB_ABORT        4	/* Callback routine requested an abort */
+#define SWITCH_CORE_DB_BUSY         5	/* The database file is locked */
+#define SWITCH_CORE_DB_LOCKED       6	/* A table in the database is locked */
+#define SWITCH_CORE_DB_NOMEM        7	/* A malloc() failed */
+#define SWITCH_CORE_DB_READONLY     8	/* Attempt to write a readonly database */
+#define SWITCH_CORE_DB_INTERRUPT    9	/* Operation terminated by switch_core_db_interrupt() */
+#define SWITCH_CORE_DB_IOERR       10	/* Some kind of disk I/O error occurred */
+#define SWITCH_CORE_DB_CORRUPT     11	/* The database disk image is malformed */
+#define SWITCH_CORE_DB_NOTFOUND    12	/* NOT USED. Table or record not found */
+#define SWITCH_CORE_DB_FULL        13	/* Insertion failed because database is full */
+#define SWITCH_CORE_DB_CANTOPEN    14	/* Unable to open the database file */
+#define SWITCH_CORE_DB_PROTOCOL    15	/* Database lock protocol error */
+#define SWITCH_CORE_DB_EMPTY       16	/* Database is empty */
+#define SWITCH_CORE_DB_SCHEMA      17	/* The database schema changed */
+#define SWITCH_CORE_DB_TOOBIG      18	/* NOT USED. Too much data for one row */
+#define SWITCH_CORE_DB_CONSTRAINT  19	/* Abort due to contraint violation */
+#define SWITCH_CORE_DB_MISMATCH    20	/* Data type mismatch */
+#define SWITCH_CORE_DB_MISUSE      21	/* Library used incorrectly */
+#define SWITCH_CORE_DB_NOLFS       22	/* Uses OS features not supported on host */
+#define SWITCH_CORE_DB_AUTH        23	/* Authorization denied */
+#define SWITCH_CORE_DB_FORMAT      24	/* Auxiliary database format error */
+#define SWITCH_CORE_DB_RANGE       25	/* 2nd parameter to switch_core_db_bind out of range */
+#define SWITCH_CORE_DB_NOTADB      26	/* File opened that is not a database file */
+#define SWITCH_CORE_DB_ROW         100	/* switch_core_db_step() has another row ready */
+#define SWITCH_CORE_DB_DONE        101	/* switch_core_db_step() has finished executing */
 /* end-of-error-codes */
 
 
@@ -547,12 +534,10 @@
  * should always use %q instead of %s when inserting text into a string 
  * literal.
  */
-SWITCH_DECLARE(char *)switch_mprintf(const char *zFormat,...);
+SWITCH_DECLARE(char *) switch_mprintf(const char *zFormat, ...);
 
 SWITCH_END_EXTERN_C
-
 #endif
-
 /* For Emacs:
  * Local Variables:
  * mode:c

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_event.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_event.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_event.h	Fri Mar 30 12:19:18 2007
@@ -61,9 +61,8 @@
 #include <switch.h>
 
 SWITCH_BEGIN_EXTERN_C
-
 /*! \brief An event Header */
-struct switch_event_header{
+	struct switch_event_header {
 	/*! the header name */
 	char *name;
 	/*! the header value */
@@ -172,7 +171,8 @@
   \param fmt the value of the header (varargs see standard sprintf family)
   \return SWITCH_STATUS_SUCCESS if the header was added
 */
-SWITCH_DECLARE(switch_status_t) switch_event_add_header(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *fmt, ...) PRINTF_FUNCTION(4,5);
+SWITCH_DECLARE(switch_status_t) switch_event_add_header(switch_event_t *event, switch_stack_t stack,
+														const char *header_name, const char *fmt, ...) PRINTF_FUNCTION(4, 5);
 
 /*!
   \brief Destroy an event
@@ -208,7 +208,8 @@
   \param user_data optional user specific data to pass whenever the callback is invoked
   \return SWITCH_STATUS_SUCCESS if the event was binded
 */
-SWITCH_DECLARE(switch_status_t) switch_event_bind(char *id, switch_event_types_t event, char *subclass_name, switch_event_callback_t callback, void *user_data);
+SWITCH_DECLARE(switch_status_t) switch_event_bind(char *id, switch_event_types_t event, char *subclass_name, switch_event_callback_t callback,
+												  void *user_data);
 
 /*!
   \brief Render the name of an event id enumeration
@@ -251,7 +252,7 @@
   \return the xml object if the operation was successful
   \note the body supplied by this function will supersede an existing body the event may have
 */
-SWITCH_DECLARE(switch_xml_t) switch_event_xmlize(switch_event_t *event, const char *fmt, ...) PRINTF_FUNCTION(2,3);
+SWITCH_DECLARE(switch_xml_t) switch_event_xmlize(switch_event_t *event, const char *fmt, ...) PRINTF_FUNCTION(2, 3);
 
 /*!
   \brief Determine if the event system has been initilized
@@ -266,7 +267,7 @@
   \return SWITCH_STATUS_SUCCESS if the body was added to the event
   \note the body parameter can be shadowed by the switch_event_reserve_subclass_detailed function
 */
-SWITCH_DECLARE(switch_status_t) switch_event_add_body(switch_event_t *event, const char *fmt, ...) PRINTF_FUNCTION(2,3);
+SWITCH_DECLARE(switch_status_t) switch_event_add_body(switch_event_t *event, const char *fmt, ...) PRINTF_FUNCTION(2, 3);
 
 
 /*!
@@ -311,9 +312,7 @@
 ///\}
 
 SWITCH_END_EXTERN_C
-
 #endif
-
 /* For Emacs:
  * Local Variables:
  * mode:c

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_frame.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_frame.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_frame.h	Fri Mar 30 12:19:18 2007
@@ -39,16 +39,15 @@
 #include <switch.h>
 
 SWITCH_BEGIN_EXTERN_C
-
 /*! \brief An abstraction of a data frame */
-struct switch_frame {
+	struct switch_frame {
 	/*! a pointer to the codec information */
 	switch_codec_t *codec;
 	/*! the originating source of the frame */
 	const char *source;
 	/*! the raw packet */
 	void *packet;
-	/*! the size of the raw packet when applicable*/
+	/*! the size of the raw packet when applicable */
 	uint32_t packetlen;
 	/*! the frame data */
 	void *data;
@@ -69,9 +68,7 @@
 };
 
 SWITCH_END_EXTERN_C
-
 #endif
-
 /* For Emacs:
  * Local Variables:
  * mode:c

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_ivr.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_ivr.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_ivr.h	Fri Mar 30 12:19:18 2007
@@ -42,7 +42,6 @@
 #include <switch.h>
 
 SWITCH_BEGIN_EXTERN_C
-
 /**
  * @defgroup switch_ivr IVR Library
  * @ingroup core1
@@ -50,8 +49,6 @@
  *	building blocks for a higher level IVR interface.
  * @{
  */
-
-
 /*!
   \brief Generate an XML CDR report.
   \param session the session to get the data from.
@@ -59,7 +56,7 @@
   \return SWITCH_STATUS_SUCCESS if successful
   \note on success the xml object must be freed
 */
-SWITCH_DECLARE(switch_status_t) switch_ivr_generate_xml_cdr(switch_core_session_t *session, switch_xml_t *xml_cdr);
+SWITCH_DECLARE(switch_status_t) switch_ivr_generate_xml_cdr(switch_core_session_t *session, switch_xml_t * xml_cdr);
 
 /*!
   \brief Parse command from an event
@@ -88,9 +85,7 @@
   \param timeout a timeout in milliseconds
   \return SWITCH_STATUS_SUCCESS to keep the collection moving.
 */
-SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_callback(switch_core_session_t *session,
-                                                                   switch_input_args_t *args,
-																   uint32_t timeout);
+SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_callback(switch_core_session_t *session, switch_input_args_t *args, uint32_t timeout);
 
 /*!
   \brief Wait for specified number of DTMF digits, untile terminator is received or until the channel hangs up.
@@ -106,10 +101,7 @@
 SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_session_t *session,
 																char *buf,
 																uint32_t buflen,
-																uint32_t maxdigits,
-																const char *terminators,
-																char *terminator,
-																uint32_t timeout);
+																uint32_t maxdigits, const char *terminators, char *terminator, uint32_t timeout);
 
 /*!
   \brief Engage background Speech detection on a session
@@ -122,11 +114,7 @@
   \return SWITCH_STATUS_SUCCESS if all is well
 */
 SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech(switch_core_session_t *session,
-														 char *mod_name,
-														 char *grammar,
-														 char *path,
-														 char *dest,
-														 switch_asr_handle_t *ah);
+														 char *mod_name, char *grammar, char *path, char *dest, switch_asr_handle_t *ah);
 
 /*!
   \brief Stop background Speech detection on a session
@@ -173,7 +161,7 @@
   \param fh file handle to use (NULL for builtin one)
   \return SWITCH_STATUS_SUCCESS if all is well
 */
-SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t *session, char *file,  switch_file_handle_t *fh);
+SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t *session, char *file, switch_file_handle_t *fh);
 
 /*!
   \brief Stop Recording a session
@@ -197,10 +185,7 @@
   \return SWITCH_STATUS_SUCCESS if all is well
   \note passing a NULL dtmf_callback nad a not NULL buf indicates to copy any dtmf to buf and stop playback.
 */
-SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *session,
-                                                     switch_file_handle_t *fh,
-                                                     char *file,
-                                                     switch_input_args_t *args);
+SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *session, switch_file_handle_t *fh, char *file, switch_input_args_t *args);
 
 
 /*!
@@ -216,10 +201,7 @@
   \note passing a NULL dtmf_callback nad a not NULL buf indicates to copy any dtmf to buf and stop recording.
 */
 SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *session,
-                                                       switch_file_handle_t *fh,
-                                                       char *file,
-                                                       switch_input_args_t *args,
-                                                       uint32_t limit);
+													   switch_file_handle_t *fh, char *file, switch_input_args_t *args, uint32_t limit);
 
 
 /*!
@@ -239,23 +221,18 @@
   \note to test for digit capture failure look for \\0 in the first position of the buffer
 */
 SWITCH_DECLARE(switch_status_t) switch_play_and_get_digits(switch_core_session_t *session,
-                                                           uint32_t min_digits,
-                                                           uint32_t max_digits,
-                                                           uint32_t max_tries,
-                                                           uint32_t timeout,
-                                                           char* valid_terminators,
-                                                           char* audio_file,
-                                                           char* bad_input_audio_file,
-                                                           void* digit_buffer,
-                                                           uint32_t digit_buffer_length,
-                                                           char* digits_regex);
+														   uint32_t min_digits,
+														   uint32_t max_digits,
+														   uint32_t max_tries,
+														   uint32_t timeout,
+														   char *valid_terminators,
+														   char *audio_file,
+														   char *bad_input_audio_file, void *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,
-                                                             switch_speech_handle_t *sh,
-                                                             switch_codec_t *codec,
-                                                             switch_timer_t *timer,
-                                                             char *text,
-                                                             switch_input_args_t *args);
+															 switch_speech_handle_t *sh,
+															 switch_codec_t *codec, switch_timer_t *timer, char *text, switch_input_args_t *args);
 
 /*!
   \brief Speak given text with given tts engine
@@ -269,12 +246,8 @@
   \param buflen the len of buf
   \return SWITCH_STATUS_SUCCESS if all is well
 */
-SWITCH_DECLARE(switch_status_t) switch_ivr_speak_text(switch_core_session_t *session, 
-													  char *tts_name,
-													  char *voice_name,
-													  uint32_t rate,
-													  char *text,
-                                                      switch_input_args_t *args);
+SWITCH_DECLARE(switch_status_t) switch_ivr_speak_text(switch_core_session_t *session,
+													  char *tts_name, char *voice_name, uint32_t rate, char *text, switch_input_args_t *args);
 
 /*!
   \brief Make an outgoing call
@@ -295,9 +268,7 @@
 													 char *bridgeto,
 													 uint32_t timelimit_sec,
 													 const switch_state_handler_table_t *table,
-													 char *cid_name_override,
-													 char *cid_num_override,
-													 switch_caller_profile_t *caller_profile_override);
+													 char *cid_name_override, char *cid_num_override, switch_caller_profile_t *caller_profile_override);
 
 /*!
   \brief Bridge Audio from one session to another
@@ -308,10 +279,9 @@
   \param peer_session_data data to pass to the DTMF callback for peer_session
   \return SWITCH_STATUS_SUCCESS if all is well
 */
-SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_session_t *session, 
+SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_session_t *session,
 																 switch_core_session_t *peer_session,
-																 switch_input_callback_function_t dtmf_callback,
-																 void *session_data,
+																 switch_input_callback_function_t dtmf_callback, void *session_data,
 																 void *peer_session_data);
 
 /*!
@@ -436,24 +406,24 @@
 
 /******************************************************************************************************/
 
-struct switch_ivr_digit_stream_parser;
-typedef struct switch_ivr_digit_stream_parser switch_ivr_digit_stream_parser_t;
-struct switch_ivr_digit_stream;
-typedef struct switch_ivr_digit_stream switch_ivr_digit_stream_t;
+	 struct switch_ivr_digit_stream_parser;
+	 typedef struct switch_ivr_digit_stream_parser switch_ivr_digit_stream_parser_t;
+	 struct switch_ivr_digit_stream;
+	 typedef struct switch_ivr_digit_stream switch_ivr_digit_stream_t;
 /*!
   \brief Create a digit stream parser object
   \param pool the pool to use for the new hash
   \param parser a pointer to the object pointer
   \return SWITCH_STATUS_SUCCESS if all is well 
 */
-SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_new(switch_memory_pool_t *pool, switch_ivr_digit_stream_parser_t **parser);
+SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_new(switch_memory_pool_t *pool, switch_ivr_digit_stream_parser_t ** parser);
 
 /*!
   \brief Destroy a digit stream parser object
   \param parser a pointer to the parser object
   \return SWITCH_STATUS_SUCCESS if all is well 
 */
-SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_destroy(switch_ivr_digit_stream_parser_t *parser);
+SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_destroy(switch_ivr_digit_stream_parser_t * parser);
 
 /*!
   \brief Create a new digit stream object
@@ -461,14 +431,14 @@
   \param stream a pointer to the stream object pointer
   \return NULL if no match found or consumer data that was associated with a given digit string when matched
 */
-SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_new(switch_ivr_digit_stream_parser_t *parser, switch_ivr_digit_stream_t **stream);
+SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_new(switch_ivr_digit_stream_parser_t * parser, switch_ivr_digit_stream_t ** stream);
 
 /*!
   \brief Destroys a digit stream object
   \param stream a pointer to the stream object
   \return NULL if no match found or consumer data that was associated with a given digit string when matched
 */
-SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_destroy(switch_ivr_digit_stream_t *stream);
+SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_destroy(switch_ivr_digit_stream_t * stream);
 
 /*!
   \brief Set a digit string to action mapping
@@ -477,7 +447,7 @@
   \param data consumer data attached to this digit string
   \return SWITCH_STATUS_SUCCESS if all is well 
 */
-SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_set_event(switch_ivr_digit_stream_parser_t *parser, char *digits, void *data);
+SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_set_event(switch_ivr_digit_stream_parser_t * parser, char *digits, void *data);
 
 /*!
   \brief Delete a string to action mapping
@@ -485,7 +455,7 @@
   \param digits the digit string to be removed from the map
   \return SWITCH_STATUS_SUCCESS if all is well 
 */
-SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_del_event(switch_ivr_digit_stream_parser_t *parser, char *digits);
+SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_del_event(switch_ivr_digit_stream_parser_t * parser, char *digits);
 
 /*!
   \brief Feed digits collected into the stream for event match testing
@@ -493,14 +463,14 @@
   \param digit a digit to collect and test against the map of digit strings
   \return NULL if no match found or consumer data that was associated with a given digit string when matched
 */
-SWITCH_DECLARE(void *) switch_ivr_digit_stream_parser_feed(switch_ivr_digit_stream_parser_t *parser, switch_ivr_digit_stream_t *stream, char digit);
+SWITCH_DECLARE(void *) switch_ivr_digit_stream_parser_feed(switch_ivr_digit_stream_parser_t * parser, switch_ivr_digit_stream_t * stream, char digit);
 
 /*!
   \brief Reset the collected digit stream to nothing
   \param stream a pointer to the parser stream object created by switch_ivr_digit_stream_new
   \return SWITCH_STATUS_SUCCESS if all is well 
 */
-SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_reset(switch_ivr_digit_stream_t *stream);
+SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_reset(switch_ivr_digit_stream_t * stream);
 
 /*!
   \brief Set a digit string terminator
@@ -508,7 +478,7 @@
   \param digit the terminator digit
   \return SWITCH_STATUS_SUCCESS if all is well 
 */
-SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_set_terminator(switch_ivr_digit_stream_parser_t *parser, char digit);
+SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_set_terminator(switch_ivr_digit_stream_parser_t * parser, char digit);
 
 
 /******************************************************************************************************/
@@ -524,28 +494,28 @@
  * @{
  */
 
-typedef enum {
-	SWITCH_IVR_MENU_FLAG_FALLTOMAIN = (1 << 0),
-	SWITCH_IVR_MENU_FLAG_FREEPOOL = (1 << 1),
-	SWITCH_IVR_MENU_FLAG_STACK = (1 << 2),
-} switch_ivr_menu_flags;
+	 typedef enum {
+		 SWITCH_IVR_MENU_FLAG_FALLTOMAIN = (1 << 0),
+		 SWITCH_IVR_MENU_FLAG_FREEPOOL = (1 << 1),
+		 SWITCH_IVR_MENU_FLAG_STACK = (1 << 2),
+	 } switch_ivr_menu_flags;
 /* Actions are either set in switch_ivr_menu_bind_function or returned by a callback */
-typedef enum {
-	SWITCH_IVR_ACTION_DIE, 		/* Exit the menu.                  */
-	SWITCH_IVR_ACTION_EXECMENU,	/* Goto another menu in the stack. */
-	SWITCH_IVR_ACTION_EXECAPP,	/* Execute an application.         */
-	SWITCH_IVR_ACTION_PLAYSOUND,	/* Play a sound.                   */
-	SWITCH_IVR_ACTION_SAYTEXT,	/* say text.                       */
-	SWITCH_IVR_ACTION_SAYPHRASE,	/* say a phrase macro.                       */
-	SWITCH_IVR_ACTION_BACK,		/* Go back 1 menu.                 */
-	SWITCH_IVR_ACTION_TOMAIN,	/* Go back to the top level menu.  */
-	SWITCH_IVR_ACTION_TRANSFER,	/* Transfer caller to another ext. */
-	SWITCH_IVR_ACTION_NOOP,		/* No operation                    */
-} switch_ivr_action_t;
-struct switch_ivr_menu;
-typedef switch_ivr_action_t switch_ivr_menu_action_function_t(struct switch_ivr_menu *, char *, char *, size_t, void *);
-typedef struct switch_ivr_menu switch_ivr_menu_t;
-typedef struct switch_ivr_menu_action switch_ivr_menu_action_t;
+	 typedef enum {
+		 SWITCH_IVR_ACTION_DIE,	/* Exit the menu.                  */
+		 SWITCH_IVR_ACTION_EXECMENU,	/* Goto another menu in the stack. */
+		 SWITCH_IVR_ACTION_EXECAPP,	/* Execute an application.         */
+		 SWITCH_IVR_ACTION_PLAYSOUND,	/* Play a sound.                   */
+		 SWITCH_IVR_ACTION_SAYTEXT,	/* say text.                       */
+		 SWITCH_IVR_ACTION_SAYPHRASE,	/* say a phrase macro.                       */
+		 SWITCH_IVR_ACTION_BACK,	/* Go back 1 menu.                 */
+		 SWITCH_IVR_ACTION_TOMAIN,	/* Go back to the top level menu.  */
+		 SWITCH_IVR_ACTION_TRANSFER,	/* Transfer caller to another ext. */
+		 SWITCH_IVR_ACTION_NOOP,	/* No operation                    */
+	 } switch_ivr_action_t;
+	 struct switch_ivr_menu;
+	 typedef switch_ivr_action_t switch_ivr_menu_action_function_t(struct switch_ivr_menu *, char *, char *, size_t, void *);
+	 typedef struct switch_ivr_menu switch_ivr_menu_t;
+	 typedef struct switch_ivr_menu_action switch_ivr_menu_action_t;
 /******************************************************************************************************/
 
 /*!
@@ -564,19 +534,16 @@
  *\param pool memory pool (NULL to create one)
  *\return SWITCH_STATUS_SUCCESS if the menu was created
  */
-SWITCH_DECLARE(switch_status_t) switch_ivr_menu_init(switch_ivr_menu_t **new_menu,
-													 switch_ivr_menu_t *main,
-													 const char *name, 
-													 const char *greeting_sound, 
+SWITCH_DECLARE(switch_status_t) switch_ivr_menu_init(switch_ivr_menu_t ** new_menu,
+													 switch_ivr_menu_t * main,
+													 const char *name,
+													 const char *greeting_sound,
 													 const char *short_greeting_sound,
 													 const char *exit_sound,
-													 const char *invalid_sound, 
+													 const char *invalid_sound,
 													 const char *tts_engine,
 													 const char *tts_voice,
-													 const char *phrase_lang,
-													 int timeout,
-													 int max_failures, 
-													 switch_memory_pool_t *pool);
+													 const char *phrase_lang, int timeout, int max_failures, switch_memory_pool_t *pool);
 
 /*!
  *\brief switch_ivr_menu_bind_action: Bind a keystroke to an action.
@@ -586,7 +553,7 @@
  *\param bind KeyStrokes to bind the action to.
  *\return SWUTCH_STATUS_SUCCESS if the action was binded
  */
-SWITCH_DECLARE(switch_status_t) switch_ivr_menu_bind_action(switch_ivr_menu_t *menu, switch_ivr_action_t ivr_action, const char *arg, const char *bind);
+SWITCH_DECLARE(switch_status_t) switch_ivr_menu_bind_action(switch_ivr_menu_t * menu, switch_ivr_action_t ivr_action, const char *arg, const char *bind);
 
 
 /*!
@@ -600,7 +567,8 @@
  *\note The function returns an switch_ivr_action_t enum of what you want to do. and looks to your buffer for args.
  *\return SWUTCH_STATUS_SUCCESS if the function was binded
  */
-SWITCH_DECLARE(switch_status_t) switch_ivr_menu_bind_function(switch_ivr_menu_t *menu, switch_ivr_menu_action_function_t *function, const char *arg, const char *bind);
+SWITCH_DECLARE(switch_status_t) switch_ivr_menu_bind_function(switch_ivr_menu_t * menu,
+															  switch_ivr_menu_action_function_t * function, const char *arg, const char *bind);
 
 
 /*!
@@ -611,17 +579,17 @@
  *\param obj A void pointer to an object you want to make avaliable to your callback functions that you may have binded with switch_ivr_menu_bind_function.
  *\return SWITCH_STATUS_SUCCESS if all is well
  */
-SWITCH_DECLARE(switch_status_t) switch_ivr_menu_execute(switch_core_session_t *session, switch_ivr_menu_t *stack, char *name, void *obj);
+SWITCH_DECLARE(switch_status_t) switch_ivr_menu_execute(switch_core_session_t *session, switch_ivr_menu_t * stack, char *name, void *obj);
 
 /*!
  *\brief free a stack of menu objects.
  *\param stack The top level menu you wish to destroy.
  *\return SWITCH_STATUS_SUCCESS if the object was a top level menu and it was freed
  */
-SWITCH_DECLARE(switch_status_t) switch_ivr_menu_stack_free(switch_ivr_menu_t *stack);
+SWITCH_DECLARE(switch_status_t) switch_ivr_menu_stack_free(switch_ivr_menu_t * stack);
 
-struct switch_ivr_menu_xml_ctx;
-typedef struct switch_ivr_menu_xml_ctx switch_ivr_menu_xml_ctx_t;
+	 struct switch_ivr_menu_xml_ctx;
+	 typedef struct switch_ivr_menu_xml_ctx switch_ivr_menu_xml_ctx_t;
 /*!
  *\brief Build a menu stack from an xml source
  *\param xml_menu_ctx The XML menu parser context previously created by switch_ivr_menu_stack_xml_init
@@ -630,10 +598,8 @@
  *\param xml_menu The xml Menu source of the menu to be created
  *\return SWITCH_STATUS_SUCCESS if all is well
  */
-SWITCH_DECLARE(switch_status_t) switch_ivr_menu_stack_xml_build(switch_ivr_menu_xml_ctx_t *xml_menu_ctx,
-                                                                switch_ivr_menu_t **menu_stack,
-                                                                switch_xml_t xml_menus,
-                                                                switch_xml_t xml_menu);
+SWITCH_DECLARE(switch_status_t) switch_ivr_menu_stack_xml_build(switch_ivr_menu_xml_ctx_t * xml_menu_ctx,
+																switch_ivr_menu_t ** menu_stack, switch_xml_t xml_menus, switch_xml_t xml_menu);
 
 /*!
  *\param xml_menu_ctx The XML menu parser context previously created by switch_ivr_menu_stack_xml_init
@@ -641,28 +607,22 @@
  *\param function The menu function callback that will be executed when menu digits are bound to this name
  *\return SWITCH_STATUS_SUCCESS if all is well
  */
-SWITCH_DECLARE(switch_status_t) switch_ivr_menu_stack_xml_add_custom(switch_ivr_menu_xml_ctx_t *xml_menu_ctx,
-										char *name,
-										switch_ivr_menu_action_function_t *function);
+SWITCH_DECLARE(switch_status_t) switch_ivr_menu_stack_xml_add_custom(switch_ivr_menu_xml_ctx_t * xml_menu_ctx,
+																	 char *name, switch_ivr_menu_action_function_t * function);
 
 /*!
  *\param xml_menu_ctx A pointer of a XML menu parser context to be created
  *\param pool memory pool (NULL to create one)
  *\return SWITCH_STATUS_SUCCESS if all is well
  */
-SWITCH_DECLARE(switch_status_t) switch_ivr_menu_stack_xml_init(switch_ivr_menu_xml_ctx_t **xml_menu_ctx, switch_memory_pool_t *pool);
+SWITCH_DECLARE(switch_status_t) switch_ivr_menu_stack_xml_init(switch_ivr_menu_xml_ctx_t ** xml_menu_ctx, switch_memory_pool_t *pool);
 
-SWITCH_DECLARE(switch_status_t) switch_ivr_phrase_macro(switch_core_session_t *session,
-                                                        char *macro_name,
-                                                        char *data,
-                                                        char *lang,
-                                                        switch_input_args_t *args);
+SWITCH_DECLARE(switch_status_t) switch_ivr_phrase_macro(switch_core_session_t *session, char *macro_name, char *data, char *lang,
+														switch_input_args_t *args);
 /** @} */
 
 SWITCH_END_EXTERN_C
-
 #endif
-
 /* For Emacs:
  * Local Variables:
  * mode:c

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_loadable_module.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_loadable_module.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_loadable_module.h	Fri Mar 30 12:19:18 2007
@@ -44,15 +44,13 @@
 #include <switch.h>
 
 SWITCH_BEGIN_EXTERN_C
-
 /*!
   \defgroup mods Loadable Module Functions
   \ingroup core1
   \{ 
 */
-
 /*! \brief The abstraction of a loadable module */
-struct switch_loadable_module_interface {
+	struct switch_loadable_module_interface {
 	/*! the name of the module */
 	const char *module_name;
 	/*! the table of endpoints the module has implmented */
@@ -76,7 +74,7 @@
 	/*! the table of chat interfaces the module has implmented */
 	const switch_chat_interface_t *chat_interface;
 	/*! the table of say interfaces the module has implmented */
-	const switch_say_interface_t *say_interface;	
+	const switch_say_interface_t *say_interface;
 	/*! the table of asr interfaces the module has implmented */
 	const switch_asr_interface_t *asr_interface;
 	/*! the table of management interfaces the module has implmented */
@@ -125,9 +123,9 @@
   \note only use this function if you are making a module that in turn gateways module loading to another technology
  */
 SWITCH_DECLARE(switch_status_t) switch_loadable_module_build_dynamic(char *filename,
-																   switch_module_load_t switch_module_load,
-																   switch_module_runtime_t switch_module_runtime,
-																   switch_module_shutdown_t switch_module_shutdown);
+																	 switch_module_load_t switch_module_load,
+																	 switch_module_runtime_t switch_module_runtime,
+																	 switch_module_shutdown_t switch_module_shutdown);
 
 /*!
   \brief Retrieve the timer interface by it's registered name
@@ -206,8 +204,7 @@
   \param arraylen the max size in elements of the array
   \return the number of elements added to the array
  */
-SWITCH_DECLARE(int) switch_loadable_module_get_codecs(switch_memory_pool_t *pool, const switch_codec_implementation_t **array,
-													  int arraylen);
+SWITCH_DECLARE(int) switch_loadable_module_get_codecs(switch_memory_pool_t *pool, const switch_codec_implementation_t **array, int arraylen);
 
 
 /*!
@@ -219,8 +216,7 @@
   \return the number of elements added to the array
   \note this function only considers codecs that are listed in the "prefs" array and ignores the rest.
 */
-SWITCH_DECLARE(int) switch_loadable_module_get_codecs_sorted(const switch_codec_implementation_t **array,
-															 int arraylen, char **prefs, int preflen);
+SWITCH_DECLARE(int) switch_loadable_module_get_codecs_sorted(const switch_codec_implementation_t **array, int arraylen, char **prefs, int preflen);
 
 /*!
   \brief Execute a registered API command
@@ -266,9 +262,7 @@
 ///\}
 
 SWITCH_END_EXTERN_C
-
 #endif
-
 /* For Emacs:
  * Local Variables:
  * mode:c

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_log.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_log.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_log.h	Fri Mar 30 12:19:18 2007
@@ -41,35 +41,32 @@
 #include <switch.h>
 
 SWITCH_BEGIN_EXTERN_C
-
 ///\defgroup log Logger Routines
 ///\ingroup core1
 ///\{
-
-
 /*! \brief Log Data
  */
-typedef struct {
+	typedef struct {
 	/*! The complete log message */
 	char *data;
-	/*! The file where the message originated */	
+	/*! The file where the message originated */
 	char *file;
-	/*! The line number where the message originated */	
+	/*! The line number where the message originated */
 	uint32_t line;
-	/*! The function where the message originated */	
+	/*! The function where the message originated */
 	char *func;
-	/*! The log level of the message */	
+	/*! The log level of the message */
 	switch_log_level_t level;
 	/*! The time when the log line was sent */
 	switch_time_t timestamp;
-	/*! A pointer to where the actual content of the message starts (skipping past the preformatted portion) */	
+	/*! A pointer to where the actual content of the message starts (skipping past the preformatted portion) */
 	char *content;
 
 	/* To maintain abi, only add new elements to the end of this struct and do not delete any elements */
 
 } switch_log_node_t;
 
-typedef switch_status_t (*switch_log_function_t)(const switch_log_node_t *node, switch_log_level_t level);
+typedef switch_status_t (*switch_log_function_t) (const switch_log_node_t *node, switch_log_level_t level);
 
 
 /*! 
@@ -97,7 +94,8 @@
   \param ... variable args
   \note there are channel macros to supply the first 4 parameters
 */
-SWITCH_DECLARE(void) switch_log_printf(switch_text_channel_t channel, const char *file, const char *func, int line, switch_log_level_t level, const char *fmt, ...) PRINTF_FUNCTION(6,7);
+SWITCH_DECLARE(void) switch_log_printf(switch_text_channel_t channel, const char *file, const char *func, int line,
+									   switch_log_level_t level, const char *fmt, ...) PRINTF_FUNCTION(6, 7);
 
 /*! 
   \brief Shut down  the logging engine
@@ -121,9 +119,7 @@
 
 ///\}
 SWITCH_END_EXTERN_C
-
 #endif
-
 /* For Emacs:
  * Local Variables:
  * mode:c

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_module_interfaces.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_module_interfaces.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_module_interfaces.h	Fri Mar 30 12:19:18 2007
@@ -42,10 +42,9 @@
 #include <switch.h>
 
 SWITCH_BEGIN_EXTERN_C
-
 /*! \brief A table of functions to execute at various states 
 */
-struct switch_state_handler_table {
+	struct switch_state_handler_table {
 	/*! executed when the state changes to init */
 	switch_state_handler_t on_init;
 	/*! executed when the state changes to ring */
@@ -54,13 +53,13 @@
 	switch_state_handler_t on_execute;
 	/*! executed when the state changes to hangup */
 	switch_state_handler_t on_hangup;
-	/*! executed when the state changes to loopback*/
+	/*! executed when the state changes to loopback */
 	switch_state_handler_t on_loopback;
-	/*! executed when the state changes to transmit*/
+	/*! executed when the state changes to transmit */
 	switch_state_handler_t on_transmit;
-	/*! executed when the state changes to hold*/
+	/*! executed when the state changes to hold */
 	switch_state_handler_t on_hold;
-	/*! executed when the state changes to hibernate*/
+	/*! executed when the state changes to hibernate */
 	switch_state_handler_t on_hibernate;
 };
 
@@ -75,133 +74,33 @@
 	switch_event_t *event;
 };
 
-/*! \brief Node in which to store custom outgoing channel callback hooks */
-struct switch_io_event_hook_outgoing_channel {
-	/*! the outgoing channel callback hook*/
-	switch_outgoing_channel_hook_t outgoing_channel;
-	struct switch_io_event_hook_outgoing_channel *next;
-};
-
-/*! \brief Node in which to store custom answer channel callback hooks */
-struct switch_io_event_hook_answer_channel {
-	/*! the answer channel callback hook*/
-	switch_answer_channel_hook_t answer_channel;
-	struct switch_io_event_hook_answer_channel *next;
-};
-
-/*! \brief Node in which to store custom receive message callback hooks */
-struct switch_io_event_hook_receive_message {
-	/*! the answer channel callback hook*/
-	switch_receive_message_hook_t receive_message;
-	struct switch_io_event_hook_receive_message *next;
-};
-
-/*! \brief Node in which to store custom receive message callback hooks */
-struct switch_io_event_hook_receive_event {
-	/*! the answer channel callback hook*/
-	switch_receive_event_hook_t receive_event;
-	struct switch_io_event_hook_receive_event *next;
-};
-
-/*! \brief Node in which to store custom read frame channel callback hooks */
-struct switch_io_event_hook_read_frame {
-	/*! the read frame channel callback hook*/
-	switch_read_frame_hook_t read_frame;
-	struct switch_io_event_hook_read_frame *next;
-};
-
-/*! \brief Node in which to store custom write_frame channel callback hooks */
-struct switch_io_event_hook_write_frame {
-	/*! the write_frame channel callback hook*/
-	switch_write_frame_hook_t write_frame;
-	struct switch_io_event_hook_write_frame *next;
-};
-
-/*! \brief Node in which to store custom kill channel callback hooks */
-struct switch_io_event_hook_kill_channel {
-	/*! the kill channel callback hook*/
-	switch_kill_channel_hook_t kill_channel;
-	struct switch_io_event_hook_kill_channel *next;
-};
-
-/*! \brief Node in which to store custom waitfor read channel callback hooks */
-struct switch_io_event_hook_waitfor_read {
-	/*! the waitfor read channel callback hook*/
-	switch_waitfor_read_hook_t waitfor_read;
-	struct switch_io_event_hook_waitfor_read *next;
-};
-
-/*! \brief Node in which to store custom waitfor write channel callback hooks */
-struct switch_io_event_hook_waitfor_write {
-	/*! the waitfor write channel callback hook*/
-	switch_waitfor_write_hook_t waitfor_write;
-	struct switch_io_event_hook_waitfor_write *next;
-};
-
-/*! \brief Node in which to store custom send dtmf channel callback hooks */
-struct switch_io_event_hook_send_dtmf {
-	/*! the send dtmf channel callback hook*/
-	switch_send_dtmf_hook_t send_dtmf;
-	struct switch_io_event_hook_send_dtmf *next;
-};
-
-/*! \brief Node in which to store state change callback hooks */
-struct switch_io_event_hook_state_change {
-	/*! the send dtmf channel callback hook*/
-	switch_state_change_hook_t state_change;
-	struct switch_io_event_hook_state_change *next;
-};
-
-/*! \brief A table of lists of io_event_hooks to store the event hooks associated with a session */
-struct switch_io_event_hooks {
-	/*! a list of outgoing channel hooks */
-	switch_io_event_hook_outgoing_channel_t *outgoing_channel;
-	/*! a list of answer channel hooks */
-	switch_io_event_hook_answer_channel_t *answer_channel;
-	/*! a list of receive message hooks */
-	switch_io_event_hook_receive_message_t *receive_message;
-	/*! a list of queue message hooks */
-	switch_io_event_hook_receive_event_t *receive_event;
-	/*! a list of read frame hooks */
-	switch_io_event_hook_read_frame_t *read_frame;
-	/*! a list of write frame hooks */
-	switch_io_event_hook_write_frame_t *write_frame;
-	/*! a list of kill channel hooks */
-	switch_io_event_hook_kill_channel_t *kill_channel;
-	/*! a list of wait for read hooks */
-	switch_io_event_hook_waitfor_read_t *waitfor_read;
-	/*! a list of wait for write hooks */
-	switch_io_event_hook_waitfor_write_t *waitfor_write;
-	/*! a list of send dtmf hooks */
-	switch_io_event_hook_send_dtmf_t *send_dtmf;
-	/*! a list of state change hooks */
-	switch_io_event_hook_state_change_t *state_change;
-};
+struct switch_io_event_hooks;
+
 
 /*! \brief A table of i/o routines that an endpoint interface can implement */
 struct switch_io_routines {
 	/*! creates an outgoing session from given session, caller profile */
-	switch_call_cause_t (*outgoing_channel)(switch_core_session_t *, switch_caller_profile_t *, switch_core_session_t **, switch_memory_pool_t **);
+	switch_call_cause_t (*outgoing_channel) (switch_core_session_t *, switch_caller_profile_t *, switch_core_session_t **, switch_memory_pool_t **);
 	/*! answers the given session's channel */
-	switch_status_t (*answer_channel)(switch_core_session_t *);
+	switch_status_t (*answer_channel) (switch_core_session_t *);
 	/*! read a frame from a session */
-	switch_status_t (*read_frame)(switch_core_session_t *, switch_frame_t **, int, switch_io_flag_t, int);
+	switch_status_t (*read_frame) (switch_core_session_t *, switch_frame_t **, int, switch_io_flag_t, int);
 	/*! write a frame to a session */
-	switch_status_t (*write_frame)(switch_core_session_t *, switch_frame_t *, int, switch_io_flag_t, int);
+	switch_status_t (*write_frame) (switch_core_session_t *, switch_frame_t *, int, switch_io_flag_t, int);
 	/*! send a kill signal to the session's channel */
-	switch_status_t (*kill_channel)(switch_core_session_t *, int);
+	switch_status_t (*kill_channel) (switch_core_session_t *, int);
 	/*! wait for the session's channel to be ready to read audio */
-	switch_status_t (*waitfor_read)(switch_core_session_t *, int, int);
+	switch_status_t (*waitfor_read) (switch_core_session_t *, int, int);
 	/*! wait for the session's channel to be ready to write audio */
-	switch_status_t (*waitfor_write)(switch_core_session_t *, int, int);
+	switch_status_t (*waitfor_write) (switch_core_session_t *, int, int);
 	/*! send a string of DTMF digits to a session's channel */
-	switch_status_t (*send_dtmf)(switch_core_session_t *, char *);
-	/*! receive a message from another session*/
-	switch_status_t (*receive_message)(switch_core_session_t *, switch_core_session_message_t *);
-	/*! queue a message for another session*/
-	switch_status_t (*receive_event)(switch_core_session_t *, switch_event_t *);
+	switch_status_t (*send_dtmf) (switch_core_session_t *, char *);
+	/*! receive a message from another session */
+	switch_status_t (*receive_message) (switch_core_session_t *, switch_core_session_message_t *);
+	/*! queue a message for another session */
+	switch_status_t (*receive_event) (switch_core_session_t *, switch_event_t *);
 	/*! change a sessions channel state */
-	switch_status_t (*state_change)(switch_core_session_t *);
+	switch_status_t (*state_change) (switch_core_session_t *);
 };
 
 /*! \brief Abstraction of an module endpoint interface
@@ -250,15 +149,15 @@
 	/*! the name of the interface */
 	const char *interface_name;
 	/*! function to allocate the timer */
-	switch_status_t (*timer_init)(switch_timer_t *);
+	switch_status_t (*timer_init) (switch_timer_t *);
 	/*! function to wait for one cycle to pass */
-	switch_status_t (*timer_next)(switch_timer_t *);
+	switch_status_t (*timer_next) (switch_timer_t *);
 	/*! function to step the timer one step */
-	switch_status_t (*timer_step)(switch_timer_t *);
+	switch_status_t (*timer_step) (switch_timer_t *);
 	/*! function to check if the current step has expired */
-	switch_status_t (*timer_check)(switch_timer_t *);
+	switch_status_t (*timer_check) (switch_timer_t *);
 	/*! function to deallocate the timer */
-	switch_status_t (*timer_destroy)(switch_timer_t *);
+	switch_status_t (*timer_destroy) (switch_timer_t *);
 	const struct switch_timer_interface *next;
 };
 
@@ -276,19 +175,19 @@
 	/*! the name of the interface */
 	const char *interface_name;
 	/*! function to open the file */
-	switch_status_t (*file_open)(switch_file_handle_t *, char *file_path);
+	switch_status_t (*file_open) (switch_file_handle_t *, char *file_path);
 	/*! function to close the file */
-	switch_status_t (*file_close)(switch_file_handle_t *);
+	switch_status_t (*file_close) (switch_file_handle_t *);
 	/*! function to read from the file */
-	switch_status_t (*file_read)(switch_file_handle_t *, void *data, switch_size_t *len);
+	switch_status_t (*file_read) (switch_file_handle_t *, void *data, switch_size_t *len);
 	/*! function to write from the file */
-	switch_status_t (*file_write)(switch_file_handle_t *, void *data, switch_size_t *len);
+	switch_status_t (*file_write) (switch_file_handle_t *, void *data, switch_size_t *len);
 	/*! function to seek to a certian position in the file */
-	switch_status_t (*file_seek)(switch_file_handle_t *, unsigned int *cur_pos, int64_t samples, int whence);
+	switch_status_t (*file_seek) (switch_file_handle_t *, unsigned int *cur_pos, int64_t samples, int whence);
 	/*! function to set meta data */
-	switch_status_t (*file_set_string)(switch_file_handle_t *fh, switch_audio_col_t col, const char *string);
+	switch_status_t (*file_set_string) (switch_file_handle_t *fh, switch_audio_col_t col, const char *string);
 	/*! function to get meta data */
-	switch_status_t (*file_get_string)(switch_file_handle_t *fh, switch_audio_col_t col, const char **string);
+	switch_status_t (*file_get_string) (switch_file_handle_t *fh, switch_audio_col_t col, const char **string);
 	/*! list of supported file extensions */
 	char **extens;
 	const struct switch_file_interface *next;
@@ -316,7 +215,7 @@
 	int seekable;
 	/*! the sample count of the file */
 	unsigned int sample_count;
-	/*! the speed of the file playback*/
+	/*! the speed of the file playback */
 	int speed;
 	/*! the handle's memory pool */
 	switch_memory_pool_t *memory_pool;
@@ -325,8 +224,8 @@
 	char *handler;
 	int64_t pos;
 	switch_buffer_t *audio_buffer;
-    uint32_t thresh;
-    uint32_t silence_hits;
+	uint32_t thresh;
+	uint32_t silence_hits;
 };
 
 /*! \brief Abstract interface to an asr module */
@@ -334,27 +233,23 @@
 	/*! the name of the interface */
 	const char *interface_name;
 	/*! function to open the asr interface */
-	switch_status_t (*asr_open)(switch_asr_handle_t *ah,
-								char *codec,
-								int rate,
-								char *dest,
-								switch_asr_flag_t *flags);
+	switch_status_t (*asr_open) (switch_asr_handle_t *ah, char *codec, int rate, char *dest, switch_asr_flag_t *flags);
 	/*! function to load a grammar to the asr interface */
-	switch_status_t (*asr_load_grammar)(switch_asr_handle_t *ah, char *grammar, char *path);
+	switch_status_t (*asr_load_grammar) (switch_asr_handle_t *ah, char *grammar, char *path);
 	/*! function to unload a grammar to the asr interface */
-	switch_status_t (*asr_unload_grammar)(switch_asr_handle_t *ah, char *grammar);
+	switch_status_t (*asr_unload_grammar) (switch_asr_handle_t *ah, char *grammar);
 	/*! function to close the asr interface */
-	switch_status_t (*asr_close)(switch_asr_handle_t *ah, switch_asr_flag_t *flags);
-	/*! function to feed audio to the ASR*/
-	switch_status_t (*asr_feed)(switch_asr_handle_t *ah, void *data, unsigned int len, switch_asr_flag_t *flags);
-	/*! function to resume the ASR*/
-	switch_status_t (*asr_resume)(switch_asr_handle_t *ah);
-	/*! function to pause the ASR*/
-	switch_status_t (*asr_pause)(switch_asr_handle_t *ah);
-	/*! function to read results from the ASR*/
-	switch_status_t (*asr_check_results)(switch_asr_handle_t *ah, switch_asr_flag_t *flags);
-	/*! 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_status_t (*asr_close) (switch_asr_handle_t *ah, switch_asr_flag_t *flags);
+	/*! function to feed audio to the ASR */
+	switch_status_t (*asr_feed) (switch_asr_handle_t *ah, void *data, unsigned int len, switch_asr_flag_t *flags);
+	/*! function to resume the ASR */
+	switch_status_t (*asr_resume) (switch_asr_handle_t *ah);
+	/*! function to pause the ASR */
+	switch_status_t (*asr_pause) (switch_asr_handle_t *ah);
+	/*! function to read results from the ASR */
+	switch_status_t (*asr_check_results) (switch_asr_handle_t *ah, switch_asr_flag_t *flags);
+	/*! 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);
 	const struct switch_asr_interface *next;
 };
 
@@ -364,11 +259,11 @@
 	const switch_asr_interface_t *asr_interface;
 	/*! flags to control behaviour */
 	uint32_t flags;
-	/*! The Name*/
+	/*! The Name */
 	char *name;
-	/*! The Codec*/
+	/*! The Codec */
 	char *codec;
-	/*! The Rate*/
+	/*! The Rate */
 	uint32_t rate;
 	char *grammar;
 	/*! the handle's memory pool */
@@ -382,24 +277,17 @@
 	/*! the name of the interface */
 	const char *interface_name;
 	/*! function to open the speech interface */
-	switch_status_t (*speech_open)(switch_speech_handle_t *sh,
-								 char *voice_name, 
-								 int rate,
-								 switch_speech_flag_t *flags);
+	switch_status_t (*speech_open) (switch_speech_handle_t *sh, char *voice_name, int rate, switch_speech_flag_t *flags);
 	/*! function to close the speech interface */
-	switch_status_t (*speech_close)(switch_speech_handle_t *, switch_speech_flag_t *flags);
-	/*! function to feed audio to the ASR*/
-	switch_status_t (*speech_feed_tts)(switch_speech_handle_t *sh, char *text, switch_speech_flag_t *flags);
-	/*! function to read audio from the TTS*/
-	switch_status_t (*speech_read_tts)(switch_speech_handle_t *sh,
-									 void *data,
-									 switch_size_t *datalen,
-									 uint32_t *rate,
-									 switch_speech_flag_t *flags);
-	void (*speech_flush_tts)(switch_speech_handle_t *sh);
-	void (*speech_text_param_tts)(switch_speech_handle_t *sh, char *param, char *val);
-	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_status_t (*speech_close) (switch_speech_handle_t *, switch_speech_flag_t *flags);
+	/*! function to feed audio to the ASR */
+	switch_status_t (*speech_feed_tts) (switch_speech_handle_t *sh, char *text, switch_speech_flag_t *flags);
+	/*! function to read audio from the TTS */
+	switch_status_t (*speech_read_tts) (switch_speech_handle_t *sh, void *data, switch_size_t *datalen, uint32_t * rate, switch_speech_flag_t *flags);
+	void (*speech_flush_tts) (switch_speech_handle_t *sh);
+	void (*speech_text_param_tts) (switch_speech_handle_t *sh, char *param, char *val);
+	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);
 
 	const struct switch_speech_interface *next;
 };
@@ -411,9 +299,9 @@
 	const switch_speech_interface_t *speech_interface;
 	/*! flags to control behaviour */
 	uint32_t flags;
-	/*! The Name*/
+	/*! The Name */
 	char *name;
-	/*! The Rate*/
+	/*! The Rate */
 	uint32_t rate;
 	uint32_t speed;
 	char voice[80];
@@ -429,7 +317,7 @@
 	/*! the name of the interface */
 	const char *interface_name;
 	/*! function to pass down to the module */
-    switch_say_callback_t say_function;
+	switch_say_callback_t say_function;
 	const struct switch_say_interface *next;
 };
 
@@ -438,7 +326,7 @@
 	/*! the name of the interface */
 	const char *interface_name;
 	/*! function to open the directory interface */
-	switch_status_t (*chat_send)(char *proto, char *from, char *to, char *subject, char *body, char *hint);
+	switch_status_t (*chat_send) (char *proto, char *from, char *to, char *subject, char *body, char *hint);
 	const struct switch_chat_interface *next;
 };
 
@@ -447,7 +335,7 @@
 	/*! the name of the interface */
 	const char *relative_oid;
 	/*! 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_status_t (*management_function) (char *relative_oid, switch_management_action_t action, char *data, switch_size_t datalen);
 	const struct switch_management_interface *next;
 };
 
@@ -456,16 +344,16 @@
 	/*! the name of the interface */
 	const char *interface_name;
 	/*! function to open the directory interface */
-	switch_status_t (*directory_open)(switch_directory_handle_t *dh, char *source, char *dsn, char *passwd);
+	switch_status_t (*directory_open) (switch_directory_handle_t *dh, char *source, char *dsn, char *passwd);
 	/*! function to close the directory interface */
-	switch_status_t (*directory_close)(switch_directory_handle_t *dh);
+	switch_status_t (*directory_close) (switch_directory_handle_t *dh);
 	/*! function to query the directory interface */
-	switch_status_t (*directory_query)(switch_directory_handle_t *dh, char *base, char *query);
+	switch_status_t (*directory_query) (switch_directory_handle_t *dh, char *base, char *query);
 	/*! function to advance to the next record */
-	switch_status_t (*directory_next)(switch_directory_handle_t *dh);
+	switch_status_t (*directory_next) (switch_directory_handle_t *dh);
 	/*! 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_status_t (*directory_next_pair) (switch_directory_handle_t *dh, char **var, char **val);
+
 	const struct switch_directory_interface *next;
 };
 
@@ -534,7 +422,7 @@
 	switch_codec_settings_t codec_settings;
 	/*! flags to modify behaviour */
 	uint32_t flags;
-	/*! the handle's memory pool*/
+	/*! the handle's memory pool */
 	switch_memory_pool_t *memory_pool;
 	/*! private data for the codec module to store handle specific info */
 	void *private_info;
@@ -569,29 +457,21 @@
 	/*! max number of frames to send in one network packet */
 	int max_frames_per_packet;
 	/*! function to initialize a codec handle using this implementation */
-	switch_status_t (*init)(switch_codec_t *, switch_codec_flag_t, const switch_codec_settings_t *codec_settings);
+	switch_status_t (*init) (switch_codec_t *, switch_codec_flag_t, const switch_codec_settings_t *codec_settings);
 	/*! function to encode raw data into encoded data */
-	switch_status_t (*encode)(switch_codec_t *codec,
-						 switch_codec_t *other_codec,
-						 void *decoded_data,
-						 uint32_t decoded_data_len,
-						 uint32_t decoded_rate,
-						 void *encoded_data,
-						 uint32_t *encoded_data_len,
-						 uint32_t *encoded_rate,
-						 unsigned int *flag);
+	switch_status_t (*encode) (switch_codec_t *codec,
+							   switch_codec_t *other_codec,
+							   void *decoded_data,
+							   uint32_t decoded_data_len,
+							   uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate, unsigned int *flag);
 	/*! function to decode encoded data into raw data */
-	switch_status_t (*decode)(switch_codec_t *codec,
-						 switch_codec_t *other_codec,
-						 void *encoded_data,
-						 uint32_t encoded_data_len,
-						 uint32_t encoded_rate,
-						 void *decoded_data,
-						 uint32_t *decoded_data_len,
-						 uint32_t *decoded_rate,
-						 unsigned int *flag);
+	switch_status_t (*decode) (switch_codec_t *codec,
+							   switch_codec_t *other_codec,
+							   void *encoded_data,
+							   uint32_t encoded_data_len,
+							   uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate, unsigned int *flag);
 	/*! deinitalize a codec handle using this implementation */
-	switch_status_t (*destroy)(switch_codec_t *);
+	switch_status_t (*destroy) (switch_codec_t *);
 	const struct switch_codec_implementation *next;
 };
 
@@ -635,9 +515,7 @@
 };
 
 SWITCH_END_EXTERN_C
-
 #endif
-
 /* For Emacs:
  * Local Variables:
  * mode:c

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_platform.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_platform.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_platform.h	Fri Mar 30 12:19:18 2007
@@ -35,23 +35,17 @@
 #define SWITCH_PLATFORM_H
 
 SWITCH_BEGIN_EXTERN_C
-
 #ifdef __ICC
 #pragma warning (disable:810 869 981 279 1469 188)
 #endif
-
 #include <stdio.h>
-
+#define SWITCH_VA_NONE "%s", ""
 #ifdef _MSC_VER
 #define __SWITCH_FUNC__ __FUNCTION__
 #else
 #define __SWITCH_FUNC__ (const char *)__func__
 #endif
-
-
 #ifdef _MSC_VER
-
-
 /* disable the following warnings 
  * C4100: The formal parameter is not referenced in the body of the function. The unreferenced parameter is ignored. 
  * C4200: Non standard extension C zero sized array
@@ -65,7 +59,11 @@
  */
 #pragma warning(disable:4100 4200 4204 4706 4819 4132 4510 4512 4610 4996)
 
-#if (_MSC_VER >= 1400) // VC8+
+#pragma include_alias(<libteletone.h>,				<../../libs/libteletone/src/libteletone.h>)
+#pragma include_alias(<libteletone_generate.h>,		<../../libs/libteletone/src/libteletone_generate.h>)
+#pragma include_alias(<libteletone_detect.h>,		<../../libs/libteletone/src/libteletone_detect.h>)
+
+#if (_MSC_VER >= 1400)			// VC8+
 #ifndef _CRT_SECURE_NO_DEPRECATE
 #define _CRT_SECURE_NO_DEPRECATE
 #endif
@@ -73,30 +71,27 @@
 #define _CRT_NONSTDC_NO_DEPRECATE
 #endif
 #endif // VC8+
-
 #if  _MSC_VER < 1300
 #ifndef __FUNCTION__
 #define __FUNCTION__ ""
 #endif
 #endif
-
 #undef inline
 #define inline __inline
-
 #ifndef uint32_t
-typedef unsigned __int8		uint8_t;
-typedef unsigned __int16	uint16_t;
-typedef unsigned __int32	uint32_t;
-typedef unsigned __int64    uint64_t;
-typedef __int8		int8_t;
-typedef __int16		int16_t;
-typedef __int32		int32_t;
-typedef __int64		int64_t;
-typedef unsigned long	in_addr_t;
-#endif
-typedef  int         pid_t;
-typedef  int         uid_t;
-typedef  int         gid_t;
+typedef unsigned __int8 uint8_t;
+typedef unsigned __int16 uint16_t;
+typedef unsigned __int32 uint32_t;
+typedef unsigned __int64 uint64_t;
+typedef __int8 int8_t;
+typedef __int16 int16_t;
+typedef __int32 int32_t;
+typedef __int64 int64_t;
+typedef unsigned long in_addr_t;
+#endif
+typedef int pid_t;
+typedef int uid_t;
+typedef int gid_t;
 #define PACKED
 #include <io.h>
 #define strcasecmp(s1, s2) stricmp(s1, s2)
@@ -116,7 +111,6 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 #endif // _MSC_VER
-
 #ifndef __LITTLE_ENDIAN
 #define __LITTLE_ENDIAN 1234
 #endif
@@ -130,9 +124,7 @@
 #define __BYTE_ORDER __LITTLE_ENDIAN
 #endif
 #endif
-
 #ifdef WIN32
-
 #if defined(SWITCH_CORE_DECLARE_STATIC)
 #define SWITCH_DECLARE(type)			type __stdcall
 #define SWITCH_DECLARE_NONSTD(type)		type __cdecl
@@ -146,7 +138,6 @@
 #define SWITCH_DECLARE_NONSTD(type)		__declspec(dllimport) type __cdecl
 #define SWITCH_DECLARE_DATA				__declspec(dllimport)
 #endif
-
 #if defined(SWITCH_MOD_DECLARE_STATIC)
 #define SWITCH_MOD_DECLARE(type)		type __cdecl
 #elif defined(MOD_EXPORTS)
@@ -169,35 +160,32 @@
 #define SWITCH_DECLARE_DATA
 #define SWITCH_THREAD_FUNC
 #endif
-
 #ifdef DOXYGEN
 #define DoxyDefine(x) x
 #else
 #define DoxyDefine(x)
 #endif
-
 #if __GNUC__ >= 3
 #define PRINTF_FUNCTION(fmtstr,vars) __attribute__((format(printf,fmtstr,vars)))
 #else
 #define PRINTF_FUNCTION(fmtstr,vars)
 #endif
-
 #ifdef SWITCH_INT32
-typedef SWITCH_INT32 switch_int32_t;
+	typedef SWITCH_INT32 switch_int32_t;
 #else
-typedef int32_t switch_int32_t;
+	typedef int32_t switch_int32_t;
 #endif
 
 #ifdef SWITCH_SIZE_T
-typedef  SWITCH_SIZE_T  switch_size_t;
+typedef SWITCH_SIZE_T switch_size_t;
 #else
-typedef  uintptr_t  switch_size_t;
+typedef uintptr_t switch_size_t;
 #endif
 
 #ifdef SWITCH_SSIZE_T
-typedef  SWITCH_SSIZE_T   switch_ssize_t;
+typedef SWITCH_SSIZE_T switch_ssize_t;
 #else
-typedef  intptr_t	switch_ssize_t;
+typedef intptr_t switch_ssize_t;
 #endif
 
 #ifdef WIN32
@@ -213,12 +201,6 @@
 #define SWITCH_INT64_T_FMT          "I64d"
 #define SWITCH_UINT64_T_FMT         "I64u"
 
-#ifdef _USE_32BIT_TIME_T
-#define TIME_T_FMT "d"
-#else
-#define TIME_T_FMT SWITCH_INT64_T_FMT
-#endif
-
 #else
 #ifndef SWITCH_SSIZE_T_FMT
 #define SWITCH_SSIZE_T_FMT          (sizeof (switch_ssize_t) == sizeof (long) ? "ld" : sizeof (switch_ssize_t) == sizeof (int) ? "d" : "lld")
@@ -245,7 +227,6 @@
 #define SWITCH_TIME_T_FMT SWITCH_INT64_T_FMT
 
 SWITCH_END_EXTERN_C
-
 /* these includes must be outside the extern "C" block on windows or it will break compatibility with c++ modules*/
 #ifdef WIN32
 /* Has windows.h already been included?  If so, our preferences don't matter,
@@ -257,7 +238,6 @@
 #define WIN32_LEAN_AND_MEAN
 #endif
 #ifndef _WIN32_WINNT
-
 /* Restrict the server to a subset of Windows NT 4.0 header files by default
  */
 #define _WIN32_WINNT 0x0400
@@ -288,19 +268,13 @@
 #endif /* !_WINDOWS_ */
 #include <process.h>
 #endif
-
 #endif
-
-
 #ifndef FALSE
 #define FALSE 0
 #endif
 #ifndef TRUE
 #define TRUE (!FALSE)
 #endif
-
-
-
 /* For Emacs:
  * Local Variables:
  * mode:c

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_regex.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_regex.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_regex.h	Fri Mar 30 12:19:18 2007
@@ -35,32 +35,23 @@
 #define SWITCH_REGEX_H
 
 SWITCH_BEGIN_EXTERN_C
-
 /**
  * @defgroup switch_regex
  * @ingroup FREESWITCH
  * @{
  */
+	typedef struct real_pcre switch_regex_t;
 
-typedef struct real_pcre switch_regex_t;
-
-SWITCH_DECLARE(switch_regex_t *) switch_regex_compile(const char *pattern,
-													  int options,
-													  const char **errorptr,
-													  int *erroroffset,
+SWITCH_DECLARE(switch_regex_t *) switch_regex_compile(const char *pattern, int options, const char **errorptr, int *erroroffset,
 													  const unsigned char *tables);
 
-SWITCH_DECLARE(int) switch_regex_copy_substring(const char *subject,
-												int *ovector,
-												int stringcount,
-												int stringnumber,
-												char *buffer,
-												int size);
+SWITCH_DECLARE(int) switch_regex_copy_substring(const char *subject, int *ovector, int stringcount, int stringnumber, char *buffer, int size);
 
 SWITCH_DECLARE(void) switch_regex_free(void *data);
 
 SWITCH_DECLARE(int) switch_regex_perform(char *field, char *expression, switch_regex_t **new_re, int *ovector, uint32_t olen);
-SWITCH_DECLARE(void) switch_perform_substitution(switch_regex_t *re, int match_count, char *data, char *field_data, char *substituted, uint32_t len, int *ovector);
+SWITCH_DECLARE(void) switch_perform_substitution(switch_regex_t *re, int match_count, char *data, char *field_data,
+												 char *substituted, uint32_t len, int *ovector);
 
 /*!
  \brief Function to evaluate an expression against a string
@@ -78,9 +69,7 @@
 /** @} */
 
 SWITCH_END_EXTERN_C
-
 #endif
-
 /* For Emacs:
  * Local Variables:
  * mode:c

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_resample.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_resample.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_resample.h	Fri Mar 30 12:19:18 2007
@@ -45,15 +45,13 @@
 
 #include <switch.h>
 SWITCH_BEGIN_EXTERN_C
-
 /*!
   \defgroup resamp Audio Resample Functions
   \ingroup core1
   \{ 
 */
-
 /*! \brief An audio resampling handle */
-typedef struct {
+	typedef struct {
 	/*! a pointer to store the resampler object */
 	void *resampler;
 	/*! the rate to resample from in hz */
@@ -87,11 +85,7 @@
   \return SWITCH_STATUS_SUCCESS if the handle was created
  */
 SWITCH_DECLARE(switch_status_t) switch_resample_create(switch_audio_resampler_t **new_resampler,
-													 int from_rate,
-													 switch_size_t from_size,
-													 int to_rate,
-													 uint32_t to_size,
-													 switch_memory_pool_t *pool);
+													   int from_rate, switch_size_t from_size, int to_rate, uint32_t to_size, switch_memory_pool_t *pool);
 
 /*!
   \brief Destroy an existing resampler handle
@@ -172,9 +166,7 @@
 ///\}
 
 SWITCH_END_EXTERN_C
-
 #endif
-
 /* For Emacs:
  * Local Variables:
  * mode:c

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_rtp.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_rtp.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_rtp.h	Fri Mar 30 12:19:18 2007
@@ -39,17 +39,12 @@
 #define SWITCH_RTP_H
 
 SWITCH_BEGIN_EXTERN_C
-
 #define SWITCH_RTP_MAX_BUF_LEN 16384
-
 ///\defgroup rtp RTP (RealTime Transport Protocol)
 ///\ingroup core1
 ///\{
-typedef void (*switch_rtp_invalid_handler_t)(switch_rtp_t *rtp_session,
-										   switch_socket_t *sock,
-										   void *data,
-										   switch_size_t datalen,
-										   switch_sockaddr_t *from_addr);
+typedef void (*switch_rtp_invalid_handler_t) (switch_rtp_t *rtp_session,
+											  switch_socket_t * sock, void *data, switch_size_t datalen, switch_sockaddr_t * from_addr);
 
 /*! 
   \brief Initilize the RTP System
@@ -77,15 +72,12 @@
   \param pool a memory pool to use for the session
   \return the new RTP session or NULL on failure
 */
-SWITCH_DECLARE(switch_status_t)switch_rtp_create(switch_rtp_t **new_rtp_session,
-												 switch_payload_t payload,
-												 uint32_t samples_per_interval,
-												 uint32_t ms_per_packet,
-												 switch_rtp_flag_t flags,
-												 char *crypto_key,
-												 char *timer_name,
-												 const char **err,
-												 switch_memory_pool_t *pool);
+SWITCH_DECLARE(switch_status_t) switch_rtp_create(switch_rtp_t **new_rtp_session,
+												  switch_payload_t payload,
+												  uint32_t samples_per_interval,
+												  uint32_t ms_per_packet,
+												  switch_rtp_flag_t flags, char *crypto_key, char *timer_name, const char **err,
+												  switch_memory_pool_t *pool);
 
 
 /*!
@@ -104,18 +96,14 @@
   \param pool a memory pool to use for the session
   \return the new RTP session or NULL on failure
 */
-SWITCH_DECLARE(switch_rtp_t *)switch_rtp_new(char *rx_host,
-											 switch_port_t rx_port,
-											 char *tx_host,
-											 switch_port_t tx_port,
-											 switch_payload_t payload,
-											 uint32_t samples_per_interval,
-											 uint32_t ms_per_packet,
-											 switch_rtp_flag_t flags,
-											 char *crypto_key,
-											 char *timer_name,
-											 const char **err,
-											 switch_memory_pool_t *pool);
+SWITCH_DECLARE(switch_rtp_t *) switch_rtp_new(char *rx_host,
+											  switch_port_t rx_port,
+											  char *tx_host,
+											  switch_port_t tx_port,
+											  switch_payload_t payload,
+											  uint32_t samples_per_interval,
+											  uint32_t ms_per_packet,
+											  switch_rtp_flag_t flags, char *crypto_key, char *timer_name, const char **err, switch_memory_pool_t *pool);
 
 
 /*! 
@@ -189,7 +177,7 @@
   \param rtp_session the RTP session to retrieve the socket from
   \return the socket from the RTP session
 */
-SWITCH_DECLARE(switch_socket_t *)switch_rtp_get_rtp_socket(switch_rtp_t *rtp_session);
+SWITCH_DECLARE(switch_socket_t *) switch_rtp_get_rtp_socket(switch_rtp_t *rtp_session);
 
 /*! 
   \brief Set the default samples per interval for a given RTP session
@@ -237,7 +225,8 @@
   \param flags flags
   \return the number of bytes read
 */
-SWITCH_DECLARE(switch_status_t) switch_rtp_read(switch_rtp_t *rtp_session, void *data, uint32_t *datalen, switch_payload_t *payload_type, switch_frame_flag_t *flags);
+SWITCH_DECLARE(switch_status_t) switch_rtp_read(switch_rtp_t *rtp_session, void *data, uint32_t * datalen,
+												switch_payload_t *payload_type, switch_frame_flag_t *flags);
 
 /*! 
   \brief Queue RFC2833 DTMF data into an RTP Session
@@ -281,10 +270,7 @@
   \return the number of bytes read
 */
 SWITCH_DECLARE(switch_status_t) switch_rtp_zerocopy_read(switch_rtp_t *rtp_session,
-														 void **data,
-														 uint32_t *datalen,
-														 switch_payload_t *payload_type,
-														 switch_frame_flag_t *flags);
+														 void **data, uint32_t * datalen, switch_payload_t *payload_type, switch_frame_flag_t *flags);
 
 /*! 
   \brief Read data from a given RTP session without copying
@@ -313,7 +299,8 @@
   \param flags flags for control
   \return SWITCH_STAUTS_SUCCESS on success
 */
-SWITCH_DECLARE(switch_status_t) switch_rtp_enable_vad(switch_rtp_t *rtp_session, switch_core_session_t *session, switch_codec_t *codec, switch_vad_flag_t flags);
+SWITCH_DECLARE(switch_status_t) switch_rtp_enable_vad(switch_rtp_t *rtp_session, switch_core_session_t *session,
+													  switch_codec_t *codec, switch_vad_flag_t flags);
 
 /*!
   \brief Disable VAD on an RTP Session
@@ -347,12 +334,7 @@
 SWITCH_DECLARE(int) switch_rtp_write_manual(switch_rtp_t *rtp_session,
 											void *data,
 											uint16_t datalen,
-											uint8_t m,
-											switch_payload_t payload,
-											uint32_t ts,
-											uint16_t mseq,
-											uint32_t ssrc,
-											switch_frame_flag_t *flags);
+											uint8_t m, switch_payload_t payload, uint32_t ts, uint16_t mseq, uint32_t ssrc, switch_frame_flag_t *flags);
 
 /*! 
   \brief Retrieve the SSRC from a given RTP session
@@ -387,16 +369,14 @@
   \param rtp_session the RTP session to retrieve the data from
   \return the pointer to the private data
 */
-SWITCH_DECLARE(void *)switch_rtp_get_private(switch_rtp_t *rtp_session);
+SWITCH_DECLARE(void *) switch_rtp_get_private(switch_rtp_t *rtp_session);
 
 /*!
   \}
 */
 
 SWITCH_END_EXTERN_C
-
 #endif
-
 /* For Emacs:
  * Local Variables:
  * mode:c

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_sqlite.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_sqlite.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_sqlite.h	Fri Mar 30 12:19:18 2007
@@ -36,26 +36,22 @@
 #define SWITCH_SQLITE_H
 
 SWITCH_BEGIN_EXTERN_C
-
 #include <sqlite3.h>
-
 /**
  * @defgroup switch_sqlite_top Brought To You By SQLite
  * @ingroup FREESWITCH
  * @{
  */
-
 /**
  * @defgroup switch_sqlite Database Routines
  * @ingroup switch_sqlite_top 
  * @{
  */
-
 /**
  * Each open sqlite database is represented by an instance of the
  * following opaque structure.
 */
-typedef sqlite3 switch_core_db_t;
+	typedef sqlite3 switch_core_db_t;
 typedef sqlite3_stmt switch_core_db_stmt_t;
 /**
  * Aggregate functions use the following routine to allocate
@@ -67,17 +63,15 @@
  *
  * The buffer allocated is freed automatically by SQLite.
  */
-DoxyDefine(void *switch_core_db_aggregate_context(sqlite3_context*, int nBytes);)
+DoxyDefine(void *switch_core_db_aggregate_context(sqlite3_context *, int nBytes);)
 #define switch_core_db_aggregate_context sqlite3_aggregate_context
-
 /**
  * /return the number of calls to xStep for a particular
  * aggregate function instance.  The current call to xStep counts so this
  * routine always returns at least 1.
  */
-DoxyDefine(int switch_core_db_aggregate_count(sqlite3_context*);)
+DoxyDefine(int switch_core_db_aggregate_count(sqlite3_context *);)
 #define switch_core_db_aggregate_count sqlite3_aggregate_count
-
 /**
  * In the SQL strings input to switch_core_db_prepare(),
  * one or more literals can be replace by parameters "?" or ":AAA" or
@@ -106,9 +100,8 @@
  * an switch_core_db_prepare() or sqlite3_reset().  Unbound parameterss are
  * interpreted as NULL.
  */
-DoxyDefine(int switch_core_db_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));)
+DoxyDefine(int switch_core_db_bind_blob(sqlite3_stmt *, int, const void *, int n, void (*)(void *));)
 #define switch_core_db_bind_blob sqlite3_bind_blob
-
 /**
  * In the SQL strings input to switch_core_db_prepare(),
  * one or more literals can be replace by parameters "?" or ":AAA" or
@@ -129,9 +122,8 @@
  * an switch_core_db_prepare() or sqlite3_reset().  Unbound parameterss are
  * interpreted as NULL.
  */
-DoxyDefine(int switch_core_db_bind_double(sqlite3_stmt*, int, double);)
+DoxyDefine(int switch_core_db_bind_double(sqlite3_stmt *, int, double);)
 #define switch_core_db_bind_double sqlite3_bind_double
-
 /**
  * In the SQL strings input to switch_core_db_prepare(),
  * one or more literals can be replace by parameters "?" or ":AAA" or
@@ -152,9 +144,8 @@
  * an switch_core_db_prepare() or sqlite3_reset().  Unbound parameterss are
  * interpreted as NULL.
  */
-DoxyDefine(int switch_core_db_bind_int(sqlite3_stmt*, int, int);)
+DoxyDefine(int switch_core_db_bind_int(sqlite3_stmt *, int, int);)
 #define switch_core_db_bind_int sqlite3_bind_int
-
 /**
  * In the SQL strings input to switch_core_db_prepare(),
  * one or more literals can be replace by parameters "?" or ":AAA" or
@@ -175,9 +166,8 @@
  * an switch_core_db_prepare() or sqlite3_reset().  Unbound parameterss are
  * interpreted as NULL.
  */
-DoxyDefine(int switch_core_db_bind_int64(sqlite3_stmt*, int, sqlite_int64);)
+DoxyDefine(int switch_core_db_bind_int64(sqlite3_stmt *, int, sqlite_int64);)
 #define switch_core_db_bind_int64 sqlite3_bind_int64
-
 /**
  * In the SQL strings input to switch_core_db_prepare(),
  * one or more literals can be replace by parameters "?" or ":AAA" or
@@ -198,9 +188,8 @@
  * an switch_core_db_prepare() or sqlite3_reset().  Unbound parameterss are
  * interpreted as NULL.
  */
-DoxyDefine(int switch_core_db_bind_null(sqlite3_stmt*, int);)
+DoxyDefine(int switch_core_db_bind_null(sqlite3_stmt *, int);)
 #define switch_core_db_bind_null sqlite3_bind_null
-
 /**
  * In the SQL strings input to switch_core_db_prepare(),
  * one or more literals can be replace by parameters "?" or ":AAA" or
@@ -229,9 +218,8 @@
  * an switch_core_db_prepare() or sqlite3_reset().  Unbound parameterss are
  * interpreted as NULL.
  */
-DoxyDefine(int switch_core_db_bind_text(sqlite3_stmt*, int, const char*, int n, void(*)(void*));)
+DoxyDefine(int switch_core_db_bind_text(sqlite3_stmt *, int, const char *, int n, void (*)(void *));)
 #define switch_core_db_bind_text sqlite3_bind_text
-
 /**
  * In the SQL strings input to switch_core_db_prepare(),
  * one or more literals can be replace by parameters "?" or ":AAA" or
@@ -260,9 +248,8 @@
  * an switch_core_db_prepare() or sqlite3_reset().  Unbound parameterss are
  * interpreted as NULL.
  */
-DoxyDefine(int switch_core_db_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));)
+DoxyDefine(int switch_core_db_bind_text16(sqlite3_stmt *, int, const void *, int, void (*)(void *));)
 #define switch_core_db_bind_text16 sqlite3_bind_text16
-
 /**
  * In the SQL strings input to switch_core_db_prepare(),
  * one or more literals can be replace by parameters "?" or ":AAA" or
@@ -283,24 +270,21 @@
  * an switch_core_db_prepare() or sqlite3_reset().  Unbound parameterss are
  * interpreted as NULL.
  */
-DoxyDefine(int switch_core_db_bind_value(sqlite3_stmt*, int, const sqlite3_value*);)
+DoxyDefine(int switch_core_db_bind_value(sqlite3_stmt *, int, const sqlite3_value *);)
 #define switch_core_db_bind_value sqlite3_bind_value
-
 /**
  * @return The number of parameters in a compiled SQL statement.
  * @remark This routine was added to support DBD::SQLite.
  */
-DoxyDefine(int switch_core_db_bind_parameter_count(sqlite3_stmt*);)
+DoxyDefine(int switch_core_db_bind_parameter_count(sqlite3_stmt *);)
 #define switch_core_db_bind_parameter_count sqlite3_bind_parameter_count
-
 /**
  * @return the index of a parameter with the given name.  If no parameter with the 
  * given name is found, return 0.
  * @remark The name must match exactly.
  */
-DoxyDefine(int switch_core_db_bind_parameter_index(sqlite3_stmt*, const char *zName);)
+DoxyDefine(int switch_core_db_bind_parameter_index(sqlite3_stmt *, const char *zName);)
 #define switch_core_db_bind_parameter_index sqlite3_bind_parameter_index
-
 /**
  * @return the name of the i-th parameter.  
  * @remark Ordinary parameters "?" are
@@ -308,9 +292,8 @@
  * $VVV the complete text of the parameter name is returned, including
  * the initial ":" or "$".  NULL is returned if the index is out of range.
  */
-DoxyDefine(const char *switch_core_db_bind_parameter_name(sqlite3_stmt*, int);)
+DoxyDefine(const char *switch_core_db_bind_parameter_name(sqlite3_stmt *, int);)
 #define switch_core_db_bind_parameter_name sqlite3_bind_parameter_name
-
 /**
  * This routine identifies a callback function that is invoked
  * whenever an attempt is made to open a database table that is
@@ -333,9 +316,8 @@
  * data structures out from under the executing query and will 
  * probably result in a coredump.
  */
-DoxyDefine(int switch_core_db_busy_handler(switch_core_db*, int(*)(void*,int), void*);)
+DoxyDefine(int switch_core_db_busy_handler(switch_core_db *, int (*)(void *, int), void *);)
 #define switch_core_db_busy_handler sqlite3_busy_handler
-
 /**
  * This routine sets a busy handler that sleeps for a while when a
  * table is locked.  The handler will sleep multiple times until 
@@ -346,9 +328,8 @@
  * Calling this routine with an argument less than or equal to zero
  * turns off all busy handlers.
  */
-DoxyDefine(int switch_core_db_busy_timeout(switch_core_db*, int ms);)
+DoxyDefine(int switch_core_db_busy_timeout(switch_core_db *, int ms);)
 #define switch_core_db_busy_timeout sqlite3_busy_timeout
-
 /**
  * This function returns the number of database rows that were changed
  * (or inserted or deleted) by the most recent called sqlite3_exec().
@@ -369,9 +350,8 @@
  * table. To get an accurate count of the number of rows deleted, use
  * "DELETE FROM table WHERE 1" instead.
  */
-DoxyDefine(int switch_core_db_changes(switch_core_db*);)
+DoxyDefine(int switch_core_db_changes(switch_core_db *);)
 #define switch_core_db_changes sqlite3_changes
-
 /**
  * A function to close the database.
  *
@@ -385,7 +365,6 @@
  */
 DoxyDefine(int switch_core_db_close(switch_core_db *);)
 #define switch_core_db_close sqlite3_close
-
 /**
  * To avoid having to register all collation sequences before a database
  * can be used, a single callback function may be registered with the
@@ -405,13 +384,9 @@
  * The collation sequence is returned to SQLite by a collation-needed
  * callback using the sqlite3_create_collation() API, described above.
  */
-DoxyDefine(int switch_core_db_collation_needed(
-  switch_core_db*, 
-  void*, 
-  void(*)(void*,switch_core_db*,int eTextRep,const char*)
-);)
+DoxyDefine(int switch_core_db_collation_needed(switch_core_db *, void *, void (*)(void *, switch_core_db *, int eTextRep, const char *)
+		   );)
 #define switch_core_db_collation_needed sqlite3_collation_needed
-
 /**
  * The next group of routines returns information about the information
  * in a single column of the current result row of a query.
@@ -453,9 +428,8 @@
  *
  * @return the value of a BLOB.
  */
-DoxyDefine(const void *switch_core_db_column_blob(sqlite3_stmt *stmt, int iCol);)
+DoxyDefine(const void *switch_core_db_column_blob(sqlite3_stmt * stmt, int iCol);)
 #define switch_core_db_column_blob sqlite3_column_blob
-
 /**
  * The next group of routines returns information about the information
  * in a single column of the current result row of a query.  In every
@@ -497,9 +471,8 @@
  * TEXT value represented as UTF-8.  The "\000" terminator is included in the 
  * byte count for TEXT values.
  */
-DoxyDefine(int switch_core_db_column_bytes(sqlite3_stmt*, int iCol);)
+DoxyDefine(int switch_core_db_column_bytes(sqlite3_stmt *, int iCol);)
 #define switch_core_db_column_bytes sqlite3_column_bytes
-
 /**
  * The next group of routines returns information about the information
  * in a single column of the current result row of a query.  In every
@@ -541,9 +514,8 @@
  * TEXT value represented as UTF-16.  The "\u0000" terminator is included in 
  * the byte count for TEXT values.
  */
-DoxyDefine(int switch_core_db_column_bytes16(sqlite3_stmt*, int iCol);)
+DoxyDefine(int switch_core_db_column_bytes16(sqlite3_stmt *, int iCol);)
 #define switch_core_db_column_bytes16 sqlite3_column_bytes16
-
 /**
  * The next group of routines returns information about the information
  * in a single column of the current result row of a query.  In every
@@ -583,9 +555,8 @@
  *
  *  Return a FLOAT value.
  */
-DoxyDefine(double switch_core_db_column_double(sqlite3_stmt*, int iCol);)
+DoxyDefine(double switch_core_db_column_double(sqlite3_stmt *, int iCol);)
 #define switch_core_db_column_double sqlite3_column_double
-
 /**
  * The next group of routines returns information about the information
  * in a single column of the current result row of a query.  In every
@@ -626,9 +597,8 @@
  *  Return an INTEGER value in the host computer's native integer representation.  
  *  This might be either a 32- or 64-bit integer depending on the host.
  */
-DoxyDefine(int switch_core_db_column_int(sqlite3_stmt*, int iCol);)
+DoxyDefine(int switch_core_db_column_int(sqlite3_stmt *, int iCol);)
 #define switch_core_db_column_int sqlite3_column_int
-
 /**
  * The next group of routines returns information about the information
  * in a single column of the current result row of a query.  In every
@@ -668,9 +638,8 @@
  *
  * Return an INTEGER value as a 64-bit signed integer.
  */
-DoxyDefine(sqlite_int64 switch_core_db_column_int64(sqlite3_stmt*, int iCol);)
+	DoxyDefine(sqlite_int64 switch_core_db_column_int64(sqlite3_stmt *, int iCol);)
 #define switch_core_db_column_int64 sqlite3_column_int64
-
 /**
  * The next group of routines returns information about the information
  * in a single column of the current result row of a query.  In every
@@ -710,9 +679,8 @@
  *
  *  Return the value as UTF-8 text.
  */
-DoxyDefine(const unsigned char *switch_core_db_column_text(sqlite3_stmt*, int iCol);)
+DoxyDefine(const unsigned char *switch_core_db_column_text(sqlite3_stmt *, int iCol);)
 #define switch_core_db_column_text sqlite3_column_text
-
 /**
  * The next group of routines returns information about the information
  * in a single column of the current result row of a query.  In every
@@ -752,9 +720,8 @@
  *
  * Return the value as UTF-16 text.
  */
-DoxyDefine(const void *switch_core_db_column_text16(sqlite3_stmt*, int iCol);)
+DoxyDefine(const void *switch_core_db_column_text16(sqlite3_stmt *, int iCol);)
 #define switch_core_db_column_text16 sqlite3_column_text16
-
 /**
  * The next group of routines returns information about the information
  * in a single column of the current result row of a query.  In every
@@ -795,25 +762,22 @@
  * ReturnS the datatype of the result.  This is one of
  * SQLITE_INTEGER, SQLITE_FLOAT, SQLITE_TEXT, SQLITE_BLOB, or SQLITE_NULL.
  */
-DoxyDefine(int switch_core_db_column_type(sqlite3_stmt*, int iCol);)
+DoxyDefine(int switch_core_db_column_type(sqlite3_stmt *, int iCol);)
 #define switch_core_db_column_type sqlite3_column_type
-
 /**
  * The first parameter is a compiled SQL statement. This function returns
  * the column heading for the Nth column of that statement, where N is the
  * second function parameter.  The string returned is UTF-8.
  */
-DoxyDefine(const char *switch_core_db_column_name(sqlite3_stmt*,int);)
+DoxyDefine(const char *switch_core_db_column_name(sqlite3_stmt *, int);)
 #define switch_core_db_column_name sqlite3_column_name
-
 /**
  * Return the number of columns in the result set returned by the compiled
  * SQL statement. This routine returns 0 if pStmt is an SQL statement
  * that does not return data (for example an UPDATE).
  */
-DoxyDefine(int switch_core_db_column_count(sqlite3_stmt *pStmt);)
+DoxyDefine(int switch_core_db_column_count(sqlite3_stmt * pStmt);)
 #define switch_core_db_column_count sqlite3_column_count
-
 /**
  * The first parameter is a compiled SQL statement. If this statement
  * is a SELECT statement, the Nth column of the returned result set 
@@ -834,7 +798,6 @@
  */
 DoxyDefine(const char *switch_core_db_column_decltype(sqlite3_stmt *, int i);)
 #define switch_core_db_column_decltype sqlite3_column_decltype
-
 /**
  * The first parameter is a compiled SQL statement. If this statement
  * is a SELECT statement, the Nth column of the returned result set 
@@ -853,9 +816,8 @@
  * result column (i==1), and a NULL pointer for the first result column
  * (i==0).
  */
-DoxyDefine(const void *switch_core_db_column_decltype16(sqlite3_stmt*,int);)
+DoxyDefine(const void *switch_core_db_column_decltype16(sqlite3_stmt *, int);)
 #define switch_core_db_column_decltype16 sqlite3_column_decltype16
-
 /**
  * Register a callback function to be invoked whenever a new transaction
  * is committed.  The pArg argument is passed through to the callback.
@@ -869,9 +831,8 @@
  *
  ****** THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ******
  */
-DoxyDefine(void *switch_core_db_commit_hook(switch_core_db*, int(*)(void*), void*);)
+DoxyDefine(void *switch_core_db_commit_hook(switch_core_db *, int (*)(void *), void *);)
 #define switch_core_db_commit_hook sqlite3_commit_hook
-
 /**
  * This functions return true if the given input string comprises
  * one or more complete SQL statements. The parameter must be a nul-terminated 
@@ -883,7 +844,6 @@
  */
 DoxyDefine(int switch_core_db_complete(const char *sql);)
 #define switch_core_db_complete sqlite3_complete
-
 /**
  * This function is used to add new collation sequences to the
  * sqlite3 handle specified as the first argument. 
@@ -909,15 +869,10 @@
  * the first string is less than, equal to, or greater than the second
  * string. i.e. (STRING1 - STRING2).
  */
-DoxyDefine(int switch_core_db_create_collation(
-  switch_core_db*, 
-  const char *zName, 
-  int eTextRep, 
-  void*,
-  int(*xCompare)(void*,int,const void*,int,const void*)
-);)
+DoxyDefine(int switch_core_db_create_collation(switch_core_db *,
+											   const char *zName, int eTextRep, void *, int (*xCompare) (void *, int, const void *, int, const void *)
+		   );)
 #define switch_core_db_create_collation sqlite3_create_collation
-
 /**
  * The following function is used to add user functions or aggregates
  * implemented in C to the SQL langauge interpreted by SQLite. The
@@ -951,18 +906,15 @@
  * xFunc and an xFinal, or an xStep but no xFinal, SQLITE_ERROR is
  * returned.
  */
-DoxyDefine(int switch_core_db_create_function(
-  switch_core_db *,
-  const char *zFunctionName,
-  int nArg,
-  int eTextRep,
-  void*,
-  void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
-  void (*xStep)(sqlite3_context*,int,sqlite3_value**),
-  void (*xFinal)(sqlite3_context*)
-);)
+DoxyDefine(int switch_core_db_create_function(switch_core_db *,
+											  const char *zFunctionName,
+											  int nArg,
+											  int eTextRep,
+											  void *,
+											  void (*xFunc) (sqlite3_context *, int, sqlite3_value **),
+											  void (*xStep) (sqlite3_context *, int, sqlite3_value **), void (*xFinal) (sqlite3_context *)
+		   );)
 #define switch_core_db_create_function sqlite3_create_function
-
 /**
  * Return the number of values in the current row of the result set.
  *
@@ -972,18 +924,16 @@
  * error code, or before switch_core_db_step() has been called on a 
  * compiled SQL statement, this routine returns zero.
  */
-DoxyDefine(int switch_core_db_data_count(sqlite3_stmt *pStmt);)
+DoxyDefine(int switch_core_db_data_count(sqlite3_stmt * pStmt);)
 #define switch_core_db_data_count sqlite3_data_count
-
 /**
  * Return the sqlite3* database handle to which the prepared statement given
  * in the argument belongs.  This is the same database handle that was
  * the first argument to the switch_core_db_prepare() that was used to create
  * the statement in the first place.
  */
-DoxyDefine(switch_core_db *switch_core_db_db_handle(sqlite3_stmt*);)
+	DoxyDefine(switch_core_db * switch_core_db_db_handle(sqlite3_stmt *);)
 #define switch_core_db_db_handle sqlite3_db_handle
-
 /**
 ** Return the error code for the most recent switch_core_db_* API call associated
 ** with switch_core_db handle 'db'. SQLITE_OK is returned if the most recent 
@@ -999,9 +949,8 @@
 ** code returned by this function is associated with the same error as
 ** the strings  returned by sqlite3_errmsg() and sqlite3_errmsg16().
 */
-DoxyDefine(int switch_core_db_errcode(switch_core_db *db);)
+DoxyDefine(int switch_core_db_errcode(switch_core_db * db);)
 #define switch_core_db_errcode sqlite3_errcode
-
 /**
  * Return a pointer to a UTF-8 encoded string describing in english the
  * error condition for the most recent sqlite3_* API call. The returned
@@ -1010,9 +959,8 @@
  * The string "not an error" is returned when the most recent API call was
  * successful.
  */
-DoxyDefine(const char *switch_core_db_errmsg(switch_core_db*);)
+DoxyDefine(const char *switch_core_db_errmsg(switch_core_db *);)
 #define switch_core_db_errmsg sqlite3_errmsg
-
 /**
  * A function to executes one or more statements of SQL.
  *
@@ -1053,15 +1001,13 @@
  * behavior can be modified somewhat using the sswitch_core_db_busy_handler()
  * and switch_core_db_busy_timeout() functions below.)
  */
-DoxyDefine(int switch_core_db_exec(
-  switch_core_db*,                     /* An open database */
-  const char *sql,              /* SQL to be executed */
-  sqlite3_callback,             /* Callback function */
-  void *,                       /* 1st argument to callback function */
-  char **errmsg                 /* Error msg written here */
-);)
+DoxyDefine(int switch_core_db_exec(switch_core_db *,	/* An open database */
+								   const char *sql,	/* SQL to be executed */
+								   sqlite3_callback,	/* Callback function */
+								   void *,	/* 1st argument to callback function */
+								   char **errmsg	/* Error msg written here */
+		   );)
 #define switch_core_db_exec sqlite3_exec
-
 /**
  * Return TRUE (non-zero) if the statement supplied as an argument needs
  * to be recompiled.  A statement needs to be recompiled whenever the
@@ -1071,9 +1017,8 @@
  * added or changed.
  *
  */
-DoxyDefine(int switch_core_db_expired(sqlite3_stmt*);)
+DoxyDefine(int switch_core_db_expired(sqlite3_stmt *);)
 #define switch_core_db_expired sqlite3_expired
-
 /**
  * This function is called to delete a compiled
  * SQL statement obtained by a previous call to switch_core_db_prepare().
@@ -1088,24 +1033,21 @@
  * rolled back and transactions cancelled,  depending on the circumstances,
  * and the result code returned will be SQLITE_ABORT.
  */
-DoxyDefine(int switch_core_db_finalize(sqlite3_stmt *pStmt);)
+DoxyDefine(int switch_core_db_finalize(sqlite3_stmt * pStmt);)
 #define switch_core_db_finalize sqlite3_finalize
-
 /**
  * Call this routine to free the memory that sqlite3_get_table() allocated.
  */
 DoxyDefine(void switch_core_db_free_table(char **result);)
 #define switch_core_db_free_table sqlite3_free_table
-
 /**
  * Test to see whether or not the database connection is in autocommit
  * mode.  Return TRUE if it is and FALSE if not.  Autocommit mode is on
  * by default.  Autocommit is disabled by a BEGIN statement and reenabled
  * by the next COMMIT or ROLLBACK.
  */
-DoxyDefine(int switch_core_db_get_autocommit(switch_core_db*);)
+DoxyDefine(int switch_core_db_get_autocommit(switch_core_db *);)
 #define switch_core_db_get_autocommit sqlite3_get_autocommit
-
 /**
  * The following function may be used by scalar user functions to
  * associate meta-data with argument values. If the same value is passed to
@@ -1125,9 +1067,8 @@
  * expressions that are constant at compile time. This includes literal
  * values and SQL variables.
  */
-DoxyDefine(void *switch_core_db_get_auxdata(sqlite3_context*, int);)
+DoxyDefine(void *switch_core_db_get_auxdata(sqlite3_context *, int);)
 #define switch_core_db_get_auxdata sqlite3_get_auxdata
-
 /**
  * The following function may be used by scalar user functions to
  * associate meta-data with argument values. If the same value is passed to
@@ -1149,9 +1090,8 @@
  * expressions that are constant at compile time. This includes literal
  * values and SQL variables.
  */
-DoxyDefine(void switch_core_db_set_auxdata(sqlite3_context*, int, void*, void (*)(void*));)
+DoxyDefine(void switch_core_db_set_auxdata(sqlite3_context *, int, void *, void (*)(void *));)
 #define switch_core_db_set_auxdata sqlite3_set_auxdata
-
 /**
  * This next routine is really just a wrapper around sqlite3_exec().
  * Instead of invoking a user-supplied callback for each row of the
@@ -1193,16 +1133,14 @@
  *
  * The return value of this routine is the same as from switch_core_db_exec().
  */
-DoxyDefine(int switch_core_db_get_table(
-  switch_core_db*,       /* An open database */
-  const char *sql,       /* SQL to be executed */
-  char ***resultp,       /* Result written to a char *[]  that this points to */
-  int *nrow,             /* Number of result rows written here */
-  int *ncolumn,          /* Number of result columns written here */
-  char **errmsg          /* Error msg written here */
-);)
+DoxyDefine(int switch_core_db_get_table(switch_core_db *,	/* An open database */
+										const char *sql,	/* SQL to be executed */
+										char ***resultp,	/* Result written to a char *[]  that this points to */
+										int *nrow,	/* Number of result rows written here */
+										int *ncolumn,	/* Number of result columns written here */
+										char **errmsg	/* Error msg written here */
+		   );)
 #define switch_core_db_get_table sqlite3_get_table
-
 /**
  * This function is called to recover from a malloc() failure that occured
  * within the SQLite library. Normally, after a single malloc() fails the 
@@ -1224,16 +1162,14 @@
  */
 DoxyDefine(int switch_core_db_global_recover();)
 #define switch_core_db_global_recover sqlite3_global_recover
-
 /** This function causes any pending database operation to abort and
  * return at its earliest opportunity.  This routine is typically
  * called in response to a user action such as pressing "Cancel"
  * or Ctrl-C where the user wants a long query operation to halt
  * immediately.
  */
-DoxyDefine(void switch_core_db_interrupt(switch_core_db*);)
+DoxyDefine(void switch_core_db_interrupt(switch_core_db *);)
 #define switch_core_db_interrupt sqlite3_interrupt
-
 /**
  * Each entry in an SQLite table has a unique integer key.  (The key is
  * the value of the INTEGER PRIMARY KEY column if there is such a column,
@@ -1243,9 +1179,8 @@
  *
  * This function is similar to the mysql_insert_id() function from MySQL.
  */
-DoxyDefine(sqlite_int64 switch_core_db_last_insert_rowid(switch_core_db*);)
+	DoxyDefine(sqlite_int64 switch_core_db_last_insert_rowid(switch_core_db *);)
 #define switch_core_db_last_insert_rowid sqlite3_last_insert_rowid
-
 /**
  * Open the sqlite database file "filename".  The "filename" is UTF-8
  * encoded.  An sqlite3* handle is returned in *ppDb, even
@@ -1261,12 +1196,10 @@
  * with the switch_core_db* handle should be released by passing it to
  * switch_core_db_close() when it is no longer required.
  */
-DoxyDefine(int switch_core_db_open(
-  const char *filename,   /* Database filename (UTF-8) */
-  switch_core_db **ppDb          /* OUT: SQLite db handle */
-);)
+DoxyDefine(int switch_core_db_open(const char *filename,	/* Database filename (UTF-8) */
+								   switch_core_db ** ppDb	/* OUT: SQLite db handle */
+		   );)
 #define switch_core_db_open sqlite3_open
-
 /**
  * To execute an SQL query, it must first be compiled into a byte-code
  * program using the following routine.
@@ -1289,15 +1222,13 @@
  *
  * On success, SQLITE_OK is returned.  Otherwise an error code is returned.
  */
-DoxyDefine(int switch_core_db_prepare(
-  sqlite3 *db,            /* Database handle */
-  const char *zSql,       /* SQL statement, UTF-8 encoded */
-  int nBytes,             /* Length of zSql in bytes. */
-  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
-  const char **pzTail     /* OUT: Pointer to unused portion of zSql */
-);)
+DoxyDefine(int switch_core_db_prepare(sqlite3 * db,	/* Database handle */
+									  const char *zSql,	/* SQL statement, UTF-8 encoded */
+									  int nBytes,	/* Length of zSql in bytes. */
+									  sqlite3_stmt ** ppStmt,	/* OUT: Statement handle */
+									  const char **pzTail	/* OUT: Pointer to unused portion of zSql */
+		   );)
 #define switch_core_db_prepare sqlite3_prepare
-
 /**
  * Register a function for tracing SQL command evaluation.  The function registered by
  * switch_core_db_profile() runs at the end of each SQL statement and includes
@@ -1306,10 +1237,8 @@
  * The sqlite3_profile() API is currently considered experimental and
  * is subject to change.
  */
-DoxyDefine(void *switch_core_db_profile(switch_core_db*,
-   void(*xProfile)(void*,const char*,sqlite_uint64), void*);)
+DoxyDefine(void *switch_core_db_profile(switch_core_db *, void (*xProfile) (void *, const char *, sqlite_uint64), void *);)
 #define switch_core_db_profile sqlite3_profile
-
 /**
  * This routine configures a callback function - the progress callback - that
  * is invoked periodically during long running calls to switch_core_db_exec(),
@@ -1336,9 +1265,8 @@
  *
  ****** THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ******
  */
-DoxyDefine(void switch_core_db_progress_handler(switch_core_db*, int, int(*)(void*), void*);)
+DoxyDefine(void switch_core_db_progress_handler(switch_core_db *, int, int (*)(void *), void *);)
 #define switch_core_db_progress_handler sqlite3_progress_handler
-
 /**
  * The switch_core_db_reset() function is called to reset a compiled SQL
  * statement obtained by a previous call to switch_core_db_prepare()
@@ -1346,93 +1274,80 @@
  * Any SQL statement variables that had values bound to them using
  * the switch_core_db_bind_*() API retain their values.
  */
-DoxyDefine(int switch_core_db_reset(sqlite3_stmt *pStmt);)
+DoxyDefine(int switch_core_db_reset(sqlite3_stmt * pStmt);)
 #define switch_core_db_reset sqlite3_reset
-
 /**
  * User-defined functions invoke this routine in order to
  * set their return value.
  */
-DoxyDefine(void switch_core_db_result_blob(sqlite3_context*, const void*, int, void(*)(void*));)
+DoxyDefine(void switch_core_db_result_blob(sqlite3_context *, const void *, int, void (*)(void *));)
 #define switch_core_db_result_blob sqlite3_result_blob
-
 /**
  * User-defined functions invoke this routine in order to
  * set their return value.
  */
-DoxyDefine(void switch_core_db_result_double(sqlite3_context*, double);)
+DoxyDefine(void switch_core_db_result_double(sqlite3_context *, double);)
 #define switch_core_db_result_double sqlite3_result_double
-
 /**
  * User-defined functions invoke this routine in order to
  * set their return value.
  */
-DoxyDefine(void switch_core_db_result_error(sqlite3_context*, const char*, int);)
+DoxyDefine(void switch_core_db_result_error(sqlite3_context *, const char *, int);)
 #define switch_core_db_result_error sqlite3_result_error
-
 /**
  * User-defined functions invoke this routine in order to
  * set their return value.
  */
-DoxyDefine(void switch_core_db_result_error16(sqlite3_context*, const void*, int);)
+DoxyDefine(void switch_core_db_result_error16(sqlite3_context *, const void *, int);)
 #define switch_core_db_result_error16 sqlite3_result_error16
-
 /**
  * User-defined functions invoke this routine in order to
  * set their return value.
  */
-DoxyDefine(void switch_core_db_result_int(sqlite3_context*, int);)
+DoxyDefine(void switch_core_db_result_int(sqlite3_context *, int);)
 #define switch_core_db_result_int sqlite3_result_int
-
 /**
  * User-defined functions invoke this routine in order to
  * set their return value.
  */
-DoxyDefine(void switch_core_db_result_int64(sqlite3_context*, sqlite_int64);)
+DoxyDefine(void switch_core_db_result_int64(sqlite3_context *, sqlite_int64);)
 #define switch_core_db_result_int64 sqlite3_result_int64
-
 /**
  * User-defined functions invoke this routine in order to
  * set their return value.
  */
-DoxyDefine(void switch_core_db_result_null(sqlite3_context*);)
+DoxyDefine(void switch_core_db_result_null(sqlite3_context *);)
 #define switch_core_db_result_null sqlite3_result_null
-
 /**
  * User-defined functions invoke this routine in order to
  * set their return value.
  */
-DoxyDefine(void switch_core_db_result_text(sqlite3_context*, const char*, int, void(*)(void*));)
+DoxyDefine(void switch_core_db_result_text(sqlite3_context *, const char *, int, void (*)(void *));)
 #define switch_core_db_result_text sqlite3_result_text
-
 /**
  * User-defined functions invoke this routine in order to
  * set their return value.
  */
-DoxyDefine(void switch_core_db_result_text16(sqlite3_context*, const void*, int, void(*)(void*));)
+DoxyDefine(void switch_core_db_result_text16(sqlite3_context *, const void *, int, void (*)(void *));)
 #define switch_core_db_result_text16 sqlite3_result_text16
-
 /**
  * User-defined functions invoke this routine in order to
  * set their return value.
  */
-DoxyDefine(void switch_core_db_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));)
+DoxyDefine(void switch_core_db_result_text16le(sqlite3_context *, const void *, int, void (*)(void *));)
 #define switch_core_db_result_text16le sqlite3_result_text16le
-
 /**
  * User-defined functions invoke this routine in order to
  * set their return value.
  */
-DoxyDefine(void switch_core_db_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));)
+DoxyDefine(void switch_core_db_result_text16be(sqlite3_context *, const void *, int, void (*)(void *));)
 #define switch_core_db_result_text16be sqlite3_result_text16be
-
 /**
  * User-defined functions invoke this routine in order to
  * set their return value.
  */
-DoxyDefine(void switch_core_db_result_value(sqlite3_context*, sqlite3_value*);)
+DoxyDefine(void switch_core_db_result_value(sqlite3_context *, sqlite3_value *);)
 #define switch_core_db_result_value sqlite3_result_value
-
 /**
  * This routine registers a callback with the SQLite library.  The
  * callback is invoked (at compile-time, not at run-time) for each
@@ -1441,13 +1356,9 @@
  * SQL statement should be aborted with an error and SQLITE_IGNORE
  * if the column should be treated as a NULL value.
  */
-DoxyDefine(int switch_core_db_set_authorizer(
-  switch_core_db*,
-  int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
-  void *pUserData
-);)
+DoxyDefine(int switch_core_db_set_authorizer(switch_core_db *,
+											 int (*xAuth) (void *, int, const char *, const char *, const char *, const char *), void *pUserData);)
 #define switch_core_db_set_authorizer sqlite3_set_authorizer
-
 /** 
  * After an SQL query has been compiled with a call to either
  * switch_core_db_prepare(), then this function must be
@@ -1480,9 +1391,8 @@
  * SQLITE_DONE.  Or it could be the case the the same database connection
  * is being used simulataneously by two or more threads.
  */
-DoxyDefine(int switch_core_db_step(sqlite3_stmt*);)
+DoxyDefine(int switch_core_db_step(sqlite3_stmt *);)
 #define switch_core_db_step sqlite3_step
-
 /**
  * If the following global variable is made to point to a
  * string which is the name of a directory, then all temporary files
@@ -1493,9 +1403,8 @@
  * Once switch_core_db_open() has been called, changing this variable will invalidate
  * the current temporary database, if any.
  */
-DoxyDefine(extern char *switch_core_db_temp_directory;)
+	DoxyDefine(extern char *switch_core_db_temp_directory;)
 #define switch_core_db_temp_directory sqlite3_temp_directory
-
 /**
  * This function returns the number of database rows that have been
  * modified by INSERT, UPDATE or DELETE statements since the database handle
@@ -1512,17 +1421,15 @@
  * table. To get an accurate count of the number of rows deleted, use
  * "DELETE FROM table WHERE 1" instead.
  */
-DoxyDefine(int switch_core_db_total_changes(switch_core_db*);)
+DoxyDefine(int switch_core_db_total_changes(switch_core_db *);)
 #define switch_core_db_total_changes sqlite3_total_changes
-
 /**
  * Register a function for tracing SQL command evaluation.  The function
  * registered is invoked at the first switch_core_db_step()
  * for the evaluation of an SQL statement.
  */
-DoxyDefine(void *switch_core_db_trace(switch_core_db*, void(*xTrace)(void*,const char*), void*);)
+DoxyDefine(void *switch_core_db_trace(switch_core_db *, void (*xTrace) (void *, const char *), void *);)
 #define switch_core_db_trace sqlite3_trace
-
 /**
  * Move all bindings from the first prepared statement over to the second.
  * This routine is useful, for example, if the first prepared statement
@@ -1530,17 +1437,15 @@
  * the second prepared statement then all of the bindings transfered over
  * to the second statement before the first statement is finalized.
  */
-DoxyDefine(int switch_core_db_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);)
+DoxyDefine(int switch_core_db_transfer_bindings(sqlite3_stmt *, sqlite3_stmt *);)
 #define switch_core_db_transfer_bindings sqlite3_transfer_bindings
-
 /**
  * The pUserData parameter to the switch_core_db_create_function()
  * routine used to register user functions is available to
  * the implementation of the function using this call.
  */
-DoxyDefine(void *switch_core_db_user_data(sqlite3_context*);)
+DoxyDefine(void *switch_core_db_user_data(sqlite3_context *);)
 #define switch_core_db_user_data sqlite3_user_data
-
 /**
  * returns information about parameters to
  * a user-defined function.  Function implementations use this routines
@@ -1549,9 +1454,8 @@
  * sqlite3_value* pointer instead of an sqlite3_stmt* and an integer
  * column number.
  */
-DoxyDefine(const void *switch_core_db_value_blob(sqlite3_value*);)
+DoxyDefine(const void *switch_core_db_value_blob(sqlite3_value *);)
 #define switch_core_db_value_blob sqlite3_value_blob
-
 /**
  * returns information about parameters to
  * a user-defined function.  Function implementations use this routines
@@ -1560,9 +1464,8 @@
  * sqlite3_value* pointer instead of an sqlite3_stmt* and an integer
  * column number.
  */
-DoxyDefine(int switch_core_db_value_bytes(sqlite3_value*);)
+DoxyDefine(int switch_core_db_value_bytes(sqlite3_value *);)
 #define switch_core_db_value_bytes sqlite3_value_bytes
-
 /**
  * returns information about parameters to
  * a user-defined function.  Function implementations use this routines
@@ -1571,9 +1474,8 @@
  * sqlite3_value* pointer instead of an sqlite3_stmt* and an integer
  * column number.
  */
-DoxyDefine(int switch_core_db_value_bytes16(sqlite3_value*);)
+DoxyDefine(int switch_core_db_value_bytes16(sqlite3_value *);)
 #define switch_core_db_value_bytes16 sqlite3_value_bytes16
-
 /**
  * returns information about parameters to
  * a user-defined function.  Function implementations use this routines
@@ -1582,9 +1484,8 @@
  * sqlite3_value* pointer instead of an sqlite3_stmt* and an integer
  * column number.
  */
-DoxyDefine(double switch_core_db_value_double(sqlite3_value*);)
+DoxyDefine(double switch_core_db_value_double(sqlite3_value *);)
 #define switch_core_db_value_double sqlite3_value_double
-
 /**
  * returns information about parameters to
  * a user-defined function.  Function implementations use this routines
@@ -1593,9 +1494,8 @@
  * sqlite3_value* pointer instead of an sqlite3_stmt* and an integer
  * column number.
  */
-DoxyDefine(int switch_core_db_value_int(sqlite3_value*);)
+DoxyDefine(int switch_core_db_value_int(sqlite3_value *);)
 #define switch_core_db_value_int sqlite3_value_int
-
 /**
  * returns information about parameters to
  * a user-defined function.  Function implementations use this routines
@@ -1604,9 +1504,8 @@
  * sqlite3_value* pointer instead of an sqlite3_stmt* and an integer
  * column number.
  */
-DoxyDefine(sqlite_int64 switch_core_db_value_int64(sqlite3_value*);)
+	DoxyDefine(sqlite_int64 switch_core_db_value_int64(sqlite3_value *);)
 #define switch_core_db_value_int64 sqlite3_value_int64
-
 /**
  * returns information about parameters to
  * a user-defined function.  Function implementations use this routines
@@ -1615,9 +1514,8 @@
  * sqlite3_value* pointer instead of an sqlite3_stmt* and an integer
  * column number.
  */
-DoxyDefine(const unsigned char *switch_core_db_value_text(sqlite3_value*);)
+DoxyDefine(const unsigned char *switch_core_db_value_text(sqlite3_value *);)
 #define switch_core_db_value_text sqlite3_value_text
-
 /**
  * returns information about parameters to
  * a user-defined function.  Function implementations use this routines
@@ -1626,9 +1524,8 @@
  * sqlite3_value* pointer instead of an sqlite3_stmt* and an integer
  * column number.
  */
-DoxyDefine(const void *switch_core_db_value_text16(sqlite3_value*);)
+DoxyDefine(const void *switch_core_db_value_text16(sqlite3_value *);)
 #define switch_core_db_value_text16 sqlite3_value_text16
-
 /**
  * returns information about parameters to
  * a user-defined function.  Function implementations use this routines
@@ -1637,9 +1534,8 @@
  * sqlite3_value* pointer instead of an sqlite3_stmt* and an integer
  * column number.
  */
-DoxyDefine(const void *switch_core_db_value_text16be(sqlite3_value*);)
+DoxyDefine(const void *switch_core_db_value_text16be(sqlite3_value *);)
 #define switch_core_db_value_text16be sqlite3_value_text16be
-
 /**
  * returns information about parameters to
  * a user-defined function.  Function implementations use this routines
@@ -1648,9 +1544,8 @@
  * sqlite3_value* pointer instead of an sqlite3_stmt* and an integer
  * column number.
  */
-DoxyDefine(const void *switch_core_db_value_text16le(sqlite3_value*);)
+DoxyDefine(const void *switch_core_db_value_text16le(sqlite3_value *);)
 #define switch_core_db_value_text16le sqlite3_value_text16le
-
 /**
  * returns information about parameters to
  * a user-defined function.  Function implementations use this routines
@@ -1659,10 +1554,8 @@
  * sqlite3_value* pointer instead of an sqlite3_stmt* and an integer
  * column number.
  */
-DoxyDefine(int switch_core_db_value_type(sqlite3_value*);)
+DoxyDefine(int switch_core_db_value_type(sqlite3_value *);)
 #define switch_core_db_value_type sqlite3_value_type
-
-
 /**
  * This routine is a variant of the "sprintf()" from the
  * standard C library.  The resulting string is written into memory
@@ -1704,10 +1597,9 @@
  * should always use %q instead of %s when inserting text into a string 
  * literal.
  */
-DoxyDefine(char *switch_core_db_mprintf(const char*,...);)
+DoxyDefine(char *switch_core_db_mprintf(const char *, ...);)
 #define switch_core_db_mprintf sqlite3_mprintf
 #define switch_mprintf sqlite3_mprintf
-
 /**
  * This routine is a variant of the "sprintf()" from the
  * standard C library.  The resulting string is written into memory
@@ -1749,9 +1641,8 @@
  * should always use %q instead of %s when inserting text into a string 
  * literal.
  */
-DoxyDefine(char *switch_core_db_vmprintf(const char*, va_list);)
+DoxyDefine(char *switch_core_db_vmprintf(const char *, va_list);)
 #define switch_core_db_vmprintf sqlite3_vmprintf
-
 /**
  * This routine is a variant of the "sprintf()" from the
  * standard C library.  The resulting string is written into memory
@@ -1793,22 +1684,17 @@
  * should always use %q instead of %s when inserting text into a string 
  * literal.
  */
-DoxyDefine(char *switch_core_db_snprintf(int,char*,const char*, ...);)
+DoxyDefine(char *switch_core_db_snprintf(int, char *, const char *, ...);)
 #define switch_core_db_snprintf sqlite3_snprintf
-
 /**
  * call this routine to free memory malloced by a call to switch_core_db_mprintf, switch_core_db_vmprintf, or switch_core_db_snprintf
  */
 DoxyDefine(void switch_core_db_free(char *z);)
 #define switch_core_db_free sqlite3_free
-
 /** @} */
 /** @} */
-
-SWITCH_END_EXTERN_C
-
+	SWITCH_END_EXTERN_C
 #endif
-
 /* For Emacs:
  * Local Variables:
  * mode:c

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_stun.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_stun.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_stun.h	Fri Mar 30 12:19:18 2007
@@ -38,59 +38,57 @@
 #define _SWITCH_STUN_PARSER_H
 
 SWITCH_BEGIN_EXTERN_C
-
 #define SWITCH_STUN_DEFAULT_PORT 3478
 #define SWITCH_STUN_PACKET_MIN_LEN 20
-
-typedef enum {
-	SWITCH_STUN_BINDING_REQUEST					= 0x0001,
-	SWITCH_STUN_BINDING_RESPONSE					= 0x0101,
-	SWITCH_STUN_BINDING_ERROR_RESPONSE				= 0x0111,
-	SWITCH_STUN_SHARED_SECRET_REQUEST				= 0x0002,
-	SWITCH_STUN_SHARED_SECRET_RESPONSE				= 0x0102,
-	SWITCH_STUN_SHARED_SECRET_ERROR_RESPONSE 		= 0x0112,
-	SWITCH_STUN_ALLOCATE_REQUEST					= 0x0003,
-	SWITCH_STUN_ALLOCATE_RESPONSE					= 0x0103,
-	SWITCH_STUN_ALLOCATE_ERROR_RESPONSE			= 0x0113,
-	SWITCH_STUN_SEND_REQUEST						= 0x0004,
-	SWITCH_STUN_SEND_RESPONSE						= 0x0104,
-	SWITCH_STUN_SEND_ERROR_RESPONSE				= 0x0114,
-	SWITCH_STUN_DATA_INDICATION					= 0x0115
+	typedef enum {
+	SWITCH_STUN_BINDING_REQUEST = 0x0001,
+	SWITCH_STUN_BINDING_RESPONSE = 0x0101,
+	SWITCH_STUN_BINDING_ERROR_RESPONSE = 0x0111,
+	SWITCH_STUN_SHARED_SECRET_REQUEST = 0x0002,
+	SWITCH_STUN_SHARED_SECRET_RESPONSE = 0x0102,
+	SWITCH_STUN_SHARED_SECRET_ERROR_RESPONSE = 0x0112,
+	SWITCH_STUN_ALLOCATE_REQUEST = 0x0003,
+	SWITCH_STUN_ALLOCATE_RESPONSE = 0x0103,
+	SWITCH_STUN_ALLOCATE_ERROR_RESPONSE = 0x0113,
+	SWITCH_STUN_SEND_REQUEST = 0x0004,
+	SWITCH_STUN_SEND_RESPONSE = 0x0104,
+	SWITCH_STUN_SEND_ERROR_RESPONSE = 0x0114,
+	SWITCH_STUN_DATA_INDICATION = 0x0115
 } switch_stun_message_t;
 
 typedef enum {
-	SWITCH_STUN_ATTR_MAPPED_ADDRESS				= 0x0001, /* Address */
-	SWITCH_STUN_ATTR_RESPONSE_ADDRESS				= 0x0002, /* Address */
-	SWITCH_STUN_ATTR_CHANGE_REQUEST				= 0x0003, /* UInt32 */
-	SWITCH_STUN_ATTR_SOURCE_ADDRESS				= 0x0004, /* Address */
-	SWITCH_STUN_ATTR_CHANGED_ADDRESS				= 0x0005, /* Address */
-	SWITCH_STUN_ATTR_USERNAME						= 0x0006, /* ByteString, multiple of 4 bytes */
-	SWITCH_STUN_ATTR_PASSWORD						= 0x0007, /* ByteString, multiple of 4 bytes */
-	SWITCH_STUN_ATTR_MESSAGE_INTEGRITY				= 0x0008, /* ByteString, 20 bytes */
-	SWITCH_STUN_ATTR_ERROR_CODE					= 0x0009, /* ErrorCode */
-	SWITCH_STUN_ATTR_UNKNOWN_ATTRIBUTES			= 0x000a, /* UInt16List */
-	SWITCH_STUN_ATTR_REFLECTED_FROM				= 0x000b, /* Address */
-	SWITCH_STUN_ATTR_TRANSPORT_PREFERENCES 		= 0x000c, /* TransportPrefs */
-	SWITCH_STUN_ATTR_LIFETIME						= 0x000d, /* UInt32 */
-	SWITCH_STUN_ATTR_ALTERNATE_SERVER				= 0x000e, /* Address */
-	SWITCH_STUN_ATTR_MAGIC_COOKIE					= 0x000f, /* ByteString, 4 bytes */
-	SWITCH_STUN_ATTR_BANDWIDTH						= 0x0010, /* UInt32 */
-	SWITCH_STUN_ATTR_DESTINATION_ADDRESS			= 0x0011, /* Address */
-	SWITCH_STUN_ATTR_SOURCE_ADDRESS2				= 0x0012, /* Address */
-	SWITCH_STUN_ATTR_DATA							= 0x0013, /* ByteString */
-	SWITCH_STUN_ATTR_OPTIONS						= 0x8001  /* UInt32 */
+	SWITCH_STUN_ATTR_MAPPED_ADDRESS = 0x0001,	/* Address */
+	SWITCH_STUN_ATTR_RESPONSE_ADDRESS = 0x0002,	/* Address */
+	SWITCH_STUN_ATTR_CHANGE_REQUEST = 0x0003,	/* UInt32 */
+	SWITCH_STUN_ATTR_SOURCE_ADDRESS = 0x0004,	/* Address */
+	SWITCH_STUN_ATTR_CHANGED_ADDRESS = 0x0005,	/* Address */
+	SWITCH_STUN_ATTR_USERNAME = 0x0006,	/* ByteString, multiple of 4 bytes */
+	SWITCH_STUN_ATTR_PASSWORD = 0x0007,	/* ByteString, multiple of 4 bytes */
+	SWITCH_STUN_ATTR_MESSAGE_INTEGRITY = 0x0008,	/* ByteString, 20 bytes */
+	SWITCH_STUN_ATTR_ERROR_CODE = 0x0009,	/* ErrorCode */
+	SWITCH_STUN_ATTR_UNKNOWN_ATTRIBUTES = 0x000a,	/* UInt16List */
+	SWITCH_STUN_ATTR_REFLECTED_FROM = 0x000b,	/* Address */
+	SWITCH_STUN_ATTR_TRANSPORT_PREFERENCES = 0x000c,	/* TransportPrefs */
+	SWITCH_STUN_ATTR_LIFETIME = 0x000d,	/* UInt32 */
+	SWITCH_STUN_ATTR_ALTERNATE_SERVER = 0x000e,	/* Address */
+	SWITCH_STUN_ATTR_MAGIC_COOKIE = 0x000f,	/* ByteString, 4 bytes */
+	SWITCH_STUN_ATTR_BANDWIDTH = 0x0010,	/* UInt32 */
+	SWITCH_STUN_ATTR_DESTINATION_ADDRESS = 0x0011,	/* Address */
+	SWITCH_STUN_ATTR_SOURCE_ADDRESS2 = 0x0012,	/* Address */
+	SWITCH_STUN_ATTR_DATA = 0x0013,	/* ByteString */
+	SWITCH_STUN_ATTR_OPTIONS = 0x8001	/* UInt32 */
 } switch_stun_attribute_t;
 
 typedef enum {
-	SWITCH_STUN_ERROR_BAD_REQUEST					= 400,
-	SWITCH_STUN_ERROR_UNAUTHORIZED					= 401,
-	SWITCH_STUN_ERROR_UNKNOWN_ATTRIBUTE			= 420,
-	SWITCH_STUN_ERROR_STALE_CREDENTIALS			= 430,
-	SWITCH_STUN_ERROR_INTEGRITY_CHECK_FAILURE		= 431,
-	SWITCH_STUN_ERROR_MISSING_USERNAME				= 432,
-	SWITCH_STUN_ERROR_USE_TLS						= 433,
-	SWITCH_STUN_ERROR_SERVER_ERROR					= 500,
-	SWITCH_STUN_ERROR_GLOBAL_FAILURE				= 600
+	SWITCH_STUN_ERROR_BAD_REQUEST = 400,
+	SWITCH_STUN_ERROR_UNAUTHORIZED = 401,
+	SWITCH_STUN_ERROR_UNKNOWN_ATTRIBUTE = 420,
+	SWITCH_STUN_ERROR_STALE_CREDENTIALS = 430,
+	SWITCH_STUN_ERROR_INTEGRITY_CHECK_FAILURE = 431,
+	SWITCH_STUN_ERROR_MISSING_USERNAME = 432,
+	SWITCH_STUN_ERROR_USE_TLS = 433,
+	SWITCH_STUN_ERROR_SERVER_ERROR = 500,
+	SWITCH_STUN_ERROR_GLOBAL_FAILURE = 600
 } switch_stun_error_t;
 
 typedef enum {
@@ -138,7 +136,7 @@
   \param len the length of the data
   \return a stun packet pointer to buf to use as an access point
 */
-SWITCH_DECLARE(switch_stun_packet_t *)switch_stun_packet_parse(uint8_t *buf, uint32_t len);
+SWITCH_DECLARE(switch_stun_packet_t *) switch_stun_packet_parse(uint8_t * buf, uint32_t len);
 
 /*!
   \brief Obtain a printable string form of a given value
@@ -146,7 +144,7 @@
   \param value the value to look up
   \return a sring version of value
 */
-SWITCH_DECLARE(const char *)switch_stun_value_to_name(int32_t type, uint32_t value);
+SWITCH_DECLARE(const char *) switch_stun_value_to_name(int32_t type, uint32_t value);
 
 
 /*!
@@ -156,7 +154,7 @@
   \param port the port
   \return true or false
 */
-SWITCH_DECLARE(uint8_t) switch_stun_packet_attribute_get_mapped_address(switch_stun_packet_attribute_t *attribute, char *ipstr, uint16_t *port);
+SWITCH_DECLARE(uint8_t) switch_stun_packet_attribute_get_mapped_address(switch_stun_packet_attribute_t *attribute, char *ipstr, uint16_t * port);
 
 /*!
   \brief Extract a username from a packet attribute
@@ -165,7 +163,7 @@
   \param len the maximum size of the username buffer
   \return a pointer to the username or NULL
 */
-SWITCH_DECLARE(char *)switch_stun_packet_attribute_get_username(switch_stun_packet_attribute_t *attribute, char *username, uint16_t len);
+SWITCH_DECLARE(char *) switch_stun_packet_attribute_get_username(switch_stun_packet_attribute_t *attribute, char *username, uint16_t len);
 
 
 /*!
@@ -175,10 +173,7 @@
   \param buf a pointer to data to use for the packet
   \return a pointer to a ready-to-use stun packet
 */
-SWITCH_DECLARE(switch_stun_packet_t *)switch_stun_packet_build_header(switch_stun_message_t type,
-																	  char *id,
-																	  uint8_t *buf
-																	  );
+SWITCH_DECLARE(switch_stun_packet_t *) switch_stun_packet_build_header(switch_stun_message_t type, char *id, uint8_t * buf);
 
 /*!
   \brief Add a username packet attribute
@@ -197,7 +192,7 @@
   \param port the port of the mapped address
   \return true or false
 */
-SWITCH_DECLARE(uint8_t) switch_stun_packet_attribute_add_binded_address(switch_stun_packet_t *packet, char *ipstr,  uint16_t port);
+SWITCH_DECLARE(uint8_t) switch_stun_packet_attribute_add_binded_address(switch_stun_packet_t *packet, char *ipstr, uint16_t port);
 
 /*!
   \brief Perform a stun lookup
@@ -209,12 +204,8 @@
   \param pool the memory pool to use
   \return SUCCESS or FAIL
 */
-SWITCH_DECLARE(switch_status_t) switch_stun_lookup (char **ip, 
-												  switch_port_t *port,
-												  char *stunip,
-												  switch_port_t stunport,
-												  char **err,
-												  switch_memory_pool_t *pool);
+SWITCH_DECLARE(switch_status_t) switch_stun_lookup(char **ip,
+												   switch_port_t *port, char *stunip, switch_port_t stunport, char **err, switch_memory_pool_t *pool);
 
 
 
@@ -241,9 +232,7 @@
 ///\}
 
 SWITCH_END_EXTERN_C
-
 #endif
-
 /* For Emacs:
  * Local Variables:
  * mode:c

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_types.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_types.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_types.h	Fri Mar 30 12:19:18 2007
@@ -36,9 +36,7 @@
 
 #include <switch.h>
 SWITCH_BEGIN_EXTERN_C
-
 #define SWITCH_SEQ_ESC "\033["
-
 /* Ansi Control character suffixes */
 #define SWITCH_SEQ_HOME_CHAR 'H'
 #define SWITCH_SEQ_HOME_CHAR_STR "H"
@@ -48,11 +46,9 @@
 #define SWITCH_SEQ_CLEARSCR_CHAR0 '2'
 #define SWITCH_SEQ_CLEARSCR_CHAR1 'J'
 #define SWITCH_SEQ_CLEARSCR_CHAR "2J"
-
-#define SWITCH_SEQ_DEFAULT_COLOR SWITCH_SEQ_ESC SWITCH_SEQ_END_COLOR /* Reset to Default fg/bg color */
-#define SWITCH_SEQ_AND_COLOR ";" /* To add multiple color definitions */
-#define SWITCH_SEQ_END_COLOR "m" /* To end color definitions */
-
+#define SWITCH_SEQ_DEFAULT_COLOR SWITCH_SEQ_ESC SWITCH_SEQ_END_COLOR	/* Reset to Default fg/bg color */
+#define SWITCH_SEQ_AND_COLOR ";"	/* To add multiple color definitions */
+#define SWITCH_SEQ_END_COLOR "m"	/* To end color definitions */
 /* Foreground colors values */
 #define SWITCH_SEQ_F_BLACK "30"
 #define SWITCH_SEQ_F_RED "31"
@@ -62,7 +58,6 @@
 #define SWITCH_SEQ_F_MAGEN "35"
 #define SWITCH_SEQ_F_CYAN "36"
 #define SWITCH_SEQ_F_WHITE "37"
-
 /* Background colors values */
 #define SWITCH_SEQ_B_BLACK "40"
 #define SWITCH_SEQ_B_RED "41"
@@ -72,7 +67,6 @@
 #define SWITCH_SEQ_B_MAGEN "45"
 #define SWITCH_SEQ_B_CYAN "46"
 #define SWITCH_SEQ_B_WHITE "47"
-
 /* Preset escape sequences - Change foreground colors only */
 #define SWITCH_SEQ_FBLACK SWITCH_SEQ_ESC SWITCH_SEQ_F_BLACK SWITCH_SEQ_END_COLOR
 #define SWITCH_SEQ_FRED SWITCH_SEQ_ESC SWITCH_SEQ_F_RED SWITCH_SEQ_END_COLOR
@@ -82,7 +76,6 @@
 #define SWITCH_SEQ_FMAGEN SWITCH_SEQ_ESC SWITCH_SEQ_F_MAGEN SWITCH_SEQ_END_COLOR
 #define SWITCH_SEQ_FCYAN SWITCH_SEQ_ESC SWITCH_SEQ_F_CYAN SWITCH_SEQ_END_COLOR
 #define SWITCH_SEQ_FWHITE SWITCH_SEQ_ESC SWITCH_SEQ_F_WHITE SWITCH_SEQ_END_COLOR
-
 #define SWITCH_SEQ_BBLACK SWITCH_SEQ_ESC SWITCH_SEQ_B_BLACK SWITCH_SEQ_END_COLOR
 #define SWITCH_SEQ_BRED SWITCH_SEQ_ESC SWITCH_SEQ_B_RED SWITCH_SEQ_END_COLOR
 #define SWITCH_SEQ_BGREEN SWITCH_SEQ_ESC SWITCH_SEQ_B_GREEN SWITCH_SEQ_END_COLOR
@@ -91,21 +84,17 @@
 #define SWITCH_SEQ_BMAGEN SWITCH_SEQ_ESC SWITCH_SEQ_B_MAGEN SWITCH_SEQ_END_COLOR
 #define SWITCH_SEQ_BCYAN SWITCH_SEQ_ESC SWITCH_SEQ_B_CYAN SWITCH_SEQ_END_COLOR
 #define SWITCH_SEQ_BWHITE SWITCH_SEQ_ESC SWITCH_SEQ_B_WHITE SWITCH_SEQ_END_COLOR
-
 /* Preset escape sequences */
 #define SWITCH_SEQ_HOME SWITCH_SEQ_ESC SWITCH_SEQ_HOME_CHAR_STR
 #define SWITCH_SEQ_CLEARLINE SWITCH_SEQ_ESC SWITCH_SEQ_CLEARLINE_CHAR_STR
 #define SWITCH_SEQ_CLEARLINEEND SWITCH_SEQ_ESC SWITCH_SEQ_CLEARLINEEND_CHAR
 #define SWITCH_SEQ_CLEARSCR SWITCH_SEQ_ESC SWITCH_SEQ_CLEARSCR_CHAR SWITCH_SEQ_HOME
-
 #ifdef WIN32
 #define SWITCH_PATH_SEPARATOR "\\"
 #else
 #define SWITCH_PATH_SEPARATOR "/"
 #endif
-
 #define SWITCH_URL_SEPARATOR "://"
-
 #define SWITCH_ENDPOINT_DISPOSITION_VARIABLE "endpoint_disposition"
 #define SWITCH_EXPORT_VARS_VARIABLE "export_vars"
 #define SWITCH_R_SDP_VARIABLE "switch_r_sdp"
@@ -122,11 +111,10 @@
 #define SWITCH_REMOTE_MEDIA_PORT_VARIABLE "remote_media_port"
 #define SWITCH_HANGUP_AFTER_BRIDGE_VARIABLE "hangup_after_bridge"
 #define SWITCH_MAX_FORWARDS_VARIABLE "max_forwards"
-
 #define SWITCH_SPEECH_KEY "speech"
 #define SWITCH_UUID_BRIDGE "uuid_bridge"
 #define SWITCH_BITS_PER_BYTE 8
-typedef uint8_t switch_byte_t;
+	typedef uint8_t switch_byte_t;
 
 typedef enum {
 	SWITCH_FALSE = 0,
@@ -137,7 +125,7 @@
 	SSM_NA,
 	SSM_PRONOUNCED,
 	SSM_ITERATED,
-    SSM_COUNTED
+	SSM_COUNTED
 } switch_say_method_t;
 
 typedef enum {
@@ -170,7 +158,8 @@
 typedef enum {
 	SSHF_NONE = 0,
 	SSHF_OWN_THREAD = (1 << 0),
-	SSHF_FREE_ARG = (1 << 1)
+	SSHF_FREE_ARG = (1 << 1),
+	SSHF_NO_DEL = (1 << 2)
 } switch_scheduler_flag_t;
 
 typedef enum {
@@ -242,12 +231,12 @@
 } switch_caller_profile_flag_t;
 
 typedef enum {
-	SWITCH_AUDIO_COL_STR_TITLE                    = 0x01,
-	SWITCH_AUDIO_COL_STR_COPYRIGHT                = 0x02,
-	SWITCH_AUDIO_COL_STR_SOFTWARE                 = 0x03,
-	SWITCH_AUDIO_COL_STR_ARTIST                   = 0x04,
-	SWITCH_AUDIO_COL_STR_COMMENT                  = 0x05,
-	SWITCH_AUDIO_COL_STR_DATE                     = 0x06
+	SWITCH_AUDIO_COL_STR_TITLE = 0x01,
+	SWITCH_AUDIO_COL_STR_COPYRIGHT = 0x02,
+	SWITCH_AUDIO_COL_STR_SOFTWARE = 0x03,
+	SWITCH_AUDIO_COL_STR_ARTIST = 0x04,
+	SWITCH_AUDIO_COL_STR_COMMENT = 0x05,
+	SWITCH_AUDIO_COL_STR_DATE = 0x06
 } switch_audio_col_t;
 
 typedef enum {
@@ -269,10 +258,10 @@
 </pre>
  */
 typedef enum {
-	SWITCH_VAD_FLAG_TALKING = ( 1 << 0 ),
-	SWITCH_VAD_FLAG_EVENTS_TALK = ( 1 << 1 ),
-	SWITCH_VAD_FLAG_EVENTS_NOTALK = ( 1 << 2 ),
-	SWITCH_VAD_FLAG_CNG = ( 1 << 3)
+	SWITCH_VAD_FLAG_TALKING = (1 << 0),
+	SWITCH_VAD_FLAG_EVENTS_TALK = (1 << 1),
+	SWITCH_VAD_FLAG_EVENTS_NOTALK = (1 << 2),
+	SWITCH_VAD_FLAG_CNG = (1 << 3)
 } switch_vad_flag_t;
 
 #define SWITCH_RTP_CNG_PAYLOAD 13
@@ -299,7 +288,7 @@
 </pre>
  */
 typedef enum {
-	SWITCH_RTP_FLAG_NOBLOCK = ( 1 << 0),
+	SWITCH_RTP_FLAG_NOBLOCK = (1 << 0),
 	SWITCH_RTP_FLAG_IO = (1 << 1),
 	SWITCH_RTP_FLAG_USE_TIMER = (1 << 2),
 	SWITCH_RTP_FLAG_TIMER_RECLOCK = (1 << 3),
@@ -308,8 +297,8 @@
 	SWITCH_RTP_FLAG_RAW_WRITE = (1 << 6),
 	SWITCH_RTP_FLAG_GOOGLEHACK = (1 << 7),
 	SWITCH_RTP_FLAG_VAD = (1 << 8),
-	SWITCH_RTP_FLAG_BREAK = ( 1 << 9),
-	SWITCH_RTP_FLAG_MINI = ( 1 << 10),
+	SWITCH_RTP_FLAG_BREAK = (1 << 9),
+	SWITCH_RTP_FLAG_MINI = (1 << 10),
 	SWITCH_RTP_FLAG_DATAWAIT = (1 << 11),
 	SWITCH_RTP_FLAG_BUGGY_2833 = (1 << 12),
 	SWITCH_RTP_FLAG_PASS_RFC2833 = (1 << 13),
@@ -453,7 +442,7 @@
 typedef enum {
 	SWITCH_LOG_CONSOLE = 8,
 	SWITCH_LOG_DEBUG = 7,
-	SWITCH_LOG_INFO  = 6,
+	SWITCH_LOG_INFO = 6,
 	SWITCH_LOG_NOTICE = 5,
 	SWITCH_LOG_WARNING = 4,
 	SWITCH_LOG_ERROR = 3,
@@ -512,7 +501,7 @@
 	CS_HOLD,
 	CS_HIBERNATE,
 	CS_HANGUP,
-	CS_DONE 
+	CS_DONE
 } switch_channel_state_t;
 
 
@@ -544,25 +533,25 @@
  */
 
 typedef enum {
-	CF_ANSWERED   	= (1 <<  0),
-	CF_OUTBOUND   	= (1 <<  1),
-	CF_EARLY_MEDIA	= (1 <<  2),
-	CF_ORIGINATOR	= (1 <<  3),
-	CF_TRANSFER		= (1 <<  4),
-	CF_ACCEPT_CNG	= (1 <<  5),
-	CF_LOCK_THREAD	= (1 <<  6),
-	CF_BRIDGED		= (1 <<  7),
-	CF_HOLD			= (1 <<  8),
-	CF_SERVICE		= (1 <<  9),
-	CF_TAGGED		= (1 << 10),
-	CF_WINNER		= (1 << 11),
-	CF_CONTROLLED	= (1 << 12),
-	CF_NOMEDIA		= (1 << 13),
-	CF_SUSPEND		= (1 << 14),
-	CF_EVENT_PARSE	= (1 << 15),
-    CF_REPEAT_STATE = (1 << 16),
-	CF_GEN_RINGBACK	= (1 << 17),
-	CF_RING_READY   = (1 << 18)
+	CF_ANSWERED = (1 << 0),
+	CF_OUTBOUND = (1 << 1),
+	CF_EARLY_MEDIA = (1 << 2),
+	CF_ORIGINATOR = (1 << 3),
+	CF_TRANSFER = (1 << 4),
+	CF_ACCEPT_CNG = (1 << 5),
+	CF_LOCK_THREAD = (1 << 6),
+	CF_BRIDGED = (1 << 7),
+	CF_HOLD = (1 << 8),
+	CF_SERVICE = (1 << 9),
+	CF_TAGGED = (1 << 10),
+	CF_WINNER = (1 << 11),
+	CF_CONTROLLED = (1 << 12),
+	CF_NOMEDIA = (1 << 13),
+	CF_SUSPEND = (1 << 14),
+	CF_EVENT_PARSE = (1 << 15),
+	CF_REPEAT_STATE = (1 << 16),
+	CF_GEN_RINGBACK = (1 << 17),
+	CF_RING_READY = (1 << 18)
 } switch_channel_flag_t;
 
 
@@ -600,7 +589,7 @@
 	SWITCH_SIG_NONE,
 	SWITCH_SIG_KILL,
 	SWITCH_SIG_XFER,
-    SWITCH_SIG_BREAK
+	SWITCH_SIG_BREAK
 } switch_signal_t;
 
 /*!
@@ -618,14 +607,14 @@
 </pre>
 */
 typedef enum {
-	SWITCH_CODEC_FLAG_ENCODE =			(1 <<  0),
-	SWITCH_CODEC_FLAG_DECODE =			(1 <<  1),
-	SWITCH_CODEC_FLAG_SILENCE_START =	(1 <<  2),
-	SWITCH_CODEC_FLAG_SILENCE_STOP =	(1 <<  3),
-	SWITCH_CODEC_FLAG_SILENCE =			(1 <<  4),
-	SWITCH_CODEC_FLAG_FREE_POOL =		(1 <<  5),
-	SWITCH_CODEC_FLAG_AAL2 =			(1 <<  6),
-	SWITCH_CODEC_FLAG_PASSTHROUGH =		(1 <<  7)
+	SWITCH_CODEC_FLAG_ENCODE = (1 << 0),
+	SWITCH_CODEC_FLAG_DECODE = (1 << 1),
+	SWITCH_CODEC_FLAG_SILENCE_START = (1 << 2),
+	SWITCH_CODEC_FLAG_SILENCE_STOP = (1 << 3),
+	SWITCH_CODEC_FLAG_SILENCE = (1 << 4),
+	SWITCH_CODEC_FLAG_FREE_POOL = (1 << 5),
+	SWITCH_CODEC_FLAG_AAL2 = (1 << 6),
+	SWITCH_CODEC_FLAG_PASSTHROUGH = (1 << 7)
 } switch_codec_flag_t;
 
 
@@ -641,12 +630,12 @@
 </pre>
 */
 typedef enum {
-	SWITCH_SPEECH_FLAG_NONE =			0,
-	SWITCH_SPEECH_FLAG_HASTEXT =		(1 <<  0),
-	SWITCH_SPEECH_FLAG_PEEK =			(1 <<  1),
-	SWITCH_SPEECH_FLAG_FREE_POOL =		(1 <<  2),
-	SWITCH_SPEECH_FLAG_BLOCKING =		(1 <<  3),
-	SWITCH_SPEECH_FLAG_PAUSE =			(1 <<  4)
+	SWITCH_SPEECH_FLAG_NONE = 0,
+	SWITCH_SPEECH_FLAG_HASTEXT = (1 << 0),
+	SWITCH_SPEECH_FLAG_PEEK = (1 << 1),
+	SWITCH_SPEECH_FLAG_FREE_POOL = (1 << 2),
+	SWITCH_SPEECH_FLAG_BLOCKING = (1 << 3),
+	SWITCH_SPEECH_FLAG_PAUSE = (1 << 4)
 
 } switch_speech_flag_t;
 
@@ -662,12 +651,12 @@
 </pre>
 */
 typedef enum {
-	SWITCH_ASR_FLAG_NONE =			0,
-	SWITCH_ASR_FLAG_DATA =			(1 <<  0),
-	SWITCH_ASR_FLAG_FREE_POOL =		(1 <<  1),
-	SWITCH_ASR_FLAG_CLOSED =		(1 <<  2),
-	SWITCH_ASR_FLAG_FIRE_EVENTS =	(1 <<  3),
-	SWITCH_ASR_FLAG_AUTO_RESUME = 	(1 <<  4)
+	SWITCH_ASR_FLAG_NONE = 0,
+	SWITCH_ASR_FLAG_DATA = (1 << 0),
+	SWITCH_ASR_FLAG_FREE_POOL = (1 << 1),
+	SWITCH_ASR_FLAG_CLOSED = (1 << 2),
+	SWITCH_ASR_FLAG_FIRE_EVENTS = (1 << 3),
+	SWITCH_ASR_FLAG_AUTO_RESUME = (1 << 4)
 } switch_asr_flag_t;
 
 /*!
@@ -678,7 +667,7 @@
 </pre>
 */
 typedef enum {
-	SWITCH_DIRECTORY_FLAG_FREE_POOL =		(1 <<  0),
+	SWITCH_DIRECTORY_FLAG_FREE_POOL = (1 << 0),
 
 } switch_directory_flag_t;
 
@@ -708,7 +697,7 @@
 </pre>
 */
 typedef enum {
-		SWITCH_TIMER_FLAG_FREE_POOL =		(1 <<  0),
+	SWITCH_TIMER_FLAG_FREE_POOL = (1 << 0),
 } switch_timer_flag_t;
 
 
@@ -747,18 +736,18 @@
 </pre>
  */
 typedef enum {
-	SWITCH_FILE_FLAG_READ =			(1 <<  0),
-	SWITCH_FILE_FLAG_WRITE =		(1 <<  1),
-	SWITCH_FILE_FLAG_FREE_POOL =	(1 <<  2),
-	SWITCH_FILE_DATA_SHORT =		(1 <<  3),
-	SWITCH_FILE_DATA_INT =			(1 <<  4),
-	SWITCH_FILE_DATA_FLOAT =		(1 <<  5),
-	SWITCH_FILE_DATA_DOUBLE =		(1 <<  6),
-	SWITCH_FILE_DATA_RAW =			(1 <<  7),
-	SWITCH_FILE_PAUSE =				(1 <<  8),
-	SWITCH_FILE_NATIVE = 			(1 <<  9),
-	SWITCH_FILE_SEEK = 				(1 << 10),
-	SWITCH_FILE_OPEN =				(1 << 11)
+	SWITCH_FILE_FLAG_READ = (1 << 0),
+	SWITCH_FILE_FLAG_WRITE = (1 << 1),
+	SWITCH_FILE_FLAG_FREE_POOL = (1 << 2),
+	SWITCH_FILE_DATA_SHORT = (1 << 3),
+	SWITCH_FILE_DATA_INT = (1 << 4),
+	SWITCH_FILE_DATA_FLOAT = (1 << 5),
+	SWITCH_FILE_DATA_DOUBLE = (1 << 6),
+	SWITCH_FILE_DATA_RAW = (1 << 7),
+	SWITCH_FILE_PAUSE = (1 << 8),
+	SWITCH_FILE_NATIVE = (1 << 9),
+	SWITCH_FILE_SEEK = (1 << 10),
+	SWITCH_FILE_OPEN = (1 << 11)
 } switch_file_flag_t;
 
 typedef enum {
@@ -809,6 +798,10 @@
 	SWITCH_EVENT_PRIVATE_COMMAND	- A private command event 
 	SWITCH_EVENT_HEARTBEAT			- Machine is alive
 	SWITCH_EVENT_TRAP				- Error Trap
+	SWITCH_EVENT_ADD_SCHEDULE		- Something has been scheduled
+	SWITCH_EVENT_DEL_SCHEDULE		- Something has been unscheduled
+	SWITCH_EVENT_EXE_SCHEDULE		- Something scheduled has been executed
+	SWITCH_EVENT_RE_SCHEDULE		- Something scheduled has been rescheduled
     SWITCH_EVENT_ALL				- All events at once
 </pre>
 
@@ -851,6 +844,10 @@
 	SWITCH_EVENT_PRIVATE_COMMAND,
 	SWITCH_EVENT_HEARTBEAT,
 	SWITCH_EVENT_TRAP,
+	SWITCH_EVENT_ADD_SCHEDULE,
+	SWITCH_EVENT_DEL_SCHEDULE,
+	SWITCH_EVENT_EXE_SCHEDULE,
+	SWITCH_EVENT_RE_SCHEDULE,
 	SWITCH_EVENT_ALL
 } switch_event_types_t;
 
@@ -951,19 +948,8 @@
 typedef struct switch_buffer switch_buffer_t;
 typedef struct switch_codec_settings switch_codec_settings_t;
 
-typedef struct switch_io_event_hook_outgoing_channel switch_io_event_hook_outgoing_channel_t;
-typedef struct switch_io_event_hook_answer_channel switch_io_event_hook_answer_channel_t;
-typedef struct switch_io_event_hook_receive_message switch_io_event_hook_receive_message_t;
-typedef struct switch_io_event_hook_receive_event switch_io_event_hook_receive_event_t;
-typedef struct switch_io_event_hook_read_frame switch_io_event_hook_read_frame_t;
-typedef struct switch_io_event_hook_write_frame switch_io_event_hook_write_frame_t;
-typedef struct switch_io_event_hook_kill_channel switch_io_event_hook_kill_channel_t;
-typedef struct switch_io_event_hook_waitfor_read switch_io_event_hook_waitfor_read_t;
-typedef struct switch_io_event_hook_waitfor_write switch_io_event_hook_waitfor_write_t;
-typedef struct switch_io_event_hook_send_dtmf switch_io_event_hook_send_dtmf_t;
-typedef struct switch_io_event_hook_state_change switch_io_event_hook_state_change_t;
+
 typedef struct switch_io_routines switch_io_routines_t;
-typedef struct switch_io_event_hooks switch_io_event_hooks_t;
 typedef struct switch_speech_handle switch_speech_handle_t;
 typedef struct switch_asr_handle switch_asr_handle_t;
 typedef struct switch_directory_handle switch_directory_handle_t;
@@ -982,43 +968,26 @@
 typedef struct switch_management_interface switch_management_interface_t;
 typedef struct switch_core_port_allocator switch_core_port_allocator_t;
 typedef struct switch_media_bug switch_media_bug_t;
-typedef switch_bool_t (*switch_media_bug_callback_t)(switch_media_bug_t *, void *, switch_abc_type_t);
-typedef void (*switch_application_function_t)(switch_core_session_t *, char *);
-typedef void (*switch_event_callback_t)(switch_event_t *);
-typedef switch_caller_extension_t *(*switch_dialplan_hunt_function_t)(switch_core_session_t *, void *);
-typedef struct switch_core_scheduler_task switch_core_scheduler_task_t;
-typedef void (*switch_core_scheduler_func_t)(switch_core_scheduler_task_t *task);
-typedef switch_status_t (*switch_state_handler_t)(switch_core_session_t *);
-typedef switch_status_t (*switch_outgoing_channel_hook_t)(switch_core_session_t *, switch_caller_profile_t *, switch_core_session_t *);
-typedef switch_status_t (*switch_answer_channel_hook_t)(switch_core_session_t *);
-typedef switch_status_t (*switch_receive_message_hook_t)(switch_core_session_t *, switch_core_session_message_t *);
-typedef switch_status_t (*switch_receive_event_hook_t)(switch_core_session_t *, switch_event_t *);
-typedef switch_status_t (*switch_read_frame_hook_t)(switch_core_session_t *, switch_frame_t **, int, switch_io_flag_t, int);
-typedef switch_status_t (*switch_write_frame_hook_t)(switch_core_session_t *, switch_frame_t *, int, switch_io_flag_t, int);
-typedef switch_status_t (*switch_kill_channel_hook_t)(switch_core_session_t *, int);
-typedef switch_status_t (*switch_waitfor_read_hook_t)(switch_core_session_t *, int, int);
-typedef switch_status_t (*switch_waitfor_write_hook_t)(switch_core_session_t *, int, int);
-typedef switch_status_t (*switch_send_dtmf_hook_t)(switch_core_session_t *, char *);
-typedef switch_status_t (*switch_state_change_hook_t)(switch_core_session_t *);
+typedef switch_bool_t (*switch_media_bug_callback_t) (switch_media_bug_t *, void *, switch_abc_type_t);
+typedef void (*switch_application_function_t) (switch_core_session_t *, char *);
+typedef void (*switch_event_callback_t) (switch_event_t *);
+typedef switch_caller_extension_t *(*switch_dialplan_hunt_function_t) (switch_core_session_t *, void *);
+typedef struct switch_scheduler_task switch_scheduler_task_t;
+typedef void (*switch_scheduler_func_t) (switch_scheduler_task_t *task);
+typedef switch_status_t (*switch_state_handler_t) (switch_core_session_t *);
 typedef struct switch_stream_handle switch_stream_handle_t;
-typedef switch_status_t (*switch_stream_handle_write_function_t)(switch_stream_handle_t *handle, const char *fmt, ...);
-typedef switch_status_t (*switch_api_function_t)(char *in, switch_core_session_t *session, switch_stream_handle_t *stream);
-typedef switch_status_t (*switch_input_callback_function_t)(switch_core_session_t *session,
-															void *input,
-															switch_input_type_t input_type,
-															void *buf,
-															unsigned int buflen);
+typedef switch_status_t (*switch_stream_handle_write_function_t) (switch_stream_handle_t *handle, const char *fmt, ...);
+typedef switch_status_t (*switch_api_function_t) (char *in, switch_core_session_t *session, switch_stream_handle_t *stream);
+typedef switch_status_t (*switch_input_callback_function_t) (switch_core_session_t *session, void *input,
+															 switch_input_type_t input_type, void *buf, unsigned int buflen);
 typedef struct switch_say_interface switch_say_interface_t;
 typedef struct {
-    switch_input_callback_function_t input_callback;
-    void *buf;
-    uint32_t buflen;
+	switch_input_callback_function_t input_callback;
+	void *buf;
+	uint32_t buflen;
 } switch_input_args_t;
-typedef switch_status_t (*switch_say_callback_t)(switch_core_session_t *session,
-                                                 char *tosay,
-                                                 switch_say_type_t type,
-                                                 switch_say_method_t method,
-                                                 switch_input_args_t *args);
+typedef switch_status_t (*switch_say_callback_t) (switch_core_session_t *session,
+												  char *tosay, switch_say_type_t type, switch_say_method_t method, switch_input_args_t *args);
 typedef switch_status_t (*switch_module_load_t) (switch_loadable_module_interface_t **, char *);
 typedef switch_status_t (*switch_module_reload_t) (void);
 typedef switch_status_t (*switch_module_pause_t) (void);
@@ -1028,12 +997,9 @@
 typedef switch_status_t (*switch_module_shutdown_t) (void);
 typedef struct switch_xml *switch_xml_t;
 typedef struct switch_core_time_duration switch_core_time_duration_t;
-typedef switch_xml_t (*switch_xml_search_function_t)(const char *section,
-													 const char *tag_name,
-													 const char *key_name,
-													 const char *key_value,
-													 const char *params,
-                                                     void *user_data);
+typedef switch_xml_t(*switch_xml_search_function_t) (const char *section,
+													 const char *tag_name, const char *key_name, const char *key_value, const char *params,
+													 void *user_data);
 
 /* things we don't deserve to know about */
 /*! \brief A channel */
@@ -1046,9 +1012,7 @@
 struct switch_ivr_digit_stream_parser;
 
 SWITCH_END_EXTERN_C
-
 #endif
-
 /* For Emacs:
  * Local Variables:
  * mode:c

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_utils.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_utils.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_utils.h	Fri Mar 30 12:19:18 2007
@@ -41,24 +41,32 @@
 #include <switch.h>
 
 SWITCH_BEGIN_EXTERN_C
-
 #define switch_bytes_per_frame(rate, interval) ((uint32_t)((float)rate / (1000.0f / (float)interval)))
-
 #define SWITCH_SMAX 32767
 #define SWITCH_SMIN -32768
 #define switch_normalize_to_16bit(n) if (n > SWITCH_SMAX) n = SWITCH_SMAX / 2; else if (n < SWITCH_SMIN) n = SWITCH_SMIN / 2;
-
 #define switch_codec2str(codec,buf,len) snprintf(buf, len, "%s@%uk@%ui", \
                                                  codec->implementation->iananame, \
                                                  codec->implementation->samples_per_second, \
                                                  codec->implementation->microseconds_per_frame / 1000)
-
 #ifdef WIN32
 #define switch_is_file_path(file) (*(file +1) == ':' || *file == '/' || strstr(file, SWITCH_URL_SEPARATOR))
 #else
 #define switch_is_file_path(file) ((*file == '/') || strstr(file, SWITCH_URL_SEPARATOR))
 #endif
 
+static inline switch_bool_t switch_is_digit_string(char *s) {
+
+	while(s && *s) {
+		if (*s < 48 || *s > 57) {
+			return SWITCH_FALSE;
+		}
+		s++;
+	}
+
+	return SWITCH_TRUE;
+}
+
 /*!
   \brief Evaluate the truthfullness of a string expression
   \param expr a string expression
@@ -69,7 +77,6 @@
 !strcasecmp(expr, "on") ||\
 !strcasecmp(expr, "true") ||\
 atoi(expr))) ? SWITCH_TRUE : SWITCH_FALSE
-
 /*!
   \brief find local ip of the box
   \param buf the buffer to write the ip adress found into
@@ -233,7 +240,7 @@
   \param ms the number of milliseconds to wait
   \return the requested condition
 */
-SWITCH_DECLARE(int) switch_socket_waitfor(switch_pollfd_t *poll, int ms);
+SWITCH_DECLARE(int) switch_socket_waitfor(switch_pollfd_t * poll, int ms);
 
 /*!
   \brief Create a pointer to the file name in a given file path eliminating the directory name
@@ -247,10 +254,18 @@
 #define SWITCH_READ_ACCEPTABLE(status) (status == SWITCH_STATUS_SUCCESS || status == SWITCH_STATUS_BREAK)
 SWITCH_DECLARE(size_t) switch_url_encode(char *url, char *buf, size_t len);
 SWITCH_DECLARE(char *) switch_url_decode(char *s);
-SWITCH_END_EXTERN_C
 
+/* malloc or DIE macros */
+#ifdef NDEBUG
+#define switch_malloc(ptr, len) (void)( (!!(ptr = malloc(len))) || (fprintf(stderr,"ABORT! Malloc failure at: %s:%s", __FILE__, __LINE__),abort(), 0), ptr )
+#define switch_zmalloc(ptr, len) (void)( (!!(ptr = malloc(len))) || (fprintf(stderr,"ABORT! Malloc failure at: %s:%s", __FILE__, __LINE__),abort(), 0), memset(ptr, 0, len))
+#else
+#define switch_malloc(ptr, len) (void)(assert(((ptr) = malloc((len)))),ptr)
+#define switch_zmalloc(ptr, len) (void)(assert((ptr = malloc(len))),memset(ptr, 0, len))
 #endif
 
+SWITCH_END_EXTERN_C
+#endif
 /* For Emacs:
  * Local Variables:
  * mode:c

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_xml.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_xml.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_xml.h	Fri Mar 30 12:19:18 2007
@@ -62,40 +62,38 @@
 ///\ingroup core1
 ///\{
 SWITCH_BEGIN_EXTERN_C
-
-#define SWITCH_XML_BUFSIZE 1024 // size of internal memory buffers
-
-typedef enum {
-	SWITCH_XML_ROOT =	   (1 << 0), // root
-	SWITCH_XML_NAMEM =  (1 << 1), // name is malloced
-	SWITCH_XML_TXTM =   (1 << 2), // txt is malloced
-	SWITCH_XML_DUP   =  (1 << 3) // attribute name and value are strduped
+#define SWITCH_XML_BUFSIZE 1024	// size of internal memory buffers
+	typedef enum {
+	SWITCH_XML_ROOT = (1 << 0),	// root
+	SWITCH_XML_NAMEM = (1 << 1),	// name is malloced
+	SWITCH_XML_TXTM = (1 << 2),	// txt is malloced
+	SWITCH_XML_DUP = (1 << 3)	// attribute name and value are strduped
 } switch_xml_flag_t;
 
 /*! \brief A representation of an XML tree */
 struct switch_xml {
 	/*! tag name */
-    char *name;      
+	char *name;
 	/*! tag attributes { name, value, name, value, ... NULL } */
-    char **attr;
+	char **attr;
 	/*! tag character content, empty string if none */
-    char *txt;
-    /*! path to free on destroy*/
-    char *free_path;
+	char *txt;
+	/*! path to free on destroy */
+	char *free_path;
 	/*! tag offset from start of parent tag character content */
-    switch_size_t off;
+	switch_size_t off;
 	/*! next tag with same name in this section at this depth */
-    switch_xml_t next;
-	/*! next tag with different name in same section and depth*/
-    switch_xml_t sibling;
+	switch_xml_t next;
+	/*! next tag with different name in same section and depth */
+	switch_xml_t sibling;
 	/*! next tag, same section and depth, in original order */
-    switch_xml_t ordered;
-	/*! head of sub tag list, NULL if none*/
-    switch_xml_t child;
-	/*! parent tag, NULL if current tag is root tag*/
-    switch_xml_t parent;
+	switch_xml_t ordered;
+	/*! head of sub tag list, NULL if none */
+	switch_xml_t child;
+	/*! parent tag, NULL if current tag is root tag */
+	switch_xml_t parent;
 	/*! flags */
-    uint32_t flags;
+	uint32_t flags;
 };
 
 ///\brief Given a string of xml data and its length, parses it and creates an switch_xml
@@ -118,13 +116,13 @@
 ///\param file a file to parse
 ///\return a formated xml node or NULL
 SWITCH_DECLARE(switch_xml_t) switch_xml_parse_file(const char *file);
-    
+
 ///\brief Wrapper for switch_xml_parse_str() that accepts a file stream. Reads the entire
 ///\ stream into memory and then parses it. For xml files, use switch_xml_parse_file()
 ///\ or switch_xml_parse_fd()
 ///\param fp a FILE pointer to parse
 ///\return an xml node or NULL
-SWITCH_DECLARE(switch_xml_t) switch_xml_parse_fp(FILE *fp);
+SWITCH_DECLARE(switch_xml_t) switch_xml_parse_fp(FILE * fp);
 
 ///\brief returns the first child tag (one level deeper) with the given name or NULL
 ///\ if not found
@@ -152,7 +150,7 @@
 ///\param xml the xml node
 ///\param idx the index
 ///\return an xml node or NULL
-switch_xml_t switch_xml_idx(switch_xml_t xml, int idx);
+	 switch_xml_t switch_xml_idx(switch_xml_t xml, int idx);
 
 ///\brief returns the name of the given tag
 ///\param xml the xml node
@@ -184,7 +182,7 @@
 ///\ Returns NULL if not found.
 ///\param xml the xml node
 ///\return an xml node or NULL
-SWITCH_DECLARE(switch_xml_t) switch_xml_get(switch_xml_t xml, ...);
+SWITCH_DECLARE(switch_xml_t) switch_xml_get(switch_xml_t xml,...);
 
 ///\brief Converts an switch_xml structure back to xml. Returns a string of xml data that
 ///\ must be freed.
@@ -203,7 +201,7 @@
 ///\param xml the xml node
 ///\note in the case of the root node the readlock will be lifted
 SWITCH_DECLARE(void) switch_xml_free(switch_xml_t xml);
-    
+
 ///\brief returns parser error message or empty string if none
 ///\param xml the xml node
 ///\return the error string or nothing
@@ -224,7 +222,7 @@
 ///\param name the name of the tag
 ///\param off the offset
 ///\return an xml node or NULL
-switch_xml_t switch_xml_add_child(switch_xml_t xml, const char *name, switch_size_t off);
+	 switch_xml_t switch_xml_add_child(switch_xml_t xml, const char *name, switch_size_t off);
 
 ///\brief wrapper for switch_xml_add_child() that strdup()s name
 ///\param xml the xml node
@@ -237,7 +235,7 @@
 ///\param xml the xml node
 ///\param txt the text
 ///\return an xml node or NULL
-switch_xml_t switch_xml_set_txt(switch_xml_t xml, const char *txt);
+	 switch_xml_t switch_xml_set_txt(switch_xml_t xml, const char *txt);
 
 ///\brief wrapper for switch_xml_set_txt() that strdup()s txt
 ///\ sets the character content for the given tag and returns the tag
@@ -314,18 +312,15 @@
 ///\return SWITCH_STATUS_SUCCESS if successful root and node will be assigned
 SWITCH_DECLARE(switch_status_t) switch_xml_locate(const char *section,
 												  const char *tag_name,
-												  const char *key_name,
-												  const char *key_value,
-												  switch_xml_t *root,
-												  switch_xml_t *node,
+												  const char *key_name, const char *key_value, switch_xml_t * root, switch_xml_t * node,
 												  const char *params);
-												 
+
 ///\brief open a config in the core registry
 ///\param file_path the name of the config section e.g. modules.conf
 ///\param node a pointer to point to the node if it is found
 ///\param params optional URL formatted params to pass to external gateways
 ///\return the root xml node associated with the current request or NULL
-SWITCH_DECLARE(switch_xml_t) switch_xml_open_cfg(const char *file_path, switch_xml_t *node, const char *params);
+SWITCH_DECLARE(switch_xml_t) switch_xml_open_cfg(const char *file_path, switch_xml_t * node, const char *params);
 
 ///\brief bind a search function to an external gateway
 ///\param function the search function to bind
@@ -341,11 +336,8 @@
 SWITCH_DECLARE(switch_xml_section_t) switch_xml_parse_section_string(const char *str);
 
 SWITCH_END_EXTERN_C
-
 ///\}
-
 #endif // _SWITCH_XML_H
-
 /* For Emacs:
  * Local Variables:
  * mode:c

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_bridgecall/mod_bridgecall.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_bridgecall/mod_bridgecall.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_bridgecall/mod_bridgecall.c	Fri Mar 30 12:19:18 2007
@@ -44,11 +44,11 @@
 	char *var;
 	uint8_t no_media_bridge = 0;
 	switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING;
-    uint8_t do_continue = 0;
+	uint8_t do_continue = 0;
 
-    if (switch_strlen_zero(data)) {
-        return;
-    }
+	if (switch_strlen_zero(data)) {
+		return;
+	}
 
 	caller_channel = switch_core_session_get_channel(session);
 	assert(caller_channel != NULL);
@@ -60,9 +60,11 @@
 	if ((var = switch_channel_get_variable(caller_channel, "continue_on_fail"))) {
 		do_continue = switch_true(var);
 	}
-	
-	if ((var = switch_channel_get_variable(caller_channel, "no_media")) && switch_true(var)) {
-		if (!switch_channel_test_flag(caller_channel, CF_ANSWERED) && !switch_channel_test_flag(caller_channel, CF_EARLY_MEDIA)) {
+
+	if (switch_channel_test_flag(caller_channel, CF_NOMEDIA)
+		|| ((var = switch_channel_get_variable(caller_channel, "no_media")) && switch_true(var))) {
+		if (!switch_channel_test_flag(caller_channel, CF_ANSWERED)
+			&& !switch_channel_test_flag(caller_channel, CF_EARLY_MEDIA)) {
 			switch_channel_set_flag(caller_channel, CF_NOMEDIA);
 		} else {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Channel is already up, delaying point-to-point mode 'till both legs are up.\n");
@@ -72,31 +74,33 @@
 
 	if (switch_ivr_originate(session, &peer_session, &cause, data, timelimit, NULL, NULL, NULL, NULL) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Originate Failed.  Cause: %s\n", switch_channel_cause2str(cause));
-        if (!do_continue && cause != SWITCH_CAUSE_NO_ANSWER) {
-            /* All Causes besides NO_ANSWER terminate the originating session unless continue_on_fail is set.
-               We will pass the fail cause on when we hangup.*/
-            switch_channel_hangup(caller_channel, cause);
-        }
-        /* Otherwise.. nobody answered.  Go back to the dialplan instructions in case there was more to do. */
+		if (!do_continue && cause != SWITCH_CAUSE_NO_ANSWER) {
+			/* All Causes besides NO_ANSWER terminate the originating session unless continue_on_fail is set.
+			   We will pass the fail cause on when we hangup. */
+			switch_channel_hangup(caller_channel, cause);
+		}
+		/* Otherwise.. nobody answered.  Go back to the dialplan instructions in case there was more to do. */
 		return;
 	} else {
 		if (no_media_bridge) {
-            switch_channel_t *peer_channel = switch_core_session_get_channel(peer_session);
-            switch_frame_t *read_frame;
-            /* SIP won't let us redir media until the call has been answered #$^#%& so we will proxy any early media until they do */
-            while(switch_channel_ready(caller_channel) && switch_channel_ready(peer_channel) && !switch_channel_test_flag(peer_channel, CF_ANSWERED)) {
-                switch_status_t status = switch_core_session_read_frame(peer_session, &read_frame, -1, 0);
-                uint8_t bad = 1;
-
-                if (SWITCH_READ_ACCEPTABLE(status) && switch_core_session_write_frame(session, read_frame, -1, 0) == SWITCH_STATUS_SUCCESS) {
-                    bad = 0;
-                }
-                if (bad) {
-                    switch_channel_hangup(caller_channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-                    switch_channel_hangup(peer_channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-                    return;
-                }
-            }
+			switch_channel_t *peer_channel = switch_core_session_get_channel(peer_session);
+			switch_frame_t *read_frame;
+			/* SIP won't let us redir media until the call has been answered #$^#%& so we will proxy any early media until they do */
+			while (switch_channel_ready(caller_channel) && switch_channel_ready(peer_channel)
+				   && !switch_channel_test_flag(peer_channel, CF_ANSWERED)) {
+				switch_status_t status = switch_core_session_read_frame(peer_session, &read_frame, -1, 0);
+				uint8_t bad = 1;
+
+				if (SWITCH_READ_ACCEPTABLE(status)
+					&& switch_core_session_write_frame(session, read_frame, -1, 0) == SWITCH_STATUS_SUCCESS) {
+					bad = 0;
+				}
+				if (bad) {
+					switch_channel_hangup(caller_channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+					switch_channel_hangup(peer_channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+					return;
+				}
+			}
 
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Redirecting media to point-to-point mode.\n");
 			switch_ivr_nomedia(switch_core_session_get_uuid(session), SMF_FORCE);

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_commands/mod_commands.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_commands/mod_commands.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_commands/mod_commands.c	Fri Mar 30 12:19:18 2007
@@ -76,18 +76,15 @@
 		stream->write_function(stream, "<h1>FreeSWITCH Status</h1>\n<b>");
 	}
 
-	stream->write_function(stream, "UP %u year%s, %u day%s, %u hour%s, %u minute%s, %u second%s, %u millisecond%s, %u microsecond%s\n",
-						   duration.yr, duration.yr == 1 ? "" : "s",
-						   duration.day, duration.day == 1 ? "" : "s",
-						   duration.hr, duration.hr == 1 ? "" : "s",
-						   duration.min, duration.min == 1 ? "" : "s",
-						   duration.sec, duration.sec == 1 ? "" : "s",
-						   duration.ms, duration.ms == 1 ? "" : "s",
-						   duration.mms, duration.mms == 1 ? "" : "s"
-						   );
+	stream->write_function(stream,
+						   "UP %u year%s, %u day%s, %u hour%s, %u minute%s, %u second%s, %u millisecond%s, %u microsecond%s\n",
+						   duration.yr, duration.yr == 1 ? "" : "s", duration.day, duration.day == 1 ? "" : "s",
+						   duration.hr, duration.hr == 1 ? "" : "s", duration.min, duration.min == 1 ? "" : "s",
+						   duration.sec, duration.sec == 1 ? "" : "s", duration.ms, duration.ms == 1 ? "" : "s", duration.mms,
+						   duration.mms == 1 ? "" : "s");
 
 	stream->write_function(stream, "%d sessions\n", switch_core_session_count());
-	
+
 	if (html) {
 		stream->write_function(stream, "</b>\n");
 	}
@@ -98,7 +95,7 @@
 			int r;
 			refresh++;
 			r = atoi(refresh);
-			if (r > 0) { 
+			if (r > 0) {
 				stream->write_function(stream, "<META HTTP-EQUIV=REFRESH CONTENT=\"%d; URL=/api/status?refresh=%d%s\">\n", r, r, html ? "html=1" : "");
 			}
 		}
@@ -120,7 +117,7 @@
 
 	if ((mydata = strdup(data))) {
 		argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
-	
+
 		if (!strcmp(argv[0], "hupall")) {
 			arg = 1;
 			switch_core_session_ctl(SCSC_HUPALL, &arg);
@@ -136,17 +133,17 @@
 		} else {
 			stream->write_function(stream, "INVALID COMMAND [%s]\nUSAGE: fsctl [hupall|pause|resume|shutdown]\n", argv[0]);
 			goto end;
-		} 
+		}
 
 		stream->write_function(stream, "OK\n");
-	end:
+	  end:
 		free(mydata);
 	} else {
 		stream->write_function(stream, "MEM ERR\n");
 	}
 
-    return SWITCH_STATUS_SUCCESS;
-	
+	return SWITCH_STATUS_SUCCESS;
+
 }
 
 static switch_status_t load_function(char *mod, switch_core_session_t *session, switch_stream_handle_t *stream)
@@ -178,11 +175,11 @@
 	if (session) {
 		return SWITCH_STATUS_FALSE;
 	}
-	
+
 	if ((xml_root = switch_xml_open_root(1, &err))) {
 		switch_xml_free(xml_root);
 	}
-	
+
 	stream->write_function(stream, "OK [%s]\n", err);
 
 	return SWITCH_STATUS_SUCCESS;
@@ -213,13 +210,13 @@
 static switch_status_t transfer_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
 {
 	switch_core_session_t *session = NULL;
-	char *argv[4] = {0};
+	char *argv[4] = { 0 };
 	int argc = 0;
 
 	if (isession) {
 		return SWITCH_STATUS_FALSE;
 	}
-	
+
 	argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
 
 	if (switch_strlen_zero(cmd) || argc < 2 || argc > 4) {
@@ -229,11 +226,11 @@
 		char *dest = argv[1];
 		char *dp = argv[2];
 		char *context = argv[3];
-		
+
 		if ((session = switch_core_session_locate(uuid))) {
 
 			if (switch_ivr_session_transfer(session, dest, dp, context) == SWITCH_STATUS_SUCCESS) {
-				 stream->write_function(stream, "OK\n");
+				stream->write_function(stream, "OK\n");
 			} else {
 				stream->write_function(stream, "ERROR\n");
 			}
@@ -252,13 +249,13 @@
 static switch_status_t sched_transfer_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
 {
 	switch_core_session_t *session = NULL;
-	char *argv[6] = {0};
+	char *argv[6] = { 0 };
 	int argc = 0;
 
 	if (isession) {
 		return SWITCH_STATUS_FALSE;
 	}
-	
+
 	argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
 
 	if (switch_strlen_zero(cmd) || argc < 2 || argc > 5) {
@@ -269,9 +266,9 @@
 		char *dp = argv[3];
 		char *context = argv[4];
 		time_t when;
-		
+
 		if (*argv[0] == '+') {
-			when = time (NULL) + atol(argv[0] + 1);
+			when = time(NULL) + atol(argv[0] + 1);
 		} else {
 			when = atol(argv[0]);
 		}
@@ -291,13 +288,13 @@
 static switch_status_t sched_hangup_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
 {
 	switch_core_session_t *session = NULL;
-	char *argv[4] = {0};
+	char *argv[4] = { 0 };
 	int argc = 0;
 
 	if (isession) {
 		return SWITCH_STATUS_FALSE;
 	}
-	
+
 	argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
 
 	if (switch_strlen_zero(cmd) || argc < 1) {
@@ -309,7 +306,7 @@
 		switch_call_cause_t cause = SWITCH_CAUSE_ALLOTTED_TIMEOUT;
 
 		if (*argv[0] == '+') {
-			when = time (NULL) + atol(argv[0] + 1);
+			when = time(NULL) + atol(argv[0] + 1);
 		} else {
 			when = atol(argv[0]);
 		}
@@ -333,14 +330,14 @@
 
 static switch_status_t uuid_media_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
 {
-	char *argv[4] = {0};
+	char *argv[4] = { 0 };
 	int argc = 0;
 	switch_status_t status = SWITCH_STATUS_FALSE;
-	
+
 	if (isession) {
 		return status;
 	}
-	
+
 	argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
 
 	if (switch_strlen_zero(cmd) || argc < 1) {
@@ -365,14 +362,14 @@
 
 static switch_status_t uuid_broadcast_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
 {
-	char *argv[4] = {0};
+	char *argv[4] = { 0 };
 	int argc = 0;
 	switch_status_t status = SWITCH_STATUS_FALSE;
 
 	if (isession) {
 		return status;
 	}
-	
+
 	argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
 
 	if (switch_strlen_zero(cmd) || argc < 2) {
@@ -391,7 +388,7 @@
 		} else {
 			flags |= SMF_ECHO_ALEG;
 		}
-		
+
 		status = switch_ivr_broadcast(argv[0], argv[1], flags);
 		stream->write_function(stream, "+OK Message Sent\n");
 	}
@@ -402,14 +399,14 @@
 
 static switch_status_t sched_broadcast_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
 {
-	char *argv[4] = {0};
+	char *argv[4] = { 0 };
 	int argc = 0;
 	switch_status_t status = SWITCH_STATUS_FALSE;
 
 	if (isession) {
 		return status;
 	}
-	
+
 	argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
 
 	if (switch_strlen_zero(cmd) || argc < 3) {
@@ -419,7 +416,7 @@
 		time_t when;
 
 		if (*argv[0] == '+') {
-			when = time (NULL) + atol(argv[0] + 1);
+			when = time(NULL) + atol(argv[0] + 1);
 		} else {
 			when = atol(argv[0]);
 		}
@@ -435,7 +432,7 @@
 		} else {
 			flags |= SMF_ECHO_ALEG;
 		}
-		
+
 		status = switch_ivr_schedule_broadcast(when, argv[1], argv[2], flags);
 		stream->write_function(stream, "+OK Message Scheduled\n");
 	}
@@ -445,14 +442,14 @@
 
 static switch_status_t uuid_hold_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
 {
-	char *argv[4] = {0};
+	char *argv[4] = { 0 };
 	int argc = 0;
 	switch_status_t status = SWITCH_STATUS_FALSE;
-	
+
 	if (isession) {
 		return status;
 	}
-	
+
 	argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
 
 	if (switch_strlen_zero(cmd) || argc < 1) {
@@ -476,13 +473,13 @@
 
 static switch_status_t uuid_bridge_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
 {
-	char *argv[4] = {0};
+	char *argv[4] = { 0 };
 	int argc = 0;
 
 	if (isession) {
 		return SWITCH_STATUS_FALSE;
 	}
-	
+
 	argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
 
 	if (switch_strlen_zero(cmd) || argc != 2) {
@@ -498,70 +495,70 @@
 
 static switch_status_t session_record_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
 {
-    switch_core_session_t *session = NULL;
-	char *argv[4] = {0};
-    char *uuid = NULL, *action = NULL, *path = NULL;
+	switch_core_session_t *session = NULL;
+	char *argv[4] = { 0 };
+	char *uuid = NULL, *action = NULL, *path = NULL;
 	int argc = 0;
 
 	if (isession) {
 		return SWITCH_STATUS_FALSE;
 	}
-	
+
 	if (switch_strlen_zero(cmd)) {
-        goto usage;
-    }
+		goto usage;
+	}
 
 	if ((argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) != 3) {
-        goto usage;
-    }
+		goto usage;
+	}
+
+	uuid = argv[0];
+	action = argv[1];
+	path = argv[2];
 
-    uuid = argv[0];
-    action = argv[1];
-    path = argv[2];
-    
-    if (!(session = switch_core_session_locate(uuid))) {
+	if (!(session = switch_core_session_locate(uuid))) {
 		stream->write_function(stream, "-Error Cannot locate session!\n");
-        return SWITCH_STATUS_SUCCESS;
-    }
-    
-    if (switch_strlen_zero(action) || switch_strlen_zero(path)) {
-        goto usage;
-    }
-
-    if (!strcasecmp(action, "start")) {
-        switch_ivr_record_session(session, path, NULL);
-    } else if (!strcasecmp(action, "stop")) {
-        switch_ivr_stop_record_session(session, path);
-    } else {
-        goto usage;
-    }
-
-    goto done;
-
- usage:
-
-    stream->write_function(stream, "USAGE: %s\n", session_record_api_interface.syntax);
-    return SWITCH_STATUS_SUCCESS;
-
- done:
-
-    if (session) {
-        switch_core_session_rwunlock(session);
-    }
+		return SWITCH_STATUS_SUCCESS;
+	}
+
+	if (switch_strlen_zero(action) || switch_strlen_zero(path)) {
+		goto usage;
+	}
+
+	if (!strcasecmp(action, "start")) {
+		switch_ivr_record_session(session, path, NULL);
+	} else if (!strcasecmp(action, "stop")) {
+		switch_ivr_stop_record_session(session, path);
+	} else {
+		goto usage;
+	}
+
+	goto done;
+
+  usage:
+
+	stream->write_function(stream, "USAGE: %s\n", session_record_api_interface.syntax);
+	return SWITCH_STATUS_SUCCESS;
+
+  done:
+
+	if (session) {
+		switch_core_session_rwunlock(session);
+	}
 
-    return SWITCH_STATUS_SUCCESS;
+	return SWITCH_STATUS_SUCCESS;
 }
 
 static switch_status_t pause_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
 {
 	switch_core_session_t *session = NULL;
-	char *argv[4] = {0};
+	char *argv[4] = { 0 };
 	int argc = 0;
 
 	if (isession) {
 		return SWITCH_STATUS_FALSE;
 	}
-	
+
 	argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
 
 	if (switch_strlen_zero(cmd) || argc < 2) {
@@ -569,7 +566,7 @@
 	} else {
 		char *uuid = argv[0];
 		char *dest = argv[1];
-		
+
 		if ((session = switch_core_session_locate(uuid))) {
 			switch_channel_t *channel = switch_core_session_get_channel(session);
 
@@ -593,7 +590,7 @@
 {
 	switch_channel_t *caller_channel;
 	switch_core_session_t *caller_session;
-	char *argv[7] = {0};
+	char *argv[7] = { 0 };
 	int i = 0, x, argc = 0;
 	char *aleg, *exten, *dp, *context, *cid_name, *cid_num;
 	uint32_t timeout = 60;
@@ -612,12 +609,12 @@
 		return SWITCH_STATUS_SUCCESS;
 	}
 
-	for(x = 0; x < argc; x++) {
+	for (x = 0; x < argc; x++) {
 		if (!strcasecmp(argv[x], "undef")) {
 			argv[x] = NULL;
 		}
 	}
-	
+
 	if (!strcasecmp(argv[0], "machine")) {
 		machine = 1;
 		i++;
@@ -629,7 +626,7 @@
 	context = argv[i++];
 	cid_name = argv[i++];
 	cid_num = argv[i++];
-	
+
 	if (!dp) {
 		dp = "XML";
 	}
@@ -649,13 +646,13 @@
 			stream->write_function(stream, "Cannot Create Outgoing Channel! [%s] cause: %s\n", aleg, switch_channel_cause2str(cause));
 		}
 		return SWITCH_STATUS_SUCCESS;
-	} 
+	}
 
 	caller_channel = switch_core_session_get_channel(caller_session);
 	assert(caller_channel != NULL);
 	switch_channel_clear_state_handler(caller_channel, NULL);
 
-	if (*exten == '&'  && *(exten + 1)) {
+	if (*exten == '&' && *(exten + 1)) {
 		switch_caller_extension_t *extension = NULL;
 		char *app_name = switch_core_session_strdup(caller_session, (exten + 1));
 		char *arg = NULL, *e;
@@ -689,6 +686,83 @@
 	return SWITCH_STATUS_SUCCESS;;
 }
 
+static void sch_api_callback(switch_scheduler_task_t *task)
+{
+	char *cmd, *arg = NULL;
+	switch_stream_handle_t stream = { 0 };
+
+	assert(task);
+
+	cmd = (char *) task->cmd_arg;
+
+	if ((arg = strchr(cmd, ' '))) {
+		*arg++ = '\0';
+	}
+
+	SWITCH_STANDARD_STREAM(stream);
+	switch_api_execute(cmd, arg, NULL, &stream);
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Command %s(%s):\n%s\n", cmd, arg, switch_str_nil((char *) stream.data));
+	switch_safe_free(stream.data);
+}
+
+static switch_status_t sched_del_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
+{
+	uint32_t cnt = 0;
+	
+	if (switch_is_digit_string(cmd)) {
+		int64_t tmp;
+		tmp = (uint32_t) atoi(cmd);
+		if (tmp > 0) {
+			cnt = switch_scheduler_del_task_id((uint32_t)tmp);
+		}
+	} else {
+		cnt = switch_scheduler_del_task_group(cmd);
+	}
+
+	stream->write_function(stream, "DELETED: %u\n", cnt);
+
+	return SWITCH_STATUS_SUCCESS;
+}
+
+static switch_status_t sched_api_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
+{
+	char *tm = NULL, *dcmd, *group;
+	time_t when;
+
+	assert(cmd != NULL);
+	tm = strdup(cmd);
+	assert(tm != NULL);
+
+	if ((group = strchr(tm, ' '))) {
+		uint32_t id;
+
+		*group++ = '\0';
+
+		if ((dcmd = strchr(group, ' '))) {
+			*dcmd++ = '\0';
+
+			if (*tm == '+') {
+				when = time(NULL) + atol(tm + 1);
+			} else {
+				when = atol(tm);
+			}
+		
+			id = switch_scheduler_add_task(when, sch_api_callback, (char *) __SWITCH_FUNC__, group, 0, strdup(dcmd), SSHF_FREE_ARG);
+			stream->write_function(stream, "ADDED: %u\n", id);
+			goto good;
+		} 
+	}
+
+	stream->write_function(stream, "Invalid syntax\n");
+
+ good:
+
+	switch_safe_free(tm);
+
+	return SWITCH_STATUS_SUCCESS;
+}
+
+
 struct holder {
 	switch_stream_handle_t *stream;
 	char *http;
@@ -696,7 +770,8 @@
 	int print_title;
 };
 
-static int show_callback(void *pArg, int argc, char **argv, char **columnNames){
+static int show_callback(void *pArg, int argc, char **argv, char **columnNames)
+{
 	struct holder *holder = (struct holder *) pArg;
 	int x;
 
@@ -706,7 +781,7 @@
 			holder->stream->write_function(holder->stream, "\n<tr>");
 		}
 
-		for(x = 0; x < argc; x++) {
+		for (x = 0; x < argc; x++) {
 			if (holder->http) {
 				holder->stream->write_function(holder->stream, "<td>");
 				holder->stream->write_function(holder->stream, "<b>%s</b>%s", columnNames[x], x == (argc - 1) ? "</td></tr>\n" : "</td><td>");
@@ -714,13 +789,13 @@
 				holder->stream->write_function(holder->stream, "%s%s", columnNames[x], x == (argc - 1) ? "\n" : ",");
 			}
 		}
-	} 
+	}
 
 	if (holder->http) {
 		holder->stream->write_function(holder->stream, "<tr bgcolor=%s>", holder->count % 2 == 0 ? "eeeeee" : "ffffff");
 	}
 
-	for(x = 0; x < argc; x++) {
+	for (x = 0; x < argc; x++) {
 		if (holder->http) {
 			holder->stream->write_function(holder->stream, "<td>");
 			holder->stream->write_function(holder->stream, "%s%s", argv[x] ? argv[x] : "", x == (argc - 1) ? "</td></tr>\n" : "</td><td>");
@@ -738,7 +813,7 @@
 	char sql[1024];
 	char *errmsg;
 	switch_core_db_t *db = switch_core_db_handle();
-	struct holder holder = {0};
+	struct holder holder = { 0 };
 	int help = 0;
 
 	if (session) {
@@ -747,7 +822,7 @@
 
 	if (stream->event) {
 		holder.http = switch_event_get_header(stream->event, "http-host");
-	} 
+	}
 
 	holder.print_title = 1;
 
@@ -756,14 +831,16 @@
 	if (!cmd) {
 		stream->write_function(stream, "USAGE: %s\n", show_api_interface.syntax);
 		return SWITCH_STATUS_SUCCESS;
-	} else if ( !strcmp(cmd,"codec") || !strcmp(cmd,"dialplan") || !strcmp(cmd,"file") || !strcmp(cmd,"timer")) {
-		sprintf (sql, "select type, name from interfaces where type = '%s'", cmd);
-	} else if (!strcmp(cmd,"application") || !strcmp(cmd,"api")) {
-		sprintf (sql, "select name, description, syntax from interfaces where type = '%s' and description != ''" , cmd);
-	} else if ( !strcmp(cmd,"calls")) {
-		sprintf (sql, "select * from calls");
-	} else if ( !strcmp(cmd,"channels")) {
-		sprintf (sql, "select * from channels");
+	} else if (!strcmp(cmd, "codec") || !strcmp(cmd, "dialplan") || !strcmp(cmd, "file") || !strcmp(cmd, "timer")) {
+		sprintf(sql, "select type, name from interfaces where type = '%s'", cmd);
+	} else if (!strcmp(cmd, "tasks")) {
+		sprintf(sql, "select * from %s", cmd);
+	} else if (!strcmp(cmd, "application") || !strcmp(cmd, "api")) {
+		sprintf(sql, "select name, description, syntax from interfaces where type = '%s' and description != ''", cmd);
+	} else if (!strcmp(cmd, "calls")) {
+		sprintf(sql, "select * from calls");
+	} else if (!strcmp(cmd, "channels")) {
+		sprintf(sql, "select * from channels");
 	} else if (!strncasecmp(cmd, "help", 4)) {
 		char *cmdname = NULL;
 
@@ -771,15 +848,15 @@
 		holder.print_title = 0;
 		if ((cmdname = strchr(cmd, ' ')) != 0) {
 			*cmdname++ = '\0';
-			snprintf (sql, sizeof(sql) - 1, "select name, syntax, description from interfaces where type = 'api' and name = '%s'", cmdname);
+			snprintf(sql, sizeof(sql) - 1, "select name, syntax, description from interfaces where type = 'api' and name = '%s'", cmdname);
 		} else {
-			snprintf (sql, sizeof(sql) - 1, "select name, syntax, description from interfaces where type = 'api'");
+			snprintf(sql, sizeof(sql) - 1, "select name, syntax, description from interfaces where type = 'api'");
 		}
 	} else {
 		stream->write_function(stream, "USAGE: %s\n", show_api_interface.syntax);
 		return SWITCH_STATUS_SUCCESS;
 	}
-    
+
 	holder.stream = stream;
 	holder.count = 0;
 
@@ -794,7 +871,7 @@
 	}
 
 	if (errmsg) {
-		stream->write_function(stream, "SQL ERR [%s]\n",errmsg);
+		stream->write_function(stream, "SQL ERR [%s]\n", errmsg);
 		switch_core_db_free(errmsg);
 		errmsg = NULL;
 	} else if (help) {
@@ -811,7 +888,7 @@
 static switch_status_t version_function(char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream)
 {
 	char version_string[1024];
-	snprintf(version_string, sizeof(version_string) - 1,  "FreeSwitch Version %s\n", SWITCH_VERSION_FULL);
+	snprintf(version_string, sizeof(version_string) - 1, "FreeSwitch Version %s\n", SWITCH_VERSION_FULL);
 
 	stream->write_function(stream, version_string);
 	return SWITCH_STATUS_SUCCESS;
@@ -822,10 +899,10 @@
 	char showcmd[1024];
 	int all = 0;
 	if (switch_strlen_zero(cmd)) {
-		sprintf (showcmd, "help");
+		sprintf(showcmd, "help");
 		all = 1;
 	} else {
-		snprintf(showcmd, sizeof(showcmd) -1, "help %s", cmd);
+		snprintf(showcmd, sizeof(showcmd) - 1, "help %s", cmd);
 	}
 
 	if (all) {
@@ -837,12 +914,28 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
+static switch_api_interface_t sched_del_api_interface = {
+	/*.interface_name */ "sched_del",
+	/*.desc */ "Delete a Scheduled task",
+	/*.function */ sched_del_function,
+	/*.syntax */ "<task_id>|<group_id>",
+	/*.next */ NULL
+};
+
+static switch_api_interface_t sched_api_api_interface = {
+	/*.interface_name */ "sched_api",
+	/*.desc */ "Schedule an api command",
+	/*.function */ sched_api_function,
+	/*.syntax */ "[+]<time> <group_name> <command_string>",
+	/*.next */ &sched_del_api_interface
+};
+
 static switch_api_interface_t sched_transfer_api_interface = {
 	/*.interface_name */ "sched_transfer",
 	/*.desc */ "Schedule a broadcast event to a running call",
 	/*.function */ sched_transfer_function,
 	/*.syntax */ "[+]<time> <uuid> <extension> [<dialplan>] [<context>]",
-	/*.next */ NULL
+	/*.next */ &sched_api_api_interface
 };
 
 static switch_api_interface_t sched_broadcast_api_interface = {
@@ -986,7 +1079,8 @@
 	/*.interface_name */ "originate",
 	/*.desc */ "Originate a Call",
 	/*.function */ originate_function,
-	/*.syntax */ "<call url> <exten>|&<application_name>(<app_args>) [<dialplan>] [<context>] [<cid_name>] [<cid_num>] [<timeout_sec>]",
+	/*.syntax */
+	"<call url> <exten>|&<application_name>(<app_args>) [<dialplan>] [<context>] [<cid_name>] [<cid_num>] [<timeout_sec>]",
 	/*.next */ &kill_api_interface
 };
 

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_conference/mod_conference.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_conference/mod_conference.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_conference/mod_conference.c	Fri Mar 30 12:19:18 2007
@@ -39,7 +39,7 @@
 static switch_api_interface_t conf_api_interface;
 
 /* Size to allocate for audio buffers */
-#define CONF_BUFFER_SIZE 1024 * 128 
+#define CONF_BUFFER_SIZE 1024 * 128
 #define CONF_EVENT_MAINT "conference::maintenence"
 #define CONF_DEFAULT_LEADIN 20
 
@@ -53,7 +53,7 @@
 #endif
 
 typedef enum {
-	FILE_STOP_CURRENT, 
+	FILE_STOP_CURRENT,
 	FILE_STOP_ALL
 } file_stop_t;
 
@@ -70,20 +70,20 @@
 } globals;
 
 typedef enum {
-	CALLER_CONTROL_MUTE, 
-	CALLER_CONTROL_DEAF_MUTE, 
-	CALLER_CONTROL_ENERGY_UP, 
-	CALLER_CONTROL_ENERGY_EQU_CONF, 
-	CALLER_CONTROL_ENERGEY_DN, 
-	CALLER_CONTROL_VOL_TALK_UP, 
-	CALLER_CONTROL_VOL_TALK_ZERO, 
-	CALLER_CONTROL_VOL_TALK_DN, 
-	CALLER_CONTROL_VOL_LISTEN_UP, 
-	CALLER_CONTROL_VOL_LISTEN_ZERO, 
-	CALLER_CONTROL_VOL_LISTEN_DN, 
-	CALLER_CONTROL_HANGUP, 
-	CALLER_CONTROL_MENU, 
-	CALLER_CONTROL_DIAL, 
+	CALLER_CONTROL_MUTE,
+	CALLER_CONTROL_DEAF_MUTE,
+	CALLER_CONTROL_ENERGY_UP,
+	CALLER_CONTROL_ENERGY_EQU_CONF,
+	CALLER_CONTROL_ENERGEY_DN,
+	CALLER_CONTROL_VOL_TALK_UP,
+	CALLER_CONTROL_VOL_TALK_ZERO,
+	CALLER_CONTROL_VOL_TALK_DN,
+	CALLER_CONTROL_VOL_LISTEN_UP,
+	CALLER_CONTROL_VOL_LISTEN_ZERO,
+	CALLER_CONTROL_VOL_LISTEN_DN,
+	CALLER_CONTROL_HANGUP,
+	CALLER_CONTROL_MENU,
+	CALLER_CONTROL_DIAL,
 	CALLER_CONTROL_EVENT
 } caller_control_t;
 
@@ -97,7 +97,7 @@
 	char *key;
 	char *digits;
 	caller_control_t action;
-	void (*handler)(conference_member_t *, struct caller_control_actions *);
+	void (*handler) (conference_member_t *, struct caller_control_actions *);
 } caller_control_fn_table_t;
 
 typedef struct caller_control_actions {
@@ -112,33 +112,33 @@
 } caller_control_menu_info_t;
 
 typedef enum {
-	MFLAG_RUNNING = (1 << 0), 
-	MFLAG_CAN_SPEAK = (1 << 1), 
-	MFLAG_CAN_HEAR = (1 << 2), 
-	MFLAG_KICKED = (1 << 3), 
-	MFLAG_ITHREAD = (1 << 4), 
+	MFLAG_RUNNING = (1 << 0),
+	MFLAG_CAN_SPEAK = (1 << 1),
+	MFLAG_CAN_HEAR = (1 << 2),
+	MFLAG_KICKED = (1 << 3),
+	MFLAG_ITHREAD = (1 << 4),
 	MFLAG_NOCHANNEL = (1 << 5),
-    MFLAG_INTREE = (1 << 6),
+	MFLAG_INTREE = (1 << 6),
 	MFLAG_WASTE_BANDWIDTH = (1 << 7),
 	MFLAG_FLUSH_BUFFER = (1 << 8)
 } member_flag_t;
 
 typedef enum {
-	CFLAG_RUNNING = (1 << 0), 
-	CFLAG_DYNAMIC = (1 << 1), 
-	CFLAG_ENFORCE_MIN = (1 << 2), 
-	CFLAG_DESTRUCT = (1 << 3), 
-	CFLAG_LOCKED = (1 << 4), 
+	CFLAG_RUNNING = (1 << 0),
+	CFLAG_DYNAMIC = (1 << 1),
+	CFLAG_ENFORCE_MIN = (1 << 2),
+	CFLAG_DESTRUCT = (1 << 3),
+	CFLAG_LOCKED = (1 << 4),
 	CFLAG_ANSWERED = (1 << 5)
 } conf_flag_t;
 
 typedef enum {
-	RFLAG_CAN_SPEAK = (1 << 0), 
+	RFLAG_CAN_SPEAK = (1 << 0),
 	RFLAG_CAN_HEAR = (1 << 1)
 } relation_flag_t;
 
 typedef enum {
-	NODE_TYPE_FILE, 
+	NODE_TYPE_FILE,
 	NODE_TYPE_SPEECH
 } node_type_t;
 
@@ -178,10 +178,10 @@
 	char *kicked_sound;
 	char *caller_id_name;
 	char *caller_id_number;
-    char *sound_prefix;
-    uint32_t max_members;
-    char *maxmember_sound;
-    uint32_t anounce_count;
+	char *sound_prefix;
+	uint32_t max_members;
+	char *maxmember_sound;
+	uint32_t anounce_count;
 	switch_ivr_digit_stream_parser_t *dtmf_parser;
 	char *pin;
 	char *pin_sound;
@@ -196,7 +196,7 @@
 	uint32_t interval;
 	switch_mutex_t *mutex;
 	conference_member_t *members;
-    switch_mutex_t *member_mutex;
+	switch_mutex_t *member_mutex;
 	conference_file_node_t *fnode;
 	conference_file_node_t *async_fnode;
 	switch_memory_pool_t *pool;
@@ -254,12 +254,12 @@
 } conference_record_t;
 
 typedef enum {
-	CONF_API_SUB_ARGS_SPLIT, 
-	CONF_API_SUB_MEMBER_TARGET, 
+	CONF_API_SUB_ARGS_SPLIT,
+	CONF_API_SUB_MEMBER_TARGET,
 	CONF_API_SUB_ARGS_AS_ONE
 } conference_fntype_t;
 
-typedef void (*void_fn_t)(void);
+typedef void (*void_fn_t) (void);
 
 /* API command parser */
 typedef struct api_command {
@@ -272,69 +272,48 @@
 
 /* Function Prototypes */
 static uint32_t next_member_id(void);
-static conference_relationship_t *member_get_relationship(conference_member_t *member, conference_member_t *other_member);
-static conference_member_t *conference_member_get(conference_obj_t *conference, uint32_t id);
-static conference_relationship_t *member_add_relationship(conference_member_t *member, uint32_t id);
-static switch_status_t member_del_relationship(conference_member_t *member, uint32_t id);
-static switch_status_t conference_add_member(conference_obj_t *conference, conference_member_t *member);
-static switch_status_t conference_del_member(conference_obj_t *conference, conference_member_t *member);
-static void *SWITCH_THREAD_FUNC conference_thread_run(switch_thread_t *thread, void *obj);
-static void conference_loop_output(conference_member_t *member);
-static uint32_t conference_stop_file(conference_obj_t *conference, file_stop_t stop);
-static switch_status_t conference_play_file(conference_obj_t *conference, char *file, uint32_t leadin, switch_channel_t *channel, uint8_t async);
-static switch_status_t conference_say(conference_obj_t *conference, const char *text, uint32_t leadin);
-static void conference_list(conference_obj_t *conference, switch_stream_handle_t *stream, char *delim);
+static conference_relationship_t *member_get_relationship(conference_member_t * member, conference_member_t * other_member);
+static conference_member_t *conference_member_get(conference_obj_t * conference, uint32_t id);
+static conference_relationship_t *member_add_relationship(conference_member_t * member, uint32_t id);
+static switch_status_t member_del_relationship(conference_member_t * member, uint32_t id);
+static switch_status_t conference_add_member(conference_obj_t * conference, conference_member_t * member);
+static switch_status_t conference_del_member(conference_obj_t * conference, conference_member_t * member);
+static void *SWITCH_THREAD_FUNC conference_thread_run(switch_thread_t * thread, void *obj);
+static void conference_loop_output(conference_member_t * member);
+static uint32_t conference_stop_file(conference_obj_t * conference, file_stop_t stop);
+static switch_status_t conference_play_file(conference_obj_t * conference, char *file, uint32_t leadin, switch_channel_t *channel, uint8_t async);
+static switch_status_t conference_say(conference_obj_t * conference, const char *text, uint32_t leadin);
+static void conference_list(conference_obj_t * conference, switch_stream_handle_t *stream, char *delim);
 static switch_status_t conf_api_main(char *buf, switch_core_session_t *session, switch_stream_handle_t *stream);
 static switch_status_t audio_bridge_on_ring(switch_core_session_t *session);
-static switch_status_t conference_outcall(conference_obj_t *conference, 
+static switch_status_t conference_outcall(conference_obj_t * conference,
 										  char *conference_name,
-										  switch_core_session_t *session, 
-										  char *bridgeto, 
-										  uint32_t timeout, 
-										  char *flags, 
-										  char *cid_name, 
-										  char *cid_num,
-                                          switch_call_cause_t *cause);
-static switch_status_t conference_outcall_bg(conference_obj_t *conference, 
+										  switch_core_session_t *session,
+										  char *bridgeto, uint32_t timeout, char *flags, char *cid_name, char *cid_num, switch_call_cause_t *cause);
+static switch_status_t conference_outcall_bg(conference_obj_t * conference,
 											 char *conference_name,
-                                             switch_core_session_t *session, 
-                                             char *bridgeto, 
-                                             uint32_t timeout, 
-                                             char *flags, 
-                                             char *cid_name, 
-                                             char *cid_num);
+											 switch_core_session_t *session, char *bridgeto, uint32_t timeout, char *flags, char *cid_name, char *cid_num);
 static void conference_function(switch_core_session_t *session, char *data);
-static void launch_conference_thread(conference_obj_t *conference);
-static void *SWITCH_THREAD_FUNC conference_loop_input(switch_thread_t *thread, void *obj);
-static switch_status_t conference_local_play_file(conference_obj_t *conference,
-                                                  switch_core_session_t *session, char *path, uint32_t leadin, char *buf, switch_size_t len);
-static switch_status_t conference_member_play_file(conference_member_t *member, char *file, uint32_t leadin);
-static switch_status_t conference_member_say(conference_member_t *member, char *text, uint32_t leadin);
-static uint32_t conference_member_stop_file(conference_member_t *member, file_stop_t stop);
+static void launch_conference_thread(conference_obj_t * conference);
+static void *SWITCH_THREAD_FUNC conference_loop_input(switch_thread_t * thread, void *obj);
+static switch_status_t conference_local_play_file(conference_obj_t * conference,
+												  switch_core_session_t *session, char *path, uint32_t leadin, char *buf, switch_size_t len);
+static switch_status_t conference_member_play_file(conference_member_t * member, char *file, uint32_t leadin);
+static switch_status_t conference_member_say(conference_member_t * member, char *text, uint32_t leadin);
+static uint32_t conference_member_stop_file(conference_member_t * member, file_stop_t stop);
 static conference_obj_t *conference_new(char *name, conf_xml_cfg_t cfg, switch_memory_pool_t *pool);
 static switch_status_t chat_send(char *proto, char *from, char *to, char *subject, char *body, char *hint);
-static void launch_conference_record_thread(conference_obj_t *conference, char *path);
+static void launch_conference_record_thread(conference_obj_t * conference, char *path);
 
-typedef switch_status_t (*conf_api_args_cmd_t)(conference_obj_t*, switch_stream_handle_t*, int, char**);
-typedef switch_status_t (*conf_api_member_cmd_t)(conference_member_t*, switch_stream_handle_t*, void*);
-typedef switch_status_t (*conf_api_text_cmd_t)(conference_obj_t*, switch_stream_handle_t*, const char*);
-
-static void conference_member_itterator(conference_obj_t *conference, 
-										switch_stream_handle_t *stream, 
-										conf_api_member_cmd_t pfncallback, 
-										void *data);
-static switch_status_t conf_api_sub_mute(conference_member_t *member, 
-                                         switch_stream_handle_t *stream, 
-                                         void *data);
-static switch_status_t conf_api_sub_unmute(conference_member_t *member, 
-                                           switch_stream_handle_t *stream, 
-                                           void *data);
-static switch_status_t conf_api_sub_deaf(conference_member_t *member, 
-                                         switch_stream_handle_t *stream, 
-                                         void *data);
-static switch_status_t conf_api_sub_undeaf(conference_member_t *member, 
-                                           switch_stream_handle_t *stream, 
-                                           void *data);
+typedef switch_status_t (*conf_api_args_cmd_t) (conference_obj_t *, switch_stream_handle_t *, int, char **);
+typedef switch_status_t (*conf_api_member_cmd_t) (conference_member_t *, switch_stream_handle_t *, void *);
+typedef switch_status_t (*conf_api_text_cmd_t) (conference_obj_t *, switch_stream_handle_t *, const char *);
+
+static void conference_member_itterator(conference_obj_t * conference, switch_stream_handle_t *stream, conf_api_member_cmd_t pfncallback, void *data);
+static switch_status_t conf_api_sub_mute(conference_member_t * member, switch_stream_handle_t *stream, void *data);
+static switch_status_t conf_api_sub_unmute(conference_member_t * member, switch_stream_handle_t *stream, void *data);
+static switch_status_t conf_api_sub_deaf(conference_member_t * member, switch_stream_handle_t *stream, void *data);
+static switch_status_t conf_api_sub_undeaf(conference_member_t * member, switch_stream_handle_t *stream, void *data);
 
 /* Return a Distinct ID # */
 static uint32_t next_member_id(void)
@@ -349,7 +328,7 @@
 }
 
 /* if other_member has a relationship with member, produce it */
-static conference_relationship_t *member_get_relationship(conference_member_t *member, conference_member_t *other_member)
+static conference_relationship_t *member_get_relationship(conference_member_t * member, conference_member_t * other_member)
 {
 	conference_relationship_t *rel = NULL;
 
@@ -368,7 +347,7 @@
 				/* 0 matches everyone.
 				   (We will still test the others brcause a real match carries more clout) */
 
-				if (rel->id == 0) { 
+				if (rel->id == 0) {
 					global = rel;
 				}
 			}
@@ -386,54 +365,54 @@
 }
 
 /* traverse the conference member list for the specified member id and return it's pointer */
-static conference_member_t *conference_member_get(conference_obj_t *conference, uint32_t id)
+static conference_member_t *conference_member_get(conference_obj_t * conference, uint32_t id)
 {
 	conference_member_t *member = NULL;
 
-    assert(conference != NULL);
-    assert(id != 0);
+	assert(conference != NULL);
+	assert(id != 0);
 
-    switch_mutex_lock(conference->member_mutex);
-    for(member = conference->members; member; member = member->next) {
-        
-        if (switch_test_flag(member, MFLAG_NOCHANNEL)) {
-            continue;
-        }
-        
-        if (member->id == id) {
-            break;
-        }
-    }
-
-    if (member && !switch_test_flag(member, MFLAG_INTREE)) {
-        member = NULL;
-    }
+	switch_mutex_lock(conference->member_mutex);
+	for (member = conference->members; member; member = member->next) {
 
-    switch_mutex_unlock(conference->member_mutex);
+		if (switch_test_flag(member, MFLAG_NOCHANNEL)) {
+			continue;
+		}
+
+		if (member->id == id) {
+			break;
+		}
+	}
+
+	if (member && !switch_test_flag(member, MFLAG_INTREE)) {
+		member = NULL;
+	}
+
+	switch_mutex_unlock(conference->member_mutex);
 
 	return member;
 }
 
 /* stop the specified recording */
-static switch_status_t conference_record_stop(conference_obj_t *conference, char *path)
+static switch_status_t conference_record_stop(conference_obj_t * conference, char *path)
 {
 	conference_member_t *member = NULL;
 	int count = 0;
 
-	assert (conference != NULL);
-    switch_mutex_lock(conference->member_mutex);
-    for(member = conference->members; member; member = member->next) {
-        if (switch_test_flag(member, MFLAG_NOCHANNEL) && (!path || !strcmp(path, member->rec_path))) {
-            switch_clear_flag_locked(member, MFLAG_RUNNING);
-            count++;
-        }
-    }
-    switch_mutex_unlock(conference->member_mutex);
+	assert(conference != NULL);
+	switch_mutex_lock(conference->member_mutex);
+	for (member = conference->members; member; member = member->next) {
+		if (switch_test_flag(member, MFLAG_NOCHANNEL) && (!path || !strcmp(path, member->rec_path))) {
+			switch_clear_flag_locked(member, MFLAG_RUNNING);
+			count++;
+		}
+	}
+	switch_mutex_unlock(conference->member_mutex);
 	return count;
 }
 
 /* Add a custom relationship to a member */
-static conference_relationship_t *member_add_relationship(conference_member_t *member, uint32_t id)
+static conference_relationship_t *member_add_relationship(conference_member_t * member, uint32_t id)
 {
 	conference_relationship_t *rel = NULL;
 
@@ -450,7 +429,7 @@
 }
 
 /* Remove a custom relationship from a member */
-static switch_status_t member_del_relationship(conference_member_t *member, uint32_t id)
+static switch_status_t member_del_relationship(conference_member_t * member, uint32_t id)
 {
 	switch_status_t status = SWITCH_STATUS_FALSE;
 	conference_relationship_t *rel, *last = NULL;
@@ -477,187 +456,186 @@
 }
 
 /* Gain exclusive access and add the member to the list */
-static switch_status_t conference_add_member(conference_obj_t *conference, conference_member_t *member)
+static switch_status_t conference_add_member(conference_obj_t * conference, conference_member_t * member)
 {
 	switch_status_t status = SWITCH_STATUS_FALSE;
-    switch_event_t *event;
-    char msg[512]; // for conference count anouncement
+	switch_event_t *event;
+	char msg[512];				// for conference count anouncement
+
+	assert(conference != NULL);
+	assert(member != NULL);
+
+	switch_mutex_lock(conference->mutex);
+	switch_mutex_lock(member->audio_in_mutex);
+	switch_mutex_lock(member->audio_out_mutex);
+	switch_mutex_lock(member->flag_mutex);
+
+	switch_mutex_lock(conference->member_mutex);
+	member->conference = conference;
+	member->next = conference->members;
+	member->energy_level = conference->energy_level;
+	conference->members = member;
+	switch_set_flag(member, MFLAG_INTREE);
+	switch_mutex_unlock(conference->member_mutex);
+
+	if (!switch_test_flag(member, MFLAG_NOCHANNEL)) {
+		conference->count++;
+		if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "proto", CONF_CHAT_PROTO);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "login", "%s", conference->name);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", conference->name, conference->domain);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "status", "Active (%d caller%s)", conference->count, conference->count == 1 ? "" : "s");
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_type", "presence");
+			switch_event_fire(&event);
+		}
+
+		if (conference->count > 1 && conference->enter_sound) {
+			conference_play_file(conference, conference->enter_sound, CONF_DEFAULT_LEADIN, switch_core_session_get_channel(member->session), 0);
+		}
+		// anounce the total number of members in the conference
+		if (conference->count >= conference->anounce_count && conference->anounce_count > 1) {
+			snprintf(msg, sizeof(msg), "There are %d callers", conference->count);
+			conference_member_say(member, msg, CONF_DEFAULT_LEADIN);
+		} else if (conference->count == 1) {
+			if (conference->alone_sound) {
+				conference_play_file(conference, conference->alone_sound, CONF_DEFAULT_LEADIN, switch_core_session_get_channel(member->session), 0);
+			} else {
+				snprintf(msg, sizeof(msg), "You are currently the only person in this conference.");
+				conference_member_say(member, msg, CONF_DEFAULT_LEADIN);
+			}
+		}
+
+		if (conference->min && conference->count >= conference->min) {
+			switch_set_flag(conference, CFLAG_ENFORCE_MIN);
+		}
+
+		if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+			switch_channel_t *channel = switch_core_session_get_channel(member->session);
+			switch_channel_event_set_data(channel, event);
+
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", "%s", conference->name);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", member->id);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "add-member");
+			switch_event_fire(&event);
+		}
+	}
+	switch_mutex_unlock(member->flag_mutex);
+	switch_mutex_unlock(member->audio_out_mutex);
+	switch_mutex_unlock(member->audio_in_mutex);
 
-    assert(conference != NULL);
-    assert(member != NULL);
+	switch_mutex_unlock(conference->mutex);
+	status = SWITCH_STATUS_SUCCESS;
 
-    switch_mutex_lock(conference->mutex);
-    switch_mutex_lock(member->audio_in_mutex);
-    switch_mutex_lock(member->audio_out_mutex);
-    switch_mutex_lock(member->flag_mutex);
-    
-    switch_mutex_lock(conference->member_mutex);
-    member->conference = conference;
-    member->next = conference->members;
-    member->energy_level = conference->energy_level;
-    conference->members = member;
-    switch_set_flag(member, MFLAG_INTREE);
-    switch_mutex_unlock(conference->member_mutex);
-
-    if (!switch_test_flag(member, MFLAG_NOCHANNEL)) {
-        conference->count++;
-        if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "proto", CONF_CHAT_PROTO);
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "login", "%s", conference->name);
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", conference->name, conference->domain);
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "status", "Active (%d caller%s)", conference->count, conference->count == 1 ? "" : "s");
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_type", "presence");
-            switch_event_fire(&event);
-        }
-
-        if (conference->count > 1 && conference->enter_sound) {
-            conference_play_file(conference, conference->enter_sound, CONF_DEFAULT_LEADIN, switch_core_session_get_channel(member->session), 0);
-        }
-
-        // anounce the total number of members in the conference
-        if (conference->count >= conference->anounce_count && conference->anounce_count > 1) {
-            snprintf(msg, sizeof(msg), "There are %d callers", conference->count);
-            conference_member_say(member, msg, CONF_DEFAULT_LEADIN);
-        } else if (conference->count == 1) {
-            if (conference->alone_sound) {
-                conference_play_file(conference, conference->alone_sound, CONF_DEFAULT_LEADIN, switch_core_session_get_channel(member->session), 0);
-            } else {
-                snprintf(msg, sizeof(msg), "You are currently the only person in this conference.");
-                conference_member_say(member, msg, CONF_DEFAULT_LEADIN);
-            }
-        }
-
-        if (conference->min && conference->count >= conference->min) {
-            switch_set_flag(conference, CFLAG_ENFORCE_MIN);	
-        }
-        
-        if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
-            switch_channel_t *channel = switch_core_session_get_channel(member->session);
-            switch_channel_event_set_data(channel, event);
-
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", "%s", conference->name);
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", member->id);
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "add-member");
-            switch_event_fire(&event);
-        }
-    }
-    switch_mutex_unlock(member->flag_mutex);
-    switch_mutex_unlock(member->audio_out_mutex);
-    switch_mutex_unlock(member->audio_in_mutex);
-
-    switch_mutex_unlock(conference->mutex);
-    status = SWITCH_STATUS_SUCCESS;
-	
 
 	return status;
 }
 
 /* Gain exclusive access and remove the member from the list */
-static switch_status_t conference_del_member(conference_obj_t *conference, conference_member_t *member)
+static switch_status_t conference_del_member(conference_obj_t * conference, conference_member_t * member)
 {
 	switch_status_t status = SWITCH_STATUS_FALSE;
-    conference_member_t *imember, *last = NULL;
-    switch_event_t *event;
+	conference_member_t *imember, *last = NULL;
+	switch_event_t *event;
+
+	assert(conference != NULL);
+	assert(member != NULL);
+
+	switch_mutex_lock(conference->mutex);
+	switch_mutex_lock(conference->member_mutex);
+	switch_mutex_lock(member->audio_in_mutex);
+	switch_mutex_lock(member->audio_out_mutex);
+	switch_mutex_lock(member->flag_mutex);
+	switch_clear_flag(member, MFLAG_INTREE);
+
+	for (imember = conference->members; imember; imember = imember->next) {
+		if (imember == member) {
+			if (last) {
+				last->next = imember->next;
+			} else {
+				conference->members = imember->next;
+			}
+			break;
+		}
+		last = imember;
+	}
+
+	/* Close Unused Handles */
+	if (member->fnode) {
+		conference_file_node_t *fnode, *cur;
+		switch_memory_pool_t *pool;
+
+		fnode = member->fnode;
+		while (fnode) {
+			cur = fnode;
+			fnode = fnode->next;
+
+			if (cur->type == NODE_TYPE_SPEECH) {
+				switch_speech_flag_t flags = SWITCH_SPEECH_FLAG_NONE;
+				switch_core_speech_close(&cur->sh, &flags);
+			} else {
+				switch_core_file_close(&cur->fh);
+			}
+
+			pool = cur->pool;
+			switch_core_destroy_memory_pool(&pool);
+		}
+	}
+
+	member->conference = NULL;
+
+	if (!switch_test_flag(member, MFLAG_NOCHANNEL)) {
+		conference->count--;
+		if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "proto", CONF_CHAT_PROTO);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "login", "%s", conference->name);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", conference->name, conference->domain);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "status", "Active (%d caller%s)", conference->count, conference->count == 1 ? "" : "s");
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_type", "presence");
+			switch_event_fire(&event);
+		}
+
+		if ((conference->min && switch_test_flag(conference, CFLAG_ENFORCE_MIN) && conference->count < conference->min)
+			|| (switch_test_flag(conference, CFLAG_DYNAMIC) && conference->count == 0)) {
+			switch_set_flag(conference, CFLAG_DESTRUCT);
+		} else {
+			if (conference->exit_sound) {
+				conference_play_file(conference, conference->exit_sound, 0, switch_core_session_get_channel(member->session), 0);
+			}
+			if (conference->count == 1 && conference->alone_sound) {
+				conference_play_file(conference, conference->alone_sound, 0, switch_core_session_get_channel(member->session), 0);
+			}
+		}
+
+		if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+			switch_channel_t *channel = switch_core_session_get_channel(member->session);
+			switch_channel_event_set_data(channel, event);
+
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", "%s", conference->name);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", member->id);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "del-member");
+			switch_event_fire(&event);
+		}
+	}
+	switch_mutex_unlock(conference->member_mutex);
+	switch_mutex_unlock(member->flag_mutex);
+	switch_mutex_unlock(member->audio_out_mutex);
+	switch_mutex_unlock(member->audio_in_mutex);
+	switch_mutex_unlock(conference->mutex);
+	status = SWITCH_STATUS_SUCCESS;
 
-    assert(conference != NULL);
-    assert(member != NULL);
-    
-    switch_mutex_lock(conference->mutex);
-    switch_mutex_lock(conference->member_mutex);
-    switch_mutex_lock(member->audio_in_mutex);
-    switch_mutex_lock(member->audio_out_mutex);
-    switch_mutex_lock(member->flag_mutex);
-    switch_clear_flag(member, MFLAG_INTREE);
-    
-    for (imember = conference->members; imember; imember = imember->next) {
-        if (imember == member ) {
-            if (last) {
-                last->next = imember->next;
-            } else {
-                conference->members = imember->next;
-            }
-            break;
-        }
-        last = imember;
-    }
-
-    /* Close Unused Handles */
-    if (member->fnode) {
-        conference_file_node_t *fnode, *cur;
-        switch_memory_pool_t *pool;
-
-        fnode = member->fnode;
-        while(fnode) {
-            cur = fnode;
-            fnode = fnode->next;
-
-            if (cur->type == NODE_TYPE_SPEECH) {
-                switch_speech_flag_t flags = SWITCH_SPEECH_FLAG_NONE;
-                switch_core_speech_close(&cur->sh, &flags);
-            } else {
-                switch_core_file_close(&cur->fh);
-            }
-
-            pool = cur->pool;
-            switch_core_destroy_memory_pool(&pool);
-        }
-    }
-
-    member->conference = NULL;
-
-    if (!switch_test_flag(member, MFLAG_NOCHANNEL)) {
-        conference->count--;
-        if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "proto", CONF_CHAT_PROTO);
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "login", "%s", conference->name);
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", conference->name, conference->domain);
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "status", "Active (%d caller%s)", conference->count, conference->count == 1 ? "" : "s");
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_type", "presence");
-            switch_event_fire(&event);
-        }
-
-        if ((conference->min && switch_test_flag(conference, CFLAG_ENFORCE_MIN) && conference->count < conference->min) 
-            || (switch_test_flag(conference, CFLAG_DYNAMIC) && conference->count == 0) ) {
-            switch_set_flag(conference, CFLAG_DESTRUCT);
-        } else { 
-            if (conference->exit_sound) {
-                conference_play_file(conference, conference->exit_sound, 0, switch_core_session_get_channel(member->session), 0);
-            }
-            if (conference->count == 1 && conference->alone_sound) {
-                conference_play_file(conference, conference->alone_sound, 0, switch_core_session_get_channel(member->session), 0);
-            } 
-        }
-
-        if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
-            switch_channel_t *channel = switch_core_session_get_channel(member->session);
-            switch_channel_event_set_data(channel, event);
-
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", "%s", conference->name);
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", member->id);
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "del-member");
-            switch_event_fire(&event);
-        }
-    }
-    switch_mutex_unlock(conference->member_mutex);
-    switch_mutex_unlock(member->flag_mutex);
-    switch_mutex_unlock(member->audio_out_mutex);
-    switch_mutex_unlock(member->audio_in_mutex);
-    switch_mutex_unlock(conference->mutex);
-    status = SWITCH_STATUS_SUCCESS;
-	
 
 	return status;
 }
 
 /* Main monitor thread (1 per distinct conference room) */
-static void *SWITCH_THREAD_FUNC conference_thread_run(switch_thread_t *thread, void *obj)
+static void *SWITCH_THREAD_FUNC conference_thread_run(switch_thread_t * thread, void *obj)
 {
 	conference_obj_t *conference = (conference_obj_t *) obj;
 	conference_member_t *imember, *omember;
 	uint32_t samples = switch_bytes_per_frame(conference->rate, conference->interval);
 	uint32_t bytes = samples * 2;
 	uint8_t ready = 0;
-	switch_timer_t timer = {0};
+	switch_timer_t timer = { 0 };
 	switch_event_t *event;
 	uint8_t *file_frame;
 	uint8_t *async_file_frame;
@@ -667,9 +645,9 @@
 
 
 	if (switch_core_timer_init(&timer, conference->timer_name, conference->interval, samples, conference->pool) == SWITCH_STATUS_SUCCESS) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "setup timer success interval: %u  samples: %u\n", conference->interval, samples);	
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "setup timer success interval: %u  samples: %u\n", conference->interval, samples);
 	} else {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer Setup Failed.  Conference Cannot Start\n");	
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer Setup Failed.  Conference Cannot Start\n");
 		return NULL;
 	}
 
@@ -677,7 +655,7 @@
 	globals.threads++;
 	switch_mutex_unlock(globals.hash_mutex);
 
-	while(globals.running && !switch_test_flag(conference, CFLAG_DESTRUCT)) {
+	while (globals.running && !switch_test_flag(conference, CFLAG_DESTRUCT)) {
 		switch_size_t file_sample_len = samples;
 		switch_size_t file_data_len = samples * 2;
 		int has_file_data = 0;
@@ -703,9 +681,9 @@
 			switch_mutex_lock(imember->audio_in_mutex);
 			/* if there is audio in the resample buffer it takes precedence over the other data */
 			if (imember->mux_resampler && switch_buffer_inuse(imember->resample_buffer) >= bytes) {
-				imember->read = (uint32_t)switch_buffer_read(imember->resample_buffer, imember->frame, bytes);
+				imember->read = (uint32_t) switch_buffer_read(imember->resample_buffer, imember->frame, bytes);
 				ready++;
-			} else if ((imember->read = (uint32_t)switch_buffer_read(imember->audio_buffer, imember->frame, imember->buflen))) {
+			} else if ((imember->read = (uint32_t) switch_buffer_read(imember->audio_buffer, imember->frame, imember->buflen))) {
 				/* If the caller is not at the right sample rate resample him to suit and buffer accordingly */
 				if (imember->mux_resampler) {
 					int16_t *bptr = (int16_t *) imember->frame;
@@ -713,18 +691,18 @@
 					int len = (int) imember->read;
 
 					imember->mux_resampler->from_len = switch_short_to_float(bptr, imember->mux_resampler->from, (int) len / 2);
-					imember->mux_resampler->to_len = switch_resample_process(imember->mux_resampler, imember->mux_resampler->from, 
-                                                                             imember->mux_resampler->from_len, imember->mux_resampler->to, 
-                                                                             imember->mux_resampler->to_size, 0);
+					imember->mux_resampler->to_len =
+						switch_resample_process(imember->mux_resampler, imember->mux_resampler->from,
+												imember->mux_resampler->from_len, imember->mux_resampler->to, imember->mux_resampler->to_size, 0);
 					switch_float_to_short(imember->mux_resampler->to, out, len);
 					len = imember->mux_resampler->to_len * 2;
 					switch_buffer_write(imember->resample_buffer, out, len);
 					if (switch_buffer_inuse(imember->resample_buffer) >= bytes) {
-						imember->read = (uint32_t)switch_buffer_read(imember->resample_buffer, imember->frame, bytes);
+						imember->read = (uint32_t) switch_buffer_read(imember->resample_buffer, imember->frame, bytes);
 						ready++;
 					}
 				} else {
-					ready++; /* Tally of how many channels had data */
+					ready++;	/* Tally of how many channels had data */
 				}
 			}
 			switch_mutex_unlock(imember->audio_in_mutex);
@@ -740,14 +718,10 @@
 					switch_speech_flag_t flags = SWITCH_SPEECH_FLAG_BLOCKING;
 					uint32_t rate = conference->rate;
 
-					if (switch_core_speech_read_tts(&conference->fnode->sh, 
-													file_frame, 
-													&file_data_len, 
-													&rate, 
-													&flags) == SWITCH_STATUS_SUCCESS) {
+					if (switch_core_speech_read_tts(&conference->fnode->sh, file_frame, &file_data_len, &rate, &flags) == SWITCH_STATUS_SUCCESS) {
 						file_sample_len = file_data_len / 2;
 					} else {
-						file_sample_len = file_data_len  = 0;
+						file_sample_len = file_data_len = 0;
 					}
 				} else if (conference->fnode->type == NODE_TYPE_FILE) {
 					switch_core_file_read(&conference->fnode->fh, file_frame, &file_sample_len);
@@ -774,16 +748,16 @@
 					conference->async_fnode->done++;
 				} else {
 					if (has_file_data) {
-						switch_size_t x;			
+						switch_size_t x;
 						for (x = 0; x < file_sample_len; x++) {
 							int32_t z;
 							int16_t *bptr, *muxed;
-							
+
 							muxed = (int16_t *) file_frame;
 							bptr = (int16_t *) async_file_frame;
 							z = muxed[x] + bptr[x];
 							switch_normalize_to_16bit(z);
-							muxed[x] = (int16_t)z;
+							muxed[x] = (int16_t) z;
 						}
 					} else {
 						memcpy(file_frame, async_file_frame, file_sample_len * 2);
@@ -810,7 +784,7 @@
 						continue;
 					}
 
-					if (imember->read) { /* mux the frame with the collective */
+					if (imember->read) {	/* mux the frame with the collective */
 						uint32_t x;
 						int16_t *bptr, *muxed;
 
@@ -819,7 +793,7 @@
 							conference_relationship_t *rel;
 
 							if ((rel = member_get_relationship(omember, imember))) {
-								if (! switch_test_flag(rel, RFLAG_CAN_HEAR)) {
+								if (!switch_test_flag(rel, RFLAG_CAN_HEAR)) {
 									continue;
 								}
 							}
@@ -830,7 +804,7 @@
 							conference_relationship_t *rel;
 
 							if ((rel = member_get_relationship(imember, omember))) {
-								if (! switch_test_flag(rel, RFLAG_CAN_SPEAK)) {
+								if (!switch_test_flag(rel, RFLAG_CAN_SPEAK)) {
 									continue;
 								}
 							}
@@ -839,22 +813,22 @@
 						if (imember->read > imember->len) {
 							imember->len = imember->read;
 						}
-						
+
 						bptr = (int16_t *) imember->frame;
 						muxed = (int16_t *) omember->mux_frame;
 
-						
+
 						for (x = 0; x < imember->read / 2; x++) {
 							int32_t z = muxed[x] + bptr[x];
 							switch_normalize_to_16bit(z);
-							muxed[x] = (int16_t)z;
+							muxed[x] = (int16_t) z;
 						}
-						
+
 						ready++;
 					}
 				}
 			}
-			
+
 			/* Go back and write each member his dedicated copy of the audio frame that does not contain his own audio. */
 			for (imember = conference->members; imember; imember = imember->next) {
 				if (switch_test_flag(imember, MFLAG_RUNNING)) {
@@ -894,7 +868,7 @@
 		}
 
 		switch_mutex_unlock(conference->mutex);
-	} /* Rinse ... Repeat */
+	}							/* Rinse ... Repeat */
 
 	if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "proto", CONF_CHAT_PROTO);
@@ -908,36 +882,36 @@
 	}
 
 	switch_core_timer_destroy(&timer);
-    
+
 	if (switch_test_flag(conference, CFLAG_DESTRUCT)) {
 
 		switch_mutex_lock(conference->mutex);
 
-		/* Close Unused Handles */ 
+		/* Close Unused Handles */
 		if (conference->fnode) {
-			conference_file_node_t *fnode, *cur; 
-			switch_memory_pool_t *pool; 
+			conference_file_node_t *fnode, *cur;
+			switch_memory_pool_t *pool;
+
+			fnode = conference->fnode;
+			while (fnode) {
+				cur = fnode;
+				fnode = fnode->next;
+
+				if (cur->type == NODE_TYPE_SPEECH) {
+					switch_speech_flag_t flags = SWITCH_SPEECH_FLAG_NONE;
+					switch_core_speech_close(&cur->sh, &flags);
+				} else {
+					switch_core_file_close(&cur->fh);
+				}
 
-			fnode = conference->fnode; 
-			while (fnode) { 
-				cur = fnode; 
-				fnode = fnode->next; 
-
-				if (cur->type == NODE_TYPE_SPEECH) { 
-					switch_speech_flag_t flags = SWITCH_SPEECH_FLAG_NONE; 
-					switch_core_speech_close(&cur->sh, &flags); 
-				} else { 
-					switch_core_file_close(&cur->fh); 
-				} 
-
-				pool = cur->pool; 
-				switch_core_destroy_memory_pool(&pool); 
-			} 
-			conference->fnode = NULL; 
-		} 
+				pool = cur->pool;
+				switch_core_destroy_memory_pool(&pool);
+			}
+			conference->fnode = NULL;
+		}
 
-        switch_mutex_lock(conference->member_mutex);
-		for(imember = conference->members; imember; imember = imember->next) {
+		switch_mutex_lock(conference->member_mutex);
+		for (imember = conference->members; imember; imember = imember->next) {
 			switch_channel_t *channel;
 
 			if (!switch_test_flag(imember, MFLAG_NOCHANNEL)) {
@@ -946,8 +920,8 @@
 				/* add this little bit to preserve the bridge cause code in case of an early media call that */
 				/* never answers */
 				if (switch_test_flag(conference, CFLAG_ANSWERED)) {
-					switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);	
-				} else 	{
+					switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
+				} else {
 					/* put actual cause code from outbound channel hangup here */
 					switch_channel_hangup(channel, conference->bridge_hangup_cause);
 				}
@@ -955,11 +929,11 @@
 
 			switch_clear_flag_locked(imember, MFLAG_RUNNING);
 		}
-        switch_mutex_unlock(conference->member_mutex);
+		switch_mutex_unlock(conference->member_mutex);
 
 		switch_mutex_unlock(conference->mutex);
 
-		switch_mutex_lock(globals.hash_mutex);		
+		switch_mutex_lock(globals.hash_mutex);
 		switch_core_hash_delete(globals.conference_hash, conference->name);
 		switch_mutex_unlock(globals.hash_mutex);
 
@@ -979,44 +953,44 @@
 	}
 
 	switch_mutex_lock(globals.hash_mutex);
-	globals.threads--;	
+	globals.threads--;
 	switch_mutex_unlock(globals.hash_mutex);
 
 	return NULL;
 }
 
-static void conference_loop_fn_mute_toggle(conference_member_t *member, caller_control_action_t *action)
+static void conference_loop_fn_mute_toggle(conference_member_t * member, caller_control_action_t * action)
 {
 	if (member != NULL) {
 		if (switch_test_flag(member, MFLAG_CAN_SPEAK)) {
 			conf_api_sub_mute(member, NULL, NULL);
 		} else {
 			conf_api_sub_unmute(member, NULL, NULL);
-            if (!switch_test_flag(member, MFLAG_CAN_HEAR)) {
-                conf_api_sub_undeaf(member, NULL, NULL);
-            }
+			if (!switch_test_flag(member, MFLAG_CAN_HEAR)) {
+				conf_api_sub_undeaf(member, NULL, NULL);
+			}
 		}
 	}
 }
 
-static void conference_loop_fn_deafmute_toggle(conference_member_t *member, caller_control_action_t *action)
+static void conference_loop_fn_deafmute_toggle(conference_member_t * member, caller_control_action_t * action)
 {
 	if (member != NULL) {
 		if (switch_test_flag(member, MFLAG_CAN_SPEAK)) {
 			conf_api_sub_mute(member, NULL, NULL);
-            if (switch_test_flag(member, MFLAG_CAN_HEAR)) {
-                conf_api_sub_deaf(member, NULL, NULL);
-            }
+			if (switch_test_flag(member, MFLAG_CAN_HEAR)) {
+				conf_api_sub_deaf(member, NULL, NULL);
+			}
 		} else {
 			conf_api_sub_unmute(member, NULL, NULL);
-            if (!switch_test_flag(member, MFLAG_CAN_HEAR)) {
-                conf_api_sub_undeaf(member, NULL, NULL);
-            }
+			if (!switch_test_flag(member, MFLAG_CAN_HEAR)) {
+				conf_api_sub_undeaf(member, NULL, NULL);
+			}
 		}
 	}
 }
 
-static void conference_loop_fn_energy_up(conference_member_t *member, caller_control_action_t *action)
+static void conference_loop_fn_energy_up(conference_member_t * member, caller_control_action_t * action)
 {
 	if (member != NULL) {
 		char msg[512];
@@ -1045,9 +1019,9 @@
 	}
 }
 
-static void conference_loop_fn_energy_equ_conf(conference_member_t *member, caller_control_action_t *action)
+static void conference_loop_fn_energy_equ_conf(conference_member_t * member, caller_control_action_t * action)
 {
-	if (member!= NULL) {
+	if (member != NULL) {
 		char msg[512];
 		switch_event_t *event;
 
@@ -1070,10 +1044,10 @@
 		}
 	}
 }
-					
-static void conference_loop_fn_energy_dn(conference_member_t *member, caller_control_action_t *action)
+
+static void conference_loop_fn_energy_dn(conference_member_t * member, caller_control_action_t * action)
 {
-	if (member!= NULL) {
+	if (member != NULL) {
 		char msg[512];
 		switch_event_t *event;
 
@@ -1100,9 +1074,9 @@
 	}
 }
 
-static void conference_loop_fn_volume_talk_up(conference_member_t *member, caller_control_action_t *action)
+static void conference_loop_fn_volume_talk_up(conference_member_t * member, caller_control_action_t * action)
 {
-	if (member!= NULL) {
+	if (member != NULL) {
 		char msg[512];
 		switch_event_t *event;
 
@@ -1127,9 +1101,9 @@
 	}
 }
 
-static void conference_loop_fn_volume_talk_zero(conference_member_t *member, caller_control_action_t *action)
+static void conference_loop_fn_volume_talk_zero(conference_member_t * member, caller_control_action_t * action)
 {
-	if (member!= NULL) {
+	if (member != NULL) {
 		char msg[512];
 		switch_event_t *event;
 
@@ -1153,9 +1127,9 @@
 	}
 }
 
-static void conference_loop_fn_volume_talk_dn(conference_member_t *member, caller_control_action_t *action)
+static void conference_loop_fn_volume_talk_dn(conference_member_t * member, caller_control_action_t * action)
 {
-	if (member!= NULL) {
+	if (member != NULL) {
 		char msg[512];
 		switch_event_t *event;
 
@@ -1180,9 +1154,9 @@
 	}
 }
 
-static void conference_loop_fn_volume_listen_up(conference_member_t *member, caller_control_action_t *action)
+static void conference_loop_fn_volume_listen_up(conference_member_t * member, caller_control_action_t * action)
 {
-	if (member!= NULL) {
+	if (member != NULL) {
 		char msg[512];
 		switch_event_t *event;
 
@@ -1207,9 +1181,9 @@
 	}
 }
 
-static void conference_loop_fn_volume_listen_zero(conference_member_t *member, caller_control_action_t *action)
+static void conference_loop_fn_volume_listen_zero(conference_member_t * member, caller_control_action_t * action)
 {
-	if (member!= NULL) {
+	if (member != NULL) {
 		char msg[512];
 		switch_event_t *event;
 
@@ -1233,9 +1207,9 @@
 	}
 }
 
-static void conference_loop_fn_volume_listen_dn(conference_member_t *member, caller_control_action_t *action)
+static void conference_loop_fn_volume_listen_dn(conference_member_t * member, caller_control_action_t * action)
 {
-	if (member!= NULL) {
+	if (member != NULL) {
 		char msg[512];
 		switch_event_t *event;
 
@@ -1260,7 +1234,7 @@
 	}
 }
 
-static void conference_loop_fn_event(conference_member_t *member, caller_control_action_t *action)
+static void conference_loop_fn_event(conference_member_t * member, caller_control_action_t * action)
 {
 	switch_event_t *event;
 	if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
@@ -1275,25 +1249,20 @@
 	}
 }
 
-static void conference_loop_fn_hangup(conference_member_t *member, caller_control_action_t *action)
+static void conference_loop_fn_hangup(conference_member_t * member, caller_control_action_t * action)
 {
 	switch_clear_flag_locked(member, MFLAG_RUNNING);
 }
 
 /* marshall frames from the call leg to the conference thread for muxing to other call legs */
-static void *SWITCH_THREAD_FUNC conference_loop_input(switch_thread_t *thread, void *obj)
+static void *SWITCH_THREAD_FUNC conference_loop_input(switch_thread_t * thread, void *obj)
 {
 	conference_member_t *member = obj;
 	switch_channel_t *channel;
 	switch_status_t status;
 	switch_frame_t *read_frame = NULL;
 	switch_codec_t *read_codec;
-	uint32_t hangover = 40, 
-		hangunder = 15, 
-		hangover_hits = 0, 
-		hangunder_hits = 0, 
-		energy_level = 0, 
-		diff_level = 400;
+	uint32_t hangover = 40, hangunder = 15, hangover_hits = 0, hangunder_hits = 0, energy_level = 0, diff_level = 400;
 	uint8_t talking = 0;
 
 	assert(member != NULL);
@@ -1307,7 +1276,7 @@
 	/* As long as we have a valid read, feed that data into an input buffer where the conference thread will take it 
 	   and mux it with any audio from other channels. */
 
-	while(switch_test_flag(member, MFLAG_RUNNING) && switch_channel_ready(channel)) {
+	while (switch_test_flag(member, MFLAG_RUNNING) && switch_channel_ready(channel)) {
 		/* Read a frame. */
 		status = switch_core_session_read_frame(member->session, &read_frame, -1, 0);
 
@@ -1359,7 +1328,7 @@
 							switch_event_fire(&event);
 						}
 					}
-				} 
+				}
 			} else {
 				if (hangunder_hits) {
 					hangunder_hits--;
@@ -1376,7 +1345,7 @@
 							switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", member->id);
 							switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "stop-talking");
 							switch_event_fire(&event);
-						}					
+						}
 					}
 				}
 			}
@@ -1389,9 +1358,9 @@
 				int len = (int) read_frame->datalen;;
 
 				member->read_resampler->from_len = switch_short_to_float(bptr, member->read_resampler->from, (int) len / 2);
-				member->read_resampler->to_len = switch_resample_process(member->read_resampler, member->read_resampler->from, 
-																		 member->read_resampler->from_len, member->read_resampler->to, 
-																		 member->read_resampler->to_size, 0);
+				member->read_resampler->to_len =
+					switch_resample_process(member->read_resampler, member->read_resampler->from,
+											member->read_resampler->from_len, member->read_resampler->to, member->read_resampler->to_size, 0);
 				switch_float_to_short(member->read_resampler->to, read_frame->data, len);
 				len = member->read_resampler->to_len * 2;
 				read_frame->datalen = len;
@@ -1415,7 +1384,7 @@
 }
 
 /* launch an input thread for the call leg */
-static void launch_conference_loop_input(conference_member_t *member, switch_memory_pool_t *pool)
+static void launch_conference_loop_input(conference_member_t * member, switch_memory_pool_t *pool)
 {
 	if (member != NULL) {
 		switch_thread_t *thread;
@@ -1430,30 +1399,31 @@
 }
 
 static caller_control_fn_table_t ccfntbl[] = {
-	{"mute", "0", CALLER_CONTROL_MUTE, conference_loop_fn_mute_toggle}, 
-	{"deaf mute", "*", CALLER_CONTROL_DEAF_MUTE, conference_loop_fn_deafmute_toggle}, 
-	{"energy up", "9", CALLER_CONTROL_ENERGY_UP, conference_loop_fn_energy_up}, 
-	{"energy equ", "8", CALLER_CONTROL_ENERGY_EQU_CONF, conference_loop_fn_energy_equ_conf}, 
-	{"energy dn", "7", CALLER_CONTROL_ENERGEY_DN, conference_loop_fn_energy_dn}, 
-	{"vol talk up", "3", CALLER_CONTROL_VOL_TALK_UP, conference_loop_fn_volume_talk_up}, 
-	{"vol talk zero", "2", CALLER_CONTROL_VOL_TALK_ZERO, conference_loop_fn_volume_talk_zero}, 
-	{"vol talk dn", "1", CALLER_CONTROL_VOL_TALK_DN, conference_loop_fn_volume_talk_dn}, 
-	{"vol listen up", "6", CALLER_CONTROL_VOL_LISTEN_UP, conference_loop_fn_volume_listen_up}, 
-	{"vol listen zero", "5", CALLER_CONTROL_VOL_LISTEN_ZERO, conference_loop_fn_volume_listen_zero}, 
-	{"vol listen dn", "4", CALLER_CONTROL_VOL_LISTEN_DN, conference_loop_fn_volume_listen_dn}, 
-	{"hangup", "#", CALLER_CONTROL_HANGUP, conference_loop_fn_hangup}, 
+	{"mute", "0", CALLER_CONTROL_MUTE, conference_loop_fn_mute_toggle},
+	{"deaf mute", "*", CALLER_CONTROL_DEAF_MUTE, conference_loop_fn_deafmute_toggle},
+	{"energy up", "9", CALLER_CONTROL_ENERGY_UP, conference_loop_fn_energy_up},
+	{"energy equ", "8", CALLER_CONTROL_ENERGY_EQU_CONF, conference_loop_fn_energy_equ_conf},
+	{"energy dn", "7", CALLER_CONTROL_ENERGEY_DN, conference_loop_fn_energy_dn},
+	{"vol talk up", "3", CALLER_CONTROL_VOL_TALK_UP, conference_loop_fn_volume_talk_up},
+	{"vol talk zero", "2", CALLER_CONTROL_VOL_TALK_ZERO, conference_loop_fn_volume_talk_zero},
+	{"vol talk dn", "1", CALLER_CONTROL_VOL_TALK_DN, conference_loop_fn_volume_talk_dn},
+	{"vol listen up", "6", CALLER_CONTROL_VOL_LISTEN_UP, conference_loop_fn_volume_listen_up},
+	{"vol listen zero", "5", CALLER_CONTROL_VOL_LISTEN_ZERO, conference_loop_fn_volume_listen_zero},
+	{"vol listen dn", "4", CALLER_CONTROL_VOL_LISTEN_DN, conference_loop_fn_volume_listen_dn},
+	{"hangup", "#", CALLER_CONTROL_HANGUP, conference_loop_fn_hangup},
 	{"event", NULL, CALLER_CONTROL_EVENT, conference_loop_fn_event}
 };
+
 #define CCFNTBL_QTY (sizeof(ccfntbl)/sizeof(ccfntbl[0]))
 
 /* marshall frames from the conference (or file or tts output) to the call leg */
 /* NB. this starts the input thread after some initial setup for the call leg */
-static void conference_loop_output(conference_member_t *member)
+static void conference_loop_output(conference_member_t * member)
 {
 	switch_channel_t *channel;
-	switch_frame_t write_frame = {0};
+	switch_frame_t write_frame = { 0 };
 	uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE];
-	switch_timer_t timer = {0};
+	switch_timer_t timer = { 0 };
 	switch_codec_t *read_codec = switch_core_session_get_read_codec(member->session);
 	uint32_t interval = read_codec->implementation->microseconds_per_frame / 1000;
 	//uint32_t samples = switch_bytes_per_frame(member->conference->rate, member->conference->interval);
@@ -1465,16 +1435,13 @@
 	assert(channel != NULL);
 	assert(member->conference != NULL);
 
-	if (switch_core_timer_init(&timer, 
-							   member->conference->timer_name, 
-							   interval,
+	if (switch_core_timer_init(&timer, member->conference->timer_name, interval,
 							   //member->conference->interval, 
-							   samples, 
-							   NULL) == SWITCH_STATUS_SUCCESS) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "setup timer %s success interval: %u  samples: %u\n", 
-						  member->conference->timer_name, interval, samples);	
+							   samples, NULL) == SWITCH_STATUS_SUCCESS) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "setup timer %s success interval: %u  samples: %u\n",
+						  member->conference->timer_name, interval, samples);
 	} else {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer Setup Failed.  Conference Cannot Start\n");	
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer Setup Failed.  Conference Cannot Start\n");
 		return;
 	}
 
@@ -1490,16 +1457,17 @@
 	launch_conference_loop_input(member, switch_core_session_get_pool(member->session));
 
 	/* build a digit stream object */
-	if (member->conference->dtmf_parser != NULL && 
-        switch_ivr_digit_stream_new(member->conference->dtmf_parser, &member->digit_stream) != SWITCH_STATUS_SUCCESS) {
+	if (member->conference->dtmf_parser != NULL
+		&& switch_ivr_digit_stream_new(member->conference->dtmf_parser, &member->digit_stream) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Warning Will Robinson, there is no digit parser stream object\n");
 	}
 
-	/* Fair WARNING, If you expect the caller to hear anything or for digit handling to be proccessed, 		*/
-	/* you better not block this thread loop for more than the duration of member->conference->timer_name!	*/
-	while(switch_test_flag(member, MFLAG_RUNNING) && switch_test_flag(member, MFLAG_ITHREAD) && switch_channel_ready(channel)) {
+	/* Fair WARNING, If you expect the caller to hear anything or for digit handling to be proccessed,      */
+	/* you better not block this thread loop for more than the duration of member->conference->timer_name!  */
+	while (switch_test_flag(member, MFLAG_RUNNING) && switch_test_flag(member, MFLAG_ITHREAD)
+		   && switch_channel_ready(channel)) {
 		char dtmf[128] = "";
-		uint8_t file_frame[CONF_BUFFER_SIZE] = {0};
+		uint8_t file_frame[CONF_BUFFER_SIZE] = { 0 };
 		switch_size_t file_data_len = samples * 2;
 		switch_size_t file_sample_len = samples;
 		char *digit;
@@ -1515,8 +1483,7 @@
 			char *body = switch_event_get_body(event);
 			char *p, *freeme = NULL;
 
-			if ((p = strchr(to, '+')) && 
-				strncmp(to, CONF_CHAT_PROTO, strlen(CONF_CHAT_PROTO))) {
+			if ((p = strchr(to, '+')) && strncmp(to, CONF_CHAT_PROTO, strlen(CONF_CHAT_PROTO))) {
 				freeme = switch_mprintf("%s+%s@%s", CONF_CHAT_PROTO, member->conference->name, member->conference->domain);
 				to = freeme;
 			}
@@ -1550,32 +1517,26 @@
 						switch_ivr_digit_stream_parser_feed(member->conference->dtmf_parser, member->digit_stream, *digit);
 				}
 			}
-            /* otherwise, clock the parser so that it can handle digit timeout detection */
+			/* otherwise, clock the parser so that it can handle digit timeout detection */
 		} else if (member->conference->dtmf_parser != NULL) {
-			caller_action = (caller_control_action_t *)switch_ivr_digit_stream_parser_feed(member->conference->dtmf_parser, member->digit_stream, '\0');
+			caller_action = (caller_control_action_t *) switch_ivr_digit_stream_parser_feed(member->conference->dtmf_parser, member->digit_stream, '\0');
 		}
 
 		/* if a caller action has been detected, handle it */
 		if (caller_action != NULL && caller_action->fndesc != NULL && caller_action->fndesc->handler != NULL) {
-			//switch_channel_t *channel		 = switch_core_session_get_channel(member->session);
-			//switch_caller_profile_t *profile	 = switch_channel_get_caller_profile(channel);
-            char *param = NULL;
-
-            if (caller_action->fndesc->action != CALLER_CONTROL_MENU) {
-                param = caller_action->data;
-            }
+			//switch_channel_t *channel      = switch_core_session_get_channel(member->session);
+			//switch_caller_profile_t *profile   = switch_channel_get_caller_profile(channel);
+			char *param = NULL;
 
+			if (caller_action->fndesc->action != CALLER_CONTROL_MENU) {
+				param = caller_action->data;
+			}
 #ifdef INTENSE_DEBUG
-			switch_log_printf(SWITCH_CHANNEL_LOG, 
-                              SWITCH_LOG_INFO, 
-                              "executing caller control '%s' param '%s' on call '%u, %s, %s, %s'\n", 
-                              caller_action->fndesc->key, 
-                              param ? param : "none", 
-                              member->id, 
-                              switch_channel_get_name(channel), 
-                              profile->caller_id_name, 
-                              profile->caller_id_number
-                              );
+			switch_log_printf(SWITCH_CHANNEL_LOG,
+							  SWITCH_LOG_INFO,
+							  "executing caller control '%s' param '%s' on call '%u, %s, %s, %s'\n",
+							  caller_action->fndesc->key,
+							  param ? param : "none", member->id, switch_channel_get_name(channel), profile->caller_id_name, profile->caller_id_number);
 #endif
 
 			caller_action->fndesc->handler(member, caller_action);
@@ -1586,7 +1547,7 @@
 
 		/* handle file and TTS frames */
 		if (member->fnode) {
-            switch_mutex_lock(member->flag_mutex);
+			switch_mutex_lock(member->flag_mutex);
 			/* if we are done, clean it up */
 			if (member->fnode->done) {
 				conference_file_node_t *fnode;
@@ -1610,19 +1571,15 @@
 				/* skip this frame until leadin time has expired */
 				if (member->fnode->leadin) {
 					member->fnode->leadin--;
-				} else {	/* send the node frame instead of the conference frame to the call leg */
+				} else {		/* send the node frame instead of the conference frame to the call leg */
 					if (member->fnode->type == NODE_TYPE_SPEECH) {
 						switch_speech_flag_t flags = SWITCH_SPEECH_FLAG_BLOCKING;
 						uint32_t rate = member->conference->rate;
 
-						if (switch_core_speech_read_tts(&member->fnode->sh, 
-														file_frame, 
-														&file_data_len, 
-														&rate, 
-														&flags) == SWITCH_STATUS_SUCCESS) {
+						if (switch_core_speech_read_tts(&member->fnode->sh, file_frame, &file_data_len, &rate, &flags) == SWITCH_STATUS_SUCCESS) {
 							file_sample_len = file_data_len / 2;
 						} else {
-							file_sample_len = file_data_len  = 0;
+							file_sample_len = file_data_len = 0;
 						}
 					} else if (member->fnode->type == NODE_TYPE_FILE) {
 						switch_core_file_read(&member->fnode->fh, file_frame, &file_sample_len);
@@ -1631,10 +1588,10 @@
 
 					if (file_sample_len <= 0) {
 						member->fnode->done++;
-					} else { /* there is file node data to deliver */
+					} else {	/* there is file node data to deliver */
 						write_frame.data = file_frame;
-						write_frame.datalen = (uint32_t)file_data_len;
-						write_frame.samples = (uint32_t)file_sample_len;
+						write_frame.datalen = (uint32_t) file_data_len;
+						write_frame.samples = (uint32_t) file_sample_len;
 						/* Check for output volume adjustments */
 						if (member->volume_out_level) {
 							switch_change_sln_volume(write_frame.data, write_frame.samples, member->volume_out_level);
@@ -1648,22 +1605,22 @@
 					}
 				}
 			}
-            switch_mutex_unlock(member->flag_mutex);
-		} else {	/* send the conferecne frame to the call leg */
+			switch_mutex_unlock(member->flag_mutex);
+		} else {				/* send the conferecne frame to the call leg */
 			switch_buffer_t *use_buffer = NULL;
 			uint32_t mux_used = (uint32_t) switch_buffer_inuse(member->mux_buffer);
 
-			if (mux_used){ 
+			if (mux_used) {
 				if (mux_used < bytes) {
 					if (++low_count >= 5) {
 						/* partial frame sitting around this long is useless and builds delay */
 						switch_set_flag_locked(member, MFLAG_FLUSH_BUFFER);
 					}
 					mux_used = 0;
-				} else 	if (mux_used > bytes * 2) {
+				} else if (mux_used > bytes * 2) {
 					/* getting behind, clear the buffer */
 					switch_set_flag_locked(member, MFLAG_FLUSH_BUFFER);
-				} 
+				}
 			}
 
 			if (switch_test_flag(member, MFLAG_FLUSH_BUFFER)) {
@@ -1683,7 +1640,7 @@
 				use_buffer = member->mux_buffer;
 				low_count = 0;
 
-				if ((write_frame.datalen = (uint32_t)switch_buffer_read(use_buffer, write_frame.data, bytes))) {
+				if ((write_frame.datalen = (uint32_t) switch_buffer_read(use_buffer, write_frame.data, bytes))) {
 					if (write_frame.datalen && switch_test_flag(member, MFLAG_CAN_HEAR)) {
 						write_frame.samples = write_frame.datalen / 2;
 
@@ -1699,7 +1656,7 @@
 
 				switch_mutex_unlock(member->audio_out_mutex);
 				switch_core_timer_next(&timer);
-				
+
 			} else {
 				if (switch_test_flag(member, MFLAG_WASTE_BANDWIDTH)) {
 					switch_generate_sln_silence(write_frame.data, samples, 1400);
@@ -1711,7 +1668,7 @@
 				switch_core_timer_next(&timer);
 			}
 		}
-	} /* Rinse ... Repeat */
+	}							/* Rinse ... Repeat */
 
 	if (member->digit_stream != NULL) {
 		switch_ivr_digit_stream_destroy(member->digit_stream);
@@ -1720,8 +1677,8 @@
 	switch_clear_flag_locked(member, MFLAG_RUNNING);
 	switch_core_timer_destroy(&timer);
 
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Channel leaving conference, cause: %s\n", 
-                      switch_channel_cause2str(switch_channel_get_cause(channel)));
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Channel leaving conference, cause: %s\n",
+					  switch_channel_cause2str(switch_channel_get_cause(channel)));
 
 	/* if it's an outbound channel, store the release cause in the conference struct, we might need it */
 	if (switch_channel_test_flag(channel, CF_OUTBOUND)) {
@@ -1729,24 +1686,24 @@
 	}
 
 	/* Wait for the input thead to end */
-	while(switch_test_flag(member, MFLAG_ITHREAD)) {
+	while (switch_test_flag(member, MFLAG_ITHREAD)) {
 		switch_yield(1000);
 	}
 }
 
 /* Sub-Routine called by a record entity inside a conference */
-static void *SWITCH_THREAD_FUNC conference_record_thread_run(switch_thread_t *thread, void *obj)
+static void *SWITCH_THREAD_FUNC conference_record_thread_run(switch_thread_t * thread, void *obj)
 {
 	uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE];
-	switch_file_handle_t fh = {0};
-	conference_member_t smember = {0}, *member;
+	switch_file_handle_t fh = { 0 };
+	conference_member_t smember = { 0 }, *member;
 	conference_record_t *rec = (conference_record_t *) obj;
 	conference_obj_t *conference = rec->conference;
 	uint32_t samples = switch_bytes_per_frame(conference->rate, conference->interval);
 	//uint32_t bytes = samples * 2;
 	uint32_t low_count = 0, mux_used;
 	char *vval;
-	switch_timer_t timer = {0};
+	switch_timer_t timer = { 0 };
 	uint32_t rlen;
 
 	if (switch_thread_rwlock_tryrdlock(conference->rwlock) != SWITCH_STATUS_SUCCESS) {
@@ -1791,11 +1748,8 @@
 		goto end;
 	}
 
-	if (switch_core_file_open(&fh, 
-							  rec->path, 
-							  (uint8_t)1,
-							  conference->rate,
-							  SWITCH_FILE_FLAG_WRITE | SWITCH_FILE_DATA_SHORT, 
+	if (switch_core_file_open(&fh,
+							  rec->path, (uint8_t) 1, conference->rate, SWITCH_FILE_FLAG_WRITE | SWITCH_FILE_DATA_SHORT,
 							  rec->pool) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening File [%s]\n", rec->path);
 		goto end;
@@ -1803,12 +1757,12 @@
 
 
 	if (switch_core_timer_init(&timer, conference->timer_name, conference->interval, samples, rec->pool) == SWITCH_STATUS_SUCCESS) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "setup timer success interval: %u  samples: %u\n", conference->interval, samples);	
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "setup timer success interval: %u  samples: %u\n", conference->interval, samples);
 	} else {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer Setup Failed.  Conference Cannot Start\n");	
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer Setup Failed.  Conference Cannot Start\n");
 		goto end;
 	}
-	
+
 	if ((vval = switch_mprintf("Conference %s", conference->name))) {
 		switch_core_file_set_string(&fh, SWITCH_AUDIO_COL_STR_TITLE, vval);
 		switch_safe_free(vval);
@@ -1816,7 +1770,7 @@
 
 	switch_core_file_set_string(&fh, SWITCH_AUDIO_COL_STR_ARTIST, "FreeSWITCH mod_conference Software Conference Module");
 
-	while(switch_test_flag(member, MFLAG_RUNNING) && switch_test_flag(conference, CFLAG_RUNNING) && conference->count) {
+	while (switch_test_flag(member, MFLAG_RUNNING) && switch_test_flag(conference, CFLAG_RUNNING) && conference->count) {
 		mux_used = (uint32_t) switch_buffer_inuse(member->mux_buffer);
 
 		if (switch_test_flag(member, MFLAG_FLUSH_BUFFER)) {
@@ -1833,8 +1787,8 @@
 			/* Flush the output buffer and write all the data (presumably muxed) to the file */
 			switch_mutex_lock(member->audio_out_mutex);
 			low_count = 0;
-			
-			if ((rlen = (uint32_t)switch_buffer_read(member->mux_buffer, data, sizeof(data)))) {
+
+			if ((rlen = (uint32_t) switch_buffer_read(member->mux_buffer, data, sizeof(data)))) {
 				if (!switch_test_flag((&fh), SWITCH_FILE_PAUSE)) {
 					switch_size_t len = (switch_size_t) rlen / sizeof(int16_t);
 					if (switch_core_file_write(&fh, data, &len) != SWITCH_STATUS_SUCCESS) {
@@ -1847,9 +1801,9 @@
 		} else {
 			switch_core_timer_next(&timer);
 		}
-	} /* Rinse ... Repeat */
+	}							/* Rinse ... Repeat */
 
- end:
+  end:
 
 	switch_core_timer_destroy(&timer);
 	conference_del_member(conference, member);
@@ -1876,38 +1830,38 @@
 }
 
 /* Make files stop playing in a conference either the current one or all of them */
-static uint32_t conference_stop_file(conference_obj_t *conference, file_stop_t stop)
+static uint32_t conference_stop_file(conference_obj_t * conference, file_stop_t stop)
 {
 	uint32_t count = 0;
-    conference_file_node_t *nptr;
+	conference_file_node_t *nptr;
 
-    assert(conference != NULL);
+	assert(conference != NULL);
 
-    switch_mutex_lock(conference->mutex);
+	switch_mutex_lock(conference->mutex);
 
-    if (stop == FILE_STOP_ALL) {
-        for (nptr = conference->fnode; nptr; nptr = nptr->next) {
-            nptr->done++;
-            count++;
-        }
+	if (stop == FILE_STOP_ALL) {
+		for (nptr = conference->fnode; nptr; nptr = nptr->next) {
+			nptr->done++;
+			count++;
+		}
 		if (conference->async_fnode) {
 			conference->async_fnode->done++;
 			count++;
 		}
-    } else {
-        if (conference->fnode) {
-            conference->fnode->done++;
-            count++;
-        }
-    }
-    
-    switch_mutex_unlock(conference->mutex);	
+	} else {
+		if (conference->fnode) {
+			conference->fnode->done++;
+			count++;
+		}
+	}
+
+	switch_mutex_unlock(conference->mutex);
 
 	return count;
 }
 
 /* stop playing a file for the member of the conference */
-static uint32_t conference_member_stop_file(conference_member_t *member, file_stop_t stop)
+static uint32_t conference_member_stop_file(conference_member_t * member, file_stop_t stop)
 {
 	uint32_t count = 0;
 
@@ -1935,88 +1889,84 @@
 }
 
 /* Play a file in the conference room */
-static switch_status_t conference_play_file(conference_obj_t *conference, char *file, uint32_t leadin, switch_channel_t *channel, uint8_t async)
+static switch_status_t conference_play_file(conference_obj_t * conference, char *file, uint32_t leadin, switch_channel_t *channel, uint8_t async)
 {
 	switch_status_t status = SWITCH_STATUS_SUCCESS;
-    conference_file_node_t *fnode, *nptr = NULL;
-    switch_memory_pool_t *pool;
-    uint32_t count;
-    char *dfile = NULL, *expanded = NULL;
-
-    assert(conference != NULL);
-
-    switch_mutex_lock(conference->mutex);
-    switch_mutex_lock(conference->member_mutex);
-    count = conference->count;
-    switch_mutex_unlock(conference->member_mutex);
-    switch_mutex_unlock(conference->mutex);	
-
-    if (!count) {
-        status = SWITCH_STATUS_FALSE;
-        goto done;
-    }
-
-    if (channel) {
-        if ((expanded = switch_channel_expand_variables(channel, file)) != file) {
-            file = expanded;
-        } else {
-            expanded = NULL;
-        }
-    }
-
-    if (!async && !strncasecmp(file, "say:", 4)) {
-        status = conference_say(conference, file + 4, leadin);
-        goto done;
-    } 
-
-    if (!switch_is_file_path(file)) {
-        if (conference->sound_prefix) {
-            if (!(dfile = switch_mprintf("%s/%s", conference->sound_prefix, file))) {
-                goto done;
-            }
-            file = dfile;
-        } else if (!async) {
-            status = conference_say(conference, file, leadin);
-            goto done;  
-        } else {
+	conference_file_node_t *fnode, *nptr = NULL;
+	switch_memory_pool_t *pool;
+	uint32_t count;
+	char *dfile = NULL, *expanded = NULL;
+
+	assert(conference != NULL);
+
+	switch_mutex_lock(conference->mutex);
+	switch_mutex_lock(conference->member_mutex);
+	count = conference->count;
+	switch_mutex_unlock(conference->member_mutex);
+	switch_mutex_unlock(conference->mutex);
+
+	if (!count) {
+		status = SWITCH_STATUS_FALSE;
+		goto done;
+	}
+
+	if (channel) {
+		if ((expanded = switch_channel_expand_variables(channel, file)) != file) {
+			file = expanded;
+		} else {
+			expanded = NULL;
+		}
+	}
+
+	if (!async && !strncasecmp(file, "say:", 4)) {
+		status = conference_say(conference, file + 4, leadin);
+		goto done;
+	}
+
+	if (!switch_is_file_path(file)) {
+		if (conference->sound_prefix) {
+			if (!(dfile = switch_mprintf("%s/%s", conference->sound_prefix, file))) {
+				goto done;
+			}
+			file = dfile;
+		} else if (!async) {
+			status = conference_say(conference, file, leadin);
+			goto done;
+		} else {
 			goto done;
 		}
-    }
+	}
+
+	/* Setup a memory pool to use. */
+	if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Pool Failure\n");
+		status = SWITCH_STATUS_MEMERR;
+		goto done;
+	}
+
+	/* Create a node object */
+	if (!(fnode = switch_core_alloc(pool, sizeof(*fnode)))) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Alloc Failure\n");
+		switch_core_destroy_memory_pool(&pool);
+		status = SWITCH_STATUS_MEMERR;
+		goto done;
+	}
 
-    /* Setup a memory pool to use. */
-    if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Pool Failure\n");
-        status = SWITCH_STATUS_MEMERR;
-        goto done;
-    }
-
-    /* Create a node object*/
-    if (!(fnode = switch_core_alloc(pool, sizeof(*fnode)))) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Alloc Failure\n");
-        switch_core_destroy_memory_pool(&pool);
-        status = SWITCH_STATUS_MEMERR;
-        goto done;
-    }
-
-    fnode->type = NODE_TYPE_FILE;
-    fnode->leadin = leadin;
-
-    /* Open the file */
-    if (switch_core_file_open(&fnode->fh, 
-                              file, 
-							  (uint8_t)1,
-							  conference->rate,
-                              SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, 
-                              pool) != SWITCH_STATUS_SUCCESS) {
-        switch_core_destroy_memory_pool(&pool);
-        status = SWITCH_STATUS_NOTFOUND;
-        goto done;
-    }
+	fnode->type = NODE_TYPE_FILE;
+	fnode->leadin = leadin;
 
-    fnode->pool = pool;
+	/* Open the file */
+	if (switch_core_file_open(&fnode->fh, file, (uint8_t) 1, conference->rate, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, pool) !=
+		SWITCH_STATUS_SUCCESS) {
+		switch_core_destroy_memory_pool(&pool);
+		status = SWITCH_STATUS_NOTFOUND;
+		goto done;
+	}
+
+	fnode->pool = pool;
 	fnode->async = async;
-    /* Queue the node */
-    switch_mutex_lock(conference->mutex);
+	/* Queue the node */
+	switch_mutex_lock(conference->mutex);
 
 	if (async) {
 		if (conference->async_fnode) {
@@ -2028,12 +1978,12 @@
 			switch_memory_pool_t *pool;
 			switch_core_file_close(&nptr->fh);
 			pool = nptr->pool;
-            switch_core_destroy_memory_pool(&pool);
+			switch_core_destroy_memory_pool(&pool);
 		}
-		
+
 	} else {
 		for (nptr = conference->fnode; nptr && nptr->next; nptr = nptr->next);
-		
+
 		if (nptr) {
 			nptr->next = fnode;
 		} else {
@@ -2041,1027 +1991,1002 @@
 		}
 	}
 
-    switch_mutex_unlock(conference->mutex);
+	switch_mutex_unlock(conference->mutex);
 
- done:
+  done:
 
 
-    switch_safe_free(expanded);
-    switch_safe_free(dfile);
+	switch_safe_free(expanded);
+	switch_safe_free(dfile);
 
-	
 
-    return status;
+
+	return status;
 }
 
 /* Play a file in the conference room to a member */
-static switch_status_t conference_member_play_file(conference_member_t *member, char *file, uint32_t leadin)
+static switch_status_t conference_member_play_file(conference_member_t * member, char *file, uint32_t leadin)
 {
-    switch_status_t status = SWITCH_STATUS_FALSE;
-    char *dfile = NULL, *expanded = NULL;
+	switch_status_t status = SWITCH_STATUS_FALSE;
+	char *dfile = NULL, *expanded = NULL;
 
-    if (member != NULL && file != NULL) {
-        conference_file_node_t *fnode, *nptr;
-        switch_memory_pool_t *pool;
-
-        if ((expanded = switch_channel_expand_variables(switch_core_session_get_channel(member->session), file)) != file) {
-            file = expanded;
-        } else {
-            expanded = NULL;
-        }
-
-        if (!strncasecmp(file, "say:", 4)) {
-            status = conference_say(member->conference, file + 4, leadin);
-            goto done;
-        } 
-
-        if (!switch_is_file_path(file)) {
-            if (member->conference->sound_prefix) {
-                if (!(dfile = switch_mprintf("%s/%s", member->conference->sound_prefix, file))) {
-                    goto done;
-                }
-                file = dfile;
-            } else {
-                status = conference_say(member->conference, file, leadin);
-                goto done;  
-            }
-        }
-
-        /* Setup a memory pool to use. */
-        if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Pool Failure\n");
-            status = SWITCH_STATUS_MEMERR;
-            goto done;
-        }
-
-        /* Create a node object*/
-        if (!(fnode = switch_core_alloc(pool, sizeof(*fnode)))) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Alloc Failure\n");
-            switch_core_destroy_memory_pool(&pool);
-            status = SWITCH_STATUS_MEMERR;
-            goto done;
-        }
-
-        fnode->type = NODE_TYPE_FILE;
-        fnode->leadin = leadin;
-
-        /* Open the file */
-        if (switch_core_file_open(&fnode->fh, 
-                                  file, 
-								  (uint8_t)1,
-								  member->conference->rate,
-                                  SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, 
-                                  pool) != SWITCH_STATUS_SUCCESS) {
-            switch_core_destroy_memory_pool(&pool);
-            status = SWITCH_STATUS_NOTFOUND;
-            goto done;
-        }
-
-        fnode->pool = pool;
-
-        /* Queue the node */
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "queueing file '%s' for play\n", file);
-        switch_mutex_lock(member->flag_mutex);
-        for (nptr = member->fnode; nptr && nptr->next; nptr = nptr->next);
-
-        if (nptr) {
-            nptr->next = fnode;
-        } else {
-            member->fnode = fnode;
-        }
-        switch_mutex_unlock(member->flag_mutex);
-
-        status = SWITCH_STATUS_SUCCESS;
-    }
+	if (member != NULL && file != NULL) {
+		conference_file_node_t *fnode, *nptr;
+		switch_memory_pool_t *pool;
 
- done:
+		if ((expanded = switch_channel_expand_variables(switch_core_session_get_channel(member->session), file)) != file) {
+			file = expanded;
+		} else {
+			expanded = NULL;
+		}
 
-    switch_safe_free(expanded);
-    switch_safe_free(dfile);
+		if (!strncasecmp(file, "say:", 4)) {
+			status = conference_say(member->conference, file + 4, leadin);
+			goto done;
+		}
 
-    return status;
-}
+		if (!switch_is_file_path(file)) {
+			if (member->conference->sound_prefix) {
+				if (!(dfile = switch_mprintf("%s/%s", member->conference->sound_prefix, file))) {
+					goto done;
+				}
+				file = dfile;
+			} else {
+				status = conference_say(member->conference, file, leadin);
+				goto done;
+			}
+		}
 
-/* Say some thing with TTS in the conference room */
-static switch_status_t conference_member_say(conference_member_t *member, char *text, uint32_t leadin)
-{
-    switch_status_t status = SWITCH_STATUS_FALSE;
+		/* Setup a memory pool to use. */
+		if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Pool Failure\n");
+			status = SWITCH_STATUS_MEMERR;
+			goto done;
+		}
+
+		/* Create a node object */
+		if (!(fnode = switch_core_alloc(pool, sizeof(*fnode)))) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Alloc Failure\n");
+			switch_core_destroy_memory_pool(&pool);
+			status = SWITCH_STATUS_MEMERR;
+			goto done;
+		}
 
-    if (member != NULL && !switch_strlen_zero(text)) {
-        conference_obj_t *conference = (member != NULL ? member->conference : NULL);
-        conference_file_node_t *fnode, *nptr;
-        switch_memory_pool_t *pool;
-        switch_speech_flag_t flags = SWITCH_SPEECH_FLAG_NONE;
-
-        assert(conference != NULL);
-        
-        if (!(conference->tts_engine && conference->tts_voice)) {
-            return SWITCH_STATUS_SUCCESS;
-        }
-
-        /* Setup a memory pool to use. */
-        if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Pool Failure\n");
-            return SWITCH_STATUS_MEMERR;
-        }
-
-        /* Create a node object*/
-        if (!(fnode = switch_core_alloc(pool, sizeof(*fnode)))) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Alloc Failure\n");
-            switch_core_destroy_memory_pool(&pool);
-            return SWITCH_STATUS_MEMERR;
-        }
-
-        fnode->type = NODE_TYPE_SPEECH;
-        fnode->leadin = leadin;
-        fnode->pool = pool;
-
-        memset(&fnode->sh, 0, sizeof(fnode->sh));
-        if (switch_core_speech_open(&fnode->sh, 
-                                    conference->tts_engine, 
-                                    conference->tts_voice, 
-                                    conference->rate, 
-                                    &flags, 
-                                    fnode->pool) != SWITCH_STATUS_SUCCESS) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid TTS module [%s]!\n", conference->tts_engine);
-            return SWITCH_STATUS_FALSE;
-        }
-
-        /* Queue the node */
-        switch_mutex_lock(member->flag_mutex);
-        for (nptr = member->fnode; nptr && nptr->next; nptr = nptr->next);
-
-        if (nptr) {
-            nptr->next = fnode;
-        } else {
-            member->fnode = fnode;
-        }
-
-        /* Begin Generation */
-        switch_sleep(200000);
-        switch_core_speech_feed_tts(&fnode->sh, text, &flags);
-        switch_mutex_unlock(member->flag_mutex);
+		fnode->type = NODE_TYPE_FILE;
+		fnode->leadin = leadin;
 
-        status = SWITCH_STATUS_SUCCESS;
-    }
+		/* Open the file */
+		if (switch_core_file_open(&fnode->fh,
+								  file, (uint8_t) 1, member->conference->rate, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT,
+								  pool) != SWITCH_STATUS_SUCCESS) {
+			switch_core_destroy_memory_pool(&pool);
+			status = SWITCH_STATUS_NOTFOUND;
+			goto done;
+		}
 
-    return status;
-}
+		fnode->pool = pool;
 
-/* Say some thing with TTS in the conference room */
-static switch_status_t conference_say(conference_obj_t *conference, const char *text, uint32_t leadin)
-{
-    switch_status_t status = SWITCH_STATUS_FALSE;
-    conference_file_node_t *fnode, *nptr;
-    switch_memory_pool_t *pool;
-    switch_speech_flag_t flags = SWITCH_SPEECH_FLAG_NONE;
-    uint32_t count;
-
-    assert(conference != NULL);
-
-    if (switch_strlen_zero(text)) {
-        return SWITCH_STATUS_GENERR;
-    }
-
-    switch_mutex_lock(conference->mutex);
-    switch_mutex_lock(conference->member_mutex);
-    count = conference->count;
-    if (!(conference->tts_engine && conference->tts_voice)) {
-        count = 0;
-    }
-    switch_mutex_unlock(conference->member_mutex);
-    switch_mutex_unlock(conference->mutex);	
-
-    if (!count) {
-        return SWITCH_STATUS_FALSE;
-    }
-
-    /* Setup a memory pool to use. */
-    if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Pool Failure\n");
-        return SWITCH_STATUS_MEMERR;
-    }
-
-    /* Create a node object*/
-    if (!(fnode = switch_core_alloc(pool, sizeof(*fnode)))) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Alloc Failure\n");
-        switch_core_destroy_memory_pool(&pool);
-        return SWITCH_STATUS_MEMERR;
-    }
-
-    fnode->type = NODE_TYPE_SPEECH;
-    fnode->leadin = leadin;
-
-    memset(&fnode->sh, 0, sizeof(fnode->sh));
-    if (switch_core_speech_open(&fnode->sh, 
-                                conference->tts_engine, 
-                                conference->tts_voice, 
-                                conference->rate, 
-                                &flags, 
-                                conference->pool) != SWITCH_STATUS_SUCCESS) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid TTS module [%s]!\n", conference->tts_engine);
-        return SWITCH_STATUS_FALSE;
-    }
-
-    fnode->pool = pool;
-
-    /* Queue the node */
-    switch_mutex_lock(conference->mutex);
-    for (nptr = conference->fnode; nptr && nptr->next; nptr = nptr->next);
-
-    if (nptr) {
-        nptr->next = fnode;
-    } else {
-        conference->fnode = fnode;
-    }
-
-    /* Begin Generation */
-    switch_sleep(200000);
-    switch_core_speech_feed_tts(&fnode->sh, (char *)text, &flags);
-    switch_mutex_unlock(conference->mutex);
+		/* Queue the node */
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "queueing file '%s' for play\n", file);
+		switch_mutex_lock(member->flag_mutex);
+		for (nptr = member->fnode; nptr && nptr->next; nptr = nptr->next);
 
-    status = SWITCH_STATUS_SUCCESS;
+		if (nptr) {
+			nptr->next = fnode;
+		} else {
+			member->fnode = fnode;
+		}
+		switch_mutex_unlock(member->flag_mutex);
 
-    return status;
-}
+		status = SWITCH_STATUS_SUCCESS;
+	}
 
-/* execute a callback for every member of the conference */
-static void conference_member_itterator(conference_obj_t *conference, switch_stream_handle_t *stream, conf_api_member_cmd_t pfncallback, void *data)
-{
-    conference_member_t *member = NULL;
+  done:
 
-    assert(conference != NULL);
-    assert(stream != NULL);
-    assert(pfncallback != NULL);
+	switch_safe_free(expanded);
+	switch_safe_free(dfile);
 
-    switch_mutex_lock(conference->member_mutex);
-    for (member = conference->members; member; member = member->next) {
-        pfncallback(member, stream, data);
-    }
-    switch_mutex_unlock(conference->member_mutex);
-	
+	return status;
 }
 
-static void conference_list_pretty(conference_obj_t *conference, switch_stream_handle_t *stream)
+/* Say some thing with TTS in the conference room */
+static switch_status_t conference_member_say(conference_member_t * member, char *text, uint32_t leadin)
 {
-    conference_member_t *member = NULL;
+	switch_status_t status = SWITCH_STATUS_FALSE;
 
-    assert(conference != NULL);
-    assert(stream != NULL);
+	if (member != NULL && !switch_strlen_zero(text)) {
+		conference_obj_t *conference = (member != NULL ? member->conference : NULL);
+		conference_file_node_t *fnode, *nptr;
+		switch_memory_pool_t *pool;
+		switch_speech_flag_t flags = SWITCH_SPEECH_FLAG_NONE;
 
-    switch_mutex_lock(conference->member_mutex);
-    //		stream->write_function(stream, "<pre>Current Callers:\n");
+		assert(conference != NULL);
 
-    for (member = conference->members; member; member = member->next) {
-        switch_channel_t *channel;
-        switch_caller_profile_t *profile;
+		if (!(conference->tts_engine && conference->tts_voice)) {
+			return SWITCH_STATUS_SUCCESS;
+		}
 
-        if (switch_test_flag(member, MFLAG_NOCHANNEL)) {
-            continue;
-        }
-        channel = switch_core_session_get_channel(member->session);
-        profile = switch_channel_get_caller_profile(channel);
+		/* Setup a memory pool to use. */
+		if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Pool Failure\n");
+			return SWITCH_STATUS_MEMERR;
+		}
 
+		/* Create a node object */
+		if (!(fnode = switch_core_alloc(pool, sizeof(*fnode)))) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Alloc Failure\n");
+			switch_core_destroy_memory_pool(&pool);
+			return SWITCH_STATUS_MEMERR;
+		}
 
-        stream->write_function(stream, "%u) %s (%s)\n", 
-                               member->id, 
-                               profile->caller_id_name, 
-                               profile->caller_id_number
-                               );
+		fnode->type = NODE_TYPE_SPEECH;
+		fnode->leadin = leadin;
+		fnode->pool = pool;
 
-    }
+		memset(&fnode->sh, 0, sizeof(fnode->sh));
+		if (switch_core_speech_open(&fnode->sh, conference->tts_engine, conference->tts_voice, conference->rate, &flags, fnode->pool) !=
+			SWITCH_STATUS_SUCCESS) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid TTS module [%s]!\n", conference->tts_engine);
+			return SWITCH_STATUS_FALSE;
+		}
 
-    switch_mutex_unlock(conference->member_mutex);
-	
-}
+		/* Queue the node */
+		switch_mutex_lock(member->flag_mutex);
+		for (nptr = member->fnode; nptr && nptr->next; nptr = nptr->next);
 
-static void conference_list(conference_obj_t *conference, switch_stream_handle_t *stream, char *delim)
-{
-    conference_member_t *member = NULL;
+		if (nptr) {
+			nptr->next = fnode;
+		} else {
+			member->fnode = fnode;
+		}
 
-    assert(conference != NULL);
-    assert(stream != NULL);
-    assert(delim != NULL);
+		/* Begin Generation */
+		switch_sleep(200000);
+		switch_core_speech_feed_tts(&fnode->sh, text, &flags);
+		switch_mutex_unlock(member->flag_mutex);
 
+		status = SWITCH_STATUS_SUCCESS;
+	}
 
-    switch_mutex_lock(conference->member_mutex);
+	return status;
+}
 
-    for (member = conference->members; member; member = member->next) {
-        switch_channel_t *channel;
-        switch_caller_profile_t *profile;
-        char *uuid;
-        char *name;
-        uint32_t count = 0;
+/* Say some thing with TTS in the conference room */
+static switch_status_t conference_say(conference_obj_t * conference, const char *text, uint32_t leadin)
+{
+	switch_status_t status = SWITCH_STATUS_FALSE;
+	conference_file_node_t *fnode, *nptr;
+	switch_memory_pool_t *pool;
+	switch_speech_flag_t flags = SWITCH_SPEECH_FLAG_NONE;
+	uint32_t count;
 
-        if (switch_test_flag(member, MFLAG_NOCHANNEL)) {
-            continue;
-        }
+	assert(conference != NULL);
 
-        uuid = switch_core_session_get_uuid(member->session);
-        channel = switch_core_session_get_channel(member->session);
-        profile = switch_channel_get_caller_profile(channel);
-        name = switch_channel_get_name(channel);
+	if (switch_strlen_zero(text)) {
+		return SWITCH_STATUS_GENERR;
+	}
 
+	switch_mutex_lock(conference->mutex);
+	switch_mutex_lock(conference->member_mutex);
+	count = conference->count;
+	if (!(conference->tts_engine && conference->tts_voice)) {
+		count = 0;
+	}
+	switch_mutex_unlock(conference->member_mutex);
+	switch_mutex_unlock(conference->mutex);
 
-        stream->write_function(stream, "%u%s%s%s%s%s%s%s%s%s", 
-                               member->id, delim, 
-                               name, delim, 
-                               uuid, delim, 
-                               profile->caller_id_name, delim, 
-                               profile->caller_id_number, delim);
+	if (!count) {
+		return SWITCH_STATUS_FALSE;
+	}
 
-        if (switch_test_flag(member, MFLAG_CAN_HEAR)) {
-            stream->write_function(stream, "hear");
-            count++;
-        }
+	/* Setup a memory pool to use. */
+	if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Pool Failure\n");
+		return SWITCH_STATUS_MEMERR;
+	}
 
-        if (switch_test_flag(member, MFLAG_CAN_SPEAK)) {
-            stream->write_function(stream, "%s%s", count ? "|" : "", "speak");
-            count++;
-        }
+	/* Create a node object */
+	if (!(fnode = switch_core_alloc(pool, sizeof(*fnode)))) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Alloc Failure\n");
+		switch_core_destroy_memory_pool(&pool);
+		return SWITCH_STATUS_MEMERR;
+	}
 
-        stream->write_function(stream, "%s%d%s%d%s%d\n", 
-                               delim, 
-                               member->volume_in_level, delim, 
-                               member->volume_out_level, delim, 
-                               member->energy_level);
-    }
+	fnode->type = NODE_TYPE_SPEECH;
+	fnode->leadin = leadin;
 
-    switch_mutex_unlock(conference->member_mutex);
-	
-}
+	memset(&fnode->sh, 0, sizeof(fnode->sh));
+	if (switch_core_speech_open(&fnode->sh, conference->tts_engine, conference->tts_voice, conference->rate, &flags, conference->pool) !=
+		SWITCH_STATUS_SUCCESS) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid TTS module [%s]!\n", conference->tts_engine);
+		return SWITCH_STATUS_FALSE;
+	}
 
-static switch_status_t conf_api_sub_mute(conference_member_t *member, switch_stream_handle_t *stream, void *data)
-{
-    switch_status_t ret_status = SWITCH_STATUS_SUCCESS;
+	fnode->pool = pool;
 
-    if (member != NULL) {
-        switch_event_t *event;
+	/* Queue the node */
+	switch_mutex_lock(conference->mutex);
+	for (nptr = conference->fnode; nptr && nptr->next; nptr = nptr->next);
 
-        switch_clear_flag_locked(member, MFLAG_CAN_SPEAK);
-        if (member->conference->muted_sound) {
-            conference_member_play_file(member, member->conference->muted_sound, 0);
-        } else {
-            char msg[512];
+	if (nptr) {
+		nptr->next = fnode;
+	} else {
+		conference->fnode = fnode;
+	}
 
-            snprintf(msg, sizeof(msg), "Muted");
-            conference_member_say(member, msg, 0);
-        }
-        if (stream != NULL) {
-            stream->write_function(stream, "OK mute %u\n", member->id);
-        }
-        if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
-            switch_channel_t *channel = switch_core_session_get_channel(member->session);
-            switch_channel_event_set_data(channel, event);
+	/* Begin Generation */
+	switch_sleep(200000);
+	switch_core_speech_feed_tts(&fnode->sh, (char *) text, &flags);
+	switch_mutex_unlock(conference->mutex);
 
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", "%s", member->conference->name);
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", member->id);
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "mute-member");
-            switch_event_fire(&event);
-        }
-    } else {
-        ret_status = SWITCH_STATUS_GENERR;
-    }
+	status = SWITCH_STATUS_SUCCESS;
 
-    return ret_status;
+	return status;
 }
 
-static switch_status_t conf_api_sub_unmute(conference_member_t *member, switch_stream_handle_t *stream, void *data)
+/* execute a callback for every member of the conference */
+static void conference_member_itterator(conference_obj_t * conference, switch_stream_handle_t *stream, conf_api_member_cmd_t pfncallback, void *data)
 {
-    switch_status_t ret_status = SWITCH_STATUS_SUCCESS;
-
-    if (member != NULL) {
-        switch_event_t *event;
-
-        switch_set_flag_locked(member, MFLAG_CAN_SPEAK);
-        if (stream != NULL) {
-            stream->write_function(stream, "OK unmute %u\n", member->id);
-        }
-        if (member->conference->unmuted_sound) {
-            conference_member_play_file(member, member->conference->unmuted_sound, 0);
-        } else {
-            char msg[512];
+	conference_member_t *member = NULL;
 
-            snprintf(msg, sizeof(msg), "Un-Muted");
-            conference_member_say(member, msg, 0);
-        }
-        if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
-            switch_channel_t *channel = switch_core_session_get_channel(member->session);
-            switch_channel_event_set_data(channel, event);
+	assert(conference != NULL);
+	assert(stream != NULL);
+	assert(pfncallback != NULL);
 
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", "%s", member->conference->name);
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", member->id);
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "unmute-member");
-            switch_event_fire(&event);
-        }
-    } else {
-        ret_status = SWITCH_STATUS_GENERR;
-    }
+	switch_mutex_lock(conference->member_mutex);
+	for (member = conference->members; member; member = member->next) {
+		pfncallback(member, stream, data);
+	}
+	switch_mutex_unlock(conference->member_mutex);
 
-    return ret_status;
 }
 
-static switch_status_t conf_api_sub_deaf(conference_member_t *member, switch_stream_handle_t *stream, void *data)
+static void conference_list_pretty(conference_obj_t * conference, switch_stream_handle_t *stream)
 {
-    switch_status_t ret_status = SWITCH_STATUS_SUCCESS;
+	conference_member_t *member = NULL;
 
-    if (member != NULL) {
-        switch_event_t *event;
+	assert(conference != NULL);
+	assert(stream != NULL);
 
-        switch_clear_flag_locked(member, MFLAG_CAN_HEAR);
-        if (stream != NULL) {
-            stream->write_function(stream, "OK deaf %u\n", member->id);
-        }
-        if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
-            switch_channel_t *channel = switch_core_session_get_channel(member->session);
-            switch_channel_event_set_data(channel, event);
+	switch_mutex_lock(conference->member_mutex);
+	//      stream->write_function(stream, "<pre>Current Callers:\n");
 
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", "%s", member->conference->name);
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", member->id);
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "deaf-member");
-            switch_event_fire(&event);
-        }
-    } else {
-        ret_status = SWITCH_STATUS_GENERR;
-    }
+	for (member = conference->members; member; member = member->next) {
+		switch_channel_t *channel;
+		switch_caller_profile_t *profile;
 
-    return ret_status;
-}
+		if (switch_test_flag(member, MFLAG_NOCHANNEL)) {
+			continue;
+		}
+		channel = switch_core_session_get_channel(member->session);
+		profile = switch_channel_get_caller_profile(channel);
 
-static switch_status_t conf_api_sub_undeaf(conference_member_t *member, switch_stream_handle_t *stream, void *data)
-{
-    switch_status_t ret_status = SWITCH_STATUS_SUCCESS;
 
-    if (member != NULL) {
-        switch_event_t *event;
+		stream->write_function(stream, "%u) %s (%s)\n", member->id, profile->caller_id_name, profile->caller_id_number);
 
-        switch_set_flag_locked(member, MFLAG_CAN_HEAR);
-        if (stream != NULL) {
-            stream->write_function(stream, "OK undeaf %u\n", member->id);
-        }
-        if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
-            switch_channel_t *channel = switch_core_session_get_channel(member->session);
-            switch_channel_event_set_data(channel, event);
+	}
 
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", "%s", member->conference->name);
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", member->id);
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "undeaf-member");
-            switch_event_fire(&event);
-        }
-    } else {
-        ret_status = SWITCH_STATUS_GENERR;
-    }
+	switch_mutex_unlock(conference->member_mutex);
 
-    return ret_status;
 }
 
-static switch_status_t conf_api_sub_kick(conference_member_t *member, switch_stream_handle_t *stream, void *data)
+static void conference_list(conference_obj_t * conference, switch_stream_handle_t *stream, char *delim)
 {
-    switch_status_t ret_status = SWITCH_STATUS_SUCCESS;
-
-    if (member != NULL) {
-        switch_event_t *event;
-
-        switch_mutex_lock(member->flag_mutex);
-        switch_clear_flag(member, MFLAG_RUNNING);
-        switch_set_flag(member, MFLAG_KICKED);
-        switch_core_session_kill_channel(member->session, SWITCH_SIG_BREAK);
-        switch_mutex_unlock(member->flag_mutex);
-
-        if (stream != NULL) {
-            stream->write_function(stream, "OK kicked %u\n", member->id);
-        }
+	conference_member_t *member = NULL;
 
-        if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
-            switch_channel_t *channel = switch_core_session_get_channel(member->session);
-            switch_channel_event_set_data(channel, event);
+	assert(conference != NULL);
+	assert(stream != NULL);
+	assert(delim != NULL);
 
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", "%s", member->conference->name);
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", member->id);
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "kick-member");
-            switch_event_fire(&event);
-        }
-    } else {
-        ret_status = SWITCH_STATUS_GENERR;
-    }
 
-    return ret_status;
-}
+	switch_mutex_lock(conference->member_mutex);
 
+	for (member = conference->members; member; member = member->next) {
+		switch_channel_t *channel;
+		switch_caller_profile_t *profile;
+		char *uuid;
+		char *name;
+		uint32_t count = 0;
 
-static switch_status_t conf_api_sub_dtmf(conference_member_t *member, switch_stream_handle_t *stream, void *data)
-{
-    switch_event_t *event;
-    char *dtmf = (char *) data;
+		if (switch_test_flag(member, MFLAG_NOCHANNEL)) {
+			continue;
+		}
 
-    if (member == NULL) {
-        stream->write_function(stream, "Invalid member!\n");
-        return SWITCH_STATUS_GENERR;
-    }
+		uuid = switch_core_session_get_uuid(member->session);
+		channel = switch_core_session_get_channel(member->session);
+		profile = switch_channel_get_caller_profile(channel);
+		name = switch_channel_get_name(channel);
 
-    if (switch_strlen_zero(dtmf)) {
-        stream->write_function(stream, "Invalid input!\n");
-        return SWITCH_STATUS_GENERR;
-    }
 
-    
-    switch_mutex_lock(member->flag_mutex);
-    switch_core_session_kill_channel(member->session, SWITCH_SIG_BREAK);
-    switch_core_session_send_dtmf(member->session, dtmf);
-    switch_mutex_unlock(member->flag_mutex);
+		stream->write_function(stream, "%u%s%s%s%s%s%s%s%s%s",
+							   member->id, delim, name, delim, uuid, delim, profile->caller_id_name, delim, profile->caller_id_number, delim);
 
+		if (switch_test_flag(member, MFLAG_CAN_HEAR)) {
+			stream->write_function(stream, "hear");
+			count++;
+		}
 
-    if (stream != NULL) {
-        stream->write_function(stream, "OK sent %s to %u\n", (char *) data, member->id);
-    }
+		if (switch_test_flag(member, MFLAG_CAN_SPEAK)) {
+			stream->write_function(stream, "%s%s", count ? "|" : "", "speak");
+			count++;
+		}
 
-    if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
-        switch_channel_t *channel = switch_core_session_get_channel(member->session);
-        switch_channel_event_set_data(channel, event);
+		stream->write_function(stream, "%s%d%s%d%s%d\n", delim, member->volume_in_level, delim, member->volume_out_level, delim, member->energy_level);
+	}
 
-        switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", "%s", member->conference->name);
-        switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", member->id);
-        switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "dtmf-member");
-        switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Digits", "%s", dtmf);
-        switch_event_fire(&event);
-    }
+	switch_mutex_unlock(conference->member_mutex);
 
-    return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t conf_api_sub_energy(conference_member_t *member, switch_stream_handle_t *stream, void *data)
+static switch_status_t conf_api_sub_mute(conference_member_t * member, switch_stream_handle_t *stream, void *data)
 {
-    switch_status_t ret_status = SWITCH_STATUS_SUCCESS;
-
-    if (member != NULL) {
-        switch_event_t *event;
+	switch_status_t ret_status = SWITCH_STATUS_SUCCESS;
 
-        if (data) {
-            switch_mutex_lock(member->flag_mutex);
-            member->energy_level = atoi((char *)data);
-            switch_mutex_unlock(member->flag_mutex);
-        }
+	if (member != NULL) {
+		switch_event_t *event;
 
-        if (stream != NULL) {
-            stream->write_function(stream, "Energy %u = %d\n", member->id, member->energy_level);
-        }
+		switch_clear_flag_locked(member, MFLAG_CAN_SPEAK);
+		if (member->conference->muted_sound) {
+			conference_member_play_file(member, member->conference->muted_sound, 0);
+		} else {
+			char msg[512];
 
-        if (data) {
-            if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
-                switch_channel_t *channel = switch_core_session_get_channel(member->session);
-                switch_channel_event_set_data(channel, event);
+			snprintf(msg, sizeof(msg), "Muted");
+			conference_member_say(member, msg, 0);
+		}
+		if (stream != NULL) {
+			stream->write_function(stream, "OK mute %u\n", member->id);
+		}
+		if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+			switch_channel_t *channel = switch_core_session_get_channel(member->session);
+			switch_channel_event_set_data(channel, event);
 
-                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", "%s", member->conference->name);
-                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", member->id);
-                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "energy-level-member");
-                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Energy-Level", "%d", member->energy_level);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", "%s", member->conference->name);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", member->id);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "mute-member");
+			switch_event_fire(&event);
+		}
+	} else {
+		ret_status = SWITCH_STATUS_GENERR;
+	}
 
-                switch_event_fire(&event);
-            }
-        }
-    } else {
-        ret_status = SWITCH_STATUS_GENERR;
-    }
+	return ret_status;
+}
+
+static switch_status_t conf_api_sub_unmute(conference_member_t * member, switch_stream_handle_t *stream, void *data)
+{
+	switch_status_t ret_status = SWITCH_STATUS_SUCCESS;
 
-    return ret_status;
+	if (member != NULL) {
+		switch_event_t *event;
+
+		switch_set_flag_locked(member, MFLAG_CAN_SPEAK);
+		if (stream != NULL) {
+			stream->write_function(stream, "OK unmute %u\n", member->id);
+		}
+		if (member->conference->unmuted_sound) {
+			conference_member_play_file(member, member->conference->unmuted_sound, 0);
+		} else {
+			char msg[512];
+
+			snprintf(msg, sizeof(msg), "Un-Muted");
+			conference_member_say(member, msg, 0);
+		}
+		if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+			switch_channel_t *channel = switch_core_session_get_channel(member->session);
+			switch_channel_event_set_data(channel, event);
+
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", "%s", member->conference->name);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", member->id);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "unmute-member");
+			switch_event_fire(&event);
+		}
+	} else {
+		ret_status = SWITCH_STATUS_GENERR;
+	}
+
+	return ret_status;
 }
 
-static switch_status_t conf_api_sub_volume_in(conference_member_t *member, switch_stream_handle_t *stream, void *data)
+static switch_status_t conf_api_sub_deaf(conference_member_t * member, switch_stream_handle_t *stream, void *data)
 {
-    switch_status_t ret_status = SWITCH_STATUS_SUCCESS;
+	switch_status_t ret_status = SWITCH_STATUS_SUCCESS;
 
-    if (member != NULL) {
-        switch_event_t *event;
+	if (member != NULL) {
+		switch_event_t *event;
 
-        if (data) {
-            switch_mutex_lock(member->flag_mutex);
-            member->volume_in_level = atoi((char *)data);
-            switch_normalize_volume(member->volume_in_level);
-            switch_mutex_unlock(member->flag_mutex);
-        }
+		switch_clear_flag_locked(member, MFLAG_CAN_HEAR);
+		if (stream != NULL) {
+			stream->write_function(stream, "OK deaf %u\n", member->id);
+		}
+		if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+			switch_channel_t *channel = switch_core_session_get_channel(member->session);
+			switch_channel_event_set_data(channel, event);
 
-        if (stream != NULL) {
-            stream->write_function(stream, "Volume IN %u = %d\n", member->id, member->volume_in_level);
-        }
-        if (data) {
-            if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
-                switch_channel_t *channel = switch_core_session_get_channel(member->session);
-                switch_channel_event_set_data(channel, event);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", "%s", member->conference->name);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", member->id);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "deaf-member");
+			switch_event_fire(&event);
+		}
+	} else {
+		ret_status = SWITCH_STATUS_GENERR;
+	}
 
-                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", "%s", member->conference->name);
-                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", member->id);
-                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "volume-in-member");
-                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Volume-Level", "%u", member->volume_in_level);
+	return ret_status;
+}
 
-                switch_event_fire(&event);
-            }
-        }
-    } else {
-        ret_status = SWITCH_STATUS_GENERR;
-    }
+static switch_status_t conf_api_sub_undeaf(conference_member_t * member, switch_stream_handle_t *stream, void *data)
+{
+	switch_status_t ret_status = SWITCH_STATUS_SUCCESS;
 
-    return ret_status;
+	if (member != NULL) {
+		switch_event_t *event;
+
+		switch_set_flag_locked(member, MFLAG_CAN_HEAR);
+		if (stream != NULL) {
+			stream->write_function(stream, "OK undeaf %u\n", member->id);
+		}
+		if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+			switch_channel_t *channel = switch_core_session_get_channel(member->session);
+			switch_channel_event_set_data(channel, event);
+
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", "%s", member->conference->name);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", member->id);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "undeaf-member");
+			switch_event_fire(&event);
+		}
+	} else {
+		ret_status = SWITCH_STATUS_GENERR;
+	}
+
+	return ret_status;
 }
 
-static switch_status_t conf_api_sub_volume_out(conference_member_t *member, switch_stream_handle_t *stream, void *data)
+static switch_status_t conf_api_sub_kick(conference_member_t * member, switch_stream_handle_t *stream, void *data)
 {
-    switch_status_t ret_status = SWITCH_STATUS_SUCCESS;
+	switch_status_t ret_status = SWITCH_STATUS_SUCCESS;
+
+	if (member != NULL) {
+		switch_event_t *event;
+
+		switch_mutex_lock(member->flag_mutex);
+		switch_clear_flag(member, MFLAG_RUNNING);
+		switch_set_flag(member, MFLAG_KICKED);
+		switch_core_session_kill_channel(member->session, SWITCH_SIG_BREAK);
+		switch_mutex_unlock(member->flag_mutex);
+
+		if (stream != NULL) {
+			stream->write_function(stream, "OK kicked %u\n", member->id);
+		}
+
+		if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+			switch_channel_t *channel = switch_core_session_get_channel(member->session);
+			switch_channel_event_set_data(channel, event);
+
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", "%s", member->conference->name);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", member->id);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "kick-member");
+			switch_event_fire(&event);
+		}
+	} else {
+		ret_status = SWITCH_STATUS_GENERR;
+	}
+
+	return ret_status;
+}
 
-    if (member != NULL) {
-        switch_event_t *event;
 
-        if (data) {
-            switch_mutex_lock(member->flag_mutex);
-            member->volume_out_level = atoi((char *)data);
-            switch_normalize_volume(member->volume_out_level);
-            switch_mutex_unlock(member->flag_mutex);
-        }
+static switch_status_t conf_api_sub_dtmf(conference_member_t * member, switch_stream_handle_t *stream, void *data)
+{
+	switch_event_t *event;
+	char *dtmf = (char *) data;
 
-        if (stream != NULL) {
-            stream->write_function(stream, "Volume OUT %u = %d\n", member->id, member->volume_out_level);
-        }
+	if (member == NULL) {
+		stream->write_function(stream, "Invalid member!\n");
+		return SWITCH_STATUS_GENERR;
+	}
 
-        if (data) {
-            if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
-                switch_channel_t *channel = switch_core_session_get_channel(member->session);
-                switch_channel_event_set_data(channel, event);
+	if (switch_strlen_zero(dtmf)) {
+		stream->write_function(stream, "Invalid input!\n");
+		return SWITCH_STATUS_GENERR;
+	}
 
-                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", "%s", member->conference->name);
-                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", member->id);
-                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "volume-out-member");
-                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Volume-Level", "%u", member->volume_out_level);
 
-                switch_event_fire(&event);
-            }
-        }
-    } else {
-        ret_status = SWITCH_STATUS_GENERR;
-    }
+	switch_mutex_lock(member->flag_mutex);
+	switch_core_session_kill_channel(member->session, SWITCH_SIG_BREAK);
+	switch_core_session_send_dtmf(member->session, dtmf);
+	switch_mutex_unlock(member->flag_mutex);
 
-    return ret_status;
+
+	if (stream != NULL) {
+		stream->write_function(stream, "OK sent %s to %u\n", (char *) data, member->id);
+	}
+
+	if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+		switch_channel_t *channel = switch_core_session_get_channel(member->session);
+		switch_channel_event_set_data(channel, event);
+
+		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", "%s", member->conference->name);
+		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", member->id);
+		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "dtmf-member");
+		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Digits", "%s", dtmf);
+		switch_event_fire(&event);
+	}
+
+	return SWITCH_STATUS_SUCCESS;
+}
+
+static switch_status_t conf_api_sub_energy(conference_member_t * member, switch_stream_handle_t *stream, void *data)
+{
+	switch_status_t ret_status = SWITCH_STATUS_SUCCESS;
+
+	if (member != NULL) {
+		switch_event_t *event;
+
+		if (data) {
+			switch_mutex_lock(member->flag_mutex);
+			member->energy_level = atoi((char *) data);
+			switch_mutex_unlock(member->flag_mutex);
+		}
+
+		if (stream != NULL) {
+			stream->write_function(stream, "Energy %u = %d\n", member->id, member->energy_level);
+		}
+
+		if (data) {
+			if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+				switch_channel_t *channel = switch_core_session_get_channel(member->session);
+				switch_channel_event_set_data(channel, event);
+
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", "%s", member->conference->name);
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", member->id);
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "energy-level-member");
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Energy-Level", "%d", member->energy_level);
+
+				switch_event_fire(&event);
+			}
+		}
+	} else {
+		ret_status = SWITCH_STATUS_GENERR;
+	}
+
+	return ret_status;
+}
+
+static switch_status_t conf_api_sub_volume_in(conference_member_t * member, switch_stream_handle_t *stream, void *data)
+{
+	switch_status_t ret_status = SWITCH_STATUS_SUCCESS;
+
+	if (member != NULL) {
+		switch_event_t *event;
+
+		if (data) {
+			switch_mutex_lock(member->flag_mutex);
+			member->volume_in_level = atoi((char *) data);
+			switch_normalize_volume(member->volume_in_level);
+			switch_mutex_unlock(member->flag_mutex);
+		}
+
+		if (stream != NULL) {
+			stream->write_function(stream, "Volume IN %u = %d\n", member->id, member->volume_in_level);
+		}
+		if (data) {
+			if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+				switch_channel_t *channel = switch_core_session_get_channel(member->session);
+				switch_channel_event_set_data(channel, event);
+
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", "%s", member->conference->name);
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", member->id);
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "volume-in-member");
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Volume-Level", "%u", member->volume_in_level);
+
+				switch_event_fire(&event);
+			}
+		}
+	} else {
+		ret_status = SWITCH_STATUS_GENERR;
+	}
+
+	return ret_status;
 }
 
-static switch_status_t conf_api_sub_list(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char**argv)
+static switch_status_t conf_api_sub_volume_out(conference_member_t * member, switch_stream_handle_t *stream, void *data)
 {
-    int ret_status = SWITCH_STATUS_GENERR;
+	switch_status_t ret_status = SWITCH_STATUS_SUCCESS;
+
+	if (member != NULL) {
+		switch_event_t *event;
+
+		if (data) {
+			switch_mutex_lock(member->flag_mutex);
+			member->volume_out_level = atoi((char *) data);
+			switch_normalize_volume(member->volume_out_level);
+			switch_mutex_unlock(member->flag_mutex);
+		}
+
+		if (stream != NULL) {
+			stream->write_function(stream, "Volume OUT %u = %d\n", member->id, member->volume_out_level);
+		}
 
-    switch_hash_index_t *hi;
-    void *val;
-    char *d = ";";
-    int pretty = 0;
-    int argofs = (argc >= 2 && strcasecmp(argv[1], "list") == 0);	// detect being called from chat vs. api
+		if (data) {
+			if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+				switch_channel_t *channel = switch_core_session_get_channel(member->session);
+				switch_channel_event_set_data(channel, event);
+
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", "%s", member->conference->name);
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", member->id);
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "volume-out-member");
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Volume-Level", "%u", member->volume_out_level);
+
+				switch_event_fire(&event);
+			}
+		}
+	} else {
+		ret_status = SWITCH_STATUS_GENERR;
+	}
+
+	return ret_status;
+}
+
+static switch_status_t conf_api_sub_list(conference_obj_t * conference, switch_stream_handle_t *stream, int argc, char **argv)
+{
+	int ret_status = SWITCH_STATUS_GENERR;
 
-    if (argv[1+argofs]) {
-        if (argv[2+argofs] && !strcasecmp(argv[1+argofs], "delim")) {
-            d = argv[2+argofs];
+	switch_hash_index_t *hi;
+	void *val;
+	char *d = ";";
+	int pretty = 0;
+	int argofs = (argc >= 2 && strcasecmp(argv[1], "list") == 0);	// detect being called from chat vs. api
 
-            if (*d == '"') {
-                if (++d) {
-                    char *p;
-                    if ((p = strchr(d, '"'))) {
-                        *p = '\0';
-                    }
-                } else {
-                    d = ";";
-                }
-            }
-        } else if (strcasecmp(argv[1+argofs], "pretty") == 0) {
-            pretty = 1;
-        }
-    }
+	if (argv[1 + argofs]) {
+		if (argv[2 + argofs] && !strcasecmp(argv[1 + argofs], "delim")) {
+			d = argv[2 + argofs];
 
-    if (conference == NULL) {
-        for (hi = switch_hash_first(globals.conference_pool, globals.conference_hash); hi; hi = switch_hash_next(hi)) {
-            switch_hash_this(hi, NULL, NULL, &val);
-            conference = (conference_obj_t *) val;
+			if (*d == '"') {
+				if (++d) {
+					char *p;
+					if ((p = strchr(d, '"'))) {
+						*p = '\0';
+					}
+				} else {
+					d = ";";
+				}
+			}
+		} else if (strcasecmp(argv[1 + argofs], "pretty") == 0) {
+			pretty = 1;
+		}
+	}
 
-            stream->write_function(stream, "Conference %s (%u member%s%s)\n", 
-                                   conference->name, 
-                                   conference->count, 
-                                   conference->count == 1 ? "" : "s",
-                                   switch_test_flag(conference, CFLAG_LOCKED) ? " locked" : ""
-                                   );
-            if (pretty) {
-                conference_list_pretty(conference, stream);
-            } else {
-                conference_list(conference, stream, d);
-            }
-        }
-    } else {
-        if (pretty) {
-            conference_list_pretty(conference, stream);
-        } else {
-            conference_list(conference, stream, d);
-        }
-    }
+	if (conference == NULL) {
+		for (hi = switch_hash_first(globals.conference_pool, globals.conference_hash); hi; hi = switch_hash_next(hi)) {
+			switch_hash_this(hi, NULL, NULL, &val);
+			conference = (conference_obj_t *) val;
+
+			stream->write_function(stream, "Conference %s (%u member%s%s)\n",
+								   conference->name,
+								   conference->count, conference->count == 1 ? "" : "s", switch_test_flag(conference, CFLAG_LOCKED) ? " locked" : "");
+			if (pretty) {
+				conference_list_pretty(conference, stream);
+			} else {
+				conference_list(conference, stream, d);
+			}
+		}
+	} else {
+		if (pretty) {
+			conference_list_pretty(conference, stream);
+		} else {
+			conference_list(conference, stream, d);
+		}
+	}
 
-    ret_status = SWITCH_STATUS_SUCCESS;
+	ret_status = SWITCH_STATUS_SUCCESS;
 
-    return ret_status;
+	return ret_status;
 }
 
-static switch_status_t conf_api_sub_play(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char**argv)
+static switch_status_t conf_api_sub_play(conference_obj_t * conference, switch_stream_handle_t *stream, int argc, char **argv)
 {
-    int ret_status = SWITCH_STATUS_GENERR;
-    switch_event_t *event;
+	int ret_status = SWITCH_STATUS_GENERR;
+	switch_event_t *event;
 	uint8_t async = 0;
 
-    assert(conference != NULL);
-    assert(stream != NULL);
+	assert(conference != NULL);
+	assert(stream != NULL);
 
-    if ((argc == 4 && !strcasecmp(argv[3], "async")) || (argc == 5 && !strcasecmp(argv[4], "async"))) {    
+	if ((argc == 4 && !strcasecmp(argv[3], "async")) || (argc == 5 && !strcasecmp(argv[4], "async"))) {
 		argc--;
 		async++;
 	}
-	
-    if (argc == 3) {
-        if (conference_play_file(conference, argv[2], 0, NULL, async) == SWITCH_STATUS_SUCCESS) {
-            stream->write_function(stream, "(play) Playing file %s\n", argv[2]);
-            if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
-                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", "%s", conference->name);
-                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "play-file");
-                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "File", "%s", argv[2]);
-                switch_event_fire(&event);
-            }
-        } else {
-            stream->write_function(stream, "(play) File: %s not found.\n", argv[2] ? argv[2] : "(unspecified)");
-        }
-        ret_status = SWITCH_STATUS_SUCCESS;
-    } else if (argc == 4) {
-        uint32_t id = atoi(argv[3]);
-        conference_member_t *member;
-
-        if ((member = conference_member_get(conference, id))) {
-            if (conference_member_play_file(member, argv[2], 0) == SWITCH_STATUS_SUCCESS) {
-                stream->write_function(stream, "(play) Playing file %s to member %u\n", argv[2], id);
-                if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
-                    switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", "%s", conference->name);
-                    switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", id);
-                    switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "play-file-member");
-                    switch_event_add_header(event, SWITCH_STACK_BOTTOM, "File", "%s", argv[2]);
-                    switch_event_fire(&event);
-                }
-            } else {
-                stream->write_function(stream, "(play) File: %s not found.\n", argv[2] ? argv[2] : "(unspecified)");
-            }
-            ret_status = SWITCH_STATUS_SUCCESS;
-        } else {
-            stream->write_function(stream, "Member: %u not found.\n", id);
-        }
-    }
-
-    return ret_status;
-}
-
-static switch_status_t conf_api_sub_say(conference_obj_t *conference, switch_stream_handle_t *stream, const char *text)
-{
-    int ret_status = SWITCH_STATUS_GENERR;
-
-    if (switch_strlen_zero(text)) {
-        stream->write_function(stream, "(say) Error! No text.");
-        return ret_status;
-    }
-
-    if (conference_say(conference, text, 0) == SWITCH_STATUS_SUCCESS) {
-        switch_event_t *event;
-
-        stream->write_function(stream, "(say) OK\n");
-        if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", "%s", conference->name);
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "speak-text");
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Text", "%s", text);
-            switch_event_fire(&event);
-        }
-        ret_status = SWITCH_STATUS_SUCCESS;
-    } else {
-        stream->write_function(stream, "(say) Error!");
-    }
-
-    return ret_status;
-}
-
-static switch_status_t conf_api_sub_saymember(conference_obj_t *conference, switch_stream_handle_t *stream, const char *text)
-{
-    int ret_status = SWITCH_STATUS_GENERR;
-    char *expanded = NULL;
-    char *start_text = NULL;
-    char *workspace = NULL;
-    uint32_t id = 0;
-    conference_member_t *member;
-
-    if (switch_strlen_zero(text)) {
-        stream->write_function(stream, "(saymember) No Text!\n");
-        goto done;
-    }
-
-    if (!(workspace = strdup(text))) {
-        stream->write_function(stream, "(saymember) Memory Error!\n");
-        goto done;
-    }
-
-    if ((start_text = strchr(workspace, ' '))) {
-        *start_text++ = '\0';
-        text = start_text;
-    }
-
-    id = atoi(workspace);
-
-    if (!id || switch_strlen_zero(text)) {
-        stream->write_function(stream, "(saymember) No Text!\n");
-        goto done;
-    }
-
-    if (!(member = conference_member_get(conference, id))) {
-        stream->write_function(stream, "(saymember) Unknown Member %u!", id);
-        goto done;
-    }
-
-    if ((expanded = switch_channel_expand_variables(switch_core_session_get_channel(member->session), (char *)text)) != text) {
-        text = expanded;
-    } else {
-        expanded = NULL;
-    }
-
-    if (text && conference_member_say(member, (char *)text, 0) == SWITCH_STATUS_SUCCESS) {
-        switch_event_t *event;
-
-        stream->write_function(stream, "(saymember) OK\n");
-        if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", "%s", conference->name);
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "speak-text-member");
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", id);
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Text", "%s", text);
-            switch_event_fire(&event);
-        }
-        ret_status = SWITCH_STATUS_SUCCESS;
-    } else {
-        stream->write_function(stream, "(saymember) Error!");
-    }
-
- done:    
-    switch_safe_free(workspace);
-    switch_safe_free(expanded);
-    return ret_status;
-}
-
-static switch_status_t conf_api_sub_stop(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char**argv)
-{
-    int ret_status = SWITCH_STATUS_GENERR;
-    uint8_t current = 0, all = 0;
-
-    assert(conference != NULL);
-    assert(stream != NULL);
-
-    if (argc > 2) {
-        current = strcasecmp(argv[2], "current") ? 0 : 1;
-        all = strcasecmp(argv[2], "all") ? 0 : 1;
-    } else {
-        all = 1;
-    }
-
-    if (current || all) {
-        if (argc == 4) {
-            uint32_t id = atoi(argv[3]);
-            conference_member_t *member;
-
-            if ((member = conference_member_get(conference, id))) {
-                uint32_t stopped = conference_member_stop_file(member, current ? FILE_STOP_CURRENT : FILE_STOP_ALL);
-                stream->write_function(stream, "Stopped %u files.\n", stopped);
-            } else {
-                stream->write_function(stream, "Member: %u not found.\n", id);
-            }
-            ret_status = SWITCH_STATUS_SUCCESS;
-        } else {
-            uint32_t stopped = conference_stop_file(conference, current ? FILE_STOP_CURRENT : FILE_STOP_ALL);
-            stream->write_function(stream, "Stopped %u files.\n", stopped);
-            ret_status = SWITCH_STATUS_SUCCESS;
-        }
-    }
-
-    return ret_status;
-}
-
-static switch_status_t conf_api_sub_relate(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char**argv)
-{
-    int ret_status = SWITCH_STATUS_GENERR;
-
-    assert(conference != NULL);
-    assert(stream != NULL);
-
-    if (argc > 4) {
-        uint8_t nospeak = 0, nohear = 0, clear = 0;
-        nospeak = strstr(argv[4], "nospeak") ? 1 : 0;
-        nohear = strstr(argv[4], "nohear") ? 1 : 0;
-
-        if (!strcasecmp(argv[4], "clear")) {
-            clear = 1;
-        }
-
-        if (!(clear || nospeak || nohear)) { 
-            ret_status = SWITCH_STATUS_GENERR;
-            goto done;
-        }
-        ret_status = SWITCH_STATUS_SUCCESS;
-
-        if (clear) {
-            conference_member_t *member = NULL;
-            uint32_t id = atoi(argv[2]);
-            uint32_t oid = atoi(argv[3]);
-
-            if ((member = conference_member_get(conference, id))) {
-                member_del_relationship(member, oid);
-                stream->write_function(stream, "relationship %u->%u cleared.", id, oid);
-            } else {
-                stream->write_function(stream, "relationship %u->%u not found", id, oid);
-            }
-        } else if (nospeak || nohear) {
-            conference_member_t *member = NULL, *other_member = NULL;
-            uint32_t id = atoi(argv[2]);
-            uint32_t oid = atoi(argv[3]);
-
-            if ((member = conference_member_get(conference, id)) && (other_member = conference_member_get(conference, oid))) {
-                conference_relationship_t *rel = NULL;
-                if ((rel = member_get_relationship(member, other_member))) {
-                    rel->flags = 0;
-                } else {
-                    rel = member_add_relationship(member, oid);
-                }
-
-                if (rel) {
-                    switch_set_flag(rel, RFLAG_CAN_SPEAK | RFLAG_CAN_HEAR);
-                    if (nospeak) {
-                        switch_clear_flag(rel, RFLAG_CAN_SPEAK);
-                    }
-                    if (nohear) {
-                        switch_clear_flag(rel, RFLAG_CAN_HEAR);
-                    }
-                    stream->write_function(stream, "ok %u->%u set\n", id, oid);
-                } else {
-                    stream->write_function(stream, "error!\n");
-                }
-            } else {
-                stream->write_function(stream, "relationship %u->%u not found", id, oid);
-            }
-        }
-    }
-
- done:
-    return ret_status;
-}
-
-static switch_status_t conf_api_sub_lock(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char**argv)
-{
-    switch_event_t *event;
-
-    assert(conference != NULL);
-    assert(stream != NULL);
-
-    if (conference->is_locked_sound) {
-        conference_play_file(conference, conference->is_locked_sound, CONF_DEFAULT_LEADIN, NULL, 0);
-    }
-
-    switch_set_flag_locked(conference, CFLAG_LOCKED);
-    stream->write_function(stream, "OK %s locked\n", argv[0]);
-    if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
-        switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", "%s", conference->name);
-        switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "lock");
-        switch_event_fire(&event);
-    }
-
-    return 0;
-}
-
-static switch_status_t conf_api_sub_unlock(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char**argv)
-{
-    switch_event_t *event;
-
-    assert(conference != NULL);
-    assert(stream != NULL);
-
-    if (conference->is_unlocked_sound) {
-        conference_play_file(conference, conference->is_unlocked_sound, CONF_DEFAULT_LEADIN, NULL, 0);
-    }
-
-    switch_clear_flag_locked(conference, CFLAG_LOCKED);
-    stream->write_function(stream, "OK %s unlocked\n", argv[0]);
-    if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
-        switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", "%s", conference->name);
-        switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "unlock");
-        switch_event_fire(&event);
-    }
-	
 
-    return 0;
+	if (argc == 3) {
+		if (conference_play_file(conference, argv[2], 0, NULL, async) == SWITCH_STATUS_SUCCESS) {
+			stream->write_function(stream, "(play) Playing file %s\n", argv[2]);
+			if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", "%s", conference->name);
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "play-file");
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "File", "%s", argv[2]);
+				switch_event_fire(&event);
+			}
+		} else {
+			stream->write_function(stream, "(play) File: %s not found.\n", argv[2] ? argv[2] : "(unspecified)");
+		}
+		ret_status = SWITCH_STATUS_SUCCESS;
+	} else if (argc == 4) {
+		uint32_t id = atoi(argv[3]);
+		conference_member_t *member;
+
+		if ((member = conference_member_get(conference, id))) {
+			if (conference_member_play_file(member, argv[2], 0) == SWITCH_STATUS_SUCCESS) {
+				stream->write_function(stream, "(play) Playing file %s to member %u\n", argv[2], id);
+				if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+					switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", "%s", conference->name);
+					switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", id);
+					switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "play-file-member");
+					switch_event_add_header(event, SWITCH_STACK_BOTTOM, "File", "%s", argv[2]);
+					switch_event_fire(&event);
+				}
+			} else {
+				stream->write_function(stream, "(play) File: %s not found.\n", argv[2] ? argv[2] : "(unspecified)");
+			}
+			ret_status = SWITCH_STATUS_SUCCESS;
+		} else {
+			stream->write_function(stream, "Member: %u not found.\n", id);
+		}
+	}
+
+	return ret_status;
+}
+
+static switch_status_t conf_api_sub_say(conference_obj_t * conference, switch_stream_handle_t *stream, const char *text)
+{
+	int ret_status = SWITCH_STATUS_GENERR;
+
+	if (switch_strlen_zero(text)) {
+		stream->write_function(stream, "(say) Error! No text.");
+		return ret_status;
+	}
+
+	if (conference_say(conference, text, 0) == SWITCH_STATUS_SUCCESS) {
+		switch_event_t *event;
+
+		stream->write_function(stream, "(say) OK\n");
+		if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", "%s", conference->name);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "speak-text");
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Text", "%s", text);
+			switch_event_fire(&event);
+		}
+		ret_status = SWITCH_STATUS_SUCCESS;
+	} else {
+		stream->write_function(stream, "(say) Error!");
+	}
+
+	return ret_status;
+}
+
+static switch_status_t conf_api_sub_saymember(conference_obj_t * conference, switch_stream_handle_t *stream, const char *text)
+{
+	int ret_status = SWITCH_STATUS_GENERR;
+	char *expanded = NULL;
+	char *start_text = NULL;
+	char *workspace = NULL;
+	uint32_t id = 0;
+	conference_member_t *member;
+
+	if (switch_strlen_zero(text)) {
+		stream->write_function(stream, "(saymember) No Text!\n");
+		goto done;
+	}
+
+	if (!(workspace = strdup(text))) {
+		stream->write_function(stream, "(saymember) Memory Error!\n");
+		goto done;
+	}
+
+	if ((start_text = strchr(workspace, ' '))) {
+		*start_text++ = '\0';
+		text = start_text;
+	}
+
+	id = atoi(workspace);
+
+	if (!id || switch_strlen_zero(text)) {
+		stream->write_function(stream, "(saymember) No Text!\n");
+		goto done;
+	}
+
+	if (!(member = conference_member_get(conference, id))) {
+		stream->write_function(stream, "(saymember) Unknown Member %u!", id);
+		goto done;
+	}
+
+	if ((expanded = switch_channel_expand_variables(switch_core_session_get_channel(member->session), (char *) text)) != text) {
+		text = expanded;
+	} else {
+		expanded = NULL;
+	}
+
+	if (text && conference_member_say(member, (char *) text, 0) == SWITCH_STATUS_SUCCESS) {
+		switch_event_t *event;
+
+		stream->write_function(stream, "(saymember) OK\n");
+		if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", "%s", conference->name);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "speak-text-member");
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", id);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Text", "%s", text);
+			switch_event_fire(&event);
+		}
+		ret_status = SWITCH_STATUS_SUCCESS;
+	} else {
+		stream->write_function(stream, "(saymember) Error!");
+	}
+
+  done:
+	switch_safe_free(workspace);
+	switch_safe_free(expanded);
+	return ret_status;
+}
+
+static switch_status_t conf_api_sub_stop(conference_obj_t * conference, switch_stream_handle_t *stream, int argc, char **argv)
+{
+	int ret_status = SWITCH_STATUS_GENERR;
+	uint8_t current = 0, all = 0;
+
+	assert(conference != NULL);
+	assert(stream != NULL);
+
+	if (argc > 2) {
+		current = strcasecmp(argv[2], "current") ? 0 : 1;
+		all = strcasecmp(argv[2], "all") ? 0 : 1;
+	} else {
+		all = 1;
+	}
+
+	if (current || all) {
+		if (argc == 4) {
+			uint32_t id = atoi(argv[3]);
+			conference_member_t *member;
+
+			if ((member = conference_member_get(conference, id))) {
+				uint32_t stopped = conference_member_stop_file(member, current ? FILE_STOP_CURRENT : FILE_STOP_ALL);
+				stream->write_function(stream, "Stopped %u files.\n", stopped);
+			} else {
+				stream->write_function(stream, "Member: %u not found.\n", id);
+			}
+			ret_status = SWITCH_STATUS_SUCCESS;
+		} else {
+			uint32_t stopped = conference_stop_file(conference, current ? FILE_STOP_CURRENT : FILE_STOP_ALL);
+			stream->write_function(stream, "Stopped %u files.\n", stopped);
+			ret_status = SWITCH_STATUS_SUCCESS;
+		}
+	}
+
+	return ret_status;
+}
+
+static switch_status_t conf_api_sub_relate(conference_obj_t * conference, switch_stream_handle_t *stream, int argc, char **argv)
+{
+	int ret_status = SWITCH_STATUS_GENERR;
+
+	assert(conference != NULL);
+	assert(stream != NULL);
+
+	if (argc > 4) {
+		uint8_t nospeak = 0, nohear = 0, clear = 0;
+		nospeak = strstr(argv[4], "nospeak") ? 1 : 0;
+		nohear = strstr(argv[4], "nohear") ? 1 : 0;
+
+		if (!strcasecmp(argv[4], "clear")) {
+			clear = 1;
+		}
+
+		if (!(clear || nospeak || nohear)) {
+			ret_status = SWITCH_STATUS_GENERR;
+			goto done;
+		}
+		ret_status = SWITCH_STATUS_SUCCESS;
+
+		if (clear) {
+			conference_member_t *member = NULL;
+			uint32_t id = atoi(argv[2]);
+			uint32_t oid = atoi(argv[3]);
+
+			if ((member = conference_member_get(conference, id))) {
+				member_del_relationship(member, oid);
+				stream->write_function(stream, "relationship %u->%u cleared.", id, oid);
+			} else {
+				stream->write_function(stream, "relationship %u->%u not found", id, oid);
+			}
+		} else if (nospeak || nohear) {
+			conference_member_t *member = NULL, *other_member = NULL;
+			uint32_t id = atoi(argv[2]);
+			uint32_t oid = atoi(argv[3]);
+
+			if ((member = conference_member_get(conference, id))
+				&& (other_member = conference_member_get(conference, oid))) {
+				conference_relationship_t *rel = NULL;
+				if ((rel = member_get_relationship(member, other_member))) {
+					rel->flags = 0;
+				} else {
+					rel = member_add_relationship(member, oid);
+				}
+
+				if (rel) {
+					switch_set_flag(rel, RFLAG_CAN_SPEAK | RFLAG_CAN_HEAR);
+					if (nospeak) {
+						switch_clear_flag(rel, RFLAG_CAN_SPEAK);
+					}
+					if (nohear) {
+						switch_clear_flag(rel, RFLAG_CAN_HEAR);
+					}
+					stream->write_function(stream, "ok %u->%u set\n", id, oid);
+				} else {
+					stream->write_function(stream, "error!\n");
+				}
+			} else {
+				stream->write_function(stream, "relationship %u->%u not found", id, oid);
+			}
+		}
+	}
+
+  done:
+	return ret_status;
+}
+
+static switch_status_t conf_api_sub_lock(conference_obj_t * conference, switch_stream_handle_t *stream, int argc, char **argv)
+{
+	switch_event_t *event;
+
+	assert(conference != NULL);
+	assert(stream != NULL);
+
+	if (conference->is_locked_sound) {
+		conference_play_file(conference, conference->is_locked_sound, CONF_DEFAULT_LEADIN, NULL, 0);
+	}
+
+	switch_set_flag_locked(conference, CFLAG_LOCKED);
+	stream->write_function(stream, "OK %s locked\n", argv[0]);
+	if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", "%s", conference->name);
+		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "lock");
+		switch_event_fire(&event);
+	}
+
+	return 0;
+}
+
+static switch_status_t conf_api_sub_unlock(conference_obj_t * conference, switch_stream_handle_t *stream, int argc, char **argv)
+{
+	switch_event_t *event;
+
+	assert(conference != NULL);
+	assert(stream != NULL);
+
+	if (conference->is_unlocked_sound) {
+		conference_play_file(conference, conference->is_unlocked_sound, CONF_DEFAULT_LEADIN, NULL, 0);
+	}
+
+	switch_clear_flag_locked(conference, CFLAG_LOCKED);
+	stream->write_function(stream, "OK %s unlocked\n", argv[0]);
+	if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", "%s", conference->name);
+		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "unlock");
+		switch_event_fire(&event);
+	}
+
+
+	return 0;
 }
 
-static switch_status_t conf_api_sub_dial(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char**argv)
+static switch_status_t conf_api_sub_dial(conference_obj_t * conference, switch_stream_handle_t *stream, int argc, char **argv)
 {
-    switch_status_t ret_status = SWITCH_STATUS_SUCCESS;
+	switch_status_t ret_status = SWITCH_STATUS_SUCCESS;
 
-    assert(stream != NULL);
+	assert(stream != NULL);
 
 	if (argc > 2) {
-        switch_call_cause_t cause;
+		switch_call_cause_t cause;
 
 		if (conference) {
 			conference_outcall(conference, NULL, NULL, argv[2], 60, NULL, argv[4], argv[3], &cause);
@@ -3069,21 +2994,21 @@
 			conference_outcall(NULL, argv[0], NULL, argv[2], 60, NULL, argv[4], argv[3], &cause);
 		}
 
-        stream->write_function(stream, "Call Requested: result: [%s]\n", switch_channel_cause2str(cause));
-    } else {
-        stream->write_function(stream, "Bad Args\n");
-        ret_status = SWITCH_STATUS_GENERR;
-    }
+		stream->write_function(stream, "Call Requested: result: [%s]\n", switch_channel_cause2str(cause));
+	} else {
+		stream->write_function(stream, "Bad Args\n");
+		ret_status = SWITCH_STATUS_GENERR;
+	}
 
-    return ret_status;
+	return ret_status;
 }
 
 
-static switch_status_t conf_api_sub_bgdial(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char**argv)
+static switch_status_t conf_api_sub_bgdial(conference_obj_t * conference, switch_stream_handle_t *stream, int argc, char **argv)
 {
-    switch_status_t ret_status = SWITCH_STATUS_SUCCESS;
+	switch_status_t ret_status = SWITCH_STATUS_SUCCESS;
 
-    assert(stream != NULL);
+	assert(stream != NULL);
 
 	if (argc > 2) {
 		if (conference) {
@@ -3092,171 +3017,171 @@
 			conference_outcall_bg(NULL, argv[1], NULL, argv[2], 60, NULL, argv[4], argv[3]);
 		}
 		stream->write_function(stream, "OK\n");
-    } else {
-        stream->write_function(stream, "Bad Args\n");
-        ret_status = SWITCH_STATUS_GENERR;
-    }
-
-    return ret_status;
-}
-
-static switch_status_t conf_api_sub_transfer(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char**argv)
-{
-    switch_status_t ret_status = SWITCH_STATUS_SUCCESS;
-    char *params = NULL;
-    assert(conference != NULL);
-    assert(stream != NULL);
-
-    if (argc > 3 && !switch_strlen_zero(argv[2])) {
-        int x;
-
-        for (x = 3; x<argc; x++) {
-            conference_member_t *member = NULL;
-            uint32_t id = atoi(argv[x]);
-            conference_obj_t *new_conference = NULL;
-            switch_channel_t *channel;
-            switch_event_t *event;
-            char *profile_name;
-            switch_xml_t cxml = NULL, cfg = NULL, profiles = NULL;
-
-            if (!id || !(member = conference_member_get(conference, id))) {								
-                stream->write_function(stream, "No Member %u in conference %s.\n", id, conference->name);
-                continue;
-            }
-
-            channel = switch_core_session_get_channel(member->session);
-
-            /* build a new conference if it doesn't exist */
-            if (!(new_conference = (conference_obj_t *) switch_core_hash_find(globals.conference_hash, argv[2]))) {
-                switch_memory_pool_t *pool = NULL;
-                char *conf_name;
-                conf_xml_cfg_t xml_cfg = {0};
-
-                /* Setup a memory pool to use. */
-                if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
-                    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Pool Failure\n");
-                    goto done;
-                }
-
-                conf_name = switch_core_strdup(pool, argv[2]);
-
-                if ((profile_name = strchr(conf_name, '@'))) {
-                    *profile_name++ = '\0';
-                } else {
-                    profile_name = "default";
-                }
-                params = switch_mprintf("conf_name=%s&profile_name=%s", conf_name, profile_name);
-                /* Open the config from the xml registry  */
-                if (!(cxml = switch_xml_open_cfg(global_cf_name, &cfg, params))) {
-                    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", global_cf_name);
-                    goto done;
-                }
-
-                if ((profiles = switch_xml_child(cfg, "profiles"))) {
-                    xml_cfg.profile = switch_xml_find_child(profiles, "profile", "name", profile_name);
-                }
-
-                if (!xml_cfg.profile) {
-                    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find profile: %s\n", profile_name);
-                    switch_xml_free(cxml);
-                    cxml = NULL;
-                    goto done;
-                }
-
-                xml_cfg.controls = switch_xml_child(cfg, "caller-controls");
-
-                /* Release the config registry handle */
-                if (cxml) {
-                    switch_xml_free(cxml);
-                    cxml = NULL;
-                }
-
-                /* Create the conference object. */
-                new_conference = conference_new(conf_name, xml_cfg, pool);
-
-                if (!new_conference) {
-                    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
-                    if (pool != NULL) {
-                        switch_core_destroy_memory_pool(&pool);
-                    }
-                    goto done;
-                }
-
-                /* Set the minimum number of members (once you go above it you cannot go below it) */
-                new_conference->min = 1;
-
-                /* Indicate the conference is dynamic */
-                switch_set_flag_locked(new_conference, CFLAG_DYNAMIC);
-
-                switch_mutex_lock(new_conference->mutex);
-
-                /* Start the conference thread for this conference */
-                launch_conference_thread(new_conference);
-            } else {
-                switch_mutex_lock(new_conference->mutex);
-            }
-
-            /* move the member from the old conference to the new one */
-            conference_del_member(conference, member);
-            conference_add_member(new_conference, member);
-            switch_mutex_unlock(new_conference->mutex);
-
-            stream->write_function(stream, "OK Members sent to conference %s.\n", argv[2]);
-
-            /* tell them what happened */
-            if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
-                switch_channel_event_set_data(channel, event);
-                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", member->id);
-                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Old-Conference-Name", "%s", conference->name);
-                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "New-Conference-Name", "%s", argv[3]);
-                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "transfer");
-                switch_event_fire(&event);
-            }
-        }
-    } else {
-        ret_status = SWITCH_STATUS_GENERR;
-    }
-
- done:
-    switch_safe_free(params);
-    return ret_status;
-}
-
-static switch_status_t conf_api_sub_record(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char**argv)
-{
-    switch_status_t ret_status = SWITCH_STATUS_SUCCESS;
-    assert(conference != NULL);
-    assert(stream != NULL);
+	} else {
+		stream->write_function(stream, "Bad Args\n");
+		ret_status = SWITCH_STATUS_GENERR;
+	}
+
+	return ret_status;
+}
+
+static switch_status_t conf_api_sub_transfer(conference_obj_t * conference, switch_stream_handle_t *stream, int argc, char **argv)
+{
+	switch_status_t ret_status = SWITCH_STATUS_SUCCESS;
+	char *params = NULL;
+	assert(conference != NULL);
+	assert(stream != NULL);
+
+	if (argc > 3 && !switch_strlen_zero(argv[2])) {
+		int x;
 
-    if (argc > 2) {
+		for (x = 3; x < argc; x++) {
+			conference_member_t *member = NULL;
+			uint32_t id = atoi(argv[x]);
+			conference_obj_t *new_conference = NULL;
+			switch_channel_t *channel;
+			switch_event_t *event;
+			char *profile_name;
+			switch_xml_t cxml = NULL, cfg = NULL, profiles = NULL;
+
+			if (!id || !(member = conference_member_get(conference, id))) {
+				stream->write_function(stream, "No Member %u in conference %s.\n", id, conference->name);
+				continue;
+			}
+
+			channel = switch_core_session_get_channel(member->session);
+
+			/* build a new conference if it doesn't exist */
+			if (!(new_conference = (conference_obj_t *) switch_core_hash_find(globals.conference_hash, argv[2]))) {
+				switch_memory_pool_t *pool = NULL;
+				char *conf_name;
+				conf_xml_cfg_t xml_cfg = { 0 };
+
+				/* Setup a memory pool to use. */
+				if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Pool Failure\n");
+					goto done;
+				}
+
+				conf_name = switch_core_strdup(pool, argv[2]);
+
+				if ((profile_name = strchr(conf_name, '@'))) {
+					*profile_name++ = '\0';
+				} else {
+					profile_name = "default";
+				}
+				params = switch_mprintf("conf_name=%s&profile_name=%s", conf_name, profile_name);
+				/* Open the config from the xml registry  */
+				if (!(cxml = switch_xml_open_cfg(global_cf_name, &cfg, params))) {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", global_cf_name);
+					goto done;
+				}
+
+				if ((profiles = switch_xml_child(cfg, "profiles"))) {
+					xml_cfg.profile = switch_xml_find_child(profiles, "profile", "name", profile_name);
+				}
+
+				if (!xml_cfg.profile) {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find profile: %s\n", profile_name);
+					switch_xml_free(cxml);
+					cxml = NULL;
+					goto done;
+				}
+
+				xml_cfg.controls = switch_xml_child(cfg, "caller-controls");
+
+				/* Release the config registry handle */
+				if (cxml) {
+					switch_xml_free(cxml);
+					cxml = NULL;
+				}
+
+				/* Create the conference object. */
+				new_conference = conference_new(conf_name, xml_cfg, pool);
+
+				if (!new_conference) {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
+					if (pool != NULL) {
+						switch_core_destroy_memory_pool(&pool);
+					}
+					goto done;
+				}
+
+				/* Set the minimum number of members (once you go above it you cannot go below it) */
+				new_conference->min = 1;
+
+				/* Indicate the conference is dynamic */
+				switch_set_flag_locked(new_conference, CFLAG_DYNAMIC);
+
+				switch_mutex_lock(new_conference->mutex);
+
+				/* Start the conference thread for this conference */
+				launch_conference_thread(new_conference);
+			} else {
+				switch_mutex_lock(new_conference->mutex);
+			}
+
+			/* move the member from the old conference to the new one */
+			conference_del_member(conference, member);
+			conference_add_member(new_conference, member);
+			switch_mutex_unlock(new_conference->mutex);
+
+			stream->write_function(stream, "OK Members sent to conference %s.\n", argv[2]);
+
+			/* tell them what happened */
+			if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+				switch_channel_event_set_data(channel, event);
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", member->id);
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Old-Conference-Name", "%s", conference->name);
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "New-Conference-Name", "%s", argv[3]);
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "transfer");
+				switch_event_fire(&event);
+			}
+		}
+	} else {
+		ret_status = SWITCH_STATUS_GENERR;
+	}
+
+  done:
+	switch_safe_free(params);
+	return ret_status;
+}
+
+static switch_status_t conf_api_sub_record(conference_obj_t * conference, switch_stream_handle_t *stream, int argc, char **argv)
+{
+	switch_status_t ret_status = SWITCH_STATUS_SUCCESS;
+	assert(conference != NULL);
+	assert(stream != NULL);
+
+	if (argc > 2) {
 		stream->write_function(stream, "Record file %s\n", argv[2]);
-        launch_conference_record_thread(conference, argv[2]);
-    } else {
-        ret_status = SWITCH_STATUS_GENERR;
-    }
+		launch_conference_record_thread(conference, argv[2]);
+	} else {
+		ret_status = SWITCH_STATUS_GENERR;
+	}
 
-    return ret_status;
+	return ret_status;
 }
 
-static switch_status_t conf_api_sub_norecord(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char**argv)
+static switch_status_t conf_api_sub_norecord(conference_obj_t * conference, switch_stream_handle_t *stream, int argc, char **argv)
 {
-    switch_status_t ret_status = SWITCH_STATUS_SUCCESS;
+	switch_status_t ret_status = SWITCH_STATUS_SUCCESS;
 
-    assert(conference != NULL);
-    assert(stream != NULL);
+	assert(conference != NULL);
+	assert(stream != NULL);
 
-    if (argc > 2) {
-        int all = (strcasecmp(argv[2], "all") == 0 );
+	if (argc > 2) {
+		int all = (strcasecmp(argv[2], "all") == 0);
 		stream->write_function(stream, "Stop recording file %s\n", argv[2]);
-		
-        if (!conference_record_stop(conference, all ? NULL : argv[2]) && !all) {
-            stream->write_function(stream, "non-existant recording '%s'\n", argv[2]);
-        }
-    } else {
-        ret_status = SWITCH_STATUS_GENERR;
-    }
-	
-    return ret_status;
+
+		if (!conference_record_stop(conference, all ? NULL : argv[2]) && !all) {
+			stream->write_function(stream, "non-existant recording '%s'\n", argv[2]);
+		}
+	} else {
+		ret_status = SWITCH_STATUS_GENERR;
+	}
+
+	return ret_status;
 }
 
 typedef enum {
@@ -3287,198 +3212,211 @@
 /* API Interface Function sub-commands */
 /* Entries in this list should be kept in sync with the enum above */
 static api_command_t conf_api_sub_commands[] = {
-	{"list", (void_fn_t)&conf_api_sub_list, CONF_API_SUB_ARGS_SPLIT, "<confname> list [delim <string>]"}, 
-	{"energy", (void_fn_t)&conf_api_sub_energy, CONF_API_SUB_MEMBER_TARGET, "<confname> energy <member_id|all|last> [<newval>]"}, 
-	{"volume_in", (void_fn_t)&conf_api_sub_volume_in, CONF_API_SUB_MEMBER_TARGET, "<confname> volume_in <member_id|all|last> [<newval>]"}, 
-	{"volume_out", (void_fn_t)&conf_api_sub_volume_out, CONF_API_SUB_MEMBER_TARGET, "<confname> volume_out <member_id|all|last> [<newval>]"}, 
-	{"play", (void_fn_t)&conf_api_sub_play, CONF_API_SUB_ARGS_SPLIT, "<confname> play <file_path> [<member_id>]"}, 
-	{"say", (void_fn_t)&conf_api_sub_say, CONF_API_SUB_ARGS_AS_ONE, "<confname> say <text>"}, 
-	{"saymember", (void_fn_t)&conf_api_sub_saymember, CONF_API_SUB_ARGS_AS_ONE, "<confname> saymember <member_id> <text>"}, 
-	{"stop", (void_fn_t)&conf_api_sub_stop, CONF_API_SUB_ARGS_SPLIT, "<confname> stop <[current|all|last]> [<member_id>]"}, 
-	{"dtmf", (void_fn_t)&conf_api_sub_dtmf, CONF_API_SUB_MEMBER_TARGET, "<confname> dtmf <[member_id|all|last]> <digits>"}, 
-	{"kick", (void_fn_t)&conf_api_sub_kick, CONF_API_SUB_MEMBER_TARGET, "<confname> kick <[member_id|all|last]>"}, 
-	{"mute", (void_fn_t)&conf_api_sub_mute, CONF_API_SUB_MEMBER_TARGET, "<confname> mute <[member_id|all]|last>"}, 
-	{"unmute", (void_fn_t)&conf_api_sub_unmute, CONF_API_SUB_MEMBER_TARGET, "<confname> unmute <[member_id|all]|last>"}, 
-	{"deaf", (void_fn_t)&conf_api_sub_deaf, CONF_API_SUB_MEMBER_TARGET, "<confname> deaf <[member_id|all]|last>"}, 
-	{"undeaf", (void_fn_t)&conf_api_sub_undeaf, CONF_API_SUB_MEMBER_TARGET, "<confname> undeaf <[member_id|all]|last>"}, 
-	{"relate", (void_fn_t)&conf_api_sub_relate, CONF_API_SUB_ARGS_SPLIT, "<confname> relate <member_id> <other_member_id> [nospeak|nohear|clear]"}, 
-	{"lock", (void_fn_t)&conf_api_sub_lock, CONF_API_SUB_ARGS_SPLIT, "<confname> lock"}, 
-	{"unlock", (void_fn_t)&conf_api_sub_unlock, CONF_API_SUB_ARGS_SPLIT, "<confname> unlock"}, 
-	{"dial", (void_fn_t)&conf_api_sub_dial, CONF_API_SUB_ARGS_SPLIT, "<confname> dial <endpoint_module_name>/<destination> <callerid number> <callerid name>"}, 
-	{"bgdial", (void_fn_t)&conf_api_sub_bgdial, CONF_API_SUB_ARGS_SPLIT, "<confname> bgdial <endpoint_module_name>/<destination> <callerid number> <callerid name>"}, 
-	{"transfer", (void_fn_t)&conf_api_sub_transfer, CONF_API_SUB_ARGS_SPLIT, "<confname> transfer <conference_name> <member id> [...<member id>]"}, 
-	{"record", (void_fn_t)&conf_api_sub_record, CONF_API_SUB_ARGS_SPLIT, "<confname> record <filename>"}, 
-	{"norecord", (void_fn_t)&conf_api_sub_norecord, CONF_API_SUB_ARGS_SPLIT, "<confname> norecord <[filename|all]>"}, 
+	{"list", (void_fn_t) & conf_api_sub_list, CONF_API_SUB_ARGS_SPLIT, "<confname> list [delim <string>]"},
+	{"energy", (void_fn_t) & conf_api_sub_energy, CONF_API_SUB_MEMBER_TARGET,
+	 "<confname> energy <member_id|all|last> [<newval>]"},
+	{"volume_in", (void_fn_t) & conf_api_sub_volume_in, CONF_API_SUB_MEMBER_TARGET,
+	 "<confname> volume_in <member_id|all|last> [<newval>]"},
+	{"volume_out", (void_fn_t) & conf_api_sub_volume_out, CONF_API_SUB_MEMBER_TARGET,
+	 "<confname> volume_out <member_id|all|last> [<newval>]"},
+	{"play", (void_fn_t) & conf_api_sub_play, CONF_API_SUB_ARGS_SPLIT, "<confname> play <file_path> [<member_id>]"},
+	{"say", (void_fn_t) & conf_api_sub_say, CONF_API_SUB_ARGS_AS_ONE, "<confname> say <text>"},
+	{"saymember", (void_fn_t) & conf_api_sub_saymember, CONF_API_SUB_ARGS_AS_ONE,
+	 "<confname> saymember <member_id> <text>"},
+	{"stop", (void_fn_t) & conf_api_sub_stop, CONF_API_SUB_ARGS_SPLIT,
+	 "<confname> stop <[current|all|last]> [<member_id>]"},
+	{"dtmf", (void_fn_t) & conf_api_sub_dtmf, CONF_API_SUB_MEMBER_TARGET,
+	 "<confname> dtmf <[member_id|all|last]> <digits>"},
+	{"kick", (void_fn_t) & conf_api_sub_kick, CONF_API_SUB_MEMBER_TARGET, "<confname> kick <[member_id|all|last]>"},
+	{"mute", (void_fn_t) & conf_api_sub_mute, CONF_API_SUB_MEMBER_TARGET, "<confname> mute <[member_id|all]|last>"},
+	{"unmute", (void_fn_t) & conf_api_sub_unmute, CONF_API_SUB_MEMBER_TARGET,
+	 "<confname> unmute <[member_id|all]|last>"},
+	{"deaf", (void_fn_t) & conf_api_sub_deaf, CONF_API_SUB_MEMBER_TARGET, "<confname> deaf <[member_id|all]|last>"},
+	{"undeaf", (void_fn_t) & conf_api_sub_undeaf, CONF_API_SUB_MEMBER_TARGET,
+	 "<confname> undeaf <[member_id|all]|last>"},
+	{"relate", (void_fn_t) & conf_api_sub_relate, CONF_API_SUB_ARGS_SPLIT,
+	 "<confname> relate <member_id> <other_member_id> [nospeak|nohear|clear]"},
+	{"lock", (void_fn_t) & conf_api_sub_lock, CONF_API_SUB_ARGS_SPLIT, "<confname> lock"},
+	{"unlock", (void_fn_t) & conf_api_sub_unlock, CONF_API_SUB_ARGS_SPLIT, "<confname> unlock"},
+	{"dial", (void_fn_t) & conf_api_sub_dial, CONF_API_SUB_ARGS_SPLIT,
+	 "<confname> dial <endpoint_module_name>/<destination> <callerid number> <callerid name>"},
+	{"bgdial", (void_fn_t) & conf_api_sub_bgdial, CONF_API_SUB_ARGS_SPLIT,
+	 "<confname> bgdial <endpoint_module_name>/<destination> <callerid number> <callerid name>"},
+	{"transfer", (void_fn_t) & conf_api_sub_transfer, CONF_API_SUB_ARGS_SPLIT,
+	 "<confname> transfer <conference_name> <member id> [...<member id>]"},
+	{"record", (void_fn_t) & conf_api_sub_record, CONF_API_SUB_ARGS_SPLIT, "<confname> record <filename>"},
+	{"norecord", (void_fn_t) & conf_api_sub_norecord, CONF_API_SUB_ARGS_SPLIT, "<confname> norecord <[filename|all]>"},
 };
 
 #define CONFFUNCAPISIZE (sizeof(conf_api_sub_commands)/sizeof(conf_api_sub_commands[0]))
 
-switch_status_t conf_api_dispatch(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char **argv, const char *cmdline, int argn)
-{	
-    switch_status_t status = SWITCH_STATUS_FALSE;
-    uint32_t i, found = 0;
-    assert(conference != NULL);
-    assert(stream != NULL);
-
-    /* loop through the command table to find a match */
-    for (i = 0; i<CONFFUNCAPISIZE && !found; i++) {
-        if (strcasecmp(argv[argn], conf_api_sub_commands[i].pname) == 0) {
-            found = 1;
-            switch(conf_api_sub_commands[i].fntype) {
-
-                /* commands that we've broken the command line into arguments for */
-            case CONF_API_SUB_ARGS_SPLIT:
-                {	conf_api_args_cmd_t pfn = (conf_api_args_cmd_t)conf_api_sub_commands[i].pfnapicmd;
-
-                    if (pfn(conference, stream, argc, argv) != SWITCH_STATUS_SUCCESS) {
-                        /* command returned error, so show syntax usage */
-                        stream->write_function(stream, conf_api_sub_commands[i].psyntax);
-                    }
-                }
-                break;
-
-                /* member specific command that can be itteratted */
-            case CONF_API_SUB_MEMBER_TARGET:
-                {
-                    uint32_t id = 0;
-                    uint8_t all = 0;
-                    uint8_t last = 0;
-
-                    if (argv[argn+1]) {
-                        if (!(id = atoi(argv[argn+1]))) {
-                            all = strcasecmp(argv[argn+1], "all") ? 0 : 1;
-                            last = strcasecmp(argv[argn+1], "last") ? 0 : 1;
-                        }                        
-                    }
-
-                    if (all) {
-                        conference_member_itterator(conference, stream, (conf_api_member_cmd_t)conf_api_sub_commands[i].pfnapicmd, argv[argn+2]);
-                    } else if (last) {
-                        conference_member_t *member = NULL;
-                        conference_member_t *last_member = NULL;
-
-                        switch_mutex_lock(conference->member_mutex);
-
-                        /* find last (oldest) member */
-                        member = conference->members;
-                        while (member != NULL) {
-                            if (last_member == NULL || member->id > last_member->id) {
-                                last_member = member;
-                            }
-                            member = member->next;
-                        }
-
-                        /* exec functio on last (oldest) member */
-                        if (last_member != NULL) {
-                            conf_api_member_cmd_t pfn = (conf_api_member_cmd_t)conf_api_sub_commands[i].pfnapicmd;
-                            pfn(last_member, stream, argv[argn+2]);
-                        }
-
-                        switch_mutex_unlock(conference->member_mutex);
-                    } else if (id) {
-                        conf_api_member_cmd_t pfn = (conf_api_member_cmd_t)conf_api_sub_commands[i].pfnapicmd;
-                        conference_member_t *member = conference_member_get(conference, id);
-                        
-                        if (member != NULL) {
-                            pfn(conference_member_get(conference, id), stream, argv[argn+2]);
-                        } else {
-                            stream->write_function(stream, "Non-Existant ID %u\n", id);
-                        }
-                    } else {
-                        stream->write_function(stream, conf_api_sub_commands[i].psyntax);
-                    }
-                }
-                break;
-
-                /* commands that deals with all text after command */
-            case CONF_API_SUB_ARGS_AS_ONE:
-                {	
-                    conf_api_text_cmd_t pfn = (conf_api_text_cmd_t) conf_api_sub_commands[i].pfnapicmd;
-                    char *start_text;
-                    const char *modified_cmdline = cmdline;
-                    const char *cmd = conf_api_sub_commands[i].pname;
-
-                    if ((start_text = strstr(modified_cmdline, cmd))) {
-                        modified_cmdline = start_text + strlen(cmd);
-                        while(modified_cmdline && *modified_cmdline && (*modified_cmdline  == ' ' || *modified_cmdline == '\t')) {
-                            modified_cmdline++;
-                        }
-                    }
-                            
-                    /* call the command handler */
-                    if (pfn(conference, stream, modified_cmdline) != SWITCH_STATUS_SUCCESS) {
-                        /* command returned error, so show syntax usage */
-                        stream->write_function(stream, conf_api_sub_commands[i].psyntax);
-                    }
-                }
-                break;
-            }
-        }
-    }
-
-    if (!found) {
-        stream->write_function(stream, "Confernece command '%s' not found.\n", argv[argn]);
-    } else {
-        status = SWITCH_STATUS_SUCCESS;
-    }
+switch_status_t conf_api_dispatch(conference_obj_t * conference, switch_stream_handle_t *stream, int argc, char **argv, const char *cmdline, int argn)
+{
+	switch_status_t status = SWITCH_STATUS_FALSE;
+	uint32_t i, found = 0;
+	assert(conference != NULL);
+	assert(stream != NULL);
+
+	/* loop through the command table to find a match */
+	for (i = 0; i < CONFFUNCAPISIZE && !found; i++) {
+		if (strcasecmp(argv[argn], conf_api_sub_commands[i].pname) == 0) {
+			found = 1;
+			switch (conf_api_sub_commands[i].fntype) {
+
+				/* commands that we've broken the command line into arguments for */
+			case CONF_API_SUB_ARGS_SPLIT:
+				{
+					conf_api_args_cmd_t pfn = (conf_api_args_cmd_t) conf_api_sub_commands[i].pfnapicmd;
+
+					if (pfn(conference, stream, argc, argv) != SWITCH_STATUS_SUCCESS) {
+						/* command returned error, so show syntax usage */
+						stream->write_function(stream, conf_api_sub_commands[i].psyntax);
+					}
+				}
+				break;
+
+				/* member specific command that can be itteratted */
+			case CONF_API_SUB_MEMBER_TARGET:
+				{
+					uint32_t id = 0;
+					uint8_t all = 0;
+					uint8_t last = 0;
+
+					if (argv[argn + 1]) {
+						if (!(id = atoi(argv[argn + 1]))) {
+							all = strcasecmp(argv[argn + 1], "all") ? 0 : 1;
+							last = strcasecmp(argv[argn + 1], "last") ? 0 : 1;
+						}
+					}
+
+					if (all) {
+						conference_member_itterator(conference, stream, (conf_api_member_cmd_t) conf_api_sub_commands[i].pfnapicmd, argv[argn + 2]);
+					} else if (last) {
+						conference_member_t *member = NULL;
+						conference_member_t *last_member = NULL;
+
+						switch_mutex_lock(conference->member_mutex);
+
+						/* find last (oldest) member */
+						member = conference->members;
+						while (member != NULL) {
+							if (last_member == NULL || member->id > last_member->id) {
+								last_member = member;
+							}
+							member = member->next;
+						}
+
+						/* exec functio on last (oldest) member */
+						if (last_member != NULL) {
+							conf_api_member_cmd_t pfn = (conf_api_member_cmd_t) conf_api_sub_commands[i].pfnapicmd;
+							pfn(last_member, stream, argv[argn + 2]);
+						}
+
+						switch_mutex_unlock(conference->member_mutex);
+					} else if (id) {
+						conf_api_member_cmd_t pfn = (conf_api_member_cmd_t) conf_api_sub_commands[i].pfnapicmd;
+						conference_member_t *member = conference_member_get(conference, id);
+
+						if (member != NULL) {
+							pfn(conference_member_get(conference, id), stream, argv[argn + 2]);
+						} else {
+							stream->write_function(stream, "Non-Existant ID %u\n", id);
+						}
+					} else {
+						stream->write_function(stream, conf_api_sub_commands[i].psyntax);
+					}
+				}
+				break;
+
+				/* commands that deals with all text after command */
+			case CONF_API_SUB_ARGS_AS_ONE:
+				{
+					conf_api_text_cmd_t pfn = (conf_api_text_cmd_t) conf_api_sub_commands[i].pfnapicmd;
+					char *start_text;
+					const char *modified_cmdline = cmdline;
+					const char *cmd = conf_api_sub_commands[i].pname;
+
+					if ((start_text = strstr(modified_cmdline, cmd))) {
+						modified_cmdline = start_text + strlen(cmd);
+						while (modified_cmdline && *modified_cmdline && (*modified_cmdline == ' ' || *modified_cmdline == '\t')) {
+							modified_cmdline++;
+						}
+					}
+
+					/* call the command handler */
+					if (pfn(conference, stream, modified_cmdline) != SWITCH_STATUS_SUCCESS) {
+						/* command returned error, so show syntax usage */
+						stream->write_function(stream, conf_api_sub_commands[i].psyntax);
+					}
+				}
+				break;
+			}
+		}
+	}
+
+	if (!found) {
+		stream->write_function(stream, "Confernece command '%s' not found.\n", argv[argn]);
+	} else {
+		status = SWITCH_STATUS_SUCCESS;
+	}
 
-    return status;
+	return status;
 }
 
 /* API Interface Function */
 static switch_status_t conf_api_main(char *buf, switch_core_session_t *session, switch_stream_handle_t *stream)
 {
-    char *lbuf = NULL;
-    switch_status_t status = SWITCH_STATUS_SUCCESS;
-    char *http = NULL;
-    int argc;
-    char *argv[25] = {0};
-
-    if (!buf) {
-        buf = "help";
-    }
-
-    if (session) {
-        return SWITCH_STATUS_FALSE;
-    }
-
-    if (stream->event) {
-        http = switch_event_get_header(stream->event, "http-host");
-    }
-
-    if (http) {
-        /* Output must be to a web browser */
-        stream->write_function(stream, "<pre>\n");
-    }
-
-    if (!(lbuf = strdup(buf))) {
-        return status;
-    }
-
-    argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
-
-    /* try to find a command to execute */
-    if (argc) {
-        conference_obj_t *conference = NULL;
-
-        if ((conference = (conference_obj_t *) switch_core_hash_find(globals.conference_hash, argv[0]))) {
-            if (switch_thread_rwlock_tryrdlock(conference->rwlock) != SWITCH_STATUS_SUCCESS) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Read Lock Fail\n");
-                goto done;
-            }
-            if (argc >= 2) {
-                conf_api_dispatch(conference, stream, argc, argv, (const char *)buf, 1);
-            } else {
-                stream->write_function(stream, "Conference command, not specified.\nTry 'help'\n");
-            }
-            switch_thread_rwlock_unlock(conference->rwlock);
-
-        } else {
-            /* special case the list command, because it doesn't require a conference argument */
-            if (strcasecmp(argv[0], "list") == 0) {
-                conf_api_sub_list(NULL, stream, argc, argv);
-            } else if (strcasecmp(argv[0], "help") == 0 || strcasecmp(argv[0], "commands") == 0) {
-                stream->write_function(stream, "%s\n", conf_api_interface.syntax);
+	char *lbuf = NULL;
+	switch_status_t status = SWITCH_STATUS_SUCCESS;
+	char *http = NULL;
+	int argc;
+	char *argv[25] = { 0 };
+
+	if (!buf) {
+		buf = "help";
+	}
+
+	if (session) {
+		return SWITCH_STATUS_FALSE;
+	}
+
+	if (stream->event) {
+		http = switch_event_get_header(stream->event, "http-host");
+	}
+
+	if (http) {
+		/* Output must be to a web browser */
+		stream->write_function(stream, "<pre>\n");
+	}
+
+	if (!(lbuf = strdup(buf))) {
+		return status;
+	}
+
+	argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
+
+	/* try to find a command to execute */
+	if (argc) {
+		conference_obj_t *conference = NULL;
+
+		if ((conference = (conference_obj_t *) switch_core_hash_find(globals.conference_hash, argv[0]))) {
+			if (switch_thread_rwlock_tryrdlock(conference->rwlock) != SWITCH_STATUS_SUCCESS) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Read Lock Fail\n");
+				goto done;
+			}
+			if (argc >= 2) {
+				conf_api_dispatch(conference, stream, argc, argv, (const char *) buf, 1);
+			} else {
+				stream->write_function(stream, "Conference command, not specified.\nTry 'help'\n");
+			}
+			switch_thread_rwlock_unlock(conference->rwlock);
+
+		} else {
+			/* special case the list command, because it doesn't require a conference argument */
+			if (strcasecmp(argv[0], "list") == 0) {
+				conf_api_sub_list(NULL, stream, argc, argv);
+			} else if (strcasecmp(argv[0], "help") == 0 || strcasecmp(argv[0], "commands") == 0) {
+				stream->write_function(stream, "%s\n", conf_api_interface.syntax);
 			} else if (argv[1] && strcasecmp(argv[1], "dial") == 0) {
 				if (conf_api_sub_dial(NULL, stream, argc, argv) != SWITCH_STATUS_SUCCESS) {
 					/* command returned error, so show syntax usage */
@@ -3489,68 +3427,63 @@
 					/* command returned error, so show syntax usage */
 					stream->write_function(stream, conf_api_sub_commands[CONF_API_COMMAND_BGDIAL].psyntax);
 				}
-            } else {
-                stream->write_function(stream, "Conference %s not found\n", argv[0]);
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Conference %s not found\n", argv[0]);
-            }
-        }
-
-    } else {
-        stream->write_function(stream, "No parameters specified.\nTry 'help conference'\n");
-    }
+			} else {
+				stream->write_function(stream, "Conference %s not found\n", argv[0]);
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Conference %s not found\n", argv[0]);
+			}
+		}
 
- done:
-    switch_safe_free(lbuf);
+	} else {
+		stream->write_function(stream, "No parameters specified.\nTry 'help conference'\n");
+	}
 
-    return status;
+  done:
+	switch_safe_free(lbuf);
+
+	return status;
 
 }
 
 /* outbound call bridge progress call state callback handler */
 static switch_status_t audio_bridge_on_ring(switch_core_session_t *session)
 {
-    switch_channel_t *channel = NULL;
+	switch_channel_t *channel = NULL;
 
-    channel = switch_core_session_get_channel(session);
-    assert(channel != NULL);
+	channel = switch_core_session_get_channel(session);
+	assert(channel != NULL);
 
-    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CUSTOM RING\n");
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CUSTOM RING\n");
 
-    /* put the channel in a passive state so we can loop audio to it */
-    switch_channel_set_state(channel, CS_TRANSMIT);
-    return SWITCH_STATUS_FALSE;
+	/* put the channel in a passive state so we can loop audio to it */
+	switch_channel_set_state(channel, CS_TRANSMIT);
+	return SWITCH_STATUS_FALSE;
 }
 
 static const switch_state_handler_table_t audio_bridge_peer_state_handlers = {
-    /*.on_init */ NULL, 
-    /*.on_ring */ audio_bridge_on_ring, 
-    /*.on_execute */ NULL, 
-    /*.on_hangup */ NULL, 
-    /*.on_loopback */ NULL, 
-    /*.on_transmit */ NULL, 
-    /*.on_hold */ NULL, 
+	/*.on_init */ NULL,
+	/*.on_ring */ audio_bridge_on_ring,
+	/*.on_execute */ NULL,
+	/*.on_hangup */ NULL,
+	/*.on_loopback */ NULL,
+	/*.on_transmit */ NULL,
+	/*.on_hold */ NULL,
 };
 
 
 /* generate an outbound call from the conference */
-static switch_status_t conference_outcall(conference_obj_t *conference, 
-										  char *conference_name,										  
-                                          switch_core_session_t *session, 
-                                          char *bridgeto, 
-                                          uint32_t timeout, 
-                                          char *flags, 
-                                          char *cid_name, 
-                                          char *cid_num,
-                                          switch_call_cause_t *cause)
-{
-    switch_core_session_t *peer_session;
-    switch_channel_t *peer_channel;
-    switch_status_t status = SWITCH_STATUS_SUCCESS;
-    switch_channel_t *caller_channel = NULL;
-    char appdata[512];
+static switch_status_t conference_outcall(conference_obj_t * conference,
+										  char *conference_name,
+										  switch_core_session_t *session,
+										  char *bridgeto, uint32_t timeout, char *flags, char *cid_name, char *cid_num, switch_call_cause_t *cause)
+{
+	switch_core_session_t *peer_session;
+	switch_channel_t *peer_channel;
+	switch_status_t status = SWITCH_STATUS_SUCCESS;
+	switch_channel_t *caller_channel = NULL;
+	char appdata[512];
 
 
-    *cause = SWITCH_CAUSE_NORMAL_CLEARING;
+	*cause = SWITCH_CAUSE_NORMAL_CLEARING;
 
 
 	if (conference == NULL) {
@@ -3565,630 +3498,608 @@
 
 		peer_channel = switch_core_session_get_channel(peer_session);
 		assert(peer_channel != NULL);
-		
+
 		goto callup;
 	}
 
 
 	conference_name = conference->name;
 
-    if (switch_thread_rwlock_tryrdlock(conference->rwlock) != SWITCH_STATUS_SUCCESS) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Read Lock Fail\n");
-        return SWITCH_STATUS_FALSE;
-    }
-
-    if (session != NULL) {
-        caller_channel = switch_core_session_get_channel(session);
-	
-    }
-
-    if (switch_strlen_zero(cid_name)) {
-        cid_name = conference->caller_id_name;
-    }
-
-    if (switch_strlen_zero(cid_num)) {
-        cid_num = conference->caller_id_number;
-    }
-
-    /* establish an outbound call leg */
-    if (switch_ivr_originate(session, 
-                             &peer_session, 
-                             cause, 
-                             bridgeto, 
-                             timeout, 
-                             &audio_bridge_peer_state_handlers, 
-                             cid_name, 
-                             cid_num, 
-                             NULL) != SWITCH_STATUS_SUCCESS) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot create outgoing channel, cause: %s\n", 
-                          switch_channel_cause2str(*cause));
-        if (caller_channel) {
-            switch_channel_hangup(caller_channel, *cause);
-        }
-        goto done;
-    } 
-
-
-    peer_channel = switch_core_session_get_channel(peer_session);
-    assert(peer_channel != NULL);
-
-    /* make sure the conference still exists */
-    if (!switch_test_flag(conference, CFLAG_RUNNING)) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Conference is gone now, nevermind..\n");
-        if (caller_channel) {
-            switch_channel_hangup(caller_channel, SWITCH_CAUSE_NO_ROUTE_DESTINATION);
-        }
-        switch_channel_hangup(peer_channel, SWITCH_CAUSE_NO_ROUTE_DESTINATION);
-        goto done;
-    }
-
-    if (caller_channel && switch_channel_test_flag(peer_channel, CF_ANSWERED)) {
-        switch_channel_answer(caller_channel);
-    }
-
- callup:
-
-    /* if the outbound call leg is ready */
-    if (switch_channel_test_flag(peer_channel, CF_ANSWERED) || switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA)) {
-        switch_caller_extension_t *extension = NULL;
-
-        /* build an extension name object */
-        if ((extension = switch_caller_extension_new(peer_session, conference_name, conference_name)) == 0) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "memory error!\n");
-            status = SWITCH_STATUS_MEMERR;
-            goto done;
-        }
-        /* add them to the conference */
-        if (flags && strcasecmp(flags, "none")) {
-            snprintf(appdata, sizeof(appdata), "%s +flags{%s}", conference_name, flags);
-            switch_caller_extension_add_application(peer_session, extension, (char *) global_app_name, appdata);
-        } else {
-            switch_caller_extension_add_application(peer_session, extension, (char *) global_app_name, conference_name);
-        }
-
-        switch_channel_set_caller_extension(peer_channel, extension);
-        switch_channel_set_state(peer_channel, CS_EXECUTE);
-
-    } else {
-        switch_channel_hangup(peer_channel, SWITCH_CAUSE_NO_ANSWER);
-        status = SWITCH_STATUS_FALSE;
-        goto done;
-    }
+	if (switch_thread_rwlock_tryrdlock(conference->rwlock) != SWITCH_STATUS_SUCCESS) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Read Lock Fail\n");
+		return SWITCH_STATUS_FALSE;
+	}
+
+	if (session != NULL) {
+		caller_channel = switch_core_session_get_channel(session);
+
+	}
+
+	if (switch_strlen_zero(cid_name)) {
+		cid_name = conference->caller_id_name;
+	}
+
+	if (switch_strlen_zero(cid_num)) {
+		cid_num = conference->caller_id_number;
+	}
+
+	/* establish an outbound call leg */
+	if (switch_ivr_originate(session,
+							 &peer_session, cause, bridgeto, timeout, &audio_bridge_peer_state_handlers, cid_name, cid_num,
+							 NULL) != SWITCH_STATUS_SUCCESS) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot create outgoing channel, cause: %s\n", switch_channel_cause2str(*cause));
+		if (caller_channel) {
+			switch_channel_hangup(caller_channel, *cause);
+		}
+		goto done;
+	}
+
+
+	peer_channel = switch_core_session_get_channel(peer_session);
+	assert(peer_channel != NULL);
+
+	/* make sure the conference still exists */
+	if (!switch_test_flag(conference, CFLAG_RUNNING)) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Conference is gone now, nevermind..\n");
+		if (caller_channel) {
+			switch_channel_hangup(caller_channel, SWITCH_CAUSE_NO_ROUTE_DESTINATION);
+		}
+		switch_channel_hangup(peer_channel, SWITCH_CAUSE_NO_ROUTE_DESTINATION);
+		goto done;
+	}
+
+	if (caller_channel && switch_channel_test_flag(peer_channel, CF_ANSWERED)) {
+		switch_channel_answer(caller_channel);
+	}
+
+  callup:
+
+	/* if the outbound call leg is ready */
+	if (switch_channel_test_flag(peer_channel, CF_ANSWERED) || switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA)) {
+		switch_caller_extension_t *extension = NULL;
+
+		/* build an extension name object */
+		if ((extension = switch_caller_extension_new(peer_session, conference_name, conference_name)) == 0) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "memory error!\n");
+			status = SWITCH_STATUS_MEMERR;
+			goto done;
+		}
+		/* add them to the conference */
+		if (flags && strcasecmp(flags, "none")) {
+			snprintf(appdata, sizeof(appdata), "%s +flags{%s}", conference_name, flags);
+			switch_caller_extension_add_application(peer_session, extension, (char *) global_app_name, appdata);
+		} else {
+			switch_caller_extension_add_application(peer_session, extension, (char *) global_app_name, conference_name);
+		}
+
+		switch_channel_set_caller_extension(peer_channel, extension);
+		switch_channel_set_state(peer_channel, CS_EXECUTE);
+
+	} else {
+		switch_channel_hangup(peer_channel, SWITCH_CAUSE_NO_ANSWER);
+		status = SWITCH_STATUS_FALSE;
+		goto done;
+	}
+
+  done:
+	if (conference) {
+		switch_thread_rwlock_unlock(conference->rwlock);
+	}
+	return status;
+}
+
+struct bg_call {
+	conference_obj_t *conference;
+	switch_core_session_t *session;
+	char *bridgeto;
+	uint32_t timeout;
+	char *flags;
+	char *cid_name;
+	char *cid_num;
+	char *conference_name;
+};
+
+static void *SWITCH_THREAD_FUNC conference_outcall_run(switch_thread_t * thread, void *obj)
+{
+	struct bg_call *call = (struct bg_call *) obj;
+
+	if (call) {
+		switch_call_cause_t cause;
+		switch_event_t *event;
+
+		conference_outcall(call->conference, NULL, call->session, call->bridgeto, call->timeout, call->flags, call->cid_name, call->cid_num, &cause);
+
+		if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", "%s", call->conference->name);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "bgdial-result");
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Result", "%s", switch_channel_cause2str(cause));
+			switch_event_fire(&event);
+		}
+		switch_safe_free(call->bridgeto);
+		switch_safe_free(call->flags);
+		switch_safe_free(call->cid_name);
+		switch_safe_free(call->cid_num);
+		switch_safe_free(call->conference_name);
+		switch_safe_free(call);
+	}
+
+	return NULL;
+}
+
+static switch_status_t conference_outcall_bg(conference_obj_t * conference,
+											 char *conference_name,
+											 switch_core_session_t *session, char *bridgeto, uint32_t timeout, char *flags, char *cid_name, char *cid_num)
+{
+	struct bg_call *call = NULL;
+
+	if ((call = malloc(sizeof(*call)))) {
+		switch_thread_t *thread;
+		switch_threadattr_t *thd_attr = NULL;
+
+		memset(call, 0, sizeof(*call));
+		call->conference = conference;
+		call->session = session;
+		call->timeout = timeout;
+
+		if (bridgeto) {
+			call->bridgeto = strdup(bridgeto);
+		}
+		if (flags) {
+			call->flags = strdup(flags);
+		}
+		if (cid_name) {
+			call->cid_name = strdup(cid_name);
+		}
+		if (cid_num) {
+			call->cid_num = strdup(cid_num);
+		}
+
+		if (conference_name) {
+			call->conference_name = strdup(conference_name);
+		}
+
+
+		switch_threadattr_create(&thd_attr, conference->pool);
+		switch_threadattr_detach_set(thd_attr, 1);
+		switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
+		switch_thread_create(&thread, thd_attr, conference_outcall_run, call, conference->pool);
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Lanuching BG Thread for outcall\n");
+
+		return SWITCH_STATUS_SUCCESS;
+	}
+
+	return SWITCH_STATUS_MEMERR;
+}
+
+/* Play a file */
+static switch_status_t conference_local_play_file(conference_obj_t * conference,
+												  switch_core_session_t *session, char *path, uint32_t leadin, char *buf, switch_size_t len)
+{
+	uint32_t x = 0;
+	switch_status_t status = SWITCH_STATUS_SUCCESS;
+
+	/* generate some space infront of the file to be played */
+	for (x = 0; x < leadin; x++) {
+		switch_frame_t *read_frame;
+		switch_status_t status = switch_core_session_read_frame(session, &read_frame, 1000, 0);
+
+		if (!SWITCH_READ_ACCEPTABLE(status)) {
+			break;
+		}
+	}
+
+	/* if all is well, really play the file */
+	if (status == SWITCH_STATUS_SUCCESS) {
+		char *dpath = NULL;
+
+		if (conference->sound_prefix) {
+			if (!(dpath = switch_mprintf("%s/%s", conference->sound_prefix, path))) {
+				return SWITCH_STATUS_MEMERR;
+			}
+			path = dpath;
+		}
+
+		status = switch_ivr_play_file(session, NULL, path, NULL);
+		switch_safe_free(dpath);
+	}
+
+	return status;
+}
+
+static void set_mflags(char *flags, member_flag_t * f)
+{
+	if (flags) {
+		if (strstr(flags, "mute")) {
+			*f &= ~MFLAG_CAN_SPEAK;
+		} else if (strstr(flags, "deaf")) {
+			*f &= ~MFLAG_CAN_HEAR;
+		} else if (strstr(flags, "waste")) {
+			*f |= MFLAG_WASTE_BANDWIDTH;
+		}
+	}
+
+}
+
+
+/* Application interface function that is called from the dialplan to join the channel to a conference */
+static void conference_function(switch_core_session_t *session, char *data)
+{
+	switch_codec_t *read_codec = NULL;
+	uint32_t flags = 0;
+	conference_member_t member = { 0 };
+	conference_obj_t *conference = NULL;
+	switch_channel_t *channel = NULL;
+	char *mydata = switch_core_session_strdup(session, data);
+	char *conf_name = NULL;
+	char *bridge_prefix = "bridge:";
+	char *flags_prefix = "+flags{";
+	char *bridgeto = NULL;
+	char *profile_name = NULL;
+	switch_xml_t cxml = NULL, cfg = NULL, profiles = NULL;
+	char *flags_str;
+	member_flag_t mflags = 0;
+	switch_core_session_message_t msg = { 0 };
+	uint8_t rl = 0, isbr = 0;
+	char *dpin = NULL;
+	conf_xml_cfg_t xml_cfg = { 0 };
+	char *params = NULL;
+
+	channel = switch_core_session_get_channel(session);
+	assert(channel != NULL);
+
+	if (!mydata) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Pool Failure\n");
+		return;
+	}
+
+
+	/* is this a bridging conference ? */
+	if (!strncasecmp(mydata, bridge_prefix, strlen(bridge_prefix))) {
+		isbr = 1;
+		mydata += strlen(bridge_prefix);
+		if ((bridgeto = strchr(mydata, ':'))) {
+			*bridgeto++ = '\0';
+		} else {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Config Error!\n");
+			goto done;
+		}
+	}
+
+	conf_name = mydata;
+
+	/* is there a conference pin ? */
+	if ((dpin = strchr(conf_name, '+'))) {
+		*dpin++ = '\0';
+	}
+
+	/* is there profile specification ? */
+	if ((profile_name = strchr(conf_name, '@'))) {
+		*profile_name++ = '\0';
+	} else {
+		profile_name = "default";
+	}
+
+	params = switch_mprintf("conf_name=%s&profile_name=%s", conf_name, profile_name);
+
+	/* Open the config from the xml registry */
+	if (!(cxml = switch_xml_open_cfg(global_cf_name, &cfg, params))) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", global_cf_name);
+		goto done;
+	}
+
+	if ((profiles = switch_xml_child(cfg, "profiles"))) {
+		xml_cfg.profile = switch_xml_find_child(profiles, "profile", "name", profile_name);
+	}
+
+	if (!xml_cfg.profile) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find profile: %s\n", profile_name);
+		switch_xml_free(cxml);
+		cxml = NULL;
+		goto done;
+	}
+
+	xml_cfg.controls = switch_xml_child(cfg, "caller-controls");
+
+	/* if this is a bridging call, and it's not a duplicate, build a */
+	/* conference object, and skip pin handling, and locked checking */
+	if (isbr) {
+		char *uuid = switch_core_session_get_uuid(session);
+
+		if (!strcmp(conf_name, "_uuid_")) {
+			conf_name = uuid;
+		}
+
+		if ((conference = (conference_obj_t *) switch_core_hash_find(globals.conference_hash, conf_name))) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Conference %s already exists!\n", conf_name);
+			goto done;
+		}
+
+		/* Create the conference object. */
+		conference = conference_new(conf_name, xml_cfg, NULL);
+
+		if (!conference) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
+			goto done;
+		}
+
+		/* Set the minimum number of members (once you go above it you cannot go below it) */
+		conference->min = 2;
+
+		/* if the dialplan specified a pin, override the profile's value */
+		if (dpin) {
+			conference->pin = switch_core_strdup(conference->pool, dpin);
+		}
+
+		/* Indicate the conference is dynamic */
+		switch_set_flag_locked(conference, CFLAG_DYNAMIC);
+
+		/* Start the conference thread for this conference */
+		launch_conference_thread(conference);
+
+	} else {
+		/* if the conference exists, get the pointer to it */
+		if (!(conference = (conference_obj_t *) switch_core_hash_find(globals.conference_hash, conf_name))) {
+			/* couldn't find the conference, create one */
+			conference = conference_new(conf_name, xml_cfg, NULL);
+
+			if (!conference) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
+				goto done;
+			}
+
+			/* if the dialplan specified a pin, override the profile's value */
+			if (dpin) {
+				conference->pin = switch_core_strdup(conference->pool, dpin);
+			}
+
+			/* Set the minimum number of members (once you go above it you cannot go below it) */
+			conference->min = 1;
+
+			/* Indicate the conference is dynamic */
+			switch_set_flag_locked(conference, CFLAG_DYNAMIC);
+
+			/* Start the conference thread for this conference */
+			launch_conference_thread(conference);
+		}
+
+		/* acquire a read lock on the thread so it can't leave without us */
+		if (switch_thread_rwlock_tryrdlock(conference->rwlock) != SWITCH_STATUS_SUCCESS) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Read Lock Fail\n");
+			goto done;
+		}
+		rl++;
+
+		/* if this is not an outbound call, deal with conference pins */
+		if (!switch_channel_test_flag(channel, CF_OUTBOUND) && conference->pin) {
+			char pin_buf[80] = "";
+			int pin_retries = 3;	/* XXX - this should be configurable - i'm too lazy to do it right now... */
+			int pin_valid = 0;
+			switch_status_t status = SWITCH_STATUS_SUCCESS;
+
+			/* Answer the channel */
+			switch_channel_answer(channel);
+
+			while (!pin_valid && pin_retries && status == SWITCH_STATUS_SUCCESS) {
+
+				/* be friendly */
+				if (conference->pin_sound) {
+					conference_local_play_file(conference, session, conference->pin_sound, 20, pin_buf, sizeof(pin_buf));
+				}
+				/* wait for them if neccessary */
+				if (strlen(pin_buf) < strlen(conference->pin)) {
+					char *buf = pin_buf + strlen(pin_buf);
+					char term = '\0';
+
+					status = switch_ivr_collect_digits_count(session,
+															 buf,
+															 sizeof(pin_buf) - (unsigned int) strlen(pin_buf),
+															 (unsigned int) strlen(conference->pin) - (unsigned int) strlen(pin_buf), "#", &term, 10000);
+				}
+
+				pin_valid = (status == SWITCH_STATUS_SUCCESS && strcmp(pin_buf, conference->pin) == 0);
+				if (!pin_valid) {
+					/* zero the collected pin */
+					memset(pin_buf, 0, sizeof(pin_buf));
+
+					/* more friendliness */
+					if (conference->bad_pin_sound) {
+						conference_local_play_file(conference, session, conference->bad_pin_sound, 20, pin_buf, sizeof(pin_buf));
+					}
+				}
+				pin_retries--;
+			}
+
+			if (!pin_valid) {
+				goto done;
+			}
+		}
+
+		/* don't allow more callers if the conference is locked, unless we invited them */
+		if (switch_test_flag(conference, CFLAG_LOCKED) && !switch_channel_test_flag(channel, CF_OUTBOUND)) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Conference %s is locked.\n", conf_name);
+			if (conference->locked_sound) {
+				/* Answer the channel */
+				switch_channel_answer(channel);
+				conference_local_play_file(conference, session, conference->locked_sound, 20, NULL, 0);
+			}
+			goto done;
+		}
+
+		/* dont allow more callers than the max_members allows for -- I explicitly didnt allow outbound calls
+		 * someone else can add that (see above) if they feel that outbound calls should be able to violate the
+		 * max_members limit -- TRX
+		 */
+		if ((conference->max_members > 0) && (conference->count >= conference->max_members)) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Conference %s is full.\n", conf_name);
+			if (conference->maxmember_sound) {
+				/* Answer the channel */
+				switch_channel_answer(channel);
+				conference_local_play_file(conference, session, conference->maxmember_sound, 20, NULL, 0);
+			}
+			goto done;
+		}
 
- done:
-	if (conference) {
-		switch_thread_rwlock_unlock(conference->rwlock);
 	}
-    return status;
-}
-
-struct bg_call {
-    conference_obj_t *conference;
-    switch_core_session_t *session;
-    char *bridgeto;
-    uint32_t timeout;
-    char *flags;
-    char *cid_name;
-    char *cid_num;
-	char *conference_name;
-};
 
-static void *SWITCH_THREAD_FUNC conference_outcall_run(switch_thread_t *thread, void *obj)
-{
-    struct bg_call *call = (struct bg_call *) obj;
-    
-    if (call) {
-        switch_call_cause_t cause;
-        switch_event_t *event;
-
-        conference_outcall(call->conference, NULL, call->session, call->bridgeto, call->timeout, call->flags, call->cid_name, call->cid_num, &cause);
-
-        if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", "%s", call->conference->name);
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "bgdial-result");
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Result", "%s", switch_channel_cause2str(cause));
-            switch_event_fire(&event);
-        }
-        switch_safe_free(call->bridgeto);
-        switch_safe_free(call->flags);
-        switch_safe_free(call->cid_name);
-        switch_safe_free(call->cid_num);
-        switch_safe_free(call->conference_name);
-        switch_safe_free(call);
-    }
+	/* Release the config registry handle */
+	if (cxml) {
+		switch_xml_free(cxml);
+		cxml = NULL;
+	}
 
-    return NULL;
-}
+	/* if we're using "bridge:" make an outbound call and bridge it in */
+	if (!switch_strlen_zero(bridgeto) && strcasecmp(bridgeto, "none")) {
+		switch_call_cause_t cause;
+		if (conference_outcall(conference, NULL, session, bridgeto, 60, NULL, NULL, NULL, &cause) != SWITCH_STATUS_SUCCESS) {
+			goto done;
+		}
+	} else {
+		/* if we're not using "bridge:" set the conference answered flag */
+		/* and this isn't an outbound channel, answer the call */
+		if (!switch_channel_test_flag(channel, CF_OUTBOUND))
+			switch_set_flag(conference, CFLAG_ANSWERED);
+	}
+
+	/* Save the original read codec. */
+	read_codec = switch_core_session_get_read_codec(session);
+	member.native_rate = read_codec->implementation->samples_per_second;
+	member.pool = switch_core_session_get_pool(session);
+
+	/* Setup a Signed Linear codec for reading audio. */
+	if (switch_core_codec_init(&member.read_codec,
+							   "L16",
+							   NULL,
+							   read_codec->implementation->samples_per_second,
+							   read_codec->implementation->microseconds_per_frame / 1000,
+							   1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, member.pool) == SWITCH_STATUS_SUCCESS) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
+						  "Raw Codec Activation Success L16@%uhz 1 channel %dms\n",
+						  read_codec->implementation->samples_per_second, read_codec->implementation->microseconds_per_frame / 1000);
+	} else {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activation Failed L16@%uhz 1 channel %dms\n",
+						  read_codec->implementation->samples_per_second, read_codec->implementation->microseconds_per_frame / 1000);
+		flags = 0;
+		goto done;
+	}
 
-static switch_status_t conference_outcall_bg(conference_obj_t *conference, 
-											 char *conference_name,
-                                             switch_core_session_t *session, 
-                                             char *bridgeto, 
-                                             uint32_t timeout, 
-                                             char *flags, 
-                                             char *cid_name, 
-                                             char *cid_num)
-{
-    struct bg_call *call = NULL;
-    
-    if ((call = malloc(sizeof(*call)))) {
-        switch_thread_t *thread;
-        switch_threadattr_t *thd_attr = NULL;
-
-        memset(call, 0, sizeof(*call));
-        call->conference = conference;
-        call->session = session;
-        call->timeout = timeout;
-
-        if (bridgeto) {
-            call->bridgeto = strdup(bridgeto);
-        }
-        if (flags) {
-            call->flags = strdup(flags);
-        }
-        if (cid_name) {
-            call->cid_name = strdup(cid_name);
-        }
-        if (cid_num) {
-            call->cid_num = strdup(cid_num);
-        }
-		
-		if (conference_name) {
-			call->conference_name = strdup(conference_name);
+	if (read_codec->implementation->samples_per_second != conference->rate) {
+		switch_audio_resampler_t **resampler = read_codec->implementation->samples_per_second > conference->rate ?
+			&member.read_resampler : &member.mux_resampler;
+
+		if (switch_resample_create(resampler,
+								   read_codec->implementation->samples_per_second,
+								   read_codec->implementation->samples_per_second * 20,
+								   conference->rate, conference->rate * 20, member.pool) != SWITCH_STATUS_SUCCESS) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unable to crete resampler!\n");
+			goto done;
 		}
 
-        
-        switch_threadattr_create(&thd_attr, conference->pool);
-        switch_threadattr_detach_set(thd_attr, 1);
-        switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
-        switch_thread_create(&thread, thd_attr, conference_outcall_run, call, conference->pool);
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Lanuching BG Thread for outcall\n");
+		/* Setup an audio buffer for the resampled audio */
+		if (switch_buffer_create_dynamic(&member.resample_buffer, CONF_DBLOCK_SIZE, CONF_DBUFFER_SIZE, CONF_DBUFFER_MAX)
+			!= SWITCH_STATUS_SUCCESS) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error Creating Audio Buffer!\n");
+			goto done;
+		}
+	}
+	/* Setup a Signed Linear codec for writing audio. */
+	if (switch_core_codec_init(&member.write_codec,
+							   "L16",
+							   NULL,
+							   read_codec->implementation->samples_per_second,
+							   read_codec->implementation->microseconds_per_frame / 1000,
+							   1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, member.pool) == SWITCH_STATUS_SUCCESS) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
+						  "Raw Codec Activation Success L16@%uhz 1 channel %dms\n",
+						  read_codec->implementation->samples_per_second, read_codec->implementation->microseconds_per_frame / 1000);
+	} else {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activation Failed L16@%uhz 1 channel %dms\n",
+						  read_codec->implementation->samples_per_second, read_codec->implementation->microseconds_per_frame / 1000);
+		flags = 0;
+		goto codec_done2;
+	}
 
-		return SWITCH_STATUS_SUCCESS;
-    }
+	/* Setup an audio buffer for the incoming audio */
+	if (switch_buffer_create_dynamic(&member.audio_buffer, CONF_DBLOCK_SIZE, CONF_DBUFFER_SIZE, CONF_DBUFFER_MAX) != SWITCH_STATUS_SUCCESS) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error Creating Audio Buffer!\n");
+		goto codec_done1;
+	}
 
-	return SWITCH_STATUS_MEMERR;
-}
+	/* Setup an audio buffer for the outgoing audio */
+	if (switch_buffer_create_dynamic(&member.mux_buffer, CONF_DBLOCK_SIZE, CONF_DBUFFER_SIZE, CONF_DBUFFER_MAX) != SWITCH_STATUS_SUCCESS) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error Creating Audio Buffer!\n");
+		goto codec_done1;
+	}
 
-/* Play a file */
-static switch_status_t conference_local_play_file(conference_obj_t *conference, 
-                                                  switch_core_session_t *session, char *path, uint32_t leadin, char *buf, switch_size_t len)
-{
-    uint32_t x = 0;
-    switch_status_t status = SWITCH_STATUS_SUCCESS;
+	/* Prepare MUTEXS */
+	member.id = next_member_id();
+	member.session = session;
+	switch_mutex_init(&member.flag_mutex, SWITCH_MUTEX_NESTED, member.pool);
+	switch_mutex_init(&member.audio_in_mutex, SWITCH_MUTEX_NESTED, member.pool);
+	switch_mutex_init(&member.audio_out_mutex, SWITCH_MUTEX_NESTED, member.pool);
+
+	/* Install our Signed Linear codec so we get the audio in that format */
+	switch_core_session_set_read_codec(member.session, &member.read_codec);
+
+	if ((flags_str = strstr(mydata, flags_prefix))) {
+		char *p;
+
+		*flags_str = '\0';
+		flags_str += strlen(flags_prefix);
+		if ((p = strchr(flags_str, '}'))) {
+			*p = '\0';
+		}
+	}
 
-    /* generate some space infront of the file to be played */
-    for (x = 0; x < leadin; x++) {
-        switch_frame_t *read_frame;
-        switch_status_t status = switch_core_session_read_frame(session, &read_frame, 1000, 0);
+	mflags = conference->mflags;
+	set_mflags(flags_str, &mflags);
+	switch_set_flag_locked((&member), MFLAG_RUNNING | mflags);
 
-        if (!SWITCH_READ_ACCEPTABLE(status)) {
-            break;
-        }
-    }
+	/* Add the caller to the conference */
+	if (conference_add_member(conference, &member) != SWITCH_STATUS_SUCCESS) {
+		goto codec_done1;
+	}
 
-    /* if all is well, really play the file */
-    if (status == SWITCH_STATUS_SUCCESS) {
-        char *dpath = NULL;
+	msg.from = __FILE__;
 
-        if (conference->sound_prefix) {
-            if (!(dpath = switch_mprintf("%s/%s", conference->sound_prefix, path))) {
-                return SWITCH_STATUS_MEMERR;
-            }
-            path = dpath;
-        }
+	/* Tell the channel we are going to be in a bridge */
+	msg.message_id = SWITCH_MESSAGE_INDICATE_BRIDGE;
+	switch_core_session_receive_message(session, &msg);
 
-        status = switch_ivr_play_file(session, NULL, path, NULL);
-        switch_safe_free(dpath);
-    }
+	/* Run the confernece loop */
+	conference_loop_output(&member);
 
-    return status;
-}
+	/* Tell the channel we are no longer going to be in a bridge */
+	msg.message_id = SWITCH_MESSAGE_INDICATE_UNBRIDGE;
+	switch_core_session_receive_message(session, &msg);
 
-static void set_mflags(char *flags, member_flag_t *f)
-{
-	if (flags) {
-		if (strstr(flags, "mute")) {
-			*f &= ~MFLAG_CAN_SPEAK;
-		} else if (strstr(flags, "deaf")) {
-			*f &= ~MFLAG_CAN_HEAR;
-		} else if (strstr(flags, "waste")) {
-			*f |= MFLAG_WASTE_BANDWIDTH;
-		}
-	}
+	/* Remove the caller from the conference */
+	conference_del_member(member.conference, &member);
 
-}
+	/* Put the original codec back */
+	switch_core_session_set_read_codec(member.session, read_codec);
 
+	/* Clean Up.  codec_done(X): is for error situations after the codecs were setup and done: is for situations before */
+  codec_done1:
+	switch_core_codec_destroy(&member.read_codec);
+  codec_done2:
+	switch_core_codec_destroy(&member.write_codec);
+  done:
+	switch_safe_free(params);
+	switch_buffer_destroy(&member.resample_buffer);
+	switch_buffer_destroy(&member.audio_buffer);
+	switch_buffer_destroy(&member.mux_buffer);
 
-/* Application interface function that is called from the dialplan to join the channel to a conference */
-static void conference_function(switch_core_session_t *session, char *data)
-{
-    switch_codec_t *read_codec = NULL;
-    uint32_t flags = 0;
-    conference_member_t member = {0};
-    conference_obj_t *conference = NULL;
-    switch_channel_t *channel = NULL;
-    char *mydata = switch_core_session_strdup(session, data);
-    char *conf_name = NULL;
-    char *bridge_prefix = "bridge:";
-    char *flags_prefix = "+flags{";
-    char *bridgeto = NULL;
-    char *profile_name = NULL;
-    switch_xml_t cxml = NULL, cfg = NULL, profiles = NULL;
-    char *flags_str;
-    member_flag_t mflags = 0;
-    switch_core_session_message_t msg = {0};
-    uint8_t rl = 0, isbr = 0;
-    char *dpin = NULL;
-    conf_xml_cfg_t xml_cfg = {0};
-    char *params = NULL;
-
-    channel = switch_core_session_get_channel(session);
-    assert(channel != NULL);
-
-    if (!mydata) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Pool Failure\n");
-        return;
-    }
-
-
-    /* is this a bridging conference ? */
-    if (!strncasecmp(mydata, bridge_prefix, strlen(bridge_prefix))) {
-        isbr = 1;
-        mydata += strlen(bridge_prefix);
-        if ((bridgeto = strchr(mydata, ':'))) {
-            *bridgeto++ = '\0';
-        } else {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Config Error!\n");
-            goto done;
-        }
-    }
-
-    conf_name = mydata;
-
-    /* is there a conference pin ? */
-    if ((dpin = strchr(conf_name, '+'))) {
-        *dpin++ = '\0';
-    }
-
-    /* is there profile specification ? */
-    if ((profile_name = strchr(conf_name, '@'))) {
-        *profile_name++ = '\0';
-    } else {
-        profile_name = "default";
-    }
-
-    params = switch_mprintf("conf_name=%s&profile_name=%s", conf_name, profile_name);
-
-    /* Open the config from the xml registry */
-    if (!(cxml = switch_xml_open_cfg(global_cf_name, &cfg, params))) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", global_cf_name);
-        goto done;
-    }
-
-    if ((profiles = switch_xml_child(cfg, "profiles"))) {
-        xml_cfg.profile = switch_xml_find_child(profiles, "profile", "name", profile_name);
-    }
-
-    if (!xml_cfg.profile) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find profile: %s\n", profile_name);
-        switch_xml_free(cxml);
-        cxml = NULL;
-        goto done;
-    }
-
-    xml_cfg.controls = switch_xml_child(cfg, "caller-controls");
-
-    /* if this is a bridging call, and it's not a duplicate, build a */
-    /* conference object, and skip pin handling, and locked checking */
-    if (isbr) {
-        char *uuid = switch_core_session_get_uuid(session);
-
-        if (!strcmp(conf_name, "_uuid_")) {
-            conf_name = uuid;
-        }
-
-        if ((conference = (conference_obj_t *) switch_core_hash_find(globals.conference_hash, conf_name))) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Conference %s already exists!\n", conf_name);
-            goto done;
-        }
-
-        /* Create the conference object. */
-        conference = conference_new(conf_name, xml_cfg, NULL);
-
-        if (!conference) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
-            goto done;
-        }
-
-        /* Set the minimum number of members (once you go above it you cannot go below it) */
-        conference->min = 2;
-
-        /* if the dialplan specified a pin, override the profile's value */
-        if (dpin) {
-            conference->pin = switch_core_strdup(conference->pool, dpin);
-        }
-
-        /* Indicate the conference is dynamic */
-        switch_set_flag_locked(conference, CFLAG_DYNAMIC);	
-
-        /* Start the conference thread for this conference */
-        launch_conference_thread(conference);
-
-    } else {
-        /* if the conference exists, get the pointer to it */
-        if (!(conference = (conference_obj_t *) switch_core_hash_find(globals.conference_hash, conf_name))) {
-            /* couldn't find the conference, create one */
-            conference = conference_new(conf_name, xml_cfg, NULL);
-
-            if (!conference) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
-                goto done;
-            }
-
-            /* if the dialplan specified a pin, override the profile's value */
-            if (dpin) {
-                conference->pin = switch_core_strdup(conference->pool, dpin);
-            }
-
-            /* Set the minimum number of members (once you go above it you cannot go below it) */
-            conference->min = 1;
-
-            /* Indicate the conference is dynamic */
-            switch_set_flag_locked(conference, CFLAG_DYNAMIC);
-
-            /* Start the conference thread for this conference */
-            launch_conference_thread(conference);
-        }
-
-        /* acquire a read lock on the thread so it can't leave without us */
-        if (switch_thread_rwlock_tryrdlock(conference->rwlock) != SWITCH_STATUS_SUCCESS) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Read Lock Fail\n");
-            goto done;
-        }
-        rl++;
-        
-        /* if this is not an outbound call, deal with conference pins */
-        if (!switch_channel_test_flag(channel, CF_OUTBOUND) && conference->pin) {
-            char pin_buf[80] = "";
-            int  pin_retries = 3;	/* XXX - this should be configurable - i'm too lazy to do it right now... */
-            int  pin_valid = 0;
-            switch_status_t status = SWITCH_STATUS_SUCCESS;
-
-            /* Answer the channel */
-            switch_channel_answer(channel);
-
-            while(!pin_valid && pin_retries && status == SWITCH_STATUS_SUCCESS) {
-
-                /* be friendly */
-                if (conference->pin_sound) {
-                    conference_local_play_file(conference, session, conference->pin_sound, 20, pin_buf, sizeof(pin_buf));
-                } 
-                /* wait for them if neccessary */
-                if (strlen(pin_buf) < strlen(conference->pin)) {
-                    char *buf = pin_buf + strlen(pin_buf);
-                    char term = '\0';
-
-                    status = switch_ivr_collect_digits_count(session, 
-                                                             buf, 
-                                                             sizeof(pin_buf) - (unsigned int)strlen(pin_buf), 
-                                                             (unsigned int)strlen(conference->pin) - (unsigned int)strlen(pin_buf), 
-                                                             "#", &term, 10000);
-                }
-
-                pin_valid = (status == SWITCH_STATUS_SUCCESS && strcmp(pin_buf, conference->pin) == 0);
-                if (!pin_valid) {
-                    /* zero the collected pin */
-                    memset(pin_buf, 0, sizeof(pin_buf));
-
-                    /* more friendliness */
-                    if (conference->bad_pin_sound) {
-                        conference_local_play_file(conference, session, conference->bad_pin_sound, 20, pin_buf, sizeof(pin_buf));
-                    }
-                }
-                pin_retries --;
-            }
-
-            if (!pin_valid) {
-                goto done;
-            }
-        }
-
-        /* don't allow more callers if the conference is locked, unless we invited them */
-        if (switch_test_flag(conference, CFLAG_LOCKED) && !switch_channel_test_flag(channel, CF_OUTBOUND)) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Conference %s is locked.\n", conf_name);
-            if (conference->locked_sound) {
-                /* Answer the channel */
-                switch_channel_answer(channel);
-                conference_local_play_file(conference, session, conference->locked_sound, 20, NULL, 0);
-            }
-            goto done;
-        }
-
-        /* dont allow more callers than the max_members allows for -- I explicitly didnt allow outbound calls
-         * someone else can add that (see above) if they feel that outbound calls should be able to violate the
-         * max_members limit -- TRX
-         */
-        if((conference->max_members > 0) && (conference->count >= conference->max_members)) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Conference %s is full.\n",conf_name);
-            if(conference->maxmember_sound) {
-                /* Answer the channel */
-                switch_channel_answer(channel);
-                conference_local_play_file(conference, session, conference->maxmember_sound, 20, NULL, 0);
-            }
-            goto done;
-        }
-
-    }
-
-    /* Release the config registry handle */
-    if (cxml) {
-        switch_xml_free(cxml);
-        cxml = NULL;
-    }
-
-    /* if we're using "bridge:" make an outbound call and bridge it in */
-    if (!switch_strlen_zero(bridgeto) && strcasecmp(bridgeto, "none")) {
-        switch_call_cause_t cause;
-        if (conference_outcall(conference, NULL, session, bridgeto, 60, NULL, NULL, NULL, &cause) != SWITCH_STATUS_SUCCESS) {
-            goto done;
-        }
-    } else {	
-        /* if we're not using "bridge:" set the conference answered flag */
-        /* and this isn't an outbound channel, answer the call */
-        if (!switch_channel_test_flag(channel, CF_OUTBOUND)) 
-            switch_set_flag(conference, CFLAG_ANSWERED);
-    }
-
-    /* Save the original read codec. */
-    read_codec = switch_core_session_get_read_codec(session);
-    member.native_rate = read_codec->implementation->samples_per_second;
-    member.pool = switch_core_session_get_pool(session);
-
-    /* Setup a Signed Linear codec for reading audio. */
-    if (switch_core_codec_init(&member.read_codec, 
-                               "L16", 
-                               NULL, 
-                               read_codec->implementation->samples_per_second, 
-                               read_codec->implementation->microseconds_per_frame / 1000, 
-                               1, 
-                               SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, 
-                               NULL, 
-                               member.pool) == SWITCH_STATUS_SUCCESS) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activation Success L16@%uhz 1 channel %dms\n", 
-                          read_codec->implementation->samples_per_second,
-						  read_codec->implementation->microseconds_per_frame / 1000);
-    } else {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activation Failed L16@%uhz 1 channel %dms\n", 
-						  read_codec->implementation->samples_per_second,
-						  read_codec->implementation->microseconds_per_frame / 1000);
-        flags = 0;
-        goto done;
-    }
-
-    if (read_codec->implementation->samples_per_second != conference->rate) {
-        switch_audio_resampler_t **resampler = read_codec->implementation->samples_per_second > conference->rate ? 
-            &member.read_resampler : &member.mux_resampler;
-
-        if (switch_resample_create(resampler, 
-                               read_codec->implementation->samples_per_second, 
-                               read_codec->implementation->samples_per_second * 20, 
-                               conference->rate, 
-                               conference->rate * 20, 
-							   member.pool) != SWITCH_STATUS_SUCCESS){
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unable to crete resampler!\n");
-            goto done;
-		}
-
-        /* Setup an audio buffer for the resampled audio */
-        if (switch_buffer_create_dynamic(&member.resample_buffer, CONF_DBLOCK_SIZE, CONF_DBUFFER_SIZE, CONF_DBUFFER_MAX) != SWITCH_STATUS_SUCCESS) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error Creating Audio Buffer!\n");
-            goto done;
-        }
-    }
-    /* Setup a Signed Linear codec for writing audio. */
-    if (switch_core_codec_init(&member.write_codec, 
-                               "L16", 
-                               NULL, 
-                               read_codec->implementation->samples_per_second, 
-                               read_codec->implementation->microseconds_per_frame / 1000, 
-                               1, 
-                               SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, 
-                               NULL, 
-                               member.pool) == SWITCH_STATUS_SUCCESS) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activation Success L16@%uhz 1 channel %dms\n", 
-						  read_codec->implementation->samples_per_second,
-						  read_codec->implementation->microseconds_per_frame / 1000);
-    } else {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activation Failed L16@%uhz 1 channel %dms\n", 
-						  read_codec->implementation->samples_per_second,
-						  read_codec->implementation->microseconds_per_frame / 1000);
-        flags = 0;
-        goto codec_done2;
-    }
-
-    /* Setup an audio buffer for the incoming audio */
-    if (switch_buffer_create_dynamic(&member.audio_buffer, CONF_DBLOCK_SIZE, CONF_DBUFFER_SIZE, CONF_DBUFFER_MAX) != SWITCH_STATUS_SUCCESS) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error Creating Audio Buffer!\n");
-        goto codec_done1;
-    }
-
-    /* Setup an audio buffer for the outgoing audio */
-    if (switch_buffer_create_dynamic(&member.mux_buffer, CONF_DBLOCK_SIZE, CONF_DBUFFER_SIZE, CONF_DBUFFER_MAX) != SWITCH_STATUS_SUCCESS) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error Creating Audio Buffer!\n");
-        goto codec_done1;
-    }
-
-    /* Prepare MUTEXS */
-    member.id = next_member_id();
-    member.session = session;
-    switch_mutex_init(&member.flag_mutex, SWITCH_MUTEX_NESTED, member.pool);
-    switch_mutex_init(&member.audio_in_mutex, SWITCH_MUTEX_NESTED, member.pool);
-    switch_mutex_init(&member.audio_out_mutex, SWITCH_MUTEX_NESTED, member.pool);
-
-    /* Install our Signed Linear codec so we get the audio in that format */
-    switch_core_session_set_read_codec(member.session, &member.read_codec);
-
-    if ((flags_str = strstr(mydata, flags_prefix))) {
-        char *p;
-
-        *flags_str = '\0';
-        flags_str += strlen(flags_prefix);
-        if ((p = strchr(flags_str, '}'))) {
-            *p = '\0';
-        }
-    }
-	
-	mflags = conference->mflags;
-	set_mflags(flags_str, &mflags);
-    switch_set_flag_locked((&member), MFLAG_RUNNING | mflags);
-	
-    /* Add the caller to the conference */
-    if (conference_add_member(conference, &member) != SWITCH_STATUS_SUCCESS) {
-        goto codec_done1;
-    }
-
-    msg.from = __FILE__;
-
-    /* Tell the channel we are going to be in a bridge */
-    msg.message_id = SWITCH_MESSAGE_INDICATE_BRIDGE;
-    switch_core_session_receive_message(session, &msg);
-
-    /* Run the confernece loop */
-    conference_loop_output(&member);
-
-    /* Tell the channel we are no longer going to be in a bridge */
-    msg.message_id = SWITCH_MESSAGE_INDICATE_UNBRIDGE;
-    switch_core_session_receive_message(session, &msg);
-
-    /* Remove the caller from the conference */
-    conference_del_member(member.conference, &member);
-
-    /* Put the original codec back */
-    switch_core_session_set_read_codec(member.session, read_codec);
-
-    /* Clean Up.  codec_done(X): is for error situations after the codecs were setup and done: is for situations before */
- codec_done1:
-    switch_core_codec_destroy(&member.read_codec);
- codec_done2:
-    switch_core_codec_destroy(&member.write_codec);
- done:
-    switch_safe_free(params);
-    switch_buffer_destroy(&member.resample_buffer);
-    switch_buffer_destroy(&member.audio_buffer);
-    switch_buffer_destroy(&member.mux_buffer);
-
-    /* Release the config registry handle */
-    if (cxml) {
-        switch_xml_free(cxml);
-    }
+	/* Release the config registry handle */
+	if (cxml) {
+		switch_xml_free(cxml);
+	}
 
-    if (switch_test_flag(&member, MFLAG_KICKED) && conference->kicked_sound) {
+	if (switch_test_flag(&member, MFLAG_KICKED) && conference->kicked_sound) {
 		char *toplay = NULL;
 		char *dfile = NULL;
 
-        if (conference->sound_prefix) {
-            assert((dfile = switch_mprintf("%s/%s", conference->sound_prefix, conference->kicked_sound)));
+		if (conference->sound_prefix) {
+			assert((dfile = switch_mprintf("%s/%s", conference->sound_prefix, conference->kicked_sound)));
 			toplay = dfile;
 		} else {
 			toplay = conference->kicked_sound;
@@ -4196,720 +4107,719 @@
 
 		switch_ivr_play_file(session, NULL, toplay, NULL);
 		switch_safe_free(dfile);
-    }
+	}
 
-    switch_core_session_reset(session);
+	switch_core_session_reset(session);
 
-    /* release the readlock */
-    if (rl) {
-        switch_thread_rwlock_unlock(conference->rwlock);
-    }
+	/* release the readlock */
+	if (rl) {
+		switch_thread_rwlock_unlock(conference->rwlock);
+	}
 }
 
 /* Create a thread for the conference and launch it */
-static void launch_conference_thread(conference_obj_t *conference)
+static void launch_conference_thread(conference_obj_t * conference)
+{
+	switch_thread_t *thread;
+	switch_threadattr_t *thd_attr = NULL;
+
+	switch_set_flag_locked(conference, CFLAG_RUNNING);
+	switch_threadattr_create(&thd_attr, conference->pool);
+	switch_threadattr_detach_set(thd_attr, 1);
+	switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
+	switch_mutex_lock(globals.hash_mutex);
+	switch_core_hash_insert(globals.conference_hash, conference->name, conference);
+	switch_mutex_unlock(globals.hash_mutex);
+	switch_thread_create(&thread, thd_attr, conference_thread_run, conference, conference->pool);
+}
+
+static void launch_conference_record_thread(conference_obj_t * conference, char *path)
 {
-    switch_thread_t *thread;
-    switch_threadattr_t *thd_attr = NULL;
+	switch_thread_t *thread;
+	switch_threadattr_t *thd_attr = NULL;
+	switch_memory_pool_t *pool;
+	conference_record_t *rec;
+
+	/* Setup a memory pool to use. */
+	if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Pool Failure\n");
+	}
+
+	/* Create a node object */
+	if (!(rec = switch_core_alloc(pool, sizeof(*rec)))) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Alloc Failure\n");
+		switch_core_destroy_memory_pool(&pool);
+	}
 
-    switch_set_flag_locked(conference, CFLAG_RUNNING);
-    switch_threadattr_create(&thd_attr, conference->pool);
-    switch_threadattr_detach_set(thd_attr, 1);
-    switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
-    switch_mutex_lock(globals.hash_mutex);
-    switch_core_hash_insert(globals.conference_hash, conference->name, conference);
-    switch_mutex_unlock(globals.hash_mutex);
-    switch_thread_create(&thread, thd_attr, conference_thread_run, conference, conference->pool);
-}
-
-static void launch_conference_record_thread(conference_obj_t *conference, char *path)
-{
-    switch_thread_t *thread;
-    switch_threadattr_t *thd_attr = NULL;
-    switch_memory_pool_t *pool;
-    conference_record_t *rec;
-
-    /* Setup a memory pool to use. */
-    if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Pool Failure\n");
-    }
-
-    /* Create a node object*/
-    if (!(rec = switch_core_alloc(pool, sizeof(*rec)))) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Alloc Failure\n");
-        switch_core_destroy_memory_pool(&pool);
-    }
-
-    rec->conference = conference;
-    rec->path = switch_core_strdup(pool, path);
-    rec->pool = pool;
-
-    switch_threadattr_create(&thd_attr, rec->pool);
-    switch_threadattr_detach_set(thd_attr, 1);
-    switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
-    switch_thread_create(&thread, thd_attr, conference_record_thread_run, rec, rec->pool);
+	rec->conference = conference;
+	rec->path = switch_core_strdup(pool, path);
+	rec->pool = pool;
+
+	switch_threadattr_create(&thd_attr, rec->pool);
+	switch_threadattr_detach_set(thd_attr, 1);
+	switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
+	switch_thread_create(&thread, thd_attr, conference_record_thread_run, rec, rec->pool);
 }
 
 static const switch_application_interface_t conference_application_interface = {
-    /*.interface_name */ global_app_name, 
-    /*.application_function */ conference_function, 
-    NULL, NULL, NULL, 
+	/*.interface_name */ global_app_name,
+	/*.application_function */ conference_function,
+	NULL, NULL, NULL,
 	/* flags */ SAF_NONE,
-    /*.next*/ NULL
+	/*.next */ NULL
 };
 
 static switch_api_interface_t conf_api_interface = {
-    /*.interface_name */	"conference", 
-    /*.desc */				"Conference module commands", 
-    /*.function */			conf_api_main, 
-    /*.syntax */		/* see switch_module_load, this is built on the fly */
-    /*.next */ 
+	/*.interface_name */ "conference",
+	/*.desc */ "Conference module commands",
+	/*.function */ conf_api_main,
+	/*.syntax *//* see switch_module_load, this is built on the fly */
+	/*.next */
 };
 
 static switch_status_t chat_send(char *proto, char *from, char *to, char *subject, char *body, char *hint)
 {
-    char name[512] = "", *p, *lbuf = NULL;
-    switch_chat_interface_t *ci;
-    conference_obj_t *conference = NULL;
-    switch_stream_handle_t stream = {0};
-
-    if ((p = strchr(to, '+'))) {
-        to = ++p;
-    }
-
-    if (!body) {
-        return SWITCH_STATUS_SUCCESS;
-    }
-
-    if (!(ci = switch_loadable_module_get_chat_interface(proto))) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Chat Interface [%s]!\n", proto);
-    }
-
-
-    if ((p = strchr(to, '@'))) {
-        switch_copy_string(name, to, ++p-to);
-    } else {
-        switch_copy_string(name, to, sizeof(name));
-    }
-
-    if (!(conference = (conference_obj_t *) switch_core_hash_find(globals.conference_hash, name))) {
-        ci->chat_send(CONF_CHAT_PROTO, to, hint && strchr(hint, '/') ? hint : from, "", "Conference not active.", NULL);
-        return SWITCH_STATUS_FALSE;
-    }
-
-    SWITCH_STANDARD_STREAM(stream);
-
-    if (body != NULL && (lbuf = strdup(body))) {
-        int argc;
-        char *argv[25];
-
-        memset(argv, 0, sizeof(argv));
-        argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
-
-        /* try to find a command to execute */
-        if (argc) {
-            /* special case list */
-            if (strcasecmp(argv[0], "list") == 0) {
-                conference_list_pretty(conference, &stream);
-                /* provide help */
-            } 
+	char name[512] = "", *p, *lbuf = NULL;
+	switch_chat_interface_t *ci;
+	conference_obj_t *conference = NULL;
+	switch_stream_handle_t stream = { 0 };
+
+	if ((p = strchr(to, '+'))) {
+		to = ++p;
+	}
+
+	if (!body) {
+		return SWITCH_STATUS_SUCCESS;
+	}
+
+	if (!(ci = switch_loadable_module_get_chat_interface(proto))) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Chat Interface [%s]!\n", proto);
+	}
+
+
+	if ((p = strchr(to, '@'))) {
+		switch_copy_string(name, to, ++p - to);
+	} else {
+		switch_copy_string(name, to, sizeof(name));
+	}
+
+	if (!(conference = (conference_obj_t *) switch_core_hash_find(globals.conference_hash, name))) {
+		ci->chat_send(CONF_CHAT_PROTO, to, hint && strchr(hint, '/') ? hint : from, "", "Conference not active.", NULL);
+		return SWITCH_STATUS_FALSE;
+	}
+
+	SWITCH_STANDARD_STREAM(stream);
+
+	if (body != NULL && (lbuf = strdup(body))) {
+		int argc;
+		char *argv[25];
+
+		memset(argv, 0, sizeof(argv));
+		argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
+
+		/* try to find a command to execute */
+		if (argc) {
+			/* special case list */
+			if (strcasecmp(argv[0], "list") == 0) {
+				conference_list_pretty(conference, &stream);
+				/* provide help */
+			}
 #if 0
-            else {
-                if (strcasecmp(argv[0], "help") == 0 || strcasecmp(argv[0], "commands") == 0) {
-                    stream.write_function(&stream, "%s\n", conf_api_interface.syntax);
-                    /* find a normal command */
-                } else {
-                    conf_api_dispatch(conference, &stream, argc, argv, (const char *)body, 0);
-                }
-            }
+			else {
+				if (strcasecmp(argv[0], "help") == 0 || strcasecmp(argv[0], "commands") == 0) {
+					stream.write_function(&stream, "%s\n", conf_api_interface.syntax);
+					/* find a normal command */
+				} else {
+					conf_api_dispatch(conference, &stream, argc, argv, (const char *) body, 0);
+				}
+			}
 #endif
-        } else {
-            stream.write_function(&stream, "No parameters specified.\nTry 'help'\n");
-        }
-    }
-    switch_safe_free(lbuf);
+		} else {
+			stream.write_function(&stream, "No parameters specified.\nTry 'help'\n");
+		}
+	}
+	switch_safe_free(lbuf);
 
-    ci->chat_send(CONF_CHAT_PROTO, to, from, "", stream.data, NULL);
-    switch_safe_free(stream.data);
+	ci->chat_send(CONF_CHAT_PROTO, to, from, "", stream.data, NULL);
+	switch_safe_free(stream.data);
 
-    return SWITCH_STATUS_SUCCESS;
+	return SWITCH_STATUS_SUCCESS;
 }
 
 static const switch_chat_interface_t conference_chat_interface = {
-    /*.name */ CONF_CHAT_PROTO, 
-    /*.chat_send */ chat_send, 
+	/*.name */ CONF_CHAT_PROTO,
+	/*.chat_send */ chat_send,
 
 };
 
 static switch_loadable_module_interface_t conference_module_interface = {
-    /*.module_name */ modname, 
-    /*.endpoint_interface */ NULL, 
-    /*.timer_interface */ NULL, 
-    /*.dialplan_interface */ NULL, 
-    /*.codec_interface */ NULL, 
-    /*.application_interface */ &conference_application_interface, 
-    /*.api_interface */ &conf_api_interface, 
-    /*.file_interface */ NULL, 
-    /*.speech_interface */ NULL, 
-    /*.directory_interface */ NULL, 
-    /*.chat_interface */ &conference_chat_interface
+	/*.module_name */ modname,
+	/*.endpoint_interface */ NULL,
+	/*.timer_interface */ NULL,
+	/*.dialplan_interface */ NULL,
+	/*.codec_interface */ NULL,
+	/*.application_interface */ &conference_application_interface,
+	/*.api_interface */ &conf_api_interface,
+	/*.file_interface */ NULL,
+	/*.speech_interface */ NULL,
+	/*.directory_interface */ NULL,
+	/*.chat_interface */ &conference_chat_interface
 };
 
-static switch_status_t conf_default_controls(conference_obj_t *conference)
+static switch_status_t conf_default_controls(conference_obj_t * conference)
+{
+	switch_status_t status = SWITCH_STATUS_FALSE;
+	uint32_t i;
+	caller_control_action_t *action;
+
+	assert(conference != NULL);
+
+	for (i = 0, status = SWITCH_STATUS_SUCCESS; status == SWITCH_STATUS_SUCCESS && i < CCFNTBL_QTY; i++) {
+		if (!switch_strlen_zero(ccfntbl[i].digits)) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
+							  "Installing default caller control action '%s' bound to '%s'.\n", ccfntbl[i].key, ccfntbl[i].digits);
+			action = (caller_control_action_t *) switch_core_alloc(conference->pool, sizeof(caller_control_action_t));
+			if (action != NULL) {
+				action->fndesc = &ccfntbl[i];
+				action->data = NULL;
+				status = switch_ivr_digit_stream_parser_set_event(conference->dtmf_parser, ccfntbl[i].digits, action);
+			} else {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
+								  "unable to alloc memory for caller control binding '%s' to '%s'\n", ccfntbl[i].key, ccfntbl[i].digits);
+				status = SWITCH_STATUS_MEMERR;
+			}
+		}
+	}
+
+
+	return status;
+}
+
+static switch_status_t conference_new_install_caller_controls_custom(conference_obj_t * conference, switch_xml_t xml_controls, switch_xml_t xml_menus)
 {
-    switch_status_t status = SWITCH_STATUS_FALSE;
-    uint32_t i;
-    caller_control_action_t *action;
-
-    assert(conference != NULL);
-
-    for(i = 0, status = SWITCH_STATUS_SUCCESS; status == SWITCH_STATUS_SUCCESS && i<CCFNTBL_QTY; i++) {
-        if (!switch_strlen_zero(ccfntbl[i].digits)) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Installing default caller control action '%s' bound to '%s'.\n", 
-                              ccfntbl[i].key, 
-                              ccfntbl[i].digits);
-            action = (caller_control_action_t *)switch_core_alloc(conference->pool, sizeof(caller_control_action_t));
-            if (action != NULL) {
-                action->fndesc = &ccfntbl[i];
-                action->data = NULL;
-                status = switch_ivr_digit_stream_parser_set_event(conference->dtmf_parser, ccfntbl[i].digits, action);
-            } else {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "unable to alloc memory for caller control binding '%s' to '%s'\n", 
-                                  ccfntbl[i].key, ccfntbl[i].digits);
-                status = SWITCH_STATUS_MEMERR;
-            }
-        }
-    }
-	
-
-    return status;
-}
-
-static switch_status_t conference_new_install_caller_controls_custom(conference_obj_t *conference, switch_xml_t xml_controls, switch_xml_t xml_menus)
-{
-    switch_status_t status = SWITCH_STATUS_FALSE;
-    switch_xml_t xml_kvp;
-
-    assert(conference != NULL);
-    assert(xml_controls != NULL);
-
-    /* parse the controls tree for caller control digit strings */
-    for (xml_kvp = switch_xml_child(xml_controls, "control"); xml_kvp; xml_kvp = xml_kvp->next) {
-        char *key = (char *) switch_xml_attr(xml_kvp, "action");
-        char *val = (char *) switch_xml_attr(xml_kvp, "digits");
-        char *data = (char *)switch_xml_attr_soft(xml_kvp, "data");
-
-        if (!switch_strlen_zero(key) && !switch_strlen_zero(val)) {
-            uint32_t i;
-
-            /* scan through all of the valid actions, and if found, */
-            /* set the new caller control action digit string, then */
-            /* stop scanning the table, and go to the next xml kvp. */
-            for(i = 0, status = SWITCH_STATUS_NOOP; i<CCFNTBL_QTY && status == SWITCH_STATUS_NOOP; i++) {
+	switch_status_t status = SWITCH_STATUS_FALSE;
+	switch_xml_t xml_kvp;
+
+	assert(conference != NULL);
+	assert(xml_controls != NULL);
+
+	/* parse the controls tree for caller control digit strings */
+	for (xml_kvp = switch_xml_child(xml_controls, "control"); xml_kvp; xml_kvp = xml_kvp->next) {
+		char *key = (char *) switch_xml_attr(xml_kvp, "action");
+		char *val = (char *) switch_xml_attr(xml_kvp, "digits");
+		char *data = (char *) switch_xml_attr_soft(xml_kvp, "data");
+
+		if (!switch_strlen_zero(key) && !switch_strlen_zero(val)) {
+			uint32_t i;
+
+			/* scan through all of the valid actions, and if found, */
+			/* set the new caller control action digit string, then */
+			/* stop scanning the table, and go to the next xml kvp. */
+			for (i = 0, status = SWITCH_STATUS_NOOP; i < CCFNTBL_QTY && status == SWITCH_STATUS_NOOP; i++) {
+
+				if (strcasecmp(ccfntbl[i].key, key) == 0) {
 
-                if (strcasecmp(ccfntbl[i].key, key) == 0) {
-					
 					caller_control_action_t *action;
 
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Installing caller control action '%s' bound to '%s'.\n", key, val);
-					action = (caller_control_action_t *)switch_core_alloc(conference->pool, sizeof(caller_control_action_t));
+					action = (caller_control_action_t *) switch_core_alloc(conference->pool, sizeof(caller_control_action_t));
 					if (action != NULL) {
 						action->fndesc = &ccfntbl[i];
-						action->data = (void *)switch_core_strdup(conference->pool, data);
+						action->data = (void *) switch_core_strdup(conference->pool, data);
 						action->binded_dtmf = switch_core_strdup(conference->pool, val);
 						status = switch_ivr_digit_stream_parser_set_event(conference->dtmf_parser, val, action);
 					} else {
-						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "unable to alloc memory for caller control binding '%s' to '%s'\n", ccfntbl[i].key, ccfntbl[i].digits);
+						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
+										  "unable to alloc memory for caller control binding '%s' to '%s'\n", ccfntbl[i].key, ccfntbl[i].digits);
 						status = SWITCH_STATUS_MEMERR;
 					}
 				}
 			}
-            if (status == SWITCH_STATUS_NOOP) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid caller control action name '%s'.\n", key);
-            }
-        } else {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid caller control config entry pair action = '%s' digits = '%s'\n", key, val);
-        }
-    }
+			if (status == SWITCH_STATUS_NOOP) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid caller control action name '%s'.\n", key);
+			}
+		} else {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid caller control config entry pair action = '%s' digits = '%s'\n", key, val);
+		}
+	}
 
-    return status;
+	return status;
 }
 
 /* create a new conferene with a specific profile */
 static conference_obj_t *conference_new(char *name, conf_xml_cfg_t cfg, switch_memory_pool_t *pool)
 {
-    conference_obj_t *conference;
-    switch_xml_t xml_kvp;
-    char *rate_name = NULL;
-    char *interval_name = NULL;
-    char *timer_name = NULL;
-    char *domain = NULL;
-    char *tts_engine = NULL;
-    char *tts_voice = NULL;
-    char *enter_sound = NULL;
-    char *sound_prefix = NULL;
-    char *exit_sound = NULL;
-    char *alone_sound = NULL;
-    char *ack_sound = NULL;
-    char *nack_sound = NULL;
-    char *muted_sound = NULL;
-    char *unmuted_sound = NULL;
-    char *locked_sound = NULL;
-    char *is_locked_sound = NULL;
-    char *is_unlocked_sound = NULL;
-    char *kicked_sound = NULL;
-    char *pin = NULL;
-    char *pin_sound = NULL; 
-    char *bad_pin_sound = NULL;
-    char *energy_level = NULL;
-    char *caller_id_name = NULL;
-    char *caller_id_number = NULL;
-    char *caller_controls = NULL;
+	conference_obj_t *conference;
+	switch_xml_t xml_kvp;
+	char *rate_name = NULL;
+	char *interval_name = NULL;
+	char *timer_name = NULL;
+	char *domain = NULL;
+	char *tts_engine = NULL;
+	char *tts_voice = NULL;
+	char *enter_sound = NULL;
+	char *sound_prefix = NULL;
+	char *exit_sound = NULL;
+	char *alone_sound = NULL;
+	char *ack_sound = NULL;
+	char *nack_sound = NULL;
+	char *muted_sound = NULL;
+	char *unmuted_sound = NULL;
+	char *locked_sound = NULL;
+	char *is_locked_sound = NULL;
+	char *is_unlocked_sound = NULL;
+	char *kicked_sound = NULL;
+	char *pin = NULL;
+	char *pin_sound = NULL;
+	char *bad_pin_sound = NULL;
+	char *energy_level = NULL;
+	char *caller_id_name = NULL;
+	char *caller_id_number = NULL;
+	char *caller_controls = NULL;
 	char *member_flags = NULL;
-    uint32_t max_members = 0;
-    uint32_t anounce_count = 0;
-    char *maxmember_sound = NULL;
-    uint32_t rate = 8000, interval = 20;
-    switch_status_t status;
-
-    /* Validate the conference name */
-    if (switch_strlen_zero(name)) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Record! no name.\n");
-        return NULL;
-    }
-
-    /* parse the profile tree for param values */
-    for (xml_kvp = switch_xml_child(cfg.profile, "param"); xml_kvp; xml_kvp = xml_kvp->next) {
-        char *var = (char *) switch_xml_attr_soft(xml_kvp, "name");
-        char *val = (char *) switch_xml_attr_soft(xml_kvp, "value");
-        char buf[128] = "";
-        char *p;
-
-        if ((p = strchr(var, '_'))) {
-            switch_copy_string(buf, var, sizeof(buf));
-            for(p = buf; *p; p++) {
-                if (*p == '_') {
-                    *p = '-';
-                }
-            }
-            var = buf;
-        }
-
-        if (!strcasecmp(var, "rate")) {
-            rate_name = val;
-        } else if (!strcasecmp(var, "domain")) {
-            domain = val;
-        } else if (!strcasecmp(var, "interval")) {
-            interval_name = val;
-        } else if (!strcasecmp(var, "timer-name")) {
-            timer_name = val;
-        } else if (!strcasecmp(var, "tts-engine")) {
-            tts_engine = val;
-        } else if (!strcasecmp(var, "tts-voice")) {
-            tts_voice = val;
-        } else if (!strcasecmp(var, "enter-sound")) {
-            enter_sound = val;
-        } else if (!strcasecmp(var, "exit-sound")) {
-            exit_sound = val;
-        } else if (!strcasecmp(var, "alone-sound")) {
-            alone_sound = val;
-        } else if (!strcasecmp(var, "ack-sound")) {
-            ack_sound = val;
-        } else if (!strcasecmp(var, "nack-sound")) {
-            nack_sound = val;
-        } else if (!strcasecmp(var, "muted-sound")) {
-            muted_sound = val;
-        } else if (!strcasecmp(var, "unmuted-sound")) {
-            unmuted_sound = val;
-        } else if (!strcasecmp(var, "locked-sound")) {
-            locked_sound = val;
-        } else if (!strcasecmp(var, "is-locked-sound")) {
-            is_locked_sound = val;
-        } else if (!strcasecmp(var, "is-unlocked-sound")) {
-            is_unlocked_sound = val;
-        } else if (!strcasecmp(var, "member-flags")) {
+	uint32_t max_members = 0;
+	uint32_t anounce_count = 0;
+	char *maxmember_sound = NULL;
+	uint32_t rate = 8000, interval = 20;
+	switch_status_t status;
+
+	/* Validate the conference name */
+	if (switch_strlen_zero(name)) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Record! no name.\n");
+		return NULL;
+	}
+
+	/* parse the profile tree for param values */
+	for (xml_kvp = switch_xml_child(cfg.profile, "param"); xml_kvp; xml_kvp = xml_kvp->next) {
+		char *var = (char *) switch_xml_attr_soft(xml_kvp, "name");
+		char *val = (char *) switch_xml_attr_soft(xml_kvp, "value");
+		char buf[128] = "";
+		char *p;
+
+		if ((p = strchr(var, '_'))) {
+			switch_copy_string(buf, var, sizeof(buf));
+			for (p = buf; *p; p++) {
+				if (*p == '_') {
+					*p = '-';
+				}
+			}
+			var = buf;
+		}
+
+		if (!strcasecmp(var, "rate")) {
+			rate_name = val;
+		} else if (!strcasecmp(var, "domain")) {
+			domain = val;
+		} else if (!strcasecmp(var, "interval")) {
+			interval_name = val;
+		} else if (!strcasecmp(var, "timer-name")) {
+			timer_name = val;
+		} else if (!strcasecmp(var, "tts-engine")) {
+			tts_engine = val;
+		} else if (!strcasecmp(var, "tts-voice")) {
+			tts_voice = val;
+		} else if (!strcasecmp(var, "enter-sound")) {
+			enter_sound = val;
+		} else if (!strcasecmp(var, "exit-sound")) {
+			exit_sound = val;
+		} else if (!strcasecmp(var, "alone-sound")) {
+			alone_sound = val;
+		} else if (!strcasecmp(var, "ack-sound")) {
+			ack_sound = val;
+		} else if (!strcasecmp(var, "nack-sound")) {
+			nack_sound = val;
+		} else if (!strcasecmp(var, "muted-sound")) {
+			muted_sound = val;
+		} else if (!strcasecmp(var, "unmuted-sound")) {
+			unmuted_sound = val;
+		} else if (!strcasecmp(var, "locked-sound")) {
+			locked_sound = val;
+		} else if (!strcasecmp(var, "is-locked-sound")) {
+			is_locked_sound = val;
+		} else if (!strcasecmp(var, "is-unlocked-sound")) {
+			is_unlocked_sound = val;
+		} else if (!strcasecmp(var, "member-flags")) {
 			member_flags = val;
-        } else if (!strcasecmp(var, "kicked-sound")) {
-            kicked_sound = val;
-        } else if (!strcasecmp(var, "pin")) {
-            pin = val;
-        } else if (!strcasecmp(var, "pin-sound")) {
-            pin_sound = val;
-        } else if (!strcasecmp(var, "bad-pin-sound")) {
-            bad_pin_sound = val;
-        } else if (!strcasecmp(var, "energy-level")) {
-            energy_level = val;
-        } else if (!strcasecmp(var, "caller-id-name")) {
-            caller_id_name = val;
-        } else if (!strcasecmp(var, "caller-id-number")) {
-            caller_id_number = val;
-        } else if (!strcasecmp(var, "caller-controls")) {
-            caller_controls = val;
-        } else if (!strcasecmp(var, "sound-prefix")) {
-            sound_prefix = val;
-        } else if (!strcasecmp(var, "max-members")) {
-            errno = 0; // sanity first
-            max_members = strtol(val,NULL,0); // base 0 lets 0x... for hex 0... for octal and base 10 otherwise through
-            if(errno == ERANGE || errno == EINVAL || max_members < 0 || max_members == 1) {
-                // a negative wont work well, and its foolish to have a conference limited to 1 person unless the outbound 
-                // stuff is added, see comments above
-                max_members = 0; // set to 0 to disable max counts
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "max-members %s is invalid, not setting a limit\n",val);
-            }
-        } else if(!strcasecmp(var, "max-members-sound")) {
-            maxmember_sound = val;
-        } else if(!strcasecmp(var, "anounce-count")) {
-            errno = 0; // safety first
-            anounce_count = strtol(val,NULL,0);
-            if(errno == ERANGE || errno == EINVAL) {
-                anounce_count = 0;
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "anounce-count is invalid, not anouncing member counts\n");
-            }
-        }
-    }
-
-    /* Set defaults and various paramaters */
-
-    /* Speed in hertz */
-    if (!switch_strlen_zero(rate_name)) {
-        uint32_t r = atoi(rate_name);
-        if (r) {
-            rate = r;
-        }
-    }
-
-    /* Packet Interval in milliseconds */
-    if (!switch_strlen_zero(interval_name)) {
-        uint32_t i = atoi(interval_name);
-        if (i) {
-            interval = i;
-        }
-    }
-
-    /* Timer module to use */
-    if (switch_strlen_zero(timer_name)) {
-        timer_name = "soft";
-    }
-
-    /* Caller ID Name */
-    if (switch_strlen_zero(caller_id_name)) {
-        caller_id_name = (char *) global_app_name;
-    }
-
-    /* Caller ID Number */
-    if (switch_strlen_zero(caller_id_number)) {
-        caller_id_number = "0000000000";
-    }
-
-    if (!pool) {
-        /* Setup a memory pool to use. */
-        if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Pool Failure\n");
-            status = SWITCH_STATUS_TERM;
-            return NULL;
-        }
-    }
-
-    /* Create the conference object. */
-    if (!(conference = switch_core_alloc(pool, sizeof(*conference)))) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
-        status = SWITCH_STATUS_TERM;
-        return NULL;
-    }
-
-    /* initialize the conference object with settings from the specified profile */
-    conference->pool = pool;
-    conference->timer_name = switch_core_strdup(conference->pool, timer_name);
-    conference->tts_engine = switch_core_strdup(conference->pool, tts_engine);
-    conference->tts_voice = switch_core_strdup(conference->pool, tts_voice);
+		} else if (!strcasecmp(var, "kicked-sound")) {
+			kicked_sound = val;
+		} else if (!strcasecmp(var, "pin")) {
+			pin = val;
+		} else if (!strcasecmp(var, "pin-sound")) {
+			pin_sound = val;
+		} else if (!strcasecmp(var, "bad-pin-sound")) {
+			bad_pin_sound = val;
+		} else if (!strcasecmp(var, "energy-level")) {
+			energy_level = val;
+		} else if (!strcasecmp(var, "caller-id-name")) {
+			caller_id_name = val;
+		} else if (!strcasecmp(var, "caller-id-number")) {
+			caller_id_number = val;
+		} else if (!strcasecmp(var, "caller-controls")) {
+			caller_controls = val;
+		} else if (!strcasecmp(var, "sound-prefix")) {
+			sound_prefix = val;
+		} else if (!strcasecmp(var, "max-members")) {
+			errno = 0;			// sanity first
+			max_members = strtol(val, NULL, 0);	// base 0 lets 0x... for hex 0... for octal and base 10 otherwise through
+			if (errno == ERANGE || errno == EINVAL || max_members < 0 || max_members == 1) {
+				// a negative wont work well, and its foolish to have a conference limited to 1 person unless the outbound 
+				// stuff is added, see comments above
+				max_members = 0;	// set to 0 to disable max counts
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "max-members %s is invalid, not setting a limit\n", val);
+			}
+		} else if (!strcasecmp(var, "max-members-sound")) {
+			maxmember_sound = val;
+		} else if (!strcasecmp(var, "anounce-count")) {
+			errno = 0;			// safety first
+			anounce_count = strtol(val, NULL, 0);
+			if (errno == ERANGE || errno == EINVAL) {
+				anounce_count = 0;
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "anounce-count is invalid, not anouncing member counts\n");
+			}
+		}
+	}
+
+	/* Set defaults and various paramaters */
+
+	/* Speed in hertz */
+	if (!switch_strlen_zero(rate_name)) {
+		uint32_t r = atoi(rate_name);
+		if (r) {
+			rate = r;
+		}
+	}
+
+	/* Packet Interval in milliseconds */
+	if (!switch_strlen_zero(interval_name)) {
+		uint32_t i = atoi(interval_name);
+		if (i) {
+			interval = i;
+		}
+	}
+
+	/* Timer module to use */
+	if (switch_strlen_zero(timer_name)) {
+		timer_name = "soft";
+	}
+
+	/* Caller ID Name */
+	if (switch_strlen_zero(caller_id_name)) {
+		caller_id_name = (char *) global_app_name;
+	}
+
+	/* Caller ID Number */
+	if (switch_strlen_zero(caller_id_number)) {
+		caller_id_number = "0000000000";
+	}
+
+	if (!pool) {
+		/* Setup a memory pool to use. */
+		if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Pool Failure\n");
+			status = SWITCH_STATUS_TERM;
+			return NULL;
+		}
+	}
+
+	/* Create the conference object. */
+	if (!(conference = switch_core_alloc(pool, sizeof(*conference)))) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
+		status = SWITCH_STATUS_TERM;
+		return NULL;
+	}
+
+	/* initialize the conference object with settings from the specified profile */
+	conference->pool = pool;
+	conference->timer_name = switch_core_strdup(conference->pool, timer_name);
+	conference->tts_engine = switch_core_strdup(conference->pool, tts_engine);
+	conference->tts_voice = switch_core_strdup(conference->pool, tts_voice);
 
-    conference->caller_id_name = switch_core_strdup(conference->pool, caller_id_name);
-    conference->caller_id_number = switch_core_strdup(conference->pool, caller_id_number);
+	conference->caller_id_name = switch_core_strdup(conference->pool, caller_id_name);
+	conference->caller_id_number = switch_core_strdup(conference->pool, caller_id_number);
 
 	conference->mflags = MFLAG_CAN_SPEAK | MFLAG_CAN_HEAR;
 
 	if (member_flags) {
 		set_mflags(member_flags, &conference->mflags);
-	} 
+	}
+
+	if (sound_prefix) {
+		conference->sound_prefix = switch_core_strdup(conference->pool, sound_prefix);
+	}
+
+	if (!switch_strlen_zero(enter_sound)) {
+		conference->enter_sound = switch_core_strdup(conference->pool, enter_sound);
+	}
+
+	if (!switch_strlen_zero(exit_sound)) {
+		conference->exit_sound = switch_core_strdup(conference->pool, exit_sound);
+	}
+
+	if (!switch_strlen_zero(ack_sound)) {
+		conference->ack_sound = switch_core_strdup(conference->pool, ack_sound);
+	}
+
+	if (!switch_strlen_zero(nack_sound)) {
+		conference->nack_sound = switch_core_strdup(conference->pool, nack_sound);
+	}
+
+	if (!switch_strlen_zero(muted_sound)) {
+		conference->muted_sound = switch_core_strdup(conference->pool, muted_sound);
+	}
+
+	if (!switch_strlen_zero(unmuted_sound)) {
+		conference->unmuted_sound = switch_core_strdup(conference->pool, unmuted_sound);
+	}
+
+	if (!switch_strlen_zero(kicked_sound)) {
+		conference->kicked_sound = switch_core_strdup(conference->pool, kicked_sound);
+	}
+
+	if (!switch_strlen_zero(pin_sound)) {
+		conference->pin_sound = switch_core_strdup(conference->pool, pin_sound);
+	}
+
+	if (!switch_strlen_zero(bad_pin_sound)) {
+		conference->bad_pin_sound = switch_core_strdup(conference->pool, bad_pin_sound);
+	}
+
+	if (!switch_strlen_zero(pin)) {
+		conference->pin = switch_core_strdup(conference->pool, pin);
+	}
+
+	if (!switch_strlen_zero(alone_sound)) {
+		conference->alone_sound = switch_core_strdup(conference->pool, alone_sound);
+	}
+
+	if (!switch_strlen_zero(locked_sound)) {
+		conference->locked_sound = switch_core_strdup(conference->pool, locked_sound);
+	}
+
+	if (!switch_strlen_zero(is_locked_sound)) {
+		conference->is_locked_sound = switch_core_strdup(conference->pool, is_locked_sound);
+	}
+
+	if (!switch_strlen_zero(is_unlocked_sound)) {
+		conference->is_unlocked_sound = switch_core_strdup(conference->pool, is_unlocked_sound);
+	}
+
+	if (!switch_strlen_zero(energy_level)) {
+		conference->energy_level = atoi(energy_level);
+	}
+
+	if (!switch_strlen_zero(maxmember_sound)) {
+		conference->maxmember_sound = switch_core_strdup(conference->pool, maxmember_sound);
+	}
+	// its going to be 0 by default, set to a value otherwise so this should be safe
+	conference->max_members = max_members;
+	conference->anounce_count = anounce_count;
+
+	conference->name = switch_core_strdup(conference->pool, name);
+	if (domain) {
+		conference->domain = switch_core_strdup(conference->pool, domain);
+	} else {
+		conference->domain = "cluecon.com";
+	}
+	conference->rate = rate;
+	conference->interval = interval;
+	conference->dtmf_parser = NULL;
+
+	/* caller control configuration chores */
+	if (switch_ivr_digit_stream_parser_new(conference->pool, &conference->dtmf_parser) == SWITCH_STATUS_SUCCESS) {
+
+		/* if no controls, or default controls specified, install default */
+		if (caller_controls == NULL || *caller_controls == '\0' || strcasecmp(caller_controls, "default") == 0) {
+			status = conf_default_controls(conference);
+		} else if (strcasecmp(caller_controls, "none") != 0) {
+			/* try to build caller control if the group has been specified and != "none" */
+			switch_xml_t xml_controls = switch_xml_find_child(cfg.controls, "group", "name", caller_controls);
+			status = conference_new_install_caller_controls_custom(conference, xml_controls, NULL);
 
-    if (sound_prefix) {
-        conference->sound_prefix = switch_core_strdup(conference->pool, sound_prefix);
-    }
-
-    if (!switch_strlen_zero(enter_sound)) {
-        conference->enter_sound = switch_core_strdup(conference->pool, enter_sound);
-    }
-
-    if (!switch_strlen_zero(exit_sound)) {
-        conference->exit_sound = switch_core_strdup(conference->pool, exit_sound);
-    }
-
-    if (!switch_strlen_zero(ack_sound)) {
-        conference->ack_sound = switch_core_strdup(conference->pool, ack_sound);
-    }
-
-    if (!switch_strlen_zero(nack_sound)) {
-        conference->nack_sound = switch_core_strdup(conference->pool, nack_sound);
-    }
-
-    if (!switch_strlen_zero(muted_sound)) {
-        conference->muted_sound = switch_core_strdup(conference->pool, muted_sound);
-    }
-
-    if (!switch_strlen_zero(unmuted_sound)) {
-        conference->unmuted_sound = switch_core_strdup(conference->pool, unmuted_sound);
-    }
-
-    if (!switch_strlen_zero(kicked_sound)) {
-        conference->kicked_sound = switch_core_strdup(conference->pool, kicked_sound);
-    }
-
-    if (!switch_strlen_zero(pin_sound)) {
-        conference->pin_sound = switch_core_strdup(conference->pool, pin_sound);
-    }
-
-    if (!switch_strlen_zero(bad_pin_sound)) {
-        conference->bad_pin_sound = switch_core_strdup(conference->pool, bad_pin_sound);
-    }
-
-    if (!switch_strlen_zero(pin)) {
-        conference->pin = switch_core_strdup(conference->pool, pin);
-    }
-
-    if (!switch_strlen_zero(alone_sound)) {
-        conference->alone_sound = switch_core_strdup(conference->pool, alone_sound);
-    } 
-
-    if (!switch_strlen_zero(locked_sound)) {
-        conference->locked_sound = switch_core_strdup(conference->pool, locked_sound);
-    }
-
-    if (!switch_strlen_zero(is_locked_sound)) {
-        conference->is_locked_sound = switch_core_strdup(conference->pool, is_locked_sound);
-    }
-
-    if (!switch_strlen_zero(is_unlocked_sound)) {
-        conference->is_unlocked_sound = switch_core_strdup(conference->pool, is_unlocked_sound);
-    }
-
-    if (!switch_strlen_zero(energy_level)) {
-        conference->energy_level = atoi(energy_level);
-    }
-
-    if (!switch_strlen_zero(maxmember_sound)) {
-        conference->maxmember_sound = switch_core_strdup(conference->pool, maxmember_sound);
-    }
-
-    // its going to be 0 by default, set to a value otherwise so this should be safe
-    conference->max_members = max_members;
-    conference->anounce_count = anounce_count;
-
-    conference->name = switch_core_strdup(conference->pool, name);
-    if (domain) {
-        conference->domain = switch_core_strdup(conference->pool, domain);
-    } else {
-        conference->domain = "cluecon.com";
-    }
-    conference->rate = rate;
-    conference->interval = interval;
-    conference->dtmf_parser = NULL;
-
-    /* caller control configuration chores */
-    if (switch_ivr_digit_stream_parser_new(conference->pool, &conference->dtmf_parser) == SWITCH_STATUS_SUCCESS) {
-
-        /* if no controls, or default controls specified, install default */
-        if (caller_controls == NULL || *caller_controls == '\0' || strcasecmp(caller_controls, "default") == 0) {
-            status = conf_default_controls(conference);
-        } else if (strcasecmp(caller_controls, "none") != 0) {
-            /* try to build caller control if the group has been specified and != "none" */
-            switch_xml_t xml_controls = switch_xml_find_child(cfg.controls, "group", "name", caller_controls);
-            status = conference_new_install_caller_controls_custom(conference, xml_controls, NULL);
-
-            if (status != SWITCH_STATUS_SUCCESS) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to install caller controls group '%s'\n", caller_controls);
-            }
-        } else {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "no caller controls intalled.\n");
-        }
-    } else {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to allocate caller control digit parser.\n");
-    }
-
-    /* Activate the conference mutex for exclusivity */
-    switch_mutex_init(&conference->mutex, SWITCH_MUTEX_NESTED, conference->pool);
-    switch_mutex_init(&conference->flag_mutex, SWITCH_MUTEX_NESTED, conference->pool);
-    switch_thread_rwlock_create(&conference->rwlock, conference->pool);
+			if (status != SWITCH_STATUS_SUCCESS) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to install caller controls group '%s'\n", caller_controls);
+			}
+		} else {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "no caller controls intalled.\n");
+		}
+	} else {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to allocate caller control digit parser.\n");
+	}
+
+	/* Activate the conference mutex for exclusivity */
+	switch_mutex_init(&conference->mutex, SWITCH_MUTEX_NESTED, conference->pool);
+	switch_mutex_init(&conference->flag_mutex, SWITCH_MUTEX_NESTED, conference->pool);
+	switch_thread_rwlock_create(&conference->rwlock, conference->pool);
 	switch_mutex_init(&conference->member_mutex, SWITCH_MUTEX_NESTED, conference->pool);
 
-    return conference;
+	return conference;
+}
+
+static void pres_event_handler(switch_event_t *event)
+{
+	char *to = switch_event_get_header(event, "to");
+	char *dup_to = NULL, *conf_name, *e;
+	conference_obj_t *conference;
+
+	if (!to || strncasecmp(to, "conf+", 5)) {
+		return;
+	}
+
+	if (!(dup_to = strdup(to))) {
+		return;
+	}
+
+	conf_name = dup_to + 5;
+
+	if ((e = strchr(conf_name, '@'))) {
+		*e = '\0';
+	}
+
+	if ((conference = (conference_obj_t *) switch_core_hash_find(globals.conference_hash, conf_name))) {
+		switch_event_t *event;
+
+		if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "proto", CONF_CHAT_PROTO);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "login", "%s", conference->name);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", conference->name, conference->domain);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "status", "Active (%d caller%s)", conference->count, conference->count == 1 ? "" : "s");
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_type", "presence");
+			switch_event_fire(&event);
+		}
+	} else if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
+		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "proto", CONF_CHAT_PROTO);
+		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "login", "%s", conf_name);
+		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s", to);
+		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "status", "Idle");
+		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "rpid", "idle");
+		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_type", "presence");
+		switch_event_fire(&event);
+	}
+
+	switch_safe_free(dup_to);
 }
 
-static void pres_event_handler(switch_event_t *event) 
-{ 
-    char *to = switch_event_get_header(event, "to"); 
-    char *dup_to = NULL, *conf_name, *e; 
-    conference_obj_t *conference; 
-
-    if (!to || strncasecmp(to, "conf+", 5)) { 
-        return; 
-    } 
-
-    if (!(dup_to = strdup(to))) { 
-        return; 
-    } 
-
-    conf_name = dup_to + 5; 
-
-    if ((e = strchr(conf_name, '@'))) { 
-        *e = '\0'; 
-    } 
-
-    if ((conference = (conference_obj_t *) switch_core_hash_find(globals.conference_hash, conf_name))) { 
-        switch_event_t *event; 
-
-        if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) { 
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "proto", CONF_CHAT_PROTO); 
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "login", "%s", conference->name); 
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", conference->name, conference->domain); 
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "status", "Active (%d caller%s)", conference->count, conference->count == 1 ? "" : "s"); 
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_type", "presence"); 
-            switch_event_fire(&event); 
-        } 
-    } else if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) { 
-        switch_event_add_header(event, SWITCH_STACK_BOTTOM, "proto", CONF_CHAT_PROTO); 
-        switch_event_add_header(event, SWITCH_STACK_BOTTOM, "login", "%s", conf_name); 
-        switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s", to); 
-        switch_event_add_header(event, SWITCH_STACK_BOTTOM, "status", "Idle"); 
-        switch_event_add_header(event, SWITCH_STACK_BOTTOM, "rpid", "idle"); 
-        switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_type", "presence"); 
-        switch_event_fire(&event); 
-    } 
-
-    switch_safe_free(dup_to); 
-} 
- 
-static void send_presence(switch_event_types_t id) 
-{ 
-    switch_xml_t cxml, cfg, advertise, room; 
-
-    /* Open the config from the xml registry */ 
-    if (!(cxml = switch_xml_open_cfg(global_cf_name, &cfg, "presence"))) { 
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", global_cf_name); 
-        goto done; 
-    } 
-
-    if ((advertise = switch_xml_child(cfg, "advertise"))) { 
-        for (room = switch_xml_child(advertise, "room"); room; room = room->next) { 
-            char *name = (char *) switch_xml_attr_soft(room, "name"); 
-            char *status = (char *) switch_xml_attr_soft(room, "status"); 
-            switch_event_t *event; 
-
-            if (name && switch_event_create(&event, id) == SWITCH_STATUS_SUCCESS) { 
-                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "proto", CONF_CHAT_PROTO); 
-                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "login", "%s", name); 
-                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s", name); 
-                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "status", "%s", status ? status : "Available"); 
-                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "rpid", "idle"); 
-                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_type", "presence"); 
-                switch_event_fire(&event); 
-            } 
-        } 
-    } 
-
- done: 
-    /* Release the config registry handle */ 
-    if (cxml) { 
-        switch_xml_free(cxml); 
-        cxml = NULL; 
-    } 
-} 
+static void send_presence(switch_event_types_t id)
+{
+	switch_xml_t cxml, cfg, advertise, room;
+
+	/* Open the config from the xml registry */
+	if (!(cxml = switch_xml_open_cfg(global_cf_name, &cfg, "presence"))) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", global_cf_name);
+		goto done;
+	}
+
+	if ((advertise = switch_xml_child(cfg, "advertise"))) {
+		for (room = switch_xml_child(advertise, "room"); room; room = room->next) {
+			char *name = (char *) switch_xml_attr_soft(room, "name");
+			char *status = (char *) switch_xml_attr_soft(room, "status");
+			switch_event_t *event;
+
+			if (name && switch_event_create(&event, id) == SWITCH_STATUS_SUCCESS) {
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "proto", CONF_CHAT_PROTO);
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "login", "%s", name);
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s", name);
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "status", "%s", status ? status : "Available");
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "rpid", "idle");
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_type", "presence");
+				switch_event_fire(&event);
+			}
+		}
+	}
+
+  done:
+	/* Release the config registry handle */
+	if (cxml) {
+		switch_xml_free(cxml);
+		cxml = NULL;
+	}
+}
 
 /* Called by FreeSWITCH when the module loads */
 SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
 {
-    uint32_t i;
-    size_t nl, ol = 0;
-    char *p = NULL;
-    switch_status_t status = SWITCH_STATUS_SUCCESS;
-
-    memset(&globals, 0, sizeof(globals));
-
-    /* build api interface help ".syntax" field string */
-    p = strdup("");
-    for (i = 0; i<CONFFUNCAPISIZE; i++) {
-        nl = strlen(conf_api_sub_commands[i].psyntax) + 4;
-        if (p != NULL) {
-            ol = strlen(p);
-        }
-        p = realloc(p, ol+nl);
-        if (p != NULL) {
-            strcat(p, "\t\t");
-            strcat(p, conf_api_sub_commands[i].psyntax);
-            if (i < CONFFUNCAPISIZE-1) {
-                strcat(p, "\n");
-            }
-        }
-		
-    }
-    /* install api interface help ".syntax" field string */
-    if (p != NULL) {
-        conf_api_interface.syntax = p;
-    }
-
-    /* Connect my internal structure to the blank pointer passed to me */
-    *module_interface = &conference_module_interface;
-
-    /* create/register custom event message type */
-    if (switch_event_reserve_subclass(CONF_EVENT_MAINT) != SWITCH_STATUS_SUCCESS) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't register subclass %s!", CONF_EVENT_MAINT);
-        return SWITCH_STATUS_TERM;
-    }
-
-    /* Setup the pool */
-    if (switch_core_new_memory_pool(&globals.conference_pool) != SWITCH_STATUS_SUCCESS) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "OH OH no conference pool\n");
-        return SWITCH_STATUS_TERM;
-    }
-
-    /* Setup a hash to store conferences by name */
-    switch_core_hash_init(&globals.conference_hash, globals.conference_pool);
-    switch_mutex_init(&globals.conference_mutex, SWITCH_MUTEX_NESTED, globals.conference_pool);
-    switch_mutex_init(&globals.id_mutex, SWITCH_MUTEX_NESTED, globals.conference_pool);
-    switch_mutex_init(&globals.hash_mutex, SWITCH_MUTEX_NESTED, globals.conference_pool);
-
-    /* Subscribe to presence request events */
-    if (switch_event_bind((char *) modname, SWITCH_EVENT_PRESENCE_PROBE, SWITCH_EVENT_SUBCLASS_ANY, pres_event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't subscribe to presence request events!\n");
-        return SWITCH_STATUS_GENERR;
-    }
-
-    send_presence(SWITCH_EVENT_PRESENCE_IN);
-
-    globals.running = 1;
-    /* indicate that the module should continue to be loaded */
-    return status;
+	uint32_t i;
+	size_t nl, ol = 0;
+	char *p = NULL;
+	switch_status_t status = SWITCH_STATUS_SUCCESS;
+
+	memset(&globals, 0, sizeof(globals));
+
+	/* build api interface help ".syntax" field string */
+	p = strdup("");
+	for (i = 0; i < CONFFUNCAPISIZE; i++) {
+		nl = strlen(conf_api_sub_commands[i].psyntax) + 4;
+		if (p != NULL) {
+			ol = strlen(p);
+		}
+		p = realloc(p, ol + nl);
+		if (p != NULL) {
+			strcat(p, "\t\t");
+			strcat(p, conf_api_sub_commands[i].psyntax);
+			if (i < CONFFUNCAPISIZE - 1) {
+				strcat(p, "\n");
+			}
+		}
+
+	}
+	/* install api interface help ".syntax" field string */
+	if (p != NULL) {
+		conf_api_interface.syntax = p;
+	}
+
+	/* Connect my internal structure to the blank pointer passed to me */
+	*module_interface = &conference_module_interface;
+
+	/* create/register custom event message type */
+	if (switch_event_reserve_subclass(CONF_EVENT_MAINT) != SWITCH_STATUS_SUCCESS) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't register subclass %s!", CONF_EVENT_MAINT);
+		return SWITCH_STATUS_TERM;
+	}
+
+	/* Setup the pool */
+	if (switch_core_new_memory_pool(&globals.conference_pool) != SWITCH_STATUS_SUCCESS) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "OH OH no conference pool\n");
+		return SWITCH_STATUS_TERM;
+	}
+
+	/* Setup a hash to store conferences by name */
+	switch_core_hash_init(&globals.conference_hash, globals.conference_pool);
+	switch_mutex_init(&globals.conference_mutex, SWITCH_MUTEX_NESTED, globals.conference_pool);
+	switch_mutex_init(&globals.id_mutex, SWITCH_MUTEX_NESTED, globals.conference_pool);
+	switch_mutex_init(&globals.hash_mutex, SWITCH_MUTEX_NESTED, globals.conference_pool);
+
+	/* Subscribe to presence request events */
+	if (switch_event_bind((char *) modname, SWITCH_EVENT_PRESENCE_PROBE, SWITCH_EVENT_SUBCLASS_ANY, pres_event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't subscribe to presence request events!\n");
+		return SWITCH_STATUS_GENERR;
+	}
+
+	send_presence(SWITCH_EVENT_PRESENCE_IN);
+
+	globals.running = 1;
+	/* indicate that the module should continue to be loaded */
+	return status;
 }
 
 SWITCH_MOD_DECLARE(switch_status_t) switch_module_shutdown(void)
 {
-    if (globals.running) {
+	if (globals.running) {
 
-        /* signal all threads to shutdown */
-        globals.running = 0;
+		/* signal all threads to shutdown */
+		globals.running = 0;
 
-        /* wait for all threads */
-        while (globals.threads) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Waiting for %d threads\n", globals.threads);
-            switch_yield(100000);
-        }
-
-        /* free api interface help ".syntax" field string */
-        if (conf_api_interface.syntax != NULL) {
-            free((char *)conf_api_interface.syntax);
-        }
-    }
+		/* wait for all threads */
+		while (globals.threads) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Waiting for %d threads\n", globals.threads);
+			switch_yield(100000);
+		}
+
+		/* free api interface help ".syntax" field string */
+		if (conf_api_interface.syntax != NULL) {
+			free((char *) conf_api_interface.syntax);
+		}
+	}
 
-    return SWITCH_STATUS_SUCCESS;
+	return SWITCH_STATUS_SUCCESS;
 }
 
 /* For Emacs:

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_dptools/mod_dptools.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_dptools/mod_dptools.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_dptools/mod_dptools.c	Fri Mar 30 12:19:18 2007
@@ -43,7 +43,8 @@
 	int argc;
 	char *lbuf = NULL;
 
-	if (data && (lbuf = switch_core_session_strdup(session, data)) && (argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
+	if (data && (lbuf = switch_core_session_strdup(session, data))
+		&& (argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
 		if (!strcasecmp(argv[0], "grammar") && argc >= 1) {
 			switch_ivr_detect_speech_load_grammar(session, argv[1], argv[2]);
 		} else if (!strcasecmp(argv[0], "nogrammar")) {
@@ -60,14 +61,14 @@
 	} else {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Usage: %s\n", detect_speech_application_interface.syntax);
 	}
-	
+
 }
 
 static void ring_ready_function(switch_core_session_t *session, char *data)
 {
 	switch_channel_t *channel;
 	channel = switch_core_session_get_channel(session);
-    assert(channel != NULL);
+	assert(channel != NULL);
 	switch_channel_ring_ready(channel);
 }
 
@@ -84,7 +85,7 @@
 static void transfer_function(switch_core_session_t *session, char *data)
 {
 	int argc;
-	char *argv[4] = {0};
+	char *argv[4] = { 0 };
 	char *mydata;
 
 	if (data && (mydata = switch_core_session_strdup(session, data))) {
@@ -99,15 +100,15 @@
 static void sched_transfer_function(switch_core_session_t *session, char *data)
 {
 	int argc;
-	char *argv[4] = {0};
+	char *argv[4] = { 0 };
 	char *mydata;
-	
+
 	if (data && (mydata = switch_core_session_strdup(session, data))) {
 		if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) >= 2) {
 			time_t when;
 
 			if (*argv[0] == '+') {
-				when = time (NULL) + atol(argv[0] + 1);
+				when = time(NULL) + atol(argv[0] + 1);
 			} else {
 				when = atol(argv[0]);
 			}
@@ -122,7 +123,7 @@
 static void sched_hangup_function(switch_core_session_t *session, char *data)
 {
 	int argc;
-	char *argv[5] = {0};
+	char *argv[5] = { 0 };
 	char *mydata;
 
 	if (data && (mydata = switch_core_session_strdup(session, data))) {
@@ -132,11 +133,11 @@
 			switch_bool_t bleg = SWITCH_FALSE;
 
 			if (*argv[0] == '+') {
-				when = time (NULL) + atol(argv[0] + 1);
+				when = time(NULL) + atol(argv[0] + 1);
 			} else {
 				when = atol(argv[0]);
 			}
-			
+
 			if (argv[1]) {
 				cause = switch_channel_str2cause(argv[1]);
 			}
@@ -156,20 +157,20 @@
 static void sched_broadcast_function(switch_core_session_t *session, char *data)
 {
 	int argc;
-	char *argv[6] = {0};
+	char *argv[6] = { 0 };
 	char *mydata;
 
 	if (data && (mydata = switch_core_session_strdup(session, data))) {
 		if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) >= 2) {
 			time_t when;
 			switch_media_flag_t flags = SMF_NONE;
-			
+
 			if (*argv[0] == '+') {
-				when = time (NULL) + atol(argv[0] + 1);
+				when = time(NULL) + atol(argv[0] + 1);
 			} else {
 				when = atol(argv[0]);
 			}
-			
+
 			if (argv[2]) {
 				if (!strcmp(argv[2], "both")) {
 					flags |= (SMF_ECHO_ALEG | SMF_ECHO_BLEG);
@@ -207,26 +208,26 @@
 
 static void phrase_function(switch_core_session_t *session, char *data)
 {
-    switch_channel_t *channel;
-    char *mydata = NULL;
+	switch_channel_t *channel;
+	char *mydata = NULL;
+
+	channel = switch_core_session_get_channel(session);
+	assert(channel != NULL);
+
+	if ((mydata = switch_core_session_strdup(session, data))) {
+		char *lang;
+		char *macro = mydata;
+		char *mdata = NULL;
+
+		if ((mdata = strchr(macro, ','))) {
+			*mdata++ = '\0';
+		}
 
-    channel = switch_core_session_get_channel(session);
-    assert(channel != NULL);
-    
-    if ((mydata = switch_core_session_strdup(session, data))) {
-        char *lang;
-        char *macro = mydata;
-        char *mdata = NULL;
-
-        if ((mdata = strchr(macro, ','))) {
-            *mdata++ = '\0';
-        }
-
-        lang = switch_channel_get_variable(channel, "language");
-        
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Execute %s(%s) lang %s\n", macro, mdata, lang);
-        switch_ivr_phrase_macro(session, macro, mdata, lang, NULL);
-    }
+		lang = switch_channel_get_variable(channel, "language");
+
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Execute %s(%s) lang %s\n", macro, mdata, lang);
+		switch_ivr_phrase_macro(session, macro, mdata, lang, NULL);
+	}
 
 }
 
@@ -234,14 +235,14 @@
 static void hangup_function(switch_core_session_t *session, char *data)
 {
 	switch_channel_t *channel;
-    switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING;
+	switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING;
 
 	channel = switch_core_session_get_channel(session);
-    assert(channel != NULL);
+	assert(channel != NULL);
 
-    if (!switch_strlen_zero((char *) data)) {
-        cause = switch_channel_str2cause((char *) data);
-    }
+	if (!switch_strlen_zero((char *) data)) {
+		cause = switch_channel_str2cause((char *) data);
+	}
 
 	switch_channel_hangup(channel, cause);
 }
@@ -251,7 +252,7 @@
 	switch_channel_t *channel;
 	channel = switch_core_session_get_channel(session);
 
-    assert(channel != NULL);
+	assert(channel != NULL);
 	switch_channel_answer(channel);
 }
 
@@ -260,18 +261,18 @@
 	switch_channel_t *channel;
 	channel = switch_core_session_get_channel(session);
 
-    assert(channel != NULL);
+	assert(channel != NULL);
 	switch_channel_pre_answer(channel);
 }
 
 static void redirect_function(switch_core_session_t *session, char *data)
 {
-    switch_core_session_message_t msg = {0};
+	switch_core_session_message_t msg = { 0 };
 
-    /* Tell the channel to redirect */
+	/* Tell the channel to redirect */
 	msg.from = __FILE__;
 	msg.string_arg = data;
-    msg.message_id = SWITCH_MESSAGE_INDICATE_REDIRECT;
+	msg.message_id = SWITCH_MESSAGE_INDICATE_REDIRECT;
 	switch_core_session_receive_message(session, &msg);
 
 }
@@ -283,7 +284,7 @@
 	char *var, *val = NULL;
 
 	channel = switch_core_session_get_channel(session);
-    assert(channel != NULL);
+	assert(channel != NULL);
 
 	if (switch_strlen_zero(data)) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No variable name specified.\n");
@@ -293,11 +294,11 @@
 
 		if (val) {
 			*val++ = '\0';
-            if (switch_strlen_zero(val)) {
-                val = NULL;
-            }
+			if (switch_strlen_zero(val)) {
+				val = NULL;
+			}
 		}
-		
+
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SET [%s]=[%s]\n", var, val ? val : "UNDEF");
 		switch_channel_set_variable(channel, var, val);
 	}
@@ -309,7 +310,7 @@
 	char *exports, *new_exports = NULL, *new_exports_d = NULL, *var, *val = NULL;
 
 	channel = switch_core_session_get_channel(session);
-    assert(channel != NULL);
+	assert(channel != NULL);
 
 	if (switch_strlen_zero(data)) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No variable name specified.\n");
@@ -320,11 +321,11 @@
 
 		if (val) {
 			*val++ = '\0';
-            if (switch_strlen_zero(val)) {
-                val = NULL;
-            }
+			if (switch_strlen_zero(val)) {
+				val = NULL;
+			}
 		}
-		
+
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "EXPORT [%s]=[%s]\n", var, val ? val : "UNDEF");
 		switch_channel_set_variable(channel, var, val);
 
@@ -346,7 +347,7 @@
 	switch_channel_t *channel;
 
 	channel = switch_core_session_get_channel(session);
-    assert(channel != NULL);
+	assert(channel != NULL);
 
 	if (switch_strlen_zero(data)) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No variable name specified.\n");
@@ -359,43 +360,43 @@
 static void log_function(switch_core_session_t *session, char *data)
 {
 	switch_channel_t *channel;
-    char *level, *log_str;
+	char *level, *log_str;
 
 	channel = switch_core_session_get_channel(session);
-    assert(channel != NULL);
+	assert(channel != NULL);
+
+	if (data && (level = strdup(data))) {
+		switch_event_types_t etype = SWITCH_LOG_DEBUG;
+
+		if ((log_str = strchr(level, ' '))) {
+			*log_str++ = '\0';
+			switch_name_event(level, &etype);
+		} else {
+			log_str = level;
+		}
 
-    if (data && (level = strdup(data))) {
-        switch_event_types_t etype = SWITCH_LOG_DEBUG;
-        
-        if ((log_str = strchr(level, ' '))) {
-            *log_str++ = '\0';
-            switch_name_event(level, &etype);
-        } else {
-            log_str = level;
-        }
-
-        switch_log_printf(SWITCH_CHANNEL_LOG, etype, "%s\n", log_str);
-        switch_safe_free(level);
-    }
+		switch_log_printf(SWITCH_CHANNEL_LOG, etype, "%s\n", log_str);
+		switch_safe_free(level);
+	}
 }
 
 
 static void info_function(switch_core_session_t *session, char *data)
 {
 	switch_channel_t *channel;
-    switch_event_t *event;
-    char *buf;
+	switch_event_t *event;
+	char *buf;
 
 	channel = switch_core_session_get_channel(session);
-    assert(channel != NULL);
+	assert(channel != NULL);
+
+	if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
+		switch_channel_event_set_data(channel, event);
+		switch_event_serialize(event, &buf);
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "CHANNEL_DATA:\n%s\n", buf);
+		switch_event_destroy(&event);
+	}
 
-    if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
-        switch_channel_event_set_data(channel, event);
-        switch_event_serialize(event, &buf);
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "CHANNEL_DATA:\n%s\n", buf);
-        switch_event_destroy(&event);
-    }
-    
 }
 
 static void privacy_function(switch_core_session_t *session, char *data)
@@ -405,8 +406,8 @@
 	char *arg;
 
 	channel = switch_core_session_get_channel(session);
-    	assert(channel != NULL);		
-	
+	assert(channel != NULL);
+
 	caller_profile = switch_channel_get_caller_profile(channel);
 
 	if (switch_strlen_zero(data)) {
@@ -416,7 +417,7 @@
 
 		switch_set_flag(caller_profile, SWITCH_CPF_SCREEN);
 
-		if(!strcasecmp(arg, "no")) {
+		if (!strcasecmp(arg, "no")) {
 			switch_clear_flag(caller_profile, SWITCH_CPF_HIDE_NAME);
 			switch_clear_flag(caller_profile, SWITCH_CPF_HIDE_NUMBER);
 		} else if (!strcasecmp(arg, "yes")) {
@@ -440,7 +441,8 @@
 	int argc;
 	char *lbuf;
 
-	if (data && (lbuf = switch_core_session_strdup(session, data)) && (argc = switch_separate_string(lbuf, '=', argv, (sizeof(argv) / sizeof(argv[0])))) > 1) {
+	if (data && (lbuf = switch_core_session_strdup(session, data))
+		&& (argc = switch_separate_string(lbuf, '=', argv, (sizeof(argv) / sizeof(argv[0])))) > 1) {
 		switch_size_t retsize;
 		switch_time_exp_t tm;
 		char date[80] = "";
@@ -459,26 +461,26 @@
 
 static switch_status_t strepoch_api_function(char *data, switch_core_session_t *session, switch_stream_handle_t *stream)
 {
-    switch_time_t out;
-    
-    if (switch_strlen_zero(data)) {
-        out = switch_time_now();
-    } else {
-        out = switch_str_time(data);
-    }
+	switch_time_t out;
 
-    stream->write_function(stream, "%d", (uint32_t)((out) / (int64_t)(1000000)) );
+	if (switch_strlen_zero(data)) {
+		out = switch_time_now();
+	} else {
+		out = switch_str_time(data);
+	}
+
+	stream->write_function(stream, "%d", (uint32_t) ((out) / (int64_t) (1000000)));
 
 	return SWITCH_STATUS_SUCCESS;
 }
 
 static switch_status_t strftime_api_function(char *fmt, switch_core_session_t *session, switch_stream_handle_t *stream)
 {
-	
+
 	switch_size_t retsize;
 	switch_time_exp_t tm;
 	char date[80] = "";
-	
+
 	switch_time_exp_lt(&tm, switch_time_now());
 	switch_strftime(date, &retsize, sizeof(date), fmt ? fmt : "%Y-%m-%d %T", &tm);
 	stream->write_function(stream, "%s", date);
@@ -493,14 +495,15 @@
 	int argc = 0;
 	switch_event_types_t type = SWITCH_EVENT_PRESENCE_IN;
 
-	if (fmt && (lbuf = strdup(fmt)) && (argc = switch_separate_string(lbuf, '|', argv, (sizeof(argv) / sizeof(argv[0])))) > 0) {
+	if (fmt && (lbuf = strdup(fmt))
+		&& (argc = switch_separate_string(lbuf, '|', argv, (sizeof(argv) / sizeof(argv[0])))) > 0) {
 		if (!strcasecmp(argv[0], "out")) {
 			type = SWITCH_EVENT_PRESENCE_OUT;
 		} else if (argc != 4) {
 			stream->write_function(stream, "Invalid");
 			return SWITCH_STATUS_SUCCESS;
 		}
-		
+
 		if (switch_event_create(&event, type) == SWITCH_STATUS_SUCCESS) {
 			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "proto", "dp");
 			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "login", "%s", __FILE__);
@@ -527,9 +530,10 @@
 	char *lbuf, *argv[4];
 	int argc = 0;
 
-	if (fmt && (lbuf = strdup(fmt)) && (argc = switch_separate_string(lbuf, '|', argv, (sizeof(argv) / sizeof(argv[0])))) == 4) {
+	if (fmt && (lbuf = strdup(fmt))
+		&& (argc = switch_separate_string(lbuf, '|', argv, (sizeof(argv) / sizeof(argv[0])))) == 4) {
 		switch_chat_interface_t *ci;
-		
+
 		if ((ci = switch_loadable_module_get_chat_interface(argv[0]))) {
 			ci->chat_send("dp", argv[1], argv[2], "", argv[3], "");
 			stream->write_function(stream, "Sent");
@@ -539,19 +543,19 @@
 	} else {
 		stream->write_function(stream, "Invalid");
 	}
-	
+
 	return SWITCH_STATUS_SUCCESS;
 }
 
 static char *ivr_cf_name = "ivr.conf";
 
 #ifdef _TEST_CALLBACK_
-static switch_ivr_action_t menu_handler(switch_ivr_menu_t *menu, char *param, char *buf, size_t buflen, void *obj)
+static switch_ivr_action_t menu_handler(switch_ivr_menu_t * menu, char *param, char *buf, size_t buflen, void *obj)
 {
 	switch_ivr_action_t action = SWITCH_IVR_ACTION_NOOP;
 
 	if (param != NULL) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "menu_handler '%s'\n",param);
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "menu_handler '%s'\n", param);
 	}
 
 	return action;
@@ -563,7 +567,7 @@
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 	char *params;
 
-	if (channel && data && (params = switch_core_session_strdup(session,data))) {
+	if (channel && data && (params = switch_core_session_strdup(session, data))) {
 		switch_xml_t cxml = NULL, cfg = NULL, xml_menus = NULL, xml_menu = NULL;
 
 		// Open the config from the xml registry
@@ -577,16 +581,15 @@
 					switch_ivr_menu_t *menu_stack = NULL;
 
 					// build a menu tree and execute it
-					if (switch_ivr_menu_stack_xml_init(&xml_ctx,NULL) == SWITCH_STATUS_SUCCESS
+					if (switch_ivr_menu_stack_xml_init(&xml_ctx, NULL) == SWITCH_STATUS_SUCCESS
 #ifdef _TEST_CALLBACK_
 						&& switch_ivr_menu_stack_xml_add_custom(xml_ctx, "custom", &menu_handler) == SWITCH_STATUS_SUCCESS
 #endif
-						&& switch_ivr_menu_stack_xml_build(xml_ctx,&menu_stack,xml_menus,xml_menu) == SWITCH_STATUS_SUCCESS)
-					{
+						&& switch_ivr_menu_stack_xml_build(xml_ctx, &menu_stack, xml_menus, xml_menu) == SWITCH_STATUS_SUCCESS) {
 						switch_xml_free(cxml);
 						cxml = NULL;
 						switch_channel_pre_answer(channel);
-						switch_ivr_menu_execute(session,menu_stack,params,NULL);
+						switch_ivr_menu_execute(session, menu_stack, params, NULL);
 						switch_ivr_menu_stack_free(menu_stack);
 					} else {
 						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to create menu '%s'\n", params);
@@ -670,7 +673,7 @@
 
 static const switch_application_interface_t queuedtmf_application_interface = {
 	/*.interface_name */ "queue_dtmf",
-	/*.application_function */ queue_dtmf_function,	
+	/*.application_function */ queue_dtmf_function,
 	/* long_desc */ "Queue dtmf to be sent from a session",
 	/* short_desc */ "Queue dtmf to be sent",
 	/* syntax */ "<dtmf_data>",
@@ -680,7 +683,7 @@
 
 static const switch_application_interface_t redirect_application_interface = {
 	/*.interface_name */ "redirect",
-	/*.application_function */ redirect_function,	
+	/*.application_function */ redirect_function,
 	/* long_desc */ "Send a redirect message to a session.",
 	/* short_desc */ "Send session redirect",
 	/* syntax */ "<redirect_data>",
@@ -690,7 +693,7 @@
 
 static const switch_application_interface_t ivr_application_interface = {
 	/*.interface_name */ "ivr",
-	/*.application_function */ ivr_application_function,	
+	/*.application_function */ ivr_application_function,
 	/* long_desc */ "Run an ivr menu.",
 	/* short_desc */ "Run an ivr menu",
 	/* syntax */ "<menu_name>",
@@ -700,7 +703,7 @@
 
 static const switch_application_interface_t detect_speech_application_interface = {
 	/*.interface_name */ "detect_speech",
-	/*.application_function */ detect_speech_function,	
+	/*.application_function */ detect_speech_function,
 	/* long_desc */ "Detect speech on a channel.",
 	/* short_desc */ "Detect speech",
 	/* syntax */ "<mod_name> <gram_name> <gram_path> [<addr>] OR grammar <gram_name> [<path>] OR pause OR resume",
@@ -777,7 +780,6 @@
 	/* syntax */ "[<cause>]",
 	/* flags */ SAF_SUPPORT_NOMEDIA,
 	/*.next */ &log_application_interface
-
 };
 
 static const switch_application_interface_t answer_application_interface = {
@@ -788,7 +790,6 @@
 	/* syntax */ "",
 	/* flags */ SAF_SUPPORT_NOMEDIA,
 	/*.next */ &hangup_application_interface
-
 };
 
 static const switch_application_interface_t pre_answer_application_interface = {
@@ -799,7 +800,6 @@
 	/* syntax */ "",
 	/* flags */ SAF_SUPPORT_NOMEDIA,
 	/*.next */ &answer_application_interface
-
 };
 
 static const switch_application_interface_t eval_application_interface = {
@@ -810,7 +810,6 @@
 	/* syntax */ "",
 	/* flags */ SAF_SUPPORT_NOMEDIA,
 	/*.next */ &pre_answer_application_interface
-
 };
 
 static const switch_application_interface_t phrase_application_interface = {
@@ -821,7 +820,6 @@
 	/* syntax */ "<macro_name>,<data>",
 	/* flags */ SAF_NONE,
 	/*.next */ &eval_application_interface
-
 };
 
 static const switch_application_interface_t strftime_application_interface = {
@@ -832,13 +830,13 @@
 	/* syntax */ NULL,
 	/* flags */ SAF_SUPPORT_NOMEDIA,
 	/*.next */ &phrase_application_interface
-
 };
 
 static const switch_application_interface_t sleep_application_interface = {
 	/*.interface_name */ "sleep",
 	/*.application_function */ sleep_function,
-	/* long_desc */ "Pause the channel for a given number of milliseconds, consuming the audio for that period of time.",
+	/* long_desc */
+	"Pause the channel for a given number of milliseconds, consuming the audio for that period of time.",
 	/* short_desc */ "Pause a channel",
 	/* syntax */ "<pausemilliseconds>",
 	/* flags */ SAF_NONE,

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_echo/mod_echo.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_echo/mod_echo.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_echo/mod_echo.c	Fri Mar 30 12:19:18 2007
@@ -38,7 +38,7 @@
 	switch_channel_t *channel;
 
 	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);	
+	assert(channel != NULL);
 
 	switch_channel_answer(channel);
 

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_enum/mod_enum.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_enum/mod_enum.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_enum/mod_enum.c	Fri Mar 30 12:19:18 2007
@@ -48,10 +48,10 @@
 typedef struct enum_record enum_record_t;
 
 struct query {
-	const char *name;		/* original query string */
+	const char *name;			/* original query string */
 	char *number;
 	unsigned char dn[DNS_MAXDN];
-	enum dns_type qtyp;		/* type of the query */
+	enum dns_type qtyp;			/* type of the query */
 	enum_record_t *results;
 };
 typedef struct query enum_query_t;
@@ -77,7 +77,7 @@
 SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_root, globals.root)
 
 
-static void add_route(char *service, char *regex, char *replace)
+	 static void add_route(char *service, char *regex, char *replace)
 {
 	enum_route_t *route, *rp;
 
@@ -86,11 +86,11 @@
 	}
 
 	memset(route, 0, sizeof(*route));
-	
+
 	route->service = strdup(service);
 	route->regex = strdup(regex);
 	route->replace = strdup(replace);
-	
+
 	if (!globals.route_order) {
 		globals.route_order = route;
 	} else {
@@ -107,8 +107,8 @@
 static switch_status_t load_config(void)
 {
 	char *cf = "enum.conf";
-    switch_xml_t cfg, xml = NULL, param, settings, route, routes;
-    switch_status_t status = SWITCH_STATUS_SUCCESS;
+	switch_xml_t cfg, xml = NULL, param, settings, route, routes;
+	switch_status_t status = SWITCH_STATUS_SUCCESS;
 
 	memset(&globals, 0, sizeof(globals));
 	if (switch_core_new_memory_pool(&globals.pool) != SWITCH_STATUS_SUCCESS) {
@@ -119,39 +119,39 @@
 
 	switch_core_hash_init(&globals.routes, globals.pool);
 
-    if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
-        status = SWITCH_STATUS_FALSE;
-        goto done;
-    }
-
-    if ((settings = switch_xml_child(cfg, "settings"))) {
-        for (param = switch_xml_child(settings, "param"); param; param = param->next) {
-            char *var = (char *) switch_xml_attr_soft(param, "name");
-            char *val = (char *) switch_xml_attr_soft(param, "value");
-            if (!strcasecmp(var, "default-root")) {
+	if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
+		status = SWITCH_STATUS_FALSE;
+		goto done;
+	}
+
+	if ((settings = switch_xml_child(cfg, "settings"))) {
+		for (param = switch_xml_child(settings, "param"); param; param = param->next) {
+			char *var = (char *) switch_xml_attr_soft(param, "name");
+			char *val = (char *) switch_xml_attr_soft(param, "value");
+			if (!strcasecmp(var, "default-root")) {
 				set_global_root(val);
-            } else if (!strcasecmp(var, "log-level-trace")) {
-				
-            }
-        }
-    }
-
-    if ((routes = switch_xml_child(cfg, "routes"))) {
-        for (route = switch_xml_child(routes, "route"); route; route = route->next) {
-            char *service = (char *) switch_xml_attr_soft(route, "service");
-            char *regex = (char *) switch_xml_attr_soft(route, "regex");
-            char *replace = (char *) switch_xml_attr_soft(route, "replace");
+			} else if (!strcasecmp(var, "log-level-trace")) {
+
+			}
+		}
+	}
+
+	if ((routes = switch_xml_child(cfg, "routes"))) {
+		for (route = switch_xml_child(routes, "route"); route; route = route->next) {
+			char *service = (char *) switch_xml_attr_soft(route, "service");
+			char *regex = (char *) switch_xml_attr_soft(route, "regex");
+			char *replace = (char *) switch_xml_attr_soft(route, "replace");
 
 			if (service && regex && replace) {
 				add_route(service, regex, replace);
 			} else {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Route!\n");
 			}
-        }
-    }
-	
- done:
+		}
+	}
+
+  done:
 
 	if (xml) {
 		switch_xml_free(xml);
@@ -168,20 +168,20 @@
 
 static char *reverse_number(char *in, char *root)
 {
-    switch_size_t len;
-    char *out = NULL;
-    char *y,*z;
-
-    if (!(in && root)) {
-        return NULL;
-    }
-
-    len = (strlen(in) * 2) + strlen(root) + 1;
-    if ((out = malloc(len))) {
-        memset(out, 0, len);
+	switch_size_t len;
+	char *out = NULL;
+	char *y, *z;
+
+	if (!(in && root)) {
+		return NULL;
+	}
 
-        z = out;
-        for(y = in + (strlen(in) - 1); y; y--) {
+	len = (strlen(in) * 2) + strlen(root) + 1;
+	if ((out = malloc(len))) {
+		memset(out, 0, len);
+
+		z = out;
+		for (y = in + (strlen(in) - 1); y; y--) {
 			if (*y > 47 && *y < 58) {
 				*z++ = *y;
 				*z++ = '.';
@@ -189,21 +189,22 @@
 			if (y == in) {
 				break;
 			}
-        }
-        strcat(z, root);
-    }
+		}
+		strcat(z, root);
+	}
 
 	return out;
 }
 
-static void dnserror(enum_query_t *q, int errnum) {
+static void dnserror(enum_query_t * q, int errnum)
+{
 
-    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "unable to lookup %s record for %s: %s\n",
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "unable to lookup %s record for %s: %s\n",
 					  dns_typename(q->qtyp), dns_dntosp(q->dn), dns_strerror(errnum));
 }
 
 
-static void add_result(enum_query_t *q, int order, int preference, char *service, char *route)
+static void add_result(enum_query_t * q, int order, int preference, char *service, char *route)
 {
 	enum_record_t *new_result, *rp, *prev = NULL;
 
@@ -213,12 +214,12 @@
 	}
 
 	memset(new_result, 0, sizeof(*new_result));
-	
+
 	new_result->order = order;
 	new_result->preference = preference;
 	new_result->service = strdup(service);
 	new_result->route = strdup(route);
-	
+
 
 	if (!q->results) {
 		q->results = new_result;
@@ -227,12 +228,12 @@
 
 	rp = q->results;
 
-	while(rp && strcmp(rp->service, new_result->service)) {
+	while (rp && strcmp(rp->service, new_result->service)) {
 		prev = rp;
 		rp = rp->next;
 	}
 
-	while(rp && !strcmp(rp->service, new_result->service) && new_result->order > rp->order) {
+	while (rp && !strcmp(rp->service, new_result->service) && new_result->order > rp->order) {
 		prev = rp;
 		rp = rp->next;
 	}
@@ -241,7 +242,7 @@
 		prev = rp;
 		rp = rp->next;
 	}
-	
+
 	if (prev) {
 		new_result->next = rp;
 		prev->next = new_result;
@@ -252,11 +253,11 @@
 }
 
 
-static void free_results(enum_record_t **results) 
+static void free_results(enum_record_t ** results)
 {
 	enum_record_t *fp, *rp;
 
-	for(rp = *results; rp;) {
+	for (rp = *results; rp;) {
 		fp = rp;
 		rp = rp->next;
 		switch_safe_free(fp->service);
@@ -266,7 +267,8 @@
 	*results = NULL;
 }
 
-static void parse_rr(const struct dns_parse *p, enum_query_t *q, struct dns_rr *rr) {
+static void parse_rr(const struct dns_parse *p, enum_query_t * q, struct dns_rr *rr)
+{
 	const unsigned char *pkt = p->dnsp_pkt;
 	const unsigned char *end = p->dnsp_end;
 	const unsigned char *dptr = rr->dnsrr_dptr;
@@ -282,25 +284,26 @@
 	char *regex = NULL;
 	char *replace = NULL;
 	int argc = 0;
-	char *argv[4] = {0};
+	char *argv[4] = { 0 };
 	int leap;
 
-	switch(rr->dnsrr_typ) {
+	switch (rr->dnsrr_typ) {
 
-	case DNS_T_NAPTR:	/* prio weight port targetDN */
+	case DNS_T_NAPTR:			/* prio weight port targetDN */
 		c = dptr;
 		c += 2 + 2 + 2;
-		if (dns_getdn(pkt, &c, end, dn, DNS_MAXDN) <= 0 || c != dend) goto xperr;
+		if (dns_getdn(pkt, &c, end, dn, DNS_MAXDN) <= 0 || c != dend)
+			goto xperr;
 		c = dptr;
-		
+
 		leap = *dn;
-		nme = (char *)dn+1;
+		nme = (char *) dn + 1;
 
-		order = dns_get16(c+0);
-		preference = dns_get16(c+2);
-		flags = (char) dns_get16(c+4);		
+		order = dns_get16(c + 0);
+		preference = dns_get16(c + 2);
+		flags = (char) dns_get16(c + 4);
 
-		if ((ptr = nme+leap)) {
+		if ((ptr = nme + leap)) {
 			service = nme;
 			*ptr++ = '\0';
 			argc = switch_separate_string(ptr, '!', argv, (sizeof(argv) / sizeof(argv[0])));
@@ -308,7 +311,7 @@
 			replace = argv[2];
 		}
 
-		for(ptr = replace; ptr && *ptr; ptr++) {
+		for (ptr = replace; ptr && *ptr; ptr++) {
 			if (*ptr == '\\') {
 				*ptr = '$';
 			}
@@ -332,7 +335,7 @@
 					uri = replace;
 				}
 
-				if ((route = (enum_route_t *) switch_core_hash_find(globals.routes, service))){
+				if ((route = (enum_route_t *) switch_core_hash_find(globals.routes, service))) {
 					switch_regex_safe_free(re);
 					if ((proceed = switch_regex_perform(uri, route->regex, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
 						if (strchr(route->regex, '(')) {
@@ -343,7 +346,7 @@
 						}
 					}
 				}
-				
+
 				add_result(q, order, preference, service, uri);
 			}
 
@@ -358,12 +361,13 @@
 
 	return;
 
- xperr:
+  xperr:
 	//printf("<parse error>\n");
 	return;
 }
 
-static void dnscb(struct dns_ctx *ctx, void *result, void *data) {
+static void dnscb(struct dns_ctx *ctx, void *result, void *data)
+{
 	int r = dns_status(ctx);
 	enum_query_t *q = data;
 	struct dns_parse p;
@@ -375,25 +379,24 @@
 		dnserror(q, r);
 		return;
 	}
-	pkt = result; end = pkt + r; cur = dns_payload(pkt);
+	pkt = result;
+	end = pkt + r;
+	cur = dns_payload(pkt);
 	dns_getdn(pkt, &cur, end, dn, sizeof(dn));
 	dns_initparse(&p, NULL, pkt, cur, end);
 	p.dnsp_qcls = p.dnsp_qtyp = 0;
 	qdn = dn;
 	nrr = 0;
-	while((r = dns_nextrr(&p, &rr)) > 0) {
-		if (!dns_dnequal(qdn, rr.dnsrr_dn)) continue;
-		if ((qcls == DNS_C_ANY || qcls == rr.dnsrr_cls) &&
-			(q->qtyp == DNS_T_ANY || q->qtyp == rr.dnsrr_typ))
+	while ((r = dns_nextrr(&p, &rr)) > 0) {
+		if (!dns_dnequal(qdn, rr.dnsrr_dn))
+			continue;
+		if ((qcls == DNS_C_ANY || qcls == rr.dnsrr_cls) && (q->qtyp == DNS_T_ANY || q->qtyp == rr.dnsrr_typ))
 			++nrr;
 		else if (rr.dnsrr_typ == DNS_T_CNAME && !nrr) {
-			if (dns_getdn(pkt, &rr.dnsrr_dptr, end,
-						  p.dnsp_dnbuf, sizeof(p.dnsp_dnbuf)) <= 0 ||
-				rr.dnsrr_dptr != rr.dnsrr_dend) {
+			if (dns_getdn(pkt, &rr.dnsrr_dptr, end, p.dnsp_dnbuf, sizeof(p.dnsp_dnbuf)) <= 0 || rr.dnsrr_dptr != rr.dnsrr_dend) {
 				r = DNS_E_PROTOCOL;
 				break;
-			}
-			else {
+			} else {
 				qdn = p.dnsp_dnbuf;
 			}
 		}
@@ -409,28 +412,28 @@
 	dns_rewind(&p, NULL);
 	p.dnsp_qtyp = q->qtyp;
 	p.dnsp_qcls = qcls;
-	while(dns_nextrr(&p, &rr)) {
+	while (dns_nextrr(&p, &rr)) {
 		parse_rr(&p, q, &rr);
 	}
-  
+
 	free(result);
 }
 
 
-static switch_status_t enum_lookup(char *root, char *in, enum_record_t **results)
+static switch_status_t enum_lookup(char *root, char *in, enum_record_t ** results)
 {
-	switch_status_t sstatus  = SWITCH_STATUS_SUCCESS;
+	switch_status_t sstatus = SWITCH_STATUS_SUCCESS;
 	char *name = NULL;
-	enum_query_t query = {0};
+	enum_query_t query = { 0 };
 	enum dns_type l_qtyp = DNS_T_NAPTR;
 	int i = 0, abs = 0;
-	dns_socket fd = (dns_socket)-1;
+	dns_socket fd = (dns_socket) - 1;
 	fd_set fds;
-	struct timeval tv = {0};
+	struct timeval tv = { 0 };
 	time_t now = 0;
 	struct dns_ctx *nctx = NULL;
 	char *num, *mnum = NULL;
-	
+
 	if (*in != '+') {
 		mnum = switch_mprintf("+%s", in);
 		num = mnum;
@@ -458,7 +461,7 @@
 		goto done;
 	}
 
-	dns_ptodn(name, (unsigned int)strlen(name), query.dn, sizeof(query.dn), &abs);
+	dns_ptodn(name, (unsigned int) strlen(name), query.dn, sizeof(query.dn), &abs);
 	query.name = name;
 	query.number = num;
 	query.qtyp = l_qtyp;
@@ -466,7 +469,7 @@
 	if (abs) {
 		abs = DNS_NOSRCH;
 	}
-	
+
 	if (!dns_submit_dn(nctx, query.dn, qcls, l_qtyp, abs, 0, dnscb, &query)) {
 		dnserror(&query, dns_status(nctx));
 	}
@@ -474,7 +477,7 @@
 	FD_ZERO(&fds);
 	now = 0;
 
-	while((i = dns_timeouts(nctx, -1, now)) > 0) {
+	while ((i = dns_timeouts(nctx, -1, now)) > 0) {
 #ifdef _MSC_VER
 #pragma warning(push)
 #pragma warning(disable: 4389 4127)
@@ -485,9 +488,10 @@
 #endif
 		tv.tv_sec = i;
 		tv.tv_usec = 0;
-		i = select((int)(fd+1), &fds, 0, 0, &tv);
+		i = select((int) (fd + 1), &fds, 0, 0, &tv);
 		now = time(NULL);
-		if (i > 0) dns_ioevent(nctx, now);
+		if (i > 0)
+			dns_ioevent(nctx, now);
 	}
 
 	if (!query.results) {
@@ -497,17 +501,17 @@
 	*results = query.results;
 	query.results = NULL;
 
- done:
+  done:
 
 	if (fd > -1) {
 		closesocket(fd);
-		fd = (dns_socket)-1;
+		fd = (dns_socket) - 1;
 	}
 
 	if (nctx) {
 		dns_free(nctx);
 	}
-	
+
 	switch_safe_free(name);
 	switch_safe_free(mnum);
 
@@ -524,34 +528,34 @@
 	enum_route_t *rtp;
 	char *dp = (char *) arg;
 
-    assert(channel != NULL);
+	assert(channel != NULL);
 
 	caller_profile = switch_channel_get_caller_profile(channel);
-	
+
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "ENUM Lookup on %s\n", caller_profile->destination_number);
 
 	if (enum_lookup(switch_strlen_zero(dp) ? globals.root : dp, caller_profile->destination_number, &results) == SWITCH_STATUS_SUCCESS) {
 		if ((extension = switch_caller_extension_new(session, caller_profile->destination_number, caller_profile->destination_number)) == 0) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "memory error!\n");
-			free_results(&results);	
+			free_results(&results);
 			return NULL;
 		}
 		switch_channel_set_variable(channel, SWITCH_HANGUP_AFTER_BRIDGE_VARIABLE, "true");
-		
-		for(rtp = globals.route_order; rtp; rtp = rtp->next) {
-			for(rp = results; rp; rp = rp->next) {
+
+		for (rtp = globals.route_order; rtp; rtp = rtp->next) {
+			for (rp = results; rp; rp = rp->next) {
 				if (!strcmp(rtp->service, rp->service)) {
-					switch_caller_extension_add_application(session, extension, "bridge", rp->route);					
+					switch_caller_extension_add_application(session, extension, "bridge", rp->route);
 				}
 			}
 		}
 
-		free_results(&results);	
+		free_results(&results);
 	}
 
 	if (extension) {
-        switch_channel_set_state(channel, CS_EXECUTE);
-    }
+		switch_channel_set_state(channel, CS_EXECUTE);
+	}
 
 	return extension;
 
@@ -560,7 +564,7 @@
 static void enum_app_function(switch_core_session_t *session, char *data)
 {
 	int argc = 0;
-    char *argv[4] = {0};
+	char *argv[4] = { 0 };
 	char *mydata = NULL;
 	char *dest = NULL, *root = NULL;
 	enum_record_t *results, *rp;
@@ -575,12 +579,12 @@
 	assert(channel != NULL);
 
 	if (!(mydata = switch_core_session_strdup(session, data))) {
-        return;
-    }
+		return;
+	}
 
-    if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
+	if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
 		dest = argv[0];
-        root = argv[1] ? argv[1] : globals.root;
+		root = argv[1] ? argv[1] : globals.root;
 		if (enum_lookup(root, data, &results) == SWITCH_STATUS_SUCCESS) {
 			switch_hash_index_t *hi;
 			void *vval;
@@ -593,8 +597,8 @@
 				}
 			}
 
-			for(rtp = globals.route_order; rtp; rtp = rtp->next) {
-				for(rp = results; rp; rp = rp->next) {
+			for (rtp = globals.route_order; rtp; rtp = rtp->next) {
+				for (rp = results; rp; rp = rp->next) {
 					if (!strcmp(rtp->service, rp->service)) {
 						snprintf(vbuf, sizeof(vbuf), "enum_route_%d", cnt++);
 						switch_channel_set_variable(channel, vbuf, rp->route);
@@ -608,19 +612,19 @@
 			}
 			snprintf(vbuf, sizeof(vbuf), "%d", cnt);
 			switch_channel_set_variable(channel, "enum_route_count", vbuf);
-			*(rbuf+strlen(rbuf)-1) = '\0';
+			*(rbuf + strlen(rbuf) - 1) = '\0';
 			switch_channel_set_variable(channel, "enum_auto_route", rbuf);
-			free_results(&results);	
+			free_results(&results);
 		}
 	}
-	
+
 }
 
 static switch_status_t enum_function(char *data, switch_core_session_t *session, switch_stream_handle_t *stream)
 {
 
 	int argc = 0;
-	char *argv[4] = {0};
+	char *argv[4] = { 0 };
 	enum_record_t *results, *rp;
 	char *mydata = NULL;
 	char *dest = NULL, *root = NULL;
@@ -639,35 +643,33 @@
 	if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
 		dest = argv[0];
 		root = argv[1] ? argv[1] : globals.root;
-		
+
 		if (!enum_lookup(root, data, &results) == SWITCH_STATUS_SUCCESS) {
 			stream->write_function(stream, "No Match!\n");
 			return SWITCH_STATUS_SUCCESS;
 		}
-		
+
 		stream->write_function(stream,
 							   "\nOffered Routes:\n"
-							   "Order\tPref\tService   \tRoute\n"
-							   "==============================================================================\n");
+							   "Order\tPref\tService   \tRoute\n" "==============================================================================\n");
 
-		for(rp = results; rp; rp = rp->next) {
+		for (rp = results; rp; rp = rp->next) {
 			stream->write_function(stream, "%d\t%d\t%-10s\t%s\n", rp->order, rp->preference, rp->service, rp->route);
 		}
-	
+
 
 		stream->write_function(stream,
 							   "\nSupported Routes:\n"
-							   "Order\tPref\tService   \tRoute\n"
-							   "==============================================================================\n");
+							   "Order\tPref\tService   \tRoute\n" "==============================================================================\n");
 
-		for(rtp = globals.route_order; rtp; rtp = rtp->next) {
-			for(rp = results; rp; rp = rp->next) {
+		for (rtp = globals.route_order; rtp; rtp = rtp->next) {
+			for (rp = results; rp; rp = rp->next) {
 				if (!strcmp(rtp->service, rp->service)) {
 					stream->write_function(stream, "%d\t%d\t%-10s\t%s\n", rp->order, rp->preference, rp->service, rp->route);
 				}
 			}
 		}
-		
+
 		free_results(&results);
 	} else {
 		stream->write_function(stream, "Invalid Input!\n");
@@ -678,14 +680,14 @@
 
 
 static const switch_dialplan_interface_t enum_dialplan_interface = {
-    /*.interface_name = */ "enum",
-    /*.hunt_function = */ enum_dialplan_hunt
-    /*.next = NULL */
+	/*.interface_name = */ "enum",
+	/*.hunt_function = */ enum_dialplan_hunt
+		/*.next = NULL */
 };
 
 static const switch_application_interface_t enum_application_interface = {
 	/*.interface_name */ "enum",
-	/*.application_function */ enum_app_function,	
+	/*.application_function */ enum_app_function,
 	/* long_desc */ "Perform an ENUM lookup",
 	/* short_desc */ "Perform an ENUM lookup",
 	/* syntax */ "<number> [<root>]",
@@ -729,5 +731,3 @@
 	/* indicate that the module should continue to be loaded */
 	return SWITCH_STATUS_SUCCESS;
 }
-
-

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_ivrtest/mod_ivrtest.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_ivrtest/mod_ivrtest.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_ivrtest/mod_ivrtest.c	Fri Mar 30 12:19:18 2007
@@ -42,13 +42,13 @@
 static switch_status_t on_dtmf(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf, unsigned int buflen)
 {
 	switch (itype) {
-	case SWITCH_INPUT_TYPE_DTMF: {
-		char *dtmf = (char *) input;
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Digits %s\n", dtmf);
-	
-		switch_copy_string((char *)buf, dtmf, buflen);
-		return SWITCH_STATUS_BREAK;
-	}
+	case SWITCH_INPUT_TYPE_DTMF:{
+			char *dtmf = (char *) input;
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Digits %s\n", dtmf);
+
+			switch_copy_string((char *) buf, dtmf, buflen);
+			return SWITCH_STATUS_BREAK;
+		}
 		break;
 	default:
 		break;
@@ -72,9 +72,8 @@
 	for (team = switch_xml_child(f1, "team"); team; team = team->next) {
 		teamname = switch_xml_attr_soft(team, "name");
 		for (driver = switch_xml_child(team, "driver"); driver; driver = driver->next) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, 
-							  "%s, %s: %s\n", switch_xml_child(driver, "name")->txt, teamname,
-							  switch_xml_child(driver, "points")->txt);
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
+							  "%s, %s: %s\n", switch_xml_child(driver, "name")->txt, teamname, switch_xml_child(driver, "points")->txt);
 		}
 	}
 	switch_xml_free(f1);
@@ -84,7 +83,7 @@
 static void ivr_application_function(switch_core_session_t *session, char *data)
 {
 	switch_channel_t *channel = switch_core_session_get_channel(session);
-	char *params = switch_core_session_strdup(session,data);
+	char *params = switch_core_session_strdup(session, data);
 
 	if (channel != NULL && params != NULL) {
 		switch_ivr_menu_t *menu = NULL, *sub_menu = NULL;
@@ -97,26 +96,11 @@
 									  NULL,
 									  "main",
 									  "please enter some numbers so i can figure out if I have any bugs or not",
-									  "enter some numbers",
-									  NULL,
-									  "I have no idea what that is",
-									  "cepstral",
-									  "david",
-									  NULL,
-									  15000, 10, NULL);
+									  "enter some numbers", NULL, "I have no idea what that is", "cepstral", "david", NULL, 15000, 10, NULL);
 
 
 		status = switch_ivr_menu_init(&sub_menu,
-									  menu,
-									  "sub",
-									  "/ram/congrats.wav",
-									  "/ram/extension.wav",
-									  NULL,
-									  "/ram/invalid.wav",
-									  NULL,
-									  NULL,
-									  NULL,
-									  15000, 10, NULL);
+									  menu, "sub", "/ram/congrats.wav", "/ram/extension.wav", NULL, "/ram/invalid.wav", NULL, NULL, NULL, 15000, 10, NULL);
 
 		if (status == SWITCH_STATUS_SUCCESS) {
 			// build the menu
@@ -125,10 +109,10 @@
 			switch_ivr_menu_bind_action(menu, SWITCH_IVR_ACTION_EXECMENU, "sub", "3");
 			//switch_ivr_menu_bind_action(menu, SWITCH_IVR_ACTION_PLAYSOUND, "/usr/local/freeswitch/sounds/3.wav", "3");
 
-			
+
 			switch_ivr_menu_bind_action(sub_menu, SWITCH_IVR_ACTION_PLAYSOUND, "/ram/swimp.raw", "1");
 			switch_ivr_menu_bind_action(sub_menu, SWITCH_IVR_ACTION_BACK, NULL, "2");
-			
+
 
 			// start the menu
 			status = switch_ivr_menu_execute(session, menu, "main", NULL);
@@ -136,11 +120,11 @@
 			// cleaup the menu
 			switch_ivr_menu_stack_free(menu);
 		} else {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "unable to build menu %s\n",params);
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "unable to build menu %s\n", params);
 		}
-			
 
-		switch_ivr_play_file(session, NULL,"/ram/goodbye.wav",NULL);
+
+		switch_ivr_play_file(session, NULL, "/ram/goodbye.wav", NULL);
 	}
 }
 
@@ -151,15 +135,10 @@
 	switch_directory_handle_t dh;
 
 	channel = switch_core_session_get_channel(session);
-    assert(channel != NULL);
+	assert(channel != NULL);
 
 
-	if (switch_core_directory_open(&dh, 
-								   "ldap",
-								   "ldap.freeswitch.org",
-								   "cn=Manager,dc=freeswitch,dc=org",
-								   "test",
-								   NULL) != SWITCH_STATUS_SUCCESS) {
+	if (switch_core_directory_open(&dh, "ldap", "ldap.freeswitch.org", "cn=Manager,dc=freeswitch,dc=org", "test", NULL) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't connect\n");
 		return;
 	}
@@ -181,12 +160,12 @@
 {
 
 	switch (itype) {
-	case SWITCH_INPUT_TYPE_DTMF: {
-		char *dtmf = (char *) input;
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Digits %s\n", dtmf);
+	case SWITCH_INPUT_TYPE_DTMF:{
+			char *dtmf = (char *) input;
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Digits %s\n", dtmf);
 
-		switch_copy_string((char *)buf, dtmf, buflen);
-	}
+			switch_copy_string((char *) buf, dtmf, buflen);
+		}
 		break;
 	default:
 		break;
@@ -203,9 +182,9 @@
 	char buf[10] = "";
 	char *argv[3];
 	int argc;
-    switch_input_args_t args = {0};
+	switch_input_args_t args = { 0 };
 
-	if(!(mydata = switch_core_session_strdup(session, (char *) data))) {
+	if (!(mydata = switch_core_session_strdup(session, (char *) data))) {
 		return;
 	}
 
@@ -221,14 +200,14 @@
 	}
 
 	channel = switch_core_session_get_channel(session);
-    assert(channel != NULL);
-	
-    switch_channel_answer(channel);
+	assert(channel != NULL);
+
+	switch_channel_answer(channel);
 
 	codec = switch_core_session_get_read_codec(session);
-    args.input_callback = show_dtmf;
-    args.buf = buf;
-    args.buflen = sizeof(buf);
+	args.input_callback = show_dtmf;
+	args.buf = buf;
+	args.buflen = sizeof(buf);
 	switch_ivr_speak_text(session, tts_name, voice_name, codec->implementation->samples_per_second, text, &args);
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Done\n");
 }
@@ -236,17 +215,17 @@
 #ifdef BUGTEST
 static switch_bool_t bug_callback(switch_media_bug_t *bug, void *user_data, switch_abc_type_t type)
 {
-    switch_frame_t *frame;
+	switch_frame_t *frame;
 
-    switch(type) {
+	switch (type) {
 	case SWITCH_ABC_TYPE_WRITE_REPLACE:
-        frame = switch_core_media_bug_get_replace_frame(bug);
-        switch_core_media_bug_set_replace_frame(bug, frame);
-        printf("W00t\n");
-        break;
-    default:
-        break;
-    }
+		frame = switch_core_media_bug_get_replace_frame(bug);
+		switch_core_media_bug_set_replace_frame(bug, frame);
+		printf("W00t\n");
+		break;
+	default:
+		break;
+	}
 
 	return SWITCH_TRUE;
 }
@@ -257,55 +236,43 @@
 #ifdef BUGTEST
 	switch_media_bug_t *bug;
 	switch_channel_t *channel = switch_core_session_get_channel(session);
-    switch_status_t status;
+	switch_status_t status;
 
-	if ((status = switch_core_media_bug_add(session,
-											bug_callback,
-											NULL,
-											SMBF_WRITE_REPLACE,
-											&bug)) != SWITCH_STATUS_SUCCESS) {
+	if ((status = switch_core_media_bug_add(session, bug_callback, NULL, SMBF_WRITE_REPLACE, &bug)) != SWITCH_STATUS_SUCCESS) {
 		switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-        return;
+		return;
 	}
 #endif
 	//switch_ivr_schedule_broadcast(time(NULL) + 10, switch_core_session_get_uuid(session), "/Users/anthm/sr8k.wav", SMF_ECHO_ALEG);
 	//switch_ivr_schedule_transfer(time(NULL) + 10, switch_core_session_get_uuid(session), "2000", NULL, NULL);
 	//switch_ivr_schedule_hangup(time(NULL) + 10, switch_core_session_get_uuid(session), SWITCH_CAUSE_ALLOTTED_TIMEOUT);
 
-    switch_ivr_play_file(session, NULL, data, NULL);
+	switch_ivr_play_file(session, NULL, data, NULL);
 }
 
 #if 1
 static void asrtest_function(switch_core_session_t *session, char *data)
 {
-	switch_ivr_detect_speech(session,
-							 "lumenvox",
-							 "demo",
-							 data,
-							 "127.0.0.1",
-							 NULL);
+	switch_ivr_detect_speech(session, "lumenvox", "demo", data, "127.0.0.1", NULL);
 }
 
-#else 
+#else
 static void asrtest_function(switch_core_session_t *session, char *data)
 {
-	switch_asr_handle_t ah = {0};
+	switch_asr_handle_t ah = { 0 };
 	switch_asr_flag_t flags = SWITCH_ASR_FLAG_NONE;
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 	char *codec_name = "L16";
-	switch_codec_t codec = {0}, *read_codec;
-	switch_frame_t write_frame = {0}, *write_frame_p = NULL;
+	switch_codec_t codec = { 0 }, *read_codec;
+	switch_frame_t write_frame = { 0 }, *write_frame_p = NULL;
 	char xdata[1024] = "";
 
 	read_codec = switch_core_session_get_read_codec(session);
 	assert(read_codec != NULL);
-	
+
 
 	if (switch_core_asr_open(&ah, "lumenvox",
-							 read_codec->implementation->iananame,
-							 8000,
-							 "127.0.0.1",
-							 &flags,
+							 read_codec->implementation->iananame, 8000, "127.0.0.1", &flags,
 							 switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
 		if (strcmp(ah.codec, read_codec->implementation->iananame)) {
 			if (switch_core_codec_init(&codec,
@@ -317,36 +284,37 @@
 									   SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
 									   NULL, switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activated\n");
-				switch_core_session_set_read_codec(session, &codec);		
+				switch_core_session_set_read_codec(session, &codec);
 				write_frame.data = xdata;
 				write_frame.buflen = sizeof(xdata);
 				write_frame.codec = &codec;
 				write_frame_p = &write_frame;
 			} else {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec Activation Failed %s@%uhz %u channels %dms\n",
-								  codec_name, read_codec->implementation->samples_per_second, read_codec->implementation->number_of_channels,
-								  read_codec->implementation->microseconds_per_frame / 1000);
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
+								  "Codec Activation Failed %s@%uhz %u channels %dms\n", codec_name,
+								  read_codec->implementation->samples_per_second,
+								  read_codec->implementation->number_of_channels, read_codec->implementation->microseconds_per_frame / 1000);
 				switch_core_session_reset(session);
 				return;
 			}
 		}
-		
-		
+
+
 		if (switch_core_asr_load_grammar(&ah, "demo", "/opt/lumenvox/engine_7.0/Lang/BuiltinGrammars/ABNFPhone.gram") != SWITCH_STATUS_SUCCESS) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error loading Grammar\n");
 			goto end;
 		}
-		
-		while(switch_channel_ready(channel)) {
+
+		while (switch_channel_ready(channel)) {
 			switch_frame_t *read_frame;
 			switch_status_t status = switch_core_session_read_frame(session, &read_frame, -1, 0);
 			char *xmlstr = NULL;
 			switch_xml_t xml = NULL, result;
- 
+
 			if (!SWITCH_READ_ACCEPTABLE(status)) {
 				break;
 			}
-			
+
 			if (switch_test_flag(read_frame, SFF_CNG)) {
 				continue;
 			}
@@ -355,7 +323,7 @@
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error Feeding Data\n");
 				break;
 			}
-			
+
 			if (switch_core_asr_check_results(&ah, &flags) == SWITCH_STATUS_SUCCESS) {
 				if (switch_core_asr_get_results(&ah, &xmlstr, &flags) != SWITCH_STATUS_SUCCESS) {
 					break;
@@ -368,7 +336,7 @@
 				}
 				switch_safe_free(xmlstr);
 			}
-			
+
 			if (write_frame_p) {
 				write_frame.datalen = read_frame->datalen;
 				switch_core_session_write_frame(session, write_frame_p, -1, 0);
@@ -378,7 +346,7 @@
 			}
 		}
 
-	end:
+	  end:
 		if (write_frame_p) {
 			switch_core_session_set_read_codec(session, read_codec);
 			switch_core_codec_destroy(&codec);
@@ -400,9 +368,9 @@
 	char buf[10] = "";
 	char term;
 	char say[128] = "";
-	
+
 	channel = switch_core_session_get_channel(session);
-    assert(channel != NULL);
+	assert(channel != NULL);
 
 	switch_channel_answer(channel);
 
@@ -413,15 +381,15 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Enter up to 10 digits, press # to terminate, * to hangup\n");
 
 		if (data) {
-            switch_input_args_t args = {0};
+			switch_input_args_t args = { 0 };
 			/* you could have passed NULL instead of on_dtmf to get this exact behaviour (copy the digits to buf and stop playing)
 			   but you may want to pass the function if you have something cooler to do...
-			*/
-            args.input_callback = on_dtmf;
-            args.buf = buf;
-            args.buflen = sizeof(buf);
+			 */
+			args.input_callback = on_dtmf;
+			args.buf = buf;
+			args.buflen = sizeof(buf);
 			status = switch_ivr_play_file(session, NULL, data, &args);
-			
+
 			if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
 				switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
 				break;
@@ -440,7 +408,7 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, say);
 		switch_ivr_speak_text(session, "cepstral", "david", codec->implementation->samples_per_second, say, NULL);
 	}
-	
+
 }
 
 
@@ -449,7 +417,7 @@
 	switch_channel_t *channel;
 
 	channel = switch_core_session_get_channel(session);
-    assert(channel != NULL);
+	assert(channel != NULL);
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "I globally hooked to [%s] on the hangup event\n", switch_channel_get_name(channel));
 	return SWITCH_STATUS_SUCCESS;
@@ -472,7 +440,7 @@
 	/*.application_function */ bugtest_function,
 	NULL, NULL, NULL,
 	/* flags */ SAF_NONE,
-	/*.next*/ NULL
+	/*.next */ NULL
 };
 
 static const switch_application_interface_t ivr_application_interface = {
@@ -480,7 +448,7 @@
 	/*.application_function */ ivr_application_function,
 	NULL, NULL, NULL,
 	/* flags */ SAF_NONE,
-	/*.next*/ &bug_application_interface
+	/*.next */ &bug_application_interface
 };
 
 static const switch_application_interface_t xml_application_interface = {
@@ -488,7 +456,7 @@
 	/*.application_function */ xml_function,
 	NULL, NULL, NULL,
 	/* flags */ SAF_NONE,
-	/*.next*/ &ivr_application_interface
+	/*.next */ &ivr_application_interface
 };
 
 static const switch_application_interface_t disast_application_interface = {
@@ -496,7 +464,7 @@
 	/*.application_function */ disast_function,
 	NULL, NULL, NULL,
 	/* flags */ SAF_SUPPORT_NOMEDIA,
-	/*.next*/ &xml_application_interface
+	/*.next */ &xml_application_interface
 };
 
 static const switch_application_interface_t tts_application_interface = {
@@ -504,7 +472,7 @@
 	/*.application_function */ tts_function,
 	NULL, NULL, NULL,
 	/* flags */ SAF_NONE,
-	/*.next*/ &disast_application_interface
+	/*.next */ &disast_application_interface
 };
 
 static const switch_application_interface_t dirtest_application_interface = {
@@ -512,7 +480,7 @@
 	/*.application_function */ dirtest_function,
 	NULL, NULL, NULL,
 	/* flags */ SAF_SUPPORT_NOMEDIA,
-	/*.next*/ &tts_application_interface
+	/*.next */ &tts_application_interface
 };
 
 static const switch_application_interface_t ivrtest_application_interface = {
@@ -520,7 +488,7 @@
 	/*.application_function */ ivrtest_function,
 	NULL, NULL, NULL,
 	/* flags */ SAF_NONE,
-	/*.next*/ &dirtest_application_interface
+	/*.next */ &dirtest_application_interface
 };
 
 static const switch_application_interface_t asrtest_application_interface = {
@@ -528,7 +496,7 @@
 	/*.application_function */ asrtest_function,
 	NULL, NULL, NULL,
 	/* flags */ SAF_NONE,
-	/*.next*/ &ivrtest_application_interface
+	/*.next */ &ivrtest_application_interface
 };
 
 static const switch_loadable_module_interface_t mod_ivrtest_module_interface = {

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_park/mod_park.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_park/mod_park.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_park/mod_park.c	Fri Mar 30 12:19:18 2007
@@ -35,13 +35,13 @@
 static void park_function(switch_core_session_t *session, char *data)
 {
 	switch_ivr_park(session, NULL);
-	
+
 }
 
 static const switch_application_interface_t park_application_interface = {
 	/*.interface_name */ "park",
 	/*.application_function */ park_function,
-	NULL,NULL,NULL,
+	NULL, NULL, NULL,
 	/* flags */ SAF_NONE,
 	NULL
 };

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_playback/mod_playback.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_playback/mod_playback.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_playback/mod_playback.c	Fri Mar 30 12:19:18 2007
@@ -41,21 +41,21 @@
 static switch_status_t on_dtmf(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf, unsigned int buflen)
 {
 
-	
+
 	switch (itype) {
-	case SWITCH_INPUT_TYPE_DTMF: {
-		char *dtmf = (char *) input;
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Digits %s\n", dtmf);
-		
-		if (*dtmf == '*') {
-			return SWITCH_STATUS_BREAK;
+	case SWITCH_INPUT_TYPE_DTMF:{
+			char *dtmf = (char *) input;
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Digits %s\n", dtmf);
+
+			if (*dtmf == '*') {
+				return SWITCH_STATUS_BREAK;
+			}
 		}
-	}
 		break;
 	default:
 		break;
 	}
-	
+
 	return SWITCH_STATUS_SUCCESS;
 }
 
@@ -64,28 +64,28 @@
 {
 	switch_channel_t *channel;
 	char buf[10];
-	char *argv[4] = {0};
+	char *argv[4] = { 0 };
 	int argc;
 	char *engine = NULL;
 	char *voice = NULL;
 	char *text = NULL;
 	char *mydata = NULL;
 	switch_codec_t *codec;
-    switch_input_args_t args = {0};
+	switch_input_args_t args = { 0 };
 
 	codec = switch_core_session_get_read_codec(session);
 	assert(codec != NULL);
 
 	channel = switch_core_session_get_channel(session);
-    assert(channel != NULL);
+	assert(channel != NULL);
 
 	mydata = switch_core_session_strdup(session, data);
-	argc = switch_separate_string(mydata, '|', argv, sizeof(argv)/sizeof(argv[0]));
+	argc = switch_separate_string(mydata, '|', argv, sizeof(argv) / sizeof(argv[0]));
 
 	engine = argv[0];
 	voice = argv[1];
 	text = argv[2];
-	
+
 	if (!(engine && voice && text)) {
 		if (!engine) {
 			engine = "NULL";
@@ -102,27 +102,27 @@
 
 	switch_channel_pre_answer(channel);
 
-    args.input_callback = on_dtmf;
-    args.buf = buf;
-    args.buflen = sizeof(buf);
+	args.input_callback = on_dtmf;
+	args.buf = buf;
+	args.buflen = sizeof(buf);
 	switch_ivr_speak_text(session, engine, voice, codec->implementation->samples_per_second, text, &args);
-	
+
 }
 
 static void playback_function(switch_core_session_t *session, char *data)
 {
 	switch_channel_t *channel;
 	char *file_name = NULL;
-    switch_input_args_t args = {0};
+	switch_input_args_t args = { 0 };
 
 	file_name = switch_core_session_strdup(session, data);
 
 	channel = switch_core_session_get_channel(session);
-    assert(channel != NULL);
+	assert(channel != NULL);
 
 	switch_channel_pre_answer(channel);
 
-    args.input_callback = on_dtmf;
+	args.input_callback = on_dtmf;
 	switch_ivr_play_file(session, NULL, file_name, &args);
 
 }
@@ -132,21 +132,21 @@
 {
 	switch_channel_t *channel;
 	switch_status_t status;
-    uint32_t limit = 0;
-    char *path;
-    char *p;
-    switch_input_args_t args = {0};
+	uint32_t limit = 0;
+	char *path;
+	char *p;
+	switch_input_args_t args = { 0 };
 
 	channel = switch_core_session_get_channel(session);
-    assert(channel != NULL);
+	assert(channel != NULL);
 
-    path = switch_core_session_strdup(session, data);
-    if ((p = strchr(path, '+'))) {
-        *p++ = '\0';
-        limit = atoi(p);
-    }
+	path = switch_core_session_strdup(session, data);
+	if ((p = strchr(path, '+'))) {
+		*p++ = '\0';
+		limit = atoi(p);
+	}
 
-    args.input_callback = on_dtmf;
+	args.input_callback = on_dtmf;
 	status = switch_ivr_record_file(session, NULL, path, &args, limit);
 
 	if (!switch_channel_ready(channel) || (status != SWITCH_STATUS_SUCCESS && !SWITCH_STATUS_IS_BREAK(status))) {
@@ -159,9 +159,9 @@
 {
 	switch_channel_t *channel;
 	channel = switch_core_session_get_channel(session);
-    assert(channel != NULL);
+	assert(channel != NULL);
 
-	switch_ivr_record_session(session, data, NULL);	
+	switch_ivr_record_session(session, data, NULL);
 }
 
 
@@ -169,9 +169,9 @@
 {
 	switch_channel_t *channel;
 	channel = switch_core_session_get_channel(session);
-    assert(channel != NULL);
+	assert(channel != NULL);
 
-	switch_ivr_stop_record_session(session, data);	
+	switch_ivr_stop_record_session(session, data);
 }
 
 
@@ -223,7 +223,7 @@
 	/* short_desc */ "Playback File",
 	/* syntax */ "<path>",
 	/* flags */ SAF_NONE,
-	/*.next*/	&stop_record_session_application_interface
+	/*.next */ &stop_record_session_application_interface
 };
 
 static const switch_loadable_module_interface_t mod_playback_module_interface = {

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_rss/mod_rss.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_rss/mod_rss.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_rss/mod_rss.c	Fri Mar 30 12:19:18 2007
@@ -68,9 +68,9 @@
 {
 	char tstr[80] = "";
 	uint32_t matches = 0, x = 0;
-	uint32_t len = (uint32_t)strlen(str);
+	uint32_t len = (uint32_t) strlen(str);
 
-	for (x = 0; x < max ; x++) {
+	for (x = 0; x < max; x++) {
 		snprintf(tstr, sizeof(tstr), "%u", x);
 		if (!strncasecmp(str, tstr, len)) {
 			matches++;
@@ -86,67 +86,66 @@
   if you return anything but SWITCH_STATUS_SUCCESS the playback will stop.
 */
 static switch_status_t on_dtmf(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf, unsigned int buflen)
-
 {
 	switch (itype) {
-	case SWITCH_INPUT_TYPE_DTMF: {
-		char *dtmf = (char *) input;
-		struct dtmf_buffer *dtb;
-		dtb = (struct dtmf_buffer *) buf;
-	
-		switch(*dtmf) {
-		case '#':
-			switch_set_flag(dtb, SFLAG_MAIN);
-			return SWITCH_STATUS_BREAK;
-		case '6':
-			dtb->index++;
-			return SWITCH_STATUS_BREAK;
-		case '4':
-			dtb->index--;
-			return SWITCH_STATUS_BREAK;
-		case '*':
-			if (switch_test_flag(dtb->sh, SWITCH_SPEECH_FLAG_PAUSE)) {
-				switch_clear_flag(dtb->sh, SWITCH_SPEECH_FLAG_PAUSE);
-			} else {
-				switch_set_flag(dtb->sh, SWITCH_SPEECH_FLAG_PAUSE);
-			}
-			break;
-		case '5':
-			switch_core_speech_text_param_tts(dtb->sh, "voice", "next");
-			switch_set_flag(dtb, SFLAG_INFO);
-			return SWITCH_STATUS_BREAK;
-			break;
-		case '9':
-			switch_core_speech_text_param_tts(dtb->sh, "voice", dtb->voice);
-			switch_set_flag(dtb, SFLAG_INFO);
-			return SWITCH_STATUS_BREAK;
-			break;
-		case '2':
-			if (dtb->speed < 260) {
-				dtb->speed += 30;
-				switch_core_speech_numeric_param_tts(dtb->sh, "speech/rate", dtb->speed);
+	case SWITCH_INPUT_TYPE_DTMF:{
+			char *dtmf = (char *) input;
+			struct dtmf_buffer *dtb;
+			dtb = (struct dtmf_buffer *) buf;
+
+			switch (*dtmf) {
+			case '#':
+				switch_set_flag(dtb, SFLAG_MAIN);
+				return SWITCH_STATUS_BREAK;
+			case '6':
+				dtb->index++;
+				return SWITCH_STATUS_BREAK;
+			case '4':
+				dtb->index--;
+				return SWITCH_STATUS_BREAK;
+			case '*':
+				if (switch_test_flag(dtb->sh, SWITCH_SPEECH_FLAG_PAUSE)) {
+					switch_clear_flag(dtb->sh, SWITCH_SPEECH_FLAG_PAUSE);
+				} else {
+					switch_set_flag(dtb->sh, SWITCH_SPEECH_FLAG_PAUSE);
+				}
+				break;
+			case '5':
+				switch_core_speech_text_param_tts(dtb->sh, "voice", "next");
 				switch_set_flag(dtb, SFLAG_INFO);
 				return SWITCH_STATUS_BREAK;
-			}
-			break;
-		case '7':
-			dtb->speed = TTS_MEAN_SPEED;
-			switch_core_speech_numeric_param_tts(dtb->sh, "speech/rate", dtb->speed);
-			switch_set_flag(dtb, SFLAG_INFO);
-			return SWITCH_STATUS_BREAK;
-		case '8':
-			if (dtb->speed > 80) {
-				dtb->speed -= 30;
+				break;
+			case '9':
+				switch_core_speech_text_param_tts(dtb->sh, "voice", dtb->voice);
+				switch_set_flag(dtb, SFLAG_INFO);
+				return SWITCH_STATUS_BREAK;
+				break;
+			case '2':
+				if (dtb->speed < 260) {
+					dtb->speed += 30;
+					switch_core_speech_numeric_param_tts(dtb->sh, "speech/rate", dtb->speed);
+					switch_set_flag(dtb, SFLAG_INFO);
+					return SWITCH_STATUS_BREAK;
+				}
+				break;
+			case '7':
+				dtb->speed = TTS_MEAN_SPEED;
 				switch_core_speech_numeric_param_tts(dtb->sh, "speech/rate", dtb->speed);
 				switch_set_flag(dtb, SFLAG_INFO);
 				return SWITCH_STATUS_BREAK;
+			case '8':
+				if (dtb->speed > 80) {
+					dtb->speed -= 30;
+					switch_core_speech_numeric_param_tts(dtb->sh, "speech/rate", dtb->speed);
+					switch_set_flag(dtb, SFLAG_INFO);
+					return SWITCH_STATUS_BREAK;
+				}
+				break;
+			case '0':
+				switch_set_flag(dtb, SFLAG_INSTRUCT);
+				return SWITCH_STATUS_BREAK;
 			}
-			break;
-		case '0':
-			switch_set_flag(dtb, SFLAG_INSTRUCT);
-			return SWITCH_STATUS_BREAK;
 		}
-	}
 		break;
 	default:
 		break;
@@ -159,9 +158,9 @@
 	switch_channel_t *channel;
 	switch_status_t status;
 	const char *err = NULL;
-	struct dtmf_buffer dtb = {0};
+	struct dtmf_buffer dtb = { 0 };
 	switch_xml_t xml = NULL, item, xchannel = NULL;
-	struct rss_entry entries[TTS_MAX_ENTRIES] = {{0}};
+	struct rss_entry entries[TTS_MAX_ENTRIES] = { {0} };
 	uint32_t i = 0;
 	char *title_txt = "", *description_txt = "", *rights_txt = "";
 	switch_codec_t speech_codec, *codec = switch_core_session_get_read_codec(session);
@@ -169,31 +168,32 @@
 	char *voice = TTS_DEFAULT_VOICE;
 	char *timer_name = NULL;
 	switch_speech_handle_t sh;
-    switch_speech_flag_t flags = SWITCH_SPEECH_FLAG_NONE;
+	switch_speech_flag_t flags = SWITCH_SPEECH_FLAG_NONE;
 	switch_core_thread_session_t thread_session;
 	uint32_t rate, interval = 20;
 	int stream_id = 0;
-	switch_timer_t timer = {0}, *timerp = NULL;
+	switch_timer_t timer = { 0 }, *timerp = NULL;
 	uint32_t last;
 	char *mydata = NULL;
 	char *filename = NULL;
-	char *argv[3], *feed_list[TTS_MAX_ENTRIES] = {0} , *feed_names[TTS_MAX_ENTRIES] = {0};
+	char *argv[3], *feed_list[TTS_MAX_ENTRIES] = { 0 }, *feed_names[TTS_MAX_ENTRIES] = {
+	0};
 	int argc, feed_index = 0;
 	char *cf = "rss.conf";
-    switch_xml_t cfg, cxml, feeds, feed;
+	switch_xml_t cfg, cxml, feeds, feed;
 	char buf[1024];
 	int32_t jumpto = -1;
 	uint32_t matches = 0;
-	switch_input_args_t args = {0};
+	switch_input_args_t args = { 0 };
 
 	channel = switch_core_session_get_channel(session);
-    assert(channel != NULL);
+	assert(channel != NULL);
 
 
 	if (!(cxml = switch_xml_open_cfg(cf, &cfg, NULL))) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
-        return;
-    }
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
+		return;
+	}
 
 	if ((feeds = switch_xml_child(cfg, "feeds"))) {
 		for (feed = switch_xml_child(feeds, "feed"); feed; feed = feed->next) {
@@ -210,14 +210,14 @@
 	}
 
 	switch_xml_free(cxml);
-	
+
 	switch_channel_answer(channel);
 
 
 
 	if (!switch_strlen_zero(data)) {
 		if ((mydata = switch_core_session_strdup(session, data))) {
-			argc = switch_separate_string(mydata, ' ', argv, sizeof(argv)/sizeof(argv[0]));
+			argc = switch_separate_string(mydata, ' ', argv, sizeof(argv) / sizeof(argv[0]));
 
 			if (argv[0]) {
 				engine = argv[0];
@@ -244,24 +244,17 @@
 	}
 
 	memset(&sh, 0, sizeof(sh));
-	if (switch_core_speech_open(&sh,
-								engine,
-								voice,
-								rate,
-								&flags,
-								switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
+	if (switch_core_speech_open(&sh, engine, voice, rate, &flags, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid TTS module!\n");
 		return;
 	}
-	
+
 	if (switch_core_codec_init(&speech_codec,
 							   "L16",
 							   NULL,
-							   (int)rate,
+							   (int) rate,
 							   interval,
-							   1,
-							   SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
-							   NULL,
+							   1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
 							   switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activated\n");
 	} else {
@@ -270,16 +263,16 @@
 		switch_core_speech_close(&sh, &flags);
 		return;
 	}
-	
+
 	if (timer_name) {
-		if (switch_core_timer_init(&timer, timer_name, interval, (int)(rate / 50), switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
+		if (switch_core_timer_init(&timer, timer_name, interval, (int) (rate / 50), switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "setup timer failed!\n");
 			switch_core_codec_destroy(&speech_codec);
 			flags = 0;
 			switch_core_speech_close(&sh, &flags);
 			return;
 		}
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "setup timer success %u bytes per %d ms!\n", (rate / 50)*2, interval);
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "setup timer success %u bytes per %d ms!\n", (rate / 50) * 2, interval);
 
 		/* start a thread to absorb incoming audio */
 		for (stream_id = 0; stream_id < switch_core_session_get_stream_count(session); stream_id++) {
@@ -292,7 +285,7 @@
 	while (switch_channel_ready(channel)) {
 		int32_t len = 0, idx = 0;
 		char cmd[3];
-	main_menu:
+	  main_menu:
 		filename = NULL;
 		len = idx = 0;
 		*cmd = '\0';
@@ -304,36 +297,29 @@
 		} else {
 			switch_core_speech_flush_tts(&sh);
 #ifdef MATCH_COUNT
-			snprintf(buf + len, sizeof(buf) - len, 
+			snprintf(buf + len, sizeof(buf) - len,
 					 ",<break time=\"500ms\"/>Main Menu. <break time=\"600ms\"/> "
-					 "Select one of the following news sources, or press 0 to exit. "
-					 ",<break time=\"600ms\"/>");
+					 "Select one of the following news sources, or press 0 to exit. " ",<break time=\"600ms\"/>");
 #else
-			snprintf(buf + len, sizeof(buf) - len, 
+			snprintf(buf + len, sizeof(buf) - len,
 					 ",<break time=\"500ms\"/>Main Menu. <break time=\"600ms\"/> "
-					 "Select one of the following news sources, followed by the pound key or press 0 to exit. "
-					 ",<break time=\"600ms\"/>");
+					 "Select one of the following news sources, followed by the pound key or press 0 to exit. " ",<break time=\"600ms\"/>");
 #endif
-			len = (int32_t)strlen(buf);
+			len = (int32_t) strlen(buf);
 
 			for (idx = 0; idx < feed_index; idx++) {
 				snprintf(buf + len, sizeof(buf) - len, "%d: %s. <break time=\"600ms\"/>", idx + 1, feed_names[idx]);
-				len = (int32_t)strlen(buf);
+				len = (int32_t) strlen(buf);
 			}
 
 
 			snprintf(buf + len, sizeof(buf) - len, "<break time=\"2000ms\"/>");
-			len = (int32_t)strlen(buf);
+			len = (int32_t) strlen(buf);
 
 			args.input_callback = NULL;
 			args.buf = cmd;
 			args.buflen = sizeof(cmd);
-			status = switch_ivr_speak_text_handle(session,
-												  &sh,
-												  &speech_codec,
-												  timerp,
-												  buf,
-												  &args);
+			status = switch_ivr_speak_text_handle(session, &sh, &speech_codec, timerp, buf, &args);
 			if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
 				goto finished;
 			}
@@ -346,51 +332,46 @@
 				break;
 			}
 
-			if ((p=strchr(cmd, '#'))) {
+			if ((p = strchr(cmd, '#'))) {
 				*p = '\0';
 #ifdef MATCH_COUNT
 				/* Hmmm... I know there are no more matches so I don't *need* them to press pound but 
 				   I already told them to press it.  Will this confuse people or not?  Let's make em press 
 				   pound unless this define is enabled for now.
-				*/
+				 */
 			} else if (match_count(cmd, feed_index) > 1) {
 #else
 			} else {
 #endif
 				char term;
 				char *cp;
-				int blen = sizeof(cmd) - (int)strlen(cmd);
+				int blen = sizeof(cmd) - (int) strlen(cmd);
 
 				cp = cmd + blen;
 				switch_ivr_collect_digits_count(session, cp, blen, blen, "#", &term, 5000);
 			}
-			
+
 			i = atoi(cmd) - 1;
 
 			if (i > -1 && i < feed_index) {
 				filename = feed_list[i];
 			} else if (matches > 1) {
-				
+
 			} else {
 				args.input_callback = NULL;
 				args.buf = NULL;
 				args.buflen = 0;
-				status = switch_ivr_speak_text_handle(session,
-													  &sh,
-													  &speech_codec,
-													  timerp,
-													  "I'm sorry. That is an Invalid Selection. ",
-													  &args);
+				status = switch_ivr_speak_text_handle(session, &sh, &speech_codec, timerp, "I'm sorry. That is an Invalid Selection. ", &args);
 				if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
 					goto finished;
 				}
 			}
 		}
-	
+
 		if (!filename) {
 			continue;
 		}
-		
+
 
 
 		if (!(xml = switch_xml_parse_file(filename))) {
@@ -411,7 +392,7 @@
 			if ((title = switch_xml_child(xchannel, "title"))) {
 				title_txt = title->txt;
 			}
-			
+
 			if ((description = switch_xml_child(xchannel, "description"))) {
 				description_txt = description->txt;
 			}
@@ -444,19 +425,19 @@
 			if ((title = switch_xml_child(item, "title"))) {
 				entries[i].title_txt = title->txt;
 			}
-		
+
 			if ((description = switch_xml_child(item, "description"))) {
 				char *t, *e;
 				entries[i].description_txt = description->txt;
-				for(;;) {
+				for (;;) {
 					if (!(t = strchr(entries[i].description_txt, '<'))) {
 						break;
 					}
 					if (!(e = strchr(t, '>'))) {
 						break;
 					}
-				
-					memset(t, 32, ++e-t);
+
+					memset(t, 32, ++e - t);
 				}
 			}
 
@@ -471,9 +452,8 @@
 			if (entries[i].description_txt && (p = strchr(entries[i].description_txt, '<'))) {
 				*p = '\0';
 			}
-
 #ifdef _STRIP_SOME_CHARS_
-			for(p = entries[i].description_txt; *p; p++) {
+			for (p = entries[i].description_txt; *p; p++) {
 				if (*p == '\'' || *p == '"' || *p == ':') {
 					*p = ' ';
 				}
@@ -493,17 +473,13 @@
 			switch_strftime(date, &retsize, sizeof(date), "%I:%M %p", &tm);
 
 
-			snprintf(buf, sizeof(buf), ",<break time=\"500ms\"/>%s. %s. %s. local time: %s, Press 0 for options, 5 to change voice, or pound to return to the main menu. ", 
+			snprintf(buf, sizeof(buf),
+					 ",<break time=\"500ms\"/>%s. %s. %s. local time: %s, Press 0 for options, 5 to change voice, or pound to return to the main menu. ",
 					 title_txt, description_txt, rights_txt, date);
 			args.input_callback = NULL;
 			args.buf = cmd;
 			args.buflen = sizeof(cmd);
-			status = switch_ivr_speak_text_handle(session,
-												  &sh,
-												  &speech_codec,
-												  timerp,
-												  buf,
-												  &args);
+			status = switch_ivr_speak_text_handle(session, &sh, &speech_codec, timerp, buf, &args);
 			if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
 				goto finished;
 			}
@@ -519,7 +495,7 @@
 			}
 		}
 
-		for(last = 0; last < TTS_MAX_ENTRIES; last++) {
+		for (last = 0; last < TTS_MAX_ENTRIES; last++) {
 			if (!entries[last].inuse) {
 				last--;
 				break;
@@ -531,8 +507,8 @@
 		dtb.speed = TTS_MEAN_SPEED;
 		switch_set_flag(&dtb, SFLAG_INFO);
 		switch_copy_string(dtb.voice, voice, sizeof(dtb.voice));
-		while(entries[0].inuse && switch_channel_ready(channel)) {
-			while(switch_channel_ready(channel)) {
+		while (entries[0].inuse && switch_channel_ready(channel)) {
+			while (switch_channel_ready(channel)) {
 				uint8_t cont = 0;
 
 				if (dtb.index >= TTS_MAX_ENTRIES) {
@@ -556,13 +532,8 @@
 					}
 					if (switch_test_flag(&dtb, SFLAG_INFO)) {
 						switch_clear_flag(&dtb, SFLAG_INFO);
-						snprintf(buf + len, sizeof(buf) - len,
-								 "%s %s. I am speaking at %u words per minute. ",
-								 sh.engine,
-								 sh.voice,
-								 dtb.speed
-								 );
-						len = (uint32_t)strlen(buf);
+						snprintf(buf + len, sizeof(buf) - len, "%s %s. I am speaking at %u words per minute. ", sh.engine, sh.voice, dtb.speed);
+						len = (uint32_t) strlen(buf);
 					}
 
 					if (switch_test_flag(&dtb, SFLAG_INSTRUCT)) {
@@ -577,33 +548,28 @@
 								 "To hear these options again, press zero or press pound to return to the main menu. ");
 					} else {
 						snprintf(buf + len, sizeof(buf) - len, "Story %d. ", dtb.index + 1);
-						len = (uint32_t)strlen(buf);
+						len = (uint32_t) strlen(buf);
 
 						if (entries[dtb.index].subject_txt) {
 							snprintf(buf + len, sizeof(buf) - len, "Subject: %s. ", entries[dtb.index].subject_txt);
-							len = (uint32_t)strlen(buf);
+							len = (uint32_t) strlen(buf);
 						}
-				
+
 						if (entries[dtb.index].dept_txt) {
 							snprintf(buf + len, sizeof(buf) - len, "From the %s department. ", entries[dtb.index].dept_txt);
-							len = (uint32_t)strlen(buf);
+							len = (uint32_t) strlen(buf);
 						}
 
 						if (entries[dtb.index].title_txt) {
 							snprintf(buf + len, sizeof(buf) - len, "%s", entries[dtb.index].title_txt);
-							len = (uint32_t)strlen(buf);
+							len = (uint32_t) strlen(buf);
 						}
 					}
 					switch_core_speech_flush_tts(&sh);
 					args.input_callback = on_dtmf;
 					args.buf = &dtb;
 					args.buflen = sizeof(dtb);
-					status = switch_ivr_speak_text_handle(session,
-														  &sh,
-														  &speech_codec,
-														  timerp,
-														  buf,
-														  &args);
+					status = switch_ivr_speak_text_handle(session, &sh, &speech_codec, timerp, buf, &args);
 					if (status == SWITCH_STATUS_BREAK) {
 						continue;
 					} else if (status != SWITCH_STATUS_SUCCESS) {
@@ -614,17 +580,12 @@
 						cont = 0;
 						continue;
 					}
-					
+
 					if (entries[dtb.index].description_txt) {
 						args.input_callback = on_dtmf;
 						args.buf = &dtb;
 						args.buflen = sizeof(dtb);
-						status = switch_ivr_speak_text_handle(session,
-															  &sh,
-															  &speech_codec,
-															  timerp,
-															  entries[dtb.index].description_txt,
-															  &args);
+						status = switch_ivr_speak_text_handle(session, &sh, &speech_codec, timerp, entries[dtb.index].description_txt, &args);
 					}
 					if (status == SWITCH_STATUS_BREAK) {
 						continue;
@@ -638,7 +599,7 @@
 		}
 	}
 
- finished:
+  finished:
 	switch_core_speech_close(&sh, &flags);
 	switch_core_codec_destroy(&speech_codec);
 
@@ -659,7 +620,7 @@
 	/*.application_function */ rss_function,
 	NULL, NULL, NULL,
 	/* flags */ SAF_NONE,
-	/*.next*/ NULL
+	/*.next */ NULL
 };
 
 

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/asr_tts/mod_cepstral/mod_cepstral.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/asr_tts/mod_cepstral/mod_cepstral.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/asr_tts/mod_cepstral/mod_cepstral.c	Fri Mar 30 12:19:18 2007
@@ -69,23 +69,23 @@
 
 
 /* This callback caches the audio in the buffer */
-static swift_result_t write_audio(swift_event *event, swift_event_t type, void *udata)
+static swift_result_t write_audio(swift_event * event, swift_event_t type, void *udata)
 {
 	cepstral_t *cepstral;
-    swift_event_t rv = SWIFT_SUCCESS;
-    void *buf = NULL;
-    int len = 0, i = 0;
-	
+	swift_event_t rv = SWIFT_SUCCESS;
+	void *buf = NULL;
+	int len = 0, i = 0;
+
 	cepstral = udata;
 	assert(cepstral != NULL);
-	
+
 	if (!cepstral->port || cepstral->done || cepstral->done_gen) {
-		return  SWIFT_UNKNOWN_ERROR;
+		return SWIFT_UNKNOWN_ERROR;
 	}
 
 	/* Only proceed when we have success */
-    if (!SWIFT_FAILED((rv = swift_event_get_audio(event, &buf, &len)))) {
-		while(!cepstral->done) {
+	if (!SWIFT_FAILED((rv = swift_event_get_audio(event, &buf, &len)))) {
+		while (!cepstral->done) {
 			switch_mutex_lock(cepstral->audio_lock);
 			if (switch_buffer_write(cepstral->audio_buffer, buf, len) > 0) {
 				switch_mutex_unlock(cepstral->audio_lock);
@@ -100,7 +100,7 @@
 					}
 				}
 			}
-			
+
 		}
 	} else {
 		cepstral->done = 1;
@@ -109,8 +109,8 @@
 	if (cepstral->done) {
 		rv = SWIFT_UNKNOWN_ERROR;
 	}
-	
-    return rv;
+
+	return rv;
 }
 
 static switch_status_t cepstral_speech_open(switch_speech_handle_t *sh, char *voice_name, int rate, switch_speech_flag_t *flags)
@@ -143,7 +143,7 @@
 		goto all_done;
 	}
 
-		
+
 	if (voice_name && SWIFT_FAILED(swift_port_set_voice_by_name(cepstral->port, voice_name))) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid voice %s!\n", voice_name);
 		voice_name = NULL;
@@ -157,7 +157,7 @@
 		}
 
 		/* Set the voice found by find_first_voice() as the port's current voice */
-		if ( SWIFT_FAILED(swift_port_set_voice(cepstral->port, cepstral->voice)) ) {
+		if (SWIFT_FAILED(swift_port_set_voice(cepstral->port, cepstral->voice))) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to set voice.\n");
 			goto all_done;
 		}
@@ -173,8 +173,8 @@
 
 	sh->private_info = cepstral;
 	return SWITCH_STATUS_SUCCESS;
-	
- all_done:
+
+  all_done:
 	return SWITCH_STATUS_FALSE;
 }
 
@@ -185,18 +185,19 @@
 	assert(sh != NULL);
 	cepstral = sh->private_info;
 	assert(cepstral != NULL);
-	
+
 
 	cepstral->done = 1;
 	cepstral->done_gen = 1;
 	swift_port_stop(cepstral->port, SWIFT_ASYNC_ANY, SWIFT_EVENT_NOW);
 	/* Close the Swift Port and Engine */
-	if (NULL != cepstral->port) swift_port_close(cepstral->port);
+	if (NULL != cepstral->port)
+		swift_port_close(cepstral->port);
 	//if (NULL != cepstral->engine) swift_engine_close(cepstral->engine);
 
 	cepstral->port = NULL;
 	//cepstral->engine = NULL;
-	
+
 	switch_buffer_destroy(&cepstral->audio_buffer);
 
 	return SWITCH_STATUS_SUCCESS;
@@ -206,7 +207,7 @@
 {
 	cepstral_t *cepstral;
 	const char *fp = "file:";
-	int len = (int)strlen(fp);
+	int len = (int) strlen(fp);
 
 	assert(sh != NULL);
 	cepstral = sh->private_info;
@@ -214,7 +215,7 @@
 
 	cepstral->done_gen = 0;
 	cepstral->done = 0;
-	
+
 	cepstral->tts_stream = NULL;
 
 	if (!strncasecmp(text, fp, len)) {
@@ -222,17 +223,17 @@
 		if (switch_strlen_zero(text)) {
 			return SWITCH_STATUS_FALSE;
 		}
-		swift_port_speak_file(cepstral->port, text, NULL, &cepstral->tts_stream, NULL); 
+		swift_port_speak_file(cepstral->port, text, NULL, &cepstral->tts_stream, NULL);
 	} else {
-        char *to_say;
+		char *to_say;
 		if (switch_strlen_zero(text)) {
 			return SWITCH_STATUS_FALSE;
 		}
 
-        if ((to_say = switch_mprintf("<break time=\"500ms\"/> %s <break time=\"500ms\"/>", text))) {
-            swift_port_speak_text(cepstral->port, to_say, 0, NULL, &cepstral->tts_stream, NULL); 
-            switch_safe_free(to_say);
-        }
+		if ((to_say = switch_mprintf("<break time=\"500ms\"/> %s <break time=\"500ms\"/>", text))) {
+			swift_port_speak_text(cepstral->port, to_say, 0, NULL, &cepstral->tts_stream, NULL);
+			switch_safe_free(to_say);
+		}
 	}
 
 	return SWITCH_STATUS_SUCCESS;
@@ -243,10 +244,10 @@
 	cepstral_t *cepstral;
 
 	cepstral = sh->private_info;
-    assert(cepstral != NULL);
+	assert(cepstral != NULL);
 
 	cepstral->done_gen = 1;
-    cepstral->done = 1;
+	cepstral->done = 1;
 	if (cepstral->audio_buffer) {
 		switch_mutex_lock(cepstral->audio_lock);
 		switch_buffer_zero(cepstral->audio_buffer);
@@ -255,11 +256,7 @@
 	swift_port_stop(cepstral->port, SWIFT_ASYNC_ANY, SWIFT_EVENT_NOW);
 }
 
-static switch_status_t cepstral_speech_read_tts(switch_speech_handle_t *sh,
-												void *data,
-												size_t *datalen,
-												uint32_t *rate,
-												switch_speech_flag_t *flags) 
+static switch_status_t cepstral_speech_read_tts(switch_speech_handle_t *sh, void *data, size_t *datalen, uint32_t * rate, switch_speech_flag_t *flags)
 {
 	cepstral_t *cepstral;
 	size_t desired = *datalen;
@@ -270,7 +267,7 @@
 	cepstral = sh->private_info;
 	assert(cepstral != NULL);
 
-	while(!cepstral->done) {
+	while (!cepstral->done) {
 		if (!cepstral->done_gen) {
 			int check = swift_port_status(cepstral->port, cepstral->tts_stream);
 
@@ -282,8 +279,8 @@
 		switch_mutex_lock(cepstral->audio_lock);
 		used = switch_buffer_inuse(cepstral->audio_buffer);
 		switch_mutex_unlock(cepstral->audio_lock);
-		
-		
+
+
 		if (!used && cepstral->done_gen) {
 
 			status = SWITCH_STATUS_BREAK;
@@ -304,15 +301,15 @@
 			switch_yield(1000);
 			continue;
 		}
-		
+
 		/* There is enough, read it and return */
 		switch_mutex_lock(cepstral->audio_lock);
 		*datalen = switch_buffer_read(cepstral->audio_buffer, data, desired);
 		if (padding) {
 			size_t x = 0;
 			unsigned char *p = data;
-			
-			for(x = 0; x < padding; x++) {
+
+			for (x = 0; x < padding; x++) {
 				*(p + x) = 0;
 				(*datalen)++;
 			}
@@ -323,7 +320,7 @@
 
 		break;
 	}
-	
+
 	return status;
 }
 
@@ -338,7 +335,7 @@
 		char *voice_name = val;
 		if (!strcasecmp(voice_name, "next")) {
 			if ((cepstral->voice = swift_port_find_next_voice(cepstral->port))) {
-				if ( SWIFT_FAILED(swift_port_set_voice(cepstral->port, cepstral->voice)) ) {
+				if (SWIFT_FAILED(swift_port_set_voice(cepstral->port, cepstral->voice))) {
 					cepstral->done = cepstral->done_gen = 1;
 					return;
 				}
@@ -354,22 +351,22 @@
 		}
 
 		if (!voice_name) {
-            /* Find the first voice on the system */
-            if ((cepstral->voice = swift_port_find_first_voice(cepstral->port, NULL, NULL)) == NULL) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to find any voices!\n");
+			/* Find the first voice on the system */
+			if ((cepstral->voice = swift_port_find_first_voice(cepstral->port, NULL, NULL)) == NULL) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to find any voices!\n");
 				cepstral->done = cepstral->done_gen = 1;
 				return;
-            }
+			}
 
-            /* Set the voice found by find_first_voice() as the port's current voice */
-            if ( SWIFT_FAILED(swift_port_set_voice(cepstral->port, cepstral->voice)) ) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to set voice.\n");
+			/* Set the voice found by find_first_voice() as the port's current voice */
+			if (SWIFT_FAILED(swift_port_set_voice(cepstral->port, cepstral->voice))) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to set voice.\n");
 				cepstral->done = cepstral->done_gen = 1;
 				return;
-            }
+			}
 
 			voice_name = (char *) swift_voice_get_attribute(cepstral->voice, "name");
-        } 
+		}
 
 		if (voice_name) {
 			switch_copy_string(sh->voice, voice_name, sizeof(sh->voice));
@@ -405,15 +402,15 @@
 }
 
 static const switch_speech_interface_t cepstral_speech_interface = {
-	/*.interface_name*/			"cepstral",
-	/*.speech_open*/			cepstral_speech_open,
-	/*.speech_close*/			cepstral_speech_close,
-	/*.speech_feed_tts*/		cepstral_speech_feed_tts,
-	/*.speech_read_tts*/		cepstral_speech_read_tts,
-	/*.speech_flush_tts*/		cepstral_speech_flush_tts,
-	/*.speech_text_param_tts*/  cepstral_text_param_tts,
-	/*.speech_numeric_param_tts*/  cepstral_numeric_param_tts,
-	/*.speech_numeric_param_tts*/  cepstral_float_param_tts
+	/*.interface_name */ "cepstral",
+	/*.speech_open */ cepstral_speech_open,
+	/*.speech_close */ cepstral_speech_close,
+	/*.speech_feed_tts */ cepstral_speech_feed_tts,
+	/*.speech_read_tts */ cepstral_speech_read_tts,
+	/*.speech_flush_tts */ cepstral_speech_flush_tts,
+	/*.speech_text_param_tts */ cepstral_text_param_tts,
+	/*.speech_numeric_param_tts */ cepstral_numeric_param_tts,
+	/*.speech_numeric_param_tts */ cepstral_float_param_tts
 };
 
 static const switch_loadable_module_interface_t cepstral_module_interface = {
@@ -433,11 +430,11 @@
 {
 
 	/* Open the Swift TTS Engine */
-	if ( SWIFT_FAILED(engine = swift_engine_open(NULL)) ) {
+	if (SWIFT_FAILED(engine = swift_engine_open(NULL))) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to open Swift Engine.");
 		return SWITCH_STATUS_GENERR;
 	}
-	
+
 	/* connect my internal structure to the blank pointer passed to me */
 	*module_interface = &cepstral_module_interface;
 

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_amr/mod_amr.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_amr/mod_amr.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_amr/mod_amr.c	Fri Mar 30 12:19:18 2007
@@ -30,7 +30,7 @@
  *
  * mod_amr.c -- GSM-AMR Codec Module
  *
- */  
+ */
 #include "switch.h"
 static const char modname[] = "mod_amr";
 
@@ -113,15 +113,14 @@
 
 #endif
 
-static switch_status_t switch_amr_init(switch_codec_t *codec, switch_codec_flag_t flags,
-									  const switch_codec_settings_t *codec_settings) 
+static switch_status_t switch_amr_init(switch_codec_t *codec, switch_codec_flag_t flags, const switch_codec_settings_t *codec_settings)
 {
 
 #ifdef AMR_PASSTHROUGH
 	codec->flags |= SWITCH_CODEC_FLAG_PASSTHROUGH;
-    if (codec->fmtp_in) {
-        codec->fmtp_out = switch_core_strdup(codec->memory_pool, codec->fmtp_in);
-    }
+	if (codec->fmtp_in) {
+		codec->fmtp_out = switch_core_strdup(codec->memory_pool, codec->fmtp_in);
+	}
 	return SWITCH_STATUS_SUCCESS;
 #else
 	struct amr_context *context = NULL;
@@ -139,10 +138,10 @@
 
 		if (codec->fmtp_in) {
 			argc = switch_separate_string(codec->fmtp_in, ';', argv, (sizeof(argv) / sizeof(argv[0])));
-			for(x = 0; x < argc; x++) {
+			for (x = 0; x < argc; x++) {
 				char *data = argv[x];
 				char *arg;
-				while(*data && *data == ' ') {
+				while (*data && *data == ' ') {
 					data++;
 				}
 				if ((arg = strchr(data, '='))) {
@@ -171,16 +170,16 @@
 					} else if (!strcasecmp(data, "mode-change-period")) {
 						context->change_period = atoi(arg);
 					} else if (!strcasecmp(data, "ptime")) {
-						context->ptime = (switch_byte_t)atoi(arg);
+						context->ptime = (switch_byte_t) atoi(arg);
 					} else if (!strcasecmp(data, "channels")) {
-						context->channels = (switch_byte_t)atoi(arg);
+						context->channels = (switch_byte_t) atoi(arg);
 					} else if (!strcasecmp(data, "maxptime")) {
-						context->max_ptime = (switch_byte_t)atoi(arg);
+						context->max_ptime = (switch_byte_t) atoi(arg);
 					} else if (!strcasecmp(data, "mode-set")) {
 						int y, m_argc;
 						char *m_argv[7];
 						m_argc = switch_separate_string(arg, ',', m_argv, (sizeof(m_argv) / sizeof(m_argv[0])));
-						for(y = 0; y < m_argc; y++) {
+						for (y = 0; y < m_argc; y++) {
 							context->enc_modes |= (1 << atoi(m_argv[y]));
 						}
 					}
@@ -192,7 +191,7 @@
 		if (context->enc_modes) {
 			for (i = 7; i > -1; i++) {
 				if (context->enc_modes & (1 << i)) {
-					context->enc_mode = (switch_byte_t)i;
+					context->enc_mode = (switch_byte_t) i;
 					break;
 				}
 			}
@@ -201,10 +200,10 @@
 		if (!context->enc_mode) {
 			context->enc_mode = globals.default_bitrate;
 		}
-		
+
 		snprintf(fmtptmp, sizeof(fmtptmp), "octet-align=%d; mode-set=%d", switch_test_flag(context, AMR_OPT_OCTET_ALIGN) ? 1 : 0, context->enc_mode);
 		codec->fmtp_out = switch_core_strdup(codec->memory_pool, fmtptmp);
-		
+
 		context->enc_mode = AMR_DEFAULT_BITRATE;
 		context->encoder_state = NULL;
 		context->decoder_state = NULL;
@@ -224,7 +223,7 @@
 #endif
 }
 
-static switch_status_t switch_amr_destroy(switch_codec_t *codec) 
+static switch_status_t switch_amr_destroy(switch_codec_t *codec)
 {
 #ifndef AMR_PASSTHROUGH
 	struct amr_context *context = codec->private_info;
@@ -240,45 +239,35 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t switch_amr_encode(switch_codec_t *codec, 
-										switch_codec_t *other_codec, 
-										void *decoded_data,
-
-										uint32_t decoded_data_len, 
-										uint32_t decoded_rate, 
-										void *encoded_data,
-
-										uint32_t *encoded_data_len, 
-										uint32_t *encoded_rate, 
-										unsigned int *flag) 
+static switch_status_t switch_amr_encode(switch_codec_t *codec,
+										 switch_codec_t *other_codec,
+										 void *decoded_data,
+										 uint32_t decoded_data_len,
+										 uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate,
+										 unsigned int *flag)
 {
 #ifdef AMR_PASSTHROUGH
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "This codec is only usable in passthrough mode!\n");
 	return SWITCH_STATUS_FALSE;
 #else
 	struct amr_context *context = codec->private_info;
-	
+
 	if (!context) {
 		return SWITCH_STATUS_FALSE;
 	}
-	
-	*encoded_data_len = Encoder_Interface_Encode( context->encoder_state, context->enc_mode, (int16_t *)decoded_data, (switch_byte_t *) encoded_data, 0);
+
+	*encoded_data_len = Encoder_Interface_Encode(context->encoder_state, context->enc_mode, (int16_t *) decoded_data, (switch_byte_t *) encoded_data, 0);
 
 	return SWITCH_STATUS_SUCCESS;
 #endif
 }
 
-static switch_status_t switch_amr_decode(switch_codec_t *codec, 
-										switch_codec_t *other_codec, 
-										void *encoded_data,
-
-										uint32_t encoded_data_len, 
-										uint32_t encoded_rate, 
-										void *decoded_data,
-
-										uint32_t *decoded_data_len, 
-										uint32_t *decoded_rate, 
-										unsigned int *flag) 
+static switch_status_t switch_amr_decode(switch_codec_t *codec,
+										 switch_codec_t *other_codec,
+										 void *encoded_data,
+										 uint32_t encoded_data_len,
+										 uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate,
+										 unsigned int *flag)
 {
 #ifdef AMR_PASSTHROUGH
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "This codec is only usable in passthrough mode!\n");
@@ -290,51 +279,50 @@
 		return SWITCH_STATUS_FALSE;
 	}
 
-	Decoder_Interface_Decode(context->decoder_state, (unsigned char *)encoded_data, (int16_t *)decoded_data, 0);
+	Decoder_Interface_Decode(context->decoder_state, (unsigned char *) encoded_data, (int16_t *) decoded_data, 0);
 	*decoded_data_len = codec->implementation->bytes_per_frame;
 
 	return SWITCH_STATUS_SUCCESS;
 #endif
 }
 
-/* Registration */ 
+/* Registration */
 
-static const switch_codec_implementation_t amr_implementation = { 
-	/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO, 
-	/*.ianacode */ 96, 
-	/*.iananame */ "AMR", 
+static const switch_codec_implementation_t amr_implementation = {
+	/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
+	/*.ianacode */ 96,
+	/*.iananame */ "AMR",
 	/*.fmtp */ "octet-align=0",
-	/*.samples_per_second */ 8000, 
-	/*.bits_per_second */ 0, 
-	/*.microseconds_per_frame */ 20000, 
-	/*.samples_per_frame */ 160, 
+	/*.samples_per_second */ 8000,
+	/*.bits_per_second */ 0,
+	/*.microseconds_per_frame */ 20000,
+	/*.samples_per_frame */ 160,
 	/*.bytes_per_frame */ 320,
-	/*.encoded_bytes_per_frame */ 0, 
-	/*.number_of_channels */ 1, 
-	/*.pref_frames_per_packet */ 1, 
-	/*.max_frames_per_packet */ 1, 
-	/*.init */ switch_amr_init, 
-	/*.encode */ switch_amr_encode, 
-	/*.decode */ switch_amr_decode, 
-	/*.destroy */ switch_amr_destroy, 
+	/*.encoded_bytes_per_frame */ 0,
+	/*.number_of_channels */ 1,
+	/*.pref_frames_per_packet */ 1,
+	/*.max_frames_per_packet */ 1,
+	/*.init */ switch_amr_init,
+	/*.encode */ switch_amr_encode,
+	/*.decode */ switch_amr_decode,
+	/*.destroy */ switch_amr_destroy,
 };
 
-static const switch_codec_interface_t amr_codec_interface = { 
-	/*.interface_name */ "GSM-AMR", 
-	/*.implementations */ &amr_implementation, 
+static const switch_codec_interface_t amr_codec_interface = {
+	/*.interface_name */ "GSM-AMR",
+	/*.implementations */ &amr_implementation,
 };
 
-static switch_loadable_module_interface_t amr_module_interface = { 
-	/*.module_name */ modname, 
-	/*.endpoint_interface */ NULL, 
-	/*.timer_interface */ NULL, 
-	/*.dialplan_interface */ NULL, 
-	/*.codec_interface */ &amr_codec_interface, 
-	/*.application_interface */ NULL 
+static switch_loadable_module_interface_t amr_module_interface = {
+	/*.module_name */ modname,
+	/*.endpoint_interface */ NULL,
+	/*.timer_interface */ NULL,
+	/*.dialplan_interface */ NULL,
+	/*.codec_interface */ &amr_codec_interface,
+	/*.application_interface */ NULL
 };
 
-SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
-													 char *filename)
+SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
 {
 #ifndef AMR_PASSTHROUGH
 	char *cf = "amr.conf";
@@ -349,17 +337,16 @@
 				char *var = (char *) switch_xml_attr_soft(param, "name");
 				char *val = (char *) switch_xml_attr_soft(param, "value");
 				if (!strcasecmp(var, "default-bitrate")) {
-					globals.default_bitrate = (switch_byte_t)atoi(val);
+					globals.default_bitrate = (switch_byte_t) atoi(val);
 				}
 			}
 		}
 	}
-
 #endif
 
-	/* connect my internal structure to the blank pointer passed to me */ 
+	/* connect my internal structure to the blank pointer passed to me */
 	*module_interface = &amr_module_interface;
 
-	/* indicate that the module should continue to be loaded */ 
+	/* indicate that the module should continue to be loaded */
 	return SWITCH_STATUS_SUCCESS;
 }

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_g711/mod_g711.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_g711/mod_g711.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_g711/mod_g711.c	Fri Mar 30 12:19:18 2007
@@ -36,8 +36,7 @@
 static const char modname[] = "mod_g711";
 
 
-static switch_status_t switch_g711u_init(switch_codec_t *codec, switch_codec_flag_t flags,
-									   const switch_codec_settings_t *codec_settings)
+static switch_status_t switch_g711u_init(switch_codec_t *codec, switch_codec_flag_t flags, const switch_codec_settings_t *codec_settings)
 {
 	int encoding, decoding;
 
@@ -53,12 +52,11 @@
 
 
 static switch_status_t switch_g711u_encode(switch_codec_t *codec,
-										 switch_codec_t *other_codec,
-										 void *decoded_data,
-										 uint32_t decoded_data_len,
-										 uint32_t decoded_rate,
-										 void *encoded_data,
-										 uint32_t *encoded_data_len, uint32_t *encoded_rate, unsigned int *flag)
+										   switch_codec_t *other_codec,
+										   void *decoded_data,
+										   uint32_t decoded_data_len,
+										   uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate,
+										   unsigned int *flag)
 {
 	short *dbuf;
 	unsigned char *ebuf;
@@ -77,12 +75,11 @@
 }
 
 static switch_status_t switch_g711u_decode(switch_codec_t *codec,
-										 switch_codec_t *other_codec,
-										 void *encoded_data,
-										 uint32_t encoded_data_len,
-										 uint32_t encoded_rate,
-										 void *decoded_data,
-										 uint32_t *decoded_data_len, uint32_t *decoded_rate, unsigned int *flag)
+										   switch_codec_t *other_codec,
+										   void *encoded_data,
+										   uint32_t encoded_data_len,
+										   uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate,
+										   unsigned int *flag)
 {
 	short *dbuf;
 	unsigned char *ebuf;
@@ -111,8 +108,7 @@
 }
 
 
-static switch_status_t switch_g711a_init(switch_codec_t *codec, switch_codec_flag_t flags,
-									   const switch_codec_settings_t *codec_settings)
+static switch_status_t switch_g711a_init(switch_codec_t *codec, switch_codec_flag_t flags, const switch_codec_settings_t *codec_settings)
 {
 	int encoding, decoding;
 
@@ -128,12 +124,11 @@
 
 
 static switch_status_t switch_g711a_encode(switch_codec_t *codec,
-										 switch_codec_t *other_codec,
-										 void *decoded_data,
-										 uint32_t decoded_data_len,
-										 uint32_t decoded_rate,
-										 void *encoded_data,
-										 uint32_t *encoded_data_len, uint32_t *encoded_rate, unsigned int *flag)
+										   switch_codec_t *other_codec,
+										   void *decoded_data,
+										   uint32_t decoded_data_len,
+										   uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate,
+										   unsigned int *flag)
 {
 	short *dbuf;
 	unsigned char *ebuf;
@@ -152,12 +147,11 @@
 }
 
 static switch_status_t switch_g711a_decode(switch_codec_t *codec,
-										 switch_codec_t *other_codec,
-										 void *encoded_data,
-										 uint32_t encoded_data_len,
-										 uint32_t encoded_rate,
-										 void *decoded_data,
-										 uint32_t *decoded_data_len, uint32_t *decoded_rate, unsigned int *flag)
+										   switch_codec_t *other_codec,
+										   void *encoded_data,
+										   uint32_t encoded_data_len,
+										   uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate,
+										   unsigned int *flag)
 {
 	short *dbuf;
 	unsigned char *ebuf;
@@ -226,7 +220,7 @@
 	/*.encode */ switch_g711u_encode,
 	/*.decode */ switch_g711u_decode,
 	/*.destroy */ switch_g711u_destroy,
-	/*.next*/ &g711u_8k_120ms_implementation
+	/*.next */ &g711u_8k_120ms_implementation
 };
 
 static const switch_codec_implementation_t g711u_8k_30ms_implementation = {
@@ -247,7 +241,7 @@
 	/*.encode */ switch_g711u_encode,
 	/*.decode */ switch_g711u_decode,
 	/*.destroy */ switch_g711u_destroy,
-	/*.next*/ &g711u_8k_60ms_implementation
+	/*.next */ &g711u_8k_60ms_implementation
 };
 
 static const switch_codec_implementation_t g711u_8k_20ms_implementation = {
@@ -268,7 +262,7 @@
 	/*.encode */ switch_g711u_encode,
 	/*.decode */ switch_g711u_decode,
 	/*.destroy */ switch_g711u_destroy,
-	/*.next*/ &g711u_8k_30ms_implementation
+	/*.next */ &g711u_8k_30ms_implementation
 };
 
 static const switch_codec_implementation_t g711u_8k_10ms_implementation = {
@@ -289,7 +283,7 @@
 	/*.encode */ switch_g711u_encode,
 	/*.decode */ switch_g711u_decode,
 	/*.destroy */ switch_g711u_destroy,
-	/*.next*/ &g711u_8k_20ms_implementation
+	/*.next */ &g711u_8k_20ms_implementation
 };
 
 
@@ -332,7 +326,7 @@
 	/*.encode */ switch_g711a_encode,
 	/*.decode */ switch_g711a_decode,
 	/*.destroy */ switch_g711a_destroy,
-    /*.next*/ &g711a_8k_120ms_implementation
+	/*.next */ &g711a_8k_120ms_implementation
 };
 
 static const switch_codec_implementation_t g711a_8k_30ms_implementation = {
@@ -353,7 +347,7 @@
 	/*.encode */ switch_g711a_encode,
 	/*.decode */ switch_g711a_decode,
 	/*.destroy */ switch_g711a_destroy,
-    /*.next*/ &g711a_8k_60ms_implementation
+	/*.next */ &g711a_8k_60ms_implementation
 };
 
 static const switch_codec_implementation_t g711a_8k_20ms_implementation = {
@@ -374,7 +368,7 @@
 	/*.encode */ switch_g711a_encode,
 	/*.decode */ switch_g711a_decode,
 	/*.destroy */ switch_g711a_destroy,
-    /*.next*/ &g711a_8k_30ms_implementation
+	/*.next */ &g711a_8k_30ms_implementation
 };
 
 static const switch_codec_implementation_t g711a_8k_10ms_implementation = {
@@ -395,7 +389,7 @@
 	/*.encode */ switch_g711a_encode,
 	/*.decode */ switch_g711a_decode,
 	/*.destroy */ switch_g711a_destroy,
-    /*.next*/ &g711a_8k_20ms_implementation
+	/*.next */ &g711a_8k_20ms_implementation
 };
 
 

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_g722/mod_g722.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_g722/mod_g722.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_g722/mod_g722.c	Fri Mar 30 12:19:18 2007
@@ -40,8 +40,7 @@
 	g722_encode_state_t encoder_object;
 };
 
-static switch_status_t switch_g722_init(switch_codec_t *codec, switch_codec_flag_t flags,
-									   const switch_codec_settings_t *codec_settings)
+static switch_status_t switch_g722_init(switch_codec_t *codec, switch_codec_flag_t flags, const switch_codec_settings_t *codec_settings)
 {
 	int encoding, decoding;
 	struct g722_context *context = NULL;
@@ -50,18 +49,18 @@
 	encoding = (flags & SWITCH_CODEC_FLAG_ENCODE);
 	decoding = (flags & SWITCH_CODEC_FLAG_DECODE);
 
-	if (!(encoding || decoding) || (!(context = switch_core_alloc(codec->memory_pool, sizeof(struct g722_context))))) { 
+	if (!(encoding || decoding) || (!(context = switch_core_alloc(codec->memory_pool, sizeof(struct g722_context))))) {
 		return SWITCH_STATUS_FALSE;
 	} else {
 		if (encoding) {
-			if(codec->implementation->samples_per_second == 16000){
+			if (codec->implementation->samples_per_second == 16000) {
 				g722_encode_init(&context->encoder_object, 64000, G722_PACKED);
 			} else {
 				g722_encode_init(&context->encoder_object, 64000, G722_SAMPLE_RATE_8000);
 			}
 		}
 		if (decoding) {
-			if(codec->implementation->samples_per_second == 16000){
+			if (codec->implementation->samples_per_second == 16000) {
 				g722_decode_init(&context->decoder_object, 64000, G722_PACKED);
 			} else {
 				g722_decode_init(&context->decoder_object, 64000, G722_SAMPLE_RATE_8000);
@@ -70,44 +69,42 @@
 	}
 
 	codec->private_info = context;
-	return SWITCH_STATUS_SUCCESS;	
+	return SWITCH_STATUS_SUCCESS;
 }
 
 static switch_status_t switch_g722_encode(switch_codec_t *codec,
-										 switch_codec_t *other_codec,
-										 void *decoded_data,
-										 uint32_t decoded_data_len,
-										 uint32_t decoded_rate,
-										 void *encoded_data,
-										 uint32_t *encoded_data_len, uint32_t *encoded_rate, unsigned int *flag)
+										  switch_codec_t *other_codec,
+										  void *decoded_data,
+										  uint32_t decoded_data_len,
+										  uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate,
+										  unsigned int *flag)
 {
 	struct g722_context *context = codec->private_info;
 
 	if (!context) {
-		return SWITCH_STATUS_FALSE; 
+		return SWITCH_STATUS_FALSE;
 	}
 
 	*encoded_data_len = g722_encode(&context->encoder_object, (uint8_t *) encoded_data, (int16_t *) decoded_data, decoded_data_len / 2);
-	
+
 	return SWITCH_STATUS_SUCCESS;
 }
 
 static switch_status_t switch_g722_decode(switch_codec_t *codec,
-										 switch_codec_t *other_codec,
-										 void *encoded_data,
-										 uint32_t encoded_data_len,
-										 uint32_t encoded_rate,
-										 void *decoded_data,
-										 uint32_t *decoded_data_len, uint32_t *decoded_rate, unsigned int *flag)
+										  switch_codec_t *other_codec,
+										  void *encoded_data,
+										  uint32_t encoded_data_len,
+										  uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate,
+										  unsigned int *flag)
 {
 	struct g722_context *context = codec->private_info;
 
 	if (!context) {
-		return SWITCH_STATUS_FALSE; 
+		return SWITCH_STATUS_FALSE;
 	}
 
 	*decoded_data_len = (2 * g722_decode(&context->decoder_object, (int16_t *) decoded_data, (uint8_t *) encoded_data, encoded_data_len));
-	
+
 	return SWITCH_STATUS_SUCCESS;
 }
 

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_g723_1/mod_g723_1.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_g723_1/mod_g723_1.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_g723_1/mod_g723_1.c	Fri Mar 30 12:19:18 2007
@@ -30,7 +30,7 @@
  *
  * mod_g723.c -- G723.1 Codec Module
  *
- */  
+ */
 #include "switch.h"
 
 #ifndef G723_PASSTHROUGH
@@ -60,12 +60,11 @@
 };
 #endif
 
-static switch_status_t switch_g723_init(switch_codec_t *codec, switch_codec_flag_t flags,
-									  const switch_codec_settings_t *codec_settings) 
+static switch_status_t switch_g723_init(switch_codec_t *codec, switch_codec_flag_t flags, const switch_codec_settings_t *codec_settings)
 {
 #ifdef G723_PASSTHROUGH
 	codec->flags |= SWITCH_CODEC_FLAG_PASSTHROUGH;
-	return  SWITCH_STATUS_FALSE;
+	return SWITCH_STATUS_FALSE;
 #else
 	struct g723_context *context = NULL;
 	int encoding, decoding;
@@ -79,10 +78,10 @@
 
 		if (encoding) {
 			Init_Coder(&context->encoder_object);
-			if( UseVx ) {
+			if (UseVx) {
 				Init_Vad(&context->encoder_object);
 				Init_Cod_Cng(&context->encoder_object);
-			}		   
+			}
 		}
 
 		if (decoding) {
@@ -98,7 +97,7 @@
 }
 
 
-static switch_status_t switch_g723_destroy(switch_codec_t *codec) 
+static switch_status_t switch_g723_destroy(switch_codec_t *codec)
 {
 #ifndef G723_PASSTHROUGH
 	codec->private_info = NULL;
@@ -106,17 +105,12 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t switch_g723_encode(switch_codec_t *codec, 
-										switch_codec_t *other_codec, 
-										void *decoded_data,
-
-										uint32_t decoded_data_len, 
-										uint32_t decoded_rate, 
-										void *encoded_data,
-
-										uint32_t *encoded_data_len, 
-										uint32_t *encoded_rate, 
-										unsigned int *flag) 
+static switch_status_t switch_g723_encode(switch_codec_t *codec,
+										  switch_codec_t *other_codec,
+										  void *decoded_data,
+										  uint32_t decoded_data_len,
+										  uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate,
+										  unsigned int *flag)
 {
 #ifdef G723_PASSTHROUGH
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "This codec is only usable in passthrough mode!\n");
@@ -131,28 +125,23 @@
 		return SWITCH_STATUS_FALSE;
 	}
 
-	for(x = 0; x < Frame; x++) {
+	for (x = 0; x < Frame; x++) {
 		context->cod_float_buf[x] = decoded_slin_buf[x];
 	}
 
-	Coder(&context->encoder_object, (FLOAT *)context->cod_float_buf, ebuf);
+	Coder(&context->encoder_object, (FLOAT *) context->cod_float_buf, ebuf);
 	*encoded_data_len = codec->implementation->encoded_bytes_per_frame;
 
 	return SWITCH_STATUS_SUCCESS;
 #endif
 }
 
-static switch_status_t switch_g723_decode(switch_codec_t *codec, 
-										switch_codec_t *other_codec, 
-										void *encoded_data,
-
-										uint32_t encoded_data_len, 
-										uint32_t encoded_rate, 
-										void *decoded_data,
-
-										uint32_t *decoded_data_len, 
-										uint32_t *decoded_rate, 
-										unsigned int *flag) 
+static switch_status_t switch_g723_decode(switch_codec_t *codec,
+										  switch_codec_t *other_codec,
+										  void *encoded_data,
+										  uint32_t encoded_data_len,
+										  uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate,
+										  unsigned int *flag)
 {
 #ifdef G723_PASSTHROUGH
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "This codec is only usable in passthrough mode!\n");
@@ -165,10 +154,10 @@
 	if (!context) {
 		return SWITCH_STATUS_FALSE;
 	}
-	
+
 	Decod(&context->decoder_object, (FLOAT *) context->dec_float_buf, (char *) decoded_data, 0);
 
-	for (x=0;x<Frame;x++) {
+	for (x = 0; x < Frame; x++) {
 		to_slin_buf[x] = context->dec_float_buf[x];
 	}
 	*decoded_data_len = codec->implementation->bytes_per_frame;
@@ -177,49 +166,48 @@
 #endif
 }
 
-/* Registration */ 
+/* Registration */
 
-static const switch_codec_implementation_t g723_1_implementation = { 
-	/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO, 
-	/*.ianacode */ 4, 
-	/*.iananame */ "G723", 
+static const switch_codec_implementation_t g723_1_implementation = {
+	/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
+	/*.ianacode */ 4,
+	/*.iananame */ "G723",
 	/*.fmtp */ NULL,
-	/*.samples_per_second */ 8000, 
-	/*.bits_per_second */ 6300, 
-	/*.microseconds_per_frame */ 30000, 
-	/*.samples_per_frame */ 240, 
-	/*.bytes_per_frame */ 480, 
-	/*.encoded_bytes_per_frame */ 24, 
-	/*.number_of_channels */ 1, 
-	/*.pref_frames_per_packet */ 1, 
-	/*.max_frames_per_packet */ 4, 
-	/*.init */ switch_g723_init, 
-	/*.encode */ switch_g723_encode, 
-	/*.decode */ switch_g723_decode, 
-	/*.destroy */ switch_g723_destroy, 
+	/*.samples_per_second */ 8000,
+	/*.bits_per_second */ 6300,
+	/*.microseconds_per_frame */ 30000,
+	/*.samples_per_frame */ 240,
+	/*.bytes_per_frame */ 480,
+	/*.encoded_bytes_per_frame */ 24,
+	/*.number_of_channels */ 1,
+	/*.pref_frames_per_packet */ 1,
+	/*.max_frames_per_packet */ 4,
+	/*.init */ switch_g723_init,
+	/*.encode */ switch_g723_encode,
+	/*.decode */ switch_g723_decode,
+	/*.destroy */ switch_g723_destroy,
 };
 
-static const switch_codec_interface_t g723_1_codec_interface = { 
-	/*.interface_name */ "g723.1 6.3k", 
-	/*.implementations */ &g723_1_implementation, 
+static const switch_codec_interface_t g723_1_codec_interface = {
+	/*.interface_name */ "g723.1 6.3k",
+	/*.implementations */ &g723_1_implementation,
 };
 
-static switch_loadable_module_interface_t g723_module_interface = { 
-	/*.module_name */ modname, 
-	/*.endpoint_interface */ NULL, 
-	/*.timer_interface */ NULL, 
-	/*.dialplan_interface */ NULL, 
-	/*.codec_interface */ &g723_1_codec_interface, 
-	/*.application_interface */ NULL 
+static switch_loadable_module_interface_t g723_module_interface = {
+	/*.module_name */ modname,
+	/*.endpoint_interface */ NULL,
+	/*.timer_interface */ NULL,
+	/*.dialplan_interface */ NULL,
+	/*.codec_interface */ &g723_1_codec_interface,
+	/*.application_interface */ NULL
 };
 
-SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
-													 char *filename)
+SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
 {
-	/* connect my internal structure to the blank pointer passed to me */ 
+	/* connect my internal structure to the blank pointer passed to me */
 	*module_interface = &g723_module_interface;
 
-	/* indicate that the module should continue to be loaded */ 
+	/* indicate that the module should continue to be loaded */
 	return SWITCH_STATUS_SUCCESS;
 }
 

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_g726/mod_g726.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_g726/mod_g726.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_g726/mod_g726.c	Fri Mar 30 12:19:18 2007
@@ -28,15 +28,15 @@
  *
  * mod_g726.c -- G726 Codec Module
  *
- */  
+ */
 #include "switch.h"
 #include "g72x.h"
 #include "switch_bitpack.h"
 
 static const char modname[] = "mod_g726";
 
-typedef int (*encoder_t)(int, int, g726_state *);
-typedef int (*decoder_t)(int, int, g726_state *);
+typedef int (*encoder_t) (int, int, g726_state *);
+typedef int (*decoder_t) (int, int, g726_state *);
 
 
 typedef struct {
@@ -52,8 +52,7 @@
 	switch_byte_t buf[160];
 } g726_handle_t;
 
-static switch_status_t switch_g726_init(switch_codec_t *codec, switch_codec_flag_t flags,
-									  const switch_codec_settings_t *codec_settings) 
+static switch_status_t switch_g726_init(switch_codec_t *codec, switch_codec_flag_t flags, const switch_codec_settings_t *codec_settings)
 {
 	uint32_t encoding, decoding;
 	g726_handle_t *handle;
@@ -65,8 +64,8 @@
 		return SWITCH_STATUS_FALSE;
 	} else {
 		handle->bytes = (switch_byte_t) codec->implementation->encoded_bytes_per_frame;
-		
-		switch(handle->bytes) {
+
+		switch (handle->bytes) {
 		case 100:
 			handle->encoder = g726_40_encoder;
 			handle->decoder = g726_40_decoder;
@@ -96,14 +95,14 @@
 		g726_init_state(&handle->context);
 		codec->private_info = handle;
 		handle->bits_per_frame = (switch_byte_t) (codec->implementation->bits_per_second / (codec->implementation->samples_per_second));
-		handle->mode = (flags & SWITCH_CODEC_FLAG_AAL2 || strstr(codec->implementation->iananame, "AAL2")) 
+		handle->mode = (flags & SWITCH_CODEC_FLAG_AAL2 || strstr(codec->implementation->iananame, "AAL2"))
 			? SWITCH_BITPACK_MODE_AAL2 : SWITCH_BITPACK_MODE_RFC3551;
 		return SWITCH_STATUS_SUCCESS;
 	}
 }
 
 
-static switch_status_t switch_g726_destroy(switch_codec_t *codec) 
+static switch_status_t switch_g726_destroy(switch_codec_t *codec)
 {
 	codec->private_info = NULL;
 	return SWITCH_STATUS_SUCCESS;
@@ -111,17 +110,12 @@
 
 
 
-static switch_status_t switch_g726_encode(switch_codec_t *codec, 
-										switch_codec_t *other_codec, 
-										void *decoded_data,
-
-										uint32_t decoded_data_len, 
-										uint32_t decoded_rate, 
-										void *encoded_data,
-
-										uint32_t *encoded_data_len, 
-										uint32_t *encoded_rate, 
-										unsigned int *flag) 
+static switch_status_t switch_g726_encode(switch_codec_t *codec,
+										  switch_codec_t *other_codec,
+										  void *decoded_data,
+										  uint32_t decoded_data_len,
+										  uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate,
+										  unsigned int *flag)
 {
 
 	g726_handle_t *handle = codec->private_info;
@@ -163,17 +157,12 @@
 
 
 
-static switch_status_t switch_g726_decode(switch_codec_t *codec, 
-										switch_codec_t *other_codec, 
-										void *encoded_data,
-
-										uint32_t encoded_data_len, 
-										uint32_t encoded_rate, 
-										void *decoded_data,
-
-										uint32_t *decoded_data_len, 
-										uint32_t *decoded_rate, 
-										unsigned int *flag) 
+static switch_status_t switch_g726_decode(switch_codec_t *codec,
+										  switch_codec_t *other_codec,
+										  void *encoded_data,
+										  uint32_t encoded_data_len,
+										  uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate,
+										  unsigned int *flag)
 {
 
 	g726_handle_t *handle = codec->private_info;
@@ -192,13 +181,13 @@
 		for (y = 0; y < handle->loops; y++) {
 			switch_bitpack_out(&handle->unpack, in[z++]);
 		}
-		for(y = 0; y < handle->bytes; y++) {
+		for (y = 0; y < handle->bytes; y++) {
 			*ddp++ = (int16_t) handle->decoder(handle->buf[y], AUDIO_ENCODING_LINEAR, context);
-            new_len += 2;
+			new_len += 2;
 		}
 		switch_bitpack_done(&handle->unpack);
 	}
-	
+
 	if (new_len <= *decoded_data_len) {
 		*decoded_data_len = new_len;
 	} else {
@@ -213,239 +202,238 @@
 
 
 
-/* Registration */ 
+/* Registration */
 
-static const switch_codec_implementation_t g726_16k_implementation = { 
-	/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO, 
-	/*.ianacode */ 127, 
-	/*.iananame */ "G726-16", 
+static const switch_codec_implementation_t g726_16k_implementation = {
+	/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
+	/*.ianacode */ 127,
+	/*.iananame */ "G726-16",
 	/*.fmtp */ NULL,
-	/*.samples_per_second */ 8000, 
-	/*.bits_per_second */ 16000, 
-	/*.microseconds_per_frame */ 20000, 
-	/*.samples_per_frame */ 160, 
-	/*.bytes_per_frame */ 320, 
-	/*.encoded_bytes_per_frame */ 40, 
-	/*.number_of_channels */ 1, 
-	/*.pref_frames_per_packet */ 1, 
-	/*.max_frames_per_packet */ 1, 
-	/*.init */ switch_g726_init, 
-	/*.encode */ switch_g726_encode, 
-	/*.decode */ switch_g726_decode, 
-	/*.destroy */ switch_g726_destroy, 
+	/*.samples_per_second */ 8000,
+	/*.bits_per_second */ 16000,
+	/*.microseconds_per_frame */ 20000,
+	/*.samples_per_frame */ 160,
+	/*.bytes_per_frame */ 320,
+	/*.encoded_bytes_per_frame */ 40,
+	/*.number_of_channels */ 1,
+	/*.pref_frames_per_packet */ 1,
+	/*.max_frames_per_packet */ 1,
+	/*.init */ switch_g726_init,
+	/*.encode */ switch_g726_encode,
+	/*.decode */ switch_g726_decode,
+	/*.destroy */ switch_g726_destroy,
 };
 
 
-static const switch_codec_implementation_t g726_24k_implementation = { 
-	/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO, 
-	/*.ianacode */ 126, 
-	/*.iananame */ "G726-24", 
+static const switch_codec_implementation_t g726_24k_implementation = {
+	/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
+	/*.ianacode */ 126,
+	/*.iananame */ "G726-24",
 	/*.fmtp */ NULL,
-	/*.samples_per_second */ 8000, 
-	/*.bits_per_second */ 24000, 
-	/*.microseconds_per_frame */ 20000, 
-	/*.samples_per_frame */ 160, 
-	/*.bytes_per_frame */ 320, 
-	/*.encoded_bytes_per_frame */ 60, 
-	/*.number_of_channels */ 1, 
-	/*.pref_frames_per_packet */ 1, 
-	/*.max_frames_per_packet */ 1, 
-	/*.init */ switch_g726_init, 
-	/*.encode */ switch_g726_encode, 
-	/*.decode */ switch_g726_decode, 
-	/*.destroy */ switch_g726_destroy, 
-};
-
-static const switch_codec_implementation_t g726_32k_implementation = { 
-	/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO, 
-	/*.ianacode */ 2, 
-	/*.iananame */ "G726-32", 
+	/*.samples_per_second */ 8000,
+	/*.bits_per_second */ 24000,
+	/*.microseconds_per_frame */ 20000,
+	/*.samples_per_frame */ 160,
+	/*.bytes_per_frame */ 320,
+	/*.encoded_bytes_per_frame */ 60,
+	/*.number_of_channels */ 1,
+	/*.pref_frames_per_packet */ 1,
+	/*.max_frames_per_packet */ 1,
+	/*.init */ switch_g726_init,
+	/*.encode */ switch_g726_encode,
+	/*.decode */ switch_g726_decode,
+	/*.destroy */ switch_g726_destroy,
+};
+
+static const switch_codec_implementation_t g726_32k_implementation = {
+	/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
+	/*.ianacode */ 2,
+	/*.iananame */ "G726-32",
 	/*.fmtp */ NULL,
-	/*.samples_per_second */ 8000, 
-	/*.bits_per_second */ 32000, 
-	/*.microseconds_per_frame */ 20000, 
-	/*.samples_per_frame */ 160, 
-	/*.bytes_per_frame */ 320, 
-	/*.encoded_bytes_per_frame */ 80, 
-	/*.number_of_channels */ 1, 
-	/*.pref_frames_per_packet */ 1, 
-	/*.max_frames_per_packet */ 1, 
-	/*.init */ switch_g726_init, 
-	/*.encode */ switch_g726_encode, 
-	/*.decode */ switch_g726_decode, 
-	/*.destroy */ switch_g726_destroy, 
-};
-
-static const switch_codec_implementation_t g726_40k_implementation = { 
-	/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO, 
-	/*.ianacode */ 125, 
-	/*.iananame */ "G726-40", 
+	/*.samples_per_second */ 8000,
+	/*.bits_per_second */ 32000,
+	/*.microseconds_per_frame */ 20000,
+	/*.samples_per_frame */ 160,
+	/*.bytes_per_frame */ 320,
+	/*.encoded_bytes_per_frame */ 80,
+	/*.number_of_channels */ 1,
+	/*.pref_frames_per_packet */ 1,
+	/*.max_frames_per_packet */ 1,
+	/*.init */ switch_g726_init,
+	/*.encode */ switch_g726_encode,
+	/*.decode */ switch_g726_decode,
+	/*.destroy */ switch_g726_destroy,
+};
+
+static const switch_codec_implementation_t g726_40k_implementation = {
+	/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
+	/*.ianacode */ 125,
+	/*.iananame */ "G726-40",
 	/*.fmtp */ NULL,
 	/*.samples_per_second */ 8000,
-	/*.bits_per_second */ 40000, 
-	/*.microseconds_per_frame */ 20000, 
-	/*.samples_per_frame */ 160, 
-	/*.bytes_per_frame */ 320, 
-	/*.encoded_bytes_per_frame */ 100, 
-	/*.number_of_channels */ 1, 
-	/*.pref_frames_per_packet */ 1, 
-	/*.max_frames_per_packet */ 1, 
-	/*.init */ switch_g726_init, 
-	/*.encode */ switch_g726_encode, 
-	/*.decode */ switch_g726_decode, 
-	/*.destroy */ switch_g726_destroy, 
+	/*.bits_per_second */ 40000,
+	/*.microseconds_per_frame */ 20000,
+	/*.samples_per_frame */ 160,
+	/*.bytes_per_frame */ 320,
+	/*.encoded_bytes_per_frame */ 100,
+	/*.number_of_channels */ 1,
+	/*.pref_frames_per_packet */ 1,
+	/*.max_frames_per_packet */ 1,
+	/*.init */ switch_g726_init,
+	/*.encode */ switch_g726_encode,
+	/*.decode */ switch_g726_decode,
+	/*.destroy */ switch_g726_destroy,
 };
 
 
 
-static const switch_codec_implementation_t aal2_g726_16k_implementation = { 
-	/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO, 
-	/*.ianacode */ 124, 
-	/*.iananame */ "AAL2-G726-16", 
+static const switch_codec_implementation_t aal2_g726_16k_implementation = {
+	/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
+	/*.ianacode */ 124,
+	/*.iananame */ "AAL2-G726-16",
 	/*.fmtp */ NULL,
-	/*.samples_per_second */ 8000, 
-	/*.bits_per_second */ 16000, 
-	/*.microseconds_per_frame */ 20000, 
-	/*.samples_per_frame */ 160, 
-	/*.bytes_per_frame */ 320, 
-	/*.encoded_bytes_per_frame */ 40, 
-	/*.number_of_channels */ 1, 
-	/*.pref_frames_per_packet */ 1, 
-	/*.max_frames_per_packet */ 1, 
-	/*.init */ switch_g726_init, 
-	/*.encode */ switch_g726_encode, 
-	/*.decode */ switch_g726_decode, 
-	/*.destroy */ switch_g726_destroy, 
+	/*.samples_per_second */ 8000,
+	/*.bits_per_second */ 16000,
+	/*.microseconds_per_frame */ 20000,
+	/*.samples_per_frame */ 160,
+	/*.bytes_per_frame */ 320,
+	/*.encoded_bytes_per_frame */ 40,
+	/*.number_of_channels */ 1,
+	/*.pref_frames_per_packet */ 1,
+	/*.max_frames_per_packet */ 1,
+	/*.init */ switch_g726_init,
+	/*.encode */ switch_g726_encode,
+	/*.decode */ switch_g726_decode,
+	/*.destroy */ switch_g726_destroy,
 };
 
 
-static const switch_codec_implementation_t aal2_g726_24k_implementation = { 
-	/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO, 
-	/*.ianacode */ 123, 
-	/*.iananame */ "AAL2-G726-24", 
+static const switch_codec_implementation_t aal2_g726_24k_implementation = {
+	/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
+	/*.ianacode */ 123,
+	/*.iananame */ "AAL2-G726-24",
 	/*.fmtp */ NULL,
-	/*.samples_per_second */ 8000, 
-	/*.bits_per_second */ 24000, 
-	/*.microseconds_per_frame */ 20000, 
-	/*.samples_per_frame */ 160, 
-	/*.bytes_per_frame */ 320, 
-	/*.encoded_bytes_per_frame */ 60, 
-	/*.number_of_channels */ 1, 
-	/*.pref_frames_per_packet */ 1, 
-	/*.max_frames_per_packet */ 1, 
-	/*.init */ switch_g726_init, 
-	/*.encode */ switch_g726_encode, 
-	/*.decode */ switch_g726_decode, 
-	/*.destroy */ switch_g726_destroy, 
-};
-
-static const switch_codec_implementation_t aal2_g726_32k_implementation = { 
-	/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO, 
-	/*.ianacode */ 2, 
-	/*.iananame */ "AAL2-G726-32", 
+	/*.samples_per_second */ 8000,
+	/*.bits_per_second */ 24000,
+	/*.microseconds_per_frame */ 20000,
+	/*.samples_per_frame */ 160,
+	/*.bytes_per_frame */ 320,
+	/*.encoded_bytes_per_frame */ 60,
+	/*.number_of_channels */ 1,
+	/*.pref_frames_per_packet */ 1,
+	/*.max_frames_per_packet */ 1,
+	/*.init */ switch_g726_init,
+	/*.encode */ switch_g726_encode,
+	/*.decode */ switch_g726_decode,
+	/*.destroy */ switch_g726_destroy,
+};
+
+static const switch_codec_implementation_t aal2_g726_32k_implementation = {
+	/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
+	/*.ianacode */ 2,
+	/*.iananame */ "AAL2-G726-32",
 	/*.fmtp */ NULL,
-	/*.samples_per_second */ 8000, 
-	/*.bits_per_second */ 32000, 
-	/*.microseconds_per_frame */ 20000, 
-	/*.samples_per_frame */ 160, 
-	/*.bytes_per_frame */ 320, 
-	/*.encoded_bytes_per_frame */ 80, 
-	/*.number_of_channels */ 1, 
-	/*.pref_frames_per_packet */ 1, 
-	/*.max_frames_per_packet */ 1, 
-	/*.init */ switch_g726_init, 
-	/*.encode */ switch_g726_encode, 
-	/*.decode */ switch_g726_decode, 
-	/*.destroy */ switch_g726_destroy, 
-};
-
-static const switch_codec_implementation_t aal2_g726_40k_implementation = { 
-	/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO, 
-	/*.ianacode */ 122, 
-	/*.iananame */ "AAL2-G726-40", 
+	/*.samples_per_second */ 8000,
+	/*.bits_per_second */ 32000,
+	/*.microseconds_per_frame */ 20000,
+	/*.samples_per_frame */ 160,
+	/*.bytes_per_frame */ 320,
+	/*.encoded_bytes_per_frame */ 80,
+	/*.number_of_channels */ 1,
+	/*.pref_frames_per_packet */ 1,
+	/*.max_frames_per_packet */ 1,
+	/*.init */ switch_g726_init,
+	/*.encode */ switch_g726_encode,
+	/*.decode */ switch_g726_decode,
+	/*.destroy */ switch_g726_destroy,
+};
+
+static const switch_codec_implementation_t aal2_g726_40k_implementation = {
+	/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
+	/*.ianacode */ 122,
+	/*.iananame */ "AAL2-G726-40",
 	/*.fmtp */ NULL,
 	/*.samples_per_second */ 8000,
-	/*.bits_per_second */ 40000, 
-	/*.microseconds_per_frame */ 20000, 
-	/*.samples_per_frame */ 160, 
-	/*.bytes_per_frame */ 320, 
-	/*.encoded_bytes_per_frame */ 100, 
-	/*.number_of_channels */ 1, 
-	/*.pref_frames_per_packet */ 1, 
-	/*.max_frames_per_packet */ 1, 
-	/*.init */ switch_g726_init, 
-	/*.encode */ switch_g726_encode, 
-	/*.decode */ switch_g726_decode, 
-	/*.destroy */ switch_g726_destroy, 
-};
-
-const switch_codec_interface_t g726_16k_codec_interface = { 
-	/*.interface_name */ "G.726 16k", 
-	/*.implementations */ &g726_16k_implementation, 
-};
-
-const switch_codec_interface_t g726_24k_codec_interface = { 
-	/*.interface_name */ "G.726 24k", 
-	/*.implementations */ &g726_24k_implementation, 
+	/*.bits_per_second */ 40000,
+	/*.microseconds_per_frame */ 20000,
+	/*.samples_per_frame */ 160,
+	/*.bytes_per_frame */ 320,
+	/*.encoded_bytes_per_frame */ 100,
+	/*.number_of_channels */ 1,
+	/*.pref_frames_per_packet */ 1,
+	/*.max_frames_per_packet */ 1,
+	/*.init */ switch_g726_init,
+	/*.encode */ switch_g726_encode,
+	/*.decode */ switch_g726_decode,
+	/*.destroy */ switch_g726_destroy,
+};
+
+const switch_codec_interface_t g726_16k_codec_interface = {
+	/*.interface_name */ "G.726 16k",
+	/*.implementations */ &g726_16k_implementation,
+};
+
+const switch_codec_interface_t g726_24k_codec_interface = {
+	/*.interface_name */ "G.726 24k",
+	/*.implementations */ &g726_24k_implementation,
 	/*.next */ &g726_16k_codec_interface
 };
 
-const switch_codec_interface_t g726_32k_codec_interface = { 
-	/*.interface_name */ "G.726 32k", 
-	/*.implementations */ &g726_32k_implementation, 
+const switch_codec_interface_t g726_32k_codec_interface = {
+	/*.interface_name */ "G.726 32k",
+	/*.implementations */ &g726_32k_implementation,
 	/*.next */ &g726_24k_codec_interface
 };
 
-const switch_codec_interface_t g726_40k_codec_interface = { 
-	/*.interface_name */ "G.726 40k", 
-	/*.implementations */ &g726_40k_implementation, 
+const switch_codec_interface_t g726_40k_codec_interface = {
+	/*.interface_name */ "G.726 40k",
+	/*.implementations */ &g726_40k_implementation,
 	/*.next */ &g726_32k_codec_interface
 };
 
 
 
-const switch_codec_interface_t aal2_g726_16k_codec_interface = { 
-	/*.interface_name */ "G.726 16k (aal2)", 
-	/*.implementations */ &aal2_g726_16k_implementation, 
+const switch_codec_interface_t aal2_g726_16k_codec_interface = {
+	/*.interface_name */ "G.726 16k (aal2)",
+	/*.implementations */ &aal2_g726_16k_implementation,
 	/*.next */ &g726_40k_codec_interface
 };
 
-const switch_codec_interface_t aal2_g726_24k_codec_interface = { 
-	/*.interface_name */ "G.726 24k (aal2)", 
-	/*.implementations */ &aal2_g726_24k_implementation, 
+const switch_codec_interface_t aal2_g726_24k_codec_interface = {
+	/*.interface_name */ "G.726 24k (aal2)",
+	/*.implementations */ &aal2_g726_24k_implementation,
 	/*.next */ &aal2_g726_16k_codec_interface
 };
 
-const switch_codec_interface_t aal2_g726_32k_codec_interface = { 
-	/*.interface_name */ "G.726 32k (aal2)", 
-	/*.implementations */ &aal2_g726_32k_implementation, 
+const switch_codec_interface_t aal2_g726_32k_codec_interface = {
+	/*.interface_name */ "G.726 32k (aal2)",
+	/*.implementations */ &aal2_g726_32k_implementation,
 	/*.next */ &aal2_g726_24k_codec_interface
 };
 
-const switch_codec_interface_t aal2_g726_40k_codec_interface = { 
-	/*.interface_name */ "G.726 40k (aal2)", 
-	/*.implementations */ &aal2_g726_40k_implementation, 
+const switch_codec_interface_t aal2_g726_40k_codec_interface = {
+	/*.interface_name */ "G.726 40k (aal2)",
+	/*.implementations */ &aal2_g726_40k_implementation,
 	/*.next */ &aal2_g726_32k_codec_interface
 };
 
 
 
-static switch_loadable_module_interface_t g726_module_interface = { 
-	/*.module_name */ modname, 
-	/*.endpoint_interface */ NULL, 
-	/*.timer_interface */ NULL, 
-	/*.dialplan_interface */ NULL, 
-	/*.codec_interface */ &aal2_g726_40k_codec_interface, 
-	/*.application_interface */ NULL 
+static switch_loadable_module_interface_t g726_module_interface = {
+	/*.module_name */ modname,
+	/*.endpoint_interface */ NULL,
+	/*.timer_interface */ NULL,
+	/*.dialplan_interface */ NULL,
+	/*.codec_interface */ &aal2_g726_40k_codec_interface,
+	/*.application_interface */ NULL
 };
 
-SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
-													 char *filename)
+SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
 {
-	/* connect my internal structure to the blank pointer passed to me */ 
+	/* connect my internal structure to the blank pointer passed to me */
 	*module_interface = &g726_module_interface;
 
-	/* indicate that the module should continue to be loaded */ 
+	/* indicate that the module should continue to be loaded */
 	return SWITCH_STATUS_SUCCESS;
 }
 

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_g729/mod_g729.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_g729/mod_g729.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_g729/mod_g729.c	Fri Mar 30 12:19:18 2007
@@ -30,7 +30,7 @@
  *
  * mod_g729.c -- G729 Codec Module
  *
- */  
+ */
 
 static const char modname[] = "mod_g729";
 
@@ -45,16 +45,15 @@
 };
 #endif
 
-static switch_status_t switch_g729_init(switch_codec_t *codec, switch_codec_flag_t flags,
-									  const switch_codec_settings_t *codec_settings) 
+static switch_status_t switch_g729_init(switch_codec_t *codec, switch_codec_flag_t flags, const switch_codec_settings_t *codec_settings)
 {
 #ifdef G729_PASSTHROUGH
 	codec->flags |= SWITCH_CODEC_FLAG_PASSTHROUGH;
-    if (codec->fmtp_in) {
-        codec->fmtp_out = switch_core_strdup(codec->memory_pool, codec->fmtp_in);
-    }
+	if (codec->fmtp_in) {
+		codec->fmtp_out = switch_core_strdup(codec->memory_pool, codec->fmtp_in);
+	}
 	return SWITCH_STATUS_SUCCESS;
-#else 
+#else
 	struct g729_context *context = NULL;
 	int encoding, decoding;
 
@@ -64,9 +63,9 @@
 	if (!(encoding || decoding) || (!(context = switch_core_alloc(codec->memory_pool, sizeof(struct g729_context))))) {
 		return SWITCH_STATUS_FALSE;
 	} else {
-        if (codec->fmtp_in) {
-            codec->fmtp_out = switch_core_strdup(codec->memory_pool, codec->fmtp_in);
-        }
+		if (codec->fmtp_in) {
+			codec->fmtp_out = switch_core_strdup(codec->memory_pool, codec->fmtp_in);
+		}
 
 		if (encoding) {
 			g729_init_coder(&context->encoder_object, 0);
@@ -84,7 +83,7 @@
 #endif
 }
 
-static switch_status_t switch_g729_destroy(switch_codec_t *codec) 
+static switch_status_t switch_g729_destroy(switch_codec_t *codec)
 {
 #ifndef G729_PASSTHROUGH
 	codec->private_info = NULL;
@@ -92,17 +91,12 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t switch_g729_encode(switch_codec_t *codec, 
-										switch_codec_t *other_codec, 
-										void *decoded_data,
-
-										uint32_t decoded_data_len, 
-										uint32_t decoded_rate, 
-										void *encoded_data,
-
-										uint32_t *encoded_data_len, 
-										uint32_t *encoded_rate, 
-										unsigned int *flag) 
+static switch_status_t switch_g729_encode(switch_codec_t *codec,
+										  switch_codec_t *other_codec,
+										  void *decoded_data,
+										  uint32_t decoded_data_len,
+										  uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate,
+										  unsigned int *flag)
 {
 #ifdef G729_PASSTHROUGH
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "This codec is only usable in passthrough mode!\n");
@@ -117,7 +111,7 @@
 
 	if (decoded_data_len % 160 == 0) {
 		uint32_t new_len = 0;
-		INT16 * ddp = decoded_data;
+		INT16 *ddp = decoded_data;
 		char *edp = encoded_data;
 		int x;
 		int loops = (int) decoded_data_len / 160;
@@ -140,17 +134,12 @@
 #endif
 }
 
-static switch_status_t switch_g729_decode(switch_codec_t *codec, 
-										switch_codec_t *other_codec, 
-										void *encoded_data,
-
-										uint32_t encoded_data_len, 
-										uint32_t encoded_rate, 
-										void *decoded_data,
-
-										uint32_t *decoded_data_len, 
-										uint32_t *decoded_rate, 
-										unsigned int *flag) 
+static switch_status_t switch_g729_decode(switch_codec_t *codec,
+										  switch_codec_t *other_codec,
+										  void *encoded_data,
+										  uint32_t encoded_data_len,
+										  uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate,
+										  unsigned int *flag)
 {
 #ifdef G729_PASSTHROUGH
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "This codec is only usable in passthrough mode!\n");
@@ -189,7 +178,7 @@
 			uint32_t new_len = 0;
 
 			test = (uint8_t *) encoded_data;
-			if (*test == 0 && *(test+1) == 0) {
+			if (*test == 0 && *(test + 1) == 0) {
 				*decoded_data_len = (encoded_data_len / divisor) * 160;
 				memset(decoded_data, 0, *decoded_data_len);
 				return SWITCH_STATUS_SUCCESS;
@@ -213,7 +202,7 @@
 				return SWITCH_STATUS_FALSE;
 
 			}
-		} 
+		}
 	} else {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "yo this frame is an odd size [%d]\n", encoded_data_len);
 		return SWITCH_STATUS_FALSE;
@@ -222,46 +211,46 @@
 #endif
 }
 
-/* Registration */ 
+/* Registration */
 
-static const switch_codec_implementation_t g729_10ms_8k_implementation = { 
-	/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO, 
-	/*.ianacode */ 18, 
-	/*.iananame */ "G729", 
+static const switch_codec_implementation_t g729_10ms_8k_implementation = {
+	/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
+	/*.ianacode */ 18,
+	/*.iananame */ "G729",
 	/*.fmtp */ NULL,
-	/*.samples_per_second */ 8000, 
-	/*.bits_per_second */ 32000, 
-	/*.microseconds_per_frame */ 10000, 
-	/*.samples_per_frame */ 80, 
-	/*.bytes_per_frame */ 160, 
-	/*.encoded_bytes_per_frame */ 10, 
-	/*.number_of_channels */ 1, 
-	/*.pref_frames_per_packet */ 1, 
-	/*.max_frames_per_packet */ 1, 
-	/*.init */ switch_g729_init, 
-	/*.encode */ switch_g729_encode, 
-	/*.decode */ switch_g729_decode, 
-	/*.destroy */ switch_g729_destroy, 
+	/*.samples_per_second */ 8000,
+	/*.bits_per_second */ 32000,
+	/*.microseconds_per_frame */ 10000,
+	/*.samples_per_frame */ 80,
+	/*.bytes_per_frame */ 160,
+	/*.encoded_bytes_per_frame */ 10,
+	/*.number_of_channels */ 1,
+	/*.pref_frames_per_packet */ 1,
+	/*.max_frames_per_packet */ 1,
+	/*.init */ switch_g729_init,
+	/*.encode */ switch_g729_encode,
+	/*.decode */ switch_g729_decode,
+	/*.destroy */ switch_g729_destroy,
 };
 
-static const switch_codec_implementation_t g729_8k_implementation = { 
-	/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO, 
-	/*.ianacode */ 18, 
-	/*.iananame */ "G729", 
+static const switch_codec_implementation_t g729_8k_implementation = {
+	/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
+	/*.ianacode */ 18,
+	/*.iananame */ "G729",
 	/*.fmtp */ NULL,
-	/*.samples_per_second */ 8000, 
-	/*.bits_per_second */ 64000, 
-	/*.microseconds_per_frame */ 20000, 
-	/*.samples_per_frame */ 160, 
-	/*.bytes_per_frame */ 320, 
-	/*.encoded_bytes_per_frame */ 20, 
-	/*.number_of_channels */ 1, 
-	/*.pref_frames_per_packet */ 1, 
-	/*.max_frames_per_packet */ 1, 
-	/*.init */ switch_g729_init, 
-	/*.encode */ switch_g729_encode, 
-	/*.decode */ switch_g729_decode, 
-	/*.destroy */ switch_g729_destroy, 
+	/*.samples_per_second */ 8000,
+	/*.bits_per_second */ 64000,
+	/*.microseconds_per_frame */ 20000,
+	/*.samples_per_frame */ 160,
+	/*.bytes_per_frame */ 320,
+	/*.encoded_bytes_per_frame */ 20,
+	/*.number_of_channels */ 1,
+	/*.pref_frames_per_packet */ 1,
+	/*.max_frames_per_packet */ 1,
+	/*.init */ switch_g729_init,
+	/*.encode */ switch_g729_encode,
+	/*.decode */ switch_g729_decode,
+	/*.destroy */ switch_g729_destroy,
 	&g729_10ms_8k_implementation
 };
 
@@ -271,22 +260,21 @@
 	/*.next */ NULL
 };
 
-static switch_loadable_module_interface_t g729_module_interface = { 
+static switch_loadable_module_interface_t g729_module_interface = {
 	/*.module_name */ "g729",
-	/*.endpoint_interface */ NULL, 
-	/*.timer_interface */ NULL, 
-	/*.dialplan_interface */ NULL, 
-	/*.codec_interface */ &g729_codec_interface, 
-	/*.application_interface */ NULL 
+	/*.endpoint_interface */ NULL,
+	/*.timer_interface */ NULL,
+	/*.dialplan_interface */ NULL,
+	/*.codec_interface */ &g729_codec_interface,
+	/*.application_interface */ NULL
 };
 
-SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
-													 char *filename)
+SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
 {
-	/* connect my internal structure to the blank pointer passed to me */ 
+	/* connect my internal structure to the blank pointer passed to me */
 	*module_interface = &g729_module_interface;
 
-	/* indicate that the module should continue to be loaded */ 
+	/* indicate that the module should continue to be loaded */
 	return SWITCH_STATUS_SUCCESS;
 }
 

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_gsm/mod_gsm.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_gsm/mod_gsm.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_gsm/mod_gsm.c	Fri Mar 30 12:19:18 2007
@@ -28,7 +28,7 @@
  *
  * mod_codec_gsm.c -- gsm Codec Module
  *
- */  
+ */
 #include "switch.h"
 #include "gsm.h"
 static const char modname[] = "mod_gsm";
@@ -36,8 +36,7 @@
 	gsm encoder;
 	gsm decoder;
 };
-static switch_status_t switch_gsm_init(switch_codec_t *codec, switch_codec_flag_t flags,
-									   const switch_codec_settings_t *codec_settings) 
+static switch_status_t switch_gsm_init(switch_codec_t *codec, switch_codec_flag_t flags, const switch_codec_settings_t *codec_settings)
 {
 	struct gsm_context *context;
 	int encoding, decoding;
@@ -55,7 +54,7 @@
 	codec->private_info = context;
 	return SWITCH_STATUS_SUCCESS;
 }
-static switch_status_t switch_gsm_destroy(switch_codec_t *codec) 
+static switch_status_t switch_gsm_destroy(switch_codec_t *codec)
 {
 	struct gsm_context *context = codec->private_info;
 	int encoding = (codec->flags & SWITCH_CODEC_FLAG_ENCODE);
@@ -68,8 +67,8 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 static switch_status_t switch_gsm_encode(switch_codec_t *codec, switch_codec_t *other_codec, void *decoded_data,
-										  uint32_t decoded_data_len, uint32_t decoded_rate, void *encoded_data,
-										  uint32_t *encoded_data_len, uint32_t *encoded_rate, unsigned int *flag) 
+										 uint32_t decoded_data_len, uint32_t decoded_rate, void *encoded_data,
+										 uint32_t * encoded_data_len, uint32_t * encoded_rate, unsigned int *flag)
 {
 	struct gsm_context *context = codec->private_info;
 	if (!context) {
@@ -77,8 +76,8 @@
 	}
 	if (decoded_data_len % 320 == 0) {
 		uint32_t new_len = 0;
-		gsm_signal * ddp = decoded_data;
-		gsm_byte * edp = encoded_data;
+		gsm_signal *ddp = decoded_data;
+		gsm_byte *edp = encoded_data;
 		int x;
 		int loops = (int) decoded_data_len / 320;
 		for (x = 0; x < loops && new_len < *encoded_data_len; x++) {
@@ -97,8 +96,8 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 static switch_status_t switch_gsm_decode(switch_codec_t *codec, switch_codec_t *other_codec, void *encoded_data,
-										  uint32_t encoded_data_len, uint32_t encoded_rate, void *decoded_data,
-										  uint32_t *decoded_data_len, uint32_t *decoded_rate, unsigned int *flag) 
+										 uint32_t encoded_data_len, uint32_t encoded_rate, void *decoded_data,
+										 uint32_t * decoded_data_len, uint32_t * decoded_rate, unsigned int *flag)
 {
 	struct gsm_context *context = codec->private_info;
 	if (!context) {
@@ -107,8 +106,8 @@
 
 	if (encoded_data_len % 33 == 0) {
 		int loops = (int) encoded_data_len / 33;
-		gsm_byte * edp = encoded_data;
-		gsm_signal * ddp = decoded_data;
+		gsm_byte *edp = encoded_data;
+		gsm_signal *ddp = decoded_data;
 		int x;
 		uint32_t new_len = 0;
 
@@ -131,47 +130,46 @@
 }
 
 
-/* Registration */ 
-static const switch_codec_implementation_t gsm_8k_implementation = { 
-		/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO, 
-		/*.ianacode */ 3, 
-		/*.iananame */ "GSM", 
-		/*.fmtp */ NULL,
-		/*.samples_per_second */ 8000, 
-		/*.bits_per_second */ 13200, 
-		/*.microseconds_per_frame */ 20000, 
-		/*.samples_per_frame */ 160, 
-		/*.bytes_per_frame */ 320, 
-		/*.encoded_bytes_per_frame */ 33, 
-		/*.number_of_channels */ 1, 
-		/*.pref_frames_per_packet */ 1, 
-		/*.max_frames_per_packet */ 1, 
-		/*.init */ switch_gsm_init, 
-		/*.encode */ switch_gsm_encode, 
-		/*.decode */ switch_gsm_decode, 
-		/*.destroy */ switch_gsm_destroy, 
+/* Registration */
+static const switch_codec_implementation_t gsm_8k_implementation = {
+	/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
+	/*.ianacode */ 3,
+	/*.iananame */ "GSM",
+	/*.fmtp */ NULL,
+	/*.samples_per_second */ 8000,
+	/*.bits_per_second */ 13200,
+	/*.microseconds_per_frame */ 20000,
+	/*.samples_per_frame */ 160,
+	/*.bytes_per_frame */ 320,
+	/*.encoded_bytes_per_frame */ 33,
+	/*.number_of_channels */ 1,
+	/*.pref_frames_per_packet */ 1,
+	/*.max_frames_per_packet */ 1,
+	/*.init */ switch_gsm_init,
+	/*.encode */ switch_gsm_encode,
+	/*.decode */ switch_gsm_decode,
+	/*.destroy */ switch_gsm_destroy,
 };
-static const switch_codec_interface_t gsm_codec_interface = { 
-		/*.interface_name */ "gsm", 
-		/*.implementations */ &gsm_8k_implementation, 
+static const switch_codec_interface_t gsm_codec_interface = {
+	/*.interface_name */ "gsm",
+	/*.implementations */ &gsm_8k_implementation,
 };
-static switch_loadable_module_interface_t gsm_module_interface = { 
-		/*.module_name */ modname, 
-		/*.endpoint_interface */ NULL, 
-		/*.timer_interface */ NULL, 
-		/*.dialplan_interface */ NULL, 
-		/*.codec_interface */ &gsm_codec_interface, 
-		/*.application_interface */ NULL 
+static switch_loadable_module_interface_t gsm_module_interface = {
+	/*.module_name */ modname,
+	/*.endpoint_interface */ NULL,
+	/*.timer_interface */ NULL,
+	/*.dialplan_interface */ NULL,
+	/*.codec_interface */ &gsm_codec_interface,
+	/*.application_interface */ NULL
 };
-SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
-														char *filename)
+SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
 {
-	
-		/* connect my internal structure to the blank pointer passed to me */ 
-		*module_interface = &gsm_module_interface;
-	
-		/* indicate that the module should continue to be loaded */ 
-		return SWITCH_STATUS_SUCCESS;
+
+	/* connect my internal structure to the blank pointer passed to me */
+	*module_interface = &gsm_module_interface;
+
+	/* indicate that the module should continue to be loaded */
+	return SWITCH_STATUS_SUCCESS;
 }
 
 /* For Emacs:

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_ilbc/mod_ilbc.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_ilbc/mod_ilbc.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_ilbc/mod_ilbc.c	Fri Mar 30 12:19:18 2007
@@ -28,7 +28,7 @@
  *
  * mod_ilbc.c -- ilbc Codec Module
  *
- */  
+ */
 #include "switch.h"
 #include "iLBC_encode.h"
 #include "iLBC_decode.h"
@@ -44,12 +44,11 @@
 	uint16_t dbytes;
 };
 
-static switch_status_t switch_ilbc_init(switch_codec_t *codec, switch_codec_flag_t flags,
-									  const switch_codec_settings_t *codec_settings) 
+static switch_status_t switch_ilbc_init(switch_codec_t *codec, switch_codec_flag_t flags, const switch_codec_settings_t *codec_settings)
 {
 	struct ilbc_context *context;
 	int encoding, decoding;
-	uint8_t ms = (uint8_t)(codec->implementation->microseconds_per_frame / 1000);
+	uint8_t ms = (uint8_t) (codec->implementation->microseconds_per_frame / 1000);
 
 
 	if (ms != 20 && ms != 30) {
@@ -82,13 +81,13 @@
 	}
 
 	codec->fmtp_out = switch_core_strdup(codec->memory_pool, codec->implementation->fmtp);
-	
+
 	codec->private_info = context;
 	return SWITCH_STATUS_SUCCESS;
 }
 
 
-static switch_status_t switch_ilbc_destroy(switch_codec_t *codec) 
+static switch_status_t switch_ilbc_destroy(switch_codec_t *codec)
 {
 	codec->private_info = NULL;
 	return SWITCH_STATUS_SUCCESS;
@@ -96,14 +95,11 @@
 
 
 static switch_status_t switch_ilbc_encode(switch_codec_t *codec,
-										 switch_codec_t *other_codec,
-										 void *decoded_data,
-										 uint32_t decoded_data_len,
-										 uint32_t decoded_rate,
-										 void *encoded_data,
-										 uint32_t *encoded_data_len, 
-										 uint32_t *encoded_rate,
-										 unsigned int *flag)
+										  switch_codec_t *other_codec,
+										  void *decoded_data,
+										  uint32_t decoded_data_len,
+										  uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate,
+										  unsigned int *flag)
 {
 	struct ilbc_context *context = codec->private_info;
 
@@ -120,7 +116,7 @@
 		float buf[240];
 
 		for (x = 0; x < loops && new_len < *encoded_data_len; x++) {
-			for(y = 0; y < context->dbytes / sizeof(short) ; y++) {
+			for (y = 0; y < context->dbytes / sizeof(short); y++) {
 				buf[y] = ddp[y];
 			}
 			iLBC_encode(edp, buf, &context->encoder);
@@ -139,14 +135,11 @@
 }
 
 static switch_status_t switch_ilbc_decode(switch_codec_t *codec,
-										switch_codec_t *other_codec,
-										void *encoded_data,
-										uint32_t encoded_data_len,
-										uint32_t encoded_rate,
-										void *decoded_data,
-										uint32_t *decoded_data_len, 
-										uint32_t *decoded_rate, 
-										unsigned int *flag)
+										  switch_codec_t *other_codec,
+										  void *encoded_data,
+										  uint32_t encoded_data_len,
+										  uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate,
+										  unsigned int *flag)
 {
 	struct ilbc_context *context = codec->private_info;
 
@@ -165,8 +158,8 @@
 
 		for (x = 0; x < loops && new_len < *decoded_data_len; x++) {
 			iLBC_decode(buf, edp, &context->decoder, 1);
-			for(y = 0; y < context->dbytes / sizeof(short) ; y++) {
-				ddp[y] = (short)buf[y];
+			for (y = 0; y < context->dbytes / sizeof(short); y++) {
+				ddp[y] = (short) buf[y];
 			}
 			ddp += context->dbytes / sizeof(short);
 			edp += context->bytes;
@@ -186,153 +179,152 @@
 }
 
 
-/* Registration */ 
+/* Registration */
 
-static const switch_codec_implementation_t ilbc_8k_30ms_implementation = { 
-		/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO, 
-		/*.ianacode */ 97, 
-		/*.iananame */ "iLBC", 
-		/*.fmtp */ "mode=30",
-		/*.samples_per_second */ 8000, 
-		/*.bits_per_second */ NO_OF_BYTES_30MS*8*8000/BLOCKL_30MS,
-		/*.microseconds_per_frame */ 30000,
-		/*.samples_per_frame */ 240,
-		/*.bytes_per_frame */ 480,
-		/*.encoded_bytes_per_frame */ NO_OF_BYTES_30MS,
-		/*.number_of_channels */ 1,
-		/*.pref_frames_per_packet */ 1,
-		/*.max_frames_per_packet */ 1,
-		/*.init */ switch_ilbc_init,
-		/*.encode */ switch_ilbc_encode,
-		/*.decode */ switch_ilbc_decode,
-		/*.destroy */ switch_ilbc_destroy
+static const switch_codec_implementation_t ilbc_8k_30ms_implementation = {
+	/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
+	/*.ianacode */ 97,
+	/*.iananame */ "iLBC",
+	/*.fmtp */ "mode=30",
+	/*.samples_per_second */ 8000,
+	/*.bits_per_second */ NO_OF_BYTES_30MS * 8 * 8000 / BLOCKL_30MS,
+	/*.microseconds_per_frame */ 30000,
+	/*.samples_per_frame */ 240,
+	/*.bytes_per_frame */ 480,
+	/*.encoded_bytes_per_frame */ NO_OF_BYTES_30MS,
+	/*.number_of_channels */ 1,
+	/*.pref_frames_per_packet */ 1,
+	/*.max_frames_per_packet */ 1,
+	/*.init */ switch_ilbc_init,
+	/*.encode */ switch_ilbc_encode,
+	/*.decode */ switch_ilbc_decode,
+	/*.destroy */ switch_ilbc_destroy
 };
 
-static const switch_codec_implementation_t ilbc_8k_20ms_implementation = { 
-		/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO, 
-		/*.ianacode */ 97, 
-		/*.iananame */ "iLBC", 
-		/*.fmtp */ "mode=20",
-		/*.samples_per_second */ 8000, 
-		/*.bits_per_second */ NO_OF_BYTES_20MS*8*8000/BLOCKL_20MS, 
-		/*.microseconds_per_frame */ 20000,
-		/*.samples_per_frame */ 160,
-		/*.bytes_per_frame */ 320,
-		/*.encoded_bytes_per_frame */ NO_OF_BYTES_20MS, 
-		/*.number_of_channels */ 1,
-		/*.pref_frames_per_packet */ 1,
-		/*.max_frames_per_packet */ 1,
-		/*.init */ switch_ilbc_init,
-		/*.encode */ switch_ilbc_encode,
-		/*.decode */ switch_ilbc_decode,
-		/*.destroy */ switch_ilbc_destroy,
-		/*.next */ &ilbc_8k_30ms_implementation
+static const switch_codec_implementation_t ilbc_8k_20ms_implementation = {
+	/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
+	/*.ianacode */ 97,
+	/*.iananame */ "iLBC",
+	/*.fmtp */ "mode=20",
+	/*.samples_per_second */ 8000,
+	/*.bits_per_second */ NO_OF_BYTES_20MS * 8 * 8000 / BLOCKL_20MS,
+	/*.microseconds_per_frame */ 20000,
+	/*.samples_per_frame */ 160,
+	/*.bytes_per_frame */ 320,
+	/*.encoded_bytes_per_frame */ NO_OF_BYTES_20MS,
+	/*.number_of_channels */ 1,
+	/*.pref_frames_per_packet */ 1,
+	/*.max_frames_per_packet */ 1,
+	/*.init */ switch_ilbc_init,
+	/*.encode */ switch_ilbc_encode,
+	/*.decode */ switch_ilbc_decode,
+	/*.destroy */ switch_ilbc_destroy,
+	/*.next */ &ilbc_8k_30ms_implementation
 };
 
 
 
-static const switch_codec_implementation_t ilbc_102_8k_30ms_implementation = { 
-		/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO, 
-		/*.ianacode */ 102, 
-		/*.iananame */ "iLBC", 
-		/*.fmtp */ "mode=30",
-		/*.samples_per_second */ 8000, 
-		/*.bits_per_second */ NO_OF_BYTES_30MS*8*8000/BLOCKL_30MS,
-		/*.microseconds_per_frame */ 30000,
-		/*.samples_per_frame */ 240,
-		/*.bytes_per_frame */ 480,
-		/*.encoded_bytes_per_frame */ NO_OF_BYTES_30MS,
-		/*.number_of_channels */ 1,
-		/*.pref_frames_per_packet */ 1,
-		/*.max_frames_per_packet */ 1,
-		/*.init */ switch_ilbc_init,
-		/*.encode */ switch_ilbc_encode,
-		/*.decode */ switch_ilbc_decode,
-		/*.destroy */ switch_ilbc_destroy
+static const switch_codec_implementation_t ilbc_102_8k_30ms_implementation = {
+	/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
+	/*.ianacode */ 102,
+	/*.iananame */ "iLBC",
+	/*.fmtp */ "mode=30",
+	/*.samples_per_second */ 8000,
+	/*.bits_per_second */ NO_OF_BYTES_30MS * 8 * 8000 / BLOCKL_30MS,
+	/*.microseconds_per_frame */ 30000,
+	/*.samples_per_frame */ 240,
+	/*.bytes_per_frame */ 480,
+	/*.encoded_bytes_per_frame */ NO_OF_BYTES_30MS,
+	/*.number_of_channels */ 1,
+	/*.pref_frames_per_packet */ 1,
+	/*.max_frames_per_packet */ 1,
+	/*.init */ switch_ilbc_init,
+	/*.encode */ switch_ilbc_encode,
+	/*.decode */ switch_ilbc_decode,
+	/*.destroy */ switch_ilbc_destroy
 };
 
-static const switch_codec_implementation_t ilbc_102_8k_20ms_implementation = { 
-		/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO, 
-		/*.ianacode */ 102, 
-		/*.iananame */ "iLBC102", 
-		/*.fmtp */ "mode=20",
-		/*.samples_per_second */ 8000, 
-		/*.bits_per_second */ NO_OF_BYTES_20MS*8*8000/BLOCKL_20MS, 
-		/*.microseconds_per_frame */ 20000,
-		/*.samples_per_frame */ 160,
-		/*.bytes_per_frame */ 320,
-		/*.encoded_bytes_per_frame */ NO_OF_BYTES_20MS, 
-		/*.number_of_channels */ 1,
-		/*.pref_frames_per_packet */ 1,
-		/*.max_frames_per_packet */ 1,
-		/*.init */ switch_ilbc_init,
-		/*.encode */ switch_ilbc_encode,
-		/*.decode */ switch_ilbc_decode,
-		/*.destroy */ switch_ilbc_destroy,
-		/*.next */ &ilbc_102_8k_30ms_implementation
+static const switch_codec_implementation_t ilbc_102_8k_20ms_implementation = {
+	/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
+	/*.ianacode */ 102,
+	/*.iananame */ "iLBC102",
+	/*.fmtp */ "mode=20",
+	/*.samples_per_second */ 8000,
+	/*.bits_per_second */ NO_OF_BYTES_20MS * 8 * 8000 / BLOCKL_20MS,
+	/*.microseconds_per_frame */ 20000,
+	/*.samples_per_frame */ 160,
+	/*.bytes_per_frame */ 320,
+	/*.encoded_bytes_per_frame */ NO_OF_BYTES_20MS,
+	/*.number_of_channels */ 1,
+	/*.pref_frames_per_packet */ 1,
+	/*.max_frames_per_packet */ 1,
+	/*.init */ switch_ilbc_init,
+	/*.encode */ switch_ilbc_encode,
+	/*.decode */ switch_ilbc_decode,
+	/*.destroy */ switch_ilbc_destroy,
+	/*.next */ &ilbc_102_8k_30ms_implementation
 };
 
 
-static const switch_codec_implementation_t ilbc_8k_20ms_nonext_implementation = { 
-		/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO, 
-		/*.ianacode */ 97, 
-		/*.iananame */ "iLBC20ms",
-		/*.fmtp */ "mode=20",
-		/*.samples_per_second */ 8000, 
-		/*.bits_per_second */ NO_OF_BYTES_20MS*8*8000/BLOCKL_20MS, 
-		/*.microseconds_per_frame */ 20000,
-		/*.samples_per_frame */ 160,
-		/*.bytes_per_frame */ 320,
-		/*.encoded_bytes_per_frame */ NO_OF_BYTES_20MS, 
-		/*.number_of_channels */ 1,
-		/*.pref_frames_per_packet */ 1,
-		/*.max_frames_per_packet */ 1,
-		/*.init */ switch_ilbc_init,
-		/*.encode */ switch_ilbc_encode,
-		/*.decode */ switch_ilbc_decode,
-		/*.destroy */ switch_ilbc_destroy
+static const switch_codec_implementation_t ilbc_8k_20ms_nonext_implementation = {
+	/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
+	/*.ianacode */ 97,
+	/*.iananame */ "iLBC20ms",
+	/*.fmtp */ "mode=20",
+	/*.samples_per_second */ 8000,
+	/*.bits_per_second */ NO_OF_BYTES_20MS * 8 * 8000 / BLOCKL_20MS,
+	/*.microseconds_per_frame */ 20000,
+	/*.samples_per_frame */ 160,
+	/*.bytes_per_frame */ 320,
+	/*.encoded_bytes_per_frame */ NO_OF_BYTES_20MS,
+	/*.number_of_channels */ 1,
+	/*.pref_frames_per_packet */ 1,
+	/*.max_frames_per_packet */ 1,
+	/*.init */ switch_ilbc_init,
+	/*.encode */ switch_ilbc_encode,
+	/*.decode */ switch_ilbc_decode,
+	/*.destroy */ switch_ilbc_destroy
 };
 
 
-static const switch_codec_interface_t ilbc_20ms_codec_interface = { 
-		/*.interface_name */ "ilbc", 
-		/*.implementations */ &ilbc_8k_20ms_nonext_implementation
+static const switch_codec_interface_t ilbc_20ms_codec_interface = {
+	/*.interface_name */ "ilbc",
+	/*.implementations */ &ilbc_8k_20ms_nonext_implementation
 };
 
-static const switch_codec_interface_t ilbc_102_codec_interface = { 
-		/*.interface_name */ "ilbc", 
-		/*.implementations */ &ilbc_102_8k_20ms_implementation, 
-		/*.next*/ &ilbc_20ms_codec_interface
+static const switch_codec_interface_t ilbc_102_codec_interface = {
+	/*.interface_name */ "ilbc",
+	/*.implementations */ &ilbc_102_8k_20ms_implementation,
+	/*.next */ &ilbc_20ms_codec_interface
 };
 
-static const switch_codec_interface_t ilbc_codec_interface = { 
-		/*.interface_name */ "ilbc", 
-		/*.implementations */ &ilbc_8k_20ms_implementation, 
-		/*.next*/ &ilbc_102_codec_interface
+static const switch_codec_interface_t ilbc_codec_interface = {
+	/*.interface_name */ "ilbc",
+	/*.implementations */ &ilbc_8k_20ms_implementation,
+	/*.next */ &ilbc_102_codec_interface
 };
 
 
-static switch_loadable_module_interface_t ilbc_module_interface = { 
-		/*.module_name */ modname, 
-		/*.endpoint_interface */ NULL, 
-		/*.timer_interface */ NULL, 
-		/*.dialplan_interface */ NULL, 
-		/*.codec_interface */ &ilbc_codec_interface, 
-		/*.application_interface */ NULL 
+static switch_loadable_module_interface_t ilbc_module_interface = {
+	/*.module_name */ modname,
+	/*.endpoint_interface */ NULL,
+	/*.timer_interface */ NULL,
+	/*.dialplan_interface */ NULL,
+	/*.codec_interface */ &ilbc_codec_interface,
+	/*.application_interface */ NULL
 };
 
 
 
-SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
-														char *filename)
+SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
 {
-	
-		/* connect my internal structure to the blank pointer passed to me */ 
-		*module_interface = &ilbc_module_interface;
-	
 
-		/* indicate that the module should continue to be loaded */ 
-		return SWITCH_STATUS_SUCCESS;
+	/* connect my internal structure to the blank pointer passed to me */
+	*module_interface = &ilbc_module_interface;
+
+
+	/* indicate that the module should continue to be loaded */
+	return SWITCH_STATUS_SUCCESS;
 
 }
 

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_l16/mod_l16.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_l16/mod_l16.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_l16/mod_l16.c	Fri Mar 30 12:19:18 2007
@@ -34,8 +34,7 @@
 static const char modname[] = "mod_l16";
 
 
-static switch_status_t switch_raw_init(switch_codec_t *codec, switch_codec_flag_t flags,
-									 const switch_codec_settings_t *codec_settings)
+static switch_status_t switch_raw_init(switch_codec_t *codec, switch_codec_flag_t flags, const switch_codec_settings_t *codec_settings)
 {
 	int encoding, decoding;
 
@@ -50,12 +49,11 @@
 }
 
 static switch_status_t switch_raw_encode(switch_codec_t *codec,
-									   switch_codec_t *other_codec,
-									   void *decoded_data,
-									   uint32_t decoded_data_len,
-									   uint32_t decoded_rate,
-									   void *encoded_data,
-									   uint32_t *encoded_data_len, uint32_t *encoded_rate, unsigned int *flag)
+										 switch_codec_t *other_codec,
+										 void *decoded_data,
+										 uint32_t decoded_data_len,
+										 uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate,
+										 unsigned int *flag)
 {
 	/* NOOP indicates that the audio in is already the same as the audio out, so no conversion was necessary. */
 	if (codec && other_codec && codec->implementation->samples_per_second != other_codec->implementation->samples_per_second) {
@@ -67,12 +65,11 @@
 }
 
 static switch_status_t switch_raw_decode(switch_codec_t *codec,
-									   switch_codec_t *other_codec,
-									   void *encoded_data,
-									   uint32_t encoded_data_len,
-									   uint32_t encoded_rate,
-									   void *decoded_data,
-									   uint32_t *decoded_data_len, uint32_t *decoded_rate, unsigned int *flag)
+										 switch_codec_t *other_codec,
+										 void *encoded_data,
+										 uint32_t encoded_data_len,
+										 uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate,
+										 unsigned int *flag)
 {
 	if (codec && other_codec && codec->implementation->samples_per_second != other_codec->implementation->samples_per_second) {
 		memcpy(decoded_data, encoded_data, encoded_data_len);
@@ -107,7 +104,7 @@
 	/*.encode = */ switch_raw_encode,
 	/*.decode = */ switch_raw_decode,
 	/*.destroy = */ switch_raw_destroy
-	/*.next = */ 
+		/*.next = */
 };
 
 static const switch_codec_implementation_t raw_32k_30ms_implementation = {
@@ -298,6 +295,7 @@
 	/*.destroy = */ switch_raw_destroy,
 	/*.next = */ &raw_16k_20ms_implementation
 };
+
 ///////////////////////////////
 
 

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_lpc10/mod_lpc10.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_lpc10/mod_lpc10.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_lpc10/mod_lpc10.c	Fri Mar 30 12:19:18 2007
@@ -28,16 +28,16 @@
  *
  * mod_lpc10.c -- LPC10 Codec Module
  *
- */  
+ */
 
 #include "switch.h"
 #include "lpc10.h"
 
 enum {
 	SamplesPerFrame = 180,
-	BitsPerFrame    = 54,
-	BytesPerFrame   = (BitsPerFrame+7)/8,
-	BitsPerSecond   = 2400
+	BitsPerFrame = 54,
+	BytesPerFrame = (BitsPerFrame + 7) / 8,
+	BitsPerSecond = 2400
 };
 
 #define   SampleValueScale 32768.0
@@ -51,8 +51,7 @@
 	struct lpc10_decoder_state decoder_object;
 };
 
-static switch_status_t switch_lpc10_init(switch_codec_t *codec, switch_codec_flag_t flags,
-									  const switch_codec_settings_t *codec_settings) 
+static switch_status_t switch_lpc10_init(switch_codec_t *codec, switch_codec_flag_t flags, const switch_codec_settings_t *codec_settings)
 {
 	uint32_t encoding, decoding;
 	struct lpc10_context *context = NULL;
@@ -78,44 +77,39 @@
 	}
 }
 
-static switch_status_t switch_lpc10_destroy(switch_codec_t *codec) 
+static switch_status_t switch_lpc10_destroy(switch_codec_t *codec)
 {
 	codec->private_info = NULL;
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t switch_lpc10_encode(switch_codec_t *codec, 
-										switch_codec_t *other_codec, 
-										void *decoded_data,
-
-										uint32_t decoded_data_len, 
-										uint32_t decoded_rate, 
-										void *encoded_data,
-
-										uint32_t *encoded_data_len, 
-										uint32_t *encoded_rate, 
-										unsigned int *flag) 
+static switch_status_t switch_lpc10_encode(switch_codec_t *codec,
+										   switch_codec_t *other_codec,
+										   void *decoded_data,
+										   uint32_t decoded_data_len,
+										   uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate,
+										   unsigned int *flag)
 {
 	struct lpc10_context *context = codec->private_info;
 	uint8_t i;
 	int32_t bits[BitsPerFrame];
 	real speech[SamplesPerFrame];
-	const short *sampleBuffer = (const short *)decoded_data;
-	unsigned char *buffer = (unsigned char *)encoded_data;
+	const short *sampleBuffer = (const short *) decoded_data;
+	unsigned char *buffer = (unsigned char *) encoded_data;
 
 	if (!context) {
 		return SWITCH_STATUS_FALSE;
 	}
 
 	for (i = 0; i < SamplesPerFrame; i++)
-		speech[i] = (real)(sampleBuffer[i]/SampleValueScale);
+		speech[i] = (real) (sampleBuffer[i] / SampleValueScale);
 
 	lpc10_encode(speech, bits, &context->encoder_object);
 
 	memset(encoded_data, 0, BytesPerFrame);
 	for (i = 0; i < BitsPerFrame; i++) {
 		if (bits[i])
-			buffer[i>>3] |= 1 << (i&7);
+			buffer[i >> 3] |= 1 << (i & 7);
 	}
 
 	*encoded_data_len = BytesPerFrame;
@@ -123,91 +117,85 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t switch_lpc10_decode(switch_codec_t *codec, 
-										switch_codec_t *other_codec, 
-										void *encoded_data,
-
-										uint32_t encoded_data_len, 
-										uint32_t encoded_rate, 
-										void *decoded_data,
-
-										uint32_t *decoded_data_len, 
-										uint32_t *decoded_rate, 
-										unsigned int *flag) 
+static switch_status_t switch_lpc10_decode(switch_codec_t *codec,
+										   switch_codec_t *other_codec,
+										   void *encoded_data,
+										   uint32_t encoded_data_len,
+										   uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate,
+										   unsigned int *flag)
 {
 	struct lpc10_context *context = codec->private_info;
 	int i;
 	INT32 bits[BitsPerFrame];
 	real speech[SamplesPerFrame];
-	short *sampleBuffer = (short *)decoded_data;
-	const unsigned char *buffer = (const unsigned char *)encoded_data;
+	short *sampleBuffer = (short *) decoded_data;
+	const unsigned char *buffer = (const unsigned char *) encoded_data;
 
 	if (!context) {
 		return SWITCH_STATUS_FALSE;
 	}
 
 	for (i = 0; i < BitsPerFrame; i++)
-		bits[i] = (buffer[i>>3]&(1<<(i&7))) != 0;
+		bits[i] = (buffer[i >> 3] & (1 << (i & 7))) != 0;
 
 	lpc10_decode(bits, speech, &context->decoder_object);
 
 	for (i = 0; i < SamplesPerFrame; i++) {
-		real sample = (real)(speech[i]*SampleValueScale);
+		real sample = (real) (speech[i] * SampleValueScale);
 		if (sample < MinSampleValue)
 			sample = MinSampleValue;
 		else if (sample > MaxSampleValue)
 			sample = MaxSampleValue;
-		sampleBuffer[i] = (short)sample;
+		sampleBuffer[i] = (short) sample;
 	}
 
-	*decoded_data_len = SamplesPerFrame*2;
+	*decoded_data_len = SamplesPerFrame * 2;
 
 	return SWITCH_STATUS_SUCCESS;
 }
 
-/* Registration */ 
+/* Registration */
 
-static const switch_codec_implementation_t lpc10_implementation = { 
-	/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO, 
-	/*.ianacode */ 7, 
-	/*.iananame */ "LPC", 
+static const switch_codec_implementation_t lpc10_implementation = {
+	/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
+	/*.ianacode */ 7,
+	/*.iananame */ "LPC",
 	/*.fmtp */ NULL,
 	/*.samples_per_second */ 8000,
-	/*.bits_per_second */ 240, 
-	/*.microseconds_per_frame */ 22500, 
-	/*.samples_per_frame */ 180, 
-	/*.bytes_per_frame */ 360, 
-	/*.encoded_bytes_per_frame */ 7, 
-	/*.number_of_channels */ 1, 
-	/*.pref_frames_per_packet */ 1, 
-	/*.max_frames_per_packet */ 1, 
-	/*.init */ switch_lpc10_init, 
-	/*.encode */ switch_lpc10_encode, 
-	/*.decode */ switch_lpc10_decode, 
-	/*.destroy */ switch_lpc10_destroy, 
+	/*.bits_per_second */ 240,
+	/*.microseconds_per_frame */ 22500,
+	/*.samples_per_frame */ 180,
+	/*.bytes_per_frame */ 360,
+	/*.encoded_bytes_per_frame */ 7,
+	/*.number_of_channels */ 1,
+	/*.pref_frames_per_packet */ 1,
+	/*.max_frames_per_packet */ 1,
+	/*.init */ switch_lpc10_init,
+	/*.encode */ switch_lpc10_encode,
+	/*.decode */ switch_lpc10_decode,
+	/*.destroy */ switch_lpc10_destroy,
 };
 
-const switch_codec_interface_t lpc10_codec_interface = { 
-	/*.interface_name */ "LPC-10 2.4kbps", 
-	/*.implementations */ &lpc10_implementation, 
+const switch_codec_interface_t lpc10_codec_interface = {
+	/*.interface_name */ "LPC-10 2.4kbps",
+	/*.implementations */ &lpc10_implementation,
 };
 
-static switch_loadable_module_interface_t lpc10_module_interface = { 
-	/*.module_name */ modname, 
-	/*.endpoint_interface */ NULL, 
-	/*.timer_interface */ NULL, 
-	/*.dialplan_interface */ NULL, 
-	/*.codec_interface */ &lpc10_codec_interface, 
-	/*.application_interface */ NULL 
+static switch_loadable_module_interface_t lpc10_module_interface = {
+	/*.module_name */ modname,
+	/*.endpoint_interface */ NULL,
+	/*.timer_interface */ NULL,
+	/*.dialplan_interface */ NULL,
+	/*.codec_interface */ &lpc10_codec_interface,
+	/*.application_interface */ NULL
 };
 
-SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
-													 char *filename)
+SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
 {
-	/* connect my internal structure to the blank pointer passed to me */ 
+	/* connect my internal structure to the blank pointer passed to me */
 	*module_interface = &lpc10_module_interface;
 
-	/* indicate that the module should continue to be loaded */ 
+	/* indicate that the module should continue to be loaded */
 	return SWITCH_STATUS_SUCCESS;
 }
 

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_speex/mod_speex.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_speex/mod_speex.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/codecs/mod_speex/mod_speex.c	Fri Mar 30 12:19:18 2007
@@ -72,8 +72,7 @@
 	int decoder_mode;
 };
 
-static switch_status_t switch_speex_init(switch_codec_t *codec, switch_codec_flag_t flags,
-									   const switch_codec_settings_t *codec_settings)
+static switch_status_t switch_speex_init(switch_codec_t *codec, switch_codec_flag_t flags, const switch_codec_settings_t *codec_settings)
 {
 	struct speex_context *context = NULL;
 	int encoding, decoding;
@@ -111,17 +110,14 @@
 			speex_encoder_ctl(context->encoder_state, SPEEX_GET_FRAME_SIZE, &context->encoder_frame_size);
 			speex_encoder_ctl(context->encoder_state, SPEEX_SET_COMPLEXITY, &codec->codec_settings.complexity);
 			if (codec->codec_settings.preproc) {
-				context->pp =
-					speex_preprocess_state_init(context->encoder_frame_size, codec->implementation->samples_per_second);
+				context->pp = speex_preprocess_state_init(context->encoder_frame_size, codec->implementation->samples_per_second);
 				speex_preprocess_ctl(context->pp, SPEEX_PREPROCESS_SET_VAD, &codec->codec_settings.pp_vad);
 				speex_preprocess_ctl(context->pp, SPEEX_PREPROCESS_SET_AGC, &codec->codec_settings.pp_agc);
 				speex_preprocess_ctl(context->pp, SPEEX_PREPROCESS_SET_AGC_LEVEL, &codec->codec_settings.pp_agc_level);
 				speex_preprocess_ctl(context->pp, SPEEX_PREPROCESS_SET_DENOISE, &codec->codec_settings.pp_denoise);
 				speex_preprocess_ctl(context->pp, SPEEX_PREPROCESS_SET_DEREVERB, &codec->codec_settings.pp_dereverb);
-				speex_preprocess_ctl(context->pp, SPEEX_PREPROCESS_SET_DEREVERB_DECAY,
-									 &codec->codec_settings.pp_dereverb_decay);
-				speex_preprocess_ctl(context->pp, SPEEX_PREPROCESS_SET_DEREVERB_LEVEL,
-									 &codec->codec_settings.pp_dereverb_level);
+				speex_preprocess_ctl(context->pp, SPEEX_PREPROCESS_SET_DEREVERB_DECAY, &codec->codec_settings.pp_dereverb_decay);
+				speex_preprocess_ctl(context->pp, SPEEX_PREPROCESS_SET_DEREVERB_LEVEL, &codec->codec_settings.pp_dereverb_level);
 			}
 
 			if (!codec->codec_settings.abr && !codec->codec_settings.vbr) {
@@ -158,12 +154,11 @@
 }
 
 static switch_status_t switch_speex_encode(switch_codec_t *codec,
-										 switch_codec_t *other_codec,
-										 void *decoded_data,
-										 uint32_t decoded_data_len,
-										 uint32_t decoded_rate,
-										 void *encoded_data,
-										 uint32_t *encoded_data_len, uint32_t *encoded_rate, unsigned int *flag)
+										   switch_codec_t *other_codec,
+										   void *decoded_data,
+										   uint32_t decoded_data_len,
+										   uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate,
+										   unsigned int *flag)
 {
 	struct speex_context *context = codec->private_info;
 	short *buf;
@@ -211,12 +206,11 @@
 }
 
 static switch_status_t switch_speex_decode(switch_codec_t *codec,
-										 switch_codec_t *other_codec,
-										 void *encoded_data,
-										 uint32_t encoded_data_len,
-										 uint32_t encoded_rate,
-										 void *decoded_data,
-										 uint32_t *decoded_data_len, uint32_t *decoded_rate, unsigned int *flag)
+										   switch_codec_t *other_codec,
+										   void *encoded_data,
+										   uint32_t encoded_data_len,
+										   uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate,
+										   unsigned int *flag)
 {
 	struct speex_context *context = codec->private_info;
 	short *buf;

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/dialplans/mod_dialplan_directory/mod_dialplan_directory.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/dialplans/mod_dialplan_directory/mod_dialplan_directory.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/dialplans/mod_dialplan_directory/mod_dialplan_directory.c	Fri Mar 30 12:19:18 2007
@@ -46,12 +46,12 @@
 } globals;
 
 SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_directory_name, globals.directory_name)
-SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_host, globals.host)
-SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_dn, globals.dn)
-SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_pass, globals.pass)
-SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_base, globals.base)
+	SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_host, globals.host)
+	SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_dn, globals.dn)
+	SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_pass, globals.pass)
+	SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_base, globals.base)
 
-static void load_config(void)
+	 static void load_config(void)
 {
 	char *cf = "dialplan_directory.conf";
 	switch_xml_t cfg, xml, settings, param;
@@ -100,19 +100,14 @@
 	caller_profile = switch_channel_get_caller_profile(channel);
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Hello %s You Dialed %s!\n", caller_profile->caller_id_name,
-						  caller_profile->destination_number);
-	
-	
-	if (! (globals.directory_name && globals.host && globals.dn && globals.base && globals.pass)) {
+					  caller_profile->destination_number);
+
+
+	if (!(globals.directory_name && globals.host && globals.dn && globals.base && globals.pass)) {
 		return NULL;
 	}
 
-	if (switch_core_directory_open(&dh, 
-								   globals.directory_name,
-								   globals.host,
-								   globals.dn,
-								   globals.pass,
-								   NULL) != SWITCH_STATUS_SUCCESS) {
+	if (switch_core_directory_open(&dh, globals.directory_name, globals.host, globals.dn, globals.pass, NULL) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't connect\n");
 		return NULL;
 	}
@@ -127,10 +122,9 @@
 	while (switch_core_directory_next(&dh) == SWITCH_STATUS_SUCCESS) {
 		while (switch_core_directory_next_pair(&dh, &var, &val) == SWITCH_STATUS_SUCCESS) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "DIRECTORY VALUE [%s]=[%s]\n", var, val);
-			if(!strcasecmp(var, "callflow")) {
+			if (!strcasecmp(var, "callflow")) {
 				if (!extension) {
-					if ((extension = switch_caller_extension_new(session, caller_profile->destination_number,
-																  caller_profile->destination_number)) == 0) {
+					if ((extension = switch_caller_extension_new(session, caller_profile->destination_number, caller_profile->destination_number)) == 0) {
 						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "memory error!\n");
 						goto out;
 					}
@@ -143,11 +137,11 @@
 			}
 		}
 	}
- out:
-	
+  out:
+
 	switch_core_directory_close(&dh);
 
-	
+
 	if (extension) {
 		switch_channel_set_state(channel, CS_EXECUTE);
 	}
@@ -159,7 +153,7 @@
 static const switch_dialplan_interface_t directory_dialplan_interface = {
 	/*.interface_name = */ "directory",
 	/*.hunt_function = */ directory_dialplan_hunt
-	/*.next = NULL */
+		/*.next = NULL */
 };
 
 static const switch_loadable_module_interface_t directory_dialplan_module_interface = {

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c	Fri Mar 30 12:19:18 2007
@@ -50,7 +50,7 @@
 	switch_channel_t *channel;
 	char *exten_name = (char *) switch_xml_attr_soft(xexten, "name");
 	int proceed = 0;
-    switch_stream_handle_t stream = {0};
+	switch_stream_handle_t stream = { 0 };
 
 	channel = switch_core_session_get_channel(session);
 	caller_profile = switch_channel_get_caller_profile(channel);
@@ -63,7 +63,7 @@
 		switch_regex_t *re = NULL;
 		int ovector[30];
 		break_t do_break_i = BREAK_ON_FALSE;
-		
+
 		field = (char *) switch_xml_attr(xcond, "field");
 
 		expression = (char *) switch_xml_attr_soft(xcond, "expression");
@@ -83,32 +83,32 @@
 		if (field) {
 			if (*field == '$') {
 				char *cmd = switch_core_session_strdup(session, field + 1);
-				char *e, *arg;                
-                field = cmd;
-                field_data = "";
-
-                if (*field == '{') {
-                    field++;
-                    if ((e = strchr(field, '}'))) {
-                        *e = '\0';
-                        field_data = switch_channel_get_variable(channel, field);
-                    }
-                } else {
-                    switch_safe_free(stream.data);
-                    memset(&stream, 0, sizeof(stream));
-                    SWITCH_STANDARD_STREAM(stream);
-
-                    if ((arg = strchr(cmd, '('))) {
-                        *arg++ = '\0';
-                        if ((e = strchr(arg, ')'))) {
-                            *e = '\0';
-                            if (switch_api_execute(cmd, arg, session, &stream) == SWITCH_STATUS_SUCCESS) {
-                                field_data = stream.data;
-                            }
-                        }
-                    }
-                }
-            } else {
+				char *e, *arg;
+				field = cmd;
+				field_data = "";
+
+				if (*field == '{') {
+					field++;
+					if ((e = strchr(field, '}'))) {
+						*e = '\0';
+						field_data = switch_channel_get_variable(channel, field);
+					}
+				} else {
+					switch_safe_free(stream.data);
+					memset(&stream, 0, sizeof(stream));
+					SWITCH_STANDARD_STREAM(stream);
+
+					if ((arg = strchr(cmd, '('))) {
+						*arg++ = '\0';
+						if ((e = strchr(arg, ')'))) {
+							*e = '\0';
+							if (switch_api_execute(cmd, arg, session, &stream) == SWITCH_STATUS_SUCCESS) {
+								field_data = stream.data;
+							}
+						}
+					}
+				}
+			} else {
 				field_data = switch_caller_get_field_by_name(caller_profile, field);
 			}
 			if (!field_data) {
@@ -119,18 +119,17 @@
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Regex mismatch\n");
 
 				for (xaction = switch_xml_child(xcond, "anti-action"); xaction; xaction = xaction->next) {
-					char *application = (char*) switch_xml_attr_soft(xaction, "application");
+					char *application = (char *) switch_xml_attr_soft(xaction, "application");
 					char *data = (char *) switch_xml_attr_soft(xaction, "data");
 
 					if (!*extension) {
-						if ((*extension =
-							 switch_caller_extension_new(session, exten_name, caller_profile->destination_number)) == 0) {
+						if ((*extension = switch_caller_extension_new(session, exten_name, caller_profile->destination_number)) == 0) {
 							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "memory error!\n");
-                            proceed = 0;
-                            goto done;
+							proceed = 0;
+							goto done;
 						}
 					}
-					
+
 					switch_caller_extension_add_application(session, *extension, application, data);
 				}
 
@@ -145,20 +144,20 @@
 
 
 		for (xaction = switch_xml_child(xcond, "action"); xaction; xaction = xaction->next) {
-			char *application = (char*) switch_xml_attr_soft(xaction, "application");
+			char *application = (char *) switch_xml_attr_soft(xaction, "application");
 			char *data = (char *) switch_xml_attr_soft(xaction, "data");
 			char *substituted = NULL;
-            uint32_t len = 0;
+			uint32_t len = 0;
 			char *app_data = NULL;
 
 			if (field && strchr(expression, '(')) {
-                len = (uint32_t)(strlen(data) + strlen(field_data) + 10);
-                if (!(substituted = malloc(len))) {
-                    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "memory error!\n");
-                    proceed = 0;
-                    goto done;
-                }
-                memset(substituted, 0, len);
+				len = (uint32_t) (strlen(data) + strlen(field_data) + 10);
+				if (!(substituted = malloc(len))) {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "memory error!\n");
+					proceed = 0;
+					goto done;
+				}
+				memset(substituted, 0, len);
 				switch_perform_substitution(re, proceed, data, field_data, substituted, len, ovector);
 				app_data = substituted;
 			} else {
@@ -166,18 +165,17 @@
 			}
 
 			if (!*extension) {
-				if ((*extension =
-					 switch_caller_extension_new(session, exten_name, caller_profile->destination_number)) == 0) {
+				if ((*extension = switch_caller_extension_new(session, exten_name, caller_profile->destination_number)) == 0) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "memory error!\n");
-                    proceed = 0;
-                    goto done;
+					proceed = 0;
+					goto done;
 				}
 			}
 
 			switch_caller_extension_add_application(session, *extension, application, app_data);
-            switch_safe_free(substituted);
+			switch_safe_free(substituted);
 		}
-        
+
 		switch_regex_safe_free(re);
 
 		if (do_break_i == BREAK_ON_TRUE || do_break_i == BREAK_ALWAYS) {
@@ -185,110 +183,109 @@
 		}
 	}
 
- done:
-    switch_safe_free(stream.data);
+  done:
+	switch_safe_free(stream.data);
 	return proceed;
 }
 
-static switch_status_t dialplan_xml_locate(switch_core_session_t *session,
-										   switch_caller_profile_t *caller_profile,
-										   switch_xml_t *root,
-										   switch_xml_t *node)
+static switch_status_t dialplan_xml_locate(switch_core_session_t *session, switch_caller_profile_t *caller_profile, switch_xml_t * root,
+										   switch_xml_t * node)
 {
 	switch_status_t status = SWITCH_STATUS_GENERR;
 	switch_channel_t *channel;
-    switch_stream_handle_t stream = {0};
-    switch_size_t encode_len = 1024, new_len = 0;
-    char *encode_buf = NULL;
-    char *prof[12] = {0}, *prof_names[12] = {0}, *e = NULL;
-    switch_hash_index_t *hi;
-    uint32_t x = 0;
+	switch_stream_handle_t stream = { 0 };
+	switch_size_t encode_len = 1024, new_len = 0;
+	char *encode_buf = NULL;
+	char *prof[12] = { 0 }, *prof_names[12] = {
+	0}, *e = NULL;
+	switch_hash_index_t *hi;
+	uint32_t x = 0;
 
 	channel = switch_core_session_get_channel(session);
 
-    SWITCH_STANDARD_STREAM(stream);
-    
-    if (!(encode_buf = malloc(encode_len))) {
-        goto done;
-    }
-    
-    prof[0] = caller_profile->context;
-    prof[1] = caller_profile->destination_number;
-    prof[2] = caller_profile->caller_id_name;
-    prof[3] = caller_profile->caller_id_number;
-    prof[4] = caller_profile->network_addr;
-    prof[5] = caller_profile->ani;
-    prof[6] = caller_profile->aniii;
-    prof[7] = caller_profile->rdnis;
-    prof[8] = caller_profile->source;
-    prof[9] = caller_profile->chan_name;
-    prof[10] = caller_profile->uuid;
-
-    prof_names[0] = "context";
-    prof_names[1] = "destination_number";
-    prof_names[2] = "caller_id_name";
-    prof_names[3] = "caller_id_number";
-    prof_names[4] = "network_addr";
-    prof_names[5] = "ani";
-    prof_names[6] = "aniii";
-    prof_names[7] = "rdnis";
-    prof_names[8] = "source";
-    prof_names[9] = "chan_name";
-    prof_names[10] = "uuid";
+	SWITCH_STANDARD_STREAM(stream);
+
+	if (!(encode_buf = malloc(encode_len))) {
+		goto done;
+	}
+
+	prof[0] = caller_profile->context;
+	prof[1] = caller_profile->destination_number;
+	prof[2] = caller_profile->caller_id_name;
+	prof[3] = caller_profile->caller_id_number;
+	prof[4] = caller_profile->network_addr;
+	prof[5] = caller_profile->ani;
+	prof[6] = caller_profile->aniii;
+	prof[7] = caller_profile->rdnis;
+	prof[8] = caller_profile->source;
+	prof[9] = caller_profile->chan_name;
+	prof[10] = caller_profile->uuid;
+
+	prof_names[0] = "context";
+	prof_names[1] = "destination_number";
+	prof_names[2] = "caller_id_name";
+	prof_names[3] = "caller_id_number";
+	prof_names[4] = "network_addr";
+	prof_names[5] = "ani";
+	prof_names[6] = "aniii";
+	prof_names[7] = "rdnis";
+	prof_names[8] = "source";
+	prof_names[9] = "chan_name";
+	prof_names[10] = "uuid";
 
-    for (x = 0; prof[x]; x++) {
+	for (x = 0; prof[x]; x++) {
 		if (switch_strlen_zero(prof[x])) {
 			continue;
 		}
-        new_len = (strlen(prof[x]) * 3) + 1;
-        if (encode_len < new_len) {
-            char *tmp;
-            
-            encode_len = new_len;
-
-            if (!(tmp = realloc(encode_buf, encode_len))) {
-                goto done;
-            }
-
-            encode_buf = tmp;
-        }
-        switch_url_encode(prof[x], encode_buf, encode_len - 1);
-        stream.write_function(&stream, "%s=%s&", prof_names[x], encode_buf);
-    }
+		new_len = (strlen(prof[x]) * 3) + 1;
+		if (encode_len < new_len) {
+			char *tmp;
+
+			encode_len = new_len;
+
+			if (!(tmp = realloc(encode_buf, encode_len))) {
+				goto done;
+			}
+
+			encode_buf = tmp;
+		}
+		switch_url_encode(prof[x], encode_buf, encode_len - 1);
+		stream.write_function(&stream, "%s=%s&", prof_names[x], encode_buf);
+	}
 
 
 	for (hi = switch_channel_variable_first(channel, switch_core_session_get_pool(session)); hi; hi = switch_hash_next(hi)) {
-        void *val;
-        const void *var;
+		void *val;
+		const void *var;
 		switch_hash_this(hi, &var, NULL, &val);
-        
-        new_len = (strlen((char *) var) * 3) + 1;
-        if (encode_len < new_len) {
-            char *tmp;
-            
-            encode_len = new_len;
-
-            if (!(tmp = realloc(encode_buf, encode_len))) {
-                goto done;
-            }
-
-            encode_buf = tmp;
-        }
-
-        switch_url_encode((char *) val, encode_buf, encode_len - 1);
-        stream.write_function(&stream, "%s=%s&", (char *) var, encode_buf);
-        
-	}
-    
-    e = (char *)stream.data + (strlen((char *)stream.data) - 1);
-
-    if (e && *e == '&') {
-        *e = '\0';
-    }
+
+		new_len = (strlen((char *) var) * 3) + 1;
+		if (encode_len < new_len) {
+			char *tmp;
+
+			encode_len = new_len;
+
+			if (!(tmp = realloc(encode_buf, encode_len))) {
+				goto done;
+			}
+
+			encode_buf = tmp;
+		}
+
+		switch_url_encode((char *) val, encode_buf, encode_len - 1);
+		stream.write_function(&stream, "%s=%s&", (char *) var, encode_buf);
+
+	}
+
+	e = (char *) stream.data + (strlen((char *) stream.data) - 1);
+
+	if (e && *e == '&') {
+		*e = '\0';
+	}
 
 	status = switch_xml_locate("dialplan", NULL, NULL, NULL, root, node, stream.data);
 
-done:
+  done:
 	switch_safe_free(stream.data);
 	switch_safe_free(encode_buf);
 	return status;
@@ -300,7 +297,7 @@
 	switch_caller_extension_t *extension = NULL;
 	switch_channel_t *channel;
 	switch_xml_t alt_root = NULL, cfg, xml = NULL, xcontext, xexten;
-    char *alt_path = (char *) arg;
+	char *alt_path = (char *) arg;
 
 	channel = switch_core_session_get_channel(session);
 
@@ -313,47 +310,45 @@
 		goto done;
 	}
 
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Processing %s->%s!\n", caller_profile->caller_id_name,
-					  caller_profile->destination_number);
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Processing %s->%s!\n", caller_profile->caller_id_name, caller_profile->destination_number);
 
 	/* get our handle to the "dialplan" section of the config */
 
 	if (!switch_strlen_zero(alt_path)) {
-        switch_xml_t conf = NULL, tag = NULL;
-        if (!(alt_root = switch_xml_parse_file(alt_path))) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of [%s] failed\n", alt_path);
-            goto done;
-        }
-        
-		if ((conf = switch_xml_find_child(alt_root, "section", "name", "dialplan")) && 
-			(tag = switch_xml_find_child(conf, "dialplan", NULL, NULL))) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Getting dialplan from alternate path: %s\n", alt_path);
-            xml = alt_root;
-            cfg = tag;
-        } else {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of dialplan failed\n");
-            goto done;
-        }
+		switch_xml_t conf = NULL, tag = NULL;
+		if (!(alt_root = switch_xml_parse_file(alt_path))) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of [%s] failed\n", alt_path);
+			goto done;
+		}
+
+		if ((conf = switch_xml_find_child(alt_root, "section", "name", "dialplan")) && (tag = switch_xml_find_child(conf, "dialplan", NULL, NULL))) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Getting dialplan from alternate path: %s\n", alt_path);
+			xml = alt_root;
+			cfg = tag;
+		} else {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of dialplan failed\n");
+			goto done;
+		}
 	} else {
 		if (dialplan_xml_locate(session, caller_profile, &xml, &cfg) != SWITCH_STATUS_SUCCESS) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of dialplan failed\n");
 			goto done;
 		}
-    }
-    
-    /* get a handle to the context tag */
+	}
+
+	/* get a handle to the context tag */
 	if (!(xcontext = switch_xml_find_child(cfg, "context", "name", caller_profile->context))) {
 		if (!(xcontext = switch_xml_find_child(cfg, "context", "name", "global"))) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "context %s not found\n", caller_profile->context);
 			goto done;
 		}
 	}
-	
+
 	if (!(xexten = switch_xml_find_child(xcontext, "extension", "name", caller_profile->destination_number))) {
 		xexten = switch_xml_child(xcontext, "extension");
 	}
-	
-	while(xexten) {
+
+	while (xexten) {
 		int proceed = 0;
 		char *cont = (char *) switch_xml_attr_soft(xexten, "continue");
 
@@ -374,7 +369,7 @@
 		switch_channel_set_state(channel, CS_EXECUTE);
 	}
 
-done:
+  done:
 	switch_xml_free(xml);
 	return extension;
 }
@@ -383,7 +378,7 @@
 static const switch_dialplan_interface_t dialplan_interface = {
 	/*.interface_name = */ "XML",
 	/*.hunt_function = */ dialplan_hunt
-	/*.next = NULL */
+		/*.next = NULL */
 };
 
 static const switch_loadable_module_interface_t dialplan_module_interface = {

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/directories/mod_ldap/mod_ldap.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/directories/mod_ldap/mod_ldap.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/directories/mod_ldap/mod_ldap.c	Fri Mar 30 12:19:18 2007
@@ -44,10 +44,10 @@
 
 struct ldap_context {
 	LDAP *ld;
-	LDAPMessage* msg;
-	LDAPMessage* entry;
-	BerElement* ber;
-	char* attr;
+	LDAPMessage *msg;
+	LDAPMessage *entry;
+	BerElement *ber;
+	char *attr;
 	char *var;
 	char *val;
 	char **vals;
@@ -60,14 +60,14 @@
 static switch_status_t mod_ldap_open(switch_directory_handle_t *dh, char *source, char *dsn, char *passwd)
 {
 	struct ldap_context *context;
-	int  auth_method = LDAP_AUTH_SIMPLE;
+	int auth_method = LDAP_AUTH_SIMPLE;
 	int desired_version = LDAP_VERSION3;
 
 	if ((context = switch_core_alloc(dh->memory_pool, sizeof(*context))) == 0) {
 		return SWITCH_STATUS_MEMERR;
 	}
-	
-	if ((context->ld = ldap_init(source, LDAP_PORT)) == NULL ) {
+
+	if ((context->ld = ldap_init(source, LDAP_PORT)) == NULL) {
 		return SWITCH_STATUS_FALSE;
 	}
 
@@ -76,11 +76,11 @@
 		return SWITCH_STATUS_FALSE;
 	}
 
-	if (ldap_bind_s(context->ld, dsn, passwd, auth_method) != LDAP_SUCCESS ) {
+	if (ldap_bind_s(context->ld, dsn, passwd, auth_method) != LDAP_SUCCESS) {
 		return SWITCH_STATUS_FALSE;
 	}
 
-	
+
 	dh->private_info = context;
 
 	return SWITCH_STATUS_SUCCESS;
@@ -112,7 +112,7 @@
 	if (ldap_count_entries(context->ld, context->msg) <= 0) {
 		return SWITCH_STATUS_FALSE;
 	}
-	
+
 	return SWITCH_STATUS_SUCCESS;
 }
 
@@ -161,7 +161,7 @@
 		*val = context->val;
 		return SWITCH_STATUS_SUCCESS;
 	} else {
-	itter:
+	  itter:
 		if (context->attr && context->vals) {
 			if ((*val = context->vals[context->vi++])) {
 				*var = context->attr;
@@ -177,7 +177,7 @@
 			ldap_memfree(context->val);
 			context->val = NULL;
 			if (context->ber) {
-				ber_free(context->ber,0);
+				ber_free(context->ber, 0);
 				context->ber = NULL;
 			}
 			context->attr = ldap_first_attribute(context->ld, context->entry, &context->ber);
@@ -192,18 +192,18 @@
 			goto itter;
 		}
 	}
-	
+
 	return SWITCH_STATUS_FALSE;
 }
 
 
 static const switch_directory_interface_t ldap_directory_interface = {
-    /*.interface_name */ "ldap",
-	/*.directory_open*/ mod_ldap_open,
-	/*.directory_close*/ mod_ldap_close,
-	/*.directory_query*/ mod_ldap_query,
-	/*.directory_next*/ mod_ldap_next,
-	/*.directory_next_pair*/ mod_ldap_next_pair
+	/*.interface_name */ "ldap",
+	/*.directory_open */ mod_ldap_open,
+	/*.directory_close */ mod_ldap_close,
+	/*.directory_query */ mod_ldap_query,
+	/*.directory_next */ mod_ldap_next,
+	/*.directory_next_pair */ mod_ldap_next_pair
 };
 
 

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_dingaling/mod_dingaling.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_dingaling/mod_dingaling.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_dingaling/mod_dingaling.c	Fri Mar 30 12:19:18 2007
@@ -45,12 +45,9 @@
 static switch_memory_pool_t *module_pool = NULL;
 
 static char sub_sql[] =
-"CREATE TABLE subscriptions (\n"
-"   sub_from            VARCHAR(255),\n"
-"   sub_to          VARCHAR(255),\n"
-"   show          VARCHAR(255),\n"
-"   status          VARCHAR(255)\n"
-");\n";
+	"CREATE TABLE subscriptions (\n"
+	"   sub_from            VARCHAR(255),\n" "   sub_to          VARCHAR(255),\n" "   show          VARCHAR(255),\n" "   status          VARCHAR(255)\n"
+	");\n";
 
 
 typedef enum {
@@ -65,16 +62,16 @@
 	TFLAG_CODEC_READY = (1 << 8),
 	TFLAG_TRANSPORT = (1 << 9),
 	TFLAG_ANSWER = (1 << 10),
-	TFLAG_VAD_IN = ( 1 << 11),
-	TFLAG_VAD_OUT = ( 1 << 12),
-	TFLAG_VAD = ( 1 << 13),
-	TFLAG_DO_CAND = ( 1 << 14),
+	TFLAG_VAD_IN = (1 << 11),
+	TFLAG_VAD_OUT = (1 << 12),
+	TFLAG_VAD = (1 << 13),
+	TFLAG_DO_CAND = (1 << 14),
 	TFLAG_DO_DESC = (1 << 15),
 	TFLAG_LANADDR = (1 << 16),
 	TFLAG_AUTO = (1 << 17),
 	TFLAG_DTMF = (1 << 18),
-	TFLAG_TIMER = ( 1 << 19),
-	TFLAG_TERM = ( 1 << 20),
+	TFLAG_TIMER = (1 << 19),
+	TFLAG_TERM = (1 << 20),
 	TFLAG_TRANSPORT_ACCEPT = (1 << 21),
 	TFLAG_READY = (1 << 22),
 } TFLAGS;
@@ -97,28 +94,28 @@
 	switch_hash_t *profile_hash;
 	int running;
 	int handles;
-    char guess_ip[80];
+	char guess_ip[80];
 } globals;
 
 struct mdl_profile {
-    char *name;
-    char *login;
-    char *password;
-    char *message;
+	char *name;
+	char *login;
+	char *password;
+	char *message;
 	char *auto_reply;
-    char *dialplan;
-    char *ip;
-    char *extip;
-    char *lanaddr;
+	char *dialplan;
+	char *ip;
+	char *extip;
+	char *lanaddr;
 	char *server;
-    char *exten;
-    char *context;
+	char *exten;
+	char *context;
 	char *timer_name;
 	char *dbname;
 	switch_mutex_t *mutex;
-    ldl_handle_t *handle;
-    uint32_t flags;
-    uint32_t user_flags;
+	ldl_handle_t *handle;
+	uint32_t flags;
+	uint32_t user_flags;
 };
 
 struct private_object {
@@ -170,32 +167,32 @@
 
 
 SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_dialplan, globals.dialplan)
-SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_string, globals.codec_string)
-SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_rates_string, globals.codec_rates_string)
+	SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_string, globals.codec_string)
+	SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_rates_string, globals.codec_rates_string)
 
-static switch_status_t dl_login(char *arg, switch_core_session_t *session, switch_stream_handle_t *stream);
-static switch_status_t dl_logout(char *profile_name, switch_core_session_t *session, switch_stream_handle_t *stream);
-static switch_status_t channel_on_init(switch_core_session_t *session);
-static switch_status_t channel_on_hangup(switch_core_session_t *session);
-static switch_status_t channel_on_ring(switch_core_session_t *session);
-static switch_status_t channel_on_loopback(switch_core_session_t *session);
-static switch_status_t channel_on_transmit(switch_core_session_t *session);
-static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile,
-													switch_core_session_t **new_session, switch_memory_pool_t **pool);
-static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout,
-										  switch_io_flag_t flags, int stream_id);
-static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout,
-										   switch_io_flag_t flags, int stream_id);
-static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig);
-
-static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsession, ldl_signal_t dl_signal, char *to, char *from, char *subject, char *msg);
-static ldl_status handle_response(ldl_handle_t *handle, char *id);
-static switch_status_t load_config(void);
-static int sin_callback(void *pArg, int argc, char **argv, char **columnNames);
+	 static switch_status_t dl_login(char *arg, switch_core_session_t *session, switch_stream_handle_t *stream);
+	 static switch_status_t dl_logout(char *profile_name, switch_core_session_t *session, switch_stream_handle_t *stream);
+	 static switch_status_t channel_on_init(switch_core_session_t *session);
+	 static switch_status_t channel_on_hangup(switch_core_session_t *session);
+	 static switch_status_t channel_on_ring(switch_core_session_t *session);
+	 static switch_status_t channel_on_loopback(switch_core_session_t *session);
+	 static switch_status_t channel_on_transmit(switch_core_session_t *session);
+	 static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session,
+														 switch_caller_profile_t *outbound_profile,
+														 switch_core_session_t **new_session, switch_memory_pool_t **pool);
+	 static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, switch_io_flag_t flags, int stream_id);
+	 static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flags, int stream_id);
+	 static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig);
+
+	 static ldl_status handle_signalling(ldl_handle_t * handle, ldl_session_t * dlsession, ldl_signal_t dl_signal,
+										 char *to, char *from, char *subject, char *msg);
+	 static ldl_status handle_response(ldl_handle_t * handle, char *id);
+	 static switch_status_t load_config(void);
+	 static int sin_callback(void *pArg, int argc, char **argv, char **columnNames);
 
 #define is_special(s) (s && (strstr(s, "ext+") || strstr(s, "user+")))
 
-static char *translate_rpid(char *in, char *ext)
+	 static char *translate_rpid(char *in, char *ext)
 {
 	char *r = NULL;
 
@@ -210,7 +207,7 @@
 	if (!in) {
 		return NULL;
 	}
-	
+
 	if (!strcasecmp(in, "busy")) {
 		r = "dnd";
 	}
@@ -228,7 +225,7 @@
 	} else if (ext && !strcasecmp(ext, "away")) {
 		r = "away";
 	}
-	
+
 	return r;
 }
 
@@ -242,7 +239,7 @@
 	char *rpid = argv[3];
 	char *status = argv[4];
 	//char *proto = argv[5];
-	
+
 	if (switch_strlen_zero(type)) {
 		type = NULL;
 	} else if (!strcasecmp(type, "unavailable")) {
@@ -283,10 +280,10 @@
 {
 	struct mdl_profile *profile = NULL;
 	switch_hash_index_t *hi;
-    void *val;
+	void *val;
 	char *proto = switch_event_get_header(event, "proto");
 	char *from = switch_event_get_header(event, "from");
-	char *status= switch_event_get_header(event, "status");
+	char *status = switch_event_get_header(event, "status");
 	char *rpid = switch_event_get_header(event, "rpid");
 	char *type = switch_event_get_header(event, "event_subtype");
 	char *sql;
@@ -306,35 +303,35 @@
 		status = NULL;
 	}
 
-	switch(event->event_id) {
-	case SWITCH_EVENT_PRESENCE_PROBE: 
-        if (proto) {
-        	char *sql;
-            switch_core_db_t *db;
-            char *errmsg;
-            char *to = switch_event_get_header(event, "to");
-            char *f_host = NULL;
-            if (to) {
-                if ((f_host = strchr(to, '@'))) {
-                    f_host++;
-                }
-            }
-
-            if (f_host && (profile = switch_core_hash_find(globals.profile_hash, f_host))) {
-                if (to && (sql = switch_mprintf("select * from subscriptions where sub_to='%q'", to))) {
-                    if (!(db = switch_core_db_open_file(profile->dbname))) {
-                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
-                        return;
-                    }
-                    switch_mutex_lock(profile->mutex);
-                    switch_core_db_exec(db, sql, sin_callback, profile, &errmsg);
-                    switch_mutex_unlock(profile->mutex);
-                    switch_core_db_close(db);
-                    switch_safe_free(sql);
-                }
-            }
-        }
-        return;
+	switch (event->event_id) {
+	case SWITCH_EVENT_PRESENCE_PROBE:
+		if (proto) {
+			char *sql;
+			switch_core_db_t *db;
+			char *errmsg;
+			char *to = switch_event_get_header(event, "to");
+			char *f_host = NULL;
+			if (to) {
+				if ((f_host = strchr(to, '@'))) {
+					f_host++;
+				}
+			}
+
+			if (f_host && (profile = switch_core_hash_find(globals.profile_hash, f_host))) {
+				if (to && (sql = switch_mprintf("select * from subscriptions where sub_to='%q'", to))) {
+					if (!(db = switch_core_db_open_file(profile->dbname))) {
+						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
+						return;
+					}
+					switch_mutex_lock(profile->mutex);
+					switch_core_db_exec(db, sql, sin_callback, profile, &errmsg);
+					switch_mutex_unlock(profile->mutex);
+					switch_core_db_close(db);
+					switch_safe_free(sql);
+				}
+			}
+		}
+		return;
 	case SWITCH_EVENT_PRESENCE_IN:
 		if (!status) {
 			status = "Available";
@@ -346,7 +343,7 @@
 	default:
 		break;
 	}
-	
+
 
 	if (!type) {
 		type = "";
@@ -357,20 +354,19 @@
 	if (!status) {
 		status = "Away";
 	}
-	
 
-	sql = switch_mprintf("select sub_from, sub_to,'%q','%q','%q','%q' from subscriptions where sub_to like '%%%q'", 
-						 type, rpid, status, proto, from);
-	
-	
+
+	sql = switch_mprintf("select sub_from, sub_to,'%q','%q','%q','%q' from subscriptions where sub_to like '%%%q'", type, rpid, status, proto, from);
+
+
 	for (hi = switch_hash_first(switch_hash_pool_get(globals.profile_hash), globals.profile_hash); hi; hi = switch_hash_next(hi)) {
 		char *errmsg;
-        switch_hash_this(hi, NULL, NULL, &val);
-        profile = (struct mdl_profile *) val;
+		switch_hash_this(hi, NULL, NULL, &val);
+		profile = (struct mdl_profile *) val;
 
-        if (!(profile->user_flags & LDL_FLAG_COMPONENT)) {
+		if (!(profile->user_flags & LDL_FLAG_COMPONENT)) {
 			continue;
-        }
+		}
 
 
 		if (sql) {
@@ -383,7 +379,7 @@
 			switch_mutex_unlock(profile->mutex);
 			switch_core_db_close(db);
 		}
-		
+
 
 	}
 
@@ -400,9 +396,9 @@
 	if (from && (f_user = strdup(from))) {
 		if ((f_host = strchr(f_user, '@'))) {
 			*f_host++ = '\0';
-            if ((f_resource = strchr(f_host, '/'))) {
-                *f_resource++ = '\0';
-            }
+			if ((f_resource = strchr(f_host, '/'))) {
+				*f_resource++ = '\0';
+			}
 		}
 	}
 
@@ -412,7 +408,7 @@
 		}
 
 		if (f_host && (profile = switch_core_hash_find(globals.profile_hash, f_host))) {
-			
+
 			if (!strcmp(proto, MDL_CHAT_PROTO)) {
 				from = hint;
 			} else {
@@ -439,12 +435,12 @@
 
 static void roster_event_handler(switch_event_t *event)
 {
-	char *status= switch_event_get_header(event, "status");
-	char *from= switch_event_get_header(event, "from");
+	char *status = switch_event_get_header(event, "status");
+	char *from = switch_event_get_header(event, "from");
 	char *event_type = switch_event_get_header(event, "event_type");
 	struct mdl_profile *profile = NULL;
 	switch_hash_index_t *hi;
-    void *val;
+	void *val;
 	char *sql;
 	switch_core_db_t *db;
 
@@ -453,7 +449,7 @@
 	}
 
 	if (switch_strlen_zero(event_type)) {
-		event_type="presence";
+		event_type = "presence";
 	}
 
 	if (from) {
@@ -464,12 +460,12 @@
 
 	for (hi = switch_hash_first(switch_hash_pool_get(globals.profile_hash), globals.profile_hash); hi; hi = switch_hash_next(hi)) {
 		char *errmsg;
-        switch_hash_this(hi, NULL, NULL, &val);
-        profile = (struct mdl_profile *) val;
+		switch_hash_this(hi, NULL, NULL, &val);
+		profile = (struct mdl_profile *) val;
 
-        if (!(profile->user_flags & LDL_FLAG_COMPONENT)) {
+		if (!(profile->user_flags & LDL_FLAG_COMPONENT)) {
 			continue;
-        }
+		}
 
 
 		if (sql) {
@@ -482,7 +478,7 @@
 			switch_mutex_unlock(profile->mutex);
 			switch_core_db_close(db);
 		}
-		
+
 	}
 
 	switch_safe_free(sql);
@@ -498,7 +494,7 @@
 
 
 	ldl_handle_send_presence(profile->handle, sub_to, sub_from, "unavailable", "dnd", "Bub-Bye");
-	
+
 	return 0;
 }
 
@@ -510,12 +506,12 @@
 
 	//char *sub_from = argv[0];
 	char *sub_to = argv[1];
-	
+
 	if (is_special(sub_to)) {
 		if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
 			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "proto", MDL_CHAT_PROTO);
 			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "login", "%s", profile->login);
-			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s",  sub_to);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s", sub_to);
 			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "rpid", "available");
 			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "status", "Online");
 			switch_event_fire(&event);
@@ -529,22 +525,22 @@
 {
 	struct mdl_profile *profile = NULL;
 	switch_hash_index_t *hi;
-    void *val;
+	void *val;
 	char *sql;
 	switch_core_db_t *db;
 
 
 	sql = switch_mprintf("select * from subscriptions");
-	
+
 
 	for (hi = switch_hash_first(switch_hash_pool_get(globals.profile_hash), globals.profile_hash); hi; hi = switch_hash_next(hi)) {
 		char *errmsg;
-        switch_hash_this(hi, NULL, NULL, &val);
-        profile = (struct mdl_profile *) val;
+		switch_hash_this(hi, NULL, NULL, &val);
+		profile = (struct mdl_profile *) val;
 
-        if (!(profile->user_flags & LDL_FLAG_COMPONENT)) {
+		if (!(profile->user_flags & LDL_FLAG_COMPONENT)) {
 			continue;
-        }
+		}
 
 
 		if (sql) {
@@ -557,9 +553,9 @@
 			switch_mutex_unlock(profile->mutex);
 			switch_core_db_close(db);
 		}
-		
+
 	}
-	
+
 	switch_yield(1000000);
 	switch_safe_free(sql);
 
@@ -590,9 +586,9 @@
 		switch_channel_t *channel = switch_core_session_get_channel(*session);
 		switch_channel_state_t state = switch_channel_get_state(channel);
 		struct private_object *tech_pvt = NULL;
-		
+
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Terminate called from line %d state=%s\n", line, switch_channel_state_name(state));
- 
+
 		tech_pvt = switch_core_session_get_private(*session);
 
 		if (!tech_pvt || !switch_test_flag(tech_pvt, TFLAG_READY)) {
@@ -601,14 +597,14 @@
 		}
 
 		if (switch_test_flag(tech_pvt, TFLAG_TERM)) {
-			/*once is enough*/
+			/*once is enough */
 			return;
 		}
 
 		if (state < CS_HANGUP) {
 			switch_channel_hangup(channel, cause);
 		}
-		
+
 		switch_mutex_lock(tech_pvt->flag_mutex);
 		switch_set_flag(tech_pvt, TFLAG_TERM);
 		switch_set_flag(tech_pvt, TFLAG_BYE);
@@ -626,7 +622,7 @@
 	char data[1024];
 
 	va_start(ap, fmt);
-	
+
 	vsnprintf(data, sizeof(data), fmt, ap);
 	switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, SWITCH_LOG_DEBUG, "%s", data);
 
@@ -641,9 +637,7 @@
 	if (!tech_pvt->num_codecs) {
 		if (globals.codec_string) {
 			if ((tech_pvt->num_codecs = switch_loadable_module_get_codecs_sorted(tech_pvt->codecs,
-																				 SWITCH_MAX_CODECS,
-																				 globals.codec_order,
-																				 globals.codec_order_last)) <= 0) {
+																				 SWITCH_MAX_CODECS, globals.codec_order, globals.codec_order_last)) <= 0) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "NO codecs?\n");
 				return 0;
 			}
@@ -659,7 +653,7 @@
 
 
 
-static void *SWITCH_THREAD_FUNC handle_thread_run(switch_thread_t *thread, void *obj)
+static void *SWITCH_THREAD_FUNC handle_thread_run(switch_thread_t * thread, void *obj)
 {
 	ldl_handle_t *handle = obj;
 	struct mdl_profile *profile = NULL;
@@ -674,15 +668,15 @@
 	globals.handles--;
 	ldl_handle_destroy(&handle);
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Handle %s [%s] Destroyed\n", profile->name, profile->login);
-	
+
 	return NULL;
 }
 
-static void handle_thread_launch(ldl_handle_t *handle)
+static void handle_thread_launch(ldl_handle_t * handle)
 {
 	switch_thread_t *thread;
 	switch_threadattr_t *thd_attr = NULL;
-	
+
 	switch_threadattr_create(&thd_attr, module_pool);
 	switch_threadattr_detach_set(thd_attr, 1);
 	switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
@@ -702,10 +696,10 @@
 		return 1;
 	}
 
-    if (!(tech_pvt->remote_ip && tech_pvt->remote_port)) {
+	if (!(tech_pvt->remote_ip && tech_pvt->remote_port)) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "No valid candidates received!\n");
-        return 0;
-    }
+		return 0;
+	}
 
 	if (switch_core_codec_init(&tech_pvt->read_codec,
 							   tech_pvt->codec_name,
@@ -722,9 +716,9 @@
 	tech_pvt->read_frame.rate = tech_pvt->read_codec.implementation->samples_per_second;
 	tech_pvt->read_frame.codec = &tech_pvt->read_codec;
 
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Set Read Codec to %s@%d\n", 
-					  tech_pvt->codec_name, (int)tech_pvt->read_codec.implementation->samples_per_second);
-	
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Set Read Codec to %s@%d\n",
+					  tech_pvt->codec_name, (int) tech_pvt->read_codec.implementation->samples_per_second);
+
 	if (switch_core_codec_init(&tech_pvt->write_codec,
 							   tech_pvt->codec_name,
 							   NULL,
@@ -737,20 +731,21 @@
 		switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
 		return 0;
 	}
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Set Write Codec to %s@%d\n",  
-					  tech_pvt->codec_name,(int)tech_pvt->write_codec.implementation->samples_per_second);
-							
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Set Write Codec to %s@%d\n",
+					  tech_pvt->codec_name, (int) tech_pvt->write_codec.implementation->samples_per_second);
+
 	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);
-	
 
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SETUP RTP %s:%d -> %s:%d\n", tech_pvt->profile->ip, tech_pvt->local_port, tech_pvt->remote_ip, tech_pvt->remote_port);
-	
+
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SETUP RTP %s:%d -> %s:%d\n", tech_pvt->profile->ip,
+					  tech_pvt->local_port, tech_pvt->remote_ip, tech_pvt->remote_port);
+
 	flags = SWITCH_RTP_FLAG_GOOGLEHACK | SWITCH_RTP_FLAG_AUTOADJ;
 	//flags = SWITCH_RTP_FLAG_AUTOADJ;
 
 	if (switch_test_flag(tech_pvt->profile, TFLAG_TIMER)) {
-	  flags |= SWITCH_RTP_FLAG_USE_TIMER;
+		flags |= SWITCH_RTP_FLAG_USE_TIMER;
 	}
 
 	flags |= SWITCH_RTP_FLAG_AUTO_CNG;
@@ -760,12 +755,9 @@
 												 tech_pvt->remote_ip,
 												 tech_pvt->remote_port,
 												 tech_pvt->codec_num,
-                                                 tech_pvt->read_codec.implementation->encoded_bytes_per_frame,
+												 tech_pvt->read_codec.implementation->encoded_bytes_per_frame,
 												 tech_pvt->read_codec.implementation->microseconds_per_frame,
-												 flags,
-												 NULL,
-												 tech_pvt->profile->timer_name,
-												 &err, switch_core_session_get_pool(tech_pvt->session)))) {
+												 flags, NULL, tech_pvt->profile->timer_name, &err, switch_core_session_get_pool(tech_pvt->session)))) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "RTP ERROR %s\n", err);
 		switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
 		return 0;
@@ -818,10 +810,10 @@
 
 		cand[0].port = tech_pvt->local_port;
 		cand[0].address = advip;
-				
+
 		if (!strncasecmp(advip, "stun:", 5)) {
 			char *stun_ip = advip + 5;
-					
+
 			if (tech_pvt->stun_ip) {
 				cand[0].address = tech_pvt->stun_ip;
 				cand[0].port = tech_pvt->stun_port;
@@ -834,12 +826,9 @@
 
 				cand[0].address = tech_pvt->profile->ip;
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Stun Lookup Local %s:%d\n", cand[0].address, cand[0].port);
-				if (switch_stun_lookup(&cand[0].address,
-									   &cand[0].port,
-									   stun_ip,
-									   SWITCH_STUN_DEFAULT_PORT,
-									   &err,
-									   switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
+				if (switch_stun_lookup
+					(&cand[0].address, &cand[0].port, stun_ip, SWITCH_STUN_DEFAULT_PORT, &err,
+					 switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Stun Failed! %s:%d [%s]\n", stun_ip, SWITCH_STUN_DEFAULT_PORT, err);
 					switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
 					return 0;
@@ -912,12 +901,12 @@
 			tech_pvt->codec_rate = tech_pvt->codecs[0]->samples_per_second;
 			tech_pvt->r_codec_num = tech_pvt->codecs[0]->ianacode;
 			tech_pvt->codec_index = 0;
-					
+
 			payloads[0].name = lame(tech_pvt->codecs[0]->iananame);
 			payloads[0].id = tech_pvt->codecs[0]->ianacode;
 			payloads[0].rate = tech_pvt->codecs[0]->samples_per_second;
 			payloads[0].bps = tech_pvt->codecs[0]->bits_per_second;
-			
+
 		} else {
 			payloads[0].name = lame(tech_pvt->codecs[tech_pvt->codec_index]->iananame);
 			payloads[0].id = tech_pvt->codecs[tech_pvt->codec_index]->ianacode;
@@ -925,12 +914,13 @@
 			payloads[0].bps = tech_pvt->codecs[tech_pvt->codec_index]->bits_per_second;
 		}
 
-				
+
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Send Describe [%s@%d]\n", payloads[0].name, payloads[0].rate);
-		tech_pvt->desc_id = ldl_session_describe(tech_pvt->dlsession, payloads, 1,
-												 switch_test_flag(tech_pvt, TFLAG_OUTBOUND) ? LDL_DESCRIPTION_INITIATE : LDL_DESCRIPTION_ACCEPT);
+		tech_pvt->desc_id =
+			ldl_session_describe(tech_pvt->dlsession, payloads, 1,
+								 switch_test_flag(tech_pvt, TFLAG_OUTBOUND) ? LDL_DESCRIPTION_INITIATE : LDL_DESCRIPTION_ACCEPT);
 		switch_set_flag_locked(tech_pvt, TFLAG_CODEC_READY);
-	} 
+	}
 	switch_clear_flag_locked(tech_pvt, TFLAG_DO_CAND);
 	return 1;
 }
@@ -957,7 +947,7 @@
 	/* jingle has no ringing indication so we will just pretend that we got one */
 	switch_core_session_queue_indication(session, SWITCH_MESSAGE_INDICATE_RINGING);
 	switch_channel_mark_ring_ready(channel);
-	
+
 	if (switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) {
 		tech_pvt->next_cand = switch_time_now() + DL_CAND_WAIT;
 		tech_pvt->next_desc = switch_time_now();
@@ -966,63 +956,62 @@
 		tech_pvt->next_desc = switch_time_now() + DL_CAND_WAIT;
 	}
 
-	while(! (switch_test_flag(tech_pvt, TFLAG_CODEC_READY) && 
-			 switch_test_flag(tech_pvt, TFLAG_RTP_READY) && 
-			 switch_test_flag(tech_pvt, TFLAG_ANSWER) && 
-			 switch_test_flag(tech_pvt, TFLAG_TRANSPORT_ACCEPT) &&
-			 switch_test_flag(tech_pvt, TFLAG_TRANSPORT))) {
+	while (!(switch_test_flag(tech_pvt, TFLAG_CODEC_READY) &&
+			 switch_test_flag(tech_pvt, TFLAG_RTP_READY) &&
+			 switch_test_flag(tech_pvt, TFLAG_ANSWER) && switch_test_flag(tech_pvt, TFLAG_TRANSPORT_ACCEPT)
+			 && switch_test_flag(tech_pvt, TFLAG_TRANSPORT))) {
 		now = switch_time_now();
-		elapsed = (unsigned int)((now - started) / 1000);
+		elapsed = (unsigned int) ((now - started) / 1000);
 
 		if (switch_channel_get_state(channel) >= CS_HANGUP || switch_test_flag(tech_pvt, TFLAG_BYE)) {
 			goto out;
 		}
 
-		
+
 		if (now >= tech_pvt->next_desc) {
 			if (!do_describe(tech_pvt, 0)) {
 				goto out;
 			}
 		}
-		
+
 		if (tech_pvt->next_cand && now >= tech_pvt->next_cand) {
 			if (!do_candidates(tech_pvt, 0)) {
 				goto out;
 			}
 		}
 		if (elapsed > 60000) {
-			terminate_session(&tech_pvt->session,  __LINE__, SWITCH_CAUSE_NORMAL_CLEARING);
+			terminate_session(&tech_pvt->session, __LINE__, SWITCH_CAUSE_NORMAL_CLEARING);
 			switch_set_flag_locked(tech_pvt, TFLAG_BYE);
 			switch_clear_flag_locked(tech_pvt, TFLAG_IO);
 			goto done;
 		}
-		if (switch_test_flag(tech_pvt, TFLAG_BYE) || ! switch_test_flag(tech_pvt, TFLAG_IO)) {
+		if (switch_test_flag(tech_pvt, TFLAG_BYE) || !switch_test_flag(tech_pvt, TFLAG_IO)) {
 			goto done;
 		}
 		switch_yield(1000);
 	}
-	
+
 	if (switch_channel_get_state(channel) >= CS_HANGUP || switch_test_flag(tech_pvt, TFLAG_BYE)) {
 		goto out;
-	}	
+	}
 
 	if (!activate_rtp(tech_pvt)) {
 		goto out;
 	}
-	
+
 	if (switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) {
 		if (!do_candidates(tech_pvt, 0)) {
 			goto out;
 		}
 		switch_channel_answer(channel);
-	} 
+	}
 	ret = SWITCH_STATUS_SUCCESS;
 
 	goto done;
-	
- out:
-	terminate_session(&session,  __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
- done:
+
+  out:
+	terminate_session(&session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+  done:
 
 	return ret;
 }
@@ -1065,7 +1054,7 @@
 
 	tech_pvt = switch_core_session_get_private(session);
 	assert(tech_pvt != NULL);
-	
+
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL RING\n", switch_channel_get_name(channel));
 
 	return SWITCH_STATUS_SUCCESS;
@@ -1093,7 +1082,7 @@
 {
 	switch_channel_t *channel = NULL;
 	struct private_object *tech_pvt = NULL;
-	
+
 	channel = switch_core_session_get_channel(session);
 	assert(channel != NULL);
 
@@ -1105,12 +1094,11 @@
 	switch_set_flag_locked(tech_pvt, TFLAG_BYE);
 
 	/* Dunno why, but if googletalk calls us for the first time, as soon as the call ends
-	 they think we are offline for no reason so we send this presence packet to stop it from happening
-	 We should find out why.....
-	*/
-	if ((tech_pvt->profile->user_flags & LDL_FLAG_COMPONENT) && is_special(tech_pvt->them)) {	
-		ldl_handle_send_presence(tech_pvt->profile->handle,
-								 tech_pvt->them, tech_pvt->us, NULL, NULL, "Click To Call");
+	   they think we are offline for no reason so we send this presence packet to stop it from happening
+	   We should find out why.....
+	 */
+	if ((tech_pvt->profile->user_flags & LDL_FLAG_COMPONENT) && is_special(tech_pvt->them)) {
+		ldl_handle_send_presence(tech_pvt->profile->handle, tech_pvt->them, tech_pvt->us, NULL, NULL, "Click To Call");
 	}
 	if (tech_pvt->dlsession) {
 		if (!switch_test_flag(tech_pvt, TFLAG_TERM)) {
@@ -1144,42 +1132,42 @@
 	switch_channel_t *channel = NULL;
 	struct private_object *tech_pvt = NULL;
 
-    if (!(channel = switch_core_session_get_channel(session))) {
-        return SWITCH_STATUS_SUCCESS;
-    }
-
-    if (!(tech_pvt = switch_core_session_get_private(session))) {
-        return SWITCH_STATUS_SUCCESS;
-    }
-    
-
-    switch (sig) {
-    case SWITCH_SIG_KILL:
-        switch_clear_flag_locked(tech_pvt, TFLAG_IO);
-        switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
-        switch_set_flag_locked(tech_pvt, TFLAG_BYE);
-
-        if (tech_pvt->dlsession) {
-            if (!switch_test_flag(tech_pvt, TFLAG_TERM)) {
-                ldl_session_terminate(tech_pvt->dlsession);
-                switch_set_flag_locked(tech_pvt, TFLAG_TERM);
-            }
-            ldl_session_destroy(&tech_pvt->dlsession);
-            
-        }
-
-        if (switch_rtp_ready(tech_pvt->rtp_session)) {
-            switch_rtp_kill_socket(tech_pvt->rtp_session);
-        }
-        break;
+	if (!(channel = switch_core_session_get_channel(session))) {
+		return SWITCH_STATUS_SUCCESS;
+	}
+
+	if (!(tech_pvt = switch_core_session_get_private(session))) {
+		return SWITCH_STATUS_SUCCESS;
+	}
+
+
+	switch (sig) {
+	case SWITCH_SIG_KILL:
+		switch_clear_flag_locked(tech_pvt, TFLAG_IO);
+		switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
+		switch_set_flag_locked(tech_pvt, TFLAG_BYE);
+
+		if (tech_pvt->dlsession) {
+			if (!switch_test_flag(tech_pvt, TFLAG_TERM)) {
+				ldl_session_terminate(tech_pvt->dlsession);
+				switch_set_flag_locked(tech_pvt, TFLAG_TERM);
+			}
+			ldl_session_destroy(&tech_pvt->dlsession);
+
+		}
+
+		if (switch_rtp_ready(tech_pvt->rtp_session)) {
+			switch_rtp_kill_socket(tech_pvt->rtp_session);
+		}
+		break;
 	case SWITCH_SIG_BREAK:
-        if (switch_rtp_ready(tech_pvt->rtp_session)) {
+		if (switch_rtp_ready(tech_pvt->rtp_session)) {
 			switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_BREAK);
 		}
 		break;
-    }
+	}
 
-    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL KILL\n", switch_channel_get_name(channel));
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL KILL\n", switch_channel_get_name(channel));
 
 
 	return SWITCH_STATUS_SUCCESS;
@@ -1227,14 +1215,11 @@
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "DTMF [%s]\n", dtmf);
 
-	return switch_rtp_queue_rfc2833(tech_pvt->rtp_session,
-									dtmf,
-									100 * (tech_pvt->read_codec.implementation->samples_per_second / 1000));
+	return switch_rtp_queue_rfc2833(tech_pvt->rtp_session, dtmf, 100 * (tech_pvt->read_codec.implementation->samples_per_second / 1000));
 
 }
 
-static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout,
-										  switch_io_flag_t flags, int stream_id)
+static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, switch_io_flag_t flags, int stream_id)
 {
 	struct private_object *tech_pvt = NULL;
 	uint32_t bytes = 0;
@@ -1268,11 +1253,12 @@
 	ms = tech_pvt->read_codec.implementation->microseconds_per_frame;
 	tech_pvt->read_frame.datalen = 0;
 
-	
-	while (!switch_test_flag(tech_pvt, TFLAG_BYE) && switch_test_flag(tech_pvt, TFLAG_IO) && tech_pvt->read_frame.datalen == 0) {
+
+	while (!switch_test_flag(tech_pvt, TFLAG_BYE) && switch_test_flag(tech_pvt, TFLAG_IO)
+		   && tech_pvt->read_frame.datalen == 0) {
 		tech_pvt->read_frame.flags = 0;
 		status = switch_rtp_zerocopy_read_frame(tech_pvt->rtp_session, &tech_pvt->read_frame);
-		
+
 		if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
 			return SWITCH_STATUS_FALSE;
 		}
@@ -1295,19 +1281,19 @@
 		}
 
 		if (tech_pvt->read_frame.datalen > 0) {
-            if (!switch_test_flag((&tech_pvt->read_frame), SFF_CNG)) {
-                if (tech_pvt->read_codec.implementation->encoded_bytes_per_frame && bytes) {
-                    bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame;
-                    frames = (tech_pvt->read_frame.datalen / bytes);
-                } else {
-                    frames = 1;
-                }
-                samples = frames * tech_pvt->read_codec.implementation->samples_per_frame;
-                ms = frames * tech_pvt->read_codec.implementation->microseconds_per_frame;
-                tech_pvt->timestamp_recv += (int32_t) samples;
-                tech_pvt->read_frame.samples = (int) samples;
-                tech_pvt->last_read = tech_pvt->read_frame.datalen;
-            }
+			if (!switch_test_flag((&tech_pvt->read_frame), SFF_CNG)) {
+				if (tech_pvt->read_codec.implementation->encoded_bytes_per_frame && bytes) {
+					bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame;
+					frames = (tech_pvt->read_frame.datalen / bytes);
+				} else {
+					frames = 1;
+				}
+				samples = frames * tech_pvt->read_codec.implementation->samples_per_frame;
+				ms = frames * tech_pvt->read_codec.implementation->microseconds_per_frame;
+				tech_pvt->timestamp_recv += (int32_t) samples;
+				tech_pvt->read_frame.samples = (int) samples;
+				tech_pvt->last_read = tech_pvt->read_frame.datalen;
+			}
 			break;
 		}
 
@@ -1322,8 +1308,7 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout,
-										   switch_io_flag_t flags, int stream_id)
+static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flags, int stream_id)
 {
 	struct private_object *tech_pvt;
 	switch_channel_t *channel = NULL;
@@ -1362,7 +1347,7 @@
 	samples = frames * tech_pvt->read_codec.implementation->samples_per_frame;
 	tech_pvt->timestamp_send += samples;
 	if (switch_rtp_write_frame(tech_pvt->rtp_session, frame, 0) < 0) {
-		terminate_session(&session,  __LINE__, SWITCH_CAUSE_NORMAL_CLEARING);
+		terminate_session(&session, __LINE__, SWITCH_CAUSE_NORMAL_CLEARING);
 		return SWITCH_STATUS_FALSE;
 	}
 
@@ -1391,16 +1376,16 @@
 {
 	switch_channel_t *channel;
 	struct private_object *tech_pvt;
-			
+
 	channel = switch_core_session_get_channel(session);
 	assert(channel != NULL);
-			
+
 	tech_pvt = switch_core_session_get_private(session);
 	assert(tech_pvt != NULL);
 
 	switch (msg->message_id) {
 	case SWITCH_MESSAGE_INDICATE_BRIDGE:
-	  if (tech_pvt->rtp_session && switch_test_flag(tech_pvt->profile, TFLAG_TIMER)) {
+		if (tech_pvt->rtp_session && switch_test_flag(tech_pvt->profile, TFLAG_TIMER)) {
 			switch_rtp_clear_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_USE_TIMER);
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "De-activate timed RTP!\n");
 			//switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_TIMER_RECLOCK);
@@ -1423,14 +1408,14 @@
 static switch_status_t channel_receive_event(switch_core_session_t *session, switch_event_t *event)
 {
 	switch_channel_t *channel;
-    struct private_object *tech_pvt;
+	struct private_object *tech_pvt;
 	char *subject, *body;
 
-    channel = switch_core_session_get_channel(session);
-    assert(channel != NULL);
+	channel = switch_core_session_get_channel(session);
+	assert(channel != NULL);
 
-    tech_pvt = switch_core_session_get_private(session);
-    assert(tech_pvt != NULL);
+	tech_pvt = switch_core_session_get_private(session);
+	assert(tech_pvt != NULL);
 
 
 	if (!(body = switch_event_get_body(event))) {
@@ -1464,8 +1449,8 @@
 	/*.waitfor_read */ channel_waitfor_read,
 	/*.waitfor_write */ channel_waitfor_write,
 	/*.send_dtmf */ channel_send_dtmf,
-	/*.receive_message*/ channel_receive_message,
-	/*.receive_event*/ channel_receive_event
+	/*.receive_message */ channel_receive_message,
+	/*.receive_event */ channel_receive_event
 };
 
 static const switch_endpoint_interface_t channel_endpoint_interface = {
@@ -1508,17 +1493,17 @@
 	/*.application_interface */ NULL,
 	/*.api_interface */ &login_api_interface,
 	/*.file_interface */ NULL,
-    /*.speech_interface */ NULL,
-    /*.directory_interface */ NULL,
-    /*.chat_interface */ &channel_chat_interface
-
+	/*.speech_interface */ NULL,
+	/*.directory_interface */ NULL,
+	/*.chat_interface */ &channel_chat_interface
 };
 
 
 /* Make sure when you have 2 sessions in the same scope that you pass the appropriate one to the routines
    that allocate memory or you will have 1 channel with memory allocated from another channel's pool!
 */
-static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile,
+static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session,
+													switch_caller_profile_t *outbound_profile,
 													switch_core_session_t **new_session, switch_memory_pool_t **pool)
 {
 	if ((*new_session = switch_core_session_request(&channel_endpoint_interface, pool)) != 0) {
@@ -1544,7 +1529,7 @@
 			*callto++ = '\0';
 		} else {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Invalid URL!\n");
-			terminate_session(new_session,  __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+			terminate_session(new_session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
 			return SWITCH_CAUSE_INVALID_NUMBER_FORMAT;
 		}
 
@@ -1552,9 +1537,9 @@
 			*dnis++ = '\0';
 		}
 
-        for (p = callto; p && *p; p++) {
-            *p = (char) tolower(*p);
-        }
+		for (p = callto; p && *p; p++) {
+			*p = (char) tolower(*p);
+		}
 
 		if ((p = strchr(profile_name, '@'))) {
 			*p++ = '\0';
@@ -1574,28 +1559,28 @@
 						user = ubuf;
 					} else {
 						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Invalid User!\n");
-						terminate_session(new_session,  __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+						terminate_session(new_session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
 					}
 				}
 			}
 
 			if (!ldl_handle_ready(mdl_profile->handle)) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Doh! we are not logged in yet!\n");
-				terminate_session(new_session,  __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+				terminate_session(new_session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
 				return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
 			}
 			if (!(full_id = ldl_handle_probe(mdl_profile->handle, callto, user, idbuf, sizeof(idbuf)))) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Unknown Recipient!\n");
-				terminate_session(new_session,  __LINE__, SWITCH_CAUSE_NO_USER_RESPONSE);
+				terminate_session(new_session, __LINE__, SWITCH_CAUSE_NO_USER_RESPONSE);
 				return SWITCH_CAUSE_NO_USER_RESPONSE;
 			}
 		} else {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Unknown Profile!\n");
-			terminate_session(new_session,  __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+			terminate_session(new_session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
 			return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
 		}
-		
-		
+
+
 		switch_core_session_add_stream(*new_session, NULL);
 		if ((tech_pvt = (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object))) != 0) {
 			memset(tech_pvt, 0, sizeof(*tech_pvt));
@@ -1611,13 +1596,13 @@
 			tech_pvt->dnis = switch_core_session_strdup(*new_session, dnis);
 		} else {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n");
-			terminate_session(new_session,  __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+			terminate_session(new_session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
 			return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
 		}
 
 		if (outbound_profile) {
 			char name[128];
-			
+
 			snprintf(name, sizeof(name), "DingaLing/%s", outbound_profile->destination_number);
 			switch_channel_set_name(channel, name);
 
@@ -1626,7 +1611,7 @@
 			tech_pvt->caller_profile = caller_profile;
 		} else {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Doh! no caller profile\n");
-			terminate_session(new_session,  __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+			terminate_session(new_session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
 			return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
 		}
 
@@ -1637,7 +1622,7 @@
 		tech_pvt->us = switch_core_session_strdup(*new_session, user);
 		tech_pvt->them = switch_core_session_strdup(*new_session, full_id);
 		ldl_session_create(&dlsession, mdl_profile->handle, sess_id, full_id, user, LDL_FLAG_OUTBOUND);
-		
+
 		if (session) {
 			switch_channel_t *calling_channel = switch_core_session_get_channel(session);
 			cid_msg = switch_channel_get_variable(calling_channel, "dl_cid_msg");
@@ -1669,8 +1654,8 @@
 		ldl_session_set_value(dlsession, "caller_id_number", outbound_profile->caller_id_number);
 		tech_pvt->dlsession = dlsession;
 		if (!get_codecs(tech_pvt)) {
-			terminate_session(new_session,  __LINE__, SWITCH_CAUSE_BEARERCAPABILITY_NOTAVAIL);
-            return SWITCH_CAUSE_BEARERCAPABILITY_NOTAVAIL;
+			terminate_session(new_session, __LINE__, SWITCH_CAUSE_BEARERCAPABILITY_NOTAVAIL);
+			return SWITCH_CAUSE_BEARERCAPABILITY_NOTAVAIL;
 		}
 		switch_channel_set_state(channel, CS_INIT);
 		return SWITCH_CAUSE_SUCCESS;
@@ -1705,7 +1690,7 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't register subclass %s!", DL_EVENT_CONNECTED);
 		return SWITCH_STATUS_GENERR;
 	}
-	
+
 	if (switch_event_bind((char *) modname, SWITCH_EVENT_PRESENCE_IN, SWITCH_EVENT_SUBCLASS_ANY, pres_event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
 		return SWITCH_STATUS_GENERR;
@@ -1721,7 +1706,8 @@
 		return SWITCH_STATUS_GENERR;
 	}
 
-	if (switch_event_bind((char *) modname, SWITCH_EVENT_ROSTER, SWITCH_EVENT_SUBCLASS_ANY, roster_event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
+	if (switch_event_bind((char *) modname, SWITCH_EVENT_ROSTER, SWITCH_EVENT_SUBCLASS_ANY, roster_event_handler, NULL)
+		!= SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
 		return SWITCH_STATUS_GENERR;
 	}
@@ -1733,7 +1719,7 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static ldl_status handle_loop(ldl_handle_t *handle)
+static ldl_status handle_loop(ldl_handle_t * handle)
 {
 	if (!globals.running) {
 		return LDL_STATUS_FALSE;
@@ -1743,18 +1729,11 @@
 
 static switch_status_t init_profile(struct mdl_profile *profile, uint8_t login)
 {
-	if (profile &&
-		profile->login &&
-		profile->password &&
-		profile->dialplan &&
-		profile->message &&
-		profile->ip &&
-		profile->name &&
-		profile->exten) {
+	if (profile && profile->login && profile->password && profile->dialplan && profile->message && profile->ip && profile->name && profile->exten) {
 		ldl_handle_t *handle;
 
 		if (switch_test_flag(profile, TFLAG_TIMER) && !profile->timer_name) {
-			profile->timer_name = switch_core_strdup(module_pool, "soft");			
+			profile->timer_name = switch_core_strdup(module_pool, "soft");
 		}
 
 		if (login) {
@@ -1762,12 +1741,7 @@
 								profile->login,
 								profile->password,
 								profile->server,
-								profile->user_flags,
-								profile->message,
-								handle_loop,
-								handle_signalling,
-								handle_response,
-								profile) == LDL_STATUS_SUCCESS) {
+								profile->user_flags, profile->message, handle_loop, handle_signalling, handle_response, profile) == LDL_STATUS_SUCCESS) {
 				profile->handle = handle;
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Started Thread for %s@%s\n", profile->login, profile->dialplan);
 				switch_core_hash_insert(globals.profile_hash, profile->name, profile);
@@ -1778,7 +1752,7 @@
 			switch_core_hash_insert(globals.profile_hash, profile->name, profile);
 		}
 	} else {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, 
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
 						  "Invalid Profile\n"
 						  "login[%s]\n"
 						  "pass[%s]\n"
@@ -1786,13 +1760,7 @@
 						  "message[%s]\n"
 						  "rtp-ip[%s]\n"
 						  "name[%s]\n"
-						  "exten[%s]\n",
-						  profile->login,
-						  profile->password,
-						  profile->dialplan,
-						  profile->message,
-						  profile->ip,
-						  profile->name,
+						  "exten[%s]\n", profile->login, profile->password, profile->dialplan, profile->message, profile->ip, profile->name,
 						  profile->exten);
 
 		return SWITCH_STATUS_FALSE;
@@ -1812,7 +1780,7 @@
 		while (globals.handles > 0) {
 			switch_yield(100000);
 			x++;
-			if(x > 10) {
+			if (x > 10) {
 				break;
 			}
 		}
@@ -1826,13 +1794,13 @@
 
 static void set_profile_val(struct mdl_profile *profile, char *var, char *val)
 {
-	
+
 	if (!strcasecmp(var, "login")) {
 		profile->login = switch_core_strdup(module_pool, val);
 	} else if (!strcasecmp(var, "password")) {
 		profile->password = switch_core_strdup(module_pool, val);
 	} else if (!strcasecmp(var, "use-rtp-timer") && switch_true(val)) {
-	  	switch_set_flag(profile, TFLAG_TIMER);
+		switch_set_flag(profile, TFLAG_TIMER);
 	} else if (!strcasecmp(var, "dialplan")) {
 		profile->dialplan = switch_core_strdup(module_pool, val);
 	} else if (!strcasecmp(var, "auto-reply")) {
@@ -1908,7 +1876,7 @@
 
 static switch_status_t dl_login(char *arg, switch_core_session_t *session, switch_stream_handle_t *stream)
 {
-	char *argv[10] = {0};
+	char *argv[10] = { 0 };
 	int argc = 0;
 	char *var, *val, *myarg;
 	struct mdl_profile *profile = NULL;
@@ -1918,10 +1886,10 @@
 		return SWITCH_STATUS_FALSE;
 	}
 
-    if (switch_strlen_zero(arg)) {
-        stream->write_function(stream, "USAGE: %s\n", login_api_interface.syntax);
-        return SWITCH_STATUS_SUCCESS;
-    }
+	if (switch_strlen_zero(arg)) {
+		stream->write_function(stream, "USAGE: %s\n", login_api_interface.syntax);
+		return SWITCH_STATUS_SUCCESS;
+	}
 
 	myarg = strdup(arg);
 
@@ -1947,7 +1915,7 @@
 	} else {
 		profile = switch_core_alloc(module_pool, sizeof(*profile));
 
-		for(x = 0; x < argc; x++) {
+		for (x = 0; x < argc; x++) {
 			var = argv[x];
 			if ((val = strchr(var, '='))) {
 				*val++ = '\0';
@@ -1955,7 +1923,7 @@
 			}
 		}
 	}
-	
+
 
 	if (profile && init_profile(profile, 1) == SWITCH_STATUS_SUCCESS) {
 		stream->write_function(stream, "OK\n");
@@ -1975,10 +1943,10 @@
 
 	memset(&globals, 0, sizeof(globals));
 	globals.running = 1;
-    
-    switch_find_local_ip(globals.guess_ip, sizeof(globals.guess_ip), AF_INET);
 
-	switch_core_hash_init(&globals.profile_hash, module_pool);	
+	switch_find_local_ip(globals.guess_ip, sizeof(globals.guess_ip), AF_INET);
+
+	switch_core_hash_init(&globals.profile_hash, module_pool);
 
 	if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
@@ -1994,16 +1962,14 @@
 				globals.debug = atoi(val);
 			} else if (!strcasecmp(var, "codec-prefs")) {
 				set_global_codec_string(val);
-				globals.codec_order_last =
-					switch_separate_string(globals.codec_string, ',', globals.codec_order, SWITCH_MAX_CODECS);
+				globals.codec_order_last = switch_separate_string(globals.codec_string, ',', globals.codec_order, SWITCH_MAX_CODECS);
 			} else if (!strcasecmp(var, "codec-rates")) {
 				set_global_codec_rates_string(val);
-				globals.codec_rates_last =
-					switch_separate_string(globals.codec_rates_string, ',', globals.codec_rates, SWITCH_MAX_CODECS);
+				globals.codec_rates_last = switch_separate_string(globals.codec_rates_string, ',', globals.codec_rates, SWITCH_MAX_CODECS);
 			}
 		}
 	}
-	
+
 	if (!(xmlint = switch_xml_child(cfg, "profile"))) {
 		if ((xmlint = switch_xml_child(cfg, "interface"))) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "!!!!!!! DEPRICATION WARNING 'interface' is now 'profile' !!!!!!!\n");
@@ -2022,7 +1988,7 @@
 				globals.init = 1;
 			}
 
-			if(!profile) {
+			if (!profile) {
 				profile = switch_core_alloc(module_pool, sizeof(*profile));
 			}
 			set_profile_val(profile, var, val);
@@ -2081,7 +2047,7 @@
 }
 
 
-static void execute_sql(char *dbname, char *sql, switch_mutex_t *mutex)
+static void execute_sql(char *dbname, char *sql, switch_mutex_t * mutex)
 {
 	switch_core_db_t *db;
 
@@ -2093,17 +2059,17 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", dbname);
 		goto end;
 	}
-	
+
 	switch_core_db_persistant_execute(db, sql, 25);
 	switch_core_db_close(db);
 
- end:
+  end:
 	if (mutex) {
 		switch_mutex_unlock(mutex);
 	}
 }
 
-static void do_vcard(ldl_handle_t *handle, char *to, char *from, char *id)
+static void do_vcard(ldl_handle_t * handle, char *to, char *from, char *id)
 {
 	char *params = NULL, *real_to, *to_user, *xmlstr = NULL, *to_host = NULL;
 	switch_xml_t domain, xml = NULL, user, vcard;
@@ -2123,22 +2089,18 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
 		goto end;
 	}
-	
+
 	if (!to_host) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Missing Host!\n");
 		goto end;
 	}
 
-	if (!(params = switch_mprintf("to=%s@%s&from=%s&object=vcard",
-								  to_user,
-								  to_host,
-								  from
-								  ))) {
+	if (!(params = switch_mprintf("to=%s@%s&from=%s&object=vcard", to_user, to_host, from))) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
 		goto end;
 	}
 
-	
+
 	if (switch_xml_locate("directory", "domain", "name", to_host, &xml, &domain, params) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "can't find domain for [%s@%s]\n", to_user, to_host);
 		goto end;
@@ -2162,19 +2124,21 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
 	}
 
- end:
-	if (xml) switch_xml_free(xml);
+  end:
+	if (xml)
+		switch_xml_free(xml);
 	switch_safe_free(to_user);
 	switch_safe_free(params);
 	switch_safe_free(xmlstr);
 }
 
-static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsession, ldl_signal_t dl_signal, char *to, char *from, char *subject, char *msg)
+static ldl_status handle_signalling(ldl_handle_t * handle, ldl_session_t * dlsession, ldl_signal_t dl_signal, char *to, char *from, char *subject,
+									char *msg)
 {
 	struct mdl_profile *profile = NULL;
 	switch_core_session_t *session = NULL;
 	switch_channel_t *channel = NULL;
-    struct private_object *tech_pvt = NULL;
+	struct private_object *tech_pvt = NULL;
 	switch_event_t *event;
 	ldl_status status = LDL_STATUS_SUCCESS;
 	char *sql;
@@ -2189,7 +2153,7 @@
 
 	if (!dlsession) {
 		if (profile->user_flags & LDL_FLAG_COMPONENT) {
-			switch(dl_signal) {
+			switch (dl_signal) {
 			case LDL_SIGNAL_VCARD:
 				do_vcard(handle, to, from, subject);
 				break;
@@ -2203,7 +2167,7 @@
 				break;
 
 			case LDL_SIGNAL_SUBSCRIBE:
-				
+
 				if ((sql = switch_mprintf("delete from subscriptions where sub_from='%q' and sub_to='%q';\n"
 										  "insert into subscriptions values('%q','%q','%q','%q');\n", from, to, from, to, msg, subject))) {
 					execute_sql(profile->dbname, sql, profile->mutex);
@@ -2213,13 +2177,12 @@
 				if (is_special(to)) {
 					ldl_handle_send_presence(profile->handle, to, from, NULL, NULL, "Click To Call");
 				}
-
 #if 0
 				if (is_special(to)) {
 					if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
 						switch_event_add_header(event, SWITCH_STACK_BOTTOM, "proto", MDL_CHAT_PROTO);
 						switch_event_add_header(event, SWITCH_STACK_BOTTOM, "login", "%s", profile->login);
-						switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s",  to);
+						switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s", to);
 						//switch_event_add_header(event, SWITCH_STACK_BOTTOM, "rpid", "unknown");
 						switch_event_add_header(event, SWITCH_STACK_BOTTOM, "status", "Click To Call");
 						switch_event_fire(&event);
@@ -2236,34 +2199,34 @@
 				break;
 			case LDL_SIGNAL_PRESENCE_PROBE:
 				if (is_special(to)) {
-                    ldl_handle_send_presence(profile->handle, to, from, NULL, NULL, "Click To Call");
-                } else {
+					ldl_handle_send_presence(profile->handle, to, from, NULL, NULL, "Click To Call");
+				} else {
 					if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_PROBE) == SWITCH_STATUS_SUCCESS) {
 						switch_event_add_header(event, SWITCH_STACK_BOTTOM, "proto", MDL_CHAT_PROTO);
 						switch_event_add_header(event, SWITCH_STACK_BOTTOM, "login", "%s", profile->login);
-						switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s",  from);
-						switch_event_add_header(event, SWITCH_STACK_BOTTOM, "to", "%s",  to);
+						switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s", from);
+						switch_event_add_header(event, SWITCH_STACK_BOTTOM, "to", "%s", to);
 						switch_event_fire(&event);
 					}
-                }
-                break;
+				}
+				break;
 			case LDL_SIGNAL_PRESENCE_IN:
-				
+
 				if ((sql = switch_mprintf("update subscriptions set show='%q', status='%q' where sub_from='%q'", msg, subject, from))) {
 					execute_sql(profile->dbname, sql, profile->mutex);
 					switch_core_db_free(sql);
 				}
-				
+
 				if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
 					switch_event_add_header(event, SWITCH_STACK_BOTTOM, "proto", MDL_CHAT_PROTO);
 					switch_event_add_header(event, SWITCH_STACK_BOTTOM, "login", "%s", profile->login);
-					switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s",  from);
+					switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s", from);
 					switch_event_add_header(event, SWITCH_STACK_BOTTOM, "rpid", "%s", msg);
 					switch_event_add_header(event, SWITCH_STACK_BOTTOM, "status", "%s", subject);
 					switch_event_fire(&event);
 				}
 
-				
+
 				if (is_special(to)) {
 					ldl_handle_send_presence(profile->handle, to, from, NULL, NULL, "Click To Call");
 				}
@@ -2272,7 +2235,7 @@
 					if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
 						switch_event_add_header(event, SWITCH_STACK_BOTTOM, "proto", MDL_CHAT_PROTO);
 						switch_event_add_header(event, SWITCH_STACK_BOTTOM, "login", "%s", profile->login);
-						switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s",  to);
+						switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s", to);
 						//switch_event_add_header(event, SWITCH_STACK_BOTTOM, "rpid", "unknown");
 						switch_event_add_header(event, SWITCH_STACK_BOTTOM, "status", "Click To Call");
 						switch_event_fire(&event);
@@ -2282,7 +2245,7 @@
 				break;
 
 			case LDL_SIGNAL_PRESENCE_OUT:
-				
+
 				if ((sql = switch_mprintf("update subscriptions set show='%q', status='%q' where sub_from='%q'", msg, subject, from))) {
 					execute_sql(profile->dbname, sql, profile->mutex);
 					switch_core_db_free(sql);
@@ -2297,48 +2260,48 @@
 			default:
 				break;
 			}
-		} 
+		}
 
-		switch(dl_signal) {
-		case LDL_SIGNAL_MSG: {
-			switch_chat_interface_t *ci;
-			char *proto = MDL_CHAT_PROTO;
-			char *pproto = NULL, *ffrom = NULL;
-			char *hint;
-
-			if (profile->auto_reply) {
-				ldl_handle_send_msg(handle,
-									(profile->user_flags & LDL_FLAG_COMPONENT) ? to : ldl_handle_get_login(profile->handle),
-									from, "", profile->auto_reply);
-			}
-
-			if (strchr(to, '+')) {
-				pproto = strdup(to);
-				if ((to = strchr(pproto, '+'))) {
-					*to++ = '\0';
+		switch (dl_signal) {
+		case LDL_SIGNAL_MSG:{
+				switch_chat_interface_t *ci;
+				char *proto = MDL_CHAT_PROTO;
+				char *pproto = NULL, *ffrom = NULL;
+				char *hint;
+
+				if (profile->auto_reply) {
+					ldl_handle_send_msg(handle,
+										(profile->user_flags & LDL_FLAG_COMPONENT) ? to : ldl_handle_get_login(profile->handle), from, "",
+										profile->auto_reply);
+				}
+
+				if (strchr(to, '+')) {
+					pproto = strdup(to);
+					if ((to = strchr(pproto, '+'))) {
+						*to++ = '\0';
+					}
+					proto = pproto;
 				}
-				proto = pproto;
-			}
 
-			hint = from;
+				hint = from;
 
-			if (strchr(from, '/') && (ffrom = strdup(from))) {
-				char *p;
-				if ((p = strchr(ffrom, '/'))) {
-					*p = '\0';
+				if (strchr(from, '/') && (ffrom = strdup(from))) {
+					char *p;
+					if ((p = strchr(ffrom, '/'))) {
+						*p = '\0';
+					}
+					from = ffrom;
 				}
-				from = ffrom;
-			}
 
-			if ((ci = switch_loadable_module_get_chat_interface(proto))) {
-				ci->chat_send(MDL_CHAT_PROTO, from, to, subject, msg, hint);
-			} else {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Chat Interface [%s]!\n", proto);
-			}
+				if ((ci = switch_loadable_module_get_chat_interface(proto))) {
+					ci->chat_send(MDL_CHAT_PROTO, from, to, subject, msg, hint);
+				} else {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Chat Interface [%s]!\n", proto);
+				}
 
-			switch_safe_free(pproto);
-			switch_safe_free(ffrom);
-		}
+				switch_safe_free(pproto);
+				switch_safe_free(ffrom);
+			}
 			break;
 		case LDL_SIGNAL_LOGIN_SUCCESS:
 			if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, DL_EVENT_LOGIN_SUCCESS) == SWITCH_STATUS_SUCCESS) {
@@ -2364,12 +2327,12 @@
 			break;
 		default:
 			break;
-			
+
 		}
 		status = LDL_STATUS_SUCCESS;
 		goto done;
 	}
-	
+
 
 	if ((session = ldl_session_get_private(dlsession))) {
 		tech_pvt = switch_core_session_get_private(session);
@@ -2377,7 +2340,7 @@
 
 		channel = switch_core_session_get_channel(session);
 		assert(channel != NULL);
-		
+
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "using Existing session for %s\n", ldl_session_get_id(dlsession));
 
 		if (switch_channel_get_state(channel) >= CS_HANGUP) {
@@ -2394,7 +2357,7 @@
 		}
 		if ((session = switch_core_session_request(&channel_endpoint_interface, NULL)) != 0) {
 			switch_core_session_add_stream(session, NULL);
-			
+
 			if ((tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object))) != 0) {
 				memset(tech_pvt, 0, sizeof(*tech_pvt));
 				switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
@@ -2411,7 +2374,7 @@
 				switch_set_flag_locked(tech_pvt, TFLAG_TRANSPORT_ACCEPT);
 			} else {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Hey where is my memory pool?\n");
-				terminate_session(&session,  __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+				terminate_session(&session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
 				status = LDL_STATUS_FALSE;
 				goto done;
 			}
@@ -2428,9 +2391,9 @@
 
 	}
 
-	switch(dl_signal) {
+	switch (dl_signal) {
 	case LDL_SIGNAL_MSG:
-		if (msg) { 
+		if (msg) {
 			if (*msg == '+') {
 				switch_channel_queue_dtmf(channel, msg + 1);
 				switch_set_flag_locked(tech_pvt, TFLAG_DTMF);
@@ -2444,12 +2407,12 @@
 		if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
 			char *hint = NULL, *p, *freeme = NULL;
 
-			hint = from;			
+			hint = from;
 			if (strchr(from, '/')) {
 				freeme = strdup(from);
 				p = strchr(freeme, '/');
 				*p = '\0';
-				from = freeme;				
+				from = freeme;
 			}
 
 			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "proto", MDL_CHAT_PROTO);
@@ -2482,7 +2445,7 @@
 				if (!strcasecmp(msg, "accept")) {
 					switch_set_flag_locked(tech_pvt, TFLAG_ANSWER);
 					if (!do_candidates(tech_pvt, 0)) {
-						terminate_session(&session,  __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+						terminate_session(&session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
 						status = LDL_STATUS_FALSE;
 						goto done;
 					}
@@ -2496,42 +2459,43 @@
 
 
 			if (!get_codecs(tech_pvt)) {
-				terminate_session(&session,  __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+				terminate_session(&session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
 				status = LDL_STATUS_FALSE;
 				goto done;
 			}
 
-			
+
 			if (ldl_session_get_payloads(dlsession, &payloads, &len) == LDL_STATUS_SUCCESS) {
-                unsigned int x, y;
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%u payloads\n", len);
-				for(x = 0; x < len; x++) {
+				unsigned int x, y;
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%u payloads\n", len);
+				for (x = 0; x < len; x++) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Available Payload %s %u\n", payloads[x].name, payloads[x].id);
-					for(y = 0; y < tech_pvt->num_codecs; y++) {
+					for (y = 0; y < tech_pvt->num_codecs; y++) {
 						char *name = tech_pvt->codecs[y]->iananame;
 
 						if (!strncasecmp(name, "ilbc", 4)) {
 							name = "ilbc";
 						}
-						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "compare %s %d/%d to %s %d/%d\n", 
-                                          payloads[x].name, payloads[x].id, payloads[x].rate,
-                                          name, tech_pvt->codecs[y]->ianacode, tech_pvt->codecs[y]->samples_per_second);
+						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "compare %s %d/%d to %s %d/%d\n",
+										  payloads[x].name, payloads[x].id, payloads[x].rate,
+										  name, tech_pvt->codecs[y]->ianacode, tech_pvt->codecs[y]->samples_per_second);
 						if (tech_pvt->codecs[y]->ianacode > 95) {
 							match = strcasecmp(name, payloads[x].name) ? 0 : 1;
 						} else {
 							match = (payloads[x].id == tech_pvt->codecs[y]->ianacode) ? 1 : 0;
 						}
-						
+
 						if (match && payloads[x].rate == tech_pvt->codecs[y]->samples_per_second) {
 							tech_pvt->codec_index = y;
-							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Choosing Payload index %u %s %u\n", y, payloads[x].name, payloads[x].id);
+							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Choosing Payload index %u %s %u\n", y, payloads[x].name,
+											  payloads[x].id);
 							tech_pvt->codec_name = tech_pvt->codecs[y]->iananame;
 							tech_pvt->codec_num = tech_pvt->codecs[y]->ianacode;
-							tech_pvt->r_codec_num = (switch_payload_t)(payloads[x].id);
+							tech_pvt->r_codec_num = (switch_payload_t) (payloads[x].id);
 							tech_pvt->codec_rate = payloads[x].rate;
 							if (!switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) {
 								if (!do_describe(tech_pvt, 0)) {
-									terminate_session(&session,  __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+									terminate_session(&session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
 									status = LDL_STATUS_FALSE;
 									goto done;
 								}
@@ -2543,14 +2507,14 @@
 				}
 				if (!match && !switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) {
 					if (!do_describe(tech_pvt, 0)) {
-						terminate_session(&session,  __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+						terminate_session(&session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
 						status = LDL_STATUS_FALSE;
 						goto done;
 					}
 				}
 			}
 		}
-		
+
 		break;
 	case LDL_SIGNAL_CANDIDATES:
 		if (dl_signal) {
@@ -2566,41 +2530,30 @@
 				goto done;
 			}
 
-				
+
 			if (tech_pvt->remote_ip) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Already picked an IP [%s]\n", tech_pvt->remote_ip);
 				break;
 			}
 
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%u candidates\n", len);
-			for(x = 0; x < len; x++) {
+			for (x = 0; x < len; x++) {
 				uint8_t lanaddr = 0;
 
 				if (profile->lanaddr) {
 					lanaddr = strncasecmp(candidates[x].address, profile->lanaddr, strlen(profile->lanaddr)) ? 0 : 1;
-				} 
+				}
 
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "candidates %s:%d\n", candidates[x].address, candidates[x].port);
-					
-				if (!strcasecmp(candidates[x].protocol, "udp") && (!strcasecmp(candidates[x].type, "local") || !strcasecmp(candidates[x].type, "stun")) && 
-					((profile->lanaddr && lanaddr) ||
-					 (strncasecmp(candidates[x].address, "10.", 3) && 
-					  strncasecmp(candidates[x].address, "192.168.", 8) &&
-					  strncasecmp(candidates[x].address, "127.", 4) &&
-					  strncasecmp(candidates[x].address, "255.", 4) &&
-					  strncasecmp(candidates[x].address, "0.", 2) &&
-					  strncasecmp(candidates[x].address, "1.", 2) &&
-					  strncasecmp(candidates[x].address, "2.", 2) &&
-					  strncasecmp(candidates[x].address, "172.16.", 7) &&
-					  strncasecmp(candidates[x].address, "172.17.", 7) &&
-					  strncasecmp(candidates[x].address, "172.18.", 7) &&
-					  strncasecmp(candidates[x].address, "172.19.", 7) &&
-					  strncasecmp(candidates[x].address, "172.2", 5) &&
-					  strncasecmp(candidates[x].address, "172.30.", 7) &&
-					  strncasecmp(candidates[x].address, "172.31.", 7)  &&
-					  strncasecmp(candidates[x].address, "192.0.2.", 8)  && // 192.0.0.0 - 192.0.127.255 is marked as reserved, should we filter all of them?
-					  strncasecmp(candidates[x].address, "169.254.", 8)
-					  ))) {
+
+				if (!strcasecmp(candidates[x].protocol, "udp") && (!strcasecmp(candidates[x].type, "local") || !strcasecmp(candidates[x].type, "stun")) && ((profile->lanaddr && lanaddr) || (strncasecmp(candidates[x].address, "10.", 3) && strncasecmp(candidates[x].address, "192.168.", 8) && strncasecmp(candidates[x].address, "127.", 4) && strncasecmp(candidates[x].address, "255.", 4) && strncasecmp(candidates[x].address, "0.", 2) && strncasecmp(candidates[x].address, "1.", 2) && strncasecmp(candidates[x].address, "2.", 2) && strncasecmp(candidates[x].address, "172.16.", 7) && strncasecmp(candidates[x].address, "172.17.", 7) && strncasecmp(candidates[x].address, "172.18.", 7) && strncasecmp(candidates[x].address, "172.19.", 7) && strncasecmp(candidates[x].address, "172.2", 5) && strncasecmp(candidates[x].address, "172.30.", 7) && strncasecmp(candidates[x].address, "172.31.", 7) && strncasecmp(candidates[x].address, "192.0.2.", 8) &&	// 192.0.0.0 - 192.0.127.255 is marked as reserved, should we filter all of them?
+																																															  strncasecmp
+																																															  (candidates
+																																															   [x].
+																																															   address,
+																																															   "169.254.",
+																																															   8)
+																																							))) {
 					ldl_payload_t payloads[5];
 					char *exten;
 					char *context;
@@ -2638,7 +2591,7 @@
 							}
 						}
 					}
-						
+
 					if (!(context = ldl_session_get_value(dlsession, "context"))) {
 						context = profile->context;
 					}
@@ -2655,7 +2608,7 @@
 					if (profile->context && !strcmp(profile->context, "_auto_")) {
 						context = profile->name;
 					}
-			
+
 					tech_pvt->them = switch_core_session_strdup(session, ldl_session_get_callee(dlsession));
 					tech_pvt->us = switch_core_session_strdup(session, ldl_session_get_caller(dlsession));
 
@@ -2673,22 +2626,23 @@
 
 						switch_safe_free(tmp);
 					}
-						
+
 					if (!tech_pvt->caller_profile) {
-						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Creating an identity for %s %s <%s> %s\n", 
-										  ldl_session_get_id(dlsession), cid_name, cid_num, exten);
-			
+						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
+										  "Creating an identity for %s %s <%s> %s\n", ldl_session_get_id(dlsession), cid_name, cid_num, exten);
+
 						if ((tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
 																				  ldl_handle_get_login(profile->handle),
 																				  profile->dialplan,
 																				  cid_name,
 																				  cid_num,
 																				  ldl_session_get_ip(dlsession),
-																				  ldl_session_get_value(dlsession, "ani"),
-																				  ldl_session_get_value(dlsession, "aniii"),
-																				  ldl_session_get_value(dlsession, "rdnis"),
-																				  (char *)modname,
-																				  context,
+																				  ldl_session_get_value(dlsession,
+																										"ani"),
+																				  ldl_session_get_value(dlsession,
+																										"aniii"),
+																				  ldl_session_get_value(dlsession,
+																										"rdnis"), (char *) modname, context,
 																				  exten)) != 0) {
 							char name[128];
 							snprintf(name, sizeof(name), "DingaLing/%s", tech_pvt->caller_profile->destination_number);
@@ -2698,32 +2652,32 @@
 					}
 
 					switch_safe_free(them);
-						
+
 					if (lanaddr) {
 						switch_set_flag_locked(tech_pvt, TFLAG_LANADDR);
 					}
 
 					if (!get_codecs(tech_pvt)) {
-						terminate_session(&session,  __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+						terminate_session(&session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
 						status = LDL_STATUS_FALSE;
 						goto done;
 					}
 
-						
+
 					tech_pvt->remote_ip = switch_core_session_strdup(session, candidates[x].address);
 					ldl_session_set_ip(dlsession, tech_pvt->remote_ip);
 					tech_pvt->remote_port = candidates[x].port;
 					tech_pvt->remote_user = switch_core_session_strdup(session, candidates[x].username);
 
-						
+
 					if (!switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) {
 						if (!do_candidates(tech_pvt, 0)) {
-							terminate_session(&session,  __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+							terminate_session(&session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
 							status = LDL_STATUS_FALSE;
 							goto done;
 						}
 					}
-						
+
 					status = LDL_STATUS_SUCCESS;
 					goto done;
 				}
@@ -2731,18 +2685,18 @@
 		}
 		break;
 	case LDL_SIGNAL_REJECT:
-        if (channel) {
+		if (channel) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "reject %s\n", switch_channel_get_name(channel));
-			terminate_session(&session,  __LINE__, SWITCH_CAUSE_CALL_REJECTED);
+			terminate_session(&session, __LINE__, SWITCH_CAUSE_CALL_REJECTED);
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "End Call (Rejected)\n");
 			goto done;
 		}
-        break;
+		break;
 	case LDL_SIGNAL_ERROR:
 	case LDL_SIGNAL_TERMINATE:
 		if (channel) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "hungup %s\n", switch_channel_get_name(channel));
-			terminate_session(&session,  __LINE__, SWITCH_CAUSE_NORMAL_CLEARING);
+			terminate_session(&session, __LINE__, SWITCH_CAUSE_NORMAL_CLEARING);
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "End Call\n");
 			goto done;
 		}
@@ -2753,12 +2707,12 @@
 		break;
 	}
 
- done:
-	
+  done:
+
 	return status;
 }
 
-static ldl_status handle_response(ldl_handle_t *handle, char *id)
+static ldl_status handle_response(ldl_handle_t * handle, char *id)
 {
 	return LDL_STATUS_SUCCESS;
 }

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_iax/mod_iax.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_iax/mod_iax.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_iax/mod_iax.c	Fri Mar 30 12:19:18 2007
@@ -98,13 +98,12 @@
 
 
 SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_dialplan, globals.dialplan)
-SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_string, globals.codec_string)
-SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_rates_string, globals.codec_rates_string)
-SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_ip, globals.ip)
+	SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_string, globals.codec_string)
+	SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_rates_string, globals.codec_rates_string)
+	SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_ip, globals.ip)
 
 
-	 static char *IAXNAMES[] =
-		 { "IAX_EVENT_CONNECT", "IAX_EVENT_ACCEPT", "IAX_EVENT_HANGUP", "IAX_EVENT_REJECT", "IAX_EVENT_VOICE",
+	 static char *IAXNAMES[] = { "IAX_EVENT_CONNECT", "IAX_EVENT_ACCEPT", "IAX_EVENT_HANGUP", "IAX_EVENT_REJECT", "IAX_EVENT_VOICE",
 		 "IAX_EVENT_DTMF", "IAX_EVENT_TIMEOUT", "IAX_EVENT_LAGRQ", "IAX_EVENT_LAGRP", "IAX_EVENT_RINGA",
 		 "IAX_EVENT_PING", "IAX_EVENT_PONG", "IAX_EVENT_BUSY", "IAX_EVENT_ANSWER", "IAX_EVENT_IMAGE",
 		 "IAX_EVENT_AUTHRQ", "IAX_EVENT_AUTHRP", "IAX_EVENT_REGREQ", "IAX_EVENT_REGACK",
@@ -209,9 +208,8 @@
 	IAX_QUERY = 2
 } iax_io_t;
 
-static switch_status_t iax_set_codec(private_t *tech_pvt, struct iax_session *iax_session,
-								   unsigned int *format, unsigned int *cababilities, unsigned short *samprate,
-								   iax_io_t io)
+static switch_status_t iax_set_codec(private_t * tech_pvt, struct iax_session *iax_session,
+									 unsigned int *format, unsigned int *cababilities, unsigned short *samprate, iax_io_t io)
 {
 	char *dname = NULL;
 	//int rate = 8000;
@@ -224,16 +222,11 @@
 	uint32_t interval = 0;
 
 	if (globals.codec_string) {
-		if ((num_codecs = switch_loadable_module_get_codecs_sorted(codecs,
-																	SWITCH_MAX_CODECS,
-																	globals.codec_order,
-																	globals.codec_order_last)) <= 0) {
+		if ((num_codecs = switch_loadable_module_get_codecs_sorted(codecs, SWITCH_MAX_CODECS, globals.codec_order, globals.codec_order_last)) <= 0) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "NO codecs?\n");
 			return SWITCH_STATUS_GENERR;
 		}
-	} else
-		if (((num_codecs =
-			 switch_loadable_module_get_codecs(switch_core_session_get_pool(tech_pvt->session), codecs, SWITCH_MAX_CODECS))) <= 0) {
+	} else if (((num_codecs = switch_loadable_module_get_codecs(switch_core_session_get_pool(tech_pvt->session), codecs, SWITCH_MAX_CODECS))) <= 0) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "NO codecs?\n");
 		return SWITCH_STATUS_GENERR;
 	}
@@ -244,7 +237,7 @@
 			unsigned int codec = iana2ast(imp->ianacode);
 			if (io == IAX_QUERY && !(codec & local_cap)) {
 				iax_pref_codec_add(iax_session, codec);
-			}	
+			}
 			local_cap |= codec;
 		}
 	}
@@ -422,12 +415,11 @@
 static switch_status_t channel_on_ring(switch_core_session_t *session);
 static switch_status_t channel_on_loopback(switch_core_session_t *session);
 static switch_status_t channel_on_transmit(switch_core_session_t *session);
-static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile,
+static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session,
+													switch_caller_profile_t *outbound_profile,
 													switch_core_session_t **new_session, switch_memory_pool_t **pool);
-static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout,
-										switch_io_flag_t flags, int stream_id);
-static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout,
-										 switch_io_flag_t flags, int stream_id);
+static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, switch_io_flag_t flags, int stream_id);
+static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flags, int stream_id);
 static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig);
 
 
@@ -443,14 +435,14 @@
 	}
 }
 
-static void tech_init(private_t *tech_pvt, switch_core_session_t *session)
+static void tech_init(private_t * tech_pvt, switch_core_session_t *session)
 {
 	tech_pvt->read_frame.data = tech_pvt->databuf;
 	tech_pvt->read_frame.buflen = sizeof(tech_pvt->databuf);
 	switch_mutex_init(&tech_pvt->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
-    switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
-    switch_core_session_set_private(session, tech_pvt);
-    tech_pvt->session = session;
+	switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
+	switch_core_session_set_private(session, tech_pvt);
+	tech_pvt->session = session;
 }
 
 /* 
@@ -559,7 +551,7 @@
 		globals.calls = 0;
 	}
 	switch_mutex_unlock(globals.mutex);
-		
+
 	return SWITCH_STATUS_SUCCESS;
 }
 
@@ -574,20 +566,20 @@
 	tech_pvt = switch_core_session_get_private(session);
 	assert(tech_pvt != NULL);
 
-    switch(sig) {
-    case SWITCH_SIG_KILL:
-        switch_clear_flag_locked(tech_pvt, TFLAG_IO);
-        switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
-        switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
-        //switch_thread_cond_signal(tech_pvt->cond);
-        break;
-    case SWITCH_SIG_BREAK:
-        switch_set_flag_locked(tech_pvt, TFLAG_BREAK);
-        break;
-    default:
-        break;
-    }
-	
+	switch (sig) {
+	case SWITCH_SIG_KILL:
+		switch_clear_flag_locked(tech_pvt, TFLAG_IO);
+		switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
+		switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
+		//switch_thread_cond_signal(tech_pvt->cond);
+		break;
+	case SWITCH_SIG_BREAK:
+		switch_set_flag_locked(tech_pvt, TFLAG_BREAK);
+		break;
+	default:
+		break;
+	}
+
 	return SWITCH_STATUS_SUCCESS;
 }
 
@@ -640,34 +632,33 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout,
-										switch_io_flag_t flags, int stream_id)
+static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, switch_io_flag_t flags, int stream_id)
 {
 	switch_channel_t *channel = NULL;
 	private_t *tech_pvt = NULL;
 	switch_time_t started = switch_time_now();
 	unsigned int elapsed;
 	switch_byte_t *data;
-	
+
 	channel = switch_core_session_get_channel(session);
 	assert(channel != NULL);
 
 	tech_pvt = switch_core_session_get_private(session);
 	assert(tech_pvt != NULL);
-    tech_pvt->read_frame.flags = SFF_NONE;
-    *frame = NULL;
+	tech_pvt->read_frame.flags = SFF_NONE;
+	*frame = NULL;
 
 	while (switch_test_flag(tech_pvt, TFLAG_IO)) {
-        
-        if (!switch_test_flag(tech_pvt, TFLAG_CODEC)) {
-            switch_yield(1000);
-            continue;
-        }
+
+		if (!switch_test_flag(tech_pvt, TFLAG_CODEC)) {
+			switch_yield(1000);
+			continue;
+		}
 		//switch_thread_cond_wait(tech_pvt->cond, tech_pvt->mutex);
 		if (switch_test_flag(tech_pvt, TFLAG_BREAK)) {
-            switch_clear_flag(tech_pvt, TFLAG_BREAK);
-            goto cng;
-        }
+			switch_clear_flag(tech_pvt, TFLAG_BREAK);
+			goto cng;
+		}
 
 		if (!switch_test_flag(tech_pvt, TFLAG_IO)) {
 			return SWITCH_STATUS_FALSE;
@@ -688,12 +679,12 @@
 		}
 
 		if (timeout > -1) {
-			elapsed = (unsigned int)((switch_time_now() - started) / 1000);
-			if (elapsed >= (unsigned int)timeout) {
+			elapsed = (unsigned int) ((switch_time_now() - started) / 1000);
+			if (elapsed >= (unsigned int) timeout) {
 				return SWITCH_STATUS_SUCCESS;
 			}
 		}
-		
+
 
 		switch_yield(1000);
 	}
@@ -701,19 +692,18 @@
 
 	return SWITCH_STATUS_FALSE;
 
- cng:
+  cng:
 	data = (switch_byte_t *) tech_pvt->read_frame.data;
 	data[0] = 65;
 	data[1] = 0;
-    tech_pvt->read_frame.datalen = 2;
-    tech_pvt->read_frame.flags = SFF_CNG; 
-    *frame = &tech_pvt->read_frame;
-    return SWITCH_STATUS_SUCCESS;
-	
+	tech_pvt->read_frame.datalen = 2;
+	tech_pvt->read_frame.flags = SFF_CNG;
+	*frame = &tech_pvt->read_frame;
+	return SWITCH_STATUS_SUCCESS;
+
 }
 
-static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout,
-										 switch_io_flag_t flags, int stream_id)
+static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flags, int stream_id)
 {
 	switch_channel_t *channel = NULL;
 	private_t *tech_pvt = NULL;
@@ -734,8 +724,7 @@
 	}
 #endif
 	//printf("Send %ld %d\n", time(NULL), (int) frame->datalen);
-	iax_send_voice(tech_pvt->iax_session, tech_pvt->codec, frame->data, (int) frame->datalen,
-				   tech_pvt->write_codec.implementation->samples_per_frame);
+	iax_send_voice(tech_pvt->iax_session, tech_pvt->codec, frame->data, (int) frame->datalen, tech_pvt->write_codec.implementation->samples_per_frame);
 
 	return SWITCH_STATUS_SUCCESS;
 
@@ -799,7 +788,8 @@
 /* Make sure when you have 2 sessions in the same scope that you pass the appropriate one to the routines
 that allocate memory or you will have 1 channel with memory allocated from another channel's pool!
 */
-static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile,
+static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session,
+													switch_caller_profile_t *outbound_profile,
 													switch_core_session_t **new_session, switch_memory_pool_t **pool)
 {
 	if ((*new_session = switch_core_session_request(&channel_endpoint_interface, pool)) != 0) {
@@ -812,7 +802,7 @@
 		switch_core_session_add_stream(*new_session, NULL);
 		if ((tech_pvt = (private_t *) switch_core_session_alloc(*new_session, sizeof(private_t))) != 0) {
 			channel = switch_core_session_get_channel(*new_session);
-            tech_init(tech_pvt, *new_session);
+			tech_init(tech_pvt, *new_session);
 		} else {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n");
 			switch_core_session_destroy(new_session);
@@ -850,8 +840,7 @@
 		}
 
 		iax_call(tech_pvt->iax_session,
-				 caller_profile->caller_id_number,
-				 caller_profile->caller_id_name, caller_profile->destination_number, NULL, 0, req, cap);
+				 caller_profile->caller_id_number, caller_profile->caller_id_name, caller_profile->destination_number, NULL, 0, req, cap);
 
 		switch_channel_set_flag(channel, CF_OUTBOUND);
 		switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
@@ -871,7 +860,7 @@
 		return SWITCH_STATUS_TERM;
 	}
 
-	
+
 	/* connect my internal structure to the blank pointer passed to me */
 	*module_interface = &channel_module_interface;
 
@@ -920,12 +909,10 @@
 				set_global_dialplan(val);
 			} else if (!strcmp(var, "codec-prefs")) {
 				set_global_codec_string(val);
-				globals.codec_order_last =
-					switch_separate_string(globals.codec_string, ',', globals.codec_order, SWITCH_MAX_CODECS);
+				globals.codec_order_last = switch_separate_string(globals.codec_string, ',', globals.codec_order, SWITCH_MAX_CODECS);
 			} else if (!strcmp(var, "codec-rates")) {
 				set_global_codec_rates_string(val);
-				globals.codec_rates_last =
-					switch_separate_string(globals.codec_rates_string, ',', globals.codec_rates, SWITCH_MAX_CODECS);
+				globals.codec_rates_last = switch_separate_string(globals.codec_rates_string, ',', globals.codec_rates, SWITCH_MAX_CODECS);
 			}
 		}
 	}
@@ -943,18 +930,18 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t tech_media(private_t *tech_pvt, struct iax_event *iaxevent)
+static switch_status_t tech_media(private_t * tech_pvt, struct iax_event *iaxevent)
 {
-    unsigned int cap = iax_session_get_capability(iaxevent->session);
-    unsigned int format = iaxevent->ies.format;
+	unsigned int cap = iax_session_get_capability(iaxevent->session);
+	unsigned int format = iaxevent->ies.format;
 	switch_status_t status = SWITCH_STATUS_SUCCESS;
-    
-    if (!switch_test_flag(tech_pvt, TFLAG_CODEC) && 
-        (status = iax_set_codec(tech_pvt, iaxevent->session, &format, &cap, &iaxevent->ies.samprate, IAX_SET)) != SWITCH_STATUS_SUCCESS) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec Error %u %u\n", iaxevent->ies.format, iaxevent->ies.capability);
-    }
-    
-    return status;
+
+	if (!switch_test_flag(tech_pvt, TFLAG_CODEC) &&
+		(status = iax_set_codec(tech_pvt, iaxevent->session, &format, &cap, &iaxevent->ies.samprate, IAX_SET)) != SWITCH_STATUS_SUCCESS) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec Error %u %u\n", iaxevent->ies.format, iaxevent->ies.capability);
+	}
+
+	return status;
 }
 
 SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
@@ -994,7 +981,7 @@
 		/* Wait for an event. */
 		if ((iaxevent = iax_get_event(0)) == NULL) {
 			int waitlen = 0;
-			
+
 			if (globals.calls == 0) {
 				waitlen = 10000;
 			} else if (globals.calls < 10) {
@@ -1007,15 +994,14 @@
 			continue;
 		} else {
 			private_t *tech_pvt = NULL;
-            switch_channel_t *channel = NULL;
+			switch_channel_t *channel = NULL;
+
+			if ((tech_pvt = iax_get_private(iaxevent->session))) {
+				channel = switch_core_session_get_channel(tech_pvt->session);
+			}
 
-            if ((tech_pvt = iax_get_private(iaxevent->session))) {
-                channel = switch_core_session_get_channel(tech_pvt->session);
-            }
-            
 			if (globals.debug && iaxevent->etype != IAX_EVENT_VOICE) {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Event %d [%s]!\n",
-								  iaxevent->etype, IAXNAMES[iaxevent->etype]);
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Event %d [%s]!\n", iaxevent->etype, IAXNAMES[iaxevent->etype]);
 			}
 
 			switch (iaxevent->etype) {
@@ -1031,11 +1017,11 @@
 				break;
 			case IAX_EVENT_ACCEPT:
 				if (channel && !switch_channel_test_flag(channel, CF_ANSWERED)) {
-                    if (tech_media(tech_pvt, iaxevent) == SWITCH_STATUS_SUCCESS) {
-                        switch_channel_mark_pre_answered(channel);
-                    } else {
-                        switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-                    }
+					if (tech_media(tech_pvt, iaxevent) == SWITCH_STATUS_SUCCESS) {
+						switch_channel_mark_pre_answered(channel);
+					} else {
+						switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+					}
 				}
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Call accepted.\n");
 				break;
@@ -1052,32 +1038,30 @@
 			case IAX_EVENT_ANSWER:
 				// the other side answered our call
 				if (channel) {
-                    if (tech_media(tech_pvt, iaxevent) == SWITCH_STATUS_SUCCESS) {
-                        if (switch_channel_test_flag(channel, CF_ANSWERED)) {
-                            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "WTF Mutiple Answer %s?\n", switch_channel_get_name(channel));
-						
-                        } else {
-                            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Answer %s\n", switch_channel_get_name(channel));
-                            switch_channel_mark_answered(channel);
-                        }
-                    } else {
-                        switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-                    }
-                }
+					if (tech_media(tech_pvt, iaxevent) == SWITCH_STATUS_SUCCESS) {
+						if (switch_channel_test_flag(channel, CF_ANSWERED)) {
+							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "WTF Mutiple Answer %s?\n", switch_channel_get_name(channel));
+
+						} else {
+							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Answer %s\n", switch_channel_get_name(channel));
+							switch_channel_mark_answered(channel);
+						}
+					} else {
+						switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+					}
+				}
 				break;
 			case IAX_EVENT_CONNECT:
 				// incoming call detected
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE,
-									  "Incoming call connected %s, %s, %s %u/%u\n",
-									  iaxevent->ies.called_number,
-									  iaxevent->ies.calling_number,
-									  iaxevent->ies.calling_name, iaxevent->ies.format, iaxevent->ies.capability);
+								  "Incoming call connected %s, %s, %s %u/%u\n",
+								  iaxevent->ies.called_number,
+								  iaxevent->ies.calling_number, iaxevent->ies.calling_name, iaxevent->ies.format, iaxevent->ies.capability);
 
 				if (iaxevent) {
 					switch_core_session_t *session;
 
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "New Inbound Channel %s!\n",
-										  iaxevent->ies.calling_name);
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "New Inbound Channel %s!\n", iaxevent->ies.calling_name);
 					if ((session = switch_core_session_request(&channel_endpoint_interface, NULL)) != 0) {
 						private_t *tech_pvt;
 						switch_channel_t *channel;
@@ -1085,7 +1069,7 @@
 						switch_core_session_add_stream(session, NULL);
 						if ((tech_pvt = (private_t *) switch_core_session_alloc(session, sizeof(private_t))) != 0) {
 							channel = switch_core_session_get_channel(session);
-                            tech_init(tech_pvt, session);
+							tech_init(tech_pvt, session);
 						} else {
 							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n");
 							switch_core_session_destroy(&session);
@@ -1100,23 +1084,19 @@
 																				  iaxevent->ies.calling_number,
 																				  iax_get_peer_ip(iaxevent->session),
 																				  iaxevent->ies.calling_ani,
-																				  NULL, 
 																				  NULL,
-																				  (char *)modname,
-																				  iaxevent->ies.called_context,
-																				  iaxevent->ies.called_number)) != 0) {
+																				  NULL,
+																				  (char *) modname,
+																				  iaxevent->ies.called_context, iaxevent->ies.called_number)) != 0) {
 							char name[128];
-							snprintf(name, sizeof(name), "IAX/%s-%04x", tech_pvt->caller_profile->destination_number,
-									 rand() & 0xffff);
+							snprintf(name, sizeof(name), "IAX/%s-%04x", tech_pvt->caller_profile->destination_number, rand() & 0xffff);
 							switch_channel_set_name(channel, name);
 							switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
 
 						}
 
 						if (iax_set_codec(tech_pvt, iaxevent->session,
-										  &iaxevent->ies.format,
-										  &iaxevent->ies.capability,
-										  &iaxevent->ies.samprate, IAX_SET) != SWITCH_STATUS_SUCCESS) {
+										  &iaxevent->ies.format, &iaxevent->ies.capability, &iaxevent->ies.samprate, IAX_SET) != SWITCH_STATUS_SUCCESS) {
 							iax_reject(iaxevent->session, "Codec Error!");
 							switch_core_session_destroy(&session);
 						} else {
@@ -1141,11 +1121,11 @@
 					switch_mutex_unlock(tech_pvt->flag_mutex);
 
 
-                    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Hangup %s\n", switch_channel_get_name(channel));
-                    switch_set_flag_locked(tech_pvt, TFLAG_HANGUP);
-                    switch_channel_hangup(channel, iaxevent->etype == IAX_EVENT_HANGUP ? SWITCH_CAUSE_NORMAL_CLEARING : SWITCH_CAUSE_FACILITY_REJECTED);
-                    //switch_thread_cond_signal(tech_pvt->cond);
-                    iaxevent->session = NULL;
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Hangup %s\n", switch_channel_get_name(channel));
+					switch_set_flag_locked(tech_pvt, TFLAG_HANGUP);
+					switch_channel_hangup(channel, iaxevent->etype == IAX_EVENT_HANGUP ? SWITCH_CAUSE_NORMAL_CLEARING : SWITCH_CAUSE_FACILITY_REJECTED);
+					//switch_thread_cond_signal(tech_pvt->cond);
+					iaxevent->session = NULL;
 				}
 				break;
 			case IAX_EVENT_CNG:
@@ -1156,7 +1136,7 @@
 				if (tech_pvt && (tech_pvt->read_frame.datalen = iaxevent->datalen) != 0) {
 					if (channel && switch_channel_get_state(channel) <= CS_HANGUP) {
 						int bytes, frames;
-						
+
 						if (!switch_test_flag(tech_pvt, TFLAG_CODEC)) {
 							//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "audio with no codec yet!\n");
 							break;
@@ -1183,18 +1163,16 @@
 				break;
 			case IAX_EVENT_DTMF:
 				if (channel) {
-                    char str[2] = { (char)iaxevent->subclass };
-                    if (globals.debug) {
-                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s DTMF %s\n", str,
-                                          switch_channel_get_name(channel));
-                    }
-                    switch_channel_queue_dtmf(channel, str);
+					char str[2] = { (char) iaxevent->subclass };
+					if (globals.debug) {
+						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s DTMF %s\n", str, switch_channel_get_name(channel));
+					}
+					switch_channel_queue_dtmf(channel, str);
 				}
 
 				break;
 			default:
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Don't know what to do with IAX event %d.\n",
-									  iaxevent->etype);
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Don't know what to do with IAX event %d.\n", iaxevent->etype);
 				break;
 			}
 
@@ -1216,7 +1194,7 @@
 	running = -1;
 
 	if (globals.fd) {
-		/* Die Mutha $%#$@% Die Mutha $#%#$^ Die*/
+		/* Die Mutha $%#$@% Die Mutha $#%#$^ Die */
 		shutdown(globals.fd, 2);
 	}
 	iax_shutdown();

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_portaudio/mod_portaudio.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_portaudio/mod_portaudio.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_portaudio/mod_portaudio.c	Fri Mar 30 12:19:18 2007
@@ -48,13 +48,13 @@
 //#define SAMPLE_TYPE  paFloat32
 typedef short SAMPLE;
 
-typedef switch_status_t (*pa_command_t)(char **argv, int argc, switch_stream_handle_t *stream);
+typedef switch_status_t (*pa_command_t) (char **argv, int argc, switch_stream_handle_t *stream);
 
 typedef enum {
-    GFLAG_NONE = 0,
-    GFLAG_EAR = (1 << 0),
-    GFLAG_MOUTH = (1 << 1),
-    GFLAG_RING = (1 << 2)
+	GFLAG_NONE = 0,
+	GFLAG_EAR = (1 << 0),
+	GFLAG_MOUTH = (1 << 1),
+	GFLAG_RING = (1 << 2)
 } GFLAGS;
 
 typedef enum {
@@ -75,17 +75,17 @@
 	switch_core_session_t *session;
 	switch_caller_profile_t *caller_profile;
 	char call_id[50];
-    int sample_rate;
-    int codec_ms;
+	int sample_rate;
+	int codec_ms;
 	switch_mutex_t *flag_mutex;
-    char *hold_file;
-    switch_file_handle_t fh;
-    switch_file_handle_t *hfh;
+	char *hold_file;
+	switch_file_handle_t fh;
+	switch_file_handle_t *hfh;
 	switch_frame_t hold_frame;
-    unsigned char holdbuf[SWITCH_RECOMMENDED_BUFFER_SIZE];
+	unsigned char holdbuf[SWITCH_RECOMMENDED_BUFFER_SIZE];
 	switch_codec_t write_codec;
-    switch_timer_t timer;
-    struct private_object *next;
+	switch_timer_t timer;
+	struct private_object *next;
 };
 
 typedef struct private_object private_t;
@@ -96,9 +96,9 @@
 	char *cid_name;
 	char *cid_num;
 	char *dialplan;
-    char *ring_file;
-    char *hold_file;
-    char *timer_name;
+	char *ring_file;
+	char *hold_file;
+	char *timer_name;
 	int ringdev;
 	int indev;
 	int outdev;
@@ -114,13 +114,13 @@
 	switch_codec_t read_codec;
 	switch_codec_t write_codec;
 	switch_frame_t read_frame;
-    switch_frame_t cng_frame;
+	switch_frame_t cng_frame;
 	unsigned char databuf[SWITCH_RECOMMENDED_BUFFER_SIZE];
 	unsigned char cngbuf[SWITCH_RECOMMENDED_BUFFER_SIZE];
-    private_t *call_list;
-    int ring_interval;
-    GFLAGS flags;
-    switch_timer_t timer;
+	private_t *call_list;
+	int ring_interval;
+	GFLAGS flags;
+	switch_timer_t timer;
 } globals;
 
 
@@ -129,37 +129,34 @@
 
 
 SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_dialplan, globals.dialplan)
-SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_cid_name, globals.cid_name)
-SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_cid_num, globals.cid_num)
-SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_ring_file, globals.ring_file)
-SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_hold_file, globals.hold_file)
-SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_timer_name, globals.timer_name)
-
+	SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_cid_name, globals.cid_name)
+	SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_cid_num, globals.cid_num)
+	SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_ring_file, globals.ring_file)
+	SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_hold_file, globals.hold_file)
+	SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_timer_name, globals.timer_name)
 #define is_master(t) switch_test_flag(t, TFLAG_MASTER)
-static void add_pvt(private_t *tech_pvt, int master);
-static void remove_pvt(private_t *tech_pvt);
-static switch_status_t channel_on_init(switch_core_session_t *session);
-static switch_status_t channel_on_hangup(switch_core_session_t *session);
-static switch_status_t channel_on_ring(switch_core_session_t *session);
-static switch_status_t channel_on_loopback(switch_core_session_t *session);
-static switch_status_t channel_on_transmit(switch_core_session_t *session);
-static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session,
-													switch_caller_profile_t *outbound_profile,
-													switch_core_session_t **new_session, switch_memory_pool_t **pool);
-static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout,
-                                          switch_io_flag_t flags, int stream_id);
-static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout,
-                                           switch_io_flag_t flags, int stream_id);
-static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig);
-static switch_status_t engage_device(int samplerate, int codec_ms);
-static switch_status_t engage_ring_device(int sample_rate, int channels);
-static void deactivate_ring_device(void);
-static int dump_info(void);
-static switch_status_t load_config(void);
-static int get_dev_by_name(char *name, int in);
-static int get_dev_by_number(int number, int in);
-static switch_status_t pa_cmd(char *dest, switch_core_session_t *session, switch_stream_handle_t *stream);
-static switch_status_t padep(char *dest, switch_core_session_t *session, switch_stream_handle_t *stream);
+	 static void add_pvt(private_t * tech_pvt, int master);
+	 static void remove_pvt(private_t * tech_pvt);
+	 static switch_status_t channel_on_init(switch_core_session_t *session);
+	 static switch_status_t channel_on_hangup(switch_core_session_t *session);
+	 static switch_status_t channel_on_ring(switch_core_session_t *session);
+	 static switch_status_t channel_on_loopback(switch_core_session_t *session);
+	 static switch_status_t channel_on_transmit(switch_core_session_t *session);
+	 static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session,
+														 switch_caller_profile_t *outbound_profile,
+														 switch_core_session_t **new_session, switch_memory_pool_t **pool);
+	 static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, switch_io_flag_t flags, int stream_id);
+	 static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flags, int stream_id);
+	 static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig);
+	 static switch_status_t engage_device(int samplerate, int codec_ms);
+	 static switch_status_t engage_ring_device(int sample_rate, int channels);
+	 static void deactivate_ring_device(void);
+	 static int dump_info(void);
+	 static switch_status_t load_config(void);
+	 static int get_dev_by_name(char *name, int in);
+	 static int get_dev_by_number(int number, int in);
+	 static switch_status_t pa_cmd(char *dest, switch_core_session_t *session, switch_stream_handle_t *stream);
+	 static switch_status_t padep(char *dest, switch_core_session_t *session, switch_stream_handle_t *stream);
 
 
 /* 
@@ -167,91 +164,90 @@
    returning SWITCH_STATUS_SUCCESS tells the core to execute the standard state method next
    so if you fully implement the state you can return SWITCH_STATUS_FALSE to skip it.
 */
-static switch_status_t channel_on_init(switch_core_session_t *session)
+	 static switch_status_t channel_on_init(switch_core_session_t *session)
 {
 	switch_channel_t *channel;
 	private_t *tech_pvt = NULL;
 	switch_time_t last;
 	int waitsec = globals.ring_interval * 1000000;
-    switch_file_handle_t fh = {0};
-    char *val, *ring_file = NULL, *hold_file = NULL;
-    int16_t abuf[2048];
+	switch_file_handle_t fh = { 0 };
+	char *val, *ring_file = NULL, *hold_file = NULL;
+	int16_t abuf[2048];
 
-    tech_pvt = switch_core_session_get_private(session);
+	tech_pvt = switch_core_session_get_private(session);
 	assert(tech_pvt != NULL);
 
 	channel = switch_core_session_get_channel(session);
 	assert(channel != NULL);
 
-    
+
 	last = switch_time_now() - waitsec;
 
 
 
-    if ((val = switch_channel_get_variable(channel, "pa_hold_file"))) {
-        hold_file = val;
-    } else {
-        hold_file = globals.hold_file;
-    }
-
-    if (hold_file) {
-        tech_pvt->hold_file = switch_core_session_strdup(session, hold_file);
-    }
+	if ((val = switch_channel_get_variable(channel, "pa_hold_file"))) {
+		hold_file = val;
+	} else {
+		hold_file = globals.hold_file;
+	}
+
+	if (hold_file) {
+		tech_pvt->hold_file = switch_core_session_strdup(session, hold_file);
+	}
 
 	if (switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) {
 
-        
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL INIT %d %d\n", switch_channel_get_name(channel),
-                          switch_channel_get_state(channel), switch_test_flag(tech_pvt, TFLAG_ANSWER));
-        
-
-
-        if (engage_device(tech_pvt->sample_rate, tech_pvt->codec_ms) != SWITCH_STATUS_SUCCESS) {
-            switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-            return SWITCH_STATUS_FALSE;
-        }
-
-        if (switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) {
-            add_pvt(tech_pvt, PA_SLAVE);
-
-            ring_file = globals.ring_file;
-            if ((val = switch_channel_get_variable(channel, "pa_ring_file"))) {
-                ring_file = val;
-            }
-
-            if (switch_test_flag((&globals), GFLAG_RING)) {
-                ring_file = NULL;
-            }
-            switch_set_flag_locked((&globals), GFLAG_RING);
-            if (ring_file) {
-                if (switch_core_file_open(&fh,
-                                          ring_file,
+
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL INIT %d %d\n",
+						  switch_channel_get_name(channel), switch_channel_get_state(channel), switch_test_flag(tech_pvt, TFLAG_ANSWER));
+
+
+
+		if (engage_device(tech_pvt->sample_rate, tech_pvt->codec_ms) != SWITCH_STATUS_SUCCESS) {
+			switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+			return SWITCH_STATUS_FALSE;
+		}
+
+		if (switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) {
+			add_pvt(tech_pvt, PA_SLAVE);
+
+			ring_file = globals.ring_file;
+			if ((val = switch_channel_get_variable(channel, "pa_ring_file"))) {
+				ring_file = val;
+			}
+
+			if (switch_test_flag((&globals), GFLAG_RING)) {
+				ring_file = NULL;
+			}
+			switch_set_flag_locked((&globals), GFLAG_RING);
+			if (ring_file) {
+				if (switch_core_file_open(&fh,
+										  ring_file,
 										  globals.read_codec.implementation->number_of_channels,
 										  globals.read_codec.implementation->samples_per_second,
-                                          SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT,
-                                          NULL) == SWITCH_STATUS_SUCCESS) {
-            
-                    if (engage_ring_device(fh.samplerate, fh.channels) != SWITCH_STATUS_SUCCESS) {
-                        switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Ring Error!\n");
-                        switch_core_file_close(&fh);
-                        return SWITCH_STATUS_GENERR;
-                    }
-                } else {
-                    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot open %s, disabling ring file!\n", ring_file);
-                    ring_file = NULL;
-                }
-            }
-        }
+										  SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) == SWITCH_STATUS_SUCCESS) {
+
+					if (engage_ring_device(fh.samplerate, fh.channels) != SWITCH_STATUS_SUCCESS) {
+						switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Ring Error!\n");
+						switch_core_file_close(&fh);
+						return SWITCH_STATUS_GENERR;
+					}
+				} else {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot open %s, disabling ring file!\n", ring_file);
+					ring_file = NULL;
+				}
+			}
+		}
 
 		switch_core_session_queue_indication(session, SWITCH_MESSAGE_INDICATE_RINGING);
 		switch_channel_mark_ring_ready(channel);
-		
+
 		while (switch_channel_get_state(channel) == CS_INIT && !switch_test_flag(tech_pvt, TFLAG_ANSWER)) {
 			if (switch_time_now() - last >= waitsec) {
 				char buf[512];
 				switch_event_t *event;
-                
+
 				snprintf(buf, sizeof(buf), "BRRRRING! BRRRRING! call %s\n", tech_pvt->call_id);
 
 				if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, MY_EVENT_RINGING) == SWITCH_STATUS_SUCCESS) {
@@ -263,46 +259,46 @@
 
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s\n", buf);
 				last = switch_time_now();
-                if (ring_file) {
-                    unsigned int pos = 0;
-                    switch_core_file_seek(&fh, &pos, 0, SEEK_SET);				 
-                    for (;;) {
-                        switch_size_t olen = 1024;
-                        switch_core_file_read(&fh, abuf, &olen);
-                        if (olen == 0) {
-                            break;
-                        }
-                        WriteAudioStream(globals.ring_stream, abuf, (long)olen);
-                    }
-                }
-            }
-
-            switch_yield(globals.read_codec.implementation->microseconds_per_frame);
-
-        }
-        switch_clear_flag_locked((&globals), GFLAG_RING);
-    }
-
-    if (ring_file) {
-        deactivate_ring_device();
-        switch_core_file_close(&fh);
-        switch_core_codec_destroy(&tech_pvt->write_codec);
+				if (ring_file) {
+					unsigned int pos = 0;
+					switch_core_file_seek(&fh, &pos, 0, SEEK_SET);
+					for (;;) {
+						switch_size_t olen = 1024;
+						switch_core_file_read(&fh, abuf, &olen);
+						if (olen == 0) {
+							break;
+						}
+						WriteAudioStream(globals.ring_stream, abuf, (long) olen);
+					}
+				}
+			}
+
+			switch_yield(globals.read_codec.implementation->microseconds_per_frame);
+
+		}
+		switch_clear_flag_locked((&globals), GFLAG_RING);
+	}
+
+	if (ring_file) {
+		deactivate_ring_device();
+		switch_core_file_close(&fh);
+		switch_core_codec_destroy(&tech_pvt->write_codec);
 		switch_core_timer_destroy(&tech_pvt->timer);
-    }
+	}
 
 	if (switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) {
-        if (!switch_test_flag(tech_pvt, TFLAG_ANSWER)) {
-            switch_channel_hangup(channel, SWITCH_CAUSE_NO_ANSWER);
-            return SWITCH_STATUS_SUCCESS;
-        }
+		if (!switch_test_flag(tech_pvt, TFLAG_ANSWER)) {
+			switch_channel_hangup(channel, SWITCH_CAUSE_NO_ANSWER);
+			return SWITCH_STATUS_SUCCESS;
+		}
 	}
 
-    switch_set_flag_locked(tech_pvt, TFLAG_IO);
-
-    /* Move Channel's State Machine to RING */
-    switch_channel_set_state(channel, CS_RING);
-	
-    return SWITCH_STATUS_SUCCESS;
+	switch_set_flag_locked(tech_pvt, TFLAG_IO);
+
+	/* Move Channel's State Machine to RING */
+	switch_channel_set_state(channel, CS_RING);
+
+	return SWITCH_STATUS_SUCCESS;
 
 }
 
@@ -363,72 +359,72 @@
 
 
 
-static void add_pvt(private_t *tech_pvt, int master) 
+static void add_pvt(private_t * tech_pvt, int master)
 {
-    private_t *tp;
-    uint8_t in_list = 0;
+	private_t *tp;
+	uint8_t in_list = 0;
+
+	switch_mutex_lock(globals.pvt_lock);
 
-    switch_mutex_lock(globals.pvt_lock);
+	if (switch_strlen_zero(tech_pvt->call_id)) {
+		snprintf(tech_pvt->call_id, sizeof(tech_pvt->call_id), "%d", ++globals.call_id);
+		switch_core_hash_insert(globals.call_hash, tech_pvt->call_id, tech_pvt);
+		switch_core_session_set_read_codec(tech_pvt->session, &globals.read_codec);
+		switch_core_session_set_write_codec(tech_pvt->session, &globals.write_codec);
+	}
 
-    if (switch_strlen_zero(tech_pvt->call_id)) {
-        snprintf(tech_pvt->call_id, sizeof(tech_pvt->call_id), "%d", ++globals.call_id);
-        switch_core_hash_insert(globals.call_hash, tech_pvt->call_id, tech_pvt);
-        switch_core_session_set_read_codec(tech_pvt->session, &globals.read_codec);
-        switch_core_session_set_write_codec(tech_pvt->session, &globals.write_codec);
-    }
-
-    for (tp = globals.call_list; tp; tp = tp->next) {
-        if (tp == tech_pvt) {
-            in_list = 1;
-        }
-        if (master) {
-            switch_clear_flag_locked(tp, TFLAG_MASTER);
-        }
-    }
-
-
-    if (master) {
-        if (!in_list) {
-            tech_pvt->next = globals.call_list;
-            globals.call_list = tech_pvt;
-        }
-        switch_set_flag_locked(tech_pvt, TFLAG_MASTER);
-
-    } else if (!in_list) {
-        for (tp = globals.call_list; tp && tp->next; tp = tp->next);
-        if (tp) {
-            tp->next = tech_pvt;
-        } else {
-            globals.call_list = tech_pvt;
-        }
-    }
+	for (tp = globals.call_list; tp; tp = tp->next) {
+		if (tp == tech_pvt) {
+			in_list = 1;
+		}
+		if (master) {
+			switch_clear_flag_locked(tp, TFLAG_MASTER);
+		}
+	}
+
+
+	if (master) {
+		if (!in_list) {
+			tech_pvt->next = globals.call_list;
+			globals.call_list = tech_pvt;
+		}
+		switch_set_flag_locked(tech_pvt, TFLAG_MASTER);
+
+	} else if (!in_list) {
+		for (tp = globals.call_list; tp && tp->next; tp = tp->next);
+		if (tp) {
+			tp->next = tech_pvt;
+		} else {
+			globals.call_list = tech_pvt;
+		}
+	}
 
 	switch_mutex_unlock(globals.pvt_lock);
 }
 
-static void remove_pvt(private_t *tech_pvt) 
+static void remove_pvt(private_t * tech_pvt)
 {
-    private_t *tp, *last = NULL;
+	private_t *tp, *last = NULL;
 
 	switch_mutex_lock(globals.pvt_lock);
-    for (tp = globals.call_list; tp; tp = tp->next) {
-        switch_clear_flag_locked(tp, TFLAG_MASTER);
-        if (tp == tech_pvt) {
-            if (last) {
-                last->next = tp->next;
-            } else {
-                globals.call_list = tp->next;
-            }
-        }
-        last = tp;
-    }
-
-    if (globals.call_list) {
-        switch_set_flag_locked(globals.call_list, TFLAG_MASTER);
-    } else {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "No more channels, deactivating audio\n");
-        deactivate_audio_device();
-    }
+	for (tp = globals.call_list; tp; tp = tp->next) {
+		switch_clear_flag_locked(tp, TFLAG_MASTER);
+		if (tp == tech_pvt) {
+			if (last) {
+				last->next = tp->next;
+			} else {
+				globals.call_list = tp->next;
+			}
+		}
+		last = tp;
+	}
+
+	if (globals.call_list) {
+		switch_set_flag_locked(globals.call_list, TFLAG_MASTER);
+	} else {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "No more channels, deactivating audio\n");
+		deactivate_audio_device();
+	}
 
 	switch_mutex_unlock(globals.pvt_lock);
 }
@@ -444,17 +440,17 @@
 	tech_pvt = switch_core_session_get_private(session);
 	assert(tech_pvt != NULL);
 
-    remove_pvt(tech_pvt);
+	remove_pvt(tech_pvt);
 
 	switch_clear_flag_locked(tech_pvt, TFLAG_IO);
 	switch_set_flag_locked(tech_pvt, TFLAG_HUP);
 
 	switch_core_hash_delete(globals.call_hash, tech_pvt->call_id);
 
-    if (tech_pvt->hfh) {
-        tech_pvt->hfh = NULL;
-        switch_core_file_close(&tech_pvt->fh);
-    }
+	if (tech_pvt->hfh) {
+		tech_pvt->hfh = NULL;
+		switch_core_file_close(&tech_pvt->fh);
+	}
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL HANGUP\n", switch_channel_get_name(channel));
 
@@ -472,14 +468,14 @@
 	tech_pvt = switch_core_session_get_private(session);
 	assert(tech_pvt != NULL);
 
-    switch (sig) {
-    case SWITCH_SIG_KILL:
-        switch_set_flag_locked(tech_pvt, TFLAG_HUP);
-        switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
-        break;
-    default:
-        break;
-    }
+	switch (sig) {
+	case SWITCH_SIG_KILL:
+		switch_set_flag_locked(tech_pvt, TFLAG_HUP);
+		switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
+		break;
+	default:
+		break;
+	}
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL KILL\n", switch_channel_get_name(channel));
 
 
@@ -542,8 +538,7 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout,
-                                          switch_io_flag_t flags, int stream_id)
+static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, switch_io_flag_t flags, int stream_id)
 {
 	switch_channel_t *channel = NULL;
 	private_t *tech_pvt = NULL;
@@ -557,94 +552,93 @@
 	assert(tech_pvt != NULL);
 
 	if (!globals.audio_stream) {
-        return SWITCH_STATUS_FALSE;
-    }
+		return SWITCH_STATUS_FALSE;
+	}
+
+	if (switch_test_flag(tech_pvt, TFLAG_HUP)) {
+		return SWITCH_STATUS_FALSE;
+	}
 
-    if (switch_test_flag(tech_pvt, TFLAG_HUP)) {
-        return SWITCH_STATUS_FALSE;
-    }
-    
-    if (!switch_test_flag(tech_pvt, TFLAG_IO)) {
-        goto cng;
-    }
-
-    if (!is_master(tech_pvt)) {
-        if (tech_pvt->hold_file) {
-            if (!tech_pvt->hfh) {
-                int codec_ms = tech_pvt->codec_ms ? tech_pvt->codec_ms : globals.codec_ms;
-                int sample_rate = tech_pvt->sample_rate ? tech_pvt->sample_rate : globals.sample_rate;
-
-                if (switch_core_codec_init(&tech_pvt->write_codec,
-                                           "L16",
-                                           NULL,
-                                           sample_rate,
-                                           codec_ms,
-                                           1,
-                                           SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
-                                           NULL,
-                                           switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
-                    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n");
-                    switch_core_codec_destroy(&globals.read_codec);
-                    tech_pvt->hold_file = NULL;
-                    goto cng;
-                }
+	if (!switch_test_flag(tech_pvt, TFLAG_IO)) {
+		goto cng;
+	}
+
+	if (!is_master(tech_pvt)) {
+		if (tech_pvt->hold_file) {
+			if (!tech_pvt->hfh) {
+				int codec_ms = tech_pvt->codec_ms ? tech_pvt->codec_ms : globals.codec_ms;
+				int sample_rate = tech_pvt->sample_rate ? tech_pvt->sample_rate : globals.sample_rate;
+
+				if (switch_core_codec_init(&tech_pvt->write_codec,
+										   "L16",
+										   NULL,
+										   sample_rate,
+										   codec_ms,
+										   1,
+										   SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
+										   NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n");
+					switch_core_codec_destroy(&globals.read_codec);
+					tech_pvt->hold_file = NULL;
+					goto cng;
+				}
 
-                if (switch_core_file_open(&tech_pvt->fh,
-                                          tech_pvt->hold_file,
+				if (switch_core_file_open(&tech_pvt->fh,
+										  tech_pvt->hold_file,
 										  globals.read_codec.implementation->number_of_channels,
-                                          globals.read_codec.implementation->samples_per_second,
-                                          SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT,
-                                          switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
-                    switch_core_codec_destroy(&tech_pvt->write_codec);
-                    tech_pvt->hold_file = NULL;
-                    goto cng;
-                }
-
-                tech_pvt->hfh = &tech_pvt->fh;
-                tech_pvt->hold_frame.data = tech_pvt->holdbuf;
-                tech_pvt->hold_frame.buflen = sizeof(tech_pvt->holdbuf);
-                tech_pvt->hold_frame.rate = sample_rate;
-                tech_pvt->hold_frame.codec = &tech_pvt->write_codec;
-            }
-            
-            goto hold;
-        }
-    cng:
-        switch_yield(globals.read_codec.implementation->microseconds_per_frame);
-        *frame = &globals.cng_frame;
+										  globals.read_codec.implementation->samples_per_second,
+										  SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT,
+										  switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
+					switch_core_codec_destroy(&tech_pvt->write_codec);
+					tech_pvt->hold_file = NULL;
+					goto cng;
+				}
+
+				tech_pvt->hfh = &tech_pvt->fh;
+				tech_pvt->hold_frame.data = tech_pvt->holdbuf;
+				tech_pvt->hold_frame.buflen = sizeof(tech_pvt->holdbuf);
+				tech_pvt->hold_frame.rate = sample_rate;
+				tech_pvt->hold_frame.codec = &tech_pvt->write_codec;
+			}
+
+			goto hold;
+		}
+	  cng:
+		switch_yield(globals.read_codec.implementation->microseconds_per_frame);
+		*frame = &globals.cng_frame;
 		return SWITCH_STATUS_SUCCESS;
 
-    hold:
+	  hold:
 
-        {
-            switch_size_t olen = globals.read_codec.implementation->samples_per_frame;
+		{
+			switch_size_t olen = globals.read_codec.implementation->samples_per_frame;
 			if (switch_core_timer_next(&tech_pvt->timer) != SWITCH_STATUS_SUCCESS) {
-                switch_core_file_close(&tech_pvt->fh);
-                switch_core_codec_destroy(&tech_pvt->write_codec);
-                goto cng;
+				switch_core_file_close(&tech_pvt->fh);
+				switch_core_codec_destroy(&tech_pvt->write_codec);
+				goto cng;
+			}
+			switch_core_file_read(tech_pvt->hfh, tech_pvt->hold_frame.data, &olen);
+
+			if (olen == 0) {
+				unsigned int pos = 0;
+				switch_core_file_seek(tech_pvt->hfh, &pos, 0, SEEK_SET);
+				goto cng;
 			}
-            switch_core_file_read(tech_pvt->hfh, tech_pvt->hold_frame.data, &olen);
-            
-            if (olen == 0) {
-                unsigned int pos = 0;
-                switch_core_file_seek(tech_pvt->hfh, &pos, 0, SEEK_SET);				 
-                goto cng;
-            }
-            
-            
-            tech_pvt->hold_frame.datalen = (uint32_t)(olen * sizeof(int16_t));
-            tech_pvt->hold_frame.samples = (uint32_t)olen;
+
+
+			tech_pvt->hold_frame.datalen = (uint32_t) (olen * sizeof(int16_t));
+			tech_pvt->hold_frame.samples = (uint32_t) olen;
 			tech_pvt->hold_frame.timestamp = tech_pvt->timer.samplecount;
-            *frame = &tech_pvt->hold_frame;
-            
-        }
+			*frame = &tech_pvt->hold_frame;
 
-		return SWITCH_STATUS_SUCCESS;        
-    }
+		}
+
+		return SWITCH_STATUS_SUCCESS;
+	}
 
 	switch_mutex_lock(globals.device_lock);
 
-    if ((samples = ReadAudioStream(globals.audio_stream, globals.read_frame.data, globals.read_codec.implementation->samples_per_frame)) != 0) {
+	if ((samples = ReadAudioStream(globals.audio_stream, globals.read_frame.data, globals.read_codec.implementation->samples_per_frame)) != 0) {
 		globals.read_frame.datalen = samples * 2;
 		globals.read_frame.samples = samples;
 
@@ -652,9 +646,9 @@
 		globals.read_frame.timestamp = globals.timer.samplecount;
 		*frame = &globals.read_frame;
 
-        if (!switch_test_flag((&globals), GFLAG_MOUTH)) {
-            memset(globals.read_frame.data, 255, globals.read_frame.datalen);
-        }
+		if (!switch_test_flag((&globals), GFLAG_MOUTH)) {
+			memset(globals.read_frame.data, 255, globals.read_frame.datalen);
+		}
 
 		status = SWITCH_STATUS_SUCCESS;
 	}
@@ -663,8 +657,7 @@
 	return status;
 }
 
-static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout,
-                                           switch_io_flag_t flags, int stream_id)
+static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flags, int stream_id)
 {
 	switch_channel_t *channel = NULL;
 	private_t *tech_pvt = NULL;
@@ -676,21 +669,21 @@
 	assert(tech_pvt != NULL);
 
 	if (!globals.audio_stream) {
-        return SWITCH_STATUS_FALSE;
-    }
+		return SWITCH_STATUS_FALSE;
+	}
 
-    if (switch_test_flag(tech_pvt, TFLAG_HUP)) {
-        return SWITCH_STATUS_FALSE;
-    }
-
-    if (!is_master(tech_pvt) || !switch_test_flag(tech_pvt, TFLAG_IO)) {
-		return SWITCH_STATUS_SUCCESS;        
-    }
+	if (switch_test_flag(tech_pvt, TFLAG_HUP)) {
+		return SWITCH_STATUS_FALSE;
+	}
+
+	if (!is_master(tech_pvt) || !switch_test_flag(tech_pvt, TFLAG_IO)) {
+		return SWITCH_STATUS_SUCCESS;
+	}
 
 	if (globals.audio_stream) {
-        if (switch_test_flag((&globals), GFLAG_EAR)) {
-            WriteAudioStream(globals.audio_stream, (short *) frame->data, (int) (frame->datalen / sizeof(SAMPLE)));
-        }
+		if (switch_test_flag((&globals), GFLAG_EAR)) {
+			WriteAudioStream(globals.audio_stream, (short *) frame->data, (int) (frame->datalen / sizeof(SAMPLE)));
+		}
 		status = SWITCH_STATUS_SUCCESS;
 	}
 
@@ -716,16 +709,16 @@
 {
 	switch_channel_t *channel;
 	private_t *tech_pvt;
-			
+
 	channel = switch_core_session_get_channel(session);
 	assert(channel != NULL);
-			
+
 	tech_pvt = switch_core_session_get_private(session);
 	assert(tech_pvt != NULL);
 
 
 	switch (msg->message_id) {
-	case SWITCH_MESSAGE_INDICATE_PROGRESS: 
+	case SWITCH_MESSAGE_INDICATE_PROGRESS:
 		{
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Engage Early Media\n");
 			switch_set_flag_locked(tech_pvt, TFLAG_IO);
@@ -737,43 +730,43 @@
 }
 
 static switch_api_interface_t send_dtmf_interface = {
-    /*.interface_name */ "padtmf",
-    /*.desc */ "DEPRICATED (see 'pa')",
-    /*.function */ padep,
-    /*.syntax */ "DEPRICATED (see 'pa')",
-    /*.next */ NULL
+	/*.interface_name */ "padtmf",
+	/*.desc */ "DEPRICATED (see 'pa')",
+	/*.function */ padep,
+	/*.syntax */ "DEPRICATED (see 'pa')",
+	/*.next */ NULL
 };
 
 static switch_api_interface_t answer_call_interface = {
-    /*.interface_name */ "paoffhook",
-    /*.desc */ "DEPRICATED (see 'pa')",
-    /*.function */ padep,
-    /*.syntax */ "DEPRICATED (see 'pa')",
-    /*.next */ &send_dtmf_interface
+	/*.interface_name */ "paoffhook",
+	/*.desc */ "DEPRICATED (see 'pa')",
+	/*.function */ padep,
+	/*.syntax */ "DEPRICATED (see 'pa')",
+	/*.next */ &send_dtmf_interface
 };
 
 static switch_api_interface_t channel_info_interface = {
-    /*.interface_name */ "painfo",
-    /*.desc */ "DEPRICATED (see 'pa')",
-    /*.function */ padep,
-    /*.syntax */ "DEPRICATED (see 'pa')",
-    /*.next */ &answer_call_interface
+	/*.interface_name */ "painfo",
+	/*.desc */ "DEPRICATED (see 'pa')",
+	/*.function */ padep,
+	/*.syntax */ "DEPRICATED (see 'pa')",
+	/*.next */ &answer_call_interface
 };
 
 static switch_api_interface_t channel_hup_interface = {
-    /*.interface_name */ "pahup",
-    /*.desc */ "DEPRICATED (see 'pa')",
-    /*.function */ padep,
-    /*.syntax */ "DEPRICATED (see 'pa')",
-    /*.next */ &channel_info_interface
+	/*.interface_name */ "pahup",
+	/*.desc */ "DEPRICATED (see 'pa')",
+	/*.function */ padep,
+	/*.syntax */ "DEPRICATED (see 'pa')",
+	/*.next */ &channel_info_interface
 };
 
 static switch_api_interface_t channel_call_interface = {
-    /*.interface_name */ "pacall",
-    /*.desc */ "DEPRICATED (see 'pa')",
-    /*.function */ padep,
-    /*.syntax */ "DEPRICATED (see 'pa')",
-    /*.next */ &channel_hup_interface
+	/*.interface_name */ "pacall",
+	/*.desc */ "DEPRICATED (see 'pa')",
+	/*.function */ padep,
+	/*.syntax */ "DEPRICATED (see 'pa')",
+	/*.next */ &channel_hup_interface
 };
 
 static switch_api_interface_t channel_api_interface = {
@@ -802,7 +795,7 @@
 	/*.waitfor_read */ channel_waitfor_read,
 	/*.waitfor_write */ channel_waitfor_write,
 	/*.send_dtmf */ channel_send_dtmf,
-	/*.receive_message*/ channel_receive_message
+	/*.receive_message */ channel_receive_message
 };
 
 static const switch_endpoint_interface_t channel_endpoint_interface = {
@@ -826,7 +819,8 @@
 /* Make sure when you have 2 sessions in the same scope that you pass the appropriate one to the routines
    that allocate memory or you will have 1 channel with memory allocated from another channel's pool!
 */
-static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile,
+static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session,
+													switch_caller_profile_t *outbound_profile,
 													switch_core_session_t **new_session, switch_memory_pool_t **pool)
 {
 
@@ -837,12 +831,12 @@
 
 		switch_core_session_add_stream(*new_session, NULL);
 		if ((tech_pvt = (private_t *) switch_core_session_alloc(*new_session, sizeof(private_t))) != 0) {
-			memset(tech_pvt, 0, sizeof(*tech_pvt));            
+			memset(tech_pvt, 0, sizeof(*tech_pvt));
 			switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(*new_session));
 			channel = switch_core_session_get_channel(*new_session);
 			switch_core_session_set_private(*new_session, tech_pvt);
 			tech_pvt->session = *new_session;
-            globals.flags = GFLAG_EAR | GFLAG_MOUTH;
+			globals.flags = GFLAG_EAR | GFLAG_MOUTH;
 		} else {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n");
 			switch_core_session_destroy(new_session);
@@ -851,9 +845,9 @@
 
 		if (outbound_profile) {
 			char name[128];
-            char *id = !switch_strlen_zero(outbound_profile->caller_id_number) ? outbound_profile->caller_id_number : "na";
+			char *id = !switch_strlen_zero(outbound_profile->caller_id_number) ? outbound_profile->caller_id_number : "na";
 			snprintf(name, sizeof(name), "PortAudio/%s", id);
-					 
+
 			switch_channel_set_name(channel, name);
 
 			caller_profile = switch_caller_profile_clone(*new_session, outbound_profile);
@@ -879,7 +873,7 @@
 SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
 {
 
-    switch_status_t status;
+	switch_status_t status;
 
 	if (switch_core_new_memory_pool(&module_pool) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "OH OH no pool\n");
@@ -889,17 +883,18 @@
 	Pa_Initialize();
 
 	if (dump_info()) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't find any audio devices!\n");
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't find any audio devices!\n");
 		return SWITCH_STATUS_TERM;
-    }
+	}
 
 	if ((status = load_config()) != SWITCH_STATUS_SUCCESS) {
-        return status;
-    }
+		return status;
+	}
 
 
-    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Input Device: %d, Output Device: %d, Ring Device: %d Sample Rate: %d MS: %d\n", 
-                      globals.indev, globals.outdev, globals.ringdev, globals.sample_rate, globals.codec_ms);
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
+					  "Input Device: %d, Output Device: %d, Ring Device: %d Sample Rate: %d MS: %d\n", globals.indev,
+					  globals.outdev, globals.ringdev, globals.sample_rate, globals.codec_ms);
 
 
 	switch_core_hash_init(&globals.call_hash, module_pool);
@@ -919,7 +914,7 @@
 	globals.cng_frame.data = globals.cngbuf;
 	globals.cng_frame.buflen = sizeof(globals.cngbuf);
 	globals.cng_frame.datalen = sizeof(globals.cngbuf);
-    switch_set_flag((&globals.cng_frame), SFF_CNG);
+	switch_set_flag((&globals.cng_frame), SFF_CNG);
 
 	/* connect my internal structure to the blank pointer passed to me */
 	*module_interface = &channel_module_interface;
@@ -933,7 +928,7 @@
 {
 	char *cf = "portaudio.conf";
 	switch_xml_t cfg, xml, settings, param;
-    switch_status_t status = SWITCH_STATUS_SUCCESS;
+	switch_status_t status = SWITCH_STATUS_SUCCESS;
 
 	if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
@@ -941,7 +936,7 @@
 	}
 
 	memset(&globals, 0, sizeof(globals));
-    globals.indev = globals.outdev = globals.ringdev = -1;
+	globals.indev = globals.outdev = globals.ringdev = -1;
 
 	if ((settings = switch_xml_child(cfg, "settings"))) {
 		for (param = switch_xml_child(settings, "param"); param; param = param->next) {
@@ -951,7 +946,7 @@
 			if (!strcmp(var, "debug")) {
 				globals.debug = atoi(val);
 			} else if (!strcmp(var, "ring-interval")) {
-                globals.ring_interval = atoi(val);
+				globals.ring_interval = atoi(val);
 			} else if (!strcmp(var, "ring-file")) {
 				set_global_ring_file(val);
 			} else if (!strcmp(var, "hold-file")) {
@@ -986,7 +981,7 @@
 				} else {
 					globals.ringdev = get_dev_by_name(val, 0);
 				}
-            }
+			}
 		}
 	}
 
@@ -1005,37 +1000,37 @@
 	if (!globals.ring_interval) {
 		globals.ring_interval = 5;
 	}
-    
-    if (!globals.timer_name) {
-        set_global_timer_name("soft");
-    }
-
-    if (globals.indev < 0) {
-        globals.indev = get_dev_by_name(NULL, 1);
-        if (globals.indev > -1) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Switching to default input device!\n");
-        } else {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find an input device!\n");
-            status = SWITCH_STATUS_GENERR;            
-        }
-    }
-
-    if (globals.outdev < 0) {
-        globals.outdev = get_dev_by_name(NULL, 0);
-        if (globals.outdev > -1) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Switching to default output device!\n");
-        } else {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find an input device!\n");
-            status = SWITCH_STATUS_GENERR;            
-        }
-    }
-
-    if (globals.ringdev < 0) {
-        if (globals.outdev > -1) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid ring device configured using output device!\n");
-            globals.ringdev = globals.outdev;
-        } 
-    }
+
+	if (!globals.timer_name) {
+		set_global_timer_name("soft");
+	}
+
+	if (globals.indev < 0) {
+		globals.indev = get_dev_by_name(NULL, 1);
+		if (globals.indev > -1) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Switching to default input device!\n");
+		} else {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find an input device!\n");
+			status = SWITCH_STATUS_GENERR;
+		}
+	}
+
+	if (globals.outdev < 0) {
+		globals.outdev = get_dev_by_name(NULL, 0);
+		if (globals.outdev > -1) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Switching to default output device!\n");
+		} else {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find an input device!\n");
+			status = SWITCH_STATUS_GENERR;
+		}
+	}
+
+	if (globals.ringdev < 0) {
+		if (globals.outdev > -1) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid ring device configured using output device!\n");
+			globals.ringdev = globals.outdev;
+		}
+	}
 
 	switch_xml_free(xml);
 
@@ -1060,18 +1055,18 @@
 
 static int get_dev_by_number(int number, int in)
 {
-    int numDevices = Pa_GetDeviceCount();
+	int numDevices = Pa_GetDeviceCount();
 	const PaDeviceInfo *pdi;
 
-    if (number > -1 && number < numDevices && (pdi = Pa_GetDeviceInfo(number))) {
-        if (in && pdi->maxInputChannels) {
-            return number;
-        } else if (!in && pdi->maxOutputChannels) {
-            return number;
-        }
-    }
-    
-    return -1;
+	if (number > -1 && number < numDevices && (pdi = Pa_GetDeviceInfo(number))) {
+		if (in && pdi->maxInputChannels) {
+			return number;
+		} else if (!in && pdi->maxOutputChannels) {
+			return number;
+		}
+	}
+
+	return -1;
 }
 
 static int get_dev_by_name(char *name, int in)
@@ -1087,15 +1082,15 @@
 	}
 
 	for (i = 0; i < numDevices; i++) {
-        int match = 0;
+		int match = 0;
 		pdi = Pa_GetDeviceInfo(i);
-        
+
 		if (switch_strlen_zero(name)) {
-            match = 1;
-        } else if (strstr(pdi->name, name)) {
-            match = 1;
-        }
-        
+			match = 1;
+		} else if (strstr(pdi->name, name)) {
+			match = 1;
+		}
+
 		if (match) {
 			if (in && pdi->maxInputChannels) {
 				return i;
@@ -1105,263 +1100,252 @@
 		}
 	}
 
-    if (switch_strlen_zero(name)) {
-        return -1;
-    }
+	if (switch_strlen_zero(name)) {
+		return -1;
+	}
 
 	return get_dev_by_name(NULL, in);
 }
 
 
 /*******************************************************************/
-static void PrintSupportedStandardSampleRates(const PaStreamParameters *inputParameters,
-                                              const PaStreamParameters *outputParameters)
+static void PrintSupportedStandardSampleRates(const PaStreamParameters * inputParameters, const PaStreamParameters * outputParameters)
 {
-    int i, printCount, cr = 7;
-    PaError err;
-    static double standardSampleRates[] = { 8000.0, 9600.0, 11025.0, 12000.0, 16000.0, 22050.0, 24000.0, 32000.0,
-                                            44100.0, 48000.0, 88200.0, 96000.0, 192000.0, -1};
-
-    printCount = cr;
-    for(i=0; standardSampleRates[i] > 0; i++) {
-        err = Pa_IsFormatSupported(inputParameters, outputParameters, standardSampleRates[i]);
-        if (err == paFormatIsSupported) {
-            if (printCount == cr) {
-                printCount = 0;
-                switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO,  "\n\t%0.2f", standardSampleRates[i]);
-            } else {
-                switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO,  ", %0.2f", standardSampleRates[i]);
-            }
-            printCount++;
-        }
-    }
-    if (!printCount) {
-        switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO,  " None\n");
-    } else {
-        switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO,  "\n");
-    }
+	int i, printCount, cr = 7;
+	PaError err;
+	static double standardSampleRates[] = { 8000.0, 9600.0, 11025.0, 12000.0, 16000.0, 22050.0, 24000.0, 32000.0,
+		44100.0, 48000.0, 88200.0, 96000.0, 192000.0, -1
+	};
+
+	printCount = cr;
+	for (i = 0; standardSampleRates[i] > 0; i++) {
+		err = Pa_IsFormatSupported(inputParameters, outputParameters, standardSampleRates[i]);
+		if (err == paFormatIsSupported) {
+			if (printCount == cr) {
+				printCount = 0;
+				switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "\n\t%0.2f", standardSampleRates[i]);
+			} else {
+				switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, ", %0.2f", standardSampleRates[i]);
+			}
+			printCount++;
+		}
+	}
+	if (!printCount) {
+		switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, " None\n");
+	} else {
+		switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "\n");
+	}
 }
+
 /*******************************************************************/
 
 static switch_status_t devlist(char **argv, int argc, switch_stream_handle_t *stream)
 {
-	int     i, numDevices;
-    const   PaDeviceInfo *deviceInfo;
-            
-    numDevices = Pa_GetDeviceCount();
-    if (numDevices < 0) {
+	int i, numDevices;
+	const PaDeviceInfo *deviceInfo;
+
+	numDevices = Pa_GetDeviceCount();
+	if (numDevices < 0) {
 		return SWITCH_STATUS_SUCCESS;
-    }
-	for(i=0; i<numDevices; i++) {
-        deviceInfo = Pa_GetDeviceInfo(i);
-        stream->write_function(stream, "%d;%s;%d;%d\n", i, deviceInfo->name, deviceInfo->maxInputChannels, deviceInfo->maxOutputChannels);
+	}
+	for (i = 0; i < numDevices; i++) {
+		deviceInfo = Pa_GetDeviceInfo(i);
+		stream->write_function(stream, "%d;%s;%d;%d\n", i, deviceInfo->name, deviceInfo->maxInputChannels, deviceInfo->maxOutputChannels);
 	}
 
-    return SWITCH_STATUS_SUCCESS;
+	return SWITCH_STATUS_SUCCESS;
 }
 
 static int dump_info(void)
 {
-    int     i, numDevices, defaultDisplayed;
-    const   PaDeviceInfo *deviceInfo;
-    PaStreamParameters inputParameters, outputParameters;
-    PaError err;
-    const char *line = "--------------------------------------------------------------------------------\n";
-    
+	int i, numDevices, defaultDisplayed;
+	const PaDeviceInfo *deviceInfo;
+	PaStreamParameters inputParameters, outputParameters;
+	PaError err;
+	const char *line = "--------------------------------------------------------------------------------\n";
 
 
-    switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO,  "PortAudio version number = %d\nPortAudio version text = '%s'\n",
-                      Pa_GetVersion(), Pa_GetVersionText());
+
+	switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO,
+					  "PortAudio version number = %d\nPortAudio version text = '%s'\n", Pa_GetVersion(), Pa_GetVersionText());
 	if (globals.audio_stream) {
-		switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO,  "ERROR: Cannot use this command this while a call is in progress\n");
+		switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "ERROR: Cannot use this command this while a call is in progress\n");
 		return 0;
 	}
-            
-    numDevices = Pa_GetDeviceCount();
-    if (numDevices < 0) {
-        switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO,  "ERROR: Pa_CountDevices returned 0x%x\n", numDevices);
-        err = numDevices;
-        goto error;
-    }
-    
-    switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO,  "Number of devices = %d\n", numDevices);
-    for(i=0; i<numDevices; i++) {
-        switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "%s", line);
-        deviceInfo = Pa_GetDeviceInfo(i);
-        switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO,  "Device #%d ", i);
-                
-        /* Mark global and API specific default devices */
-        defaultDisplayed = 0;
-        if (i == Pa_GetDefaultInputDevice()) {
-            switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO,  "**Default Input");
-            defaultDisplayed = 1;
-            
-        } else if (i == Pa_GetHostApiInfo(deviceInfo->hostApi)->defaultInputDevice) {
-            
-            const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo(deviceInfo->hostApi);
-            switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO,  "**Default %s Input", hostInfo->name);
-            defaultDisplayed = 1;
-        }
-        
-        if (i == Pa_GetDefaultOutputDevice()) {
-            switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO,  "**Default Output");
-            defaultDisplayed = 1;
-
-        } else if (i == Pa_GetHostApiInfo(deviceInfo->hostApi)->defaultOutputDevice) {
-
-            const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo(deviceInfo->hostApi);
-            switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO,  "**Default %s Output", hostInfo->name);
-            defaultDisplayed = 1;
-        }
-
-        if (defaultDisplayed) {
-            switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO,  "** | ");
-        }
-        /* print device info fields */
-        switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO,  "Name: %s\n", deviceInfo->name);
-        switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO,  "Host: %s | ",  Pa_GetHostApiInfo(deviceInfo->hostApi)->name);
-        switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO,  "inputs: %d | ", deviceInfo->maxInputChannels );
-        switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO,  "outputs: %d | ", deviceInfo->maxOutputChannels );
-
-        switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO,  "Default rate: %8.2f\n", deviceInfo->defaultSampleRate);
-
-        /* poll for standard sample rates */
-        inputParameters.device = i;
-        inputParameters.channelCount = deviceInfo->maxInputChannels;
-        inputParameters.sampleFormat = paInt16;
-        inputParameters.suggestedLatency = 0; /* ignored by Pa_IsFormatSupported() */
-        inputParameters.hostApiSpecificStreamInfo = NULL;
-        
-        outputParameters.device = i;
-        outputParameters.channelCount = deviceInfo->maxOutputChannels;
-        outputParameters.sampleFormat = paInt16;
-        outputParameters.suggestedLatency = 0; /* ignored by Pa_IsFormatSupported() */
-        outputParameters.hostApiSpecificStreamInfo = NULL;
-
-        if (inputParameters.channelCount > 0) {
-
-            switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "half-duplex 16 bit %d channel input rates:",
-                              inputParameters.channelCount);
-            PrintSupportedStandardSampleRates(&inputParameters, NULL);
-        }
-
-        if (outputParameters.channelCount > 0) {
-            switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "half-duplex 16 bit %d channel output rates:",
-                              outputParameters.channelCount);
-            PrintSupportedStandardSampleRates(NULL, &outputParameters);
-        }
-
-        if (inputParameters.channelCount > 0 && outputParameters.channelCount > 0) {
-
-            switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "full-duplex 16 bit %d channel input, %d channel output rates:",
-                              inputParameters.channelCount, outputParameters.channelCount);
-            PrintSupportedStandardSampleRates(&inputParameters, &outputParameters);
-        }
-    }
-
-    switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "%s", line);
-    
-    return 0;
-
- error:
-    switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR,  "An error occured while using the portaudio stream\n");
-    switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR,  "Error number: %d\n", err);
-    switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR,  "Error message: %s\n", Pa_GetErrorText(err));
-    return err;
+
+	numDevices = Pa_GetDeviceCount();
+	if (numDevices < 0) {
+		switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "ERROR: Pa_CountDevices returned 0x%x\n", numDevices);
+		err = numDevices;
+		goto error;
+	}
+
+	switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "Number of devices = %d\n", numDevices);
+	for (i = 0; i < numDevices; i++) {
+		switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "%s", line);
+		deviceInfo = Pa_GetDeviceInfo(i);
+		switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "Device #%d ", i);
+
+		/* Mark global and API specific default devices */
+		defaultDisplayed = 0;
+		if (i == Pa_GetDefaultInputDevice()) {
+			switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "**Default Input");
+			defaultDisplayed = 1;
+
+		} else if (i == Pa_GetHostApiInfo(deviceInfo->hostApi)->defaultInputDevice) {
+
+			const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo(deviceInfo->hostApi);
+			switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "**Default %s Input", hostInfo->name);
+			defaultDisplayed = 1;
+		}
+
+		if (i == Pa_GetDefaultOutputDevice()) {
+			switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "**Default Output");
+			defaultDisplayed = 1;
+
+		} else if (i == Pa_GetHostApiInfo(deviceInfo->hostApi)->defaultOutputDevice) {
+
+			const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo(deviceInfo->hostApi);
+			switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "**Default %s Output", hostInfo->name);
+			defaultDisplayed = 1;
+		}
+
+		if (defaultDisplayed) {
+			switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "** | ");
+		}
+		/* print device info fields */
+		switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "Name: %s\n", deviceInfo->name);
+		switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "Host: %s | ", Pa_GetHostApiInfo(deviceInfo->hostApi)->name);
+		switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "inputs: %d | ", deviceInfo->maxInputChannels);
+		switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "outputs: %d | ", deviceInfo->maxOutputChannels);
+
+		switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "Default rate: %8.2f\n", deviceInfo->defaultSampleRate);
+
+		/* poll for standard sample rates */
+		inputParameters.device = i;
+		inputParameters.channelCount = deviceInfo->maxInputChannels;
+		inputParameters.sampleFormat = paInt16;
+		inputParameters.suggestedLatency = 0;	/* ignored by Pa_IsFormatSupported() */
+		inputParameters.hostApiSpecificStreamInfo = NULL;
+
+		outputParameters.device = i;
+		outputParameters.channelCount = deviceInfo->maxOutputChannels;
+		outputParameters.sampleFormat = paInt16;
+		outputParameters.suggestedLatency = 0;	/* ignored by Pa_IsFormatSupported() */
+		outputParameters.hostApiSpecificStreamInfo = NULL;
+
+		if (inputParameters.channelCount > 0) {
+
+			switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "half-duplex 16 bit %d channel input rates:", inputParameters.channelCount);
+			PrintSupportedStandardSampleRates(&inputParameters, NULL);
+		}
+
+		if (outputParameters.channelCount > 0) {
+			switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "half-duplex 16 bit %d channel output rates:", outputParameters.channelCount);
+			PrintSupportedStandardSampleRates(NULL, &outputParameters);
+		}
+
+		if (inputParameters.channelCount > 0 && outputParameters.channelCount > 0) {
+
+			switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO,
+							  "full-duplex 16 bit %d channel input, %d channel output rates:", inputParameters.channelCount,
+							  outputParameters.channelCount);
+			PrintSupportedStandardSampleRates(&inputParameters, &outputParameters);
+		}
+	}
+
+	switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "%s", line);
+
+	return 0;
+
+  error:
+	switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, "An error occured while using the portaudio stream\n");
+	switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, "Error number: %d\n", err);
+	switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, "Error message: %s\n", Pa_GetErrorText(err));
+	return err;
 }
 
 
 
 static switch_status_t engage_device(int sample_rate, int codec_ms)
 {
-    PaStreamParameters inputParameters, outputParameters;
+	PaStreamParameters inputParameters, outputParameters;
 	PaError err;
 
-    if (!globals.audio_stream) {
-        if (!sample_rate) {
-            sample_rate = globals.sample_rate;
-        }
-        if (!codec_ms) {
-            codec_ms = globals.codec_ms;
-        }
-
-        if (switch_core_codec_init(&globals.read_codec,
-                                   "L16",
-                                   NULL,
-                                   sample_rate,
-                                   codec_ms,
-                                   1,
-                                   SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
-                                   NULL, 
-                                   NULL) != SWITCH_STATUS_SUCCESS) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n");
-            return SWITCH_STATUS_FALSE;
-        } else {
-            if (switch_core_codec_init(&globals.write_codec,
-                                       "L16",
-                                       NULL,
-                                       sample_rate,
-                                       codec_ms,
-                                       1,
-                                       SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
-                                       NULL,
-                                       NULL) != SWITCH_STATUS_SUCCESS) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n");
-                switch_core_codec_destroy(&globals.read_codec);
-                return SWITCH_STATUS_FALSE;
-            }
-        }
-		
+	if (!globals.audio_stream) {
+		if (!sample_rate) {
+			sample_rate = globals.sample_rate;
+		}
+		if (!codec_ms) {
+			codec_ms = globals.codec_ms;
+		}
+
+		if (switch_core_codec_init(&globals.read_codec,
+								   "L16",
+								   NULL, sample_rate, codec_ms, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
+								   NULL) != SWITCH_STATUS_SUCCESS) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n");
+			return SWITCH_STATUS_FALSE;
+		} else {
+			if (switch_core_codec_init(&globals.write_codec,
+									   "L16",
+									   NULL,
+									   sample_rate, codec_ms, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
+									   NULL) != SWITCH_STATUS_SUCCESS) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n");
+				switch_core_codec_destroy(&globals.read_codec);
+				return SWITCH_STATUS_FALSE;
+			}
+		}
+
 		if (switch_core_timer_init(&globals.timer,
-								   globals.timer_name,
-								   codec_ms,
-								   globals.read_codec.implementation->samples_per_frame,
+								   globals.timer_name, codec_ms, globals.read_codec.implementation->samples_per_frame,
 								   module_pool) != SWITCH_STATUS_SUCCESS) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "setup timer failed!\n");
 			switch_core_codec_destroy(&globals.read_codec);
 			switch_core_codec_destroy(&globals.write_codec);
 			return SWITCH_STATUS_FALSE;
 		}
-                
 
 
 
 
-        globals.read_frame.rate = sample_rate;
-        globals.read_frame.codec = &globals.read_codec;
 
+		globals.read_frame.rate = sample_rate;
+		globals.read_frame.codec = &globals.read_codec;
 
 
-        switch_mutex_lock(globals.device_lock);
-        /* LOCKED ***************************************************************************************************/
-        inputParameters.device = globals.indev;
-        inputParameters.channelCount = 1;
-        inputParameters.sampleFormat = SAMPLE_TYPE;
-        inputParameters.suggestedLatency = Pa_GetDeviceInfo(inputParameters.device)->defaultLowInputLatency;
-        inputParameters.hostApiSpecificStreamInfo = NULL;
 
-        outputParameters.device = globals.outdev;
-        outputParameters.channelCount = 1;
-        outputParameters.sampleFormat =  SAMPLE_TYPE;
-        outputParameters.suggestedLatency = Pa_GetDeviceInfo(outputParameters.device)->defaultLowOutputLatency;
-        outputParameters.hostApiSpecificStreamInfo = NULL;
-        err = OpenAudioStream(&globals.audio_stream, &inputParameters, &outputParameters, sample_rate, paClipOff);
-        /* UNLOCKED **************************************************************************************************/
-        switch_mutex_unlock(globals.device_lock);
+		switch_mutex_lock(globals.device_lock);
+		/* LOCKED ************************************************************************************************** */
+		inputParameters.device = globals.indev;
+		inputParameters.channelCount = 1;
+		inputParameters.sampleFormat = SAMPLE_TYPE;
+		inputParameters.suggestedLatency = Pa_GetDeviceInfo(inputParameters.device)->defaultLowInputLatency;
+		inputParameters.hostApiSpecificStreamInfo = NULL;
+
+		outputParameters.device = globals.outdev;
+		outputParameters.channelCount = 1;
+		outputParameters.sampleFormat = SAMPLE_TYPE;
+		outputParameters.suggestedLatency = Pa_GetDeviceInfo(outputParameters.device)->defaultLowOutputLatency;
+		outputParameters.hostApiSpecificStreamInfo = NULL;
+		err = OpenAudioStream(&globals.audio_stream, &inputParameters, &outputParameters, sample_rate, paClipOff);
+		/* UNLOCKED ************************************************************************************************* */
+		switch_mutex_unlock(globals.device_lock);
 
 
-        if (err != paNoError) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open audio device!\n");
-            switch_core_codec_destroy(&globals.read_codec);
-            switch_core_codec_destroy(&globals.write_codec);
+		if (err != paNoError) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open audio device!\n");
+			switch_core_codec_destroy(&globals.read_codec);
+			switch_core_codec_destroy(&globals.write_codec);
 
-            return SWITCH_STATUS_FALSE;
-        }
-    }
+			return SWITCH_STATUS_FALSE;
+		}
+	}
 
 
 
-    return SWITCH_STATUS_SUCCESS;
+	return SWITCH_STATUS_SUCCESS;
 
 
 }
@@ -1370,34 +1354,34 @@
 static switch_status_t engage_ring_device(int sample_rate, int channels)
 {
 	//int codec_ms = 20;
-    PaStreamParameters outputParameters;
+	PaStreamParameters outputParameters;
 	PaError err;
 
-    if (!globals.ring_stream) {
-        if (!sample_rate) {
-            sample_rate = globals.sample_rate;
-        }
-
-        switch_mutex_lock(globals.device_lock);
-        /* LOCKED ***************************************************************************************************/
-        outputParameters.device = globals.ringdev;
-        outputParameters.channelCount = channels;
-        outputParameters.sampleFormat =  SAMPLE_TYPE;
-        outputParameters.suggestedLatency = Pa_GetDeviceInfo(outputParameters.device)->defaultLowOutputLatency;
-        outputParameters.hostApiSpecificStreamInfo = NULL;
-        err = OpenAudioStream(&globals.ring_stream, NULL, &outputParameters, sample_rate, paClipOff);
-        /* UNLOCKED **************************************************************************************************/
-        switch_mutex_unlock(globals.device_lock);
-
-
-        if (err != paNoError) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open ring device!\n");
-            return SWITCH_STATUS_FALSE;
-        }
-    }
+	if (!globals.ring_stream) {
+		if (!sample_rate) {
+			sample_rate = globals.sample_rate;
+		}
 
-    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Engage ring device! rate: %d channels %d\n", sample_rate, channels);
-    return SWITCH_STATUS_SUCCESS;
+		switch_mutex_lock(globals.device_lock);
+		/* LOCKED ************************************************************************************************** */
+		outputParameters.device = globals.ringdev;
+		outputParameters.channelCount = channels;
+		outputParameters.sampleFormat = SAMPLE_TYPE;
+		outputParameters.suggestedLatency = Pa_GetDeviceInfo(outputParameters.device)->defaultLowOutputLatency;
+		outputParameters.hostApiSpecificStreamInfo = NULL;
+		err = OpenAudioStream(&globals.ring_stream, NULL, &outputParameters, sample_rate, paClipOff);
+		/* UNLOCKED ************************************************************************************************* */
+		switch_mutex_unlock(globals.device_lock);
+
+
+		if (err != paNoError) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open ring device!\n");
+			return SWITCH_STATUS_FALSE;
+		}
+	}
+
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Engage ring device! rate: %d channels %d\n", sample_rate, channels);
+	return SWITCH_STATUS_SUCCESS;
 }
 
 
@@ -1405,64 +1389,64 @@
 
 static switch_status_t dtmf_call(char **argv, int argc, switch_stream_handle_t *stream)
 {
-    char *dtmf = argv[0];
+	char *dtmf = argv[0];
 
-    if (switch_strlen_zero(dtmf)) {
-        stream->write_function(stream, "No DTMF Supplied!\n");
-    } else {
-        switch_mutex_lock(globals.pvt_lock);
-        if (globals.call_list) {
-            switch_channel_t *channel = switch_core_session_get_channel(globals.call_list->session);
-            switch_channel_queue_dtmf(channel, dtmf);
-        }
-        switch_mutex_unlock(globals.pvt_lock);
-    }
+	if (switch_strlen_zero(dtmf)) {
+		stream->write_function(stream, "No DTMF Supplied!\n");
+	} else {
+		switch_mutex_lock(globals.pvt_lock);
+		if (globals.call_list) {
+			switch_channel_t *channel = switch_core_session_get_channel(globals.call_list->session);
+			switch_channel_queue_dtmf(channel, dtmf);
+		}
+		switch_mutex_unlock(globals.pvt_lock);
+	}
 
-    return SWITCH_STATUS_SUCCESS;
+	return SWITCH_STATUS_SUCCESS;
 }
 
 static switch_status_t switch_call(char **argv, int argc, switch_stream_handle_t *stream)
 {
-    private_t *tp,*tech_pvt = NULL;
-    char *callid = argv[0];
-    uint8_t one_call = 0;
-
-    switch_mutex_lock(globals.pvt_lock);
-    if (switch_strlen_zero(callid)) {
-        if (globals.call_list) {
-            if (globals.call_list->next) {
-                tech_pvt = globals.call_list->next;
-            } else {
-                tech_pvt = globals.call_list;
-                one_call = 1;
-            }
-        }
-    } else if (!strcasecmp(callid, "none")) {
-        for (tp = globals.call_list; tp; tp = tp->next) {
-            switch_clear_flag_locked(tp, TFLAG_MASTER);
-        }
-        stream->write_function(stream, "OK\n");
-        goto done;
-    } else {
-        tech_pvt = switch_core_hash_find(globals.call_hash, callid);
-    }
+	private_t *tp, *tech_pvt = NULL;
+	char *callid = argv[0];
+	uint8_t one_call = 0;
+
+	switch_mutex_lock(globals.pvt_lock);
+	if (switch_strlen_zero(callid)) {
+		if (globals.call_list) {
+			if (globals.call_list->next) {
+				tech_pvt = globals.call_list->next;
+			} else {
+				tech_pvt = globals.call_list;
+				one_call = 1;
+			}
+		}
+	} else if (!strcasecmp(callid, "none")) {
+		for (tp = globals.call_list; tp; tp = tp->next) {
+			switch_clear_flag_locked(tp, TFLAG_MASTER);
+		}
+		stream->write_function(stream, "OK\n");
+		goto done;
+	} else {
+		tech_pvt = switch_core_hash_find(globals.call_hash, callid);
+	}
 
 	if (tech_pvt) {
-        if (tech_pvt == globals.call_list && !tech_pvt->next) {
-            one_call = 1;
-        }
-
-        if (!one_call) {
-            remove_pvt(tech_pvt);
-        }
-        add_pvt(tech_pvt, PA_MASTER);
-        stream->write_function(stream, "OK\n");
+		if (tech_pvt == globals.call_list && !tech_pvt->next) {
+			one_call = 1;
+		}
+
+		if (!one_call) {
+			remove_pvt(tech_pvt);
+		}
+		add_pvt(tech_pvt, PA_MASTER);
+		stream->write_function(stream, "OK\n");
 	} else {
 		stream->write_function(stream, "NO SUCH CALL\n");
 	}
 
- done:
-    switch_mutex_unlock(globals.pvt_lock);
+  done:
+	switch_mutex_unlock(globals.pvt_lock);
 
 	return SWITCH_STATUS_SUCCESS;
 
@@ -1470,24 +1454,24 @@
 
 static switch_status_t hangup_call(char **argv, int argc, switch_stream_handle_t *stream)
 {
-    private_t *tech_pvt;
-    char *callid = argv[0];
-    
-    switch_mutex_lock(globals.pvt_lock);
-    if (switch_strlen_zero(callid)) {
-        tech_pvt = globals.call_list;
-    } else {
-        tech_pvt = switch_core_hash_find(globals.call_hash, callid);
-    }
+	private_t *tech_pvt;
+	char *callid = argv[0];
+
+	switch_mutex_lock(globals.pvt_lock);
+	if (switch_strlen_zero(callid)) {
+		tech_pvt = globals.call_list;
+	} else {
+		tech_pvt = switch_core_hash_find(globals.call_hash, callid);
+	}
 
 	if (tech_pvt) {
 		switch_channel_hangup(switch_core_session_get_channel(tech_pvt->session), SWITCH_CAUSE_NORMAL_CLEARING);
-        //switch_set_flag_locked(tech_pvt, TFLAG_HUP);
+		//switch_set_flag_locked(tech_pvt, TFLAG_HUP);
 		stream->write_function(stream, "OK\n");
 	} else {
 		stream->write_function(stream, "NO SUCH CALL\n");
 	}
-    switch_mutex_unlock(globals.pvt_lock);
+	switch_mutex_unlock(globals.pvt_lock);
 
 	return SWITCH_STATUS_SUCCESS;
 
@@ -1495,43 +1479,43 @@
 
 static switch_status_t answer_call(char **argv, int argc, switch_stream_handle_t *stream)
 {
-    private_t *tp;
-    int x = 0;
-    char *callid = argv[0];
-    
-    switch_mutex_lock(globals.pvt_lock);
-
-    if (!switch_strlen_zero(callid)) {
-        if ((tp = switch_core_hash_find(globals.call_hash, callid))) {
-            if (switch_test_flag(tp, TFLAG_ANSWER)) {
-                stream->write_function(stream, "CALL ALREADY ANSWERED\n");
-            } else {
-                switch_channel_t *channel = switch_core_session_get_channel(tp->session);
-                switch_set_flag_locked(tp, TFLAG_ANSWER);
-                switch_channel_answer(channel);
-                add_pvt(tp, PA_MASTER);
-            }
-        } else {
-            stream->write_function(stream, "NO SUCH CALL\n");
-        }
-
-        goto done;
-    }
-
-    for (tp = globals.call_list; tp; tp = tp->next) {
-        if (!switch_test_flag(tp, TFLAG_ANSWER)) {
-            switch_channel_t *channel = switch_core_session_get_channel(tp->session);
-            switch_set_flag_locked(tp, TFLAG_ANSWER);
-            switch_channel_answer(channel);
-            add_pvt(tp, PA_MASTER);
-            x++;
-            break;
-        }
-	} 
- done:
-    switch_mutex_unlock(globals.pvt_lock);
+	private_t *tp;
+	int x = 0;
+	char *callid = argv[0];
 
-    stream->write_function(stream, "Answered %d channels.\n", x);    
+	switch_mutex_lock(globals.pvt_lock);
+
+	if (!switch_strlen_zero(callid)) {
+		if ((tp = switch_core_hash_find(globals.call_hash, callid))) {
+			if (switch_test_flag(tp, TFLAG_ANSWER)) {
+				stream->write_function(stream, "CALL ALREADY ANSWERED\n");
+			} else {
+				switch_channel_t *channel = switch_core_session_get_channel(tp->session);
+				switch_set_flag_locked(tp, TFLAG_ANSWER);
+				switch_channel_answer(channel);
+				add_pvt(tp, PA_MASTER);
+			}
+		} else {
+			stream->write_function(stream, "NO SUCH CALL\n");
+		}
+
+		goto done;
+	}
+
+	for (tp = globals.call_list; tp; tp = tp->next) {
+		if (!switch_test_flag(tp, TFLAG_ANSWER)) {
+			switch_channel_t *channel = switch_core_session_get_channel(tp->session);
+			switch_set_flag_locked(tp, TFLAG_ANSWER);
+			switch_channel_answer(channel);
+			add_pvt(tp, PA_MASTER);
+			x++;
+			break;
+		}
+	}
+  done:
+	switch_mutex_unlock(globals.pvt_lock);
+
+	stream->write_function(stream, "Answered %d channels.\n", x);
 
 
 	return SWITCH_STATUS_SUCCESS;
@@ -1540,113 +1524,110 @@
 
 static switch_status_t do_flags(char **argv, int argc, switch_stream_handle_t *stream)
 {
-    char *action = argv[0];
-    char *flag_str = argv[1];
-    GFLAGS flags = GFLAG_NONE;
-    char *p;
-    int x = 0;
-
-    if (argc < 2) {
-        goto desc;
-    }
-
-    for (x = 1; x < argc; x++) {
-        flag_str = argv[x];
-        for(p = flag_str; *p; p++) {
-            *p = (char)tolower(*p);
-        }
-    
-        if (strstr(flag_str, "ear")) {
-            flags |= GFLAG_EAR;
-        } 
-        if (strstr(flag_str, "mouth")) {
-            flags |= GFLAG_MOUTH;
-        }
-    }
-
-    if (!strcasecmp(action, "on")) {
-        if (flags & GFLAG_EAR) {
-            switch_set_flag((&globals), GFLAG_EAR);
-        }
-        if (flags & GFLAG_MOUTH) {
-            switch_set_flag((&globals), GFLAG_MOUTH);
-        }
-    } else if (!strcasecmp(action, "off")) {
-        if (flags & GFLAG_EAR) {
-            switch_clear_flag((&globals), GFLAG_EAR);
-        }
-        if (flags & GFLAG_MOUTH) {
-            switch_clear_flag((&globals), GFLAG_MOUTH);
-        }
-    } else {
-        goto bad;
-    }
-
- desc:
-    x = 0;
-    stream->write_function(stream, "FLAGS: ");
-    if (switch_test_flag((&globals), GFLAG_EAR)) {
-        stream->write_function(stream, "ear");
-        x++;
-    }
-    if (switch_test_flag((&globals), GFLAG_MOUTH)) {
-        stream->write_function(stream, "%smouth", x ? "|" : "");
-        x++;
-    }
-    if (!x) {
-        stream->write_function(stream, "none");
-    }
-
-    goto done;
-
- bad:
-    stream->write_function(stream, "Usage: flags [on|off] <flags>\n");    
- done:
-    return SWITCH_STATUS_SUCCESS;
+	char *action = argv[0];
+	char *flag_str = argv[1];
+	GFLAGS flags = GFLAG_NONE;
+	char *p;
+	int x = 0;
+
+	if (argc < 2) {
+		goto desc;
+	}
+
+	for (x = 1; x < argc; x++) {
+		flag_str = argv[x];
+		for (p = flag_str; *p; p++) {
+			*p = (char) tolower(*p);
+		}
+
+		if (strstr(flag_str, "ear")) {
+			flags |= GFLAG_EAR;
+		}
+		if (strstr(flag_str, "mouth")) {
+			flags |= GFLAG_MOUTH;
+		}
+	}
+
+	if (!strcasecmp(action, "on")) {
+		if (flags & GFLAG_EAR) {
+			switch_set_flag((&globals), GFLAG_EAR);
+		}
+		if (flags & GFLAG_MOUTH) {
+			switch_set_flag((&globals), GFLAG_MOUTH);
+		}
+	} else if (!strcasecmp(action, "off")) {
+		if (flags & GFLAG_EAR) {
+			switch_clear_flag((&globals), GFLAG_EAR);
+		}
+		if (flags & GFLAG_MOUTH) {
+			switch_clear_flag((&globals), GFLAG_MOUTH);
+		}
+	} else {
+		goto bad;
+	}
+
+  desc:
+	x = 0;
+	stream->write_function(stream, "FLAGS: ");
+	if (switch_test_flag((&globals), GFLAG_EAR)) {
+		stream->write_function(stream, "ear");
+		x++;
+	}
+	if (switch_test_flag((&globals), GFLAG_MOUTH)) {
+		stream->write_function(stream, "%smouth", x ? "|" : "");
+		x++;
+	}
+	if (!x) {
+		stream->write_function(stream, "none");
+	}
+
+	goto done;
+
+  bad:
+	stream->write_function(stream, "Usage: flags [on|off] <flags>\n");
+  done:
+	return SWITCH_STATUS_SUCCESS;
 }
 
 static switch_status_t list_calls(char **argv, int argc, switch_stream_handle_t *stream)
 {
-    private_t *tp;
-    int x = 0;
-    char *cid_name = "n/a";
-    char *cid_num = "n/a";
-    
-    switch_mutex_lock(globals.pvt_lock);
-    for (tp = globals.call_list; tp; tp = tp->next) {
+	private_t *tp;
+	int x = 0;
+	char *cid_name = "n/a";
+	char *cid_num = "n/a";
+
+	switch_mutex_lock(globals.pvt_lock);
+	for (tp = globals.call_list; tp; tp = tp->next) {
 		switch_channel_t *channel;
-        switch_caller_profile_t *profile;
-        x++;
-        channel = switch_core_session_get_channel(tp->session);        
-        
-        if ((profile = switch_channel_get_caller_profile(channel))) {
-            if (profile->originatee_caller_profile) {
-                cid_name = "Outbound Call";
-                cid_num = profile->originatee_caller_profile->destination_number;
-            } else {
-                cid_name = profile->caller_id_name;
-                cid_num = profile->caller_id_number;
-            }
-        }
-
-        stream->write_function(stream, "%s %s [%s (%s)] %s\n", tp->call_id, switch_channel_get_name(channel),
-                               cid_name,
-                               cid_num,
-                               switch_test_flag(tp, TFLAG_MASTER) ? "active" : "hold"
-                               );
-    }
-    switch_mutex_unlock(globals.pvt_lock);
+		switch_caller_profile_t *profile;
+		x++;
+		channel = switch_core_session_get_channel(tp->session);
+
+		if ((profile = switch_channel_get_caller_profile(channel))) {
+			if (profile->originatee_caller_profile) {
+				cid_name = "Outbound Call";
+				cid_num = profile->originatee_caller_profile->destination_number;
+			} else {
+				cid_name = profile->caller_id_name;
+				cid_num = profile->caller_id_number;
+			}
+		}
 
-    stream->write_function(stream, "\n%d call%s\n", x, x == 1 ? "" : "s");
+		stream->write_function(stream, "%s %s [%s (%s)] %s\n", tp->call_id, switch_channel_get_name(channel),
+							   cid_name, cid_num, switch_test_flag(tp, TFLAG_MASTER) ? "active" : "hold");
+	}
+	switch_mutex_unlock(globals.pvt_lock);
 
-    return SWITCH_STATUS_SUCCESS;
+	stream->write_function(stream, "\n%d call%s\n", x, x == 1 ? "" : "s");
+
+	return SWITCH_STATUS_SUCCESS;
 }
 
 static switch_status_t place_call(char **argv, int argc, switch_stream_handle_t *stream)
 {
 	switch_core_session_t *session;
 	switch_status_t status = SWITCH_STATUS_SUCCESS;
-    char *dest = NULL;
+	char *dest = NULL;
 
 	if (!argv[0]) {
 		stream->write_function(stream, "FAIL:Usage: call <dest>\n");
@@ -1657,9 +1638,9 @@
 	if ((session = switch_core_session_request(&channel_endpoint_interface, NULL)) != 0) {
 		private_t *tech_pvt;
 		switch_channel_t *channel;
-        char *dialplan = globals.dialplan;
-        char *cid_name = globals.cid_name;
-        char *cid_num = globals.cid_num;        
+		char *dialplan = globals.dialplan;
+		char *cid_name = globals.cid_name;
+		char *cid_num = globals.cid_num;
 
 		switch_core_session_add_stream(session, NULL);
 		if ((tech_pvt = (private_t *) switch_core_session_alloc(session, sizeof(private_t))) != 0) {
@@ -1668,7 +1649,7 @@
 			channel = switch_core_session_get_channel(session);
 			switch_core_session_set_private(session, tech_pvt);
 			tech_pvt->session = session;
-            globals.flags = GFLAG_EAR | GFLAG_MOUTH;
+			globals.flags = GFLAG_EAR | GFLAG_MOUTH;
 		} else {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n");
 			switch_core_session_destroy(&session);
@@ -1676,31 +1657,29 @@
 		}
 
 		if (!switch_strlen_zero(argv[1])) {
-            dialplan = argv[1];
-        }
+			dialplan = argv[1];
+		}
+
+		if (!switch_strlen_zero(argv[2])) {
+			cid_num = argv[2];
+		}
+
+		if (!switch_strlen_zero(argv[3])) {
+			cid_name = argv[3];
+		}
+
+		if (!switch_strlen_zero(argv[4])) {
+			tech_pvt->sample_rate = atoi(argv[4]);
+		}
 
-        if (!switch_strlen_zero(argv[2])) {
-            cid_num = argv[2];
-        }
-
-        if (!switch_strlen_zero(argv[3])) {
-            cid_name = argv[3];
-        }
-
-        if (!switch_strlen_zero(argv[4])) {
-            tech_pvt->sample_rate = atoi(argv[4]);
-        }
-
-        if (!switch_strlen_zero(argv[4])) {
-            tech_pvt->codec_ms = atoi(argv[5]);
-        }
+		if (!switch_strlen_zero(argv[4])) {
+			tech_pvt->codec_ms = atoi(argv[5]);
+		}
 
 		if ((tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
 																  NULL,
-																  dialplan,
-                                                                  cid_name,
-																  cid_num,
-                                                                  NULL, NULL, NULL, NULL, (char *)modname, NULL, dest)) != 0) {
+																  dialplan, cid_name, cid_num, NULL, NULL, NULL, NULL, (char *) modname, NULL,
+																  dest)) != 0) {
 			char name[128];
 			snprintf(name, sizeof(name), "PortAudio/%s",
 					 tech_pvt->caller_profile->destination_number ? tech_pvt->caller_profile->destination_number : modname);
@@ -1710,14 +1689,14 @@
 		}
 		tech_pvt->session = session;
 		if ((status = engage_device(tech_pvt->sample_rate, tech_pvt->codec_ms)) == SWITCH_STATUS_SUCCESS) {
-            switch_set_flag_locked(tech_pvt, TFLAG_ANSWER);
-            switch_channel_mark_answered(channel);
+			switch_set_flag_locked(tech_pvt, TFLAG_ANSWER);
+			switch_channel_mark_answered(channel);
 			switch_channel_set_state(channel, CS_INIT);
 			switch_core_session_thread_launch(tech_pvt->session);
-            add_pvt(tech_pvt, PA_MASTER);
+			add_pvt(tech_pvt, PA_MASTER);
 			stream->write_function(stream, "SUCCESS:%s:%s\n", tech_pvt->call_id, switch_core_session_get_uuid(tech_pvt->session));
 		} else {
-            switch_core_session_destroy(&session);
+			switch_core_session_destroy(&session);
 			stream->write_function(stream, "FAIL:Device Error!\n");
 		}
 	}
@@ -1727,72 +1706,71 @@
 
 static switch_status_t padep(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
 {
-    stream->write_function(stream, "This command no longer exists (try 'pa help')\n");
-    return SWITCH_STATUS_SUCCESS;
+	stream->write_function(stream, "This command no longer exists (try 'pa help')\n");
+	return SWITCH_STATUS_SUCCESS;
 }
 
 static switch_status_t pa_cmd(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
 {
-    char *argv[1024] = {0};
-    int argc = 0;
-    char *mycmd = NULL, *devname = NULL;
-    switch_status_t status = SWITCH_STATUS_SUCCESS;
-    pa_command_t func = NULL;
-    int lead = 1, devval = 0;
-    const char *usage_string = "USAGE:\n"
-        "--------------------------------------------------------------------------------\n"
-        "pa help\n"
-        "pa dump\n"
-        "pa call <dest> [<dialplan> <cid_name> <cid_num> <rate>]\n"
-        "pa answer [<call_id>]\n"
-        "pa hangup [<call_id>]\n"
-        "pa list\n"
-        "pa switch [<call_id>|none]\n"
-        "pa dtmf <digit string>\n"
-        "pa flags [on|off] [ear] [mouth]\n"
+	char *argv[1024] = { 0 };
+	int argc = 0;
+	char *mycmd = NULL, *devname = NULL;
+	switch_status_t status = SWITCH_STATUS_SUCCESS;
+	pa_command_t func = NULL;
+	int lead = 1, devval = 0;
+	const char *usage_string = "USAGE:\n"
+		"--------------------------------------------------------------------------------\n"
+		"pa help\n"
+		"pa dump\n"
+		"pa call <dest> [<dialplan> <cid_name> <cid_num> <rate>]\n"
+		"pa answer [<call_id>]\n"
+		"pa hangup [<call_id>]\n"
+		"pa list\n"
+		"pa switch [<call_id>|none]\n"
+		"pa dtmf <digit string>\n"
+		"pa flags [on|off] [ear] [mouth]\n"
 		"pa devlist\n"
 		"pa indev [#<num>|<partial name>\n"
 		"pa outdev [#<num>|<partial name>\n"
-		"pa ringdev [#<num>|<partial name>\n"
-        "--------------------------------------------------------------------------------\n";
+		"pa ringdev [#<num>|<partial name>\n" "--------------------------------------------------------------------------------\n";
+
+	if (switch_strlen_zero(cmd)) {
+		stream->write_function(stream, "%s", usage_string);
+		goto done;
+	}
+
+	if (!(mycmd = strdup(cmd))) {
+		status = SWITCH_STATUS_MEMERR;
+		goto done;
+	}
 
-    if (switch_strlen_zero(cmd)) {
-        stream->write_function(stream, "%s", usage_string);
-        goto done;
-    }
-
-    if (!(mycmd = strdup(cmd))) {
-        status = SWITCH_STATUS_MEMERR;
-        goto done;
-    }
-    
-    if (!(argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
-        stream->write_function(stream, "%s", usage_string);
-        goto done;
-    }
-    
-    if (!strcasecmp(argv[0], "call")) {
-        func = place_call;
-    } else if (!strcasecmp(argv[0], "help")) {
-        stream->write_function(stream, "%s", usage_string);
-        goto done;
-    } else if (!strcasecmp(argv[0], "devlist")) {
+	if (!(argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
+		stream->write_function(stream, "%s", usage_string);
+		goto done;
+	}
+
+	if (!strcasecmp(argv[0], "call")) {
+		func = place_call;
+	} else if (!strcasecmp(argv[0], "help")) {
+		stream->write_function(stream, "%s", usage_string);
+		goto done;
+	} else if (!strcasecmp(argv[0], "devlist")) {
 		func = devlist;
-    } else if (!strcasecmp(argv[0], "dump")) {
-        dump_info();
-        goto done;
-    } else if (!strcasecmp(argv[0], "list")) {
-        func = list_calls;
-    } else if (!strcasecmp(argv[0], "flags")) {
-        func = do_flags;
-    } else if (!strcasecmp(argv[0], "hangup")) {
-        func = hangup_call;
-    } else if (!strcasecmp(argv[0], "answer")) {
-        func = answer_call;
-    } else if (!strcasecmp(argv[0], "switch")) {
-        func = switch_call;
-    } else if (!strcasecmp(argv[0], "dtmf")) {
-        func = dtmf_call;
+	} else if (!strcasecmp(argv[0], "dump")) {
+		dump_info();
+		goto done;
+	} else if (!strcasecmp(argv[0], "list")) {
+		func = list_calls;
+	} else if (!strcasecmp(argv[0], "flags")) {
+		func = do_flags;
+	} else if (!strcasecmp(argv[0], "hangup")) {
+		func = hangup_call;
+	} else if (!strcasecmp(argv[0], "answer")) {
+		func = answer_call;
+	} else if (!strcasecmp(argv[0], "switch")) {
+		func = switch_call;
+	} else if (!strcasecmp(argv[0], "dtmf")) {
+		func = dtmf_call;
 	} else if (argv[1] && !strcmp(argv[0], "indev")) {
 		if (*argv[1] == '#') {
 			devval = get_dev_by_number(atoi(argv[1] + 1), 1);
@@ -1810,7 +1788,7 @@
 			devval = get_dev_by_name(argv[1], 0);
 		}
 		devname = "outdev";
-		if (devval > 0)  {
+		if (devval > 0) {
 			globals.outdev = devval;
 		}
 	} else if (argv[1] && !strcmp(argv[0], "ringdev")) {
@@ -1823,11 +1801,11 @@
 		if (devval > 0) {
 			globals.ringdev = devval;
 		}
-    }
-    
-    if (func) {
-        status = func(&argv[lead], argc - lead, stream);
-    } else {
+	}
+
+	if (func) {
+		status = func(&argv[lead], argc - lead, stream);
+	} else {
 		if (devname) {
 			if (devval > 0) {
 				stream->write_function(stream, "%s set to %d\n", devname, devval);
@@ -1837,13 +1815,13 @@
 		} else {
 			stream->write_function(stream, "Unknown Command [%s]\n", argv[0]);
 		}
-    }
+	}
 
- done:
+  done:
 
-    switch_safe_free(mycmd);
+	switch_safe_free(mycmd);
 
-    return status;
+	return status;
 }
 
 

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_portaudio/pa_ringbuffer.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_portaudio/pa_ringbuffer.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_portaudio/pa_ringbuffer.c	Fri Mar 30 12:19:18 2007
@@ -81,17 +81,17 @@
 #   define PaUtil_WriteMemoryBarrier()
 #else
 
-#if defined(__APPLE__) //|| defined(__FreeBSD__)
+#if defined(__APPLE__)			//|| defined(__FreeBSD__)
 #   include <libkern/OSAtomic.h>
-    /* Here are the memory barrier functions. Mac OS X and FreeBSD only provide
-       full memory barriers, so the three types of barriers are the same. */
+	/* Here are the memory barrier functions. Mac OS X and FreeBSD only provide
+	   full memory barriers, so the three types of barriers are the same. */
 #   define PaUtil_FullMemoryBarrier()  OSMemoryBarrier()
 #   define PaUtil_ReadMemoryBarrier()  OSMemoryBarrier()
 #   define PaUtil_WriteMemoryBarrier() OSMemoryBarrier()
 #elif defined(__GNUC__)
 
-    /* GCC understands volatile asm and "memory" to mean it
-     * should not reorder memory read/writes */
+	/* GCC understands volatile asm and "memory" to mean it
+	 * should not reorder memory read/writes */
 #   if defined( __PPC__ )
 #      define PaUtil_FullMemoryBarrier()  __asm__ volatile("sync":::"memory")
 #      define PaUtil_ReadMemoryBarrier()  __asm__ volatile("sync":::"memory")
@@ -123,37 +123,39 @@
  * Initialize FIFO.
  * numBytes must be power of 2, returns -1 if not.
  */
-long PaUtil_InitializeRingBuffer( PaUtilRingBuffer *rbuf, long numBytes, void *dataPtr )
+long PaUtil_InitializeRingBuffer(PaUtilRingBuffer * rbuf, long numBytes, void *dataPtr)
 {
-    if( ((numBytes-1) & numBytes) != 0) return -1; /* Not Power of two. */
-    rbuf->bufferSize = numBytes;
-    rbuf->buffer = (char *)dataPtr;
-    PaUtil_FlushRingBuffer( rbuf );
-    rbuf->bigMask = (numBytes*2)-1;
-    rbuf->smallMask = (numBytes)-1;
-    return 0;
+	if (((numBytes - 1) & numBytes) != 0)
+		return -1;				/* Not Power of two. */
+	rbuf->bufferSize = numBytes;
+	rbuf->buffer = (char *) dataPtr;
+	PaUtil_FlushRingBuffer(rbuf);
+	rbuf->bigMask = (numBytes * 2) - 1;
+	rbuf->smallMask = (numBytes) - 1;
+	return 0;
 }
 
 /***************************************************************************
 ** Return number of bytes available for reading. */
-long PaUtil_GetRingBufferReadAvailable( PaUtilRingBuffer *rbuf )
+long PaUtil_GetRingBufferReadAvailable(PaUtilRingBuffer * rbuf)
 {
-    PaUtil_ReadMemoryBarrier();
-    return ( (rbuf->writeIndex - rbuf->readIndex) & rbuf->bigMask );
+	PaUtil_ReadMemoryBarrier();
+	return ((rbuf->writeIndex - rbuf->readIndex) & rbuf->bigMask);
 }
+
 /***************************************************************************
 ** Return number of bytes available for writing. */
-long PaUtil_GetRingBufferWriteAvailable( PaUtilRingBuffer *rbuf )
+long PaUtil_GetRingBufferWriteAvailable(PaUtilRingBuffer * rbuf)
 {
-    /* Since we are calling PaUtil_GetRingBufferReadAvailable, we don't need an aditional MB */
-    return ( rbuf->bufferSize - PaUtil_GetRingBufferReadAvailable(rbuf));
+	/* Since we are calling PaUtil_GetRingBufferReadAvailable, we don't need an aditional MB */
+	return (rbuf->bufferSize - PaUtil_GetRingBufferReadAvailable(rbuf));
 }
 
 /***************************************************************************
 ** Clear buffer. Should only be called when buffer is NOT being read. */
-void PaUtil_FlushRingBuffer( PaUtilRingBuffer *rbuf )
+void PaUtil_FlushRingBuffer(PaUtilRingBuffer * rbuf)
 {
-    rbuf->writeIndex = rbuf->readIndex = 0;
+	rbuf->writeIndex = rbuf->readIndex = 0;
 }
 
 /***************************************************************************
@@ -162,42 +164,38 @@
 ** If non-contiguous, size2 will be the size of second region.
 ** Returns room available to be written or numBytes, whichever is smaller.
 */
-long PaUtil_GetRingBufferWriteRegions( PaUtilRingBuffer *rbuf, long numBytes,
-                                       void **dataPtr1, long *sizePtr1,
-                                       void **dataPtr2, long *sizePtr2 )
-{
-    long   index;
-    long   available = PaUtil_GetRingBufferWriteAvailable( rbuf );
-    if( numBytes > available ) numBytes = available;
-    /* Check to see if write is not contiguous. */
-    index = rbuf->writeIndex & rbuf->smallMask;
-    if( (index + numBytes) > rbuf->bufferSize )
-    {
-        /* Write data in two blocks that wrap the buffer. */
-        long   firstHalf = rbuf->bufferSize - index;
-        *dataPtr1 = &rbuf->buffer[index];
-        *sizePtr1 = firstHalf;
-        *dataPtr2 = &rbuf->buffer[0];
-        *sizePtr2 = numBytes - firstHalf;
-    }
-    else
-    {
-        *dataPtr1 = &rbuf->buffer[index];
-        *sizePtr1 = numBytes;
-        *dataPtr2 = NULL;
-        *sizePtr2 = 0;
-    }
-    return numBytes;
+long PaUtil_GetRingBufferWriteRegions(PaUtilRingBuffer * rbuf, long numBytes, void **dataPtr1, long *sizePtr1, void **dataPtr2, long *sizePtr2)
+{
+	long index;
+	long available = PaUtil_GetRingBufferWriteAvailable(rbuf);
+	if (numBytes > available)
+		numBytes = available;
+	/* Check to see if write is not contiguous. */
+	index = rbuf->writeIndex & rbuf->smallMask;
+	if ((index + numBytes) > rbuf->bufferSize) {
+		/* Write data in two blocks that wrap the buffer. */
+		long firstHalf = rbuf->bufferSize - index;
+		*dataPtr1 = &rbuf->buffer[index];
+		*sizePtr1 = firstHalf;
+		*dataPtr2 = &rbuf->buffer[0];
+		*sizePtr2 = numBytes - firstHalf;
+	} else {
+		*dataPtr1 = &rbuf->buffer[index];
+		*sizePtr1 = numBytes;
+		*dataPtr2 = NULL;
+		*sizePtr2 = 0;
+	}
+	return numBytes;
 }
 
 
 /***************************************************************************
 */
-long PaUtil_AdvanceRingBufferWriteIndex( PaUtilRingBuffer *rbuf, long numBytes )
+long PaUtil_AdvanceRingBufferWriteIndex(PaUtilRingBuffer * rbuf, long numBytes)
 {
-    /* we need to ensure that previous writes are seen before we update the write index */
-    PaUtil_WriteMemoryBarrier();
-    return rbuf->writeIndex = (rbuf->writeIndex + numBytes) & rbuf->bigMask;
+	/* we need to ensure that previous writes are seen before we update the write index */
+	PaUtil_WriteMemoryBarrier();
+	return rbuf->writeIndex = (rbuf->writeIndex + numBytes) & rbuf->bigMask;
 }
 
 /***************************************************************************
@@ -206,81 +204,72 @@
 ** If non-contiguous, size2 will be the size of second region.
 ** Returns room available to be written or numBytes, whichever is smaller.
 */
-long PaUtil_GetRingBufferReadRegions( PaUtilRingBuffer *rbuf, long numBytes,
-                                void **dataPtr1, long *sizePtr1,
-                                void **dataPtr2, long *sizePtr2 )
-{
-    long   index;
-    long   available = PaUtil_GetRingBufferReadAvailable( rbuf );
-    if( numBytes > available ) numBytes = available;
-    /* Check to see if read is not contiguous. */
-    index = rbuf->readIndex & rbuf->smallMask;
-    if( (index + numBytes) > rbuf->bufferSize )
-    {
-        /* Write data in two blocks that wrap the buffer. */
-        long firstHalf = rbuf->bufferSize - index;
-        *dataPtr1 = &rbuf->buffer[index];
-        *sizePtr1 = firstHalf;
-        *dataPtr2 = &rbuf->buffer[0];
-        *sizePtr2 = numBytes - firstHalf;
-    }
-    else
-    {
-        *dataPtr1 = &rbuf->buffer[index];
-        *sizePtr1 = numBytes;
-        *dataPtr2 = NULL;
-        *sizePtr2 = 0;
-    }
-    return numBytes;
+long PaUtil_GetRingBufferReadRegions(PaUtilRingBuffer * rbuf, long numBytes, void **dataPtr1, long *sizePtr1, void **dataPtr2, long *sizePtr2)
+{
+	long index;
+	long available = PaUtil_GetRingBufferReadAvailable(rbuf);
+	if (numBytes > available)
+		numBytes = available;
+	/* Check to see if read is not contiguous. */
+	index = rbuf->readIndex & rbuf->smallMask;
+	if ((index + numBytes) > rbuf->bufferSize) {
+		/* Write data in two blocks that wrap the buffer. */
+		long firstHalf = rbuf->bufferSize - index;
+		*dataPtr1 = &rbuf->buffer[index];
+		*sizePtr1 = firstHalf;
+		*dataPtr2 = &rbuf->buffer[0];
+		*sizePtr2 = numBytes - firstHalf;
+	} else {
+		*dataPtr1 = &rbuf->buffer[index];
+		*sizePtr1 = numBytes;
+		*dataPtr2 = NULL;
+		*sizePtr2 = 0;
+	}
+	return numBytes;
 }
+
 /***************************************************************************
 */
-long PaUtil_AdvanceRingBufferReadIndex( PaUtilRingBuffer *rbuf, long numBytes )
+long PaUtil_AdvanceRingBufferReadIndex(PaUtilRingBuffer * rbuf, long numBytes)
 {
-    /* we need to ensure that previous writes are always seen before updating the index. */
-    PaUtil_WriteMemoryBarrier();
-    return rbuf->readIndex = (rbuf->readIndex + numBytes) & rbuf->bigMask;
+	/* we need to ensure that previous writes are always seen before updating the index. */
+	PaUtil_WriteMemoryBarrier();
+	return rbuf->readIndex = (rbuf->readIndex + numBytes) & rbuf->bigMask;
 }
 
 /***************************************************************************
 ** Return bytes written. */
-long PaUtil_WriteRingBuffer( PaUtilRingBuffer *rbuf, const void *data, long numBytes )
+long PaUtil_WriteRingBuffer(PaUtilRingBuffer * rbuf, const void *data, long numBytes)
 {
-    long size1, size2, numWritten;
-    void *data1, *data2;
-    numWritten = PaUtil_GetRingBufferWriteRegions( rbuf, numBytes, &data1, &size1, &data2, &size2 );
-    if( size2 > 0 )
-    {
-
-        memcpy( data1, data, size1 );
-        data = ((char *)data) + size1;
-        memcpy( data2, data, size2 );
-    }
-    else
-    {
-        memcpy( data1, data, size1 );
-    }
-    PaUtil_AdvanceRingBufferWriteIndex( rbuf, numWritten );
-    return numWritten;
+	long size1, size2, numWritten;
+	void *data1, *data2;
+	numWritten = PaUtil_GetRingBufferWriteRegions(rbuf, numBytes, &data1, &size1, &data2, &size2);
+	if (size2 > 0) {
+
+		memcpy(data1, data, size1);
+		data = ((char *) data) + size1;
+		memcpy(data2, data, size2);
+	} else {
+		memcpy(data1, data, size1);
+	}
+	PaUtil_AdvanceRingBufferWriteIndex(rbuf, numWritten);
+	return numWritten;
 }
 
 /***************************************************************************
 ** Return bytes read. */
-long PaUtil_ReadRingBuffer( PaUtilRingBuffer *rbuf, void *data, long numBytes )
+long PaUtil_ReadRingBuffer(PaUtilRingBuffer * rbuf, void *data, long numBytes)
 {
-    long size1, size2, numRead;
-    void *data1, *data2;
-    numRead = PaUtil_GetRingBufferReadRegions( rbuf, numBytes, &data1, &size1, &data2, &size2 );
-    if( size2 > 0 )
-    {
-        memcpy( data, data1, size1 );
-        data = ((char *)data) + size1;
-        memcpy( data, data2, size2 );
-    }
-    else
-    {
-        memcpy( data, data1, size1 );
-    }
-    PaUtil_AdvanceRingBufferReadIndex( rbuf, numRead );
-    return numRead;
+	long size1, size2, numRead;
+	void *data1, *data2;
+	numRead = PaUtil_GetRingBufferReadRegions(rbuf, numBytes, &data1, &size1, &data2, &size2);
+	if (size2 > 0) {
+		memcpy(data, data1, size1);
+		data = ((char *) data) + size1;
+		memcpy(data, data2, size2);
+	} else {
+		memcpy(data, data1, size1);
+	}
+	PaUtil_AdvanceRingBufferReadIndex(rbuf, numRead);
+	return numRead;
 }

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_portaudio/pa_ringbuffer.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_portaudio/pa_ringbuffer.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_portaudio/pa_ringbuffer.h	Fri Mar 30 12:19:18 2007
@@ -51,19 +51,17 @@
 */
 
 #ifdef __cplusplus
-extern "C"
-{
-#endif /* __cplusplus */
-
-typedef struct PaUtilRingBuffer
-{
-    long   bufferSize; /* Number of bytes in FIFO. Power of 2. Set by PaUtil_InitRingBuffer. */
-    long   writeIndex; /* Index of next writable byte. Set by PaUtil_AdvanceRingBufferWriteIndex. */
-    long   readIndex;  /* Index of next readable byte. Set by PaUtil_AdvanceRingBufferReadIndex. */
-    long   bigMask;    /* Used for wrapping indices with extra bit to distinguish full/empty. */
-    long   smallMask;  /* Used for fitting indices to buffer. */
-    char  *buffer;
-}PaUtilRingBuffer;
+extern "C" {
+#endif							/* __cplusplus */
+
+	typedef struct PaUtilRingBuffer {
+		long bufferSize;		/* Number of bytes in FIFO. Power of 2. Set by PaUtil_InitRingBuffer. */
+		long writeIndex;		/* Index of next writable byte. Set by PaUtil_AdvanceRingBufferWriteIndex. */
+		long readIndex;			/* Index of next readable byte. Set by PaUtil_AdvanceRingBufferReadIndex. */
+		long bigMask;			/* Used for wrapping indices with extra bit to distinguish full/empty. */
+		long smallMask;			/* Used for fitting indices to buffer. */
+		char *buffer;
+	} PaUtilRingBuffer;
 
 /** Initialize Ring Buffer.
 
@@ -76,13 +74,13 @@
 
  @return -1 if numBytes is not a power of 2, otherwise 0.
 */
-long PaUtil_InitializeRingBuffer( PaUtilRingBuffer *rbuf, long numBytes, void *dataPtr );
+	long PaUtil_InitializeRingBuffer(PaUtilRingBuffer * rbuf, long numBytes, void *dataPtr);
 
 /** Clear buffer. Should only be called when buffer is NOT being read.
 
  @param rbuf The ring buffer.
 */
-void PaUtil_FlushRingBuffer( PaUtilRingBuffer *rbuf );
+	void PaUtil_FlushRingBuffer(PaUtilRingBuffer * rbuf);
 
 /** Retrieve the number of bytes available in the ring buffer for writing.
 
@@ -90,7 +88,7 @@
 
  @return The number of bytes available for writing.
 */
-long PaUtil_GetRingBufferWriteAvailable( PaUtilRingBuffer *rbuf );
+	long PaUtil_GetRingBufferWriteAvailable(PaUtilRingBuffer * rbuf);
 
 /** Retrieve the number of bytes available in the ring buffer for reading.
 
@@ -98,7 +96,7 @@
 
  @return The number of bytes available for reading.
 */
-long PaUtil_GetRingBufferReadAvailable( PaUtilRingBuffer *rbuf );
+	long PaUtil_GetRingBufferReadAvailable(PaUtilRingBuffer * rbuf);
 
 /** Write data to the ring buffer.
 
@@ -110,7 +108,7 @@
 
  @return The number of bytes written.
 */
-long PaUtil_WriteRingBuffer( PaUtilRingBuffer *rbuf, const void *data, long numBytes );
+	long PaUtil_WriteRingBuffer(PaUtilRingBuffer * rbuf, const void *data, long numBytes);
 
 /** Read data from the ring buffer.
 
@@ -122,7 +120,7 @@
 
  @return The number of bytes read.
 */
-long PaUtil_ReadRingBuffer( PaUtilRingBuffer *rbuf, void *data, long numBytes );
+	long PaUtil_ReadRingBuffer(PaUtilRingBuffer * rbuf, void *data, long numBytes);
 
 /** Get address of region(s) to which we can write data.
 
@@ -144,9 +142,7 @@
 
  @return The room available to be written or numBytes, whichever is smaller.
 */
-long PaUtil_GetRingBufferWriteRegions( PaUtilRingBuffer *rbuf, long numBytes,
-                                       void **dataPtr1, long *sizePtr1,
-                                       void **dataPtr2, long *sizePtr2 );
+	long PaUtil_GetRingBufferWriteRegions(PaUtilRingBuffer * rbuf, long numBytes, void **dataPtr1, long *sizePtr1, void **dataPtr2, long *sizePtr2);
 
 /** Advance the write index to the next location to be written.
 
@@ -156,7 +152,7 @@
 
  @return The new position.
 */
-long PaUtil_AdvanceRingBufferWriteIndex( PaUtilRingBuffer *rbuf, long numBytes );
+	long PaUtil_AdvanceRingBufferWriteIndex(PaUtilRingBuffer * rbuf, long numBytes);
 
 /** Get address of region(s) from which we can write data.
 
@@ -178,9 +174,7 @@
 
  @return The number of bytes available for reading.
 */
-long PaUtil_GetRingBufferReadRegions( PaUtilRingBuffer *rbuf, long numBytes,
-                                      void **dataPtr1, long *sizePtr1,
-                                      void **dataPtr2, long *sizePtr2 );
+	long PaUtil_GetRingBufferReadRegions(PaUtilRingBuffer * rbuf, long numBytes, void **dataPtr1, long *sizePtr1, void **dataPtr2, long *sizePtr2);
 
 /** Advance the read index to the next location to be read.
 
@@ -190,9 +184,9 @@
 
  @return The new position.
 */
-long PaUtil_AdvanceRingBufferReadIndex( PaUtilRingBuffer *rbuf, long numBytes );
+	long PaUtil_AdvanceRingBufferReadIndex(PaUtilRingBuffer * rbuf, long numBytes);
 
 #ifdef __cplusplus
 }
-#endif /* __cplusplus */
-#endif /* PA_RINGBUFFER_H */
+#endif							/* __cplusplus */
+#endif							/* PA_RINGBUFFER_H */

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_portaudio/pablio.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_portaudio/pablio.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_portaudio/pablio.c	Fri Mar 30 12:19:18 2007
@@ -59,13 +59,10 @@
 /******** Prototypes ****************************************************/
 /************************************************************************/
 
-static int blockingIOCallback( const void *inputBuffer, void *outputBuffer,
-                               unsigned long framesPerBuffer,
-							   const PaStreamCallbackTimeInfo* timeInfo,
-							   PaStreamCallbackFlags statusFlags,
-							   void *userData );
-static PaError PABLIO_InitFIFO( PaUtilRingBuffer *rbuf, long numFrames, long bytesPerFrame );
-static PaError PABLIO_TermFIFO( PaUtilRingBuffer *rbuf );
+static int blockingIOCallback(const void *inputBuffer, void *outputBuffer,
+							  unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo * timeInfo, PaStreamCallbackFlags statusFlags, void *userData);
+static PaError PABLIO_InitFIFO(PaUtilRingBuffer * rbuf, long numFrames, long bytesPerFrame);
+static PaError PABLIO_TermFIFO(PaUtilRingBuffer * rbuf);
 
 /************************************************************************/
 /******** Functions *****************************************************/
@@ -74,122 +71,118 @@
 /* Called from PortAudio.
  * Read and write data only if there is room in FIFOs.
  */
-static int blockingIOCallback( const void *inputBuffer, void *outputBuffer,
-                               unsigned long framesPerBuffer,
-                               const PaStreamCallbackTimeInfo* timeInfo,
-							   PaStreamCallbackFlags statusFlags,
-							   void *userData )
-{
-    PABLIO_Stream *data = (PABLIO_Stream*)userData;
-    long numBytes = data->bytesPerFrame * framesPerBuffer;
-
-    /* This may get called with NULL inputBuffer during initial setup. */
-    if( inputBuffer != NULL )
-    {
-        PaUtil_WriteRingBuffer( &data->inFIFO, inputBuffer, numBytes );
-    }
-    if( outputBuffer != NULL )
-    {
-        int i;
-        int numRead = PaUtil_ReadRingBuffer( &data->outFIFO, outputBuffer, numBytes );
-        /* Zero out remainder of buffer if we run out of data. */
-        for( i=numRead; i<numBytes; i++ )
-        {
-            ((char *)outputBuffer)[i] = 0;
-        }
-    }
+static int blockingIOCallback(const void *inputBuffer, void *outputBuffer,
+							  unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo * timeInfo, PaStreamCallbackFlags statusFlags, void *userData)
+{
+	PABLIO_Stream *data = (PABLIO_Stream *) userData;
+	long numBytes = data->bytesPerFrame * framesPerBuffer;
+
+	/* This may get called with NULL inputBuffer during initial setup. */
+	if (inputBuffer != NULL) {
+		PaUtil_WriteRingBuffer(&data->inFIFO, inputBuffer, numBytes);
+	}
+	if (outputBuffer != NULL) {
+		int i;
+		int numRead = PaUtil_ReadRingBuffer(&data->outFIFO, outputBuffer, numBytes);
+		/* Zero out remainder of buffer if we run out of data. */
+		for (i = numRead; i < numBytes; i++) {
+			((char *) outputBuffer)[i] = 0;
+		}
+	}
 
-    return 0;
+	return 0;
 }
 
 /* Allocate buffer. */
-static PaError PABLIO_InitFIFO( PaUtilRingBuffer *rbuf, long numFrames, long bytesPerFrame )
+static PaError PABLIO_InitFIFO(PaUtilRingBuffer * rbuf, long numFrames, long bytesPerFrame)
 {
-    long numBytes = numFrames * bytesPerFrame;
-    char *buffer = (char *) malloc( numBytes );
-    if( buffer == NULL ) return paInsufficientMemory;
-    memset( buffer, 0, numBytes );
-    return (PaError) PaUtil_InitializeRingBuffer( rbuf, numBytes, buffer );
+	long numBytes = numFrames * bytesPerFrame;
+	char *buffer = (char *) malloc(numBytes);
+	if (buffer == NULL)
+		return paInsufficientMemory;
+	memset(buffer, 0, numBytes);
+	return (PaError) PaUtil_InitializeRingBuffer(rbuf, numBytes, buffer);
 }
 
 /* Free buffer. */
-static PaError PABLIO_TermFIFO( PaUtilRingBuffer *rbuf )
+static PaError PABLIO_TermFIFO(PaUtilRingBuffer * rbuf)
 {
-    if( rbuf->buffer ) free( rbuf->buffer );
-    rbuf->buffer = NULL;
-    return paNoError;
+	if (rbuf->buffer)
+		free(rbuf->buffer);
+	rbuf->buffer = NULL;
+	return paNoError;
 }
 
 /************************************************************
  * Write data to ring buffer.
  * Will not return until all the data has been written.
  */
-long WriteAudioStream( PABLIO_Stream *aStream, void *data, long numFrames )
+long WriteAudioStream(PABLIO_Stream * aStream, void *data, long numFrames)
 {
-    long bytesWritten;
-    char *p = (char *) data;
-    long numBytes = aStream->bytesPerFrame * numFrames;
-    while( numBytes > 0)
-    {
-        bytesWritten = PaUtil_WriteRingBuffer( &aStream->outFIFO, p, numBytes );
-        numBytes -= bytesWritten;
-        p += bytesWritten;
-        if( numBytes > 0) Pa_Sleep(10);
-    }
-    return numFrames;
+	long bytesWritten;
+	char *p = (char *) data;
+	long numBytes = aStream->bytesPerFrame * numFrames;
+	while (numBytes > 0) {
+		bytesWritten = PaUtil_WriteRingBuffer(&aStream->outFIFO, p, numBytes);
+		numBytes -= bytesWritten;
+		p += bytesWritten;
+		if (numBytes > 0)
+			Pa_Sleep(10);
+	}
+	return numFrames;
 }
 
 /************************************************************
  * Read data from ring buffer.
  * Will not return until all the data has been read.
  */
-long ReadAudioStream( PABLIO_Stream *aStream, void *data, long numFrames )
+long ReadAudioStream(PABLIO_Stream * aStream, void *data, long numFrames)
 {
-    long bytesRead;
-    char *p = (char *) data;
-    long numBytes = aStream->bytesPerFrame * numFrames;
-
-    while( numBytes > 0)
-    {
-        bytesRead = PaUtil_ReadRingBuffer( &aStream->inFIFO, p, numBytes );
-        numBytes -= bytesRead;
-        p += bytesRead;
-        if( numBytes > 0) Pa_Sleep(10);
-    }
-    return numFrames;
+	long bytesRead;
+	char *p = (char *) data;
+	long numBytes = aStream->bytesPerFrame * numFrames;
+
+	while (numBytes > 0) {
+		bytesRead = PaUtil_ReadRingBuffer(&aStream->inFIFO, p, numBytes);
+		numBytes -= bytesRead;
+		p += bytesRead;
+		if (numBytes > 0)
+			Pa_Sleep(10);
+	}
+	return numFrames;
 }
 
 /************************************************************
  * Return the number of frames that could be written to the stream without
  * having to wait.
  */
-long GetAudioStreamWriteable( PABLIO_Stream *aStream )
+long GetAudioStreamWriteable(PABLIO_Stream * aStream)
 {
-    int bytesEmpty = PaUtil_GetRingBufferWriteAvailable( &aStream->outFIFO );
-    return bytesEmpty / aStream->bytesPerFrame;
+	int bytesEmpty = PaUtil_GetRingBufferWriteAvailable(&aStream->outFIFO);
+	return bytesEmpty / aStream->bytesPerFrame;
 }
 
 /************************************************************
  * Return the number of frames that are available to be read from the
  * stream without having to wait.
  */
-long GetAudioStreamReadable( PABLIO_Stream *aStream )
+long GetAudioStreamReadable(PABLIO_Stream * aStream)
 {
-    int bytesFull = PaUtil_GetRingBufferReadAvailable( &aStream->inFIFO );
-    return bytesFull / aStream->bytesPerFrame;
+	int bytesFull = PaUtil_GetRingBufferReadAvailable(&aStream->inFIFO);
+	return bytesFull / aStream->bytesPerFrame;
 }
 
 /************************************************************/
-static unsigned long RoundUpToNextPowerOf2( unsigned long n )
+static unsigned long RoundUpToNextPowerOf2(unsigned long n)
 {
-    long numBits = 0;
-    if( ((n-1) & n) == 0) return n; /* Already Power of two. */
-    while( n > 0 )
-    {
-        n= n>>1;
-        numBits++;
-    }
-    return (1<<numBits);
+	long numBits = 0;
+	if (((n - 1) & n) == 0)
+		return n;				/* Already Power of two. */
+	while (n > 0) {
+		n = n >> 1;
+		numBits++;
+	}
+	return (1 << numBits);
 }
 
 /************************************************************
@@ -197,27 +190,27 @@
  * Allocates PABLIO_Stream structure.
  *
  */
-PaError OpenAudioStream( PABLIO_Stream **rwblPtr, 
-						 const PaStreamParameters *inputParameters,
-						 const PaStreamParameters *outputParameters,
-						 double sampleRate,
-						 PaStreamFlags streamFlags)
-{
-    long   bytesPerSample;
-    PaError err;
-    PABLIO_Stream *aStream;
-    long   numFrames;
+PaError OpenAudioStream(PABLIO_Stream ** rwblPtr,
+						const PaStreamParameters * inputParameters, const PaStreamParameters * outputParameters, double sampleRate,
+						PaStreamFlags streamFlags)
+{
+	long bytesPerSample;
+	PaError err;
+	PABLIO_Stream *aStream;
+	long numFrames;
 	long numBytes;
 	int channels = 1;
 
-    /* Allocate PABLIO_Stream structure for caller. */
-    aStream = (PABLIO_Stream *) malloc( sizeof(PABLIO_Stream) );
-    if( aStream == NULL ) return paInsufficientMemory;
-    memset( aStream, 0, sizeof(PABLIO_Stream) );
-
-    /* Initialize PortAudio  */
-    err = Pa_Initialize();
-    if( err != paNoError ) goto error;
+	/* Allocate PABLIO_Stream structure for caller. */
+	aStream = (PABLIO_Stream *) malloc(sizeof(PABLIO_Stream));
+	if (aStream == NULL)
+		return paInsufficientMemory;
+	memset(aStream, 0, sizeof(PABLIO_Stream));
+
+	/* Initialize PortAudio  */
+	err = Pa_Initialize();
+	if (err != paNoError)
+		goto error;
 
 	if (inputParameters) {
 		channels = inputParameters->channelCount;
@@ -225,81 +218,77 @@
 		channels = outputParameters->channelCount;
 	}
 
-    numFrames = 4 * FRAMES_PER_BUFFER;
-    numFrames = RoundUpToNextPowerOf2( numFrames );
+	numFrames = 4 * FRAMES_PER_BUFFER;
+	numFrames = RoundUpToNextPowerOf2(numFrames);
 
 	bytesPerSample = 2;
 	aStream->samplesPerFrame = channels;
-    aStream->bytesPerFrame = bytesPerSample * aStream->samplesPerFrame;
+	aStream->bytesPerFrame = bytesPerSample * aStream->samplesPerFrame;
 
-    /* Initialize Ring Buffers */
+	/* Initialize Ring Buffers */
 
 	if (inputParameters) {
-		err = PABLIO_InitFIFO( &aStream->inFIFO, numFrames, aStream->bytesPerFrame );
-		if( err != paNoError ) goto error;
+		err = PABLIO_InitFIFO(&aStream->inFIFO, numFrames, aStream->bytesPerFrame);
+		if (err != paNoError)
+			goto error;
 	}
 
 	if (outputParameters) {
-		err = PABLIO_InitFIFO( &aStream->outFIFO, numFrames, aStream->bytesPerFrame );
-		if( err != paNoError ) goto error;
+		err = PABLIO_InitFIFO(&aStream->outFIFO, numFrames, aStream->bytesPerFrame);
+		if (err != paNoError)
+			goto error;
 	}
 
 	/* Make Write FIFO appear full initially. */
-	numBytes = PaUtil_GetRingBufferWriteAvailable( &aStream->outFIFO );
-	PaUtil_AdvanceRingBufferWriteIndex( &aStream->outFIFO, numBytes );
-	
-
-    /* Open a PortAudio stream that we will use to communicate with the underlying
-     * audio drivers. */
-    err = Pa_OpenStream(
-              &aStream->stream,
-			  inputParameters,
-              outputParameters,
-			  sampleRate,
-              FRAMES_PER_BUFFER,
-			  streamFlags,
-              blockingIOCallback,
-              aStream );
-    if( err != paNoError ) goto error;
-
-    err = Pa_StartStream( aStream->stream );
-    if( err != paNoError ) goto error;
-    *rwblPtr = aStream;
-    return paNoError;
-
-error:
-    CloseAudioStream( aStream );
-    *rwblPtr = NULL;
-    return err;
+	numBytes = PaUtil_GetRingBufferWriteAvailable(&aStream->outFIFO);
+	PaUtil_AdvanceRingBufferWriteIndex(&aStream->outFIFO, numBytes);
+
+
+	/* Open a PortAudio stream that we will use to communicate with the underlying
+	 * audio drivers. */
+	err = Pa_OpenStream(&aStream->stream, inputParameters, outputParameters, sampleRate, FRAMES_PER_BUFFER, streamFlags, blockingIOCallback, aStream);
+	if (err != paNoError)
+		goto error;
+
+	err = Pa_StartStream(aStream->stream);
+	if (err != paNoError)
+		goto error;
+	*rwblPtr = aStream;
+	return paNoError;
+
+  error:
+	CloseAudioStream(aStream);
+	*rwblPtr = NULL;
+	return err;
 }
 
 /************************************************************/
-PaError CloseAudioStream( PABLIO_Stream *aStream )
+PaError CloseAudioStream(PABLIO_Stream * aStream)
 {
-    PaError err;
-    int bytesEmpty;
-    int byteSize = aStream->outFIFO.bufferSize;
-
-    /* If we are writing data, make sure we play everything written. */
-    if( byteSize > 0 )
-    {
-        bytesEmpty = PaUtil_GetRingBufferWriteAvailable( &aStream->outFIFO );
-        while( bytesEmpty < byteSize )
-        {
-            Pa_Sleep( 10 );
-            bytesEmpty = PaUtil_GetRingBufferWriteAvailable( &aStream->outFIFO );
-        }
-    }
-
-    err = Pa_StopStream( aStream->stream );
-    if( err != paNoError ) goto error;
-    err = Pa_CloseStream( aStream->stream );
-    if( err != paNoError ) goto error;
-    Pa_Terminate();
-
-error:
-    PABLIO_TermFIFO( &aStream->inFIFO );
-    PABLIO_TermFIFO( &aStream->outFIFO );
-    free( aStream );
-    return err;
+	PaError err;
+	int bytesEmpty;
+	int byteSize = aStream->outFIFO.bufferSize;
+
+	/* If we are writing data, make sure we play everything written. */
+	if (byteSize > 0) {
+		bytesEmpty = PaUtil_GetRingBufferWriteAvailable(&aStream->outFIFO);
+		while (bytesEmpty < byteSize) {
+			Pa_Sleep(10);
+			bytesEmpty = PaUtil_GetRingBufferWriteAvailable(&aStream->outFIFO);
+		}
+	}
+
+	err = Pa_StopStream(aStream->stream);
+	if (err != paNoError)
+		goto error;
+	err = Pa_CloseStream(aStream->stream);
+	if (err != paNoError)
+		goto error;
+	Pa_Terminate();
+
+  error:
+	PABLIO_TermFIFO(&aStream->inFIFO);
+	PABLIO_TermFIFO(&aStream->outFIFO);
+	free(aStream);
+	return err;
 }

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_portaudio/pablio.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_portaudio/pablio.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_portaudio/pablio.h	Fri Mar 30 12:19:18 2007
@@ -2,9 +2,8 @@
 #define _PABLIO_H
 
 #ifdef __cplusplus
-extern "C"
-{
-#endif /* __cplusplus */
+extern "C" {
+#endif							/* __cplusplus */
 
 /*
  * $Id: pablio.h 1083 2006-08-23 07:30:49Z rossb $
@@ -57,15 +56,13 @@
 
 #include <string.h>
 
-typedef struct
-{
-    PaUtilRingBuffer   inFIFO;
-    PaUtilRingBuffer   outFIFO;
-    PaStream *stream;
-    int          bytesPerFrame;
-    int          samplesPerFrame;
-}
-PABLIO_Stream;
+	typedef struct {
+		PaUtilRingBuffer inFIFO;
+		PaUtilRingBuffer outFIFO;
+		PaStream *stream;
+		int bytesPerFrame;
+		int samplesPerFrame;
+	} PABLIO_Stream;
 
 /* Values for flags for OpenAudioStream(). */
 #define PABLIO_READ     (1<<0)
@@ -78,25 +75,25 @@
  * Write data to ring buffer.
  * Will not return until all the data has been written.
  */
-long WriteAudioStream( PABLIO_Stream *aStream, void *data, long numFrames );
+	long WriteAudioStream(PABLIO_Stream * aStream, void *data, long numFrames);
 
 /************************************************************
  * Read data from ring buffer.
  * Will not return until all the data has been read.
  */
-long ReadAudioStream( PABLIO_Stream *aStream, void *data, long numFrames );
+	long ReadAudioStream(PABLIO_Stream * aStream, void *data, long numFrames);
 
 /************************************************************
  * Return the number of frames that could be written to the stream without
  * having to wait.
  */
-long GetAudioStreamWriteable( PABLIO_Stream *aStream );
+	long GetAudioStreamWriteable(PABLIO_Stream * aStream);
 
 /************************************************************
  * Return the number of frames that are available to be read from the
  * stream without having to wait.
  */
-long GetAudioStreamReadable( PABLIO_Stream *aStream );
+	long GetAudioStreamReadable(PABLIO_Stream * aStream);
 
 /************************************************************
  * Opens a PortAudio stream with default characteristics.
@@ -106,15 +103,13 @@
  *    PABLIO_READ, PABLIO_WRITE, or PABLIO_READ_WRITE,
  *    and either PABLIO_MONO or PABLIO_STEREO
  */
-PaError OpenAudioStream( PABLIO_Stream **rwblPtr, 
-						 const PaStreamParameters *inputParameters,
-						 const PaStreamParameters *outputParameters,
-						 double sampleRate,
-						 PaStreamCallbackFlags statusFlags);
+	PaError OpenAudioStream(PABLIO_Stream ** rwblPtr,
+							const PaStreamParameters * inputParameters,
+							const PaStreamParameters * outputParameters, double sampleRate, PaStreamCallbackFlags statusFlags);
 
-PaError CloseAudioStream( PABLIO_Stream *aStream );
+	PaError CloseAudioStream(PABLIO_Stream * aStream);
 
 #ifdef __cplusplus
 }
-#endif /* __cplusplus */
-#endif /* _PABLIO_H */
+#endif							/* __cplusplus */
+#endif							/* _PABLIO_H */

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/mod_sofia.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/mod_sofia.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/mod_sofia.c	Fri Mar 30 12:19:18 2007
@@ -41,7 +41,7 @@
 /*************************************************************************************************************************************************************/
 #define HAVE_APR
 #include <switch.h>
-static const switch_state_handler_table_t noop_state_handler = {0};
+static const switch_state_handler_table_t noop_state_handler = { 0 };
 struct outbound_reg;
 typedef struct outbound_reg outbound_reg_t;
 
@@ -50,7 +50,7 @@
 #define NUA_MAGIC_T sofia_profile_t
 
 struct sofia_private {
-    char uuid[SWITCH_UUID_FORMATTED_LENGTH + 1];
+	char uuid[SWITCH_UUID_FORMATTED_LENGTH + 1];
 	outbound_reg_t *gateway;
 };
 
@@ -87,40 +87,29 @@
 
 
 static char reg_sql[] =
-"CREATE TABLE sip_registrations (\n"
-"   user            VARCHAR(255),\n"
-"   host            VARCHAR(255),\n"
-"   contact         VARCHAR(1024),\n"
-"   status          VARCHAR(255),\n"
-"   rpid            VARCHAR(255),\n"
-"   expires         INTEGER(8)"
-");\n";
+	"CREATE TABLE sip_registrations (\n"
+	"   user            VARCHAR(255),\n"
+	"   host            VARCHAR(255),\n"
+	"   contact         VARCHAR(1024),\n" "   status          VARCHAR(255),\n" "   rpid            VARCHAR(255),\n" "   expires         INTEGER(8)" ");\n";
 
 
 static char sub_sql[] =
-"CREATE TABLE sip_subscriptions (\n"
-"   proto           VARCHAR(255),\n"
-"   user            VARCHAR(255),\n"
-"   host            VARCHAR(255),\n"
-"   sub_to_user     VARCHAR(255),\n"
-"   sub_to_host     VARCHAR(255),\n"
-"   event           VARCHAR(255),\n"
-"   contact         VARCHAR(1024),\n"
-"   call_id         VARCHAR(255),\n"
-"   full_from       VARCHAR(255),\n"
-"   full_via        VARCHAR(255),\n"
-"   expires         INTEGER(8)"
-");\n";
+	"CREATE TABLE sip_subscriptions (\n"
+	"   proto           VARCHAR(255),\n"
+	"   user            VARCHAR(255),\n"
+	"   host            VARCHAR(255),\n"
+	"   sub_to_user     VARCHAR(255),\n"
+	"   sub_to_host     VARCHAR(255),\n"
+	"   event           VARCHAR(255),\n"
+	"   contact         VARCHAR(1024),\n"
+	"   call_id         VARCHAR(255),\n" "   full_from       VARCHAR(255),\n" "   full_via        VARCHAR(255),\n" "   expires         INTEGER(8)" ");\n";
 
 
 static char auth_sql[] =
-"CREATE TABLE sip_authentication (\n"
-"   user            VARCHAR(255),\n"
-"   host            VARCHAR(255),\n"
-"   passwd            VARCHAR(255),\n"
-"   nonce           VARCHAR(255),\n"
-"   expires         INTEGER(8)"
-");\n";
+	"CREATE TABLE sip_authentication (\n"
+	"   user            VARCHAR(255),\n"
+	"   host            VARCHAR(255),\n" "   passwd            VARCHAR(255),\n" "   nonce           VARCHAR(255),\n" "   expires         INTEGER(8)"
+	");\n";
 
 static const char modname[] = "mod_sofia";
 #define STRLEN 15
@@ -148,7 +137,7 @@
 	PFLAG_FULL_ID = (1 << 3),
 	PFLAG_PRESENCE = (1 << 4),
 	PFLAG_PASS_RFC2833 = (1 << 5),
-    PFLAG_DISABLE_TRANSCODING = (1 << 6)
+	PFLAG_DISABLE_TRANSCODING = (1 << 6)
 } PFLAGS;
 
 typedef enum {
@@ -163,9 +152,9 @@
 	TFLAG_ANS = (1 << 8),
 	TFLAG_EARLY_MEDIA = (1 << 9),
 	TFLAG_SECURE = (1 << 10),
-	TFLAG_VAD_IN = ( 1 << 11),
-	TFLAG_VAD_OUT = ( 1 << 12),
-	TFLAG_VAD = ( 1 << 13),
+	TFLAG_VAD_IN = (1 << 11),
+	TFLAG_VAD_OUT = (1 << 12),
+	TFLAG_VAD = (1 << 13),
 	TFLAG_TIMER = (1 << 14),
 	TFLAG_READY = (1 << 15),
 	TFLAG_REINVITE = (1 << 16),
@@ -186,7 +175,7 @@
 	uint32_t callid;
 	int32_t running;
 	switch_mutex_t *mutex;
-    char guess_ip[80];
+	char guess_ip[80];
 } globals;
 
 typedef enum {
@@ -250,7 +239,7 @@
 	unsigned int flags;
 	unsigned int pflags;
 	uint32_t max_calls;
-    uint32_t nonce_ttl;
+	uint32_t nonce_ttl;
 	nua_t *nua;
 	switch_memory_pool_t *pool;
 	su_root_t *s_root;
@@ -318,7 +307,7 @@
 	char *chat_from;
 	char *chat_to;
 	char *e_dest;
-    char *call_id;
+	char *call_id;
 	unsigned long rm_rate;
 	switch_payload_t pt;
 	switch_mutex_t *flag_mutex;
@@ -342,96 +331,62 @@
 
 static switch_status_t sofia_on_transmit(switch_core_session_t *session);
 
-static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile,
-												  switch_core_session_t **new_session, switch_memory_pool_t **pool);
+static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session,
+												  switch_caller_profile_t *outbound_profile, switch_core_session_t **new_session,
+												  switch_memory_pool_t **pool);
 
-static switch_status_t sofia_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout,
-										switch_io_flag_t flags, int stream_id);
+static switch_status_t sofia_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, switch_io_flag_t flags, int stream_id);
 
-static switch_status_t sofia_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout,
-										 switch_io_flag_t flags, int stream_id);
+static switch_status_t sofia_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flags, int stream_id);
 
 static switch_status_t config_sofia(int reload);
 
 static switch_status_t sofia_kill_channel(switch_core_session_t *session, int sig);
 
-static switch_status_t activate_rtp(private_object_t *tech_pvt);
+static switch_status_t activate_rtp(private_object_t * tech_pvt);
 
-static void deactivate_rtp(private_object_t *tech_pvt);
+static void deactivate_rtp(private_object_t * tech_pvt);
 
-static void set_local_sdp(private_object_t *tech_pvt, char *ip, uint32_t port, char *sr, int force);
+static void set_local_sdp(private_object_t * tech_pvt, char *ip, uint32_t port, char *sr, int force);
 
-static void tech_set_codecs(private_object_t *tech_pvt);
+static void tech_set_codecs(private_object_t * tech_pvt);
 
-static void attach_private(switch_core_session_t *session,
-                           sofia_profile_t *profile,
-                           private_object_t *tech_pvt,
-                           const char *channame);
+static void attach_private(switch_core_session_t *session, sofia_profile_t * profile, private_object_t * tech_pvt, const char *channame);
 
 static void terminate_session(switch_core_session_t **session, switch_call_cause_t cause, int line);
 
-static switch_status_t tech_choose_port(private_object_t *tech_pvt);
+static switch_status_t tech_choose_port(private_object_t * tech_pvt);
 
 static switch_status_t do_invite(switch_core_session_t *session);
 
-static uint8_t negotiate_sdp(switch_core_session_t *session, sdp_session_t *sdp);
+static uint8_t negotiate_sdp(switch_core_session_t *session, sdp_session_t * sdp);
 
-static char *get_auth_data(char *dbname, char *nonce, char *npassword, size_t len, switch_mutex_t *mutex);
+static char *get_auth_data(char *dbname, char *nonce, char *npassword, size_t len, switch_mutex_t * mutex);
 
-static void establish_presence(sofia_profile_t *profile);
+static void establish_presence(sofia_profile_t * profile);
 
 static void sip_i_state(int status,
-                        char const *phrase,
-                        nua_t *nua,
-                        sofia_profile_t *profile,
-                        nua_handle_t *nh,
-						sofia_private_t *sofia_private,
-                        sip_t const *sip,
-                        tagi_t tags[]);
-
-
-static void sip_i_refer(nua_t *nua,
-						sofia_profile_t *profile,
-						nua_handle_t *nh,
-                        switch_core_session_t *session,
-						sip_t const *sip,
-						tagi_t tags[]);
-
-static void sip_i_info(nua_t *nua,
-                       sofia_profile_t *profile,
-                       nua_handle_t *nh,
-                       switch_core_session_t *session,
-                       sip_t const *sip,
-                       tagi_t tags[]);
-
-static void sip_i_invite(nua_t *nua,
-                         sofia_profile_t *profile,
-                         nua_handle_t *nh,
-						 sofia_private_t *sofia_private,
-                         sip_t const *sip,
-                         tagi_t tags[]);
-
-static void sip_i_register(nua_t *nua,
-						   sofia_profile_t *profile,
-						   nua_handle_t *nh,
-						   sofia_private_t *sofia_private,
-						   sip_t const *sip,
-						   tagi_t tags[]);
-
-static void event_callback(nua_event_t   event,
-                           int           status,
-                           char const   *phrase,
-                           nua_t        *nua,
-                           sofia_profile_t  *profile,
-                           nua_handle_t *nh,
-						   sofia_private_t *sofia_private,
-                           sip_t const  *sip,
-                           tagi_t        tags[]);
+						char const *phrase,
+						nua_t * nua, sofia_profile_t * profile, nua_handle_t * nh, sofia_private_t * sofia_private, sip_t const *sip, tagi_t tags[]);
 
 
-static void *SWITCH_THREAD_FUNC profile_thread_run(switch_thread_t *thread, void *obj);
+static void sip_i_refer(nua_t * nua, sofia_profile_t * profile, nua_handle_t * nh, switch_core_session_t *session, sip_t const *sip, tagi_t tags[]);
 
-static void launch_profile_thread(sofia_profile_t *profile);
+static void sip_i_info(nua_t * nua, sofia_profile_t * profile, nua_handle_t * nh, switch_core_session_t *session, sip_t const *sip, tagi_t tags[]);
+
+static void sip_i_invite(nua_t * nua, sofia_profile_t * profile, nua_handle_t * nh, sofia_private_t * sofia_private, sip_t const *sip, tagi_t tags[]);
+
+static void sip_i_register(nua_t * nua, sofia_profile_t * profile, nua_handle_t * nh, sofia_private_t * sofia_private, sip_t const *sip, tagi_t tags[]);
+
+static void event_callback(nua_event_t event,
+						   int status,
+						   char const *phrase,
+						   nua_t * nua, sofia_profile_t * profile, nua_handle_t * nh, sofia_private_t * sofia_private, sip_t const *sip, tagi_t tags[]);
+
+
+static void *SWITCH_THREAD_FUNC profile_thread_run(switch_thread_t * thread, void *obj);
+
+static void launch_profile_thread(sofia_profile_t * profile);
 
 static switch_status_t chat_send(char *proto, char *from, char *to, char *subject, char *body, char *hint);
 
@@ -456,10 +411,10 @@
 	return profile;
 }
 
-static void add_profile(char *key, sofia_profile_t *profile)
+static void add_profile(char *key, sofia_profile_t * profile)
 {
 	switch_mutex_lock(globals.hash_mutex);
-	switch_core_hash_insert(globals.profile_hash, key, profile);	
+	switch_core_hash_insert(globals.profile_hash, key, profile);
 	switch_mutex_unlock(globals.hash_mutex);
 }
 
@@ -474,7 +429,7 @@
 	return gateway;
 }
 
-static void add_gateway(char *key, outbound_reg_t *gateway)
+static void add_gateway(char *key, outbound_reg_t * gateway)
 {
 	switch_mutex_lock(globals.hash_mutex);
 	switch_core_hash_insert(globals.gateway_hash, key, gateway);
@@ -494,12 +449,12 @@
 
 		*e = '\0';
 	}
-	
+
 	return url;
 }
 
 
-static auth_res_t parse_auth(sofia_profile_t *profile, sip_authorization_t const *authorization, const char *regstr, char *np, size_t nplen)
+static auth_res_t parse_auth(sofia_profile_t * profile, sip_authorization_t const *authorization, const char *regstr, char *np, size_t nplen)
 {
 	int indexnum;
 	const char *cur;
@@ -513,14 +468,14 @@
 	nonce = uri = qop = cnonce = nc = response = NULL;
 
 	if (authorization->au_params) {
-		for(indexnum = 0; (cur=authorization->au_params[indexnum]); indexnum++) {
-			char *var, *val, *p, *work; 
+		for (indexnum = 0; (cur = authorization->au_params[indexnum]); indexnum++) {
+			char *var, *val, *p, *work;
 			var = val = work = NULL;
 			if ((work = strdup(cur))) {
 				var = work;
 				if ((val = strchr(var, '='))) {
 					*val++ = '\0';
-					while(*val == '"') {
+					while (*val == '"') {
 						*val++ = '\0';
 					}
 					if ((p = strchr(val, '"'))) {
@@ -547,7 +502,7 @@
 						cnt++;
 					}
 				}
-				
+
 				free(work);
 			}
 		}
@@ -562,7 +517,7 @@
 		if (!get_auth_data(profile->dbname, nonce, np, nplen, profile->ireg_mutex)) {
 			ret = AUTH_STALE;
 			goto end;
-		} 
+		}
 	}
 
 	npassword = np;
@@ -588,9 +543,9 @@
 		}
 	}
 
- end:
-    switch_safe_free(input);
-    switch_safe_free(input2);
+  end:
+	switch_safe_free(input);
+	switch_safe_free(input2);
 	switch_safe_free(nonce);
 	switch_safe_free(uri);
 	switch_safe_free(qop);
@@ -603,7 +558,7 @@
 }
 
 
-static void execute_sql(char *dbname, char *sql, switch_mutex_t *mutex)
+static void execute_sql(char *dbname, char *sql, switch_mutex_t * mutex)
 {
 	switch_core_db_t *db;
 
@@ -618,7 +573,7 @@
 	switch_core_db_persistant_execute(db, sql, 25);
 	switch_core_db_close(db);
 
- end:
+  end:
 	if (mutex) {
 		switch_mutex_unlock(mutex);
 	}
@@ -631,7 +586,8 @@
 	int matches;
 };
 
-static int find_callback(void *pArg, int argc, char **argv, char **columnNames){
+static int find_callback(void *pArg, int argc, char **argv, char **columnNames)
+{
 	struct callback_t *cbt = (struct callback_t *) pArg;
 
 	switch_copy_string(cbt->val, argv[0], cbt->len);
@@ -639,10 +595,11 @@
 	return 0;
 }
 
-static int del_callback(void *pArg, int argc, char **argv, char **columnNames){
+static int del_callback(void *pArg, int argc, char **argv, char **columnNames)
+{
 	switch_event_t *s_event;
 
-	if (argc >=3 ) {
+	if (argc >= 3) {
 		if (switch_event_create_subclass(&s_event, SWITCH_EVENT_CUSTOM, MY_EVENT_EXPIRE) == SWITCH_STATUS_SUCCESS) {
 			switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "profile-name", "%s", argv[0]);
 			switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "user", "%s", argv[1]);
@@ -655,7 +612,7 @@
 	return 0;
 }
 
-static void check_expire(switch_core_db_t *db, sofia_profile_t *profile, time_t now)
+static void check_expire(switch_core_db_t *db, sofia_profile_t * profile, time_t now)
 {
 	char sql[1024];
 	char *errmsg;
@@ -666,7 +623,7 @@
 	}
 
 	switch_mutex_lock(profile->ireg_mutex);
-	snprintf(sql, sizeof(sql), "select '%s',* from sip_registrations where expires > 0 and expires < %ld", profile->name, (long) now);	
+	snprintf(sql, sizeof(sql), "select '%s',* from sip_registrations where expires > 0 and expires < %ld", profile->name, (long) now);
 	switch_core_db_exec(db, sql, del_callback, NULL, &errmsg);
 
 	if (errmsg) {
@@ -674,7 +631,7 @@
 		switch_safe_free(errmsg);
 		errmsg = NULL;
 	}
-	
+
 	snprintf(sql, sizeof(sql), "delete from sip_registrations where expires > 0 and expires < %ld", (long) now);
 	switch_core_db_persistant_execute(db, sql, 1000);
 	snprintf(sql, sizeof(sql), "delete from sip_authentication where expires > 0 and expires < %ld", (long) now);
@@ -686,15 +643,15 @@
 
 }
 
-static char *find_reg_url(sofia_profile_t *profile, const char *user, const char *host, char *val, switch_size_t len)
+static char *find_reg_url(sofia_profile_t * profile, const char *user, const char *host, char *val, switch_size_t len)
 {
 	char *errmsg;
-	struct callback_t cbt = {0};
+	struct callback_t cbt = { 0 };
 	switch_core_db_t *db;
 
 	if (!user) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Called with null user!\n");
-        return NULL;
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Called with null user!\n");
+		return NULL;
 	}
 
 	if (!(db = switch_core_db_open_file(profile->dbname))) {
@@ -706,9 +663,9 @@
 	cbt.len = len;
 	switch_mutex_lock(profile->ireg_mutex);
 	if (host) {
-		snprintf(val, len, "select contact from sip_registrations where user='%s' and host='%s'", user, host);	
+		snprintf(val, len, "select contact from sip_registrations where user='%s' and host='%s'", user, host);
 	} else {
-		snprintf(val, len, "select contact from sip_registrations where user='%s'", user);	
+		snprintf(val, len, "select contact from sip_registrations where user='%s'", user);
 	}
 
 	switch_core_db_exec(db, val, find_callback, &cbt, &errmsg);
@@ -722,19 +679,19 @@
 	switch_mutex_unlock(profile->ireg_mutex);
 
 	switch_core_db_close(db);
-    if (cbt.matches) {
-        return val;
-    } else {
-        return NULL;
-    }
+	if (cbt.matches) {
+		return val;
+	} else {
+		return NULL;
+	}
 }
 
 
-static void set_local_sdp(private_object_t *tech_pvt, char *ip, uint32_t port, char *sr, int force)
+static void set_local_sdp(private_object_t * tech_pvt, char *ip, uint32_t port, char *sr, int force)
 {
 	char buf[2048];
 	switch_time_t now = switch_time_now();
-    int ptime = 0;
+	int ptime = 0;
 	int rate = 0;
 
 	if (!force && !ip && !sr && switch_test_flag(tech_pvt, TFLAG_NOMEDIA)) {
@@ -755,23 +712,10 @@
 		sr = "sendrecv";
 	}
 
-	snprintf(buf, sizeof(buf), 
+	snprintf(buf, sizeof(buf),
 			 "v=0\n"
-			 "o=FreeSWITCH %d%"SWITCH_TIME_T_FMT" %d%"SWITCH_TIME_T_FMT" IN IP4 %s\n"
-			 "s=FreeSWITCH\n"
-			 "c=IN IP4 %s\n"
-			 "t=0 0\n"
-			 "a=%s\n"
-			 "m=audio %d RTP/AVP",
-			 port,
-			 now,
-			 port,
-			 now,
-			 ip,
-			 ip,
-			 sr,
-			 port
-			 );
+			 "o=FreeSWITCH %d%" SWITCH_TIME_T_FMT " %d%" SWITCH_TIME_T_FMT " IN IP4 %s\n"
+			 "s=FreeSWITCH\n" "c=IN IP4 %s\n" "t=0 0\n" "a=%s\n" "m=audio %d RTP/AVP", port, now, port, now, ip, ip, sr, port);
 
 	if (tech_pvt->rm_encoding) {
 		snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " %d", tech_pvt->pt);
@@ -781,9 +725,9 @@
 			const switch_codec_implementation_t *imp = tech_pvt->codecs[i];
 
 			snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " %d", imp->ianacode);
-            if (!ptime) {
-                ptime = imp->microseconds_per_frame / 1000;
-            }
+			if (!ptime) {
+				ptime = imp->microseconds_per_frame / 1000;
+			}
 		}
 	}
 
@@ -803,8 +747,8 @@
 		if (tech_pvt->fmtp_out) {
 			snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=fmtp:%d %s\n", tech_pvt->pt, tech_pvt->fmtp_out);
 		}
-		if (tech_pvt->read_codec.implementation && ! ptime) {
-            ptime = tech_pvt->read_codec.implementation->microseconds_per_frame / 1000;
+		if (tech_pvt->read_codec.implementation && !ptime) {
+			ptime = tech_pvt->read_codec.implementation->microseconds_per_frame / 1000;
 		}
 
 	} else if (tech_pvt->num_codecs) {
@@ -812,14 +756,14 @@
 		for (i = 0; i < tech_pvt->num_codecs; i++) {
 			const switch_codec_implementation_t *imp = tech_pvt->codecs[i];
 			uint32_t rfc_3551_sucks = imp->samples_per_second;
-			
+
 			if (!rate) {
 				rate = imp->samples_per_second;
 			}
-            if (ptime && ptime != imp->microseconds_per_frame / 1000) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "ptime %u != advertised ptime %u\n", imp->microseconds_per_frame / 1000, ptime);
-            }
-			
+			if (ptime && ptime != imp->microseconds_per_frame / 1000) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "ptime %u != advertised ptime %u\n", imp->microseconds_per_frame / 1000, ptime);
+			}
+
 			if (rfc_3551_sucks && imp->ianacode == 9) {
 				rfc_3551_sucks = 8000;
 			}
@@ -830,7 +774,7 @@
 			}
 		}
 	}
-	
+
 	if (tech_pvt->te > 95) {
 		snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=rtpmap:%d telephone-event/8000\na=fmtp:%d 0-16\n", tech_pvt->te, tech_pvt->te);
 	}
@@ -840,18 +784,18 @@
 			tech_pvt->cng_pt = 0;
 		}
 	}
-    if (ptime) {
-        snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=ptime:%d\n", ptime);
-    }
+	if (ptime) {
+		snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=ptime:%d\n", ptime);
+	}
 
 	tech_pvt->local_sdp_str = switch_core_session_strdup(tech_pvt->session, buf);
 }
 
-static void tech_set_codecs(private_object_t *tech_pvt)
+static void tech_set_codecs(private_object_t * tech_pvt)
 {
-    switch_channel_t *channel;
-    char *abs, *codec_string = NULL;
-    char *ocodec = NULL;
+	switch_channel_t *channel;
+	char *abs, *codec_string = NULL;
+	char *ocodec = NULL;
 
 	if (switch_test_flag(tech_pvt, TFLAG_NOMEDIA)) {
 		return;
@@ -861,53 +805,49 @@
 		return;
 	}
 
-    assert(tech_pvt->session != NULL);
+	assert(tech_pvt->session != NULL);
 
-    channel = switch_core_session_get_channel(tech_pvt->session);
-    assert (channel != NULL);
+	channel = switch_core_session_get_channel(tech_pvt->session);
+	assert(channel != NULL);
 
 
-    if ((abs = switch_channel_get_variable(channel, "absolute_codec_string"))) {
-        codec_string = abs;
-    } else {
-        if (!(codec_string = switch_channel_get_variable(channel, "codec_string"))) {
+	if ((abs = switch_channel_get_variable(channel, "absolute_codec_string"))) {
+		codec_string = abs;
+	} else {
+		if (!(codec_string = switch_channel_get_variable(channel, "codec_string"))) {
 			if (tech_pvt->profile->codec_string) {
 				codec_string = tech_pvt->profile->codec_string;
 			}
-        }
-        
-        if ((ocodec = switch_channel_get_variable(channel, SWITCH_ORIGINATOR_CODEC_VARIABLE))) {
-            if (!codec_string || (tech_pvt->profile->pflags & PFLAG_DISABLE_TRANSCODING)) {
-                codec_string = ocodec;
-            } else {
+		}
+
+		if ((ocodec = switch_channel_get_variable(channel, SWITCH_ORIGINATOR_CODEC_VARIABLE))) {
+			if (!codec_string || (tech_pvt->profile->pflags & PFLAG_DISABLE_TRANSCODING)) {
+				codec_string = ocodec;
+			} else {
 				if (!(codec_string = switch_core_session_sprintf(tech_pvt->session, "%s,%s", ocodec, codec_string))) {
 					codec_string = ocodec;
 				}
-            }
-        }
-    }
+			}
+		}
+	}
 
 	if (codec_string) {
 		char *tmp_codec_string;
 		if ((tmp_codec_string = switch_core_session_strdup(tech_pvt->session, codec_string))) {
 			tech_pvt->codec_order_last = switch_separate_string(tmp_codec_string, ',', tech_pvt->codec_order, SWITCH_MAX_CODECS);
-			tech_pvt->num_codecs = switch_loadable_module_get_codecs_sorted(tech_pvt->codecs,
-																			SWITCH_MAX_CODECS,
-																			tech_pvt->codec_order,
-																			tech_pvt->codec_order_last);
+			tech_pvt->num_codecs =
+				switch_loadable_module_get_codecs_sorted(tech_pvt->codecs, SWITCH_MAX_CODECS, tech_pvt->codec_order, tech_pvt->codec_order_last);
 		}
 	} else {
-		tech_pvt->num_codecs = switch_loadable_module_get_codecs(switch_core_session_get_pool(tech_pvt->session), tech_pvt->codecs,
-																 sizeof(tech_pvt->codecs) / sizeof(tech_pvt->codecs[0]));
+		tech_pvt->num_codecs =
+			switch_loadable_module_get_codecs(switch_core_session_get_pool(tech_pvt->session), tech_pvt->codecs,
+											  sizeof(tech_pvt->codecs) / sizeof(tech_pvt->codecs[0]));
 	}
 
 }
 
 
-static void attach_private(switch_core_session_t *session,
-						   sofia_profile_t *profile,
-						   private_object_t *tech_pvt,
-						   const char *channame)
+static void attach_private(switch_core_session_t *session, sofia_profile_t * profile, private_object_t * tech_pvt, const char *channame)
 {
 	switch_channel_t *channel;
 	char name[256];
@@ -918,9 +858,9 @@
 
 	switch_core_session_add_stream(session, NULL);
 	channel = switch_core_session_get_channel(session);
-	
+
 	//switch_channel_set_flag(channel, CF_ACCEPT_CNG);
-	
+
 	switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
 	switch_mutex_lock(tech_pvt->flag_mutex);
 	tech_pvt->flags = profile->flags;
@@ -940,47 +880,44 @@
 
 	tech_pvt->session = session;
 	tech_pvt->home = su_home_new(sizeof(*tech_pvt->home));
-	
+
 	switch_core_session_set_private(session, tech_pvt);
 
 
 	snprintf(name, sizeof(name), "sofia/%s/%s", profile->name, channame);
-    switch_channel_set_name(channel, name);
+	switch_channel_set_name(channel, name);
 	//tech_set_codecs(tech_pvt);
 
 }
 
 static void terminate_session(switch_core_session_t **session, switch_call_cause_t cause, int line)
 {
-    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Term called from line: %d\n", line);
-    if (*session) {
-        switch_channel_t *channel = switch_core_session_get_channel(*session);
-        struct private_object *tech_pvt = NULL;
-        unsigned running = switch_core_session_running(*session);
-        tech_pvt = switch_core_session_get_private(*session);
-
-        if (running) {
-            switch_channel_hangup(channel, cause);
-        } else {
-            if (tech_pvt) {
-                sofia_on_hangup(*session);
-            }
-            if (session && *session) {
-                switch_core_session_destroy(session);
-            }
-        }
-    }
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Term called from line: %d\n", line);
+	if (*session) {
+		switch_channel_t *channel = switch_core_session_get_channel(*session);
+		struct private_object *tech_pvt = NULL;
+		unsigned running = switch_core_session_running(*session);
+		tech_pvt = switch_core_session_get_private(*session);
+
+		if (running) {
+			switch_channel_hangup(channel, cause);
+		} else {
+			if (tech_pvt) {
+				sofia_on_hangup(*session);
+			}
+			if (session && *session) {
+				switch_core_session_destroy(session);
+			}
+		}
+	}
 }
 
 
 
-static switch_status_t sofia_ext_address_lookup(char **ip, 
-												  switch_port_t *port,
-												  char *sourceip,
-												  switch_memory_pool_t *pool)
+static switch_status_t sofia_ext_address_lookup(char **ip, switch_port_t *port, char *sourceip, switch_memory_pool_t *pool)
 {
 	char *error;
-	
+
 	if (!sourceip) {
 		return SWITCH_STATUS_FALSE;
 	}
@@ -991,12 +928,7 @@
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Stun Failed! NO STUN SERVER\n");
 			return SWITCH_STATUS_FALSE;
 		}
-		if (switch_stun_lookup(ip,
-							   port,
-							   stun_ip,
-							   SWITCH_STUN_DEFAULT_PORT,
-							   &error,
-							   pool) != SWITCH_STATUS_SUCCESS) {
+		if (switch_stun_lookup(ip, port, stun_ip, SWITCH_STUN_DEFAULT_PORT, &error, pool) != SWITCH_STATUS_SUCCESS) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Stun Failed! %s:%d [%s]\n", stun_ip, SWITCH_STUN_DEFAULT_PORT, error);
 			return SWITCH_STATUS_FALSE;
 		}
@@ -1008,7 +940,7 @@
 }
 
 
-static switch_status_t tech_choose_port(private_object_t *tech_pvt)
+static switch_status_t tech_choose_port(private_object_t * tech_pvt)
 {
 	char *ip = tech_pvt->profile->rtpip;
 	switch_channel_t *channel;
@@ -1016,22 +948,20 @@
 	char tmp[50];
 
 	channel = switch_core_session_get_channel(tech_pvt->session);
-	
+
 	if (switch_test_flag(tech_pvt, TFLAG_NOMEDIA) || tech_pvt->adv_sdp_audio_port) {
 		return SWITCH_STATUS_SUCCESS;
 	}
-	
+
 	tech_pvt->local_sdp_audio_ip = ip;
 	tech_pvt->local_sdp_audio_port = switch_rtp_request_port();
 	sdp_port = tech_pvt->local_sdp_audio_port;
 
 	if (tech_pvt->profile->extrtpip) {
-		if (sofia_ext_address_lookup(&ip,
-									&sdp_port,
-									tech_pvt->profile->extrtpip,
-									switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
-				terminate_session(&tech_pvt->session, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __LINE__);
-				return SWITCH_STATUS_FALSE;
+		if (sofia_ext_address_lookup(&ip, &sdp_port, tech_pvt->profile->extrtpip, switch_core_session_get_pool(tech_pvt->session)) !=
+			SWITCH_STATUS_SUCCESS) {
+			terminate_session(&tech_pvt->session, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __LINE__);
+			return SWITCH_STATUS_FALSE;
 		}
 	}
 
@@ -1041,7 +971,7 @@
 	snprintf(tmp, sizeof(tmp), "%d", sdp_port);
 	switch_channel_set_variable(channel, SWITCH_LOCAL_MEDIA_IP_VARIABLE, tech_pvt->adv_sdp_audio_ip);
 	switch_channel_set_variable(channel, SWITCH_LOCAL_MEDIA_PORT_VARIABLE, tmp);
-	
+
 
 	return SWITCH_STATUS_SUCCESS;
 }
@@ -1055,12 +985,12 @@
 	char *forwardbuf;
 	int forwardval;
 	private_object_t *tech_pvt;
-    switch_channel_t *channel = NULL;
+	switch_channel_t *channel = NULL;
 	switch_caller_profile_t *caller_profile;
 	char *cid_name, *cid_num;
 	char *e_dest = NULL;
 	const char *holdstr = "";
-	switch_stream_handle_t stream = {0};
+	switch_stream_handle_t stream = { 0 };
 	switch_hash_index_t *hi;
 	void *vval;
 	char *extra_headers = NULL;
@@ -1068,26 +998,25 @@
 	switch_status_t status = SWITCH_STATUS_FALSE;
 	char *rep;
 
-    channel = switch_core_session_get_channel(session);
-    assert(channel != NULL);
+	channel = switch_core_session_get_channel(session);
+	assert(channel != NULL);
 
 	rep = switch_channel_get_variable(channel, SOFIA_REPLACES_HEADER);
 
-    tech_pvt = (private_object_t *) switch_core_session_get_private(session);
-    assert(tech_pvt != NULL);
+	tech_pvt = (private_object_t *) switch_core_session_get_private(session);
+	assert(tech_pvt != NULL);
 
 	caller_profile = switch_channel_get_caller_profile(channel);
 
 	cid_name = (char *) caller_profile->caller_id_name;
 	cid_num = (char *) caller_profile->caller_id_number;
-    tech_set_codecs(tech_pvt);
+	tech_set_codecs(tech_pvt);
 
 	if (!tech_pvt->from_str) {
-		tech_pvt->from_str = switch_core_session_sprintf(tech_pvt->session, "\"%s\" <sip:%s@%s>", 
+		tech_pvt->from_str = switch_core_session_sprintf(tech_pvt->session, "\"%s\" <sip:%s@%s>",
 														 cid_name,
-														 cid_num,
-														 tech_pvt->profile->extsipip ? tech_pvt->profile->extsipip : tech_pvt->profile->sipip);
-		
+														 cid_num, tech_pvt->profile->extsipip ? tech_pvt->profile->extsipip : tech_pvt->profile->sipip);
+
 	}
 
 	if (!tech_pvt->from_str) {
@@ -1110,7 +1039,7 @@
 	if (tech_choose_port(tech_pvt) != SWITCH_STATUS_SUCCESS) {
 		return status;
 	}
-        
+
 	set_local_sdp(tech_pvt, NULL, 0, NULL, 0);
 
 	switch_set_flag_locked(tech_pvt, TFLAG_READY);
@@ -1132,16 +1061,14 @@
 		}
 
 		snprintf(rpid, sizeof(rpid) - 1, "Remote-Party-ID: %s;party=calling;screen=%s;privacy=%s", tech_pvt->from_str, screen, priv);
-								
+
 	}
 
 	if (!tech_pvt->nh) {
-		char *url =  get_url_from_contact(tech_pvt->dest, 1);
+		char *url = get_url_from_contact(tech_pvt->dest, 1);
 		tech_pvt->nh = nua_handle(tech_pvt->profile->nua, NULL,
 								  NUTAG_URL(url),
-								  SIPTAG_TO_STR(tech_pvt->dest_to),
-								  SIPTAG_FROM_STR(tech_pvt->from_str),
-								  SIPTAG_CONTACT_STR(tech_pvt->profile->url),
+								  SIPTAG_TO_STR(tech_pvt->dest_to), SIPTAG_FROM_STR(tech_pvt->from_str), SIPTAG_CONTACT_STR(tech_pvt->profile->url),
 								  TAG_END());
 		switch_safe_free(url);
 
@@ -1168,7 +1095,7 @@
 		tech_pvt->chat_to = tech_pvt->dest;
 		tech_pvt->hash_key = switch_core_session_strdup(tech_pvt->session, hash_key);
 		switch_core_hash_insert(tech_pvt->profile->chat_hash, tech_pvt->hash_key, tech_pvt);
-		free(e_dest);			
+		free(e_dest);
 	}
 
 	holdstr = switch_test_flag(tech_pvt, TFLAG_SIP_HOLD) ? "*" : "";
@@ -1187,7 +1114,7 @@
 			}
 		}
 	}
-		
+
 	if (stream.data) {
 		extra_headers = stream.data;
 	}
@@ -1196,19 +1123,16 @@
 			   TAG_IF(!switch_strlen_zero(rpid), SIPTAG_HEADER_STR(rpid)),
 			   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(!switch_strlen_zero(max_forwards), SIPTAG_MAX_FORWARDS_STR(max_forwards)),
 			   //SIPTAG_CONTACT_STR(tech_pvt->profile->url),
 			   SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
 			   SOATAG_RTP_SORT(SOA_RTP_SORT_REMOTE),
-			   SOATAG_RTP_SELECT(SOA_RTP_SELECT_ALL),
-			   TAG_IF(rep, SIPTAG_REPLACES_STR(rep)),
-			   SOATAG_HOLD(holdstr),
-			   TAG_END());
-		
+			   SOATAG_RTP_SELECT(SOA_RTP_SELECT_ALL), TAG_IF(rep, SIPTAG_REPLACES_STR(rep)), SOATAG_HOLD(holdstr), TAG_END());
+
 	switch_safe_free(stream.data);
 
 	return SWITCH_STATUS_SUCCESS;
-	
+
 }
 
 
@@ -1217,67 +1141,61 @@
 {
 	char rpid[1024];
 	private_object_t *tech_pvt;
-    switch_channel_t *channel = NULL;
+	switch_channel_t *channel = NULL;
 	switch_caller_profile_t *caller_profile;
 
-    channel = switch_core_session_get_channel(session);
-    assert(channel != NULL);
+	channel = switch_core_session_get_channel(session);
+	assert(channel != NULL);
 
-    tech_pvt = (private_object_t *) switch_core_session_get_private(session);
-    assert(tech_pvt != NULL);
+	tech_pvt = (private_object_t *) switch_core_session_get_private(session);
+	assert(tech_pvt != NULL);
 
 	caller_profile = switch_channel_get_caller_profile(channel);
 
-	
 
-	if ((tech_pvt->from_str = switch_core_session_sprintf(session, "\"%s\" <sip:%s@%s>", 
-														 (char *) caller_profile->caller_id_name, 
-														 (char *) caller_profile->caller_id_number,
-														 tech_pvt->profile->extsipip ? tech_pvt->profile->extsipip : tech_pvt->profile->sipip
-														 ))) {
+
+	if ((tech_pvt->from_str = switch_core_session_sprintf(session, "\"%s\" <sip:%s@%s>",
+														  (char *) caller_profile->caller_id_name,
+														  (char *) caller_profile->caller_id_number,
+														  tech_pvt->profile->extsipip ? tech_pvt->profile->extsipip : tech_pvt->profile->sipip))) {
 
 		char *rep = switch_channel_get_variable(channel, SOFIA_REPLACES_HEADER);
 
 		tech_pvt->nh2 = nua_handle(tech_pvt->profile->nua, NULL,
-								  SIPTAG_TO_STR(tech_pvt->dest),
-								  SIPTAG_FROM_STR(tech_pvt->from_str),
-								  SIPTAG_CONTACT_STR(tech_pvt->profile->url),
-								  TAG_END());
-			
-        
+								   SIPTAG_TO_STR(tech_pvt->dest), SIPTAG_FROM_STR(tech_pvt->from_str), SIPTAG_CONTACT_STR(tech_pvt->profile->url),
+								   TAG_END());
+
+
 		nua_handle_bind(tech_pvt->nh2, tech_pvt->sofia_private);
 
 		nua_invite(tech_pvt->nh2,
 				   TAG_IF(rpid, SIPTAG_HEADER_STR(rpid)),
 				   SIPTAG_CONTACT_STR(tech_pvt->profile->url),
 				   SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
-				   SOATAG_RTP_SORT(SOA_RTP_SORT_REMOTE),
-				   SOATAG_RTP_SELECT(SOA_RTP_SELECT_ALL),
-				   TAG_IF(rep, SIPTAG_REPLACES_STR(rep)),
-				   TAG_END());
+				   SOATAG_RTP_SORT(SOA_RTP_SORT_REMOTE), SOATAG_RTP_SELECT(SOA_RTP_SELECT_ALL), TAG_IF(rep, SIPTAG_REPLACES_STR(rep)), TAG_END());
 	} else {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error!\n");
 	}
-	
+
 }
 
-static void tech_absorb_sdp(private_object_t *tech_pvt)
+static void tech_absorb_sdp(private_object_t * tech_pvt)
 {
 	switch_channel_t *channel;
 	char *sdp_str;
 
 	channel = switch_core_session_get_channel(tech_pvt->session);
 	assert(channel != NULL);
-	
+
 	if ((sdp_str = switch_channel_get_variable(channel, SWITCH_B_SDP_VARIABLE))) {
 		sdp_parser_t *parser;
 		sdp_session_t *sdp;
 		sdp_media_t *m;
 		sdp_connection_t *connection;
 
-		if ((parser = sdp_parse(tech_pvt->home, sdp_str, (int)strlen(sdp_str), 0))) {
+		if ((parser = sdp_parse(tech_pvt->home, sdp_str, (int) strlen(sdp_str), 0))) {
 			if ((sdp = sdp_session(parser))) {
-				for (m = sdp->sdp_media; m ; m = m->m_next) {
+				for (m = sdp->sdp_media; m; m = m->m_next) {
 					if (m->m_type != sdp_media_audio) {
 						continue;
 					}
@@ -1290,14 +1208,14 @@
 					if (connection) {
 						tech_pvt->proxy_sdp_audio_ip = switch_core_session_strdup(tech_pvt->session, connection->c_address);
 					}
-					tech_pvt->proxy_sdp_audio_port = (switch_port_t)m->m_port;
+					tech_pvt->proxy_sdp_audio_port = (switch_port_t) m->m_port;
 					if (tech_pvt->proxy_sdp_audio_ip && tech_pvt->proxy_sdp_audio_port) {
 						break;
 					}
 				}
 			}
 			sdp_parser_free(parser);
-		}	
+		}
 		tech_pvt->local_sdp_str = switch_core_session_strdup(tech_pvt->session, sdp_str);
 	}
 }
@@ -1311,7 +1229,7 @@
 {
 	private_object_t *tech_pvt;
 	switch_channel_t *channel = NULL;
-	
+
 	channel = switch_core_session_get_channel(session);
 	assert(channel != NULL);
 
@@ -1331,7 +1249,7 @@
 			return SWITCH_STATUS_FALSE;
 		}
 	}
-	
+
 	/* Move Channel's State Machine to RING */
 	switch_channel_set_state(channel, CS_RING);
 	return SWITCH_STATUS_SUCCESS;
@@ -1371,7 +1289,8 @@
 }
 
 // map QSIG cause codes to SIP from RFC4497 section 8.4.1
-static int hangup_cause_to_sip(switch_call_cause_t cause) {
+static int hangup_cause_to_sip(switch_call_cause_t cause)
+{
 	switch (cause) {
 	case SWITCH_CAUSE_NO_ROUTE_TRANSIT_NET:
 	case SWITCH_CAUSE_NO_ROUTE_DESTINATION:
@@ -1405,7 +1324,7 @@
 		return 503;
 	case SWITCH_CAUSE_OUTGOING_CALL_BARRED:
 	case SWITCH_CAUSE_INCOMING_CALL_BARRED:
-	case SWITCH_CAUSE_BEARERCAPABILITY_NOTAUTH: 
+	case SWITCH_CAUSE_BEARERCAPABILITY_NOTAUTH:
 		return 403;
 	case SWITCH_CAUSE_BEARERCAPABILITY_NOTAVAIL:
 		return 503;
@@ -1445,7 +1364,7 @@
 
 	deactivate_rtp(tech_pvt);
 
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Channel %s hanging up, cause: %s\n", 
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Channel %s hanging up, cause: %s\n",
 					  switch_channel_get_name(channel), switch_channel_cause2str(cause));
 
 	if (tech_pvt->hash_key) {
@@ -1483,9 +1402,9 @@
 		tech_pvt->home = NULL;
 	}
 
-    if (tech_pvt->sofia_private) {
-        *tech_pvt->sofia_private->uuid = '\0';
-    }
+	if (tech_pvt->sofia_private) {
+		*tech_pvt->sofia_private->uuid = '\0';
+	}
 
 	return SWITCH_STATUS_SUCCESS;
 }
@@ -1502,9 +1421,9 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static void deactivate_rtp(private_object_t *tech_pvt)
+static void deactivate_rtp(private_object_t * tech_pvt)
 {
-	int loops = 0;//, sock = -1;
+	int loops = 0;				//, sock = -1;
 	if (switch_rtp_ready(tech_pvt->rtp_session)) {
 		while (loops < 10 && (switch_test_flag(tech_pvt, TFLAG_READING) || switch_test_flag(tech_pvt, TFLAG_WRITING))) {
 			switch_yield(10000);
@@ -1514,7 +1433,7 @@
 	}
 }
 
-static switch_status_t tech_set_codec(private_object_t *tech_pvt, int force)
+static switch_status_t tech_set_codec(private_object_t * tech_pvt, int force)
 {
 	switch_channel_t *channel;
 
@@ -1527,12 +1446,11 @@
 
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Changing Codec from %s to %s\n",
 							  tech_pvt->read_codec.implementation->iananame, tech_pvt->rm_encoding);
-		switch_core_codec_destroy(&tech_pvt->read_codec);
-		switch_core_codec_destroy(&tech_pvt->write_codec);
-		switch_core_session_reset(tech_pvt->session);
+			switch_core_codec_destroy(&tech_pvt->read_codec);
+			switch_core_codec_destroy(&tech_pvt->write_codec);
+			switch_core_session_reset(tech_pvt->session);
 		} else {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Already using %s\n",
-							  tech_pvt->read_codec.implementation->iananame);
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Already using %s\n", tech_pvt->read_codec.implementation->iananame);
 			return SWITCH_STATUS_SUCCESS;
 		}
 	}
@@ -1546,15 +1464,14 @@
 		return SWITCH_STATUS_FALSE;
 	}
 
-	if (switch_core_codec_init(&tech_pvt->read_codec,  
+	if (switch_core_codec_init(&tech_pvt->read_codec,
 							   tech_pvt->rm_encoding,
 							   tech_pvt->rm_fmtp,
 							   tech_pvt->rm_rate,
 							   tech_pvt->codec_ms,
 							   1,
 							   SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE | tech_pvt->profile->codec_flags,
-							   NULL,
-							   switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
+							   NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n");
 		terminate_session(&tech_pvt->session, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __LINE__);
 		return SWITCH_STATUS_FALSE;
@@ -1566,8 +1483,7 @@
 								   tech_pvt->codec_ms,
 								   1,
 								   SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE | tech_pvt->profile->codec_flags,
-								   NULL,
-								   switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
+								   NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n");
 			terminate_session(&tech_pvt->session, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __LINE__);
 			return SWITCH_STATUS_FALSE;
@@ -1576,10 +1492,9 @@
 			tech_pvt->read_frame.rate = tech_pvt->rm_rate;
 			ms = tech_pvt->write_codec.implementation->microseconds_per_frame / 1000;
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set Codec %s %s/%ld %d ms\n",
-							  switch_channel_get_name(channel),
-							  tech_pvt->rm_encoding, tech_pvt->rm_rate, tech_pvt->codec_ms);
+							  switch_channel_get_name(channel), tech_pvt->rm_encoding, tech_pvt->rm_rate, tech_pvt->codec_ms);
 			tech_pvt->read_frame.codec = &tech_pvt->read_codec;
-				
+
 			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);
@@ -1589,12 +1504,12 @@
 }
 
 
-static switch_status_t activate_rtp(private_object_t *tech_pvt)
+static switch_status_t activate_rtp(private_object_t * tech_pvt)
 {
 	int bw, ms;
 	switch_channel_t *channel;
 	const char *err = NULL;
-    char *val = NULL;
+	char *val = NULL;
 	switch_rtp_flag_t flags;
 	switch_status_t status;
 	char tmp[50];
@@ -1614,7 +1529,7 @@
 	if ((status = tech_set_codec(tech_pvt, 0)) != SWITCH_STATUS_SUCCESS) {
 		return status;
 	}
-	
+
 	bw = tech_pvt->read_codec.implementation->bits_per_second;
 	ms = tech_pvt->read_codec.implementation->microseconds_per_frame;
 
@@ -1624,9 +1539,10 @@
 		flags |= SWITCH_RTP_FLAG_BUGGY_2833;
 	}
 
-    if ((tech_pvt->profile->pflags & PFLAG_PASS_RFC2833) || ((val = switch_channel_get_variable(channel, "pass_rfc2833")) && switch_true(val))) {
-        flags |= SWITCH_RTP_FLAG_PASS_RFC2833;
-    }
+	if ((tech_pvt->profile->pflags & PFLAG_PASS_RFC2833)
+		|| ((val = switch_channel_get_variable(channel, "pass_rfc2833")) && switch_true(val))) {
+		flags |= SWITCH_RTP_FLAG_PASS_RFC2833;
+	}
 
 	if (tech_pvt->cng_pt) {
 		flags |= SWITCH_RTP_FLAG_AUTO_CNG;
@@ -1637,27 +1553,23 @@
 					  tech_pvt->local_sdp_audio_ip,
 					  tech_pvt->local_sdp_audio_port,
 					  tech_pvt->remote_sdp_audio_ip,
-					  tech_pvt->remote_sdp_audio_port,
-					  tech_pvt->agreed_pt,
-					  tech_pvt->read_codec.implementation->microseconds_per_frame / 1000);
+					  tech_pvt->remote_sdp_audio_port, tech_pvt->agreed_pt, tech_pvt->read_codec.implementation->microseconds_per_frame / 1000);
 
 	snprintf(tmp, sizeof(tmp), "%d", tech_pvt->remote_sdp_audio_port);
 	switch_channel_set_variable(channel, SWITCH_LOCAL_MEDIA_IP_VARIABLE, tech_pvt->adv_sdp_audio_ip);
 	switch_channel_set_variable(channel, SWITCH_LOCAL_MEDIA_PORT_VARIABLE, tmp);
-	
+
 	if (tech_pvt->rtp_session && switch_test_flag(tech_pvt, TFLAG_REINVITE)) {
 		switch_clear_flag_locked(tech_pvt, TFLAG_REINVITE);
-		
-		if (switch_rtp_set_remote_address(tech_pvt->rtp_session,
-										  tech_pvt->remote_sdp_audio_ip,
-										  tech_pvt->remote_sdp_audio_port,
-										  &err) != SWITCH_STATUS_SUCCESS) {
+
+		if (switch_rtp_set_remote_address(tech_pvt->rtp_session, tech_pvt->remote_sdp_audio_ip, tech_pvt->remote_sdp_audio_port, &err) !=
+			SWITCH_STATUS_SUCCESS) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "RTP REPORTS ERROR: [%s]\n", err);
 		} else {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "RTP CHANGING DEST TO: [%s:%d]\n", 
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "RTP CHANGING DEST TO: [%s:%d]\n",
 							  tech_pvt->remote_sdp_audio_ip, tech_pvt->remote_sdp_audio_port);
-            /* Reactivate the NAT buster flag. */
-            switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_AUTOADJ);
+			/* Reactivate the NAT buster flag. */
+			switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_AUTOADJ);
 		}
 		return SWITCH_STATUS_SUCCESS;
 	}
@@ -1670,11 +1582,8 @@
 										   tech_pvt->read_codec.implementation->samples_per_frame,
 										   tech_pvt->codec_ms * 1000,
 										   (switch_rtp_flag_t) flags,
-										   NULL,
-										   tech_pvt->profile->timer_name,
-										   &err,
-										   switch_core_session_get_pool(tech_pvt->session));
-	
+										   NULL, tech_pvt->profile->timer_name, &err, switch_core_session_get_pool(tech_pvt->session));
+
 	if (switch_rtp_ready(tech_pvt->rtp_session)) {
 		uint8_t vad_in = switch_test_flag(tech_pvt, TFLAG_VAD_IN) ? 1 : 0;
 		uint8_t vad_out = switch_test_flag(tech_pvt, TFLAG_VAD_OUT) ? 1 : 0;
@@ -1683,13 +1592,12 @@
 		tech_pvt->ssrc = switch_rtp_get_ssrc(tech_pvt->rtp_session);
 		switch_set_flag_locked(tech_pvt, TFLAG_RTP);
 		switch_set_flag_locked(tech_pvt, TFLAG_IO);
-		
+
 		if ((vad_in && inb) || (vad_out && !inb)) {
 			switch_rtp_enable_vad(tech_pvt->rtp_session, tech_pvt->session, &tech_pvt->read_codec, SWITCH_VAD_FLAG_TALKING);
 			switch_set_flag_locked(tech_pvt, TFLAG_VAD);
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "RTP Engage VAD for %s ( %s %s )\n", 
-                              switch_channel_get_name(switch_core_session_get_channel(tech_pvt->session)),
-                              vad_in ? "in" : "", vad_out ? "out" : "");
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "RTP Engage VAD for %s ( %s %s )\n",
+							  switch_channel_get_name(switch_core_session_get_channel(tech_pvt->session)), vad_in ? "in" : "", vad_out ? "out" : "");
 		}
 
 		if (tech_pvt->te) {
@@ -1698,53 +1606,53 @@
 		if (tech_pvt->cng_pt) {
 			switch_rtp_set_cng_pt(tech_pvt->rtp_session, tech_pvt->cng_pt);
 		}
-		
+
 	} else {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "RTP REPORTS ERROR: [%s]\n", err);
 		terminate_session(&tech_pvt->session, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __LINE__);
 		switch_clear_flag_locked(tech_pvt, TFLAG_IO);
 		return SWITCH_STATUS_FALSE;
 	}
-		
+
 	switch_set_flag_locked(tech_pvt, TFLAG_IO);
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t tech_media(private_object_t *tech_pvt, char *r_sdp)
+static switch_status_t tech_media(private_object_t * tech_pvt, char *r_sdp)
 {
-    sdp_parser_t *parser = sdp_parse(tech_pvt->home, r_sdp, (int)strlen(r_sdp), 0);
-    sdp_session_t *sdp;
-    uint8_t match = 0;
-    switch_channel_t *channel = switch_core_session_get_channel(tech_pvt->session);
-
-    assert(tech_pvt != NULL);
-
-    if (switch_strlen_zero(r_sdp)) {
-        return SWITCH_STATUS_FALSE;
-    }
-
-    if (tech_pvt->num_codecs) {
-        if ((sdp = sdp_session(parser))) {
-            match = negotiate_sdp(tech_pvt->session, sdp);
-        }
-    }
-
-    if (parser) {
-        sdp_parser_free(parser);
-    }
-
-    if (match) {
-        if (tech_choose_port(tech_pvt) != SWITCH_STATUS_SUCCESS) {
-            return SWITCH_STATUS_FALSE;
-        }
-        activate_rtp(tech_pvt);
-        switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "EARLY MEDIA");
-        switch_set_flag_locked(tech_pvt, TFLAG_EARLY_MEDIA);
-        switch_channel_mark_pre_answered(channel);
-        return SWITCH_STATUS_SUCCESS;
-    }
-    
-    return SWITCH_STATUS_FALSE;
+	sdp_parser_t *parser = sdp_parse(tech_pvt->home, r_sdp, (int) strlen(r_sdp), 0);
+	sdp_session_t *sdp;
+	uint8_t match = 0;
+	switch_channel_t *channel = switch_core_session_get_channel(tech_pvt->session);
+
+	assert(tech_pvt != NULL);
+
+	if (switch_strlen_zero(r_sdp)) {
+		return SWITCH_STATUS_FALSE;
+	}
+
+	if (tech_pvt->num_codecs) {
+		if ((sdp = sdp_session(parser))) {
+			match = negotiate_sdp(tech_pvt->session, sdp);
+		}
+	}
+
+	if (parser) {
+		sdp_parser_free(parser);
+	}
+
+	if (match) {
+		if (tech_choose_port(tech_pvt) != SWITCH_STATUS_SUCCESS) {
+			return SWITCH_STATUS_FALSE;
+		}
+		activate_rtp(tech_pvt);
+		switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "EARLY MEDIA");
+		switch_set_flag_locked(tech_pvt, TFLAG_EARLY_MEDIA);
+		switch_channel_mark_pre_answered(channel);
+		return SWITCH_STATUS_SUCCESS;
+	}
+
+	return SWITCH_STATUS_FALSE;
 }
 
 
@@ -1762,7 +1670,7 @@
 
 	tech_pvt = (private_object_t *) switch_core_session_get_private(session);
 	assert(tech_pvt != NULL);
-    
+
 	if (!switch_test_flag(tech_pvt, TFLAG_ANS) && !switch_channel_test_flag(channel, CF_OUTBOUND)) {
 		switch_set_flag_locked(tech_pvt, TFLAG_ANS);
 
@@ -1789,34 +1697,29 @@
 
 			set_local_sdp(tech_pvt, NULL, 0, NULL, 0);
 			activate_rtp(tech_pvt);
-		
+
 			if (tech_pvt->nh) {
 				if (tech_pvt->local_sdp_str) {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Local SDP %s:\n%s\n",
-									  switch_channel_get_name(channel),
-								  tech_pvt->local_sdp_str);
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Local SDP %s:\n%s\n", switch_channel_get_name(channel),
+									  tech_pvt->local_sdp_str);
 				}
 			}
 		}
-		nua_respond(tech_pvt->nh, SIP_200_OK, 
+		nua_respond(tech_pvt->nh, SIP_200_OK,
 					SIPTAG_CONTACT_STR(tech_pvt->profile->url),
-					SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
-					SOATAG_AUDIO_AUX("cn telephone-event"),
-					NUTAG_INCLUDE_EXTRA_SDP(1),
-					TAG_END());
-	} 
+					SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str), SOATAG_AUDIO_AUX("cn telephone-event"), NUTAG_INCLUDE_EXTRA_SDP(1), TAG_END());
+	}
 
 	return SWITCH_STATUS_SUCCESS;
 }
 
 
-static switch_status_t sofia_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout,
-										switch_io_flag_t flags, int stream_id)
+static switch_status_t sofia_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, switch_io_flag_t flags, int stream_id)
 {
 	private_object_t *tech_pvt = NULL;
 	switch_channel_t *channel = NULL;
 	int payload = 0;
-	
+
 	channel = switch_core_session_get_channel(session);
 	assert(channel != NULL);
 
@@ -1839,9 +1742,9 @@
 	tech_pvt->read_frame.datalen = 0;
 	switch_set_flag_locked(tech_pvt, TFLAG_READING);
 
-#if 0	
+#if 0
 	if (tech_pvt->last_read) {
-		elapsed = (unsigned int)((switch_time_now() - tech_pvt->last_read) / 1000);
+		elapsed = (unsigned int) ((switch_time_now() - tech_pvt->last_read) / 1000);
 		if (elapsed > 60000) {
 			return SWITCH_STATUS_TIMEOUT;
 		}
@@ -1868,20 +1771,20 @@
 				return SWITCH_STATUS_FALSE;
 			}
 
-			
-			
+
+
 			payload = tech_pvt->read_frame.payload;
 
 #if 0
-			elapsed = (unsigned int)((switch_time_now() - started) / 1000);
+			elapsed = (unsigned int) ((switch_time_now() - started) / 1000);
 
 			if (timeout > -1) {
-				if (elapsed >= (unsigned int)timeout) {
+				if (elapsed >= (unsigned int) timeout) {
 					return SWITCH_STATUS_BREAK;
 				}
 			}
-			
-			elapsed = (unsigned int)((switch_time_now() - last_act) / 1000);
+
+			elapsed = (unsigned int) ((switch_time_now() - last_act) / 1000);
 			if (elapsed >= hard_timeout) {
 				return SWITCH_STATUS_BREAK;
 			}
@@ -1894,20 +1797,20 @@
 
 
 			if (tech_pvt->read_frame.datalen > 0) {
-                size_t bytes = 0;
-                int frames = 1;
+				size_t bytes = 0;
+				int frames = 1;
 
-                if (!switch_test_flag((&tech_pvt->read_frame), SFF_CNG)) {
-                    if ((bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame)) {
-                        frames = (tech_pvt->read_frame.datalen / bytes);
-                    }
-                    tech_pvt->read_frame.samples = (int) (frames * tech_pvt->read_codec.implementation->samples_per_frame);
-                }
+				if (!switch_test_flag((&tech_pvt->read_frame), SFF_CNG)) {
+					if ((bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame)) {
+						frames = (tech_pvt->read_frame.datalen / bytes);
+					}
+					tech_pvt->read_frame.samples = (int) (frames * tech_pvt->read_codec.implementation->samples_per_frame);
+				}
 				break;
 			}
 		}
 	}
-	
+
 	switch_clear_flag_locked(tech_pvt, TFLAG_READING);
 
 	if (tech_pvt->read_frame.datalen == 0) {
@@ -1921,8 +1824,7 @@
 }
 
 
-static switch_status_t sofia_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout,
-										 switch_io_flag_t flags, int stream_id)
+static switch_status_t sofia_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flags, int stream_id)
 {
 	private_object_t *tech_pvt;
 	switch_channel_t *channel = NULL;
@@ -1966,16 +1868,10 @@
 
 		samples = frames * tech_pvt->read_codec.implementation->samples_per_frame;
 	}
-
 #if 0
 	printf("%s %s->%s send %d bytes %d samples in %d frames ts=%d\n",
 		   switch_channel_get_name(channel),
-		   tech_pvt->local_sdp_audio_ip,
-		   tech_pvt->remote_sdp_audio_ip,
-		   frame->datalen,
-		   samples,
-		   frames,
-		   tech_pvt->timestamp_send);
+		   tech_pvt->local_sdp_audio_ip, tech_pvt->remote_sdp_audio_ip, frame->datalen, samples, frames, tech_pvt->timestamp_send);
 #endif
 
 	tech_pvt->timestamp_send += samples;
@@ -2000,22 +1896,22 @@
 	assert(tech_pvt != NULL);
 
 
-    switch(sig) {
-    case SWITCH_SIG_BREAK:
-        if (switch_rtp_ready(tech_pvt->rtp_session)) {
+	switch (sig) {
+	case SWITCH_SIG_BREAK:
+		if (switch_rtp_ready(tech_pvt->rtp_session)) {
 			switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_BREAK);
 		}
-        break;
-    case SWITCH_SIG_KILL:
-    default:
-        switch_clear_flag_locked(tech_pvt, TFLAG_IO);
-        switch_set_flag_locked(tech_pvt, TFLAG_HUP);
-
-        if (switch_rtp_ready(tech_pvt->rtp_session)) {
-            switch_rtp_kill_socket(tech_pvt->rtp_session);
-        }
-        break;
-    }
+		break;
+	case SWITCH_SIG_KILL:
+	default:
+		switch_clear_flag_locked(tech_pvt, TFLAG_IO);
+		switch_set_flag_locked(tech_pvt, TFLAG_HUP);
+
+		if (switch_rtp_ready(tech_pvt->rtp_session)) {
+			switch_rtp_kill_socket(tech_pvt->rtp_session);
+		}
+		break;
+	}
 
 	return SWITCH_STATUS_SUCCESS;
 
@@ -2056,78 +1952,78 @@
 	private_object_t *tech_pvt;
 
 	tech_pvt = (private_object_t *) switch_core_session_get_private(session);
-    assert(tech_pvt != NULL);
+	assert(tech_pvt != NULL);
 
 	return switch_rtp_queue_rfc2833(tech_pvt->rtp_session,
-									digits,
-									tech_pvt->profile->dtmf_duration * (tech_pvt->read_codec.implementation->samples_per_second / 1000));
-	
+									digits, tech_pvt->profile->dtmf_duration * (tech_pvt->read_codec.implementation->samples_per_second / 1000));
+
 }
 
 static switch_status_t sofia_receive_message(switch_core_session_t *session, switch_core_session_message_t *msg)
 {
 	switch_channel_t *channel;
 	private_object_t *tech_pvt;
-    switch_status_t status;
+	switch_status_t status;
 
 	channel = switch_core_session_get_channel(session);
 	assert(channel != NULL);
-			
+
 	tech_pvt = (private_object_t *) switch_core_session_get_private(session);
 	assert(tech_pvt != NULL);
 
 
 	switch (msg->message_id) {
-	case SWITCH_MESSAGE_INDICATE_NOMEDIA: {
-		char *uuid;
-		switch_core_session_t *other_session;
-		switch_channel_t *other_channel;
-		char *ip = NULL, *port = NULL;
+	case SWITCH_MESSAGE_INDICATE_NOMEDIA:{
+			char *uuid;
+			switch_core_session_t *other_session;
+			switch_channel_t *other_channel;
+			char *ip = NULL, *port = NULL;
 
-		switch_set_flag_locked(tech_pvt, TFLAG_NOMEDIA);
-		tech_pvt->local_sdp_str = NULL;
-		if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE)) && (other_session = switch_core_session_locate(uuid))) {
-			other_channel = switch_core_session_get_channel(other_session);
-			ip = switch_channel_get_variable(other_channel, SWITCH_REMOTE_MEDIA_IP_VARIABLE);
-			port = switch_channel_get_variable(other_channel, SWITCH_REMOTE_MEDIA_PORT_VARIABLE);
-			switch_core_session_rwunlock(other_session);
-			if (ip && port) {
-				set_local_sdp(tech_pvt, ip, atoi(port), NULL, 1);
+			switch_set_flag_locked(tech_pvt, TFLAG_NOMEDIA);
+			tech_pvt->local_sdp_str = NULL;
+			if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))
+				&& (other_session = switch_core_session_locate(uuid))) {
+				other_channel = switch_core_session_get_channel(other_session);
+				ip = switch_channel_get_variable(other_channel, SWITCH_REMOTE_MEDIA_IP_VARIABLE);
+				port = switch_channel_get_variable(other_channel, SWITCH_REMOTE_MEDIA_PORT_VARIABLE);
+				switch_core_session_rwunlock(other_session);
+				if (ip && port) {
+					set_local_sdp(tech_pvt, ip, atoi(port), NULL, 1);
+				}
 			}
+			if (!tech_pvt->local_sdp_str) {
+				tech_absorb_sdp(tech_pvt);
+			}
+			do_invite(session);
 		}
-		if (!tech_pvt->local_sdp_str) {
-			tech_absorb_sdp(tech_pvt);
-		}
-		do_invite(session);
-	}
 		break;
-	case SWITCH_MESSAGE_INDICATE_MEDIA: {
-		switch_clear_flag_locked(tech_pvt, TFLAG_NOMEDIA);
-		tech_pvt->local_sdp_str = NULL;
-		if (!switch_rtp_ready(tech_pvt->rtp_session)) {
-			tech_set_codecs(tech_pvt);
-			if ((status=tech_choose_port(tech_pvt)) != SWITCH_STATUS_SUCCESS) {
-                return status;
-            }
-		}
-		set_local_sdp(tech_pvt, NULL, 0, NULL, 1);
-		do_invite(session);
-		while (!switch_rtp_ready(tech_pvt->rtp_session) && switch_channel_get_state(channel) < CS_HANGUP) {
-			switch_yield(1000);
+	case SWITCH_MESSAGE_INDICATE_MEDIA:{
+			switch_clear_flag_locked(tech_pvt, TFLAG_NOMEDIA);
+			tech_pvt->local_sdp_str = NULL;
+			if (!switch_rtp_ready(tech_pvt->rtp_session)) {
+				tech_set_codecs(tech_pvt);
+				if ((status = tech_choose_port(tech_pvt)) != SWITCH_STATUS_SUCCESS) {
+					return status;
+				}
+			}
+			set_local_sdp(tech_pvt, NULL, 0, NULL, 1);
+			do_invite(session);
+			while (!switch_rtp_ready(tech_pvt->rtp_session) && switch_channel_get_state(channel) < CS_HANGUP) {
+				switch_yield(1000);
+			}
 		}
-	}
 		break;
 
-	case SWITCH_MESSAGE_INDICATE_HOLD: {
-		switch_set_flag_locked(tech_pvt, TFLAG_SIP_HOLD);
-		do_invite(session);
-	}
+	case SWITCH_MESSAGE_INDICATE_HOLD:{
+			switch_set_flag_locked(tech_pvt, TFLAG_SIP_HOLD);
+			do_invite(session);
+		}
 		break;
 
-	case SWITCH_MESSAGE_INDICATE_UNHOLD: {
-		switch_clear_flag_locked(tech_pvt, TFLAG_SIP_HOLD);
-		do_invite(session);
-	}
+	case SWITCH_MESSAGE_INDICATE_UNHOLD:{
+			switch_clear_flag_locked(tech_pvt, TFLAG_SIP_HOLD);
+			do_invite(session);
+		}
 		break;
 	case SWITCH_MESSAGE_INDICATE_BRIDGE:
 
@@ -2146,12 +2042,12 @@
 					a_tech_pvt->local_sdp_audio_ip = switch_core_session_strdup(a_session, b_tech_pvt->local_sdp_audio_ip);
 					a_tech_pvt->local_sdp_audio_port = b_tech_pvt->local_sdp_audio_port;
 					activate_rtp(a_tech_pvt);
-					
+
 					b_tech_pvt->kick = switch_core_session_strdup(b_session, tech_pvt->xferto);
-                    switch_core_session_rwunlock(a_session);
+					switch_core_session_rwunlock(a_session);
 				}
 
-				
+
 				msg->pointer_arg = NULL;
 				return SWITCH_STATUS_FALSE;
 			}
@@ -2168,7 +2064,7 @@
 		}
 		break;
 	case SWITCH_MESSAGE_INDICATE_REDIRECT:
-		if(msg->string_arg) {
+		if (msg->string_arg) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Re-directing to %s\n", msg->string_arg);
 			nua_respond(tech_pvt->nh, SIP_302_MOVED_TEMPORARILY, SIPTAG_CONTACT_STR(msg->string_arg), TAG_END());
 		}
@@ -2176,47 +2072,45 @@
 	case SWITCH_MESSAGE_INDICATE_RINGING:
 		nua_respond(tech_pvt->nh, SIP_180_RINGING, SIPTAG_CONTACT_STR(tech_pvt->profile->url), TAG_END());
 		break;
-	case SWITCH_MESSAGE_INDICATE_PROGRESS: {
-		if (!switch_test_flag(tech_pvt, TFLAG_ANS)) {
-			switch_set_flag_locked(tech_pvt, TFLAG_EARLY_MEDIA);
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Asked to send early media by %s\n", msg->from);
-
-			/* Transmit 183 Progress with SDP */
-			if (switch_channel_test_flag(channel, CF_NOMEDIA)) {
-				char *sdp = NULL;
-				switch_set_flag_locked(tech_pvt, TFLAG_NOMEDIA);
-				if ((sdp = switch_channel_get_variable(channel, SWITCH_B_SDP_VARIABLE))) {
-					tech_pvt->local_sdp_str = switch_core_session_strdup(session, sdp);
-				}
-			} else {
-				if (switch_test_flag(tech_pvt, TFLAG_LATE_NEGOTIATION)) {
-					char *r_sdp = switch_channel_get_variable(channel, SWITCH_R_SDP_VARIABLE);
-					if (tech_media(tech_pvt, r_sdp) != SWITCH_STATUS_SUCCESS) {
-						switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "CODEC NEGOTIATION ERROR");
-						nua_respond(tech_pvt->nh, SIP_488_NOT_ACCEPTABLE, TAG_END());
-						return SWITCH_STATUS_FALSE;
+	case SWITCH_MESSAGE_INDICATE_PROGRESS:{
+			if (!switch_test_flag(tech_pvt, TFLAG_ANS)) {
+				switch_set_flag_locked(tech_pvt, TFLAG_EARLY_MEDIA);
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Asked to send early media by %s\n", msg->from);
+
+				/* Transmit 183 Progress with SDP */
+				if (switch_channel_test_flag(channel, CF_NOMEDIA)) {
+					char *sdp = NULL;
+					switch_set_flag_locked(tech_pvt, TFLAG_NOMEDIA);
+					if ((sdp = switch_channel_get_variable(channel, SWITCH_B_SDP_VARIABLE))) {
+						tech_pvt->local_sdp_str = switch_core_session_strdup(session, sdp);
+					}
+				} else {
+					if (switch_test_flag(tech_pvt, TFLAG_LATE_NEGOTIATION)) {
+						char *r_sdp = switch_channel_get_variable(channel, SWITCH_R_SDP_VARIABLE);
+						if (tech_media(tech_pvt, r_sdp) != SWITCH_STATUS_SUCCESS) {
+							switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "CODEC NEGOTIATION ERROR");
+							nua_respond(tech_pvt->nh, SIP_488_NOT_ACCEPTABLE, TAG_END());
+							return SWITCH_STATUS_FALSE;
+						}
+						switch_clear_flag_locked(tech_pvt, TFLAG_LATE_NEGOTIATION);
 					}
-					switch_clear_flag_locked(tech_pvt, TFLAG_LATE_NEGOTIATION);
-				}
 
-				if ((status=tech_choose_port(tech_pvt)) != SWITCH_STATUS_SUCCESS) {
-					return status;
-				}
-				set_local_sdp(tech_pvt, NULL, 0, NULL, 0);
-				activate_rtp(tech_pvt);
-				if (tech_pvt->local_sdp_str) {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Ring SDP:\n%s\n", tech_pvt->local_sdp_str);
+					if ((status = tech_choose_port(tech_pvt)) != SWITCH_STATUS_SUCCESS) {
+						return status;
+					}
+					set_local_sdp(tech_pvt, NULL, 0, NULL, 0);
+					activate_rtp(tech_pvt);
+					if (tech_pvt->local_sdp_str) {
+						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Ring SDP:\n%s\n", tech_pvt->local_sdp_str);
+					}
 				}
+
+				nua_respond(tech_pvt->nh,
+							SIP_183_SESSION_PROGRESS,
+							SIPTAG_CONTACT_STR(tech_pvt->profile->url),
+							SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str), SOATAG_AUDIO_AUX("cn telephone-event"), TAG_END());
 			}
-			
-			nua_respond(tech_pvt->nh,
-						SIP_183_SESSION_PROGRESS,
-						SIPTAG_CONTACT_STR(tech_pvt->profile->url),
-						SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
-						SOATAG_AUDIO_AUX("cn telephone-event"),
-						TAG_END());
-	    }
-	}
+		}
 		break;
 	default:
 		break;
@@ -2228,15 +2122,15 @@
 static switch_status_t sofia_receive_event(switch_core_session_t *session, switch_event_t *event)
 {
 	switch_channel_t *channel;
-    struct private_object *tech_pvt;
+	struct private_object *tech_pvt;
 	char *body;
 	nua_handle_t *msg_nh;
 
-    channel = switch_core_session_get_channel(session);
-    assert(channel != NULL);
+	channel = switch_core_session_get_channel(session);
+	assert(channel != NULL);
 
-    tech_pvt = switch_core_session_get_private(session);
-    assert(tech_pvt != NULL);
+	tech_pvt = switch_core_session_get_private(session);
+	assert(tech_pvt != NULL);
 
 
 	if (!(body = switch_event_get_body(event))) {
@@ -2246,15 +2140,9 @@
 	if (tech_pvt->hash_key) {
 		msg_nh = nua_handle(tech_pvt->profile->nua, NULL,
 							SIPTAG_FROM_STR(tech_pvt->chat_from),
-							NUTAG_URL(tech_pvt->chat_to),
-							SIPTAG_TO_STR(tech_pvt->chat_to),
-							SIPTAG_CONTACT_STR(tech_pvt->profile->url),
-							TAG_END());
+							NUTAG_URL(tech_pvt->chat_to), SIPTAG_TO_STR(tech_pvt->chat_to), SIPTAG_CONTACT_STR(tech_pvt->profile->url), TAG_END());
 
-		nua_message(msg_nh,
-					SIPTAG_CONTENT_TYPE_STR("text/html"),
-					SIPTAG_PAYLOAD_STR(body),
-					TAG_END());
+		nua_message(msg_nh, SIPTAG_CONTENT_TYPE_STR("text/html"), SIPTAG_PAYLOAD_STR(body), TAG_END());
 	}
 
 	return SWITCH_STATUS_SUCCESS;
@@ -2268,9 +2156,9 @@
 	/*.kill_channel */ sofia_kill_channel,
 	/*.waitfor_read */ sofia_waitfor_read,
 	/*.waitfor_read */ sofia_waitfor_write,
-	/*.send_dtmf*/ sofia_send_dtmf,
-	/*.receive_message*/ sofia_receive_message,
-	/*.receive_event*/ sofia_receive_event
+	/*.send_dtmf */ sofia_send_dtmf,
+	/*.receive_message */ sofia_receive_message,
+	/*.receive_event */ sofia_receive_event
 };
 
 static const switch_state_handler_table_t sofia_event_handlers = {
@@ -2293,7 +2181,7 @@
 static const switch_chat_interface_t sofia_chat_interface = {
 	/*.name */ SOFIA_CHAT_PROTO,
 	/*.chat_send */ chat_send,
-	
+
 };
 
 static switch_status_t sofia_manage(char *relative_oid, switch_management_action_t action, char *data, switch_size_t datalen)
@@ -2302,8 +2190,8 @@
 }
 
 static const switch_management_interface_t sofia_management_interface = {
-	/*.relative_oid*/ "1",
-	/*.management_function*/ sofia_manage
+	/*.relative_oid */ "1",
+	/*.management_function */ sofia_manage
 };
 
 static const switch_loadable_module_interface_t sofia_module_interface = {
@@ -2339,20 +2227,21 @@
 		data = (char *) malloc(2048);
 		if (data) {
 			vsnprintf(data, 2048, fmt, ap);
-		} else { 
+		} else {
 			return;
 		}
 #endif
 	}
 	if (data) {
-		switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_CONSOLE, (char*) "%s", data);
+		switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_CONSOLE, (char *) "%s", data);
 		free(data);
 	}
 }
 
 
-static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile,
-												  switch_core_session_t **new_session, switch_memory_pool_t **pool)
+static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session,
+												  switch_caller_profile_t *outbound_profile, switch_core_session_t **new_session,
+												  switch_memory_pool_t **pool)
 {
 	switch_call_cause_t cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
 	switch_core_session_t *nsession;
@@ -2378,12 +2267,12 @@
 
 	data = switch_core_session_strdup(nsession, outbound_profile->destination_number);
 	profile_name = data;
-	
+
 	if (!strncasecmp(profile_name, "gateway", 7)) {
 		char *gw;
 		outbound_reg_t *gateway_ptr;
 
-		
+
 		if (!(gw = strchr(profile_name, '/'))) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid URL\n");
 			terminate_session(&nsession, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __LINE__);
@@ -2392,7 +2281,7 @@
 		}
 
 		*gw++ = '\0';
-		
+
 		if (!(dest = strchr(gw, '/'))) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid URL\n");
 			terminate_session(&nsession, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __LINE__);
@@ -2408,7 +2297,7 @@
 			cause = SWITCH_CAUSE_INVALID_NUMBER_FORMAT;
 			goto done;
 		}
-		
+
 		profile = gateway_ptr->profile;
 		tech_pvt->from_str = switch_core_session_strdup(nsession, gateway_ptr->register_from);
 		if (!strchr(dest, '@')) {
@@ -2428,7 +2317,7 @@
 		if (!(profile = find_profile(profile_name))) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Profile\n");
 			terminate_session(&nsession, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __LINE__);
-			cause =  SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
+			cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
 			goto done;
 		}
 
@@ -2445,7 +2334,7 @@
 			*host++ = '\0';
 			if (find_reg_url(profile, dest, host, buf, sizeof(buf))) {
 				tech_pvt->dest = switch_core_session_strdup(nsession, buf);
-				
+
 			} else {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cannot locate registered user %s@%s\n", dest, host);
 				cause = SWITCH_CAUSE_NO_ROUTE_DESTINATION;
@@ -2457,7 +2346,7 @@
 			tech_pvt->e_dest = switch_core_session_strdup(nsession, dest);
 			if (find_reg_url(profile, dest, profile_name, buf, sizeof(buf))) {
 				tech_pvt->dest = switch_core_session_strdup(nsession, buf);
-				
+
 			} else {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cannot locate registered user %s@%s\n", dest, profile_name);
 				cause = SWITCH_CAUSE_NO_ROUTE_DESTINATION;
@@ -2492,7 +2381,7 @@
 		if (switch_core_session_compare(session, nsession)) {
 			/* It's another sofia channel! so lets cache what they use as a pt for telephone event so 
 			   we can keep it the same
-			*/
+			 */
 			private_object_t *ctech_pvt;
 			ctech_pvt = switch_core_session_get_private(session);
 			assert(ctech_pvt != NULL);
@@ -2501,12 +2390,12 @@
 		}
 	}
 
- done:
+  done:
 	return cause;
 }
 
 
-static uint8_t negotiate_sdp(switch_core_session_t *session, sdp_session_t *sdp)
+static uint8_t negotiate_sdp(switch_core_session_t *session, sdp_session_t * sdp)
 {
 	uint8_t match = 0;
 	switch_payload_t te = 0, cng_pt = 0;
@@ -2514,13 +2403,13 @@
 	sdp_media_t *m;
 	sdp_attribute_t *a;
 	switch_channel_t *channel;
-    int ptime = 0, dptime = 0;
+	int ptime = 0, dptime = 0;
 
 	tech_pvt = switch_core_session_get_private(session);
 	assert(tech_pvt != NULL);
 
 	channel = switch_core_session_get_channel(session);
-	
+
 	if ((tech_pvt->origin = switch_core_session_strdup(session, (char *) sdp->sdp_origin->o_username))) {
 		if (strstr(tech_pvt->origin, "CiscoSystemsSIP-GW-UserAgent")) {
 			switch_set_flag_locked(tech_pvt, TFLAG_BUGGY_2833);
@@ -2534,19 +2423,19 @@
 		} else if (!strcasecmp(a->a_name, "sendrecv")) {
 			switch_clear_flag_locked(tech_pvt, TFLAG_SIP_HOLD);
 		} else if (!strcasecmp(a->a_name, "ptime")) {
-            dptime = atoi(a->a_value);
+			dptime = atoi(a->a_value);
 		}
 	}
 
-	for (m = sdp->sdp_media; m ; m = m->m_next) {
-        sdp_connection_t *connection;
+	for (m = sdp->sdp_media; m; m = m->m_next) {
+		sdp_connection_t *connection;
 
-        ptime = dptime;
-        for (a = m->m_attributes; a; a = a->a_next) {
-            if (!strcasecmp(a->a_name, "ptime") && a->a_value) {
-                ptime = atoi(a->a_value);
-            }
-        }
+		ptime = dptime;
+		for (a = m->m_attributes; a; a = a->a_next) {
+			if (!strcasecmp(a->a_name, "ptime") && a->a_value) {
+				ptime = atoi(a->a_value);
+			}
+		}
 
 		if (m->m_type == sdp_media_audio) {
 			sdp_rtpmap_t *map;
@@ -2564,16 +2453,16 @@
 
 			for (map = m->m_rtpmaps; map; map = map->rm_next) {
 				int32_t i;
-                const switch_codec_implementation_t *mimp = NULL, *near_match = NULL;
-				const char * rm_encoding;
+				const switch_codec_implementation_t *mimp = NULL, *near_match = NULL;
+				const char *rm_encoding;
+
 
-				
 				if (!(rm_encoding = map->rm_encoding)) {
 					rm_encoding = "";
 				}
-				
+
 				if (!te && !strcasecmp(rm_encoding, "telephone-event")) {
-					te = tech_pvt->te = (switch_payload_t)map->rm_pt;
+					te = tech_pvt->te = (switch_payload_t) map->rm_pt;
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Set 2833 dtmf payload to %u\n", te);
 					if (tech_pvt->rtp_session) {
 						switch_rtp_set_telephony_event(tech_pvt->rtp_session, tech_pvt->te);
@@ -2581,14 +2470,14 @@
 				}
 
 				if (!cng_pt && !strcasecmp(rm_encoding, "CN")) {
-					cng_pt = tech_pvt->cng_pt = (switch_payload_t)map->rm_pt;
+					cng_pt = tech_pvt->cng_pt = (switch_payload_t) map->rm_pt;
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Set comfort noise payload to %u\n", cng_pt);
 					if (tech_pvt->rtp_session) {
 						switch_rtp_set_cng_pt(tech_pvt->rtp_session, tech_pvt->cng_pt);
 						switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_AUTO_CNG);
 					}
 				}
-				
+
 				if (match) {
 					if (te && cng_pt) {
 						break;
@@ -2598,7 +2487,7 @@
 
 				for (i = 0; i < tech_pvt->num_codecs; i++) {
 					const switch_codec_implementation_t *imp = tech_pvt->codecs[i];
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Codec Compare [%s:%d]/[%s:%d]\n", 
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Codec Compare [%s:%d]/[%s:%d]\n",
 									  rm_encoding, map->rm_pt, imp->iananame, imp->ianacode);
 					if (map->rm_pt < 96) {
 						match = (map->rm_pt == imp->ianacode) ? 1 : 0;
@@ -2607,61 +2496,58 @@
 					}
 
 					if (match && (map->rm_rate == imp->samples_per_second)) {
-                        if (ptime && ptime * 1000 != imp->microseconds_per_frame) {
-                            near_match = imp;
-                            match = 0;
-                            continue;
-                        }
-                        mimp = imp;
+						if (ptime && ptime * 1000 != imp->microseconds_per_frame) {
+							near_match = imp;
+							match = 0;
+							continue;
+						}
+						mimp = imp;
 						break;
 					} else {
 						match = 0;
 					}
-                }
-                
-                if (!match && near_match) {
-                    const switch_codec_implementation_t *search[1];
-                    char *prefs[1];
-                    char tmp[80];
-                    int num;
-                    
-                    snprintf(tmp, sizeof(tmp), "%s@%uk@%ui",
-                             near_match->iananame,
-                             near_match->samples_per_second,
-                             ptime);
-
-                    prefs[0] = tmp;
-                    num = switch_loadable_module_get_codecs_sorted(search, 1, prefs, 1);
-
-                    if (num) {
-                        mimp = search[0];
-                    } else {
-                        mimp = near_match;
-                    }
-
-                    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Substituting codec %s@%ums\n", 
-                                      mimp->iananame, mimp->microseconds_per_frame / 1000 );
-                    match = 1;
-                }
-
-                if (mimp) {
-                    if ((tech_pvt->rm_encoding = switch_core_session_strdup(session, (char *)rm_encoding))) {
-                        char tmp[50];
-                        tech_pvt->pt = (switch_payload_t)map->rm_pt;
-                        tech_pvt->rm_rate = map->rm_rate;
-                        tech_pvt->codec_ms = mimp->microseconds_per_frame / 1000;
-                        tech_pvt->remote_sdp_audio_ip = switch_core_session_strdup(session, (char *)connection->c_address);
-                        tech_pvt->rm_fmtp = switch_core_session_strdup(session, (char *)map->rm_fmtp);
-                        tech_pvt->remote_sdp_audio_port = (switch_port_t)m->m_port;
-                        tech_pvt->agreed_pt = (switch_payload_t)map->rm_pt;
-                        snprintf(tmp, sizeof(tmp), "%d", tech_pvt->remote_sdp_audio_port);
-                        switch_channel_set_variable(channel, SWITCH_REMOTE_MEDIA_IP_VARIABLE, tech_pvt->remote_sdp_audio_ip);
-                        switch_channel_set_variable(channel, SWITCH_REMOTE_MEDIA_PORT_VARIABLE, tmp);
-                    } else {
-                        match = 0;
-                    }
-                }
-                
+				}
+
+				if (!match && near_match) {
+					const switch_codec_implementation_t *search[1];
+					char *prefs[1];
+					char tmp[80];
+					int num;
+
+					snprintf(tmp, sizeof(tmp), "%s@%uk@%ui", near_match->iananame, near_match->samples_per_second, ptime);
+
+					prefs[0] = tmp;
+					num = switch_loadable_module_get_codecs_sorted(search, 1, prefs, 1);
+
+					if (num) {
+						mimp = search[0];
+					} else {
+						mimp = near_match;
+					}
+
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Substituting codec %s@%ums\n",
+									  mimp->iananame, mimp->microseconds_per_frame / 1000);
+					match = 1;
+				}
+
+				if (mimp) {
+					if ((tech_pvt->rm_encoding = switch_core_session_strdup(session, (char *) rm_encoding))) {
+						char tmp[50];
+						tech_pvt->pt = (switch_payload_t) map->rm_pt;
+						tech_pvt->rm_rate = map->rm_rate;
+						tech_pvt->codec_ms = mimp->microseconds_per_frame / 1000;
+						tech_pvt->remote_sdp_audio_ip = switch_core_session_strdup(session, (char *) connection->c_address);
+						tech_pvt->rm_fmtp = switch_core_session_strdup(session, (char *) map->rm_fmtp);
+						tech_pvt->remote_sdp_audio_port = (switch_port_t) m->m_port;
+						tech_pvt->agreed_pt = (switch_payload_t) map->rm_pt;
+						snprintf(tmp, sizeof(tmp), "%d", tech_pvt->remote_sdp_audio_port);
+						switch_channel_set_variable(channel, SWITCH_REMOTE_MEDIA_IP_VARIABLE, tech_pvt->remote_sdp_audio_ip);
+						switch_channel_set_variable(channel, SWITCH_REMOTE_MEDIA_PORT_VARIABLE, tmp);
+					} else {
+						match = 0;
+					}
+				}
+
 				if (match) {
 					if (tech_set_codec(tech_pvt, 1) != SWITCH_STATUS_SUCCESS) {
 						match = 0;
@@ -2675,26 +2561,27 @@
 }
 
 // map sip responses to QSIG cause codes ala RFC4497 section 8.4.4
-static switch_call_cause_t sip_cause_to_freeswitch(int status) {
+static switch_call_cause_t sip_cause_to_freeswitch(int status)
+{
 	switch (status) {
 	case 200:
 		return SWITCH_CAUSE_NORMAL_CLEARING;
 	case 401:
-	case 402: 
+	case 402:
 	case 403:
 	case 407:
 	case 603:
 		return SWITCH_CAUSE_CALL_REJECTED;
 	case 404:
 	case 485:
-	case 604:	
+	case 604:
 		return SWITCH_CAUSE_NO_ROUTE_DESTINATION;
-	case 408: 
+	case 408:
 	case 504:
 		return SWITCH_CAUSE_RECOVERY_ON_TIMER_EXPIRE;
-	case 410: 
+	case 410:
 		return SWITCH_CAUSE_NUMBER_CHANGED;
-	case 413: 
+	case 413:
 	case 414:
 	case 416:
 	case 420:
@@ -2732,7 +2619,7 @@
 	case 487:
 		return SWITCH_CAUSE_ORIGINATOR_CANCEL;
 
-	default: 
+	default:
 		return SWITCH_CAUSE_NORMAL_UNSPECIFIED;
 
 	}
@@ -2742,11 +2629,8 @@
 static void set_hash_key(char *hash_key, int32_t len, sip_t const *sip)
 {
 
-	snprintf(hash_key, len, "%s%s%s",
-			 (char *) sip->sip_from->a_url->url_user,
-			 (char *) sip->sip_from->a_url->url_host,
-			 (char *) sip->sip_to->a_url->url_user
-			 );	
+	snprintf(hash_key, len, "%s%s%s", (char *) sip->sip_from->a_url->url_user, (char *) sip->sip_from->a_url->url_host,
+			 (char *) sip->sip_to->a_url->url_user);
 
 
 #if 0
@@ -2755,29 +2639,22 @@
 			 (char *) sip->sip_to->a_url->url_user,
 			 (char *) sip->sip_to->a_url->url_host,
 			 (char *) sip->sip_to->a_url->url_params,
-			 
-			 (char *) sip->sip_from->a_url->url_user,
-			 (char *) sip->sip_from->a_url->url_host,
-			 (char *) sip->sip_from->a_url->url_params
-			 );	
+			 (char *) sip->sip_from->a_url->url_user, (char *) sip->sip_from->a_url->url_host, (char *) sip->sip_from->a_url->url_params);
 #endif
 
 }
 
-static void set_chat_hash(private_object_t *tech_pvt, sip_t const *sip)
+static void set_chat_hash(private_object_t * tech_pvt, sip_t const *sip)
 {
 	char hash_key[256] = "";
 	char buf[512];
 
-	if (tech_pvt->hash_key || !sip || !sip->sip_from ||
-		!sip->sip_from->a_url ||
-		!sip->sip_from->a_url->url_user ||
-		!sip->sip_from->a_url->url_host) {
+	if (tech_pvt->hash_key || !sip || !sip->sip_from || !sip->sip_from->a_url || !sip->sip_from->a_url->url_user || !sip->sip_from->a_url->url_host) {
 		return;
 	}
 
 	if (find_reg_url(tech_pvt->profile, sip->sip_from->a_url->url_user, sip->sip_from->a_url->url_host, buf, sizeof(buf))) {
-		tech_pvt->chat_from = sip_header_as_string(tech_pvt->home, (const sip_header_t *)sip->sip_to);
+		tech_pvt->chat_from = sip_header_as_string(tech_pvt->home, (const sip_header_t *) sip->sip_to);
 		tech_pvt->chat_to = switch_core_session_strdup(tech_pvt->session, buf);
 		set_hash_key(hash_key, sizeof(hash_key), sip);
 	} else {
@@ -2791,13 +2668,8 @@
 
 
 static void sip_i_message(int status,
-						char const *phrase, 
-						nua_t *nua,
-						sofia_profile_t *profile,
-						nua_handle_t *nh,
-						sofia_private_t *sofia_private,
-						sip_t const *sip,
-						tagi_t tags[])
+						  char const *phrase,
+						  nua_t * nua, sofia_profile_t * profile, nua_handle_t * nh, sofia_private_t * sofia_private, sip_t const *sip, tagi_t tags[])
 {
 	if (sip) {
 		sip_from_t const *from = sip->sip_from;
@@ -2812,7 +2684,7 @@
 		char *msg = NULL;
 
 		if (sip->sip_content_type) {
-			if (strstr((char*)sip->sip_content_type->c_subtype, "composing")) {
+			if (strstr((char *) sip->sip_content_type->c_subtype, "composing")) {
 				return;
 			}
 		}
@@ -2827,7 +2699,7 @@
 			to_host = (char *) to->a_url->url_host;
 		}
 
-        
+
 		if (!to_user) {
 			return;
 		}
@@ -2840,7 +2712,7 @@
 			subject = sip_subject->g_value;
 		}
 
-		if (nh) {			
+		if (nh) {
 			char hash_key[512];
 			private_object_t *tech_pvt;
 			switch_channel_t *channel;
@@ -2850,20 +2722,20 @@
 			char *p;
 			char *full_from;
 			char proto[512] = SOFIA_CHAT_PROTO;
-			
-			full_from = sip_header_as_string(profile->home, (void *)sip->sip_from);
 
-			if ((p=strchr(to_user, '+'))) {
+			full_from = sip_header_as_string(profile->home, (void *) sip->sip_from);
+
+			if ((p = strchr(to_user, '+'))) {
 				switch_copy_string(proto, to_user, sizeof(proto));
 				p = strchr(proto, '+');
 				*p++ = '\0';
-				
+
 				if ((to_addr = strdup(p))) {
-					if((p = strchr(to_addr, '+'))) {
+					if ((p = strchr(to_addr, '+'))) {
 						*p = '@';
 					}
 				}
-				
+
 			} else {
 				to_addr = switch_mprintf("%s@%s", to_user, to_host);
 			}
@@ -2890,13 +2762,13 @@
 				}
 			} else {
 				switch_chat_interface_t *ci;
-				
+
 				if ((ci = switch_loadable_module_get_chat_interface(proto))) {
 					ci->chat_send(SOFIA_CHAT_PROTO, from_addr, to_addr, "", msg, full_from);
 				} else {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Chat Interface [%s]!\n", proto ? proto : "(none)");
 				}
-				
+
 			}
 			switch_safe_free(to_addr);
 			switch_safe_free(from_addr);
@@ -2908,45 +2780,37 @@
 	}
 }
 
-static void pass_sdp(private_object_t *tech_pvt, char *sdp) 
+static void pass_sdp(private_object_t * tech_pvt, char *sdp)
 {
 	char *val;
 	switch_channel_t *channel;
 	switch_core_session_t *other_session;
 	switch_channel_t *other_channel;
-	
+
 	channel = switch_core_session_get_channel(tech_pvt->session);
 	assert(channel != NULL);
-	
-	if ((val = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE)) && (other_session = switch_core_session_locate(val))) {
+
+	if ((val = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))
+		&& (other_session = switch_core_session_locate(val))) {
 		other_channel = switch_core_session_get_channel(other_session);
 		assert(other_channel != NULL);
-		if (!switch_channel_get_variable(other_channel, SWITCH_B_SDP_VARIABLE)) {
-			switch_channel_set_variable(other_channel, SWITCH_B_SDP_VARIABLE, sdp);
-		}
+		switch_channel_set_variable(other_channel, SWITCH_B_SDP_VARIABLE, sdp);
 
-		if (!switch_test_flag(tech_pvt, TFLAG_CHANGE_MEDIA) && (
-			switch_channel_test_flag(other_channel, CF_OUTBOUND) && 
-			//switch_channel_test_flag(other_channel, CF_NOMEDIA) && 
-			switch_channel_test_flag(channel, CF_OUTBOUND) && 
-			switch_channel_test_flag(channel, CF_NOMEDIA))) {
+		if (!switch_test_flag(tech_pvt, TFLAG_CHANGE_MEDIA) && (switch_channel_test_flag(other_channel, CF_OUTBOUND) &&
+																//switch_channel_test_flag(other_channel, CF_NOMEDIA) && 
+																switch_channel_test_flag(channel, CF_OUTBOUND) &&
+																switch_channel_test_flag(channel, CF_NOMEDIA))) {
 			switch_ivr_nomedia(val, SMF_FORCE);
 			switch_set_flag_locked(tech_pvt, TFLAG_CHANGE_MEDIA);
 		}
-		
+
 		switch_core_session_rwunlock(other_session);
 	}
 }
 
 static void sip_i_state(int status,
-						char const *phrase, 
-						nua_t *nua,
-						sofia_profile_t *profile,
-						nua_handle_t *nh,
-						sofia_private_t *sofia_private,
-						sip_t const *sip,
-						tagi_t tags[])
-	 
+						char const *phrase,
+						nua_t * nua, sofia_profile_t * profile, nua_handle_t * nh, sofia_private_t * sofia_private, sip_t const *sip, tagi_t tags[])
 {
 	const char *l_sdp = NULL, *r_sdp = NULL;
 	int offer_recv = 0, answer_recv = 0, offer_sent = 0, answer_sent = 0;
@@ -2961,26 +2825,23 @@
 	char st[80] = "";
 
 
-    if (sofia_private) {
-        if (!switch_strlen_zero(sofia_private->uuid)) {
-            if (!(session = switch_core_session_locate(sofia_private->uuid))) {
-                /* too late */
-                return;            
-            }
-        }
-    }
+	if (sofia_private) {
+		if (!switch_strlen_zero(sofia_private->uuid)) {
+			if (!(session = switch_core_session_locate(sofia_private->uuid))) {
+				/* too late */
+				return;
+			}
+		}
+	}
+
 
-	
-	tl_gets(tags, 
+	tl_gets(tags,
 			NUTAG_CALLSTATE_REF(ss_state),
 			NUTAG_OFFER_RECV_REF(offer_recv),
 			NUTAG_ANSWER_RECV_REF(answer_recv),
 			NUTAG_OFFER_SENT_REF(offer_sent),
 			NUTAG_ANSWER_SENT_REF(answer_sent),
-			SIPTAG_REPLACES_STR_REF(replaces_str),
-			SOATAG_LOCAL_SDP_STR_REF(l_sdp),
-			SOATAG_REMOTE_SDP_STR_REF(r_sdp),
-			TAG_END()); 
+			SIPTAG_REPLACES_STR_REF(replaces_str), SOATAG_LOCAL_SDP_STR_REF(l_sdp), SOATAG_REMOTE_SDP_STR_REF(r_sdp), TAG_END());
 
 	if (session) {
 		channel = switch_core_session_get_channel(session);
@@ -2988,21 +2849,20 @@
 
 		tech_pvt = switch_core_session_get_private(session);
 		assert(tech_pvt != NULL);
-        assert(tech_pvt->nh != NULL);
+		assert(tech_pvt->nh != NULL);
 
 		if (switch_channel_test_flag(channel, CF_NOMEDIA)) {
-            switch_set_flag(tech_pvt, TFLAG_NOMEDIA);
-        }
+			switch_set_flag(tech_pvt, TFLAG_NOMEDIA);
+		}
 
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Channel %s entering state [%s]\n", 
-						  switch_channel_get_name(channel),
-						  nua_callstate_name(ss_state));
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Channel %s entering state [%s]\n",
+						  switch_channel_get_name(channel), nua_callstate_name(ss_state));
 
 		if (r_sdp) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Remote SDP:\n%s\n", r_sdp);			
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Remote SDP:\n%s\n", r_sdp);
 			tech_pvt->remote_sdp_str = switch_core_session_strdup(session, r_sdp);
 			switch_channel_set_variable(channel, SWITCH_R_SDP_VARIABLE, r_sdp);
-			pass_sdp(tech_pvt, (char *)r_sdp);
+			pass_sdp(tech_pvt, (char *) r_sdp);
 
 		}
 	}
@@ -3011,7 +2871,7 @@
 		goto done;
 	}
 
-	switch ((enum nua_callstate)ss_state) {
+	switch ((enum nua_callstate) ss_state) {
 	case nua_callstate_init:
 		break;
 	case nua_callstate_authenticating:
@@ -3024,14 +2884,15 @@
 				switch_channel_mark_ring_ready(channel);
 				if (!switch_channel_test_flag(channel, CF_GEN_RINGBACK)) {
 					if (switch_test_flag(tech_pvt, TFLAG_NOMEDIA)) {
-						if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE)) && (other_session = switch_core_session_locate(uuid))) {
+						if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))
+							&& (other_session = switch_core_session_locate(uuid))) {
 							switch_core_session_message_t msg;
 							msg.message_id = SWITCH_MESSAGE_INDICATE_RINGING;
 							msg.from = __FILE__;
 							switch_core_session_receive_message(other_session, &msg);
 							switch_core_session_rwunlock(other_session);
 						}
-						
+
 					} else {
 						switch_core_session_queue_indication(session, SWITCH_MESSAGE_INDICATE_RINGING);
 					}
@@ -3041,40 +2902,40 @@
 			if (r_sdp) {
 				if (switch_test_flag(tech_pvt, TFLAG_NOMEDIA)) {
 					switch_set_flag_locked(tech_pvt, TFLAG_EARLY_MEDIA);
-                    switch_channel_mark_pre_answered(channel);
-					if (!switch_channel_test_flag(channel, CF_GEN_RINGBACK) && 
-						(uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE)) && (other_session = switch_core_session_locate(uuid))) {
+					switch_channel_mark_pre_answered(channel);
+					if (!switch_channel_test_flag(channel, CF_GEN_RINGBACK) && (uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))
+						&& (other_session = switch_core_session_locate(uuid))) {
 						other_channel = switch_core_session_get_channel(other_session);
 						if (!switch_channel_get_variable(other_channel, SWITCH_B_SDP_VARIABLE)) {
 							switch_channel_set_variable(other_channel, SWITCH_B_SDP_VARIABLE, r_sdp);
 						}
-						
+
 						switch_channel_pre_answer(other_channel);
 						switch_core_session_rwunlock(other_session);
 					}
-                    goto done;
+					goto done;
 				} else {
 					if (switch_test_flag(tech_pvt, TFLAG_LATE_NEGOTIATION)) {
 						switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "DELAYED NEGOTIATION");
 					} else {
-						if (tech_media(tech_pvt, (char *)r_sdp) != SWITCH_STATUS_SUCCESS) {
+						if (tech_media(tech_pvt, (char *) r_sdp) != SWITCH_STATUS_SUCCESS) {
 							switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "CODEC NEGOTIATION ERROR");
 							nua_respond(nh, SIP_488_NOT_ACCEPTABLE, TAG_END());
 						}
 					}
 					goto done;
-                }
+				}
 			}
 		}
 		break;
 	case nua_callstate_completing:
 		nua_ack(nh, TAG_END());
 		break;
-	case nua_callstate_received: 
+	case nua_callstate_received:
 
 		if (session && switch_core_session_running(session)) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Re-Entering Call State Received!\n");
-            goto done;
+			goto done;
 		}
 
 		if (channel) {
@@ -3084,12 +2945,12 @@
 					switch_channel_set_state(channel, CS_INIT);
 					switch_set_flag_locked(tech_pvt, TFLAG_READY);
 					switch_core_session_thread_launch(session);
-                    goto done;
+					goto done;
 				} else {
-					sdp_parser_t *parser = sdp_parse(tech_pvt->home, r_sdp, (int)strlen(r_sdp), 0);
+					sdp_parser_t *parser = sdp_parse(tech_pvt->home, r_sdp, (int) strlen(r_sdp), 0);
 					sdp_session_t *sdp;
 					uint8_t match = 0;
-				
+
 					if (tech_pvt->num_codecs) {
 						if ((sdp = sdp_session(parser))) {
 							match = negotiate_sdp(session, sdp);
@@ -3108,8 +2969,9 @@
 						switch_set_flag_locked(tech_pvt, TFLAG_READY);
 
 						switch_core_session_thread_launch(session);
-						
-						if (replaces_str && (replaces = sip_replaces_make(tech_pvt->home, replaces_str)) && (bnh = nua_handle_by_replaces(nua, replaces))) {
+
+						if (replaces_str && (replaces = sip_replaces_make(tech_pvt->home, replaces_str))
+							&& (bnh = nua_handle_by_replaces(nua, replaces))) {
 							sofia_private_t *b_private;
 
 							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Processing Replaces Attended Transfer\n");
@@ -3135,12 +2997,11 @@
 							}
 							nua_handle_unref(bnh);
 						}
-                        goto done;
+						goto done;
 					}
 
 					switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "NO CODECS");
-					nua_respond(nh, SIP_488_NOT_ACCEPTABLE, 
-								TAG_END());
+					nua_respond(nh, SIP_488_NOT_ACCEPTABLE, TAG_END());
 				}
 			} else {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Invite with no SDP activating no-media-mode\n");
@@ -3156,16 +3017,16 @@
 			}
 		}
 
-		break;		
+		break;
 	case nua_callstate_early:
 		break;
 	case nua_callstate_completed:
 		if (tech_pvt && r_sdp) {
 			if (r_sdp) {
 				if (switch_test_flag(tech_pvt, TFLAG_NOMEDIA)) {
-                    goto done;
+					goto done;
 				} else {
-					sdp_parser_t *parser = sdp_parse(tech_pvt->home, r_sdp, (int)strlen(r_sdp), 0);
+					sdp_parser_t *parser = sdp_parse(tech_pvt->home, r_sdp, (int) strlen(r_sdp), 0);
 					sdp_session_t *sdp;
 					uint8_t match = 0;
 
@@ -3176,8 +3037,8 @@
 					}
 					if (match) {
 						if (tech_choose_port(tech_pvt) != SWITCH_STATUS_SUCCESS) {
-                            goto done;
-                        }
+							goto done;
+						}
 						set_local_sdp(tech_pvt, NULL, 0, NULL, 0);
 						switch_set_flag_locked(tech_pvt, TFLAG_REINVITE);
 						activate_rtp(tech_pvt);
@@ -3197,20 +3058,21 @@
 			tech_pvt->nh = tech_pvt->nh2;
 			tech_pvt->nh2 = NULL;
 			if (tech_choose_port(tech_pvt) == SWITCH_STATUS_SUCCESS) {
-                activate_rtp(tech_pvt);
-            }
+				activate_rtp(tech_pvt);
+			}
 			goto done;
 		}
 
 		if (channel) {
 			if (switch_test_flag(tech_pvt, TFLAG_EARLY_MEDIA)) {
 				switch_set_flag_locked(tech_pvt, TFLAG_ANS);
-                switch_channel_mark_answered(channel);
-                if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE)) && (other_session = switch_core_session_locate(uuid))) {
-                    other_channel = switch_core_session_get_channel(other_session);
-                    switch_channel_answer(other_channel);
-                    switch_core_session_rwunlock(other_session);
-                }
+				switch_channel_mark_answered(channel);
+				if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))
+					&& (other_session = switch_core_session_locate(uuid))) {
+					other_channel = switch_core_session_get_channel(other_session);
+					switch_channel_answer(other_channel);
+					switch_core_session_rwunlock(other_session);
+				}
 				goto done;
 			}
 
@@ -3220,8 +3082,9 @@
 			if (r_sdp) {
 				if (switch_test_flag(tech_pvt, TFLAG_NOMEDIA)) {
 					switch_set_flag_locked(tech_pvt, TFLAG_ANS);
-                    switch_channel_mark_answered(channel);
-					if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE)) && (other_session = switch_core_session_locate(uuid))) {
+					switch_channel_mark_answered(channel);
+					if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))
+						&& (other_session = switch_core_session_locate(uuid))) {
 						other_channel = switch_core_session_get_channel(other_session);
 						if (!switch_channel_get_variable(other_channel, SWITCH_B_SDP_VARIABLE)) {
 							switch_channel_set_variable(other_channel, SWITCH_B_SDP_VARIABLE, r_sdp);
@@ -3231,7 +3094,7 @@
 					}
 					goto done;
 				} else {
-					sdp_parser_t *parser = sdp_parse(tech_pvt->home, r_sdp, (int)strlen(r_sdp), 0);
+					sdp_parser_t *parser = sdp_parse(tech_pvt->home, r_sdp, (int) strlen(r_sdp), 0);
 					sdp_session_t *sdp;
 					uint8_t match = 0;
 
@@ -3249,26 +3112,26 @@
 					if (match) {
 						switch_set_flag_locked(tech_pvt, TFLAG_ANS);
 						if (tech_choose_port(tech_pvt) == SWITCH_STATUS_SUCCESS) {
-                            activate_rtp(tech_pvt);
-                            switch_channel_mark_answered(channel);
-                            goto done;
-                        }
+							activate_rtp(tech_pvt);
+							switch_channel_mark_answered(channel);
+							goto done;
+						}
 					}
-					
+
 					switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "NO CODECS");
 					nua_respond(nh, SIP_488_NOT_ACCEPTABLE, TAG_END());
 				}
 			}
-			
+
 		}
-		
+
 		break;
 	case nua_callstate_terminating:
 		break;
-	case nua_callstate_terminated: 
+	case nua_callstate_terminated:
 		if (session) {
 			if (!switch_test_flag(tech_pvt, TFLAG_BYE)) {
-                
+
 				switch_set_flag_locked(tech_pvt, TFLAG_BYE);
 				if (switch_test_flag(tech_pvt, TFLAG_NOHUP)) {
 					switch_clear_flag_locked(tech_pvt, TFLAG_NOHUP);
@@ -3279,31 +3142,31 @@
 				}
 			}
 
-            if (tech_pvt->sofia_private) {
-                free(tech_pvt->sofia_private);
-                tech_pvt->sofia_private = NULL;
-            }
+			if (tech_pvt->sofia_private) {
+				free(tech_pvt->sofia_private);
+				tech_pvt->sofia_private = NULL;
+			}
 			tech_pvt->nh = NULL;
 		} else if (sofia_private) {
-            free(sofia_private);
-        }
+			free(sofia_private);
+		}
 
 		if (nh) {
-            nua_handle_bind(nh, NULL);
+			nua_handle_bind(nh, NULL);
 			nua_handle_destroy(nh);
 		}
 		break;
 	}
 
- done:
+  done:
 
-    if (session) {
-        switch_core_session_rwunlock(session);
-    }
+	if (session) {
+		switch_core_session_rwunlock(session);
+	}
 }
 
 
-static char *get_auth_data(char *dbname, char *nonce, char *npassword, size_t len, switch_mutex_t *mutex)
+static char *get_auth_data(char *dbname, char *nonce, char *npassword, size_t len, switch_mutex_t * mutex)
 {
 	switch_core_db_t *db;
 	switch_core_db_stmt_t *stmt;
@@ -3335,7 +3198,7 @@
 
 			if (result == SWITCH_CORE_DB_ROW) {
 				if ((colcount = switch_core_db_column_count(stmt))) {
-					switch_copy_string(npassword, (char *)switch_core_db_column_text(stmt, 0), len);
+					switch_copy_string(npassword, (char *) switch_core_db_column_text(stmt, 0), len);
 					ret = npassword;
 				}
 				break;
@@ -3346,16 +3209,16 @@
 			}
 			break;
 		}
-			
+
 		switch_core_db_finalize(stmt);
 	}
-	
 
- fail:
+
+  fail:
 
 	switch_core_db_close(db);
 
- end:
+  end:
 	if (mutex) {
 		switch_mutex_unlock(mutex);
 	}
@@ -3363,7 +3226,7 @@
 	if (sql) {
 		switch_safe_free(sql);
 	}
-	
+
 	return ret;
 }
 
@@ -3373,12 +3236,7 @@
 	REG_INVITE
 } sofia_regtype_t;
 
-static uint8_t handle_register(nua_t *nua,
-							   sofia_profile_t *profile,
-							   nua_handle_t *nh,
-							   sip_t const *sip,
-							   sofia_regtype_t regtype,
-							   char *key,
+static uint8_t handle_register(nua_t * nua, sofia_profile_t * profile, nua_handle_t * nh, sip_t const *sip, sofia_regtype_t regtype, char *key,
 							   uint32_t keylen)
 {
 	sip_from_t const *from = NULL;
@@ -3433,25 +3291,24 @@
 				}
 			}
 		}
-		
+
 		if (!port) {
 			port = SOFIA_DEFAULT_PORT;
 		}
 
 		if (contact->m_url->url_params) {
-			snprintf(contact_str, sizeof(contact_str), "%s <sip:%s@%s:%s;%s>", 
+			snprintf(contact_str, sizeof(contact_str), "%s <sip:%s@%s:%s;%s>",
 					 display, contact->m_url->url_user, contact->m_url->url_host, port, contact->m_url->url_params);
 		} else {
-			snprintf(contact_str, sizeof(contact_str), "%s <sip:%s@%s:%s>", 
-					 display, contact->m_url->url_user, contact->m_url->url_host, port);
+			snprintf(contact_str, sizeof(contact_str), "%s <sip:%s@%s:%s>", display, contact->m_url->url_user, contact->m_url->url_host, port);
 		}
 	}
-	
+
 	if (expires) {
 		exptime = expires->ex_delta;
 	} else if (contact->m_expires) {
 		exptime = atol(contact->m_expires);
-	} 
+	}
 
 	if (regtype == REG_REGISTER) {
 		authorization = sip->sip_authorization;
@@ -3465,13 +3322,11 @@
 
 	if (authorization) {
 		if ((auth_res = parse_auth(profile, authorization, sip->sip_request->rq_method_name, key, keylen)) == AUTH_STALE) {
-            stale = 1;
-        }
+			stale = 1;
+		}
 
 		if (auth_res != AUTH_OK && !stale) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "send %s for [%s@%s]\n",
-							  forbidden ? "forbidden" : "challange",
-							  from_user, from_host);
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "send %s for [%s@%s]\n", forbidden ? "forbidden" : "challange", from_user, from_host);
 			if (auth_res == AUTH_FORBIDDEN) {
 				nua_respond(nh, SIP_403_FORBIDDEN, NUTAG_WITH_THIS(nua), TAG_END());
 			} else {
@@ -3479,16 +3334,12 @@
 			}
 			return 1;
 		}
-	} 
+	}
 
 	if (!authorization || stale) {
-		snprintf(params, sizeof(params), "from_user=%s&from_host=%s&contact=%s",
-				 from_user,
-				 from_host,
-				 contact_str
-				 );
+		snprintf(params, sizeof(params), "from_user=%s&from_host=%s&contact=%s", from_user, from_host, contact_str);
+
 
-		
 		if (switch_xml_locate("directory", "domain", "name", from_host, &xml, &domain, params) != SWITCH_STATUS_SUCCESS) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "can't find domain for [%s@%s]\n", from_user, from_host);
 			nua_respond(nh, SIP_401_UNAUTHORIZED, NUTAG_WITH_THIS(nua), SIPTAG_CONTACT(contact), TAG_END());
@@ -3508,21 +3359,21 @@
 			switch_xml_free(xml);
 			return 1;
 		}
-	
+
 
 		for (param = switch_xml_child(xparams, "param"); param; param = param->next) {
 			const char *var = switch_xml_attr_soft(param, "name");
 			const char *val = switch_xml_attr_soft(param, "value");
-		
+
 			if (!strcasecmp(var, "password")) {
 				passwd = val;
 			}
 
 			if (!strcasecmp(var, "a1-hash")) {
-                a1_hash = val;
+				a1_hash = val;
 			}
 		}
-	
+
 		if (passwd || a1_hash) {
 			switch_uuid_t uuid;
 			char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
@@ -3532,43 +3383,31 @@
 			char hexdigest[2 * SU_MD5_DIGEST_SIZE + 1];
 			char *input;
 
-            if (!a1_hash) {
-                input = switch_mprintf("%s:%s:%s", from_user, from_host, passwd);
-                su_md5_init(&ctx);
-                su_md5_strupdate(&ctx, input);
-                su_md5_hexdigest(&ctx, hexdigest);
-                su_md5_deinit(&ctx);
-                switch_safe_free(input);
-
-                switch_uuid_get(&uuid);
-                switch_uuid_format(uuid_str, &uuid);
-                a1_hash = hexdigest;
-            }
+			if (!a1_hash) {
+				input = switch_mprintf("%s:%s:%s", from_user, from_host, passwd);
+				su_md5_init(&ctx);
+				su_md5_strupdate(&ctx, input);
+				su_md5_hexdigest(&ctx, hexdigest);
+				su_md5_deinit(&ctx);
+				switch_safe_free(input);
+
+				switch_uuid_get(&uuid);
+				switch_uuid_format(uuid_str, &uuid);
+				a1_hash = hexdigest;
+			}
 
 			sql = switch_mprintf("delete from sip_authentication where user='%q' and host='%q';\n"
-                                 "insert into sip_authentication values('%q','%q','%q','%q', %ld)",
-                                 from_user,
-                                 from_host,
-                                 from_user,
-                                 from_host,
-                                 a1_hash,
-                                 uuid_str,
-                                 time(NULL) + profile->nonce_ttl);
-			auth_str = switch_mprintf("Digest realm=\"%q\", nonce=\"%q\",%s algorithm=MD5, qop=\"auth\"", from_host, uuid_str, 
-											  stale ? " stale=\"true\"," : "");
+								 "insert into sip_authentication values('%q','%q','%q','%q', %ld)",
+								 from_user, from_host, from_user, from_host, a1_hash, uuid_str, time(NULL) + profile->nonce_ttl);
+			auth_str =
+				switch_mprintf("Digest realm=\"%q\", nonce=\"%q\",%s algorithm=MD5, qop=\"auth\"", from_host, uuid_str, stale ? " stale=\"true\"," : "");
 
 
 			if (regtype == REG_REGISTER) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Requesting Registration from: [%s@%s]\n", from_user, from_host);
-				nua_respond(nh, SIP_401_UNAUTHORIZED,
-							NUTAG_WITH_THIS(nua),
-							SIPTAG_WWW_AUTHENTICATE_STR(auth_str),
-							TAG_END());
+				nua_respond(nh, SIP_401_UNAUTHORIZED, NUTAG_WITH_THIS(nua), SIPTAG_WWW_AUTHENTICATE_STR(auth_str), TAG_END());
 			} else if (regtype == REG_INVITE) {
-				nua_respond(nh, SIP_407_PROXY_AUTH_REQUIRED,
-							NUTAG_WITH_THIS(nua),
-							SIPTAG_PROXY_AUTHENTICATE_STR(auth_str),
-							TAG_END());
+				nua_respond(nh, SIP_407_PROXY_AUTH_REQUIRED, NUTAG_WITH_THIS(nua), SIPTAG_PROXY_AUTHENTICATE_STR(auth_str), TAG_END());
 
 			}
 
@@ -3579,32 +3418,26 @@
 		} else {
 			ret = 0;
 		}
-		
+
 		switch_xml_free(xml);
 
 		if (ret) {
 			return ret;
 		}
 	}
- reg:
+  reg:
 
 	if (exptime) {
 		if (!find_reg_url(profile, from_user, from_host, buf, sizeof(buf))) {
-			sql = switch_mprintf("insert into sip_registrations values ('%q','%q','%q','Registered', '%q', %ld)", 
-								 from_user,
-								 from_host,
-								 contact_str,
-								 rpid,
-								 (long) time(NULL) + (long)exptime * 2);
+			sql = switch_mprintf("insert into sip_registrations values ('%q','%q','%q','Registered', '%q', %ld)",
+								 from_user, from_host, contact_str, rpid, (long) time(NULL) + (long) exptime * 2);
 
 		} else {
-			sql = switch_mprintf("update sip_registrations set contact='%q', expires=%ld, rpid='%q' where user='%q' and host='%q'",
-								 contact_str,
-								 (long) time(NULL) + (long)exptime * 2,
-								 rpid,
-								 from_user,
-								 from_host);
-		
+			sql =
+				switch_mprintf
+				("update sip_registrations set contact='%q', expires=%ld, rpid='%q' where user='%q' and host='%q'",
+				 contact_str, (long) time(NULL) + (long) exptime * 2, rpid, from_user, from_host);
+
 		}
 
 		if (switch_event_create_subclass(&s_event, SWITCH_EVENT_CUSTOM, MY_EVENT_REGISTER) == SWITCH_STATUS_SUCCESS) {
@@ -3613,7 +3446,7 @@
 			switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "from-host", "%s", from_host);
 			switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "contact", "%s", contact_str);
 			switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "rpid", "%s", rpid);
-			switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "expires", "%ld", (long)exptime);
+			switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "expires", "%ld", (long) exptime);
 			switch_event_fire(&s_event);
 		}
 
@@ -3622,13 +3455,9 @@
 			switch_safe_free(sql);
 			sql = NULL;
 		}
-	
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Register:\nFrom:    [%s@%s]\nContact: [%s]\nExpires: [%ld]\n", 
-						  from_user, 
-						  from_host,
-					  contact_str,
-					  (long)exptime
-					  );
+
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
+						  "Register:\nFrom:    [%s@%s]\nContact: [%s]\nExpires: [%ld]\n", from_user, from_host, contact_str, (long) exptime);
 
 
 		if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
@@ -3636,7 +3465,7 @@
 			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "login", "%s", profile->url);
 			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "rpid", "%s", rpid);
 			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", from_user, from_host);
-			
+
 			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "status", "Registered");
 			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_type", "presence");
 			switch_event_fire(&event);
@@ -3651,7 +3480,7 @@
 			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "proto", "sip");
 			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "login", "%s", profile->url);
 			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s+%s@%s", SOFIA_CHAT_PROTO, from_user, from_host);
-		
+
 			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "status", "unavailable");
 			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "rpid", "%s", rpid);
 			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_type", "presence");
@@ -3667,9 +3496,7 @@
 	}
 
 	if (regtype == REG_REGISTER) {
-		nua_respond(nh, SIP_200_OK, SIPTAG_CONTACT(contact),
-					NUTAG_WITH_THIS(nua),
-					TAG_END());
+		nua_respond(nh, SIP_200_OK, SIPTAG_CONTACT(contact), NUTAG_WITH_THIS(nua), TAG_END());
 		return 1;
 	}
 
@@ -3763,11 +3590,11 @@
 		open = "closed";
 	}
 
-    if (!strcasecmp(sub_to_host, host)) {
-        /* same host */
+	if (!strcasecmp(sub_to_host, host)) {
+		/* same host */
 		id = switch_mprintf("sip:%s+%s@%s", proto, sub_to_user, sub_to_host);
 	} else if (strcasecmp(proto, SOFIA_CHAT_PROTO)) {
-		/*encapsulate*/
+		/*encapsulate */
 		id = switch_mprintf("sip:%s+%s+%s@%s", proto, sub_to_user, sub_to_host, host);
 	} else {
 		id = switch_mprintf("sip:%s@%s", sub_to_user, sub_to_host);
@@ -3775,25 +3602,22 @@
 
 	to = switch_mprintf("sip:%s@%s", user, host);
 	pl = switch_mprintf("<?xml version='1.0' encoding='UTF-8'?>\r\n"
-								"<presence xmlns='urn:ietf:params:xml:ns:pidf'\r\n"
-								"xmlns:dm='urn:ietf:params:xml:ns:pidf:data-model'\r\n"
-								"xmlns:rpid='urn:ietf:params:xml:ns:pidf:rpid'\r\n"
-								"xmlns:c='urn:ietf:params:xml:ns:pidf:cipid'\r\n"
-								"entity='pres:%s'>\r\n"
-								"<tuple id='t6a5ed77e'>\r\n"
-								"<status>\r\n"
-								"<basic>%s</basic>\r\n"
-								"</status>\r\n"
-								"</tuple>\r\n"
-								"<dm:person id='p06360c4a'>\r\n"
-								"<rpid:activities>\r\n"
-								"<rpid:%s/>\r\n"
-								"</rpid:activities>%s</dm:person>\r\n"
-								"</presence>", id, open, rpid, note);
+						"<presence xmlns='urn:ietf:params:xml:ns:pidf'\r\n"
+						"xmlns:dm='urn:ietf:params:xml:ns:pidf:data-model'\r\n"
+						"xmlns:rpid='urn:ietf:params:xml:ns:pidf:rpid'\r\n"
+						"xmlns:c='urn:ietf:params:xml:ns:pidf:cipid'\r\n"
+						"entity='pres:%s'>\r\n"
+						"<tuple id='t6a5ed77e'>\r\n"
+						"<status>\r\n"
+						"<basic>%s</basic>\r\n"
+						"</status>\r\n"
+						"</tuple>\r\n"
+						"<dm:person id='p06360c4a'>\r\n"
+						"<rpid:activities>\r\n" "<rpid:%s/>\r\n" "</rpid:activities>%s</dm:person>\r\n" "</presence>", id, open, rpid, note);
+
 
-	
 
-	nh = nua_handle(profile->nua, NULL,	TAG_END());
+	nh = nua_handle(profile->nua, NULL, TAG_END());
 	tmp = contact;
 	contact = get_url_from_contact(tmp, 0);
 
@@ -3805,10 +3629,7 @@
 			   SIPTAG_CALL_ID_STR(callid),
 			   SIPTAG_VIA_STR(full_via),
 			   SIPTAG_SUBSCRIPTION_STATE_STR("active;expires=3600"),
-			   SIPTAG_EVENT_STR(event),
-			   SIPTAG_CONTENT_TYPE_STR("application/pidf+xml"),
-			   SIPTAG_PAYLOAD_STR(pl),
-			   TAG_END());
+			   SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR("application/pidf+xml"), SIPTAG_PAYLOAD_STR(pl), TAG_END());
 
 	switch_safe_free(id);
 	switch_safe_free(note);
@@ -3819,496 +3640,426 @@
 }
 
 static void sip_i_subscribe(int status,
-						char const *phrase, 
-						nua_t *nua,
-						sofia_profile_t *profile,
-						nua_handle_t *nh,
-						sofia_private_t *sofia_private,
-						sip_t const *sip,
-						tagi_t tags[])
-{
-		if (sip) {
-			long exp, exp_raw;
-			sip_to_t const *to = sip->sip_to;
-			sip_from_t const *from = sip->sip_from;
-			sip_contact_t const *contact = sip->sip_contact;
-			char *from_user = NULL;
-			char *from_host = NULL;
-			char *to_user = NULL;
-			char *to_host = NULL;
-			char *sql, *event = NULL;
-			char *proto = "sip";
-			char *d_user = NULL;
-			char *contact_str = "";
-			char *call_id = NULL;
-			char *to_str = NULL;
-			char *full_from = NULL;
-			char *full_via = NULL;
-			switch_core_db_t *db;
-			char *errmsg;
-			char *sstr;
-			const char *display = "\"user\"";
-			switch_event_t *sevent;
-
-			if (contact) {
-				char *port = (char *) contact->m_url->url_port;
-
-				display = contact->m_display;
-				
-				if (switch_strlen_zero(display)) {
-					if (from) {
-						display = from->a_display;
-						if (switch_strlen_zero(display)) {
-							display = "\"user\"";
-						}
+							char const *phrase,
+							nua_t * nua, sofia_profile_t * profile, nua_handle_t * nh, sofia_private_t * sofia_private, sip_t const *sip, tagi_t tags[])
+{
+	if (sip) {
+		long exp, exp_raw;
+		sip_to_t const *to = sip->sip_to;
+		sip_from_t const *from = sip->sip_from;
+		sip_contact_t const *contact = sip->sip_contact;
+		char *from_user = NULL;
+		char *from_host = NULL;
+		char *to_user = NULL;
+		char *to_host = NULL;
+		char *sql, *event = NULL;
+		char *proto = "sip";
+		char *d_user = NULL;
+		char *contact_str = "";
+		char *call_id = NULL;
+		char *to_str = NULL;
+		char *full_from = NULL;
+		char *full_via = NULL;
+		switch_core_db_t *db;
+		char *errmsg;
+		char *sstr;
+		const char *display = "\"user\"";
+		switch_event_t *sevent;
+
+		if (contact) {
+			char *port = (char *) contact->m_url->url_port;
+
+			display = contact->m_display;
+
+			if (switch_strlen_zero(display)) {
+				if (from) {
+					display = from->a_display;
+					if (switch_strlen_zero(display)) {
+						display = "\"user\"";
 					}
-				} else {
-					display = "\"user\"";
-				}
-
-				if (!port) {
-					port = SOFIA_DEFAULT_PORT;
-				}
-
-				if (contact->m_url->url_params) {
-					contact_str = switch_mprintf("%s <sip:%s@%s:%s;%s>", 
-												 display,
-												 contact->m_url->url_user,
-												 contact->m_url->url_host, port, contact->m_url->url_params);
-				} else {
-					contact_str = switch_mprintf("%s <sip:%s@%s:%s>", 
-												 display,
-												 contact->m_url->url_user,
-												 contact->m_url->url_host, port);
 				}
+			} else {
+				display = "\"user\"";
 			}
-			
-			if (to) {
-				to_str = switch_mprintf("sip:%s@%s", to->a_url->url_user, to->a_url->url_host);//, to->a_url->url_port);
+
+			if (!port) {
+				port = SOFIA_DEFAULT_PORT;
 			}
 
-			if (to) {
-				to_user = (char *) to->a_url->url_user;
-				to_host = (char *) to->a_url->url_host;
+			if (contact->m_url->url_params) {
+				contact_str = switch_mprintf("%s <sip:%s@%s:%s;%s>",
+											 display, contact->m_url->url_user, contact->m_url->url_host, port, contact->m_url->url_params);
+			} else {
+				contact_str = switch_mprintf("%s <sip:%s@%s:%s>", display, contact->m_url->url_user, contact->m_url->url_host, port);
 			}
+		}
 
+		if (to) {
+			to_str = switch_mprintf("sip:%s@%s", to->a_url->url_user, to->a_url->url_host);	//, to->a_url->url_port);
+		}
 
-			if (strstr(to_user, "ext+") || strstr(to_user, "user+") || strstr(to_user, "conf+")) {
-				char proto[80];
-				char *p;
+		if (to) {
+			to_user = (char *) to->a_url->url_user;
+			to_host = (char *) to->a_url->url_host;
+		}
 
-				switch_copy_string(proto, to_user, sizeof(proto));
-				if ((p = strchr(proto, '+'))) {
-					*p = '\0';
-				}
-				
-				if (switch_event_create(&sevent, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
-					switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
-					switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "login", "%s", profile->name);
-					switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "from", "%s@%s",  to_user, to_host);
-					switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "rpid", "unknown");
-					switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "status", "Click To Call");
-					switch_event_fire(&sevent);
-				}
+
+		if (strstr(to_user, "ext+") || strstr(to_user, "user+") || strstr(to_user, "conf+")) {
+			char proto[80];
+			char *p;
+
+			switch_copy_string(proto, to_user, sizeof(proto));
+			if ((p = strchr(proto, '+'))) {
+				*p = '\0';
 			}
 
-			if (strchr(to_user, '+')) {
-				char *h;
-				if ((proto = (d_user = strdup(to_user)))) {
-					if ((to_user = strchr(d_user, '+'))) {
-						*to_user++ = '\0';
-						if ((h = strchr(to_user, '+')) || (h = strchr(to_user, '@'))) {
-							*h++ = '\0';
-							to_host = h;
-						}
-					}
-				}
+			if (switch_event_create(&sevent, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
+				switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
+				switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "login", "%s", profile->name);
+				switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "from", "%s@%s", to_user, to_host);
+				switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "rpid", "unknown");
+				switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "status", "Click To Call");
+				switch_event_fire(&sevent);
+			}
+		}
 
-				if (!(proto && to_user && to_host)) {
-					nua_respond(nh, SIP_404_NOT_FOUND, NUTAG_WITH_THIS(nua), TAG_END());
-					goto end;
+		if (strchr(to_user, '+')) {
+			char *h;
+			if ((proto = (d_user = strdup(to_user)))) {
+				if ((to_user = strchr(d_user, '+'))) {
+					*to_user++ = '\0';
+					if ((h = strchr(to_user, '+')) || (h = strchr(to_user, '@'))) {
+						*h++ = '\0';
+						to_host = h;
+					}
 				}
 			}
 
-			call_id = sip_header_as_string(profile->home, (void *)sip->sip_call_id);
-			event = sip_header_as_string(profile->home, (void *)sip->sip_event);
-			full_from = sip_header_as_string(profile->home, (void *)sip->sip_from);
-			full_via = sip_header_as_string(profile->home, (void *)sip->sip_via);
-
-			exp_raw = (sip->sip_expires ? sip->sip_expires->ex_delta : 3600);
-			exp = (long) time(NULL) + exp_raw;
-			
-            if (sip && sip->sip_from) {
-                from_user = (char *) sip->sip_from->a_url->url_user;
-                from_host = (char *) sip->sip_from->a_url->url_host;
-            } else {
-                from_user = "n/a";
-                from_host = "n/a";
-            }
-
-			if ((sql = switch_mprintf("delete from sip_subscriptions where "
-											  "proto='%q' and user='%q' and host='%q' and sub_to_user='%q' and sub_to_host='%q' and event='%q';\n"
-											  "insert into sip_subscriptions values ('%q','%q','%q','%q','%q','%q','%q','%q','%q','%q',%ld)",
-											  proto,
-											  from_user,
-											  from_host,
-											  to_user,
-											  to_host,
-											  event,
-											  proto,
-											  from_user,
-											  from_host,
-											  to_user,
-											  to_host,
-											  event,
-											  contact_str,
-											  call_id,
-											  full_from,
-											  full_via,
-											  exp
-									  ))) {
-				execute_sql(profile->dbname, sql, profile->ireg_mutex);
-				switch_safe_free(sql);
+			if (!(proto && to_user && to_host)) {
+				nua_respond(nh, SIP_404_NOT_FOUND, NUTAG_WITH_THIS(nua), TAG_END());
+				goto end;
 			}
+		}
 
-			sstr = switch_mprintf("active;expires=%ld", exp_raw);
+		call_id = sip_header_as_string(profile->home, (void *) sip->sip_call_id);
+		event = sip_header_as_string(profile->home, (void *) sip->sip_event);
+		full_from = sip_header_as_string(profile->home, (void *) sip->sip_from);
+		full_via = sip_header_as_string(profile->home, (void *) sip->sip_via);
+
+		exp_raw = (sip->sip_expires ? sip->sip_expires->ex_delta : 3600);
+		exp = (long) time(NULL) + exp_raw;
+
+		if (sip && sip->sip_from) {
+			from_user = (char *) sip->sip_from->a_url->url_user;
+			from_host = (char *) sip->sip_from->a_url->url_host;
+		} else {
+			from_user = "n/a";
+			from_host = "n/a";
+		}
 
-			nua_respond(nh, SIP_202_ACCEPTED,
-						NUTAG_WITH_THIS(nua),
-						SIPTAG_SUBSCRIPTION_STATE_STR(sstr),
-						SIPTAG_FROM(sip->sip_to),
-						SIPTAG_TO(sip->sip_from),
-						SIPTAG_CONTACT_STR(to_str),
-						TAG_END());
+		if ((sql = switch_mprintf("delete from sip_subscriptions where "
+								  "proto='%q' and user='%q' and host='%q' and sub_to_user='%q' and sub_to_host='%q' and event='%q';\n"
+								  "insert into sip_subscriptions values ('%q','%q','%q','%q','%q','%q','%q','%q','%q','%q',%ld)",
+								  proto,
+								  from_user,
+								  from_host,
+								  to_user,
+								  to_host, event, proto, from_user, from_host, to_user, to_host, event, contact_str, call_id, full_from, full_via, exp))) {
+			execute_sql(profile->dbname, sql, profile->ireg_mutex);
+			switch_safe_free(sql);
+		}
 
+		sstr = switch_mprintf("active;expires=%ld", exp_raw);
 
+		nua_respond(nh, SIP_202_ACCEPTED,
+					NUTAG_WITH_THIS(nua),
+					SIPTAG_SUBSCRIPTION_STATE_STR(sstr), SIPTAG_FROM(sip->sip_to), SIPTAG_TO(sip->sip_from), SIPTAG_CONTACT_STR(to_str), TAG_END());
 
-			switch_safe_free(sstr);
-			
-			if (!(db = switch_core_db_open_file(profile->dbname))) {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
-				goto end;
-			}
-			if ((sql = switch_mprintf("select * from sip_subscriptions where user='%q' and host='%q'", 
-									  to_user, to_host, to_user, to_host))) {
-				switch_mutex_lock(profile->ireg_mutex);
-				switch_core_db_exec(db, sql, sub_reg_callback, profile, &errmsg);
-				switch_mutex_unlock(profile->ireg_mutex);
-				switch_safe_free(sql);
-			}
-			switch_core_db_close(db);
-		end:
-		
-			if (event) {
-				su_free(profile->home, event);
-			}
-			if (call_id) {
-				su_free(profile->home, call_id);
-			}
-			if (full_from) {
-				su_free(profile->home, full_from);
-			}
-			if (full_via) {
-				su_free(profile->home, full_via);
-			}
 
-			switch_safe_free(d_user);
-			switch_safe_free(to_str);
-			switch_safe_free(contact_str);
+
+		switch_safe_free(sstr);
+
+		if (!(db = switch_core_db_open_file(profile->dbname))) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
+			goto end;
 		}
+		if ((sql = switch_mprintf("select * from sip_subscriptions where user='%q' and host='%q'", to_user, to_host, to_user, to_host))) {
+			switch_mutex_lock(profile->ireg_mutex);
+			switch_core_db_exec(db, sql, sub_reg_callback, profile, &errmsg);
+			switch_mutex_unlock(profile->ireg_mutex);
+			switch_safe_free(sql);
+		}
+		switch_core_db_close(db);
+	  end:
+
+		if (event) {
+			su_free(profile->home, event);
+		}
+		if (call_id) {
+			su_free(profile->home, call_id);
+		}
+		if (full_from) {
+			su_free(profile->home, full_from);
+		}
+		if (full_via) {
+			su_free(profile->home, full_via);
+		}
+
+		switch_safe_free(d_user);
+		switch_safe_free(to_str);
+		switch_safe_free(contact_str);
+	}
 }
 
 static void sip_r_subscribe(int status,
-						char const *phrase, 
-						nua_t *nua,
-						sofia_profile_t *profile,
-						nua_handle_t *nh,
-						sofia_private_t *sofia_private,
-						sip_t const *sip,
-						tagi_t tags[])
+							char const *phrase,
+							nua_t * nua, sofia_profile_t * profile, nua_handle_t * nh, sofia_private_t * sofia_private, sip_t const *sip, tagi_t tags[])
 {
 
 }
 
 
 /*---------------------------------------*/
-static void sip_i_refer(nua_t *nua,
-						sofia_profile_t *profile,
-						nua_handle_t *nh,
-                        switch_core_session_t *session,
-						sip_t const *sip,
-						tagi_t tags[])
+static void sip_i_refer(nua_t * nua, sofia_profile_t * profile, nua_handle_t * nh, switch_core_session_t *session, sip_t const *sip, tagi_t tags[])
 {
 	/* Incoming refer */
 	sip_from_t const *from;
 	sip_to_t const *to;
 	sip_refer_to_t const *refer_to;
-    private_object_t *tech_pvt = NULL;
-    char *etmp = NULL, *exten = NULL;
-    switch_channel_t *channel_a = NULL, *channel_b = NULL;
-
-    tech_pvt = switch_core_session_get_private(session);
-    channel_a = switch_core_session_get_channel(session);
-
-    if (!sip->sip_cseq || !(etmp = switch_mprintf("refer;id=%u", sip->sip_cseq->cs_seq))) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error!\n");
-        goto done;
-    }
-
-
-    if (switch_channel_test_flag(channel_a, CF_NOMEDIA)) {
-        nua_notify(tech_pvt->nh, SIPTAG_CONTENT_TYPE_STR("message/sipfrag"),
-                   NUTAG_SUBSTATE(nua_substate_terminated),
-                   SIPTAG_PAYLOAD_STR("SIP/2.0 403 Forbidden"),
-                   SIPTAG_EVENT_STR(etmp),
-                   TAG_END());
-        goto done;
-    }
-		
-    from = sip->sip_from;
-    to = sip->sip_to;
-
-    if ((refer_to = sip->sip_refer_to)) {
-        if (profile->pflags & PFLAG_FULL_ID) {
-            exten = switch_mprintf("%s@%s", (char *) refer_to->r_url->url_user, (char *) refer_to->r_url->url_host);
-        } else {
-            exten = (char *) refer_to->r_url->url_user;
-        }
-
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Process REFER to [%s@%s]\n", exten, (char *) refer_to->r_url->url_host);
-
-        if (refer_to->r_url->url_headers) {
-            sip_replaces_t *replaces;
-            nua_handle_t *bnh;
-            char *rep;
-
-            if ((rep = strchr(refer_to->r_url->url_headers, '='))) {
-                char *br_a = NULL, *br_b = NULL;
-                char *buf;
-                rep++;
-
-					
-
-                if ((buf = switch_core_session_alloc(session, strlen(rep) + 1))) {
-                    rep = url_unescape(buf, (const char *) rep); 
-                    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Replaces: [%s]\n", rep);
-                } else {
-                    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error!\n");
-                    goto done;
-                }
-                if ((replaces = sip_replaces_make(tech_pvt->home, rep)) && (bnh = nua_handle_by_replaces(nua, replaces))) {
-                    sofia_private_t *b_private = NULL;
-                    private_object_t *b_tech_pvt = NULL;
-                    switch_core_session_t *b_session = NULL;
-
-                    switch_channel_set_variable(channel_a, SOFIA_REPLACES_HEADER, rep);	
-                    if ((b_private = nua_handle_magic(bnh))) {
-                        if (!(b_session = switch_core_session_locate(b_private->uuid))) {
-                            goto done;
-                        }
-                        b_tech_pvt = (private_object_t *) switch_core_session_get_private(b_session);
-                        channel_b = switch_core_session_get_channel(b_session);
-				
-                        br_a = switch_channel_get_variable(channel_a, SWITCH_SIGNAL_BOND_VARIABLE);
-                        br_b = switch_channel_get_variable(channel_b, SWITCH_SIGNAL_BOND_VARIABLE);
-
-                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Attended Transfer [%s][%s]\n", br_a, br_b);
-                            
-                        if (br_a && br_b) {
-                            switch_ivr_uuid_bridge(br_a, br_b);
-                            switch_channel_set_variable(channel_b, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "ATTENDED_TRANSFER");
-                            switch_set_flag_locked(tech_pvt, TFLAG_BYE);
-                            switch_set_flag_locked(b_tech_pvt, TFLAG_BYE);
-                            nua_notify(tech_pvt->nh, SIPTAG_CONTENT_TYPE_STR("message/sipfrag"),
-                                       NUTAG_SUBSTATE(nua_substate_terminated),
-                                       SIPTAG_PAYLOAD_STR("SIP/2.0 200 OK"),
-                                       SIPTAG_EVENT_STR(etmp),
-                                       TAG_END());
-                                
-                        } else {
-                            if (!br_a && !br_b) {
-                                switch_set_flag_locked(tech_pvt, TFLAG_NOHUP);
-                                switch_set_flag_locked(b_tech_pvt, TFLAG_XFER);
-                                b_tech_pvt->xferto = switch_core_session_strdup(b_session, switch_core_session_get_uuid(session));
-                            } else if (!br_a && br_b) {
-                                switch_core_session_t *br_b_session;
-
-                                if ((br_b_session = switch_core_session_locate(br_b))) {
-                                    private_object_t *br_b_tech_pvt = switch_core_session_get_private(br_b_session);
-                                    switch_channel_t *br_b_channel = switch_core_session_get_channel(br_b_session);
-                                    
-                                    switch_set_flag_locked(tech_pvt, TFLAG_NOHUP);
-										
-                                    switch_channel_clear_state_handler(br_b_channel, NULL);
-                                    switch_channel_set_state_flag(br_b_channel, CF_TRANSFER);
-                                    switch_channel_set_state(br_b_channel, CS_TRANSMIT);
-
-                                    switch_set_flag_locked(tech_pvt, TFLAG_REINVITE);
-                                    tech_pvt->local_sdp_audio_ip = switch_core_session_strdup(session, b_tech_pvt->local_sdp_audio_ip);
-                                    tech_pvt->local_sdp_audio_port = b_tech_pvt->local_sdp_audio_port;
-
-                                    tech_pvt->remote_sdp_audio_ip = switch_core_session_strdup(session, br_b_tech_pvt->remote_sdp_audio_ip);
-                                    tech_pvt->remote_sdp_audio_port = br_b_tech_pvt->remote_sdp_audio_port;
-                                    activate_rtp(tech_pvt);
-	
-                                    br_b_tech_pvt->kick = switch_core_session_strdup(br_b_session, switch_core_session_get_uuid(session));
-										
-
-                                    switch_core_session_rwunlock(br_b_session);
-                                }
-
-                                switch_channel_hangup(channel_b, SWITCH_CAUSE_ATTENDED_TRANSFER);
-                            }
-                            switch_set_flag_locked(tech_pvt, TFLAG_BYE);
-                            nua_notify(tech_pvt->nh, SIPTAG_CONTENT_TYPE_STR("message/sipfrag"),
-                                       NUTAG_SUBSTATE(nua_substate_terminated),
-                                       SIPTAG_PAYLOAD_STR("SIP/2.0 200 OK"),
-                                       SIPTAG_EVENT_STR(etmp),
-                                       TAG_END());
-
-                        }
-                        if (b_session) {
-                            switch_core_session_rwunlock(b_session);
-                        }
-                    }
-                    nua_handle_unref(bnh);
-                } else { /* the other channel is on a different box, we have to go find them */
-                    if (exten && (br_a = switch_channel_get_variable(channel_a, SWITCH_SIGNAL_BOND_VARIABLE))) {
-                        switch_core_session_t *a_session;
-                        switch_channel_t *channel = switch_core_session_get_channel(session);
-							
-                        if ((a_session = switch_core_session_locate(br_a))) {
-                            switch_core_session_t *tsession;
-                            switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING;
-                            uint32_t timeout = 60;
-                            char *tuuid_str;
-
-                            channel = switch_core_session_get_channel(a_session);
-
-                            exten = switch_mprintf("sofia/%s/%s@%s:%s", 
-                                                   profile->name,
-                                                   (char *) refer_to->r_url->url_user,
-                                                   (char *) refer_to->r_url->url_host,
-                                                   refer_to->r_url->url_port
-                                                   );
-
-                            switch_channel_set_variable(channel, SOFIA_REPLACES_HEADER, rep);
-								
-                            if (switch_ivr_originate(a_session,
-                                                     &tsession,
-                                                     &cause,
-                                                     exten,
-                                                     timeout,
-                                                     &noop_state_handler,
-                                                     NULL,
-                                                     NULL,
-                                                     NULL) != SWITCH_STATUS_SUCCESS) {
-                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Create Outgoing Channel! [%s]\n", exten);
-                                nua_notify(tech_pvt->nh, SIPTAG_CONTENT_TYPE_STR("message/sipfrag"),
-                                           NUTAG_SUBSTATE(nua_substate_terminated),
-                                           SIPTAG_PAYLOAD_STR("SIP/2.0 403 Forbidden"),
-                                           SIPTAG_EVENT_STR(etmp),
-                                           TAG_END());
-                                goto done;
-                            } 
-
-                            switch_core_session_rwunlock(a_session);
-                            tuuid_str = switch_core_session_get_uuid(tsession);
-                            switch_ivr_uuid_bridge(br_a, tuuid_str);
-                            switch_channel_set_variable(channel_a, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "ATTENDED_TRANSFER");
-                            switch_set_flag_locked(tech_pvt, TFLAG_BYE);
-                            nua_notify(tech_pvt->nh, SIPTAG_CONTENT_TYPE_STR("message/sipfrag"),
-                                       NUTAG_SUBSTATE(nua_substate_terminated),
-                                       SIPTAG_PAYLOAD_STR("SIP/2.0 200 OK"),
-                                       SIPTAG_EVENT_STR(etmp),
-                                       TAG_END());
-                        } else {
-                            goto error;
-                        }
-
-                    } else { error:
-                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Transfer! [%s]\n", br_a);
-                        switch_channel_set_variable(channel_a, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "ATTENDED_TRANSFER_ERROR");
-                        nua_notify(tech_pvt->nh, SIPTAG_CONTENT_TYPE_STR("message/sipfrag"),
-                                   NUTAG_SUBSTATE(nua_substate_terminated),
-                                   SIPTAG_PAYLOAD_STR("SIP/2.0 403 Forbidden"),
-                                   SIPTAG_EVENT_STR(etmp),
-                                   TAG_END());
-                    }
-                }
-            } else {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot parse Replaces!\n");
-            }
-            goto done;
-        }
-
-    } else {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing Refer-To\n");
-        goto done;
-    }
-
-    if (exten) {
-        switch_channel_t *channel = switch_core_session_get_channel(session);
-        char *br;
-				
-        if ((br = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))) {
-            switch_core_session_t *b_session;
-				
-            if ((b_session = switch_core_session_locate(br))) {
-                switch_channel_set_variable(channel, "TRANSFER_FALLBACK", from->a_user);
-                switch_ivr_session_transfer(b_session, exten, profile->dialplan, profile->context);
-                switch_core_session_rwunlock(b_session);
-            } 
-
-            switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "BLIND_TRANSFER");
-                
-            /*
-              nua_notify(tech_pvt->nh, SIPTAG_CONTENT_TYPE_STR("message/sipfrag"),
-              NUTAG_SUBSTATE(nua_substate_terminated),
-              SIPTAG_PAYLOAD_STR("SIP/2.0 200 OK"),
-              SIPTAG_EVENT_STR(etmp),
-              TAG_END());
-            */
-        } else {
-            exten = switch_mprintf("sip:%s@%s:%s", 
-                                   (char *) refer_to->r_url->url_user,
-                                   (char *) refer_to->r_url->url_host,
-                                   refer_to->r_url->url_port);
-            tech_pvt->dest = switch_core_session_strdup(session, exten);
-				
-				
-            switch_set_flag_locked(tech_pvt, TFLAG_NOHUP);
-
-            /*
-              nua_notify(tech_pvt->nh, SIPTAG_CONTENT_TYPE_STR("message/sipfrag"),
-              NUTAG_SUBSTATE(nua_substate_terminated),
-              SIPTAG_PAYLOAD_STR("SIP/2.0 200 OK"),
-              SIPTAG_EVENT_STR(etmp),
-              TAG_END());
-            */
-            do_xfer_invite(session);
-
-        }
-    }
-
- done:
-    if (exten && strchr(exten, '@')) {
-        switch_safe_free(exten);
-    }
-    if (etmp) {
-        switch_safe_free(etmp);
-    }
-	
-
-}
-
-
-static void sip_i_publish(nua_t *nua, 
-						  sofia_profile_t *profile,
-						  nua_handle_t *nh, 
-						  sofia_private_t *sofia_private,
-						  sip_t const *sip,
-						  tagi_t tags[])
+	private_object_t *tech_pvt = NULL;
+	char *etmp = NULL, *exten = NULL;
+	switch_channel_t *channel_a = NULL, *channel_b = NULL;
+
+	tech_pvt = switch_core_session_get_private(session);
+	channel_a = switch_core_session_get_channel(session);
+
+	if (!sip->sip_cseq || !(etmp = switch_mprintf("refer;id=%u", sip->sip_cseq->cs_seq))) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error!\n");
+		goto done;
+	}
+
+
+	if (switch_channel_test_flag(channel_a, CF_NOMEDIA)) {
+		nua_notify(tech_pvt->nh, SIPTAG_CONTENT_TYPE_STR("message/sipfrag"),
+				   NUTAG_SUBSTATE(nua_substate_terminated), SIPTAG_PAYLOAD_STR("SIP/2.0 403 Forbidden"), SIPTAG_EVENT_STR(etmp), TAG_END());
+		goto done;
+	}
+
+	from = sip->sip_from;
+	to = sip->sip_to;
+
+	if ((refer_to = sip->sip_refer_to)) {
+		if (profile->pflags & PFLAG_FULL_ID) {
+			exten = switch_mprintf("%s@%s", (char *) refer_to->r_url->url_user, (char *) refer_to->r_url->url_host);
+		} else {
+			exten = (char *) refer_to->r_url->url_user;
+		}
+
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Process REFER to [%s@%s]\n", exten, (char *) refer_to->r_url->url_host);
+
+		if (refer_to->r_url->url_headers) {
+			sip_replaces_t *replaces;
+			nua_handle_t *bnh;
+			char *rep;
+
+			if ((rep = strchr(refer_to->r_url->url_headers, '='))) {
+				char *br_a = NULL, *br_b = NULL;
+				char *buf;
+				rep++;
+
+
+
+				if ((buf = switch_core_session_alloc(session, strlen(rep) + 1))) {
+					rep = url_unescape(buf, (const char *) rep);
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Replaces: [%s]\n", rep);
+				} else {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error!\n");
+					goto done;
+				}
+				if ((replaces = sip_replaces_make(tech_pvt->home, rep))
+					&& (bnh = nua_handle_by_replaces(nua, replaces))) {
+					sofia_private_t *b_private = NULL;
+					private_object_t *b_tech_pvt = NULL;
+					switch_core_session_t *b_session = NULL;
+
+					switch_channel_set_variable(channel_a, SOFIA_REPLACES_HEADER, rep);
+					if ((b_private = nua_handle_magic(bnh))) {
+						if (!(b_session = switch_core_session_locate(b_private->uuid))) {
+							goto done;
+						}
+						b_tech_pvt = (private_object_t *) switch_core_session_get_private(b_session);
+						channel_b = switch_core_session_get_channel(b_session);
+
+						br_a = switch_channel_get_variable(channel_a, SWITCH_SIGNAL_BOND_VARIABLE);
+						br_b = switch_channel_get_variable(channel_b, SWITCH_SIGNAL_BOND_VARIABLE);
+
+						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Attended Transfer [%s][%s]\n", br_a, br_b);
+
+						if (br_a && br_b) {
+							switch_ivr_uuid_bridge(br_a, br_b);
+							switch_channel_set_variable(channel_b, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "ATTENDED_TRANSFER");
+							switch_set_flag_locked(tech_pvt, TFLAG_BYE);
+							switch_set_flag_locked(b_tech_pvt, TFLAG_BYE);
+							nua_notify(tech_pvt->nh, SIPTAG_CONTENT_TYPE_STR("message/sipfrag"),
+									   NUTAG_SUBSTATE(nua_substate_terminated), SIPTAG_PAYLOAD_STR("SIP/2.0 200 OK"), SIPTAG_EVENT_STR(etmp), TAG_END());
+
+						} else {
+							if (!br_a && !br_b) {
+								switch_set_flag_locked(tech_pvt, TFLAG_NOHUP);
+								switch_set_flag_locked(b_tech_pvt, TFLAG_XFER);
+								b_tech_pvt->xferto = switch_core_session_strdup(b_session, switch_core_session_get_uuid(session));
+							} else if (!br_a && br_b) {
+								switch_core_session_t *br_b_session;
+
+								if ((br_b_session = switch_core_session_locate(br_b))) {
+									private_object_t *br_b_tech_pvt = switch_core_session_get_private(br_b_session);
+									switch_channel_t *br_b_channel = switch_core_session_get_channel(br_b_session);
+
+									switch_set_flag_locked(tech_pvt, TFLAG_NOHUP);
+
+									switch_channel_clear_state_handler(br_b_channel, NULL);
+									switch_channel_set_state_flag(br_b_channel, CF_TRANSFER);
+									switch_channel_set_state(br_b_channel, CS_TRANSMIT);
+
+									switch_set_flag_locked(tech_pvt, TFLAG_REINVITE);
+									tech_pvt->local_sdp_audio_ip = switch_core_session_strdup(session, b_tech_pvt->local_sdp_audio_ip);
+									tech_pvt->local_sdp_audio_port = b_tech_pvt->local_sdp_audio_port;
+
+									tech_pvt->remote_sdp_audio_ip = switch_core_session_strdup(session, br_b_tech_pvt->remote_sdp_audio_ip);
+									tech_pvt->remote_sdp_audio_port = br_b_tech_pvt->remote_sdp_audio_port;
+									activate_rtp(tech_pvt);
+
+									br_b_tech_pvt->kick = switch_core_session_strdup(br_b_session, switch_core_session_get_uuid(session));
+
+
+									switch_core_session_rwunlock(br_b_session);
+								}
+
+								switch_channel_hangup(channel_b, SWITCH_CAUSE_ATTENDED_TRANSFER);
+							}
+							switch_set_flag_locked(tech_pvt, TFLAG_BYE);
+							nua_notify(tech_pvt->nh, SIPTAG_CONTENT_TYPE_STR("message/sipfrag"),
+									   NUTAG_SUBSTATE(nua_substate_terminated), SIPTAG_PAYLOAD_STR("SIP/2.0 200 OK"), SIPTAG_EVENT_STR(etmp), TAG_END());
+
+						}
+						if (b_session) {
+							switch_core_session_rwunlock(b_session);
+						}
+					}
+					nua_handle_unref(bnh);
+				} else {		/* the other channel is on a different box, we have to go find them */
+					if (exten && (br_a = switch_channel_get_variable(channel_a, SWITCH_SIGNAL_BOND_VARIABLE))) {
+						switch_core_session_t *a_session;
+						switch_channel_t *channel = switch_core_session_get_channel(session);
+
+						if ((a_session = switch_core_session_locate(br_a))) {
+							switch_core_session_t *tsession;
+							switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING;
+							uint32_t timeout = 60;
+							char *tuuid_str;
+
+							channel = switch_core_session_get_channel(a_session);
+
+							exten = switch_mprintf("sofia/%s/%s@%s:%s",
+												   profile->name,
+												   (char *) refer_to->r_url->url_user, (char *) refer_to->r_url->url_host, refer_to->r_url->url_port);
+
+							switch_channel_set_variable(channel, SOFIA_REPLACES_HEADER, rep);
+
+							if (switch_ivr_originate(a_session,
+													 &tsession, &cause, exten, timeout, &noop_state_handler, NULL, NULL, NULL) != SWITCH_STATUS_SUCCESS) {
+								switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Create Outgoing Channel! [%s]\n", exten);
+								nua_notify(tech_pvt->nh, SIPTAG_CONTENT_TYPE_STR("message/sipfrag"),
+										   NUTAG_SUBSTATE(nua_substate_terminated),
+										   SIPTAG_PAYLOAD_STR("SIP/2.0 403 Forbidden"), SIPTAG_EVENT_STR(etmp), TAG_END());
+								goto done;
+							}
+
+							switch_core_session_rwunlock(a_session);
+							tuuid_str = switch_core_session_get_uuid(tsession);
+							switch_ivr_uuid_bridge(br_a, tuuid_str);
+							switch_channel_set_variable(channel_a, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "ATTENDED_TRANSFER");
+							switch_set_flag_locked(tech_pvt, TFLAG_BYE);
+							nua_notify(tech_pvt->nh, SIPTAG_CONTENT_TYPE_STR("message/sipfrag"),
+									   NUTAG_SUBSTATE(nua_substate_terminated), SIPTAG_PAYLOAD_STR("SIP/2.0 200 OK"), SIPTAG_EVENT_STR(etmp), TAG_END());
+						} else {
+							goto error;
+						}
+
+					} else {
+					  error:
+						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Transfer! [%s]\n", br_a);
+						switch_channel_set_variable(channel_a, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "ATTENDED_TRANSFER_ERROR");
+						nua_notify(tech_pvt->nh, SIPTAG_CONTENT_TYPE_STR("message/sipfrag"),
+								   NUTAG_SUBSTATE(nua_substate_terminated), SIPTAG_PAYLOAD_STR("SIP/2.0 403 Forbidden"), SIPTAG_EVENT_STR(etmp),
+								   TAG_END());
+					}
+				}
+			} else {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot parse Replaces!\n");
+			}
+			goto done;
+		}
+
+	} else {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing Refer-To\n");
+		goto done;
+	}
+
+	if (exten) {
+		switch_channel_t *channel = switch_core_session_get_channel(session);
+		char *br;
+
+		if ((br = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))) {
+			switch_core_session_t *b_session;
+
+			if ((b_session = switch_core_session_locate(br))) {
+				switch_channel_set_variable(channel, "TRANSFER_FALLBACK", from->a_user);
+				switch_ivr_session_transfer(b_session, exten, profile->dialplan, profile->context);
+				switch_core_session_rwunlock(b_session);
+			}
+
+			switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "BLIND_TRANSFER");
+
+			/*
+			   nua_notify(tech_pvt->nh, SIPTAG_CONTENT_TYPE_STR("message/sipfrag"),
+			   NUTAG_SUBSTATE(nua_substate_terminated),
+			   SIPTAG_PAYLOAD_STR("SIP/2.0 200 OK"),
+			   SIPTAG_EVENT_STR(etmp),
+			   TAG_END());
+			 */
+		} else {
+			exten = switch_mprintf("sip:%s@%s:%s", (char *) refer_to->r_url->url_user, (char *) refer_to->r_url->url_host, refer_to->r_url->url_port);
+			tech_pvt->dest = switch_core_session_strdup(session, exten);
+
+
+			switch_set_flag_locked(tech_pvt, TFLAG_NOHUP);
+
+			/*
+			   nua_notify(tech_pvt->nh, SIPTAG_CONTENT_TYPE_STR("message/sipfrag"),
+			   NUTAG_SUBSTATE(nua_substate_terminated),
+			   SIPTAG_PAYLOAD_STR("SIP/2.0 200 OK"),
+			   SIPTAG_EVENT_STR(etmp),
+			   TAG_END());
+			 */
+			do_xfer_invite(session);
+
+		}
+	}
+
+  done:
+	if (exten && strchr(exten, '@')) {
+		switch_safe_free(exten);
+	}
+	if (etmp) {
+		switch_safe_free(etmp);
+	}
+
+
+}
+
+
+static void sip_i_publish(nua_t * nua, sofia_profile_t * profile, nua_handle_t * nh, sofia_private_t * sofia_private, sip_t const *sip, tagi_t tags[])
 {
 	if (sip) {
 		sip_from_t const *from = sip->sip_from;
@@ -4331,11 +4082,12 @@
 
 			if ((xml = switch_xml_parse_str(payload->pl_data, strlen(payload->pl_data)))) {
 				char *status_txt = "", *note_txt = "";
-				
-				if ((tuple = switch_xml_child(xml, "tuple")) && (status = switch_xml_child(tuple, "status")) && (basic = switch_xml_child(status, "basic"))) {
+
+				if ((tuple = switch_xml_child(xml, "tuple")) && (status = switch_xml_child(tuple, "status"))
+					&& (basic = switch_xml_child(status, "basic"))) {
 					status_txt = basic->txt;
 				}
-					
+
 				if ((person = switch_xml_child(xml, "dm:person")) && (note = switch_xml_child(person, "dm:note"))) {
 					note_txt = note->txt;
 				}
@@ -4358,14 +4110,15 @@
 						note_txt = "Unavailable";
 					}
 				}
-				
-				if ((sql = switch_mprintf("update sip_registrations set status='%q',rpid='%q' where user='%q' and host='%q'", 
-										  note_txt, rpid, from_user, from_host))) {
+
+				if ((sql =
+					 switch_mprintf("update sip_registrations set status='%q',rpid='%q' where user='%q' and host='%q'",
+									note_txt, rpid, from_user, from_host))) {
 					execute_sql(profile->dbname, sql, profile->ireg_mutex);
 					switch_safe_free(sql);
 				}
-				
-				event_type = sip_header_as_string(profile->home, (void *)sip->sip_event);
+
+				event_type = sip_header_as_string(profile->home, (void *) sip->sip_event);
 
 				if (in) {
 					if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
@@ -4373,7 +4126,7 @@
 						switch_event_add_header(event, SWITCH_STACK_BOTTOM, "rpid", "%s", rpid);
 						switch_event_add_header(event, SWITCH_STACK_BOTTOM, "login", "%s", profile->url);
 						switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", from_user, from_host);
-						
+
 						switch_event_add_header(event, SWITCH_STACK_BOTTOM, "status", "%s", note_txt);
 						switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_type", "%s", event_type);
 						switch_event_fire(&event);
@@ -4392,25 +4145,21 @@
 
 				if (event_type) {
 					su_free(profile->home, event_type);
-				}				
+				}
 
 				switch_xml_free(xml);
 			}
-			
+
 		}
-		
+
 	}
 
 	nua_respond(nh, SIP_200_OK, NUTAG_WITH_THIS(nua), TAG_END());
 
 }
 
-static void sip_i_info(nua_t *nua,
-                       sofia_profile_t *profile,
-                       nua_handle_t *nh,
-                       switch_core_session_t *session,
-                       sip_t const *sip,
-                       tagi_t tags[]) {
+static void sip_i_info(nua_t * nua, sofia_profile_t * profile, nua_handle_t * nh, switch_core_session_t *session, sip_t const *sip, tagi_t tags[])
+{
 
 	//placeholder for string searching
 	char *signal_ptr;
@@ -4419,10 +4168,10 @@
 	signal_ptr = strstr(sip->sip_payload->pl_data, "Signal=");
 
 	//See if we found a match
-	if(signal_ptr) {
+	if (signal_ptr) {
 		struct private_object *tech_pvt = NULL;
 		switch_channel_t *channel = NULL;
-		char dtmf_digit[2] = {0,0};
+		char dtmf_digit[2] = { 0, 0 };
 
 		//Get the channel
 		channel = switch_core_session_get_channel(session);
@@ -4444,19 +4193,18 @@
 
 		//queue it up
 		switch_channel_queue_dtmf(channel, dtmf_digit);
-		
+
 		//print debug info
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "INFO DTMF(%s)\n", dtmf_digit);
 
-	} else { //unknown info type
+	} else {					//unknown info type
 		sip_from_t const *from;
 
 		from = sip->sip_from;
 
 		//print in the logs if something comes through we don't understand
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Unknown INFO Recieved: %s%s" URL_PRINT_FORMAT "[%s]\n",
-		                  from->a_display ? from->a_display : "", from->a_display ? " " : "",
-		                  URL_PRINT_ARGS(from->a_url), sip->sip_payload->pl_data);
+						  from->a_display ? from->a_display : "", from->a_display ? " " : "", URL_PRINT_ARGS(from->a_url), sip->sip_payload->pl_data);
 	}
 
 	return;
@@ -4464,7 +4212,8 @@
 
 
 #define url_set_chanvars(session, url, varprefix) _url_set_chanvars(session, url, #varprefix "_user", #varprefix "_host", #varprefix "_port", #varprefix "_uri")
-static const char * _url_set_chanvars(switch_core_session_t *session, url_t *url, const char * user_var, const char * host_var, const char * port_var, const char * uri_var)
+static const char *_url_set_chanvars(switch_core_session_t *session, url_t * url, const char *user_var,
+									 const char *host_var, const char *port_var, const char *uri_var)
 {
 	const char *user = NULL, *host = NULL, *port = NULL;
 	char *uri = NULL;
@@ -4498,22 +4247,22 @@
 	return uri;
 }
 
-static void process_rpid(sip_unknown_t *un, private_object_t *tech_pvt)
+static void process_rpid(sip_unknown_t * un, private_object_t * tech_pvt)
 {
 	int argc, x, screen = 1;
 	char *mydata, *argv[10] = { 0 };
-	if (!switch_strlen_zero(un->un_value)) { 
+	if (!switch_strlen_zero(un->un_value)) {
 		if ((mydata = strdup(un->un_value))) {
-			argc = switch_separate_string(mydata, ';', argv, (sizeof(argv) / sizeof(argv[0]))); 
+			argc = switch_separate_string(mydata, ';', argv, (sizeof(argv) / sizeof(argv[0])));
 
 			// Do We really need this at this time 
 			// clid_uri = argv[0];
 
-			for (x=1; x < argc && argv[x]; x++){
+			for (x = 1; x < argc && argv[x]; x++) {
 				// we dont need to do anything with party yet we should only be seeing party=calling here anyway
 				// maybe thats a dangerous assumption bit oh well yell at me later
 				// if (!strncasecmp(argv[x], "party", 5)) {
-				//	party = argv[x];
+				//  party = argv[x];
 				// } else 
 				if (!strncasecmp(argv[x], "privacy=", 8)) {
 					char *arg = argv[x] + 9;
@@ -4544,12 +4293,7 @@
 	}
 }
 
-static void sip_i_invite(nua_t *nua, 
-						 sofia_profile_t *profile,
-						 nua_handle_t *nh, 
-						 sofia_private_t *sofia_private,
-						 sip_t const *sip,
-						 tagi_t tags[])
+static void sip_i_invite(nua_t * nua, sofia_profile_t * profile, nua_handle_t * nh, sofia_private_t * sofia_private, sip_t const *sip, tagi_t tags[])
 {
 	switch_core_session_t *session = NULL;
 	char key[128] = "";
@@ -4599,7 +4343,7 @@
 		tech_pvt->key = switch_core_session_strdup(session, key);
 	}
 
-	get_addr(network_ip, sizeof(network_ip), &((struct sockaddr_in *)msg_addrinfo(nua_current_request(nua))->ai_addr)->sin_addr);
+	get_addr(network_ip, sizeof(network_ip), &((struct sockaddr_in *) msg_addrinfo(nua_current_request(nua))->ai_addr)->sin_addr);
 
 	channel = switch_core_session_get_channel(session);
 
@@ -4610,7 +4354,7 @@
 
 		if (!switch_strlen_zero(from_user)) {
 			if (*from_user == '+') {
-				switch_channel_set_variable(channel, "sip_from_user_stripped", (const char *)(from_user+1));
+				switch_channel_set_variable(channel, "sip_from_user_stripped", (const char *) (from_user + 1));
 			} else {
 				switch_channel_set_variable(channel, "sip_from_user_stripped", from_user);
 			}
@@ -4634,8 +4378,8 @@
 	}
 
 	if (sip->sip_request->rq_url) {
-		const char * req_uri = url_set_chanvars(session, sip->sip_request->rq_url, sip_req);
-		if (profile->pflags & PFLAG_FULL_ID)  {
+		const char *req_uri = url_set_chanvars(session, sip->sip_request->rq_url, sip_req);
+		if (profile->pflags & PFLAG_FULL_ID) {
 			destination_number = req_uri;
 		} else {
 			destination_number = sip->sip_request->rq_url->url_user;
@@ -4687,19 +4431,19 @@
 		switch_channel_set_variable(channel, SWITCH_MAX_FORWARDS_VARIABLE, max_forwards);
 	}
 
-	
+
 	if (sip->sip_request->rq_url) {
 		outbound_reg_t *gateway;
 		char *from_key = switch_core_session_sprintf(session, "sip:%s@%s",
 													 (char *) sip->sip_request->rq_url->url_user,
 													 (char *) sip->sip_request->rq_url->url_host);
-		
+
 		if ((gateway = find_gateway(from_key))) {
 			context = gateway->register_context;
 			switch_channel_set_variable(channel, "sip_gateway", gateway->name);
 		}
 	}
-	
+
 
 	if (!context) {
 		if (profile->context && !strcasecmp(profile->context, "_domain_")) {
@@ -4710,30 +4454,22 @@
 	}
 
 	tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
-														from_user,
-														profile->dialplan,
-														displayname,
-														from_user,
-														network_ip,
-														NULL,
-														NULL,
-														NULL,
-														modname,
-														context,
-														destination_number);
+														 from_user,
+														 profile->dialplan,
+														 displayname, from_user, network_ip, NULL, NULL, NULL, modname, context, destination_number);
 
 	if (tech_pvt->caller_profile) {
-				
+
 		/* Loop thru unknown Headers Here so we can do something with them */
-		for (un=sip->sip_unknown; un; un=un->un_next) {
+		for (un = sip->sip_unknown; un; un = un->un_next) {
 			if (!strncasecmp(un->un_name, "Alert-Info", 10)) {
-				if (!switch_strlen_zero(un->un_value)) { 
+				if (!switch_strlen_zero(un->un_value)) {
 					switch_channel_set_variable(channel, "alert_info", un->un_value);
 				}
 			} else if (!strncasecmp(un->un_name, "Remote-Party-ID", 15)) {
 				process_rpid(un, tech_pvt);
 			} else if (!strncasecmp(un->un_name, "X-", 2)) {
-				if (!switch_strlen_zero(un->un_value)) { 
+				if (!switch_strlen_zero(un->un_value)) {
 					char *new_name;
 					if ((new_name = switch_mprintf("%s%s", SOFIA_SIP_HEADER_PREFIX, un->un_name))) {
 						switch_channel_set_variable(channel, new_name, un->un_value);
@@ -4755,14 +4491,9 @@
 	tech_pvt->nh = nh;
 }
 
-static void sip_i_register(nua_t *nua,
-						   sofia_profile_t *profile,
-						   nua_handle_t *nh,
-						   sofia_private_t *sofia_private,
-						   sip_t const *sip,
-						   tagi_t tags[])
+static void sip_i_register(nua_t * nua, sofia_profile_t * profile, nua_handle_t * nh, sofia_private_t * sofia_private, sip_t const *sip, tagi_t tags[])
 {
-    char key[128] = "";
+	char key[128] = "";
 
 	if (!sip || !sip->sip_request || !sip->sip_request->rq_method_name) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Received an invalid packet!\n");
@@ -4782,14 +4513,9 @@
 
 static void sip_i_options(int status,
 						  char const *phrase,
-						  nua_t *nua,
-						  sofia_profile_t *profile,
-						  nua_handle_t *nh,
-						  sofia_private_t *sofia_private,
-						  sip_t const *sip,
-						  tagi_t tags[])
+						  nua_t * nua, sofia_profile_t * profile, nua_handle_t * nh, sofia_private_t * sofia_private, sip_t const *sip, tagi_t tags[])
 {
-	nua_respond(nh, SIP_200_OK, 
+	nua_respond(nh, SIP_200_OK,
 				//SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
 				//SOATAG_AUDIO_AUX("cn telephone-event"),
 				//NUTAG_INCLUDE_EXTRA_SDP(1),
@@ -4799,20 +4525,15 @@
 
 static void sip_r_register(int status,
 						   char const *phrase,
-						   nua_t *nua,
-						   sofia_profile_t *profile,
-						   nua_handle_t *nh,
-						   sofia_private_t *sofia_private,
-						   sip_t const *sip,
-						   tagi_t tags[])
+						   nua_t * nua, sofia_profile_t * profile, nua_handle_t * nh, sofia_private_t * sofia_private, sip_t const *sip, tagi_t tags[])
 {
 	if (sofia_private && sofia_private->gateway) {
 		switch (status) {
 		case 200:
 			if (sip && sip->sip_contact && sip->sip_contact->m_expires) {
 				char *new_expires = (char *) sip->sip_contact->m_expires;
-				uint32_t expi = (uint32_t)atoi(new_expires);
-				
+				uint32_t expi = (uint32_t) atoi(new_expires);
+
 				if (expi != sofia_private->gateway->freq) {
 					sofia_private->gateway->freq = expi;
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE,
@@ -4833,24 +4554,19 @@
 }
 
 static void sip_r_challenge(int status,
-                            char const *phrase,
-                            nua_t *nua,
-                            sofia_profile_t *profile,
-                            nua_handle_t *nh,
-                            switch_core_session_t *session,
-                            sip_t const *sip,
-                            tagi_t tags[])
+							char const *phrase,
+							nua_t * nua, sofia_profile_t * profile, nua_handle_t * nh, switch_core_session_t *session, sip_t const *sip, tagi_t tags[])
 {
 	outbound_reg_t *gateway = NULL;
 	sip_www_authenticate_t const *authenticate = NULL;
-	char const *realm = NULL; 
+	char const *realm = NULL;
 	char *p = NULL, *duprealm = NULL, *qrealm = NULL;
 	char const *scheme = NULL;
 	int indexnum;
 	char *cur;
 	char authentication[256] = "";
 	int ss_state;
-	
+
 	if (session) {
 		private_object_t *tech_pvt;
 		if ((tech_pvt = switch_core_session_get_private(session)) && switch_test_flag(tech_pvt, TFLAG_REFER)) {
@@ -4870,7 +4586,7 @@
 	}
 	scheme = (char const *) authenticate->au_scheme;
 	if (authenticate->au_params) {
-		for(indexnum = 0; (cur=(char*)authenticate->au_params[indexnum]); indexnum++) {
+		for (indexnum = 0; (cur = (char *) authenticate->au_params[indexnum]); indexnum++) {
 			if ((realm = strstr(cur, "realm="))) {
 				realm += 6;
 				break;
@@ -4888,30 +4604,31 @@
 
 		if ((duprealm = strdup(realm))) {
 			qrealm = duprealm;
-	
-			while(*qrealm && *qrealm == '"') {
+
+			while (*qrealm && *qrealm == '"') {
 				qrealm++;
 			}
 
 			if ((p = strchr(qrealm, '"'))) {
 				*p = '\0';
 			}
-			
+
 			if (sip->sip_from) {
-				char *from_key = switch_mprintf("sip:%s@%s", 
+				char *from_key = switch_mprintf("sip:%s@%s",
 												(char *) sip->sip_from->a_url->url_user,
 												(char *) sip->sip_from->a_url->url_host);
 
 				if (!(gateway = find_gateway(from_key))) {
 					gateway = find_gateway(qrealm);
-				} 
-				
+				}
+
 				switch_safe_free(from_key);
 			}
 
 			if (!gateway) {
 				for (gateway_ptr = profile->gateways; gateway_ptr; gateway_ptr = gateway_ptr->next) {
-					if (scheme && qrealm && !strcasecmp(gateway_ptr->register_scheme, scheme) && !strcasecmp(gateway_ptr->register_realm, qrealm)) {
+					if (scheme && qrealm && !strcasecmp(gateway_ptr->register_scheme, scheme)
+						&& !strcasecmp(gateway_ptr->register_realm, qrealm)) {
 						gateway = gateway_ptr;
 						break;
 					}
@@ -4928,80 +4645,67 @@
 			return;
 		}
 	}
-		
-	snprintf(authentication, sizeof(authentication), "%s:%s:%s:%s", scheme, realm, 
-			 gateway->register_username,
-			 gateway->register_password);
-		
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Authenticating '%s' with '%s'.\n",
-					  profile->username, authentication);
-		
-		
+
+	snprintf(authentication, sizeof(authentication), "%s:%s:%s:%s", scheme, realm, gateway->register_username, gateway->register_password);
+
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Authenticating '%s' with '%s'.\n", profile->username, authentication);
+
+
 	ss_state = nua_callstate_authenticating;
-		
-	tl_gets(tags,
-			NUTAG_CALLSTATE_REF(ss_state),
-			SIPTAG_WWW_AUTHENTICATE_REF(authenticate),
-			TAG_END());
-		
+
+	tl_gets(tags, NUTAG_CALLSTATE_REF(ss_state), SIPTAG_WWW_AUTHENTICATE_REF(authenticate), TAG_END());
+
 	nua_authenticate(nh, SIPTAG_EXPIRES_STR(gateway->expires_str), NUTAG_AUTH(authentication), TAG_END());
-	
+
 }
 
 static void event_callback(nua_event_t event,
 						   int status,
 						   char const *phrase,
-						   nua_t *nua,
-						   sofia_profile_t *profile,
-						   nua_handle_t *nh,
-						   sofia_private_t *sofia_private,
-						   sip_t const *sip,
-						   tagi_t tags[])
+						   nua_t * nua, sofia_profile_t * profile, nua_handle_t * nh, sofia_private_t * sofia_private, sip_t const *sip, tagi_t tags[])
 {
 	struct private_object *tech_pvt = NULL;
 	auth_res_t auth_res = AUTH_FORBIDDEN;
 	switch_core_session_t *session = NULL;
-    switch_channel_t *channel = NULL;
+	switch_channel_t *channel = NULL;
 
-    if (sofia_private) {
-        if (!switch_strlen_zero(sofia_private->uuid)) {
+	if (sofia_private) {
+		if (!switch_strlen_zero(sofia_private->uuid)) {
 
-            if ((session = switch_core_session_locate(sofia_private->uuid))) {
-                tech_pvt = switch_core_session_get_private(session);
-                channel = switch_core_session_get_channel(tech_pvt->session);
-                if (switch_channel_test_flag(channel, CF_NOMEDIA)) {
-                    switch_set_flag(tech_pvt, TFLAG_NOMEDIA);
-                }
-                if (!tech_pvt->call_id && sip && sip->sip_call_id && sip->sip_call_id->i_id) {
-                    tech_pvt->call_id = switch_core_session_strdup(session, (char *)sip->sip_call_id->i_id);
-                    switch_channel_set_variable(channel, "sip_call_id", tech_pvt->call_id);
-                }
-            } else {
-                /* too late */
-                return;            
-            }
-        }
-    }
+			if ((session = switch_core_session_locate(sofia_private->uuid))) {
+				tech_pvt = switch_core_session_get_private(session);
+				channel = switch_core_session_get_channel(tech_pvt->session);
+				if (switch_channel_test_flag(channel, CF_NOMEDIA)) {
+					switch_set_flag(tech_pvt, TFLAG_NOMEDIA);
+				}
+				if (!tech_pvt->call_id && sip && sip->sip_call_id && sip->sip_call_id->i_id) {
+					tech_pvt->call_id = switch_core_session_strdup(session, (char *) sip->sip_call_id->i_id);
+					switch_channel_set_variable(channel, "sip_call_id", tech_pvt->call_id);
+				}
+			} else {
+				/* too late */
+				return;
+			}
+		}
+	}
 
 
 	if (status != 100 && status != 200) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "event [%s] status [%d][%s] session: %s\n",
-						  nua_event_name (event), status, phrase,
-						  session ? switch_channel_get_name(channel) : "n/a"
-						  );
+						  nua_event_name(event), status, phrase, session ? switch_channel_get_name(channel) : "n/a");
 	}
 
 	if ((profile->pflags & PFLAG_AUTH_ALL) && tech_pvt && tech_pvt->key && sip) {
 		sip_authorization_t const *authorization = NULL;
 
-        if (sip->sip_authorization) {
+		if (sip->sip_authorization) {
 			authorization = sip->sip_authorization;
 		} else if (sip->sip_proxy_authorization) {
 			authorization = sip->sip_proxy_authorization;
 		}
 
 		if (authorization) {
-			auth_res = parse_auth(profile, authorization, (char *)sip->sip_request->rq_method_name, tech_pvt->key, strlen(tech_pvt->key));
+			auth_res = parse_auth(profile, authorization, (char *) sip->sip_request->rq_method_name, tech_pvt->key, strlen(tech_pvt->key));
 		}
 
 		if (auth_res != AUTH_OK) {
@@ -5019,46 +4723,46 @@
 		sip_r_challenge(status, phrase, nua, profile, nh, session, sip, tags);
 		goto done;
 	}
-	
+
 	switch (event) {
-	case nua_r_shutdown:    
-	case nua_r_get_params:    
+	case nua_r_shutdown:
+	case nua_r_get_params:
 	case nua_r_invite:
-    case nua_r_unregister:
-    case nua_r_options:
+	case nua_r_unregister:
+	case nua_r_options:
 	case nua_i_fork:
 	case nua_r_info:
-    case nua_r_bye:
+	case nua_r_bye:
 	case nua_i_bye:
 	case nua_r_unsubscribe:
 	case nua_r_publish:
 	case nua_r_message:
 	case nua_r_notify:
-    case nua_i_notify:
+	case nua_i_notify:
 	case nua_i_cancel:
 	case nua_i_error:
 	case nua_i_active:
 	case nua_i_ack:
 	case nua_i_terminated:
 	case nua_r_set_params:
-        break;
+		break;
 	case nua_r_register:
 		sip_r_register(status, phrase, nua, profile, nh, sofia_private, sip, tags);
 		break;
 	case nua_i_options:
 		sip_i_options(status, phrase, nua, profile, nh, sofia_private, sip, tags);
 		break;
-    case nua_i_invite:
-        if (!session) {
-            sip_i_invite(nua, profile, nh, sofia_private, sip, tags);
-        }
+	case nua_i_invite:
+		if (!session) {
+			sip_i_invite(nua, profile, nh, sofia_private, sip, tags);
+		}
 		break;
 	case nua_i_publish:
 		sip_i_publish(nua, profile, nh, sofia_private, sip, tags);
 		break;
-    case nua_i_register:
- 		sip_i_register (nua, profile, nh, sofia_private, sip, tags);
-        break;
+	case nua_i_register:
+		sip_i_register(nua, profile, nh, sofia_private, sip, tags);
+		break;
 	case nua_i_prack:
 		break;
 	case nua_i_state:
@@ -5073,11 +4777,11 @@
 	case nua_r_refer:
 		break;
 	case nua_i_refer:
-        if (session) {
-            sip_i_refer(nua, profile, nh, session, sip, tags);
-        }
+		if (session) {
+			sip_i_refer(nua, profile, nh, session, sip, tags);
+		}
 		break;
-    case nua_r_subscribe:
+	case nua_r_subscribe:
 		sip_r_subscribe(status, phrase, nua, profile, nh, sofia_private, sip, tags);
 		break;
 	case nua_i_subscribe:
@@ -5085,15 +4789,14 @@
 		break;
 	default:
 		if (status > 100) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s: unknown event %d: %03d %s\n", 
-							  nua_event_name (event), event, status, phrase);
-        } else {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s: unknown event %d\n", nua_event_name (event), event);
-        }
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s: unknown event %d: %03d %s\n", nua_event_name(event), event, status, phrase);
+		} else {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s: unknown event %d\n", nua_event_name(event), event);
+		}
 		break;
 	}
 
- done:
+  done:
 
 	if (session) {
 		switch_core_session_rwunlock(session);
@@ -5101,44 +4804,43 @@
 }
 
 
-static void unreg(sofia_profile_t *profile)
+static void unreg(sofia_profile_t * profile)
 {
 	outbound_reg_t *gateway_ptr;
-    for (gateway_ptr = profile->gateways; gateway_ptr; gateway_ptr = gateway_ptr->next) {
-        if (gateway_ptr->sofia_private) {
-            free(gateway_ptr->sofia_private);
-            nua_handle_bind(gateway_ptr->nh, NULL);
-            gateway_ptr->sofia_private = NULL;
-        }
+	for (gateway_ptr = profile->gateways; gateway_ptr; gateway_ptr = gateway_ptr->next) {
+		if (gateway_ptr->sofia_private) {
+			free(gateway_ptr->sofia_private);
+			nua_handle_bind(gateway_ptr->nh, NULL);
+			gateway_ptr->sofia_private = NULL;
+		}
 		nua_handle_destroy(gateway_ptr->nh);
 	}
 }
 
-static void check_gateway(sofia_profile_t *profile, time_t now)
+static void check_gateway(sofia_profile_t * profile, time_t now)
 {
 	outbound_reg_t *gateway_ptr;
 	for (gateway_ptr = profile->gateways; gateway_ptr; gateway_ptr = gateway_ptr->next) {
 		int ss_state = nua_callstate_authenticating;
 		reg_state_t ostate = gateway_ptr->state;
 
-		switch(ostate) {
+		switch (ostate) {
 		case REG_STATE_REGISTER:
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE,  "registered %s\n", gateway_ptr->name);
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "registered %s\n", gateway_ptr->name);
 			gateway_ptr->expires = now + gateway_ptr->freq;
 			gateway_ptr->state = REG_STATE_REGED;
 			break;
 		case REG_STATE_UNREGED:
 			if ((gateway_ptr->nh = nua_handle(gateway_ptr->profile->nua, NULL,
-										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()))) {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE,  "registering %s\n", gateway_ptr->name);	
-                
-                if (!(gateway_ptr->sofia_private = malloc(sizeof(*gateway_ptr->sofia_private)))) {
-                    abort();
-                }
-                memset(gateway_ptr->sofia_private, 0, sizeof(*gateway_ptr->sofia_private));
+											  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()))) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "registering %s\n", gateway_ptr->name);
+
+				if (!(gateway_ptr->sofia_private = malloc(sizeof(*gateway_ptr->sofia_private)))) {
+					abort();
+				}
+				memset(gateway_ptr->sofia_private, 0, sizeof(*gateway_ptr->sofia_private));
 
 				gateway_ptr->sofia_private->gateway = gateway_ptr;
 				nua_handle_bind(gateway_ptr->nh, gateway_ptr->sofia_private);
@@ -5148,14 +4850,11 @@
 							 SIPTAG_CONTACT_STR(gateway_ptr->register_contact),
 							 SIPTAG_EXPIRES_STR(gateway_ptr->expires_str),
 							 NUTAG_REGISTRAR(gateway_ptr->register_proxy),
-							 NUTAG_OUTBOUND("no-options-keepalive"),
-							 NUTAG_OUTBOUND("no-validate"),
-							 NUTAG_KEEPALIVE(0),
-							 TAG_NULL());
+							 NUTAG_OUTBOUND("no-options-keepalive"), NUTAG_OUTBOUND("no-validate"), NUTAG_KEEPALIVE(0), TAG_NULL());
 				gateway_ptr->retry = now + 10;
 				gateway_ptr->state = REG_STATE_TRYING;
 			} else {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,  "Error registering %s\n", gateway_ptr->name);
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error registering %s\n", gateway_ptr->name);
 				gateway_ptr->state = REG_STATE_FAILED;
 			}
 			break;
@@ -5178,7 +4877,7 @@
 
 #define IREG_SECONDS 30
 #define GATEWAY_SECONDS 1
-static void *SWITCH_THREAD_FUNC profile_thread_run(switch_thread_t *thread, void *obj)
+static void *SWITCH_THREAD_FUNC profile_thread_run(switch_thread_t * thread, void *obj)
 {
 	sofia_profile_t *profile = (sofia_profile_t *) obj;
 	switch_memory_pool_t *pool;
@@ -5191,15 +4890,13 @@
 	profile->s_root = su_root_create(NULL);
 	profile->home = su_home_new(sizeof(*profile->home));
 
-	profile->nua = nua_create(profile->s_root, /* Event loop */
-							  event_callback, /* Callback for processing events */
-							  profile, /* Additional data to pass to callback */
-							  NUTAG_URL(profile->bindurl),
-							  NTATAG_UDP_MTU(65536),
-							  TAG_END()); /* Last tag should always finish the sequence */
+	profile->nua = nua_create(profile->s_root,	/* Event loop */
+							  event_callback,	/* Callback for processing events */
+							  profile,	/* Additional data to pass to callback */
+							  NUTAG_URL(profile->bindurl), NTATAG_UDP_MTU(65536), TAG_END());	/* Last tag should always finish the sequence */
 
 	nua_set_params(profile->nua,
-				   //NUTAG_EARLY_MEDIA(1),				   
+				   //NUTAG_EARLY_MEDIA(1),                 
 				   NUTAG_AUTOANSWER(0),
 				   NUTAG_AUTOALERT(0),
 				   NUTAG_ALLOW("REGISTER"),
@@ -5211,20 +4908,17 @@
 				   TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ENABLEMESSAGE(1)),
 				   TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ALLOW_EVENTS("presence")),
 				   TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ALLOW_EVENTS("presence.winfo")),
-				   SIPTAG_SUPPORTED_STR("100rel, precondition"),
-				   SIPTAG_USER_AGENT_STR(SOFIA_USER_AGENT),
-				   TAG_END());
-				   
+				   SIPTAG_SUPPORTED_STR("100rel, precondition"), SIPTAG_USER_AGENT_STR(SOFIA_USER_AGENT), TAG_END());
+
 
 	for (node = profile->aliases; node; node = node->next) {
-		node->nua = nua_create(profile->s_root, /* Event loop */
-							   event_callback, /* Callback for processing events */
-							   profile, /* Additional data to pass to callback */
-							   NUTAG_URL(node->url),
-							   TAG_END()); /* Last tag should always finish the sequence */
+		node->nua = nua_create(profile->s_root,	/* Event loop */
+							   event_callback,	/* Callback for processing events */
+							   profile,	/* Additional data to pass to callback */
+							   NUTAG_URL(node->url), TAG_END());	/* Last tag should always finish the sequence */
 
 		nua_set_params(node->nua,
-				   NUTAG_EARLY_MEDIA(1),				   
+					   NUTAG_EARLY_MEDIA(1),
 					   NUTAG_AUTOANSWER(0),
 					   NUTAG_AUTOALERT(0),
 					   NUTAG_ALLOW("REGISTER"),
@@ -5232,10 +4926,8 @@
 					   NUTAG_ALLOW("INFO"),
 					   TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ALLOW("PUBLISH")),
 					   TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ENABLEMESSAGE(1)),
-					   SIPTAG_SUPPORTED_STR("100rel, precondition"),
-					   SIPTAG_USER_AGENT_STR(SOFIA_USER_AGENT),
-					   TAG_END());
-		
+					   SIPTAG_SUPPORTED_STR("100rel, precondition"), SIPTAG_USER_AGENT_STR(SOFIA_USER_AGENT), TAG_END());
+
 	}
 
 
@@ -5279,7 +4971,7 @@
 		establish_presence(profile);
 	}
 
-	while(globals.running == 1) {
+	while (globals.running == 1) {
 		if (++ireg_loops >= IREG_SECONDS) {
 			check_expire(db, profile, time(NULL));
 			ireg_loops = 0;
@@ -5296,7 +4988,7 @@
 	switch_core_db_close(db);
 	unreg(profile);
 	su_home_unref(profile->home);
-	
+
 
 	if (switch_event_create(&s_event, SWITCH_EVENT_UNPUBLISH) == SWITCH_STATUS_SUCCESS) {
 		switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "service", "_sip._udp");
@@ -5310,15 +5002,15 @@
 	switch_mutex_lock(globals.mutex);
 	globals.running = 0;
 	switch_mutex_unlock(globals.mutex);
-	
+
 	return NULL;
 }
 
-static void launch_profile_thread(sofia_profile_t *profile)
+static void launch_profile_thread(sofia_profile_t * profile)
 {
 	switch_thread_t *thread;
 	switch_threadattr_t *thd_attr = NULL;
-	
+
 	switch_threadattr_create(&thd_attr, profile->pool);
 	switch_threadattr_detach_set(thd_attr, 1);
 	switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
@@ -5364,7 +5056,7 @@
 				char *xprofilename = (char *) switch_xml_attr_soft(xprofile, "name");
 				switch_memory_pool_t *pool = NULL;
 
-				
+
 				/* Setup the pool */
 				if ((status = switch_core_new_memory_pool(&pool)) != SWITCH_STATUS_SUCCESS) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
@@ -5379,7 +5071,7 @@
 				if (!xprofilename) {
 					xprofilename = "unnamed";
 				}
-		
+
 				profile->pool = pool;
 
 				profile->name = switch_core_strdup(profile->pool, xprofilename);
@@ -5387,7 +5079,7 @@
 				profile->dbname = switch_core_strdup(profile->pool, url);
 				switch_core_hash_init(&profile->chat_hash, profile->pool);
 
-				profile->dtmf_duration = 100;		
+				profile->dtmf_duration = 100;
 				profile->codec_ms = 20;
 
 				for (param = switch_xml_child(settings, "param"); param; param = param->next) {
@@ -5431,10 +5123,7 @@
 						} else {
 							char *ip = NULL;
 							switch_port_t port = 0;
-							if (sofia_ext_address_lookup(&ip,
-														&port,
-														val,
-														profile->pool) == SWITCH_STATUS_SUCCESS) {
+							if (sofia_ext_address_lookup(&ip, &port, val, profile->pool) == SWITCH_STATUS_SUCCESS) {
 
 								if (ip) {
 									profile->extsipip = switch_core_strdup(profile->pool, ip);
@@ -5463,7 +5152,7 @@
 							profile->pflags |= PFLAG_AUTH_CALLS;
 						}
 					} else if (!strcasecmp(var, "nonce-ttl")) {
-                        profile->nonce_ttl = atoi(val);
+						profile->nonce_ttl = atoi(val);
 					} else if (!strcasecmp(var, "accept-blind-reg")) {
 						if (switch_true(val)) {
 							profile->pflags |= PFLAG_BLIND_REG;
@@ -5479,7 +5168,7 @@
 					} else if (!strcasecmp(var, "bitpacking")) {
 						if (!strcasecmp(val, "aal2")) {
 							profile->codec_flags = SWITCH_CODEC_FLAG_AAL2;
-						} 
+						}
 					} else if (!strcasecmp(var, "username")) {
 						profile->username = switch_core_strdup(profile->pool, val);
 					} else if (!strcasecmp(var, "context")) {
@@ -5510,25 +5199,25 @@
 					}
 				}
 
-                if (!profile->cng_pt) {
+				if (!profile->cng_pt) {
 					profile->cng_pt = SWITCH_RTP_CNG_PAYLOAD;
 				}
 
-                if (!profile->sipip) {
-                    profile->sipip = switch_core_strdup(profile->pool, globals.guess_ip);
-                }
-
-                if (!profile->rtpip) {
-                    profile->rtpip = switch_core_strdup(profile->pool, globals.guess_ip);
-                }
-
-                if (profile->nonce_ttl < 60) {
-                    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Setting nonce TTL to 60 seconds\n");
-                    profile->nonce_ttl = 60;
-                }
+				if (!profile->sipip) {
+					profile->sipip = switch_core_strdup(profile->pool, globals.guess_ip);
+				}
+
+				if (!profile->rtpip) {
+					profile->rtpip = switch_core_strdup(profile->pool, globals.guess_ip);
+				}
+
+				if (profile->nonce_ttl < 60) {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Setting nonce TTL to 60 seconds\n");
+					profile->nonce_ttl = 60;
+				}
 
 				if (switch_test_flag(profile, TFLAG_TIMER) && !profile->timer_name) {
-					profile->timer_name = switch_core_strdup(profile->pool, "soft");			
+					profile->timer_name = switch_core_strdup(profile->pool, "soft");
 				}
 
 				if (!profile->username) {
@@ -5561,7 +5250,7 @@
 			}
 			if (profile) {
 				if ((gateways_tag = switch_xml_child(xprofile, "registrations"))) {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, 
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
 									  "The <registrations> syntax has been discontinued, please see the new syntax in the default configuration examples\n");
 				}
 
@@ -5569,31 +5258,26 @@
 					for (gateway_tag = switch_xml_child(gateways_tag, "gateway"); gateway_tag; gateway_tag = gateway_tag->next) {
 						char *name = (char *) switch_xml_attr_soft(gateway_tag, "name");
 						outbound_reg_t *gateway;
-						
+
 						if (switch_strlen_zero(name)) {
 							name = "anonymous";
 						}
-						
+
 						if ((gateway = switch_core_alloc(profile->pool, sizeof(*gateway)))) {
 							char *scheme = "Digest",
 								*realm = NULL,
-								*username = NULL,
-								*password = NULL,
-								*extension = NULL,
-								*proxy = NULL,
-								*context = "default",
-								*expire_seconds = "3600";
+								*username = NULL, *password = NULL, *extension = NULL, *proxy = NULL, *context = "default", *expire_seconds = "3600";
 
 							gateway->pool = profile->pool;
 							gateway->profile = profile;
 							gateway->name = switch_core_strdup(gateway->pool, name);
 							gateway->freq = 0;
-							
-							
+
+
 							for (param = switch_xml_child(gateway_tag, "param"); param; param = param->next) {
 								char *var = (char *) switch_xml_attr_soft(param, "name");
 								char *val = (char *) switch_xml_attr_soft(param, "value");
-								
+
 								if (!strcmp(var, "scheme")) {
 									scheme = val;
 								} else if (!strcmp(var, "realm")) {
@@ -5616,23 +5300,23 @@
 							if (switch_strlen_zero(realm)) {
 								realm = name;
 							}
-							
+
 							if (switch_strlen_zero(username)) {
 								switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ERROR: username param is REQUIRED!\n");
 								switch_xml_free(xml);
 								goto skip;
 							}
-							
+
 							if (switch_strlen_zero(password)) {
 								switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ERROR: password param is REQUIRED!\n");
 								switch_xml_free(xml);
 								goto skip;
 							}
-							
+
 							if (switch_strlen_zero(extension)) {
 								extension = username;
 							}
-							
+
 							if (switch_strlen_zero(proxy)) {
 								proxy = realm;
 							}
@@ -5643,9 +5327,8 @@
 							gateway->register_username = switch_core_strdup(gateway->pool, username);
 							gateway->register_password = switch_core_strdup(gateway->pool, password);
 							gateway->register_from = switch_core_sprintf(gateway->pool, "sip:%s@%s", username, realm);
-							gateway->register_contact = switch_core_sprintf(gateway->pool,
-																			"sip:%s@%s:%d", extension, profile->sipip, profile->sip_port);
-								
+							gateway->register_contact = switch_core_sprintf(gateway->pool, "sip:%s@%s:%d", extension, profile->sipip, profile->sip_port);
+
 							if (!strncasecmp(proxy, "sip:", 4)) {
 								gateway->register_proxy = switch_core_strdup(gateway->pool, proxy);
 								gateway->register_to = switch_core_sprintf(gateway->pool, "sip:%s@%s", username, proxy + 4);
@@ -5653,15 +5336,15 @@
 								gateway->register_proxy = switch_core_sprintf(gateway->pool, "sip:%s", proxy);
 								gateway->register_to = switch_core_sprintf(gateway->pool, "sip:%s@%s", username, proxy);
 							}
-							
+
 							gateway->expires_str = switch_core_strdup(gateway->pool, expire_seconds);
-							
+
 							if ((gateway->freq = atoi(gateway->expires_str)) < 5) {
-                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
+								switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
 												  "Invalid Freq: %d.  Setting Register-Frequency to 3600\n", gateway->freq);
-                                gateway->freq = 3600;
-                            }
-                            gateway->freq -= 2;
+								gateway->freq = 3600;
+							}
+							gateway->freq -= 2;
 
 							gateway->next = profile->gateways;
 							profile->gateways = gateway;
@@ -5679,7 +5362,7 @@
 							}
 						}
 
-					skip:
+					  skip:
 						assert(gateway_tag);
 					}
 				}
@@ -5694,7 +5377,7 @@
 			}
 		}
 	}
- done:
+  done:
 	if (xml) {
 		switch_xml_free(xml);
 	}
@@ -5713,7 +5396,7 @@
 		char *contact_str = switch_event_get_header(event, "orig-contact");
 		char *exp_str = switch_event_get_header(event, "orig-expires");
 		char *rpid = switch_event_get_header(event, "orig-rpid");
-		long expires = (long)time(NULL) + atol(exp_str);
+		long expires = (long) time(NULL) + atol(exp_str);
 		char *profile_name = switch_event_get_header(event, "orig-profile-name");
 		sofia_profile_t *profile;
 		char buf[512];
@@ -5729,28 +5412,21 @@
 
 
 		if (!find_reg_url(profile, from_user, from_host, buf, sizeof(buf))) {
-			sql = switch_mprintf("insert into sip_registrations values ('%q','%q','%q','Regestered', '%q', %ld)", 
-								 from_user,
-								 from_host,
-								 contact_str,
-								 rpid,
-								 expires);
+			sql = switch_mprintf("insert into sip_registrations values ('%q','%q','%q','Regestered', '%q', %ld)",
+								 from_user, from_host, contact_str, rpid, expires);
 		} else {
-			sql = switch_mprintf("update sip_registrations set contact='%q', rpid='%q', expires=%ld where user='%q' and host='%q'",
-								 contact_str,
-								 rpid,
-								 expires,
-								 from_user,
-								 from_host);
-			
+			sql =
+				switch_mprintf
+				("update sip_registrations set contact='%q', rpid='%q', expires=%ld where user='%q' and host='%q'",
+				 contact_str, rpid, expires, from_user, from_host);
+
 		}
-	
+
 		if (sql) {
 			execute_sql(profile->dbname, sql, profile->ireg_mutex);
 			switch_safe_free(sql);
 			sql = NULL;
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Propagating registration for %s@%s->%s\n", 
-							  from_user, from_host, contact_str);
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Propagating registration for %s@%s->%s\n", from_user, from_host, contact_str);
 
 		}
 
@@ -5771,18 +5447,15 @@
 		if ((host = strchr(user, '@'))) {
 			*host++ = '\0';
 		}
-		
+
 		if (!host || !(profile = find_profile(host))) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Chat proto [%s]\nfrom [%s]\nto [%s]\n%s\nInvalid Profile %s\n", 
-                              proto,
-                              from,
-                              to,
-                              body ? body : "[no body]",
-                              host ? host : "NULL");
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
+							  "Chat proto [%s]\nfrom [%s]\nto [%s]\n%s\nInvalid Profile %s\n", proto, from, to,
+							  body ? body : "[no body]", host ? host : "NULL");
 			return SWITCH_STATUS_FALSE;
 		}
 
-        if (!find_reg_url(profile, user, host, buf, sizeof(buf))) {
+		if (!find_reg_url(profile, user, host, buf, sizeof(buf))) {
 			return SWITCH_STATUS_FALSE;
 		}
 
@@ -5801,44 +5474,37 @@
 				fu = strdup(fp);
 				*p = '+';
 			}
-			
-			ffrom = switch_mprintf("\"%s\" <sip:%s+%s@%s>", fu, proto, fp, profile->name);			
+
+			ffrom = switch_mprintf("\"%s\" <sip:%s+%s@%s>", fu, proto, fp, profile->name);
 			from = ffrom;
 			switch_safe_free(fu);
 			switch_safe_free(fp);
 		}
 
 		contact = get_url_from_contact(buf, 1);
-		msg_nh = nua_handle(profile->nua, NULL,
-							SIPTAG_FROM_STR(from),
-							NUTAG_URL(contact),
-							SIPTAG_TO_STR(buf), // if this cries, add contact here too, change the 1 to 0 and omit the safe_free
-							SIPTAG_CONTACT_STR(profile->url),
-							TAG_END());
+		msg_nh = nua_handle(profile->nua, NULL, SIPTAG_FROM_STR(from), NUTAG_URL(contact), SIPTAG_TO_STR(buf),	// if this cries, add contact here too, change the 1 to 0 and omit the safe_free
+							SIPTAG_CONTACT_STR(profile->url), TAG_END());
 
 		switch_safe_free(contact);
 
 
-		nua_message(msg_nh,
-					SIPTAG_CONTENT_TYPE_STR("text/html"),
-					SIPTAG_PAYLOAD_STR(body),
-					TAG_END());
-		
-		
+		nua_message(msg_nh, SIPTAG_CONTENT_TYPE_STR("text/html"), SIPTAG_PAYLOAD_STR(body), TAG_END());
+
+
 		switch_safe_free(ffrom);
 		free(user);
 	}
-		
+
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static void cancel_presence(void) 
+static void cancel_presence(void)
 {
 	char *sql, *errmsg = NULL;
 	switch_core_db_t *db;
 	sofia_profile_t *profile;
 	switch_hash_index_t *hi;
-    void *val;
+	void *val;
 
 	if ((sql = switch_mprintf("select 0,'unavailable','unavailable',* from sip_subscriptions where event='presence'"))) {
 		switch_mutex_lock(globals.hash_mutex);
@@ -5863,7 +5529,7 @@
 	switch_mutex_unlock(globals.hash_mutex);
 }
 
-static void establish_presence(sofia_profile_t *profile) 
+static void establish_presence(sofia_profile_t * profile)
 {
 	char *sql, *errmsg = NULL;
 	switch_core_db_t *db;
@@ -5909,7 +5575,7 @@
 	if (!in) {
 		return NULL;
 	}
-	
+
 	if (!strcasecmp(in, "dnd")) {
 		r = "busy";
 	}
@@ -5917,7 +5583,7 @@
 	if (ext && !strcasecmp(ext, "away")) {
 		r = "idle";
 	}
-	
+
 	return r;
 }
 
@@ -5925,11 +5591,11 @@
 {
 	sofia_profile_t *profile;
 	switch_hash_index_t *hi;
-    void *val;
+	void *val;
 	char *from = switch_event_get_header(event, "from");
 	char *proto = switch_event_get_header(event, "proto");
 	char *rpid = switch_event_get_header(event, "rpid");
-	char *status= switch_event_get_header(event, "status");
+	char *status = switch_event_get_header(event, "status");
 	char *event_type = switch_event_get_header(event, "event_type");
 	//char *event_subtype = switch_event_get_header(event, "event_subtype");
 	char *sql = NULL;
@@ -5948,7 +5614,7 @@
 
 	if (rpid) {
 		rpid = translate_rpid(rpid, status);
-	} 
+	}
 
 	if (!status) {
 		status = "Available";
@@ -6002,7 +5668,7 @@
 	}
 
 	if (switch_strlen_zero(event_type)) {
-		event_type="presence";
+		event_type = "presence";
 	}
 
 	if ((user = strdup(from))) {
@@ -6021,69 +5687,74 @@
 		} else {
 			euser = user;
 		}
-		
+
 	} else {
 		return;
 	}
 
 
-	switch(event->event_id) {
-    case SWITCH_EVENT_PRESENCE_PROBE: 
-        if (proto) {
-            switch_core_db_t *db = NULL;
-            char *to = switch_event_get_header(event, "to");
-            char *user, *euser, *host, *p;
-
-            if (!to || !(user = strdup(to))) {
-                return;
-            }
-
-            if ((host = strchr(user, '@'))) {
-                *host++ = '\0';
-            }
-            euser = user;
-            if ((p = strchr(euser, '+'))) {
-                euser = (p+1);
-            }
-
-            if (euser && host && 
-                (sql = switch_mprintf("select user,host,status,rpid,'' from sip_registrations where user='%q' and host='%q'", euser, host)) &&
-                (profile = find_profile(host))) {
-                if (!(db = switch_core_db_open_file(profile->dbname))) {
-                    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
-                    switch_safe_free(user);
-                    switch_safe_free(sql);
-                    return;
-                }
-
-                switch_mutex_lock(profile->ireg_mutex);
-                switch_core_db_exec(db, sql, resub_callback, profile, &errmsg);
-                switch_mutex_unlock(profile->ireg_mutex);
-                switch_safe_free(sql);
-            }
-            switch_safe_free(user);
-            switch_core_db_close(db);
-        }
-        return;
+	switch (event->event_id) {
+	case SWITCH_EVENT_PRESENCE_PROBE:
+		if (proto) {
+			switch_core_db_t *db = NULL;
+			char *to = switch_event_get_header(event, "to");
+			char *user, *euser, *host, *p;
+
+			if (!to || !(user = strdup(to))) {
+				return;
+			}
+
+			if ((host = strchr(user, '@'))) {
+				*host++ = '\0';
+			}
+			euser = user;
+			if ((p = strchr(euser, '+'))) {
+				euser = (p + 1);
+			}
+
+			if (euser && host &&
+				(sql =
+				 switch_mprintf("select user,host,status,rpid,'' from sip_registrations where user='%q' and host='%q'",
+								euser, host)) && (profile = find_profile(host))) {
+				if (!(db = switch_core_db_open_file(profile->dbname))) {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
+					switch_safe_free(user);
+					switch_safe_free(sql);
+					return;
+				}
+
+				switch_mutex_lock(profile->ireg_mutex);
+				switch_core_db_exec(db, sql, resub_callback, profile, &errmsg);
+				switch_mutex_unlock(profile->ireg_mutex);
+				switch_safe_free(sql);
+			}
+			switch_safe_free(user);
+			switch_core_db_close(db);
+		}
+		return;
 	case SWITCH_EVENT_PRESENCE_IN:
-		sql = switch_mprintf("select 1,'%q','%q',* from sip_subscriptions where proto='%q' and event='%q' and sub_to_user='%q' and sub_to_host='%q'", 
-							 status , rpid, proto, event_type, euser, host);
+		sql =
+			switch_mprintf
+			("select 1,'%q','%q',* from sip_subscriptions where proto='%q' and event='%q' and sub_to_user='%q' and sub_to_host='%q'",
+			 status, rpid, proto, event_type, euser, host);
 		break;
 	case SWITCH_EVENT_PRESENCE_OUT:
-		sql = switch_mprintf("select 0,'%q','%q',* from sip_subscriptions where proto='%q' and event='%q' and sub_to_user='%q' and sub_to_host='%q'", 
-							 status, rpid, proto, event_type, euser, host);
+		sql =
+			switch_mprintf
+			("select 0,'%q','%q',* from sip_subscriptions where proto='%q' and event='%q' and sub_to_user='%q' and sub_to_host='%q'",
+			 status, rpid, proto, event_type, euser, host);
 		break;
 	default:
 		break;
 	}
 
 	switch_mutex_lock(globals.hash_mutex);
-    for (hi = switch_hash_first(switch_hash_pool_get(globals.profile_hash), globals.profile_hash); hi; hi = switch_hash_next(hi)) {
-        switch_hash_this(hi, NULL, NULL, &val);
-        profile = (sofia_profile_t *) val;
-        if (!(profile->pflags & PFLAG_PRESENCE)) {
+	for (hi = switch_hash_first(switch_hash_pool_get(globals.profile_hash), globals.profile_hash); hi; hi = switch_hash_next(hi)) {
+		switch_hash_this(hi, NULL, NULL, &val);
+		profile = (sofia_profile_t *) val;
+		if (!(profile->pflags & PFLAG_PRESENCE)) {
 			continue;
-        }
+		}
 
 		if (sql) {
 			if (!(db = switch_core_db_open_file(profile->dbname))) {
@@ -6093,7 +5764,7 @@
 			switch_mutex_lock(profile->ireg_mutex);
 			switch_core_db_exec(db, sql, sub_callback, profile, &errmsg);
 			switch_mutex_unlock(profile->ireg_mutex);
-			
+
 			switch_core_db_close(db);
 		}
 	}
@@ -6121,7 +5792,7 @@
 	memset(&globals, 0, sizeof(globals));
 	switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, module_pool);
 
-    switch_find_local_ip(globals.guess_ip, sizeof(globals.guess_ip), AF_INET);
+	switch_find_local_ip(globals.guess_ip, sizeof(globals.guess_ip), AF_INET);
 
 	if (switch_event_bind((char *) modname, SWITCH_EVENT_CUSTOM, MULTICAST_EVENT, event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
@@ -6178,7 +5849,7 @@
 	}
 	switch_mutex_unlock(globals.mutex);
 
-	while(globals.running) {
+	while (globals.running) {
 		switch_yield(1000);
 	}
 

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/libsangoma/g711.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/libsangoma/g711.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/libsangoma/g711.h	Fri Mar 30 12:19:18 2007
@@ -50,137 +50,108 @@
 #ifndef __inline__
 #define __inline__ __inline
 #endif
-typedef unsigned __int8 uint8_t;
-typedef __int16 int16_t;
-typedef __int32 int32_t;
-typedef unsigned __int16 uint16_t;
+	typedef unsigned __int8 uint8_t;
+	typedef __int16 int16_t;
+	typedef __int32 int32_t;
+	typedef unsigned __int16 uint16_t;
 #endif
 
 #if defined(__i386__)
 /*! \brief Find the bit position of the highest set bit in a word
     \param bits The word to be searched
     \return The bit number of the highest set bit, or -1 if the word is zero. */
-static __inline__ int top_bit(unsigned int bits)
-{
-    int res;
-
-    __asm__ __volatile__(" movl $-1,%%edx;\n"
-                         " bsrl %%eax,%%edx;\n"
-                         : "=d" (res)
-                         : "a" (bits));
-    return res;
-}
-/*- End of function --------------------------------------------------------*/
+	static __inline__ int top_bit(unsigned int bits) {
+		int res;
 
-/*! \brief Find the bit position of the lowest set bit in a word
-    \param bits The word to be searched
-    \return The bit number of the lowest set bit, or -1 if the word is zero. */
-static __inline__ int bottom_bit(unsigned int bits)
-{
-    int res;
-
-    __asm__ __volatile__(" movl $-1,%%edx;\n"
-                         " bsfl %%eax,%%edx;\n"
-                         : "=d" (res)
-                         : "a" (bits));
-    return res;
-}
+		__asm__ __volatile__(" movl $-1,%%edx;\n" " bsrl %%eax,%%edx;\n":"=d"(res)
+							 :"a"    (bits));
+		        return res;
+	}
+	/*- End of function --------------------------------------------------------*//*! \brief Find the bit position of the lowest set bit in a word
+	   \param bits The word to be searched
+	   \return The bit number of the lowest set bit, or -1 if the word is zero. */ static __inline__ int bottom_bit(unsigned int bits) {
+		int res;
+
+		__asm__ __volatile__(" movl $-1,%%edx;\n" " bsfl %%eax,%%edx;\n":"=d"(res)
+							 :"a"    (bits));
+		return res;
+	}
 /*- End of function --------------------------------------------------------*/
 #elif defined(__x86_64__)
-static __inline__ int top_bit(unsigned int bits)
-{
-    int res;
-
-    __asm__ __volatile__(" movq $-1,%%rdx;\n"
-                         " bsrq %%rax,%%rdx;\n"
-                         : "=d" (res)
-                         : "a" (bits));
-    return res;
-}
-/*- End of function --------------------------------------------------------*/
+	static __inline__ int top_bit(unsigned int bits) {
+		int res;
 
-static __inline__ int bottom_bit(unsigned int bits)
-{
-    int res;
-
-    __asm__ __volatile__(" movq $-1,%%rdx;\n"
-                         " bsfq %%rax,%%rdx;\n"
-                         : "=d" (res)
-                         : "a" (bits));
-    return res;
-}
+		__asm__ __volatile__(" movq $-1,%%rdx;\n" " bsrq %%rax,%%rdx;\n":"=d"(res)
+							 :"a"    (bits));
+		        return res;
+	}
+/*- End of function --------------------------------------------------------*/ static __inline__ int bottom_bit(unsigned int bits) {
+		int res;
+
+		__asm__ __volatile__(" movq $-1,%%rdx;\n" " bsfq %%rax,%%rdx;\n":"=d"(res)
+							 :"a"    (bits));
+		return res;
+	}
 /*- End of function --------------------------------------------------------*/
 #else
-static __inline__ int top_bit(unsigned int bits)
-{
-    int i;
-    
-    if (bits == 0)
-        return -1;
-    i = 0;
-    if (bits & 0xFFFF0000)
-    {
-        bits &= 0xFFFF0000;
-        i += 16;
-    }
-    if (bits & 0xFF00FF00)
-    {
-        bits &= 0xFF00FF00;
-        i += 8;
-    }
-    if (bits & 0xF0F0F0F0)
-    {
-        bits &= 0xF0F0F0F0;
-        i += 4;
-    }
-    if (bits & 0xCCCCCCCC)
-    {
-        bits &= 0xCCCCCCCC;
-        i += 2;
-    }
-    if (bits & 0xAAAAAAAA)
-    {
-        bits &= 0xAAAAAAAA;
-        i += 1;
-    }
-    return i;
-}
+	static __inline__ int top_bit(unsigned int bits) {
+		int i;
+
+		if  (bits == 0)
+			return -1;
+		    i = 0;
+		if  (bits & 0xFFFF0000) {
+			bits &= 0xFFFF0000;
+			i += 16;
+		}
+		if     (bits & 0xFF00FF00) {
+			bits &= 0xFF00FF00;
+			i += 8;
+		}
+		if (bits & 0xF0F0F0F0) {
+			bits &= 0xF0F0F0F0;
+			i += 4;
+		}
+		if (bits & 0xCCCCCCCC) {
+			bits &= 0xCCCCCCCC;
+			i += 2;
+		}
+		if (bits & 0xAAAAAAAA) {
+			bits &= 0xAAAAAAAA;
+			i += 1;
+		}
+		return i;
+	}
 /*- End of function --------------------------------------------------------*/
 
-static __inline__ int bottom_bit(unsigned int bits)
-{
-    int i;
-    
-    if (bits == 0)
-        return -1;
-    i = 32;
-    if (bits & 0x0000FFFF)
-    {
-        bits &= 0x0000FFFF;
-        i -= 16;
-    }
-    if (bits & 0x00FF00FF)
-    {
-        bits &= 0x00FF00FF;
-        i -= 8;
-    }
-    if (bits & 0x0F0F0F0F)
-    {
-        bits &= 0x0F0F0F0F;
-        i -= 4;
-    }
-    if (bits & 0x33333333)
-    {
-        bits &= 0x33333333;
-        i -= 2;
-    }
-    if (bits & 0x55555555)
-    {
-        bits &= 0x55555555;
-        i -= 1;
-    }
-    return i;
-}
+	static __inline__ int bottom_bit(unsigned int bits) {
+		int i;
+
+		if (bits == 0)
+			return -1;
+		i = 32;
+		if (bits & 0x0000FFFF) {
+			bits &= 0x0000FFFF;
+			i -= 16;
+		}
+		if (bits & 0x00FF00FF) {
+			bits &= 0x00FF00FF;
+			i -= 8;
+		}
+		if (bits & 0x0F0F0F0F) {
+			bits &= 0x0F0F0F0F;
+			i -= 4;
+		}
+		if (bits & 0x33333333) {
+			bits &= 0x33333333;
+			i -= 2;
+		}
+		if (bits & 0x55555555) {
+			bits &= 0x55555555;
+			i -= 1;
+		}
+		return i;
+	}
 /*- End of function --------------------------------------------------------*/
 #endif
 
@@ -194,7 +165,7 @@
  *      segment, but a little inline assembly can fix that on an i386, x86_64 and
  *      many other modern processors.
  */
- 
+
 /*
  * Mu-law is basically as follows:
  *
@@ -222,66 +193,61 @@
  */
 
 //#define ULAW_ZEROTRAP                 /* turn on the trap as per the MIL-STD */
-#define ULAW_BIAS        0x84           /* Bias for linear code. */
+#define ULAW_BIAS        0x84	/* Bias for linear code. */
 
 /*! \brief Encode a linear sample to u-law
     \param linear The sample to encode.
     \return The u-law value.
 */
-static __inline__ uint8_t linear_to_ulaw(int linear)
-{
-    uint8_t u_val;
-    int mask;
-    int seg;
-
-    /* Get the sign and the magnitude of the value. */
-    if (linear < 0)
-    {
-        linear = ULAW_BIAS - linear;
-        mask = 0x7F;
-    }
-    else
-    {
-        linear = ULAW_BIAS + linear;
-        mask = 0xFF;
-    }
-
-    seg = top_bit(linear | 0xFF) - 7;
-
-    /*
-     * Combine the sign, segment, quantization bits,
-     * and complement the code word.
-     */
-    if (seg >= 8)
-        u_val = (uint8_t) (0x7F ^ mask);
-    else
-        u_val = (uint8_t) (((seg << 4) | ((linear >> (seg + 3)) & 0xF)) ^ mask);
+	static __inline__ uint8_t linear_to_ulaw(int linear) {
+		uint8_t u_val;
+		int mask;
+		int seg;
+
+		/* Get the sign and the magnitude of the value. */
+		if (linear < 0) {
+			linear = ULAW_BIAS - linear;
+			mask = 0x7F;
+		} else {
+			linear = ULAW_BIAS + linear;
+			mask = 0xFF;
+		}
+
+		seg = top_bit(linear | 0xFF) - 7;
+
+		/*
+		 * Combine the sign, segment, quantization bits,
+		 * and complement the code word.
+		 */
+		if (seg >= 8)
+			u_val = (uint8_t) (0x7F ^ mask);
+		else
+			u_val = (uint8_t) (((seg << 4) | ((linear >> (seg + 3)) & 0xF)) ^ mask);
 #ifdef ULAW_ZEROTRAP
-    /* Optional ITU trap */
-    if (u_val == 0)
-        u_val = 0x02;
+		/* Optional ITU trap */
+		if (u_val == 0)
+			u_val = 0x02;
 #endif
-    return  u_val;
-}
+		return u_val;
+	}
 /*- End of function --------------------------------------------------------*/
 
 /*! \brief Decode an u-law sample to a linear value.
     \param ulaw The u-law sample to decode.
     \return The linear value.
 */
-static __inline__ int16_t ulaw_to_linear(uint8_t ulaw)
-{
-    int t;
-    
-    /* Complement to obtain normal u-law value. */
-    ulaw = ~ulaw;
-    /*
-     * Extract and bias the quantization bits. Then
-     * shift up by the segment number and subtract out the bias.
-     */
-    t = (((ulaw & 0x0F) << 3) + ULAW_BIAS) << (((int) ulaw & 0x70) >> 4);
-    return  (int16_t) ((ulaw & 0x80)  ?  (ULAW_BIAS - t)  :  (t - ULAW_BIAS));
-}
+	static __inline__ int16_t ulaw_to_linear(uint8_t ulaw) {
+		int t;
+
+		/* Complement to obtain normal u-law value. */
+		ulaw = ~ulaw;
+		/*
+		 * Extract and bias the quantization bits. Then
+		 * shift up by the segment number and subtract out the bias.
+		 */
+		t = (((ulaw & 0x0F) << 3) + ULAW_BIAS) << (((int) ulaw & 0x70) >> 4);
+		return (int16_t) ((ulaw & 0x80) ? (ULAW_BIAS - t) : (t - ULAW_BIAS));
+	}
 /*- End of function --------------------------------------------------------*/
 
 /*
@@ -308,71 +274,64 @@
     \param linear The sample to encode.
     \return The A-law value.
 */
-static __inline__ uint8_t linear_to_alaw(int linear)
-{
-    int mask;
-    int seg;
-    
-    if (linear >= 0)
-    {
-        /* Sign (bit 7) bit = 1 */
-        mask = ALAW_AMI_MASK | 0x80;
-    }
-    else
-    {
-        /* Sign (bit 7) bit = 0 */
-        mask = ALAW_AMI_MASK;
-        linear = -linear - 8;
-    }
-
-    /* Convert the scaled magnitude to segment number. */
-    seg = top_bit(linear | 0xFF) - 7;
-    if (seg >= 8)
-    {
-        if (linear >= 0)
-        {
-            /* Out of range. Return maximum value. */
-            return (uint8_t) (0x7F ^ mask);
-        }
-        /* We must be just a tiny step below zero */
-        return (uint8_t) (0x00 ^ mask);
-    }
-    /* Combine the sign, segment, and quantization bits. */
-    return (uint8_t) (((seg << 4) | ((linear >> ((seg)  ?  (seg + 3)  :  4)) & 0x0F)) ^ mask);
-}
+	static __inline__ uint8_t linear_to_alaw(int linear) {
+		int mask;
+		int seg;
+
+		if (linear >= 0) {
+			/* Sign (bit 7) bit = 1 */
+			mask = ALAW_AMI_MASK | 0x80;
+		} else {
+			/* Sign (bit 7) bit = 0 */
+			mask = ALAW_AMI_MASK;
+			linear = -linear - 8;
+		}
+
+		/* Convert the scaled magnitude to segment number. */
+		seg = top_bit(linear | 0xFF) - 7;
+		if (seg >= 8) {
+			if (linear >= 0) {
+				/* Out of range. Return maximum value. */
+				return (uint8_t) (0x7F ^ mask);
+			}
+			/* We must be just a tiny step below zero */
+			return (uint8_t) (0x00 ^ mask);
+		}
+		/* Combine the sign, segment, and quantization bits. */
+		return (uint8_t) (((seg << 4) | ((linear >> ((seg) ? (seg + 3) : 4)) & 0x0F)) ^ mask);
+	}
 /*- End of function --------------------------------------------------------*/
 
 /*! \brief Decode an A-law sample to a linear value.
     \param alaw The A-law sample to decode.
     \return The linear value.
 */
-static __inline__ int16_t alaw_to_linear(uint8_t alaw)
-{
-    int i;
-    int seg;
-
-    alaw ^= ALAW_AMI_MASK;
-    i = ((alaw & 0x0F) << 4);
-    seg = (((int) alaw & 0x70) >> 4);
-    if (seg)
-        i = (i + 0x108) << (seg - 1);
-    else
-        i += 8;
-    return (int16_t) ((alaw & 0x80)  ?  i  :  -i);
-}
+	static __inline__ int16_t alaw_to_linear(uint8_t alaw) {
+		int i;
+		int seg;
+
+		alaw ^= ALAW_AMI_MASK;
+		i = ((alaw & 0x0F) << 4);
+		seg = (((int) alaw & 0x70) >> 4);
+		if (seg)
+			i = (i + 0x108) << (seg - 1);
+		else
+			i += 8;
+		return (int16_t) ((alaw & 0x80) ? i : -i);
+	}
 /*- End of function --------------------------------------------------------*/
 
 /*! \brief Transcode from A-law to u-law, using the procedure defined in G.711.
     \param alaw The A-law sample to transcode.
     \return The best matching u-law value.
 */
-uint8_t alaw_to_ulaw(uint8_t alaw);
+	uint8_t alaw_to_ulaw(uint8_t alaw);
 
 /*! \brief Transcode from u-law to A-law, using the procedure defined in G.711.
     \param alaw The u-law sample to transcode.
     \return The best matching A-law value.
 */
-uint8_t ulaw_to_alaw(uint8_t ulaw);
+	uint8_t ulaw_to_alaw(uint8_t ulaw);
 
 #ifdef __cplusplus
 }

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.c	Fri Mar 30 12:19:18 2007
@@ -23,99 +23,96 @@
 #define DFT_CARD "wanpipe1"
 
 #if defined(WIN32)
-//extern int	verbose;
+//extern int    verbose;
 
 #define DEV_NAME_LEN	100
 char device_name[DEV_NAME_LEN];
 
 /* IOCTL management structures and variables*/
-wan_udp_hdr_t	wan_udp;
+wan_udp_hdr_t wan_udp;
 
 #include "win_api_common.h"
 
 static wan_cmd_api_t api_cmd;
-static api_tx_hdr_t *tx_hdr = (api_tx_hdr_t *)api_cmd.data;
+static api_tx_hdr_t *tx_hdr = (api_tx_hdr_t *) api_cmd.data;
 
 /* keeps the LAST (and single) event received */
 static wp_tdm_api_rx_hdr_t last_tdm_api_event_buffer;
 
-#endif	/* WIN32 */
+#endif /* WIN32 */
 
-void sangoma_socket_close(sng_fd_t *sp) 
+void sangoma_socket_close(sng_fd_t * sp)
 {
 #if defined(WIN32)
-	if(	*sp != INVALID_HANDLE_VALUE){
+	if (*sp != INVALID_HANDLE_VALUE) {
 		CloseHandle(*sp);
 		*sp = INVALID_HANDLE_VALUE;
 	}
 #else
-    if (*sp > -1) {
-	close(*sp);
-	*sp = -1;
-    }
+	if (*sp > -1) {
+		close(*sp);
+		*sp = -1;
+	}
 #endif
 }
 
 int sangoma_socket_waitfor(sng_fd_t fd, int timeout, int flags)
 {
 #if defined(WIN32)
-	API_POLL_STRUCT	api_poll;
+	API_POLL_STRUCT api_poll;
 
 	memset(&api_poll, 0x00, sizeof(API_POLL_STRUCT));
-	
+
 	api_poll.user_flags_bitmap = flags;
 
-	if(DoApiPollCommand(fd, &api_poll)){
+	if (DoApiPollCommand(fd, &api_poll)) {
 		//failed
 		return 0;
 	}
 
-	switch(api_poll.operation_status)
-	{
-		case SANG_STATUS_RX_DATA_AVAILABLE:
-			break;
+	switch (api_poll.operation_status) {
+	case SANG_STATUS_RX_DATA_AVAILABLE:
+		break;
 
-		default:
-			prn(1, "Error: sangoma_socket_waitfor(): Unknown Operation Status: %d\n", 
-				api_poll.operation_status);
-			return 0;
-	}//switch()
-
-	if(api_poll.poll_events_bitmap == 0){
-		prn(1, "Error: invalid Poll Events bitmap: 0x%X\n",
-			api_poll.poll_events_bitmap);
+	default:
+		prn(1, "Error: sangoma_socket_waitfor(): Unknown Operation Status: %d\n", api_poll.operation_status);
+		return 0;
+	}							//switch()
+
+	if (api_poll.poll_events_bitmap == 0) {
+		prn(1, "Error: invalid Poll Events bitmap: 0x%X\n", api_poll.poll_events_bitmap);
 	}
 	return api_poll.poll_events_bitmap;
 #else
-    struct pollfd pfds[1];
-    int res;
+	struct pollfd pfds[1];
+	int res;
 
-    memset(&pfds[0], 0, sizeof(pfds[0]));
-    pfds[0].fd = fd;
-    pfds[0].events = flags;
-    res = poll(pfds, 1, timeout);
-    if (res > 0) {
-	if ((pfds[0].revents & POLLERR)) {
-		res = -1;
-	} else if((pfds[0].revents)) {
-		res = 1;
+	memset(&pfds[0], 0, sizeof(pfds[0]));
+	pfds[0].fd = fd;
+	pfds[0].events = flags;
+	res = poll(pfds, 1, timeout);
+	if (res > 0) {
+		if ((pfds[0].revents & POLLERR)) {
+			res = -1;
+		} else if ((pfds[0].revents)) {
+			res = 1;
+		}
 	}
-    }
 
-    return res;
+	return res;
 #endif
 }
 
 
 int sangoma_span_chan_toif(int span, int chan, char *interface_name)
 {
- 	sprintf(interface_name,"s%ic%i",span,chan);
+	sprintf(interface_name, "s%ic%i", span, chan);
 	return 0;
 }
 
 int sangoma_interface_toi(char *interface_name, int *span, int *chan)
 {
-	char *p=NULL, *sp = NULL, *ch = NULL;
+	char *p = NULL, *sp = NULL, *ch = NULL;
 	int ret = 0;
 	char data[FNAME_LEN];
 
@@ -131,7 +128,7 @@
 			}
 		}
 
-		if(ch && sp) {
+		if (ch && sp) {
 			*span = atoi(sp);
 			*chan = atoi(ch);
 			ret = 1;
@@ -162,7 +159,7 @@
 			}
 		}
 
-		if(ch && sp) {
+		if (ch && sp) {
 			*span = atoi(sp);
 			*chan = atoi(ch);
 			ret = 1;
@@ -175,132 +172,123 @@
 	return ret;
 }
 
-sng_fd_t sangoma_open_tdmapi_span_chan(int span, int chan) 
+sng_fd_t sangoma_open_tdmapi_span_chan(int span, int chan)
 {
-   	char fname[FNAME_LEN];
+	char fname[FNAME_LEN];
 #if defined(WIN32)
 
 	//NOTE: under Windows Interfaces are zero based but 'chan' is 1 based.
-	//		Subtract 1 from 'chan'.
-	_snprintf(fname , FNAME_LEN, "\\\\.\\WANPIPE%d_IF%d", span, chan - 1);
+	//      Subtract 1 from 'chan'.
+	_snprintf(fname, FNAME_LEN, "\\\\.\\WANPIPE%d_IF%d", span, chan - 1);
 
 	//prn(verbose, "Opening device: %s...\n", fname);
 
-	return CreateFile(	fname, 
-						GENERIC_READ | GENERIC_WRITE, 
-						FILE_SHARE_READ | FILE_SHARE_WRITE,
-						(LPSECURITY_ATTRIBUTES)NULL, 
-						OPEN_EXISTING,
-						FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH,
-						(HANDLE)NULL
-						);
+	return CreateFile(fname,
+					  GENERIC_READ | GENERIC_WRITE,
+					  FILE_SHARE_READ | FILE_SHARE_WRITE,
+					  (LPSECURITY_ATTRIBUTES) NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, (HANDLE) NULL);
 #else
-  	int fd=-1;
+	int fd = -1;
 
-	sprintf(fname,"/dev/wptdm_s%dc%d",span,chan);
+	sprintf(fname, "/dev/wptdm_s%dc%d", span, chan);
 
 	fd = open(fname, O_RDWR);
 
-	return fd;  
+	return fd;
 #endif
-}            
+}
 
-sng_fd_t sangoma_create_socket_by_name(char *device, char *card) 
+sng_fd_t sangoma_create_socket_by_name(char *device, char *card)
 {
-	int span,chan;
-	sangoma_interface_toi(device,&span,&chan);
-	
-	return sangoma_open_tdmapi_span_chan(span,chan);
+	int span, chan;
+	sangoma_interface_toi(device, &span, &chan);
+
+	return sangoma_open_tdmapi_span_chan(span, chan);
 }
 
-          
-sng_fd_t sangoma_open_tdmapi_span(int span) 
+
+sng_fd_t sangoma_open_tdmapi_span(int span)
 {
-    int i=0;
+	int i = 0;
 #if defined(WIN32)
 	sng_fd_t fd = INVALID_HANDLE_VALUE;
 
-	for(i = 1; i < 32; i++){
-		if((fd = sangoma_open_tdmapi_span_chan(span, i)) == INVALID_HANDLE_VALUE){
+	for (i = 1; i < 32; i++) {
+		if ((fd = sangoma_open_tdmapi_span_chan(span, i)) == INVALID_HANDLE_VALUE) {
 			//prn(verbose, "Span: %d, chan: %d: is not running, consider 'busy'\n",
-			//	span, i);
+			//  span, i);
 			continue;
 		}
-
 		//get the open handle counter
-		wan_udp.wan_udphdr_command = GET_OPEN_HANDLES_COUNTER; 
+		wan_udp.wan_udphdr_command = GET_OPEN_HANDLES_COUNTER;
 		wan_udp.wan_udphdr_data_len = 0;
 
 		DoManagementCommand(fd, &wan_udp);
-		if(wan_udp.wan_udphdr_return_code){
-			prn(1, "Error: command GET_OPEN_HANDLES_COUNTER failed! Span: %d, chan: %d\n",
-				span, i);
+		if (wan_udp.wan_udphdr_return_code) {
+			prn(1, "Error: command GET_OPEN_HANDLES_COUNTER failed! Span: %d, chan: %d\n", span, i);
 			//don't forget to close!! otherwize counter will stay incremented.
 			sangoma_socket_close(&fd);
 			continue;
 		}
-
 		//prn(verbose, "open handles counter: %d\n", *(int*)&wan_udp.wan_udphdr_data[0]);
-		if(*(int*)&wan_udp.wan_udphdr_data[0] == 1){
+		if (*(int *) &wan_udp.wan_udphdr_data[0] == 1) {
 			//this is the only process using this chan/span, so it is 'free'
 			//prn(verbose, "Found 'free' Span: %d, chan: %d\n",span, i);
 			break;
 		}
 		//don't forget to close!! otherwize counter will stay incremented.
 		sangoma_socket_close(&fd);
-	}//for()
+	}							//for()
 
 #else
-    unsigned char fname[FNAME_LEN];
-	int fd=0;
-	for (i=1;i<32;i++){
-		sprintf(fname,"/dev/wptdm_s%dc%d",span,i);
+	unsigned char fname[FNAME_LEN];
+	int fd = 0;
+	for (i = 1; i < 32; i++) {
+		sprintf(fname, "/dev/wptdm_s%dc%d", span, i);
 		fd = open(fname, O_RDWR);
-		if (fd < 0){
-         	continue;
+		if (fd < 0) {
+			continue;
 		}
 		break;
 	}
-#endif	
-    return fd;  
-}      
+#endif
+	return fd;
+}
 
 int sangoma_readmsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen, void *databuf, int datalen, int flag)
 {
-	int rx_len=0;
+	int rx_len = 0;
 
 #if defined(WIN32)
-	static RX_DATA_STRUCT	rx_data;
-	api_header_t			*pri;
-	wp_tdm_api_rx_hdr_t		*tdm_api_rx_hdr;
-	wp_tdm_api_rx_hdr_t		*user_buf = (wp_tdm_api_rx_hdr_t*)hdrbuf;
+	static RX_DATA_STRUCT rx_data;
+	api_header_t *pri;
+	wp_tdm_api_rx_hdr_t *tdm_api_rx_hdr;
+	wp_tdm_api_rx_hdr_t *user_buf = (wp_tdm_api_rx_hdr_t *) hdrbuf;
 
-	if(hdrlen != sizeof(wp_tdm_api_rx_hdr_t)){
+	if (hdrlen != sizeof(wp_tdm_api_rx_hdr_t)) {
 		//error
 		prn(1, "Error: sangoma_readmsg_tdm(): invalid size of user's 'header buffer'.\
 Should be 'sizeof(wp_tdm_api_rx_hdr_t)'.\n");
 		return -1;
 	}
 
-	if(DoReadCommand(fd, &rx_data) ){
+	if (DoReadCommand(fd, &rx_data)) {
 		//error
 		prn(1, "Error: DoReadCommand() failed! Check messages log.\n");
 		return -1;
 	}
-
 	//use our special buffer at rxdata to hold received data
 	pri = &rx_data.api_header;
-	tdm_api_rx_hdr = (wp_tdm_api_rx_hdr_t*)rx_data.data;
+	tdm_api_rx_hdr = (wp_tdm_api_rx_hdr_t *) rx_data.data;
 
 	user_buf->wp_tdm_api_event_type = pri->operation_status;
 
-	switch(pri->operation_status)
-	{
+	switch (pri->operation_status) {
 	case SANG_STATUS_RX_DATA_AVAILABLE:
 		//prn(verbose, "SANG_STATUS_RX_DATA_AVAILABLE\n");
 
-		if(pri->data_length > datalen){
-			rx_len=0;
+		if (pri->data_length > datalen) {
+			rx_len = 0;
 			break;
 		}
 		memcpy(databuf, rx_data.data, pri->data_length);
@@ -315,12 +303,11 @@
 		rx_len = pri->data_length;
 
 		//make copy for use with sangoma_tdm_read_event() - indirect access.
-		memcpy(	&last_tdm_api_event_buffer,	tdm_api_rx_hdr, sizeof(wp_tdm_api_rx_hdr_t));
+		memcpy(&last_tdm_api_event_buffer, tdm_api_rx_hdr, sizeof(wp_tdm_api_rx_hdr_t));
 		break;
 
 	default:
-		switch(pri->operation_status)
-		{
+		switch (pri->operation_status) {
 		case SANG_STATUS_RX_DATA_TIMEOUT:
 			//no data in READ_CMD_TIMEOUT, try again.
 			prn(1, "Error: Timeout on read.\n");
@@ -344,43 +331,43 @@
 		default:
 			prn(1, "Rx:Unknown Operation Status: %d\n", pri->operation_status);
 			break;
-		}//switch()
+		}						//switch()
 		return 0;
-	}//switch()
+	}							//switch()
 
 #else
 	struct msghdr msg;
 	struct iovec iov[2];
 
-	memset(&msg,0,sizeof(struct msghdr));
+	memset(&msg, 0, sizeof(struct msghdr));
 
-	iov[0].iov_len=hdrlen;
-	iov[0].iov_base=hdrbuf;
+	iov[0].iov_len = hdrlen;
+	iov[0].iov_base = hdrbuf;
 
-	iov[1].iov_len=datalen;
-	iov[1].iov_base=databuf;
+	iov[1].iov_len = datalen;
+	iov[1].iov_base = databuf;
 
-	msg.msg_iovlen=2;
-	msg.msg_iov=iov;
+	msg.msg_iovlen = 2;
+	msg.msg_iov = iov;
 
-	rx_len = read(fd,&msg,datalen+hdrlen);
+	rx_len = read(fd, &msg, datalen + hdrlen);
 
-	if (rx_len <= sizeof(wp_tdm_api_rx_hdr_t)){
+	if (rx_len <= sizeof(wp_tdm_api_rx_hdr_t)) {
 		return -EINVAL;
 	}
 
-	rx_len-=sizeof(wp_tdm_api_rx_hdr_t);
+	rx_len -= sizeof(wp_tdm_api_rx_hdr_t);
 #endif
-    return rx_len;
-}                    
+	return rx_len;
+}
 
 int sangoma_writemsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen, void *databuf, unsigned short datalen, int flag)
 {
 	int bsent;
 
 #if defined(WIN32)
-	static TX_DATA_STRUCT	local_tx_data;
-	api_header_t			*pri;
+	static TX_DATA_STRUCT local_tx_data;
+	api_header_t *pri;
 
 	pri = &local_tx_data.api_header;
 
@@ -388,36 +375,35 @@
 	memcpy(local_tx_data.data, databuf, pri->data_length);
 
 	//queue data for transmission
-	if(	DoWriteCommand(fd, &local_tx_data)){
+	if (DoWriteCommand(fd, &local_tx_data)) {
 		//error
 		prn(1, "Error: DoWriteCommand() failed!! Check messages log.\n");
 		return -1;
 	}
 
-	bsent=0;
+	bsent = 0;
 	//check that frame was transmitted
-	switch(local_tx_data.api_header.operation_status)
-	{
+	switch (local_tx_data.api_header.operation_status) {
 	case SANG_STATUS_SUCCESS:
 		bsent = datalen;
 		break;
-				
+
 	case SANG_STATUS_TX_TIMEOUT:
 		//error
 		prn(1, "****** Error: SANG_STATUS_TX_TIMEOUT ******\n");
 		//Check messages log or look at statistics.
 		break;
-				
+
 	case SANG_STATUS_TX_DATA_TOO_LONG:
 		//Attempt to transmit data longer than the pre-configured maximum.
 		//Maximum length is set in 'Interface Properties',
 		//in the 'Device Manager'.
 		prn(1, "****** SANG_STATUS_TX_DATA_TOO_LONG ******\n");
 		break;
-				
+
 	case SANG_STATUS_TX_DATA_TOO_SHORT:
 		//Minimum is 1 byte  for Primary   port,
-		//			 2 bytes for Secondary port
+		//           2 bytes for Secondary port
 		prn(1, "****** SANG_STATUS_TX_DATA_TOO_SHORT ******\n");
 		break;
 
@@ -430,28 +416,27 @@
 		break;
 
 	default:
-		prn(1, "Unknown return code (0x%X) on transmission!\n",
-			local_tx_data.api_header.operation_status);
+		prn(1, "Unknown return code (0x%X) on transmission!\n", local_tx_data.api_header.operation_status);
 		break;
-	}//switch()
+	}							//switch()
 #else
 	struct msghdr msg;
 	struct iovec iov[2];
 
-	memset(&msg,0,sizeof(struct msghdr));
+	memset(&msg, 0, sizeof(struct msghdr));
 
-	iov[0].iov_len=hdrlen;
-	iov[0].iov_base=hdrbuf;
+	iov[0].iov_len = hdrlen;
+	iov[0].iov_base = hdrbuf;
 
-	iov[1].iov_len=datalen;
-	iov[1].iov_base=databuf;
+	iov[1].iov_len = datalen;
+	iov[1].iov_base = databuf;
 
-	msg.msg_iovlen=2;
-	msg.msg_iov=iov;
+	msg.msg_iovlen = 2;
+	msg.msg_iov = iov;
 
-	bsent = write(fd,&msg,datalen+hdrlen);
-	if (bsent > 0){
-		bsent-=sizeof(wp_tdm_api_tx_hdr_t);
+	bsent = write(fd, &msg, datalen + hdrlen);
+	if (bsent > 0) {
+		bsent -= sizeof(wp_tdm_api_tx_hdr_t);
 	}
 #endif
 	return bsent;
@@ -464,17 +449,17 @@
  * Execute TDM command
  *
  */
-static int sangoma_tdm_cmd_exec(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api)
+static int sangoma_tdm_cmd_exec(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api)
 {
 	int err;
 
 #if defined(WIN32)
 	err = tdmv_api_ioctl(fd, &tdm_api->wp_tdm_cmd);
 #else
-	err = ioctl(fd,SIOC_WANPIPE_TDM_API,&tdm_api->wp_tdm_cmd);
-	if (err < 0){
+	err = ioctl(fd, SIOC_WANPIPE_TDM_API, &tdm_api->wp_tdm_cmd);
+	if (err < 0) {
 		char tmp[50];
-		sprintf(tmp,"TDM API: CMD: %i\n",tdm_api->wp_tdm_cmd.cmd);
+		sprintf(tmp, "TDM API: CMD: %i\n", tdm_api->wp_tdm_cmd.cmd);
 		perror(tmp);
 		return -1;
 	}
@@ -486,40 +471,35 @@
  * Get Full TDM API configuration per channel
  *
  */
-int sangoma_get_full_cfg(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api)
+int sangoma_get_full_cfg(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api)
 {
 	int err;
 
 	tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_FULL_CFG;
 
-	err=sangoma_tdm_cmd_exec(fd,tdm_api);
-	if (err){
+	err = sangoma_tdm_cmd_exec(fd, tdm_api);
+	if (err) {
 		return err;
 	}
 
 	printf("TDM API CFG:\n");
-	printf("\thw_tdm_coding:\t%d\n",tdm_api->wp_tdm_cmd.hw_tdm_coding);
-	printf("\tusr_mtu_mru:\t%d\n",tdm_api->wp_tdm_cmd.hw_mtu_mru);
-	printf("\tusr_period:\t%d\n",tdm_api->wp_tdm_cmd.usr_period);
-	printf("\ttdm_codec:\t%d\n",tdm_api->wp_tdm_cmd.tdm_codec);
-	printf("\tpower_level:\t%d\n",tdm_api->wp_tdm_cmd.power_level);
-	printf("\trx_disable:\t%d\n",tdm_api->wp_tdm_cmd.rx_disable);
-	printf("\ttx_disable:\t%d\n",tdm_api->wp_tdm_cmd.tx_disable);
-	printf("\tusr_mtu_mru:\t%d\n",tdm_api->wp_tdm_cmd.usr_mtu_mru);
-	printf("\tidle flag:\t0x%02X\n",tdm_api->wp_tdm_cmd.idle_flag);
-	printf("\tfe alarms:\t0x%02X\n",tdm_api->wp_tdm_cmd.fe_alarms);
-	
-	printf("\trx pkt\t%d\ttx pkt\t%d\n",tdm_api->wp_tdm_cmd.stats.rx_packets,
-				tdm_api->wp_tdm_cmd.stats.tx_packets);
-	printf("\trx err\t%d\ttx err\t%d\n",
-				tdm_api->wp_tdm_cmd.stats.rx_errors,
-				tdm_api->wp_tdm_cmd.stats.tx_errors);
+	printf("\thw_tdm_coding:\t%d\n", tdm_api->wp_tdm_cmd.hw_tdm_coding);
+	printf("\tusr_mtu_mru:\t%d\n", tdm_api->wp_tdm_cmd.hw_mtu_mru);
+	printf("\tusr_period:\t%d\n", tdm_api->wp_tdm_cmd.usr_period);
+	printf("\ttdm_codec:\t%d\n", tdm_api->wp_tdm_cmd.tdm_codec);
+	printf("\tpower_level:\t%d\n", tdm_api->wp_tdm_cmd.power_level);
+	printf("\trx_disable:\t%d\n", tdm_api->wp_tdm_cmd.rx_disable);
+	printf("\ttx_disable:\t%d\n", tdm_api->wp_tdm_cmd.tx_disable);
+	printf("\tusr_mtu_mru:\t%d\n", tdm_api->wp_tdm_cmd.usr_mtu_mru);
+	printf("\tidle flag:\t0x%02X\n", tdm_api->wp_tdm_cmd.idle_flag);
+	printf("\tfe alarms:\t0x%02X\n", tdm_api->wp_tdm_cmd.fe_alarms);
+
+	printf("\trx pkt\t%d\ttx pkt\t%d\n", tdm_api->wp_tdm_cmd.stats.rx_packets, tdm_api->wp_tdm_cmd.stats.tx_packets);
+	printf("\trx err\t%d\ttx err\t%d\n", tdm_api->wp_tdm_cmd.stats.rx_errors, tdm_api->wp_tdm_cmd.stats.tx_errors);
 #ifndef __WINDOWS__
-	printf("\trx ovr\t%d\ttx idl\t%d\n",
-				tdm_api->wp_tdm_cmd.stats.rx_fifo_errors,
-				tdm_api->wp_tdm_cmd.stats.tx_carrier_errors);
-#endif				
-	
+	printf("\trx ovr\t%d\ttx idl\t%d\n", tdm_api->wp_tdm_cmd.stats.rx_fifo_errors, tdm_api->wp_tdm_cmd.stats.tx_carrier_errors);
+#endif
+
 	return 0;
 }
 
@@ -535,14 +515,14 @@
  * }
  *
  */
-int sangoma_tdm_set_codec(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, int codec)
+int sangoma_tdm_set_codec(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api, int codec)
 {
 	int err;
 
 	tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_CODEC;
 	tdm_api->wp_tdm_cmd.tdm_codec = codec;
 
-	err=sangoma_tdm_cmd_exec(fd,tdm_api);
+	err = sangoma_tdm_cmd_exec(fd, tdm_api);
 
 	return err;
 }
@@ -559,18 +539,18 @@
  * }
  *
  */
-int sangoma_tdm_get_codec(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api)
+int sangoma_tdm_get_codec(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api)
 {
 	int err;
 
 	tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_CODEC;
 
-	err=sangoma_tdm_cmd_exec(fd,tdm_api);
-	if (err){
+	err = sangoma_tdm_cmd_exec(fd, tdm_api);
+	if (err) {
 		return err;
 	}
 
-	return tdm_api->wp_tdm_cmd.tdm_codec;	
+	return tdm_api->wp_tdm_cmd.tdm_codec;
 }
 
 
@@ -581,14 +561,14 @@
  *  10,20,30,40,50 ms      
  *
  */
-int sangoma_tdm_set_usr_period(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, int period)
+int sangoma_tdm_set_usr_period(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api, int period)
 {
 	int err;
 
 	tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_USR_PERIOD;
 	tdm_api->wp_tdm_cmd.usr_period = period;
 
-	err=sangoma_tdm_cmd_exec(fd,tdm_api);
+	err = sangoma_tdm_cmd_exec(fd, tdm_api);
 
 	return err;
 }
@@ -600,14 +580,14 @@
  *  10,20,30,40,50 ms      
  *
  */
-int sangoma_tdm_get_usr_period(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api)
+int sangoma_tdm_get_usr_period(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api)
 {
 	int err;
 
 	tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_USR_PERIOD;
 
-	err=sangoma_tdm_cmd_exec(fd,tdm_api);
-	if (err){
+	err = sangoma_tdm_cmd_exec(fd, tdm_api);
+	if (err) {
 		return err;
 	}
 
@@ -620,15 +600,15 @@
  * Coding Format will be ULAW/ALAW based on T1/E1 
  */
 
-int sangoma_tdm_get_hw_coding(int fd, wanpipe_tdm_api_t *tdm_api)
+int sangoma_tdm_get_hw_coding(int fd, wanpipe_tdm_api_t * tdm_api)
 {
-        int err;
-        tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_HW_CODING;
-        err=sangoma_tdm_cmd_exec(fd,tdm_api);
-        if (err){
-                return err;
-        }
-        return tdm_api->wp_tdm_cmd.hw_tdm_coding;
+	int err;
+	tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_HW_CODING;
+	err = sangoma_tdm_cmd_exec(fd, tdm_api);
+	if (err) {
+		return err;
+	}
+	return tdm_api->wp_tdm_cmd.hw_tdm_coding;
 }
 
 
@@ -638,14 +618,14 @@
  * The USER MTU/MRU values will change each time a PERIOD
  * or CODEC is adjusted.
  */
-int sangoma_tdm_get_usr_mtu_mru(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api)
+int sangoma_tdm_get_usr_mtu_mru(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api)
 {
 	int err;
 
 	tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_USR_MTU_MRU;
 
-	err=sangoma_tdm_cmd_exec(fd,tdm_api);
-	if (err){
+	err = sangoma_tdm_cmd_exec(fd, tdm_api);
+	if (err) {
 		return err;
 	}
 
@@ -658,14 +638,14 @@
  * This option is not implemented yet
  *
  */
-int sangoma_tdm_set_power_level(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, int power)
+int sangoma_tdm_set_power_level(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api, int power)
 {
 	int err;
 
 	tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_POWER_LEVEL;
 	tdm_api->wp_tdm_cmd.power_level = power;
 
-	err=sangoma_tdm_cmd_exec(fd,tdm_api);
+	err = sangoma_tdm_cmd_exec(fd, tdm_api);
 
 	return err;
 }
@@ -676,42 +656,43 @@
  * This option is not implemented yet
  *
  */
-int sangoma_tdm_get_power_level(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api)
+int sangoma_tdm_get_power_level(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api)
 {
 	int err;
 
 	tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_POWER_LEVEL;
 
-	err=sangoma_tdm_cmd_exec(fd,tdm_api);
-	if (err){
+	err = sangoma_tdm_cmd_exec(fd, tdm_api);
+	if (err) {
 		return err;
 	}
 
 	return tdm_api->wp_tdm_cmd.power_level;
 }
 
-int sangoma_tdm_flush_bufs(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api)
+int sangoma_tdm_flush_bufs(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api)
 {
 #if 0
 	tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_FLUSH_BUFFERS;
 
-	err=sangoma_tdm_cmd_exec(fd,tdm_api);
-	if (err){
+	err = sangoma_tdm_cmd_exec(fd, tdm_api);
+	if (err) {
 		return err;
 	}
 #endif
 	return 0;
 }
 
-int sangoma_tdm_enable_rbs_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, int poll_in_sec) {
-	
+int sangoma_tdm_enable_rbs_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api, int poll_in_sec)
+{
+
 	int err;
-	
+
 	tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_ENABLE_RBS_EVENTS;
-	tdm_api->wp_tdm_cmd.rbs_poll=poll_in_sec; 
-	
-	err=sangoma_tdm_cmd_exec(fd,tdm_api);
-	if (err){
+	tdm_api->wp_tdm_cmd.rbs_poll = poll_in_sec;
+
+	err = sangoma_tdm_cmd_exec(fd, tdm_api);
+	if (err) {
 		return err;
 	}
 
@@ -719,185 +700,180 @@
 }
 
 
-int sangoma_tdm_disable_rbs_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api) {
+int sangoma_tdm_disable_rbs_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api)
+{
 
 	int err;
 	tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_DISABLE_RBS_EVENTS;
-	
-	err=sangoma_tdm_cmd_exec(fd,tdm_api);
-	if (err){
+
+	err = sangoma_tdm_cmd_exec(fd, tdm_api);
+	if (err) {
 		return err;
 	}
 
 	return 0;
 }
 
-int sangoma_tdm_write_rbs(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, unsigned char rbs) 
+int sangoma_tdm_write_rbs(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api, unsigned char rbs)
 {
-	
+
 	int err;
 	tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_WRITE_RBS_BITS;
-	tdm_api->wp_tdm_cmd.rbs_tx_bits=rbs; 
-	
-	err=sangoma_tdm_cmd_exec(fd,tdm_api);
-	if (err){
+	tdm_api->wp_tdm_cmd.rbs_tx_bits = rbs;
+
+	err = sangoma_tdm_cmd_exec(fd, tdm_api);
+	if (err) {
 		return err;
 	}
 
 	return 0;
-}        
+}
 
-int sangoma_tdm_read_event(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api) 
+int sangoma_tdm_read_event(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api)
 {
 	wp_tdm_api_rx_hdr_t *rx_event;
 
-#if defined(WIN32)	
+#if defined(WIN32)
 	rx_event = &last_tdm_api_event_buffer;
 #else
 	int err;
 
 	tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_READ_EVENT;
-	
-	err=sangoma_tdm_cmd_exec(fd,tdm_api);
-	if (err){
+
+	err = sangoma_tdm_cmd_exec(fd, tdm_api);
+	if (err) {
 		return err;
 	}
 
 	rx_event = &tdm_api->wp_tdm_cmd.event;
 #endif
 
-	switch (rx_event->wp_tdm_api_event_type){
-	
+	switch (rx_event->wp_tdm_api_event_type) {
+
 	case WP_TDM_EVENT_RBS:
-		printf("%d: GOT RBS EVENT %p\n",(int)fd,tdm_api->wp_tdm_event.wp_rbs_event);
+		printf("%d: GOT RBS EVENT %p\n", (int) fd, tdm_api->wp_tdm_event.wp_rbs_event);
 		if (tdm_api->wp_tdm_event.wp_rbs_event) {
-			tdm_api->wp_tdm_event.wp_rbs_event(fd,rx_event->wp_tdm_api_event_rbs_rx_bits);
+			tdm_api->wp_tdm_event.wp_rbs_event(fd, rx_event->wp_tdm_api_event_rbs_rx_bits);
 		}
-		
+
 		break;
-		
+
 	case WP_TDM_EVENT_DTMF:
-		printf("%d: GOT DTMF EVENT\n",(int)fd);
+		printf("%d: GOT DTMF EVENT\n", (int) fd);
 		if (tdm_api->wp_tdm_event.wp_dtmf_event) {
 			tdm_api->wp_tdm_event.wp_dtmf_event(fd,
-						rx_event->wp_tdm_api_event_dtmf_digit,
-						rx_event->wp_tdm_api_event_dtmf_type,
-						rx_event->wp_tdm_api_event_dtmf_port);
+												rx_event->wp_tdm_api_event_dtmf_digit,
+												rx_event->wp_tdm_api_event_dtmf_type, rx_event->wp_tdm_api_event_dtmf_port);
 		}
 		break;
-		
+
 	case WP_TDM_EVENT_RXHOOK:
-		printf("%d: GOT RXHOOK EVENT\n",(int)fd);
+		printf("%d: GOT RXHOOK EVENT\n", (int) fd);
 		if (tdm_api->wp_tdm_event.wp_rxhook_event) {
-			tdm_api->wp_tdm_event.wp_rxhook_event(fd,
-						rx_event->wp_tdm_api_event_rxhook_state);
+			tdm_api->wp_tdm_event.wp_rxhook_event(fd, rx_event->wp_tdm_api_event_rxhook_state);
 		}
 		break;
 
 	case WP_TDM_EVENT_RING_DETECT:
-		printf("%d: GOT RXRING EVENT\n",(int)fd);
+		printf("%d: GOT RXRING EVENT\n", (int) fd);
 		if (tdm_api->wp_tdm_event.wp_rxring_event) {
-			tdm_api->wp_tdm_event.wp_rxring_event(fd,
-						rx_event->wp_tdm_api_event_ring_state);
+			tdm_api->wp_tdm_event.wp_rxring_event(fd, rx_event->wp_tdm_api_event_ring_state);
 		}
 		break;
 
 	case WP_TDM_EVENT_RING_TRIP:
-		printf("%d: GOT RING TRIP EVENT\n",(int)fd);
+		printf("%d: GOT RING TRIP EVENT\n", (int) fd);
 		if (tdm_api->wp_tdm_event.wp_ringtrip_event) {
-			tdm_api->wp_tdm_event.wp_ringtrip_event(fd,
-						rx_event->wp_tdm_api_event_ring_state);
+			tdm_api->wp_tdm_event.wp_ringtrip_event(fd, rx_event->wp_tdm_api_event_ring_state);
 		}
 		break;
 
 	case WP_TDM_EVENT_FE_ALARM:
-		printf("%d: GOT FE ALARMS EVENT %i\n",(int)fd,
-				rx_event->wp_tdm_api_event_fe_alarm);
+		printf("%d: GOT FE ALARMS EVENT %i\n", (int) fd, rx_event->wp_tdm_api_event_fe_alarm);
 		if (tdm_api->wp_tdm_event.wp_fe_alarm_event) {
-			tdm_api->wp_tdm_event.wp_fe_alarm_event(fd,
-						rx_event->wp_tdm_api_event_fe_alarm);
-		}    
-		
+			tdm_api->wp_tdm_event.wp_fe_alarm_event(fd, rx_event->wp_tdm_api_event_fe_alarm);
+		}
+
 	default:
-		printf("%d: Unknown TDM event!", (int)fd);
+		printf("%d: Unknown TDM event!", (int) fd);
 		break;
 	}
-	
+
 	return 0;
-}        
+}
 
-int sangoma_tdm_enable_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api)
+int sangoma_tdm_enable_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api)
 {
 	int err;
-	
+
 	tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_ENABLE_DTMF_EVENTS;
-	err=sangoma_tdm_cmd_exec(fd,tdm_api);
-	if (err){
+	err = sangoma_tdm_cmd_exec(fd, tdm_api);
+	if (err) {
 		return err;
 	}
 
 	return 0;
 }
 
-int sangoma_tdm_disable_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api) 
+int sangoma_tdm_disable_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api)
 {
 	int err;
 
 	tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_DISABLE_DTMF_EVENTS;
-	err=sangoma_tdm_cmd_exec(fd,tdm_api);
-	if (err){
+	err = sangoma_tdm_cmd_exec(fd, tdm_api);
+	if (err) {
 		return err;
 	}
 
 	return 0;
 }
 
-int sangoma_tdm_enable_rm_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api) 
+int sangoma_tdm_enable_rm_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api)
 {
 	int err;
-	
+
 	tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_ENABLE_RM_DTMF_EVENTS;
-	err=sangoma_tdm_cmd_exec(fd,tdm_api);
-	if (err){
+	err = sangoma_tdm_cmd_exec(fd, tdm_api);
+	if (err) {
 		return err;
 	}
 
 	return 0;
 }
 
-int sangoma_tdm_disable_rm_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api) 
+int sangoma_tdm_disable_rm_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api)
 {
 	int err;
 
 	tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_DISABLE_RM_DTMF_EVENTS;
-	err=sangoma_tdm_cmd_exec(fd,tdm_api);
-	if (err){
+	err = sangoma_tdm_cmd_exec(fd, tdm_api);
+	if (err) {
 		return err;
 	}
 
 	return 0;
 }
 
-int sangoma_tdm_enable_rxhook_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api) 
+int sangoma_tdm_enable_rxhook_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api)
 {
 	int err;
 
 	tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_ENABLE_RXHOOK_EVENTS;
-	err=sangoma_tdm_cmd_exec(fd,tdm_api);
-	if (err){
+	err = sangoma_tdm_cmd_exec(fd, tdm_api);
+	if (err) {
 		return err;
 	}
 
 	return 0;
 }
 
-int sangoma_tdm_disable_rxhook_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api) 
+int sangoma_tdm_disable_rxhook_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api)
 {
 	int err;
 
 	tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_DISABLE_RXHOOK_EVENTS;
-	err=sangoma_tdm_cmd_exec(fd,tdm_api);
-	if (err){
+	err = sangoma_tdm_cmd_exec(fd, tdm_api);
+	if (err) {
 		return err;
 	}
 
@@ -908,18 +884,18 @@
  * GET Front End Alarms
  * 
  */
-int sangoma_tdm_get_fe_alarms(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api)
+int sangoma_tdm_get_fe_alarms(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api)
 {
 	int err;
 
 	tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_FE_ALARMS;
 
-	err=sangoma_tdm_cmd_exec(fd,tdm_api);
-	if (err){
+	err = sangoma_tdm_cmd_exec(fd, tdm_api);
+	if (err) {
 		return err;
 	}
 
 	return tdm_api->wp_tdm_cmd.fe_alarms;
-}         
+}
 
 #endif /* WANPIPE_TDM_API */

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.h	Fri Mar 30 12:19:18 2007
@@ -34,7 +34,7 @@
 #ifdef WANPIPE_TDM_API
 #include <wanpipe_tdm_api.h>	//for TDMV API
 #endif
-#include <sang_status_defines.h>//return codes
+#include <sang_status_defines.h>	//return codes
 #include <sang_api.h>			//for IOCTL codes
 #include <sdla_te1_pmc.h>		//RBS definitions
 #include <sdla_te1.h>			//TE1 macros
@@ -94,7 +94,7 @@
 /* Open Span/Chan devices
  * open_tdmapi_span_chan: open device based on span chan values 
  * sangoma_open_tdmapi_span: open first available device on span
- */     
+ */
 
 sng_fd_t sangoma_open_tdmapi_span_chan(int span, int chan);
 sng_fd_t sangoma_open_tdmapi_span(int span);
@@ -104,67 +104,65 @@
 /* Device Rx/Tx functions 
  * writemsg_tdm: 	tx header + data from separate buffers 
  * readmsg_tdm: 	rx header + data to separate buffers
- */    
-int sangoma_writemsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen, 
-						 void *databuf, unsigned short datalen, int flag);
-int sangoma_readmsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen, 
-						void *databuf, int datalen, int flag);
+ */
+int sangoma_writemsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen, void *databuf, unsigned short datalen, int flag);
+int sangoma_readmsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen, void *databuf, int datalen, int flag);
 
 #define sangoma_readmsg_socket sangoma_readmsg_tdm
 #define sangoma_sendmsg_socket sangoma_writemsg_tdm
 
 #ifdef WANPIPE_TDM_API
 
-void sangoma_socket_close(sng_fd_t *sp);
+void sangoma_socket_close(sng_fd_t * sp);
 int sangoma_socket_waitfor(sng_fd_t fd, int timeout, int flags);
 
 /* Get Full TDM API configuration per chan */
-int sangoma_get_full_cfg(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
+int sangoma_get_full_cfg(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
 
 /* Get/Set TDM Codec per chan */
-int sangoma_tdm_set_codec(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, int codec);
-int sangoma_tdm_get_codec(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
+int sangoma_tdm_set_codec(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api, int codec);
+int sangoma_tdm_get_codec(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
 
 /* Get/Set USR Tx/Rx Period in milliseconds */
-int sangoma_tdm_set_usr_period(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, int period);
-int sangoma_tdm_get_usr_period(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
+int sangoma_tdm_set_usr_period(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api, int period);
+int sangoma_tdm_get_usr_period(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
 
 /* Get user MTU/MRU values in bytes */
-int sangoma_tdm_get_usr_mtu_mru(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
+int sangoma_tdm_get_usr_mtu_mru(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
 
 /* Not supported yet */
-int sangoma_tdm_set_power_level(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, int power);
-int sangoma_tdm_get_power_level(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
+int sangoma_tdm_set_power_level(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api, int power);
+int sangoma_tdm_get_power_level(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
 
 /* Flush buffers from current channel */
-int sangoma_tdm_flush_bufs(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
+int sangoma_tdm_flush_bufs(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
 
-int sangoma_tdm_enable_rbs_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, int poll_in_sec);
-int sangoma_tdm_disable_rbs_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
+int sangoma_tdm_enable_rbs_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api, int poll_in_sec);
+int sangoma_tdm_disable_rbs_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
 
-int sangoma_tdm_write_rbs(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, unsigned char rbs);
+int sangoma_tdm_write_rbs(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api, unsigned char rbs);
 
-int sangoma_tdm_read_event(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
+int sangoma_tdm_read_event(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
 
 /* DTMF Detection on Octasic chip */
-int sangoma_tdm_enable_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
-int sangoma_tdm_disable_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
+int sangoma_tdm_enable_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
+int sangoma_tdm_disable_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
 
 /* DTMF Detection on A200 (SLIC) chip */
-int sangoma_tdm_enable_rm_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
-int sangoma_tdm_disable_rm_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
+int sangoma_tdm_enable_rm_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
+int sangoma_tdm_disable_rm_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
 
 /* On/Off hook events on A200 (Analog) card */
-int sangoma_tdm_enable_rxhook_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
-int sangoma_tdm_disable_rxhook_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
+int sangoma_tdm_enable_rxhook_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
+int sangoma_tdm_disable_rxhook_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
 
-int sangoma_tdm_get_fe_alarms(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
+int sangoma_tdm_get_fe_alarms(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
 
 #ifndef LIBSANGOMA_GET_HWCODING
 #define LIBSANGOMA_GET_HWCODING 1
 #endif
-int sangoma_tdm_get_hw_coding(int fd, wanpipe_tdm_api_t *tdm_api);
+int sangoma_tdm_get_hw_coding(int fd, wanpipe_tdm_api_t * tdm_api);
 
-#endif 	/* WANPIPE_TDM_API */
+#endif /* WANPIPE_TDM_API */
 
 #endif

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/libsangoma/sangoma_pri.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/libsangoma/sangoma_pri.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/libsangoma/sangoma_pri.c	Fri Mar 30 12:19:18 2007
@@ -23,20 +23,21 @@
 static __inline int gettimeofday(struct timeval *tp, void *nothing)
 {
 #ifdef WITHOUT_MM_LIB
-  SYSTEMTIME st;
-  time_t tt;
-  struct tm tmtm;
-  /* mktime converts local to UTC */
-  GetLocalTime (&st);
-  tmtm.tm_sec = st.wSecond;
-  tmtm.tm_min = st.wMinute;
-  tmtm.tm_hour = st.wHour;
-  tmtm.tm_mday = st.wDay;
-  tmtm.tm_mon = st.wMonth - 1;
-  tmtm.tm_year = st.wYear - 1900;  tmtm.tm_isdst = -1;
-  tt = mktime (&tmtm);
-  tp->tv_sec = tt;
-  tp->tv_usec = st.wMilliseconds * 1000;
+	SYSTEMTIME st;
+	time_t tt;
+	struct tm tmtm;
+	/* mktime converts local to UTC */
+	GetLocalTime(&st);
+	tmtm.tm_sec = st.wSecond;
+	tmtm.tm_min = st.wMinute;
+	tmtm.tm_hour = st.wHour;
+	tmtm.tm_mday = st.wDay;
+	tmtm.tm_mon = st.wMonth - 1;
+	tmtm.tm_year = st.wYear - 1900;
+	tmtm.tm_isdst = -1;
+	tt = mktime(&tmtm);
+	tp->tv_sec = tt;
+	tp->tv_usec = st.wMilliseconds * 1000;
 #else
   /**
    ** The earlier time calculations using GetLocalTime
@@ -44,18 +45,18 @@
    ** of multimedia apis offer a better time resolution
    ** of 1ms.Need to link against winmm.lib for this
    **/
-  unsigned long Ticks = 0;
-  unsigned long Sec =0;
-  unsigned long Usec = 0;
-  Ticks = timeGetTime();
-
-  Sec = Ticks/1000;
-  Usec = (Ticks - (Sec*1000))*1000;
-  tp->tv_sec = Sec;
-  tp->tv_usec = Usec;
+	unsigned long Ticks = 0;
+	unsigned long Sec = 0;
+	unsigned long Usec = 0;
+	Ticks = timeGetTime();
+
+	Sec = Ticks / 1000;
+	Usec = (Ticks - (Sec * 1000)) * 1000;
+	tp->tv_sec = Sec;
+	tp->tv_usec = Usec;
 #endif /* WITHOUT_MM_LIB */
-  (void)nothing;
-  return 0;
+	(void) nothing;
+	return 0;
 }
 #endif /* WIN32 */
 #endif /* HAVE_GETTIMEOFDAY */
@@ -84,37 +85,37 @@
 
 
 char *sangoma_pri_event_str(sangoma_pri_event_t event_id)
-{ 
+{
 	return SANGOMA_PRI_EVENT_LIST[event_id].name;
 }
 
 static int __pri_sangoma_read(struct pri *pri, void *buf, int buflen)
 {
 	unsigned char tmpbuf[sizeof(wp_tdm_api_rx_hdr_t)];
-	
+
 
 	/* NOTE: This code will be different for A104 
 	 *       A104   receives data + 2byte CRC + 1 byte flag 
-	 *       A101/2 receives data only */ 
-	
-	int res = sangoma_readmsg_socket((sng_fd_t)(pri->fd), 
-					 tmpbuf, sizeof(wp_tdm_api_rx_hdr_t), 
-					 buf, buflen, 
-					 0);
-	if (res > 0){
+	 *       A101/2 receives data only */
+
+	int res = sangoma_readmsg_socket((sng_fd_t) (pri->fd),
+									 tmpbuf, sizeof(wp_tdm_api_rx_hdr_t),
+									 buf, buflen,
+									 0);
+	if (res > 0) {
 #ifdef WANPIPE_LEGACY_A104
 		/* Prior 2.3.4 release A104 API passed up
-                 * 3 extra bytes: 2 CRC + 1 FLAG,
-                 * PRI is expecting only 2 CRC bytes, thus we
-                 * must remove 1 flag byte */
+		 * 3 extra bytes: 2 CRC + 1 FLAG,
+		 * PRI is expecting only 2 CRC bytes, thus we
+		 * must remove 1 flag byte */
 		res--;
 #else
-		/* Add 2 byte CRC and set it to ZERO */ 
-		memset(&((unsigned char*)buf)[res],0,2);
-		res+=2;
+		/* Add 2 byte CRC and set it to ZERO */
+		memset(&((unsigned char *) buf)[res], 0, 2);
+		res += 2;
 #endif
-	}else{
-		res=0;
+	} else {
+		res = 0;
 	}
 
 	return res;
@@ -126,25 +127,22 @@
 	int res;
 
 
-	memset(&tmpbuf[0],0,sizeof(wp_tdm_api_rx_hdr_t));	
+	memset(&tmpbuf[0], 0, sizeof(wp_tdm_api_rx_hdr_t));
 
-	if (buflen < 1){
+	if (buflen < 1) {
 		/* HDLC Frame must be greater than 2byte CRC */
-		fprintf(stderr,"%s: Got short frame %i\n",__FUNCTION__,buflen);
+		fprintf(stderr, "%s: Got short frame %i\n", __FUNCTION__, buflen);
 		return 0;
 	}
 
 	/* FIXME: This might cause problems with other libraries
 	 * We must remove 2 bytes from buflen because
 	 * libpri sends 2 fake CRC bytes */
-	res=sangoma_sendmsg_socket((sng_fd_t)(pri->fd),
-				   tmpbuf, sizeof(wp_tdm_api_rx_hdr_t),
-				   buf, (unsigned short)buflen-2,
-				   0);	
-	if (res > 0){
-		res=buflen;
+	res = sangoma_sendmsg_socket((sng_fd_t) (pri->fd), tmpbuf, sizeof(wp_tdm_api_rx_hdr_t), buf, (unsigned short) buflen - 2, 0);
+	if (res > 0) {
+		res = buflen;
 	}
-	
+
 	return res;
 }
 
@@ -155,10 +153,10 @@
 
 	memset(spri, 0, sizeof(struct sangoma_pri));
 
-	if((dfd = sangoma_open_tdmapi_span_chan(span, dchan)) < 0) {
+	if ((dfd = sangoma_open_tdmapi_span_chan(span, dchan)) < 0) {
 		fprintf(stderr, "Unable to open DCHAN %d for span %d (%s)\n", dchan, span, strerror(errno));
 	} else {
-		  if ((spri->pri = pri_new_cb((int)dfd, node, swtype, __pri_sangoma_read, __pri_sangoma_write, NULL))){
+		if ((spri->pri = pri_new_cb((int) dfd, node, swtype, __pri_sangoma_read, __pri_sangoma_write, NULL))) {
 			spri->span = span;
 			pri_set_debug(spri->pri, debug);
 			ret = 0;
@@ -173,10 +171,10 @@
 int sangoma_one_loop(struct sangoma_pri *spri)
 {
 	fd_set rfds, efds;
-	struct timeval now = {0,0}, *next;
+	struct timeval now = { 0, 0 }, *next;
 	pri_event *event;
-    int sel;
-	
+	int sel;
+
 	if (spri->on_loop) {
 		spri->on_loop(spri);
 	}
@@ -226,7 +224,7 @@
 		if ((handler = spri->eventmap[event->e] ? spri->eventmap[event->e] : spri->eventmap[0] ? spri->eventmap[0] : NULL)) {
 			handler(spri, event->e, event);
 		} else {
-			fprintf(stderr,"No event handler found for event %d.\n", event->e);
+			fprintf(stderr, "No event handler found for event %d.\n", event->e);
 		}
 	}
 
@@ -237,23 +235,22 @@
 {
 	int ret = 0;
 
-	for (;;){
-		ret=sangoma_one_loop(spri);
-		if (ret < 0){
+	for (;;) {
+		ret = sangoma_one_loop(spri);
+		if (ret < 0) {
 
-#ifndef WIN32 //This needs to be adressed fror WIN32 still
-			if (errno == EINTR){
+#ifndef WIN32					//This needs to be adressed fror WIN32 still
+			if (errno == EINTR) {
 				/* Igonore an interrupted system call */
 				continue;
 			}
-#endif	
-			printf("Error = %i\n",ret);
+#endif
+			printf("Error = %i\n", ret);
 			perror("Sangoma Run Pri: ");
-			break;		
+			break;
 		}
 	}
 
 	return ret;
 
 }
-

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/libsangoma/sangoma_pri.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/libsangoma/sangoma_pri.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/libsangoma/sangoma_pri.h	Fri Mar 30 12:19:18 2007
@@ -50,7 +50,7 @@
 
 typedef enum {
 	SANGOMA_PRI_SWITCH_UNKNOWN = PRI_SWITCH_UNKNOWN,
-	SANGOMA_PRI_SWITCH_NI2 = PRI_SWITCH_NI2,	   		
+	SANGOMA_PRI_SWITCH_NI2 = PRI_SWITCH_NI2,
 	SANGOMA_PRI_SWITCH_DMS100 = PRI_SWITCH_DMS100,
 	SANGOMA_PRI_SWITCH_LUCENT5E = PRI_SWITCH_LUCENT5E,
 	SANGOMA_PRI_SWITCH_ATT4ESS = PRI_SWITCH_ATT4ESS,
@@ -67,8 +67,8 @@
 } sangoma_pri_flag_t;
 
 struct sangoma_pri;
-typedef int (*event_handler)(struct sangoma_pri *, sangoma_pri_event_t, pri_event *);
-typedef int (*loop_handler)(struct sangoma_pri *);
+typedef int (*event_handler) (struct sangoma_pri *, sangoma_pri_event_t, pri_event *);
+typedef int (*loop_handler) (struct sangoma_pri *);
 #define MAX_EVENT 18
 
 struct sangoma_pri {
@@ -77,7 +77,7 @@
 	int dchan;
 	unsigned int flags;
 	void *private_info;
-	event_handler eventmap[MAX_EVENT+1];
+	event_handler eventmap[MAX_EVENT + 1];
 	loop_handler on_loop;
 };
 

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/libsangoma/win_api_common.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/libsangoma/win_api_common.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/libsangoma/win_api_common.h	Fri Mar 30 12:19:18 2007
@@ -11,228 +11,147 @@
 #ifndef _WIN_API_COMMON_H
 #define _WIN_API_COMMON_H
 
-static 
-int 
-tdmv_api_ioctl(
-	HANDLE fd, 
-	wanpipe_tdm_api_cmd_t *tdm_api_cmd
-	)
-{
-	DWORD			ln;
-    unsigned char	id = 0;
-	int				err = 0;
+static
+int tdmv_api_ioctl(HANDLE fd, wanpipe_tdm_api_cmd_t * tdm_api_cmd)
+{
+	DWORD ln;
+	unsigned char id = 0;
+	int err = 0;
 
 	wan_udp.wan_udphdr_request_reply = 0x01;
-	wan_udp.wan_udphdr_id			 = id;
-   	wan_udp.wan_udphdr_return_code	 = WAN_UDP_TIMEOUT_CMD;
+	wan_udp.wan_udphdr_id = id;
+	wan_udp.wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD;
 
-	wan_udp.wan_udphdr_command	= WAN_TDMV_API_IOCTL;
-	wan_udp.wan_udphdr_data_len	= sizeof(wanpipe_tdm_api_cmd_t);
+	wan_udp.wan_udphdr_command = WAN_TDMV_API_IOCTL;
+	wan_udp.wan_udphdr_data_len = sizeof(wanpipe_tdm_api_cmd_t);
 
 	//copy data from caller's buffer to driver's buffer
-	memcpy(	wan_udp.wan_udphdr_data, 
-			(void*)tdm_api_cmd,
-			sizeof(wanpipe_tdm_api_cmd_t));
-
-	if(DeviceIoControl(
-			fd,
-			IoctlManagementCommand,
-			(LPVOID)&wan_udp,
-			sizeof(wan_udp_hdr_t),
-			(LPVOID)&wan_udp,
-			sizeof(wan_udp_hdr_t),
-			(LPDWORD)(&ln),
-			(LPOVERLAPPED)NULL
-			) == FALSE){
+	memcpy(wan_udp.wan_udphdr_data, (void *) tdm_api_cmd, sizeof(wanpipe_tdm_api_cmd_t));
+
+	if (DeviceIoControl(fd,
+						IoctlManagementCommand,
+						(LPVOID) & wan_udp, sizeof(wan_udp_hdr_t), (LPVOID) & wan_udp, sizeof(wan_udp_hdr_t), (LPDWORD) (&ln),
+						(LPOVERLAPPED) NULL) == FALSE) {
 		//actual ioctl failed
 		err = 1;
 		prn(1, "Error: tdmv_api_ioctl(): DeviceIoControl failed!!\n");
 		return err;
-	}else{
+	} else {
 		err = 0;
 	}
 
-	if(wan_udp.wan_udphdr_return_code != WAN_CMD_OK){
+	if (wan_udp.wan_udphdr_return_code != WAN_CMD_OK) {
 		//ioctl ok, but command failed
-		prn(1, "Error: tdmv_api_ioctl(): command failed! Return code: 0x%X.\n",
-			wan_udp.wan_udphdr_return_code);
+		prn(1, "Error: tdmv_api_ioctl(): command failed! Return code: 0x%X.\n", wan_udp.wan_udphdr_return_code);
 		return 2;
 	}
-
 	//copy data from driver's buffer to caller's buffer
-	memcpy(	(void*)tdm_api_cmd,
-			wan_udp.wan_udphdr_data, 
-			sizeof(wanpipe_tdm_api_cmd_t));
+	memcpy((void *) tdm_api_cmd, wan_udp.wan_udphdr_data, sizeof(wanpipe_tdm_api_cmd_t));
 	return 0;
 }
 
-static 
-int 
-wanpipe_api_ioctl(
-	HANDLE fd,
-	wan_cmd_api_t *api_cmd
-	)
-{
-	DWORD			ln;
-    unsigned char	id = 0;
-	int				err = 0;
+static
+int wanpipe_api_ioctl(HANDLE fd, wan_cmd_api_t * api_cmd)
+{
+	DWORD ln;
+	unsigned char id = 0;
+	int err = 0;
 
 	wan_udp.wan_udphdr_request_reply = 0x01;
-	wan_udp.wan_udphdr_id			 = id;
-   	wan_udp.wan_udphdr_return_code   = WAN_UDP_TIMEOUT_CMD;
+	wan_udp.wan_udphdr_id = id;
+	wan_udp.wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD;
 
-	wan_udp.wan_udphdr_command	= SIOC_WANPIPE_API;
-	wan_udp.wan_udphdr_data_len	= sizeof(wan_cmd_api_t);
+	wan_udp.wan_udphdr_command = SIOC_WANPIPE_API;
+	wan_udp.wan_udphdr_data_len = sizeof(wan_cmd_api_t);
 
 	//copy data from caller's buffer to driver's buffer
-	memcpy(	wan_udp.wan_udphdr_data, 
-			(void*)api_cmd,
-			sizeof(wan_cmd_api_t));
-
-	if(DeviceIoControl(
-			fd,
-			IoctlManagementCommand,
-			(LPVOID)&wan_udp,
-			sizeof(wan_udp_hdr_t),
-			(LPVOID)&wan_udp,
-			sizeof(wan_udp_hdr_t),
-			(LPDWORD)(&ln),
-			(LPOVERLAPPED)NULL
-			) == FALSE){
+	memcpy(wan_udp.wan_udphdr_data, (void *) api_cmd, sizeof(wan_cmd_api_t));
+
+	if (DeviceIoControl(fd,
+						IoctlManagementCommand,
+						(LPVOID) & wan_udp, sizeof(wan_udp_hdr_t), (LPVOID) & wan_udp, sizeof(wan_udp_hdr_t), (LPDWORD) (&ln),
+						(LPOVERLAPPED) NULL) == FALSE) {
 		err = 1;
 		prn(1, "Error: wanpipe_api_ioctl(): DeviceIoControl failed!!\n");
 		return err;
-	}else{
+	} else {
 		err = 0;
 	}
 
-	if(wan_udp.wan_udphdr_return_code != WAN_CMD_OK){
-		prn(1, "Error: wanpipe_api_ioctl(): command failed! Return code: 0x%X.\n",
-			wan_udp.wan_udphdr_return_code);
+	if (wan_udp.wan_udphdr_return_code != WAN_CMD_OK) {
+		prn(1, "Error: wanpipe_api_ioctl(): command failed! Return code: 0x%X.\n", wan_udp.wan_udphdr_return_code);
 		return 2;
 	}
-
 	//copy data from driver's buffer to caller's buffer
-	memcpy(	(void*)api_cmd,
-			wan_udp.wan_udphdr_data, 
-			sizeof(wan_cmd_api_t));
+	memcpy((void *) api_cmd, wan_udp.wan_udphdr_data, sizeof(wan_cmd_api_t));
 	return 0;
 }
 
 // Blocking read command. If used after DoApiPollCommand(),
 // it will return immediatly, without blocking.
-static 
-USHORT 
-DoReadCommand(
-	HANDLE drv, 
-	RX_DATA_STRUCT * pRx
-	)
+static USHORT DoReadCommand(HANDLE drv, RX_DATA_STRUCT * pRx)
 {
 	DWORD ln;
 
-	if (DeviceIoControl(
-			drv,
-			IoctlReadCommand,
-			(LPVOID)NULL,
-			0L,
-			(LPVOID)pRx,
-			sizeof(RX_DATA_STRUCT),
-			(LPDWORD)(&ln),
-			(LPOVERLAPPED)NULL
-			) == FALSE){
+	if (DeviceIoControl(drv, IoctlReadCommand, (LPVOID) NULL, 0L, (LPVOID) pRx, sizeof(RX_DATA_STRUCT), (LPDWORD) (&ln), (LPOVERLAPPED) NULL) == FALSE) {
 		//check messages log
 		prn(1, "Error: DoReadCommand(): DeviceIoControl failed!\n");
 		return 1;
-	}else{
+	} else {
 		return 0;
 	}
 }
 
 // Blocking write command. If used after DoApiPollCommand(),
 // it will return immediatly, without blocking.
-static
-UCHAR 
-DoWriteCommand(
-	HANDLE drv, 
-	TX_DATA_STRUCT * pTx
-	)
+static UCHAR DoWriteCommand(HANDLE drv, TX_DATA_STRUCT * pTx)
 {
 	DWORD ln;
 
-	if(DeviceIoControl(
-			drv,
-			IoctlWriteCommand,
-			(LPVOID)pTx,
-			(ULONG)sizeof(TX_DATA_STRUCT),
-			(LPVOID)pTx,
-			sizeof(TX_DATA_STRUCT),
-			(LPDWORD)(&ln),
-			(LPOVERLAPPED)NULL
-			) == FALSE){
+	if (DeviceIoControl(drv,
+						IoctlWriteCommand,
+						(LPVOID) pTx, (ULONG) sizeof(TX_DATA_STRUCT), (LPVOID) pTx, sizeof(TX_DATA_STRUCT), (LPDWORD) (&ln),
+						(LPOVERLAPPED) NULL) == FALSE) {
 		//check messages log
 		prn(1, "Error: DoWriteCommand(): DeviceIoControl failed!\n");
 		return 1;
-	}else{
+	} else {
 		return 0;
 	}
 }
 
 // Blocking API Poll command.
-static
-USHORT 
-DoApiPollCommand(
-	HANDLE drv, 
-	API_POLL_STRUCT *api_poll_ptr
-	)
+static USHORT DoApiPollCommand(HANDLE drv, API_POLL_STRUCT * api_poll_ptr)
 {
 	DWORD ln;
 
-	if (DeviceIoControl(
-			drv,
-			IoctlApiPoll,
-			(LPVOID)NULL,
-			0L,
-			(LPVOID)api_poll_ptr,
-			sizeof(API_POLL_STRUCT),
-			(LPDWORD)(&ln),
-			(LPOVERLAPPED)NULL
-						) == FALSE){
+	if (DeviceIoControl(drv, IoctlApiPoll, (LPVOID) NULL, 0L, (LPVOID) api_poll_ptr, sizeof(API_POLL_STRUCT), (LPDWORD) (&ln), (LPOVERLAPPED) NULL) ==
+		FALSE) {
 		//check messages log
 		prn(1, "Error: DoApiPollCommand(): DeviceIoControl failed!\n");
 		return 1;
-	}else{
+	} else {
 		return 0;
 	}
 }
 
 static
-int 
-DoManagementCommand(
-	HANDLE drv, 
-	wan_udp_hdr_t* wan_udp
-	)
+int DoManagementCommand(HANDLE drv, wan_udp_hdr_t * wan_udp)
 {
 	DWORD ln;
-    static unsigned char id = 0;
+	static unsigned char id = 0;
 
 	wan_udp->wan_udphdr_request_reply = 0x01;
 	wan_udp->wan_udphdr_id = id++;
-   	wan_udp->wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD;
+	wan_udp->wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD;
 
-	if(DeviceIoControl(
-			drv,
-			IoctlManagementCommand,
-			(LPVOID)wan_udp,
-			sizeof(wan_udp_hdr_t),
-			(LPVOID)wan_udp,
-			sizeof(wan_udp_hdr_t),
-			(LPDWORD)(&ln),
-			(LPOVERLAPPED)NULL
-						) == FALSE){
+	if (DeviceIoControl(drv,
+						IoctlManagementCommand,
+						(LPVOID) wan_udp, sizeof(wan_udp_hdr_t), (LPVOID) wan_udp, sizeof(wan_udp_hdr_t), (LPDWORD) (&ln), (LPOVERLAPPED) NULL) == FALSE) {
 		//check messages log
 		prn(1, "Error: DoManagementCommand(): DeviceIoControl failed!\n");
 		return 1;
-	}else{
+	} else {
 		return 0;
 	}
 }

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c	Fri Mar 30 12:19:18 2007
@@ -80,8 +80,8 @@
 	char map[SANGOMA_MAX_CHAN_PER_SPAN][SWITCH_UUID_FORMATTED_LENGTH + 1];
 };
 
-unsigned int txseq=0;
-unsigned int rxseq=0;
+unsigned int txseq = 0;
+unsigned int rxseq = 0;
 
 #define SETUP_LEN CORE_MAX_CHAN_PER_SPAN*CORE_MAX_SPANS+1
 
@@ -99,7 +99,7 @@
 
 typedef struct ss7boost_handle ss7boost_handle_t;
 
-static int isup_exec_command(ss7boost_handle_t *ss7boost_handle, int span, int chan, int id, int cmd, int cause);
+static int isup_exec_command(ss7boost_handle_t * ss7boost_handle, int span, int chan, int id, int cmd, int cause);
 
 static struct {
 	int debug;
@@ -210,38 +210,38 @@
 
 
 
-static int local_sangoma_tdm_read_event(sng_fd_t fd, wp_tdm_api_rx_hdr_t *rx_event)
+static int local_sangoma_tdm_read_event(sng_fd_t fd, wp_tdm_api_rx_hdr_t * rx_event)
 {
 	wanpipe_tdm_api_t tdm_api[1];
-	
+
 #if defined(WIN32)
-    rx_event = &last_tdm_api_event_buffer;
+	rx_event = &last_tdm_api_event_buffer;
 #else
-    int err;
+	int err;
 
-    tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_READ_EVENT;
+	tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_READ_EVENT;
 
-    if ((err = sangoma_tdm_cmd_exec(fd, tdm_api))) {
-        return err;
-    }
+	if ((err = sangoma_tdm_cmd_exec(fd, tdm_api))) {
+		return err;
+	}
 
-    rx_event = &tdm_api->wp_tdm_cmd.event;
+	rx_event = &tdm_api->wp_tdm_cmd.event;
 #endif
 
 	return 0;
 }
 
-static int analog_set_state(analog_channel_t *alc, analog_state_t state)
+static int analog_set_state(analog_channel_t * alc, analog_state_t state)
 {
 	alc->state = state;
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Changing State to %d\n", state);
 }
 
-static void analog_check_state(analog_channel_t *alc)
+static void analog_check_state(analog_channel_t * alc)
 {
 	wanpipe_tdm_api_t tdm_api;
 
-	switch(alc->state) {
+	switch (alc->state) {
 	case ANALOG_STATE_DOWN:
 		sangoma_tdm_enable_rxhook_events(alc->sock->fd, &tdm_api);
 		analog_set_state(alc, ANALOG_STATE_ONHOOK);
@@ -251,11 +251,11 @@
 	}
 }
 
-static void analog_parse_event(analog_channel_t *alc)
+static void analog_parse_event(analog_channel_t * alc)
 {
 	wp_tdm_api_rx_hdr_t rx_event;
 	int err = local_sangoma_tdm_read_event(alc->sock->fd, &rx_event);
-	
+
 	if (err < 0) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error reading event!\n");
 		return;
@@ -269,21 +269,21 @@
 
 }
 
-static void *SWITCH_THREAD_FUNC fxs_thread_run(switch_thread_t *thread, void *obj)
+static void *SWITCH_THREAD_FUNC fxs_thread_run(switch_thread_t * thread, void *obj)
 {
 
-	for(;;) {
+	for (;;) {
 		int i = 0, sel_on = -1;
 		fd_set oob;
 		FD_ZERO(&oob);
-		
-		for(i = 0; i < globals.fxs_index; i++) {
+
+		for (i = 0; i < globals.fxs_index; i++) {
 			int fd;
 			assert(FXS_ANALOG_CHANNELS[i]);
 			assert(FXS_ANALOG_CHANNELS[i]->sock);
 
 			fd = FXS_ANALOG_CHANNELS[i]->sock->fd;
-			
+
 			analog_check_state(FXS_ANALOG_CHANNELS[i]);
 
 			FD_SET(fd, &oob);
@@ -295,7 +295,7 @@
 
 		if (sel_on > -1) {
 			if (select(++sel_on, NULL, NULL, &oob, NULL)) {
-				for(i = 0; i < globals.fxs_index; i++) {
+				for (i = 0; i < globals.fxs_index; i++) {
 					int fd = FXS_ANALOG_CHANNELS[i]->sock->fd;
 					if (FD_ISSET(fd, &oob)) {
 						analog_parse_event(FXS_ANALOG_CHANNELS[i]);
@@ -307,7 +307,7 @@
 }
 
 
-static int wp_close(private_object_t *tech_pvt)
+static int wp_close(private_object_t * tech_pvt)
 {
 	int ret = 0;
 
@@ -317,16 +317,16 @@
 		ret = 1;
 	}
 	switch_mutex_unlock(globals.hash_mutex);
-	
+
 	return ret;
 }
 
-static wpsock_t *wp_open(private_object_t *tech_pvt, int span, int chan)
+static wpsock_t *wp_open(private_object_t * tech_pvt, int span, int chan)
 {
 	sng_fd_t fd;
 	wpsock_t *sock;
 	char name[25];
-	
+
 	snprintf(name, sizeof(name), "s%dc%d", span, chan);
 
 	switch_mutex_lock(globals.hash_mutex);
@@ -364,7 +364,7 @@
 	wpsock_t *sock;
 	sng_fd_t fd;
 	char name[25];
-	
+
 	snprintf(name, sizeof(name), "s%dc%d", span, chan);
 
 	switch_mutex_lock(globals.hash_mutex);
@@ -380,7 +380,7 @@
 		sangoma_socket_close(&fd);
 		return 0;
 	}
-	
+
 	return -1;
 }
 
@@ -444,7 +444,7 @@
 	if (!strcasecmp(dp, "local"))
 		return PRI_LOCAL_ISDN;
 	if (!strcasecmp(dp, "private"))
-		return PRI_PRIVATE;		
+		return PRI_PRIVATE;
 	if (!strcasecmp(dp, "unknown"))
 		return PRI_UNKNOWN;
 
@@ -460,26 +460,25 @@
 static switch_status_t wanpipe_on_hangup(switch_core_session_t *session);
 static switch_status_t wanpipe_on_loopback(switch_core_session_t *session);
 static switch_status_t wanpipe_on_transmit(switch_core_session_t *session);
-static switch_call_cause_t wanpipe_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile,
+static switch_call_cause_t wanpipe_outgoing_channel(switch_core_session_t *session,
+													switch_caller_profile_t *outbound_profile,
 													switch_core_session_t **new_session, switch_memory_pool_t **pool);
-static switch_status_t wanpipe_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout,
-										switch_io_flag_t flags, int stream_id);
-static switch_status_t wanpipe_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout,
-										 switch_io_flag_t flags, int stream_id);
-static int on_info(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *pevent);
-static int on_hangup(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *pevent);
-static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *pevent);
+static switch_status_t wanpipe_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, switch_io_flag_t flags, int stream_id);
+static switch_status_t wanpipe_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flags, int stream_id);
+static int on_info(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent);
+static int on_hangup(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent);
+static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent);
 static int check_flags(struct sangoma_pri *spri);
-static int on_restart(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *pevent);
-static int on_anything(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *pevent);
-static void *SWITCH_THREAD_FUNC pri_thread_run(switch_thread_t *thread, void *obj);
+static int on_restart(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent);
+static int on_anything(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent);
+static void *SWITCH_THREAD_FUNC pri_thread_run(switch_thread_t * thread, void *obj);
 static switch_status_t config_wanpipe(int reload);
 
 
-static switch_status_t wanpipe_codec_init(private_object_t *tech_pvt)
+static switch_status_t wanpipe_codec_init(private_object_t * tech_pvt)
 {
 	int err = 0;
-	wanpipe_tdm_api_t tdm_api = {{0}};
+	wanpipe_tdm_api_t tdm_api = { {0} };
 	unsigned int rate = 8000;
 	switch_channel_t *channel = NULL;
 
@@ -492,21 +491,21 @@
 	assert(channel != NULL);
 
 	err = sangoma_tdm_set_codec(tech_pvt->wpsock->fd, &tdm_api, WP_SLINEAR);
-	
+
 	sangoma_tdm_set_usr_period(tech_pvt->wpsock->fd, &tdm_api, globals.samples_per_frame / 8);
 	tech_pvt->frame_size = sangoma_tdm_get_usr_mtu_mru(tech_pvt->wpsock->fd, &tdm_api);
 
 	if (switch_core_codec_init
-		(&tech_pvt->read_codec, "L16", NULL, rate, globals.samples_per_frame / 8, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
-		 switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
+		(&tech_pvt->read_codec, "L16", NULL, rate, globals.samples_per_frame / 8, 1,
+		 SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s Cannot set read codec\n", switch_channel_get_name(channel));
 		switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
 		return SWITCH_STATUS_FALSE;
 	}
 
 	if (switch_core_codec_init
-		(&tech_pvt->write_codec, "L16", NULL, rate, globals.samples_per_frame / 8, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
-		 switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
+		(&tech_pvt->write_codec, "L16", NULL, rate, globals.samples_per_frame / 8, 1,
+		 SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s Cannot set read codec\n", switch_channel_get_name(channel));
 		switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
 		return SWITCH_STATUS_FALSE;
@@ -516,25 +515,25 @@
 	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);
 
-#ifdef DOTRACE	
-						tech_pvt->fd = open("/tmp/wp-in.raw", O_WRONLY | O_TRUNC | O_CREAT);
-						tech_pvt->fd2 = open("/tmp/wp-out.raw", O_WRONLY | O_TRUNC | O_CREAT);
+#ifdef DOTRACE
+	tech_pvt->fd = open("/tmp/wp-in.raw", O_WRONLY | O_TRUNC | O_CREAT);
+	tech_pvt->fd2 = open("/tmp/wp-out.raw", O_WRONLY | O_TRUNC | O_CREAT);
 #endif
 
 	/* Setup artificial DTMF stuff */
 	memset(&tech_pvt->tone_session, 0, sizeof(tech_pvt->tone_session));
 	teletone_init_session(&tech_pvt->tone_session, 1024, NULL, NULL);
-	
+
 	if (globals.debug) {
 		tech_pvt->tone_session.debug = globals.debug;
 		tech_pvt->tone_session.debug_stream = stdout;
 	}
-	
+
 	tech_pvt->tone_session.rate = rate;
 	tech_pvt->tone_session.duration = globals.dtmf_on * (tech_pvt->tone_session.rate / 1000);
 	tech_pvt->tone_session.wait = globals.dtmf_off * (tech_pvt->tone_session.rate / 1000);
-	
-	teletone_dtmf_detect_init (&tech_pvt->dtmf_detect, rate);
+
+	teletone_dtmf_detect_init(&tech_pvt->dtmf_detect, rate);
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Audio init %s\n", switch_channel_get_name(channel));
 
 	switch_set_flag(tech_pvt, TFLAG_CODEC);
@@ -563,46 +562,46 @@
 
 	tech_pvt->read_frame.data = tech_pvt->databuf;
 
-	if (tech_pvt->ss7boost_handle)  {
+	if (tech_pvt->ss7boost_handle) {
 		if (switch_channel_test_flag(channel, CF_OUTBOUND)) {
 			ss7boost_client_event_t event;
 
 			event.calling_number_presentation = tech_pvt->boost_pres;
 			event.trunk_group = tech_pvt->boost_trunk_group;
-		
+
 			switch_mutex_lock(tech_pvt->ss7boost_handle->mutex);
 			tech_pvt->setup_index = ++tech_pvt->ss7boost_handle->setup_index;
 			if (tech_pvt->ss7boost_handle->setup_index == SETUP_LEN - 1) {
 				tech_pvt->ss7boost_handle->setup_index = 0;
 			}
 			switch_mutex_unlock(tech_pvt->ss7boost_handle->mutex);
-		
+
 			switch_copy_string(tech_pvt->ss7boost_handle->setup_array[tech_pvt->setup_index],
-							   switch_core_session_get_uuid(session), 
-							   sizeof(tech_pvt->ss7boost_handle->setup_array[tech_pvt->setup_index]));
-		
-			
-			ss7boost_client_call_init(&event, tech_pvt->caller_profile->caller_id_number, tech_pvt->caller_profile->destination_number, tech_pvt->setup_index);
-			
+							   switch_core_session_get_uuid(session), sizeof(tech_pvt->ss7boost_handle->setup_array[tech_pvt->setup_index]));
+
+
+			ss7boost_client_call_init(&event, tech_pvt->caller_profile->caller_id_number, tech_pvt->caller_profile->destination_number,
+									  tech_pvt->setup_index);
+
 			if (ss7boost_client_connection_write(&tech_pvt->ss7boost_handle->mcon, &event) <= 0) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Critical System Error: Failed to tx on ISUP socket [%s]\n", strerror(errno));
 			}
-			
+
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Call Called Event TG=%d\n", tech_pvt->boost_trunk_group);
 			goto done;
 		}
-	} 
+	}
 
 	if ((status = wanpipe_codec_init(tech_pvt)) != SWITCH_STATUS_SUCCESS) {
 		switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
 		return status;
 	}
-	
+
 	if (switch_test_flag(tech_pvt, TFLAG_NOSIG)) {
 		switch_channel_mark_answered(channel);
 	}
 
- done:
+  done:
 
 	/* Move Channel's State Machine to RING */
 	switch_channel_set_state(channel, CS_RING);
@@ -622,7 +621,7 @@
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "WANPIPE RING\n");
 
-	
+
 
 	return SWITCH_STATUS_SUCCESS;
 }
@@ -633,7 +632,7 @@
 	switch_channel_t *channel = NULL;
 	struct channel_map *chanmap = NULL;
 
-	
+
 	channel = switch_core_session_get_channel(session);
 	assert(channel != NULL);
 
@@ -656,11 +655,7 @@
 		switch_mutex_unlock(tech_pvt->ss7boost_handle->mutex);
 		if (!switch_test_flag(tech_pvt, TFLAG_BYE)) {
 			isup_exec_command(tech_pvt->ss7boost_handle,
-							  tech_pvt->boost_span_number,
-							  tech_pvt->boost_chan_number,
-							  -1,
-							  SIGBOOST_EVENT_CALL_STOPPED,
-							  SIGBOOST_RELEASE_CAUSE_NORMAL);
+							  tech_pvt->boost_span_number, tech_pvt->boost_chan_number, -1, SIGBOOST_EVENT_CALL_STOPPED, SIGBOOST_RELEASE_CAUSE_NORMAL);
 		}
 	} else if (tech_pvt->spri) {
 		chanmap = tech_pvt->spri->private_info;
@@ -673,7 +668,7 @@
 		switch_mutex_lock(globals.channel_mutex);
 		*chanmap->map[tech_pvt->callno] = '\0';
 		switch_mutex_unlock(globals.channel_mutex);
-		
+
 	}
 
 	switch_set_flag_locked(tech_pvt, TFLAG_BYE);
@@ -681,7 +676,7 @@
 	teletone_destroy_session(&tech_pvt->tone_session);
 
 	switch_buffer_destroy(&tech_pvt->dtmf_buffer);
-	
+
 	return SWITCH_STATUS_SUCCESS;
 }
 
@@ -725,12 +720,7 @@
 			pri_answer(tech_pvt->spri->pri, tech_pvt->call, 0, 1);
 		}
 	} else if (tech_pvt->ss7boost_handle) {
-		isup_exec_command(tech_pvt->ss7boost_handle,
-						  tech_pvt->boost_span_number,
-						  tech_pvt->boost_chan_number,
-						  -1,
-						  SIGBOOST_EVENT_CALL_ANSWERED,
-						  0);
+		isup_exec_command(tech_pvt->ss7boost_handle, tech_pvt->boost_span_number, tech_pvt->boost_chan_number, -1, SIGBOOST_EVENT_CALL_ANSWERED, 0);
 	}
 
 	return SWITCH_STATUS_SUCCESS;
@@ -738,8 +728,7 @@
 
 
 
-static switch_status_t wanpipe_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout,
-										switch_io_flag_t flags, int stream_id)
+static switch_status_t wanpipe_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, switch_io_flag_t flags, int stream_id)
 {
 	private_object_t *tech_pvt;
 	switch_channel_t *channel = NULL;
@@ -772,8 +761,7 @@
 		}
 
 		if ((bread = sangoma_readmsg_socket(tech_pvt->wpsock->fd,
-										  &tech_pvt->hdrframe,
-										  sizeof(tech_pvt->hdrframe), bp, sizeof(tech_pvt->databuf) - bytes, 0)) < 0) {
+											&tech_pvt->hdrframe, sizeof(tech_pvt->hdrframe), bp, sizeof(tech_pvt->databuf) - bytes, 0)) < 0) {
 			if (errno == EBUSY) {
 				continue;
 			} else {
@@ -792,10 +780,10 @@
 	tech_pvt->read_frame.datalen = bytes;
 	tech_pvt->read_frame.samples = bytes / 2;
 
-	teletone_dtmf_detect (&tech_pvt->dtmf_detect, tech_pvt->read_frame.data, tech_pvt->read_frame.samples);
+	teletone_dtmf_detect(&tech_pvt->dtmf_detect, tech_pvt->read_frame.data, tech_pvt->read_frame.samples);
 	teletone_dtmf_get(&tech_pvt->dtmf_detect, digit_str, sizeof(digit_str));
-	
-	if(digit_str[0]) {
+
+	if (digit_str[0]) {
 		switch_channel_queue_dtmf(channel, digit_str);
 		if (globals.debug) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "DTMF DETECTED: [%s]\n", digit_str);
@@ -809,8 +797,7 @@
 		memset(tech_pvt->read_frame.data, 0, tech_pvt->read_frame.datalen);
 		tech_pvt->skip_read_frames--;
 	}
-
-#ifdef DOTRACE	
+#ifdef DOTRACE
 	write(tech_pvt->fd2, tech_pvt->read_frame.data, (int) tech_pvt->read_frame.datalen);
 #endif
 	//printf("read %d\n", tech_pvt->read_frame.datalen);
@@ -818,8 +805,7 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t wanpipe_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout,
-										 switch_io_flag_t flags, int stream_id)
+static switch_status_t wanpipe_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flags, int stream_id)
 {
 	private_object_t *tech_pvt;
 	uint32_t dtmf_blen;
@@ -836,25 +822,24 @@
 	if (tech_pvt->dtmf_buffer && (dtmf_blen = switch_buffer_inuse(tech_pvt->dtmf_buffer))) {
 		uint32_t len = dtmf_blen > frame->datalen ? frame->datalen : dtmf_blen;
 
-		switch_buffer_read(tech_pvt->dtmf_buffer, tech_pvt->auxbuf, len);		
+		switch_buffer_read(tech_pvt->dtmf_buffer, tech_pvt->auxbuf, len);
 		if (len < frame->datalen) {
 			uint8_t *data = frame->data;
 			memcpy(data + len, tech_pvt->auxbuf + len, frame->datalen - len);
 		}
-		data= tech_pvt->auxbuf;
-	} 
-	
+		data = tech_pvt->auxbuf;
+	}
+
 	if (tech_pvt->skip_write_frames) {
 		tech_pvt->skip_write_frames--;
 		return SWITCH_STATUS_SUCCESS;
 	}
-
 #ifdef DOTRACE
 	write(tech_pvt->fd, data, frame->datalen);
 #endif
 
 	result = sangoma_sendmsg_socket(tech_pvt->wpsock->fd, &tech_pvt->hdrframe, sizeof(tech_pvt->hdrframe), data, frame->datalen, 0);
-	
+
 	if (result < 0 && errno != EBUSY) {
 		return SWITCH_STATUS_GENERR;
 	}
@@ -886,13 +871,13 @@
 		}
 	}
 	for (cur = digits; *cur; cur++) {
-		if ((wrote = teletone_mux_tones(&tech_pvt->tone_session, &tech_pvt->tone_session.TONES[(int)*cur]))) {
+		if ((wrote = teletone_mux_tones(&tech_pvt->tone_session, &tech_pvt->tone_session.TONES[(int) *cur]))) {
 			switch_buffer_write(tech_pvt->dtmf_buffer, tech_pvt->tone_session.buffer, wrote * 2);
 		}
 	}
 
 	tech_pvt->skip_read_frames = 200;
-	
+
 	return status;
 }
 
@@ -903,7 +888,7 @@
 
 	channel = switch_core_session_get_channel(session);
 	assert(channel != NULL);
-			
+
 	tech_pvt = (private_object_t *) switch_core_session_get_private(session);
 	assert(tech_pvt != NULL);
 
@@ -945,7 +930,7 @@
 	tech_pvt = switch_core_session_get_private(session);
 	assert(tech_pvt != NULL);
 
-	switch(sig) {
+	switch (sig) {
 	case SWITCH_SIG_KILL:
 		switch_clear_flag_locked(tech_pvt, TFLAG_MEDIA);
 		break;
@@ -968,8 +953,8 @@
 	/*.kill_channel */ wanpipe_kill_channel,
 	/*.waitfor_read */ NULL,
 	/*.waitfor_read */ NULL,
-	/*.send_dtmf*/ wanpipe_send_dtmf,
-	/*.receive_message*/ wanpipe_receive_message
+	/*.send_dtmf */ wanpipe_send_dtmf,
+	/*.receive_message */ wanpipe_receive_message
 };
 
 static const switch_state_handler_table_t wanpipe_state_handlers = {
@@ -999,7 +984,8 @@
 };
 
 
-static switch_call_cause_t wanpipe_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile,
+static switch_call_cause_t wanpipe_outgoing_channel(switch_core_session_t *session,
+													switch_caller_profile_t *outbound_profile,
 													switch_core_session_t **new_session, switch_memory_pool_t **pool)
 {
 	char *bchan = NULL;
@@ -1008,7 +994,7 @@
 	char *dest;
 	int ready = 0, is_pri = 0, is_boost = 0, is_raw = 0;
 	switch_call_cause_t cause = SWITCH_CAUSE_SUCCESS;
-	
+
 	if (!outbound_profile) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Doh! no caller profile\n");
 		cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
@@ -1022,7 +1008,7 @@
 		cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
 		goto error;
 	}
-	
+
 	*dest++ = '\0';
 
 	if (!strcasecmp(protocol, "raw")) {
@@ -1041,7 +1027,7 @@
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error No SS7BOOST Spans Configured.\n");
 		}
 	}
-	
+
 	if (!ready) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Continue!\n");
 		cause = SWITCH_CAUSE_NETWORK_OUT_OF_ORDER;
@@ -1075,7 +1061,7 @@
 			goto error;
 		}
 
-		
+
 		caller_profile = switch_caller_profile_clone(*new_session, outbound_profile);
 
 		if (is_pri) {
@@ -1138,7 +1124,7 @@
 				}
 				switch_set_flag_locked(tech_pvt, TFLAG_NOSIG);
 				snprintf(name, sizeof(name), "wanpipe/%s/nosig", bchan);
-				switch_channel_set_name(channel, name);			
+				switch_channel_set_name(channel, name);
 				switch_channel_set_caller_profile(channel, caller_profile);
 			} else {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid address\n");
@@ -1160,18 +1146,18 @@
 
 				if (SPANS[span] && (spri = &SPANS[span]->spri) && switch_test_flag(spri, SANGOMA_PRI_READY)) {
 					chanmap = spri->private_info;
-						
+
 					if (autochan > 0) {
-						for(callno = 1; callno < SANGOMA_MAX_CHAN_PER_SPAN; callno++) {
-							if ((SPANS[span]->bchans & (1 << callno)) && ! *chanmap->map[callno]) {
+						for (callno = 1; callno < SANGOMA_MAX_CHAN_PER_SPAN; callno++) {
+							if ((SPANS[span]->bchans & (1 << callno)) && !*chanmap->map[callno]) {
 								switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Choosing channel s%dc%d\n", span, callno);
 								goto done;
 							}
 						}
 						callno = 0;
 					} else if (autochan < 0) {
-						for(callno = SANGOMA_MAX_CHAN_PER_SPAN; callno > 0; callno--) {
-							if ((SPANS[span]->bchans & (1 << callno)) && ! *chanmap->map[callno]) {
+						for (callno = SANGOMA_MAX_CHAN_PER_SPAN; callno > 0; callno--) {
+							if ((SPANS[span]->bchans & (1 << callno)) && !*chanmap->map[callno]) {
 								switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Choosing channel s%dc%d\n", span, callno);
 								goto done;
 							}
@@ -1186,7 +1172,7 @@
 					span--;
 				}
 			}
-		done:
+		  done:
 			switch_mutex_unlock(globals.channel_mutex);
 
 			if (!spri || callno == 0 || callno == (SANGOMA_MAX_CHAN_PER_SPAN)) {
@@ -1195,31 +1181,26 @@
 				cause = SWITCH_CAUSE_SWITCH_CONGESTION;
 				goto error;
 			}
-				
+
 			tech_pvt->callno = callno;
-				
+
 			if (spri && (tech_pvt->call = pri_new_call(spri->pri))) {
 				struct pri_sr *sr;
-					
+
 				snprintf(name, sizeof(name), "wanpipe/pri/s%dc%d/%s", spri->span, callno, caller_profile->destination_number);
-				switch_channel_set_name(channel, name);			
+				switch_channel_set_name(channel, name);
 				switch_channel_set_caller_profile(channel, caller_profile);
 				sr = pri_sr_new();
 				pri_sr_set_channel(sr, callno, 0, 0);
 				pri_sr_set_bearer(sr, 0, SPANS[span]->l1);
 				pri_sr_set_called(sr, caller_profile->destination_number, SPANS[span]->dp, 1);
 				pri_sr_set_caller(sr,
-								  caller_profile->caller_id_number,
-								  caller_profile->caller_id_name,
-								  SPANS[span]->dp,
+								  caller_profile->caller_id_number, caller_profile->caller_id_name, SPANS[span]->dp,
 								  PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN);
-				pri_sr_set_redirecting(sr,
-									   caller_profile->caller_id_number,
-									   SPANS[span]->dp,
-									   PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN,
+				pri_sr_set_redirecting(sr, caller_profile->caller_id_number, SPANS[span]->dp, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN,
 									   PRI_REDIR_UNCONDITIONAL);
-				
-				if (pri_setup(spri->pri, tech_pvt->call , sr)) {
+
+				if (pri_setup(spri->pri, tech_pvt->call, sr)) {
 					switch_core_session_destroy(new_session);
 					pri_sr_free(sr);
 					cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
@@ -1234,9 +1215,7 @@
 					goto error;
 				}
 				pri_sr_free(sr);
-				switch_copy_string(chanmap->map[callno],
-								   switch_core_session_get_uuid(*new_session),
-								   sizeof(chanmap->map[callno]));
+				switch_copy_string(chanmap->map[callno], switch_core_session_get_uuid(*new_session), sizeof(chanmap->map[callno]));
 				tech_pvt->spri = spri;
 			}
 		} else if (is_boost) {
@@ -1245,8 +1224,8 @@
 			if ((p = strchr(caller_profile->destination_number, '/'))) {
 				char *grp = caller_profile->destination_number;
 				*p = '\0';
-				caller_profile->destination_number = p+1;
-				tech_pvt->boost_trunk_group = atoi(grp+1) - 1;
+				caller_profile->destination_number = p + 1;
+				tech_pvt->boost_trunk_group = atoi(grp + 1) - 1;
 				if (tech_pvt->boost_trunk_group < 0) {
 					tech_pvt->boost_trunk_group = 0;
 				}
@@ -1269,7 +1248,7 @@
 		cause = SWITCH_CAUSE_SUCCESS;
 	}
 
- error:
+  error:
 	switch_safe_free(protocol);
 	return cause;
 }
@@ -1331,7 +1310,7 @@
 
 /*event Handlers */
 
-static int on_info(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *pevent)
+static int on_info(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent)
 {
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "number is: %s\n", pevent->ring.callednum);
 	if (strlen(pevent->ring.callednum) > 3) {
@@ -1341,7 +1320,7 @@
 	return 0;
 }
 
-static int on_hangup(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *pevent)
+static int on_hangup(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent)
 {
 	struct channel_map *chanmap;
 	switch_core_session_t *session;
@@ -1364,7 +1343,7 @@
 		tech_pvt->cause = pevent->hangup.cause;
 		switch_set_flag_locked(tech_pvt, TFLAG_BYE);
 		switch_channel_hangup(channel, tech_pvt->cause);
-		
+
 		switch_mutex_lock(globals.channel_mutex);
 		*chanmap->map[pevent->hangup.channel] = '\0';
 		switch_mutex_unlock(globals.channel_mutex);
@@ -1376,7 +1355,7 @@
 	return 0;
 }
 
-static int on_answer(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *pevent)
+static int on_answer(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent)
 {
 	switch_core_session_t *session;
 	switch_channel_t *channel;
@@ -1394,12 +1373,12 @@
 	} else {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "-- Answer on channel s%dc%d but it's not in use?\n", spri->span, pevent->answer.channel);
 	}
-	
+
 	return 0;
 }
 
 
-static int on_proceed(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *pevent)
+static int on_proceed(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent)
 {
 	switch_core_session_t *session;
 	switch_channel_t *channel;
@@ -1411,10 +1390,10 @@
 		switch_core_session_message_t *msg;
 
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "-- Proceeding on channel s%dc%d\n", spri->span, pevent->proceeding.channel);
-		
+
 		channel = switch_core_session_get_channel(session);
 		assert(channel != NULL);
-		
+
 		if ((msg = malloc(sizeof(*msg)))) {
 			memset(msg, 0, sizeof(*msg));
 			msg->message_id = SWITCH_MESSAGE_INDICATE_PROGRESS;
@@ -1425,18 +1404,18 @@
 		} else {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
 		}
-		
+
 		switch_core_session_rwunlock(session);
 	} else {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "-- Proceeding on channel s%dc%d but it's not in use?\n", 
-						  spri->span, pevent->proceeding.channel);
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE,
+						  "-- Proceeding on channel s%dc%d but it's not in use?\n", spri->span, pevent->proceeding.channel);
 	}
 
 	return 0;
 }
 
 
-static int on_ringing(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *pevent)
+static int on_ringing(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent)
 {
 	switch_core_session_t *session;
 	switch_channel_t *channel;
@@ -1455,34 +1434,35 @@
 
 		switch_core_session_rwunlock(session);
 	} else {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "-- Ringing on channel s%dc%d %s but it's not in use?\n", spri->span, pevent->ringing.channel, chanmap->map[pevent->ringing.channel]);
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
+						  "-- Ringing on channel s%dc%d %s but it's not in use?\n", spri->span, pevent->ringing.channel,
+						  chanmap->map[pevent->ringing.channel]);
 	}
 
 	return 0;
 }
 
 
-static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *pevent)
+static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent)
 {
 	char name[128];
 	switch_core_session_t *session;
 	switch_channel_t *channel;
 	struct channel_map *chanmap;
 	int ret = 0;
-	
+
 	switch_mutex_lock(globals.channel_mutex);
 
 	chanmap = spri->private_info;
 	if (switch_core_session_locate(chanmap->map[pevent->ring.channel])) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "--Duplicate Ring on channel s%dc%d (ignored)\n",
-							  spri->span, pevent->ring.channel);
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "--Duplicate Ring on channel s%dc%d (ignored)\n", spri->span, pevent->ring.channel);
 		switch_core_session_rwunlock(session);
 		ret = 0;
 		goto done;
 	}
 
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "-- Ring on channel s%dc%d (from %s to %s)\n", spri->span, pevent->ring.channel,
-						  pevent->ring.callingnum, pevent->ring.callednum);
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "-- Ring on channel s%dc%d (from %s to %s)\n", spri->span,
+					  pevent->ring.channel, pevent->ring.callingnum, pevent->ring.callednum);
 
 
 	pri_proceeding(spri->pri, pevent->ring.call, pevent->ring.channel, 0);
@@ -1514,21 +1494,14 @@
 		}
 
 		if ((tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
-																  NULL,
-																  globals.dialplan,
-																  "FreeSWITCH",
-																  pevent->ring.callingnum,
+																  NULL, globals.dialplan, "FreeSWITCH", pevent->ring.callingnum,
 #ifdef WIN32
 																  NULL,
 #else
 																  pevent->ring.callingani,
 #endif
 																  switch_strlen_zero(ani2str) ? NULL : ani2str,
-																  NULL,
-																  NULL,
-																  (char *)modname,
-																  NULL,
-																  pevent->ring.callednum))) {
+																  NULL, NULL, (char *) modname, NULL, pevent->ring.callednum))) {
 			switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
 		}
 
@@ -1539,7 +1512,7 @@
 		if (!tech_pvt->call) {
 			tech_pvt->call = pevent->ring.call;
 		}
-		
+
 		tech_pvt->callno = pevent->ring.channel;
 		tech_pvt->span = spri->span;
 
@@ -1548,16 +1521,16 @@
 		}
 
 		switch_copy_string(chanmap->map[pevent->ring.channel], switch_core_session_get_uuid(session), sizeof(chanmap->map[pevent->ring.channel]));
-		
+
 		switch_channel_set_state(channel, CS_INIT);
 		switch_core_session_thread_launch(session);
 	} else {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Create new Inbound Channel!\n");
 	}
 
- done:
+  done:
 	switch_mutex_unlock(globals.channel_mutex);
-	
+
 	return ret;
 }
 
@@ -1567,7 +1540,7 @@
 	return 0;
 }
 
-static int on_restart(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *pevent)
+static int on_restart(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent)
 {
 	switch_core_session_t *session;
 	struct channel_map *chanmap;
@@ -1581,7 +1554,7 @@
 
 
 	chanmap = spri->private_info;
-	
+
 	if ((session = switch_core_session_locate(chanmap->map[pevent->restart.channel]))) {
 		switch_channel_t *channel;
 		channel = switch_core_session_get_channel(session);
@@ -1589,13 +1562,13 @@
 		switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
 		switch_core_session_rwunlock(session);
 	}
-	
+
 	wp_restart(spri->span, pevent->restart.channel);
 
 	return 0;
 }
 
-static int on_dchan_up(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *pevent)
+static int on_dchan_up(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent)
 {
 
 	if (!switch_test_flag(spri, SANGOMA_PRI_READY)) {
@@ -1606,27 +1579,26 @@
 	return 0;
 }
 
-static int on_dchan_down(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *pevent)
+static int on_dchan_down(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent)
 {
 
 	if (switch_test_flag(spri, SANGOMA_PRI_READY)) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Span %d D-Chan DOWN!\n", spri->span);
 		switch_clear_flag(spri, SANGOMA_PRI_READY);
 	}
-	
+
 	return 0;
 }
 
-static int on_anything(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *pevent)
+static int on_anything(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent)
 {
 
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Caught Event span %d %u (%s)\n", spri->span, event_type,
-						  sangoma_pri_event_str(event_type));
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Caught Event span %d %u (%s)\n", spri->span, event_type, sangoma_pri_event_str(event_type));
 	return 0;
 }
 
 
-static void *SWITCH_THREAD_FUNC pri_thread_run(switch_thread_t *thread, void *obj)
+static void *SWITCH_THREAD_FUNC pri_thread_run(switch_thread_t * thread, void *obj)
 {
 	struct sangoma_pri *spri = obj;
 	struct channel_map chanmap;
@@ -1665,7 +1637,7 @@
 {
 	switch_thread_t *thread;
 	switch_threadattr_t *thd_attr = NULL;
-	
+
 	switch_threadattr_create(&thd_attr, module_pool);
 	switch_threadattr_detach_set(thd_attr, 1);
 	switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
@@ -1674,7 +1646,7 @@
 }
 
 
-static int isup_exec_command(ss7boost_handle_t *ss7boost_handle, int span, int chan, int id, int cmd, int cause)
+static int isup_exec_command(ss7boost_handle_t * ss7boost_handle, int span, int chan, int id, int cmd, int cause)
 {
 	ss7boost_client_event_t oevent;
 	int r = 0;
@@ -1682,12 +1654,12 @@
 	switch_mutex_lock(ss7boost_handle->mutex);
 	ss7boost_client_event_init(&oevent, cmd, chan, span);
 	oevent.release_cause = cause;
-	
+
 	if (id >= 0) {
 		oevent.call_setup_id = id;
 	}
-	
-	if (ss7boost_client_connection_write(&ss7boost_handle->mcon, &oevent) <= 0){
+
+	if (ss7boost_client_connection_write(&ss7boost_handle->mcon, &oevent) <= 0) {
 		r = -1;
 	}
 
@@ -1699,26 +1671,26 @@
 #ifdef USE_WAITFOR_SOCKET
 static int waitfor_socket(int fd, int timeout, int flags)
 {
-    struct pollfd pfds[1];
-    int res;
- 
-    memset(&pfds[0], 0, sizeof(pfds[0]));
-    pfds[0].fd = fd;
-    pfds[0].events = flags;
-    res = poll(pfds, 1, timeout);
-
-    if (res > 0) {
-	if(pfds[0].revents & POLLIN) {
-		res = 1;
-	} else if ((pfds[0].revents & POLLERR)) {
-		res = -1;
-    	} else {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,"System Error: Poll Event Error no event!\n");
-		res = -1;
+	struct pollfd pfds[1];
+	int res;
+
+	memset(&pfds[0], 0, sizeof(pfds[0]));
+	pfds[0].fd = fd;
+	pfds[0].events = flags;
+	res = poll(pfds, 1, timeout);
+
+	if (res > 0) {
+		if (pfds[0].revents & POLLIN) {
+			res = 1;
+		} else if ((pfds[0].revents & POLLERR)) {
+			res = -1;
+		} else {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "System Error: Poll Event Error no event!\n");
+			res = -1;
+		}
 	}
-    }
 
-    return res;
+	return res;
 }
 #endif
 
@@ -1736,7 +1708,7 @@
 }
 
 
-static void handle_call_stop(ss7boost_handle_t *ss7boost_handle, ss7boost_client_event_t *event)
+static void handle_call_stop(ss7boost_handle_t * ss7boost_handle, ss7boost_client_event_t * event)
 {
 	char *uuid = ss7boost_handle->span_chanmap[event->span].map[event->chan];
 
@@ -1746,7 +1718,7 @@
 		if ((session = switch_core_session_locate(uuid))) {
 			private_object_t *tech_pvt;
 			switch_channel_t *channel;
-	
+
 			channel = switch_core_session_get_channel(session);
 			assert(channel != NULL);
 
@@ -1758,35 +1730,25 @@
 		}
 		*uuid = '\0';
 
-	} 
+	}
 
-	isup_exec_command(ss7boost_handle,
-					  event->span, 
-					  event->chan, 
-					  -1,
-					  SIGBOOST_EVENT_CALL_STOPPED_ACK,
-					  0);
+	isup_exec_command(ss7boost_handle, event->span, event->chan, -1, SIGBOOST_EVENT_CALL_STOPPED_ACK, 0);
 
 
 }
 
-static void handle_call_start(ss7boost_handle_t *ss7boost_handle, ss7boost_client_event_t *event)
+static void handle_call_start(ss7boost_handle_t * ss7boost_handle, ss7boost_client_event_t * event)
 {
 	switch_core_session_t *session = NULL;
 	switch_channel_t *channel = NULL;
 	char name[128];
 
 	if (*ss7boost_handle->span_chanmap[event->span].map[event->chan]) {
-		isup_exec_command(ss7boost_handle,
-						  event->span, 
-						  event->chan, 
-						  -1,
-						  SIGBOOST_EVENT_CALL_START_NACK,
-						  SIGBOOST_RELEASE_CAUSE_BUSY);		
+		isup_exec_command(ss7boost_handle, event->span, event->chan, -1, SIGBOOST_EVENT_CALL_START_NACK, SIGBOOST_RELEASE_CAUSE_BUSY);
 		return;
 	}
 
-	
+
 	if ((session = switch_core_session_request(&wanpipe_endpoint_interface, NULL))) {
 		private_object_t *tech_pvt;
 
@@ -1796,7 +1758,7 @@
 			switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
 			channel = switch_core_session_get_channel(session);
 			switch_core_session_set_private(session, tech_pvt);
-			sprintf(name, "wanpipe/ss7boost/s%dc%d", event->span+1, event->chan+1);
+			sprintf(name, "wanpipe/ss7boost/s%dc%d", event->span + 1, event->chan + 1);
 			switch_channel_set_name(channel, name);
 			tech_pvt->session = session;
 		} else {
@@ -1806,21 +1768,13 @@
 
 
 		if ((tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
-																  NULL,
-																  globals.dialplan,
-																  "FreeSWITCH(boost)",
-																  (char *)event->calling_number_digits,
+																  NULL, globals.dialplan, "FreeSWITCH(boost)", (char *) event->calling_number_digits,
 #ifdef WIN32
 																  NULL,
 #else
-																  (char *)event->calling_number_digits,
+																  (char *) event->calling_number_digits,
 #endif
-																  NULL,
-																  NULL,
-																  NULL,
-																  (char *)modname,
-																  NULL,
-																  (char *)event->called_number_digits))) {
+																  NULL, NULL, NULL, (char *) modname, NULL, (char *) event->called_number_digits))) {
 			switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
 		}
 
@@ -1832,88 +1786,73 @@
 		tech_pvt->boost_span_number = event->span;
 		tech_pvt->boost_chan_number = event->chan;
 		tech_pvt->boost_pres = event->calling_number_presentation;
-		
-		if (!wp_open(tech_pvt, event->span+1, event->chan+1)) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open channel %d:%d\n", event->span+1, event->chan+1);
+
+		if (!wp_open(tech_pvt, event->span + 1, event->chan + 1)) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open channel %d:%d\n", event->span + 1, event->chan + 1);
 			goto fail;
 		}
 
-		switch_copy_string(ss7boost_handle->span_chanmap[event->span].map[event->chan], switch_core_session_get_uuid(session), 
-						   sizeof(ss7boost_handle->span_chanmap[event->span].map[event->chan]));
-		
+		switch_copy_string(ss7boost_handle->span_chanmap[event->span].map[event->chan],
+						   switch_core_session_get_uuid(session), sizeof(ss7boost_handle->span_chanmap[event->span].map[event->chan]));
+
 		switch_channel_set_state(channel, CS_INIT);
-		isup_exec_command(ss7boost_handle,
-						  event->span, 
-						  event->chan, 
-						  -1,
-						  SIGBOOST_EVENT_CALL_START_ACK,
-						  0);
+		isup_exec_command(ss7boost_handle, event->span, event->chan, -1, SIGBOOST_EVENT_CALL_START_ACK, 0);
 		switch_core_session_thread_launch(session);
 		return;
 	} else {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Create new Inbound Channel!\n");
 	}
 
-	
- fail:
+
+  fail:
 	if (session) {
 		switch_core_session_destroy(&session);
 	}
 
-	isup_exec_command(ss7boost_handle,
-					  event->span, 
-					  event->chan, 
-					  -1,
-					  SIGBOOST_EVENT_CALL_STOPPED,
-					  SIGBOOST_RELEASE_CAUSE_BUSY);
+	isup_exec_command(ss7boost_handle, event->span, event->chan, -1, SIGBOOST_EVENT_CALL_STOPPED, SIGBOOST_RELEASE_CAUSE_BUSY);
 
 }
 
 
-static void handle_heartbeat(ss7boost_handle_t *ss7boost_handle, ss7boost_client_event_t *event)
+static void handle_heartbeat(ss7boost_handle_t * ss7boost_handle, ss7boost_client_event_t * event)
 {
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Heartbeat!\n");
 
-	isup_exec_command(ss7boost_handle,
-					  event->span, 
-					  event->chan, 
-					  -1,
-					  SIGBOOST_EVENT_HEARTBEAT,
-					  0);
+	isup_exec_command(ss7boost_handle, event->span, event->chan, -1, SIGBOOST_EVENT_HEARTBEAT, 0);
 }
 
 
-static void handle_call_start_ack(ss7boost_handle_t *ss7boost_handle, ss7boost_client_event_t *event)
+static void handle_call_start_ack(ss7boost_handle_t * ss7boost_handle, ss7boost_client_event_t * event)
 {
 	char *uuid = ss7boost_handle->setup_array[event->call_setup_id];
-	
+
 	if (*uuid) {
 		switch_core_session_t *session;
 
 		if ((session = switch_core_session_locate(uuid))) {
 			private_object_t *tech_pvt;
 			switch_channel_t *channel;
-	
+
 			channel = switch_core_session_get_channel(session);
 			assert(channel != NULL);
-			
+
 			tech_pvt = switch_core_session_get_private(session);
 			assert(tech_pvt != NULL);
-			
+
 			tech_pvt->ss7boost_handle = ss7boost_handle;
 			tech_pvt->boost_span_number = event->span;
 			tech_pvt->boost_chan_number = event->chan;
-			
-			switch_copy_string(ss7boost_handle->span_chanmap[event->span].map[event->chan], switch_core_session_get_uuid(session), 
-							   sizeof(ss7boost_handle->span_chanmap[event->span].map[event->chan]));
+
+			switch_copy_string(ss7boost_handle->span_chanmap[event->span].map[event->chan],
+							   switch_core_session_get_uuid(session), sizeof(ss7boost_handle->span_chanmap[event->span].map[event->chan]));
 
 
 
 			if (!tech_pvt->wpsock) {
-				if (!wp_open(tech_pvt, tech_pvt->boost_span_number+1, tech_pvt->boost_chan_number+1)) {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open fd for s%dc%d! [%s]\n", 
-									  tech_pvt->boost_span_number+1, tech_pvt->boost_chan_number+1, strerror(errno));
+				if (!wp_open(tech_pvt, tech_pvt->boost_span_number + 1, tech_pvt->boost_chan_number + 1)) {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open fd for s%dc%d! [%s]\n",
+									  tech_pvt->boost_span_number + 1, tech_pvt->boost_chan_number + 1, strerror(errno));
 					switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
 					return;
 				}
@@ -1924,29 +1863,29 @@
 			}
 
 			switch_channel_mark_pre_answered(channel);
-			
+
 			switch_core_session_rwunlock(session);
 		}
 		*uuid = '\0';
 	}
 }
 
-static void handle_call_start_nack_ack(ss7boost_handle_t *ss7boost_handle, ss7boost_client_event_t *event)
+static void handle_call_start_nack_ack(ss7boost_handle_t * ss7boost_handle, ss7boost_client_event_t * event)
 {
 	// WTF IS THIS! ?
 }
 
-static void handle_call_answer(ss7boost_handle_t *ss7boost_handle, ss7boost_client_event_t *event)
+static void handle_call_answer(ss7boost_handle_t * ss7boost_handle, ss7boost_client_event_t * event)
 {
 	char *uuid = ss7boost_handle->span_chanmap[event->span].map[event->chan];
 
 	if (*uuid) {
 		switch_core_session_t *session;
-		
+
 		if ((session = switch_core_session_locate(uuid))) {
 			private_object_t *tech_pvt;
 			switch_channel_t *channel;
-	
+
 			channel = switch_core_session_get_channel(session);
 			assert(channel != NULL);
 
@@ -1954,9 +1893,9 @@
 			assert(tech_pvt != NULL);
 
 			if (!tech_pvt->wpsock) {
-				if (!wp_open(tech_pvt, tech_pvt->boost_span_number+1, tech_pvt->boost_chan_number+1)) {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open fd for s%dc%d! [%s]\n", 
-									  tech_pvt->boost_span_number+1, tech_pvt->boost_chan_number+1, strerror(errno));
+				if (!wp_open(tech_pvt, tech_pvt->boost_span_number + 1, tech_pvt->boost_chan_number + 1)) {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open fd for s%dc%d! [%s]\n",
+									  tech_pvt->boost_span_number + 1, tech_pvt->boost_chan_number + 1, strerror(errno));
 					switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
 					return;
 				}
@@ -1965,7 +1904,7 @@
 					return;
 				}
 			}
-			
+
 			switch_channel_mark_answered(channel);
 			switch_core_session_rwunlock(session);
 		} else {
@@ -1978,41 +1917,36 @@
 	}
 }
 
-static void handle_call_stop_ack(ss7boost_handle_t *ss7boost_handle, ss7boost_client_event_t *event)
+static void handle_call_stop_ack(ss7boost_handle_t * ss7boost_handle, ss7boost_client_event_t * event)
 {
 	// TODO anything here?
 }
 
 
-static void handle_call_start_nack(ss7boost_handle_t *ss7boost_handle, ss7boost_client_event_t *event)
+static void handle_call_start_nack(ss7boost_handle_t * ss7boost_handle, ss7boost_client_event_t * event)
 {
 	char *uuid = ss7boost_handle->setup_array[event->call_setup_id];
-	
+
 	if (*uuid) {
 		switch_core_session_t *session;
 
 		if ((session = switch_core_session_locate(uuid))) {
 			private_object_t *tech_pvt;
 			switch_channel_t *channel;
-	
+
 			channel = switch_core_session_get_channel(session);
 			assert(channel != NULL);
-			
+
 			tech_pvt = switch_core_session_get_private(session);
 			assert(tech_pvt != NULL);
-			
+
 			tech_pvt->ss7boost_handle = ss7boost_handle;
 			tech_pvt->boost_span_number = event->span;
 			tech_pvt->boost_chan_number = event->chan;
-			
+
 			switch_channel_hangup(channel, event->release_cause);
-			
-			isup_exec_command(ss7boost_handle,
-							  event->span,
-							  event->chan, 
-							  event->call_setup_id,
-							  SIGBOOST_EVENT_CALL_START_NACK_ACK,
-							  0);
+
+			isup_exec_command(ss7boost_handle, event->span, event->chan, event->call_setup_id, SIGBOOST_EVENT_CALL_START_NACK_ACK, 0);
 
 			switch_core_session_rwunlock(session);
 		} else {
@@ -2022,14 +1956,14 @@
 	}
 }
 
-static int parse_ss7_event(ss7boost_handle_t *ss7boost_handle, ss7boost_client_event_t *event)
+static int parse_ss7_event(ss7boost_handle_t * ss7boost_handle, ss7boost_client_event_t * event)
 {
 	int ret = 0;
 
 	switch_mutex_lock(ss7boost_handle->mutex);
-		
-	validate_number((unsigned char*)event->called_number_digits);
-	validate_number((unsigned char*)event->calling_number_digits);
+
+	validate_number((unsigned char *) event->called_number_digits);
+	validate_number((unsigned char *) event->calling_number_digits);
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
 					  "\nRX EVENT\n"
@@ -2048,21 +1982,16 @@
 					  "\n",
 					  ss7boost_client_event_id_name(event->event_id),
 					  event->event_id,
-					  event->span+1,
-					  event->chan+1,
+					  event->span + 1,
+					  event->chan + 1,
 					  (event->called_number_digits_count ? (char *) event->called_number_digits : "N/A"),
 					  (event->calling_number_digits_count ? (char *) event->calling_number_digits : "N/A"),
-					  switch_channel_cause2str(event->release_cause),
-					  event->span+1,
-					  event->chan+1,
-					  event->event_id,
-					  event->call_setup_id,
-					  event->seqno
-					  );
-	
+					  switch_channel_cause2str(event->release_cause), event->span + 1, event->chan + 1, event->event_id, event->call_setup_id,
+					  event->seqno);
+
+
+	switch (event->event_id) {
 
-	switch(event->event_id) {
-	
 	case SIGBOOST_EVENT_CALL_START:
 		handle_call_start(ss7boost_handle, event);
 		break;
@@ -2088,7 +2017,7 @@
 		handle_call_stop_ack(ss7boost_handle, event);
 		break;
 	default:
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Warning no handler implemented for [%s]\n", 
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Warning no handler implemented for [%s]\n",
 						  ss7boost_client_event_id_name(event->event_id));
 		break;
 	}
@@ -2096,48 +2025,40 @@
 	return ret;
 }
 
-static void *SWITCH_THREAD_FUNC boost_thread_run(switch_thread_t *thread, void *obj)
+static void *SWITCH_THREAD_FUNC boost_thread_run(switch_thread_t * thread, void *obj)
 {
 	ss7boost_handle_t *ss7boost_handle = (ss7boost_handle_t *) obj;
 	ss7boost_client_event_t *event;
 
 	if (ss7boost_client_connection_open(&ss7boost_handle->mcon,
-									ss7boost_handle->local_ip, 
-									ss7boost_handle->local_port,
-									ss7boost_handle->remote_ip,
-									ss7boost_handle->remote_port,
-									module_pool) != SWITCH_STATUS_SUCCESS) {
+										ss7boost_handle->local_ip,
+										ss7boost_handle->local_port,
+										ss7boost_handle->remote_ip, ss7boost_handle->remote_port, module_pool) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "FATAL ERROR CREATING CLIENT CONNECTION\n");
 		return NULL;
 	}
-			
-	isup_exec_command(ss7boost_handle,
-					  0,
-					  0, 
-					  -1,
-					  SIGBOOST_EVENT_SYSTEM_RESTART,
-					  0);
-	
-	
+
+	isup_exec_command(ss7boost_handle, 0, 0, -1, SIGBOOST_EVENT_SYSTEM_RESTART, 0);
+
+
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Monitor Thread Started\n");
-	
+
 	switch_mutex_lock(globals.hash_mutex);
 	globals.configured_boost_spans++;
 	switch_mutex_unlock(globals.hash_mutex);
 
 	globals.ss7boost_handle = ss7boost_handle;
-	
-	for(;;) {
+
+	for (;;) {
 		if (ss7boost_client_connection_read(&ss7boost_handle->mcon, &event) == SWITCH_STATUS_SUCCESS) {
-				struct timeval current;
-				struct timeval difftime;
-				gettimeofday(&current,NULL);
-				timersub (&current, &event->tv, &difftime);
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Socket Event [%s] T=%d:%d\n",
-								  ss7boost_client_event_id_name(event->event_id),
-								  (int)difftime.tv_sec, (int)difftime.tv_usec);
-				
-				parse_ss7_event(ss7boost_handle, event);
+			struct timeval current;
+			struct timeval difftime;
+			gettimeofday(&current, NULL);
+			timersub(&current, &event->tv, &difftime);
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Socket Event [%s] T=%d:%d\n",
+							  ss7boost_client_event_id_name(event->event_id), (int) difftime.tv_sec, (int) difftime.tv_usec);
+
+			parse_ss7_event(ss7boost_handle, event);
 		} else {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error: Reading from Boost Socket! %s\n", strerror(errno));
 			break;
@@ -2146,17 +2067,17 @@
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Close udp socket\n");
 	ss7boost_client_connection_close(&ss7boost_handle->mcon);
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Monitor Thread Ended\n");	
-	
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Monitor Thread Ended\n");
+
 
 	return NULL;
 }
 
-static void launch_ss7boost_handle(ss7boost_handle_t *ss7boost_handle)
+static void launch_ss7boost_handle(ss7boost_handle_t * ss7boost_handle)
 {
 	switch_thread_t *thread;
 	switch_threadattr_t *thd_attr = NULL;
-	
+
 	switch_threadattr_create(&thd_attr, module_pool);
 	switch_threadattr_detach_set(thd_attr, 1);
 	switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
@@ -2213,7 +2134,7 @@
 		for (param = switch_xml_child(span, "param"); param; param = param->next) {
 			char *var = (char *) switch_xml_attr_soft(param, "name");
 			char *val = (char *) switch_xml_attr_soft(param, "value");
-			
+
 			if (!strcasecmp(var, "local-ip")) {
 				local_ip = val;
 			} else if (!strcasecmp(var, "local-port")) {
@@ -2244,7 +2165,7 @@
 	}
 
 	analog_channels = switch_xml_child(cfg, "analog_channels");
-	for(channel = switch_xml_child(analog_channels, "channel"); channel; channel = channel->next) {
+	for (channel = switch_xml_child(analog_channels, "channel"); channel; channel = channel->next) {
 		char *c_type = (char *) switch_xml_attr(channel, "type");
 		char *c_dev = (char *) switch_xml_attr(channel, "device");
 		char *user = NULL;
@@ -2254,7 +2175,7 @@
 		analog_type_t a_type = ANALOG_TYPE_UNKNOWN;
 		wpsock_t *sock;
 		int chan, span;
-		
+
 		if (!c_type) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing required attribute 'type'\n");
 			continue;
@@ -2278,16 +2199,16 @@
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid device name '%s'\n", c_dev);
 			continue;
 		}
-		
+
 		if (!(sock = wp_open(NULL, span, chan))) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot open device '%s' (%s)\n", c_dev, strerror(errno));
 			continue;
 		}
 
 		for (param = switch_xml_child(channel, "param"); param; param = param->next) {
-            char *var = (char *) switch_xml_attr_soft(param, "name");
-            char *val = (char *) switch_xml_attr_soft(param, "value");
-			
+			char *var = (char *) switch_xml_attr_soft(param, "name");
+			char *val = (char *) switch_xml_attr_soft(param, "value");
+
 			if (!strcasecmp(var, "user")) {
 				user = var;
 			} else if (!strcasecmp(var, "domain")) {
@@ -2313,7 +2234,7 @@
 		if (cid_num) {
 			alc->cid_name = strdup(cid_num);
 		}
-		
+
 		alc->a_type = a_type;
 		alc->sock = sock;
 		alc->chan = chan;
@@ -2330,7 +2251,7 @@
 	if (globals.fxs_index) {
 		switch_thread_t *thread;
 		switch_threadattr_t *thd_attr = NULL;
-	
+
 		switch_threadattr_create(&thd_attr, module_pool);
 		switch_threadattr_detach_set(thd_attr, 1);
 		switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
@@ -2345,10 +2266,10 @@
 		int32_t i = 0;
 
 		current_span = 0;
-		
+
 		if (id) {
 			char *p;
-			
+
 			min_span = atoi(id);
 			if ((p = strchr(id, '-'))) {
 				p++;
@@ -2364,16 +2285,16 @@
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Missing SPAN ID!\n");
 			continue;
 		}
-		
+
 		for (i = min_span; i <= max_span; i++) {
 			current_span = i;
-			
+
 			if (current_span <= 0 || current_span > MAX_SPANS) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid SPAN %d!\n", current_span);
 				current_span = 0;
 				continue;
 			}
-			
+
 			if (!SPANS[current_span]) {
 				if (!(SPANS[current_span] = switch_core_alloc(module_pool, sizeof(*SPANS[current_span])))) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "MEMORY ERROR\n");
@@ -2381,12 +2302,12 @@
 				}
 				SPANS[current_span]->span = current_span;
 			}
-			
+
 
 			for (param = switch_xml_child(span, "param"); param; param = param->next) {
 				char *var = (char *) switch_xml_attr_soft(param, "name");
 				char *val = (char *) switch_xml_attr_soft(param, "value");
-			
+
 				if (!strcmp(var, "dchan")) {
 					SPANS[current_span]->dchan = atoi(val);
 				} else if (!strcmp(var, "bchan")) {
@@ -2399,7 +2320,7 @@
 						fromi = atoi(from);
 						toi = atoi(to);
 						if (fromi > 0 && toi > 0 && fromi < toi && fromi < MAX_SPANS && toi < MAX_SPANS) {
-							for(x = fromi; x <= toi; x++) {
+							for (x = fromi; x <= toi; x++) {
 								SPANS[current_span]->bchans |= (1 << x);
 							}
 						} else {
@@ -2433,18 +2354,14 @@
 
 
 	globals.configured_spans = 0;
-	for(current_span = 1; current_span < MAX_SPANS; current_span++) {
+	for (current_span = 1; current_span < MAX_SPANS; current_span++) {
 		if (SPANS[current_span]) {
 
 			if (!SPANS[current_span]->l1) {
 				SPANS[current_span]->l1 = PRI_LAYER_1_ULAW;
 			}
 			if (sangoma_init_pri(&SPANS[current_span]->spri,
-								 current_span,
-								 SPANS[current_span]->dchan,
-								 SPANS[current_span]->pswitch,
-								 SPANS[current_span]->node,
-								 globals.debug)) {
+								 current_span, SPANS[current_span]->dchan, SPANS[current_span]->pswitch, SPANS[current_span]->node, globals.debug)) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cannot launch span %d\n", current_span);
 				continue;
 			}
@@ -2461,6 +2378,3 @@
 	return SWITCH_STATUS_SUCCESS;
 
 }
-
-
-

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/sigboost.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/sigboost.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/sigboost.h	Fri Mar 30 12:19:18 2007
@@ -16,38 +16,35 @@
 
 #include <stdint.h>
 
-enum	e_sigboost_event_id_values
-{
-	SIGBOOST_EVENT_CALL_START			= 0x80, /*128*/
-	SIGBOOST_EVENT_CALL_START_ACK			= 0x81, /*129*/
-	SIGBOOST_EVENT_CALL_START_NACK			= 0x82, /*130*/
-	SIGBOOST_EVENT_CALL_START_NACK_ACK		= 0x83, /*131*/
-	SIGBOOST_EVENT_CALL_ANSWERED			= 0x84, /*132*/
-	SIGBOOST_EVENT_CALL_STOPPED			= 0x85, /*133*/
-	SIGBOOST_EVENT_CALL_STOPPED_ACK			= 0x86, /*134*/
-	SIGBOOST_EVENT_SYSTEM_RESTART			= 0x87, /*135*/
-	SIGBOOST_EVENT_HEARTBEAT			= 0x88, /*136*/
+enum e_sigboost_event_id_values {
+	SIGBOOST_EVENT_CALL_START = 0x80,	/*128 */
+	SIGBOOST_EVENT_CALL_START_ACK = 0x81,	/*129 */
+	SIGBOOST_EVENT_CALL_START_NACK = 0x82,	/*130 */
+	SIGBOOST_EVENT_CALL_START_NACK_ACK = 0x83,	/*131 */
+	SIGBOOST_EVENT_CALL_ANSWERED = 0x84,	/*132 */
+	SIGBOOST_EVENT_CALL_STOPPED = 0x85,	/*133 */
+	SIGBOOST_EVENT_CALL_STOPPED_ACK = 0x86,	/*134 */
+	SIGBOOST_EVENT_SYSTEM_RESTART = 0x87,	/*135 */
+	SIGBOOST_EVENT_HEARTBEAT = 0x88,	/*136 */
 };
 
-enum	e_sigboost_release_cause_values
-{
-	SIGBOOST_RELEASE_CAUSE_UNDEFINED		= 0x00,
-	SIGBOOST_RELEASE_CAUSE_NORMAL			= 0x90,
-	SIGBOOST_RELEASE_CAUSE_BUSY			= 0x91,
-	SIGBOOST_RELEASE_CAUSE_CALLED_NOT_EXIST		= 0x92,
-	SIGBOOST_RELEASE_CAUSE_CIRCUIT_RESET		= 0x93,
-	SIGBOOST_RELEASE_CAUSE_NOANSWER			= 0x94
+enum e_sigboost_release_cause_values {
+	SIGBOOST_RELEASE_CAUSE_UNDEFINED = 0x00,
+	SIGBOOST_RELEASE_CAUSE_NORMAL = 0x90,
+	SIGBOOST_RELEASE_CAUSE_BUSY = 0x91,
+	SIGBOOST_RELEASE_CAUSE_CALLED_NOT_EXIST = 0x92,
+	SIGBOOST_RELEASE_CAUSE_CIRCUIT_RESET = 0x93,
+	SIGBOOST_RELEASE_CAUSE_NOANSWER = 0x94
 };
 
-enum	e_sigboost_call_setup_ack_nack_cause_values
-{
-	SIGBOOST_CALL_SETUP_CIRCUIT_RESET		= 0x10,
-	SIGBOOST_CALL_SETUP_NACK_CKT_START_TIMEOUT	= 0x11,
-	SIGBOOST_CALL_SETUP_NACK_ALL_CKTS_BUSY		= 0x12,
-	SIGBOOST_CALL_SETUP_NACK_CALLED_NUM_TOO_BIG	= 0x13,
-	SIGBOOST_CALL_SETUP_NACK_CALLING_NUM_TOO_BIG	= 0x14,
-	SIGBOOST_CALL_SETUP_NACK_CALLED_NUM_TOO_SMALL	= 0x15,
-	SIGBOOST_CALL_SETUP_NACK_CALLING_NUM_TOO_SMALL	= 0x16,
+enum e_sigboost_call_setup_ack_nack_cause_values {
+	SIGBOOST_CALL_SETUP_CIRCUIT_RESET = 0x10,
+	SIGBOOST_CALL_SETUP_NACK_CKT_START_TIMEOUT = 0x11,
+	SIGBOOST_CALL_SETUP_NACK_ALL_CKTS_BUSY = 0x12,
+	SIGBOOST_CALL_SETUP_NACK_CALLED_NUM_TOO_BIG = 0x13,
+	SIGBOOST_CALL_SETUP_NACK_CALLING_NUM_TOO_BIG = 0x14,
+	SIGBOOST_CALL_SETUP_NACK_CALLED_NUM_TOO_SMALL = 0x15,
+	SIGBOOST_CALL_SETUP_NACK_CALLING_NUM_TOO_SMALL = 0x16,
 };
 
 #define MAX_DIALED_DIGITS	31
@@ -61,21 +58,20 @@
 /* 0..(MAX_PENDING_CALLS-1) is range of call_setup_id below */
 
 #pragma pack(1)
-typedef struct
-{
-	uint32_t	event_id;
-	uint32_t	seqno;
-	uint32_t	call_setup_id;
-	uint32_t	trunk_group;
-	uint32_t	span;
-	uint32_t	chan;
-	uint32_t	called_number_digits_count;
-	int8_t		called_number_digits [MAX_DIALED_DIGITS + 1]; /* it's a null terminated string */
-	uint32_t	calling_number_digits_count; /* it's an array */
-	int8_t		calling_number_digits [MAX_DIALED_DIGITS + 1]; /* it's a null terminated string */
-	uint32_t	release_cause;
-	struct timeval  tv;
-	uint32_t	calling_number_presentation;
+typedef struct {
+	uint32_t event_id;
+	uint32_t seqno;
+	uint32_t call_setup_id;
+	uint32_t trunk_group;
+	uint32_t span;
+	uint32_t chan;
+	uint32_t called_number_digits_count;
+	int8_t called_number_digits[MAX_DIALED_DIGITS + 1];	/* it's a null terminated string */
+	uint32_t calling_number_digits_count;	/* it's an array */
+	int8_t calling_number_digits[MAX_DIALED_DIGITS + 1];	/* it's a null terminated string */
+	uint32_t release_cause;
+	struct timeval tv;
+	uint32_t calling_number_presentation;
 } t_sigboost;
 #pragma pack()
 

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/ss7boost_client.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/ss7boost_client.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/ss7boost_client.c	Fri Mar 30 12:19:18 2007
@@ -52,11 +52,11 @@
 	{SIGBOOST_EVENT_CALL_STOPPED_ACK, "CALL_STOPPED_ACK"},
 	{SIGBOOST_EVENT_SYSTEM_RESTART, "SYSTEM_RESTART"},
 	{SIGBOOST_EVENT_HEARTBEAT, "HEARTBEAT"},
-}; 
+};
 
 
 
-static switch_status_t create_udp_socket(ss7boost_client_connection_t *mcon, char *local_ip, int local_port, char *ip, int port)
+static switch_status_t create_udp_socket(ss7boost_client_connection_t * mcon, char *local_ip, int local_port, char *ip, int port)
 {
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "connect %s:%d->%s:%d\n", local_ip, local_port, ip, port);
@@ -68,7 +68,7 @@
 	if (switch_sockaddr_info_get(&mcon->remote_addr, ip, SWITCH_UNSPEC, port, 0, mcon->pool) != SWITCH_STATUS_SUCCESS) {
 		goto fail;
 	}
-	
+
 	if (switch_socket_create(&mcon->socket, AF_INET, SOCK_DGRAM, 0, mcon->pool) == SWITCH_STATUS_SUCCESS) {
 		if (switch_socket_bind(mcon->socket, mcon->local_addr) != SWITCH_STATUS_SUCCESS) {
 			goto fail;
@@ -80,7 +80,7 @@
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Created boost connection %s:%d->%s:%d\n", local_ip, local_port, ip, port);
 	return SWITCH_STATUS_SUCCESS;
 
- fail:
+  fail:
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failure creating boost connection %s:%d->%s:%d\n", local_ip, local_port, ip, port);
 	return SWITCH_STATUS_FALSE;
@@ -88,7 +88,7 @@
 
 
 
-SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_close(ss7boost_client_connection_t *mcon)
+SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_close(ss7boost_client_connection_t * mcon)
 {
 	switch_socket_close(mcon->socket);
 	mcon->socket = NULL;
@@ -97,12 +97,8 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_open(ss7boost_client_connection_t *mcon,
-															char *local_ip,
-															int local_port,
-															char *ip,
-															int port,
-															switch_memory_pool_t *pool)
+SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_open(ss7boost_client_connection_t * mcon,
+																char *local_ip, int local_port, char *ip, int port, switch_memory_pool_t *pool)
 {
 	memset(mcon, 0, sizeof(*mcon));
 	mcon->pool = pool;
@@ -111,32 +107,27 @@
 		switch_mutex_init(&mcon->mutex, SWITCH_MUTEX_NESTED, mcon->pool);
 		return SWITCH_STATUS_SUCCESS;
 	}
-	
+
 	memset(mcon, 0, sizeof(*mcon));
 	return SWITCH_STATUS_FALSE;
 }
 
-SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_read(ss7boost_client_connection_t *mcon, ss7boost_client_event_t **event)
+SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_read(ss7boost_client_connection_t * mcon, ss7boost_client_event_t ** event)
 {
 	unsigned int fromlen = sizeof(struct sockaddr_in);
 	switch_size_t bytes = 0;
 
 	bytes = sizeof(mcon->event);
 
-	if (switch_socket_recvfrom(mcon->local_addr, mcon->socket, 0, (void *)&mcon->event, &bytes) != SWITCH_STATUS_SUCCESS) {
+	if (switch_socket_recvfrom(mcon->local_addr, mcon->socket, 0, (void *) &mcon->event, &bytes) != SWITCH_STATUS_SUCCESS) {
 		bytes = 0;
 	}
 
-	if (bytes == sizeof(mcon->event) || 
-            bytes == (sizeof(mcon->event)-sizeof(uint32_t))) {
+	if (bytes == sizeof(mcon->event) || bytes == (sizeof(mcon->event) - sizeof(uint32_t))) {
 		if (rxseq != mcon->event.seqno) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, 
-			"------------------------------------------\n");
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, 
-			"Critical Error: Invalid Sequence Number Expect=%i Rx=%i\n",
-			rxseq,mcon->event.seqno);
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, 
-			"------------------------------------------\n");
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "------------------------------------------\n");
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Critical Error: Invalid Sequence Number Expect=%i Rx=%i\n", rxseq, mcon->event.seqno);
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "------------------------------------------\n");
 		}
 		rxseq++;
 
@@ -147,7 +138,7 @@
 	return SWITCH_STATUS_FALSE;
 }
 
-SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_write(ss7boost_client_connection_t *mcon, ss7boost_client_event_t *event)
+SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_write(ss7boost_client_connection_t * mcon, ss7boost_client_event_t * event)
 {
 	int err;
 	switch_size_t len;
@@ -158,23 +149,18 @@
 	}
 
 	if (event->span < 0 || event->chan < 0 || event->span > 7 || event->chan > 30) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, 
-			"------------------------------------------\n");
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, 
-			"Critical Error: Invalid Span=%i Chan=%i\n",
-			event->span,event->chan);
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, 
-			"------------------------------------------\n");
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "------------------------------------------\n");
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Critical Error: Invalid Span=%i Chan=%i\n", event->span, event->chan);
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "------------------------------------------\n");
 	}
-
 #ifdef WIN32
 	//TODO set the tv with win func
-#else 
-	gettimeofday(&event->tv,NULL);
+#else
+	gettimeofday(&event->tv, NULL);
 #endif
 
 	switch_mutex_lock(mcon->mutex);
-	event->seqno=txseq++;
+	event->seqno = txseq++;
 	len = sizeof(*event);
 	if (switch_socket_sendto(mcon->socket, mcon->remote_addr, 0, (void *) event, &len) != SWITCH_STATUS_SUCCESS) {
 		err = -1;
@@ -204,42 +190,36 @@
 					  "\n",
 					  ss7boost_client_event_id_name(event->event_id),
 					  event->event_id,
-					  event->span+1,
-					  event->chan+1,
+					  event->span + 1,
+					  event->chan + 1,
 					  (event->called_number_digits_count ? (char *) event->called_number_digits : "N/A"),
 					  (event->calling_number_digits_count ? (char *) event->calling_number_digits : "N/A"),
-					  event->release_cause,
-					  event->span+1,
-					  event->chan+1,
-					  event->event_id,
-					  event->call_setup_id,
-					  event->seqno
-					  );
+					  event->release_cause, event->span + 1, event->chan + 1, event->event_id, event->call_setup_id, event->seqno);
 
 
 	return err ? SWITCH_STATUS_FALSE : SWITCH_STATUS_SUCCESS;
 }
 
-SWITCH_DECLARE(void) ss7boost_client_call_init(ss7boost_client_event_t *event, char *calling, char *called, int setup_id)
+SWITCH_DECLARE(void) ss7boost_client_call_init(ss7boost_client_event_t * event, char *calling, char *called, int setup_id)
 {
 	memset(event, 0, sizeof(ss7boost_client_event_t));
 	event->event_id = SIGBOOST_EVENT_CALL_START;
 
 	if (calling) {
-		strncpy((char*)event->calling_number_digits, calling, sizeof(event->calling_number_digits)-1);
+		strncpy((char *) event->calling_number_digits, calling, sizeof(event->calling_number_digits) - 1);
 		event->calling_number_digits_count = strlen(calling);
 	}
 
 	if (called) {
-		strncpy((char*)event->called_number_digits, called, sizeof(event->called_number_digits)-1);
+		strncpy((char *) event->called_number_digits, called, sizeof(event->called_number_digits) - 1);
 		event->called_number_digits_count = strlen(called);
 	}
-		
+
 	event->call_setup_id = setup_id;
-	
+
 }
 
-SWITCH_DECLARE(void) ss7boost_client_event_init(ss7boost_client_event_t *event, ss7boost_client_event_id_t event_id, int chan, int span) 
+SWITCH_DECLARE(void) ss7boost_client_event_init(ss7boost_client_event_t * event, ss7boost_client_event_id_t event_id, int chan, int span)
 {
 	memset(event, 0, sizeof(ss7boost_client_event_t));
 	event->event_id = event_id;
@@ -252,7 +232,7 @@
 	int x;
 	char *ret = NULL;
 
-	for (x = 0 ; x < sizeof(ss7boost_client_table)/sizeof(struct ss7boost_client_map); x++) {
+	for (x = 0; x < sizeof(ss7boost_client_table) / sizeof(struct ss7boost_client_map); x++) {
 		if (ss7boost_client_table[x].event_id == event_id) {
 			ret = ss7boost_client_table[x].name;
 			break;

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/ss7boost_client.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/ss7boost_client.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_wanpipe/ss7boost_client.h	Fri Mar 30 12:19:18 2007
@@ -70,7 +70,7 @@
 					(dest)->flags |= ((src)->flags & (flagz)); \
 					} while (0)
 
-typedef  t_sigboost ss7boost_client_event_t;
+typedef t_sigboost ss7boost_client_event_t;
 typedef uint32_t ss7boost_client_event_id_t;
 
 struct ss7boost_client_connection {
@@ -80,7 +80,7 @@
 	ss7boost_client_event_t event;
 	unsigned int flags;
 	switch_mutex_t *mutex;
-	switch_memory_pool_t * pool;
+	switch_memory_pool_t *pool;
 };
 
 typedef enum {
@@ -89,19 +89,13 @@
 
 typedef struct ss7boost_client_connection ss7boost_client_connection_t;
 
-SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_close(ss7boost_client_connection_t *mcon);
-SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_open(ss7boost_client_connection_t *mcon,
-															char *local_ip,
-															int local_port,
-															char *ip,
-															int port,
-															switch_memory_pool_t *pool);
-SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_read(ss7boost_client_connection_t *mcon, ss7boost_client_event_t **event);
-SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_write(ss7boost_client_connection_t *mcon, ss7boost_client_event_t *event);
-SWITCH_DECLARE(void) ss7boost_client_event_init(ss7boost_client_event_t *event, ss7boost_client_event_id_t event_id, int chan, int span);
-SWITCH_DECLARE(void) ss7boost_client_call_init(ss7boost_client_event_t *event, char *calling, char *called, int setup_id);
+SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_close(ss7boost_client_connection_t * mcon);
+SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_open(ss7boost_client_connection_t * mcon,
+																char *local_ip, int local_port, char *ip, int port, switch_memory_pool_t *pool);
+SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_read(ss7boost_client_connection_t * mcon, ss7boost_client_event_t ** event);
+SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_write(ss7boost_client_connection_t * mcon, ss7boost_client_event_t * event);
+SWITCH_DECLARE(void) ss7boost_client_event_init(ss7boost_client_event_t * event, ss7boost_client_event_id_t event_id, int chan, int span);
+SWITCH_DECLARE(void) ss7boost_client_call_init(ss7boost_client_event_t * event, char *calling, char *called, int setup_id);
 SWITCH_DECLARE(char *) ss7boost_client_event_id_name(uint32_t event_id);
 
 #endif
-
-

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_woomera/mod_woomera.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_woomera/mod_woomera.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_woomera/mod_woomera.c	Fri Mar 30 12:19:18 2007
@@ -169,25 +169,23 @@
 static switch_status_t woomera_on_ring(switch_core_session_t *session);
 static switch_status_t woomera_on_loopback(switch_core_session_t *session);
 static switch_status_t woomera_on_transmit(switch_core_session_t *session);
-static switch_call_cause_t woomera_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile,
+static switch_call_cause_t woomera_outgoing_channel(switch_core_session_t *session,
+													switch_caller_profile_t *outbound_profile,
 													switch_core_session_t **new_session, switch_memory_pool_t **pool);
-static switch_status_t woomera_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout,
-											switch_io_flag_t flags, int stream_id);
-static switch_status_t woomera_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout,
-											 switch_io_flag_t flags, int stream_id);
+static switch_status_t woomera_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, switch_io_flag_t flags, int stream_id);
+static switch_status_t woomera_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flags, int stream_id);
 static switch_status_t woomera_kill_channel(switch_core_session_t *session, int sig);
 static void tech_destroy(private_object * tech_pvt);
-static void woomera_printf(woomera_profile * profile, switch_socket_t *socket, char *fmt, ...);
+static void woomera_printf(woomera_profile * profile, switch_socket_t * socket, char *fmt, ...);
 static char *woomera_message_header(woomera_message * wmsg, char *key);
 static int woomera_enqueue_event(woomera_event_queue * event_queue, woomera_message * wmsg);
 static int woomera_dequeue_event(woomera_event_queue * event_queue, woomera_message * wmsg);
-static int woomera_message_parse(switch_socket_t *fd, woomera_message * wmsg, int timeout, woomera_profile * profile,
-								 woomera_event_queue * event_queue);
-static int connect_woomera(switch_socket_t **new_sock, woomera_profile * profile, int flags);
+static int woomera_message_parse(switch_socket_t * fd, woomera_message * wmsg, int timeout, woomera_profile * profile, woomera_event_queue * event_queue);
+static int connect_woomera(switch_socket_t ** new_sock, woomera_profile * profile, int flags);
 static int woomera_profile_thread_running(woomera_profile * profile, int set, int new);
-static int woomera_locate_socket(woomera_profile * profile, switch_socket_t **woomera_socket);
+static int woomera_locate_socket(woomera_profile * profile, switch_socket_t ** woomera_socket);
 static int tech_create_read_socket(private_object * tech_pvt);
-static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj);
+static void *woomera_channel_thread_run(switch_thread_t * thread, void *obj);
 static void *woomera_thread_run(void *obj);
 static int tech_activate(private_object * tech_pvt);
 
@@ -294,7 +292,7 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static void woomera_socket_close(switch_socket_t **socket)
+static void woomera_socket_close(switch_socket_t ** socket)
 {
 	if (*socket) {
 		switch_socket_close(*socket);
@@ -327,19 +325,19 @@
 		return SWITCH_STATUS_FALSE;
 	}
 
-    switch(sig) {
-    case SWITCH_SIG_KILL:
-        udp_socket_close(tech_pvt);
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s WOOMERA KILL\n", switch_channel_get_name(channel));
-        break;
-    case SWITCH_SIG_BREAK:
-        {
-            const char p = 0;
-            switch_size_t len = sizeof(p);
-            switch_socket_sendto(tech_pvt->udp_socket, tech_pvt->udpwrite, 0, &p, &len);
-        }
-        break;
-    }
+	switch (sig) {
+	case SWITCH_SIG_KILL:
+		udp_socket_close(tech_pvt);
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s WOOMERA KILL\n", switch_channel_get_name(channel));
+		break;
+	case SWITCH_SIG_BREAK:
+		{
+			const char p = 0;
+			switch_size_t len = sizeof(p);
+			switch_socket_sendto(tech_pvt->udp_socket, tech_pvt->udpwrite, 0, &p, &len);
+		}
+		break;
+	}
 
 
 	return SWITCH_STATUS_SUCCESS;
@@ -375,11 +373,10 @@
 	assert(tech_pvt != NULL);
 
 	return SWITCH_STATUS_SUCCESS;
-//	return switch_socket_waitfor(tech_pvt->write_poll, ms);
+//  return switch_socket_waitfor(tech_pvt->write_poll, ms);
 }
 
-static switch_status_t woomera_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout,
-											switch_io_flag_t flags, int stream_id)
+static switch_status_t woomera_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, switch_io_flag_t flags, int stream_id)
 {
 	switch_channel_t *channel = NULL;
 	struct private_object *tech_pvt = NULL;
@@ -405,7 +402,7 @@
 
 	len = sizeof(tech_pvt->databuf);
 	if (switch_socket_recvfrom(tech_pvt->udpread, tech_pvt->udp_socket, 0, tech_pvt->databuf, &len) == SWITCH_STATUS_SUCCESS) {
-		pframe->datalen = (uint32_t)len;
+		pframe->datalen = (uint32_t) len;
 		pframe->samples = (int) pframe->datalen / 2;
 		return SWITCH_STATUS_SUCCESS;
 	}
@@ -413,14 +410,13 @@
 	return SWITCH_STATUS_FALSE;
 }
 
-static switch_status_t woomera_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout,
-											 switch_io_flag_t flags, int stream_id)
+static switch_status_t woomera_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flags, int stream_id)
 {
 	switch_channel_t *channel = NULL;
 	struct private_object *tech_pvt = NULL;
 	switch_size_t len;
 	//switch_frame_t *pframe;
-	
+
 	channel = switch_core_session_get_channel(session);
 	assert(channel != NULL);
 
@@ -430,11 +426,10 @@
 	if (!tech_pvt->udp_socket) {
 		return SWITCH_STATUS_GENERR;
 	}
-
 	//pframe = &tech_pvt->frame;
 	len = frame->datalen;
 	if (switch_socket_sendto(tech_pvt->udp_socket, tech_pvt->udpwrite, 0, frame->data, &len) == SWITCH_STATUS_SUCCESS) {
-		frame->datalen = (uint32_t)len;
+		frame->datalen = (uint32_t) len;
 		return SWITCH_STATUS_SUCCESS;
 	}
 
@@ -481,7 +476,8 @@
 /* Make sure when you have 2 sessions in the same scope that you pass the appropriate one to the routines
    that allocate memory or you will have 1 channel with memory allocated from another channel's pool!
 */
-static switch_call_cause_t woomera_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile,
+static switch_call_cause_t woomera_outgoing_channel(switch_core_session_t *session,
+													switch_caller_profile_t *outbound_profile,
 													switch_core_session_t **new_session, switch_memory_pool_t **pool)
 {
 	if ((*new_session = switch_core_session_request(&woomera_endpoint_interface, pool)) != 0) {
@@ -489,8 +485,7 @@
 		switch_channel_t *channel;
 
 		switch_core_session_add_stream(*new_session, NULL);
-		if ((tech_pvt =
-			 (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object))) != 0) {
+		if ((tech_pvt = (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object))) != 0) {
 			memset(tech_pvt, 0, sizeof(*tech_pvt));
 			switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(*new_session));
 			tech_pvt->profile = &default_profile;
@@ -538,10 +533,8 @@
 	}
 
 
-	woomera_printf(tech_pvt->profile, tech_pvt->command_channel, "hangup %s%s", tech_pvt->call_info.callid,
-				   WOOMERA_RECORD_SEPERATOR);
-	if (woomera_message_parse
-		(tech_pvt->command_channel, &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue) < 0) {
+	woomera_printf(tech_pvt->profile, tech_pvt->command_channel, "hangup %s%s", tech_pvt->call_info.callid, WOOMERA_RECORD_SEPERATOR);
+	if (woomera_message_parse(tech_pvt->command_channel, &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue) < 0) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "{%s} Already Disconnected\n", tech_pvt->profile->name);
 	}
 
@@ -551,7 +544,7 @@
 }
 
 
-static void woomera_printf(woomera_profile * profile, switch_socket_t *socket, char *fmt, ...)
+static void woomera_printf(woomera_profile * profile, switch_socket_t * socket, char *fmt, ...)
 {
 	char *stuff;
 	size_t res = 0, len = 0;
@@ -570,7 +563,7 @@
 	} else {
 		if (profile && globals.debug) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Send Message: {%s} [%s/%d]\n%s\n%s", profile->name,
-								  profile->woomera_host, profile->woomera_port, WOOMERA_DEBUG_LINE, stuff);
+							  profile->woomera_host, profile->woomera_port, WOOMERA_DEBUG_LINE, stuff);
 		}
 		len = strlen(stuff);
 		switch_socket_send(socket, stuff, &len);
@@ -637,8 +630,7 @@
 	return 0;
 }
 
-static int woomera_message_parse(switch_socket_t *fd, woomera_message * wmsg, int timeout, woomera_profile * profile,
-								 woomera_event_queue * event_queue)
+static int woomera_message_parse(switch_socket_t * fd, woomera_message * wmsg, int timeout, woomera_profile * profile, woomera_event_queue * event_queue)
 {
 	char *cur, *cr, *next = NULL;
 	char buf[2048] = "", *ptr;
@@ -660,7 +652,7 @@
 	bytes = 0;
 	while (!strstr(buf, WOOMERA_RECORD_SEPERATOR)) {
 		size_t len = 1;
-        switch_status_t status;
+		switch_status_t status;
 
 		if (!profile->thread_running) {
 			return -1;
@@ -668,16 +660,16 @@
 
 		status = switch_socket_recv(fd, ptr, &len);
 
-        if (status == 70007) {
-            char bbuf = '\n';
-            switch_size_t blen = sizeof(bbuf);
-            switch_socket_send(fd, &bbuf, &blen);
-            continue;
-        }
-        
-        if (status != SWITCH_STATUS_SUCCESS) {
-                return -1;
-        }
+		if (status == 70007) {
+			char bbuf = '\n';
+			switch_size_t blen = sizeof(bbuf);
+			switch_socket_send(fd, &bbuf, &blen);
+			continue;
+		}
+
+		if (status != SWITCH_STATUS_SUCCESS) {
+			return -1;
+		}
 
 		ptr++;
 		bytes++;
@@ -687,7 +679,7 @@
 
 	if (globals.debug) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Receive Message: {%s} [%s/%d]\n%s\n%s", profile->name,
-							  profile->woomera_host, profile->woomera_port, WOOMERA_DEBUG_LINE, buf);
+						  profile->woomera_host, profile->woomera_port, WOOMERA_DEBUG_LINE, buf);
 	}
 
 	while ((cur = next) != 0) {
@@ -796,7 +788,7 @@
 }
 
 
-static int connect_woomera(switch_socket_t **new_sock, woomera_profile * profile, int flags)
+static int connect_woomera(switch_socket_t ** new_sock, woomera_profile * profile, int flags)
 {
 
 	switch_sockaddr_t *sa;
@@ -809,8 +801,8 @@
 		return -1;
 	}
 
-    switch_socket_timeout_set((*new_sock), 10000000);
-    switch_socket_opt_set((*new_sock), SWITCH_SO_KEEPALIVE, 1);
+	switch_socket_timeout_set((*new_sock), 10000000);
+	switch_socket_opt_set((*new_sock), SWITCH_SO_KEEPALIVE, 1);
 
 	/*
 	   status = switch_socket_bind((*new_sock), sa);
@@ -841,7 +833,7 @@
 
 }
 
-static int woomera_locate_socket(woomera_profile * profile, switch_socket_t **woomera_socket)
+static int woomera_locate_socket(woomera_profile * profile, switch_socket_t ** woomera_socket)
 {
 	woomera_message wmsg;
 
@@ -851,16 +843,14 @@
 			if (!woomera_profile_thread_running(profile, 0, 0)) {
 				break;
 			}
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "{%s} Cannot Reconnect to Woomera! retry in 5 seconds\n",
-								  profile->name);
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "{%s} Cannot Reconnect to Woomera! retry in 5 seconds\n", profile->name);
 			switch_sleep(WOOMERA_RECONNECT_TIME);
 		}
 
 		if (*woomera_socket) {
 			if (switch_test_flag(profile, PFLAG_INBOUND)) {
 				woomera_printf(profile, *woomera_socket, "LISTEN%s", WOOMERA_RECORD_SEPERATOR);
-				if (woomera_message_parse(*woomera_socket,
-										  &wmsg, WOOMERA_HARD_TIMEOUT, profile, &profile->event_queue) < 0) {
+				if (woomera_message_parse(*woomera_socket, &wmsg, WOOMERA_HARD_TIMEOUT, profile, &profile->event_queue) < 0) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n", profile->name);
 					globals.panic = 1;
 					woomera_profile_thread_running(&default_profile, 1, 0);
@@ -927,18 +917,14 @@
 						   tech_pvt->profile->audio_ip,
 						   tech_pvt->port,
 						   WOOMERA_LINE_SEPERATOR,
-						   tech_pvt->caller_profile->caller_id_name,
-						   tech_pvt->caller_profile->caller_id_number, WOOMERA_RECORD_SEPERATOR);
+						   tech_pvt->caller_profile->caller_id_name, tech_pvt->caller_profile->caller_id_number, WOOMERA_RECORD_SEPERATOR);
 
-			woomera_message_parse(tech_pvt->command_channel,
-								  &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue);
+			woomera_message_parse(tech_pvt->command_channel, &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue);
 		} else {
 			switch_set_flag_locked(tech_pvt, TFLAG_PARSE_INCOMING);
 			woomera_printf(tech_pvt->profile, tech_pvt->command_channel, "LISTEN%s", WOOMERA_RECORD_SEPERATOR);
-			if (woomera_message_parse(tech_pvt->command_channel,
-									  &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue) < 0) {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n",
-									  tech_pvt->profile->name);
+			if (woomera_message_parse(tech_pvt->command_channel, &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue) < 0) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n", tech_pvt->profile->name);
 				switch_set_flag_locked(tech_pvt, TFLAG_ABORT);
 				globals.panic = 1;
 			}
@@ -952,7 +938,7 @@
 
 
 
-static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj)
+static void *woomera_channel_thread_run(switch_thread_t * thread, void *obj)
 {
 	switch_core_session_t *session = obj;
 	switch_channel_t *channel = NULL;
@@ -992,13 +978,9 @@
 		if (switch_test_flag(tech_pvt, TFLAG_ANSWER)) {
 			switch_clear_flag_locked(tech_pvt, TFLAG_ANSWER);
 #ifdef USE_ANSWER
-			woomera_printf(tech_pvt->profile, tech_pvt->command_channel, "ANSWER %s%s", tech_pvt->call_info.callid,
-						   WOOMERA_RECORD_SEPERATOR);
-			if (woomera_message_parse
-				(tech_pvt->command_channel, &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile,
-				 &tech_pvt->event_queue) < 0) {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n",
-									  tech_pvt->profile->name);
+			woomera_printf(tech_pvt->profile, tech_pvt->command_channel, "ANSWER %s%s", tech_pvt->call_info.callid, WOOMERA_RECORD_SEPERATOR);
+			if (woomera_message_parse(tech_pvt->command_channel, &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue) < 0) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n", tech_pvt->profile->name);
 				switch_set_flag_locked(tech_pvt, TFLAG_ABORT);
 				globals.panic = 1;
 				continue;
@@ -1010,11 +992,8 @@
 			switch_mutex_lock(tech_pvt->iolock);
 			woomera_printf(tech_pvt->profile, tech_pvt->command_channel, "DTMF %s %s%s", tech_pvt->call_info.callid,
 						   tech_pvt->dtmfbuf, WOOMERA_RECORD_SEPERATOR);
-			if (woomera_message_parse
-				(tech_pvt->command_channel, &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile,
-				 &tech_pvt->event_queue) < 0) {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n",
-									  tech_pvt->profile->name);
+			if (woomera_message_parse(tech_pvt->command_channel, &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue) < 0) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n", tech_pvt->profile->name);
 				switch_set_flag_locked(tech_pvt, TFLAG_ABORT);
 				globals.panic = 1;
 				continue;
@@ -1028,9 +1007,7 @@
 			struct timeval now;
 			int elapsed;
 			gettimeofday(&now, NULL);
-			elapsed =
-				(((now.tv_sec * 1000) + now.tv_usec / 1000) -
-				 ((tech_pvt->started.tv_sec * 1000) + tech_pvt->started.tv_usec / 1000));
+			elapsed = (((now.tv_sec * 1000) + now.tv_usec / 1000) - ((tech_pvt->started.tv_sec * 1000) + tech_pvt->started.tv_usec / 1000));
 			if (elapsed > tech_pvt->timeout) {
 				/* call timed out! */
 				switch_set_flag_locked(tech_pvt, TFLAG_ABORT);
@@ -1095,10 +1072,9 @@
 				if ((tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
 																		  NULL,
 																		  tech_pvt->profile->dialplan,
-																		  cid_name, cid_num, ip, NULL, NULL, NULL, (char *)modname, NULL, exten)) != 0) {
+																		  cid_name, cid_num, ip, NULL, NULL, NULL, (char *) modname, NULL, exten)) != 0) {
 					char name[128];
-					snprintf(name, sizeof(name), "Woomera/%s-%04x", tech_pvt->caller_profile->destination_number,
-							 rand() & 0xffff);
+					snprintf(name, sizeof(name), "Woomera/%s-%04x", tech_pvt->caller_profile->destination_number, rand() & 0xffff);
 					switch_channel_set_name(channel, name);
 					switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
 
@@ -1107,15 +1083,10 @@
 				woomera_printf(tech_pvt->profile, tech_pvt->command_channel,
 							   "%s %s%s"
 							   "Raw-Audio: %s/%d%s",
-							   MEDIA_ANSWER,
-							   wmsg.callid,
-							   WOOMERA_LINE_SEPERATOR,
-							   tech_pvt->profile->audio_ip, tech_pvt->port, WOOMERA_RECORD_SEPERATOR);
-
-				if (woomera_message_parse(tech_pvt->command_channel,
-										  &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue) < 0) {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n",
-										  tech_pvt->profile->name);
+							   MEDIA_ANSWER, wmsg.callid, WOOMERA_LINE_SEPERATOR, tech_pvt->profile->audio_ip, tech_pvt->port, WOOMERA_RECORD_SEPERATOR);
+
+				if (woomera_message_parse(tech_pvt->command_channel, &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue) < 0) {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n", tech_pvt->profile->name);
 					switch_set_flag_locked(tech_pvt, TFLAG_ABORT);
 					globals.panic = 1;
 					continue;
@@ -1135,23 +1106,17 @@
 					if ((ptr = strchr(ip, '/')) != 0) {
 						*ptr = '\0';
 						ptr++;
-						port = (switch_port_t)atoi(ptr);
+						port = (switch_port_t) atoi(ptr);
 					}
 					/* Move Channel's State Machine to RING */
 					switch_channel_answer(channel);
 					switch_channel_set_state(channel, CS_RING);
 
 					if (switch_sockaddr_info_get(&tech_pvt->udpwrite,
-												 ip,
-												 SWITCH_UNSPEC,
-												 port,
-												 0,
-												 switch_core_session_get_pool(tech_pvt->session)) !=
-						SWITCH_STATUS_SUCCESS) {
+												 ip, SWITCH_UNSPEC, port, 0, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
 						if (globals.debug) {
 							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
-												  WOOMERA_DEBUG_PREFIX "{%s} Cannot resolve %s\n",
-												  tech_pvt->profile->name, ip);
+											  WOOMERA_DEBUG_PREFIX "{%s} Cannot resolve %s\n", tech_pvt->profile->name, ip);
 						}
 						switch_channel_hangup(channel, SWITCH_CAUSE_NETWORK_OUT_OF_ORDER);
 					}
@@ -1159,13 +1124,11 @@
 			}
 		}
 		if (globals.debug > 2) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, WOOMERA_DEBUG_PREFIX "CHECK {%s}(%d)\n",
-								  tech_pvt->profile->name, res);
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, WOOMERA_DEBUG_PREFIX "CHECK {%s}(%d)\n", tech_pvt->profile->name, res);
 		}
 	}
 	if (globals.debug > 1) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, WOOMERA_DEBUG_PREFIX "Monitor thread for %s done.\n",
-							  tech_pvt->profile->name);
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, WOOMERA_DEBUG_PREFIX "Monitor thread for %s done.\n", tech_pvt->profile->name);
 	}
 
 	return NULL;
@@ -1204,7 +1167,7 @@
 				break;
 			}
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Woomera Thread Up {%s} %s/%d\n", profile->name,
-								  profile->woomera_host, profile->woomera_port);
+							  profile->woomera_host, profile->woomera_port);
 
 		}
 
@@ -1219,20 +1182,18 @@
 			continue;
 		}
 
-		if ((((res = woomera_dequeue_event(&profile->event_queue, &wmsg)) != 0) ||
-			 ((res = woomera_message_parse(profile->woomera_socket, &wmsg,
-										  /* if we are not stingy with threads we can block forever */
-										  0, profile, NULL))) != 0)) {
+		if ((((res = woomera_dequeue_event(&profile->event_queue, &wmsg)) != 0) || ((res = woomera_message_parse(profile->woomera_socket, &wmsg,
+																												 /* if we are not stingy with threads we can block forever */
+																												 0, profile, NULL))) != 0)) {
 			if (res < 0) {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! I lost my connection to woomera!\n",
-									  profile->name);
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! I lost my connection to woomera!\n", profile->name);
 				woomera_socket_close(&profile->woomera_socket);
 
 				//global_set_flag(TFLAG_ABORT);
 				globals.panic = 1;
 				continue;
 
-		/* Can't get to the following code --Commented out for now.*/
+				/* Can't get to the following code --Commented out for now. */
 /*				if (profile->woomera_socket) 
 					if (switch_test_flag(profile, PFLAG_INBOUND)) {
 						woomera_printf(profile, profile->woomera_socket, "LISTEN%s", WOOMERA_RECORD_SEPERATOR);
@@ -1267,8 +1228,7 @@
 
 					switch_core_session_add_stream(session, NULL);
 
-					if ((tech_pvt =
-						 (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object))) != 0) {
+					if ((tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object))) != 0) {
 						memset(tech_pvt, 0, sizeof(*tech_pvt));
 						switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
 						tech_pvt->profile = &default_profile;
@@ -1346,7 +1306,7 @@
 	strncpy(profile->dialplan, "default", sizeof(profile->dialplan) - 1);
 	strncpy(profile->audio_ip, "127.0.0.1", sizeof(profile->audio_ip) - 1);
 	strncpy(profile->woomera_host, "127.0.0.1", sizeof(profile->woomera_host) - 1);
-	profile->woomera_port = (switch_port_t)42420;
+	profile->woomera_port = (switch_port_t) 42420;
 
 	if ((settings = switch_xml_child(cfg, "settings"))) {
 		for (param = switch_xml_child(settings, "param"); param; param = param->next) {
@@ -1371,7 +1331,7 @@
 			} else if (!strcmp(var, "host")) {
 				strncpy(profile->woomera_host, val, sizeof(profile->woomera_host) - 1);
 			} else if (!strcmp(var, "port")) {
-				profile->woomera_port = (switch_port_t)atoi(val);
+				profile->woomera_port = (switch_port_t) atoi(val);
 			} else if (!strcmp(var, "disabled")) {
 				if (atoi(val) > 0) {
 					switch_set_flag(profile, PFLAG_DISABLED);

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/basecdr.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/basecdr.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/basecdr.h	Fri Mar 30 12:19:18 2007
@@ -46,8 +46,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 
-struct switch_mod_cdr_newchannel_t 
-{
+struct switch_mod_cdr_newchannel_t {
 	switch_core_session_t *session;
 	switch_channel_t *channel;
 	//switch_channel_timetable_t *timetable;
@@ -57,7 +56,7 @@
 	//bool originate;
 };
 
-enum switch_mod_cdr_sql_types_t { CDR_INTEGER,CDR_STRING,CDR_DECIMAL,CDR_DOUBLE,CDR_TINY };
+enum switch_mod_cdr_sql_types_t { CDR_INTEGER, CDR_STRING, CDR_DECIMAL, CDR_DOUBLE, CDR_TINY };
 
 #ifdef WIN32
 #define STDCALL __stdcall
@@ -65,54 +64,54 @@
 #define STDCALL
 #endif
 
-typedef switch_status_t (STDCALL *modcdr_time_convert_t)(switch_time_exp_t*,switch_time_t);
+typedef switch_status_t (STDCALL * modcdr_time_convert_t) (switch_time_exp_t *, switch_time_t);
 
 class BaseCDR {
-	public:
-		BaseCDR();
-		virtual ~BaseCDR();
-		BaseCDR(switch_mod_cdr_newchannel_t *newchannel);
-		virtual void connect(switch_xml_t& cfg, switch_xml_t& xml, switch_xml_t& settings, switch_xml_t& param) = 0;
-		virtual void disconnect() = 0;
-		virtual bool process_record() = 0;
-		virtual bool is_activated() = 0;
-		virtual void tempdump_record() = 0;
-		virtual void reread_tempdumped_records() = 0;
-		virtual std::string get_display_name() = 0; // Get the module name
-	protected:
-		void parse_channel_variables_xconfig(std::string& unparsed,std::list<std::string>& chanvarslist,bool fixed);
-		void parse_channel_variables_xconfig(std::string& unparsed,std::list<std::string>& chanvarslist,std::vector<switch_mod_cdr_sql_types_t>& chanvars_fixed_types);  // Typically used for SQL types
-		void process_channel_variables(const std::list<std::string>& stringlist,const std::list<std::string>& fixedlist,switch_channel_t *channel,bool repeat = 1); //This is used for supplemental chanvars
-		void process_channel_variables(const std::list<std::string>& stringlist,switch_channel_t *channel); // This is used for fixed chanvars
-		void escape_string(std::string& src);
-		std::string escape_chararray(char* src);
-		switch_time_t callstartdate;
-		switch_time_t callanswerdate;
-		switch_time_t callenddate;
-		switch_time_t calltransferdate;
-		switch_call_cause_t hangupcause;
-		char *hangupcause_text;
-		char clid[80];
-		bool originated;  // Did they originate this call?
-		char dialplan[80];
-		char myuuid[37]; // 36 + 1 to hold \0
-		char destuuid[37];
-		char src[80];
-		char dst[80];
-		char srcchannel[80];
-		char dstchannel[80];
-		char ani[80];
-		char aniii[80];
-		char network_addr[40];
-		char lastapp[80];
-		char lastdata[255]; 
-		switch_time_t billusec; // Yes, you heard me, we're measuring in microseconds
-		int disposition; // Currently 0 = Busy/Unanswered, 1 = Answered
-		int amaflags;
-		switch_core_session_t *coresession;
-		std::list<std::pair<std::string,std::string> > chanvars_fixed;
-		std::map<std::string,std::string> chanvars_supp;
-		bool errorstate; // True if there is an error writing the log
+  public:
+	BaseCDR();
+	virtual ~ BaseCDR();
+	BaseCDR(switch_mod_cdr_newchannel_t * newchannel);
+	virtual void connect(switch_xml_t & cfg, switch_xml_t & xml, switch_xml_t & settings, switch_xml_t & param) = 0;
+	virtual void disconnect() = 0;
+	virtual bool process_record() = 0;
+	virtual bool is_activated() = 0;
+	virtual void tempdump_record() = 0;
+	virtual void reread_tempdumped_records() = 0;
+	virtual std::string get_display_name() = 0;	// Get the module name
+  protected:
+	void parse_channel_variables_xconfig(std::string & unparsed, std::list < std::string > &chanvarslist, bool fixed);
+	void parse_channel_variables_xconfig(std::string & unparsed, std::list < std::string > &chanvarslist, std::vector < switch_mod_cdr_sql_types_t > &chanvars_fixed_types);	// Typically used for SQL types
+	void process_channel_variables(const std::list < std::string > &stringlist, const std::list < std::string > &fixedlist, switch_channel_t *channel, bool repeat = 1);	//This is used for supplemental chanvars
+	void process_channel_variables(const std::list < std::string > &stringlist, switch_channel_t *channel);	// This is used for fixed chanvars
+	void escape_string(std::string & src);
+	     std::string escape_chararray(char *src);
+	switch_time_t callstartdate;
+	switch_time_t callanswerdate;
+	switch_time_t callenddate;
+	switch_time_t calltransferdate;
+	switch_call_cause_t hangupcause;
+	char *hangupcause_text;
+	char clid[80];
+	bool originated;			// Did they originate this call?
+	char dialplan[80];
+	char myuuid[37];			// 36 + 1 to hold \0
+	char destuuid[37];
+	char src[80];
+	char dst[80];
+	char srcchannel[80];
+	char dstchannel[80];
+	char ani[80];
+	char aniii[80];
+	char network_addr[40];
+	char lastapp[80];
+	char lastdata[255];
+	switch_time_t billusec;		// Yes, you heard me, we're measuring in microseconds
+	int disposition;			// Currently 0 = Busy/Unanswered, 1 = Answered
+	int amaflags;
+	switch_core_session_t *coresession;
+	                      std::list < std::pair < std::string, std::string > >chanvars_fixed;
+	                      std::map < std::string, std::string > chanvars_supp;
+	bool errorstate;			// True if there is an error writing the log
 };
 
 #endif

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/baseregistry.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/baseregistry.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/baseregistry.h	Fri Mar 30 12:19:18 2007
@@ -42,34 +42,32 @@
 #ifdef __cplusplus
 #include <vector>
 
-template<class T> BaseCDR* basecdr_factory(switch_mod_cdr_newchannel_t *newchannel)
+template < class T > BaseCDR * basecdr_factory(switch_mod_cdr_newchannel_t * newchannel)
 {
 	return new T(newchannel);
 }
 
-typedef BaseCDR* (*basecdr_creator)(switch_mod_cdr_newchannel_t *newchannel);
+typedef BaseCDR *(*basecdr_creator) (switch_mod_cdr_newchannel_t * newchannel);
 
-class BaseRegistry
-{
-	private:
-		std::vector<basecdr_creator> m_bases; // Stores all modules
-		std::vector<basecdr_creator> active_bases; // Stores only active modules
-	public:
-		typedef std::vector<basecdr_creator>::iterator iterator;
-		static BaseRegistry& get();
-		void add(basecdr_creator);
-		void reset_active(); // Clears the active vector for reloading of configuration.
-		void add_active(iterator);
-		iterator begin();
-		iterator end();
-		iterator active_begin();
-		iterator active_end();
+class BaseRegistry {
+  private:
+	std::vector < basecdr_creator > m_bases;	// Stores all modules
+	std::vector < basecdr_creator > active_bases;	// Stores only active modules
+  public:
+	typedef std::vector < basecdr_creator >::iterator iterator;
+	static BaseRegistry & get();
+	void add(basecdr_creator);
+	void reset_active();		// Clears the active vector for reloading of configuration.
+	void add_active(iterator);
+	iterator begin();
+	iterator end();
+	iterator active_begin();
+	iterator active_end();
 };
 
-class BaseRegistration
-{
-	public:
-		BaseRegistration(basecdr_creator);
+class BaseRegistration {
+  public:
+	BaseRegistration(basecdr_creator);
 };
 
 #define AUTO_REGISTER_BASECDR(basecdr) BaseRegistration _basecdr_registration_ ## basecdr(&basecdr_factory<basecdr>);

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/cdrcontainer.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/cdrcontainer.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/cdrcontainer.h	Fri Mar 30 12:19:18 2007
@@ -51,11 +51,11 @@
 extern "C" {
 #endif
 
-class CDRContainer {
-	public:
+	class CDRContainer {
+	  public:
 		CDRContainer();
 		CDRContainer(switch_memory_pool_t *module_pool);
-		~CDRContainer();
+		                    ~CDRContainer();
 		void add_cdr(switch_core_session_t *session);
 		void process_records();
 #ifdef SWITCH_QUEUE_ENHANCED
@@ -65,21 +65,19 @@
 #endif
 		void active(switch_stream_handle_t *stream);
 		void available(switch_stream_handle_t *stream);
-	protected:
-	private:
-		switch_xml_t cfg, xml, settings, param;
+	  protected:
+	  private:
+		                       switch_xml_t cfg, xml, settings, param;
 		switch_queue_t *cdrqueue;
-		std::string tempfilepath;
+		               std::string tempfilepath;
 		char configfile[13];
 		bool queue_paused;
-};
+	};
 
 #ifdef __cplusplus
 }
 #endif
-
 #endif
-
 /* For Emacs:
  * Local Variables:
  * mode:c++

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/csvcdr.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/csvcdr.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/csvcdr.h	Fri Mar 30 12:19:18 2007
@@ -44,38 +44,38 @@
 #ifndef CSVCDR
 #define CSVCDR
 
-class CsvCDR : public BaseCDR {
-	public:
-		CsvCDR();
-		CsvCDR(switch_mod_cdr_newchannel_t *newchannel);
-		//CsvCDR(const CsvCDR& copyFrom);
-		virtual ~CsvCDR();
-		virtual bool process_record();
-		virtual void connect(switch_xml_t& cfg, switch_xml_t& xml, switch_xml_t& settings, switch_xml_t& param); // connect and disconnect need to be static because we're persisting connections until shutdown
-		virtual void disconnect();
-		virtual bool is_activated();
-		virtual void tempdump_record();
-		virtual void reread_tempdumped_records();
-		virtual std::string get_display_name();
+class CsvCDR:public BaseCDR {
+  public:
+	CsvCDR();
+	CsvCDR(switch_mod_cdr_newchannel_t * newchannel);
+	//CsvCDR(const CsvCDR& copyFrom);
+	virtual ~ CsvCDR();
+	virtual bool process_record();
+	virtual void connect(switch_xml_t & cfg, switch_xml_t & xml, switch_xml_t & settings, switch_xml_t & param);	// connect and disconnect need to be static because we're persisting connections until shutdown
+	virtual void disconnect();
+	virtual bool is_activated();
+	virtual void tempdump_record();
+	virtual void reread_tempdumped_records();
+	virtual std::string get_display_name();
 
-	private:
-		static bool activated; // Is this module activated?
-		static bool connectionstate; // What is the status of the connection?
-		static bool logchanvars;
-		static modcdr_time_convert_t convert_time;
-		static bool repeat_fixed_in_supp; // Repeat the fixed chanvars in the supplemental?
-		static std::string outputfile_path; // The directory we'll dump these into
-		static std::list<std::string> chanvars_fixed_list; // Normally this would be used, but not in this class
-		static std::list<std::string> chanvars_supp_list; // This will hold the list for all chanvars here
-		static std::string display_name;
-		char formattedcallstartdate[100];
-		char formattedcallanswerdate[100];
-		char formattedcalltransferdate[100];
-		char formattedcallenddate[100];
-		static std::ofstream outputfile;
-		static std::ofstream::pos_type filesize_limit;
-		void check_file_size_and_open(); // Checks the size of the file, and if it's greater than size allowed, rotates it.
-		void open_file();
+  private:
+	static bool activated;		// Is this module activated?
+	static bool connectionstate;	// What is the status of the connection?
+	static bool logchanvars;
+	static modcdr_time_convert_t convert_time;
+	static bool repeat_fixed_in_supp;	// Repeat the fixed chanvars in the supplemental?
+	static std::string outputfile_path;	// The directory we'll dump these into
+	static std::list < std::string > chanvars_fixed_list;	// Normally this would be used, but not in this class
+	static std::list < std::string > chanvars_supp_list;	// This will hold the list for all chanvars here
+	static std::string display_name;
+	char formattedcallstartdate[100];
+	char formattedcallanswerdate[100];
+	char formattedcalltransferdate[100];
+	char formattedcallenddate[100];
+	static std::ofstream outputfile;
+	static std::ofstream::pos_type filesize_limit;
+	void check_file_size_and_open();	// Checks the size of the file, and if it's greater than size allowed, rotates it.
+	void open_file();
 };
 
 #endif

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/curlcdr.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/curlcdr.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/curlcdr.h	Fri Mar 30 12:19:18 2007
@@ -50,37 +50,37 @@
 #ifndef CURLCDR
 #define CURLCDR
 
-class CurlCDR : public BaseCDR {
-	public:
-		CurlCDR();
-		CurlCDR(switch_mod_cdr_newchannel_t *newchannel);
-		//CurlCDR(const CurlCDR& copyFrom);
-		virtual ~CurlCDR();
-		virtual bool process_record();
-		virtual void connect(switch_xml_t& cfg, switch_xml_t& xml, switch_xml_t& settings, switch_xml_t& param); // connect and disconnect need to be static because we're persisting connections until shutdown
-		virtual void disconnect();
-		virtual bool is_activated();
-		virtual void tempdump_record();
-		virtual void reread_tempdumped_records();
-		virtual std::string get_display_name();
-    virtual std::string itos(int i);
-    virtual std::string lltos(long long ll);
+class CurlCDR:public BaseCDR {
+  public:
+	CurlCDR();
+	CurlCDR(switch_mod_cdr_newchannel_t * newchannel);
+	//CurlCDR(const CurlCDR& copyFrom);
+	virtual ~ CurlCDR();
+	virtual bool process_record();
+	virtual void connect(switch_xml_t & cfg, switch_xml_t & xml, switch_xml_t & settings, switch_xml_t & param);	// connect and disconnect need to be static because we're persisting connections until shutdown
+	virtual void disconnect();
+	virtual bool is_activated();
+	virtual void tempdump_record();
+	virtual void reread_tempdumped_records();
+	virtual std::string get_display_name();
+	virtual std::string itos(int i);
+	virtual std::string lltos(long long ll);
 
-	private:
-		static bool activated; // Is this module activated?
-		static bool connectionstate; // What is the status of the connection?
-		static bool logchanvars;
-		static modcdr_time_convert_t convert_time;
-		static const char *gateway_url; // The URL to send data to
-		static const char *gateway_credentials; // The credentials for http auth
-		static std::list<std::string> chanvars_fixed_list; // Normally this would be used, but not in this class
-		static std::list<std::string> chanvars_supp_list; // This will hold the list for all chanvars here
-		static std::string display_name;
-        static std::string postdata;
-		char formattedcallstartdate[100];
-		char formattedcallanswerdate[100];
-		char formattedcalltransferdate[100];
-		char formattedcallenddate[100];
+  private:
+	static bool activated;		// Is this module activated?
+	static bool connectionstate;	// What is the status of the connection?
+	static bool logchanvars;
+	static modcdr_time_convert_t convert_time;
+	static const char *gateway_url;	// The URL to send data to
+	static const char *gateway_credentials;	// The credentials for http auth
+	static std::list < std::string > chanvars_fixed_list;	// Normally this would be used, but not in this class
+	static std::list < std::string > chanvars_supp_list;	// This will hold the list for all chanvars here
+	static std::string display_name;
+	static std::string postdata;
+	char formattedcallstartdate[100];
+	char formattedcallanswerdate[100];
+	char formattedcalltransferdate[100];
+	char formattedcallenddate[100];
 };
 
 #endif

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/mysqlcdr.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/mysqlcdr.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/mysqlcdr.h	Fri Mar 30 12:19:18 2007
@@ -41,66 +41,66 @@
 #ifndef MYSQLCDR
 #define MYSQLCDR
 
-class MysqlCDR : public BaseCDR {
-	public:
-		MysqlCDR();
-		MysqlCDR(switch_mod_cdr_newchannel_t *newchannel);
-		//MysqlCDR(const MysqlCDR& copyFrom);
-		virtual ~MysqlCDR();
-		virtual bool process_record();
-		virtual void connect(switch_xml_t& cfg, switch_xml_t& xml, switch_xml_t& settings, switch_xml_t& param);
-		virtual void disconnect();
-		virtual bool is_activated();
-		virtual void tempdump_record();
-		virtual void reread_tempdumped_records();
-		virtual std::string get_display_name();
+class MysqlCDR:public BaseCDR {
+  public:
+	MysqlCDR();
+	MysqlCDR(switch_mod_cdr_newchannel_t * newchannel);
+	//MysqlCDR(const MysqlCDR& copyFrom);
+	virtual ~ MysqlCDR();
+	virtual bool process_record();
+	virtual void connect(switch_xml_t & cfg, switch_xml_t & xml, switch_xml_t & settings, switch_xml_t & param);
+	virtual void disconnect();
+	virtual bool is_activated();
+	virtual void tempdump_record();
+	virtual void reread_tempdumped_records();
+	virtual std::string get_display_name();
 
-	private:
-		static bool activated;
-		static char sql_query[1024];
-		static std::string tmp_sql_query; // Object must exist to bind the statement, this used for generating the sql
-		static char sql_query_chanvars[100];
-		static MYSQL *conn;
-		static MYSQL_STMT *stmt;
-		static MYSQL_STMT *stmt_chanvars;
-		static bool connectionstate;
-		static bool logchanvars;
-		static std::list<std::string> chanvars_fixed_list;
-		static std::vector<switch_mod_cdr_sql_types_t> chanvars_fixed_types;
-		static std::list<std::string> chanvars_supp_list; // The supplemental list
-		static bool repeat_fixed_in_supp;
-		static char hostname[255];
-		static char username[255];
-		static char dbname[255];
-		static char password[255];
-		static modcdr_time_convert_t convert_time;
-		static std::string display_name;
-		//static fstream tmpfile;
-		std::vector<MYSQL_BIND> bindme;
-		//MYSQL_BIND *bindme;
-		MYSQL_TIME my_callstartdate;
-		MYSQL_TIME my_callanswerdate;
-		MYSQL_TIME my_calltransferdate;
-		MYSQL_TIME my_callenddate;
-		// Why all these long unsigned int's?  MySQL's prep statement API expects these to actually exist and not just be params passed to the function calls.  The are to measure the length of actual data in the char* arrays.
-		long unsigned int clid_length;
-		long unsigned int dialplan_length;
-		long unsigned int myuuid_length;
-		long unsigned int destuuid_length;
-		long unsigned int src_length;
-		long unsigned int dst_length;
-		long unsigned int srcchannel_length;
-		long unsigned int dstchannel_length;
-		long unsigned int ani_length;
-		long unsigned int aniii_length;
-		long unsigned int lastapp_length;
-		long unsigned int lastdata_length;
-		long unsigned int network_addr_length;
-		// Now a couple internal methods
-		template <typename T> void add_parameter(T& param, enum_field_types type, bool *is_null=0);
-		void add_string_parameter(char* param, long unsigned int& param_length, enum_field_types type, bool* is_null=0);
-		void set_mysql_time(switch_time_exp_t& param, MYSQL_TIME& destination);
-		void connect_to_database();
+  private:
+	static bool activated;
+	static char sql_query[1024];
+	static std::string tmp_sql_query;	// Object must exist to bind the statement, this used for generating the sql
+	static char sql_query_chanvars[100];
+	static MYSQL *conn;
+	static MYSQL_STMT *stmt;
+	static MYSQL_STMT *stmt_chanvars;
+	static bool connectionstate;
+	static bool logchanvars;
+	static std::list < std::string > chanvars_fixed_list;
+	static std::vector < switch_mod_cdr_sql_types_t > chanvars_fixed_types;
+	static std::list < std::string > chanvars_supp_list;	// The supplemental list
+	static bool repeat_fixed_in_supp;
+	static char hostname[255];
+	static char username[255];
+	static char dbname[255];
+	static char password[255];
+	static modcdr_time_convert_t convert_time;
+	static std::string display_name;
+	//static fstream tmpfile;
+	       std::vector < MYSQL_BIND > bindme;
+	//MYSQL_BIND *bindme;
+	MYSQL_TIME my_callstartdate;
+	MYSQL_TIME my_callanswerdate;
+	MYSQL_TIME my_calltransferdate;
+	MYSQL_TIME my_callenddate;
+	// Why all these long unsigned int's?  MySQL's prep statement API expects these to actually exist and not just be params passed to the function calls.  The are to measure the length of actual data in the char* arrays.
+	long unsigned int clid_length;
+	long unsigned int dialplan_length;
+	long unsigned int myuuid_length;
+	long unsigned int destuuid_length;
+	long unsigned int src_length;
+	long unsigned int dst_length;
+	long unsigned int srcchannel_length;
+	long unsigned int dstchannel_length;
+	long unsigned int ani_length;
+	long unsigned int aniii_length;
+	long unsigned int lastapp_length;
+	long unsigned int lastdata_length;
+	long unsigned int network_addr_length;
+	// Now a couple internal methods
+	    template < typename T > void add_parameter(T & param, enum_field_types type, bool * is_null = 0);
+	void add_string_parameter(char *param, long unsigned int &param_length, enum_field_types type, bool * is_null = 0);
+	void set_mysql_time(switch_time_exp_t & param, MYSQL_TIME & destination);
+	void connect_to_database();
 };
 
 #endif

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/odbccdr.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/odbccdr.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/odbccdr.h	Fri Mar 30 12:19:18 2007
@@ -52,53 +52,53 @@
 #ifndef ODBCCDR
 #define ODBCCDR
 
-class OdbcCDR : public BaseCDR {
-	public:
-		OdbcCDR();
-		OdbcCDR(switch_mod_cdr_newchannel_t *newchannel);
-		//OdbcCDR(const MysqlCDR& copyFrom);
-		virtual ~OdbcCDR();
-		virtual bool process_record();
-		virtual void connect(switch_xml_t& cfg, switch_xml_t& xml, switch_xml_t& settings, switch_xml_t& param);
-		virtual void disconnect();
-		virtual bool is_activated();
-		virtual void tempdump_record();
-		virtual void reread_tempdumped_records();
-		virtual std::string get_display_name();
+class OdbcCDR:public BaseCDR {
+  public:
+	OdbcCDR();
+	OdbcCDR(switch_mod_cdr_newchannel_t * newchannel);
+	//OdbcCDR(const MysqlCDR& copyFrom);
+	virtual ~ OdbcCDR();
+	virtual bool process_record();
+	virtual void connect(switch_xml_t & cfg, switch_xml_t & xml, switch_xml_t & settings, switch_xml_t & param);
+	virtual void disconnect();
+	virtual bool is_activated();
+	virtual void tempdump_record();
+	virtual void reread_tempdumped_records();
+	virtual std::string get_display_name();
 
-	private:
-		static bool activated;
-		static char sql_query[1024];
-		static modcdr_time_convert_t convert_time;
-		static std::string display_name;
-		static std::string tmp_sql_query; // Object must exist to bind the statement, this used for generating the sql
-		static char sql_query_chanvars[355];
-		static char sql_query_ping[10];
-		static bool connectionstate;
-		static bool logchanvars;
-		static SQLHENV ODBC_env;     /* global ODBC Environment */
-		static SQLHDBC ODBC_con;     /* global ODBC Connection Handle */
-		static SQLHSTMT ODBC_stmt;
-		static SQLHSTMT ODBC_stmt_chanvars;
-		static SQLHSTMT ODBC_stmt_ping;
-		static std::list<std::string> chanvars_fixed_list;
-		static std::vector<switch_mod_cdr_sql_types_t> chanvars_fixed_types;
-		static std::list<std::string> chanvars_supp_list; // The supplemental list
-		static bool repeat_fixed_in_supp;
-		static char dsn[255];
-		static char hostname[255];
-		static char username[255];
-		static char dbname[255];
-		static char password[255];
-		static char tablename[255];
-		static char tablename_chanvars[255];
-		//static fstream tmpfile;
-		char odbc_callstartdate[128];
-		char odbc_callanswerdate[128];
-		char odbc_calltransferdate[128];
-		char odbc_callenddate[128];
-		void disconnect_stage_1();
-		void connect_to_database();
+  private:
+	static bool activated;
+	static char sql_query[1024];
+	static modcdr_time_convert_t convert_time;
+	static std::string display_name;
+	static std::string tmp_sql_query;	// Object must exist to bind the statement, this used for generating the sql
+	static char sql_query_chanvars[355];
+	static char sql_query_ping[10];
+	static bool connectionstate;
+	static bool logchanvars;
+	static SQLHENV ODBC_env;	/* global ODBC Environment */
+	static SQLHDBC ODBC_con;	/* global ODBC Connection Handle */
+	static SQLHSTMT ODBC_stmt;
+	static SQLHSTMT ODBC_stmt_chanvars;
+	static SQLHSTMT ODBC_stmt_ping;
+	static std::list < std::string > chanvars_fixed_list;
+	static std::vector < switch_mod_cdr_sql_types_t > chanvars_fixed_types;
+	static std::list < std::string > chanvars_supp_list;	// The supplemental list
+	static bool repeat_fixed_in_supp;
+	static char dsn[255];
+	static char hostname[255];
+	static char username[255];
+	static char dbname[255];
+	static char password[255];
+	static char tablename[255];
+	static char tablename_chanvars[255];
+	//static fstream tmpfile;
+	char odbc_callstartdate[128];
+	char odbc_callanswerdate[128];
+	char odbc_calltransferdate[128];
+	char odbc_callenddate[128];
+	void disconnect_stage_1();
+	void connect_to_database();
 };
 
 #endif

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/pddcdr.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/pddcdr.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/pddcdr.h	Fri Mar 30 12:19:18 2007
@@ -43,33 +43,33 @@
 #ifndef PDDCDR
 #define PDDMCDR
 
-class PddCDR : public BaseCDR {
-	public:
-		PddCDR();
-		PddCDR(switch_mod_cdr_newchannel_t *newchannel);
-		virtual ~PddCDR();
-		virtual bool process_record();
-		virtual void connect(switch_xml_t& cfg, switch_xml_t& xml, switch_xml_t& settings, switch_xml_t& param); // connect and disconnect need to be static because we're persisting connections until shutdown
-		virtual void disconnect();
-		virtual bool is_activated();
-		virtual void tempdump_record();
-		virtual void reread_tempdumped_records();
-		virtual std::string get_display_name();
-	private:
-		static bool activated; // Is this module activated?
-		static bool connectionstate; // What is the status of the connection?
-		static bool logchanvars;
-		static modcdr_time_convert_t convert_time;
-		static std::string outputfile_path; // The directory we'll dump these into
-		static std::list<std::string> chanvars_fixed_list; // Normally this would be used, but not in this class
-		static std::list<std::string> chanvars_supp_list; // This will hold the list for all chanvars here
-		static std::string display_name;
-		char formattedcallstartdate[100];
-		char formattedcallanswerdate[100];
-		char formattedcalltransferdate[100];
-		char formattedcallenddate[100];
-		std::string outputfile_name;
-		std::ofstream outputfile;
+class PddCDR:public BaseCDR {
+  public:
+	PddCDR();
+	PddCDR(switch_mod_cdr_newchannel_t * newchannel);
+	virtual ~ PddCDR();
+	virtual bool process_record();
+	virtual void connect(switch_xml_t & cfg, switch_xml_t & xml, switch_xml_t & settings, switch_xml_t & param);	// connect and disconnect need to be static because we're persisting connections until shutdown
+	virtual void disconnect();
+	virtual bool is_activated();
+	virtual void tempdump_record();
+	virtual void reread_tempdumped_records();
+	virtual std::string get_display_name();
+  private:
+	static bool activated;		// Is this module activated?
+	static bool connectionstate;	// What is the status of the connection?
+	static bool logchanvars;
+	static modcdr_time_convert_t convert_time;
+	static std::string outputfile_path;	// The directory we'll dump these into
+	static std::list < std::string > chanvars_fixed_list;	// Normally this would be used, but not in this class
+	static std::list < std::string > chanvars_supp_list;	// This will hold the list for all chanvars here
+	static std::string display_name;
+	char formattedcallstartdate[100];
+	char formattedcallanswerdate[100];
+	char formattedcalltransferdate[100];
+	char formattedcallenddate[100];
+	     std::string outputfile_name;
+	     std::ofstream outputfile;
 };
 
 #endif

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/sqlitecdr.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/sqlitecdr.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/sqlitecdr.h	Fri Mar 30 12:19:18 2007
@@ -39,43 +39,43 @@
 #ifndef SQLITECDR
 #define SQLITECDR
 
-class SqliteCDR : public BaseCDR {
-	public:
-		SqliteCDR();
-		SqliteCDR(switch_mod_cdr_newchannel_t *newchannel);
-		//SqliteCDR(const SqliteCDR& copyFrom);
-		virtual ~SqliteCDR();
-		virtual bool process_record();
-		virtual void connect(switch_xml_t& cfg, switch_xml_t& xml, switch_xml_t& settings, switch_xml_t& param);
-		virtual void disconnect();
-		virtual bool is_activated();
-		virtual void tempdump_record();
-		virtual void reread_tempdumped_records();
-		virtual std::string get_display_name();
+class SqliteCDR:public BaseCDR {
+  public:
+	SqliteCDR();
+	SqliteCDR(switch_mod_cdr_newchannel_t * newchannel);
+	//SqliteCDR(const SqliteCDR& copyFrom);
+	virtual ~ SqliteCDR();
+	virtual bool process_record();
+	virtual void connect(switch_xml_t & cfg, switch_xml_t & xml, switch_xml_t & settings, switch_xml_t & param);
+	virtual void disconnect();
+	virtual bool is_activated();
+	virtual void tempdump_record();
+	virtual void reread_tempdumped_records();
+	virtual std::string get_display_name();
 
-	private:
-		static bool activated;
-		static char sql_query[1024];
-		static std::string tmp_sql_query; // Object must exist to bind the statement, this used for generating the sql
-		static char sql_query_chanvars[100];
-		static std::string db_filename;
-		static bool use_utc_time;
-		switch_time_t sqlite_callstartdate;
-		switch_time_t sqlite_callanswerdate;
-		switch_time_t sqlite_calltransferdate;
-		switch_time_t sqlite_callenddate;
-		static switch_core_db_t *db;
-		static switch_core_db_stmt_t *stmt;
-		static switch_core_db_stmt_t *stmt_chanvars;
-		static switch_core_db_stmt_t *stmt_begin;
-		static switch_core_db_stmt_t *stmt_commit;
-		static bool connectionstate;
-		static bool logchanvars;
-		static std::list<std::string> chanvars_fixed_list;
-		static std::vector<switch_mod_cdr_sql_types_t> chanvars_fixed_types;
-		static std::list<std::string> chanvars_supp_list; // The supplemental list
-		static bool repeat_fixed_in_supp;
-		static std::string display_name;
+  private:
+	static bool activated;
+	static char sql_query[1024];
+	static std::string tmp_sql_query;	// Object must exist to bind the statement, this used for generating the sql
+	static char sql_query_chanvars[100];
+	static std::string db_filename;
+	static bool use_utc_time;
+	switch_time_t sqlite_callstartdate;
+	switch_time_t sqlite_callanswerdate;
+	switch_time_t sqlite_calltransferdate;
+	switch_time_t sqlite_callenddate;
+	static switch_core_db_t *db;
+	static switch_core_db_stmt_t *stmt;
+	static switch_core_db_stmt_t *stmt_chanvars;
+	static switch_core_db_stmt_t *stmt_begin;
+	static switch_core_db_stmt_t *stmt_commit;
+	static bool connectionstate;
+	static bool logchanvars;
+	static std::list < std::string > chanvars_fixed_list;
+	static std::vector < switch_mod_cdr_sql_types_t > chanvars_fixed_types;
+	static std::list < std::string > chanvars_supp_list;	// The supplemental list
+	static bool repeat_fixed_in_supp;
+	static std::string display_name;
 };
 
 #endif

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/xmlcdr.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/xmlcdr.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/xmlcdr.h	Fri Mar 30 12:19:18 2007
@@ -43,34 +43,34 @@
 #ifndef XMLCDR
 #define XMLCDR
 
-class XmlCDR : public BaseCDR {
-	public:
-		XmlCDR();
-		XmlCDR(switch_mod_cdr_newchannel_t *newchannel);
-		virtual ~XmlCDR();
-		virtual bool process_record();
-		virtual void connect(switch_xml_t& cfg, switch_xml_t& xml, switch_xml_t& settings, switch_xml_t& param); // connect and disconnect need to be static because we're persisting connections until shutdown
-		virtual void disconnect();
-		virtual bool is_activated();
-		virtual void tempdump_record();
-		virtual void reread_tempdumped_records();
-		virtual std::string get_display_name();
+class XmlCDR:public BaseCDR {
+  public:
+	XmlCDR();
+	XmlCDR(switch_mod_cdr_newchannel_t * newchannel);
+	virtual ~ XmlCDR();
+	virtual bool process_record();
+	virtual void connect(switch_xml_t & cfg, switch_xml_t & xml, switch_xml_t & settings, switch_xml_t & param);	// connect and disconnect need to be static because we're persisting connections until shutdown
+	virtual void disconnect();
+	virtual bool is_activated();
+	virtual void tempdump_record();
+	virtual void reread_tempdumped_records();
+	virtual std::string get_display_name();
 
-	private:
-		static bool activated; // Is this module activated?
-		static bool connectionstate; // What is the status of the connection?
-		static bool logchanvars;
-		static modcdr_time_convert_t convert_time;
-		static std::string outputfile_path; // The directory we'll dump these into
-		static std::list<std::string> chanvars_fixed_list; // Normally this would be used, but not in this class
-		static std::list<std::string> chanvars_supp_list; // This will hold the list for all chanvars here
-		static std::string display_name;
-		char formattedcallstartdate[100];
-		char formattedcallanswerdate[100];
-		char formattedcalltransferdate[100];
-		char formattedcallenddate[100];
-		std::string outputfile_name;
-		std::ofstream outputfile;
+  private:
+	static bool activated;		// Is this module activated?
+	static bool connectionstate;	// What is the status of the connection?
+	static bool logchanvars;
+	static modcdr_time_convert_t convert_time;
+	static std::string outputfile_path;	// The directory we'll dump these into
+	static std::list < std::string > chanvars_fixed_list;	// Normally this would be used, but not in this class
+	static std::list < std::string > chanvars_supp_list;	// This will hold the list for all chanvars here
+	static std::string display_name;
+	char formattedcallstartdate[100];
+	char formattedcallanswerdate[100];
+	char formattedcalltransferdate[100];
+	char formattedcallenddate[100];
+	     std::string outputfile_name;
+	     std::ofstream outputfile;
 };
 
 #endif

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c	Fri Mar 30 12:19:18 2007
@@ -46,17 +46,13 @@
 	switch_sockaddr_t *addr;
 	switch_socket_t *udp_socket;
 	switch_hash_t *event_hash;
-	uint8_t event_list[SWITCH_EVENT_ALL+1];
+	uint8_t event_list[SWITCH_EVENT_ALL + 1];
 	int running;
 } globals;
 
 SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_address, globals.address)
-SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_bindings, globals.bindings)
-
-
+	SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_bindings, globals.bindings)
 #define MULTICAST_EVENT "multicast::event"
-
-
 	 static switch_status_t load_config(void)
 {
 	switch_status_t status = SWITCH_STATUS_SUCCESS;
@@ -80,7 +76,7 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't register subclass!");
 		return SWITCH_STATUS_GENERR;
 	}
-	
+
 	if ((settings = switch_xml_child(cfg, "settings"))) {
 		for (param = switch_xml_child(settings, "param"); param; param = param->next) {
 			char *var = (char *) switch_xml_attr_soft(param, "name");
@@ -91,7 +87,7 @@
 			} else if (!strcasecmp(var, "bindings")) {
 				set_global_bindings(val);
 			} else if (!strcasecmp(var, "port")) {
-				globals.port = (switch_port_t)atoi(val);
+				globals.port = (switch_port_t) atoi(val);
 			}
 		}
 	}
@@ -100,13 +96,13 @@
 
 
 	if (globals.bindings) {
-		for(cur = globals.bindings; cur; count++) {
+		for (cur = globals.bindings; cur; count++) {
 			switch_event_types_t type;
 
 			if ((next = strchr(cur, ' '))) {
 				*next++ = '\0';
 			}
-				
+
 			if (custom) {
 				switch_core_hash_insert_dup(globals.event_hash, cur, MARKER);
 			} else if (switch_name_event(cur, &type) == SWITCH_STATUS_SUCCESS) {
@@ -143,22 +139,21 @@
 
 
 	if (event->subclass && !strcmp(event->subclass->name, MULTICAST_EVENT)) {
-		/* ignore our own events to avoid ping pong*/
+		/* ignore our own events to avoid ping pong */
 		return;
 	}
 
-	if (globals.event_list[(uint8_t)SWITCH_EVENT_ALL]) {
+	if (globals.event_list[(uint8_t) SWITCH_EVENT_ALL]) {
 		send = 1;
-	} else if ((globals.event_list[(uint8_t)event->event_id])) {
-		if (event->event_id != SWITCH_EVENT_CUSTOM || 
-			(event->subclass && switch_core_hash_find(globals.event_hash, event->subclass->name))) {
+	} else if ((globals.event_list[(uint8_t) event->event_id])) {
+		if (event->event_id != SWITCH_EVENT_CUSTOM || (event->subclass && switch_core_hash_find(globals.event_hash, event->subclass->name))) {
 			send = 1;
 		}
 	}
 
 	if (send) {
 		char *packet;
-		
+
 		switch (event->event_id) {
 		case SWITCH_EVENT_LOG:
 			return;
@@ -199,7 +194,7 @@
 	}
 
 	switch_core_hash_init(&globals.event_hash, module_pool);
-	
+
 	if (load_config() != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Configure\n");
 		return SWITCH_STATUS_TERM;
@@ -214,7 +209,7 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Socket Error\n");
 		return SWITCH_STATUS_TERM;
 	}
-	
+
 	if (switch_socket_opt_set(globals.udp_socket, SWITCH_SO_REUSEADDR, 1) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Socket Option Error\n");
 		switch_socket_close(globals.udp_socket);
@@ -224,7 +219,7 @@
 	if (switch_mcast_join(globals.udp_socket, globals.addr, NULL, NULL) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Multicast Error\n");
 		switch_socket_close(globals.udp_socket);
-        return SWITCH_STATUS_TERM;
+		return SWITCH_STATUS_TERM;
 	}
 
 	if (switch_socket_bind(globals.udp_socket, globals.addr) != SWITCH_STATUS_SUCCESS) {
@@ -238,9 +233,8 @@
 	/* connect my internal structure to the blank pointer passed to me */
 	*module_interface = &event_test_module_interface;
 
-	
-	if (switch_event_bind((char *) modname, SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL) !=
-		SWITCH_STATUS_SUCCESS) {
+
+	if (switch_event_bind((char *) modname, SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
 		switch_socket_close(globals.udp_socket);
 		return SWITCH_STATUS_GENERR;
@@ -258,7 +252,7 @@
 
 	switch_socket_shutdown(globals.udp_socket, SWITCH_SHUTDOWN_READWRITE);
 	globals.running = -1;
-	while(x < 100000 && globals.running) {
+	while (x < 100000 && globals.running) {
 		x++;
 		switch_yield(1000);
 	}
@@ -269,16 +263,16 @@
 SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
 {
 	switch_event_t *local_event;
-	char buf[65536] = {0};
+	char buf[65536] = { 0 };
 	switch_sockaddr_t *addr;
 
 	switch_sockaddr_info_get(&addr, NULL, SWITCH_UNSPEC, 0, 0, module_pool);
 	globals.running = 1;
-	while(globals.running == 1) {
+	while (globals.running == 1) {
 		char *myaddr;
 		size_t len = sizeof(buf);
 		memset(buf, 0, len);
-		
+
 		switch_sockaddr_ip_get(&myaddr, globals.addr);
 
 		if (switch_socket_recvfrom(addr, globals.udp_socket, 0, buf, &len) == SWITCH_STATUS_SUCCESS) {
@@ -287,25 +281,24 @@
 
 			memcpy(&host_hash, buf, sizeof(host_hash));
 			packet = buf + sizeof(host_hash);
-			
+
 			if (host_hash == globals.host_hash) {
 				continue;
 			}
-
 			//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "\nEVENT %d\n--------------------------------\n%s\n", (int) len, packet);
 			if (switch_event_create_subclass(&local_event, SWITCH_EVENT_CUSTOM, MULTICAST_EVENT) == SWITCH_STATUS_SUCCESS) {
 				char *var, *val, *term = NULL, tmpname[128];
 				switch_event_add_header(local_event, SWITCH_STACK_BOTTOM, "Multicast", "yes");
 				var = packet;
-				while(*var) {
+				while (*var) {
 					if ((val = strchr(var, ':')) != 0) {
 						*val++ = '\0';
-						while(*val == ' ') {
+						while (*val == ' ') {
 							val++;
 						}
-						if ((term = strchr(val, '\r')) != 0 || (term=strchr(val, '\n')) != 0) {
+						if ((term = strchr(val, '\r')) != 0 || (term = strchr(val, '\n')) != 0) {
 							*term = '\0';
-							while(*term == '\r' || *term == '\n') {
+							while (*term == '\r' || *term == '\n') {
 								term++;
 							}
 						}
@@ -315,18 +308,18 @@
 					} else {
 						break;
 					}
-				} 
+				}
 
 				if (var && strlen(var) > 1) {
 					switch_event_add_body(local_event, var);
 				}
 
 				switch_event_fire(&local_event);
-			
+
 			}
 		}
 	}
-		
+
 	globals.running = 0;
 	return SWITCH_STATUS_TERM;
 }

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_event_socket/mod_event_socket.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_event_socket/mod_event_socket.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_event_socket/mod_event_socket.c	Fri Mar 30 12:19:18 2007
@@ -61,10 +61,10 @@
 	uint32_t flags;
 	switch_log_level_t level;
 	char *ebuf;
-	uint8_t event_list[SWITCH_EVENT_ALL+1];
+	uint8_t event_list[SWITCH_EVENT_ALL + 1];
 	switch_hash_t *event_hash;
 	switch_thread_rwlock_t *rwlock;
-    switch_core_session_t *session;
+	switch_core_session_t *session;
 	struct listener *next;
 };
 
@@ -86,15 +86,15 @@
 } prefs;
 
 SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_pref_ip, prefs.ip)
-SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_pref_pass, prefs.password)
+	SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_pref_pass, prefs.password)
 
-static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t *thread, void *obj);
-static void launch_listener_thread(listener_t *listener);
+	 static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t * thread, void *obj);
+	 static void launch_listener_thread(listener_t * listener);
 
-static switch_status_t socket_logger(const switch_log_node_t *node, switch_log_level_t level)
+	 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);
 	for (l = listen_list.listeners; l; l = l->next) {
 		if (switch_test_flag(l, LFLAG_LOG) && l->level >= node->level) {
@@ -121,7 +121,7 @@
 	if (!listen_list.ready) {
 		return;
 	}
-	
+
 	switch_mutex_lock(listen_list.mutex);
 	for (l = listen_list.listeners; l; l = l->next) {
 		uint8_t send = 0;
@@ -130,21 +130,21 @@
 			continue;
 		}
 
-        if (l->event_list[(uint8_t)SWITCH_EVENT_ALL]) {
+		if (l->event_list[(uint8_t) SWITCH_EVENT_ALL]) {
 			send = 1;
-		} else if ((l->event_list[(uint8_t)event->event_id])) {
+		} else if ((l->event_list[(uint8_t) event->event_id])) {
 			if (event->event_id != SWITCH_EVENT_CUSTOM || (event->subclass && switch_core_hash_find(l->event_hash, event->subclass->name))) {
 				send = 1;
 			}
 		}
 
-        if (send && switch_test_flag(l, LFLAG_MYEVENTS)) {
-            char *uuid = switch_event_get_header(event, "unique-id");
-            if (!uuid || strcmp(uuid, switch_core_session_get_uuid(l->session))) {
-                send = 1;
-            }
-        }
-        
+		if (send && switch_test_flag(l, LFLAG_MYEVENTS)) {
+			char *uuid = switch_event_get_header(event, "unique-id");
+			if (!uuid || strcmp(uuid, switch_core_session_get_uuid(l->session))) {
+				send = 1;
+			}
+		}
+
 		if (send) {
 			if (switch_event_dup(&clone, event) == SWITCH_STATUS_SUCCESS) {
 				switch_queue_push(l->event_queue, clone);
@@ -159,101 +159,102 @@
 
 static void socket_function(switch_core_session_t *session, char *data)
 {
-    char *host, *port_name;
-    switch_socket_t *new_sock;
-    switch_sockaddr_t *sa;
-    switch_port_t port = 8084;
-    listener_t *listener;
+	char *host, *port_name;
+	switch_socket_t *new_sock;
+	switch_sockaddr_t *sa;
+	switch_port_t port = 8084;
+	listener_t *listener;
 	int argc = 0, x = 0;
-	char *argv[80] = {0};
+	char *argv[80] = { 0 };
 	char *mydata;
 
 	if (data && (mydata = switch_core_session_strdup(session, data))) {
 		argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
-	} 
+	}
+
+	if (argc < 1) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
+		return;
+	}
+
+	host = argv[0];
 
-    if (argc < 1) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
-        return;
-    }
-
-    host = argv[0];
-
-    if (switch_strlen_zero(host)) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing Host!\n");
-        return;
-    }
-
-    if ((port_name = strchr(host, ':'))) {
-        *port_name++ = '\0';
-        port = (switch_port_t)atoi(port_name);
-    }
+	if (switch_strlen_zero(host)) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing Host!\n");
+		return;
+	}
+
+	if ((port_name = strchr(host, ':'))) {
+		*port_name++ = '\0';
+		port = (switch_port_t) atoi(port_name);
+	}
 
 	if (switch_sockaddr_info_get(&sa, host, AF_INET, port, 0, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Socket Error!\n");
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Socket Error!\n");
 		return;
 	}
 
-	if (switch_socket_create(&new_sock, AF_INET, SOCK_STREAM, SWITCH_PROTO_TCP, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Socket Error!\n");
+	if (switch_socket_create(&new_sock, AF_INET, SOCK_STREAM, SWITCH_PROTO_TCP, switch_core_session_get_pool(session))
+		!= SWITCH_STATUS_SUCCESS) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Socket Error!\n");
 		return;
 	}
 
-    switch_socket_opt_set(new_sock, SWITCH_SO_KEEPALIVE, 1);
+	switch_socket_opt_set(new_sock, SWITCH_SO_KEEPALIVE, 1);
 
 	if (switch_socket_connect(new_sock, sa) != SWITCH_STATUS_SUCCESS) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Socket Error!\n");
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Socket Error!\n");
+		return;
+	}
+
+
+	if (!(listener = switch_core_session_alloc(session, sizeof(*listener)))) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error\n");
 		return;
 	}
 
+	switch_thread_rwlock_create(&listener->rwlock, switch_core_session_get_pool(session));
+	switch_queue_create(&listener->event_queue, SWITCH_CORE_QUEUE_LEN, switch_core_session_get_pool(session));
+	switch_queue_create(&listener->log_queue, SWITCH_CORE_QUEUE_LEN, switch_core_session_get_pool(session));
+
+	listener->sock = new_sock;
+	listener->pool = switch_core_session_get_pool(session);
+	listener->format = EVENT_FORMAT_PLAIN;
+	listener->session = session;
+
+	switch_mutex_init(&listener->flag_mutex, SWITCH_MUTEX_NESTED, listener->pool);
+	switch_core_hash_init(&listener->event_hash, listener->pool);
+	switch_set_flag(listener, LFLAG_AUTHED);
+	for (x = 1; x < argc; x++) {
+		if (argv[x] && !strcasecmp(argv[x], "full")) {
+			switch_set_flag(listener, LFLAG_FULL);
+		} else if (argv[x] && !strcasecmp(argv[x], "async")) {
+			switch_set_flag(listener, LFLAG_ASYNC);
+		}
+	}
+
+	if (switch_test_flag(listener, LFLAG_ASYNC)) {
+		launch_listener_thread(listener);
+		switch_ivr_park(session, NULL);
+	} else {
+		listener_run(NULL, (void *) listener);
+	}
+
+	while (switch_test_flag(listener, LFLAG_SESSION)) {
+		switch_yield(100000);
+	}
 
-    if (!(listener = switch_core_session_alloc(session, sizeof(*listener)))) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error\n");
-        return;
-    }
-		
-    switch_thread_rwlock_create(&listener->rwlock, switch_core_session_get_pool(session));
-    switch_queue_create(&listener->event_queue, SWITCH_CORE_QUEUE_LEN, switch_core_session_get_pool(session));
-    switch_queue_create(&listener->log_queue, SWITCH_CORE_QUEUE_LEN, switch_core_session_get_pool(session));
-
-    listener->sock = new_sock;
-    listener->pool = switch_core_session_get_pool(session);
-    listener->format = EVENT_FORMAT_PLAIN;
-    listener->session = session;
-    
-    switch_mutex_init(&listener->flag_mutex, SWITCH_MUTEX_NESTED, listener->pool);
-    switch_core_hash_init(&listener->event_hash, listener->pool);
-    switch_set_flag(listener, LFLAG_AUTHED);
-    for(x = 1; x < argc; x++) {
-        if (argv[x] && !strcasecmp(argv[x], "full")) {
-            switch_set_flag(listener, LFLAG_FULL);
-        } else if (argv[x] && !strcasecmp(argv[x], "async")) {
-            switch_set_flag(listener, LFLAG_ASYNC);
-        }
-    }
-    
-    if (switch_test_flag(listener, LFLAG_ASYNC)) {
-        launch_listener_thread(listener);
-        switch_ivr_park(session, NULL);
-    } else {
-        listener_run(NULL, (void*) listener);
-    }
-
-    while(switch_test_flag(listener, LFLAG_SESSION)) {
-        switch_yield(100000);
-    }
-    
 }
 
 
 static const switch_application_interface_t socket_application_interface = {
-    /*.interface_name */ "socket",
-    /*.application_function */ socket_function,
-    /* long_desc */ "Connect to a socket",
-    /* short_desc */ "Connect to a socket",
-    /* syntax */ "<ip>[:<port>]",
+	/*.interface_name */ "socket",
+	/*.application_function */ socket_function,
+	/* long_desc */ "Connect to a socket",
+	/* short_desc */ "Connect to a socket",
+	/* syntax */ "<ip>[:<port>]",
 	/* flags */ SAF_SUPPORT_NOMEDIA,
-    /*.next */ NULL
+	/*.next */ NULL
 };
 
 
@@ -268,7 +269,8 @@
 };
 
 
-static void close_socket(switch_socket_t **sock) {
+static void close_socket(switch_socket_t ** sock)
+{
 	switch_mutex_lock(listen_list.sock_mutex);
 	if (*sock) {
 		switch_socket_shutdown(*sock, SWITCH_SHUTDOWN_READWRITE);
@@ -308,7 +310,7 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static void add_listener(listener_t *listener) 
+static void add_listener(listener_t * listener)
 {
 	/* add me to the listeners so I get events */
 	switch_mutex_lock(listen_list.mutex);
@@ -317,7 +319,7 @@
 	switch_mutex_unlock(listen_list.mutex);
 }
 
-static void remove_listener(listener_t *listener)
+static void remove_listener(listener_t * listener)
 {
 	listener_t *l, *last = NULL;
 
@@ -343,7 +345,7 @@
 	}
 }
 
-static switch_status_t read_packet(listener_t *listener, switch_event_t **event, uint32_t timeout) 
+static switch_status_t read_packet(listener_t * listener, switch_event_t **event, uint32_t timeout)
 {
 	switch_size_t mlen, bytes = 0;
 	char mbuf[2048] = "";
@@ -361,7 +363,7 @@
 	start = time(NULL);
 	ptr = mbuf;
 
-	while(listener->sock) {
+	while (listener->sock) {
 		uint8_t do_sleep = 1;
 		mlen = 1;
 		status = switch_socket_recv(listener->sock, ptr, &mlen);
@@ -370,16 +372,16 @@
 			return SWITCH_STATUS_FALSE;
 		}
 
-        if (listener->session && !switch_channel_ready(switch_core_session_get_channel(listener->session))) {
-            status = SWITCH_STATUS_FALSE;
-            break;
-        }
+		if (listener->session && !switch_channel_ready(switch_core_session_get_channel(listener->session))) {
+			status = SWITCH_STATUS_FALSE;
+			break;
+		}
 
 		if (mlen) {
 			bytes += mlen;
 			do_sleep = 0;
 
-			if (*mbuf == '\r' || *mbuf == '\n') { /* bah */
+			if (*mbuf == '\r' || *mbuf == '\n') {	/* bah */
 				ptr = mbuf;
 				mbuf[0] = '\0';
 				bytes = 0;
@@ -401,7 +403,7 @@
 				char *next;
 				char *cur = mbuf;
 				bytes = 0;
-				while(cur) {
+				while (cur) {
 					if ((next = strchr(cur, '\r')) || (next = strchr(cur, '\n'))) {
 						while (*next == '\r' || *next == '\n') {
 							next++;
@@ -418,30 +420,30 @@
 						if (!switch_strlen_zero(var)) {
 							if ((val = strchr(var, ':'))) {
 								*val++ = '\0';
-								while(*val == ' ') {
+								while (*val == ' ') {
 									val++;
 								}
-							} 
+							}
 							if (var && val) {
 								switch_event_add_header(*event, SWITCH_STACK_BOTTOM, var, "%s", val);
 							}
 						}
 					}
-					
+
 					cur = next;
 				}
 				break;
 			}
 		}
-        
+
 		if (timeout) {
-			elapsed = (uint32_t)(time(NULL) - start);
+			elapsed = (uint32_t) (time(NULL) - start);
 			if (elapsed >= timeout) {
 				switch_clear_flag_locked(listener, LFLAG_RUNNING);
 				return SWITCH_STATUS_FALSE;
 			}
 		}
-		
+
 		if (!*mbuf) {
 			if (switch_test_flag(listener, LFLAG_LOG)) {
 				if (switch_queue_trypop(listener->log_queue, &pop) == SWITCH_STATUS_SUCCESS) {
@@ -449,12 +451,12 @@
 
 
 					if (data) {
-						snprintf(buf, sizeof(buf), "Content-Type: log/data\nContent-Length: %"SWITCH_SSIZE_T_FMT"\n\n", strlen(data));
+						snprintf(buf, sizeof(buf), "Content-Type: log/data\nContent-Length: %" SWITCH_SSIZE_T_FMT "\n\n", strlen(data));
 						len = strlen(buf);
 						switch_socket_send(listener->sock, buf, &len);
 						len = strlen(data);
 						switch_socket_send(listener->sock, data, &len);
-					
+
 						free(data);
 					}
 					do_sleep = 0;
@@ -483,12 +485,10 @@
 							continue;
 						}
 					}
-			
+
 					len = strlen(listener->ebuf);
 
-					snprintf(hbuf, sizeof(hbuf), "Content-Length: %"SWITCH_SSIZE_T_FMT"\n" 
-							 "Content-Type: text/event-%s\n"
-							 "\n", len, etype);
+					snprintf(hbuf, sizeof(hbuf), "Content-Length: %" SWITCH_SSIZE_T_FMT "\n" "Content-Type: text/event-%s\n" "\n", len, etype);
 
 					len = strlen(hbuf);
 					switch_socket_send(listener->sock, hbuf, &len);
@@ -519,13 +519,13 @@
 	uint8_t bg;
 };
 
-static void *SWITCH_THREAD_FUNC api_exec(switch_thread_t *thread, void *obj)
+static void *SWITCH_THREAD_FUNC api_exec(switch_thread_t * thread, void *obj)
 {
 
 	struct api_command_struct *acs = (struct api_command_struct *) obj;
-	switch_stream_handle_t stream = {0};
-    char *reply, *freply = NULL;
-    switch_status_t status;
+	switch_stream_handle_t stream = { 0 };
+	char *reply, *freply = NULL;
+	switch_status_t status;
 
 	if (switch_thread_rwlock_tryrdlock(acs->listener->rwlock) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error! cannot get read lock.\n");
@@ -535,42 +535,42 @@
 
 	SWITCH_STANDARD_STREAM(stream);
 
-    if ((status = switch_api_execute(acs->api_cmd, acs->arg, NULL, &stream)) == SWITCH_STATUS_SUCCESS) {
-        reply = stream.data;
-    } else {
-        freply = switch_mprintf("%s: Command not found!", acs->api_cmd);
-        reply = freply;
-    }
-        
-    if (!reply) {
-        reply = "Command returned no output!";
-    }
-    
-    if (acs->bg) {
-        switch_event_t *event;
-        
-        if (switch_event_create(&event, SWITCH_EVENT_BACKGROUND_JOB) == SWITCH_STATUS_SUCCESS) {
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Job-UUID", "%s", acs->uuid_str);
-            switch_event_add_body(event, "%s", reply);
-            switch_event_fire(&event);
-        }
-    } else {
-        switch_size_t rlen, blen;
-        char buf[1024] = "";
-        rlen = strlen(reply);			
-        snprintf(buf, sizeof(buf), "Content-Type: api/response\nContent-Length: %"SWITCH_SSIZE_T_FMT"\n\n", rlen);
-        blen = strlen(buf);
-        switch_socket_send(acs->listener->sock, buf, &blen);
-        switch_socket_send(acs->listener->sock, reply, &rlen);
-    }
-		
-    switch_safe_free(stream.data);
-    switch_safe_free(freply);
+	if ((status = switch_api_execute(acs->api_cmd, acs->arg, NULL, &stream)) == SWITCH_STATUS_SUCCESS) {
+		reply = stream.data;
+	} else {
+		freply = switch_mprintf("%s: Command not found!", acs->api_cmd);
+		reply = freply;
+	}
+
+	if (!reply) {
+		reply = "Command returned no output!";
+	}
+
+	if (acs->bg) {
+		switch_event_t *event;
+
+		if (switch_event_create(&event, SWITCH_EVENT_BACKGROUND_JOB) == SWITCH_STATUS_SUCCESS) {
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Job-UUID", "%s", acs->uuid_str);
+			switch_event_add_body(event, "%s", reply);
+			switch_event_fire(&event);
+		}
+	} else {
+		switch_size_t rlen, blen;
+		char buf[1024] = "";
+		rlen = strlen(reply);
+		snprintf(buf, sizeof(buf), "Content-Type: api/response\nContent-Length: %" SWITCH_SSIZE_T_FMT "\n\n", rlen);
+		blen = strlen(buf);
+		switch_socket_send(acs->listener->sock, buf, &blen);
+		switch_socket_send(acs->listener->sock, reply, &rlen);
+	}
+
+	switch_safe_free(stream.data);
+	switch_safe_free(freply);
 
 	switch_thread_rwlock_unlock(acs->listener->rwlock);
-	
 
- done:
+
+  done:
 	if (acs && acs->bg) {
 		if (acs->api_cmd) {
 			free(acs->api_cmd);
@@ -581,9 +581,9 @@
 		free(acs);
 	}
 	return NULL;
-	
+
 }
-static switch_status_t parse_command(listener_t *listener, switch_event_t *event, char *reply, uint32_t reply_len)
+static switch_status_t parse_command(listener_t * listener, switch_event_t *event, char *reply, uint32_t reply_len)
 {
 	switch_status_t status = SWITCH_STATUS_SUCCESS;
 	char *cmd = switch_event_get_header(event, "command");
@@ -618,70 +618,70 @@
 	}
 
 
-    if (listener->session) {
-        switch_channel_t *channel = switch_core_session_get_channel(listener->session);
-        assert(channel != NULL);
-
-        if (!strncasecmp(cmd, "connect", 7)) {
-            snprintf(reply, reply_len, "+OK");
-            goto done;
-        } else if (!strncasecmp(cmd, "sendmsg", 4)) {
-            if (switch_test_flag(listener, LFLAG_ASYNC)) {
-                if ((status = switch_core_session_queue_private_event(listener->session, &event)) == SWITCH_STATUS_SUCCESS) {
-                    snprintf(reply, reply_len, "+OK");
-                } else {
-                    snprintf(reply, reply_len, "-ERR memory error");
-                }
-            } else {
-                switch_ivr_parse_event(listener->session, event);
-                snprintf(reply, reply_len, "+OK");
-            }
-            goto done;
-        } else if (!strncasecmp(cmd, "getvar", 6)) {
-            char *arg;
-            char *val = "";
-            
-            strip_cr(cmd);
-
-            if ((arg = strchr(cmd, ' '))) {
-                *arg++ = '\0';
-                if (!(val = switch_channel_get_variable(channel, arg))) {
-                    val = "";
-                }
-
-            }
-            snprintf(reply, reply_len, "%s", val);
-            goto done;
-        } else if (!strncasecmp(cmd, "myevents", 8)) {
-            listener->event_list[SWITCH_EVENT_CHANNEL_CREATE] = 1;
-            listener->event_list[SWITCH_EVENT_CHANNEL_DESTROY] = 1;
-            listener->event_list[SWITCH_EVENT_CHANNEL_STATE] = 1;
-            listener->event_list[SWITCH_EVENT_CHANNEL_ANSWER] = 1;
-            listener->event_list[SWITCH_EVENT_CHANNEL_HANGUP] = 1;
-            listener->event_list[SWITCH_EVENT_CHANNEL_EXECUTE] = 1;
-            listener->event_list[SWITCH_EVENT_CHANNEL_BRIDGE] = 1;
-            listener->event_list[SWITCH_EVENT_CHANNEL_UNBRIDGE] = 1;
-            listener->event_list[SWITCH_EVENT_CHANNEL_PROGRESS] = 1;
-            listener->event_list[SWITCH_EVENT_CHANNEL_OUTGOING] = 1;
-            listener->event_list[SWITCH_EVENT_CHANNEL_PARK] = 1;
-            listener->event_list[SWITCH_EVENT_CHANNEL_UNPARK] = 1;
-            listener->event_list[SWITCH_EVENT_TALK] = 1;
-            listener->event_list[SWITCH_EVENT_DTMF] = 1;
-            listener->event_list[SWITCH_EVENT_NOTALK] = 1;
-            listener->event_list[SWITCH_EVENT_DETECTED_SPEECH] = 1;
-            switch_set_flag_locked(listener, LFLAG_MYEVENTS);
-            switch_set_flag_locked(listener, LFLAG_EVENTS);
-            if (strstr(cmd, "xml") || strstr(cmd, "XML")) {
-                listener->format = EVENT_FORMAT_XML;
-            }
-            snprintf(reply, reply_len, "+OK Events Enabled");
-            goto done;
-        }
-
-        if (!switch_test_flag(listener, LFLAG_FULL)) {
-            goto done;
-        }
-    }
+	if (listener->session) {
+		switch_channel_t *channel = switch_core_session_get_channel(listener->session);
+		assert(channel != NULL);
+
+		if (!strncasecmp(cmd, "connect", 7)) {
+			snprintf(reply, reply_len, "+OK");
+			goto done;
+		} else if (!strncasecmp(cmd, "sendmsg", 4)) {
+			if (switch_test_flag(listener, LFLAG_ASYNC)) {
+				if ((status = switch_core_session_queue_private_event(listener->session, &event)) == SWITCH_STATUS_SUCCESS) {
+					snprintf(reply, reply_len, "+OK");
+				} else {
+					snprintf(reply, reply_len, "-ERR memory error");
+				}
+			} else {
+				switch_ivr_parse_event(listener->session, event);
+				snprintf(reply, reply_len, "+OK");
+			}
+			goto done;
+		} else if (!strncasecmp(cmd, "getvar", 6)) {
+			char *arg;
+			char *val = "";
+
+			strip_cr(cmd);
+
+			if ((arg = strchr(cmd, ' '))) {
+				*arg++ = '\0';
+				if (!(val = switch_channel_get_variable(channel, arg))) {
+					val = "";
+				}
+
+			}
+			snprintf(reply, reply_len, "%s", val);
+			goto done;
+		} else if (!strncasecmp(cmd, "myevents", 8)) {
+			listener->event_list[SWITCH_EVENT_CHANNEL_CREATE] = 1;
+			listener->event_list[SWITCH_EVENT_CHANNEL_DESTROY] = 1;
+			listener->event_list[SWITCH_EVENT_CHANNEL_STATE] = 1;
+			listener->event_list[SWITCH_EVENT_CHANNEL_ANSWER] = 1;
+			listener->event_list[SWITCH_EVENT_CHANNEL_HANGUP] = 1;
+			listener->event_list[SWITCH_EVENT_CHANNEL_EXECUTE] = 1;
+			listener->event_list[SWITCH_EVENT_CHANNEL_BRIDGE] = 1;
+			listener->event_list[SWITCH_EVENT_CHANNEL_UNBRIDGE] = 1;
+			listener->event_list[SWITCH_EVENT_CHANNEL_PROGRESS] = 1;
+			listener->event_list[SWITCH_EVENT_CHANNEL_OUTGOING] = 1;
+			listener->event_list[SWITCH_EVENT_CHANNEL_PARK] = 1;
+			listener->event_list[SWITCH_EVENT_CHANNEL_UNPARK] = 1;
+			listener->event_list[SWITCH_EVENT_TALK] = 1;
+			listener->event_list[SWITCH_EVENT_DTMF] = 1;
+			listener->event_list[SWITCH_EVENT_NOTALK] = 1;
+			listener->event_list[SWITCH_EVENT_DETECTED_SPEECH] = 1;
+			switch_set_flag_locked(listener, LFLAG_MYEVENTS);
+			switch_set_flag_locked(listener, LFLAG_EVENTS);
+			if (strstr(cmd, "xml") || strstr(cmd, "XML")) {
+				listener->format = EVENT_FORMAT_XML;
+			}
+			snprintf(reply, reply_len, "+OK Events Enabled");
+			goto done;
+		}
+
+		if (!switch_test_flag(listener, LFLAG_FULL)) {
+			goto done;
+		}
+	}
 
 	if (!strncasecmp(cmd, "sendevent", 9)) {
 		char *ename;
@@ -691,7 +691,7 @@
 		if (*ename == '\r' || *ename == '\n') {
 			ename = NULL;
 		}
-		
+
 		if (ename) {
 			switch_event_types_t etype;
 			if (switch_name_event(ename, &etype) == SWITCH_STATUS_SUCCESS) {
@@ -707,7 +707,7 @@
 		char *uuid = cmd + 8;
 
 		if (uuid) {
-			while(*uuid == ' ') {
+			while (*uuid == ' ') {
 				uuid++;
 			}
 
@@ -729,7 +729,7 @@
 				session = NULL;
 			}
 		}
-		
+
 		if (session) {
 			if ((status = switch_core_session_queue_private_event(session, &event)) == SWITCH_STATUS_SUCCESS) {
 				snprintf(reply, reply_len, "+OK");
@@ -742,9 +742,9 @@
 		}
 
 		goto done;
-	
+
 	} else if (!strncasecmp(cmd, "api ", 4)) {
-		struct api_command_struct acs = {0};
+		struct api_command_struct acs = { 0 };
 		char *api_cmd = cmd + 4;
 		char *arg = NULL;
 		strip_cr(api_cmd);
@@ -766,7 +766,7 @@
 		struct api_command_struct *acs;
 		char *api_cmd = cmd + 6;
 		char *arg = NULL;
-        char *uuid_str = NULL;
+		char *uuid_str = NULL;
 		strip_cr(api_cmd);
 
 		if ((arg = strchr(api_cmd, ' '))) {
@@ -786,17 +786,17 @@
 			if (arg) {
 				acs->arg = strdup(arg);
 			}
-			acs->bg = 1;	
+			acs->bg = 1;
 			switch_threadattr_create(&thd_attr, listener->pool);
 			switch_threadattr_detach_set(thd_attr, 1);
 			switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
 			switch_thread_create(&thread, thd_attr, api_exec, acs, listener->pool);
 			if ((uuid_str = switch_event_get_header(event, "job-uuid"))) {
-                switch_copy_string(acs->uuid_str, uuid_str, sizeof(acs->uuid_str));
-            } else {
-                switch_uuid_get(&uuid);
-                switch_uuid_format(acs->uuid_str, &uuid);
-            }
+				switch_copy_string(acs->uuid_str, uuid_str, sizeof(acs->uuid_str));
+			} else {
+				switch_uuid_get(&uuid);
+				switch_uuid_format(acs->uuid_str, &uuid);
+			}
 			snprintf(reply, reply_len, "+OK Job-UUID: %s", acs->uuid_str);
 		} else {
 			snprintf(reply, reply_len, "-ERR memory error!");
@@ -809,16 +809,15 @@
 
 		//pull off the first newline/carriage return
 		strip_cr(cmd);
-		
+
 		//move past the command
 		level_s = cmd + 3;
 
 		//see if we got an argument
-		if(!switch_strlen_zero(level_s)) {
+		if (!switch_strlen_zero(level_s)) {
 			//if so move to the argument
 			level_s++;
 		}
-			
 		//see if we lined up on an argument or not
 		if (switch_strlen_zero(level_s)) {
 			level_s = "debug";
@@ -833,7 +832,7 @@
 	} else if (!strncasecmp(cmd, "nolog", 5)) {
 		void *pop;
 		while (switch_queue_trypop(listener->log_queue, &pop) == SWITCH_STATUS_SUCCESS);
-		
+
 		if (switch_test_flag(listener, LFLAG_LOG)) {
 			switch_clear_flag_locked(listener, LFLAG_LOG);
 			snprintf(reply, reply_len, "+OK no longer logging");
@@ -844,18 +843,18 @@
 		char *next, *cur;
 		uint32_t count = 0, key_count = 0;
 		uint8_t custom = 0;
-		
+
 		strip_cr(cmd);
 		cur = cmd + 5;
 
 		if (cur && (cur = strchr(cur, ' '))) {
-			for(cur++; cur; count++) {
+			for (cur++; cur; count++) {
 				switch_event_types_t type;
 
 				if ((next = strchr(cur, ' '))) {
 					*next++ = '\0';
 				}
-				
+
 				if (!count) {
 					if (!strcasecmp(cur, "xml")) {
 						listener->format = EVENT_FORMAT_XML;
@@ -882,10 +881,10 @@
 					}
 				}
 
-			end:
+			  end:
 				cur = next;
 			}
-		} 
+		}
 
 		if (!key_count) {
 			snprintf(reply, reply_len, "-ERR no keywords supplied");
@@ -902,18 +901,18 @@
 		char *next, *cur;
 		uint32_t count = 0, key_count = 0;
 		uint8_t custom = 0;
-		
+
 		strip_cr(cmd);
 		cur = cmd + 5;
 
 		if (cur && (cur = strchr(cur, ' '))) {
-			for(cur++; cur; count++) {
+			for (cur++; cur; count++) {
 				switch_event_types_t type;
 
 				if ((next = strchr(cur, ' '))) {
 					*next++ = '\0';
 				}
-				
+
 				if (custom) {
 					switch_core_hash_delete(listener->event_hash, cur);
 				} else if (switch_name_event(cur, &type) == SWITCH_STATUS_SUCCESS) {
@@ -942,7 +941,7 @@
 
 				cur = next;
 			}
-		} 
+		}
 
 		if (!key_count) {
 			snprintf(reply, reply_len, "-ERR no keywords supplied");
@@ -954,7 +953,7 @@
 		}
 
 		snprintf(reply, reply_len, "+OK events nixed");
-		
+
 	} else if (!strncasecmp(cmd, "noevents", 8)) {
 		void *pop;
 		while (switch_queue_trypop(listener->event_queue, &pop) == SWITCH_STATUS_SUCCESS);
@@ -971,9 +970,9 @@
 		} else {
 			snprintf(reply, reply_len, "-ERR not listening for events");
 		}
-	} 
-	
- done:
+	}
+
+  done:
 	if (event) {
 		switch_event_destroy(&event);
 	}
@@ -985,7 +984,7 @@
 	return status;
 }
 
-static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t *thread, void *obj)
+static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t * thread, void *obj)
 {
 	listener_t *listener = (listener_t *) obj;
 	char buf[1024];
@@ -993,16 +992,16 @@
 	switch_status_t status;
 	switch_event_t *event;
 	char reply[512] = "";
-    switch_core_session_t *session = NULL;
-    switch_channel_t *channel = NULL;
-    
+	switch_core_session_t *session = NULL;
+	switch_channel_t *channel = NULL;
+
 
 	assert(listener != NULL);
 
-    if ((session = listener->session)) {
-        channel = switch_core_session_get_channel(session);
-        switch_core_session_read_lock(session);
-    }
+	if ((session = listener->session)) {
+		channel = switch_core_session_get_channel(session);
+		switch_core_session_read_lock(session);
+	}
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connection Open\n");
 
@@ -1010,83 +1009,83 @@
 	switch_set_flag_locked(listener, LFLAG_RUNNING);
 	add_listener(listener);
 
-    if (session && switch_test_flag(listener, LFLAG_AUTHED)) {
-        switch_event_t *event = NULL, *call_event;
-        char *event_str;
-        
-
-        switch_set_flag_locked(listener, LFLAG_SESSION);
-        status = read_packet(listener, &event, 25);
-
-        if (status != SWITCH_STATUS_SUCCESS || !event) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Socket Error!\n");
-            switch_clear_flag_locked(listener, LFLAG_RUNNING);
-            goto done;
-        }
-
-        if (switch_event_create(&call_event, SWITCH_EVENT_MESSAGE) != SWITCH_STATUS_SUCCESS) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
-            switch_clear_flag_locked(listener, LFLAG_RUNNING);
-            goto done;
-        }
-
-        if (parse_command(listener, event, reply, sizeof(reply)) != SWITCH_STATUS_SUCCESS) {
-            switch_clear_flag_locked(listener, LFLAG_RUNNING);
-            goto done;
-        }
-
-        switch_caller_profile_event_set_data(switch_channel_get_caller_profile(channel), "Channel", call_event);
-        switch_channel_event_set_data(channel, call_event);
-        switch_event_add_header(call_event, SWITCH_STACK_BOTTOM, "Content-Type", "command/reply");
-        
-        switch_event_add_header(call_event, SWITCH_STACK_BOTTOM, "Socket-Mode", switch_test_flag(listener, LFLAG_ASYNC) ? "async" : "static");
-        switch_event_add_header(call_event, SWITCH_STACK_BOTTOM, "Control", switch_test_flag(listener, LFLAG_FULL) ? "full" : "single-channel");
-        
-        switch_event_serialize(call_event, &event_str);
-        if (!event_str) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
-            switch_clear_flag_locked(listener, LFLAG_RUNNING);
-            goto done;
-        }
-        len = strlen(event_str);
-        switch_socket_send(listener->sock, event_str, &len);
-
-        switch_safe_free(event_str);
-    } else {
-        snprintf(buf, sizeof(buf), "Content-Type: auth/request\n\n");
-		
-        len = strlen(buf);
-        switch_socket_send(listener->sock, buf, &len);
-		
-        while (!switch_test_flag(listener, LFLAG_AUTHED)) {
-            status = read_packet(listener, &event, 25);
-            if (status != SWITCH_STATUS_SUCCESS) {
-                goto done;
-            }
-            if (!event) {
-                continue;
-            }
-
-            if (parse_command(listener, event, reply, sizeof(reply)) != SWITCH_STATUS_SUCCESS) {
-                switch_clear_flag_locked(listener, LFLAG_RUNNING);
-                goto done;
-            }
-            if (!switch_strlen_zero(reply)) {
-                snprintf(buf, sizeof(buf), "Content-Type: command/reply\nReply-Text: %s\n\n", reply);
-                len = strlen(buf);
-                switch_socket_send(listener->sock, buf, &len);
-            }
-            break;
-        }
-    }
+	if (session && switch_test_flag(listener, LFLAG_AUTHED)) {
+		switch_event_t *event = NULL, *call_event;
+		char *event_str;
+
+
+		switch_set_flag_locked(listener, LFLAG_SESSION);
+		status = read_packet(listener, &event, 25);
+
+		if (status != SWITCH_STATUS_SUCCESS || !event) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Socket Error!\n");
+			switch_clear_flag_locked(listener, LFLAG_RUNNING);
+			goto done;
+		}
+
+		if (switch_event_create(&call_event, SWITCH_EVENT_MESSAGE) != SWITCH_STATUS_SUCCESS) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
+			switch_clear_flag_locked(listener, LFLAG_RUNNING);
+			goto done;
+		}
 
-	while(switch_test_flag(listener, LFLAG_RUNNING) && listen_list.ready) {
+		if (parse_command(listener, event, reply, sizeof(reply)) != SWITCH_STATUS_SUCCESS) {
+			switch_clear_flag_locked(listener, LFLAG_RUNNING);
+			goto done;
+		}
+
+		switch_caller_profile_event_set_data(switch_channel_get_caller_profile(channel), "Channel", call_event);
+		switch_channel_event_set_data(channel, call_event);
+		switch_event_add_header(call_event, SWITCH_STACK_BOTTOM, "Content-Type", "command/reply");
+
+		switch_event_add_header(call_event, SWITCH_STACK_BOTTOM, "Socket-Mode", switch_test_flag(listener, LFLAG_ASYNC) ? "async" : "static");
+		switch_event_add_header(call_event, SWITCH_STACK_BOTTOM, "Control", switch_test_flag(listener, LFLAG_FULL) ? "full" : "single-channel");
+
+		switch_event_serialize(call_event, &event_str);
+		if (!event_str) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
+			switch_clear_flag_locked(listener, LFLAG_RUNNING);
+			goto done;
+		}
+		len = strlen(event_str);
+		switch_socket_send(listener->sock, event_str, &len);
+
+		switch_safe_free(event_str);
+	} else {
+		snprintf(buf, sizeof(buf), "Content-Type: auth/request\n\n");
+
+		len = strlen(buf);
+		switch_socket_send(listener->sock, buf, &len);
+
+		while (!switch_test_flag(listener, LFLAG_AUTHED)) {
+			status = read_packet(listener, &event, 25);
+			if (status != SWITCH_STATUS_SUCCESS) {
+				goto done;
+			}
+			if (!event) {
+				continue;
+			}
+
+			if (parse_command(listener, event, reply, sizeof(reply)) != SWITCH_STATUS_SUCCESS) {
+				switch_clear_flag_locked(listener, LFLAG_RUNNING);
+				goto done;
+			}
+			if (!switch_strlen_zero(reply)) {
+				snprintf(buf, sizeof(buf), "Content-Type: command/reply\nReply-Text: %s\n\n", reply);
+				len = strlen(buf);
+				switch_socket_send(listener->sock, buf, &len);
+			}
+			break;
+		}
+	}
+
+	while (switch_test_flag(listener, LFLAG_RUNNING) && listen_list.ready) {
 		switch_event_t *event;
 
 		len = sizeof(buf);
 		memset(buf, 0, len);
 		status = read_packet(listener, &event, 0);
-		
+
 		if (status != SWITCH_STATUS_SUCCESS) {
 			break;
 		}
@@ -1105,10 +1104,10 @@
 			len = strlen(buf);
 			switch_socket_send(listener->sock, buf, &len);
 		}
-			
+
 	}
 
- done:
+  done:
 
 	remove_listener(listener);
 	close_socket(&listener->sock);
@@ -1117,29 +1116,29 @@
 
 	switch_thread_rwlock_wrlock(listener->rwlock);
 	switch_thread_rwlock_unlock(listener->rwlock);
-	
+
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connection Closed\n");
 
-    if (session) {
-        switch_channel_clear_flag(switch_core_session_get_channel(session), CF_CONTROLLED);
-        switch_clear_flag_locked(listener, LFLAG_SESSION);
-        switch_core_session_rwunlock(session);
-    } else if (listener->pool) {
+	if (session) {
+		switch_channel_clear_flag(switch_core_session_get_channel(session), CF_CONTROLLED);
+		switch_clear_flag_locked(listener, LFLAG_SESSION);
+		switch_core_session_rwunlock(session);
+	} else if (listener->pool) {
 		switch_memory_pool_t *pool = listener->pool;
 		switch_core_destroy_memory_pool(&pool);
 	}
 
-    
+
 	return NULL;
 }
 
 
 /* Create a thread for the socket and launch it */
-static void launch_listener_thread(listener_t *listener)
+static void launch_listener_thread(listener_t * listener)
 {
 	switch_thread_t *thread;
 	switch_threadattr_t *thd_attr = NULL;
-	
+
 	switch_threadattr_create(&thd_attr, listener->pool);
 	switch_threadattr_detach_set(thd_attr, 1);
 	switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
@@ -1164,15 +1163,15 @@
 				if (!strcmp(var, "listen-ip")) {
 					set_pref_ip(val);
 				} else if (!strcmp(var, "listen-port")) {
-					prefs.port = (uint16_t)atoi(val);
+					prefs.port = (uint16_t) atoi(val);
 				} else if (!strcmp(var, "password")) {
 					set_pref_pass(val);
-				} 
+				}
 			}
 		}
 		switch_xml_free(xml);
 	}
-	
+
 	if (switch_strlen_zero(prefs.ip)) {
 		set_pref_ip("127.0.0.1");
 	}
@@ -1192,9 +1191,9 @@
 SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
 {
 	switch_memory_pool_t *pool = NULL, *listener_pool = NULL;
-    switch_status_t rv;
-    switch_sockaddr_t *sa;
-    switch_socket_t  *inbound_socket = NULL;
+	switch_status_t rv;
+	switch_sockaddr_t *sa;
+	switch_socket_t *inbound_socket = NULL;
 	listener_t *listener;
 
 	memset(&listen_list, 0, sizeof(listen_list));
@@ -1207,22 +1206,27 @@
 
 	switch_mutex_init(&listen_list.mutex, SWITCH_MUTEX_NESTED, pool);
 	switch_mutex_init(&listen_list.sock_mutex, SWITCH_MUTEX_NESTED, pool);
-	
-	
-	for(;;) {
+
+
+	for (;;) {
 		rv = switch_sockaddr_info_get(&sa, prefs.ip, SWITCH_INET, prefs.port, 0, pool);
-		if (rv) goto fail;
+		if (rv)
+			goto fail;
 		rv = switch_socket_create(&listen_list.sock, switch_sockaddr_get_family(sa), SOCK_STREAM, SWITCH_PROTO_TCP, pool);
-		if (rv) goto sock_fail;
+		if (rv)
+			goto sock_fail;
 		rv = switch_socket_opt_set(listen_list.sock, SWITCH_SO_REUSEADDR, 1);
-		if (rv) goto sock_fail;
+		if (rv)
+			goto sock_fail;
 		rv = switch_socket_bind(listen_list.sock, sa);
-		if (rv) goto sock_fail;
+		if (rv)
+			goto sock_fail;
 		rv = switch_socket_listen(listen_list.sock, 5);
-		if (rv) goto sock_fail;
+		if (rv)
+			goto sock_fail;
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Socket up listening on %s:%u\n", prefs.ip, prefs.port);
 		break;
-	sock_fail:
+	  sock_fail:
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Socket Error!\n");
 		switch_yield(100000);
 	}
@@ -1242,7 +1246,7 @@
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "OH OH no pool\n");
 			goto fail;
 		}
-		
+
 		if ((rv = switch_socket_accept(&inbound_socket, listen_list.sock, listener_pool))) {
 			if (prefs.done) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Shutting Down\n");
@@ -1251,12 +1255,12 @@
 			}
 			break;
 		}
-		
+
 		if (!(listener = switch_core_alloc(listener_pool, sizeof(*listener)))) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error\n");
 			break;
 		}
-		
+
 		switch_thread_rwlock_create(&listener->rwlock, listener_pool);
 		switch_queue_create(&listener->event_queue, SWITCH_CORE_QUEUE_LEN, listener_pool);
 		switch_queue_create(&listener->log_queue, SWITCH_CORE_QUEUE_LEN, listener_pool);
@@ -1268,7 +1272,7 @@
 		switch_mutex_init(&listener->flag_mutex, SWITCH_MUTEX_NESTED, listener->pool);
 		switch_core_hash_init(&listener->event_hash, listener->pool);
 		launch_listener_thread(listener);
-		
+
 	}
 
 	close_socket(&listen_list.sock);
@@ -1281,7 +1285,7 @@
 		switch_core_destroy_memory_pool(&listener_pool);
 	}
 
-	fail:
+  fail:
 	return SWITCH_STATUS_TERM;
 }
 

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_event_test/mod_event_test.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_event_test/mod_event_test.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_event_test/mod_event_test.c	Fri Mar 30 12:19:18 2007
@@ -59,7 +59,7 @@
 	}
 
 	switch_safe_free(buf);
-	
+
 	if (dofree) {
 		if (xml) {
 			switch_xml_free(xml);
@@ -88,7 +88,7 @@
 #define TTHREADS 500
 static int THREADS = 0;
 
-static void *torture_thread(switch_thread_t *thread, void *obj)
+static void *torture_thread(switch_thread_t * thread, void *obj)
 {
 	int y = 0;
 	int z = 0;
@@ -135,12 +135,10 @@
 		return SWITCH_STATUS_GENERR;
 	}
 
-	if (switch_event_bind((char *) modname, SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL) !=
-		SWITCH_STATUS_SUCCESS) {
+	if (switch_event_bind((char *) modname, SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
 		return SWITCH_STATUS_GENERR;
 	}
-
 #ifdef TORTURE_ME
 	if (1) {
 		int x = 0;

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_xmpp_event/mod_xmpp_event.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_xmpp_event/mod_xmpp_event.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_xmpp_event/mod_xmpp_event.c	Fri Mar 30 12:19:18 2007
@@ -134,8 +134,7 @@
 
 	if (count == 3) {
 		/* TBD use config to pick what events to bind to */
-		if (switch_event_bind((char *) modname, SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL) !=
-			SWITCH_STATUS_SUCCESS) {
+		if (switch_event_bind((char *) modname, SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
 			return SWITCH_STATUS_GENERR;
 		}
@@ -151,7 +150,7 @@
 {
 	iks *msg, *ctag;
 
-	msg = iks_make_pres (IKS_SHOW_AVAILABLE, "Available"); 
+	msg = iks_make_pres(IKS_SHOW_AVAILABLE, "Available");
 	ctag = iks_insert(msg, "c");
 	iks_insert_attrib(ctag, "node", "http://www.freeswitch.org/xmpp/client/caps");
 	iks_insert_attrib(ctag, "ver", "1.0.0.1");
@@ -159,7 +158,7 @@
 	iks_insert_attrib(ctag, "xmlns", "http://jabber.org/protocol/caps");
 
 	iks_send(sess->parser, msg);
-    iks_delete(msg);
+	iks_delete(msg);
 
 	return IKS_FILTER_EAT;
 }
@@ -231,16 +230,16 @@
 }
 
 
-static int on_subscribe(void *user_data, ikspak *pak)
+static int on_subscribe(void *user_data, ikspak * pak)
 {
 	char *from = iks_find_attrib(pak->x, "from");
 	struct session *sess = (struct session *) user_data;
 
-	iks *msg = iks_make_s10n (IKS_TYPE_SUBSCRIBED, from, "mod_xmpp_event"); 
+	iks *msg = iks_make_s10n(IKS_TYPE_SUBSCRIBED, from, "mod_xmpp_event");
 	iks_send(sess->parser, msg);
 	iks_delete(msg);
-		
-	msg = iks_make_s10n (IKS_TYPE_SUBSCRIBE, from, "mod_xmpp_event"); 
+
+	msg = iks_make_s10n(IKS_TYPE_SUBSCRIBE, from, "mod_xmpp_event");
 	iks_send(sess->parser, msg);
 	iks_delete(msg);
 
@@ -251,7 +250,7 @@
 {
 	char *cmd = iks_find_cdata(pak->x, "body");
 	char *arg = NULL;
-	switch_stream_handle_t stream = {0};
+	switch_stream_handle_t stream = { 0 };
 	char retbuf[2048] = "";
 	char *p;
 	iks *msg;
@@ -272,12 +271,12 @@
 	stream.write_function = switch_console_stream_write;
 	switch_api_execute(cmd, arg, NULL, &stream);
 
-	
+
 	msg = iks_make_msg(IKS_TYPE_NONE, globals.target_jid, retbuf);
 	iks_insert_attrib(msg, "subject", "Reply");
 	iks_send(globals.session.parser, msg);
 	iks_delete(msg);
-	
+
 
 	return 0;
 }
@@ -305,19 +304,12 @@
 		iks_filter_delete(my_filter);
 	my_filter = iks_filter_new();
 	iks_filter_add_rule(my_filter, on_msg, 0,
-						IKS_RULE_TYPE, IKS_PAK_MESSAGE,
-						IKS_RULE_SUBTYPE, IKS_TYPE_CHAT, IKS_RULE_FROM, globals.target_jid, IKS_RULE_DONE);
+						IKS_RULE_TYPE, IKS_PAK_MESSAGE, IKS_RULE_SUBTYPE, IKS_TYPE_CHAT, IKS_RULE_FROM, globals.target_jid, IKS_RULE_DONE);
 	iks_filter_add_rule(my_filter, (iksFilterHook *) on_result, sess,
-						IKS_RULE_TYPE, IKS_PAK_IQ,
-						IKS_RULE_SUBTYPE, IKS_TYPE_RESULT, IKS_RULE_ID, "auth", IKS_RULE_DONE);
-	iks_filter_add_rule(my_filter, on_error, sess,
-						IKS_RULE_TYPE, IKS_PAK_IQ,
-						IKS_RULE_SUBTYPE, IKS_TYPE_ERROR, IKS_RULE_ID, "auth", IKS_RULE_DONE);
-
-	iks_filter_add_rule(my_filter, on_subscribe, sess,
-						IKS_RULE_TYPE, IKS_PAK_S10N,
-						IKS_RULE_SUBTYPE, IKS_TYPE_SUBSCRIBE,
-						IKS_RULE_DONE);
+						IKS_RULE_TYPE, IKS_PAK_IQ, IKS_RULE_SUBTYPE, IKS_TYPE_RESULT, IKS_RULE_ID, "auth", IKS_RULE_DONE);
+	iks_filter_add_rule(my_filter, on_error, sess, IKS_RULE_TYPE, IKS_PAK_IQ, IKS_RULE_SUBTYPE, IKS_TYPE_ERROR, IKS_RULE_ID, "auth", IKS_RULE_DONE);
+
+	iks_filter_add_rule(my_filter, on_subscribe, sess, IKS_RULE_TYPE, IKS_PAK_S10N, IKS_RULE_SUBTYPE, IKS_TYPE_SUBSCRIBE, IKS_RULE_DONE);
 
 }
 

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_zeroconf/mod_zeroconf.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_zeroconf/mod_zeroconf.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_zeroconf/mod_zeroconf.c	Fri Mar 30 12:19:18 2007
@@ -50,57 +50,54 @@
 static sw_result HOWL_API my_browser(sw_discovery discovery,
 									 sw_discovery_oid oid,
 									 sw_discovery_browse_status status,
-									 sw_uint32 interface_index,
-									 sw_const_string name,
-									 sw_const_string type,
-									 sw_const_string domain,
-									 sw_opaque_t extra) {
+									 sw_uint32 interface_index, sw_const_string name, sw_const_string type, sw_const_string domain, sw_opaque_t extra)
+{
 	//sw_discovery_resolve_id rid;
 
 	switch (status) {
-		case SW_DISCOVERY_BROWSE_INVALID:
+	case SW_DISCOVERY_BROWSE_INVALID:
 		{
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "browse reply: Invalid\n");
 		}
 		break;
 
-		case SW_DISCOVERY_BROWSE_RELEASE:
+	case SW_DISCOVERY_BROWSE_RELEASE:
 		{
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "browse reply: Release\n");
 		}
 		break;
 
-		case SW_DISCOVERY_BROWSE_ADD_DOMAIN:
+	case SW_DISCOVERY_BROWSE_ADD_DOMAIN:
 		{
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "browse reply: Add Domain\n");
 		}
 		break;
 
-		case SW_DISCOVERY_BROWSE_ADD_DEFAULT_DOMAIN:
+	case SW_DISCOVERY_BROWSE_ADD_DEFAULT_DOMAIN:
 		{
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "browse reply: Add Default Domain\n");
 		}
 		break;
 
-		case SW_DISCOVERY_BROWSE_REMOVE_DOMAIN:
+	case SW_DISCOVERY_BROWSE_REMOVE_DOMAIN:
 		{
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "browse reply: Remove Domain\n");
 		}
 		break;
 
-		case SW_DISCOVERY_BROWSE_REMOVE_SERVICE:
+	case SW_DISCOVERY_BROWSE_REMOVE_SERVICE:
 		{
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "browse reply: Remove Service\n");
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "remove service: 0x%x %s %s %s\n", interface_index, name, type, domain);
 		}
 		break;
 
-		case SW_DISCOVERY_BROWSE_RESOLVED:
+	case SW_DISCOVERY_BROWSE_RESOLVED:
 		{
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "browse reply: Resolved\n");
 		}
 		break;
-		case SW_DISCOVERY_BROWSE_ADD_SERVICE:
+	case SW_DISCOVERY_BROWSE_ADD_SERVICE:
 		break;
 	}
 
@@ -108,17 +105,15 @@
 }
 
 
-static sw_result HOWL_API my_service_reply(sw_discovery	discovery,
-   sw_discovery_oid	oid,
-   sw_discovery_publish_status status,
-   sw_opaque extra) {
+static sw_result HOWL_API my_service_reply(sw_discovery discovery, sw_discovery_oid oid, sw_discovery_publish_status status, sw_opaque extra)
+{
 	static sw_string status_text[] = {
 		"Started",
 		"Stopped",
 		"Name Collision",
 		"Invalid"
 	};
-	
+
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "publish reply: %s\n", status_text[status]);
 	return SW_OKAY;
 }
@@ -126,7 +121,7 @@
 
 static void event_handler(switch_event_t *event)
 {
-	sw_text_record text_record;	
+	sw_text_record text_record;
 	sw_result result;
 
 	switch (event->event_id) {
@@ -159,10 +154,10 @@
 				service = "_freeswitch._tcp";
 			}
 			if (port) {
-				porti = (sw_port)atoi(port);				
+				porti = (sw_port) atoi(port);
 			}
 
-			switch_mutex_lock(globals.zc_lock);			
+			switch_mutex_lock(globals.zc_lock);
 			if ((result = sw_discovery_publish(globals.discovery,
 											   0,
 											   "freeswitch",
@@ -171,10 +166,7 @@
 											   NULL,
 											   porti,
 											   sw_text_record_bytes(text_record),
-											   sw_text_record_len(text_record),
-											   my_service_reply,
-											   NULL,
-											   &globals.disc_id)) != SW_OKAY) {
+											   sw_text_record_len(text_record), my_service_reply, NULL, &globals.disc_id)) != SW_OKAY) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "publish failed: %u\n", result);
 				sw_text_record_fina(text_record);
 				switch_mutex_unlock(globals.zc_lock);
@@ -183,7 +175,7 @@
 			switch_mutex_unlock(globals.zc_lock);
 			sw_text_record_fina(text_record);
 		}
-		
+
 		break;
 	case SWITCH_EVENT_UNPUBLISH:
 
@@ -211,11 +203,11 @@
 		for (param = switch_xml_child(settings, "param"); param; param = param->next) {
 			char *var = (char *) switch_xml_attr_soft(param, "name");
 			char *val = (char *) switch_xml_attr_soft(param, "value");
-			
+
 			if (!strcmp(var, "browse")) {
 				if ((oid = switch_core_alloc(module_pool, sizeof(*oid))) != 0) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Bind browser to to %s\n", val);
-					switch_mutex_lock(globals.zc_lock);	
+					switch_mutex_lock(globals.zc_lock);
 					sw_discovery_browse(globals.discovery, 0, val, NULL, my_browser, NULL, oid);
 					switch_mutex_unlock(globals.zc_lock);
 					count++;
@@ -223,14 +215,12 @@
 					return SWITCH_STATUS_MEMERR;
 				}
 			} else if (!strcasecmp(var, "publish") && !strcasecmp(val, "yes")) {
-				if (switch_event_bind((char *) modname, SWITCH_EVENT_PUBLISH, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL) !=
-					SWITCH_STATUS_SUCCESS) {
+				if (switch_event_bind((char *) modname, SWITCH_EVENT_PUBLISH, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
 					return SWITCH_STATUS_GENERR;
 				}
-				
-				if (switch_event_bind((char *) modname, SWITCH_EVENT_UNPUBLISH, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL) !=
-					SWITCH_STATUS_SUCCESS) {
+
+				if (switch_event_bind((char *) modname, SWITCH_EVENT_UNPUBLISH, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
 					return SWITCH_STATUS_GENERR;
 				}
@@ -289,7 +279,7 @@
 	if (load_config() != SWITCH_STATUS_SUCCESS) {
 		return SWITCH_STATUS_TERM;
 	}
-	
+
 	if (switch_event_reserve_subclass(MY_EVENT_PUBLISH) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't register subclass!");
 		return SWITCH_STATUS_GENERR;
@@ -312,7 +302,7 @@
 {
 
 	RUNNING = 1;
-	while(RUNNING == 1) {
+	while (RUNNING == 1) {
 		sw_uint32 ms;
 		ms = 100;
 		sw_discovery_step(globals.discovery, &ms);

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_native_file/mod_native_file.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_native_file/mod_native_file.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_native_file/mod_native_file.c	Fri Mar 30 12:19:18 2007
@@ -63,7 +63,7 @@
 		flags |= SWITCH_FOPEN_READ;
 	}
 
-	if (switch_file_open(&context->fd, path, flags, SWITCH_FPROT_UREAD|SWITCH_FPROT_UWRITE, handle->memory_pool) != SWITCH_STATUS_SUCCESS) {
+	if (switch_file_open(&context->fd, path, flags, SWITCH_FPROT_UREAD | SWITCH_FPROT_UWRITE, handle->memory_pool) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening %s\n", path);
 		return SWITCH_STATUS_GENERR;
 	}
@@ -78,7 +78,7 @@
 	handle->seekable = 1;
 	handle->speed = 0;
 	handle->private_info = context;
-	handle->flags |=  SWITCH_FILE_NATIVE;
+	handle->flags |= SWITCH_FILE_NATIVE;
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Opening File [%s] %dhz\n", path, handle->samplerate);
 
 
@@ -88,7 +88,7 @@
 static switch_status_t native_file_file_close(switch_file_handle_t *handle)
 {
 	native_file_context *context = handle->private_info;
-	
+
 	if (context->fd) {
 		switch_file_close(context->fd);
 		context->fd = NULL;
@@ -100,9 +100,9 @@
 static switch_status_t native_file_file_seek(switch_file_handle_t *handle, unsigned int *cur_sample, int64_t samples, int whence)
 {
 	native_file_context *context = handle->private_info;
-	
+
 	switch_file_seek(context->fd, whence, &samples);
-	
+
 	return SWITCH_STATUS_FALSE;
 
 }
@@ -135,7 +135,7 @@
 
 /* Registration */
 
-static char *supported_formats[SWITCH_MAX_CODECS] = {0};
+static char *supported_formats[SWITCH_MAX_CODECS] = { 0 };
 
 static switch_file_interface_t native_file_file_interface = {
 	/*.interface_name */ modname,
@@ -170,7 +170,7 @@
 	uint32_t num_codecs = switch_loadable_module_get_codecs(NULL, codecs, sizeof(codecs) / sizeof(codecs[0]));
 	uint32_t x;
 
-	for (x = 0 ; x < num_codecs; x++) {
+	for (x = 0; x < num_codecs; x++) {
 		supported_formats[x] = codecs[x]->iananame;
 	}
 

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/common.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/common.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/common.c	Fri Mar 30 12:19:18 2007
@@ -9,47 +9,47 @@
 #include "mpg123.h"
 #include "mpglib.h"
 
-struct parameter param = { 1 , 1 , 0 , 0 };
+struct parameter param = { 1, 1, 0, 0 };
 
 int tabsel_123[2][3][16] = {
-   { {0,32,64,96,128,160,192,224,256,288,320,352,384,416,448,},
-     {0,32,48,56, 64, 80, 96,112,128,160,192,224,256,320,384,},
-     {0,32,40,48, 56, 64, 80, 96,112,128,160,192,224,256,320,} },
-
-   { {0,32,48,56,64,80,96,112,128,144,160,176,192,224,256,},
-     {0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,},
-     {0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,} }
+	{{0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448,},
+	 {0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384,},
+	 {0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320,}},
+
+	{{0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256,},
+	 {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160,},
+	 {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160,}}
 };
 
 long freqs[9] = { 44100, 48000, 32000,
-                  22050, 24000, 16000 ,
-                  11025 , 12000 , 8000 };
+	22050, 24000, 16000,
+	11025, 12000, 8000
+};
 
 
 #if 0
 static void get_II_stuff(struct frame *fr)
 {
-  static int translate[3][2][16] = 
-   { { { 0,2,2,2,2,2,2,0,0,0,1,1,1,1,1,0 } ,
-       { 0,2,2,0,0,0,1,1,1,1,1,1,1,1,1,0 } } ,
-     { { 0,2,2,2,2,2,2,0,0,0,0,0,0,0,0,0 } ,
-       { 0,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0 } } ,
-     { { 0,3,3,3,3,3,3,0,0,0,1,1,1,1,1,0 } ,
-       { 0,3,3,0,0,0,1,1,1,1,1,1,1,1,1,0 } } };
-
-  int table,sblim;
-  static struct al_table *tables[5] = 
-       { alloc_0, alloc_1, alloc_2, alloc_3 , alloc_4 };
-  static int sblims[5] = { 27 , 30 , 8, 12 , 30 };
-
-  if(fr->lsf)
-    table = 4;
-  else
-    table = translate[fr->sampling_frequency][2-fr->stereo][fr->bitrate_index];
-  sblim = sblims[table];
+	static int translate[3][2][16] = { {{0, 2, 2, 2, 2, 2, 2, 0, 0, 0, 1, 1, 1, 1, 1, 0},
+										{0, 2, 2, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}},
+	{{0, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+	 {0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
+	{{0, 3, 3, 3, 3, 3, 3, 0, 0, 0, 1, 1, 1, 1, 1, 0},
+	 {0, 3, 3, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}}
+	};
+
+	int table, sblim;
+	static struct al_table *tables[5] = { alloc_0, alloc_1, alloc_2, alloc_3, alloc_4 };
+	static int sblims[5] = { 27, 30, 8, 12, 30 };
+
+	if (fr->lsf)
+		table = 4;
+	else
+		table = translate[fr->sampling_frequency][2 - fr->stereo][fr->bitrate_index];
+	sblim = sblims[table];
 
-  fr->alloc = tables[table];
-  fr->II_sblimit = sblim;
+	fr->alloc = tables[table];
+	fr->II_sblimit = sblim;
 }
 #endif
 
@@ -58,15 +58,15 @@
 #if 0
 int head_check(unsigned long head)
 {
-    if( (head & 0xffe00000) != 0xffe00000)
-	return FALSE;
-    if(!((head>>17)&3))
-	return FALSE;
-    if( ((head>>12)&0xf) == 0xf)
-	return FALSE;
-    if( ((head>>10)&0x3) == 0x3 )
-	return FALSE;
-    return TRUE;
+	if ((head & 0xffe00000) != 0xffe00000)
+		return FALSE;
+	if (!((head >> 17) & 3))
+		return FALSE;
+	if (((head >> 12) & 0xf) == 0xf)
+		return FALSE;
+	if (((head >> 10) & 0x3) == 0x3)
+		return FALSE;
+	return TRUE;
 }
 #endif
 
@@ -75,190 +75,175 @@
  * the code a header and write the information
  * into the frame structure
  */
-int decode_header(struct frame *fr,unsigned long newhead)
+int decode_header(struct frame *fr, unsigned long newhead)
 {
-    if( newhead & (1<<20) ) {
-      fr->lsf = (newhead & (1<<19)) ? 0x0 : 0x1;
-      fr->mpeg25 = 0;
-    }
-    else {
-      fr->lsf = 1;
-      fr->mpeg25 = 1;
-    }
-    
-    fr->lay = 4-((newhead>>17)&3);
-    if( ((newhead>>10)&0x3) == 0x3) {
-		debug_printf("%d Stream error\n",  __LINE__);
-      return (0);
-    }
-    if(fr->mpeg25) {
-      fr->sampling_frequency = 6 + ((newhead>>10)&0x3);
-    }
-    else
-      fr->sampling_frequency = ((newhead>>10)&0x3) + (fr->lsf*3);
-    fr->error_protection = ((newhead>>16)&0x1)^0x1;
-
-    if(fr->mpeg25) /* allow Bitrate change for 2.5 ... */
-      fr->bitrate_index = ((newhead>>12)&0xf);
-
-    fr->bitrate_index = ((newhead>>12)&0xf);
-    fr->padding   = ((newhead>>9)&0x1);
-    fr->extension = ((newhead>>8)&0x1);
-    fr->mode      = ((newhead>>6)&0x3);
-    fr->mode_ext  = ((newhead>>4)&0x3);
-    fr->copyright = ((newhead>>3)&0x1);
-    fr->original  = ((newhead>>2)&0x1);
-    fr->emphasis  = newhead & 0x3;
-
-    fr->stereo    = (fr->mode == MPG_MD_MONO) ? 1 : 2;
-
-    if(!fr->bitrate_index)
-    {
-		debug_printf("%d Free format not supported.\n",  __LINE__);
-      return (0);
-    }
-
-    switch(fr->lay)
-    {
-      case 1:
+	if (newhead & (1 << 20)) {
+		fr->lsf = (newhead & (1 << 19)) ? 0x0 : 0x1;
+		fr->mpeg25 = 0;
+	} else {
+		fr->lsf = 1;
+		fr->mpeg25 = 1;
+	}
+
+	fr->lay = 4 - ((newhead >> 17) & 3);
+	if (((newhead >> 10) & 0x3) == 0x3) {
+		debug_printf("%d Stream error\n", __LINE__);
+		return (0);
+	}
+	if (fr->mpeg25) {
+		fr->sampling_frequency = 6 + ((newhead >> 10) & 0x3);
+	} else
+		fr->sampling_frequency = ((newhead >> 10) & 0x3) + (fr->lsf * 3);
+	fr->error_protection = ((newhead >> 16) & 0x1) ^ 0x1;
+
+	if (fr->mpeg25)				/* allow Bitrate change for 2.5 ... */
+		fr->bitrate_index = ((newhead >> 12) & 0xf);
+
+	fr->bitrate_index = ((newhead >> 12) & 0xf);
+	fr->padding = ((newhead >> 9) & 0x1);
+	fr->extension = ((newhead >> 8) & 0x1);
+	fr->mode = ((newhead >> 6) & 0x3);
+	fr->mode_ext = ((newhead >> 4) & 0x3);
+	fr->copyright = ((newhead >> 3) & 0x1);
+	fr->original = ((newhead >> 2) & 0x1);
+	fr->emphasis = newhead & 0x3;
+
+	fr->stereo = (fr->mode == MPG_MD_MONO) ? 1 : 2;
+
+	if (!fr->bitrate_index) {
+		debug_printf("%d Free format not supported.\n", __LINE__);
+		return (0);
+	}
+
+	switch (fr->lay) {
+	case 1:
 #if 0
 		fr->do_layer = do_layer1;
-        fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ? 
-                         (fr->mode_ext<<2)+4 : 32;
-        fr->framesize  = (long) tabsel_123[fr->lsf][0][fr->bitrate_index] * 12000;
-        fr->framesize /= freqs[fr->sampling_frequency];
-        fr->framesize  = ((fr->framesize+fr->padding)<<2)-4;
+		fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ? (fr->mode_ext << 2) + 4 : 32;
+		fr->framesize = (long) tabsel_123[fr->lsf][0][fr->bitrate_index] * 12000;
+		fr->framesize /= freqs[fr->sampling_frequency];
+		fr->framesize = ((fr->framesize + fr->padding) << 2) - 4;
 #else
-        debug_printf("%d Layer 1 not supported!\n",  __LINE__);
+		debug_printf("%d Layer 1 not supported!\n", __LINE__);
 #endif
-        break;
-      case 2:
+		break;
+	case 2:
 #if 0
 		fr->do_layer = do_layer2;
-        get_II_stuff(fr);
-        fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ?
-                         (fr->mode_ext<<2)+4 : fr->II_sblimit;
-        fr->framesize = (long) tabsel_123[fr->lsf][1][fr->bitrate_index] * 144000;
-        fr->framesize /= freqs[fr->sampling_frequency];
-        fr->framesize += fr->padding - 4;
+		get_II_stuff(fr);
+		fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ? (fr->mode_ext << 2) + 4 : fr->II_sblimit;
+		fr->framesize = (long) tabsel_123[fr->lsf][1][fr->bitrate_index] * 144000;
+		fr->framesize /= freqs[fr->sampling_frequency];
+		fr->framesize += fr->padding - 4;
 #else
-        debug_printf("%d Layer 2 not supported!\n",  __LINE__);
+		debug_printf("%d Layer 2 not supported!\n", __LINE__);
 #endif
-        break;
-      case 3:
+		break;
+	case 3:
 #if 0
-        fr->do_layer = do_layer3;
-        if(fr->lsf)
-          ssize = (fr->stereo == 1) ? 9 : 17;
-        else
-          ssize = (fr->stereo == 1) ? 17 : 32;
+		fr->do_layer = do_layer3;
+		if (fr->lsf)
+			ssize = (fr->stereo == 1) ? 9 : 17;
+		else
+			ssize = (fr->stereo == 1) ? 17 : 32;
 #endif
 
 #if 0
-        if(fr->error_protection)
-          ssize += 2;
-#endif
-          fr->framesize  = (long) tabsel_123[fr->lsf][2][fr->bitrate_index] * 144000;
-          fr->framesize /= freqs[fr->sampling_frequency]<<(fr->lsf);
-          fr->framesize = fr->framesize + fr->padding - 4;
-        break; 
-      default:
-		  debug_printf("%d Sorry, unknown layer type.\n",  __LINE__); 
-        return (0);
-    }
-    return 1;
+		if (fr->error_protection)
+			ssize += 2;
+#endif
+		fr->framesize = (long) tabsel_123[fr->lsf][2][fr->bitrate_index] * 144000;
+		fr->framesize /= freqs[fr->sampling_frequency] << (fr->lsf);
+		fr->framesize = fr->framesize + fr->padding - 4;
+		break;
+	default:
+		debug_printf("%d Sorry, unknown layer type.\n", __LINE__);
+		return (0);
+	}
+	return 1;
 }
 
 #if 0
 void print_header(struct frame *fr)
 {
 	static char *modes[4] = { "Stereo", "Joint-Stereo", "Dual-Channel", "Single-Channel" };
-	static char *layers[4] = { "Unknown" , "I", "II", "III" };
+	static char *layers[4] = { "Unknown", "I", "II", "III" };
 
-	debug_printf("MPEG %s, Layer: %s, Freq: %ld, mode: %s, modext: %d, BPF : %d\n", 
-		fr->mpeg25 ? "2.5" : (fr->lsf ? "2.0" : "1.0"),
-		layers[fr->lay],freqs[fr->sampling_frequency],
-		modes[fr->mode],fr->mode_ext,fr->framesize+4);
+	debug_printf("MPEG %s, Layer: %s, Freq: %ld, mode: %s, modext: %d, BPF : %d\n",
+				 fr->mpeg25 ? "2.5" : (fr->lsf ? "2.0" : "1.0"),
+				 layers[fr->lay], freqs[fr->sampling_frequency], modes[fr->mode], fr->mode_ext, fr->framesize + 4);
 	debug_printf("Channels: %d, copyright: %s, original: %s, CRC: %s, emphasis: %d.\n",
-		fr->stereo,fr->copyright?"Yes":"No",
-		fr->original?"Yes":"No",fr->error_protection?"Yes":"No",
-		fr->emphasis);
-	debug_printf("Bitrate: %d Kbits/s, Extension value: %d\n",
-		tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index],fr->extension);
+				 fr->stereo, fr->copyright ? "Yes" : "No", fr->original ? "Yes" : "No", fr->error_protection ? "Yes" : "No", fr->emphasis);
+	debug_printf("Bitrate: %d Kbits/s, Extension value: %d\n", tabsel_123[fr->lsf][fr->lay - 1][fr->bitrate_index], fr->extension);
 }
 
 void print_header_compact(struct frame *fr)
 {
 	static char *modes[4] = { "stereo", "joint-stereo", "dual-channel", "mono" };
-	static char *layers[4] = { "Unknown" , "I", "II", "III" };
- 
+	static char *layers[4] = { "Unknown", "I", "II", "III" };
+
 	debug_printf("MPEG %s layer %s, %d kbit/s, %ld Hz %s\n",
-		fr->mpeg25 ? "2.5" : (fr->lsf ? "2.0" : "1.0"),
-		layers[fr->lay],
-		tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index],
-		freqs[fr->sampling_frequency], modes[fr->mode]);
+				 fr->mpeg25 ? "2.5" : (fr->lsf ? "2.0" : "1.0"),
+				 layers[fr->lay], tabsel_123[fr->lsf][fr->lay - 1][fr->bitrate_index], freqs[fr->sampling_frequency], modes[fr->mode]);
 }
 
 #endif
 
 unsigned int getbits(struct mpstr *mp, int number_of_bits)
 {
-  unsigned long rval;
+	unsigned long rval;
 
-  if(!number_of_bits)
-    return 0;
+	if (!number_of_bits)
+		return 0;
 
-  {
-    rval = (mp->worksample).wordpointer[0];
-    rval <<= 8;
-    rval |= (mp->worksample).wordpointer[1];
-    rval <<= 8;
-    rval |= (mp->worksample).wordpointer[2];
-    rval <<= (mp->worksample).bitindex;
-    rval &= 0xffffff;
-
-    (mp->worksample).bitindex += number_of_bits;
-
-    rval >>= (24-number_of_bits);
-
-    (mp->worksample).wordpointer += ((mp->worksample).bitindex>>3);
-    (mp->worksample).bitindex &= 7;
-  }
-  return rval;
+	{
+		rval = (mp->worksample).wordpointer[0];
+		rval <<= 8;
+		rval |= (mp->worksample).wordpointer[1];
+		rval <<= 8;
+		rval |= (mp->worksample).wordpointer[2];
+		rval <<= (mp->worksample).bitindex;
+		rval &= 0xffffff;
+
+		(mp->worksample).bitindex += number_of_bits;
+
+		rval >>= (24 - number_of_bits);
+
+		(mp->worksample).wordpointer += ((mp->worksample).bitindex >> 3);
+		(mp->worksample).bitindex &= 7;
+	}
+	return rval;
 }
 
 unsigned int getbits_fast(struct mpstr *mp, int number_of_bits)
 {
-  unsigned long rval;
+	unsigned long rval;
 
-  {
-    rval = (mp->worksample).wordpointer[0];
-    rval <<= 8;	
-    rval |= (mp->worksample).wordpointer[1];
-    rval <<= (mp->worksample).bitindex;
-    rval &= 0xffff;
-    (mp->worksample).bitindex += number_of_bits;
-
-    rval >>= (16-number_of_bits);
-
-    (mp->worksample).wordpointer += ((mp->worksample).bitindex>>3);
-    (mp->worksample).bitindex &= 7;
-  }
-  return rval;
+	{
+		rval = (mp->worksample).wordpointer[0];
+		rval <<= 8;
+		rval |= (mp->worksample).wordpointer[1];
+		rval <<= (mp->worksample).bitindex;
+		rval &= 0xffff;
+		(mp->worksample).bitindex += number_of_bits;
+
+		rval >>= (16 - number_of_bits);
+
+		(mp->worksample).wordpointer += ((mp->worksample).bitindex >> 3);
+		(mp->worksample).bitindex &= 7;
+	}
+	return rval;
 }
 
 unsigned int get1bit(struct mpstr *mp)
 {
-  unsigned char rval;
+	unsigned char rval;
 
-  rval = *((mp->worksample).wordpointer) << (mp->worksample).bitindex;
+	rval = *((mp->worksample).wordpointer) << (mp->worksample).bitindex;
 
-  (mp->worksample).bitindex++;
-  (mp->worksample).wordpointer += ((mp->worksample).bitindex>>3);
-  (mp->worksample).bitindex &= 7;
+	(mp->worksample).bitindex++;
+	(mp->worksample).wordpointer += ((mp->worksample).bitindex >> 3);
+	(mp->worksample).bitindex &= 7;
 
-  return rval>>7;
+	return rval >> 7;
 }
-
-
-

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/dct64_i386.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/dct64_i386.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/dct64_i386.c	Fri Mar 30 12:19:18 2007
@@ -13,323 +13,322 @@
  * the call via dct64 is a trick to force GCC to use
  * (new) registers for the b1,b2 pointer to the bufs[xx] field
  */
-void dct64(real *a,real *b,real *c);
+void dct64(real * a, real * b, real * c);
 
-static void dct64_1(real *out0,real *out1,real *b1,real *b2,real *samples)
+static void dct64_1(real * out0, real * out1, real * b1, real * b2, real * samples)
 {
- {
-  register real *costab = pnts[0];
+	{
+		register real *costab = pnts[0];
 
-  b1[0x00] = samples[0x00] + samples[0x1F];
-  b1[0x01] = samples[0x01] + samples[0x1E];
-  b1[0x1F] = (samples[0x00] - samples[0x1F]) * costab[0x0];
-  b1[0x1E] = (samples[0x01] - samples[0x1E]) * costab[0x1];
-
-  b1[0x02] = samples[0x02] + samples[0x1D];
-  b1[0x03] = samples[0x03] + samples[0x1C];
-  b1[0x1D] = (samples[0x02] - samples[0x1D]) * costab[0x2];
-  b1[0x1C] = (samples[0x03] - samples[0x1C]) * costab[0x3];
-
-  b1[0x04] = samples[0x04] + samples[0x1B];
-  b1[0x05] = samples[0x05] + samples[0x1A];
-  b1[0x1B] = (samples[0x04] - samples[0x1B]) * costab[0x4];
-  b1[0x1A] = (samples[0x05] - samples[0x1A]) * costab[0x5];
-
-  b1[0x06] = samples[0x06] + samples[0x19];
-  b1[0x07] = samples[0x07] + samples[0x18];
-  b1[0x19] = (samples[0x06] - samples[0x19]) * costab[0x6];
-  b1[0x18] = (samples[0x07] - samples[0x18]) * costab[0x7];
-
-  b1[0x08] = samples[0x08] + samples[0x17];
-  b1[0x09] = samples[0x09] + samples[0x16];
-  b1[0x17] = (samples[0x08] - samples[0x17]) * costab[0x8];
-  b1[0x16] = (samples[0x09] - samples[0x16]) * costab[0x9];
-
-  b1[0x0A] = samples[0x0A] + samples[0x15];
-  b1[0x0B] = samples[0x0B] + samples[0x14];
-  b1[0x15] = (samples[0x0A] - samples[0x15]) * costab[0xA];
-  b1[0x14] = (samples[0x0B] - samples[0x14]) * costab[0xB];
-
-  b1[0x0C] = samples[0x0C] + samples[0x13];
-  b1[0x0D] = samples[0x0D] + samples[0x12];
-  b1[0x13] = (samples[0x0C] - samples[0x13]) * costab[0xC];
-  b1[0x12] = (samples[0x0D] - samples[0x12]) * costab[0xD];
-
-  b1[0x0E] = samples[0x0E] + samples[0x11];
-  b1[0x0F] = samples[0x0F] + samples[0x10];
-  b1[0x11] = (samples[0x0E] - samples[0x11]) * costab[0xE];
-  b1[0x10] = (samples[0x0F] - samples[0x10]) * costab[0xF];
-
- }
-
-
- {
-  register real *costab = pnts[1];
-
-  b2[0x00] = b1[0x00] + b1[0x0F]; 
-  b2[0x01] = b1[0x01] + b1[0x0E]; 
-  b2[0x0F] = (b1[0x00] - b1[0x0F]) * costab[0];
-  b2[0x0E] = (b1[0x01] - b1[0x0E]) * costab[1];
-
-  b2[0x02] = b1[0x02] + b1[0x0D]; 
-  b2[0x03] = b1[0x03] + b1[0x0C]; 
-  b2[0x0D] = (b1[0x02] - b1[0x0D]) * costab[2];
-  b2[0x0C] = (b1[0x03] - b1[0x0C]) * costab[3];
-
-  b2[0x04] = b1[0x04] + b1[0x0B]; 
-  b2[0x05] = b1[0x05] + b1[0x0A]; 
-  b2[0x0B] = (b1[0x04] - b1[0x0B]) * costab[4];
-  b2[0x0A] = (b1[0x05] - b1[0x0A]) * costab[5];
-
-  b2[0x06] = b1[0x06] + b1[0x09]; 
-  b2[0x07] = b1[0x07] + b1[0x08]; 
-  b2[0x09] = (b1[0x06] - b1[0x09]) * costab[6];
-  b2[0x08] = (b1[0x07] - b1[0x08]) * costab[7];
-
-  /* */
-
-  b2[0x10] = b1[0x10] + b1[0x1F];
-  b2[0x11] = b1[0x11] + b1[0x1E];
-  b2[0x1F] = (b1[0x1F] - b1[0x10]) * costab[0];
-  b2[0x1E] = (b1[0x1E] - b1[0x11]) * costab[1];
-
-  b2[0x12] = b1[0x12] + b1[0x1D];
-  b2[0x13] = b1[0x13] + b1[0x1C];
-  b2[0x1D] = (b1[0x1D] - b1[0x12]) * costab[2];
-  b2[0x1C] = (b1[0x1C] - b1[0x13]) * costab[3];
-
-  b2[0x14] = b1[0x14] + b1[0x1B];
-  b2[0x15] = b1[0x15] + b1[0x1A];
-  b2[0x1B] = (b1[0x1B] - b1[0x14]) * costab[4];
-  b2[0x1A] = (b1[0x1A] - b1[0x15]) * costab[5];
-
-  b2[0x16] = b1[0x16] + b1[0x19];
-  b2[0x17] = b1[0x17] + b1[0x18];
-  b2[0x19] = (b1[0x19] - b1[0x16]) * costab[6];
-  b2[0x18] = (b1[0x18] - b1[0x17]) * costab[7];
- }
-
- {
-  register real *costab = pnts[2];
-
-  b1[0x00] = b2[0x00] + b2[0x07];
-  b1[0x07] = (b2[0x00] - b2[0x07]) * costab[0];
-  b1[0x01] = b2[0x01] + b2[0x06];
-  b1[0x06] = (b2[0x01] - b2[0x06]) * costab[1];
-  b1[0x02] = b2[0x02] + b2[0x05];
-  b1[0x05] = (b2[0x02] - b2[0x05]) * costab[2];
-  b1[0x03] = b2[0x03] + b2[0x04];
-  b1[0x04] = (b2[0x03] - b2[0x04]) * costab[3];
-
-  b1[0x08] = b2[0x08] + b2[0x0F];
-  b1[0x0F] = (b2[0x0F] - b2[0x08]) * costab[0];
-  b1[0x09] = b2[0x09] + b2[0x0E];
-  b1[0x0E] = (b2[0x0E] - b2[0x09]) * costab[1];
-  b1[0x0A] = b2[0x0A] + b2[0x0D];
-  b1[0x0D] = (b2[0x0D] - b2[0x0A]) * costab[2];
-  b1[0x0B] = b2[0x0B] + b2[0x0C];
-  b1[0x0C] = (b2[0x0C] - b2[0x0B]) * costab[3];
-
-  b1[0x10] = b2[0x10] + b2[0x17];
-  b1[0x17] = (b2[0x10] - b2[0x17]) * costab[0];
-  b1[0x11] = b2[0x11] + b2[0x16];
-  b1[0x16] = (b2[0x11] - b2[0x16]) * costab[1];
-  b1[0x12] = b2[0x12] + b2[0x15];
-  b1[0x15] = (b2[0x12] - b2[0x15]) * costab[2];
-  b1[0x13] = b2[0x13] + b2[0x14];
-  b1[0x14] = (b2[0x13] - b2[0x14]) * costab[3];
-
-  b1[0x18] = b2[0x18] + b2[0x1F];
-  b1[0x1F] = (b2[0x1F] - b2[0x18]) * costab[0];
-  b1[0x19] = b2[0x19] + b2[0x1E];
-  b1[0x1E] = (b2[0x1E] - b2[0x19]) * costab[1];
-  b1[0x1A] = b2[0x1A] + b2[0x1D];
-  b1[0x1D] = (b2[0x1D] - b2[0x1A]) * costab[2];
-  b1[0x1B] = b2[0x1B] + b2[0x1C];
-  b1[0x1C] = (b2[0x1C] - b2[0x1B]) * costab[3];
- }
-
- {
-  register real const cos0 = pnts[3][0];
-  register real const cos1 = pnts[3][1];
-
-  b2[0x00] = b1[0x00] + b1[0x03];
-  b2[0x03] = (b1[0x00] - b1[0x03]) * cos0;
-  b2[0x01] = b1[0x01] + b1[0x02];
-  b2[0x02] = (b1[0x01] - b1[0x02]) * cos1;
-
-  b2[0x04] = b1[0x04] + b1[0x07];
-  b2[0x07] = (b1[0x07] - b1[0x04]) * cos0;
-  b2[0x05] = b1[0x05] + b1[0x06];
-  b2[0x06] = (b1[0x06] - b1[0x05]) * cos1;
-
-  b2[0x08] = b1[0x08] + b1[0x0B];
-  b2[0x0B] = (b1[0x08] - b1[0x0B]) * cos0;
-  b2[0x09] = b1[0x09] + b1[0x0A];
-  b2[0x0A] = (b1[0x09] - b1[0x0A]) * cos1;
-  
-  b2[0x0C] = b1[0x0C] + b1[0x0F];
-  b2[0x0F] = (b1[0x0F] - b1[0x0C]) * cos0;
-  b2[0x0D] = b1[0x0D] + b1[0x0E];
-  b2[0x0E] = (b1[0x0E] - b1[0x0D]) * cos1;
-
-  b2[0x10] = b1[0x10] + b1[0x13];
-  b2[0x13] = (b1[0x10] - b1[0x13]) * cos0;
-  b2[0x11] = b1[0x11] + b1[0x12];
-  b2[0x12] = (b1[0x11] - b1[0x12]) * cos1;
-
-  b2[0x14] = b1[0x14] + b1[0x17];
-  b2[0x17] = (b1[0x17] - b1[0x14]) * cos0;
-  b2[0x15] = b1[0x15] + b1[0x16];
-  b2[0x16] = (b1[0x16] - b1[0x15]) * cos1;
-
-  b2[0x18] = b1[0x18] + b1[0x1B];
-  b2[0x1B] = (b1[0x18] - b1[0x1B]) * cos0;
-  b2[0x19] = b1[0x19] + b1[0x1A];
-  b2[0x1A] = (b1[0x19] - b1[0x1A]) * cos1;
-
-  b2[0x1C] = b1[0x1C] + b1[0x1F];
-  b2[0x1F] = (b1[0x1F] - b1[0x1C]) * cos0;
-  b2[0x1D] = b1[0x1D] + b1[0x1E];
-  b2[0x1E] = (b1[0x1E] - b1[0x1D]) * cos1;
- }
-
- {
-  register real const cos0 = pnts[4][0];
-
-  b1[0x00] = b2[0x00] + b2[0x01];
-  b1[0x01] = (b2[0x00] - b2[0x01]) * cos0;
-  b1[0x02] = b2[0x02] + b2[0x03];
-  b1[0x03] = (b2[0x03] - b2[0x02]) * cos0;
-  b1[0x02] += b1[0x03];
-
-  b1[0x04] = b2[0x04] + b2[0x05];
-  b1[0x05] = (b2[0x04] - b2[0x05]) * cos0;
-  b1[0x06] = b2[0x06] + b2[0x07];
-  b1[0x07] = (b2[0x07] - b2[0x06]) * cos0;
-  b1[0x06] += b1[0x07];
-  b1[0x04] += b1[0x06];
-  b1[0x06] += b1[0x05];
-  b1[0x05] += b1[0x07];
-
-  b1[0x08] = b2[0x08] + b2[0x09];
-  b1[0x09] = (b2[0x08] - b2[0x09]) * cos0;
-  b1[0x0A] = b2[0x0A] + b2[0x0B];
-  b1[0x0B] = (b2[0x0B] - b2[0x0A]) * cos0;
-  b1[0x0A] += b1[0x0B];
-
-  b1[0x0C] = b2[0x0C] + b2[0x0D];
-  b1[0x0D] = (b2[0x0C] - b2[0x0D]) * cos0;
-  b1[0x0E] = b2[0x0E] + b2[0x0F];
-  b1[0x0F] = (b2[0x0F] - b2[0x0E]) * cos0;
-  b1[0x0E] += b1[0x0F];
-  b1[0x0C] += b1[0x0E];
-  b1[0x0E] += b1[0x0D];
-  b1[0x0D] += b1[0x0F];
-
-  b1[0x10] = b2[0x10] + b2[0x11];
-  b1[0x11] = (b2[0x10] - b2[0x11]) * cos0;
-  b1[0x12] = b2[0x12] + b2[0x13];
-  b1[0x13] = (b2[0x13] - b2[0x12]) * cos0;
-  b1[0x12] += b1[0x13];
-
-  b1[0x14] = b2[0x14] + b2[0x15];
-  b1[0x15] = (b2[0x14] - b2[0x15]) * cos0;
-  b1[0x16] = b2[0x16] + b2[0x17];
-  b1[0x17] = (b2[0x17] - b2[0x16]) * cos0;
-  b1[0x16] += b1[0x17];
-  b1[0x14] += b1[0x16];
-  b1[0x16] += b1[0x15];
-  b1[0x15] += b1[0x17];
-
-  b1[0x18] = b2[0x18] + b2[0x19];
-  b1[0x19] = (b2[0x18] - b2[0x19]) * cos0;
-  b1[0x1A] = b2[0x1A] + b2[0x1B];
-  b1[0x1B] = (b2[0x1B] - b2[0x1A]) * cos0;
-  b1[0x1A] += b1[0x1B];
-
-  b1[0x1C] = b2[0x1C] + b2[0x1D];
-  b1[0x1D] = (b2[0x1C] - b2[0x1D]) * cos0;
-  b1[0x1E] = b2[0x1E] + b2[0x1F];
-  b1[0x1F] = (b2[0x1F] - b2[0x1E]) * cos0;
-  b1[0x1E] += b1[0x1F];
-  b1[0x1C] += b1[0x1E];
-  b1[0x1E] += b1[0x1D];
-  b1[0x1D] += b1[0x1F];
- }
-
- out0[0x10*16] = b1[0x00];
- out0[0x10*12] = b1[0x04];
- out0[0x10* 8] = b1[0x02];
- out0[0x10* 4] = b1[0x06];
- out0[0x10* 0] = b1[0x01];
- out1[0x10* 0] = b1[0x01];
- out1[0x10* 4] = b1[0x05];
- out1[0x10* 8] = b1[0x03];
- out1[0x10*12] = b1[0x07];
+		b1[0x00] = samples[0x00] + samples[0x1F];
+		b1[0x01] = samples[0x01] + samples[0x1E];
+		b1[0x1F] = (samples[0x00] - samples[0x1F]) * costab[0x0];
+		b1[0x1E] = (samples[0x01] - samples[0x1E]) * costab[0x1];
+
+		b1[0x02] = samples[0x02] + samples[0x1D];
+		b1[0x03] = samples[0x03] + samples[0x1C];
+		b1[0x1D] = (samples[0x02] - samples[0x1D]) * costab[0x2];
+		b1[0x1C] = (samples[0x03] - samples[0x1C]) * costab[0x3];
+
+		b1[0x04] = samples[0x04] + samples[0x1B];
+		b1[0x05] = samples[0x05] + samples[0x1A];
+		b1[0x1B] = (samples[0x04] - samples[0x1B]) * costab[0x4];
+		b1[0x1A] = (samples[0x05] - samples[0x1A]) * costab[0x5];
+
+		b1[0x06] = samples[0x06] + samples[0x19];
+		b1[0x07] = samples[0x07] + samples[0x18];
+		b1[0x19] = (samples[0x06] - samples[0x19]) * costab[0x6];
+		b1[0x18] = (samples[0x07] - samples[0x18]) * costab[0x7];
+
+		b1[0x08] = samples[0x08] + samples[0x17];
+		b1[0x09] = samples[0x09] + samples[0x16];
+		b1[0x17] = (samples[0x08] - samples[0x17]) * costab[0x8];
+		b1[0x16] = (samples[0x09] - samples[0x16]) * costab[0x9];
+
+		b1[0x0A] = samples[0x0A] + samples[0x15];
+		b1[0x0B] = samples[0x0B] + samples[0x14];
+		b1[0x15] = (samples[0x0A] - samples[0x15]) * costab[0xA];
+		b1[0x14] = (samples[0x0B] - samples[0x14]) * costab[0xB];
+
+		b1[0x0C] = samples[0x0C] + samples[0x13];
+		b1[0x0D] = samples[0x0D] + samples[0x12];
+		b1[0x13] = (samples[0x0C] - samples[0x13]) * costab[0xC];
+		b1[0x12] = (samples[0x0D] - samples[0x12]) * costab[0xD];
+
+		b1[0x0E] = samples[0x0E] + samples[0x11];
+		b1[0x0F] = samples[0x0F] + samples[0x10];
+		b1[0x11] = (samples[0x0E] - samples[0x11]) * costab[0xE];
+		b1[0x10] = (samples[0x0F] - samples[0x10]) * costab[0xF];
+
+	}
+
+
+	{
+		register real *costab = pnts[1];
+
+		b2[0x00] = b1[0x00] + b1[0x0F];
+		b2[0x01] = b1[0x01] + b1[0x0E];
+		b2[0x0F] = (b1[0x00] - b1[0x0F]) * costab[0];
+		b2[0x0E] = (b1[0x01] - b1[0x0E]) * costab[1];
+
+		b2[0x02] = b1[0x02] + b1[0x0D];
+		b2[0x03] = b1[0x03] + b1[0x0C];
+		b2[0x0D] = (b1[0x02] - b1[0x0D]) * costab[2];
+		b2[0x0C] = (b1[0x03] - b1[0x0C]) * costab[3];
+
+		b2[0x04] = b1[0x04] + b1[0x0B];
+		b2[0x05] = b1[0x05] + b1[0x0A];
+		b2[0x0B] = (b1[0x04] - b1[0x0B]) * costab[4];
+		b2[0x0A] = (b1[0x05] - b1[0x0A]) * costab[5];
+
+		b2[0x06] = b1[0x06] + b1[0x09];
+		b2[0x07] = b1[0x07] + b1[0x08];
+		b2[0x09] = (b1[0x06] - b1[0x09]) * costab[6];
+		b2[0x08] = (b1[0x07] - b1[0x08]) * costab[7];
+
+		/* */
+
+		b2[0x10] = b1[0x10] + b1[0x1F];
+		b2[0x11] = b1[0x11] + b1[0x1E];
+		b2[0x1F] = (b1[0x1F] - b1[0x10]) * costab[0];
+		b2[0x1E] = (b1[0x1E] - b1[0x11]) * costab[1];
+
+		b2[0x12] = b1[0x12] + b1[0x1D];
+		b2[0x13] = b1[0x13] + b1[0x1C];
+		b2[0x1D] = (b1[0x1D] - b1[0x12]) * costab[2];
+		b2[0x1C] = (b1[0x1C] - b1[0x13]) * costab[3];
+
+		b2[0x14] = b1[0x14] + b1[0x1B];
+		b2[0x15] = b1[0x15] + b1[0x1A];
+		b2[0x1B] = (b1[0x1B] - b1[0x14]) * costab[4];
+		b2[0x1A] = (b1[0x1A] - b1[0x15]) * costab[5];
+
+		b2[0x16] = b1[0x16] + b1[0x19];
+		b2[0x17] = b1[0x17] + b1[0x18];
+		b2[0x19] = (b1[0x19] - b1[0x16]) * costab[6];
+		b2[0x18] = (b1[0x18] - b1[0x17]) * costab[7];
+	}
+
+	{
+		register real *costab = pnts[2];
+
+		b1[0x00] = b2[0x00] + b2[0x07];
+		b1[0x07] = (b2[0x00] - b2[0x07]) * costab[0];
+		b1[0x01] = b2[0x01] + b2[0x06];
+		b1[0x06] = (b2[0x01] - b2[0x06]) * costab[1];
+		b1[0x02] = b2[0x02] + b2[0x05];
+		b1[0x05] = (b2[0x02] - b2[0x05]) * costab[2];
+		b1[0x03] = b2[0x03] + b2[0x04];
+		b1[0x04] = (b2[0x03] - b2[0x04]) * costab[3];
+
+		b1[0x08] = b2[0x08] + b2[0x0F];
+		b1[0x0F] = (b2[0x0F] - b2[0x08]) * costab[0];
+		b1[0x09] = b2[0x09] + b2[0x0E];
+		b1[0x0E] = (b2[0x0E] - b2[0x09]) * costab[1];
+		b1[0x0A] = b2[0x0A] + b2[0x0D];
+		b1[0x0D] = (b2[0x0D] - b2[0x0A]) * costab[2];
+		b1[0x0B] = b2[0x0B] + b2[0x0C];
+		b1[0x0C] = (b2[0x0C] - b2[0x0B]) * costab[3];
+
+		b1[0x10] = b2[0x10] + b2[0x17];
+		b1[0x17] = (b2[0x10] - b2[0x17]) * costab[0];
+		b1[0x11] = b2[0x11] + b2[0x16];
+		b1[0x16] = (b2[0x11] - b2[0x16]) * costab[1];
+		b1[0x12] = b2[0x12] + b2[0x15];
+		b1[0x15] = (b2[0x12] - b2[0x15]) * costab[2];
+		b1[0x13] = b2[0x13] + b2[0x14];
+		b1[0x14] = (b2[0x13] - b2[0x14]) * costab[3];
+
+		b1[0x18] = b2[0x18] + b2[0x1F];
+		b1[0x1F] = (b2[0x1F] - b2[0x18]) * costab[0];
+		b1[0x19] = b2[0x19] + b2[0x1E];
+		b1[0x1E] = (b2[0x1E] - b2[0x19]) * costab[1];
+		b1[0x1A] = b2[0x1A] + b2[0x1D];
+		b1[0x1D] = (b2[0x1D] - b2[0x1A]) * costab[2];
+		b1[0x1B] = b2[0x1B] + b2[0x1C];
+		b1[0x1C] = (b2[0x1C] - b2[0x1B]) * costab[3];
+	}
+
+	{
+		register real const cos0 = pnts[3][0];
+		register real const cos1 = pnts[3][1];
+
+		b2[0x00] = b1[0x00] + b1[0x03];
+		b2[0x03] = (b1[0x00] - b1[0x03]) * cos0;
+		b2[0x01] = b1[0x01] + b1[0x02];
+		b2[0x02] = (b1[0x01] - b1[0x02]) * cos1;
+
+		b2[0x04] = b1[0x04] + b1[0x07];
+		b2[0x07] = (b1[0x07] - b1[0x04]) * cos0;
+		b2[0x05] = b1[0x05] + b1[0x06];
+		b2[0x06] = (b1[0x06] - b1[0x05]) * cos1;
+
+		b2[0x08] = b1[0x08] + b1[0x0B];
+		b2[0x0B] = (b1[0x08] - b1[0x0B]) * cos0;
+		b2[0x09] = b1[0x09] + b1[0x0A];
+		b2[0x0A] = (b1[0x09] - b1[0x0A]) * cos1;
+
+		b2[0x0C] = b1[0x0C] + b1[0x0F];
+		b2[0x0F] = (b1[0x0F] - b1[0x0C]) * cos0;
+		b2[0x0D] = b1[0x0D] + b1[0x0E];
+		b2[0x0E] = (b1[0x0E] - b1[0x0D]) * cos1;
+
+		b2[0x10] = b1[0x10] + b1[0x13];
+		b2[0x13] = (b1[0x10] - b1[0x13]) * cos0;
+		b2[0x11] = b1[0x11] + b1[0x12];
+		b2[0x12] = (b1[0x11] - b1[0x12]) * cos1;
+
+		b2[0x14] = b1[0x14] + b1[0x17];
+		b2[0x17] = (b1[0x17] - b1[0x14]) * cos0;
+		b2[0x15] = b1[0x15] + b1[0x16];
+		b2[0x16] = (b1[0x16] - b1[0x15]) * cos1;
+
+		b2[0x18] = b1[0x18] + b1[0x1B];
+		b2[0x1B] = (b1[0x18] - b1[0x1B]) * cos0;
+		b2[0x19] = b1[0x19] + b1[0x1A];
+		b2[0x1A] = (b1[0x19] - b1[0x1A]) * cos1;
+
+		b2[0x1C] = b1[0x1C] + b1[0x1F];
+		b2[0x1F] = (b1[0x1F] - b1[0x1C]) * cos0;
+		b2[0x1D] = b1[0x1D] + b1[0x1E];
+		b2[0x1E] = (b1[0x1E] - b1[0x1D]) * cos1;
+	}
+
+	{
+		register real const cos0 = pnts[4][0];
+
+		b1[0x00] = b2[0x00] + b2[0x01];
+		b1[0x01] = (b2[0x00] - b2[0x01]) * cos0;
+		b1[0x02] = b2[0x02] + b2[0x03];
+		b1[0x03] = (b2[0x03] - b2[0x02]) * cos0;
+		b1[0x02] += b1[0x03];
+
+		b1[0x04] = b2[0x04] + b2[0x05];
+		b1[0x05] = (b2[0x04] - b2[0x05]) * cos0;
+		b1[0x06] = b2[0x06] + b2[0x07];
+		b1[0x07] = (b2[0x07] - b2[0x06]) * cos0;
+		b1[0x06] += b1[0x07];
+		b1[0x04] += b1[0x06];
+		b1[0x06] += b1[0x05];
+		b1[0x05] += b1[0x07];
+
+		b1[0x08] = b2[0x08] + b2[0x09];
+		b1[0x09] = (b2[0x08] - b2[0x09]) * cos0;
+		b1[0x0A] = b2[0x0A] + b2[0x0B];
+		b1[0x0B] = (b2[0x0B] - b2[0x0A]) * cos0;
+		b1[0x0A] += b1[0x0B];
+
+		b1[0x0C] = b2[0x0C] + b2[0x0D];
+		b1[0x0D] = (b2[0x0C] - b2[0x0D]) * cos0;
+		b1[0x0E] = b2[0x0E] + b2[0x0F];
+		b1[0x0F] = (b2[0x0F] - b2[0x0E]) * cos0;
+		b1[0x0E] += b1[0x0F];
+		b1[0x0C] += b1[0x0E];
+		b1[0x0E] += b1[0x0D];
+		b1[0x0D] += b1[0x0F];
+
+		b1[0x10] = b2[0x10] + b2[0x11];
+		b1[0x11] = (b2[0x10] - b2[0x11]) * cos0;
+		b1[0x12] = b2[0x12] + b2[0x13];
+		b1[0x13] = (b2[0x13] - b2[0x12]) * cos0;
+		b1[0x12] += b1[0x13];
+
+		b1[0x14] = b2[0x14] + b2[0x15];
+		b1[0x15] = (b2[0x14] - b2[0x15]) * cos0;
+		b1[0x16] = b2[0x16] + b2[0x17];
+		b1[0x17] = (b2[0x17] - b2[0x16]) * cos0;
+		b1[0x16] += b1[0x17];
+		b1[0x14] += b1[0x16];
+		b1[0x16] += b1[0x15];
+		b1[0x15] += b1[0x17];
+
+		b1[0x18] = b2[0x18] + b2[0x19];
+		b1[0x19] = (b2[0x18] - b2[0x19]) * cos0;
+		b1[0x1A] = b2[0x1A] + b2[0x1B];
+		b1[0x1B] = (b2[0x1B] - b2[0x1A]) * cos0;
+		b1[0x1A] += b1[0x1B];
+
+		b1[0x1C] = b2[0x1C] + b2[0x1D];
+		b1[0x1D] = (b2[0x1C] - b2[0x1D]) * cos0;
+		b1[0x1E] = b2[0x1E] + b2[0x1F];
+		b1[0x1F] = (b2[0x1F] - b2[0x1E]) * cos0;
+		b1[0x1E] += b1[0x1F];
+		b1[0x1C] += b1[0x1E];
+		b1[0x1E] += b1[0x1D];
+		b1[0x1D] += b1[0x1F];
+	}
+
+	out0[0x10 * 16] = b1[0x00];
+	out0[0x10 * 12] = b1[0x04];
+	out0[0x10 * 8] = b1[0x02];
+	out0[0x10 * 4] = b1[0x06];
+	out0[0x10 * 0] = b1[0x01];
+	out1[0x10 * 0] = b1[0x01];
+	out1[0x10 * 4] = b1[0x05];
+	out1[0x10 * 8] = b1[0x03];
+	out1[0x10 * 12] = b1[0x07];
 
 #if 1
- out0[0x10*14] = b1[0x08] + b1[0x0C];
- out0[0x10*10] = b1[0x0C] + b1[0x0a];
- out0[0x10* 6] = b1[0x0A] + b1[0x0E];
- out0[0x10* 2] = b1[0x0E] + b1[0x09];
- out1[0x10* 2] = b1[0x09] + b1[0x0D];
- out1[0x10* 6] = b1[0x0D] + b1[0x0B];
- out1[0x10*10] = b1[0x0B] + b1[0x0F];
- out1[0x10*14] = b1[0x0F];
+	out0[0x10 * 14] = b1[0x08] + b1[0x0C];
+	out0[0x10 * 10] = b1[0x0C] + b1[0x0a];
+	out0[0x10 * 6] = b1[0x0A] + b1[0x0E];
+	out0[0x10 * 2] = b1[0x0E] + b1[0x09];
+	out1[0x10 * 2] = b1[0x09] + b1[0x0D];
+	out1[0x10 * 6] = b1[0x0D] + b1[0x0B];
+	out1[0x10 * 10] = b1[0x0B] + b1[0x0F];
+	out1[0x10 * 14] = b1[0x0F];
 #else
- b1[0x08] += b1[0x0C];
- out0[0x10*14] = b1[0x08];
- b1[0x0C] += b1[0x0a];
- out0[0x10*10] = b1[0x0C];
- b1[0x0A] += b1[0x0E];
- out0[0x10* 6] = b1[0x0A];
- b1[0x0E] += b1[0x09];
- out0[0x10* 2] = b1[0x0E];
- b1[0x09] += b1[0x0D];
- out1[0x10* 2] = b1[0x09];
- b1[0x0D] += b1[0x0B];
- out1[0x10* 6] = b1[0x0D];
- b1[0x0B] += b1[0x0F];
- out1[0x10*10] = b1[0x0B];
- out1[0x10*14] = b1[0x0F];
+	b1[0x08] += b1[0x0C];
+	out0[0x10 * 14] = b1[0x08];
+	b1[0x0C] += b1[0x0a];
+	out0[0x10 * 10] = b1[0x0C];
+	b1[0x0A] += b1[0x0E];
+	out0[0x10 * 6] = b1[0x0A];
+	b1[0x0E] += b1[0x09];
+	out0[0x10 * 2] = b1[0x0E];
+	b1[0x09] += b1[0x0D];
+	out1[0x10 * 2] = b1[0x09];
+	b1[0x0D] += b1[0x0B];
+	out1[0x10 * 6] = b1[0x0D];
+	b1[0x0B] += b1[0x0F];
+	out1[0x10 * 10] = b1[0x0B];
+	out1[0x10 * 14] = b1[0x0F];
 #endif
 
- { 
- real tmp;
- tmp = b1[0x18] + b1[0x1C];
- out0[0x10*15] = tmp + b1[0x10];
- out0[0x10*13] = tmp + b1[0x14];
- tmp = b1[0x1C] + b1[0x1A];
- out0[0x10*11] = tmp + b1[0x14];
- out0[0x10* 9] = tmp + b1[0x12];
- tmp = b1[0x1A] + b1[0x1E];
- out0[0x10* 7] = tmp + b1[0x12];
- out0[0x10* 5] = tmp + b1[0x16];
- tmp = b1[0x1E] + b1[0x19];
- out0[0x10* 3] = tmp + b1[0x16];
- out0[0x10* 1] = tmp + b1[0x11];
- tmp = b1[0x19] + b1[0x1D];
- out1[0x10* 1] = tmp + b1[0x11];
- out1[0x10* 3] = tmp + b1[0x15]; 
- tmp = b1[0x1D] + b1[0x1B];
- out1[0x10* 5] = tmp + b1[0x15];
- out1[0x10* 7] = tmp + b1[0x13];
- tmp = b1[0x1B] + b1[0x1F];
- out1[0x10* 9] = tmp + b1[0x13];
- out1[0x10*11] = tmp + b1[0x17];
- out1[0x10*13] = b1[0x17] + b1[0x1F];
- out1[0x10*15] = b1[0x1F];
- }
+	{
+		real tmp;
+		tmp = b1[0x18] + b1[0x1C];
+		out0[0x10 * 15] = tmp + b1[0x10];
+		out0[0x10 * 13] = tmp + b1[0x14];
+		tmp = b1[0x1C] + b1[0x1A];
+		out0[0x10 * 11] = tmp + b1[0x14];
+		out0[0x10 * 9] = tmp + b1[0x12];
+		tmp = b1[0x1A] + b1[0x1E];
+		out0[0x10 * 7] = tmp + b1[0x12];
+		out0[0x10 * 5] = tmp + b1[0x16];
+		tmp = b1[0x1E] + b1[0x19];
+		out0[0x10 * 3] = tmp + b1[0x16];
+		out0[0x10 * 1] = tmp + b1[0x11];
+		tmp = b1[0x19] + b1[0x1D];
+		out1[0x10 * 1] = tmp + b1[0x11];
+		out1[0x10 * 3] = tmp + b1[0x15];
+		tmp = b1[0x1D] + b1[0x1B];
+		out1[0x10 * 5] = tmp + b1[0x15];
+		out1[0x10 * 7] = tmp + b1[0x13];
+		tmp = b1[0x1B] + b1[0x1F];
+		out1[0x10 * 9] = tmp + b1[0x13];
+		out1[0x10 * 11] = tmp + b1[0x17];
+		out1[0x10 * 13] = b1[0x17] + b1[0x1F];
+		out1[0x10 * 15] = b1[0x1F];
+	}
 }
 
 /*
  * the call via dct64 is a trick to force GCC to use
  * (new) registers for the b1,b2 pointer to the bufs[xx] field
  */
-void dct64(real *a,real *b,real *c)
+void dct64(real * a, real * b, real * c)
 {
-  real bufs[0x40];
-  dct64_1(a,b,bufs,bufs+0x20,c);
+	real bufs[0x40];
+	dct64_1(a, b, bufs, bufs + 0x20, c);
 }
-

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/decode_i386.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/decode_i386.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/decode_i386.c	Fri Mar 30 12:19:18 2007
@@ -25,129 +25,124 @@
   else if( (sum) < -32768.0) { *(samples) = -0x8000; (clip)++; } \
   else { *(samples) = sum; }
 
-int synth_1to1_mono(struct mpstr *mp,real *bandPtr,unsigned char *samples,int *pnt)
+int synth_1to1_mono(struct mpstr *mp, real * bandPtr, unsigned char *samples, int *pnt)
 {
-  short samples_tmp[64];
-  short *tmp1 = samples_tmp;
-  int i,ret;
-  int pnt1 = 0;
-
-  ret = synth_1to1(mp,bandPtr,0,(unsigned char *) samples_tmp,&pnt1);
-  samples += *pnt;
-
-  for(i=0;i<32;i++) {
-    *( (short *) samples) = *tmp1;
-    samples += 2;
-    tmp1 += 2;
-  }
-  *pnt += 64;
+	short samples_tmp[64];
+	short *tmp1 = samples_tmp;
+	int i, ret;
+	int pnt1 = 0;
+
+	ret = synth_1to1(mp, bandPtr, 0, (unsigned char *) samples_tmp, &pnt1);
+	samples += *pnt;
+
+	for (i = 0; i < 32; i++) {
+		*((short *) samples) = *tmp1;
+		samples += 2;
+		tmp1 += 2;
+	}
+	*pnt += 64;
 
-  return ret;
+	return ret;
 }
 
 
-int synth_1to1(struct mpstr *mp, real *bandPtr,int channel,unsigned char *out,int *pnt)
+int synth_1to1(struct mpstr *mp, real * bandPtr, int channel, unsigned char *out, int *pnt)
 {
-  static const int step = 2;
-  int bo;
-  short *samples = (short *) (out + *pnt);
-
-  real *b0,(*buf)[0x110];
-  int clip = 0; 
-  int bo1;
-
-  bo = mp->synth_bo;
-
-  if(!channel) {
-    bo--;
-    bo &= 0xf;
-    buf = mp->synth_buffs[0];
-  }
-  else {
-    samples++;
-    buf = mp->synth_buffs[1];
-  }
-
-  if(bo & 0x1) {
-    b0 = buf[0];
-    bo1 = bo;
-    dct64(buf[1]+((bo+1)&0xf),buf[0]+bo,bandPtr);
-  }
-  else {
-    b0 = buf[1];
-    bo1 = bo+1;
-    dct64(buf[0]+bo,buf[1]+bo+1,bandPtr);
-  }
-
-  mp->synth_bo = bo;
-  
-  {
-    register int j;
-    real *window = decwin + 16 - bo1;
-
-    for (j=16;j;j--,b0+=0x10,window+=0x20,samples+=step)
-    {
-      real sum;
-      sum  = window[0x0] * b0[0x0];
-      sum -= window[0x1] * b0[0x1];
-      sum += window[0x2] * b0[0x2];
-      sum -= window[0x3] * b0[0x3];
-      sum += window[0x4] * b0[0x4];
-      sum -= window[0x5] * b0[0x5];
-      sum += window[0x6] * b0[0x6];
-      sum -= window[0x7] * b0[0x7];
-      sum += window[0x8] * b0[0x8];
-      sum -= window[0x9] * b0[0x9];
-      sum += window[0xA] * b0[0xA];
-      sum -= window[0xB] * b0[0xB];
-      sum += window[0xC] * b0[0xC];
-      sum -= window[0xD] * b0[0xD];
-      sum += window[0xE] * b0[0xE];
-      sum -= window[0xF] * b0[0xF];
-
-      WRITE_SAMPLE(samples,sum,clip);
-    }
-
-    {
-      real sum;
-      sum  = window[0x0] * b0[0x0];
-      sum += window[0x2] * b0[0x2];
-      sum += window[0x4] * b0[0x4];
-      sum += window[0x6] * b0[0x6];
-      sum += window[0x8] * b0[0x8];
-      sum += window[0xA] * b0[0xA];
-      sum += window[0xC] * b0[0xC];
-      sum += window[0xE] * b0[0xE];
-      WRITE_SAMPLE(samples,sum,clip);
-      b0-=0x10,window-=0x20,samples+=step;
-    }
-    window += bo1<<1;
-
-    for (j=15;j;j--,b0-=0x10,window-=0x20,samples+=step)
-    {
-      real sum;
-      sum = -window[-0x1] * b0[0x0];
-      sum -= window[-0x2] * b0[0x1];
-      sum -= window[-0x3] * b0[0x2];
-      sum -= window[-0x4] * b0[0x3];
-      sum -= window[-0x5] * b0[0x4];
-      sum -= window[-0x6] * b0[0x5];
-      sum -= window[-0x7] * b0[0x6];
-      sum -= window[-0x8] * b0[0x7];
-      sum -= window[-0x9] * b0[0x8];
-      sum -= window[-0xA] * b0[0x9];
-      sum -= window[-0xB] * b0[0xA];
-      sum -= window[-0xC] * b0[0xB];
-      sum -= window[-0xD] * b0[0xC];
-      sum -= window[-0xE] * b0[0xD];
-      sum -= window[-0xF] * b0[0xE];
-      sum -= window[-0x0] * b0[0xF];
-
-      WRITE_SAMPLE(samples,sum,clip);
-    }
-  }
-  *pnt += 128;
+	static const int step = 2;
+	int bo;
+	short *samples = (short *) (out + *pnt);
+
+	real *b0, (*buf)[0x110];
+	int clip = 0;
+	int bo1;
+
+	bo = mp->synth_bo;
+
+	if (!channel) {
+		bo--;
+		bo &= 0xf;
+		buf = mp->synth_buffs[0];
+	} else {
+		samples++;
+		buf = mp->synth_buffs[1];
+	}
+
+	if (bo & 0x1) {
+		b0 = buf[0];
+		bo1 = bo;
+		dct64(buf[1] + ((bo + 1) & 0xf), buf[0] + bo, bandPtr);
+	} else {
+		b0 = buf[1];
+		bo1 = bo + 1;
+		dct64(buf[0] + bo, buf[1] + bo + 1, bandPtr);
+	}
+
+	mp->synth_bo = bo;
+
+	{
+		register int j;
+		real *window = decwin + 16 - bo1;
+
+		for (j = 16; j; j--, b0 += 0x10, window += 0x20, samples += step) {
+			real sum;
+			sum = window[0x0] * b0[0x0];
+			sum -= window[0x1] * b0[0x1];
+			sum += window[0x2] * b0[0x2];
+			sum -= window[0x3] * b0[0x3];
+			sum += window[0x4] * b0[0x4];
+			sum -= window[0x5] * b0[0x5];
+			sum += window[0x6] * b0[0x6];
+			sum -= window[0x7] * b0[0x7];
+			sum += window[0x8] * b0[0x8];
+			sum -= window[0x9] * b0[0x9];
+			sum += window[0xA] * b0[0xA];
+			sum -= window[0xB] * b0[0xB];
+			sum += window[0xC] * b0[0xC];
+			sum -= window[0xD] * b0[0xD];
+			sum += window[0xE] * b0[0xE];
+			sum -= window[0xF] * b0[0xF];
+
+			WRITE_SAMPLE(samples, sum, clip);
+		}
+
+		{
+			real sum;
+			sum = window[0x0] * b0[0x0];
+			sum += window[0x2] * b0[0x2];
+			sum += window[0x4] * b0[0x4];
+			sum += window[0x6] * b0[0x6];
+			sum += window[0x8] * b0[0x8];
+			sum += window[0xA] * b0[0xA];
+			sum += window[0xC] * b0[0xC];
+			sum += window[0xE] * b0[0xE];
+			WRITE_SAMPLE(samples, sum, clip);
+			b0 -= 0x10, window -= 0x20, samples += step;
+		}
+		window += bo1 << 1;
+
+		for (j = 15; j; j--, b0 -= 0x10, window -= 0x20, samples += step) {
+			real sum;
+			sum = -window[-0x1] * b0[0x0];
+			sum -= window[-0x2] * b0[0x1];
+			sum -= window[-0x3] * b0[0x2];
+			sum -= window[-0x4] * b0[0x3];
+			sum -= window[-0x5] * b0[0x4];
+			sum -= window[-0x6] * b0[0x5];
+			sum -= window[-0x7] * b0[0x6];
+			sum -= window[-0x8] * b0[0x7];
+			sum -= window[-0x9] * b0[0x8];
+			sum -= window[-0xA] * b0[0x9];
+			sum -= window[-0xB] * b0[0xA];
+			sum -= window[-0xC] * b0[0xB];
+			sum -= window[-0xD] * b0[0xC];
+			sum -= window[-0xE] * b0[0xD];
+			sum -= window[-0xF] * b0[0xE];
+			sum -= window[-0x0] * b0[0xF];
+
+			WRITE_SAMPLE(samples, sum, clip);
+		}
+	}
+	*pnt += 128;
 
-  return clip;
+	return clip;
 }
-

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/decode_ntom.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/decode_ntom.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/decode_ntom.c	Fri Mar 30 12:19:18 2007
@@ -21,198 +21,191 @@
   else { *(samples) = sum; }
 
 #define NTOM_MUL (32768)
-static unsigned long ntom_val[2] = { NTOM_MUL>>1,NTOM_MUL>>1 };
+static unsigned long ntom_val[2] = { NTOM_MUL >> 1, NTOM_MUL >> 1 };
 static unsigned long ntom_step = NTOM_MUL;
 
 
-int synth_ntom_set_step(long m,long n)
+int synth_ntom_set_step(long m, long n)
 {
-	if(param.verbose > 1)
-		debug_printf("Init rate converter: %ld->%ld\n",m,n);
+	if (param.verbose > 1)
+		debug_printf("Init rate converter: %ld->%ld\n", m, n);
 
-	if(n >= 96000 || m >= 96000 || m == 0 || n == 0) {
-		debug_printf("NtoM converter: %d illegal rates\n",  __LINE__);
+	if (n >= 96000 || m >= 96000 || m == 0 || n == 0) {
+		debug_printf("NtoM converter: %d illegal rates\n", __LINE__);
 		return (1);
 	}
 
 	n *= NTOM_MUL;
 	ntom_step = n / m;
 
-	if(ntom_step > 8*NTOM_MUL) {
-		debug_printf("%d max. 1:8 conversion allowed!\n",  __LINE__);
+	if (ntom_step > 8 * NTOM_MUL) {
+		debug_printf("%d max. 1:8 conversion allowed!\n", __LINE__);
 		return (1);
 	}
 
-	ntom_val[0] = ntom_val[1] = NTOM_MUL>>1;
+	ntom_val[0] = ntom_val[1] = NTOM_MUL >> 1;
 
 	return (0);
-	
+
 }
 
 
-int synth_ntom_mono (struct mpstr *mp, real *bandPtr,unsigned char *samples,int *pnt)
+int synth_ntom_mono(struct mpstr *mp, real * bandPtr, unsigned char *samples, int *pnt)
 {
-  short samples_tmp[8*64];
-  short *tmp1 = samples_tmp;
-  int i,ret;
-  int pnt1 = 0;
-
-  ret = synth_ntom(mp, bandPtr,0,(unsigned char *) samples_tmp,&pnt1);
-  samples += *pnt;
-
-  for(i=0;i<(pnt1>>2);i++) {
-    *( (short *)samples) = *tmp1;
-    samples += 2;
-    tmp1 += 2;
-  }
-  *pnt += pnt1 >> 1;
+	short samples_tmp[8 * 64];
+	short *tmp1 = samples_tmp;
+	int i, ret;
+	int pnt1 = 0;
+
+	ret = synth_ntom(mp, bandPtr, 0, (unsigned char *) samples_tmp, &pnt1);
+	samples += *pnt;
+
+	for (i = 0; i < (pnt1 >> 2); i++) {
+		*((short *) samples) = *tmp1;
+		samples += 2;
+		tmp1 += 2;
+	}
+	*pnt += pnt1 >> 1;
 
-  return ret;
+	return ret;
 }
 
 
 
-int synth_ntom(struct mpstr *mp, real *bandPtr,int channel,unsigned char *out,int *pnt)
+int synth_ntom(struct mpstr *mp, real * bandPtr, int channel, unsigned char *out, int *pnt)
 {
-  static const int step = 2;
-  int bo;
-  short *samples = (short *) (out + *pnt);
-
-  real *b0,(*buf)[0x110];
-  int clip = 0; 
-  int bo1;
-  int ntom;
-
-  bo = mp->synth_bo;
-  
-  if(!channel) {
-    bo--;
-    bo &= 0xf;
-    buf = mp->synth_buffs[0];
-    ntom = ntom_val[1] = ntom_val[0];
-  }
-  else {
-    samples++;
-    out += 2; /* to compute the right *pnt value */
-    buf = mp->synth_buffs[1];
-    ntom = ntom_val[1];
-  }
-
-  if(bo & 0x1) {
-    b0 = buf[0];
-    bo1 = bo;
-    dct64(buf[1]+((bo+1)&0xf),buf[0]+bo,bandPtr);
-  }
-  else {
-    b0 = buf[1];
-    bo1 = bo+1;
-    dct64(buf[0]+bo,buf[1]+bo+1,bandPtr);
-  }
-
-  mp->synth_bo = bo;
-  
-  {
-    register int j;
-    real *window = (mp->decwin) + 16 - bo1;
- 
-    for (j=16;j;j--,window+=0x10)
-    {
-      real sum;
-
-      ntom += ntom_step;
-      if(ntom < NTOM_MUL) {
-        window += 16;
-        b0 += 16;
-        continue;
-      }
-
-      sum  = *window++ * *b0++;
-      sum -= *window++ * *b0++;
-      sum += *window++ * *b0++;
-      sum -= *window++ * *b0++;
-      sum += *window++ * *b0++;
-      sum -= *window++ * *b0++;
-      sum += *window++ * *b0++;
-      sum -= *window++ * *b0++;
-      sum += *window++ * *b0++;
-      sum -= *window++ * *b0++;
-      sum += *window++ * *b0++;
-      sum -= *window++ * *b0++;
-      sum += *window++ * *b0++;
-      sum -= *window++ * *b0++;
-      sum += *window++ * *b0++;
-      sum -= *window++ * *b0++;
-
-      while(ntom >= NTOM_MUL) {
-        WRITE_SAMPLE(samples,sum,clip);
-        samples += step;
-        ntom -= NTOM_MUL;
-      }
-    }
-
-    ntom += ntom_step;
-    if(ntom >= NTOM_MUL)
-    {
-      real sum;
-      sum  = window[0x0] * b0[0x0];
-      sum += window[0x2] * b0[0x2];
-      sum += window[0x4] * b0[0x4];
-      sum += window[0x6] * b0[0x6];
-      sum += window[0x8] * b0[0x8];
-      sum += window[0xA] * b0[0xA];
-      sum += window[0xC] * b0[0xC];
-      sum += window[0xE] * b0[0xE];
-
-      while(ntom >= NTOM_MUL) {
-        WRITE_SAMPLE(samples,sum,clip);
-        samples += step;
-        ntom -= NTOM_MUL;
-      }
-    }
-
-    b0-=0x10,window-=0x20;
-    window += bo1<<1;
-
-    for (j=15;j;j--,b0-=0x20,window-=0x10)
-    {
-      real sum;
-
-      ntom += ntom_step;
-      if(ntom < NTOM_MUL) {
-        window -= 16;
-        b0 += 16;
-        continue;
-      }
-
-      sum = -*(--window) * *b0++;
-      sum -= *(--window) * *b0++;
-      sum -= *(--window) * *b0++;
-      sum -= *(--window) * *b0++;
-      sum -= *(--window) * *b0++;
-      sum -= *(--window) * *b0++;
-      sum -= *(--window) * *b0++;
-      sum -= *(--window) * *b0++;
-      sum -= *(--window) * *b0++;
-      sum -= *(--window) * *b0++;
-      sum -= *(--window) * *b0++;
-      sum -= *(--window) * *b0++;
-      sum -= *(--window) * *b0++;
-      sum -= *(--window) * *b0++;
-      sum -= *(--window) * *b0++;
-      sum -= *(--window) * *b0++;
-
-      while(ntom >= NTOM_MUL) {
-        WRITE_SAMPLE(samples,sum,clip);
-        samples += step;
-        ntom -= NTOM_MUL;
-      }
-    }
-  }
+	static const int step = 2;
+	int bo;
+	short *samples = (short *) (out + *pnt);
+
+	real *b0, (*buf)[0x110];
+	int clip = 0;
+	int bo1;
+	int ntom;
+
+	bo = mp->synth_bo;
+
+	if (!channel) {
+		bo--;
+		bo &= 0xf;
+		buf = mp->synth_buffs[0];
+		ntom = ntom_val[1] = ntom_val[0];
+	} else {
+		samples++;
+		out += 2;				/* to compute the right *pnt value */
+		buf = mp->synth_buffs[1];
+		ntom = ntom_val[1];
+	}
+
+	if (bo & 0x1) {
+		b0 = buf[0];
+		bo1 = bo;
+		dct64(buf[1] + ((bo + 1) & 0xf), buf[0] + bo, bandPtr);
+	} else {
+		b0 = buf[1];
+		bo1 = bo + 1;
+		dct64(buf[0] + bo, buf[1] + bo + 1, bandPtr);
+	}
 
-  ntom_val[channel] = ntom;
-  *pnt = ((unsigned char *) samples - out);
+	mp->synth_bo = bo;
 
-  return clip;
-}
+	{
+		register int j;
+		real *window = (mp->decwin) + 16 - bo1;
+
+		for (j = 16; j; j--, window += 0x10) {
+			real sum;
+
+			ntom += ntom_step;
+			if (ntom < NTOM_MUL) {
+				window += 16;
+				b0 += 16;
+				continue;
+			}
+
+			sum = *window++ * *b0++;
+			sum -= *window++ * *b0++;
+			sum += *window++ * *b0++;
+			sum -= *window++ * *b0++;
+			sum += *window++ * *b0++;
+			sum -= *window++ * *b0++;
+			sum += *window++ * *b0++;
+			sum -= *window++ * *b0++;
+			sum += *window++ * *b0++;
+			sum -= *window++ * *b0++;
+			sum += *window++ * *b0++;
+			sum -= *window++ * *b0++;
+			sum += *window++ * *b0++;
+			sum -= *window++ * *b0++;
+			sum += *window++ * *b0++;
+			sum -= *window++ * *b0++;
+
+			while (ntom >= NTOM_MUL) {
+				WRITE_SAMPLE(samples, sum, clip);
+				samples += step;
+				ntom -= NTOM_MUL;
+			}
+		}
+
+		ntom += ntom_step;
+		if (ntom >= NTOM_MUL) {
+			real sum;
+			sum = window[0x0] * b0[0x0];
+			sum += window[0x2] * b0[0x2];
+			sum += window[0x4] * b0[0x4];
+			sum += window[0x6] * b0[0x6];
+			sum += window[0x8] * b0[0x8];
+			sum += window[0xA] * b0[0xA];
+			sum += window[0xC] * b0[0xC];
+			sum += window[0xE] * b0[0xE];
+
+			while (ntom >= NTOM_MUL) {
+				WRITE_SAMPLE(samples, sum, clip);
+				samples += step;
+				ntom -= NTOM_MUL;
+			}
+		}
+
+		b0 -= 0x10, window -= 0x20;
+		window += bo1 << 1;
+
+		for (j = 15; j; j--, b0 -= 0x20, window -= 0x10) {
+			real sum;
+
+			ntom += ntom_step;
+			if (ntom < NTOM_MUL) {
+				window -= 16;
+				b0 += 16;
+				continue;
+			}
+
+			sum = -*(--window) * *b0++;
+			sum -= *(--window) * *b0++;
+			sum -= *(--window) * *b0++;
+			sum -= *(--window) * *b0++;
+			sum -= *(--window) * *b0++;
+			sum -= *(--window) * *b0++;
+			sum -= *(--window) * *b0++;
+			sum -= *(--window) * *b0++;
+			sum -= *(--window) * *b0++;
+			sum -= *(--window) * *b0++;
+			sum -= *(--window) * *b0++;
+			sum -= *(--window) * *b0++;
+			sum -= *(--window) * *b0++;
+			sum -= *(--window) * *b0++;
+			sum -= *(--window) * *b0++;
+			sum -= *(--window) * *b0++;
+
+			while (ntom >= NTOM_MUL) {
+				WRITE_SAMPLE(samples, sum, clip);
+				samples += step;
+				ntom -= NTOM_MUL;
+			}
+		}
+	}
 
+	ntom_val[channel] = ntom;
+	*pnt = ((unsigned char *) samples - out);
 
+	return clip;
+}

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/huffman.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/huffman.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/huffman.h	Fri Mar 30 12:19:18 2007
@@ -6,327 +6,304 @@
  * smaller tables are often the part of a bigger table
  */
 
-struct newhuff 
-{
-  unsigned int linbits;
-  short *table;
-};
-
-static short tab0[] = 
-{ 
-   0
-};
-
-static short tab1[] =
-{
-  -5,  -3,  -1,  17,   1,  16,   0
-};
-
-static short tab2[] =
-{
- -15, -11,  -9,  -5,  -3,  -1,  34,   2,  18,  -1,  33,  32,  17,  -1,   1,
-  16,   0
-};
-
-static short tab3[] =
-{
- -13, -11,  -9,  -5,  -3,  -1,  34,   2,  18,  -1,  33,  32,  16,  17,  -1,
-   1,   0
-};
-
-static short tab5[] =
-{
- -29, -25, -23, -15,  -7,  -5,  -3,  -1,  51,  35,  50,  49,  -3,  -1,  19,
-   3,  -1,  48,  34,  -3,  -1,  18,  33,  -1,   2,  32,  17,  -1,   1,  16,
-   0
-};
-
-static short tab6[] =
-{
- -25, -19, -13,  -9,  -5,  -3,  -1,  51,   3,  35,  -1,  50,  48,  -1,  19,
-  49,  -3,  -1,  34,   2,  18,  -3,  -1,  33,  32,   1,  -1,  17,  -1,  16,
-   0
-};
-
-static short tab7[] =
-{
- -69, -65, -57, -39, -29, -17, -11,  -7,  -3,  -1,  85,  69,  -1,  84,  83,
-  -1,  53,  68,  -3,  -1,  37,  82,  21,  -5,  -1,  81,  -1,   5,  52,  -1,
-  80,  -1,  67,  51,  -5,  -3,  -1,  36,  66,  20,  -1,  65,  64, -11,  -7,
-  -3,  -1,   4,  35,  -1,  50,   3,  -1,  19,  49,  -3,  -1,  48,  34,  18,
-  -5,  -1,  33,  -1,   2,  32,  17,  -1,   1,  16,   0
-};
-
-static short tab8[] =
-{
- -65, -63, -59, -45, -31, -19, -13,  -7,  -5,  -3,  -1,  85,  84,  69,  83,
-  -3,  -1,  53,  68,  37,  -3,  -1,  82,   5,  21,  -5,  -1,  81,  -1,  52,
-  67,  -3,  -1,  80,  51,  36,  -5,  -3,  -1,  66,  20,  65,  -3,  -1,   4,
-  64,  -1,  35,  50,  -9,  -7,  -3,  -1,  19,  49,  -1,   3,  48,  34,  -1,
-   2,  32,  -1,  18,  33,  17,  -3,  -1,   1,  16,   0
-};
-
-static short tab9[] =
-{
- -63, -53, -41, -29, -19, -11,  -5,  -3,  -1,  85,  69,  53,  -1,  83,  -1,
-  84,   5,  -3,  -1,  68,  37,  -1,  82,  21,  -3,  -1,  81,  52,  -1,  67,
-  -1,  80,   4,  -7,  -3,  -1,  36,  66,  -1,  51,  64,  -1,  20,  65,  -5,
-  -3,  -1,  35,  50,  19,  -1,  49,  -1,   3,  48,  -5,  -3,  -1,  34,   2,
-  18,  -1,  33,  32,  -3,  -1,  17,   1,  -1,  16,   0
-};
-
-static short tab10[] =
-{
--125,-121,-111, -83, -55, -35, -21, -13,  -7,  -3,  -1, 119, 103,  -1, 118,
-  87,  -3,  -1, 117, 102,  71,  -3,  -1, 116,  86,  -1, 101,  55,  -9,  -3,
-  -1, 115,  70,  -3,  -1,  85,  84,  99,  -1,  39, 114, -11,  -5,  -3,  -1,
- 100,   7, 112,  -1,  98,  -1,  69,  53,  -5,  -1,   6,  -1,  83,  68,  23,
- -17,  -5,  -1, 113,  -1,  54,  38,  -5,  -3,  -1,  37,  82,  21,  -1,  81,
-  -1,  52,  67,  -3,  -1,  22,  97,  -1,  96,  -1,   5,  80, -19, -11,  -7,
-  -3,  -1,  36,  66,  -1,  51,   4,  -1,  20,  65,  -3,  -1,  64,  35,  -1,
-  50,   3,  -3,  -1,  19,  49,  -1,  48,  34,  -7,  -3,  -1,  18,  33,  -1,
-   2,  32,  17,  -1,   1,  16,   0
-};
-
-static short tab11[] =
-{
--121,-113, -89, -59, -43, -27, -17,  -7,  -3,  -1, 119, 103,  -1, 118, 117,
-  -3,  -1, 102,  71,  -1, 116,  -1,  87,  85,  -5,  -3,  -1,  86, 101,  55,
-  -1, 115,  70,  -9,  -7,  -3,  -1,  69,  84,  -1,  53,  83,  39,  -1, 114,
-  -1, 100,   7,  -5,  -1, 113,  -1,  23, 112,  -3,  -1,  54,  99,  -1,  96,
-  -1,  68,  37, -13,  -7,  -5,  -3,  -1,  82,   5,  21,  98,  -3,  -1,  38,
-   6,  22,  -5,  -1,  97,  -1,  81,  52,  -5,  -1,  80,  -1,  67,  51,  -1,
-  36,  66, -15, -11,  -7,  -3,  -1,  20,  65,  -1,   4,  64,  -1,  35,  50,
-  -1,  19,  49,  -5,  -3,  -1,   3,  48,  34,  33,  -5,  -1,  18,  -1,   2,
-  32,  17,  -3,  -1,   1,  16,   0
-};
-
-static short tab12[] =
-{
--115, -99, -73, -45, -27, -17,  -9,  -5,  -3,  -1, 119, 103, 118,  -1,  87,
- 117,  -3,  -1, 102,  71,  -1, 116, 101,  -3,  -1,  86,  55,  -3,  -1, 115,
-  85,  39,  -7,  -3,  -1, 114,  70,  -1, 100,  23,  -5,  -1, 113,  -1,   7,
- 112,  -1,  54,  99, -13,  -9,  -3,  -1,  69,  84,  -1,  68,  -1,   6,   5,
-  -1,  38,  98,  -5,  -1,  97,  -1,  22,  96,  -3,  -1,  53,  83,  -1,  37,
-  82, -17,  -7,  -3,  -1,  21,  81,  -1,  52,  67,  -5,  -3,  -1,  80,   4,
-  36,  -1,  66,  20,  -3,  -1,  51,  65,  -1,  35,  50, -11,  -7,  -5,  -3,
-  -1,  64,   3,  48,  19,  -1,  49,  34,  -1,  18,  33,  -7,  -5,  -3,  -1,
-   2,  32,   0,  17,  -1,   1,  16
-};
-
-static short tab13[] =
-{
--509,-503,-475,-405,-333,-265,-205,-153,-115, -83, -53, -35, -21, -13,  -9,
-  -7,  -5,  -3,  -1, 254, 252, 253, 237, 255,  -1, 239, 223,  -3,  -1, 238,
- 207,  -1, 222, 191,  -9,  -3,  -1, 251, 206,  -1, 220,  -1, 175, 233,  -1,
- 236, 221,  -9,  -5,  -3,  -1, 250, 205, 190,  -1, 235, 159,  -3,  -1, 249,
- 234,  -1, 189, 219, -17,  -9,  -3,  -1, 143, 248,  -1, 204,  -1, 174, 158,
-  -5,  -1, 142,  -1, 127, 126, 247,  -5,  -1, 218,  -1, 173, 188,  -3,  -1,
- 203, 246, 111, -15,  -7,  -3,  -1, 232,  95,  -1, 157, 217,  -3,  -1, 245,
- 231,  -1, 172, 187,  -9,  -3,  -1,  79, 244,  -3,  -1, 202, 230, 243,  -1,
-  63,  -1, 141, 216, -21,  -9,  -3,  -1,  47, 242,  -3,  -1, 110, 156,  15,
-  -5,  -3,  -1, 201,  94, 171,  -3,  -1, 125, 215,  78, -11,  -5,  -3,  -1,
- 200, 214,  62,  -1, 185,  -1, 155, 170,  -1,  31, 241, -23, -13,  -5,  -1,
- 240,  -1, 186, 229,  -3,  -1, 228, 140,  -1, 109, 227,  -5,  -1, 226,  -1,
-  46,  14,  -1,  30, 225, -15,  -7,  -3,  -1, 224,  93,  -1, 213, 124,  -3,
-  -1, 199,  77,  -1, 139, 184,  -7,  -3,  -1, 212, 154,  -1, 169, 108,  -1,
- 198,  61, -37, -21,  -9,  -5,  -3,  -1, 211, 123,  45,  -1, 210,  29,  -5,
-  -1, 183,  -1,  92, 197,  -3,  -1, 153, 122, 195,  -7,  -5,  -3,  -1, 167,
- 151,  75, 209,  -3,  -1,  13, 208,  -1, 138, 168, -11,  -7,  -3,  -1,  76,
- 196,  -1, 107, 182,  -1,  60,  44,  -3,  -1, 194,  91,  -3,  -1, 181, 137,
-  28, -43, -23, -11,  -5,  -1, 193,  -1, 152,  12,  -1, 192,  -1, 180, 106,
-  -5,  -3,  -1, 166, 121,  59,  -1, 179,  -1, 136,  90, -11,  -5,  -1,  43,
-  -1, 165, 105,  -1, 164,  -1, 120, 135,  -5,  -1, 148,  -1, 119, 118, 178,
- -11,  -3,  -1,  27, 177,  -3,  -1,  11, 176,  -1, 150,  74,  -7,  -3,  -1,
-  58, 163,  -1,  89, 149,  -1,  42, 162, -47, -23,  -9,  -3,  -1,  26, 161,
-  -3,  -1,  10, 104, 160,  -5,  -3,  -1, 134,  73, 147,  -3,  -1,  57,  88,
-  -1, 133, 103,  -9,  -3,  -1,  41, 146,  -3,  -1,  87, 117,  56,  -5,  -1,
- 131,  -1, 102,  71,  -3,  -1, 116,  86,  -1, 101, 115, -11,  -3,  -1,  25,
- 145,  -3,  -1,   9, 144,  -1,  72, 132,  -7,  -5,  -1, 114,  -1,  70, 100,
-  40,  -1, 130,  24, -41, -27, -11,  -5,  -3,  -1,  55,  39,  23,  -1, 113,
-  -1,  85,   7,  -7,  -3,  -1, 112,  54,  -1,  99,  69,  -3,  -1,  84,  38,
-  -1,  98,  53,  -5,  -1, 129,  -1,   8, 128,  -3,  -1,  22,  97,  -1,   6,
-  96, -13,  -9,  -5,  -3,  -1,  83,  68,  37,  -1,  82,   5,  -1,  21,  81,
-  -7,  -3,  -1,  52,  67,  -1,  80,  36,  -3,  -1,  66,  51,  20, -19, -11,
-  -5,  -1,  65,  -1,   4,  64,  -3,  -1,  35,  50,  19,  -3,  -1,  49,   3,
-  -1,  48,  34,  -3,  -1,  18,  33,  -1,   2,  32,  -3,  -1,  17,   1,  16,
-   0
-};
-
-static short tab15[] =
-{
--495,-445,-355,-263,-183,-115, -77, -43, -27, -13,  -7,  -3,  -1, 255, 239,
-  -1, 254, 223,  -1, 238,  -1, 253, 207,  -7,  -3,  -1, 252, 222,  -1, 237,
- 191,  -1, 251,  -1, 206, 236,  -7,  -3,  -1, 221, 175,  -1, 250, 190,  -3,
-  -1, 235, 205,  -1, 220, 159, -15,  -7,  -3,  -1, 249, 234,  -1, 189, 219,
-  -3,  -1, 143, 248,  -1, 204, 158,  -7,  -3,  -1, 233, 127,  -1, 247, 173,
-  -3,  -1, 218, 188,  -1, 111,  -1, 174,  15, -19, -11,  -3,  -1, 203, 246,
-  -3,  -1, 142, 232,  -1,  95, 157,  -3,  -1, 245, 126,  -1, 231, 172,  -9,
-  -3,  -1, 202, 187,  -3,  -1, 217, 141,  79,  -3,  -1, 244,  63,  -1, 243,
- 216, -33, -17,  -9,  -3,  -1, 230,  47,  -1, 242,  -1, 110, 240,  -3,  -1,
-  31, 241,  -1, 156, 201,  -7,  -3,  -1,  94, 171,  -1, 186, 229,  -3,  -1,
- 125, 215,  -1,  78, 228, -15,  -7,  -3,  -1, 140, 200,  -1,  62, 109,  -3,
-  -1, 214, 227,  -1, 155, 185,  -7,  -3,  -1,  46, 170,  -1, 226,  30,  -5,
-  -1, 225,  -1,  14, 224,  -1,  93, 213, -45, -25, -13,  -7,  -3,  -1, 124,
- 199,  -1,  77, 139,  -1, 212,  -1, 184, 154,  -7,  -3,  -1, 169, 108,  -1,
- 198,  61,  -1, 211, 210,  -9,  -5,  -3,  -1,  45,  13,  29,  -1, 123, 183,
-  -5,  -1, 209,  -1,  92, 208,  -1, 197, 138, -17,  -7,  -3,  -1, 168,  76,
-  -1, 196, 107,  -5,  -1, 182,  -1, 153,  12,  -1,  60, 195,  -9,  -3,  -1,
- 122, 167,  -1, 166,  -1, 192,  11,  -1, 194,  -1,  44,  91, -55, -29, -15,
-  -7,  -3,  -1, 181,  28,  -1, 137, 152,  -3,  -1, 193,  75,  -1, 180, 106,
-  -5,  -3,  -1,  59, 121, 179,  -3,  -1, 151, 136,  -1,  43,  90, -11,  -5,
-  -1, 178,  -1, 165,  27,  -1, 177,  -1, 176, 105,  -7,  -3,  -1, 150,  74,
-  -1, 164, 120,  -3,  -1, 135,  58, 163, -17,  -7,  -3,  -1,  89, 149,  -1,
-  42, 162,  -3,  -1,  26, 161,  -3,  -1,  10, 160, 104,  -7,  -3,  -1, 134,
-  73,  -1, 148,  57,  -5,  -1, 147,  -1, 119,   9,  -1,  88, 133, -53, -29,
- -13,  -7,  -3,  -1,  41, 103,  -1, 118, 146,  -1, 145,  -1,  25, 144,  -7,
-  -3,  -1,  72, 132,  -1,  87, 117,  -3,  -1,  56, 131,  -1, 102,  71,  -7,
-  -3,  -1,  40, 130,  -1,  24, 129,  -7,  -3,  -1, 116,   8,  -1, 128,  86,
-  -3,  -1, 101,  55,  -1, 115,  70, -17,  -7,  -3,  -1,  39, 114,  -1, 100,
-  23,  -3,  -1,  85, 113,  -3,  -1,   7, 112,  54,  -7,  -3,  -1,  99,  69,
-  -1,  84,  38,  -3,  -1,  98,  22,  -3,  -1,   6,  96,  53, -33, -19,  -9,
-  -5,  -1,  97,  -1,  83,  68,  -1,  37,  82,  -3,  -1,  21,  81,  -3,  -1,
-   5,  80,  52,  -7,  -3,  -1,  67,  36,  -1,  66,  51,  -1,  65,  -1,  20,
-   4,  -9,  -3,  -1,  35,  50,  -3,  -1,  64,   3,  19,  -3,  -1,  49,  48,
-  34,  -9,  -7,  -3,  -1,  18,  33,  -1,   2,  32,  17,  -3,  -1,   1,  16,
-   0
-};
-
-static short tab16[] =
-{
--509,-503,-461,-323,-103, -37, -27, -15,  -7,  -3,  -1, 239, 254,  -1, 223,
- 253,  -3,  -1, 207, 252,  -1, 191, 251,  -5,  -1, 175,  -1, 250, 159,  -3,
-  -1, 249, 248, 143,  -7,  -3,  -1, 127, 247,  -1, 111, 246, 255,  -9,  -5,
-  -3,  -1,  95, 245,  79,  -1, 244, 243, -53,  -1, 240,  -1,  63, -29, -19,
- -13,  -7,  -5,  -1, 206,  -1, 236, 221, 222,  -1, 233,  -1, 234, 217,  -1,
- 238,  -1, 237, 235,  -3,  -1, 190, 205,  -3,  -1, 220, 219, 174, -11,  -5,
-  -1, 204,  -1, 173, 218,  -3,  -1, 126, 172, 202,  -5,  -3,  -1, 201, 125,
-  94, 189, 242, -93,  -5,  -3,  -1,  47,  15,  31,  -1, 241, -49, -25, -13,
-  -5,  -1, 158,  -1, 188, 203,  -3,  -1, 142, 232,  -1, 157, 231,  -7,  -3,
-  -1, 187, 141,  -1, 216, 110,  -1, 230, 156, -13,  -7,  -3,  -1, 171, 186,
-  -1, 229, 215,  -1,  78,  -1, 228, 140,  -3,  -1, 200,  62,  -1, 109,  -1,
- 214, 155, -19, -11,  -5,  -3,  -1, 185, 170, 225,  -1, 212,  -1, 184, 169,
-  -5,  -1, 123,  -1, 183, 208, 227,  -7,  -3,  -1,  14, 224,  -1,  93, 213,
-  -3,  -1, 124, 199,  -1,  77, 139, -75, -45, -27, -13,  -7,  -3,  -1, 154,
- 108,  -1, 198,  61,  -3,  -1,  92, 197,  13,  -7,  -3,  -1, 138, 168,  -1,
- 153,  76,  -3,  -1, 182, 122,  60, -11,  -5,  -3,  -1,  91, 137,  28,  -1,
- 192,  -1, 152, 121,  -1, 226,  -1,  46,  30, -15,  -7,  -3,  -1, 211,  45,
-  -1, 210, 209,  -5,  -1,  59,  -1, 151, 136,  29,  -7,  -3,  -1, 196, 107,
-  -1, 195, 167,  -1,  44,  -1, 194, 181, -23, -13,  -7,  -3,  -1, 193,  12,
-  -1,  75, 180,  -3,  -1, 106, 166, 179,  -5,  -3,  -1,  90, 165,  43,  -1,
- 178,  27, -13,  -5,  -1, 177,  -1,  11, 176,  -3,  -1, 105, 150,  -1,  74,
- 164,  -5,  -3,  -1, 120, 135, 163,  -3,  -1,  58,  89,  42, -97, -57, -33,
- -19, -11,  -5,  -3,  -1, 149, 104, 161,  -3,  -1, 134, 119, 148,  -5,  -3,
-  -1,  73,  87, 103, 162,  -5,  -1,  26,  -1,  10, 160,  -3,  -1,  57, 147,
-  -1,  88, 133,  -9,  -3,  -1,  41, 146,  -3,  -1, 118,   9,  25,  -5,  -1,
- 145,  -1, 144,  72,  -3,  -1, 132, 117,  -1,  56, 131, -21, -11,  -5,  -3,
-  -1, 102,  40, 130,  -3,  -1,  71, 116,  24,  -3,  -1, 129, 128,  -3,  -1,
-   8,  86,  55,  -9,  -5,  -1, 115,  -1, 101,  70,  -1,  39, 114,  -5,  -3,
-  -1, 100,  85,   7,  23, -23, -13,  -5,  -1, 113,  -1, 112,  54,  -3,  -1,
-  99,  69,  -1,  84,  38,  -3,  -1,  98,  22,  -1,  97,  -1,   6,  96,  -9,
-  -5,  -1,  83,  -1,  53,  68,  -1,  37,  82,  -1,  81,  -1,  21,   5, -33,
- -23, -13,  -7,  -3,  -1,  52,  67,  -1,  80,  36,  -3,  -1,  66,  51,  20,
-  -5,  -1,  65,  -1,   4,  64,  -1,  35,  50,  -3,  -1,  19,  49,  -3,  -1,
-   3,  48,  34,  -3,  -1,  18,  33,  -1,   2,  32,  -3,  -1,  17,   1,  16,
-   0
-};
-
-static short tab24[] =
-{
--451,-117, -43, -25, -15,  -7,  -3,  -1, 239, 254,  -1, 223, 253,  -3,  -1,
- 207, 252,  -1, 191, 251,  -5,  -1, 250,  -1, 175, 159,  -1, 249, 248,  -9,
-  -5,  -3,  -1, 143, 127, 247,  -1, 111, 246,  -3,  -1,  95, 245,  -1,  79,
- 244, -71,  -7,  -3,  -1,  63, 243,  -1,  47, 242,  -5,  -1, 241,  -1,  31,
- 240, -25,  -9,  -1,  15,  -3,  -1, 238, 222,  -1, 237, 206,  -7,  -3,  -1,
- 236, 221,  -1, 190, 235,  -3,  -1, 205, 220,  -1, 174, 234, -15,  -7,  -3,
-  -1, 189, 219,  -1, 204, 158,  -3,  -1, 233, 173,  -1, 218, 188,  -7,  -3,
-  -1, 203, 142,  -1, 232, 157,  -3,  -1, 217, 126,  -1, 231, 172, 255,-235,
--143, -77, -45, -25, -15,  -7,  -3,  -1, 202, 187,  -1, 141, 216,  -5,  -3,
-  -1,  14, 224,  13, 230,  -5,  -3,  -1, 110, 156, 201,  -1,  94, 186,  -9,
-  -5,  -1, 229,  -1, 171, 125,  -1, 215, 228,  -3,  -1, 140, 200,  -3,  -1,
-  78,  46,  62, -15,  -7,  -3,  -1, 109, 214,  -1, 227, 155,  -3,  -1, 185,
- 170,  -1, 226,  30,  -7,  -3,  -1, 225,  93,  -1, 213, 124,  -3,  -1, 199,
-  77,  -1, 139, 184, -31, -15,  -7,  -3,  -1, 212, 154,  -1, 169, 108,  -3,
-  -1, 198,  61,  -1, 211,  45,  -7,  -3,  -1, 210,  29,  -1, 123, 183,  -3,
-  -1, 209,  92,  -1, 197, 138, -17,  -7,  -3,  -1, 168, 153,  -1,  76, 196,
-  -3,  -1, 107, 182,  -3,  -1, 208,  12,  60,  -7,  -3,  -1, 195, 122,  -1,
- 167,  44,  -3,  -1, 194,  91,  -1, 181,  28, -57, -35, -19,  -7,  -3,  -1,
- 137, 152,  -1, 193,  75,  -5,  -3,  -1, 192,  11,  59,  -3,  -1, 176,  10,
-  26,  -5,  -1, 180,  -1, 106, 166,  -3,  -1, 121, 151,  -3,  -1, 160,   9,
- 144,  -9,  -3,  -1, 179, 136,  -3,  -1,  43,  90, 178,  -7,  -3,  -1, 165,
-  27,  -1, 177, 105,  -1, 150, 164, -17,  -9,  -5,  -3,  -1,  74, 120, 135,
-  -1,  58, 163,  -3,  -1,  89, 149,  -1,  42, 162,  -7,  -3,  -1, 161, 104,
-  -1, 134, 119,  -3,  -1,  73, 148,  -1,  57, 147, -63, -31, -15,  -7,  -3,
-  -1,  88, 133,  -1,  41, 103,  -3,  -1, 118, 146,  -1,  25, 145,  -7,  -3,
-  -1,  72, 132,  -1,  87, 117,  -3,  -1,  56, 131,  -1, 102,  40, -17,  -7,
-  -3,  -1, 130,  24,  -1,  71, 116,  -5,  -1, 129,  -1,   8, 128,  -1,  86,
- 101,  -7,  -5,  -1,  23,  -1,   7, 112, 115,  -3,  -1,  55,  39, 114, -15,
-  -7,  -3,  -1,  70, 100,  -1,  85, 113,  -3,  -1,  54,  99,  -1,  69,  84,
-  -7,  -3,  -1,  38,  98,  -1,  22,  97,  -5,  -3,  -1,   6,  96,  53,  -1,
-  83,  68, -51, -37, -23, -15,  -9,  -3,  -1,  37,  82,  -1,  21,  -1,   5,
-  80,  -1,  81,  -1,  52,  67,  -3,  -1,  36,  66,  -1,  51,  20,  -9,  -5,
-  -1,  65,  -1,   4,  64,  -1,  35,  50,  -1,  19,  49,  -7,  -5,  -3,  -1,
-   3,  48,  34,  18,  -1,  33,  -1,   2,  32,  -3,  -1,  17,   1,  -1,  16,
-   0
-};
-
-static short tab_c0[] =
-{
- -29, -21, -13,  -7,  -3,  -1,  11,  15,  -1,  13,  14,  -3,  -1,   7,   5,
-   9,  -3,  -1,   6,   3,  -1,  10,  12,  -3,  -1,   2,   1,  -1,   4,   8,
-   0
-};
-
-static short tab_c1[] =
-{
- -15,  -7,  -3,  -1,  15,  14,  -1,  13,  12,  -3,  -1,  11,  10,  -1,   9,
-   8,  -7,  -3,  -1,   7,   6,  -1,   5,   4,  -3,  -1,   3,   2,  -1,   1,
-   0
-};
-
-
-
-static struct newhuff ht[] = 
-{
- { /* 0 */ 0 , tab0  } ,
- { /* 2 */ 0 , tab1  } ,
- { /* 3 */ 0 , tab2  } ,
- { /* 3 */ 0 , tab3  } ,
- { /* 0 */ 0 , tab0  } ,
- { /* 4 */ 0 , tab5  } ,
- { /* 4 */ 0 , tab6  } ,
- { /* 6 */ 0 , tab7  } ,
- { /* 6 */ 0 , tab8  } ,
- { /* 6 */ 0 , tab9  } ,
- { /* 8 */ 0 , tab10 } ,
- { /* 8 */ 0 , tab11 } ,
- { /* 8 */ 0 , tab12 } ,
- { /* 16 */ 0 , tab13 } ,
- { /* 0  */ 0 , tab0  } ,
- { /* 16 */ 0 , tab15 } ,
-
- { /* 16 */ 1 , tab16 } ,
- { /* 16 */ 2 , tab16 } ,
- { /* 16 */ 3 , tab16 } ,
- { /* 16 */ 4 , tab16 } ,
- { /* 16 */ 6 , tab16 } ,
- { /* 16 */ 8 , tab16 } ,
- { /* 16 */ 10, tab16 } ,
- { /* 16 */ 13, tab16 } ,
- { /* 16 */ 4 , tab24 } ,
- { /* 16 */ 5 , tab24 } ,
- { /* 16 */ 6 , tab24 } ,
- { /* 16 */ 7 , tab24 } ,
- { /* 16 */ 8 , tab24 } ,
- { /* 16 */ 9 , tab24 } ,
- { /* 16 */ 11, tab24 } ,
- { /* 16 */ 13, tab24 }
-};
-
-static struct newhuff htc[] = 
-{
- { /* 1 , 1 , */ 0 , tab_c0 } ,
- { /* 1 , 1 , */ 0 , tab_c1 }
+struct newhuff {
+	unsigned int linbits;
+	short *table;
+};
+
+static short tab0[] = {
+	0
+};
+
+static short tab1[] = {
+	-5, -3, -1, 17, 1, 16, 0
+};
+
+static short tab2[] = {
+	-15, -11, -9, -5, -3, -1, 34, 2, 18, -1, 33, 32, 17, -1, 1,
+	16, 0
+};
+
+static short tab3[] = {
+	-13, -11, -9, -5, -3, -1, 34, 2, 18, -1, 33, 32, 16, 17, -1,
+	1, 0
+};
+
+static short tab5[] = {
+	-29, -25, -23, -15, -7, -5, -3, -1, 51, 35, 50, 49, -3, -1, 19,
+	3, -1, 48, 34, -3, -1, 18, 33, -1, 2, 32, 17, -1, 1, 16,
+	0
+};
+
+static short tab6[] = {
+	-25, -19, -13, -9, -5, -3, -1, 51, 3, 35, -1, 50, 48, -1, 19,
+	49, -3, -1, 34, 2, 18, -3, -1, 33, 32, 1, -1, 17, -1, 16,
+	0
+};
+
+static short tab7[] = {
+	-69, -65, -57, -39, -29, -17, -11, -7, -3, -1, 85, 69, -1, 84, 83,
+	-1, 53, 68, -3, -1, 37, 82, 21, -5, -1, 81, -1, 5, 52, -1,
+	80, -1, 67, 51, -5, -3, -1, 36, 66, 20, -1, 65, 64, -11, -7,
+	-3, -1, 4, 35, -1, 50, 3, -1, 19, 49, -3, -1, 48, 34, 18,
+	-5, -1, 33, -1, 2, 32, 17, -1, 1, 16, 0
+};
+
+static short tab8[] = {
+	-65, -63, -59, -45, -31, -19, -13, -7, -5, -3, -1, 85, 84, 69, 83,
+	-3, -1, 53, 68, 37, -3, -1, 82, 5, 21, -5, -1, 81, -1, 52,
+	67, -3, -1, 80, 51, 36, -5, -3, -1, 66, 20, 65, -3, -1, 4,
+	64, -1, 35, 50, -9, -7, -3, -1, 19, 49, -1, 3, 48, 34, -1,
+	2, 32, -1, 18, 33, 17, -3, -1, 1, 16, 0
+};
+
+static short tab9[] = {
+	-63, -53, -41, -29, -19, -11, -5, -3, -1, 85, 69, 53, -1, 83, -1,
+	84, 5, -3, -1, 68, 37, -1, 82, 21, -3, -1, 81, 52, -1, 67,
+	-1, 80, 4, -7, -3, -1, 36, 66, -1, 51, 64, -1, 20, 65, -5,
+	-3, -1, 35, 50, 19, -1, 49, -1, 3, 48, -5, -3, -1, 34, 2,
+	18, -1, 33, 32, -3, -1, 17, 1, -1, 16, 0
+};
+
+static short tab10[] = {
+	-125, -121, -111, -83, -55, -35, -21, -13, -7, -3, -1, 119, 103, -1, 118,
+	87, -3, -1, 117, 102, 71, -3, -1, 116, 86, -1, 101, 55, -9, -3,
+	-1, 115, 70, -3, -1, 85, 84, 99, -1, 39, 114, -11, -5, -3, -1,
+	100, 7, 112, -1, 98, -1, 69, 53, -5, -1, 6, -1, 83, 68, 23,
+	-17, -5, -1, 113, -1, 54, 38, -5, -3, -1, 37, 82, 21, -1, 81,
+	-1, 52, 67, -3, -1, 22, 97, -1, 96, -1, 5, 80, -19, -11, -7,
+	-3, -1, 36, 66, -1, 51, 4, -1, 20, 65, -3, -1, 64, 35, -1,
+	50, 3, -3, -1, 19, 49, -1, 48, 34, -7, -3, -1, 18, 33, -1,
+	2, 32, 17, -1, 1, 16, 0
+};
+
+static short tab11[] = {
+	-121, -113, -89, -59, -43, -27, -17, -7, -3, -1, 119, 103, -1, 118, 117,
+	-3, -1, 102, 71, -1, 116, -1, 87, 85, -5, -3, -1, 86, 101, 55,
+	-1, 115, 70, -9, -7, -3, -1, 69, 84, -1, 53, 83, 39, -1, 114,
+	-1, 100, 7, -5, -1, 113, -1, 23, 112, -3, -1, 54, 99, -1, 96,
+	-1, 68, 37, -13, -7, -5, -3, -1, 82, 5, 21, 98, -3, -1, 38,
+	6, 22, -5, -1, 97, -1, 81, 52, -5, -1, 80, -1, 67, 51, -1,
+	36, 66, -15, -11, -7, -3, -1, 20, 65, -1, 4, 64, -1, 35, 50,
+	-1, 19, 49, -5, -3, -1, 3, 48, 34, 33, -5, -1, 18, -1, 2,
+	32, 17, -3, -1, 1, 16, 0
+};
+
+static short tab12[] = {
+	-115, -99, -73, -45, -27, -17, -9, -5, -3, -1, 119, 103, 118, -1, 87,
+	117, -3, -1, 102, 71, -1, 116, 101, -3, -1, 86, 55, -3, -1, 115,
+	85, 39, -7, -3, -1, 114, 70, -1, 100, 23, -5, -1, 113, -1, 7,
+	112, -1, 54, 99, -13, -9, -3, -1, 69, 84, -1, 68, -1, 6, 5,
+	-1, 38, 98, -5, -1, 97, -1, 22, 96, -3, -1, 53, 83, -1, 37,
+	82, -17, -7, -3, -1, 21, 81, -1, 52, 67, -5, -3, -1, 80, 4,
+	36, -1, 66, 20, -3, -1, 51, 65, -1, 35, 50, -11, -7, -5, -3,
+	-1, 64, 3, 48, 19, -1, 49, 34, -1, 18, 33, -7, -5, -3, -1,
+	2, 32, 0, 17, -1, 1, 16
+};
+
+static short tab13[] = {
+	-509, -503, -475, -405, -333, -265, -205, -153, -115, -83, -53, -35, -21, -13, -9,
+	-7, -5, -3, -1, 254, 252, 253, 237, 255, -1, 239, 223, -3, -1, 238,
+	207, -1, 222, 191, -9, -3, -1, 251, 206, -1, 220, -1, 175, 233, -1,
+	236, 221, -9, -5, -3, -1, 250, 205, 190, -1, 235, 159, -3, -1, 249,
+	234, -1, 189, 219, -17, -9, -3, -1, 143, 248, -1, 204, -1, 174, 158,
+	-5, -1, 142, -1, 127, 126, 247, -5, -1, 218, -1, 173, 188, -3, -1,
+	203, 246, 111, -15, -7, -3, -1, 232, 95, -1, 157, 217, -3, -1, 245,
+	231, -1, 172, 187, -9, -3, -1, 79, 244, -3, -1, 202, 230, 243, -1,
+	63, -1, 141, 216, -21, -9, -3, -1, 47, 242, -3, -1, 110, 156, 15,
+	-5, -3, -1, 201, 94, 171, -3, -1, 125, 215, 78, -11, -5, -3, -1,
+	200, 214, 62, -1, 185, -1, 155, 170, -1, 31, 241, -23, -13, -5, -1,
+	240, -1, 186, 229, -3, -1, 228, 140, -1, 109, 227, -5, -1, 226, -1,
+	46, 14, -1, 30, 225, -15, -7, -3, -1, 224, 93, -1, 213, 124, -3,
+	-1, 199, 77, -1, 139, 184, -7, -3, -1, 212, 154, -1, 169, 108, -1,
+	198, 61, -37, -21, -9, -5, -3, -1, 211, 123, 45, -1, 210, 29, -5,
+	-1, 183, -1, 92, 197, -3, -1, 153, 122, 195, -7, -5, -3, -1, 167,
+	151, 75, 209, -3, -1, 13, 208, -1, 138, 168, -11, -7, -3, -1, 76,
+	196, -1, 107, 182, -1, 60, 44, -3, -1, 194, 91, -3, -1, 181, 137,
+	28, -43, -23, -11, -5, -1, 193, -1, 152, 12, -1, 192, -1, 180, 106,
+	-5, -3, -1, 166, 121, 59, -1, 179, -1, 136, 90, -11, -5, -1, 43,
+	-1, 165, 105, -1, 164, -1, 120, 135, -5, -1, 148, -1, 119, 118, 178,
+	-11, -3, -1, 27, 177, -3, -1, 11, 176, -1, 150, 74, -7, -3, -1,
+	58, 163, -1, 89, 149, -1, 42, 162, -47, -23, -9, -3, -1, 26, 161,
+	-3, -1, 10, 104, 160, -5, -3, -1, 134, 73, 147, -3, -1, 57, 88,
+	-1, 133, 103, -9, -3, -1, 41, 146, -3, -1, 87, 117, 56, -5, -1,
+	131, -1, 102, 71, -3, -1, 116, 86, -1, 101, 115, -11, -3, -1, 25,
+	145, -3, -1, 9, 144, -1, 72, 132, -7, -5, -1, 114, -1, 70, 100,
+	40, -1, 130, 24, -41, -27, -11, -5, -3, -1, 55, 39, 23, -1, 113,
+	-1, 85, 7, -7, -3, -1, 112, 54, -1, 99, 69, -3, -1, 84, 38,
+	-1, 98, 53, -5, -1, 129, -1, 8, 128, -3, -1, 22, 97, -1, 6,
+	96, -13, -9, -5, -3, -1, 83, 68, 37, -1, 82, 5, -1, 21, 81,
+	-7, -3, -1, 52, 67, -1, 80, 36, -3, -1, 66, 51, 20, -19, -11,
+	-5, -1, 65, -1, 4, 64, -3, -1, 35, 50, 19, -3, -1, 49, 3,
+	-1, 48, 34, -3, -1, 18, 33, -1, 2, 32, -3, -1, 17, 1, 16,
+	0
+};
+
+static short tab15[] = {
+	-495, -445, -355, -263, -183, -115, -77, -43, -27, -13, -7, -3, -1, 255, 239,
+	-1, 254, 223, -1, 238, -1, 253, 207, -7, -3, -1, 252, 222, -1, 237,
+	191, -1, 251, -1, 206, 236, -7, -3, -1, 221, 175, -1, 250, 190, -3,
+	-1, 235, 205, -1, 220, 159, -15, -7, -3, -1, 249, 234, -1, 189, 219,
+	-3, -1, 143, 248, -1, 204, 158, -7, -3, -1, 233, 127, -1, 247, 173,
+	-3, -1, 218, 188, -1, 111, -1, 174, 15, -19, -11, -3, -1, 203, 246,
+	-3, -1, 142, 232, -1, 95, 157, -3, -1, 245, 126, -1, 231, 172, -9,
+	-3, -1, 202, 187, -3, -1, 217, 141, 79, -3, -1, 244, 63, -1, 243,
+	216, -33, -17, -9, -3, -1, 230, 47, -1, 242, -1, 110, 240, -3, -1,
+	31, 241, -1, 156, 201, -7, -3, -1, 94, 171, -1, 186, 229, -3, -1,
+	125, 215, -1, 78, 228, -15, -7, -3, -1, 140, 200, -1, 62, 109, -3,
+	-1, 214, 227, -1, 155, 185, -7, -3, -1, 46, 170, -1, 226, 30, -5,
+	-1, 225, -1, 14, 224, -1, 93, 213, -45, -25, -13, -7, -3, -1, 124,
+	199, -1, 77, 139, -1, 212, -1, 184, 154, -7, -3, -1, 169, 108, -1,
+	198, 61, -1, 211, 210, -9, -5, -3, -1, 45, 13, 29, -1, 123, 183,
+	-5, -1, 209, -1, 92, 208, -1, 197, 138, -17, -7, -3, -1, 168, 76,
+	-1, 196, 107, -5, -1, 182, -1, 153, 12, -1, 60, 195, -9, -3, -1,
+	122, 167, -1, 166, -1, 192, 11, -1, 194, -1, 44, 91, -55, -29, -15,
+	-7, -3, -1, 181, 28, -1, 137, 152, -3, -1, 193, 75, -1, 180, 106,
+	-5, -3, -1, 59, 121, 179, -3, -1, 151, 136, -1, 43, 90, -11, -5,
+	-1, 178, -1, 165, 27, -1, 177, -1, 176, 105, -7, -3, -1, 150, 74,
+	-1, 164, 120, -3, -1, 135, 58, 163, -17, -7, -3, -1, 89, 149, -1,
+	42, 162, -3, -1, 26, 161, -3, -1, 10, 160, 104, -7, -3, -1, 134,
+	73, -1, 148, 57, -5, -1, 147, -1, 119, 9, -1, 88, 133, -53, -29,
+	-13, -7, -3, -1, 41, 103, -1, 118, 146, -1, 145, -1, 25, 144, -7,
+	-3, -1, 72, 132, -1, 87, 117, -3, -1, 56, 131, -1, 102, 71, -7,
+	-3, -1, 40, 130, -1, 24, 129, -7, -3, -1, 116, 8, -1, 128, 86,
+	-3, -1, 101, 55, -1, 115, 70, -17, -7, -3, -1, 39, 114, -1, 100,
+	23, -3, -1, 85, 113, -3, -1, 7, 112, 54, -7, -3, -1, 99, 69,
+	-1, 84, 38, -3, -1, 98, 22, -3, -1, 6, 96, 53, -33, -19, -9,
+	-5, -1, 97, -1, 83, 68, -1, 37, 82, -3, -1, 21, 81, -3, -1,
+	5, 80, 52, -7, -3, -1, 67, 36, -1, 66, 51, -1, 65, -1, 20,
+	4, -9, -3, -1, 35, 50, -3, -1, 64, 3, 19, -3, -1, 49, 48,
+	34, -9, -7, -3, -1, 18, 33, -1, 2, 32, 17, -3, -1, 1, 16,
+	0
+};
+
+static short tab16[] = {
+	-509, -503, -461, -323, -103, -37, -27, -15, -7, -3, -1, 239, 254, -1, 223,
+	253, -3, -1, 207, 252, -1, 191, 251, -5, -1, 175, -1, 250, 159, -3,
+	-1, 249, 248, 143, -7, -3, -1, 127, 247, -1, 111, 246, 255, -9, -5,
+	-3, -1, 95, 245, 79, -1, 244, 243, -53, -1, 240, -1, 63, -29, -19,
+	-13, -7, -5, -1, 206, -1, 236, 221, 222, -1, 233, -1, 234, 217, -1,
+	238, -1, 237, 235, -3, -1, 190, 205, -3, -1, 220, 219, 174, -11, -5,
+	-1, 204, -1, 173, 218, -3, -1, 126, 172, 202, -5, -3, -1, 201, 125,
+	94, 189, 242, -93, -5, -3, -1, 47, 15, 31, -1, 241, -49, -25, -13,
+	-5, -1, 158, -1, 188, 203, -3, -1, 142, 232, -1, 157, 231, -7, -3,
+	-1, 187, 141, -1, 216, 110, -1, 230, 156, -13, -7, -3, -1, 171, 186,
+	-1, 229, 215, -1, 78, -1, 228, 140, -3, -1, 200, 62, -1, 109, -1,
+	214, 155, -19, -11, -5, -3, -1, 185, 170, 225, -1, 212, -1, 184, 169,
+	-5, -1, 123, -1, 183, 208, 227, -7, -3, -1, 14, 224, -1, 93, 213,
+	-3, -1, 124, 199, -1, 77, 139, -75, -45, -27, -13, -7, -3, -1, 154,
+	108, -1, 198, 61, -3, -1, 92, 197, 13, -7, -3, -1, 138, 168, -1,
+	153, 76, -3, -1, 182, 122, 60, -11, -5, -3, -1, 91, 137, 28, -1,
+	192, -1, 152, 121, -1, 226, -1, 46, 30, -15, -7, -3, -1, 211, 45,
+	-1, 210, 209, -5, -1, 59, -1, 151, 136, 29, -7, -3, -1, 196, 107,
+	-1, 195, 167, -1, 44, -1, 194, 181, -23, -13, -7, -3, -1, 193, 12,
+	-1, 75, 180, -3, -1, 106, 166, 179, -5, -3, -1, 90, 165, 43, -1,
+	178, 27, -13, -5, -1, 177, -1, 11, 176, -3, -1, 105, 150, -1, 74,
+	164, -5, -3, -1, 120, 135, 163, -3, -1, 58, 89, 42, -97, -57, -33,
+	-19, -11, -5, -3, -1, 149, 104, 161, -3, -1, 134, 119, 148, -5, -3,
+	-1, 73, 87, 103, 162, -5, -1, 26, -1, 10, 160, -3, -1, 57, 147,
+	-1, 88, 133, -9, -3, -1, 41, 146, -3, -1, 118, 9, 25, -5, -1,
+	145, -1, 144, 72, -3, -1, 132, 117, -1, 56, 131, -21, -11, -5, -3,
+	-1, 102, 40, 130, -3, -1, 71, 116, 24, -3, -1, 129, 128, -3, -1,
+	8, 86, 55, -9, -5, -1, 115, -1, 101, 70, -1, 39, 114, -5, -3,
+	-1, 100, 85, 7, 23, -23, -13, -5, -1, 113, -1, 112, 54, -3, -1,
+	99, 69, -1, 84, 38, -3, -1, 98, 22, -1, 97, -1, 6, 96, -9,
+	-5, -1, 83, -1, 53, 68, -1, 37, 82, -1, 81, -1, 21, 5, -33,
+	-23, -13, -7, -3, -1, 52, 67, -1, 80, 36, -3, -1, 66, 51, 20,
+	-5, -1, 65, -1, 4, 64, -1, 35, 50, -3, -1, 19, 49, -3, -1,
+	3, 48, 34, -3, -1, 18, 33, -1, 2, 32, -3, -1, 17, 1, 16,
+	0
+};
+
+static short tab24[] = {
+	-451, -117, -43, -25, -15, -7, -3, -1, 239, 254, -1, 223, 253, -3, -1,
+	207, 252, -1, 191, 251, -5, -1, 250, -1, 175, 159, -1, 249, 248, -9,
+	-5, -3, -1, 143, 127, 247, -1, 111, 246, -3, -1, 95, 245, -1, 79,
+	244, -71, -7, -3, -1, 63, 243, -1, 47, 242, -5, -1, 241, -1, 31,
+	240, -25, -9, -1, 15, -3, -1, 238, 222, -1, 237, 206, -7, -3, -1,
+	236, 221, -1, 190, 235, -3, -1, 205, 220, -1, 174, 234, -15, -7, -3,
+	-1, 189, 219, -1, 204, 158, -3, -1, 233, 173, -1, 218, 188, -7, -3,
+	-1, 203, 142, -1, 232, 157, -3, -1, 217, 126, -1, 231, 172, 255, -235,
+	-143, -77, -45, -25, -15, -7, -3, -1, 202, 187, -1, 141, 216, -5, -3,
+	-1, 14, 224, 13, 230, -5, -3, -1, 110, 156, 201, -1, 94, 186, -9,
+	-5, -1, 229, -1, 171, 125, -1, 215, 228, -3, -1, 140, 200, -3, -1,
+	78, 46, 62, -15, -7, -3, -1, 109, 214, -1, 227, 155, -3, -1, 185,
+	170, -1, 226, 30, -7, -3, -1, 225, 93, -1, 213, 124, -3, -1, 199,
+	77, -1, 139, 184, -31, -15, -7, -3, -1, 212, 154, -1, 169, 108, -3,
+	-1, 198, 61, -1, 211, 45, -7, -3, -1, 210, 29, -1, 123, 183, -3,
+	-1, 209, 92, -1, 197, 138, -17, -7, -3, -1, 168, 153, -1, 76, 196,
+	-3, -1, 107, 182, -3, -1, 208, 12, 60, -7, -3, -1, 195, 122, -1,
+	167, 44, -3, -1, 194, 91, -1, 181, 28, -57, -35, -19, -7, -3, -1,
+	137, 152, -1, 193, 75, -5, -3, -1, 192, 11, 59, -3, -1, 176, 10,
+	26, -5, -1, 180, -1, 106, 166, -3, -1, 121, 151, -3, -1, 160, 9,
+	144, -9, -3, -1, 179, 136, -3, -1, 43, 90, 178, -7, -3, -1, 165,
+	27, -1, 177, 105, -1, 150, 164, -17, -9, -5, -3, -1, 74, 120, 135,
+	-1, 58, 163, -3, -1, 89, 149, -1, 42, 162, -7, -3, -1, 161, 104,
+	-1, 134, 119, -3, -1, 73, 148, -1, 57, 147, -63, -31, -15, -7, -3,
+	-1, 88, 133, -1, 41, 103, -3, -1, 118, 146, -1, 25, 145, -7, -3,
+	-1, 72, 132, -1, 87, 117, -3, -1, 56, 131, -1, 102, 40, -17, -7,
+	-3, -1, 130, 24, -1, 71, 116, -5, -1, 129, -1, 8, 128, -1, 86,
+	101, -7, -5, -1, 23, -1, 7, 112, 115, -3, -1, 55, 39, 114, -15,
+	-7, -3, -1, 70, 100, -1, 85, 113, -3, -1, 54, 99, -1, 69, 84,
+	-7, -3, -1, 38, 98, -1, 22, 97, -5, -3, -1, 6, 96, 53, -1,
+	83, 68, -51, -37, -23, -15, -9, -3, -1, 37, 82, -1, 21, -1, 5,
+	80, -1, 81, -1, 52, 67, -3, -1, 36, 66, -1, 51, 20, -9, -5,
+	-1, 65, -1, 4, 64, -1, 35, 50, -1, 19, 49, -7, -5, -3, -1,
+	3, 48, 34, 18, -1, 33, -1, 2, 32, -3, -1, 17, 1, -1, 16,
+	0
+};
+
+static short tab_c0[] = {
+	-29, -21, -13, -7, -3, -1, 11, 15, -1, 13, 14, -3, -1, 7, 5,
+	9, -3, -1, 6, 3, -1, 10, 12, -3, -1, 2, 1, -1, 4, 8,
+	0
+};
+
+static short tab_c1[] = {
+	-15, -7, -3, -1, 15, 14, -1, 13, 12, -3, -1, 11, 10, -1, 9,
+	8, -7, -3, -1, 7, 6, -1, 5, 4, -3, -1, 3, 2, -1, 1,
+	0
+};
+
+
+
+static struct newhuff ht[] = {
+	{ /* 0 */ 0, tab0},
+	{ /* 2 */ 0, tab1},
+	{ /* 3 */ 0, tab2},
+	{ /* 3 */ 0, tab3},
+	{ /* 0 */ 0, tab0},
+	{ /* 4 */ 0, tab5},
+	{ /* 4 */ 0, tab6},
+	{ /* 6 */ 0, tab7},
+	{ /* 6 */ 0, tab8},
+	{ /* 6 */ 0, tab9},
+	{ /* 8 */ 0, tab10},
+	{ /* 8 */ 0, tab11},
+	{ /* 8 */ 0, tab12},
+	{ /* 16 */ 0, tab13},
+	{ /* 0  */ 0, tab0},
+	{ /* 16 */ 0, tab15},
+
+	{ /* 16 */ 1, tab16},
+	{ /* 16 */ 2, tab16},
+	{ /* 16 */ 3, tab16},
+	{ /* 16 */ 4, tab16},
+	{ /* 16 */ 6, tab16},
+	{ /* 16 */ 8, tab16},
+	{ /* 16 */ 10, tab16},
+	{ /* 16 */ 13, tab16},
+	{ /* 16 */ 4, tab24},
+	{ /* 16 */ 5, tab24},
+	{ /* 16 */ 6, tab24},
+	{ /* 16 */ 7, tab24},
+	{ /* 16 */ 8, tab24},
+	{ /* 16 */ 9, tab24},
+	{ /* 16 */ 11, tab24},
+	{ /* 16 */ 13, tab24}
+};
+
+static struct newhuff htc[] = {
+	{ /* 1 , 1 , */ 0, tab_c0},
+	{ /* 1 , 1 , */ 0, tab_c1}
 };
-
-

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/interface.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/interface.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/interface.c	Fri Mar 30 12:19:18 2007
@@ -9,21 +9,21 @@
 {
 	init_layer3_const();
 	make_decode_tables_const();
-	
+
 }
 
 
-BOOL InitMP3(struct mpstr *mp, long outscale, int samplerate) 
+BOOL InitMP3(struct mpstr *mp, long outscale, int samplerate)
 {
 	/* quiet 4096 med 8192 */
 
-	memset(mp,0,sizeof(struct mpstr));
+	memset(mp, 0, sizeof(struct mpstr));
 
 	mp->framesize = 0;
 	mp->fsizeold = -1;
 	mp->bsize = 0;
 	mp->head = mp->tail = NULL;
-	mp->fr.single = 3; /* force mono */
+	mp->fr.single = 3;			/* force mono */
 	mp->bsnum = 0;
 	mp->synth_bo = 1;
 	mp->outsamplerate = samplerate;
@@ -37,10 +37,10 @@
 
 void ExitMP3(struct mpstr *mp)
 {
-	struct buf *b,*bn;
-	
+	struct buf *b, *bn;
+
 	b = mp->tail;
-	while(b) {
+	while (b) {
 		free(b->pnt);
 		bn = b->next;
 		free(b);
@@ -48,31 +48,30 @@
 	}
 }
 
-static struct buf *addbuf(struct mpstr *mp,char *buf,int size)
+static struct buf *addbuf(struct mpstr *mp, char *buf, int size)
 {
 	struct buf *nbuf;
 
-	nbuf = malloc( sizeof(struct buf) );
-	if(!nbuf) {
-		debug_printf("%d Out of memory!\n",  __LINE__);
+	nbuf = malloc(sizeof(struct buf));
+	if (!nbuf) {
+		debug_printf("%d Out of memory!\n", __LINE__);
 		return NULL;
 	}
 	nbuf->pnt = malloc(size);
-	if(!nbuf->pnt) {
+	if (!nbuf->pnt) {
 		free(nbuf);
 		return NULL;
 	}
 	nbuf->size = size;
-	memcpy(nbuf->pnt,buf,size);
+	memcpy(nbuf->pnt, buf, size);
 	nbuf->next = NULL;
 	nbuf->prev = mp->head;
 	nbuf->pos = 0;
 
-	if(!mp->tail) {
+	if (!mp->tail) {
 		mp->tail = nbuf;
-	}
-	else {
-	  mp->head->next = nbuf;
+	} else {
+		mp->head->next = nbuf;
 	}
 
 	mp->head = nbuf;
@@ -83,50 +82,51 @@
 
 static void remove_buf(struct mpstr *mp)
 {
-  struct buf *buf = mp->tail;
-  
-  mp->tail = buf->next;
-  if(mp->tail)
-    mp->tail->prev = NULL;
-  else {
-    mp->tail = mp->head = NULL;
-  }
-  
-  free(buf->pnt);
-  free(buf);
+	struct buf *buf = mp->tail;
+
+	mp->tail = buf->next;
+	if (mp->tail)
+		mp->tail->prev = NULL;
+	else {
+		mp->tail = mp->head = NULL;
+	}
+
+	free(buf->pnt);
+	free(buf);
 
 }
 
 static int read_buf_byte(int *error, struct mpstr *mp)
 {
-	unsigned int b;int pos;
+	unsigned int b;
+	int pos;
 
 	pos = mp->tail->pos;
-	while(pos >= mp->tail->size) {
+	while (pos >= mp->tail->size) {
 		remove_buf(mp);
 		pos = mp->tail->pos;
-		if(!mp->tail) {
-			/* We may pick up this error a few times*/
+		if (!mp->tail) {
+			/* We may pick up this error a few times */
 			/* But things have gone pear shaped */
-			debug_printf("%d Fatal Buffer error!\n",  __LINE__);
+			debug_printf("%d Fatal Buffer error!\n", __LINE__);
 			*error = 1;
-			return (0);		
+			return (0);
 		}
 	}
 
 	b = mp->tail->pnt[pos];
 	mp->bsize--;
 	mp->tail->pos++;
-	
+
 
 	return b;
 }
 
-static int  read_head(struct mpstr *mp)
+static int read_head(struct mpstr *mp)
 {
 	unsigned long head;
-	int error=0;
-	
+	int error = 0;
+
 
 	head = read_buf_byte(&error, mp);
 	head <<= 8;
@@ -138,130 +138,127 @@
 
 	mp->header = head;
 
-	if(error){
+	if (error) {
 		return (1);
-	}else
+	} else
 		return (0);
-		
+
 }
 
 static int head_check(unsigned long head)
 {
-    if( (head & 0xffe00000) != 0xffe00000)
-	return FALSE;
-    if(!((head>>17)&3))
-	return FALSE;
-    if( ((head>>12)&0xf) == 0xf || ((head>>12)&0xf) == 0)
-	return FALSE;
-    if( ((head>>10)&0x3) == 0x3 )
-	return FALSE;
-    if ((head & 0xffff0000) == 0xfffe0000)
-      return FALSE;
+	if ((head & 0xffe00000) != 0xffe00000)
+		return FALSE;
+	if (!((head >> 17) & 3))
+		return FALSE;
+	if (((head >> 12) & 0xf) == 0xf || ((head >> 12) & 0xf) == 0)
+		return FALSE;
+	if (((head >> 10) & 0x3) == 0x3)
+		return FALSE;
+	if ((head & 0xffff0000) == 0xfffe0000)
+		return FALSE;
 
-    return TRUE;
+	return TRUE;
 }
 
 static int head_shift(struct mpstr *mp)
 {
 	unsigned long head;
 	int error = 0;
-	
+
 	head = mp->header;
-	
+
 	head <<= 8;
 	head |= read_buf_byte(&error, mp);
-	
+
 	mp->header = head;
 
-	if (error){
+	if (error) {
 		return (1);
-	}else
+	} else
 		return (0);
-	
+
 }
 
 
-int decodeMP3(struct mpstr *mp,char *in,int isize,char *out,
-		int osize,int *done)
+int decodeMP3(struct mpstr *mp, char *in, int isize, char *out, int osize, int *done)
 {
 	int len;
-	long n,m;
+	long n, m;
 	int down_sample_sblimit;
 
-	if(osize < 4608) {
-		debug_printf("%d To less out space\n",  __LINE__);
+	if (osize < 4608) {
+		debug_printf("%d To less out space\n", __LINE__);
 		return MP3_TOOSMALL;
 	}
 
-	if(in) {
-		if(addbuf(mp,in,isize) == NULL) {
+	if (in) {
+		if (addbuf(mp, in, isize) == NULL) {
 			return MP3_ERR;
 		}
 	}
 
 	/* First decode header */
-	if(mp->framesize == 0) {
-		if(mp->bsize < 4) {
+	if (mp->framesize == 0) {
+		if (mp->bsize < 4) {
 			return MP3_NEED_MORE;
 		}
 		if (read_head(mp))
 			return MP3_ERR;
-		
-		if(!head_check(mp->header) ) {
+
+		if (!head_check(mp->header)) {
 			int i;
 
-			debug_printf("Junk at the beginning of frame %08lx\n",mp->header);
-			
+			debug_printf("Junk at the beginning of frame %08lx\n", mp->header);
+
 			/* step in byte steps through next 64K */
-			for(i=0;i<65536;i++) {
-				if(!mp->bsize)
+			for (i = 0; i < 65536; i++) {
+				if (!mp->bsize)
 					return MP3_NEED_MORE;
-				
-				if(head_shift(mp))
+
+				if (head_shift(mp))
 					return MP3_ERR;
-				
-				if(head_check(mp->header))
+
+				if (head_check(mp->header))
 					break;
 			}
-			if(i == 65536) {
-				debug_printf("%d Giving up searching valid MPEG header\n",  __LINE__);
+			if (i == 65536) {
+				debug_printf("%d Giving up searching valid MPEG header\n", __LINE__);
 				return MP3_ERR;
 			}
 		}
 
-		decode_header(&mp->fr,mp->header);
+		decode_header(&mp->fr, mp->header);
 		mp->framesize = mp->fr.framesize;
 
-		if (!mp->initmp3){
+		if (!mp->initmp3) {
 			mp->initmp3 = 1;
-			
+
 			n = freqs[mp->fr.sampling_frequency];
 			if (mp->outsamplerate) {
 				m = mp->outsamplerate;
+			} else {
+				m = n;
 			}
-			else {
-				m =n;
-			}
-		
-			if (synth_ntom_set_step(n,m))
+
+			if (synth_ntom_set_step(n, m))
 				return MP3_ERR;
-			
-			
-			if(n>m) {
+
+
+			if (n > m) {
 				down_sample_sblimit = SBLIMIT * m;
 				down_sample_sblimit /= n;
-			}
-			else {
+			} else {
 				down_sample_sblimit = SBLIMIT;
 			}
-			
+
 			init_layer3_sample_limits(mp, down_sample_sblimit);
-	
+
 		}
 	}
-	
 
-	if(mp->fr.framesize > mp->bsize)
+
+	if (mp->fr.framesize > mp->bsize)
 		return MP3_NEED_MORE;
 
 	(mp->worksample).wordpointer = mp->bsspace[mp->bsnum] + 512;
@@ -269,29 +266,28 @@
 	(mp->worksample).bitindex = 0;
 
 	len = 0;
-	while(len < mp->framesize) {
+	while (len < mp->framesize) {
 		int nlen;
 		int blen = mp->tail->size - mp->tail->pos;
-		if( (mp->framesize - len) <= blen) {
-                  nlen = mp->framesize-len;
+		if ((mp->framesize - len) <= blen) {
+			nlen = mp->framesize - len;
+		} else {
+			nlen = blen;
 		}
-		else {
-                  nlen = blen;
-                }
-		memcpy((mp->worksample).wordpointer+len,mp->tail->pnt+mp->tail->pos,nlen);
-                len += nlen;
-                mp->tail->pos += nlen;
+		memcpy((mp->worksample).wordpointer + len, mp->tail->pnt + mp->tail->pos, nlen);
+		len += nlen;
+		mp->tail->pos += nlen;
 		mp->bsize -= nlen;
-                if(mp->tail->pos == mp->tail->size) {
-                   remove_buf(mp);
-                }
+		if (mp->tail->pos == mp->tail->size) {
+			remove_buf(mp);
+		}
 	}
 
 	*done = 0;
-	if(mp->fr.error_protection)
-           getbits(mp, 16);
-	
-	if (do_layer3(mp,(unsigned char *) out,done))
+	if (mp->fr.error_protection)
+		getbits(mp, 16);
+
+	if (do_layer3(mp, (unsigned char *) out, done))
 		return MP3_ERR;
 
 	mp->fsizeold = mp->framesize;
@@ -302,19 +298,15 @@
 
 int set_pointer(struct mpstr *mp, long backstep)
 {
-  unsigned char *bsbufold;
-  if(mp->fsizeold < 0 && backstep > 0) {
-    debug_printf("Can't step back %ld!\n",backstep);
-    return MP3_ERR;
-  }
-  bsbufold = mp->bsspace[mp->bsnum] + 512;
-  (mp->worksample).wordpointer -= backstep;
-  if (backstep)
-    memcpy((mp->worksample).wordpointer,bsbufold+mp->fsizeold-backstep,backstep);
-  (mp->worksample).bitindex = 0;
-  return MP3_OK;
+	unsigned char *bsbufold;
+	if (mp->fsizeold < 0 && backstep > 0) {
+		debug_printf("Can't step back %ld!\n", backstep);
+		return MP3_ERR;
+	}
+	bsbufold = mp->bsspace[mp->bsnum] + 512;
+	(mp->worksample).wordpointer -= backstep;
+	if (backstep)
+		memcpy((mp->worksample).wordpointer, bsbufold + mp->fsizeold - backstep, backstep);
+	(mp->worksample).bitindex = 0;
+	return MP3_OK;
 }
-
-
-
-

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/layer3.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/layer3.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/layer3.c	Fri Mar 30 12:19:18 2007
@@ -3,7 +3,7 @@
  * --------------------------
  * copyright (c) 1995,1996,1997 by Michael Hipp.
  * All rights reserved. See also 'README'
- */ 
+ */
 
 
 #include <stdlib.h>
@@ -15,70 +15,70 @@
 
 /* These should all be constants setup once using init_layer3_const */
 static real ispow[8207];
-static real aa_ca[8],aa_cs[8];
+static real aa_ca[8], aa_cs[8];
 static real COS1[12][6];
 static real win[4][36];
 static real win1[4][36];
-static real gainpow2[256+118+4];
+static real gainpow2[256 + 118 + 4];
 static real COS9[9];
-static real COS6_1,COS6_2;
+static real COS6_1, COS6_2;
 static real tfcos36[9];
 static real tfcos12[3];
 
 struct bandInfoStruct {
-  short longIdx[23];
-  short longDiff[22];
-  short shortIdx[14];
-  short shortDiff[13];
+	short longIdx[23];
+	short longDiff[22];
+	short shortIdx[14];
+	short shortDiff[13];
 };
 
 
-struct bandInfoStruct bandInfo[9] = { 
+struct bandInfoStruct bandInfo[9] = {
 
 /* MPEG 1.0 */
- { {0,4,8,12,16,20,24,30,36,44,52,62,74, 90,110,134,162,196,238,288,342,418,576},
-   {4,4,4,4,4,4,6,6,8, 8,10,12,16,20,24,28,34,42,50,54, 76,158},
-   {0,4*3,8*3,12*3,16*3,22*3,30*3,40*3,52*3,66*3, 84*3,106*3,136*3,192*3},
-   {4,4,4,4,6,8,10,12,14,18,22,30,56} } ,
-
- { {0,4,8,12,16,20,24,30,36,42,50,60,72, 88,106,128,156,190,230,276,330,384,576},
-   {4,4,4,4,4,4,6,6,6, 8,10,12,16,18,22,28,34,40,46,54, 54,192},
-   {0,4*3,8*3,12*3,16*3,22*3,28*3,38*3,50*3,64*3, 80*3,100*3,126*3,192*3},
-   {4,4,4,4,6,6,10,12,14,16,20,26,66} } ,
-
- { {0,4,8,12,16,20,24,30,36,44,54,66,82,102,126,156,194,240,296,364,448,550,576} ,
-   {4,4,4,4,4,4,6,6,8,10,12,16,20,24,30,38,46,56,68,84,102, 26} ,
-   {0,4*3,8*3,12*3,16*3,22*3,30*3,42*3,58*3,78*3,104*3,138*3,180*3,192*3} ,
-   {4,4,4,4,6,8,12,16,20,26,34,42,12} }  ,
+	{{0, 4, 8, 12, 16, 20, 24, 30, 36, 44, 52, 62, 74, 90, 110, 134, 162, 196, 238, 288, 342, 418, 576},
+	 {4, 4, 4, 4, 4, 4, 6, 6, 8, 8, 10, 12, 16, 20, 24, 28, 34, 42, 50, 54, 76, 158},
+	 {0, 4 * 3, 8 * 3, 12 * 3, 16 * 3, 22 * 3, 30 * 3, 40 * 3, 52 * 3, 66 * 3, 84 * 3, 106 * 3, 136 * 3, 192 * 3},
+	 {4, 4, 4, 4, 6, 8, 10, 12, 14, 18, 22, 30, 56}},
+
+	{{0, 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 60, 72, 88, 106, 128, 156, 190, 230, 276, 330, 384, 576},
+	 {4, 4, 4, 4, 4, 4, 6, 6, 6, 8, 10, 12, 16, 18, 22, 28, 34, 40, 46, 54, 54, 192},
+	 {0, 4 * 3, 8 * 3, 12 * 3, 16 * 3, 22 * 3, 28 * 3, 38 * 3, 50 * 3, 64 * 3, 80 * 3, 100 * 3, 126 * 3, 192 * 3},
+	 {4, 4, 4, 4, 6, 6, 10, 12, 14, 16, 20, 26, 66}},
+
+	{{0, 4, 8, 12, 16, 20, 24, 30, 36, 44, 54, 66, 82, 102, 126, 156, 194, 240, 296, 364, 448, 550, 576},
+	 {4, 4, 4, 4, 4, 4, 6, 6, 8, 10, 12, 16, 20, 24, 30, 38, 46, 56, 68, 84, 102, 26},
+	 {0, 4 * 3, 8 * 3, 12 * 3, 16 * 3, 22 * 3, 30 * 3, 42 * 3, 58 * 3, 78 * 3, 104 * 3, 138 * 3, 180 * 3, 192 * 3},
+	 {4, 4, 4, 4, 6, 8, 12, 16, 20, 26, 34, 42, 12}},
 
 /* MPEG 2.0 */
- { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576},
-   {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54 } ,
-   {0,4*3,8*3,12*3,18*3,24*3,32*3,42*3,56*3,74*3,100*3,132*3,174*3,192*3} ,
-   {4,4,4,6,6,8,10,14,18,26,32,42,18 } } ,
-
- { {0,6,12,18,24,30,36,44,54,66,80,96,114,136,162,194,232,278,330,394,464,540,576},
-   {6,6,6,6,6,6,8,10,12,14,16,18,22,26,32,38,46,52,64,70,76,36 } ,
-   {0,4*3,8*3,12*3,18*3,26*3,36*3,48*3,62*3,80*3,104*3,136*3,180*3,192*3} ,
-   {4,4,4,6,8,10,12,14,18,24,32,44,12 } } ,
-
- { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576},
-   {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54 },
-   {0,4*3,8*3,12*3,18*3,26*3,36*3,48*3,62*3,80*3,104*3,134*3,174*3,192*3},
-   {4,4,4,6,8,10,12,14,18,24,30,40,18 } } ,
+	{{0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396, 464, 522, 576},
+	 {6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16, 20, 24, 28, 32, 38, 46, 52, 60, 68, 58, 54},
+	 {0, 4 * 3, 8 * 3, 12 * 3, 18 * 3, 24 * 3, 32 * 3, 42 * 3, 56 * 3, 74 * 3, 100 * 3, 132 * 3, 174 * 3, 192 * 3},
+	 {4, 4, 4, 6, 6, 8, 10, 14, 18, 26, 32, 42, 18}},
+
+	{{0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 114, 136, 162, 194, 232, 278, 330, 394, 464, 540, 576},
+	 {6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16, 18, 22, 26, 32, 38, 46, 52, 64, 70, 76, 36},
+	 {0, 4 * 3, 8 * 3, 12 * 3, 18 * 3, 26 * 3, 36 * 3, 48 * 3, 62 * 3, 80 * 3, 104 * 3, 136 * 3, 180 * 3, 192 * 3},
+	 {4, 4, 4, 6, 8, 10, 12, 14, 18, 24, 32, 44, 12}},
+
+	{{0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396, 464, 522, 576},
+	 {6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16, 20, 24, 28, 32, 38, 46, 52, 60, 68, 58, 54},
+	 {0, 4 * 3, 8 * 3, 12 * 3, 18 * 3, 26 * 3, 36 * 3, 48 * 3, 62 * 3, 80 * 3, 104 * 3, 134 * 3, 174 * 3, 192 * 3},
+	 {4, 4, 4, 6, 8, 10, 12, 14, 18, 24, 30, 40, 18}},
 /* MPEG 2.5 */
- { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576} ,
-   {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54},
-   {0,12,24,36,54,78,108,144,186,240,312,402,522,576},
-   {4,4,4,6,8,10,12,14,18,24,30,40,18} },
- { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576} ,
-   {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54},
-   {0,12,24,36,54,78,108,144,186,240,312,402,522,576},
-   {4,4,4,6,8,10,12,14,18,24,30,40,18} },
- { {0,12,24,36,48,60,72,88,108,132,160,192,232,280,336,400,476,566,568,570,572,574,576},
-   {12,12,12,12,12,12,16,20,24,28,32,40,48,56,64,76,90,2,2,2,2,2},
-   {0, 24, 48, 72,108,156,216,288,372,480,486,492,498,576},
-   {8,8,8,12,16,20,24,28,36,2,2,2,26} } ,
+	{{0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396, 464, 522, 576},
+	 {6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16, 20, 24, 28, 32, 38, 46, 52, 60, 68, 58, 54},
+	 {0, 12, 24, 36, 54, 78, 108, 144, 186, 240, 312, 402, 522, 576},
+	 {4, 4, 4, 6, 8, 10, 12, 14, 18, 24, 30, 40, 18}},
+	{{0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396, 464, 522, 576},
+	 {6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16, 20, 24, 28, 32, 38, 46, 52, 60, 68, 58, 54},
+	 {0, 12, 24, 36, 54, 78, 108, 144, 186, 240, 312, 402, 522, 576},
+	 {4, 4, 4, 6, 8, 10, 12, 14, 18, 24, 30, 40, 18}},
+	{{0, 12, 24, 36, 48, 60, 72, 88, 108, 132, 160, 192, 232, 280, 336, 400, 476, 566, 568, 570, 572, 574, 576},
+	 {12, 12, 12, 12, 12, 12, 16, 20, 24, 28, 32, 40, 48, 56, 64, 76, 90, 2, 2, 2, 2, 2},
+	 {0, 24, 48, 72, 108, 156, 216, 288, 372, 480, 486, 492, 498, 576},
+	 {8, 8, 8, 12, 16, 20, 24, 28, 36, 2, 2, 2, 26}},
 };
 
 static int mapbuf0[9][152];
@@ -87,206 +87,200 @@
 static int *map[9][3];
 static int *mapend[9][3];
 
-static unsigned int n_slen2[512]; /* MPEG 2.0 slen for 'normal' mode */
-static unsigned int i_slen2[256]; /* MPEG 2.0 slen for intensity stereo */
+static unsigned int n_slen2[512];	/* MPEG 2.0 slen for 'normal' mode */
+static unsigned int i_slen2[256];	/* MPEG 2.0 slen for intensity stereo */
 
-static real tan1_1[16],tan2_1[16],tan1_2[16],tan2_2[16];
-static real pow1_1[2][16],pow2_1[2][16],pow1_2[2][16],pow2_2[2][16];
+static real tan1_1[16], tan2_1[16], tan1_2[16], tan2_2[16];
+static real pow1_1[2][16], pow2_1[2][16], pow1_2[2][16], pow2_2[2][16];
 
 /* 
  * init constant tables for layer-3 
  */
 void init_layer3_const(void)
 {
-  int i,j,k,l;
+	int i, j, k, l;
+
+	for (i = -256; i < 118 + 4; i++)
+		gainpow2[i + 256] = pow((double) 2.0, -0.25 * (double) (i + 210));
+
+	for (i = 0; i < 8207; i++)
+		ispow[i] = pow((double) i, (double) 4.0 / 3.0);
 
-  for(i=-256;i<118+4;i++)
-    gainpow2[i+256] = pow((double)2.0,-0.25 * (double) (i+210) );
+	for (i = 0; i < 8; i++) {
+		static double Ci[8] = { -0.6, -0.535, -0.33, -0.185, -0.095, -0.041, -0.0142, -0.0037 };
+		double sq = sqrt(1.0 + Ci[i] * Ci[i]);
+		aa_cs[i] = 1.0 / sq;
+		aa_ca[i] = Ci[i] / sq;
+	}
 
-  for(i=0;i<8207;i++)
-    ispow[i] = pow((double)i,(double)4.0/3.0);
+	for (i = 0; i < 18; i++) {
+		win[0][i] = win[1][i] = 0.5 * sin(M_PI / 72.0 * (double) (2 * (i + 0) + 1)) / cos(M_PI * (double) (2 * (i + 0) + 19) / 72.0);
+		win[0][i + 18] = win[3][i + 18] = 0.5 * sin(M_PI / 72.0 * (double) (2 * (i + 18) + 1)) / cos(M_PI * (double) (2 * (i + 18) + 19) / 72.0);
+	}
+	for (i = 0; i < 6; i++) {
+		win[1][i + 18] = 0.5 / cos(M_PI * (double) (2 * (i + 18) + 19) / 72.0);
+		win[3][i + 12] = 0.5 / cos(M_PI * (double) (2 * (i + 12) + 19) / 72.0);
+		win[1][i + 24] = 0.5 * sin(M_PI / 24.0 * (double) (2 * i + 13)) / cos(M_PI * (double) (2 * (i + 24) + 19) / 72.0);
+		win[1][i + 30] = win[3][i] = 0.0;
+		win[3][i + 6] = 0.5 * sin(M_PI / 24.0 * (double) (2 * i + 1)) / cos(M_PI * (double) (2 * (i + 6) + 19) / 72.0);
+	}
+
+	for (i = 0; i < 9; i++)
+		COS9[i] = cos(M_PI / 18.0 * (double) i);
+
+	for (i = 0; i < 9; i++)
+		tfcos36[i] = 0.5 / cos(M_PI * (double) (i * 2 + 1) / 36.0);
+	for (i = 0; i < 3; i++)
+		tfcos12[i] = 0.5 / cos(M_PI * (double) (i * 2 + 1) / 12.0);
+
+	COS6_1 = cos(M_PI / 6.0 * (double) 1);
+	COS6_2 = cos(M_PI / 6.0 * (double) 2);
+
+	for (i = 0; i < 12; i++) {
+		win[2][i] = 0.5 * sin(M_PI / 24.0 * (double) (2 * i + 1)) / cos(M_PI * (double) (2 * i + 7) / 24.0);
+		for (j = 0; j < 6; j++)
+			COS1[i][j] = cos(M_PI / 24.0 * (double) ((2 * i + 7) * (2 * j + 1)));
+	}
+
+	for (j = 0; j < 4; j++) {
+		static int len[4] = { 36, 36, 12, 36 };
+		for (i = 0; i < len[j]; i += 2)
+			win1[j][i] = +win[j][i];
+		for (i = 1; i < len[j]; i += 2)
+			win1[j][i] = -win[j][i];
+	}
+
+	for (i = 0; i < 16; i++) {
+		double t = tan((double) i * M_PI / 12.0);
+		tan1_1[i] = t / (1.0 + t);
+		tan2_1[i] = 1.0 / (1.0 + t);
+		tan1_2[i] = M_SQRT2 * t / (1.0 + t);
+		tan2_2[i] = M_SQRT2 / (1.0 + t);
+
+		for (j = 0; j < 2; j++) {
+			double base = pow(2.0, -0.25 * (j + 1.0));
+			double p1 = 1.0, p2 = 1.0;
+			if (i > 0) {
+				if (i & 1)
+					p1 = pow(base, (i + 1.0) * 0.5);
+				else
+					p2 = pow(base, i * 0.5);
+			}
+			pow1_1[j][i] = p1;
+			pow2_1[j][i] = p2;
+			pow1_2[j][i] = M_SQRT2 * p1;
+			pow2_2[j][i] = M_SQRT2 * p2;
+		}
+	}
+
+	for (j = 0; j < 9; j++) {
+		struct bandInfoStruct *bi = &bandInfo[j];
+		int *mp;
+		int cb, lwin;
+		short *bdf;
+
+		mp = map[j][0] = mapbuf0[j];
+		bdf = bi->longDiff;
+		for (i = 0, cb = 0; cb < 8; cb++, i += *bdf++) {
+			*mp++ = (*bdf) >> 1;
+			*mp++ = i;
+			*mp++ = 3;
+			*mp++ = cb;
+		}
+		bdf = bi->shortDiff + 3;
+		for (cb = 3; cb < 13; cb++) {
+			int l = (*bdf++) >> 1;
+			for (lwin = 0; lwin < 3; lwin++) {
+				*mp++ = l;
+				*mp++ = i + lwin;
+				*mp++ = lwin;
+				*mp++ = cb;
+			}
+			i += 6 * l;
+		}
+		mapend[j][0] = mp;
+
+		mp = map[j][1] = mapbuf1[j];
+		bdf = bi->shortDiff + 0;
+		for (i = 0, cb = 0; cb < 13; cb++) {
+			int l = (*bdf++) >> 1;
+			for (lwin = 0; lwin < 3; lwin++) {
+				*mp++ = l;
+				*mp++ = i + lwin;
+				*mp++ = lwin;
+				*mp++ = cb;
+			}
+			i += 6 * l;
+		}
+		mapend[j][1] = mp;
+
+		mp = map[j][2] = mapbuf2[j];
+		bdf = bi->longDiff;
+		for (cb = 0; cb < 22; cb++) {
+			*mp++ = (*bdf++) >> 1;
+			*mp++ = cb;
+		}
+		mapend[j][2] = mp;
 
-  for (i=0;i<8;i++)
-  {
-    static double Ci[8]={-0.6,-0.535,-0.33,-0.185,-0.095,-0.041,-0.0142,-0.0037};
-    double sq=sqrt(1.0+Ci[i]*Ci[i]);
-    aa_cs[i] = 1.0/sq;
-    aa_ca[i] = Ci[i]/sq;
-  }
-
-  for(i=0;i<18;i++)
-  {
-    win[0][i]    = win[1][i]    = 0.5 * sin( M_PI / 72.0 * (double) (2*(i+0) +1) ) / cos ( M_PI * (double) (2*(i+0) +19) / 72.0 );
-    win[0][i+18] = win[3][i+18] = 0.5 * sin( M_PI / 72.0 * (double) (2*(i+18)+1) ) / cos ( M_PI * (double) (2*(i+18)+19) / 72.0 );
-  }
-  for(i=0;i<6;i++)
-  {
-    win[1][i+18] = 0.5 / cos ( M_PI * (double) (2*(i+18)+19) / 72.0 );
-    win[3][i+12] = 0.5 / cos ( M_PI * (double) (2*(i+12)+19) / 72.0 );
-    win[1][i+24] = 0.5 * sin( M_PI / 24.0 * (double) (2*i+13) ) / cos ( M_PI * (double) (2*(i+24)+19) / 72.0 );
-    win[1][i+30] = win[3][i] = 0.0;
-    win[3][i+6 ] = 0.5 * sin( M_PI / 24.0 * (double) (2*i+1) )  / cos ( M_PI * (double) (2*(i+6 )+19) / 72.0 );
-  }
-
-  for(i=0;i<9;i++)
-    COS9[i] = cos( M_PI / 18.0 * (double) i);
-
-  for(i=0;i<9;i++)
-    tfcos36[i] = 0.5 / cos ( M_PI * (double) (i*2+1) / 36.0 );
-  for(i=0;i<3;i++)
-    tfcos12[i] = 0.5 / cos ( M_PI * (double) (i*2+1) / 12.0 );
-
-  COS6_1 = cos( M_PI / 6.0 * (double) 1);
-  COS6_2 = cos( M_PI / 6.0 * (double) 2);
-
-  for(i=0;i<12;i++)
-  {
-    win[2][i]  = 0.5 * sin( M_PI / 24.0 * (double) (2*i+1) ) / cos ( M_PI * (double) (2*i+7) / 24.0 );
-    for(j=0;j<6;j++)
-      COS1[i][j] = cos( M_PI / 24.0 * (double) ((2*i+7)*(2*j+1)) );
-  }
-
-  for(j=0;j<4;j++) {
-    static int len[4] = { 36,36,12,36 };
-    for(i=0;i<len[j];i+=2)
-      win1[j][i] = + win[j][i];
-    for(i=1;i<len[j];i+=2)
-      win1[j][i] = - win[j][i];
-  }
-
-  for(i=0;i<16;i++)
-  {
-    double t = tan( (double) i * M_PI / 12.0 );
-    tan1_1[i] = t / (1.0+t);
-    tan2_1[i] = 1.0 / (1.0 + t);
-    tan1_2[i] = M_SQRT2 * t / (1.0+t);
-    tan2_2[i] = M_SQRT2 / (1.0 + t);
-
-    for(j=0;j<2;j++) {
-      double base = pow(2.0,-0.25*(j+1.0));
-      double p1=1.0,p2=1.0;
-      if(i > 0) {
-        if( i & 1 )
-          p1 = pow(base,(i+1.0)*0.5);
-        else
-          p2 = pow(base,i*0.5);
-      }
-      pow1_1[j][i] = p1;
-      pow2_1[j][i] = p2;
-      pow1_2[j][i] = M_SQRT2 * p1;
-      pow2_2[j][i] = M_SQRT2 * p2;
-    }
-  }
-
-  for(j=0;j<9;j++)
-  {
-   struct bandInfoStruct *bi = &bandInfo[j];
-   int *mp;
-   int cb,lwin;
-   short *bdf;
-
-   mp = map[j][0] = mapbuf0[j];
-   bdf = bi->longDiff;
-   for(i=0,cb = 0; cb < 8 ; cb++,i+=*bdf++) {
-     *mp++ = (*bdf) >> 1;
-     *mp++ = i;
-     *mp++ = 3;
-     *mp++ = cb;
-   }
-   bdf = bi->shortDiff+3;
-   for(cb=3;cb<13;cb++) {
-     int l = (*bdf++) >> 1;
-     for(lwin=0;lwin<3;lwin++) {
-       *mp++ = l;
-       *mp++ = i + lwin;
-       *mp++ = lwin;
-       *mp++ = cb;
-     }
-     i += 6*l;
-   }
-   mapend[j][0] = mp;
-
-   mp = map[j][1] = mapbuf1[j];
-   bdf = bi->shortDiff+0;
-   for(i=0,cb=0;cb<13;cb++) {
-     int l = (*bdf++) >> 1;
-     for(lwin=0;lwin<3;lwin++) {
-       *mp++ = l;
-       *mp++ = i + lwin;
-       *mp++ = lwin;
-       *mp++ = cb;
-     }
-     i += 6*l;
-   }
-   mapend[j][1] = mp;
-
-   mp = map[j][2] = mapbuf2[j];
-   bdf = bi->longDiff;
-   for(cb = 0; cb < 22 ; cb++) {
-     *mp++ = (*bdf++) >> 1;
-     *mp++ = cb;
-   }
-   mapend[j][2] = mp;
-
-  }
-
-  for(i=0;i<5;i++) {
-    for(j=0;j<6;j++) {
-      for(k=0;k<6;k++) {
-        int n = k + j * 6 + i * 36;
-        i_slen2[n] = i|(j<<3)|(k<<6)|(3<<12);
-      }
-    }
-  }
-  for(i=0;i<4;i++) {
-    for(j=0;j<4;j++) {
-      for(k=0;k<4;k++) {
-        int n = k + j * 4 + i * 16;
-        i_slen2[n+180] = i|(j<<3)|(k<<6)|(4<<12);
-      }
-    }
-  }
-  for(i=0;i<4;i++) {
-    for(j=0;j<3;j++) {
-      int n = j + i * 3;
-      i_slen2[n+244] = i|(j<<3) | (5<<12);
-      n_slen2[n+500] = i|(j<<3) | (2<<12) | (1<<15);
-    }
-  }
-
-  for(i=0;i<5;i++) {
-    for(j=0;j<5;j++) {
-      for(k=0;k<4;k++) {
-        for(l=0;l<4;l++) {
-          int n = l + k * 4 + j * 16 + i * 80;
-          n_slen2[n] = i|(j<<3)|(k<<6)|(l<<9)|(0<<12);
-        }
-      }
-    }
-  }
-  for(i=0;i<5;i++) {
-    for(j=0;j<5;j++) {
-      for(k=0;k<4;k++) {
-        int n = k + j * 4 + i * 20;
-        n_slen2[n+400] = i|(j<<3)|(k<<6)|(1<<12);
-      }
-    }
-  }
+	}
+
+	for (i = 0; i < 5; i++) {
+		for (j = 0; j < 6; j++) {
+			for (k = 0; k < 6; k++) {
+				int n = k + j * 6 + i * 36;
+				i_slen2[n] = i | (j << 3) | (k << 6) | (3 << 12);
+			}
+		}
+	}
+	for (i = 0; i < 4; i++) {
+		for (j = 0; j < 4; j++) {
+			for (k = 0; k < 4; k++) {
+				int n = k + j * 4 + i * 16;
+				i_slen2[n + 180] = i | (j << 3) | (k << 6) | (4 << 12);
+			}
+		}
+	}
+	for (i = 0; i < 4; i++) {
+		for (j = 0; j < 3; j++) {
+			int n = j + i * 3;
+			i_slen2[n + 244] = i | (j << 3) | (5 << 12);
+			n_slen2[n + 500] = i | (j << 3) | (2 << 12) | (1 << 15);
+		}
+	}
+
+	for (i = 0; i < 5; i++) {
+		for (j = 0; j < 5; j++) {
+			for (k = 0; k < 4; k++) {
+				for (l = 0; l < 4; l++) {
+					int n = l + k * 4 + j * 16 + i * 80;
+					n_slen2[n] = i | (j << 3) | (k << 6) | (l << 9) | (0 << 12);
+				}
+			}
+		}
+	}
+	for (i = 0; i < 5; i++) {
+		for (j = 0; j < 5; j++) {
+			for (k = 0; k < 4; k++) {
+				int n = k + j * 4 + i * 20;
+				n_slen2[n + 400] = i | (j << 3) | (k << 6) | (1 << 12);
+			}
+		}
+	}
 }
 
 /* MP3 file specific rates */
 void init_layer3_sample_limits(struct mpstr *mp, int down_sample_sblimit)
 {
-	int i,j;	
-	for(j=0;j<9;j++) {
-		for(i=0;i<23;i++) {
+	int i, j;
+	for (j = 0; j < 9; j++) {
+		for (i = 0; i < 23; i++) {
 			(mp->longLimit)[j][i] = (bandInfo[j].longIdx[i] - 1 + 8) / 18 + 1;
-			if((mp->longLimit)[j][i] > (down_sample_sblimit) )
+			if ((mp->longLimit)[j][i] > (down_sample_sblimit))
 				(mp->longLimit)[j][i] = down_sample_sblimit;
 		}
-		for(i=0;i<14;i++) {
+		for (i = 0; i < 14; i++) {
 			(mp->shortLimit)[j][i] = (bandInfo[j].shortIdx[i] - 1) / 18 + 1;
-			if((mp->shortLimit)[j][i] > (down_sample_sblimit) )
+			if ((mp->shortLimit)[j][i] > (down_sample_sblimit))
 				(mp->shortLimit)[j][i] = down_sample_sblimit;
 		}
 	}
@@ -297,1272 +291,1216 @@
 /*
  * read additional side information
  */
-#ifdef MPEG1 
-static int III_get_side_info_1(struct mpstr *mp, struct III_sideinfo *si,int stereo,
- int ms_stereo,long sfreq,int single)
+#ifdef MPEG1
+static int III_get_side_info_1(struct mpstr *mp, struct III_sideinfo *si, int stereo, int ms_stereo, long sfreq, int single)
 {
-   int ch, gr;
-   int powdiff = (single == 3) ? 4 : 0;
+	int ch, gr;
+	int powdiff = (single == 3) ? 4 : 0;
+
+	si->main_data_begin = getbits(mp, 9);
+	if (stereo == 1)
+		si->private_bits = getbits_fast(mp, 5);
+	else
+		si->private_bits = getbits_fast(mp, 3);
+
+	for (ch = 0; ch < stereo; ch++) {
+		si->ch[ch].gr[0].scfsi = -1;
+		si->ch[ch].gr[1].scfsi = getbits_fast(mp, 4);
+	}
 
-   si->main_data_begin = getbits(mp, 9);
-   if (stereo == 1)
-     si->private_bits = getbits_fast(mp, 5);
-   else 
-     si->private_bits = getbits_fast(mp, 3);
-
-   for (ch=0; ch<stereo; ch++) {
-       si->ch[ch].gr[0].scfsi = -1;
-       si->ch[ch].gr[1].scfsi = getbits_fast(mp, 4);
-   }
-
-   for (gr=0; gr<2; gr++) 
-   {
-     for (ch=0; ch<stereo; ch++) 
-     {
-       register struct gr_info_s *gr_info = &(si->ch[ch].gr[gr]);
-
-       gr_info->part2_3_length = getbits(mp, 12);
-       gr_info->big_values = getbits_fast(mp, 9);
-       if(gr_info->big_values > 288) {
-		   debug_printf("%d big_values too large!\n", __LINE__);
-          gr_info->big_values = 288;
-       }
-       gr_info->pow2gain = gainpow2+256 - getbits_fast(mp, 8) + powdiff;
-       if(ms_stereo)
-         gr_info->pow2gain += 2;
-       gr_info->scalefac_compress = getbits_fast(mp, 4);
+	for (gr = 0; gr < 2; gr++) {
+		for (ch = 0; ch < stereo; ch++) {
+			register struct gr_info_s *gr_info = &(si->ch[ch].gr[gr]);
+
+			gr_info->part2_3_length = getbits(mp, 12);
+			gr_info->big_values = getbits_fast(mp, 9);
+			if (gr_info->big_values > 288) {
+				debug_printf("%d big_values too large!\n", __LINE__);
+				gr_info->big_values = 288;
+			}
+			gr_info->pow2gain = gainpow2 + 256 - getbits_fast(mp, 8) + powdiff;
+			if (ms_stereo)
+				gr_info->pow2gain += 2;
+			gr_info->scalefac_compress = getbits_fast(mp, 4);
 /* window-switching flag == 1 for block_Type != 0 .. and block-type == 0 -> win-sw-flag = 0 */
-       if(get1bit(mp)) 
-       {
-         int i;
-         gr_info->block_type = getbits_fast(mp, 2);
-         gr_info->mixed_block_flag = get1bit(mp);
-         gr_info->table_select[0] = getbits_fast(mp, 5);
-         gr_info->table_select[1] = getbits_fast(mp, 5);
-         /*
-          * table_select[2] not needed, because there is no region2,
-          * but to satisfy some verifications tools we set it either.
-          */
-         gr_info->table_select[2] = 0;
-         for(i=0;i<3;i++)
-           gr_info->full_gain[i] = gr_info->pow2gain + (getbits_fast(mp, 3)<<3);
-
-         if(gr_info->block_type == 0) {
-			 debug_printf("%d Blocktype == 0 and window-switching == 1 not allowed.\n",  __LINE__);
-           return (1);
-         }
-         /* region_count/start parameters are implicit in this case. */       
-         gr_info->region1start = 36>>1;
-         gr_info->region2start = 576>>1;
-       }
-       else 
-       {
-         int i,r0c,r1c;
-         for (i=0; i<3; i++)
-           gr_info->table_select[i] = getbits_fast(mp, 5);
-         r0c = getbits_fast(mp, 4);
-         r1c = getbits_fast(mp, 3);
-         gr_info->region1start = bandInfo[sfreq].longIdx[r0c+1] >> 1 ;
-         gr_info->region2start = bandInfo[sfreq].longIdx[r0c+1+r1c+1] >> 1;
-         gr_info->block_type = 0;
-         gr_info->mixed_block_flag = 0;
-       }
-       gr_info->preflag = get1bit(mp);
-       gr_info->scalefac_scale = get1bit(mp);
-       gr_info->count1table_select = get1bit(mp);
-     }
-   }
-   return (0);
-   
+			if (get1bit(mp)) {
+				int i;
+				gr_info->block_type = getbits_fast(mp, 2);
+				gr_info->mixed_block_flag = get1bit(mp);
+				gr_info->table_select[0] = getbits_fast(mp, 5);
+				gr_info->table_select[1] = getbits_fast(mp, 5);
+				/*
+				 * table_select[2] not needed, because there is no region2,
+				 * but to satisfy some verifications tools we set it either.
+				 */
+				gr_info->table_select[2] = 0;
+				for (i = 0; i < 3; i++)
+					gr_info->full_gain[i] = gr_info->pow2gain + (getbits_fast(mp, 3) << 3);
+
+				if (gr_info->block_type == 0) {
+					debug_printf("%d Blocktype == 0 and window-switching == 1 not allowed.\n", __LINE__);
+					return (1);
+				}
+				/* region_count/start parameters are implicit in this case. */
+				gr_info->region1start = 36 >> 1;
+				gr_info->region2start = 576 >> 1;
+			} else {
+				int i, r0c, r1c;
+				for (i = 0; i < 3; i++)
+					gr_info->table_select[i] = getbits_fast(mp, 5);
+				r0c = getbits_fast(mp, 4);
+				r1c = getbits_fast(mp, 3);
+				gr_info->region1start = bandInfo[sfreq].longIdx[r0c + 1] >> 1;
+				gr_info->region2start = bandInfo[sfreq].longIdx[r0c + 1 + r1c + 1] >> 1;
+				gr_info->block_type = 0;
+				gr_info->mixed_block_flag = 0;
+			}
+			gr_info->preflag = get1bit(mp);
+			gr_info->scalefac_scale = get1bit(mp);
+			gr_info->count1table_select = get1bit(mp);
+		}
+	}
+	return (0);
+
 }
 #endif
 
 /*
  * Side Info for MPEG 2.0 / LSF
  */
-static int III_get_side_info_2(struct mpstr *mp, struct III_sideinfo *si,int stereo,
- int ms_stereo,long sfreq,int single)
+static int III_get_side_info_2(struct mpstr *mp, struct III_sideinfo *si, int stereo, int ms_stereo, long sfreq, int single)
 {
-   int ch;
-   int powdiff = (single == 3) ? 4 : 0;
+	int ch;
+	int powdiff = (single == 3) ? 4 : 0;
 
-   si->main_data_begin = getbits(mp, 8);
-   if (stereo == 1)
-     si->private_bits = get1bit(mp);
-   else 
-     si->private_bits = getbits_fast(mp, 2);
-
-   for (ch=0; ch<stereo; ch++) 
-   {
-       register struct gr_info_s *gr_info = &(si->ch[ch].gr[0]);
-
-       gr_info->part2_3_length = getbits(mp, 12);
-       gr_info->big_values = getbits_fast(mp, 9);
-       if(gr_info->big_values > 288) {
-		   debug_printf("%d big_values too large!\n",  __LINE__);
-         gr_info->big_values = 288;
-       }
-       gr_info->pow2gain = gainpow2+256 - getbits_fast(mp, 8) + powdiff;
-       if(ms_stereo)
-         gr_info->pow2gain += 2;
-       gr_info->scalefac_compress = getbits(mp, 9);
+	si->main_data_begin = getbits(mp, 8);
+	if (stereo == 1)
+		si->private_bits = get1bit(mp);
+	else
+		si->private_bits = getbits_fast(mp, 2);
+
+	for (ch = 0; ch < stereo; ch++) {
+		register struct gr_info_s *gr_info = &(si->ch[ch].gr[0]);
+
+		gr_info->part2_3_length = getbits(mp, 12);
+		gr_info->big_values = getbits_fast(mp, 9);
+		if (gr_info->big_values > 288) {
+			debug_printf("%d big_values too large!\n", __LINE__);
+			gr_info->big_values = 288;
+		}
+		gr_info->pow2gain = gainpow2 + 256 - getbits_fast(mp, 8) + powdiff;
+		if (ms_stereo)
+			gr_info->pow2gain += 2;
+		gr_info->scalefac_compress = getbits(mp, 9);
 /* window-switching flag == 1 for block_Type != 0 .. and block-type == 0 -> win-sw-flag = 0 */
-       if(get1bit(mp)) 
-       {
-         int i;
-         gr_info->block_type = getbits_fast(mp, 2);
-         gr_info->mixed_block_flag = get1bit(mp);
-         gr_info->table_select[0] = getbits_fast(mp, 5);
-         gr_info->table_select[1] = getbits_fast(mp, 5);
-         /*
-          * table_select[2] not needed, because there is no region2,
-          * but to satisfy some verifications tools we set it either.
-          */
-         gr_info->table_select[2] = 0;
-         for(i=0;i<3;i++)
-           gr_info->full_gain[i] = gr_info->pow2gain + (getbits_fast(mp, 3)<<3);
-
-         if(gr_info->block_type == 0) {
-			 debug_printf("%d Blocktype == 0 and window-switching == 1 not allowed.\n",  __LINE__);
-           return (1);
-         }
-         /* region_count/start parameters are implicit in this case. */       
+		if (get1bit(mp)) {
+			int i;
+			gr_info->block_type = getbits_fast(mp, 2);
+			gr_info->mixed_block_flag = get1bit(mp);
+			gr_info->table_select[0] = getbits_fast(mp, 5);
+			gr_info->table_select[1] = getbits_fast(mp, 5);
+			/*
+			 * table_select[2] not needed, because there is no region2,
+			 * but to satisfy some verifications tools we set it either.
+			 */
+			gr_info->table_select[2] = 0;
+			for (i = 0; i < 3; i++)
+				gr_info->full_gain[i] = gr_info->pow2gain + (getbits_fast(mp, 3) << 3);
+
+			if (gr_info->block_type == 0) {
+				debug_printf("%d Blocktype == 0 and window-switching == 1 not allowed.\n", __LINE__);
+				return (1);
+			}
+			/* region_count/start parameters are implicit in this case. */
 /* check this again! */
-         if(gr_info->block_type == 2)
-           gr_info->region1start = 36>>1;
-         else if(sfreq == 8)
+			if (gr_info->block_type == 2)
+				gr_info->region1start = 36 >> 1;
+			else if (sfreq == 8)
 /* check this for 2.5 and sfreq=8 */
-           gr_info->region1start = 108>>1;
-         else
-           gr_info->region1start = 54>>1;
-         gr_info->region2start = 576>>1;
-       }
-       else 
-       {
-         int i,r0c,r1c;
-         for (i=0; i<3; i++)
-           gr_info->table_select[i] = getbits_fast(mp, 5);
-         r0c = getbits_fast(mp, 4);
-         r1c = getbits_fast(mp, 3);
-         gr_info->region1start = bandInfo[sfreq].longIdx[r0c+1] >> 1 ;
-         gr_info->region2start = bandInfo[sfreq].longIdx[r0c+1+r1c+1] >> 1;
-         gr_info->block_type = 0;
-         gr_info->mixed_block_flag = 0;
-       }
-       gr_info->scalefac_scale = get1bit(mp);
-       gr_info->count1table_select = get1bit(mp);
-   }
-   return (0);
+				gr_info->region1start = 108 >> 1;
+			else
+				gr_info->region1start = 54 >> 1;
+			gr_info->region2start = 576 >> 1;
+		} else {
+			int i, r0c, r1c;
+			for (i = 0; i < 3; i++)
+				gr_info->table_select[i] = getbits_fast(mp, 5);
+			r0c = getbits_fast(mp, 4);
+			r1c = getbits_fast(mp, 3);
+			gr_info->region1start = bandInfo[sfreq].longIdx[r0c + 1] >> 1;
+			gr_info->region2start = bandInfo[sfreq].longIdx[r0c + 1 + r1c + 1] >> 1;
+			gr_info->block_type = 0;
+			gr_info->mixed_block_flag = 0;
+		}
+		gr_info->scalefac_scale = get1bit(mp);
+		gr_info->count1table_select = get1bit(mp);
+	}
+	return (0);
 }
 
 /*
  * read scalefactors
  */
 #ifdef MPEG1
-static int III_get_scale_factors_1(struct mpstr *mp, int *scf,struct gr_info_s *gr_info)
+static int III_get_scale_factors_1(struct mpstr *mp, int *scf, struct gr_info_s *gr_info)
 {
-   static unsigned char slen[2][16] = {
-     {0, 0, 0, 0, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4},
-     {0, 1, 2, 3, 0, 1, 2, 3, 1, 2, 3, 1, 2, 3, 2, 3}
-   };
-   int numbits;
-   int num0 = slen[0][gr_info->scalefac_compress];
-   int num1 = slen[1][gr_info->scalefac_compress];
-
-    if (gr_info->block_type == 2) 
-    {
-      int i=18;
-      numbits = (num0 + num1) * 18;
-
-      if (gr_info->mixed_block_flag) {
-         for (i=8;i;i--)
-           *scf++ = getbits_fast(mp, num0);
-         i = 9;
-         numbits -= num0; /* num0 * 17 + num1 * 18 */
-      }
-
-      for (;i;i--)
-        *scf++ = getbits_fast(mp, num0);
-      for (i = 18; i; i--)
-        *scf++ = getbits_fast(mp, num1);
-      *scf++ = 0; *scf++ = 0; *scf++ = 0; /* short[13][0..2] = 0 */
-    }
-    else 
-    {
-      int i;
-      int scfsi = gr_info->scfsi;
-
-      if(scfsi < 0) { /* scfsi < 0 => granule == 0 */
-         for(i=11;i;i--)
-           *scf++ = getbits_fast(mp, num0);
-         for(i=10;i;i--)
-           *scf++ = getbits_fast(mp, num1);
-         numbits = (num0 + num1) * 10 + num0;
-      }
-      else {
-        numbits = 0;
-        if(!(scfsi & 0x8)) {
-          for (i=6;i;i--)
-            *scf++ = getbits_fast(mp, num0);
-          numbits += num0 * 6;
-        }
-        else {
-          *scf++ = 0; *scf++ = 0; *scf++ = 0;  /* set to ZERO necessary? */
-          *scf++ = 0; *scf++ = 0; *scf++ = 0;
-        }
-
-        if(!(scfsi & 0x4)) {
-          for (i=5;i;i--)
-            *scf++ = getbits_fast(mp, num0);
-          numbits += num0 * 5;
-        }
-        else {
-          *scf++ = 0; *scf++ = 0; *scf++ = 0;  /* set to ZERO necessary? */
-          *scf++ = 0; *scf++ = 0;
-        }
-
-        if(!(scfsi & 0x2)) {
-          for(i=5;i;i--)
-            *scf++ = getbits_fast(mp, num1);
-          numbits += num1 * 5;
-        }
-        else {
-          *scf++ = 0; *scf++ = 0; *scf++ = 0;  /* set to ZERO necessary? */
-          *scf++ = 0; *scf++ = 0;
-        }
-
-        if(!(scfsi & 0x1)) {
-          for (i=5;i;i--)
-            *scf++ = getbits_fast(mp, num1);
-          numbits += num1 * 5;
-        }
-        else {
-          *scf++ = 0; *scf++ = 0; *scf++ = 0;  /* set to ZERO necessary? */
-          *scf++ = 0; *scf++ = 0;
-        }
-      }
-
-      *scf++ = 0;  /* no l[21] in original sources */
-    }
-    return numbits;
+	static unsigned char slen[2][16] = {
+		{0, 0, 0, 0, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4},
+		{0, 1, 2, 3, 0, 1, 2, 3, 1, 2, 3, 1, 2, 3, 2, 3}
+	};
+	int numbits;
+	int num0 = slen[0][gr_info->scalefac_compress];
+	int num1 = slen[1][gr_info->scalefac_compress];
+
+	if (gr_info->block_type == 2) {
+		int i = 18;
+		numbits = (num0 + num1) * 18;
+
+		if (gr_info->mixed_block_flag) {
+			for (i = 8; i; i--)
+				*scf++ = getbits_fast(mp, num0);
+			i = 9;
+			numbits -= num0;	/* num0 * 17 + num1 * 18 */
+		}
+
+		for (; i; i--)
+			*scf++ = getbits_fast(mp, num0);
+		for (i = 18; i; i--)
+			*scf++ = getbits_fast(mp, num1);
+		*scf++ = 0;
+		*scf++ = 0;
+		*scf++ = 0;				/* short[13][0..2] = 0 */
+	} else {
+		int i;
+		int scfsi = gr_info->scfsi;
+
+		if (scfsi < 0) {		/* scfsi < 0 => granule == 0 */
+			for (i = 11; i; i--)
+				*scf++ = getbits_fast(mp, num0);
+			for (i = 10; i; i--)
+				*scf++ = getbits_fast(mp, num1);
+			numbits = (num0 + num1) * 10 + num0;
+		} else {
+			numbits = 0;
+			if (!(scfsi & 0x8)) {
+				for (i = 6; i; i--)
+					*scf++ = getbits_fast(mp, num0);
+				numbits += num0 * 6;
+			} else {
+				*scf++ = 0;
+				*scf++ = 0;
+				*scf++ = 0;		/* set to ZERO necessary? */
+				*scf++ = 0;
+				*scf++ = 0;
+				*scf++ = 0;
+			}
+
+			if (!(scfsi & 0x4)) {
+				for (i = 5; i; i--)
+					*scf++ = getbits_fast(mp, num0);
+				numbits += num0 * 5;
+			} else {
+				*scf++ = 0;
+				*scf++ = 0;
+				*scf++ = 0;		/* set to ZERO necessary? */
+				*scf++ = 0;
+				*scf++ = 0;
+			}
+
+			if (!(scfsi & 0x2)) {
+				for (i = 5; i; i--)
+					*scf++ = getbits_fast(mp, num1);
+				numbits += num1 * 5;
+			} else {
+				*scf++ = 0;
+				*scf++ = 0;
+				*scf++ = 0;		/* set to ZERO necessary? */
+				*scf++ = 0;
+				*scf++ = 0;
+			}
+
+			if (!(scfsi & 0x1)) {
+				for (i = 5; i; i--)
+					*scf++ = getbits_fast(mp, num1);
+				numbits += num1 * 5;
+			} else {
+				*scf++ = 0;
+				*scf++ = 0;
+				*scf++ = 0;		/* set to ZERO necessary? */
+				*scf++ = 0;
+				*scf++ = 0;
+			}
+		}
+
+		*scf++ = 0;				/* no l[21] in original sources */
+	}
+	return numbits;
 }
 #endif
 
-static int III_get_scale_factors_2(struct mpstr *mp, int *scf,struct gr_info_s *gr_info,int i_stereo)
+static int III_get_scale_factors_2(struct mpstr *mp, int *scf, struct gr_info_s *gr_info, int i_stereo)
 {
-  unsigned char *pnt;
-  int i,j;
-  unsigned int slen;
-  int n = 0;
-  int numbits = 0;
-
-  static unsigned char stab[3][6][4] = {
-   { { 6, 5, 5,5 } , { 6, 5, 7,3 } , { 11,10,0,0} ,
-     { 7, 7, 7,0 } , { 6, 6, 6,3 } , {  8, 8,5,0} } ,
-   { { 9, 9, 9,9 } , { 9, 9,12,6 } , { 18,18,0,0} ,
-     {12,12,12,0 } , {12, 9, 9,6 } , { 15,12,9,0} } ,
-   { { 6, 9, 9,9 } , { 6, 9,12,6 } , { 15,18,0,0} ,
-     { 6,15,12,0 } , { 6,12, 9,6 } , {  6,18,9,0} } }; 
-
-  if(i_stereo) /* i_stereo AND second channel -> do_layer3() checks this */
-    slen = i_slen2[gr_info->scalefac_compress>>1];
-  else
-    slen = n_slen2[gr_info->scalefac_compress];
-
-  gr_info->preflag = (slen>>15) & 0x1;
-
-  n = 0;  
-  if( gr_info->block_type == 2 ) {
-    n++;
-    if(gr_info->mixed_block_flag)
-      n++;
-  }
-
-  pnt = stab[n][(slen>>12)&0x7];
-
-  for(i=0;i<4;i++) {
-    int num = slen & 0x7;
-    slen >>= 3;
-    if(num) {
-      for(j=0;j<(int)(pnt[i]);j++)
-        *scf++ = getbits_fast(mp, num);
-      numbits += pnt[i] * num;
-    }
-    else {
-      for(j=0;j<(int)(pnt[i]);j++)
-        *scf++ = 0;
-    }
-  }
-  
-  n = (n << 1) + 1;
-  for(i=0;i<n;i++)
-    *scf++ = 0;
+	unsigned char *pnt;
+	int i, j;
+	unsigned int slen;
+	int n = 0;
+	int numbits = 0;
+
+	static unsigned char stab[3][6][4] = {
+		{{6, 5, 5, 5}, {6, 5, 7, 3}, {11, 10, 0, 0},
+		 {7, 7, 7, 0}, {6, 6, 6, 3}, {8, 8, 5, 0}},
+		{{9, 9, 9, 9}, {9, 9, 12, 6}, {18, 18, 0, 0},
+		 {12, 12, 12, 0}, {12, 9, 9, 6}, {15, 12, 9, 0}},
+		{{6, 9, 9, 9}, {6, 9, 12, 6}, {15, 18, 0, 0},
+		 {6, 15, 12, 0}, {6, 12, 9, 6}, {6, 18, 9, 0}}
+	};
+
+	if (i_stereo)				/* i_stereo AND second channel -> do_layer3() checks this */
+		slen = i_slen2[gr_info->scalefac_compress >> 1];
+	else
+		slen = n_slen2[gr_info->scalefac_compress];
+
+	gr_info->preflag = (slen >> 15) & 0x1;
+
+	n = 0;
+	if (gr_info->block_type == 2) {
+		n++;
+		if (gr_info->mixed_block_flag)
+			n++;
+	}
+
+	pnt = stab[n][(slen >> 12) & 0x7];
 
-  return numbits;
+	for (i = 0; i < 4; i++) {
+		int num = slen & 0x7;
+		slen >>= 3;
+		if (num) {
+			for (j = 0; j < (int) (pnt[i]); j++)
+				*scf++ = getbits_fast(mp, num);
+			numbits += pnt[i] * num;
+		} else {
+			for (j = 0; j < (int) (pnt[i]); j++)
+				*scf++ = 0;
+		}
+	}
+
+	n = (n << 1) + 1;
+	for (i = 0; i < n; i++)
+		*scf++ = 0;
+
+	return numbits;
 }
 
-static int pretab1[22] = {0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,2,2,3,3,3,2,0};
-static int pretab2[22] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+static int pretab1[22] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 2, 0 };
+static int pretab2[22] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
 
 /*
  * don't forget to apply the same changes to III_dequantize_sample_ms() !!! 
  */
-static int III_dequantize_sample(struct mpstr *mp, real xr[SBLIMIT][SSLIMIT],int *scf,
-   struct gr_info_s *gr_info,int sfreq,int part2bits)
+static int III_dequantize_sample(struct mpstr *mp, real xr[SBLIMIT][SSLIMIT], int *scf, struct gr_info_s *gr_info, int sfreq, int part2bits)
 {
-  int shift = 1 + gr_info->scalefac_scale;
-  real *xrpnt = (real *) xr;
-  int l[3],l3;
-  int part2remain = gr_info->part2_3_length - part2bits;
-  int *me;
-
-  {
-    int bv       = gr_info->big_values;
-    int region1  = gr_info->region1start;
-    int region2  = gr_info->region2start;
+	int shift = 1 + gr_info->scalefac_scale;
+	real *xrpnt = (real *) xr;
+	int l[3], l3;
+	int part2remain = gr_info->part2_3_length - part2bits;
+	int *me;
 
-    l3 = ((576>>1)-bv)>>1;   
+	{
+		int bv = gr_info->big_values;
+		int region1 = gr_info->region1start;
+		int region2 = gr_info->region2start;
+
+		l3 = ((576 >> 1) - bv) >> 1;
 /*
  * we may lose the 'odd' bit here !! 
  * check this later again 
  */
-    if(bv <= region1) {
-      l[0] = bv; l[1] = 0; l[2] = 0;
-    }
-    else {
-      l[0] = region1;
-      if(bv <= region2) {
-        l[1] = bv - l[0];  l[2] = 0;
-      }
-      else {
-        l[1] = region2 - l[0]; l[2] = bv - region2;
-      }
-    }
-  }
- 
-  if(gr_info->block_type == 2) {
-    /*
-     * decoding with short or mixed mode BandIndex table 
-     */
-    int i,max[4];
-    int step=0,lwin=0,cb=0;
-    register real v = 0.0;
-    register int *m,mc;
-
-    if(gr_info->mixed_block_flag) {
-      max[3] = -1;
-      max[0] = max[1] = max[2] = 2;
-      m = map[sfreq][0];
-      me = mapend[sfreq][0];
-    }
-    else {
-      max[0] = max[1] = max[2] = max[3] = -1;
-      /* max[3] not really needed in this case */
-      m = map[sfreq][1];
-      me = mapend[sfreq][1];
-    }
-
-    mc = 0;
-    for(i=0;i<2;i++) {
-      int lp = l[i];
-      struct newhuff *h = ht+gr_info->table_select[i];
-      for(;lp;lp--,mc--) {
-        register int x,y;
-        if( (!mc) ) {
-          mc = *m++;
-          xrpnt = ((real *) xr) + (*m++);
-          lwin = *m++;
-          cb = *m++;
-          if(lwin == 3) {
-            v = gr_info->pow2gain[(*scf++) << shift];
-            step = 1;
-          }
-          else {
-            v = gr_info->full_gain[lwin][(*scf++) << shift];
-            step = 3;
-          }
-        }
-        {
-          register short *val = h->table;
-          while((y=*val++)<0) {
-            if (get1bit(mp))
-              val -= y;
-            part2remain--;
-          }
-          x = y >> 4;
-          y &= 0xf;
-        }
-        if(x == 15) {
-          max[lwin] = cb;
-          part2remain -= h->linbits+1;
-          x += getbits(mp, h->linbits);
-          if(get1bit(mp))
-            *xrpnt = -ispow[x] * v;
-          else
-            *xrpnt =  ispow[x] * v;
-        }
-        else if(x) {
-          max[lwin] = cb;
-          if(get1bit(mp))
-            *xrpnt = -ispow[x] * v;
-          else
-            *xrpnt =  ispow[x] * v;
-          part2remain--;
-        }
-        else
-          *xrpnt = 0.0;
-        xrpnt += step;
-        if(y == 15) {
-          max[lwin] = cb;
-          part2remain -= h->linbits+1;
-          y += getbits(mp, h->linbits);
-          if(get1bit(mp))
-            *xrpnt = -ispow[y] * v;
-          else
-            *xrpnt =  ispow[y] * v;
-        }
-        else if(y) {
-          max[lwin] = cb;
-          if(get1bit(mp))
-            *xrpnt = -ispow[y] * v;
-          else
-            *xrpnt =  ispow[y] * v;
-          part2remain--;
-        }
-        else
-          *xrpnt = 0.0;
-        xrpnt += step;
-      }
-    }
-    for(;l3 && (part2remain > 0);l3--) {
-      struct newhuff *h = htc+gr_info->count1table_select;
-      register short *val = h->table,a;
-
-      while((a=*val++)<0) {
-        part2remain--;
-        if(part2remain < 0) {
-          part2remain++;
-          a = 0;
-          break;
-        }
-        if (get1bit(mp))
-          val -= a;
-      }
-
-      for(i=0;i<4;i++) {
-        if(!(i & 1)) {
-          if(!mc) {
-            mc = *m++;
-            xrpnt = ((real *) xr) + (*m++);
-            lwin = *m++;
-            cb = *m++;
-            if(lwin == 3) {
-              v = gr_info->pow2gain[(*scf++) << shift];
-              step = 1;
-            }
-            else {
-              v = gr_info->full_gain[lwin][(*scf++) << shift];
-              step = 3;
-            }
-          }
-          mc--;
-        }
-        if( (a & (0x8>>i)) ) {
-          max[lwin] = cb;
-          part2remain--;
-          if(part2remain < 0) {
-            part2remain++;
-            break;
-          }
-          if(get1bit(mp)) 
-            *xrpnt = -v;
-          else
-            *xrpnt = v;
-        }
-        else
-          *xrpnt = 0.0;
-        xrpnt += step;
-      }
-    }
- 
-    while( m < me ) {
-      if(!mc) {
-        mc = *m++;
-        xrpnt = ((real *) xr) + *m++;
-        if( (*m++) == 3)
-          step = 1;
-        else
-          step = 3;
-        m++; /* cb */
-      }
-      mc--;
-      *xrpnt = 0.0;
-      xrpnt += step;
-      *xrpnt = 0.0;
-      xrpnt += step;
+		if (bv <= region1) {
+			l[0] = bv;
+			l[1] = 0;
+			l[2] = 0;
+		} else {
+			l[0] = region1;
+			if (bv <= region2) {
+				l[1] = bv - l[0];
+				l[2] = 0;
+			} else {
+				l[1] = region2 - l[0];
+				l[2] = bv - region2;
+			}
+		}
+	}
+
+	if (gr_info->block_type == 2) {
+		/*
+		 * decoding with short or mixed mode BandIndex table 
+		 */
+		int i, max[4];
+		int step = 0, lwin = 0, cb = 0;
+		register real v = 0.0;
+		register int *m, mc;
+
+		if (gr_info->mixed_block_flag) {
+			max[3] = -1;
+			max[0] = max[1] = max[2] = 2;
+			m = map[sfreq][0];
+			me = mapend[sfreq][0];
+		} else {
+			max[0] = max[1] = max[2] = max[3] = -1;
+			/* max[3] not really needed in this case */
+			m = map[sfreq][1];
+			me = mapend[sfreq][1];
+		}
+
+		mc = 0;
+		for (i = 0; i < 2; i++) {
+			int lp = l[i];
+			struct newhuff *h = ht + gr_info->table_select[i];
+			for (; lp; lp--, mc--) {
+				register int x, y;
+				if ((!mc)) {
+					mc = *m++;
+					xrpnt = ((real *) xr) + (*m++);
+					lwin = *m++;
+					cb = *m++;
+					if (lwin == 3) {
+						v = gr_info->pow2gain[(*scf++) << shift];
+						step = 1;
+					} else {
+						v = gr_info->full_gain[lwin][(*scf++) << shift];
+						step = 3;
+					}
+				}
+				{
+					register short *val = h->table;
+					while ((y = *val++) < 0) {
+						if (get1bit(mp))
+							val -= y;
+						part2remain--;
+					}
+					x = y >> 4;
+					y &= 0xf;
+				}
+				if (x == 15) {
+					max[lwin] = cb;
+					part2remain -= h->linbits + 1;
+					x += getbits(mp, h->linbits);
+					if (get1bit(mp))
+						*xrpnt = -ispow[x] * v;
+					else
+						*xrpnt = ispow[x] * v;
+				} else if (x) {
+					max[lwin] = cb;
+					if (get1bit(mp))
+						*xrpnt = -ispow[x] * v;
+					else
+						*xrpnt = ispow[x] * v;
+					part2remain--;
+				} else
+					*xrpnt = 0.0;
+				xrpnt += step;
+				if (y == 15) {
+					max[lwin] = cb;
+					part2remain -= h->linbits + 1;
+					y += getbits(mp, h->linbits);
+					if (get1bit(mp))
+						*xrpnt = -ispow[y] * v;
+					else
+						*xrpnt = ispow[y] * v;
+				} else if (y) {
+					max[lwin] = cb;
+					if (get1bit(mp))
+						*xrpnt = -ispow[y] * v;
+					else
+						*xrpnt = ispow[y] * v;
+					part2remain--;
+				} else
+					*xrpnt = 0.0;
+				xrpnt += step;
+			}
+		}
+		for (; l3 && (part2remain > 0); l3--) {
+			struct newhuff *h = htc + gr_info->count1table_select;
+			register short *val = h->table, a;
+
+			while ((a = *val++) < 0) {
+				part2remain--;
+				if (part2remain < 0) {
+					part2remain++;
+					a = 0;
+					break;
+				}
+				if (get1bit(mp))
+					val -= a;
+			}
+
+			for (i = 0; i < 4; i++) {
+				if (!(i & 1)) {
+					if (!mc) {
+						mc = *m++;
+						xrpnt = ((real *) xr) + (*m++);
+						lwin = *m++;
+						cb = *m++;
+						if (lwin == 3) {
+							v = gr_info->pow2gain[(*scf++) << shift];
+							step = 1;
+						} else {
+							v = gr_info->full_gain[lwin][(*scf++) << shift];
+							step = 3;
+						}
+					}
+					mc--;
+				}
+				if ((a & (0x8 >> i))) {
+					max[lwin] = cb;
+					part2remain--;
+					if (part2remain < 0) {
+						part2remain++;
+						break;
+					}
+					if (get1bit(mp))
+						*xrpnt = -v;
+					else
+						*xrpnt = v;
+				} else
+					*xrpnt = 0.0;
+				xrpnt += step;
+			}
+		}
+
+		while (m < me) {
+			if (!mc) {
+				mc = *m++;
+				xrpnt = ((real *) xr) + *m++;
+				if ((*m++) == 3)
+					step = 1;
+				else
+					step = 3;
+				m++;			/* cb */
+			}
+			mc--;
+			*xrpnt = 0.0;
+			xrpnt += step;
+			*xrpnt = 0.0;
+			xrpnt += step;
 /* we could add a little opt. here:
  * if we finished a band for window 3 or a long band
  * further bands could copied in a simple loop without a
  * special 'map' decoding
  */
-    }
+		}
+
+		gr_info->maxband[0] = max[0] + 1;
+		gr_info->maxband[1] = max[1] + 1;
+		gr_info->maxband[2] = max[2] + 1;
+		gr_info->maxbandl = max[3] + 1;
+
+		{
+			int rmax = max[0] > max[1] ? max[0] : max[1];
+			rmax = (rmax > max[2] ? rmax : max[2]) + 1;
+			gr_info->maxb = rmax ? (mp->shortLimit)[sfreq][rmax] : (mp->longLimit)[sfreq][max[3] + 1];
+		}
 
-    gr_info->maxband[0] = max[0]+1;
-    gr_info->maxband[1] = max[1]+1;
-    gr_info->maxband[2] = max[2]+1;
-    gr_info->maxbandl = max[3]+1;
-
-    {
-      int rmax = max[0] > max[1] ? max[0] : max[1];
-      rmax = (rmax > max[2] ? rmax : max[2]) + 1;
-      gr_info->maxb = rmax ? (mp->shortLimit)[sfreq][rmax] : (mp->longLimit)[sfreq][max[3]+1];
-    }
-
-  }
-  else {
-	/*
-     * decoding with 'long' BandIndex table (block_type != 2)
-     */
-    int *pretab = gr_info->preflag ? pretab1 : pretab2;
-    int i,max = -1;
-    int cb = 0;
-    register int *m = map[sfreq][2];
-    register real v = 0.0;
-    register int mc = 0;
+	} else {
+		/*
+		 * decoding with 'long' BandIndex table (block_type != 2)
+		 */
+		int *pretab = gr_info->preflag ? pretab1 : pretab2;
+		int i, max = -1;
+		int cb = 0;
+		register int *m = map[sfreq][2];
+		register real v = 0.0;
+		register int mc = 0;
 #if 0
-    me = mapend[sfreq][2];
+		me = mapend[sfreq][2];
 #endif
 
-	/*
-     * long hash table values
-     */
-    for(i=0;i<3;i++) {
-      int lp = l[i];
-      struct newhuff *h = ht+gr_info->table_select[i];
-
-      for(;lp;lp--,mc--) {
-        int x,y;
-
-        if(!mc) {
-          mc = *m++;
-          v = gr_info->pow2gain[((*scf++) + (*pretab++)) << shift];
-          cb = *m++;
-        }
-        {
-          register short *val = h->table;
-          while((y=*val++)<0) {
-            if (get1bit(mp))
-              val -= y;
-            part2remain--;
-          }
-          x = y >> 4;
-          y &= 0xf;
-        }
-        if (x == 15) {
-          max = cb;
-          part2remain -= h->linbits+1;
-          x += getbits(mp, h->linbits);
-          if(get1bit(mp))
-            *xrpnt++ = -ispow[x] * v;
-          else
-            *xrpnt++ =  ispow[x] * v;
-        }
-        else if(x) {
-          max = cb;
-          if(get1bit(mp))
-            *xrpnt++ = -ispow[x] * v;
-          else
-            *xrpnt++ =  ispow[x] * v;
-          part2remain--;
-        }
-        else
-          *xrpnt++ = 0.0;
-
-        if (y == 15) {
-          max = cb;
-          part2remain -= h->linbits+1;
-          y += getbits(mp, h->linbits);
-          if(get1bit(mp))
-            *xrpnt++ = -ispow[y] * v;
-          else
-            *xrpnt++ =  ispow[y] * v;
-        }
-        else if(y) {
-          max = cb;
-          if(get1bit(mp))
-            *xrpnt++ = -ispow[y] * v;
-          else
-            *xrpnt++ =  ispow[y] * v;
-          part2remain--;
-        }
-        else
-          *xrpnt++ = 0.0;
-      }
-    }
-
-	/*
-     * short (count1table) values
-     */
-    for(;l3 && (part2remain > 0);l3--) {
-      struct newhuff *h = htc+gr_info->count1table_select;
-      register short *val = h->table,a;
-
-      while((a=*val++)<0) {
-        part2remain--;
-        if(part2remain < 0) {
-          part2remain++;
-          a = 0;
-          break;
-        }
-        if (get1bit(mp))
-          val -= a;
-      }
-
-      for(i=0;i<4;i++) {
-        if(!(i & 1)) {
-          if(!mc) {
-            mc = *m++;
-            cb = *m++;
-            v = gr_info->pow2gain[((*scf++) + (*pretab++)) << shift];
-          }
-          mc--;
-        }
-        if ( (a & (0x8>>i)) ) {
-          max = cb;
-          part2remain--;
-          if(part2remain < 0) {
-            part2remain++;
-            break;
-          }
-          if(get1bit(mp))
-            *xrpnt++ = -v;
-          else
-            *xrpnt++ = v;
-        }
-        else
-          *xrpnt++ = 0.0;
-      }
-    }
-
-	/* 
-     * zero part
-     */
-    for(i=(&xr[SBLIMIT][0]-xrpnt)>>1;i;i--) {
-      *xrpnt++ = 0.0;
-      *xrpnt++ = 0.0;
-    }
-
-    gr_info->maxbandl = max+1;
-    gr_info->maxb = (mp->longLimit)[sfreq][gr_info->maxbandl];
-  }
-
-  while( part2remain > 16 ) {
-    getbits(mp, 16); /* Dismiss stuffing Bits */
-    part2remain -= 16;
-  }
-  if(part2remain > 0)
-    getbits(mp, part2remain);
-  else if(part2remain < 0) {
-	  debug_printf("mpg123: %d Can't rewind stream by %d bits!\n",-part2remain,  __LINE__);
-    return 1; /* -> error */
-  }
-  return 0;
+		/*
+		 * long hash table values
+		 */
+		for (i = 0; i < 3; i++) {
+			int lp = l[i];
+			struct newhuff *h = ht + gr_info->table_select[i];
+
+			for (; lp; lp--, mc--) {
+				int x, y;
+
+				if (!mc) {
+					mc = *m++;
+					v = gr_info->pow2gain[((*scf++) + (*pretab++)) << shift];
+					cb = *m++;
+				}
+				{
+					register short *val = h->table;
+					while ((y = *val++) < 0) {
+						if (get1bit(mp))
+							val -= y;
+						part2remain--;
+					}
+					x = y >> 4;
+					y &= 0xf;
+				}
+				if (x == 15) {
+					max = cb;
+					part2remain -= h->linbits + 1;
+					x += getbits(mp, h->linbits);
+					if (get1bit(mp))
+						*xrpnt++ = -ispow[x] * v;
+					else
+						*xrpnt++ = ispow[x] * v;
+				} else if (x) {
+					max = cb;
+					if (get1bit(mp))
+						*xrpnt++ = -ispow[x] * v;
+					else
+						*xrpnt++ = ispow[x] * v;
+					part2remain--;
+				} else
+					*xrpnt++ = 0.0;
+
+				if (y == 15) {
+					max = cb;
+					part2remain -= h->linbits + 1;
+					y += getbits(mp, h->linbits);
+					if (get1bit(mp))
+						*xrpnt++ = -ispow[y] * v;
+					else
+						*xrpnt++ = ispow[y] * v;
+				} else if (y) {
+					max = cb;
+					if (get1bit(mp))
+						*xrpnt++ = -ispow[y] * v;
+					else
+						*xrpnt++ = ispow[y] * v;
+					part2remain--;
+				} else
+					*xrpnt++ = 0.0;
+			}
+		}
+
+		/*
+		 * short (count1table) values
+		 */
+		for (; l3 && (part2remain > 0); l3--) {
+			struct newhuff *h = htc + gr_info->count1table_select;
+			register short *val = h->table, a;
+
+			while ((a = *val++) < 0) {
+				part2remain--;
+				if (part2remain < 0) {
+					part2remain++;
+					a = 0;
+					break;
+				}
+				if (get1bit(mp))
+					val -= a;
+			}
+
+			for (i = 0; i < 4; i++) {
+				if (!(i & 1)) {
+					if (!mc) {
+						mc = *m++;
+						cb = *m++;
+						v = gr_info->pow2gain[((*scf++) + (*pretab++)) << shift];
+					}
+					mc--;
+				}
+				if ((a & (0x8 >> i))) {
+					max = cb;
+					part2remain--;
+					if (part2remain < 0) {
+						part2remain++;
+						break;
+					}
+					if (get1bit(mp))
+						*xrpnt++ = -v;
+					else
+						*xrpnt++ = v;
+				} else
+					*xrpnt++ = 0.0;
+			}
+		}
+
+		/* 
+		 * zero part
+		 */
+		for (i = (&xr[SBLIMIT][0] - xrpnt) >> 1; i; i--) {
+			*xrpnt++ = 0.0;
+			*xrpnt++ = 0.0;
+		}
+
+		gr_info->maxbandl = max + 1;
+		gr_info->maxb = (mp->longLimit)[sfreq][gr_info->maxbandl];
+	}
+
+	while (part2remain > 16) {
+		getbits(mp, 16);		/* Dismiss stuffing Bits */
+		part2remain -= 16;
+	}
+	if (part2remain > 0)
+		getbits(mp, part2remain);
+	else if (part2remain < 0) {
+		debug_printf("mpg123: %d Can't rewind stream by %d bits!\n", -part2remain, __LINE__);
+		return 1;				/* -> error */
+	}
+	return 0;
 }
 
 #if 0
-static int III_dequantize_sample_ms(real xr[2][SBLIMIT][SSLIMIT],int *scf,
-   struct gr_info_s *gr_info,int sfreq,int part2bits)
+static int III_dequantize_sample_ms(real xr[2][SBLIMIT][SSLIMIT], int *scf, struct gr_info_s *gr_info, int sfreq, int part2bits)
 {
-  int shift = 1 + gr_info->scalefac_scale;
-  real *xrpnt = (real *) xr[1];
-  real *xr0pnt = (real *) xr[0];
-  int l[3],l3;
-  int part2remain = gr_info->part2_3_length - part2bits;
-  int *me;
-
-  {
-    int bv       = gr_info->big_values;
-    int region1  = gr_info->region1start;
-    int region2  = gr_info->region2start;
+	int shift = 1 + gr_info->scalefac_scale;
+	real *xrpnt = (real *) xr[1];
+	real *xr0pnt = (real *) xr[0];
+	int l[3], l3;
+	int part2remain = gr_info->part2_3_length - part2bits;
+	int *me;
 
-    l3 = ((576>>1)-bv)>>1;   
+	{
+		int bv = gr_info->big_values;
+		int region1 = gr_info->region1start;
+		int region2 = gr_info->region2start;
+
+		l3 = ((576 >> 1) - bv) >> 1;
 /*
  * we may lose the 'odd' bit here !! 
  * check this later gain 
  */
-    if(bv <= region1) {
-      l[0] = bv; l[1] = 0; l[2] = 0;
-    }
-    else {
-      l[0] = region1;
-      if(bv <= region2) {
-        l[1] = bv - l[0];  l[2] = 0;
-      }
-      else {
-        l[1] = region2 - l[0]; l[2] = bv - region2;
-      }
-    }
-  }
- 
-  if(gr_info->block_type == 2) {
-    int i,max[4];
-    int step=0,lwin=0,cb=0;
-    register real v = 0.0;
-    register int *m,mc = 0;
-
-    if(gr_info->mixed_block_flag) {
-      max[3] = -1;
-      max[0] = max[1] = max[2] = 2;
-      m = map[sfreq][0];
-      me = mapend[sfreq][0];
-    }
-    else {
-      max[0] = max[1] = max[2] = max[3] = -1;
-      /* max[3] not really needed in this case */
-      m = map[sfreq][1];
-      me = mapend[sfreq][1];
-    }
-
-    for(i=0;i<2;i++) {
-      int lp = l[i];
-      struct newhuff *h = ht+gr_info->table_select[i];
-      for(;lp;lp--,mc--) {
-        int x,y;
-
-        if(!mc) {
-          mc = *m++;
-          xrpnt = ((real *) xr[1]) + *m;
-          xr0pnt = ((real *) xr[0]) + *m++;
-          lwin = *m++;
-          cb = *m++;
-          if(lwin == 3) {
-            v = gr_info->pow2gain[(*scf++) << shift];
-            step = 1;
-          }
-          else {
-            v = gr_info->full_gain[lwin][(*scf++) << shift];
-            step = 3;
-          }
-        }
-        {
-          register short *val = h->table;
-          while((y=*val++)<0) {
-            if (get1bit(mp))
-              val -= y;
-            part2remain--;
-          }
-          x = y >> 4;
-          y &= 0xf;
-        }
-        if(x == 15) {
-          max[lwin] = cb;
-          part2remain -= h->linbits+1;
-          x += getbits(mp, h->linbits);
-          if(get1bit(mp)) {
-            real a = ispow[x] * v;
-            *xrpnt = *xr0pnt + a;
-            *xr0pnt -= a;
-          }
-          else {
-            real a = ispow[x] * v;
-            *xrpnt = *xr0pnt - a;
-            *xr0pnt += a;
-          }
-        }
-        else if(x) {
-          max[lwin] = cb;
-          if(get1bit(mp)) {
-            real a = ispow[x] * v;
-            *xrpnt = *xr0pnt + a;
-            *xr0pnt -= a;
-          }
-          else {
-            real a = ispow[x] * v;
-            *xrpnt = *xr0pnt - a;
-            *xr0pnt += a;
-          }
-          part2remain--;
-        }
-        else
-          *xrpnt = *xr0pnt;
-        xrpnt += step;
-        xr0pnt += step;
-
-        if(y == 15) {
-          max[lwin] = cb;
-          part2remain -= h->linbits+1;
-          y += getbits(mp, h->linbits);
-          if(get1bit(mp)) {
-            real a = ispow[y] * v;
-            *xrpnt = *xr0pnt + a;
-            *xr0pnt -= a;
-          }
-          else {
-            real a = ispow[y] * v;
-            *xrpnt = *xr0pnt - a;
-            *xr0pnt += a;
-          }
-        }
-        else if(y) {
-          max[lwin] = cb;
-          if(get1bit(mp)) {
-            real a = ispow[y] * v;
-            *xrpnt = *xr0pnt + a;
-            *xr0pnt -= a;
-          }
-          else {
-            real a = ispow[y] * v;
-            *xrpnt = *xr0pnt - a;
-            *xr0pnt += a;
-          }
-          part2remain--;
-        }
-        else
-          *xrpnt = *xr0pnt;
-        xrpnt += step;
-        xr0pnt += step;
-      }
-    }
-
-    for(;l3 && (part2remain > 0);l3--) {
-      struct newhuff *h = htc+gr_info->count1table_select;
-      register short *val = h->table,a;
-
-      while((a=*val++)<0) {
-        part2remain--;
-        if(part2remain < 0) {
-          part2remain++;
-          a = 0;
-          break;
-        }
-        if (get1bit(mp))
-          val -= a;
-      }
-
-      for(i=0;i<4;i++) {
-        if(!(i & 1)) {
-          if(!mc) {
-            mc = *m++;
-            xrpnt = ((real *) xr[1]) + *m;
-            xr0pnt = ((real *) xr[0]) + *m++;
-            lwin = *m++;
-            cb = *m++;
-            if(lwin == 3) {
-              v = gr_info->pow2gain[(*scf++) << shift];
-              step = 1;
-            }
-            else {
-              v = gr_info->full_gain[lwin][(*scf++) << shift];
-              step = 3;
-            }
-          }
-          mc--;
-        }
-        if( (a & (0x8>>i)) ) {
-          max[lwin] = cb;
-          part2remain--;
-          if(part2remain < 0) {
-            part2remain++;
-            break;
-          }
-          if(get1bit(mp)) {
-            *xrpnt = *xr0pnt + v;
-            *xr0pnt -= v;
-          }
-          else {
-            *xrpnt = *xr0pnt - v;
-            *xr0pnt += v;
-          }
-        }
-        else
-          *xrpnt = *xr0pnt;
-        xrpnt += step;
-        xr0pnt += step;
-      }
-    }
- 
-    while( m < me ) {
-      if(!mc) {
-        mc = *m++;
-        xrpnt = ((real *) xr[1]) + *m;
-        xr0pnt = ((real *) xr[0]) + *m++;
-        if(*m++ == 3)
-          step = 1;
-        else
-          step = 3;
-        m++; /* cb */
-      }
-      mc--;
-      *xrpnt = *xr0pnt;
-      xrpnt += step;
-      xr0pnt += step;
-      *xrpnt = *xr0pnt;
-      xrpnt += step;
-      xr0pnt += step;
+		if (bv <= region1) {
+			l[0] = bv;
+			l[1] = 0;
+			l[2] = 0;
+		} else {
+			l[0] = region1;
+			if (bv <= region2) {
+				l[1] = bv - l[0];
+				l[2] = 0;
+			} else {
+				l[1] = region2 - l[0];
+				l[2] = bv - region2;
+			}
+		}
+	}
+
+	if (gr_info->block_type == 2) {
+		int i, max[4];
+		int step = 0, lwin = 0, cb = 0;
+		register real v = 0.0;
+		register int *m, mc = 0;
+
+		if (gr_info->mixed_block_flag) {
+			max[3] = -1;
+			max[0] = max[1] = max[2] = 2;
+			m = map[sfreq][0];
+			me = mapend[sfreq][0];
+		} else {
+			max[0] = max[1] = max[2] = max[3] = -1;
+			/* max[3] not really needed in this case */
+			m = map[sfreq][1];
+			me = mapend[sfreq][1];
+		}
+
+		for (i = 0; i < 2; i++) {
+			int lp = l[i];
+			struct newhuff *h = ht + gr_info->table_select[i];
+			for (; lp; lp--, mc--) {
+				int x, y;
+
+				if (!mc) {
+					mc = *m++;
+					xrpnt = ((real *) xr[1]) + *m;
+					xr0pnt = ((real *) xr[0]) + *m++;
+					lwin = *m++;
+					cb = *m++;
+					if (lwin == 3) {
+						v = gr_info->pow2gain[(*scf++) << shift];
+						step = 1;
+					} else {
+						v = gr_info->full_gain[lwin][(*scf++) << shift];
+						step = 3;
+					}
+				}
+				{
+					register short *val = h->table;
+					while ((y = *val++) < 0) {
+						if (get1bit(mp))
+							val -= y;
+						part2remain--;
+					}
+					x = y >> 4;
+					y &= 0xf;
+				}
+				if (x == 15) {
+					max[lwin] = cb;
+					part2remain -= h->linbits + 1;
+					x += getbits(mp, h->linbits);
+					if (get1bit(mp)) {
+						real a = ispow[x] * v;
+						*xrpnt = *xr0pnt + a;
+						*xr0pnt -= a;
+					} else {
+						real a = ispow[x] * v;
+						*xrpnt = *xr0pnt - a;
+						*xr0pnt += a;
+					}
+				} else if (x) {
+					max[lwin] = cb;
+					if (get1bit(mp)) {
+						real a = ispow[x] * v;
+						*xrpnt = *xr0pnt + a;
+						*xr0pnt -= a;
+					} else {
+						real a = ispow[x] * v;
+						*xrpnt = *xr0pnt - a;
+						*xr0pnt += a;
+					}
+					part2remain--;
+				} else
+					*xrpnt = *xr0pnt;
+				xrpnt += step;
+				xr0pnt += step;
+
+				if (y == 15) {
+					max[lwin] = cb;
+					part2remain -= h->linbits + 1;
+					y += getbits(mp, h->linbits);
+					if (get1bit(mp)) {
+						real a = ispow[y] * v;
+						*xrpnt = *xr0pnt + a;
+						*xr0pnt -= a;
+					} else {
+						real a = ispow[y] * v;
+						*xrpnt = *xr0pnt - a;
+						*xr0pnt += a;
+					}
+				} else if (y) {
+					max[lwin] = cb;
+					if (get1bit(mp)) {
+						real a = ispow[y] * v;
+						*xrpnt = *xr0pnt + a;
+						*xr0pnt -= a;
+					} else {
+						real a = ispow[y] * v;
+						*xrpnt = *xr0pnt - a;
+						*xr0pnt += a;
+					}
+					part2remain--;
+				} else
+					*xrpnt = *xr0pnt;
+				xrpnt += step;
+				xr0pnt += step;
+			}
+		}
+
+		for (; l3 && (part2remain > 0); l3--) {
+			struct newhuff *h = htc + gr_info->count1table_select;
+			register short *val = h->table, a;
+
+			while ((a = *val++) < 0) {
+				part2remain--;
+				if (part2remain < 0) {
+					part2remain++;
+					a = 0;
+					break;
+				}
+				if (get1bit(mp))
+					val -= a;
+			}
+
+			for (i = 0; i < 4; i++) {
+				if (!(i & 1)) {
+					if (!mc) {
+						mc = *m++;
+						xrpnt = ((real *) xr[1]) + *m;
+						xr0pnt = ((real *) xr[0]) + *m++;
+						lwin = *m++;
+						cb = *m++;
+						if (lwin == 3) {
+							v = gr_info->pow2gain[(*scf++) << shift];
+							step = 1;
+						} else {
+							v = gr_info->full_gain[lwin][(*scf++) << shift];
+							step = 3;
+						}
+					}
+					mc--;
+				}
+				if ((a & (0x8 >> i))) {
+					max[lwin] = cb;
+					part2remain--;
+					if (part2remain < 0) {
+						part2remain++;
+						break;
+					}
+					if (get1bit(mp)) {
+						*xrpnt = *xr0pnt + v;
+						*xr0pnt -= v;
+					} else {
+						*xrpnt = *xr0pnt - v;
+						*xr0pnt += v;
+					}
+				} else
+					*xrpnt = *xr0pnt;
+				xrpnt += step;
+				xr0pnt += step;
+			}
+		}
+
+		while (m < me) {
+			if (!mc) {
+				mc = *m++;
+				xrpnt = ((real *) xr[1]) + *m;
+				xr0pnt = ((real *) xr[0]) + *m++;
+				if (*m++ == 3)
+					step = 1;
+				else
+					step = 3;
+				m++;			/* cb */
+			}
+			mc--;
+			*xrpnt = *xr0pnt;
+			xrpnt += step;
+			xr0pnt += step;
+			*xrpnt = *xr0pnt;
+			xrpnt += step;
+			xr0pnt += step;
 /* we could add a little opt. here:
  * if we finished a band for window 3 or a long band
  * further bands could copied in a simple loop without a
  * special 'map' decoding
  */
-    }
+		}
 
-    gr_info->maxband[0] = max[0]+1;
-    gr_info->maxband[1] = max[1]+1;
-    gr_info->maxband[2] = max[2]+1;
-    gr_info->maxbandl = max[3]+1;
-
-    {
-      int rmax = max[0] > max[1] ? max[0] : max[1];
-      rmax = (rmax > max[2] ? rmax : max[2]) + 1;
-      gr_info->maxb = rmax ? (mp->shortLimit)[sfreq][rmax] : (mp->longLimit)[sfreq][max[3]+1];
-    }
-  }
-  else {
-    int *pretab = gr_info->preflag ? pretab1 : pretab2;
-    int i,max = -1;
-    int cb = 0;
-    register int mc=0,*m = map[sfreq][2];
-    register real v = 0.0;
+		gr_info->maxband[0] = max[0] + 1;
+		gr_info->maxband[1] = max[1] + 1;
+		gr_info->maxband[2] = max[2] + 1;
+		gr_info->maxbandl = max[3] + 1;
+
+		{
+			int rmax = max[0] > max[1] ? max[0] : max[1];
+			rmax = (rmax > max[2] ? rmax : max[2]) + 1;
+			gr_info->maxb = rmax ? (mp->shortLimit)[sfreq][rmax] : (mp->longLimit)[sfreq][max[3] + 1];
+		}
+	} else {
+		int *pretab = gr_info->preflag ? pretab1 : pretab2;
+		int i, max = -1;
+		int cb = 0;
+		register int mc = 0, *m = map[sfreq][2];
+		register real v = 0.0;
 #if 0
-    me = mapend[sfreq][2];
+		me = mapend[sfreq][2];
 #endif
 
-    for(i=0;i<3;i++) {
-      int lp = l[i];
-      struct newhuff *h = ht+gr_info->table_select[i];
-
-      for(;lp;lp--,mc--) {
-        int x,y;
-        if(!mc) {
-          mc = *m++;
-          cb = *m++;
-          v = gr_info->pow2gain[((*scf++) + (*pretab++)) << shift];
-        }
-        {
-          register short *val = h->table;
-          while((y=*val++)<0) {
-            if (get1bit(mp))
-              val -= y;
-            part2remain--;
-          }
-          x = y >> 4;
-          y &= 0xf;
-        }
-        if (x == 15) {
-          max = cb;
-          part2remain -= h->linbits+1;
-          x += getbits(mp, h->linbits);
-          if(get1bit(mp)) {
-            real a = ispow[x] * v;
-            *xrpnt++ = *xr0pnt + a;
-            *xr0pnt++ -= a;
-          }
-          else {
-            real a = ispow[x] * v;
-            *xrpnt++ = *xr0pnt - a;
-            *xr0pnt++ += a;
-          }
-        }
-        else if(x) {
-          max = cb;
-          if(get1bit(mp)) {
-            real a = ispow[x] * v;
-            *xrpnt++ = *xr0pnt + a;
-            *xr0pnt++ -= a;
-          }
-          else {
-            real a = ispow[x] * v;
-            *xrpnt++ = *xr0pnt - a;
-            *xr0pnt++ += a;
-          }
-          part2remain--;
-        }
-        else
-          *xrpnt++ = *xr0pnt++;
-
-        if (y == 15) {
-          max = cb;
-          part2remain -= h->linbits+1;
-          y += getbits(mp, h->linbits);
-          if(get1bit(mp)) {
-            real a = ispow[y] * v;
-            *xrpnt++ = *xr0pnt + a;
-            *xr0pnt++ -= a;
-          }
-          else {
-            real a = ispow[y] * v;
-            *xrpnt++ = *xr0pnt - a;
-            *xr0pnt++ += a;
-          }
-        }
-        else if(y) {
-          max = cb;
-          if(get1bit(mp)) {
-            real a = ispow[y] * v;
-            *xrpnt++ = *xr0pnt + a;
-            *xr0pnt++ -= a;
-          }
-          else {
-            real a = ispow[y] * v;
-            *xrpnt++ = *xr0pnt - a;
-            *xr0pnt++ += a;
-          }
-          part2remain--;
-        }
-        else
-          *xrpnt++ = *xr0pnt++;
-      }
-    }
-
-    for(;l3 && (part2remain > 0);l3--) {
-      struct newhuff *h = htc+gr_info->count1table_select;
-      register short *val = h->table,a;
-
-      while((a=*val++)<0) {
-        part2remain--;
-        if(part2remain < 0) {
-          part2remain++;
-          a = 0;
-          break;
-        }
-        if (get1bit(mp))
-          val -= a;
-      }
-
-      for(i=0;i<4;i++) {
-        if(!(i & 1)) {
-          if(!mc) {
-            mc = *m++;
-            cb = *m++;
-            v = gr_info->pow2gain[((*scf++) + (*pretab++)) << shift];
-          }
-          mc--;
-        }
-        if ( (a & (0x8>>i)) ) {
-          max = cb;
-          part2remain--;
-          if(part2remain <= 0) {
-            part2remain++;
-            break;
-          }
-          if(get1bit(mp)) {
-            *xrpnt++ = *xr0pnt + v;
-            *xr0pnt++ -= v;
-          }
-          else {
-            *xrpnt++ = *xr0pnt - v;
-            *xr0pnt++ += v;
-          }
-        }
-        else
-          *xrpnt++ = *xr0pnt++;
-      }
-    }
-    for(i=(&xr[1][SBLIMIT][0]-xrpnt)>>1;i;i--) {
-      *xrpnt++ = *xr0pnt++;
-      *xrpnt++ = *xr0pnt++;
-    }
-
-    gr_info->maxbandl = max+1;
-    gr_info->maxb = longLimit[sfreq][gr_info->maxbandl];
-  }
-
-  while ( part2remain > 16 ) {
-    getbits(mp, 16); /* Dismiss stuffing Bits */
-    part2remain -= 16;
-  }
-  if(part2remain > 0 )
-    getbits(mp, part2remain);
-  else if(part2remain < 0) {
-	  debug_printf("mpg123_ms: %d: Can't rewind stream by %d bits!\n",-part2remain,  __LINE__);
-    return 1; /* -> error */
-  }
-  return 0;
+		for (i = 0; i < 3; i++) {
+			int lp = l[i];
+			struct newhuff *h = ht + gr_info->table_select[i];
+
+			for (; lp; lp--, mc--) {
+				int x, y;
+				if (!mc) {
+					mc = *m++;
+					cb = *m++;
+					v = gr_info->pow2gain[((*scf++) + (*pretab++)) << shift];
+				}
+				{
+					register short *val = h->table;
+					while ((y = *val++) < 0) {
+						if (get1bit(mp))
+							val -= y;
+						part2remain--;
+					}
+					x = y >> 4;
+					y &= 0xf;
+				}
+				if (x == 15) {
+					max = cb;
+					part2remain -= h->linbits + 1;
+					x += getbits(mp, h->linbits);
+					if (get1bit(mp)) {
+						real a = ispow[x] * v;
+						*xrpnt++ = *xr0pnt + a;
+						*xr0pnt++ -= a;
+					} else {
+						real a = ispow[x] * v;
+						*xrpnt++ = *xr0pnt - a;
+						*xr0pnt++ += a;
+					}
+				} else if (x) {
+					max = cb;
+					if (get1bit(mp)) {
+						real a = ispow[x] * v;
+						*xrpnt++ = *xr0pnt + a;
+						*xr0pnt++ -= a;
+					} else {
+						real a = ispow[x] * v;
+						*xrpnt++ = *xr0pnt - a;
+						*xr0pnt++ += a;
+					}
+					part2remain--;
+				} else
+					*xrpnt++ = *xr0pnt++;
+
+				if (y == 15) {
+					max = cb;
+					part2remain -= h->linbits + 1;
+					y += getbits(mp, h->linbits);
+					if (get1bit(mp)) {
+						real a = ispow[y] * v;
+						*xrpnt++ = *xr0pnt + a;
+						*xr0pnt++ -= a;
+					} else {
+						real a = ispow[y] * v;
+						*xrpnt++ = *xr0pnt - a;
+						*xr0pnt++ += a;
+					}
+				} else if (y) {
+					max = cb;
+					if (get1bit(mp)) {
+						real a = ispow[y] * v;
+						*xrpnt++ = *xr0pnt + a;
+						*xr0pnt++ -= a;
+					} else {
+						real a = ispow[y] * v;
+						*xrpnt++ = *xr0pnt - a;
+						*xr0pnt++ += a;
+					}
+					part2remain--;
+				} else
+					*xrpnt++ = *xr0pnt++;
+			}
+		}
+
+		for (; l3 && (part2remain > 0); l3--) {
+			struct newhuff *h = htc + gr_info->count1table_select;
+			register short *val = h->table, a;
+
+			while ((a = *val++) < 0) {
+				part2remain--;
+				if (part2remain < 0) {
+					part2remain++;
+					a = 0;
+					break;
+				}
+				if (get1bit(mp))
+					val -= a;
+			}
+
+			for (i = 0; i < 4; i++) {
+				if (!(i & 1)) {
+					if (!mc) {
+						mc = *m++;
+						cb = *m++;
+						v = gr_info->pow2gain[((*scf++) + (*pretab++)) << shift];
+					}
+					mc--;
+				}
+				if ((a & (0x8 >> i))) {
+					max = cb;
+					part2remain--;
+					if (part2remain <= 0) {
+						part2remain++;
+						break;
+					}
+					if (get1bit(mp)) {
+						*xrpnt++ = *xr0pnt + v;
+						*xr0pnt++ -= v;
+					} else {
+						*xrpnt++ = *xr0pnt - v;
+						*xr0pnt++ += v;
+					}
+				} else
+					*xrpnt++ = *xr0pnt++;
+			}
+		}
+		for (i = (&xr[1][SBLIMIT][0] - xrpnt) >> 1; i; i--) {
+			*xrpnt++ = *xr0pnt++;
+			*xrpnt++ = *xr0pnt++;
+		}
+
+		gr_info->maxbandl = max + 1;
+		gr_info->maxb = longLimit[sfreq][gr_info->maxbandl];
+	}
+
+	while (part2remain > 16) {
+		getbits(mp, 16);		/* Dismiss stuffing Bits */
+		part2remain -= 16;
+	}
+	if (part2remain > 0)
+		getbits(mp, part2remain);
+	else if (part2remain < 0) {
+		debug_printf("mpg123_ms: %d: Can't rewind stream by %d bits!\n", -part2remain, __LINE__);
+		return 1;				/* -> error */
+	}
+	return 0;
 }
 #endif
 
 /* 
  * III_stereo: calculate real channel values for Joint-I-Stereo-mode
  */
-static void III_i_stereo(real xr_buf[2][SBLIMIT][SSLIMIT],int *scalefac,
-   struct gr_info_s *gr_info,int sfreq,int ms_stereo,int lsf)
+static void III_i_stereo(real xr_buf[2][SBLIMIT][SSLIMIT], int *scalefac, struct gr_info_s *gr_info, int sfreq, int ms_stereo, int lsf)
 {
-      real (*xr)[SBLIMIT*SSLIMIT] = (real (*)[SBLIMIT*SSLIMIT] ) xr_buf;
-      struct bandInfoStruct *bi = &bandInfo[sfreq];
-      real *tab1,*tab2;
-
-      if(lsf) {
-        int p = gr_info->scalefac_compress & 0x1;
-	    if(ms_stereo) {
-          tab1 = pow1_2[p]; tab2 = pow2_2[p];
-        }
-        else {
-          tab1 = pow1_1[p]; tab2 = pow2_1[p];
-        }
-      }
-      else {
-        if(ms_stereo) {
-          tab1 = tan1_2; tab2 = tan2_2;
-        }
-        else {
-          tab1 = tan1_1; tab2 = tan2_1;
-        }
-      }
-
-      if (gr_info->block_type == 2)
-      {
-         int lwin,do_l = 0;
-         if( gr_info->mixed_block_flag )
-           do_l = 1;
-
-         for (lwin=0;lwin<3;lwin++) /* process each window */
-         {
-             /* get first band with zero values */
-           int is_p,sb,idx,sfb = gr_info->maxband[lwin];  /* sfb is minimal 3 for mixed mode */
-           if(sfb > 3)
-             do_l = 0;
-
-           for(;sfb<12;sfb++)
-           {
-             is_p = scalefac[sfb*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */ 
-             if(is_p != 7) {
-               real t1,t2;
-               sb = bi->shortDiff[sfb];
-               idx = bi->shortIdx[sfb] + lwin;
-               t1 = tab1[is_p]; t2 = tab2[is_p];
-               for (; sb > 0; sb--,idx+=3)
-               {
-                 real v = xr[0][idx];
-                 xr[0][idx] = v * t1;
-                 xr[1][idx] = v * t2;
-               }
-             }
-           }
+	real(*xr)[SBLIMIT * SSLIMIT] = (real(*)[SBLIMIT * SSLIMIT]) xr_buf;
+	struct bandInfoStruct *bi = &bandInfo[sfreq];
+	real *tab1, *tab2;
+
+	if (lsf) {
+		int p = gr_info->scalefac_compress & 0x1;
+		if (ms_stereo) {
+			tab1 = pow1_2[p];
+			tab2 = pow2_2[p];
+		} else {
+			tab1 = pow1_1[p];
+			tab2 = pow2_1[p];
+		}
+	} else {
+		if (ms_stereo) {
+			tab1 = tan1_2;
+			tab2 = tan2_2;
+		} else {
+			tab1 = tan1_1;
+			tab2 = tan2_1;
+		}
+	}
+
+	if (gr_info->block_type == 2) {
+		int lwin, do_l = 0;
+		if (gr_info->mixed_block_flag)
+			do_l = 1;
+
+		for (lwin = 0; lwin < 3; lwin++) {	/* process each window */
+			/* get first band with zero values */
+			int is_p, sb, idx, sfb = gr_info->maxband[lwin];	/* sfb is minimal 3 for mixed mode */
+			if (sfb > 3)
+				do_l = 0;
+
+			for (; sfb < 12; sfb++) {
+				is_p = scalefac[sfb * 3 + lwin - gr_info->mixed_block_flag];	/* scale: 0-15 */
+				if (is_p != 7) {
+					real t1, t2;
+					sb = bi->shortDiff[sfb];
+					idx = bi->shortIdx[sfb] + lwin;
+					t1 = tab1[is_p];
+					t2 = tab2[is_p];
+					for (; sb > 0; sb--, idx += 3) {
+						real v = xr[0][idx];
+						xr[0][idx] = v * t1;
+						xr[1][idx] = v * t2;
+					}
+				}
+			}
 
 #if 1
 /* in the original: copy 10 to 11 , here: copy 11 to 12 
 maybe still wrong??? (copy 12 to 13?) */
-           is_p = scalefac[11*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */
-           sb = bi->shortDiff[12];
-           idx = bi->shortIdx[12] + lwin;
+			is_p = scalefac[11 * 3 + lwin - gr_info->mixed_block_flag];	/* scale: 0-15 */
+			sb = bi->shortDiff[12];
+			idx = bi->shortIdx[12] + lwin;
 #else
-           is_p = scalefac[10*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */
-           sb = bi->shortDiff[11];
-           idx = bi->shortIdx[11] + lwin;
+			is_p = scalefac[10 * 3 + lwin - gr_info->mixed_block_flag];	/* scale: 0-15 */
+			sb = bi->shortDiff[11];
+			idx = bi->shortIdx[11] + lwin;
 #endif
-           if(is_p != 7)
-           {
-             real t1,t2;
-             t1 = tab1[is_p]; t2 = tab2[is_p];
-             for ( ; sb > 0; sb--,idx+=3 )
-             {  
-               real v = xr[0][idx];
-               xr[0][idx] = v * t1;
-               xr[1][idx] = v * t2;
-             }
-           }
-         } /* end for(lwin; .. ; . ) */
+			if (is_p != 7) {
+				real t1, t2;
+				t1 = tab1[is_p];
+				t2 = tab2[is_p];
+				for (; sb > 0; sb--, idx += 3) {
+					real v = xr[0][idx];
+					xr[0][idx] = v * t1;
+					xr[1][idx] = v * t2;
+				}
+			}
+		}						/* end for(lwin; .. ; . ) */
 
-         if (do_l)
-         {
+		if (do_l) {
 /* also check l-part, if ALL bands in the three windows are 'empty'
  * and mode = mixed_mode 
  */
-           int sfb = gr_info->maxbandl;
-           int idx = bi->longIdx[sfb];
+			int sfb = gr_info->maxbandl;
+			int idx = bi->longIdx[sfb];
 
-           for ( ; sfb<8; sfb++ )
-           {
-             int sb = bi->longDiff[sfb];
-             int is_p = scalefac[sfb]; /* scale: 0-15 */
-             if(is_p != 7) {
-               real t1,t2;
-               t1 = tab1[is_p]; t2 = tab2[is_p];
-               for ( ; sb > 0; sb--,idx++)
-               {
-                 real v = xr[0][idx];
-                 xr[0][idx] = v * t1;
-                 xr[1][idx] = v * t2;
-               }
-             }
-             else 
-               idx += sb;
-           }
-         }     
-      } 
-      else /* ((gr_info->block_type != 2)) */
-      {
-        int sfb = gr_info->maxbandl;
-        int is_p,idx = bi->longIdx[sfb];
-        for ( ; sfb<21; sfb++)
-        {
-          int sb = bi->longDiff[sfb];
-          is_p = scalefac[sfb]; /* scale: 0-15 */
-          if(is_p != 7) {
-            real t1,t2;
-            t1 = tab1[is_p]; t2 = tab2[is_p];
-            for ( ; sb > 0; sb--,idx++)
-            {
-               real v = xr[0][idx];
-               xr[0][idx] = v * t1;
-               xr[1][idx] = v * t2;
-            }
-          }
-          else
-            idx += sb;
-        }
-
-        is_p = scalefac[20]; /* copy l-band 20 to l-band 21 */
-        if(is_p != 7)
-        {
-          int sb;
-          real t1 = tab1[is_p],t2 = tab2[is_p]; 
-
-          for ( sb = bi->longDiff[21]; sb > 0; sb--,idx++ )
-          {
-            real v = xr[0][idx];
-            xr[0][idx] = v * t1;
-            xr[1][idx] = v * t2;
-          }
-        }
-      } /* ... */
+			for (; sfb < 8; sfb++) {
+				int sb = bi->longDiff[sfb];
+				int is_p = scalefac[sfb];	/* scale: 0-15 */
+				if (is_p != 7) {
+					real t1, t2;
+					t1 = tab1[is_p];
+					t2 = tab2[is_p];
+					for (; sb > 0; sb--, idx++) {
+						real v = xr[0][idx];
+						xr[0][idx] = v * t1;
+						xr[1][idx] = v * t2;
+					}
+				} else
+					idx += sb;
+			}
+		}
+	} else {					/* ((gr_info->block_type != 2)) */
+
+		int sfb = gr_info->maxbandl;
+		int is_p, idx = bi->longIdx[sfb];
+		for (; sfb < 21; sfb++) {
+			int sb = bi->longDiff[sfb];
+			is_p = scalefac[sfb];	/* scale: 0-15 */
+			if (is_p != 7) {
+				real t1, t2;
+				t1 = tab1[is_p];
+				t2 = tab2[is_p];
+				for (; sb > 0; sb--, idx++) {
+					real v = xr[0][idx];
+					xr[0][idx] = v * t1;
+					xr[1][idx] = v * t2;
+				}
+			} else
+				idx += sb;
+		}
+
+		is_p = scalefac[20];	/* copy l-band 20 to l-band 21 */
+		if (is_p != 7) {
+			int sb;
+			real t1 = tab1[is_p], t2 = tab2[is_p];
+
+			for (sb = bi->longDiff[21]; sb > 0; sb--, idx++) {
+				real v = xr[0][idx];
+				xr[0][idx] = v * t1;
+				xr[1][idx] = v * t2;
+			}
+		}
+	}							/* ... */
 }
 
-static void III_antialias(real xr[SBLIMIT][SSLIMIT],struct gr_info_s *gr_info)
+static void III_antialias(real xr[SBLIMIT][SSLIMIT], struct gr_info_s *gr_info)
 {
-   int sblim;
+	int sblim;
+
+	if (gr_info->block_type == 2) {
+		if (!gr_info->mixed_block_flag)
+			return;
+		sblim = 1;
+	} else {
+		sblim = gr_info->maxb - 1;
+	}
+
+	/* 31 alias-reduction operations between each pair of sub-bands */
+	/* with 8 butterflies between each pair                         */
+
+	{
+		int sb;
+		real *xr1 = (real *) xr[1];
 
-   if(gr_info->block_type == 2)
-   {
-      if(!gr_info->mixed_block_flag) 
-        return;
-      sblim = 1; 
-   }
-   else {
-     sblim = gr_info->maxb-1;
-   }
-
-   /* 31 alias-reduction operations between each pair of sub-bands */
-   /* with 8 butterflies between each pair                         */
-
-   {
-     int sb;
-     real *xr1=(real *) xr[1];
-
-     for(sb=sblim;sb;sb--,xr1+=10)
-     {
-       int ss;
-       real *cs=aa_cs,*ca=aa_ca;
-       real *xr2 = xr1;
-
-       for(ss=7;ss>=0;ss--)
-       {       /* upper and lower butterfly inputs */
-         register real bu = *--xr2,bd = *xr1;
-         *xr2   = (bu * (*cs)   ) - (bd * (*ca)   );
-         *xr1++ = (bd * (*cs++) ) + (bu * (*ca++) );
-       }
-     }
-  }
+		for (sb = sblim; sb; sb--, xr1 += 10) {
+			int ss;
+			real *cs = aa_cs, *ca = aa_ca;
+			real *xr2 = xr1;
+
+			for (ss = 7; ss >= 0; ss--) {	/* upper and lower butterfly inputs */
+				register real bu = *--xr2, bd = *xr1;
+				*xr2 = (bu * (*cs)) - (bd * (*ca));
+				*xr1++ = (bd * (*cs++)) + (bu * (*ca++));
+			}
+		}
+	}
 }
 
 /*
@@ -1575,23 +1513,40 @@
      Pages 175-199
 */
 
-static void dct36(real *inbuf,real *o1,real *o2,real *wintab,real *tsbuf)
+static void dct36(real * inbuf, real * o1, real * o2, real * wintab, real * tsbuf)
 {
-  {
-    register real *in = inbuf;
-
-    in[17]+=in[16]; in[16]+=in[15]; in[15]+=in[14];
-    in[14]+=in[13]; in[13]+=in[12]; in[12]+=in[11];
-    in[11]+=in[10]; in[10]+=in[9];  in[9] +=in[8];
-    in[8] +=in[7];  in[7] +=in[6];  in[6] +=in[5];
-    in[5] +=in[4];  in[4] +=in[3];  in[3] +=in[2];
-    in[2] +=in[1];  in[1] +=in[0];
+	{
+		register real *in = inbuf;
 
-    in[17]+=in[15]; in[15]+=in[13]; in[13]+=in[11]; in[11]+=in[9];
-    in[9] +=in[7];  in[7] +=in[5];  in[5] +=in[3];  in[3] +=in[1];
+		in[17] += in[16];
+		in[16] += in[15];
+		in[15] += in[14];
+		in[14] += in[13];
+		in[13] += in[12];
+		in[12] += in[11];
+		in[11] += in[10];
+		in[10] += in[9];
+		in[9] += in[8];
+		in[8] += in[7];
+		in[7] += in[6];
+		in[6] += in[5];
+		in[5] += in[4];
+		in[4] += in[3];
+		in[3] += in[2];
+		in[2] += in[1];
+		in[1] += in[0];
+
+		in[17] += in[15];
+		in[15] += in[13];
+		in[13] += in[11];
+		in[11] += in[9];
+		in[9] += in[7];
+		in[7] += in[5];
+		in[5] += in[3];
+		in[3] += in[1];
 
 
-  {
+		{
 
 #define MACRO0(v) { \
     real tmp; \
@@ -1599,7 +1554,7 @@
     out2[8-(v)] = tmp * w[26-(v)];  } \
     sum0 -= sum1; \
     ts[SBLIMIT*(8-(v))] = out1[8-(v)] + sum0 * w[8-(v)]; \
-    ts[SBLIMIT*(9+(v))] = out1[9+(v)] + sum0 * w[9+(v)]; 
+    ts[SBLIMIT*(9+(v))] = out1[9+(v)] + sum0 * w[9+(v)];
 #define MACRO1(v) { \
 	real sum0,sum1; \
     sum0 = tmp1a + tmp2a; \
@@ -1611,78 +1566,78 @@
     sum1 = (tmp2b - tmp1b) * tfcos36[(v)]; \
 	MACRO0(v); }
 
-    register const real *c = COS9;
-    register real *out2 = o2;
-	register real *w = wintab;
-	register real *out1 = o1;
-	register real *ts = tsbuf;
-
-    real ta33,ta66,tb33,tb66;
-
-    ta33 = in[2*3+0] * c[3];
-    ta66 = in[2*6+0] * c[6];
-    tb33 = in[2*3+1] * c[3];
-    tb66 = in[2*6+1] * c[6];
-
-    { 
-      real tmp1a,tmp2a,tmp1b,tmp2b;
-      tmp1a =             in[2*1+0] * c[1] + ta33 + in[2*5+0] * c[5] + in[2*7+0] * c[7];
-      tmp1b =             in[2*1+1] * c[1] + tb33 + in[2*5+1] * c[5] + in[2*7+1] * c[7];
-      tmp2a = in[2*0+0] + in[2*2+0] * c[2] + in[2*4+0] * c[4] + ta66 + in[2*8+0] * c[8];
-      tmp2b = in[2*0+1] + in[2*2+1] * c[2] + in[2*4+1] * c[4] + tb66 + in[2*8+1] * c[8];
-
-      MACRO1(0);
-      MACRO2(8);
-    }
-
-    {
-      real tmp1a,tmp2a,tmp1b,tmp2b;
-      tmp1a = ( in[2*1+0] - in[2*5+0] - in[2*7+0] ) * c[3];
-      tmp1b = ( in[2*1+1] - in[2*5+1] - in[2*7+1] ) * c[3];
-      tmp2a = ( in[2*2+0] - in[2*4+0] - in[2*8+0] ) * c[6] - in[2*6+0] + in[2*0+0];
-      tmp2b = ( in[2*2+1] - in[2*4+1] - in[2*8+1] ) * c[6] - in[2*6+1] + in[2*0+1];
-
-      MACRO1(1);
-      MACRO2(7);
-    }
-
-    {
-      real tmp1a,tmp2a,tmp1b,tmp2b;
-      tmp1a =             in[2*1+0] * c[5] - ta33 - in[2*5+0] * c[7] + in[2*7+0] * c[1];
-      tmp1b =             in[2*1+1] * c[5] - tb33 - in[2*5+1] * c[7] + in[2*7+1] * c[1];
-      tmp2a = in[2*0+0] - in[2*2+0] * c[8] - in[2*4+0] * c[2] + ta66 + in[2*8+0] * c[4];
-      tmp2b = in[2*0+1] - in[2*2+1] * c[8] - in[2*4+1] * c[2] + tb66 + in[2*8+1] * c[4];
-
-      MACRO1(2);
-      MACRO2(6);
-    }
-
-    {
-      real tmp1a,tmp2a,tmp1b,tmp2b;
-      tmp1a =             in[2*1+0] * c[7] - ta33 + in[2*5+0] * c[1] - in[2*7+0] * c[5];
-      tmp1b =             in[2*1+1] * c[7] - tb33 + in[2*5+1] * c[1] - in[2*7+1] * c[5];
-      tmp2a = in[2*0+0] - in[2*2+0] * c[4] + in[2*4+0] * c[8] + ta66 - in[2*8+0] * c[2];
-      tmp2b = in[2*0+1] - in[2*2+1] * c[4] + in[2*4+1] * c[8] + tb66 - in[2*8+1] * c[2];
-
-      MACRO1(3);
-      MACRO2(5);
-    }
+			register const real *c = COS9;
+			register real *out2 = o2;
+			register real *w = wintab;
+			register real *out1 = o1;
+			register real *ts = tsbuf;
+
+			real ta33, ta66, tb33, tb66;
+
+			ta33 = in[2 * 3 + 0] * c[3];
+			ta66 = in[2 * 6 + 0] * c[6];
+			tb33 = in[2 * 3 + 1] * c[3];
+			tb66 = in[2 * 6 + 1] * c[6];
+
+			{
+				real tmp1a, tmp2a, tmp1b, tmp2b;
+				tmp1a = in[2 * 1 + 0] * c[1] + ta33 + in[2 * 5 + 0] * c[5] + in[2 * 7 + 0] * c[7];
+				tmp1b = in[2 * 1 + 1] * c[1] + tb33 + in[2 * 5 + 1] * c[5] + in[2 * 7 + 1] * c[7];
+				tmp2a = in[2 * 0 + 0] + in[2 * 2 + 0] * c[2] + in[2 * 4 + 0] * c[4] + ta66 + in[2 * 8 + 0] * c[8];
+				tmp2b = in[2 * 0 + 1] + in[2 * 2 + 1] * c[2] + in[2 * 4 + 1] * c[4] + tb66 + in[2 * 8 + 1] * c[8];
+
+				MACRO1(0);
+				MACRO2(8);
+			}
+
+			{
+				real tmp1a, tmp2a, tmp1b, tmp2b;
+				tmp1a = (in[2 * 1 + 0] - in[2 * 5 + 0] - in[2 * 7 + 0]) * c[3];
+				tmp1b = (in[2 * 1 + 1] - in[2 * 5 + 1] - in[2 * 7 + 1]) * c[3];
+				tmp2a = (in[2 * 2 + 0] - in[2 * 4 + 0] - in[2 * 8 + 0]) * c[6] - in[2 * 6 + 0] + in[2 * 0 + 0];
+				tmp2b = (in[2 * 2 + 1] - in[2 * 4 + 1] - in[2 * 8 + 1]) * c[6] - in[2 * 6 + 1] + in[2 * 0 + 1];
+
+				MACRO1(1);
+				MACRO2(7);
+			}
+
+			{
+				real tmp1a, tmp2a, tmp1b, tmp2b;
+				tmp1a = in[2 * 1 + 0] * c[5] - ta33 - in[2 * 5 + 0] * c[7] + in[2 * 7 + 0] * c[1];
+				tmp1b = in[2 * 1 + 1] * c[5] - tb33 - in[2 * 5 + 1] * c[7] + in[2 * 7 + 1] * c[1];
+				tmp2a = in[2 * 0 + 0] - in[2 * 2 + 0] * c[8] - in[2 * 4 + 0] * c[2] + ta66 + in[2 * 8 + 0] * c[4];
+				tmp2b = in[2 * 0 + 1] - in[2 * 2 + 1] * c[8] - in[2 * 4 + 1] * c[2] + tb66 + in[2 * 8 + 1] * c[4];
+
+				MACRO1(2);
+				MACRO2(6);
+			}
+
+			{
+				real tmp1a, tmp2a, tmp1b, tmp2b;
+				tmp1a = in[2 * 1 + 0] * c[7] - ta33 + in[2 * 5 + 0] * c[1] - in[2 * 7 + 0] * c[5];
+				tmp1b = in[2 * 1 + 1] * c[7] - tb33 + in[2 * 5 + 1] * c[1] - in[2 * 7 + 1] * c[5];
+				tmp2a = in[2 * 0 + 0] - in[2 * 2 + 0] * c[4] + in[2 * 4 + 0] * c[8] + ta66 - in[2 * 8 + 0] * c[2];
+				tmp2b = in[2 * 0 + 1] - in[2 * 2 + 1] * c[4] + in[2 * 4 + 1] * c[8] + tb66 - in[2 * 8 + 1] * c[2];
+
+				MACRO1(3);
+				MACRO2(5);
+			}
+
+			{
+				real sum0, sum1;
+				sum0 = in[2 * 0 + 0] - in[2 * 2 + 0] + in[2 * 4 + 0] - in[2 * 6 + 0] + in[2 * 8 + 0];
+				sum1 = (in[2 * 0 + 1] - in[2 * 2 + 1] + in[2 * 4 + 1] - in[2 * 6 + 1] + in[2 * 8 + 1]) * tfcos36[4];
+				MACRO0(4);
+			}
+		}
 
-	{
-		real sum0,sum1;
-    	sum0 =  in[2*0+0] - in[2*2+0] + in[2*4+0] - in[2*6+0] + in[2*8+0];
-    	sum1 = (in[2*0+1] - in[2*2+1] + in[2*4+1] - in[2*6+1] + in[2*8+1] ) * tfcos36[4];
-		MACRO0(4);
 	}
-  }
-
-  }
 }
 
 /*
  * new DCT12
  */
-static void dct12(real *in,real *rawout1,real *rawout2,register real *wi,register real *ts)
+static void dct12(real * in, real * rawout1, real * rawout2, register real * wi, register real * ts)
 {
 #define DCT12_PART1 \
              in5 = in[5*3];  \
@@ -1715,314 +1670,299 @@
      in0 -= in1;
 
 
-   {
-     real in0,in1,in2,in3,in4,in5;
-     register real *out1 = rawout1;
-     ts[SBLIMIT*0] = out1[0]; ts[SBLIMIT*1] = out1[1]; ts[SBLIMIT*2] = out1[2];
-     ts[SBLIMIT*3] = out1[3]; ts[SBLIMIT*4] = out1[4]; ts[SBLIMIT*5] = out1[5];
- 
-     DCT12_PART1
-
-     {
-       real tmp0,tmp1 = (in0 - in4);
-       {
-         real tmp2 = (in1 - in5) * tfcos12[1];
-         tmp0 = tmp1 + tmp2;
-         tmp1 -= tmp2;
-       }
-       ts[(17-1)*SBLIMIT] = out1[17-1] + tmp0 * wi[11-1];
-       ts[(12+1)*SBLIMIT] = out1[12+1] + tmp0 * wi[6+1];
-       ts[(6 +1)*SBLIMIT] = out1[6 +1] + tmp1 * wi[1];
-       ts[(11-1)*SBLIMIT] = out1[11-1] + tmp1 * wi[5-1];
-     }
-
-     DCT12_PART2
-
-     ts[(17-0)*SBLIMIT] = out1[17-0] + in2 * wi[11-0];
-     ts[(12+0)*SBLIMIT] = out1[12+0] + in2 * wi[6+0];
-     ts[(12+2)*SBLIMIT] = out1[12+2] + in3 * wi[6+2];
-     ts[(17-2)*SBLIMIT] = out1[17-2] + in3 * wi[11-2];
-
-     ts[(6+0)*SBLIMIT]  = out1[6+0] + in0 * wi[0];
-     ts[(11-0)*SBLIMIT] = out1[11-0] + in0 * wi[5-0];
-     ts[(6+2)*SBLIMIT]  = out1[6+2] + in4 * wi[2];
-     ts[(11-2)*SBLIMIT] = out1[11-2] + in4 * wi[5-2];
-  }
-
-  in++;
-
-  {
-     real in0,in1,in2,in3,in4,in5;
-     register real *out2 = rawout2;
- 
-     DCT12_PART1
-
-     {
-       real tmp0,tmp1 = (in0 - in4);
-       {
-         real tmp2 = (in1 - in5) * tfcos12[1];
-         tmp0 = tmp1 + tmp2;
-         tmp1 -= tmp2;
-       }
-       out2[5-1] = tmp0 * wi[11-1];
-       out2[0+1] = tmp0 * wi[6+1];
-       ts[(12+1)*SBLIMIT] += tmp1 * wi[1];
-       ts[(17-1)*SBLIMIT] += tmp1 * wi[5-1];
-     }
-
-     DCT12_PART2
-
-     out2[5-0] = in2 * wi[11-0];
-     out2[0+0] = in2 * wi[6+0];
-     out2[0+2] = in3 * wi[6+2];
-     out2[5-2] = in3 * wi[11-2];
-
-     ts[(12+0)*SBLIMIT] += in0 * wi[0];
-     ts[(17-0)*SBLIMIT] += in0 * wi[5-0];
-     ts[(12+2)*SBLIMIT] += in4 * wi[2];
-     ts[(17-2)*SBLIMIT] += in4 * wi[5-2];
-  }
-
-  in++; 
-
-  {
-     real in0,in1,in2,in3,in4,in5;
-     register real *out2 = rawout2;
-     out2[12]=out2[13]=out2[14]=out2[15]=out2[16]=out2[17]=0.0;
-
-     DCT12_PART1
-
-     {
-       real tmp0,tmp1 = (in0 - in4);
-       {
-         real tmp2 = (in1 - in5) * tfcos12[1];
-         tmp0 = tmp1 + tmp2;
-         tmp1 -= tmp2;
-       }
-       out2[11-1] = tmp0 * wi[11-1];
-       out2[6 +1] = tmp0 * wi[6+1];
-       out2[0+1] += tmp1 * wi[1];
-       out2[5-1] += tmp1 * wi[5-1];
-     }
-
-     DCT12_PART2
-
-     out2[11-0] = in2 * wi[11-0];
-     out2[6 +0] = in2 * wi[6+0];
-     out2[6 +2] = in3 * wi[6+2];
-     out2[11-2] = in3 * wi[11-2];
-
-     out2[0+0] += in0 * wi[0];
-     out2[5-0] += in0 * wi[5-0];
-     out2[0+2] += in4 * wi[2];
-     out2[5-2] += in4 * wi[5-2];
-  }
+	{
+		real in0, in1, in2, in3, in4, in5;
+		register real *out1 = rawout1;
+		ts[SBLIMIT * 0] = out1[0];
+		ts[SBLIMIT * 1] = out1[1];
+		ts[SBLIMIT * 2] = out1[2];
+		ts[SBLIMIT * 3] = out1[3];
+		ts[SBLIMIT * 4] = out1[4];
+		ts[SBLIMIT * 5] = out1[5];
+
+		DCT12_PART1 {
+			real tmp0, tmp1 = (in0 - in4);
+			{
+				real tmp2 = (in1 - in5) * tfcos12[1];
+				tmp0 = tmp1 + tmp2;
+				tmp1 -= tmp2;
+			}
+			ts[(17 - 1) * SBLIMIT] = out1[17 - 1] + tmp0 * wi[11 - 1];
+			ts[(12 + 1) * SBLIMIT] = out1[12 + 1] + tmp0 * wi[6 + 1];
+			ts[(6 + 1) * SBLIMIT] = out1[6 + 1] + tmp1 * wi[1];
+			ts[(11 - 1) * SBLIMIT] = out1[11 - 1] + tmp1 * wi[5 - 1];
+		}
+
+		DCT12_PART2 ts[(17 - 0) * SBLIMIT] = out1[17 - 0] + in2 * wi[11 - 0];
+		ts[(12 + 0) * SBLIMIT] = out1[12 + 0] + in2 * wi[6 + 0];
+		ts[(12 + 2) * SBLIMIT] = out1[12 + 2] + in3 * wi[6 + 2];
+		ts[(17 - 2) * SBLIMIT] = out1[17 - 2] + in3 * wi[11 - 2];
+
+		ts[(6 + 0) * SBLIMIT] = out1[6 + 0] + in0 * wi[0];
+		ts[(11 - 0) * SBLIMIT] = out1[11 - 0] + in0 * wi[5 - 0];
+		ts[(6 + 2) * SBLIMIT] = out1[6 + 2] + in4 * wi[2];
+		ts[(11 - 2) * SBLIMIT] = out1[11 - 2] + in4 * wi[5 - 2];
+	}
+
+	in++;
+
+	{
+		real in0, in1, in2, in3, in4, in5;
+		register real *out2 = rawout2;
+
+		DCT12_PART1 {
+			real tmp0, tmp1 = (in0 - in4);
+			{
+				real tmp2 = (in1 - in5) * tfcos12[1];
+				tmp0 = tmp1 + tmp2;
+				tmp1 -= tmp2;
+			}
+			out2[5 - 1] = tmp0 * wi[11 - 1];
+			out2[0 + 1] = tmp0 * wi[6 + 1];
+			ts[(12 + 1) * SBLIMIT] += tmp1 * wi[1];
+			ts[(17 - 1) * SBLIMIT] += tmp1 * wi[5 - 1];
+		}
+
+		DCT12_PART2 out2[5 - 0] = in2 * wi[11 - 0];
+		out2[0 + 0] = in2 * wi[6 + 0];
+		out2[0 + 2] = in3 * wi[6 + 2];
+		out2[5 - 2] = in3 * wi[11 - 2];
+
+		ts[(12 + 0) * SBLIMIT] += in0 * wi[0];
+		ts[(17 - 0) * SBLIMIT] += in0 * wi[5 - 0];
+		ts[(12 + 2) * SBLIMIT] += in4 * wi[2];
+		ts[(17 - 2) * SBLIMIT] += in4 * wi[5 - 2];
+	}
+
+	in++;
+
+	{
+		real in0, in1, in2, in3, in4, in5;
+		register real *out2 = rawout2;
+		out2[12] = out2[13] = out2[14] = out2[15] = out2[16] = out2[17] = 0.0;
+
+		DCT12_PART1 {
+			real tmp0, tmp1 = (in0 - in4);
+			{
+				real tmp2 = (in1 - in5) * tfcos12[1];
+				tmp0 = tmp1 + tmp2;
+				tmp1 -= tmp2;
+			}
+			out2[11 - 1] = tmp0 * wi[11 - 1];
+			out2[6 + 1] = tmp0 * wi[6 + 1];
+			out2[0 + 1] += tmp1 * wi[1];
+			out2[5 - 1] += tmp1 * wi[5 - 1];
+		}
+
+		DCT12_PART2 out2[11 - 0] = in2 * wi[11 - 0];
+		out2[6 + 0] = in2 * wi[6 + 0];
+		out2[6 + 2] = in3 * wi[6 + 2];
+		out2[11 - 2] = in3 * wi[11 - 2];
+
+		out2[0 + 0] += in0 * wi[0];
+		out2[5 - 0] += in0 * wi[5 - 0];
+		out2[0 + 2] += in4 * wi[2];
+		out2[5 - 2] += in4 * wi[5 - 2];
+	}
 }
 
 /*
  * III_hybrid
  */
-static void III_hybrid(struct mpstr *mp, real fsIn[SBLIMIT][SSLIMIT],real tsOut[SSLIMIT][SBLIMIT],
-   int ch,struct gr_info_s *gr_info)
+static void III_hybrid(struct mpstr *mp, real fsIn[SBLIMIT][SSLIMIT], real tsOut[SSLIMIT][SBLIMIT], int ch, struct gr_info_s *gr_info)
 {
-   real *tspnt = (real *) tsOut;
-   real (*block)[2][SBLIMIT*SSLIMIT] = mp->hybrid_block;
-   int *blc = mp->hybrid_blc;
-   real *rawout1,*rawout2;
-   int bt;
-   int sb = 0;
-
-   {
-     int b = blc[ch];
-     rawout1=block[b][ch];
-     b=-b+1;
-     rawout2=block[b][ch];
-     blc[ch] = b;
-   }
-
-  
-   if(gr_info->mixed_block_flag) {
-     sb = 2;
-     dct36(fsIn[0],rawout1,rawout2,win[0],tspnt);
-     dct36(fsIn[1],rawout1+18,rawout2+18,win1[0],tspnt+1);
-     rawout1 += 36; rawout2 += 36; tspnt += 2;
-   }
- 
-   bt = gr_info->block_type;
-   if(bt == 2) {
-     for (; sb<gr_info->maxb; sb+=2,tspnt+=2,rawout1+=36,rawout2+=36) {
-       dct12(fsIn[sb],rawout1,rawout2,win[2],tspnt);
-       dct12(fsIn[sb+1],rawout1+18,rawout2+18,win1[2],tspnt+1);
-     }
-   }
-   else {
-     for (; sb<gr_info->maxb; sb+=2,tspnt+=2,rawout1+=36,rawout2+=36) {
-       dct36(fsIn[sb],rawout1,rawout2,win[bt],tspnt);
-       dct36(fsIn[sb+1],rawout1+18,rawout2+18,win1[bt],tspnt+1);
-     }
-   }
-
-   for(;sb<SBLIMIT;sb++,tspnt++) {
-     int i;
-     for(i=0;i<SSLIMIT;i++) {
-       tspnt[i*SBLIMIT] = *rawout1++;
-       *rawout2++ = 0.0;
-     }
-   }
+	real *tspnt = (real *) tsOut;
+	real(*block)[2][SBLIMIT * SSLIMIT] = mp->hybrid_block;
+	int *blc = mp->hybrid_blc;
+	real *rawout1, *rawout2;
+	int bt;
+	int sb = 0;
+
+	{
+		int b = blc[ch];
+		rawout1 = block[b][ch];
+		b = -b + 1;
+		rawout2 = block[b][ch];
+		blc[ch] = b;
+	}
+
+
+	if (gr_info->mixed_block_flag) {
+		sb = 2;
+		dct36(fsIn[0], rawout1, rawout2, win[0], tspnt);
+		dct36(fsIn[1], rawout1 + 18, rawout2 + 18, win1[0], tspnt + 1);
+		rawout1 += 36;
+		rawout2 += 36;
+		tspnt += 2;
+	}
+
+	bt = gr_info->block_type;
+	if (bt == 2) {
+		for (; sb < gr_info->maxb; sb += 2, tspnt += 2, rawout1 += 36, rawout2 += 36) {
+			dct12(fsIn[sb], rawout1, rawout2, win[2], tspnt);
+			dct12(fsIn[sb + 1], rawout1 + 18, rawout2 + 18, win1[2], tspnt + 1);
+		}
+	} else {
+		for (; sb < gr_info->maxb; sb += 2, tspnt += 2, rawout1 += 36, rawout2 += 36) {
+			dct36(fsIn[sb], rawout1, rawout2, win[bt], tspnt);
+			dct36(fsIn[sb + 1], rawout1 + 18, rawout2 + 18, win1[bt], tspnt + 1);
+		}
+	}
+
+	for (; sb < SBLIMIT; sb++, tspnt++) {
+		int i;
+		for (i = 0; i < SSLIMIT; i++) {
+			tspnt[i * SBLIMIT] = *rawout1++;
+			*rawout2++ = 0.0;
+		}
+	}
 }
 
 /*
  * main layer3 handler
  */
-int do_layer3(struct mpstr *mp,unsigned char *pcm_sample,int *pcm_point)
+int do_layer3(struct mpstr *mp, unsigned char *pcm_sample, int *pcm_point)
 {
 
-  int gr, ch, ss,clip=0;
-  int scalefacs[39]; /* max 39 for short[13][3] mode, mixed: 38, long: 22 */
-  struct III_sideinfo sideinfo;
-  struct frame *fr;
-  int stereo, single, sfreq;
-  int ms_stereo,i_stereo;
-  int stereo1,granules;
-
-  fr = &(mp->fr);
-  stereo = fr->stereo;
-  single = fr->single;
-  sfreq = fr->sampling_frequency;
-
-  
-  
-  if(stereo == 1) { /* stream is mono */
-    stereo1 = 1;
-    single = 0;
-  }
-  else if(single >= 0) /* stream is stereo, but force to mono */
-    stereo1 = 1;
-  else
-    stereo1 = 2;
-
-  if(fr->mode == MPG_MD_JOINT_STEREO) {
-    ms_stereo = fr->mode_ext & 0x2;
-    i_stereo  = fr->mode_ext & 0x1;
-  }
-  else
-    ms_stereo = i_stereo = 0;
-
-  if(fr->lsf) {
-    granules = 1;
-    if (III_get_side_info_2(mp, &sideinfo,stereo,ms_stereo,sfreq,single))
-	    return (MP3_ERR);
-  }
-  else {
-    granules = 2;
+	int gr, ch, ss, clip = 0;
+	int scalefacs[39];			/* max 39 for short[13][3] mode, mixed: 38, long: 22 */
+	struct III_sideinfo sideinfo;
+	struct frame *fr;
+	int stereo, single, sfreq;
+	int ms_stereo, i_stereo;
+	int stereo1, granules;
+
+	fr = &(mp->fr);
+	stereo = fr->stereo;
+	single = fr->single;
+	sfreq = fr->sampling_frequency;
+
+
+
+	if (stereo == 1) {			/* stream is mono */
+		stereo1 = 1;
+		single = 0;
+	} else if (single >= 0)		/* stream is stereo, but force to mono */
+		stereo1 = 1;
+	else
+		stereo1 = 2;
+
+	if (fr->mode == MPG_MD_JOINT_STEREO) {
+		ms_stereo = fr->mode_ext & 0x2;
+		i_stereo = fr->mode_ext & 0x1;
+	} else
+		ms_stereo = i_stereo = 0;
+
+	if (fr->lsf) {
+		granules = 1;
+		if (III_get_side_info_2(mp, &sideinfo, stereo, ms_stereo, sfreq, single))
+			return (MP3_ERR);
+	} else {
+		granules = 2;
 #ifdef MPEG1
-   if ( III_get_side_info_1(mp, &sideinfo,stereo,ms_stereo,sfreq,single))
-	   return (MP3_ERR);
-   
+		if (III_get_side_info_1(mp, &sideinfo, stereo, ms_stereo, sfreq, single))
+			return (MP3_ERR);
+
 #else
-   debug_printf("%d Not supported\n",  __LINE__);
+		debug_printf("%d Not supported\n", __LINE__);
 #endif
-  }
+	}
 
-  if(set_pointer(mp, sideinfo.main_data_begin) == MP3_ERR)
-    return 0;
+	if (set_pointer(mp, sideinfo.main_data_begin) == MP3_ERR)
+		return 0;
 
-  for (gr=0;gr<granules;gr++) 
-  {
-    static real hybridIn[2][SBLIMIT][SSLIMIT];
-    static real hybridOut[2][SSLIMIT][SBLIMIT];
-
-    {
-      struct gr_info_s *gr_info = &(sideinfo.ch[0].gr[gr]);
-      long part2bits;
-      if(fr->lsf)
-        part2bits = III_get_scale_factors_2(mp, scalefacs,gr_info,0);
-      else {
+	for (gr = 0; gr < granules; gr++) {
+		static real hybridIn[2][SBLIMIT][SSLIMIT];
+		static real hybridOut[2][SSLIMIT][SBLIMIT];
+
+		{
+			struct gr_info_s *gr_info = &(sideinfo.ch[0].gr[gr]);
+			long part2bits;
+			if (fr->lsf)
+				part2bits = III_get_scale_factors_2(mp, scalefacs, gr_info, 0);
+			else {
 #ifdef MPEG1
-        part2bits = III_get_scale_factors_1(mp, scalefacs,gr_info);
+				part2bits = III_get_scale_factors_1(mp, scalefacs, gr_info);
 #else
-		debug_printf("%d Not supported\n",  __LINE__);
+				debug_printf("%d Not supported\n", __LINE__);
 #endif
-      }
-      if(III_dequantize_sample(mp, hybridIn[0], scalefacs,gr_info,sfreq,part2bits))
-        return (MP3_ERR);
-    }
-    if(stereo == 2) {
-      struct gr_info_s *gr_info = &(sideinfo.ch[1].gr[gr]);
-      long part2bits;
-      if(fr->lsf) 
-        part2bits = III_get_scale_factors_2(mp, scalefacs,gr_info,i_stereo);
-      else {
+			}
+			if (III_dequantize_sample(mp, hybridIn[0], scalefacs, gr_info, sfreq, part2bits))
+				return (MP3_ERR);
+		}
+		if (stereo == 2) {
+			struct gr_info_s *gr_info = &(sideinfo.ch[1].gr[gr]);
+			long part2bits;
+			if (fr->lsf)
+				part2bits = III_get_scale_factors_2(mp, scalefacs, gr_info, i_stereo);
+			else {
 #ifdef MPEG1
-        part2bits = III_get_scale_factors_1(mp, scalefacs,gr_info);
+				part2bits = III_get_scale_factors_1(mp, scalefacs, gr_info);
 #else
-		debug_printf("%d Not supported\n",  __LINE__);
+				debug_printf("%d Not supported\n", __LINE__);
 #endif
-      }
+			}
 
-      if(III_dequantize_sample(mp, hybridIn[1],scalefacs,gr_info,sfreq,part2bits))
-          return (MP3_ERR);
+			if (III_dequantize_sample(mp, hybridIn[1], scalefacs, gr_info, sfreq, part2bits))
+				return (MP3_ERR);
 
-      if(ms_stereo) {
-        int i;
-        for(i=0;i<SBLIMIT*SSLIMIT;i++) {
-          real tmp0,tmp1;
-          tmp0 = ((real *) hybridIn[0])[i];
-          tmp1 = ((real *) hybridIn[1])[i];
-          ((real *) hybridIn[1])[i] = tmp0 - tmp1;  
-          ((real *) hybridIn[0])[i] = tmp0 + tmp1;
-        }
-      }
-
-      if(i_stereo)
-        III_i_stereo(hybridIn,scalefacs,gr_info,sfreq,ms_stereo,fr->lsf);
-
-      if(ms_stereo || i_stereo || (single == 3) ) {
-        if(gr_info->maxb > sideinfo.ch[0].gr[gr].maxb) 
-          sideinfo.ch[0].gr[gr].maxb = gr_info->maxb;
-        else
-          gr_info->maxb = sideinfo.ch[0].gr[gr].maxb;
-      }
-
-      switch(single) {
-        case 3:
-          {
-            register int i;
-            register real *in0 = (real *) hybridIn[0],*in1 = (real *) hybridIn[1];
-            for(i=0;i<SSLIMIT*gr_info->maxb;i++,in0++)
-              *in0 = (*in0 + *in1++); /* *0.5 done by pow-scale */ 
-          }
-          break;
-        case 1:
-          {
-            register int i;
-            register real *in0 = (real *) hybridIn[0],*in1 = (real *) hybridIn[1];
-            for(i=0;i<SSLIMIT*gr_info->maxb;i++)
-              *in0++ = *in1++;
-          }
-          break;
-      }
-    }
-
-    for(ch=0;ch<stereo1;ch++) {
-      struct gr_info_s *gr_info = &(sideinfo.ch[ch].gr[gr]);
-      III_antialias(hybridIn[ch],gr_info);
-      III_hybrid(mp, hybridIn[ch], hybridOut[ch], ch,gr_info);
-    }
-
-    for(ss=0;ss<SSLIMIT;ss++) {
-      if(single >= 0) {
-        clip += synth_ntom_mono(mp,hybridOut[0][ss],pcm_sample,pcm_point);
-      }
-      else {
-        int p1 = *pcm_point;
-        clip += synth_ntom(mp,hybridOut[0][ss],0,pcm_sample,&p1);
-        clip += synth_ntom(mp,hybridOut[1][ss],1,pcm_sample,pcm_point);
-      }
-    }
-  }
-  
-  return 0;
-}
+			if (ms_stereo) {
+				int i;
+				for (i = 0; i < SBLIMIT * SSLIMIT; i++) {
+					real tmp0, tmp1;
+					tmp0 = ((real *) hybridIn[0])[i];
+					tmp1 = ((real *) hybridIn[1])[i];
+					((real *) hybridIn[1])[i] = tmp0 - tmp1;
+					((real *) hybridIn[0])[i] = tmp0 + tmp1;
+				}
+			}
+
+			if (i_stereo)
+				III_i_stereo(hybridIn, scalefacs, gr_info, sfreq, ms_stereo, fr->lsf);
+
+			if (ms_stereo || i_stereo || (single == 3)) {
+				if (gr_info->maxb > sideinfo.ch[0].gr[gr].maxb)
+					sideinfo.ch[0].gr[gr].maxb = gr_info->maxb;
+				else
+					gr_info->maxb = sideinfo.ch[0].gr[gr].maxb;
+			}
+
+			switch (single) {
+			case 3:
+				{
+					register int i;
+					register real *in0 = (real *) hybridIn[0], *in1 = (real *) hybridIn[1];
+					for (i = 0; i < SSLIMIT * gr_info->maxb; i++, in0++)
+						*in0 = (*in0 + *in1++);	/* *0.5 done by pow-scale */
+				}
+				break;
+			case 1:
+				{
+					register int i;
+					register real *in0 = (real *) hybridIn[0], *in1 = (real *) hybridIn[1];
+					for (i = 0; i < SSLIMIT * gr_info->maxb; i++)
+						*in0++ = *in1++;
+				}
+				break;
+			}
+		}
 
+		for (ch = 0; ch < stereo1; ch++) {
+			struct gr_info_s *gr_info = &(sideinfo.ch[ch].gr[gr]);
+			III_antialias(hybridIn[ch], gr_info);
+			III_hybrid(mp, hybridIn[ch], hybridOut[ch], ch, gr_info);
+		}
 
+		for (ss = 0; ss < SSLIMIT; ss++) {
+			if (single >= 0) {
+				clip += synth_ntom_mono(mp, hybridOut[0][ss], pcm_sample, pcm_point);
+			} else {
+				int p1 = *pcm_point;
+				clip += synth_ntom(mp, hybridOut[0][ss], 0, pcm_sample, &p1);
+				clip += synth_ntom(mp, hybridOut[1][ss], 1, pcm_sample, pcm_point);
+			}
+		}
+	}
+
+	return 0;
+}

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/mod_shout.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/mod_shout.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/mod_shout.c	Fri Mar 30 12:19:18 2007
@@ -46,84 +46,84 @@
 
 
 
-static char *supported_formats[SWITCH_MAX_CODECS] = {0};
+static char *supported_formats[SWITCH_MAX_CODECS] = { 0 };
 
 struct shout_context {
 	shout_t *shout;
-    lame_global_flags *gfp;
-    char *stream_url;
+	lame_global_flags *gfp;
+	char *stream_url;
 	switch_mutex_t *audio_mutex;
 	switch_buffer_t *audio_buffer;
-    switch_memory_pool_t *memory_pool;
-    char decode_buf[MP3_DCACHE];
-    struct mpstr mp;
-    int err;
-    int mp3err;
-    int dlen;
-    switch_file_t *fd;
-    FILE *fp;
-    int samplerate;
-    uint8_t thread_running;
-    uint8_t shout_init;
+	switch_memory_pool_t *memory_pool;
+	char decode_buf[MP3_DCACHE];
+	struct mpstr mp;
+	int err;
+	int mp3err;
+	int dlen;
+	switch_file_t *fd;
+	FILE *fp;
+	int samplerate;
+	uint8_t thread_running;
+	uint8_t shout_init;
 };
 
 typedef struct shout_context shout_context_t;
 
 
-static size_t decode_fd(shout_context_t *context, void *data, size_t bytes);
+static size_t decode_fd(shout_context_t * context, void *data, size_t bytes);
 
-static inline void free_context(shout_context_t *context)
+static inline void free_context(shout_context_t * context)
 {
-    if (context) {
-        context->err++;
+	if (context) {
+		context->err++;
 
-        if (context->fd) {
-            switch_file_close(context->fd);
-            context->fd = NULL;
-        }
-
-        if (context->fp) {
-            unsigned char mp3buffer[1024];
-            int len;
-
-            while ((len = lame_encode_flush(context->gfp, mp3buffer, sizeof(mp3buffer))) > 0) {
-                fwrite(mp3buffer, 1, len, context->fp);
-            }
-            
-            lame_mp3_tags_fid(context->gfp, context->fp);
-            fclose(context->fp);
-            context->fp = NULL;
-        }
-
-        if (context->audio_buffer) {
-            switch_mutex_lock(context->audio_mutex);
-            switch_buffer_destroy(&context->audio_buffer);
-            switch_mutex_unlock(context->audio_mutex);
-        }
-
-        if (context->shout) {
-            shout_close(context->shout);
-            context->shout = NULL;
-        }
-
-        if (context->gfp) {
-            lame_close(context->gfp);
-            context->gfp = NULL;
-        }
-
-        if (context->stream_url) {
-            int sanity = 0;
-        
-            while(context->thread_running) {
-                switch_yield(500000);
-                if (++sanity > 10) {
-                    break;
-                }
-            }
-
-            ExitMP3(&context->mp);
-        }
-    }
+		if (context->fd) {
+			switch_file_close(context->fd);
+			context->fd = NULL;
+		}
+
+		if (context->fp) {
+			unsigned char mp3buffer[1024];
+			int len;
+
+			while ((len = lame_encode_flush(context->gfp, mp3buffer, sizeof(mp3buffer))) > 0) {
+				fwrite(mp3buffer, 1, len, context->fp);
+			}
+
+			lame_mp3_tags_fid(context->gfp, context->fp);
+			fclose(context->fp);
+			context->fp = NULL;
+		}
+
+		if (context->audio_buffer) {
+			switch_mutex_lock(context->audio_mutex);
+			switch_buffer_destroy(&context->audio_buffer);
+			switch_mutex_unlock(context->audio_mutex);
+		}
+
+		if (context->shout) {
+			shout_close(context->shout);
+			context->shout = NULL;
+		}
+
+		if (context->gfp) {
+			lame_close(context->gfp);
+			context->gfp = NULL;
+		}
+
+		if (context->stream_url) {
+			int sanity = 0;
+
+			while (context->thread_running) {
+				switch_yield(500000);
+				if (++sanity > 10) {
+					break;
+				}
+			}
+
+			ExitMP3(&context->mp);
+		}
+	}
 }
 
 
@@ -142,13 +142,13 @@
 		data = (char *) malloc(2048);
 		if (data) {
 			vsnprintf(data, 2048, fmt, ap);
-		} else { 
+		} else {
 			return;
 		}
 #endif
 	}
 	if (data) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, (char*) "%s", data);
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, (char *) "%s", data);
 		free(data);
 	}
 }
@@ -168,13 +168,13 @@
 		data = (char *) malloc(2048);
 		if (data) {
 			vsnprintf(data, 2048, fmt, ap);
-		} else { 
+		} else {
 			return;
 		}
 #endif
 	}
 	if (data) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, (char*) "%s", data);
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, (char *) "%s", data);
 		free(data);
 	}
 }
@@ -194,120 +194,120 @@
 		data = (char *) malloc(2048);
 		if (data) {
 			vsnprintf(data, 2048, fmt, ap);
-		} else { 
+		} else {
 			return;
 		}
 #endif
 	}
 	if (data) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, (char*) "%s", data);
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, (char *) "%s", data);
 		free(data);
 	}
 }
 
-static size_t decode_fd(shout_context_t *context, void *data, size_t bytes)
+static size_t decode_fd(shout_context_t * context, void *data, size_t bytes)
 {
-    int decode_status = 0;
-    int dlen = 0;
-    int x = 0;
-    char *in;
-    int inlen;
-    char *out;
-    int outlen;
-    int usedlen;
-    char inbuf[MP3_SCACHE];
-    int done = 0;
-    
-    size_t lp;
-    size_t rb = 0;
-
-    while (switch_buffer_inuse(context->audio_buffer) < bytes) {
-        lp = sizeof(inbuf);
-        if ((switch_file_read(context->fd, inbuf, &lp) != SWITCH_STATUS_SUCCESS) || lp == 0) {
-            goto error;
-        }
-
-        inlen = (int) lp;
-        in = inbuf;
-        
-        out = context->decode_buf;
-        outlen = (int) sizeof(context->decode_buf);
-        usedlen = 0;
-        x =  0;
-
-        if (inlen < bytes) {
-            done = 1;
-        }
-
-        do {
-            decode_status = decodeMP3(&context->mp, in, inlen, out, outlen, &dlen);
-
-            if (context->err) {
-                goto error;
-            }
-
-            if (!x) {
-                in = NULL;
-                inlen = 0;
-                x++;
-            }
-            
-            if (decode_status == MP3_TOOSMALL) {
-                if (context->audio_buffer) {
-                    switch_buffer_write(context->audio_buffer, context->decode_buf, usedlen);
-                } else {
-                    goto error;
-                }
-                
-                out = context->decode_buf;
-                outlen = sizeof(context->decode_buf);
-                usedlen = 0;
-                continue;
-                
-            }
-
-            if (decode_status == MP3_ERR) {
-                if (++context->mp3err >= 20) {
-                    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Decoder Error!\n");
-                }
-                dlen = 0;
-                continue;
-            }
-            
-            context->mp3err = 0;
-            
-            usedlen += dlen;        
-            out += dlen;
-            outlen -= dlen;
-            dlen = 0;
-            
-
-        } while (decode_status != MP3_NEED_MORE);
-        
-
-        if (context->audio_buffer) {
-            switch_buffer_write(context->audio_buffer, context->decode_buf, usedlen);
-        } else {
-            goto error;
-        }
-
-        if (done) {
-            break;
-        }
-    }
-
-    if (done || switch_buffer_inuse(context->audio_buffer) >= bytes) {
-        rb = switch_buffer_read(context->audio_buffer, data, bytes);
-        return rb;
-    }
-
-    return 0;
-    
- error:
-    switch_mutex_lock(context->audio_mutex);
-    context->err++;
-    switch_mutex_unlock(context->audio_mutex);
-    return 0;
+	int decode_status = 0;
+	int dlen = 0;
+	int x = 0;
+	char *in;
+	int inlen;
+	char *out;
+	int outlen;
+	int usedlen;
+	char inbuf[MP3_SCACHE];
+	int done = 0;
+
+	size_t lp;
+	size_t rb = 0;
+
+	while (switch_buffer_inuse(context->audio_buffer) < bytes) {
+		lp = sizeof(inbuf);
+		if ((switch_file_read(context->fd, inbuf, &lp) != SWITCH_STATUS_SUCCESS) || lp == 0) {
+			goto error;
+		}
+
+		inlen = (int) lp;
+		in = inbuf;
+
+		out = context->decode_buf;
+		outlen = (int) sizeof(context->decode_buf);
+		usedlen = 0;
+		x = 0;
+
+		if (inlen < bytes) {
+			done = 1;
+		}
+
+		do {
+			decode_status = decodeMP3(&context->mp, in, inlen, out, outlen, &dlen);
+
+			if (context->err) {
+				goto error;
+			}
+
+			if (!x) {
+				in = NULL;
+				inlen = 0;
+				x++;
+			}
+
+			if (decode_status == MP3_TOOSMALL) {
+				if (context->audio_buffer) {
+					switch_buffer_write(context->audio_buffer, context->decode_buf, usedlen);
+				} else {
+					goto error;
+				}
+
+				out = context->decode_buf;
+				outlen = sizeof(context->decode_buf);
+				usedlen = 0;
+				continue;
+
+			}
+
+			if (decode_status == MP3_ERR) {
+				if (++context->mp3err >= 20) {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Decoder Error!\n");
+				}
+				dlen = 0;
+				continue;
+			}
+
+			context->mp3err = 0;
+
+			usedlen += dlen;
+			out += dlen;
+			outlen -= dlen;
+			dlen = 0;
+
+
+		} while (decode_status != MP3_NEED_MORE);
+
+
+		if (context->audio_buffer) {
+			switch_buffer_write(context->audio_buffer, context->decode_buf, usedlen);
+		} else {
+			goto error;
+		}
+
+		if (done) {
+			break;
+		}
+	}
+
+	if (done || switch_buffer_inuse(context->audio_buffer) >= bytes) {
+		rb = switch_buffer_read(context->audio_buffer, data, bytes);
+		return rb;
+	}
+
+	return 0;
+
+  error:
+	switch_mutex_lock(context->audio_mutex);
+	context->err++;
+	switch_mutex_unlock(context->audio_mutex);
+	return 0;
 
 }
 
@@ -315,211 +315,211 @@
 
 static size_t stream_callback(void *ptr, size_t size, size_t nmemb, void *data)
 {
-	register unsigned int realsize = (unsigned int)(size * nmemb);
+	register unsigned int realsize = (unsigned int) (size * nmemb);
 	shout_context_t *context = data;
-    int decode_status = 0;
-    int dlen = 0;
-    int x = 0;
-    char *in;
-    int inlen;
-    char *out;
-    int outlen;
-    int usedlen;
-    uint32_t used, buf_size = 1024 * 64;
-    
-    in = ptr;
-    inlen = realsize;
-    out = context->decode_buf;
-    outlen = sizeof(context->decode_buf);
-    usedlen = 0;
-
-    error_check();
-    
-    /* make sure we aren't over zealous by slowing down the stream when the buffer is too full */
-    for(;;) { 
-        error_check();
-
-        switch_mutex_lock(context->audio_mutex);
-        if (!context->audio_buffer) {
-            context->err++;
-            break;
-        }
-
-        used = switch_buffer_inuse(context->audio_buffer);
-        switch_mutex_unlock(context->audio_mutex);
-
-        if (used < buf_size) {
-            break;
-        }
-
-        switch_yield(1000000);
-    }
-
-    error_check();
-
-    do {
-        decode_status = decodeMP3(&context->mp, in, inlen, out, outlen, &dlen);
-
-        error_check();
-
-        if (!x) {
-            in = NULL;
-            inlen = 0;
-            x++;
-        }
-        
-        if (decode_status == MP3_TOOSMALL) {
-            switch_mutex_lock(context->audio_mutex);
-            if (context->audio_buffer) {
-                switch_buffer_write(context->audio_buffer, context->decode_buf, usedlen);
-            } else {
-                goto error;
-            }
-            out = context->decode_buf;
-            outlen = sizeof(context->decode_buf);
-            usedlen = 0;
-            switch_mutex_unlock(context->audio_mutex);
-            
-        } else if (decode_status == MP3_ERR) {
-
-            if (++context->mp3err >= 20) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Decoder Error!\n");
-                goto error;
-            }
-
-            ExitMP3(&context->mp);
-            InitMP3(&context->mp, OUTSCALE, context->samplerate);
-            
-            return realsize;
-        }
-
-        context->mp3err = 0;    
-        usedlen += dlen;        
-        out += dlen;
-        outlen -= dlen;
-        dlen = 0;
-    } while (decode_status != MP3_NEED_MORE);
-
-
-    switch_mutex_lock(context->audio_mutex);
-    if (context->audio_buffer) {
-        switch_buffer_write(context->audio_buffer, context->decode_buf, usedlen);
-    } else {
-        goto error;
-    }
-    switch_mutex_unlock(context->audio_mutex);
+	int decode_status = 0;
+	int dlen = 0;
+	int x = 0;
+	char *in;
+	int inlen;
+	char *out;
+	int outlen;
+	int usedlen;
+	uint32_t used, buf_size = 1024 * 64;
+
+	in = ptr;
+	inlen = realsize;
+	out = context->decode_buf;
+	outlen = sizeof(context->decode_buf);
+	usedlen = 0;
+
+	error_check();
+
+	/* make sure we aren't over zealous by slowing down the stream when the buffer is too full */
+	for (;;) {
+		error_check();
+
+		switch_mutex_lock(context->audio_mutex);
+		if (!context->audio_buffer) {
+			context->err++;
+			break;
+		}
+
+		used = switch_buffer_inuse(context->audio_buffer);
+		switch_mutex_unlock(context->audio_mutex);
+
+		if (used < buf_size) {
+			break;
+		}
+
+		switch_yield(1000000);
+	}
+
+	error_check();
+
+	do {
+		decode_status = decodeMP3(&context->mp, in, inlen, out, outlen, &dlen);
+
+		error_check();
+
+		if (!x) {
+			in = NULL;
+			inlen = 0;
+			x++;
+		}
+
+		if (decode_status == MP3_TOOSMALL) {
+			switch_mutex_lock(context->audio_mutex);
+			if (context->audio_buffer) {
+				switch_buffer_write(context->audio_buffer, context->decode_buf, usedlen);
+			} else {
+				goto error;
+			}
+			out = context->decode_buf;
+			outlen = sizeof(context->decode_buf);
+			usedlen = 0;
+			switch_mutex_unlock(context->audio_mutex);
+
+		} else if (decode_status == MP3_ERR) {
+
+			if (++context->mp3err >= 20) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Decoder Error!\n");
+				goto error;
+			}
+
+			ExitMP3(&context->mp);
+			InitMP3(&context->mp, OUTSCALE, context->samplerate);
+
+			return realsize;
+		}
+
+		context->mp3err = 0;
+		usedlen += dlen;
+		out += dlen;
+		outlen -= dlen;
+		dlen = 0;
+	} while (decode_status != MP3_NEED_MORE);
+
+
+	switch_mutex_lock(context->audio_mutex);
+	if (context->audio_buffer) {
+		switch_buffer_write(context->audio_buffer, context->decode_buf, usedlen);
+	} else {
+		goto error;
+	}
+	switch_mutex_unlock(context->audio_mutex);
 
 	return realsize;
-    
- error:
-    switch_mutex_lock(context->audio_mutex);
-    context->err++;
-    switch_mutex_unlock(context->audio_mutex);
-    return 0;
+
+  error:
+	switch_mutex_lock(context->audio_mutex);
+	context->err++;
+	switch_mutex_unlock(context->audio_mutex);
+	return 0;
 
 }
 
 
 #define MY_BUF_LEN 1024 * 32
 #define MY_BLOCK_SIZE MY_BUF_LEN
-static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void *obj)
+static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t * thread, void *obj)
 {
-    CURL *curl_handle = NULL;
-    shout_context_t *context = (shout_context_t *) obj;
+	CURL *curl_handle = NULL;
+	shout_context_t *context = (shout_context_t *) obj;
 
 	curl_handle = curl_easy_init();
-    curl_easy_setopt(curl_handle, CURLOPT_URL, context->stream_url);
-    curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, stream_callback);
-    curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)context);
-    curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "FreeSWITCH(mod_shout)/1.0");
-    curl_easy_perform(curl_handle);
-    curl_easy_cleanup(curl_handle);
-    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Thread Done\n");
-    switch_mutex_lock(context->audio_mutex);
-    context->err++;
-    switch_mutex_unlock(context->audio_mutex);
-    context->thread_running = 0;
-    return NULL;
+	curl_easy_setopt(curl_handle, CURLOPT_URL, context->stream_url);
+	curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, stream_callback);
+	curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *) context);
+	curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "FreeSWITCH(mod_shout)/1.0");
+	curl_easy_perform(curl_handle);
+	curl_easy_cleanup(curl_handle);
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Thread Done\n");
+	switch_mutex_lock(context->audio_mutex);
+	context->err++;
+	switch_mutex_unlock(context->audio_mutex);
+	context->thread_running = 0;
+	return NULL;
 }
 
-static void launch_read_stream_thread(shout_context_t *context)
+static void launch_read_stream_thread(shout_context_t * context)
 {
 	switch_thread_t *thread;
 	switch_threadattr_t *thd_attr = NULL;
 
 	if (context->err) {
-        return;
-    }
-    
-    context->thread_running = 1;
+		return;
+	}
+
+	context->thread_running = 1;
 	switch_threadattr_create(&thd_attr, context->memory_pool);
 	switch_threadattr_detach_set(thd_attr, 1);
 	switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
 	switch_thread_create(&thread, thd_attr, read_stream_thread, context, context->memory_pool);
 }
 
-static void *SWITCH_THREAD_FUNC write_stream_thread(switch_thread_t *thread, void *obj)
+static void *SWITCH_THREAD_FUNC write_stream_thread(switch_thread_t * thread, void *obj)
 {
-    shout_context_t *context = (shout_context_t *) obj;
+	shout_context_t *context = (shout_context_t *) obj;
 
-    while(!context->err && context->thread_running) {
-        unsigned char mp3buf[8192] = "";
-        unsigned char audio[8192] = "";
-        switch_size_t audio_read = 0;
-        int rlen;
-        long ret = 0;
-
-        switch_mutex_lock(context->audio_mutex);
-        if (context->audio_buffer) {
-            audio_read = switch_buffer_read(context->audio_buffer, audio, sizeof(audio));
-        } else {
-            context->err++;
-        }
-        switch_mutex_unlock(context->audio_mutex);
-
-        error_check();
-
-        if (!audio_read) {
-            audio_read = sizeof(audio);
-            memset(audio, 255, sizeof(audio));
-        }
-        
-        if ((rlen = lame_encode_buffer(context->gfp, (void *) audio, NULL, audio_read / sizeof(int16_t), mp3buf, sizeof(mp3buf))) < 0) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "MP3 encode error %d!\n", rlen);
-            goto error;
-        }
-
-        if (rlen) {
-            ret = shout_send(context->shout, mp3buf, rlen);
-            if (ret != SHOUTERR_SUCCESS) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Send error: %s\n", shout_get_error(context->shout));
-                goto error;
-            }
-        } else {
-            memset(mp3buf, 0, 128);
-            ret = shout_send(context->shout, mp3buf, 128);
-        }
-        
-        shout_sync(context->shout);
-        switch_yield(100000);
-    }
-
-    error:
-    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Thread Done\n");
-    context->thread_running = 0;
-    return NULL;
+	while (!context->err && context->thread_running) {
+		unsigned char mp3buf[8192] = "";
+		unsigned char audio[8192] = "";
+		switch_size_t audio_read = 0;
+		int rlen;
+		long ret = 0;
+
+		switch_mutex_lock(context->audio_mutex);
+		if (context->audio_buffer) {
+			audio_read = switch_buffer_read(context->audio_buffer, audio, sizeof(audio));
+		} else {
+			context->err++;
+		}
+		switch_mutex_unlock(context->audio_mutex);
+
+		error_check();
+
+		if (!audio_read) {
+			audio_read = sizeof(audio);
+			memset(audio, 255, sizeof(audio));
+		}
+
+		if ((rlen = lame_encode_buffer(context->gfp, (void *) audio, NULL, audio_read / sizeof(int16_t), mp3buf, sizeof(mp3buf))) < 0) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "MP3 encode error %d!\n", rlen);
+			goto error;
+		}
+
+		if (rlen) {
+			ret = shout_send(context->shout, mp3buf, rlen);
+			if (ret != SHOUTERR_SUCCESS) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Send error: %s\n", shout_get_error(context->shout));
+				goto error;
+			}
+		} else {
+			memset(mp3buf, 0, 128);
+			ret = shout_send(context->shout, mp3buf, 128);
+		}
+
+		shout_sync(context->shout);
+		switch_yield(100000);
+	}
+
+  error:
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Thread Done\n");
+	context->thread_running = 0;
+	return NULL;
 }
 
-static void launch_write_stream_thread(shout_context_t *context)
+static void launch_write_stream_thread(shout_context_t * context)
 {
 	switch_thread_t *thread;
 	switch_threadattr_t *thd_attr = NULL;
 
 	if (context->err) {
-        return;
-    }
-    
-    context->thread_running = 1;
+		return;
+	}
+
+	context->thread_running = 1;
 	switch_threadattr_create(&thd_attr, context->memory_pool);
 	switch_threadattr_detach_set(thd_attr, 1);
 	switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
@@ -529,178 +529,178 @@
 static switch_status_t shout_file_open(switch_file_handle_t *handle, char *path)
 {
 	shout_context_t *context;
-    char *host, *file;
-    char *username, *password, *port;
-    char *err = NULL;
-    int portno = 0;
+	char *host, *file;
+	char *username, *password, *port;
+	char *err = NULL;
+	int portno = 0;
 
 	if ((context = switch_core_alloc(handle->memory_pool, sizeof(*context))) == 0) {
 		return SWITCH_STATUS_MEMERR;
 	}
 
-    if (!handle->samplerate) {
-        handle->samplerate = 8000;
-    }
-
-    context->memory_pool = handle->memory_pool;
-    context->samplerate = handle->samplerate;
-    
-    if (switch_test_flag(handle, SWITCH_FILE_FLAG_READ)) {
-        if (switch_buffer_create_dynamic(&context->audio_buffer, MY_BLOCK_SIZE, MY_BUF_LEN, 0) != SWITCH_STATUS_SUCCESS) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error!\n");
-            goto error;
-        }
-        
-        switch_mutex_init(&context->audio_mutex, SWITCH_MUTEX_NESTED, context->memory_pool);
-        InitMP3(&context->mp, OUTSCALE, context->samplerate);
-        if (handle->handler) {
-            context->stream_url = switch_core_sprintf(context->memory_pool, "http://%s", path);
-            launch_read_stream_thread(context);
-        } else {
-            if (switch_file_open(&context->fd, path, SWITCH_FOPEN_READ, 
-                                 SWITCH_FPROT_UREAD|SWITCH_FPROT_UWRITE, handle->memory_pool) != SWITCH_STATUS_SUCCESS) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening %s\n", path);
-                goto error;
-            }
-        }
-    } else if (switch_test_flag(handle, SWITCH_FILE_FLAG_WRITE)) {
-        if (!(context->gfp = lame_init())) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not allocate lame\n");
-            goto error;
-        }
-
-        lame_set_num_channels(context->gfp, handle->channels);
-        lame_set_in_samplerate(context->gfp, handle->samplerate);
-        lame_set_brate(context->gfp, 64);
-        lame_set_mode(context->gfp, 3);
-        lame_set_quality(context->gfp, 2);   /* 2=high  5 = medium  7=low */
-        
-        lame_set_errorf(context->gfp, log_error);
-        lame_set_debugf(context->gfp, log_debug);
-        lame_set_msgf(context->gfp, log_msg);
-        
-        lame_init_params(context->gfp);
-        lame_print_config(context->gfp);
-        
-        if (handle->handler) {
-            if (switch_buffer_create_dynamic(&context->audio_buffer, MY_BLOCK_SIZE, MY_BUF_LEN, 0) != SWITCH_STATUS_SUCCESS) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error!\n");
-                goto error;
-            }
-            switch_mutex_init(&context->audio_mutex, SWITCH_MUTEX_NESTED, context->memory_pool);
-            lame_set_bWriteVbrTag(context->gfp, 0);
-            lame_mp3_tags_fid(context->gfp, NULL);
-            
-            username = switch_core_strdup(handle->memory_pool, path);
-            if (!(password = strchr(username, ':'))) {
-                err = "invalid url";
-                goto error;
-            }
-            *password++ = '\0';
-        
-            if (!(host = strchr(password, '@'))) {
-                err = "invalid url";
-                goto error;
-            }
-            *host++ = '\0';
-    
-            if ((file = strchr(host, '/'))) {
-                *file++ = '\0';
-            } else {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid URL: %s\n", path);
-                goto error;
-            }
-            
-            if ((port = strchr(host, ':'))) {
-                *port++ = '\0';
-                if (port) {
-                    portno = atoi(port);
-                }
-            }
-
-            if (!portno) {
-                portno = 8000;
-            }
-
-            if (!(context->shout = shout_new())) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not allocate shout_t\n");
-                goto error;
-            }
-            
-            if (shout_set_host(context->shout, host) != SHOUTERR_SUCCESS) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error setting hostname: %s\n", shout_get_error(context->shout));
-                goto error;
-            }
-
-            if (shout_set_protocol(context->shout, SHOUT_PROTOCOL_HTTP) != SHOUTERR_SUCCESS) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error setting protocol: %s\n", shout_get_error(context->shout));
-                goto error;
-            }
-    
-            if (shout_set_port(context->shout, portno) != SHOUTERR_SUCCESS) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error setting port: %s\n", shout_get_error(context->shout));
-                goto error;
-            }
-
-            if (shout_set_password(context->shout, password) != SHOUTERR_SUCCESS) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error setting password: %s\n", shout_get_error(context->shout));
-                goto error;
-            }
-
-            if (shout_set_mount(context->shout, file) != SHOUTERR_SUCCESS) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error setting mount: %s\n", shout_get_error(context->shout));
-                goto error;
-            }
-
-            if (shout_set_user(context->shout, username) != SHOUTERR_SUCCESS) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error setting user: %s\n", shout_get_error(context->shout));
-                goto error;
-            }
-
-            if (shout_set_url(context->shout, "http://www.freeswitch.org") != SHOUTERR_SUCCESS) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error setting name: %s\n", shout_get_error(context->shout));
-                goto error;
-            }
-
-            if (shout_set_description(context->shout, "FreeSWITCH mod_shout Broadcasting Module") != SHOUTERR_SUCCESS) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error setting name: %s\n", shout_get_error(context->shout));
-                goto error;
-            }
-
-            if (shout_set_audio_info(context->shout, "bitrate", "64000") != SHOUTERR_SUCCESS) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error setting user: %s\n", shout_get_error(context->shout));
-                goto error;
-            }
-
-            if (shout_set_format(context->shout, SHOUT_FORMAT_MP3) != SHOUTERR_SUCCESS) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error setting user: %s\n", shout_get_error(context->shout));
-                goto error;
-            }
-
-        } else {
-            handle->seekable = 1;
-            /* lame being lame and all has FILE * coded into it's API for some functions so we gotta use it */
-            if (!(context->fp = fopen(path, "wb+"))) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening %s\n", path);
-                return SWITCH_STATUS_GENERR;
-            }
-        }
-    }
-
-    handle->samples = 0;
-    handle->format = 0;
-    handle->sections = 0;
-    handle->speed = 0;
+	if (!handle->samplerate) {
+		handle->samplerate = 8000;
+	}
+
+	context->memory_pool = handle->memory_pool;
+	context->samplerate = handle->samplerate;
+
+	if (switch_test_flag(handle, SWITCH_FILE_FLAG_READ)) {
+		if (switch_buffer_create_dynamic(&context->audio_buffer, MY_BLOCK_SIZE, MY_BUF_LEN, 0) != SWITCH_STATUS_SUCCESS) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error!\n");
+			goto error;
+		}
+
+		switch_mutex_init(&context->audio_mutex, SWITCH_MUTEX_NESTED, context->memory_pool);
+		InitMP3(&context->mp, OUTSCALE, context->samplerate);
+		if (handle->handler) {
+			context->stream_url = switch_core_sprintf(context->memory_pool, "http://%s", path);
+			launch_read_stream_thread(context);
+		} else {
+			if (switch_file_open(&context->fd, path, SWITCH_FOPEN_READ, SWITCH_FPROT_UREAD | SWITCH_FPROT_UWRITE, handle->memory_pool) !=
+				SWITCH_STATUS_SUCCESS) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening %s\n", path);
+				goto error;
+			}
+		}
+	} else if (switch_test_flag(handle, SWITCH_FILE_FLAG_WRITE)) {
+		if (!(context->gfp = lame_init())) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not allocate lame\n");
+			goto error;
+		}
+
+		lame_set_num_channels(context->gfp, handle->channels);
+		lame_set_in_samplerate(context->gfp, handle->samplerate);
+		lame_set_brate(context->gfp, 64);
+		lame_set_mode(context->gfp, 3);
+		lame_set_quality(context->gfp, 2);	/* 2=high  5 = medium  7=low */
+
+		lame_set_errorf(context->gfp, log_error);
+		lame_set_debugf(context->gfp, log_debug);
+		lame_set_msgf(context->gfp, log_msg);
+
+		lame_init_params(context->gfp);
+		lame_print_config(context->gfp);
+
+		if (handle->handler) {
+			if (switch_buffer_create_dynamic(&context->audio_buffer, MY_BLOCK_SIZE, MY_BUF_LEN, 0) != SWITCH_STATUS_SUCCESS) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error!\n");
+				goto error;
+			}
+			switch_mutex_init(&context->audio_mutex, SWITCH_MUTEX_NESTED, context->memory_pool);
+			lame_set_bWriteVbrTag(context->gfp, 0);
+			lame_mp3_tags_fid(context->gfp, NULL);
+
+			username = switch_core_strdup(handle->memory_pool, path);
+			if (!(password = strchr(username, ':'))) {
+				err = "invalid url";
+				goto error;
+			}
+			*password++ = '\0';
+
+			if (!(host = strchr(password, '@'))) {
+				err = "invalid url";
+				goto error;
+			}
+			*host++ = '\0';
+
+			if ((file = strchr(host, '/'))) {
+				*file++ = '\0';
+			} else {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid URL: %s\n", path);
+				goto error;
+			}
+
+			if ((port = strchr(host, ':'))) {
+				*port++ = '\0';
+				if (port) {
+					portno = atoi(port);
+				}
+			}
+
+			if (!portno) {
+				portno = 8000;
+			}
+
+			if (!(context->shout = shout_new())) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not allocate shout_t\n");
+				goto error;
+			}
+
+			if (shout_set_host(context->shout, host) != SHOUTERR_SUCCESS) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error setting hostname: %s\n", shout_get_error(context->shout));
+				goto error;
+			}
+
+			if (shout_set_protocol(context->shout, SHOUT_PROTOCOL_HTTP) != SHOUTERR_SUCCESS) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error setting protocol: %s\n", shout_get_error(context->shout));
+				goto error;
+			}
+
+			if (shout_set_port(context->shout, portno) != SHOUTERR_SUCCESS) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error setting port: %s\n", shout_get_error(context->shout));
+				goto error;
+			}
+
+			if (shout_set_password(context->shout, password) != SHOUTERR_SUCCESS) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error setting password: %s\n", shout_get_error(context->shout));
+				goto error;
+			}
+
+			if (shout_set_mount(context->shout, file) != SHOUTERR_SUCCESS) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error setting mount: %s\n", shout_get_error(context->shout));
+				goto error;
+			}
+
+			if (shout_set_user(context->shout, username) != SHOUTERR_SUCCESS) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error setting user: %s\n", shout_get_error(context->shout));
+				goto error;
+			}
+
+			if (shout_set_url(context->shout, "http://www.freeswitch.org") != SHOUTERR_SUCCESS) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error setting name: %s\n", shout_get_error(context->shout));
+				goto error;
+			}
+
+			if (shout_set_description(context->shout, "FreeSWITCH mod_shout Broadcasting Module") != SHOUTERR_SUCCESS) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error setting name: %s\n", shout_get_error(context->shout));
+				goto error;
+			}
+
+			if (shout_set_audio_info(context->shout, "bitrate", "64000") != SHOUTERR_SUCCESS) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error setting user: %s\n", shout_get_error(context->shout));
+				goto error;
+			}
+
+			if (shout_set_format(context->shout, SHOUT_FORMAT_MP3) != SHOUTERR_SUCCESS) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error setting user: %s\n", shout_get_error(context->shout));
+				goto error;
+			}
+
+		} else {
+			handle->seekable = 1;
+			/* lame being lame and all has FILE * coded into it's API for some functions so we gotta use it */
+			if (!(context->fp = fopen(path, "wb+"))) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening %s\n", path);
+				return SWITCH_STATUS_GENERR;
+			}
+		}
+	}
+
+	handle->samples = 0;
+	handle->format = 0;
+	handle->sections = 0;
+	handle->speed = 0;
 	handle->private_info = context;
-    
+
 	return SWITCH_STATUS_SUCCESS;
-    
- error:
-    if (err) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error: %s\n", err);
-    }
-    free_context(context);
-    return SWITCH_STATUS_GENERR;
+
+  error:
+	if (err) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error: %s\n", err);
+	}
+	free_context(context);
+	return SWITCH_STATUS_GENERR;
 
 }
 
@@ -708,7 +708,7 @@
 {
 	shout_context_t *context = handle->private_info;
 
-    free_context(context);
+	free_context(context);
 
 	return SWITCH_STATUS_SUCCESS;
 }
@@ -717,57 +717,57 @@
 {
 	shout_context_t *context = handle->private_info;
 
-    if (handle->handler) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot seek on a stream.\n");
-        return SWITCH_STATUS_FALSE;
-    } else {
-        switch_mutex_lock(context->audio_mutex);
-        if (context->audio_buffer) {
-            if (context->fd) {
-                switch_file_seek(context->fd, whence, &samples);
-            } else if (context->fp) {
-                *cur_sample = fseek(context->fp, *cur_sample, whence);
-            }
-            switch_buffer_zero(context->audio_buffer);
-        } else {
-            context->err++;
-        }
-        switch_mutex_unlock(context->audio_mutex);
-        return SWITCH_STATUS_SUCCESS;
-    }
+	if (handle->handler) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot seek on a stream.\n");
+		return SWITCH_STATUS_FALSE;
+	} else {
+		switch_mutex_lock(context->audio_mutex);
+		if (context->audio_buffer) {
+			if (context->fd) {
+				switch_file_seek(context->fd, whence, &samples);
+			} else if (context->fp) {
+				*cur_sample = fseek(context->fp, *cur_sample, whence);
+			}
+			switch_buffer_zero(context->audio_buffer);
+		} else {
+			context->err++;
+		}
+		switch_mutex_unlock(context->audio_mutex);
+		return SWITCH_STATUS_SUCCESS;
+	}
 }
 
 static switch_status_t shout_file_read(switch_file_handle_t *handle, void *data, size_t *len)
 {
 	shout_context_t *context = handle->private_info;
-    size_t rb = 0, bytes = *len * sizeof(int16_t);
+	size_t rb = 0, bytes = *len * sizeof(int16_t);
 
-    *len = 0;
+	*len = 0;
 
-    if (context->fd) {
-        rb = decode_fd(context, data, bytes);
-    } else {
-        switch_mutex_lock(context->audio_mutex);
-        if (context->audio_buffer) {
-            rb = switch_buffer_read(context->audio_buffer, data, bytes);
-        } else {
-            switch_mutex_lock(context->audio_mutex);
-            context->err++;
-            switch_mutex_unlock(context->audio_mutex);
-        }
-        switch_mutex_unlock(context->audio_mutex);
-    }
-
-    if (context->err) {
-        return SWITCH_STATUS_FALSE;
-    }
-
-    if (rb) {
-        *len = rb / sizeof(int16_t);
-    } else {
-        memset(data, 255, bytes);
-        *len = bytes / sizeof(int16_t);
-    }
+	if (context->fd) {
+		rb = decode_fd(context, data, bytes);
+	} else {
+		switch_mutex_lock(context->audio_mutex);
+		if (context->audio_buffer) {
+			rb = switch_buffer_read(context->audio_buffer, data, bytes);
+		} else {
+			switch_mutex_lock(context->audio_mutex);
+			context->err++;
+			switch_mutex_unlock(context->audio_mutex);
+		}
+		switch_mutex_unlock(context->audio_mutex);
+	}
+
+	if (context->err) {
+		return SWITCH_STATUS_FALSE;
+	}
+
+	if (rb) {
+		*len = rb / sizeof(int16_t);
+	} else {
+		memset(data, 255, bytes);
+		*len = bytes / sizeof(int16_t);
+	}
 
 	return SWITCH_STATUS_SUCCESS;
 }
@@ -775,75 +775,75 @@
 static switch_status_t shout_file_write(switch_file_handle_t *handle, void *data, size_t *len)
 {
 	shout_context_t *context = handle->private_info;
-    unsigned char mp3buf[2048] = "";
-    int rlen;
-    int16_t *audio = data;
-    int nsamples = *len;
-    
-
-    if (context->shout && !context->shout_init) {
-        context->shout_init++;
-        if (shout_open(context->shout) != SHOUTERR_SUCCESS) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening stream: %s\n", shout_get_error(context->shout));
-            context->err++;
-            return SWITCH_STATUS_FALSE;
-        }
-        launch_write_stream_thread(context);
-    }
-
-    if (handle->handler) {
-        switch_mutex_lock(context->audio_mutex);
-        if (context->audio_buffer) {
-            if (!switch_buffer_write(context->audio_buffer, data, nsamples * sizeof(int16_t))) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Buffer error\n");
-                context->err++;
-            }
-        } else {
-            context->err++;
-        }
-        switch_mutex_unlock(context->audio_mutex);
-        if (context->err) {
-            return SWITCH_STATUS_FALSE;
-        }
-    } else {
-        if ((rlen = lame_encode_buffer(context->gfp, audio, NULL, nsamples, mp3buf, sizeof(mp3buf))) < 0) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "MP3 encode error %d!\n", rlen);
-            return SWITCH_STATUS_FALSE;
-        }
-        if (rlen) {
-            if (fwrite(mp3buf, 1, rlen, context->fp) < 0) {
-                return SWITCH_STATUS_FALSE;
-            }
-        }
-    }
+	unsigned char mp3buf[2048] = "";
+	int rlen;
+	int16_t *audio = data;
+	int nsamples = *len;
 
-    return SWITCH_STATUS_SUCCESS;
+
+	if (context->shout && !context->shout_init) {
+		context->shout_init++;
+		if (shout_open(context->shout) != SHOUTERR_SUCCESS) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening stream: %s\n", shout_get_error(context->shout));
+			context->err++;
+			return SWITCH_STATUS_FALSE;
+		}
+		launch_write_stream_thread(context);
+	}
+
+	if (handle->handler) {
+		switch_mutex_lock(context->audio_mutex);
+		if (context->audio_buffer) {
+			if (!switch_buffer_write(context->audio_buffer, data, nsamples * sizeof(int16_t))) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Buffer error\n");
+				context->err++;
+			}
+		} else {
+			context->err++;
+		}
+		switch_mutex_unlock(context->audio_mutex);
+		if (context->err) {
+			return SWITCH_STATUS_FALSE;
+		}
+	} else {
+		if ((rlen = lame_encode_buffer(context->gfp, audio, NULL, nsamples, mp3buf, sizeof(mp3buf))) < 0) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "MP3 encode error %d!\n", rlen);
+			return SWITCH_STATUS_FALSE;
+		}
+		if (rlen) {
+			if (fwrite(mp3buf, 1, rlen, context->fp) < 0) {
+				return SWITCH_STATUS_FALSE;
+			}
+		}
+	}
+
+	return SWITCH_STATUS_SUCCESS;
 }
 
 static switch_status_t shout_file_set_string(switch_file_handle_t *handle, switch_audio_col_t col, const char *string)
 {
 	shout_context_t *context = handle->private_info;
 
-    switch(col) {
-    case SWITCH_AUDIO_COL_STR_TITLE:
-        if (shout_set_name(context->shout, string) != SHOUTERR_SUCCESS) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error setting name: %s\n", shout_get_error(context->shout));
-        }
-        break;
-    case SWITCH_AUDIO_COL_STR_COMMENT:
-        if (shout_set_url(context->shout, string) != SHOUTERR_SUCCESS) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error setting name: %s\n", shout_get_error(context->shout));
-        }
-        break;
-    case SWITCH_AUDIO_COL_STR_ARTIST:
-        if (shout_set_description(context->shout, string) != SHOUTERR_SUCCESS) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error setting name: %s\n", shout_get_error(context->shout));
-        }
-        break;
-    default:
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Value Ignored\n");
-        break;
-    }
+	switch (col) {
+	case SWITCH_AUDIO_COL_STR_TITLE:
+		if (shout_set_name(context->shout, string) != SHOUTERR_SUCCESS) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error setting name: %s\n", shout_get_error(context->shout));
+		}
+		break;
+	case SWITCH_AUDIO_COL_STR_COMMENT:
+		if (shout_set_url(context->shout, string) != SHOUTERR_SUCCESS) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error setting name: %s\n", shout_get_error(context->shout));
+		}
+		break;
+	case SWITCH_AUDIO_COL_STR_ARTIST:
+		if (shout_set_description(context->shout, string) != SHOUTERR_SUCCESS) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error setting name: %s\n", shout_get_error(context->shout));
+		}
+		break;
+	default:
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Value Ignored\n");
+		break;
+	}
 	return SWITCH_STATUS_FALSE;
 }
 
@@ -880,17 +880,17 @@
 
 SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
 {
-    supported_formats[0] = "shout";
-    supported_formats[1] = "mp3";
+	supported_formats[0] = "shout";
+	supported_formats[1] = "mp3";
 	shout_file_interface.extens = supported_formats;
 
-    curl_global_init(CURL_GLOBAL_ALL);
+	curl_global_init(CURL_GLOBAL_ALL);
 
 	/* connect my internal structure to the blank pointer passed to me */
 	*module_interface = &shout_module_interface;
 
 	shout_init();
-    InitMP3Constants();
+	InitMP3Constants();
 
 	/* indicate that the module should continue to be loaded */
 	return SWITCH_STATUS_SUCCESS;

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/mpg123.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/mpg123.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/mpg123.h	Fri Mar 30 12:19:18 2007
@@ -58,69 +58,67 @@
 #define AUSHIFT (3)
 
 struct frame {
-    int stereo;
-    int jsbound;
-    int single;
-    int lsf;
-    int mpeg25;
-    int header_change;
-    int lay;
-    int error_protection;
-    int bitrate_index;
-    int sampling_frequency;
-    int padding;
-    int extension;
-    int mode;
-    int mode_ext;
-    int copyright;
-    int original;
-    int emphasis;
-    int framesize; /* computed framesize */
+	int stereo;
+	int jsbound;
+	int single;
+	int lsf;
+	int mpeg25;
+	int header_change;
+	int lay;
+	int error_protection;
+	int bitrate_index;
+	int sampling_frequency;
+	int padding;
+	int extension;
+	int mode;
+	int mode_ext;
+	int copyright;
+	int original;
+	int emphasis;
+	int framesize;				/* computed framesize */
 };
 
 struct parameter {
-	int quiet;	/* shut up! */
-	int tryresync;  /* resync stream after error */
-	int verbose;    /* verbose level */
+	int quiet;					/* shut up! */
+	int tryresync;				/* resync stream after error */
+	int verbose;				/* verbose level */
 	int checkrange;
 };
 
-extern int decode_header(struct frame *fr,unsigned long newhead);
+extern int decode_header(struct frame *fr, unsigned long newhead);
 
 
 
 struct gr_info_s {
-      int scfsi;
-      unsigned part2_3_length;
-      unsigned big_values;
-      unsigned scalefac_compress;
-      unsigned block_type;
-      unsigned mixed_block_flag;
-      unsigned table_select[3];
-      unsigned subblock_gain[3];
-      unsigned maxband[3];
-      unsigned maxbandl;
-      unsigned maxb;
-      unsigned region1start;
-      unsigned region2start;
-      unsigned preflag;
-      unsigned scalefac_scale;
-      unsigned count1table_select;
-      real *full_gain[3];
-      real *pow2gain;
+	int scfsi;
+	unsigned part2_3_length;
+	unsigned big_values;
+	unsigned scalefac_compress;
+	unsigned block_type;
+	unsigned mixed_block_flag;
+	unsigned table_select[3];
+	unsigned subblock_gain[3];
+	unsigned maxband[3];
+	unsigned maxbandl;
+	unsigned maxb;
+	unsigned region1start;
+	unsigned region2start;
+	unsigned preflag;
+	unsigned scalefac_scale;
+	unsigned count1table_select;
+	real *full_gain[3];
+	real *pow2gain;
 };
 
-struct III_sideinfo
-{
-  unsigned main_data_begin;
-  unsigned private_bits;
-  struct {
-    struct gr_info_s gr[2];
-  } ch[2];
+struct III_sideinfo {
+	unsigned main_data_begin;
+	unsigned private_bits;
+	struct {
+		struct gr_info_s gr[2];
+	} ch[2];
 };
 
-struct pcm_workingsample
-{
+struct pcm_workingsample {
 	int bitindex;
 	unsigned char *wordpointer;
 };
@@ -129,4 +127,3 @@
 extern long freqs[9];
 extern struct parameter param;
 extern real *pnts[5];
-

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/mpglib.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/mpglib.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/mpglib.h	Fri Mar 30 12:19:18 2007
@@ -5,11 +5,11 @@
 #endif
 
 struct buf {
-        unsigned char *pnt;
+	unsigned char *pnt;
 	long size;
 	long pos;
-        struct buf *next;
-        struct buf *prev;
+	struct buf *next;
+	struct buf *prev;
 };
 
 struct framebuf {
@@ -20,27 +20,27 @@
 };
 
 struct mpstr {
-	struct buf *head,*tail;
+	struct buf *head, *tail;
 	int bsize;
 	int framesize;
-        int fsizeold;
+	int fsizeold;
 	struct frame fr;
-        unsigned char bsspace[2][MAXFRAMESIZE+512]; /* MAXFRAMESIZE */
-	real hybrid_block[2][2][SBLIMIT*SSLIMIT];
+	unsigned char bsspace[2][MAXFRAMESIZE + 512];	/* MAXFRAMESIZE */
+	real hybrid_block[2][2][SBLIMIT * SSLIMIT];
 	int hybrid_blc[2];
 	unsigned long header;
 	int bsnum;
 	real synth_buffs[2][2][0x110];
-        int  synth_bo;
-	long outscale; /* volume control default value 32768 */
-	long outsamplerate; /* raw output rate default same as mp3 sample rate*/
-	struct pcm_workingsample worksample; /* keep the state of the working sample for threads */
-	int initmp3; /* flag for first initialisation */
-	int longLimit[9][23]; /*sample limits re setting volume */
+	int synth_bo;
+	long outscale;				/* volume control default value 32768 */
+	long outsamplerate;			/* raw output rate default same as mp3 sample rate */
+	struct pcm_workingsample worksample;	/* keep the state of the working sample for threads */
+	int initmp3;				/* flag for first initialisation */
+	int longLimit[9][23];		/*sample limits re setting volume */
 	int shortLimit[9][14];
-	real decwin[512+32]; /* scale table */
-	
-	};
+	real decwin[512 + 32];		/* scale table */
+
+};
 
 #define BOOL int
 
@@ -51,30 +51,28 @@
 
 void InitMP3Constants(void);
 BOOL InitMP3(struct mpstr *mp, long outscale, int samplerate);
-int decodeMP3(struct mpstr *mp,char *inmemory,int inmemsize,
-     char *outmemory,int outmemsize,int *done);
+int decodeMP3(struct mpstr *mp, char *inmemory, int inmemsize, char *outmemory, int outmemsize, int *done);
 void ExitMP3(struct mpstr *mp);
 
-extern int synth_ntom_set_step(long,long);
-extern int synth_ntom(struct mpstr *mp, real *bandPtr,int channel,unsigned char *out,int *pnt);
-extern int synth_ntom_mono (struct mpstr *mp, real *bandPtr,unsigned char *samples,int *pnt);
-extern int synth_ntom_8bit (real *,int,unsigned char *,int *);
-extern int synth_ntom_mono2stereo (real *,unsigned char *,int *);
-extern int synth_ntom_8bit_mono (real *,unsigned char *,int *);
-extern int synth_ntom_8bit_mono2stereo (real *,unsigned char *,int *);
+extern int synth_ntom_set_step(long, long);
+extern int synth_ntom(struct mpstr *mp, real * bandPtr, int channel, unsigned char *out, int *pnt);
+extern int synth_ntom_mono(struct mpstr *mp, real * bandPtr, unsigned char *samples, int *pnt);
+extern int synth_ntom_8bit(real *, int, unsigned char *, int *);
+extern int synth_ntom_mono2stereo(real *, unsigned char *, int *);
+extern int synth_ntom_8bit_mono(real *, unsigned char *, int *);
+extern int synth_ntom_8bit_mono2stereo(real *, unsigned char *, int *);
 
 extern void init_layer3_sample_limits(struct mpstr *mp, int down_sample_sblimit);
 extern void init_layer3_const(void);
-extern int do_layer3(struct mpstr *mp,unsigned char *,int *);
+extern int do_layer3(struct mpstr *mp, unsigned char *, int *);
 
 extern void make_decode_tables_scale(struct mpstr *mp, long scaleval);
 extern void make_decode_tables_const(void);
 extern void make_conv16to8_table(int);
 
-extern void dct64(real *,real *,real *);
+extern void dct64(real *, real *, real *);
 
-extern unsigned int   get1bit(struct mpstr *mp);
-extern unsigned int   getbits(struct mpstr *mp, int);
-extern unsigned int   getbits_fast(struct mpstr *mp, int);
+extern unsigned int get1bit(struct mpstr *mp);
+extern unsigned int getbits(struct mpstr *mp, int);
+extern unsigned int getbits_fast(struct mpstr *mp, int);
 extern int set_pointer(struct mpstr *mp, long backstep);
-

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/tabinit.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/tabinit.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_shout/tabinit.c	Fri Mar 30 12:19:18 2007
@@ -4,47 +4,48 @@
 #include "mpg123.h"
 #include "mpglib.h"
 
-static real cos64[16],cos32[8],cos16[4],cos8[2],cos4[1];
-real *pnts[] = { cos64,cos32,cos16,cos8,cos4 };
+static real cos64[16], cos32[8], cos16[4], cos8[2], cos4[1];
+real *pnts[] = { cos64, cos32, cos16, cos8, cos4 };
 
 static long intwinbase[] = {
-     0,    -1,    -1,    -1,    -1,    -1,    -1,    -2,    -2,    -2,
-    -2,    -3,    -3,    -4,    -4,    -5,    -5,    -6,    -7,    -7,
-    -8,    -9,   -10,   -11,   -13,   -14,   -16,   -17,   -19,   -21,
-   -24,   -26,   -29,   -31,   -35,   -38,   -41,   -45,   -49,   -53,
-   -58,   -63,   -68,   -73,   -79,   -85,   -91,   -97,  -104,  -111,
-  -117,  -125,  -132,  -139,  -147,  -154,  -161,  -169,  -176,  -183,
-  -190,  -196,  -202,  -208,  -213,  -218,  -222,  -225,  -227,  -228,
-  -228,  -227,  -224,  -221,  -215,  -208,  -200,  -189,  -177,  -163,
-  -146,  -127,  -106,   -83,   -57,   -29,     2,    36,    72,   111,
-   153,   197,   244,   294,   347,   401,   459,   519,   581,   645,
-   711,   779,   848,   919,   991,  1064,  1137,  1210,  1283,  1356,
-  1428,  1498,  1567,  1634,  1698,  1759,  1817,  1870,  1919,  1962,
-  2001,  2032,  2057,  2075,  2085,  2087,  2080,  2063,  2037,  2000,
-  1952,  1893,  1822,  1739,  1644,  1535,  1414,  1280,  1131,   970,
-   794,   605,   402,   185,   -45,  -288,  -545,  -814, -1095, -1388,
- -1692, -2006, -2330, -2663, -3004, -3351, -3705, -4063, -4425, -4788,
- -5153, -5517, -5879, -6237, -6589, -6935, -7271, -7597, -7910, -8209,
- -8491, -8755, -8998, -9219, -9416, -9585, -9727, -9838, -9916, -9959,
- -9966, -9935, -9863, -9750, -9592, -9389, -9139, -8840, -8492, -8092,
- -7640, -7134, -6574, -5959, -5288, -4561, -3776, -2935, -2037, -1082,
-   -70,   998,  2122,  3300,  4533,  5818,  7154,  8540,  9975, 11455,
- 12980, 14548, 16155, 17799, 19478, 21189, 22929, 24694, 26482, 28289,
- 30112, 31947, 33791, 35640, 37489, 39336, 41176, 43006, 44821, 46617,
- 48390, 50137, 51853, 53534, 55178, 56778, 58333, 59838, 61289, 62684,
- 64019, 65290, 66494, 67629, 68692, 69679, 70590, 71420, 72169, 72835,
- 73415, 73908, 74313, 74630, 74856, 74992, 75038 };
+	0, -1, -1, -1, -1, -1, -1, -2, -2, -2,
+	-2, -3, -3, -4, -4, -5, -5, -6, -7, -7,
+	-8, -9, -10, -11, -13, -14, -16, -17, -19, -21,
+	-24, -26, -29, -31, -35, -38, -41, -45, -49, -53,
+	-58, -63, -68, -73, -79, -85, -91, -97, -104, -111,
+	-117, -125, -132, -139, -147, -154, -161, -169, -176, -183,
+	-190, -196, -202, -208, -213, -218, -222, -225, -227, -228,
+	-228, -227, -224, -221, -215, -208, -200, -189, -177, -163,
+	-146, -127, -106, -83, -57, -29, 2, 36, 72, 111,
+	153, 197, 244, 294, 347, 401, 459, 519, 581, 645,
+	711, 779, 848, 919, 991, 1064, 1137, 1210, 1283, 1356,
+	1428, 1498, 1567, 1634, 1698, 1759, 1817, 1870, 1919, 1962,
+	2001, 2032, 2057, 2075, 2085, 2087, 2080, 2063, 2037, 2000,
+	1952, 1893, 1822, 1739, 1644, 1535, 1414, 1280, 1131, 970,
+	794, 605, 402, 185, -45, -288, -545, -814, -1095, -1388,
+	-1692, -2006, -2330, -2663, -3004, -3351, -3705, -4063, -4425, -4788,
+	-5153, -5517, -5879, -6237, -6589, -6935, -7271, -7597, -7910, -8209,
+	-8491, -8755, -8998, -9219, -9416, -9585, -9727, -9838, -9916, -9959,
+	-9966, -9935, -9863, -9750, -9592, -9389, -9139, -8840, -8492, -8092,
+	-7640, -7134, -6574, -5959, -5288, -4561, -3776, -2935, -2037, -1082,
+	-70, 998, 2122, 3300, 4533, 5818, 7154, 8540, 9975, 11455,
+	12980, 14548, 16155, 17799, 19478, 21189, 22929, 24694, 26482, 28289,
+	30112, 31947, 33791, 35640, 37489, 39336, 41176, 43006, 44821, 46617,
+	48390, 50137, 51853, 53534, 55178, 56778, 58333, 59838, 61289, 62684,
+	64019, 65290, 66494, 67629, 68692, 69679, 70590, 71420, 72169, 72835,
+	73415, 73908, 74313, 74630, 74856, 74992, 75038
+};
 
 void make_decode_tables_const(void)
 {
-	int i,k,kr,divv;
+	int i, k, kr, divv;
 	real *costab;
-		
-	for(i=0;i<5;i++)
-	{
-		kr=0x10>>i; divv=0x40>>i;
+
+	for (i = 0; i < 5; i++) {
+		kr = 0x10 >> i;
+		divv = 0x40 >> i;
 		costab = pnts[i];
-		for(k=0;k<kr;k++)
+		for (k = 0; k < kr; k++)
 			costab[k] = 1.0 / (2.0 * cos(M_PI * ((double) k * 2.0 + 1.0) / (double) divv));
 	}
 
@@ -52,30 +53,26 @@
 
 void make_decode_tables_scale(struct mpstr *mp, long scaleval)
 {
-  int i,j;
-  real *table;
-  
-  table = mp->decwin;
-  scaleval = -scaleval;
-  for(i=0,j=0;i<256;i++,j++,table+=32)
-  {
-    if(table < (mp->decwin)+512+16)
-      table[16] = table[0] = (double) intwinbase[j] / 65536.0 * (double) scaleval;
-    if(i % 32 == 31)
-      table -= 1023;
-    if(i % 64 == 63)
-      scaleval = - scaleval;
-  }
-
-  for( /* i=256 */ ;i<512;i++,j--,table+=32)
-  {
-    if(table < (mp->decwin)+512+16)
-      table[16] = table[0] = (double) intwinbase[j] / 65536.0 * (double) scaleval;
-    if(i % 32 == 31)
-      table -= 1023;
-    if(i % 64 == 63)
-      scaleval = - scaleval;
-  }
-}
+	int i, j;
+	real *table;
 
+	table = mp->decwin;
+	scaleval = -scaleval;
+	for (i = 0, j = 0; i < 256; i++, j++, table += 32) {
+		if (table < (mp->decwin) + 512 + 16)
+			table[16] = table[0] = (double) intwinbase[j] / 65536.0 * (double) scaleval;
+		if (i % 32 == 31)
+			table -= 1023;
+		if (i % 64 == 63)
+			scaleval = -scaleval;
+	}
 
+	for ( /* i=256 */ ; i < 512; i++, j--, table += 32) {
+		if (table < (mp->decwin) + 512 + 16)
+			table[16] = table[0] = (double) intwinbase[j] / 65536.0 * (double) scaleval;
+		if (i % 32 == 31)
+			table -= 1023;
+		if (i % 64 == 63)
+			scaleval = -scaleval;
+	}
+}

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_sndfile/mod_sndfile.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_sndfile/mod_sndfile.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/formats/mod_sndfile/mod_sndfile.c	Fri Mar 30 12:19:18 2007
@@ -87,8 +87,8 @@
 	map = switch_core_hash_find(globals.format_hash, ext);
 
 	if (mode & SFM_WRITE) {
-		sf_count_t  frames = 0 ;
-		
+		sf_count_t frames = 0;
+
 		context->sfinfo.channels = handle->channels;
 		context->sfinfo.samplerate = handle->samplerate;
 		if (handle->samplerate == 8000 || handle->samplerate == 16000) {
@@ -99,9 +99,9 @@
 			context->sfinfo.format |= SF_FORMAT_PCM_32;
 		}
 
-        sf_command (context->handle, SFC_FILE_TRUNCATE, &frames, sizeof (frames));
-	} 
-	
+		sf_command(context->handle, SFC_FILE_TRUNCATE, &frames, sizeof(frames));
+	}
+
 	if (map) {
 		context->sfinfo.format |= map->format;
 	}
@@ -134,23 +134,22 @@
 		context->sfinfo.format = SF_FORMAT_RAW | SF_FORMAT_ALAW;
 		context->sfinfo.channels = 1;
 		context->sfinfo.samplerate = 8000;
-	} 
-	
-	if ((mode & SFM_WRITE) && sf_format_check (&context->sfinfo) == 0) {
+	}
+
+	if ((mode & SFM_WRITE) && sf_format_check(&context->sfinfo) == 0) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error : file format is invalid (0x%08X).\n", context->sfinfo.format);
 		return SWITCH_STATUS_GENERR;
 	};
-	
+
 	if ((context->handle = sf_open(path, mode, &context->sfinfo)) == 0) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening File [%s] [%s]\n", path,
-							  sf_strerror(context->handle));
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening File [%s] [%s]\n", path, sf_strerror(context->handle));
 		return SWITCH_STATUS_GENERR;
 	}
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Opening File [%s] %dhz\n", path, context->sfinfo.samplerate);
 	handle->samples = (unsigned int) context->sfinfo.frames;
 	handle->samplerate = context->sfinfo.samplerate;
-	handle->channels = (uint8_t)context->sfinfo.channels;
+	handle->channels = (uint8_t) context->sfinfo.channels;
 	handle->format = context->sfinfo.format;
 	handle->sections = context->sfinfo.sections;
 	handle->seekable = context->sfinfo.seekable;
@@ -233,7 +232,7 @@
 {
 	sndfile_context *context = handle->private_info;
 
-	return sf_set_string(context->handle, (int)col, string) ? SWITCH_STATUS_FALSE : SWITCH_STATUS_SUCCESS;
+	return sf_set_string(context->handle, (int) col, string) ? SWITCH_STATUS_FALSE : SWITCH_STATUS_SUCCESS;
 }
 
 static switch_status_t sndfile_file_get_string(switch_file_handle_t *handle, switch_audio_col_t col, const char **string)
@@ -241,7 +240,7 @@
 	sndfile_context *context = handle->private_info;
 	const char *s;
 
-	if ((s = sf_get_string(context->handle, (int)col))) {
+	if ((s = sf_get_string(context->handle, (int) col))) {
 		*string = s;
 		return SWITCH_STATUS_SUCCESS;
 	}
@@ -287,7 +286,7 @@
 	char *extras[] = { "r8", "r16", "r24", "r32", "gsm", "ul", "al", NULL };
 	int exlen = (sizeof(extras) / sizeof(extras[0]));
 	buffer[0] = 0;
-	
+
 	sf_command(NULL, SFC_GET_LIB_VERSION, buffer, sizeof(buffer));
 	if (strlen(buffer) < 1) {
 		switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, "Line %d: could not retrieve lib version.\n", __LINE__);
@@ -296,8 +295,7 @@
 
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "\nLibSndFile Version : %s Supported Formats\n", buffer);
-	switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO,
-						  "================================================================================\n");
+	switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "================================================================================\n");
 	sf_command(NULL, SFC_GET_FORMAT_MAJOR_COUNT, &major_count, sizeof(int));
 	sf_command(NULL, SFC_GET_FORMAT_SUBTYPE_COUNT, &subtype_count, sizeof(int));
 
@@ -327,11 +325,11 @@
 			map->ext = switch_core_permanent_strdup(info.extension);
 			map->uext = switch_core_permanent_strdup(info.extension);
 			map->format = info.format;
-			for(p = map->ext; *p; p++) {
-				*p = (char)tolower(*p);
+			for (p = map->ext; *p; p++) {
+				*p = (char) tolower(*p);
 			}
-			for(p = map->uext; *p; p++) {
-				*p = (char)toupper(*p);
+			for (p = map->uext; *p; p++) {
+				*p = (char) toupper(*p);
 			}
 			switch_core_hash_insert(globals.format_hash, map->ext, map);
 			switch_core_hash_insert(globals.format_hash, map->uext, map);
@@ -339,16 +337,16 @@
 		}
 		format = info.format;
 
-		for (s = 0; s < subtype_count; s++) {			
+		for (s = 0; s < subtype_count; s++) {
 			info.format = s;
 			sf_command(NULL, SFC_GET_FORMAT_SUBTYPE, &info, sizeof(info));
 			format = (format & SF_FORMAT_TYPEMASK) | info.format;
 			sfinfo.format = format;
 			/*
-			if (sf_format_check(&sfinfo)) {
-				switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_DEBUG, "   %s\n", info.name);
-			}
-			*/
+			   if (sf_format_check(&sfinfo)) {
+			   switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_DEBUG, "   %s\n", info.name);
+			   }
+			 */
 		}
 
 	}
@@ -358,9 +356,8 @@
 
 
 
-	switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_NOTICE,
-						  "================================================================================\n");
-	
+	switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_NOTICE, "================================================================================\n");
+
 	return SWITCH_STATUS_SUCCESS;
 }
 
@@ -373,7 +370,7 @@
 	}
 
 	switch_core_hash_init(&globals.format_hash, module_pool);
-	
+
 	if (setup_formats() != SWITCH_STATUS_SUCCESS) {
 		return SWITCH_STATUS_FALSE;
 	}

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_mono/mod_mono.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_mono/mod_mono.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_mono/mod_mono.c	Fri Mar 30 12:19:18 2007
@@ -39,13 +39,13 @@
 //#include <gc/gc.h>
 #include <switch.h>
 
-#define SWITCH_MONO_MODULES  "mono/" 
+#define SWITCH_MONO_MODULES  "mono/"
 #define SWITCH_MONO_LIBDIR   "lib/"
 #define SWITCH_MONO_ASSEMBLY "FreeSwitch.dll"
 
 /* Module functions */
 switch_status_t mod_mono_load_modules(const char *module_dir);
-MonoClass* mod_mono_find_assembly_class(MonoImage *image);
+MonoClass *mod_mono_find_assembly_class(MonoImage * image);
 
 /* Managed functions */
 void mod_mono_switch_console_printf(switch_text_channel_t channel, char *file, const char *func, int line, char *fmt, char *msg);
@@ -61,7 +61,7 @@
 typedef struct {
 	MonoAssembly *assembly;
 	MonoClass *class;
-	MonoObject *object;	
+	MonoObject *object;
 } mono_plugin;
 
 static switch_loadable_module_interface_t mono_module_interface = {
@@ -83,17 +83,17 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not allocate memory pool\n");
 		return SWITCH_STATUS_FALSE;
 	}
-	
+
 	/* Initialise plugin hash */
 	if (switch_core_hash_init(&globals.plugins, mono_pool) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not initialise plugins hash\n");
 		return SWITCH_STATUS_FALSE;
-	}		
-	
+	}
+
 	/* Construct the path to the FreeSwitch assembly, then check to make sure it exists */
-	switch_size_t assembly_dir_len  = strlen(SWITCH_GLOBAL_dirs.base_dir) + strlen(SWITCH_MONO_LIBDIR) + 2; /* Account for / and \0 */
+	switch_size_t assembly_dir_len = strlen(SWITCH_GLOBAL_dirs.base_dir) + strlen(SWITCH_MONO_LIBDIR) + 2;	/* Account for / and \0 */
 	switch_size_t assembly_file_len = assembly_dir_len + strlen(SWITCH_MONO_ASSEMBLY);
-	char *assembly_dir  = (char *) switch_core_alloc(mono_pool, assembly_dir_len);
+	char *assembly_dir = (char *) switch_core_alloc(mono_pool, assembly_dir_len);
 	char *assembly_file = (char *) switch_core_alloc(mono_pool, assembly_file_len);
 
 	apr_finfo_t *assembly_finfo = (apr_finfo_t *) switch_core_alloc(mono_pool, sizeof(*assembly_finfo));
@@ -108,22 +108,21 @@
 
 	/* Mono wants to know where it will be able to find the FreeSwitch assembly if it's not in the GAC */
 	if (getenv("MONO_PATH") != NULL) {
-		switch_size_t mono_path_len = strlen(getenv("MONO_PATH")) + strlen(assembly_dir) + 2; /* Account for : and \0 */ 
+		switch_size_t mono_path_len = strlen(getenv("MONO_PATH")) + strlen(assembly_dir) + 2;	/* Account for : and \0 */
 		char *mono_path = (char *) switch_core_alloc(mono_pool, mono_path_len);
-	
+
 		snprintf(mono_path, mono_path_len, "%s:%s", getenv("MONO_PATH"), assembly_dir);
 
 		setenv("MONO_PATH", mono_path, 1);
-	}
-	else
+	} else
 		setenv("MONO_PATH", assembly_dir, 1);
 
 	/* Now find where our managed modules are */
-	switch_size_t module_dir_len = strlen(SWITCH_GLOBAL_dirs.mod_dir) + strlen(SWITCH_MONO_MODULES) + 2; /* Account for / and \0 */
+	switch_size_t module_dir_len = strlen(SWITCH_GLOBAL_dirs.mod_dir) + strlen(SWITCH_MONO_MODULES) + 2;	/* Account for / and \0 */
 	char *module_dir = (char *) switch_core_alloc(mono_pool, module_dir_len);
 
 	snprintf(module_dir, module_dir_len, "%s/%s", SWITCH_GLOBAL_dirs.mod_dir, SWITCH_MONO_MODULES);
-	
+
 	/* Initialise the mono domain */
 	if (!(globals.domain = mono_jit_init("freeswitch"))) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error initialising mono runtime\n");
@@ -139,7 +138,7 @@
 		return SWITCH_STATUS_FALSE;
 	}
 
-	/* Finally, go through and initialise each plugin before returning SUCCESS */ 
+	/* Finally, go through and initialise each plugin before returning SUCCESS */
 	switch_hash_index_t *p = NULL;
 
 	for (p = switch_hash_first(mono_pool, globals.plugins); p; p = switch_hash_next(p)) {
@@ -150,10 +149,10 @@
 
 		switch_hash_this(p, &key, key_length, &value);
 		plugin = (mono_plugin *) value;
-		
+
 		mono_runtime_object_init(plugin->object);
 	}
-	
+
 	return SWITCH_STATUS_SUCCESS;
 }
 
@@ -175,16 +174,16 @@
 /*
  * This function will load the managed modules
  *
- */ 
+ */
 switch_status_t mod_mono_load_modules(const char *module_dir)
 {
 	apr_finfo_t *module_finfo = (apr_finfo_t *) switch_core_alloc(mono_pool, sizeof(*module_finfo));
-	
+
 	if (apr_stat(module_finfo, module_dir, 0, mono_pool) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not access module dir!.\n");
 		return SWITCH_STATUS_FALSE;
 	}
-	
+
 	apr_dir_t *module_dir_handle;
 	char *file;
 	size_t len;
@@ -196,22 +195,21 @@
 	MonoAssembly *assembly;
 	MonoImage *image;
 	gpointer iter;
-	iter=NULL;
-	mono_plugin *plugin=NULL;
+	iter = NULL;
+	mono_plugin *plugin = NULL;
 
 	if (apr_dir_open(&module_dir_handle, module_dir, mono_pool) != SWITCH_STATUS_SUCCESS)
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Could not open directory: %s\n", module_dir);
 
 	/* Read the modules directory */
-	while (apr_dir_read(&finfo, finfo_flags, module_dir_handle) == SWITCH_STATUS_SUCCESS)
-	{
+	while (apr_dir_read(&finfo, finfo_flags, module_dir_handle) == SWITCH_STATUS_SUCCESS) {
 		assembly = (MonoAssembly *) switch_core_alloc(mono_pool, sizeof(assembly));
 		image = (MonoImage *) switch_core_alloc(mono_pool, sizeof(image));
 		const char *fname = finfo.fname;
 
 		if (finfo.filetype != APR_REG)
 			continue;
-                        
+
 		if (!fname)
 			fname = finfo.name;
 
@@ -222,7 +220,7 @@
 			continue;
 
 		len = strlen(module_dir) + strlen(fname) + 2;
-		file = (char *)switch_core_alloc(mono_pool, len);
+		file = (char *) switch_core_alloc(mono_pool, len);
 		snprintf(file, len, "%s%s", module_dir, fname);
 
 		/* Attempt to open the assembly */
@@ -233,13 +231,13 @@
 			continue;
 		}
 
-		/* Get the image from assembly */	
+		/* Get the image from assembly */
 		image = mono_assembly_get_image(assembly);
-	
-		plugin = (mono_plugin *)switch_core_alloc(mono_pool, sizeof(*plugin));
+
+		plugin = (mono_plugin *) switch_core_alloc(mono_pool, sizeof(*plugin));
 
 		plugin->assembly = assembly;
-		plugin->class    = mod_mono_find_assembly_class(mono_assembly_get_image(plugin->assembly));
+		plugin->class = mod_mono_find_assembly_class(mono_assembly_get_image(plugin->assembly));
 
 		if (!plugin->class)
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "No plugin class\n");
@@ -249,30 +247,29 @@
 		switch_core_hash_insert(globals.plugins, (char *) mono_image_get_name(mono_assembly_get_image(assembly)), plugin);
 
 		plugin = NULL;
-	}	
+	}
 	return SWITCH_STATUS_SUCCESS;
 }
 
 /*
  *
- */ 
-MonoClass* mod_mono_find_assembly_class(MonoImage *image)
+ */
+MonoClass *mod_mono_find_assembly_class(MonoImage * image)
 {
 	MonoClass *class, *parent_class = NULL;
 	int i, total;
 
 	total = mono_image_get_table_rows(image, MONO_TABLE_TYPEDEF);
-	
-	for (i = 1; i <= total; ++i)
-	{
+
+	for (i = 1; i <= total; ++i) {
 		class = mono_class_get(image, MONO_TOKEN_TYPE_DEF | i);
 		parent_class = mono_class_get_parent(class);
-		
-		if (parent_class) 
+
+		if (parent_class)
 			if (!strcmp("Module", mono_class_get_name(parent_class)))
 				return class;
 	}
-						
+
 	return NULL;
 }
 

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_perl/mod_perl.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_perl/mod_perl.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_perl/mod_perl.c	Fri Mar 30 12:19:18 2007
@@ -50,7 +50,7 @@
 } globals;
 
 
-static void destroy_perl(PerlInterpreter **to_destroy)
+static void destroy_perl(PerlInterpreter ** to_destroy)
 {
 	perl_destruct(*to_destroy);
 	perl_free(*to_destroy);
@@ -59,7 +59,7 @@
 
 static PerlInterpreter *clone_perl(void)
 {
-	return perl_clone(globals.my_perl, CLONEf_COPY_STACKS|CLONEf_KEEP_PTR_TABLE);
+	return perl_clone(globals.my_perl, CLONEf_COPY_STACKS | CLONEf_KEEP_PTR_TABLE);
 }
 
 
@@ -68,10 +68,7 @@
 	char *uuid = switch_core_session_get_uuid(session);
 	char code[1024];
 	PerlInterpreter *my_perl = clone_perl();
-	sprintf(code, "package fs_perl;\n"
-			"$SWITCH_ENV{UUID} = \"%s\";\n"
-			"chdir(\"%s/perl\");\n",
-			uuid, SWITCH_GLOBAL_dirs.base_dir);
+	sprintf(code, "package fs_perl;\n" "$SWITCH_ENV{UUID} = \"%s\";\n" "chdir(\"%s/perl\");\n", uuid, SWITCH_GLOBAL_dirs.base_dir);
 
 	Perl_eval_pv(my_perl, code, TRUE);
 
@@ -84,8 +81,9 @@
 	/*.interface_name */ "perl",
 	/*.application_function */ perl_function,
 	NULL, NULL, NULL,
-	/* flags */ SAF_NONE, /* should we support no media mode here?  If so, we need to detect the mode, and either disable the media functions or indicate media if/when we need */
-	/*.next*/ NULL
+	/* flags */ SAF_NONE,
+	/* should we support no media mode here?  If so, we need to detect the mode, and either disable the media functions or indicate media if/when we need */
+	/*.next */ NULL
 };
 
 static switch_loadable_module_interface_t perl_module_interface = {
@@ -102,7 +100,7 @@
 };
 
 
-SWITCH_MOD_DECLARE(switch_status_t) switch_module_shutdown(void) 
+SWITCH_MOD_DECLARE(switch_status_t) switch_module_shutdown(void)
 {
 	if (globals.my_perl) {
 		perl_destruct(globals.my_perl);
@@ -118,7 +116,7 @@
 
 	PerlInterpreter *my_perl;
 	char code[1024];
-	
+
 	if (!(my_perl = perl_alloc())) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not allocate perl intrepreter\n");
 		return SWITCH_STATUS_MEMERR;
@@ -131,7 +129,7 @@
 	perl_run(my_perl);
 	globals.my_perl = my_perl;
 	sprintf(code, "use lib '%s/perl';use fs_perl;use freeswitch\n", SWITCH_GLOBAL_dirs.base_dir);
-    Perl_eval_pv(my_perl, code, TRUE);
+	Perl_eval_pv(my_perl, code, TRUE);
 
 
 	/* connect my internal structure to the blank pointer passed to me */

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_perl/perlxsi.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_perl/perlxsi.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_perl/perlxsi.c	Fri Mar 30 12:19:18 2007
@@ -4,12 +4,11 @@
 #include <EXTERN.h>
 #include <perl.h>
 
-EXTERN_C void xs_init (pTHX);
+EXTERN_C void xs_init(pTHX);
 
-EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);
+EXTERN_C void boot_DynaLoader(pTHX_ CV * cv);
 
-EXTERN_C void
-xs_init(pTHX)
+EXTERN_C void xs_init(pTHX)
 {
 	char *file = __FILE__;
 	dXSUB_SYS;

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_perl/switch_swig_wrap.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_perl/switch_swig_wrap.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_perl/switch_swig_wrap.c	Fri Mar 30 12:19:18 2007
@@ -24,8 +24,8 @@
 #define SWIG_TypeName        SWIG_Perl_TypeName
 #define SWIG_TypeQuery       SWIG_Perl_TypeQuery
 #define SWIG_TypeClientData  SWIG_Perl_TypeClientData
-#define SWIG_PackData        SWIG_Perl_PackData 
-#define SWIG_UnpackData      SWIG_Perl_UnpackData 
+#define SWIG_PackData        SWIG_Perl_PackData
+#define SWIG_UnpackData      SWIG_Perl_UnpackData
 
 
 /***********************************************************************
@@ -78,194 +78,205 @@
 extern "C" {
 #endif
 
-typedef void *(*swig_converter_func)(void *);
-typedef struct swig_type_info *(*swig_dycast_func)(void **);
+	typedef void *(*swig_converter_func) (void *);
+	typedef struct swig_type_info *(*swig_dycast_func) (void **);
 
-typedef struct swig_type_info {
-  const char             *name;
-  swig_converter_func     converter;
-  const char             *str;
-  void                   *clientdata;
-  swig_dycast_func        dcast;
-  struct swig_type_info  *next;
-  struct swig_type_info  *prev;
-} swig_type_info;
+	typedef struct swig_type_info {
+		const char *name;
+		swig_converter_func converter;
+		const char *str;
+		void *clientdata;
+		swig_dycast_func dcast;
+		struct swig_type_info *next;
+		struct swig_type_info *prev;
+	} swig_type_info;
 
 #ifdef SWIG_NOINCLUDE
 
-SWIGIMPORT(swig_type_info *) SWIG_TypeRegister(swig_type_info *);
-SWIGIMPORT(swig_type_info *) SWIG_TypeCheck(char *c, swig_type_info *);
-SWIGIMPORT(void *)           SWIG_TypeCast(swig_type_info *, void *);
-SWIGIMPORT(swig_type_info *) SWIG_TypeDynamicCast(swig_type_info *, void **);
-SWIGIMPORT(const char *)     SWIG_TypeName(const swig_type_info *);
-SWIGIMPORT(swig_type_info *) SWIG_TypeQuery(const char *);
-SWIGIMPORT(void)             SWIG_TypeClientData(swig_type_info *, void *);
-SWIGIMPORT(char *)           SWIG_PackData(char *, void *, int);
-SWIGIMPORT(char *)           SWIG_UnpackData(char *, void *, int);
+	               SWIGIMPORT(swig_type_info *) SWIG_TypeRegister(swig_type_info *);
+	               SWIGIMPORT(swig_type_info *) SWIG_TypeCheck(char *c, swig_type_info *);
+	     SWIGIMPORT(void *) SWIG_TypeCast(swig_type_info *, void *);
+	     SWIGIMPORT(swig_type_info *) SWIG_TypeDynamicCast(swig_type_info *, void **);
+	     SWIGIMPORT(const char *) SWIG_TypeName(const swig_type_info *);
+	      SWIGIMPORT(swig_type_info *) SWIG_TypeQuery(const char *);
+	     SWIGIMPORT(void) SWIG_TypeClientData(swig_type_info *, void *);
+	     SWIGIMPORT(char *) SWIG_PackData(char *, void *, int);
+	    SWIGIMPORT(char *) SWIG_UnpackData(char *, void *, int);
 
 #else
 
-static swig_type_info *swig_type_list = 0;
+	static swig_type_info *swig_type_list = 0;
 
 /* Register a type mapping with the type-checking */
-SWIGRUNTIME(swig_type_info *)
-SWIG_TypeRegister(swig_type_info *ti) {
-  swig_type_info *tc, *head, *ret, *next;
-  /* Check to see if this type has already been registered */
-  tc = swig_type_list;
-  while (tc) {
-    if (strcmp(tc->name, ti->name) == 0) {
-      /* Already exists in the table.  Just add additional types to the list */
-      if (tc->clientdata) ti->clientdata = tc->clientdata;
-      head = tc;
-      next = tc->next;
-      goto l1;
-    }
-    tc = tc->prev;
-  }
-  head = ti;
-  next = 0;
-
-  /* Place in list */
-  ti->prev = swig_type_list;
-  swig_type_list = ti;
-
-  /* Build linked lists */
-  l1:
-  ret = head;
-  tc = ti + 1;
-  /* Patch up the rest of the links */
-  while (tc->name) {
-    head->next = tc;
-    tc->prev = head;
-    head = tc;
-    tc++;
-  }
-  if (next) next->prev = head;
-  head->next = next;
-  return ret;
-}
+	               SWIGRUNTIME(swig_type_info *)
+	               SWIG_TypeRegister(swig_type_info * ti) {
+		swig_type_info *tc, *head, *ret, *next;
+		/* Check to see if this type has already been registered */
+		               tc = swig_type_list;
+		while          (tc) {
+			if (strcmp(tc->name, ti->name) == 0) {
+				/* Already exists in the table.  Just add additional types to the list */
+				if (tc->clientdata)
+					ti->clientdata = tc->clientdata;
+				head = tc;
+				next = tc->next;
+				goto l1;
+			}
+			tc = tc->prev;
+		}
+		head = ti;
+		next = 0;
+
+		/* Place in list */
+		ti->prev = swig_type_list;
+		swig_type_list = ti;
+
+		/* Build linked lists */
+	  l1:
+		ret = head;
+		tc = ti + 1;
+		/* Patch up the rest of the links */
+		while (tc->name) {
+			head->next = tc;
+			tc->prev = head;
+			head = tc;
+			tc++;
+		}
+		if (next)
+			next->prev = head;
+		head->next = next;
+		return ret;
+	}
 
 /* Check the typename */
-SWIGRUNTIME(swig_type_info *) 
-SWIG_TypeCheck(char *c, swig_type_info *ty) {
-  swig_type_info *s;
-  if (!ty) return 0;        /* Void pointer */
-  s = ty->next;             /* First element always just a name */
-  do {
-    if (strcmp(s->name,c) == 0) {
-      if (s == ty->next) return s;
-      /* Move s to the top of the linked list */
-      s->prev->next = s->next;
-      if (s->next) {
-        s->next->prev = s->prev;
-      }
-      /* Insert s as second element in the list */
-      s->next = ty->next;
-      if (ty->next) ty->next->prev = s;
-      ty->next = s;
-      s->prev = ty;
-      return s;
-    }
-    s = s->next;
-  } while (s && (s != ty->next));
-  return 0;
-}
+	SWIGRUNTIME(swig_type_info *)
+		SWIG_TypeCheck(char *c, swig_type_info * ty) {
+		swig_type_info *s;
+		if (!ty)
+			return 0;			/* Void pointer */
+		s = ty->next;			/* First element always just a name */
+		do {
+			if (strcmp(s->name, c) == 0) {
+				if (s == ty->next)
+					return s;
+				/* Move s to the top of the linked list */
+				s->prev->next = s->next;
+				if (s->next) {
+					s->next->prev = s->prev;
+				}
+				/* Insert s as second element in the list */
+				s->next = ty->next;
+				if (ty->next)
+					ty->next->prev = s;
+				ty->next = s;
+				s->prev = ty;
+				return s;
+			}
+			s = s->next;
+		} while (s && (s != ty->next));
+		return 0;
+	}
 
 /* Cast a pointer up an inheritance hierarchy */
-SWIGRUNTIME(void *) 
-SWIG_TypeCast(swig_type_info *ty, void *ptr) {
-  if ((!ty) || (!ty->converter)) return ptr;
-  return (*ty->converter)(ptr);
-}
+	SWIGRUNTIME(void *)
+		SWIG_TypeCast(swig_type_info * ty, void *ptr) {
+		if ((!ty) || (!ty->converter))
+			return ptr;
+		return (*ty->converter) (ptr);
+	}
 
 /* Dynamic pointer casting. Down an inheritance hierarchy */
-SWIGRUNTIME(swig_type_info *) 
-SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr) {
-  swig_type_info *lastty = ty;
-  if (!ty || !ty->dcast) return ty;
-  while (ty && (ty->dcast)) {
-    ty = (*ty->dcast)(ptr);
-    if (ty) lastty = ty;
-  }
-  return lastty;
-}
+	SWIGRUNTIME(swig_type_info *)
+		SWIG_TypeDynamicCast(swig_type_info * ty, void **ptr) {
+		swig_type_info *lastty = ty;
+		if (!ty || !ty->dcast)
+			return ty;
+		while (ty && (ty->dcast)) {
+			ty = (*ty->dcast) (ptr);
+			if (ty)
+				lastty = ty;
+		}
+		return lastty;
+	}
 
 /* Return the name associated with this type */
-SWIGRUNTIME(const char *)
-SWIG_TypeName(const swig_type_info *ty) {
-  return ty->name;
-}
+	SWIGRUNTIME(const char *)
+		SWIG_TypeName(const swig_type_info * ty) {
+		return ty->name;
+	}
 
 /* Search for a swig_type_info structure */
-SWIGRUNTIME(swig_type_info *)
-SWIG_TypeQuery(const char *name) {
-  swig_type_info *ty = swig_type_list;
-  while (ty) {
-    if (ty->str && (strcmp(name,ty->str) == 0)) return ty;
-    if (ty->name && (strcmp(name,ty->name) == 0)) return ty;
-    ty = ty->prev;
-  }
-  return 0;
-}
+	SWIGRUNTIME(swig_type_info *)
+		SWIG_TypeQuery(const char *name) {
+		swig_type_info *ty = swig_type_list;
+		while (ty) {
+			if (ty->str && (strcmp(name, ty->str) == 0))
+				return ty;
+			if (ty->name && (strcmp(name, ty->name) == 0))
+				return ty;
+			ty = ty->prev;
+		}
+		return 0;
+	}
 
 /* Set the clientdata field for a type */
-SWIGRUNTIME(void)
-SWIG_TypeClientData(swig_type_info *ti, void *clientdata) {
-  swig_type_info *tc, *equiv;
-  if (ti->clientdata == clientdata) return;
-  ti->clientdata = clientdata;
-  equiv = ti->next;
-  while (equiv) {
-    if (!equiv->converter) {
-      tc = swig_type_list;
-      while (tc) {
-        if ((strcmp(tc->name, equiv->name) == 0))
-          SWIG_TypeClientData(tc,clientdata);
-        tc = tc->prev;
-      }
-    }
-    equiv = equiv->next;
-  }
-}
+	SWIGRUNTIME(void)
+		SWIG_TypeClientData(swig_type_info * ti, void *clientdata) {
+		swig_type_info *tc, *equiv;
+		if (ti->clientdata == clientdata)
+			return;
+		ti->clientdata = clientdata;
+		equiv = ti->next;
+		while (equiv) {
+			if (!equiv->converter) {
+				tc = swig_type_list;
+				while (tc) {
+					if ((strcmp(tc->name, equiv->name) == 0))
+						SWIG_TypeClientData(tc, clientdata);
+					tc = tc->prev;
+				}
+			}
+			equiv = equiv->next;
+		}
+	}
 
 /* Pack binary data into a string */
-SWIGRUNTIME(char *)
-SWIG_PackData(char *c, void *ptr, int sz) {
-  static char hex[17] = "0123456789abcdef";
-  int i;
-  unsigned char *u = (unsigned char *) ptr;
-  register unsigned char uu;
-  for (i = 0; i < sz; i++,u++) {
-    uu = *u;
-    *(c++) = hex[(uu & 0xf0) >> 4];
-    *(c++) = hex[uu & 0xf];
-  }
-  return c;
-}
+	SWIGRUNTIME(char *)
+	     SWIG_PackData(char *c, void *ptr, int sz) {
+		static char hex[17] = "0123456789abcdef";
+		int i;
+		unsigned char *u = (unsigned char *) ptr;
+		register unsigned char uu;
+		for (i = 0; i < sz; i++, u++) {
+			uu = *u;
+			*(c++) = hex[(uu & 0xf0) >> 4];
+			*(c++) = hex[uu & 0xf];
+		}
+		return c;
+	}
 
 /* Unpack binary data from a string */
-SWIGRUNTIME(char *)
-SWIG_UnpackData(char *c, void *ptr, int sz) {
-  register unsigned char uu = 0;
-  register int d;
-  unsigned char *u = (unsigned char *) ptr;
-  int i;
-  for (i = 0; i < sz; i++, u++) {
-    d = *(c++);
-    if ((d >= '0') && (d <= '9'))
-      uu = ((d - '0') << 4);
-    else if ((d >= 'a') && (d <= 'f'))
-      uu = ((d - ('a'-10)) << 4);
-    d = *(c++);
-    if ((d >= '0') && (d <= '9'))
-      uu |= (d - '0');
-    else if ((d >= 'a') && (d <= 'f'))
-      uu |= (d - ('a'-10));
-    *u = uu;
-  }
-  return c;
-}
+	SWIGRUNTIME(char *)
+		SWIG_UnpackData(char *c, void *ptr, int sz) {
+		register unsigned char uu = 0;
+		register int d;
+		unsigned char *u = (unsigned char *) ptr;
+		int i;
+		for (i = 0; i < sz; i++, u++) {
+			d = *(c++);
+			if ((d >= '0') && (d <= '9'))
+				uu = ((d - '0') << 4);
+			else if ((d >= 'a') && (d <= 'f'))
+				uu = ((d - ('a' - 10)) << 4);
+			d = *(c++);
+			if ((d >= '0') && (d <= '9'))
+				uu |= (d - '0');
+			else if ((d >= 'a') && (d <= 'f'))
+				uu |= (d - ('a' - 10));
+			*u = uu;
+		}
+		return c;
+	}
 
 #endif
 
@@ -304,37 +315,30 @@
 #ifdef __cplusplus
 }
 #endif
-
 /* Macro to call an XS function */
-
-#ifdef PERL_OBJECT 
-#  define SWIG_CALLXS(_name) _name(cv,pPerl) 
-#else 
-#  ifndef MULTIPLICITY 
-#    define SWIG_CALLXS(_name) _name(cv) 
-#  else 
-#    define SWIG_CALLXS(_name) _name(PERL_GET_THX, cv) 
-#  endif 
-#endif 
-
+#ifdef PERL_OBJECT
+#  define SWIG_CALLXS(_name) _name(cv,pPerl)
+#else
+#  ifndef MULTIPLICITY
+#    define SWIG_CALLXS(_name) _name(cv)
+#  else
+#    define SWIG_CALLXS(_name) _name(PERL_GET_THX, cv)
+#  endif
+#endif
 /* Contract support */
-
 #define SWIG_contract_assert(expr,msg) if (!(expr)) { SWIG_croak(msg); } else
-
 /* Note: SwigMagicFuncHack is a typedef used to get the C++ compiler to just shut up already */
-
 #ifdef PERL_OBJECT
 #define MAGIC_PPERL  CPerlObj *pPerl = (CPerlObj *) this;
-typedef int (CPerlObj::*SwigMagicFunc)(SV *, MAGIC *);
+typedef int (CPerlObj::*SwigMagicFunc) (SV *, MAGIC *);
 
 #ifdef __cplusplus
 extern "C" {
 #endif
-typedef int (CPerlObj::*SwigMagicFuncHack)(SV *, MAGIC *);
+	typedef int (CPerlObj::*SwigMagicFuncHack) (SV *, MAGIC *);
 #ifdef __cplusplus
 }
 #endif
-
 #define SWIG_MAGIC(a,b) (SV *a, MAGIC *b)
 #define SWIGCLASS_STATIC
 #else
@@ -342,37 +346,31 @@
 #define SWIGCLASS_STATIC static
 #ifndef MULTIPLICITY
 #define SWIG_MAGIC(a,b) (SV *a, MAGIC *b)
-typedef int (*SwigMagicFunc)(SV *, MAGIC *);
+typedef int (*SwigMagicFunc) (SV *, MAGIC *);
 
 #ifdef __cplusplus
 extern "C" {
 #endif
-typedef int (*SwigMagicFuncHack)(SV *, MAGIC *);
+	typedef int (*SwigMagicFuncHack) (SV *, MAGIC *);
 #ifdef __cplusplus
 }
 #endif
-
-
 #else
 #define SWIG_MAGIC(a,b) (struct interpreter *interp, SV *a, MAGIC *b)
-typedef int (*SwigMagicFunc)(struct interpreter *, SV *, MAGIC *);
+typedef int (*SwigMagicFunc) (struct interpreter *, SV *, MAGIC *);
 #ifdef __cplusplus
 extern "C" {
 #endif
-typedef int (*SwigMagicFuncHack)(struct interpreter *, SV *, MAGIC *);
+	typedef int (*SwigMagicFuncHack) (struct interpreter *, SV *, MAGIC *);
 #ifdef __cplusplus
 }
 #endif
-
 #endif
 #endif
-
 #if defined(WIN32) && defined(PERL_OBJECT) && !defined(PerlIO_exportFILE)
 #define PerlIO_exportFILE(fh,fl) (FILE*)(fh)
 #endif
-
 /* Modifications for newer Perl 5.005 releases */
-
 #if !defined(PERL_REVISION) || ((PERL_REVISION >= 5) && ((PERL_VERSION < 5) || ((PERL_VERSION == 5) && (PERL_SUBVERSION < 50))))
 #  ifndef PL_sv_yes
 #    define PL_sv_yes sv_yes
@@ -384,9 +382,7 @@
 #    define PL_na na
 #  endif
 #endif
-
 #include <stdlib.h>
-
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -447,187 +443,195 @@
 
 #ifdef SWIG_NOINCLUDE
 
-SWIGIMPORT(int)               SWIG_Perl_ConvertPtr(SWIG_MAYBE_PERL_OBJECT SV *, void **, swig_type_info *, int flags);
-SWIGIMPORT(void)              SWIG_Perl_MakePtr(SWIG_MAYBE_PERL_OBJECT SV *, void *, swig_type_info *, int flags);
-SWIGIMPORT(SV *)              SWIG_Perl_NewPointerObj(SWIG_MAYBE_PERL_OBJECT void *, swig_type_info *, int flags);
-SWIGIMPORT(void)              SWIG_Perl_MakePackedObj(SWIG_MAYBE_PERL_OBJECT SV *, void *, int, swig_type_info *);
-SWIGIMPORT(int)               SWIG_Perl_ConvertPacked(SWIG_MAYBE_PERL_OBJECT SV *, void *, int, swig_type_info *, int flags);
-SWIGIMPORT(swig_type_info *)  SWIG_Perl_TypeCheckRV(SWIG_MAYBE_PERL_OBJECT SV *rv, swig_type_info *ty);
-SWIGIMPORT(SV *)              SWIG_Perl_SetError(SWIG_MAYBE_PERL_OBJECT char *);
+	SWIGIMPORT(int) SWIG_Perl_ConvertPtr(SWIG_MAYBE_PERL_OBJECT SV *, void **, swig_type_info *, int flags);
+	    SWIGIMPORT(void) SWIG_Perl_MakePtr(SWIG_MAYBE_PERL_OBJECT SV *, void *, swig_type_info *, int flags);
+	    SWIGIMPORT(SV *) SWIG_Perl_NewPointerObj(SWIG_MAYBE_PERL_OBJECT void *, swig_type_info *, int flags);
+	    SWIGIMPORT(void) SWIG_Perl_MakePackedObj(SWIG_MAYBE_PERL_OBJECT SV *, void *, int, swig_type_info *);
+	    SWIGIMPORT(int) SWIG_Perl_ConvertPacked(SWIG_MAYBE_PERL_OBJECT SV *, void *, int, swig_type_info *, int flags);
+	    SWIGIMPORT(swig_type_info *) SWIG_Perl_TypeCheckRV(SWIG_MAYBE_PERL_OBJECT SV * rv, swig_type_info * ty);
+	    SWIGIMPORT(SV *) SWIG_Perl_SetError(SWIG_MAYBE_PERL_OBJECT char *);
 
 #else
 
-SWIGRUNTIME(swig_type_info *)
-SWIG_Perl_TypeCheckRV(SWIG_MAYBE_PERL_OBJECT SV *rv, swig_type_info *ty) {
-  swig_type_info *s;
-  if (!ty) return 0;        /* Void pointer */
-  s = ty->next;             /* First element always just a name */
-  do {
-    if (sv_derived_from(rv, (char *) s->name)) {
-      if (s == ty->next) return s;
-      /* Move s to the top of the linked list */
-      s->prev->next = s->next;
-      if (s->next) {
-        s->next->prev = s->prev;
-      }
-      /* Insert s as second element in the list */
-      s->next = ty->next;
-      if (ty->next) ty->next->prev = s;
-      ty->next = s;
-      s->prev = ty;
-      return s;
-    }
-    s = s->next;
-  } while (s && (s != ty->next));
-  return 0;
-}
+	     SWIGRUNTIME(swig_type_info *)
+	     SWIG_Perl_TypeCheckRV(SWIG_MAYBE_PERL_OBJECT SV * rv, swig_type_info * ty) {
+		swig_type_info *s;
+		if             (!ty)
+			               return 0;	/* Void pointer */
+		               s = ty->next;	/* First element always just a name */
+		do {
+			if (sv_derived_from(rv, (char *) s->name)) {
+				if (s == ty->next)
+					return s;
+				/* Move s to the top of the linked list */
+				s->prev->next = s->next;
+				if (s->next) {
+					s->next->prev = s->prev;
+				}
+				/* Insert s as second element in the list */
+				s->    next = ty->next;
+				if (ty->next)
+					ty->next->prev = s;
+				ty->next = s;
+				s->prev = ty;
+				return s;
+			}
+			s = s->next;
+		} while (s && (s != ty->next));
+		return 0;
+	}
 
 /* Function for getting a pointer value */
 
-SWIGRUNTIME(int) 
-SWIG_Perl_ConvertPtr(SWIG_MAYBE_PERL_OBJECT SV *sv, void **ptr, swig_type_info *_t, int flags) {
-  swig_type_info *tc;
-  void *voidptr = (void *)0;
-
-  /* If magical, apply more magic */
-  if (SvGMAGICAL(sv))
-    mg_get(sv);
-
-  /* Check to see if this is an object */
-  if (sv_isobject(sv)) {
-    SV *tsv = (SV*) SvRV(sv);
-    IV tmp = 0;
-    if ((SvTYPE(tsv) == SVt_PVHV)) {
-      MAGIC *mg;
-      if (SvMAGICAL(tsv)) {
-        mg = mg_find(tsv,'P');
-        if (mg) {
-          SV *rsv = mg->mg_obj;
-          if (sv_isobject(rsv)) {
-            tmp = SvIV((SV*)SvRV(rsv));
-          }
-        }
-      } else {
-        return -1;
-      }
-    } else {
-      tmp = SvIV((SV*)SvRV(sv));
-    }
-    voidptr = (void *)tmp;
-    if (!_t) {
-      *(ptr) = voidptr;
-      return 0;
-    }
-  } else if (! SvOK(sv)) {            /* Check for undef */
-    *(ptr) = (void *) 0;
-    return 0;
-  } else if (SvTYPE(sv) == SVt_RV) {  /* Check for NULL pointer */
-    *(ptr) = (void *) 0;
-    if (!SvROK(sv))
-      return 0;
-    else
-      return -1;
-  } else {                            /* Don't know what it is */
-    *(ptr) = (void *) 0;
-    return -1;
-  }
-  if (_t) {
-    /* Now see if the types match */
-    tc = SWIG_TypeCheckRV(sv,_t);
-    if (!tc) {
-      *ptr = voidptr;
-      return -1;
-    }
-    *ptr = SWIG_TypeCast(tc,voidptr);
-    return 0;
-  }
-  *ptr = voidptr;
-  return 0;
-}
-
-SWIGRUNTIME(void)
-SWIG_Perl_MakePtr(SWIG_MAYBE_PERL_OBJECT SV *sv, void *ptr, swig_type_info *t, int flags) {
-  if (ptr && (flags & SWIG_SHADOW)) {
-    SV *self;
-    SV *obj=newSV(0);
-    HV *hash=newHV();
-    HV *stash;
-    sv_setref_pv(obj, (char *) t->name, ptr);
-    stash=SvSTASH(SvRV(obj));
-    if (flags & SWIG_OWNER) {
-      HV *hv;
-      GV *gv=*(GV**)hv_fetch(stash, "OWNER", 5, TRUE);
-      if (!isGV(gv))
-        gv_init(gv, stash, "OWNER", 5, FALSE);
-      hv=GvHVn(gv);
-      hv_store_ent(hv, obj, newSViv(1), 0);
-    }
-    sv_magic((SV *)hash, (SV *)obj, 'P', Nullch, 0);
-    SvREFCNT_dec(obj);
-    self=newRV_noinc((SV *)hash);
-    sv_setsv(sv, self);
-    SvREFCNT_dec((SV *)self);
-    sv_bless(sv, stash);
-  }
-  else {
-    sv_setref_pv(sv, (char *) t->name, ptr);
-  }
-}
-
-SWIGRUNTIME(SV *)
-SWIG_Perl_NewPointerObj(SWIG_MAYBE_PERL_OBJECT void *ptr, swig_type_info *t, int flags) {
-  SV *result = sv_newmortal();
-  SWIG_MakePtr(result, ptr, t, flags);
-  return result;
-}
-
-SWIGRUNTIME(void)
-  SWIG_Perl_MakePackedObj(SWIG_MAYBE_PERL_OBJECT SV *sv, void *ptr, int sz, swig_type_info *type) {
-  char result[1024];
-  char *r = result;
-  if ((2*sz + 1 + strlen(type->name)) > 1000) return;
-  *(r++) = '_';
-  r = SWIG_PackData(r,ptr,sz);
-  strcpy(r,type->name);
-  sv_setpv(sv, result);
-}
+	SWIGRUNTIME(int)
+		SWIG_Perl_ConvertPtr(SWIG_MAYBE_PERL_OBJECT SV * sv, void **ptr, swig_type_info * _t, int flags) {
+		swig_type_info *tc;
+		void *voidptr = (void *) 0;
+
+		/* If magical, apply more magic */
+		if (SvGMAGICAL(sv))
+			mg_get(sv);
+
+		/* Check to see if this is an object */
+		if (sv_isobject(sv)) {
+			SV *tsv = (SV *) SvRV(sv);
+			IV tmp = 0;
+			if ((SvTYPE(tsv) == SVt_PVHV)) {
+				MAGIC *mg;
+				if (SvMAGICAL(tsv)) {
+					mg = mg_find(tsv, 'P');
+					if (mg) {
+						SV *rsv = mg->mg_obj;
+						if (sv_isobject(rsv)) {
+							tmp = SvIV((SV *) SvRV(rsv));
+						}
+					}
+				} else {
+					return -1;
+				}
+			} else {
+				tmp = SvIV((SV *) SvRV(sv));
+			}
+			voidptr = (void *) tmp;
+			if (!_t) {
+				*(ptr) = voidptr;
+				return 0;
+			}
+		} else if (!SvOK(sv)) {	/* Check for undef */
+			*(ptr) = (void *) 0;
+			return 0;
+		} else if (SvTYPE(sv) == SVt_RV) {	/* Check for NULL pointer */
+			*(ptr) = (void *) 0;
+			if (!SvROK(sv))
+				return 0;
+			else
+				return -1;
+		} else {				/* Don't know what it is */
+			*(ptr) = (void *) 0;
+			return -1;
+		}
+		if (_t) {
+			/* Now see if the types match */
+			tc = SWIG_TypeCheckRV(sv, _t);
+			if (!tc) {
+				*ptr = voidptr;
+				return -1;
+			}
+			*ptr = SWIG_TypeCast(tc, voidptr);
+			return 0;
+		}
+		*ptr = voidptr;
+		return 0;
+	}
+
+	SWIGRUNTIME(void)
+		SWIG_Perl_MakePtr(SWIG_MAYBE_PERL_OBJECT SV * sv, void *ptr, swig_type_info * t, int flags) {
+		if (ptr && (flags & SWIG_SHADOW)) {
+			SV *self;
+			SV *obj = newSV(0);
+			HV *hash = newHV();
+			HV *stash;
+			sv_setref_pv(obj, (char *) t->name, ptr);
+			stash = SvSTASH(SvRV(obj));
+			if (flags & SWIG_OWNER) {
+				HV *hv;
+				GV *gv = *(GV **) hv_fetch(stash, "OWNER", 5, TRUE);
+				if (!isGV(gv))
+					gv_init(gv, stash, "OWNER", 5, FALSE);
+				hv = GvHVn(gv);
+				hv_store_ent(hv, obj, newSViv(1), 0);
+			}
+			sv_magic((SV *) hash, (SV *) obj, 'P', Nullch, 0);
+			SvREFCNT_dec(obj);
+			self = newRV_noinc((SV *) hash);
+			sv_setsv(sv, self);
+			SvREFCNT_dec((SV *) self);
+			sv_bless(sv, stash);
+		} else {
+			sv_setref_pv(sv, (char *) t->name, ptr);
+		}
+	}
+
+	SWIGRUNTIME(SV *)
+		SWIG_Perl_NewPointerObj(SWIG_MAYBE_PERL_OBJECT void *ptr, swig_type_info * t, int flags) {
+		SV *result = sv_newmortal();
+		SWIG_MakePtr(result, ptr, t, flags);
+		return result;
+	}
+
+	SWIGRUNTIME(void)
+		SWIG_Perl_MakePackedObj(SWIG_MAYBE_PERL_OBJECT SV * sv, void *ptr, int sz, swig_type_info * type) {
+		char result[1024];
+		char *r = result;
+		if ((2 * sz + 1 + strlen(type->name)) > 1000)
+			return;
+		*(r++) = '_';
+		r = SWIG_PackData(r, ptr, sz);
+		strcpy(r, type->name);
+		sv_setpv(sv, result);
+	}
 
 /* Convert a packed value value */
-SWIGRUNTIME(int)
-SWIG_Perl_ConvertPacked(SWIG_MAYBE_PERL_OBJECT SV *obj, void *ptr, int sz, swig_type_info *ty, int flags) {
-  swig_type_info *tc;
-  char  *c = 0;
-
-  if ((!obj) || (!SvOK(obj))) return -1;
-  c = SvPV(obj, PL_na);
-  /* Pointer values must start with leading underscore */
-  if (*c != '_') return -1;
-  c++;
-  c = SWIG_UnpackData(c,ptr,sz);
-  if (ty) {
-    tc = SWIG_TypeCheck(c,ty);
-    if (!tc) return -1;
-  }
-  return 0;
-}
-
-SWIGRUNTIME(void)
-SWIG_Perl_SetError(SWIG_MAYBE_PERL_OBJECT const char *error) {
-  if (error) sv_setpv(perl_get_sv("@", TRUE), error);
-}
-
-SWIGRUNTIME(void)
-SWIG_Perl_SetErrorSV(SWIG_MAYBE_PERL_OBJECT SV *error) {
-  if (error) sv_setsv(perl_get_sv("@", TRUE), error);
-}
-
-SWIGRUNTIME(void)
-SWIG_Perl_SetErrorf(const char *fmt, ...) {
-  va_list args;
-  va_start(args, fmt);
-  sv_vsetpvfn(perl_get_sv("@", TRUE), fmt, strlen(fmt), &args, Null(SV**), 0, Null(bool*));
-  va_end(args);
-}
+	SWIGRUNTIME(int)
+		SWIG_Perl_ConvertPacked(SWIG_MAYBE_PERL_OBJECT SV * obj, void *ptr, int sz, swig_type_info * ty, int flags) {
+		swig_type_info *tc;
+		char *c = 0;
+
+		if ((!obj) || (!SvOK(obj)))
+			return -1;
+		c = SvPV(obj, PL_na);
+		/* Pointer values must start with leading underscore */
+		if (*c != '_')
+			return -1;
+		c++;
+		c = SWIG_UnpackData(c, ptr, sz);
+		if (ty) {
+			tc = SWIG_TypeCheck(c, ty);
+			if (!tc)
+				return -1;
+		}
+		return 0;
+	}
+
+	SWIGRUNTIME(void)
+		SWIG_Perl_SetError(SWIG_MAYBE_PERL_OBJECT const char *error) {
+		if (error)
+			sv_setpv(perl_get_sv("@", TRUE), error);
+	}
+
+	SWIGRUNTIME(void)
+	     SWIG_Perl_SetErrorSV(SWIG_MAYBE_PERL_OBJECT SV * error) {
+		if (error)
+			sv_setsv(perl_get_sv("@", TRUE), error);
+	}
+
+	SWIGRUNTIME(void)
+	     SWIG_Perl_SetErrorf(const char *fmt, ...) {
+		va_list args;
+		va_start(args, fmt);
+		sv_vsetpvfn(perl_get_sv("@", TRUE), fmt, strlen(fmt), &args, Null(SV **), 0, Null(bool *));
+		va_end(args);
+	}
 
 #endif
 
@@ -639,14 +643,14 @@
 /* #define SWIG_croakf(x...) { SWIG_SetErrorf(x); goto fail; } */
 
 
-typedef XS(SwigPerlWrapper);
-typedef SwigPerlWrapper *SwigPerlWrapperPtr;
+	typedef XS(SwigPerlWrapper);
+	typedef SwigPerlWrapper *SwigPerlWrapperPtr;
 
 /* Structure for command table */
-typedef struct {
-  const char         *name;
-  SwigPerlWrapperPtr  wrapper;
-} swig_command_info;
+	typedef struct {
+		const char *name;
+		SwigPerlWrapperPtr wrapper;
+	} swig_command_info;
 
 /* Information for constant table */
 
@@ -657,14 +661,14 @@
 #define SWIG_BINARY  5
 
 /* Constant information structure */
-typedef struct swig_constant_info {
-    int              type;
-    const char      *name;
-    long             lvalue;
-    double           dvalue;
-    void            *pvalue;
-    swig_type_info **ptype;
-} swig_constant_info;
+	typedef struct swig_constant_info {
+		int type;
+		const char *name;
+		long lvalue;
+		double dvalue;
+		void *pvalue;
+		swig_type_info **ptype;
+	} swig_constant_info;
 
 #ifdef __cplusplus
 }
@@ -672,33 +676,36 @@
 
 /* Structure for variable table */
 typedef struct {
-  const char   *name;
-  SwigMagicFunc   set;
-  SwigMagicFunc   get;
-  swig_type_info  **type;
+	const char *name;
+	SwigMagicFunc set;
+	SwigMagicFunc get;
+	swig_type_info **type;
 } swig_variable_info;
 
 /* Magic variable code */
 #ifndef PERL_OBJECT
 #define swig_create_magic(s,a,b,c) _swig_create_magic(s,a,b,c)
-  #ifndef MULTIPLICITY
-     static void _swig_create_magic(SV *sv, char *name, int (*set)(SV *, MAGIC *), int (*get)(SV *,MAGIC *)) {
-  #else
-     static void _swig_create_magic(SV *sv, char *name, int (*set)(struct interpreter*, SV *, MAGIC *), int (*get)(struct interpreter*, SV *,MAGIC *)) {
-  #endif
+#ifndef MULTIPLICITY
+static void _swig_create_magic(SV * sv, char *name, int (*set) (SV *, MAGIC *), int (*get) (SV *, MAGIC *))
+{
+#else
+static void _swig_create_magic(SV * sv, char *name, int (*set) (struct interpreter *, SV *, MAGIC *), int (*get) (struct interpreter *, SV *, MAGIC *))
+{
+#endif
 #else
 #  define swig_create_magic(s,a,b,c) _swig_create_magic(pPerl,s,a,b,c)
-static void _swig_create_magic(CPerlObj *pPerl, SV *sv, const char *name, int (CPerlObj::*set)(SV *, MAGIC *), int (CPerlObj::*get)(SV *, MAGIC *)) {
+static void _swig_create_magic(CPerlObj * pPerl, SV * sv, const char *name, int (CPerlObj::*set) (SV *, MAGIC *), int (CPerlObj::*get) (SV *, MAGIC *))
+{
 #endif
-  MAGIC *mg;
-  sv_magic(sv,sv,'U',(char *) name,strlen(name));
-  mg = mg_find(sv,'U');
-  mg->mg_virtual = (MGVTBL *) malloc(sizeof(MGVTBL));
-  mg->mg_virtual->svt_get = (SwigMagicFuncHack) get;
-  mg->mg_virtual->svt_set = (SwigMagicFuncHack) set;
-  mg->mg_virtual->svt_len = 0;
-  mg->mg_virtual->svt_clear = 0;
-  mg->mg_virtual->svt_free = 0;
+	MAGIC *mg;
+	sv_magic(sv, sv, 'U', (char *) name, strlen(name));
+	mg = mg_find(sv, 'U');
+	mg->mg_virtual = (MGVTBL *) malloc(sizeof(MGVTBL));
+	mg->mg_virtual->svt_get = (SwigMagicFuncHack) get;
+	mg->mg_virtual->svt_set = (SwigMagicFuncHack) set;
+	mg->mg_virtual->svt_len = 0;
+	mg->mg_virtual->svt_clear = 0;
+	mg->mg_virtual->svt_free = 0;
 }
 
 
@@ -707,69 +714,69 @@
 
 
 #ifdef do_open
-  #undef do_open
+#undef do_open
 #endif
 #ifdef do_close
-  #undef do_close
+#undef do_close
 #endif
 #ifdef scalar
-  #undef scalar
+#undef scalar
 #endif
 #ifdef list
-  #undef list
+#undef list
 #endif
 #ifdef apply
-  #undef apply
+#undef apply
 #endif
 #ifdef convert
-  #undef convert
+#undef convert
 #endif
 #ifdef Error
-  #undef Error
+#undef Error
 #endif
 #ifdef form
-  #undef form
+#undef form
 #endif
 #ifdef vform
-  #undef vform
+#undef vform
 #endif
 #ifdef LABEL
-  #undef LABEL
+#undef LABEL
 #endif
 #ifdef METHOD
-  #undef METHOD
+#undef METHOD
 #endif
 #ifdef Move
-  #undef Move
+#undef Move
 #endif
 #ifdef yylex
-  #undef yylex
+#undef yylex
 #endif
 #ifdef yyparse
-  #undef yyparse
+#undef yyparse
 #endif
 #ifdef yyerror
-  #undef yyerror
+#undef yyerror
 #endif
 #ifdef invert
-  #undef invert
+#undef invert
 #endif
 #ifdef ref
-  #undef ref
+#undef ref
 #endif
 #ifdef ENTER
-  #undef ENTER
+#undef ENTER
 #endif
 
 
 /* -------- TYPES TABLE (BEGIN) -------- */
 
-#define  SWIGTYPE_p_switch_channel_t swig_types[0] 
-#define  SWIGTYPE_p_switch_file_handle_t swig_types[1] 
-#define  SWIGTYPE_p_switch_core_session_t swig_types[2] 
-#define  SWIGTYPE_p_p_switch_core_session_t swig_types[3] 
-#define  SWIGTYPE_p_uint32_t swig_types[4] 
-#define  SWIGTYPE_p_switch_input_callback_function_t swig_types[5] 
+#define  SWIGTYPE_p_switch_channel_t swig_types[0]
+#define  SWIGTYPE_p_switch_file_handle_t swig_types[1]
+#define  SWIGTYPE_p_switch_core_session_t swig_types[2]
+#define  SWIGTYPE_p_p_switch_core_session_t swig_types[3]
+#define  SWIGTYPE_p_uint32_t swig_types[4]
+#define  SWIGTYPE_p_switch_input_callback_function_t swig_types[5]
 static swig_type_info *swig_types[7];
 
 /* -------- TYPES TABLE (END) -------- */
@@ -784,55 +791,57 @@
 #endif
 #ifndef PERL_OBJECT
 #ifndef MULTIPLICITY
-SWIGEXPORT(void) SWIG_init (CV* cv);
+SWIGEXPORT(void) SWIG_init(CV * cv);
 #else
-SWIGEXPORT(void) SWIG_init (pTHXo_ CV* cv);
+SWIGEXPORT(void) SWIG_init(pTHXo_ CV * cv);
 #endif
 #else
-SWIGEXPORT(void) SWIG_init (CV *cv, CPerlObj *);
+SWIGEXPORT(void) SWIG_init(CV * cv, CPerlObj *);
 #endif
 
-extern void fs_core_set_globals(void);
-extern int fs_core_init(char *);
-extern int fs_core_destroy(void);
-extern int fs_loadable_module_init(void);
-extern int fs_loadable_module_shutdown(void);
-extern int fs_console_loop(void);
-extern void fs_consol_log(char *,char *);
-extern void fs_consol_clean(char *);
-extern switch_core_session_t *fs_core_session_locate(char *);
-extern void fs_channel_answer(switch_core_session_t *);
-extern void fs_channel_pre_answer(switch_core_session_t *);
-extern void fs_channel_hangup(switch_core_session_t *,char *);
-extern void fs_channel_set_variable(switch_core_session_t *,char *,char *);
-extern void fs_channel_get_variable(switch_core_session_t *,char *);
-extern void fs_channel_set_state(switch_core_session_t *,char *);
-extern int fs_ivr_play_file(switch_core_session_t *,char *);
-extern int fs_switch_ivr_record_file(switch_core_session_t *,switch_file_handle_t *,char *,switch_input_callback_function_t,void *,unsigned int,unsigned int);
-extern int fs_switch_ivr_sleep(switch_core_session_t *,uint32_t);
-extern int fs_ivr_play_file2(switch_core_session_t *,char *);
-extern int fs_switch_ivr_collect_digits_callback(switch_core_session_t *,switch_input_callback_function_t,void *,unsigned int,unsigned int);
-extern int fs_switch_ivr_collect_digits_count(switch_core_session_t *,char *,unsigned int,unsigned int,char const *,char *,unsigned int);
-extern int fs_switch_ivr_originate(switch_core_session_t *,switch_core_session_t **,char *,uint32_t);
-extern int fs_switch_ivr_session_transfer(switch_core_session_t *,char *,char *,char *);
-extern int fs_switch_ivr_speak_text(switch_core_session_t *,char *,char *,uint32_t,char *);
-extern char *fs_switch_channel_get_variable(switch_channel_t *,char *);
-extern int fs_switch_channel_set_variable(switch_channel_t *,char *,char *);
+	 extern void fs_core_set_globals(void);
+	 extern int fs_core_init(char *);
+	 extern int fs_core_destroy(void);
+	 extern int fs_loadable_module_init(void);
+	 extern int fs_loadable_module_shutdown(void);
+	 extern int fs_console_loop(void);
+	 extern void fs_consol_log(char *, char *);
+	 extern void fs_consol_clean(char *);
+	 extern switch_core_session_t *fs_core_session_locate(char *);
+	 extern void fs_channel_answer(switch_core_session_t *);
+	 extern void fs_channel_pre_answer(switch_core_session_t *);
+	 extern void fs_channel_hangup(switch_core_session_t *, char *);
+	 extern void fs_channel_set_variable(switch_core_session_t *, char *, char *);
+	 extern void fs_channel_get_variable(switch_core_session_t *, char *);
+	 extern void fs_channel_set_state(switch_core_session_t *, char *);
+	 extern int fs_ivr_play_file(switch_core_session_t *, char *);
+	 extern int fs_switch_ivr_record_file(switch_core_session_t *, switch_file_handle_t *, char *,
+										  switch_input_callback_function_t, void *, unsigned int, unsigned int);
+	 extern int fs_switch_ivr_sleep(switch_core_session_t *, uint32_t);
+	 extern int fs_ivr_play_file2(switch_core_session_t *, char *);
+	 extern int fs_switch_ivr_collect_digits_callback(switch_core_session_t *, switch_input_callback_function_t, void *, unsigned int, unsigned int);
+	 extern int fs_switch_ivr_collect_digits_count(switch_core_session_t *, char *, unsigned int, unsigned int, char const *, char *, unsigned int);
+	 extern int fs_switch_ivr_originate(switch_core_session_t *, switch_core_session_t **, char *, uint32_t);
+	 extern int fs_switch_ivr_session_transfer(switch_core_session_t *, char *, char *, char *);
+	 extern int fs_switch_ivr_speak_text(switch_core_session_t *, char *, char *, uint32_t, char *);
+	 extern char *fs_switch_channel_get_variable(switch_channel_t *, char *);
+	 extern int fs_switch_channel_set_variable(switch_channel_t *, char *, char *);
 
 #include "switch.h"
 
 #ifdef PERL_OBJECT
 #define MAGIC_CLASS _wrap_fs_perl_var::
-class _wrap_fs_perl_var : public CPerlObj {
-public:
+	 class _wrap_fs_perl_var:public CPerlObj {
+	   public:
 #else
 #define MAGIC_CLASS
 #endif
-SWIGCLASS_STATIC int swig_magic_readonly(pTHX_ SV *sv, MAGIC *mg) {
-    MAGIC_PPERL
-    sv = sv; mg = mg;
-    croak("Value is read-only.");
-    return 0;
+	 SWIGCLASS_STATIC int swig_magic_readonly(pTHX_ SV * sv, MAGIC * mg)
+{
+	MAGIC_PPERL sv = sv;
+	mg = mg;
+	croak("Value is read-only.");
+	return 0;
 }
 
 
@@ -843,917 +852,974 @@
 #ifdef __cplusplus
 extern "C" {
 #endif
-XS(_wrap_fs_core_set_globals) {
-    {
-        int argvi = 0;
-        dXSARGS;
-        
-        if ((items < 0) || (items > 0)) {
-            SWIG_croak("Usage: fs_core_set_globals();");
-        }
-        fs_core_set_globals();
-        
-        
-        XSRETURN(argvi);
-        fail:
-        ;
-    }
-    croak(Nullch);
-}
-
-
-XS(_wrap_fs_core_init) {
-    {
-        char *arg1 ;
-        int result;
-        int argvi = 0;
-        dXSARGS;
-        
-        if ((items < 1) || (items > 1)) {
-            SWIG_croak("Usage: fs_core_init(path);");
-        }
-        if (!SvOK((SV*) ST(0))) arg1 = 0;
-        else arg1 = (char *) SvPV(ST(0), PL_na);
-        result = (int)fs_core_init(arg1);
-        
-        ST(argvi) = sv_newmortal();
-        sv_setiv(ST(argvi++), (IV) result);
-        XSRETURN(argvi);
-        fail:
-        ;
-    }
-    croak(Nullch);
-}
-
-
-XS(_wrap_fs_core_destroy) {
-    {
-        int result;
-        int argvi = 0;
-        dXSARGS;
-        
-        if ((items < 0) || (items > 0)) {
-            SWIG_croak("Usage: fs_core_destroy();");
-        }
-        result = (int)fs_core_destroy();
-        
-        ST(argvi) = sv_newmortal();
-        sv_setiv(ST(argvi++), (IV) result);
-        XSRETURN(argvi);
-        fail:
-        ;
-    }
-    croak(Nullch);
-}
-
-
-XS(_wrap_fs_loadable_module_init) {
-    {
-        int result;
-        int argvi = 0;
-        dXSARGS;
-        
-        if ((items < 0) || (items > 0)) {
-            SWIG_croak("Usage: fs_loadable_module_init();");
-        }
-        result = (int)fs_loadable_module_init();
-        
-        ST(argvi) = sv_newmortal();
-        sv_setiv(ST(argvi++), (IV) result);
-        XSRETURN(argvi);
-        fail:
-        ;
-    }
-    croak(Nullch);
-}
-
-
-XS(_wrap_fs_loadable_module_shutdown) {
-    {
-        int result;
-        int argvi = 0;
-        dXSARGS;
-        
-        if ((items < 0) || (items > 0)) {
-            SWIG_croak("Usage: fs_loadable_module_shutdown();");
-        }
-        result = (int)fs_loadable_module_shutdown();
-        
-        ST(argvi) = sv_newmortal();
-        sv_setiv(ST(argvi++), (IV) result);
-        XSRETURN(argvi);
-        fail:
-        ;
-    }
-    croak(Nullch);
-}
-
-
-XS(_wrap_fs_console_loop) {
-    {
-        int result;
-        int argvi = 0;
-        dXSARGS;
-        
-        if ((items < 0) || (items > 0)) {
-            SWIG_croak("Usage: fs_console_loop();");
-        }
-        result = (int)fs_console_loop();
-        
-        ST(argvi) = sv_newmortal();
-        sv_setiv(ST(argvi++), (IV) result);
-        XSRETURN(argvi);
-        fail:
-        ;
-    }
-    croak(Nullch);
-}
-
-
-XS(_wrap_fs_consol_log) {
-    {
-        char *arg1 ;
-        char *arg2 ;
-        int argvi = 0;
-        dXSARGS;
-        
-        if ((items < 2) || (items > 2)) {
-            SWIG_croak("Usage: fs_consol_log(level_str,msg);");
-        }
-        if (!SvOK((SV*) ST(0))) arg1 = 0;
-        else arg1 = (char *) SvPV(ST(0), PL_na);
-        if (!SvOK((SV*) ST(1))) arg2 = 0;
-        else arg2 = (char *) SvPV(ST(1), PL_na);
-        fs_consol_log(arg1,arg2);
-        
-        
-        XSRETURN(argvi);
-        fail:
-        ;
-    }
-    croak(Nullch);
-}
-
-
-XS(_wrap_fs_consol_clean) {
-    {
-        char *arg1 ;
-        int argvi = 0;
-        dXSARGS;
-        
-        if ((items < 1) || (items > 1)) {
-            SWIG_croak("Usage: fs_consol_clean(msg);");
-        }
-        if (!SvOK((SV*) ST(0))) arg1 = 0;
-        else arg1 = (char *) SvPV(ST(0), PL_na);
-        fs_consol_clean(arg1);
-        
-        
-        XSRETURN(argvi);
-        fail:
-        ;
-    }
-    croak(Nullch);
-}
-
-
-XS(_wrap_fs_core_session_locate) {
-    {
-        char *arg1 ;
-        switch_core_session_t *result;
-        int argvi = 0;
-        dXSARGS;
-        
-        if ((items < 1) || (items > 1)) {
-            SWIG_croak("Usage: fs_core_session_locate(uuid);");
-        }
-        if (!SvOK((SV*) ST(0))) arg1 = 0;
-        else arg1 = (char *) SvPV(ST(0), PL_na);
-        result = (switch_core_session_t *)fs_core_session_locate(arg1);
-        
-        ST(argvi) = sv_newmortal();
-        SWIG_MakePtr(ST(argvi++), (void *) result, SWIGTYPE_p_switch_core_session_t, 0|0);
-        XSRETURN(argvi);
-        fail:
-        ;
-    }
-    croak(Nullch);
-}
-
-
-XS(_wrap_fs_channel_answer) {
-    {
-        switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
-        int argvi = 0;
-        dXSARGS;
-        
-        if ((items < 1) || (items > 1)) {
-            SWIG_croak("Usage: fs_channel_answer(session);");
-        }
-        {
-            if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_core_session_t,0) < 0) {
-                SWIG_croak("Type error in argument 1 of fs_channel_answer. Expected _p_switch_core_session_t");
-            }
-        }
-        fs_channel_answer(arg1);
-        
-        
-        XSRETURN(argvi);
-        fail:
-        ;
-    }
-    croak(Nullch);
-}
-
-
-XS(_wrap_fs_channel_pre_answer) {
-    {
-        switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
-        int argvi = 0;
-        dXSARGS;
-        
-        if ((items < 1) || (items > 1)) {
-            SWIG_croak("Usage: fs_channel_pre_answer(session);");
-        }
-        {
-            if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_core_session_t,0) < 0) {
-                SWIG_croak("Type error in argument 1 of fs_channel_pre_answer. Expected _p_switch_core_session_t");
-            }
-        }
-        fs_channel_pre_answer(arg1);
-        
-        
-        XSRETURN(argvi);
-        fail:
-        ;
-    }
-    croak(Nullch);
-}
-
-
-XS(_wrap_fs_channel_hangup) {
-    {
-        switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
-        char *arg2 ;
-        int argvi = 0;
-        dXSARGS;
-        
-        if ((items < 2) || (items > 2)) {
-            SWIG_croak("Usage: fs_channel_hangup(session,cause);");
-        }
-        {
-            if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_core_session_t,0) < 0) {
-                SWIG_croak("Type error in argument 1 of fs_channel_hangup. Expected _p_switch_core_session_t");
-            }
-        }
-        if (!SvOK((SV*) ST(1))) arg2 = 0;
-        else arg2 = (char *) SvPV(ST(1), PL_na);
-        fs_channel_hangup(arg1,arg2);
-        
-        
-        XSRETURN(argvi);
-        fail:
-        ;
-    }
-    croak(Nullch);
-}
-
-
-XS(_wrap_fs_channel_set_variable) {
-    {
-        switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
-        char *arg2 ;
-        char *arg3 ;
-        int argvi = 0;
-        dXSARGS;
-        
-        if ((items < 3) || (items > 3)) {
-            SWIG_croak("Usage: fs_channel_set_variable(session,var,val);");
-        }
-        {
-            if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_core_session_t,0) < 0) {
-                SWIG_croak("Type error in argument 1 of fs_channel_set_variable. Expected _p_switch_core_session_t");
-            }
-        }
-        if (!SvOK((SV*) ST(1))) arg2 = 0;
-        else arg2 = (char *) SvPV(ST(1), PL_na);
-        if (!SvOK((SV*) ST(2))) arg3 = 0;
-        else arg3 = (char *) SvPV(ST(2), PL_na);
-        fs_channel_set_variable(arg1,arg2,arg3);
-        
-        
-        XSRETURN(argvi);
-        fail:
-        ;
-    }
-    croak(Nullch);
-}
-
-
-XS(_wrap_fs_channel_get_variable) {
-    {
-        switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
-        char *arg2 ;
-        int argvi = 0;
-        dXSARGS;
-        
-        if ((items < 2) || (items > 2)) {
-            SWIG_croak("Usage: fs_channel_get_variable(session,var);");
-        }
-        {
-            if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_core_session_t,0) < 0) {
-                SWIG_croak("Type error in argument 1 of fs_channel_get_variable. Expected _p_switch_core_session_t");
-            }
-        }
-        if (!SvOK((SV*) ST(1))) arg2 = 0;
-        else arg2 = (char *) SvPV(ST(1), PL_na);
-        fs_channel_get_variable(arg1,arg2);
-        
-        
-        XSRETURN(argvi);
-        fail:
-        ;
-    }
-    croak(Nullch);
-}
-
-
-XS(_wrap_fs_channel_set_state) {
-    {
-        switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
-        char *arg2 ;
-        int argvi = 0;
-        dXSARGS;
-        
-        if ((items < 2) || (items > 2)) {
-            SWIG_croak("Usage: fs_channel_set_state(session,state);");
-        }
-        {
-            if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_core_session_t,0) < 0) {
-                SWIG_croak("Type error in argument 1 of fs_channel_set_state. Expected _p_switch_core_session_t");
-            }
-        }
-        if (!SvOK((SV*) ST(1))) arg2 = 0;
-        else arg2 = (char *) SvPV(ST(1), PL_na);
-        fs_channel_set_state(arg1,arg2);
-        
-        
-        XSRETURN(argvi);
-        fail:
-        ;
-    }
-    croak(Nullch);
-}
-
-
-XS(_wrap_fs_ivr_play_file) {
-    {
-        switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
-        char *arg2 ;
-        int result;
-        int argvi = 0;
-        dXSARGS;
-        
-        if ((items < 2) || (items > 2)) {
-            SWIG_croak("Usage: fs_ivr_play_file(session,file);");
-        }
-        {
-            if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_core_session_t,0) < 0) {
-                SWIG_croak("Type error in argument 1 of fs_ivr_play_file. Expected _p_switch_core_session_t");
-            }
-        }
-        if (!SvOK((SV*) ST(1))) arg2 = 0;
-        else arg2 = (char *) SvPV(ST(1), PL_na);
-        result = (int)fs_ivr_play_file(arg1,arg2);
-        
-        ST(argvi) = sv_newmortal();
-        sv_setiv(ST(argvi++), (IV) result);
-        XSRETURN(argvi);
-        fail:
-        ;
-    }
-    croak(Nullch);
-}
-
-
-XS(_wrap_fs_switch_ivr_record_file) {
-    {
-        switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
-        switch_file_handle_t *arg2 = (switch_file_handle_t *) 0 ;
-        char *arg3 ;
-        switch_input_callback_function_t arg4 ;
-        void *arg5 = (void *) 0 ;
-        unsigned int arg6 ;
-        unsigned int arg7 ;
-        int result;
-        int argvi = 0;
-        dXSARGS;
-        
-        if ((items < 7) || (items > 7)) {
-            SWIG_croak("Usage: fs_switch_ivr_record_file(session,fh,file,dtmf_callback,buf,buflen,limit);");
-        }
-        {
-            if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_core_session_t,0) < 0) {
-                SWIG_croak("Type error in argument 1 of fs_switch_ivr_record_file. Expected _p_switch_core_session_t");
-            }
-        }
-        {
-            if (SWIG_ConvertPtr(ST(1), (void **) &arg2, SWIGTYPE_p_switch_file_handle_t,0) < 0) {
-                SWIG_croak("Type error in argument 2 of fs_switch_ivr_record_file. Expected _p_switch_file_handle_t");
-            }
-        }
-        if (!SvOK((SV*) ST(2))) arg3 = 0;
-        else arg3 = (char *) SvPV(ST(2), PL_na);
-        {
-            switch_input_callback_function_t * argp;
-            if (SWIG_ConvertPtr(ST(3),(void **) &argp, SWIGTYPE_p_switch_input_callback_function_t,0) < 0) {
-                SWIG_croak("Type error in argument 4 of fs_switch_ivr_record_file. Expected _p_switch_input_callback_function_t");
-            }
-            arg4 = *argp;
-        }
-        {
-            if (SWIG_ConvertPtr(ST(4), (void **) &arg5, 0,0) < 0) {
-                SWIG_croak("Type error in argument 5 of fs_switch_ivr_record_file. Expected _p_void");
-            }
-        }
-        arg6 = (unsigned int) SvUV(ST(5));
-        arg7 = (unsigned int) SvUV(ST(6));
-        result = (int)fs_switch_ivr_record_file(arg1,arg2,arg3,arg4,arg5,arg6,arg7);
-        
-        ST(argvi) = sv_newmortal();
-        sv_setiv(ST(argvi++), (IV) result);
-        XSRETURN(argvi);
-        fail:
-        ;
-    }
-    croak(Nullch);
-}
-
-
-XS(_wrap_fs_switch_ivr_sleep) {
-    {
-        switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
-        uint32_t arg2 ;
-        int result;
-        int argvi = 0;
-        dXSARGS;
-        
-        if ((items < 2) || (items > 2)) {
-            SWIG_croak("Usage: fs_switch_ivr_sleep(session,ms);");
-        }
-        {
-            if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_core_session_t,0) < 0) {
-                SWIG_croak("Type error in argument 1 of fs_switch_ivr_sleep. Expected _p_switch_core_session_t");
-            }
-        }
-        {
-            uint32_t * argp;
-            if (SWIG_ConvertPtr(ST(1),(void **) &argp, SWIGTYPE_p_uint32_t,0) < 0) {
-                SWIG_croak("Type error in argument 2 of fs_switch_ivr_sleep. Expected _p_uint32_t");
-            }
-            arg2 = *argp;
-        }
-        result = (int)fs_switch_ivr_sleep(arg1,arg2);
-        
-        ST(argvi) = sv_newmortal();
-        sv_setiv(ST(argvi++), (IV) result);
-        XSRETURN(argvi);
-        fail:
-        ;
-    }
-    croak(Nullch);
-}
-
-
-XS(_wrap_fs_ivr_play_file2) {
-    {
-        switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
-        char *arg2 ;
-        int result;
-        int argvi = 0;
-        dXSARGS;
-        
-        if ((items < 2) || (items > 2)) {
-            SWIG_croak("Usage: fs_ivr_play_file2(session,file);");
-        }
-        {
-            if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_core_session_t,0) < 0) {
-                SWIG_croak("Type error in argument 1 of fs_ivr_play_file2. Expected _p_switch_core_session_t");
-            }
-        }
-        if (!SvOK((SV*) ST(1))) arg2 = 0;
-        else arg2 = (char *) SvPV(ST(1), PL_na);
-        result = (int)fs_ivr_play_file2(arg1,arg2);
-        
-        ST(argvi) = sv_newmortal();
-        sv_setiv(ST(argvi++), (IV) result);
-        XSRETURN(argvi);
-        fail:
-        ;
-    }
-    croak(Nullch);
-}
-
-
-XS(_wrap_fs_switch_ivr_collect_digits_callback) {
-    {
-        switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
-        switch_input_callback_function_t arg2 ;
-        void *arg3 = (void *) 0 ;
-        unsigned int arg4 ;
-        unsigned int arg5 ;
-        int result;
-        int argvi = 0;
-        dXSARGS;
-        
-        if ((items < 5) || (items > 5)) {
-            SWIG_croak("Usage: fs_switch_ivr_collect_digits_callback(session,dtmf_callback,buf,buflen,timeout);");
-        }
-        {
-            if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_core_session_t,0) < 0) {
-                SWIG_croak("Type error in argument 1 of fs_switch_ivr_collect_digits_callback. Expected _p_switch_core_session_t");
-            }
-        }
-        {
-            switch_input_callback_function_t * argp;
-            if (SWIG_ConvertPtr(ST(1),(void **) &argp, SWIGTYPE_p_switch_input_callback_function_t,0) < 0) {
-                SWIG_croak("Type error in argument 2 of fs_switch_ivr_collect_digits_callback. Expected _p_switch_input_callback_function_t");
-            }
-            arg2 = *argp;
-        }
-        {
-            if (SWIG_ConvertPtr(ST(2), (void **) &arg3, 0,0) < 0) {
-                SWIG_croak("Type error in argument 3 of fs_switch_ivr_collect_digits_callback. Expected _p_void");
-            }
-        }
-        arg4 = (unsigned int) SvUV(ST(3));
-        arg5 = (unsigned int) SvUV(ST(4));
-        result = (int)fs_switch_ivr_collect_digits_callback(arg1,arg2,arg3,arg4,arg5);
-        
-        ST(argvi) = sv_newmortal();
-        sv_setiv(ST(argvi++), (IV) result);
-        XSRETURN(argvi);
-        fail:
-        ;
-    }
-    croak(Nullch);
-}
-
-
-XS(_wrap_fs_switch_ivr_collect_digits_count) {
-    {
-        switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
-        char *arg2 ;
-        unsigned int arg3 ;
-        unsigned int arg4 ;
-        char *arg5 ;
-        char *arg6 ;
-        unsigned int arg7 ;
-        int result;
-        int argvi = 0;
-        dXSARGS;
-        
-        if ((items < 7) || (items > 7)) {
-            SWIG_croak("Usage: fs_switch_ivr_collect_digits_count(session,buf,buflen,maxdigits,terminators,terminator,timeout);");
-        }
-        {
-            if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_core_session_t,0) < 0) {
-                SWIG_croak("Type error in argument 1 of fs_switch_ivr_collect_digits_count. Expected _p_switch_core_session_t");
-            }
-        }
-        if (!SvOK((SV*) ST(1))) arg2 = 0;
-        else arg2 = (char *) SvPV(ST(1), PL_na);
-        arg3 = (unsigned int) SvUV(ST(2));
-        arg4 = (unsigned int) SvUV(ST(3));
-        if (!SvOK((SV*) ST(4))) arg5 = 0;
-        else arg5 = (char *) SvPV(ST(4), PL_na);
-        if (!SvOK((SV*) ST(5))) arg6 = 0;
-        else arg6 = (char *) SvPV(ST(5), PL_na);
-        arg7 = (unsigned int) SvUV(ST(6));
-        result = (int)fs_switch_ivr_collect_digits_count(arg1,arg2,arg3,arg4,(char const *)arg5,arg6,arg7);
-        
-        ST(argvi) = sv_newmortal();
-        sv_setiv(ST(argvi++), (IV) result);
-        XSRETURN(argvi);
-        fail:
-        ;
-    }
-    croak(Nullch);
-}
-
-
-XS(_wrap_fs_switch_ivr_originate) {
-    {
-        switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
-        switch_core_session_t **arg2 = (switch_core_session_t **) 0 ;
-        char *arg3 ;
-        uint32_t arg4 ;
-        int result;
-        int argvi = 0;
-        dXSARGS;
-        
-        if ((items < 4) || (items > 4)) {
-            SWIG_croak("Usage: fs_switch_ivr_originate(session,bleg,bridgeto,timelimit_sec);");
-        }
-        {
-            if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_core_session_t,0) < 0) {
-                SWIG_croak("Type error in argument 1 of fs_switch_ivr_originate. Expected _p_switch_core_session_t");
-            }
-        }
-        {
-            if (SWIG_ConvertPtr(ST(1), (void **) &arg2, SWIGTYPE_p_p_switch_core_session_t,0) < 0) {
-                SWIG_croak("Type error in argument 2 of fs_switch_ivr_originate. Expected _p_p_switch_core_session_t");
-            }
-        }
-        if (!SvOK((SV*) ST(2))) arg3 = 0;
-        else arg3 = (char *) SvPV(ST(2), PL_na);
-        {
-            uint32_t * argp;
-            if (SWIG_ConvertPtr(ST(3),(void **) &argp, SWIGTYPE_p_uint32_t,0) < 0) {
-                SWIG_croak("Type error in argument 4 of fs_switch_ivr_originate. Expected _p_uint32_t");
-            }
-            arg4 = *argp;
-        }
-        result = (int)fs_switch_ivr_originate(arg1,arg2,arg3,arg4);
-        
-        ST(argvi) = sv_newmortal();
-        sv_setiv(ST(argvi++), (IV) result);
-        XSRETURN(argvi);
-        fail:
-        ;
-    }
-    croak(Nullch);
-}
-
-
-XS(_wrap_fs_switch_ivr_session_transfer) {
-    {
-        switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
-        char *arg2 ;
-        char *arg3 ;
-        char *arg4 ;
-        int result;
-        int argvi = 0;
-        dXSARGS;
-        
-        if ((items < 4) || (items > 4)) {
-            SWIG_croak("Usage: fs_switch_ivr_session_transfer(session,extension,dialplan,context);");
-        }
-        {
-            if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_core_session_t,0) < 0) {
-                SWIG_croak("Type error in argument 1 of fs_switch_ivr_session_transfer. Expected _p_switch_core_session_t");
-            }
-        }
-        if (!SvOK((SV*) ST(1))) arg2 = 0;
-        else arg2 = (char *) SvPV(ST(1), PL_na);
-        if (!SvOK((SV*) ST(2))) arg3 = 0;
-        else arg3 = (char *) SvPV(ST(2), PL_na);
-        if (!SvOK((SV*) ST(3))) arg4 = 0;
-        else arg4 = (char *) SvPV(ST(3), PL_na);
-        result = (int)fs_switch_ivr_session_transfer(arg1,arg2,arg3,arg4);
-        
-        ST(argvi) = sv_newmortal();
-        sv_setiv(ST(argvi++), (IV) result);
-        XSRETURN(argvi);
-        fail:
-        ;
-    }
-    croak(Nullch);
-}
-
-
-XS(_wrap_fs_switch_ivr_speak_text) {
-    {
-        switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
-        char *arg2 ;
-        char *arg3 ;
-        uint32_t arg4 ;
-        char *arg5 ;
-        int result;
-        int argvi = 0;
-        dXSARGS;
-        
-        if ((items < 5) || (items > 5)) {
-            SWIG_croak("Usage: fs_switch_ivr_speak_text(session,tts_name,voice_name,rate,text);");
-        }
-        {
-            if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_core_session_t,0) < 0) {
-                SWIG_croak("Type error in argument 1 of fs_switch_ivr_speak_text. Expected _p_switch_core_session_t");
-            }
-        }
-        if (!SvOK((SV*) ST(1))) arg2 = 0;
-        else arg2 = (char *) SvPV(ST(1), PL_na);
-        if (!SvOK((SV*) ST(2))) arg3 = 0;
-        else arg3 = (char *) SvPV(ST(2), PL_na);
-        {
-            uint32_t * argp;
-            if (SWIG_ConvertPtr(ST(3),(void **) &argp, SWIGTYPE_p_uint32_t,0) < 0) {
-                SWIG_croak("Type error in argument 4 of fs_switch_ivr_speak_text. Expected _p_uint32_t");
-            }
-            arg4 = *argp;
-        }
-        if (!SvOK((SV*) ST(4))) arg5 = 0;
-        else arg5 = (char *) SvPV(ST(4), PL_na);
-        result = (int)fs_switch_ivr_speak_text(arg1,arg2,arg3,arg4,arg5);
-        
-        ST(argvi) = sv_newmortal();
-        sv_setiv(ST(argvi++), (IV) result);
-        XSRETURN(argvi);
-        fail:
-        ;
-    }
-    croak(Nullch);
-}
-
-
-XS(_wrap_fs_switch_channel_get_variable) {
-    {
-        switch_channel_t *arg1 = (switch_channel_t *) 0 ;
-        char *arg2 ;
-        char *result;
-        int argvi = 0;
-        dXSARGS;
-        
-        if ((items < 2) || (items > 2)) {
-            SWIG_croak("Usage: fs_switch_channel_get_variable(channel,varname);");
-        }
-        {
-            if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_channel_t,0) < 0) {
-                SWIG_croak("Type error in argument 1 of fs_switch_channel_get_variable. Expected _p_switch_channel_t");
-            }
-        }
-        if (!SvOK((SV*) ST(1))) arg2 = 0;
-        else arg2 = (char *) SvPV(ST(1), PL_na);
-        result = (char *)fs_switch_channel_get_variable(arg1,arg2);
-        
-        ST(argvi) = sv_newmortal();
-        if (result) {
-            sv_setpv((SV*)ST(argvi++), (char *) result);
-        } else {
-            sv_setsv((SV*)ST(argvi++), &PL_sv_undef);
-        }
-        XSRETURN(argvi);
-        fail:
-        ;
-    }
-    croak(Nullch);
-}
-
-
-XS(_wrap_fs_switch_channel_set_variable) {
-    {
-        switch_channel_t *arg1 = (switch_channel_t *) 0 ;
-        char *arg2 ;
-        char *arg3 ;
-        int result;
-        int argvi = 0;
-        dXSARGS;
-        
-        if ((items < 3) || (items > 3)) {
-            SWIG_croak("Usage: fs_switch_channel_set_variable(channel,varname,value);");
-        }
-        {
-            if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_channel_t,0) < 0) {
-                SWIG_croak("Type error in argument 1 of fs_switch_channel_set_variable. Expected _p_switch_channel_t");
-            }
-        }
-        if (!SvOK((SV*) ST(1))) arg2 = 0;
-        else arg2 = (char *) SvPV(ST(1), PL_na);
-        if (!SvOK((SV*) ST(2))) arg3 = 0;
-        else arg3 = (char *) SvPV(ST(2), PL_na);
-        result = (int)fs_switch_channel_set_variable(arg1,arg2,arg3);
-        
-        ST(argvi) = sv_newmortal();
-        sv_setiv(ST(argvi++), (IV) result);
-        XSRETURN(argvi);
-        fail:
-        ;
-    }
-    croak(Nullch);
-}
+	XS(_wrap_fs_core_set_globals) {
+		{
+			int argvi = 0;
+			    dXSARGS;
+
+			if  ((items < 0) || (items > 0)) {
+				SWIG_croak("Usage: fs_core_set_globals();");
+			}
+			fs_core_set_globals();
+
+
+			XSRETURN(argvi);
+		  fail:
+			;
+		}
+		croak(Nullch);
+	}
+
+
+	XS(_wrap_fs_core_init) {
+		{
+			char *arg1;
+			int result;
+			int argvi = 0;
+			dXSARGS;
+
+			if ((items < 1) || (items > 1)) {
+				SWIG_croak("Usage: fs_core_init(path);");
+			}
+			if (!SvOK((SV *) ST(0)))
+				arg1 = 0;
+			else
+				arg1 = (char *) SvPV(ST(0), PL_na);
+			result = (int) fs_core_init(arg1);
+
+			ST(argvi) = sv_newmortal();
+			sv_setiv(ST(argvi++), (IV) result);
+			XSRETURN(argvi);
+		  fail:
+			;
+		}
+		croak(Nullch);
+	}
+
+
+	XS(_wrap_fs_core_destroy) {
+		{
+			int result;
+			int argvi = 0;
+			dXSARGS;
+
+			if ((items < 0) || (items > 0)) {
+				SWIG_croak("Usage: fs_core_destroy();");
+			}
+			result = (int) fs_core_destroy();
+
+			ST(argvi) = sv_newmortal();
+			sv_setiv(ST(argvi++), (IV) result);
+			XSRETURN(argvi);
+		  fail:
+			;
+		}
+		croak(Nullch);
+	}
+
+
+	XS(_wrap_fs_loadable_module_init) {
+		{
+			int result;
+			int argvi = 0;
+			dXSARGS;
+
+			if ((items < 0) || (items > 0)) {
+				SWIG_croak("Usage: fs_loadable_module_init();");
+			}
+			result = (int) fs_loadable_module_init();
+
+			ST(argvi) = sv_newmortal();
+			sv_setiv(ST(argvi++), (IV) result);
+			XSRETURN(argvi);
+		  fail:
+			;
+		}
+		croak(Nullch);
+	}
+
+
+	XS(_wrap_fs_loadable_module_shutdown) {
+		{
+			int result;
+			int argvi = 0;
+			dXSARGS;
+
+			if ((items < 0) || (items > 0)) {
+				SWIG_croak("Usage: fs_loadable_module_shutdown();");
+			}
+			result = (int) fs_loadable_module_shutdown();
+
+			ST(argvi) = sv_newmortal();
+			sv_setiv(ST(argvi++), (IV) result);
+			XSRETURN(argvi);
+		  fail:
+			;
+		}
+		croak(Nullch);
+	}
+
+
+	XS(_wrap_fs_console_loop) {
+		{
+			int result;
+			int argvi = 0;
+			dXSARGS;
+
+			if ((items < 0) || (items > 0)) {
+				SWIG_croak("Usage: fs_console_loop();");
+			}
+			result = (int) fs_console_loop();
+
+			ST(argvi) = sv_newmortal();
+			sv_setiv(ST(argvi++), (IV) result);
+			XSRETURN(argvi);
+		  fail:
+			;
+		}
+		croak(Nullch);
+	}
+
+
+	XS(_wrap_fs_consol_log) {
+		{
+			char *arg1;
+			char *arg2;
+			int argvi = 0;
+			dXSARGS;
+
+			if ((items < 2) || (items > 2)) {
+				SWIG_croak("Usage: fs_consol_log(level_str,msg);");
+			}
+			if (!SvOK((SV *) ST(0)))
+				arg1 = 0;
+			else
+				arg1 = (char *) SvPV(ST(0), PL_na);
+			if (!SvOK((SV *) ST(1)))
+				arg2 = 0;
+			else
+				arg2 = (char *) SvPV(ST(1), PL_na);
+			fs_consol_log(arg1, arg2);
+
+
+			XSRETURN(argvi);
+		  fail:
+			;
+		}
+		croak(Nullch);
+	}
+
+
+	XS(_wrap_fs_consol_clean) {
+		{
+			char *arg1;
+			int argvi = 0;
+			dXSARGS;
+
+			if ((items < 1) || (items > 1)) {
+				SWIG_croak("Usage: fs_consol_clean(msg);");
+			}
+			if (!SvOK((SV *) ST(0)))
+				arg1 = 0;
+			else
+				arg1 = (char *) SvPV(ST(0), PL_na);
+			fs_consol_clean(arg1);
+
+
+			XSRETURN(argvi);
+		  fail:
+			;
+		}
+		croak(Nullch);
+	}
+
+
+	XS(_wrap_fs_core_session_locate) {
+		{
+			char *arg1;
+			switch_core_session_t *result;
+			int argvi = 0;
+			dXSARGS;
+
+			if ((items < 1) || (items > 1)) {
+				SWIG_croak("Usage: fs_core_session_locate(uuid);");
+			}
+			if (!SvOK((SV *) ST(0)))
+				arg1 = 0;
+			else
+				arg1 = (char *) SvPV(ST(0), PL_na);
+			result = (switch_core_session_t *) fs_core_session_locate(arg1);
+
+			ST(argvi) = sv_newmortal();
+			SWIG_MakePtr(ST(argvi++), (void *) result, SWIGTYPE_p_switch_core_session_t, 0 | 0);
+			XSRETURN(argvi);
+		  fail:
+			;
+		}
+		croak(Nullch);
+	}
+
+
+	XS(_wrap_fs_channel_answer) {
+		{
+			switch_core_session_t *arg1 = (switch_core_session_t *) 0;
+			int argvi = 0;
+			dXSARGS;
+
+			if ((items < 1) || (items > 1)) {
+				SWIG_croak("Usage: fs_channel_answer(session);");
+			}
+			{
+				if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_core_session_t, 0) < 0) {
+					SWIG_croak("Type error in argument 1 of fs_channel_answer. Expected _p_switch_core_session_t");
+				}
+			}
+			fs_channel_answer(arg1);
+
+
+			XSRETURN(argvi);
+		  fail:
+			;
+		}
+		croak(Nullch);
+	}
+
+
+	XS(_wrap_fs_channel_pre_answer) {
+		{
+			switch_core_session_t *arg1 = (switch_core_session_t *) 0;
+			int argvi = 0;
+			dXSARGS;
+
+			if ((items < 1) || (items > 1)) {
+				SWIG_croak("Usage: fs_channel_pre_answer(session);");
+			}
+			{
+				if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_core_session_t, 0) < 0) {
+					SWIG_croak("Type error in argument 1 of fs_channel_pre_answer. Expected _p_switch_core_session_t");
+				}
+			}
+			fs_channel_pre_answer(arg1);
+
+
+			XSRETURN(argvi);
+		  fail:
+			;
+		}
+		croak(Nullch);
+	}
+
+
+	XS(_wrap_fs_channel_hangup) {
+		{
+			switch_core_session_t *arg1 = (switch_core_session_t *) 0;
+			char *arg2;
+			int argvi = 0;
+			dXSARGS;
+
+			if ((items < 2) || (items > 2)) {
+				SWIG_croak("Usage: fs_channel_hangup(session,cause);");
+			}
+			{
+				if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_core_session_t, 0) < 0) {
+					SWIG_croak("Type error in argument 1 of fs_channel_hangup. Expected _p_switch_core_session_t");
+				}
+			}
+			if (!SvOK((SV *) ST(1)))
+				arg2 = 0;
+			else
+				arg2 = (char *) SvPV(ST(1), PL_na);
+			fs_channel_hangup(arg1, arg2);
+
+
+			XSRETURN(argvi);
+		  fail:
+			;
+		}
+		croak(Nullch);
+	}
+
+
+	XS(_wrap_fs_channel_set_variable) {
+		{
+			switch_core_session_t *arg1 = (switch_core_session_t *) 0;
+			char *arg2;
+			char *arg3;
+			int argvi = 0;
+			dXSARGS;
+
+			if ((items < 3) || (items > 3)) {
+				SWIG_croak("Usage: fs_channel_set_variable(session,var,val);");
+			}
+			{
+				if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_core_session_t, 0) < 0) {
+					SWIG_croak("Type error in argument 1 of fs_channel_set_variable. Expected _p_switch_core_session_t");
+				}
+			}
+			if (!SvOK((SV *) ST(1)))
+				arg2 = 0;
+			else
+				arg2 = (char *) SvPV(ST(1), PL_na);
+			if (!SvOK((SV *) ST(2)))
+				arg3 = 0;
+			else
+				arg3 = (char *) SvPV(ST(2), PL_na);
+			fs_channel_set_variable(arg1, arg2, arg3);
+
+
+			XSRETURN(argvi);
+		  fail:
+			;
+		}
+		croak(Nullch);
+	}
+
+
+	XS(_wrap_fs_channel_get_variable) {
+		{
+			switch_core_session_t *arg1 = (switch_core_session_t *) 0;
+			char *arg2;
+			int argvi = 0;
+			dXSARGS;
+
+			if ((items < 2) || (items > 2)) {
+				SWIG_croak("Usage: fs_channel_get_variable(session,var);");
+			}
+			{
+				if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_core_session_t, 0) < 0) {
+					SWIG_croak("Type error in argument 1 of fs_channel_get_variable. Expected _p_switch_core_session_t");
+				}
+			}
+			if (!SvOK((SV *) ST(1)))
+				arg2 = 0;
+			else
+				arg2 = (char *) SvPV(ST(1), PL_na);
+			fs_channel_get_variable(arg1, arg2);
+
+
+			XSRETURN(argvi);
+		  fail:
+			;
+		}
+		croak(Nullch);
+	}
+
+
+	XS(_wrap_fs_channel_set_state) {
+		{
+			switch_core_session_t *arg1 = (switch_core_session_t *) 0;
+			char *arg2;
+			int argvi = 0;
+			dXSARGS;
+
+			if ((items < 2) || (items > 2)) {
+				SWIG_croak("Usage: fs_channel_set_state(session,state);");
+			}
+			{
+				if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_core_session_t, 0) < 0) {
+					SWIG_croak("Type error in argument 1 of fs_channel_set_state. Expected _p_switch_core_session_t");
+				}
+			}
+			if (!SvOK((SV *) ST(1)))
+				arg2 = 0;
+			else
+				arg2 = (char *) SvPV(ST(1), PL_na);
+			fs_channel_set_state(arg1, arg2);
+
+
+			XSRETURN(argvi);
+		  fail:
+			;
+		}
+		croak(Nullch);
+	}
+
+
+	XS(_wrap_fs_ivr_play_file) {
+		{
+			switch_core_session_t *arg1 = (switch_core_session_t *) 0;
+			char *arg2;
+			int result;
+			int argvi = 0;
+			dXSARGS;
+
+			if ((items < 2) || (items > 2)) {
+				SWIG_croak("Usage: fs_ivr_play_file(session,file);");
+			}
+			{
+				if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_core_session_t, 0) < 0) {
+					SWIG_croak("Type error in argument 1 of fs_ivr_play_file. Expected _p_switch_core_session_t");
+				}
+			}
+			if (!SvOK((SV *) ST(1)))
+				arg2 = 0;
+			else
+				arg2 = (char *) SvPV(ST(1), PL_na);
+			result = (int) fs_ivr_play_file(arg1, arg2);
+
+			ST(argvi) = sv_newmortal();
+			sv_setiv(ST(argvi++), (IV) result);
+			XSRETURN(argvi);
+		  fail:
+			;
+		}
+		croak(Nullch);
+	}
+
+
+	XS(_wrap_fs_switch_ivr_record_file) {
+		{
+			switch_core_session_t *arg1 = (switch_core_session_t *) 0;
+			switch_file_handle_t *arg2 = (switch_file_handle_t *) 0;
+			char *arg3;
+			switch_input_callback_function_t arg4;
+			void *arg5 = (void *) 0;
+			unsigned int arg6;
+			unsigned int arg7;
+			int result;
+			int argvi = 0;
+			dXSARGS;
+
+			if ((items < 7) || (items > 7)) {
+				SWIG_croak("Usage: fs_switch_ivr_record_file(session,fh,file,dtmf_callback,buf,buflen,limit);");
+			}
+			{
+				if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_core_session_t, 0) < 0) {
+					SWIG_croak("Type error in argument 1 of fs_switch_ivr_record_file. Expected _p_switch_core_session_t");
+				}
+			}
+			{
+				if (SWIG_ConvertPtr(ST(1), (void **) &arg2, SWIGTYPE_p_switch_file_handle_t, 0) < 0) {
+					SWIG_croak("Type error in argument 2 of fs_switch_ivr_record_file. Expected _p_switch_file_handle_t");
+				}
+			}
+			if (!SvOK((SV *) ST(2)))
+				arg3 = 0;
+			else
+				arg3 = (char *) SvPV(ST(2), PL_na);
+			{
+				switch_input_callback_function_t *argp;
+				if (SWIG_ConvertPtr(ST(3), (void **) &argp, SWIGTYPE_p_switch_input_callback_function_t, 0) < 0) {
+					SWIG_croak("Type error in argument 4 of fs_switch_ivr_record_file. Expected _p_switch_input_callback_function_t");
+				}
+				arg4 = *argp;
+			}
+			{
+				if (SWIG_ConvertPtr(ST(4), (void **) &arg5, 0, 0) < 0) {
+					SWIG_croak("Type error in argument 5 of fs_switch_ivr_record_file. Expected _p_void");
+				}
+			}
+			arg6 = (unsigned int) SvUV(ST(5));
+			arg7 = (unsigned int) SvUV(ST(6));
+			result = (int) fs_switch_ivr_record_file(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
+
+			ST(argvi) = sv_newmortal();
+			sv_setiv(ST(argvi++), (IV) result);
+			XSRETURN(argvi);
+		  fail:
+			;
+		}
+		croak(Nullch);
+	}
+
+
+	XS(_wrap_fs_switch_ivr_sleep) {
+		{
+			switch_core_session_t *arg1 = (switch_core_session_t *) 0;
+			uint32_t arg2;
+			int result;
+			int argvi = 0;
+			dXSARGS;
+
+			if ((items < 2) || (items > 2)) {
+				SWIG_croak("Usage: fs_switch_ivr_sleep(session,ms);");
+			}
+			{
+				if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_core_session_t, 0) < 0) {
+					SWIG_croak("Type error in argument 1 of fs_switch_ivr_sleep. Expected _p_switch_core_session_t");
+				}
+			}
+			{
+				uint32_t *argp;
+				if (SWIG_ConvertPtr(ST(1), (void **) &argp, SWIGTYPE_p_uint32_t, 0) < 0) {
+					SWIG_croak("Type error in argument 2 of fs_switch_ivr_sleep. Expected _p_uint32_t");
+				}
+				arg2 = *argp;
+			}
+			result = (int) fs_switch_ivr_sleep(arg1, arg2);
+
+			ST(argvi) = sv_newmortal();
+			sv_setiv(ST(argvi++), (IV) result);
+			XSRETURN(argvi);
+		  fail:
+			;
+		}
+		croak(Nullch);
+	}
+
+
+	XS(_wrap_fs_ivr_play_file2) {
+		{
+			switch_core_session_t *arg1 = (switch_core_session_t *) 0;
+			char *arg2;
+			int result;
+			int argvi = 0;
+			dXSARGS;
+
+			if ((items < 2) || (items > 2)) {
+				SWIG_croak("Usage: fs_ivr_play_file2(session,file);");
+			}
+			{
+				if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_core_session_t, 0) < 0) {
+					SWIG_croak("Type error in argument 1 of fs_ivr_play_file2. Expected _p_switch_core_session_t");
+				}
+			}
+			if (!SvOK((SV *) ST(1)))
+				arg2 = 0;
+			else
+				arg2 = (char *) SvPV(ST(1), PL_na);
+			result = (int) fs_ivr_play_file2(arg1, arg2);
+
+			ST(argvi) = sv_newmortal();
+			sv_setiv(ST(argvi++), (IV) result);
+			XSRETURN(argvi);
+		  fail:
+			;
+		}
+		croak(Nullch);
+	}
+
+
+	XS(_wrap_fs_switch_ivr_collect_digits_callback) {
+		{
+			switch_core_session_t *arg1 = (switch_core_session_t *) 0;
+			switch_input_callback_function_t arg2;
+			void *arg3 = (void *) 0;
+			unsigned int arg4;
+			unsigned int arg5;
+			int result;
+			int argvi = 0;
+			dXSARGS;
+
+			if ((items < 5) || (items > 5)) {
+				SWIG_croak("Usage: fs_switch_ivr_collect_digits_callback(session,dtmf_callback,buf,buflen,timeout);");
+			}
+			{
+				if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_core_session_t, 0) < 0) {
+					SWIG_croak("Type error in argument 1 of fs_switch_ivr_collect_digits_callback. Expected _p_switch_core_session_t");
+				}
+			}
+			{
+				switch_input_callback_function_t *argp;
+				if (SWIG_ConvertPtr(ST(1), (void **) &argp, SWIGTYPE_p_switch_input_callback_function_t, 0) < 0) {
+					SWIG_croak("Type error in argument 2 of fs_switch_ivr_collect_digits_callback. Expected _p_switch_input_callback_function_t");
+				}
+				arg2 = *argp;
+			}
+			{
+				if (SWIG_ConvertPtr(ST(2), (void **) &arg3, 0, 0) < 0) {
+					SWIG_croak("Type error in argument 3 of fs_switch_ivr_collect_digits_callback. Expected _p_void");
+				}
+			}
+			arg4 = (unsigned int) SvUV(ST(3));
+			arg5 = (unsigned int) SvUV(ST(4));
+			result = (int) fs_switch_ivr_collect_digits_callback(arg1, arg2, arg3, arg4, arg5);
+
+			ST(argvi) = sv_newmortal();
+			sv_setiv(ST(argvi++), (IV) result);
+			XSRETURN(argvi);
+		  fail:
+			;
+		}
+		croak(Nullch);
+	}
+
+
+	XS(_wrap_fs_switch_ivr_collect_digits_count) {
+		{
+			switch_core_session_t *arg1 = (switch_core_session_t *) 0;
+			char *arg2;
+			unsigned int arg3;
+			unsigned int arg4;
+			char *arg5;
+			char *arg6;
+			unsigned int arg7;
+			int result;
+			int argvi = 0;
+			dXSARGS;
+
+			if ((items < 7) || (items > 7)) {
+				SWIG_croak("Usage: fs_switch_ivr_collect_digits_count(session,buf,buflen,maxdigits,terminators,terminator,timeout);");
+			}
+			{
+				if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_core_session_t, 0) < 0) {
+					SWIG_croak("Type error in argument 1 of fs_switch_ivr_collect_digits_count. Expected _p_switch_core_session_t");
+				}
+			}
+			if (!SvOK((SV *) ST(1)))
+				arg2 = 0;
+			else
+				arg2 = (char *) SvPV(ST(1), PL_na);
+			arg3 = (unsigned int) SvUV(ST(2));
+			arg4 = (unsigned int) SvUV(ST(3));
+			if (!SvOK((SV *) ST(4)))
+				arg5 = 0;
+			else
+				arg5 = (char *) SvPV(ST(4), PL_na);
+			if (!SvOK((SV *) ST(5)))
+				arg6 = 0;
+			else
+				arg6 = (char *) SvPV(ST(5), PL_na);
+			arg7 = (unsigned int) SvUV(ST(6));
+			result = (int) fs_switch_ivr_collect_digits_count(arg1, arg2, arg3, arg4, (char const *) arg5, arg6, arg7);
+
+			ST(argvi) = sv_newmortal();
+			sv_setiv(ST(argvi++), (IV) result);
+			XSRETURN(argvi);
+		  fail:
+			;
+		}
+		croak(Nullch);
+	}
+
+
+	XS(_wrap_fs_switch_ivr_originate) {
+		{
+			switch_core_session_t *arg1 = (switch_core_session_t *) 0;
+			switch_core_session_t **arg2 = (switch_core_session_t **) 0;
+			char *arg3;
+			uint32_t arg4;
+			int result;
+			int argvi = 0;
+			dXSARGS;
+
+			if ((items < 4) || (items > 4)) {
+				SWIG_croak("Usage: fs_switch_ivr_originate(session,bleg,bridgeto,timelimit_sec);");
+			}
+			{
+				if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_core_session_t, 0) < 0) {
+					SWIG_croak("Type error in argument 1 of fs_switch_ivr_originate. Expected _p_switch_core_session_t");
+				}
+			}
+			{
+				if (SWIG_ConvertPtr(ST(1), (void **) &arg2, SWIGTYPE_p_p_switch_core_session_t, 0) < 0) {
+					SWIG_croak("Type error in argument 2 of fs_switch_ivr_originate. Expected _p_p_switch_core_session_t");
+				}
+			}
+			if (!SvOK((SV *) ST(2)))
+				arg3 = 0;
+			else
+				arg3 = (char *) SvPV(ST(2), PL_na);
+			{
+				uint32_t *argp;
+				if (SWIG_ConvertPtr(ST(3), (void **) &argp, SWIGTYPE_p_uint32_t, 0) < 0) {
+					SWIG_croak("Type error in argument 4 of fs_switch_ivr_originate. Expected _p_uint32_t");
+				}
+				arg4 = *argp;
+			}
+			result = (int) fs_switch_ivr_originate(arg1, arg2, arg3, arg4);
+
+			ST(argvi) = sv_newmortal();
+			sv_setiv(ST(argvi++), (IV) result);
+			XSRETURN(argvi);
+		  fail:
+			;
+		}
+		croak(Nullch);
+	}
+
+
+	XS(_wrap_fs_switch_ivr_session_transfer) {
+		{
+			switch_core_session_t *arg1 = (switch_core_session_t *) 0;
+			char *arg2;
+			char *arg3;
+			char *arg4;
+			int result;
+			int argvi = 0;
+			dXSARGS;
+
+			if ((items < 4) || (items > 4)) {
+				SWIG_croak("Usage: fs_switch_ivr_session_transfer(session,extension,dialplan,context);");
+			}
+			{
+				if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_core_session_t, 0) < 0) {
+					SWIG_croak("Type error in argument 1 of fs_switch_ivr_session_transfer. Expected _p_switch_core_session_t");
+				}
+			}
+			if (!SvOK((SV *) ST(1)))
+				arg2 = 0;
+			else
+				arg2 = (char *) SvPV(ST(1), PL_na);
+			if (!SvOK((SV *) ST(2)))
+				arg3 = 0;
+			else
+				arg3 = (char *) SvPV(ST(2), PL_na);
+			if (!SvOK((SV *) ST(3)))
+				arg4 = 0;
+			else
+				arg4 = (char *) SvPV(ST(3), PL_na);
+			result = (int) fs_switch_ivr_session_transfer(arg1, arg2, arg3, arg4);
+
+			ST(argvi) = sv_newmortal();
+			sv_setiv(ST(argvi++), (IV) result);
+			XSRETURN(argvi);
+		  fail:
+			;
+		}
+		croak(Nullch);
+	}
+
+
+	XS(_wrap_fs_switch_ivr_speak_text) {
+		{
+			switch_core_session_t *arg1 = (switch_core_session_t *) 0;
+			char *arg2;
+			char *arg3;
+			uint32_t arg4;
+			char *arg5;
+			int result;
+			int argvi = 0;
+			dXSARGS;
+
+			if ((items < 5) || (items > 5)) {
+				SWIG_croak("Usage: fs_switch_ivr_speak_text(session,tts_name,voice_name,rate,text);");
+			}
+			{
+				if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_core_session_t, 0) < 0) {
+					SWIG_croak("Type error in argument 1 of fs_switch_ivr_speak_text. Expected _p_switch_core_session_t");
+				}
+			}
+			if (!SvOK((SV *) ST(1)))
+				arg2 = 0;
+			else
+				arg2 = (char *) SvPV(ST(1), PL_na);
+			if (!SvOK((SV *) ST(2)))
+				arg3 = 0;
+			else
+				arg3 = (char *) SvPV(ST(2), PL_na);
+			{
+				uint32_t *argp;
+				if (SWIG_ConvertPtr(ST(3), (void **) &argp, SWIGTYPE_p_uint32_t, 0) < 0) {
+					SWIG_croak("Type error in argument 4 of fs_switch_ivr_speak_text. Expected _p_uint32_t");
+				}
+				arg4 = *argp;
+			}
+			if (!SvOK((SV *) ST(4)))
+				arg5 = 0;
+			else
+				arg5 = (char *) SvPV(ST(4), PL_na);
+			result = (int) fs_switch_ivr_speak_text(arg1, arg2, arg3, arg4, arg5);
+
+			ST(argvi) = sv_newmortal();
+			sv_setiv(ST(argvi++), (IV) result);
+			XSRETURN(argvi);
+		  fail:
+			;
+		}
+		croak(Nullch);
+	}
+
+
+	XS(_wrap_fs_switch_channel_get_variable) {
+		{
+			switch_channel_t *arg1 = (switch_channel_t *) 0;
+			char *arg2;
+			char *result;
+			int argvi = 0;
+			dXSARGS;
+
+			if ((items < 2) || (items > 2)) {
+				SWIG_croak("Usage: fs_switch_channel_get_variable(channel,varname);");
+			}
+			{
+				if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_channel_t, 0) < 0) {
+					SWIG_croak("Type error in argument 1 of fs_switch_channel_get_variable. Expected _p_switch_channel_t");
+				}
+			}
+			if (!SvOK((SV *) ST(1)))
+				arg2 = 0;
+			else
+				arg2 = (char *) SvPV(ST(1), PL_na);
+			result = (char *) fs_switch_channel_get_variable(arg1, arg2);
+
+			ST(argvi) = sv_newmortal();
+			if (result) {
+				sv_setpv((SV *) ST(argvi++), (char *) result);
+			} else {
+				sv_setsv((SV *) ST(argvi++), &PL_sv_undef);
+			}
+			XSRETURN(argvi);
+		  fail:
+			;
+		}
+		croak(Nullch);
+	}
+
+
+	XS(_wrap_fs_switch_channel_set_variable) {
+		{
+			switch_channel_t *arg1 = (switch_channel_t *) 0;
+			char *arg2;
+			char *arg3;
+			int result;
+			int argvi = 0;
+			dXSARGS;
+
+			if ((items < 3) || (items > 3)) {
+				SWIG_croak("Usage: fs_switch_channel_set_variable(channel,varname,value);");
+			}
+			{
+				if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_switch_channel_t, 0) < 0) {
+					SWIG_croak("Type error in argument 1 of fs_switch_channel_set_variable. Expected _p_switch_channel_t");
+				}
+			}
+			if (!SvOK((SV *) ST(1)))
+				arg2 = 0;
+			else
+				arg2 = (char *) SvPV(ST(1), PL_na);
+			if (!SvOK((SV *) ST(2)))
+				arg3 = 0;
+			else
+				arg3 = (char *) SvPV(ST(2), PL_na);
+			result = (int) fs_switch_channel_set_variable(arg1, arg2, arg3);
+
+			ST(argvi) = sv_newmortal();
+			sv_setiv(ST(argvi++), (IV) result);
+			XSRETURN(argvi);
+		  fail:
+			;
+		}
+		croak(Nullch);
+	}
 
 
 
 /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */
 
-static swig_type_info _swigt__p_switch_channel_t[] = {{"_p_switch_channel_t", 0, "switch_channel_t *", 0},{"_p_switch_channel_t"},{0}};
-static swig_type_info _swigt__p_switch_file_handle_t[] = {{"_p_switch_file_handle_t", 0, "switch_file_handle_t *", 0},{"_p_switch_file_handle_t"},{0}};
-static swig_type_info _swigt__p_switch_core_session_t[] = {{"_p_switch_core_session_t", 0, "switch_core_session_t *", 0},{"_p_switch_core_session_t"},{0}};
-static swig_type_info _swigt__p_p_switch_core_session_t[] = {{"_p_p_switch_core_session_t", 0, "switch_core_session_t **", 0},{"_p_p_switch_core_session_t"},{0}};
-static swig_type_info _swigt__p_uint32_t[] = {{"_p_uint32_t", 0, "uint32_t *", 0},{"_p_uint32_t"},{0}};
-static swig_type_info _swigt__p_switch_input_callback_function_t[] = {{"_p_switch_input_callback_function_t", 0, "switch_input_callback_function_t *", 0},{"_p_switch_input_callback_function_t"},{0}};
-
-static swig_type_info *swig_types_initial[] = {
-_swigt__p_switch_channel_t, 
-_swigt__p_switch_file_handle_t, 
-_swigt__p_switch_core_session_t, 
-_swigt__p_p_switch_core_session_t, 
-_swigt__p_uint32_t, 
-_swigt__p_switch_input_callback_function_t, 
-0
-};
+	static swig_type_info _swigt__p_switch_channel_t[] = { {"_p_switch_channel_t", 0, "switch_channel_t *", 0}, {"_p_switch_channel_t"}, {0} };
+	static swig_type_info _swigt__p_switch_file_handle_t[] =
+		{ {"_p_switch_file_handle_t", 0, "switch_file_handle_t *", 0}, {"_p_switch_file_handle_t"}, {0} };
+	static swig_type_info _swigt__p_switch_core_session_t[] =
+		{ {"_p_switch_core_session_t", 0, "switch_core_session_t *", 0}, {"_p_switch_core_session_t"}, {0} };
+	static swig_type_info _swigt__p_p_switch_core_session_t[] =
+		{ {"_p_p_switch_core_session_t", 0, "switch_core_session_t **", 0}, {"_p_p_switch_core_session_t"}, {0} };
+	static swig_type_info _swigt__p_uint32_t[] = { {"_p_uint32_t", 0, "uint32_t *", 0}, {"_p_uint32_t"}, {0} };
+	static swig_type_info _swigt__p_switch_input_callback_function_t[] =
+		{ {"_p_switch_input_callback_function_t", 0, "switch_input_callback_function_t *", 0},
+	{"_p_switch_input_callback_function_t"}, {0}
+	};
+
+	static swig_type_info *swig_types_initial[] = {
+		_swigt__p_switch_channel_t,
+		_swigt__p_switch_file_handle_t,
+		_swigt__p_switch_core_session_t,
+		_swigt__p_p_switch_core_session_t,
+		_swigt__p_uint32_t,
+		_swigt__p_switch_input_callback_function_t,
+		0
+	};
 
 
 /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (END) -------- */
 
-static swig_constant_info swig_constants[] = {
-{0}
-};
+	static swig_constant_info swig_constants[] = {
+		{0}
+	};
 #ifdef __cplusplus
 }
 #endif
 static swig_variable_info swig_variables[] = {
-{0}
+	{0}
 };
 static swig_command_info swig_commands[] = {
-{"fs_perlc::fs_core_set_globals", _wrap_fs_core_set_globals},
-{"fs_perlc::fs_core_init", _wrap_fs_core_init},
-{"fs_perlc::fs_core_destroy", _wrap_fs_core_destroy},
-{"fs_perlc::fs_loadable_module_init", _wrap_fs_loadable_module_init},
-{"fs_perlc::fs_loadable_module_shutdown", _wrap_fs_loadable_module_shutdown},
-{"fs_perlc::fs_console_loop", _wrap_fs_console_loop},
-{"fs_perlc::fs_consol_log", _wrap_fs_consol_log},
-{"fs_perlc::fs_consol_clean", _wrap_fs_consol_clean},
-{"fs_perlc::fs_core_session_locate", _wrap_fs_core_session_locate},
-{"fs_perlc::fs_channel_answer", _wrap_fs_channel_answer},
-{"fs_perlc::fs_channel_pre_answer", _wrap_fs_channel_pre_answer},
-{"fs_perlc::fs_channel_hangup", _wrap_fs_channel_hangup},
-{"fs_perlc::fs_channel_set_variable", _wrap_fs_channel_set_variable},
-{"fs_perlc::fs_channel_get_variable", _wrap_fs_channel_get_variable},
-{"fs_perlc::fs_channel_set_state", _wrap_fs_channel_set_state},
-{"fs_perlc::fs_ivr_play_file", _wrap_fs_ivr_play_file},
-{"fs_perlc::fs_switch_ivr_record_file", _wrap_fs_switch_ivr_record_file},
-{"fs_perlc::fs_switch_ivr_sleep", _wrap_fs_switch_ivr_sleep},
-{"fs_perlc::fs_ivr_play_file2", _wrap_fs_ivr_play_file2},
-{"fs_perlc::fs_switch_ivr_collect_digits_callback", _wrap_fs_switch_ivr_collect_digits_callback},
-{"fs_perlc::fs_switch_ivr_collect_digits_count", _wrap_fs_switch_ivr_collect_digits_count},
-{"fs_perlc::fs_switch_ivr_originate", _wrap_fs_switch_ivr_originate},
-{"fs_perlc::fs_switch_ivr_session_transfer", _wrap_fs_switch_ivr_session_transfer},
-{"fs_perlc::fs_switch_ivr_speak_text", _wrap_fs_switch_ivr_speak_text},
-{"fs_perlc::fs_switch_channel_get_variable", _wrap_fs_switch_channel_get_variable},
-{"fs_perlc::fs_switch_channel_set_variable", _wrap_fs_switch_channel_set_variable},
-{0,0}
+	{"fs_perlc::fs_core_set_globals", _wrap_fs_core_set_globals},
+	{"fs_perlc::fs_core_init", _wrap_fs_core_init},
+	{"fs_perlc::fs_core_destroy", _wrap_fs_core_destroy},
+	{"fs_perlc::fs_loadable_module_init", _wrap_fs_loadable_module_init},
+	{"fs_perlc::fs_loadable_module_shutdown", _wrap_fs_loadable_module_shutdown},
+	{"fs_perlc::fs_console_loop", _wrap_fs_console_loop},
+	{"fs_perlc::fs_consol_log", _wrap_fs_consol_log},
+	{"fs_perlc::fs_consol_clean", _wrap_fs_consol_clean},
+	{"fs_perlc::fs_core_session_locate", _wrap_fs_core_session_locate},
+	{"fs_perlc::fs_channel_answer", _wrap_fs_channel_answer},
+	{"fs_perlc::fs_channel_pre_answer", _wrap_fs_channel_pre_answer},
+	{"fs_perlc::fs_channel_hangup", _wrap_fs_channel_hangup},
+	{"fs_perlc::fs_channel_set_variable", _wrap_fs_channel_set_variable},
+	{"fs_perlc::fs_channel_get_variable", _wrap_fs_channel_get_variable},
+	{"fs_perlc::fs_channel_set_state", _wrap_fs_channel_set_state},
+	{"fs_perlc::fs_ivr_play_file", _wrap_fs_ivr_play_file},
+	{"fs_perlc::fs_switch_ivr_record_file", _wrap_fs_switch_ivr_record_file},
+	{"fs_perlc::fs_switch_ivr_sleep", _wrap_fs_switch_ivr_sleep},
+	{"fs_perlc::fs_ivr_play_file2", _wrap_fs_ivr_play_file2},
+	{"fs_perlc::fs_switch_ivr_collect_digits_callback", _wrap_fs_switch_ivr_collect_digits_callback},
+	{"fs_perlc::fs_switch_ivr_collect_digits_count", _wrap_fs_switch_ivr_collect_digits_count},
+	{"fs_perlc::fs_switch_ivr_originate", _wrap_fs_switch_ivr_originate},
+	{"fs_perlc::fs_switch_ivr_session_transfer", _wrap_fs_switch_ivr_session_transfer},
+	{"fs_perlc::fs_switch_ivr_speak_text", _wrap_fs_switch_ivr_speak_text},
+	{"fs_perlc::fs_switch_channel_get_variable", _wrap_fs_switch_channel_get_variable},
+	{"fs_perlc::fs_switch_channel_set_variable", _wrap_fs_switch_channel_set_variable},
+	{0, 0}
 };
 
 #ifdef __cplusplus
 extern "C"
 #endif
+XS(SWIG_init)
+{
+	dXSARGS;
+	int i;
+	static int _init = 0;
+	if (!_init) {
+		for (i = 0; swig_types_initial[i]; i++) {
+			swig_types[i] = SWIG_TypeRegister(swig_types_initial[i]);
+		}
+		_init = 1;
+	}
+
+	/* Install commands */
+	for (i = 0; swig_commands[i].name; i++) {
+		newXS((char *) swig_commands[i].name, swig_commands[i].wrapper, (char *) __FILE__);
+	}
+
+	/* Install variables */
+	for (i = 0; swig_variables[i].name; i++) {
+		SV *sv;
+		sv = perl_get_sv((char *) swig_variables[i].name, TRUE | 0x2);
+		if (swig_variables[i].type) {
+			SWIG_MakePtr(sv, (void *) 1, *swig_variables[i].type, 0);
+		} else {
+			sv_setiv(sv, (IV) 0);
+		}
+		swig_create_magic(sv, (char *) swig_variables[i].name, swig_variables[i].set, swig_variables[i].get);
+	}
+
+	/* Install constant */
+	for (i = 0; swig_constants[i].type; i++) {
+		SV *sv;
+		sv = perl_get_sv((char *) swig_constants[i].name, TRUE | 0x2);
+		switch (swig_constants[i].type) {
+		case SWIG_INT:
+			sv_setiv(sv, (IV) swig_constants[i].lvalue);
+			break;
+		case SWIG_FLOAT:
+			sv_setnv(sv, (double) swig_constants[i].dvalue);
+			break;
+		case SWIG_STRING:
+			sv_setpv(sv, (char *) swig_constants[i].pvalue);
+			break;
+		case SWIG_POINTER:
+			SWIG_MakePtr(sv, swig_constants[i].pvalue, *(swig_constants[i].ptype), 0);
+			break;
+		case SWIG_BINARY:
+			SWIG_MakePackedObj(sv, swig_constants[i].pvalue, swig_constants[i].lvalue, *(swig_constants[i].ptype));
+			break;
+		default:
+			break;
+		}
+		SvREADONLY_on(sv);
+	}
 
-XS(SWIG_init) {
-    dXSARGS;
-    int i;
-    static int _init = 0;
-    if (!_init) {
-        for (i = 0; swig_types_initial[i]; i++) {
-            swig_types[i] = SWIG_TypeRegister(swig_types_initial[i]);
-        }	
-        _init = 1;
-    }
-    
-    /* Install commands */
-    for (i = 0; swig_commands[i].name; i++) {
-        newXS((char*) swig_commands[i].name,swig_commands[i].wrapper, (char*)__FILE__);
-    }
-    
-    /* Install variables */
-    for (i = 0; swig_variables[i].name; i++) {
-        SV *sv;
-        sv = perl_get_sv((char*) swig_variables[i].name, TRUE | 0x2);
-        if (swig_variables[i].type) {
-            SWIG_MakePtr(sv,(void *)1, *swig_variables[i].type,0);
-        } else {
-            sv_setiv(sv,(IV) 0);
-        }
-        swig_create_magic(sv, (char *) swig_variables[i].name, swig_variables[i].set, swig_variables[i].get); 
-    }
-    
-    /* Install constant */
-    for (i = 0; swig_constants[i].type; i++) {
-        SV *sv;
-        sv = perl_get_sv((char*)swig_constants[i].name, TRUE | 0x2);
-        switch(swig_constants[i].type) {
-            case SWIG_INT:
-            sv_setiv(sv, (IV) swig_constants[i].lvalue);
-            break;
-            case SWIG_FLOAT:
-            sv_setnv(sv, (double) swig_constants[i].dvalue);
-            break;
-            case SWIG_STRING:
-            sv_setpv(sv, (char *) swig_constants[i].pvalue);
-            break;
-            case SWIG_POINTER:
-            SWIG_MakePtr(sv, swig_constants[i].pvalue, *(swig_constants[i].ptype),0);
-            break;
-            case SWIG_BINARY:
-            SWIG_MakePackedObj(sv, swig_constants[i].pvalue, swig_constants[i].lvalue, *(swig_constants[i].ptype));
-            break;
-            default:
-            break;
-        }
-        SvREADONLY_on(sv);
-    }
-    
-    ST(0) = &PL_sv_yes;
-    XSRETURN(1);
+	ST(0) = &PL_sv_yes;
+	XSRETURN(1);
 }
-

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_python/freeswitch_python.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_python/freeswitch_python.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_python/freeswitch_python.h	Fri Mar 30 12:19:18 2007
@@ -1,4 +1,4 @@
-#ifndef FREESWITCH_PYTHON_H 
+#ifndef FREESWITCH_PYTHON_H
 #define FREESWITCH_PYTHON_H
 
 #include <Python.h>
@@ -9,45 +9,40 @@
 
 #include <switch.h>
 
-extern void *globalDTMFCallbackFunction;
-extern switch_status_t PythonDTMFCallback(switch_core_session *session, 
-                                    void *input, 
-                                    switch_input_type_t itype,
-                                    void *buf,
-                                    unsigned int buflen);
-
-class SessionContainer {
-    private:
-        switch_core_session_t *session;
-        switch_channel_t *channel;
-        char *uuid;
-        PyObject *dtmfCallbackFunction;
-        char *tts_name;
-        char *voice_name;
-    public:
-        SessionContainer(char *uuid);
-        ~SessionContainer();
-        void console_log(char *level_str, char *msg);
-        void console_clean_log(char *msg);
-        int  answer();
-        int  pre_answer();
-        void hangup(char *cause);
-        void set_variable(char *var, char *val);
-        void get_variable(char *var, char *val);
-        void set_state(char *state);
-        int  play_file(char *file, char *timer_name);
-        void set_dtmf_callback(PyObject *pyfunc);
-        int  speak_text(char *text);
-        void set_tts_parms(char *tts_name, char *voice_name);
-        int  get_digits(char *dtmf_buf, int len, char *terminators, char *terminator, int timeout);
-        int  transfer(char *extensions, char *dialplan, char *context);
-        int  play_and_get_digits(int min_digits, int max_digits, int max_tries, int timeout, char *terminators, 
-                char *audio_files, char *bad_input_audio_files, char *dtmf_buf, char *digits_regex);
-    protected:
-};
+	extern void *globalDTMFCallbackFunction;
+	extern switch_status_t PythonDTMFCallback(switch_core_session * session, void *input, switch_input_type_t itype, void *buf, unsigned int buflen);
+
+	class SessionContainer {
+	  private:
+		switch_core_session_t *session;
+		switch_channel_t *channel;
+		char *uuid;
+		PyObject *dtmfCallbackFunction;
+		char *tts_name;
+		char *voice_name;
+	  public:
+		     SessionContainer(char *uuid);
+		    ~SessionContainer();
+		void console_log(char *level_str, char *msg);
+		void console_clean_log(char *msg);
+		int answer();
+		int pre_answer();
+		void hangup(char *cause);
+		void set_variable(char *var, char *val);
+		void get_variable(char *var, char *val);
+		void set_state(char *state);
+		int play_file(char *file, char *timer_name);
+		void set_dtmf_callback(PyObject * pyfunc);
+		int speak_text(char *text);
+		void set_tts_parms(char *tts_name, char *voice_name);
+		int get_digits(char *dtmf_buf, int len, char *terminators, char *terminator, int timeout);
+		int transfer(char *extensions, char *dialplan, char *context);
+		int play_and_get_digits(int min_digits, int max_digits, int max_tries, int timeout, char *terminators,
+								char *audio_files, char *bad_input_audio_files, char *dtmf_buf, char *digits_regex);
+	  protected:
+	};
 
 #ifdef __cplusplus
 }
 #endif
-
 #endif

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_python/mod_python.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_python/mod_python.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_python/mod_python.c	Fri Mar 30 12:19:18 2007
@@ -50,54 +50,55 @@
 static void python_function(switch_core_session_t *session, char *data)
 {
 	char *uuid = switch_core_session_get_uuid(session);
-    char *argv[1];
-    FILE* pythonfile;
+	char *argv[1];
+	FILE *pythonfile;
 
-    argv[0] = uuid;
-    pythonfile = fopen(data, "r");
+	argv[0] = uuid;
+	pythonfile = fopen(data, "r");
 
-    Py_Initialize();
-    PySys_SetArgv(1, argv);
-    init_freeswitch();
-    PyRun_SimpleFile(pythonfile, "");
-    Py_Finalize();
+	Py_Initialize();
+	PySys_SetArgv(1, argv);
+	init_freeswitch();
+	PyRun_SimpleFile(pythonfile, "");
+	Py_Finalize();
 
 }
 
 static switch_status_t launch_python(char *text, switch_core_session_t *session, switch_stream_handle_t *stream)
 {
-    FILE* pythonfile;
+	FILE *pythonfile;
 
-    if (switch_strlen_zero(text)) {
-        stream->write_function(stream, "USAGE: %s\n", python_run_interface.syntax);
-        return SWITCH_STATUS_SUCCESS;
-    }
-
-    pythonfile = fopen(text, "r");
-
-    Py_Initialize();
-    init_freeswitch();
-    PyRun_SimpleFile(pythonfile, "");
-    Py_Finalize();
+	if (switch_strlen_zero(text)) {
+		stream->write_function(stream, "USAGE: %s\n", python_run_interface.syntax);
+		return SWITCH_STATUS_SUCCESS;
+	}
 
-    stream->write_function(stream, "OK\n");
-    return SWITCH_STATUS_SUCCESS;
+	pythonfile = fopen(text, "r");
+
+	Py_Initialize();
+	init_freeswitch();
+	PyRun_SimpleFile(pythonfile, "");
+	Py_Finalize();
+
+	stream->write_function(stream, "OK\n");
+	return SWITCH_STATUS_SUCCESS;
 }
 
 static const switch_application_interface_t python_application_interface = {
 	/*.interface_name */ "python",
 	/*.application_function */ python_function,
 	NULL, NULL, NULL,
-	/* flags */ SAF_NONE, /* should we support no media mode here?  If so, we need to detect the mode, and either disable the media functions or indicate media if/when we need */
-	/*.next*/ NULL
+	/* flags */ SAF_NONE,
+	/* should we support no media mode here?  If so, we need to detect the mode, and either disable the media functions or indicate media if/when we need */
+	/*.next */ NULL
 };
 
 static switch_api_interface_t python_run_interface = {
-    /*.interface_name */ "python",
-    /*.desc */ "run a python script",
-    /*.function */ launch_python,
-    /*.syntax */ "python </path/to/script>",
-    /*.next */ NULL
+	/*.interface_name */ "python",
+	/*.desc */ "run a python script",
+	/*.function */ launch_python,
+	/*.syntax */ "python </path/to/script>",
+	/*.next */ NULL
 };
 
 static switch_loadable_module_interface_t python_module_interface = {

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_python/switch_swig_wrap.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_python/switch_swig_wrap.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_python/switch_swig_wrap.c	Fri Mar 30 12:19:18 2007
@@ -21,7 +21,7 @@
 #  if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560)
 #    define SWIGTEMPLATEDISAMBIGUATOR template
 #  else
-#    define SWIGTEMPLATEDISAMBIGUATOR 
+#    define SWIGTEMPLATEDISAMBIGUATOR
 #  endif
 #endif
 
@@ -37,9 +37,9 @@
 /* attribute recognised by some compilers to avoid 'unused' warnings */
 #ifndef SWIGUNUSED
 # if defined(__GNUC__) || defined(__ICC)
-#   define SWIGUNUSED __attribute__ ((unused)) 
+#   define SWIGUNUSED __attribute__ ((unused))
 # else
-#   define SWIGUNUSED 
+#   define SWIGUNUSED
 # endif
 #endif
 
@@ -72,7 +72,7 @@
 #   define SWIGSTDCALL __stdcall
 # else
 #   define SWIGSTDCALL
-# endif 
+# endif
 #endif
 
 
@@ -123,37 +123,37 @@
 extern "C" {
 #endif
 
-typedef void *(*swig_converter_func)(void *);
-typedef struct swig_type_info *(*swig_dycast_func)(void **);
+	typedef void *(*swig_converter_func) (void *);
+	typedef struct swig_type_info *(*swig_dycast_func) (void **);
 
 /* Structure to store inforomation on one type */
-typedef struct swig_type_info {
-  const char             *name;			/* mangled name of this type */
-  const char             *str;			/* human readable name of this type */
-  swig_dycast_func        dcast;		/* dynamic cast function down a hierarchy */
-  struct swig_cast_info  *cast;			/* linked list of types that can cast into this type */
-  void                   *clientdata;		/* language specific type data */
-} swig_type_info;
+	typedef struct swig_type_info {
+		const char *name;		/* mangled name of this type */
+		const char *str;		/* human readable name of this type */
+		swig_dycast_func dcast;	/* dynamic cast function down a hierarchy */
+		struct swig_cast_info *cast;	/* linked list of types that can cast into this type */
+		void *clientdata;		/* language specific type data */
+	} swig_type_info;
 
 /* Structure to store a type and conversion function used for casting */
-typedef struct swig_cast_info {
-  swig_type_info         *type;			/* pointer to type that is equivalent to this type */
-  swig_converter_func     converter;		/* function to cast the void pointers */
-  struct swig_cast_info  *next;			/* pointer to next cast in linked list */
-  struct swig_cast_info  *prev;			/* pointer to the previous cast */
-} swig_cast_info;
+	typedef struct swig_cast_info {
+		swig_type_info *type;	/* pointer to type that is equivalent to this type */
+		swig_converter_func converter;	/* function to cast the void pointers */
+		struct swig_cast_info *next;	/* pointer to next cast in linked list */
+		struct swig_cast_info *prev;	/* pointer to the previous cast */
+	} swig_cast_info;
 
 /* Structure used to store module information
  * Each module generates one structure like this, and the runtime collects
  * all of these structures and stores them in a circularly linked list.*/
-typedef struct swig_module_info {
-  swig_type_info         **types;		/* Array of pointers to swig_type_info structures that are in this module */
-  size_t                 size;		        /* Number of types in this module */
-  struct swig_module_info *next;		/* Pointer to next element in circularly linked list */
-  swig_type_info         **type_initial;	/* Array of initially generated type structures */
-  swig_cast_info         **cast_initial;	/* Array of initially generated casting structures */
-  void                    *clientdata;		/* Language specific module data */
-} swig_module_info;
+	typedef struct swig_module_info {
+		swig_type_info **types;	/* Array of pointers to swig_type_info structures that are in this module */
+		size_t size;			/* Number of types in this module */
+		struct swig_module_info *next;	/* Pointer to next element in circularly linked list */
+		swig_type_info **type_initial;	/* Array of initially generated type structures */
+		swig_cast_info **cast_initial;	/* Array of initially generated casting structures */
+		void *clientdata;		/* Language specific module data */
+	} swig_module_info;
 
 
 /* 
@@ -163,54 +163,59 @@
   Return 0 when the two name types are equivalent, as in
   strncmp, but skipping ' '.
 */
-SWIGRUNTIME int
-SWIG_TypeNameComp(const char *f1, const char *l1,
-		  const char *f2, const char *l2) {
-  for (;(f1 != l1) && (f2 != l2); ++f1, ++f2) {
-    while ((*f1 == ' ') && (f1 != l1)) ++f1;
-    while ((*f2 == ' ') && (f2 != l2)) ++f2;
-    if (*f1 != *f2) return (int)(*f1 - *f2);
-  }
-  return (l1 - f1) - (l2 - f2);
-}
+	SWIGRUNTIME int
+	    SWIG_TypeNameComp(const char *f1, const char *l1, const char *f2, const char *l2) {
+		for (; (f1 != l1) && (f2 != l2); ++f1, ++f2) {
+			while ((*f1 == ' ') && (f1 != l1))
+				++f1;
+			while ((*f2 == ' ') && (f2 != l2))
+				++f2;
+			if (*f1 != *f2)
+				return (int) (*f1 - *f2);
+		} return (l1 - f1) - (l2 - f2);
+	}
 
 /*
   Check type equivalence in a name list like <name1>|<name2>|...
   Return 0 if not equal, 1 if equal
 */
-SWIGRUNTIME int
-SWIG_TypeEquiv(const char *nb, const char *tb) {
-  int equiv = 0;
-  const char* te = tb + strlen(tb);
-  const char* ne = nb;
-  while (!equiv && *ne) {
-    for (nb = ne; *ne; ++ne) {
-      if (*ne == '|') break;
-    }
-    equiv = (SWIG_TypeNameComp(nb, ne, tb, te) == 0) ? 1 : 0;
-    if (*ne) ++ne;
-  }
-  return equiv;
-}
+	SWIGRUNTIME int
+	    SWIG_TypeEquiv(const char *nb, const char *tb) {
+		int equiv = 0;
+		const char *te = tb + strlen(tb);
+		const char *ne = nb;
+		while (!equiv && *ne) {
+			for (nb = ne; *ne; ++ne) {
+				if (*ne == '|')
+					break;
+			}
+			equiv = (SWIG_TypeNameComp(nb, ne, tb, te) == 0) ? 1 : 0;
+			if (*ne)
+				++ne;
+		}
+		return equiv;
+	}
 
 /*
   Check type equivalence in a name list like <name1>|<name2>|...
   Return 0 if equal, -1 if nb < tb, 1 if nb > tb
 */
-SWIGRUNTIME int
-SWIG_TypeCompare(const char *nb, const char *tb) {
-  int equiv = 0;
-  const char* te = tb + strlen(tb);
-  const char* ne = nb;
-  while (!equiv && *ne) {
-    for (nb = ne; *ne; ++ne) {
-      if (*ne == '|') break;
-    }
-    equiv = (SWIG_TypeNameComp(nb, ne, tb, te) == 0) ? 1 : 0;
-    if (*ne) ++ne;
-  }
-  return equiv;
-}
+	SWIGRUNTIME int
+	    SWIG_TypeCompare(const char *nb, const char *tb) {
+		int equiv = 0;
+		const char *te = tb + strlen(tb);
+		const char *ne = nb;
+		while (!equiv && *ne) {
+			for (nb = ne; *ne; ++ne) {
+				if (*ne == '|')
+					break;
+			}
+			equiv = (SWIG_TypeNameComp(nb, ne, tb, te) == 0) ? 1 : 0;
+			if (*ne)
+				++ne;
+		}
+		return equiv;
+	}
 
 
 /* think of this as a c++ template<> or a scheme macro */
@@ -238,87 +243,83 @@
 /*
   Check the typename
 */
-SWIGRUNTIME swig_cast_info *
-SWIG_TypeCheck(const char *c, swig_type_info *ty) {
-  SWIG_TypeCheck_Template(strcmp(iter->type->name, c) == 0, ty);
-}
+	SWIGRUNTIME swig_cast_info *SWIG_TypeCheck(const char *c, swig_type_info * ty) {
+		SWIG_TypeCheck_Template(strcmp(iter->type->name, c) == 0, ty);
+	}
 
 /* Same as previous function, except strcmp is replaced with a pointer comparison */
-SWIGRUNTIME swig_cast_info *
-SWIG_TypeCheckStruct(swig_type_info *from, swig_type_info *into) {
-  SWIG_TypeCheck_Template(iter->type == from, into);
-}
+	SWIGRUNTIME swig_cast_info *SWIG_TypeCheckStruct(swig_type_info * from, swig_type_info * into) {
+		SWIG_TypeCheck_Template(iter->type == from, into);
+	}
 
 /*
   Cast a pointer up an inheritance hierarchy
 */
-SWIGRUNTIMEINLINE void *
-SWIG_TypeCast(swig_cast_info *ty, void *ptr) {
-  return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr);
-}
+	SWIGRUNTIMEINLINE void *SWIG_TypeCast(swig_cast_info * ty, void *ptr) {
+		return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter) (ptr);
+	}
 
 /* 
    Dynamic pointer casting. Down an inheritance hierarchy
 */
-SWIGRUNTIME swig_type_info *
-SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr) {
-  swig_type_info *lastty = ty;
-  if (!ty || !ty->dcast) return ty;
-  while (ty && (ty->dcast)) {
-    ty = (*ty->dcast)(ptr);
-    if (ty) lastty = ty;
-  }
-  return lastty;
-}
+	SWIGRUNTIME swig_type_info *SWIG_TypeDynamicCast(swig_type_info * ty, void **ptr) {
+		swig_type_info *lastty = ty;
+		if (!ty || !ty->dcast)
+			return ty;
+		while (ty && (ty->dcast)) {
+			ty = (*ty->dcast) (ptr);
+			if (ty)
+				lastty = ty;
+		}
+		return lastty;
+	}
 
 /*
   Return the name associated with this type
 */
-SWIGRUNTIMEINLINE const char *
-SWIG_TypeName(const swig_type_info *ty) {
-  return ty->name;
-}
+	SWIGRUNTIMEINLINE const char *SWIG_TypeName(const swig_type_info * ty) {
+		return ty->name;
+	}
 
 /*
   Return the pretty name associated with this type,
   that is an unmangled type name in a form presentable to the user.
 */
-SWIGRUNTIME const char *
-SWIG_TypePrettyName(const swig_type_info *type) {
-  /* The "str" field contains the equivalent pretty names of the
-     type, separated by vertical-bar characters.  We choose
-     to print the last name, as it is often (?) the most
-     specific. */
-  if (type->str != NULL) {
-    const char *last_name = type->str;
-    const char *s;
-    for (s = type->str; *s; s++)
-      if (*s == '|') last_name = s+1;
-    return last_name;
-  }
-  else
-    return type->name;
-}
+	SWIGRUNTIME const char *SWIG_TypePrettyName(const swig_type_info * type) {
+		/* The "str" field contains the equivalent pretty names of the
+		   type, separated by vertical-bar characters.  We choose
+		   to print the last name, as it is often (?) the most
+		   specific. */
+		if (type->str != NULL) {
+			const char *last_name = type->str;
+			const char *s;
+			for (s = type->str; *s; s++)
+				if (*s == '|')
+					last_name = s + 1;
+			return last_name;
+		} else
+			return type->name;
+	}
 
 /* 
    Set the clientdata field for a type
 */
-SWIGRUNTIME void
-SWIG_TypeClientData(swig_type_info *ti, void *clientdata) {
-  swig_cast_info *cast = ti->cast;
-  /* if (ti->clientdata == clientdata) return; */
-  ti->clientdata = clientdata;
-  
-  while (cast) {
-    if (!cast->converter) {
-      swig_type_info *tc = cast->type;
-      if (!tc->clientdata) {
-	SWIG_TypeClientData(tc, clientdata);
-      }
-    }    
-    cast = cast->next;
-  }
-}
+	SWIGRUNTIME void
+	     SWIG_TypeClientData(swig_type_info * ti, void *clientdata) {
+		swig_cast_info *cast = ti->cast;
+		/* if (ti->clientdata == clientdata) return; */
+		ti->clientdata = clientdata;
+
+		while (cast) {
+			if (!cast->converter) {
+				swig_type_info *tc = cast->type;
+				if (!tc->clientdata) {
+					SWIG_TypeClientData(tc, clientdata);
+				}
+			}
+			cast = cast->next;
+		}
+	}
 
 /*
   Search for a swig_type_info structure only by mangled name
@@ -328,41 +329,38 @@
   Note: if start == end at the beginning of the function, we go all the way around
   the circular list.
 */
-SWIGRUNTIME swig_type_info *
-SWIG_MangledTypeQueryModule(swig_module_info *start, 
-                            swig_module_info *end, 
-		            const char *name) {
-  swig_module_info *iter = start;
-  do {
-    if (iter->size) {
-      register size_t l = 0;
-      register size_t r = iter->size - 1;
-      do {
-	/* since l+r >= 0, we can (>> 1) instead (/ 2) */
-	register size_t i = (l + r) >> 1; 
-	const char *iname = iter->types[i]->name;
-	if (iname) {
-	  register int compare = strcmp(name, iname);
-	  if (compare == 0) {	    
-	    return iter->types[i];
-	  } else if (compare < 0) {
-	    if (i) {
-	      r = i - 1;
-	    } else {
-	      break;
-	    }
-	  } else if (compare > 0) {
-	    l = i + 1;
-	  }
-	} else {
-	  break; /* should never happen */
+	SWIGRUNTIME swig_type_info *SWIG_MangledTypeQueryModule(swig_module_info * start, swig_module_info * end, const char *name) {
+		swig_module_info *iter = start;
+		do {
+			if (iter->size) {
+				register size_t l = 0;
+				register size_t r = iter->size - 1;
+				do {
+					/* since l+r >= 0, we can (>> 1) instead (/ 2) */
+					register size_t i = (l + r) >> 1;
+					const char *iname = iter->types[i]->name;
+					if (iname) {
+						register int compare = strcmp(name, iname);
+						if (compare == 0) {
+							return iter->types[i];
+						} else if (compare < 0) {
+							if (i) {
+								r = i - 1;
+							} else {
+								break;
+							}
+						} else if (compare > 0) {
+							l = i + 1;
+						}
+					} else {
+						break;	/* should never happen */
+					}
+				} while (l <= r);
+			}
+			iter = iter->next;
+		} while (iter != end);
+		return 0;
 	}
-      } while (l <= r);
-    }
-    iter = iter->next;
-  } while (iter != end);
-  return 0;
-}
 
 /*
   Search for a swig_type_info structure for either a mangled name or a human readable name.
@@ -373,131 +371,125 @@
   Note: if start == end at the beginning of the function, we go all the way around
   the circular list.
 */
-SWIGRUNTIME swig_type_info *
-SWIG_TypeQueryModule(swig_module_info *start, 
-                     swig_module_info *end, 
-		     const char *name) {
-  /* STEP 1: Search the name field using binary search */
-  swig_type_info *ret = SWIG_MangledTypeQueryModule(start, end, name);
-  if (ret) {
-    return ret;
-  } else {
-    /* STEP 2: If the type hasn't been found, do a complete search
-       of the str field (the human readable name) */
-    swig_module_info *iter = start;
-    do {
-      register size_t i = 0;
-      for (; i < iter->size; ++i) {
-	if (iter->types[i]->str && (SWIG_TypeEquiv(iter->types[i]->str, name)))
-	  return iter->types[i];
-      }
-      iter = iter->next;
-    } while (iter != end);
-  }
-  
-  /* neither found a match */
-  return 0;
-}
+	SWIGRUNTIME swig_type_info *SWIG_TypeQueryModule(swig_module_info * start, swig_module_info * end, const char *name) {
+		/* STEP 1: Search the name field using binary search */
+		swig_type_info *ret = SWIG_MangledTypeQueryModule(start, end, name);
+		if (ret) {
+			return ret;
+		} else {
+			/* STEP 2: If the type hasn't been found, do a complete search
+			   of the str field (the human readable name) */
+			swig_module_info *iter = start;
+			do {
+				register size_t i = 0;
+				for (; i < iter->size; ++i) {
+					if (iter->types[i]->str && (SWIG_TypeEquiv(iter->types[i]->str, name)))
+						return iter->types[i];
+				}
+				iter = iter->next;
+			} while (iter != end);
+		}
+
+		/* neither found a match */
+		return 0;
+	}
 
 
 /* 
    Pack binary data into a string
 */
-SWIGRUNTIME char *
-SWIG_PackData(char *c, void *ptr, size_t sz) {
-  static const char hex[17] = "0123456789abcdef";
-  register const unsigned char *u = (unsigned char *) ptr;
-  register const unsigned char *eu =  u + sz;
-  for (; u != eu; ++u) {
-    register unsigned char uu = *u;
-    *(c++) = hex[(uu & 0xf0) >> 4];
-    *(c++) = hex[uu & 0xf];
-  }
-  return c;
-}
+	SWIGRUNTIME char *SWIG_PackData(char *c, void *ptr, size_t sz) {
+		static const char hex[17] = "0123456789abcdef";
+		register const unsigned char *u = (unsigned char *) ptr;
+		register const unsigned char *eu = u + sz;
+		for (; u != eu; ++u) {
+			register unsigned char uu = *u;
+			*(c++) = hex[(uu & 0xf0) >> 4];
+			*(c++) = hex[uu & 0xf];
+		}
+		return c;
+	}
 
 /* 
    Unpack binary data from a string
 */
-SWIGRUNTIME const char *
-SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
-  register unsigned char *u = (unsigned char *) ptr;
-  register const unsigned char *eu = u + sz;
-  for (; u != eu; ++u) {
-    register char d = *(c++);
-    register unsigned char uu = 0;
-    if ((d >= '0') && (d <= '9'))
-      uu = ((d - '0') << 4);
-    else if ((d >= 'a') && (d <= 'f'))
-      uu = ((d - ('a'-10)) << 4);
-    else 
-      return (char *) 0;
-    d = *(c++);
-    if ((d >= '0') && (d <= '9'))
-      uu |= (d - '0');
-    else if ((d >= 'a') && (d <= 'f'))
-      uu |= (d - ('a'-10));
-    else 
-      return (char *) 0;
-    *u = uu;
-  }
-  return c;
-}
+	SWIGRUNTIME const char *SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
+		register unsigned char *u = (unsigned char *) ptr;
+		register const unsigned char *eu = u + sz;
+		for (; u != eu; ++u) {
+			register char d = *(c++);
+			register unsigned char uu = 0;
+			if ((d >= '0') && (d <= '9'))
+				uu = ((d - '0') << 4);
+			else if ((d >= 'a') && (d <= 'f'))
+				uu = ((d - ('a' - 10)) << 4);
+			else
+				return (char *) 0;
+			d = *(c++);
+			if ((d >= '0') && (d <= '9'))
+				uu |= (d - '0');
+			else if ((d >= 'a') && (d <= 'f'))
+				uu |= (d - ('a' - 10));
+			else
+				return (char *) 0;
+			*u = uu;
+		}
+		return c;
+	}
 
 /* 
    Pack 'void *' into a string buffer.
 */
-SWIGRUNTIME char *
-SWIG_PackVoidPtr(char *buff, void *ptr, const char *name, size_t bsz) {
-  char *r = buff;
-  if ((2*sizeof(void *) + 2) > bsz) return 0;
-  *(r++) = '_';
-  r = SWIG_PackData(r,&ptr,sizeof(void *));
-  if (strlen(name) + 1 > (bsz - (r - buff))) return 0;
-  strcpy(r,name);
-  return buff;
-}
+	SWIGRUNTIME char *SWIG_PackVoidPtr(char *buff, void *ptr, const char *name, size_t bsz) {
+		char *r = buff;
+		if ((2 * sizeof(void *) + 2) > bsz)
+			return 0;
+		*(r++) = '_';
+		r = SWIG_PackData(r, &ptr, sizeof(void *));
+		if (strlen(name) + 1 > (bsz - (r - buff)))
+			return 0;
+		strcpy(r, name);
+		return buff;
+	}
 
-SWIGRUNTIME const char *
-SWIG_UnpackVoidPtr(const char *c, void **ptr, const char *name) {
-  if (*c != '_') {
-    if (strcmp(c,"NULL") == 0) {
-      *ptr = (void *) 0;
-      return name;
-    } else {
-      return 0;
-    }
-  }
-  return SWIG_UnpackData(++c,ptr,sizeof(void *));
-}
+	SWIGRUNTIME const char *SWIG_UnpackVoidPtr(const char *c, void **ptr, const char *name) {
+		if (*c != '_') {
+			if (strcmp(c, "NULL") == 0) {
+				*ptr = (void *) 0;
+				return name;
+			} else {
+				return 0;
+			}
+		}
+		return SWIG_UnpackData(++c, ptr, sizeof(void *));
+	}
 
-SWIGRUNTIME char *
-SWIG_PackDataName(char *buff, void *ptr, size_t sz, const char *name, size_t bsz) {
-  char *r = buff;
-  size_t lname = (name ? strlen(name) : 0);
-  if ((2*sz + 2 + lname) > bsz) return 0;
-  *(r++) = '_';
-  r = SWIG_PackData(r,ptr,sz);
-  if (lname) {
-    strncpy(r,name,lname+1);
-  } else {
-    *r = 0;
-  }
-  return buff;
-}
+	SWIGRUNTIME char *SWIG_PackDataName(char *buff, void *ptr, size_t sz, const char *name, size_t bsz) {
+		char *r = buff;
+		size_t lname = (name ? strlen(name) : 0);
+		if ((2 * sz + 2 + lname) > bsz)
+			return 0;
+		*(r++) = '_';
+		r = SWIG_PackData(r, ptr, sz);
+		if (lname) {
+			strncpy(r, name, lname + 1);
+		} else {
+			*r = 0;
+		}
+		return buff;
+	}
 
-SWIGRUNTIME const char *
-SWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name) {
-  if (*c != '_') {
-    if (strcmp(c,"NULL") == 0) {
-      memset(ptr,0,sz);
-      return name;
-    } else {
-      return 0;
-    }
-  }
-  return SWIG_UnpackData(++c,ptr,sz);
-}
+	SWIGRUNTIME const char *SWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name) {
+		if (*c != '_') {
+			if (strcmp(c, "NULL") == 0) {
+				memset(ptr, 0, sz);
+				return name;
+			} else {
+				return 0;
+			}
+		}
+		return SWIG_UnpackData(++c, ptr, sz);
+	}
 
 #ifdef __cplusplus
 }
@@ -551,14 +543,14 @@
 #define SWIG_PY_BINARY  5
 
 /* Constant information structure */
-typedef struct swig_const_info {
-    int type;
-    char *name;
-    long lvalue;
-    double dvalue;
-    void   *pvalue;
-    swig_type_info **ptype;
-} swig_const_info;
+	typedef struct swig_const_info {
+		int type;
+		char *name;
+		long lvalue;
+		double dvalue;
+		void *pvalue;
+		swig_type_info **ptype;
+	} swig_const_info;
 
 
 /* -----------------------------------------------------------------------------
@@ -571,8 +563,6 @@
 #ifdef __cplusplus
 }
 #endif
-
-
 /***********************************************************************
  * pyrun.swg
  *
@@ -581,44 +571,33 @@
  *     type checking.
  *
  * Author : David Beazley (beazley at cs.uchicago.edu)
- ************************************************************************/
-
-/* Common SWIG API */
+																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																													   ************************************************************************//* Common SWIG API */
 #define SWIG_ConvertPtr(obj, pp, type, flags)    SWIG_Python_ConvertPtr(obj, pp, type, flags)
 #define SWIG_NewPointerObj(p, type, flags)       SWIG_Python_NewPointerObj(p, type, flags)
 #define SWIG_MustGetPtr(p, type, argnum, flags)  SWIG_Python_MustGetPtr(p, type, argnum, flags)
- 
-
 /* Python-specific SWIG API */
 #define SWIG_ConvertPacked(obj, ptr, sz, ty, flags)   SWIG_Python_ConvertPacked(obj, ptr, sz, ty, flags)
 #define SWIG_NewPackedObj(ptr, sz, type)              SWIG_Python_NewPackedObj(ptr, sz, type)
-
 /* Runtime API */
 #define SWIG_GetModule(clientdata) SWIG_Python_GetModule()
 #define SWIG_SetModule(clientdata, pointer) SWIG_Python_SetModule(pointer)
-
 /* -----------------------------------------------------------------------------
  * Pointer declarations
- * ----------------------------------------------------------------------------- */
-/*
-  Use SWIG_NO_COBJECT_TYPES to force the use of strings to represent
-  C/C++ pointers in the python side. Very useful for debugging, but
-  not always safe.
-*/
+																																																																																																																																																																																																																																																																																																																																								  																																																																																																																																																																				  																																																																																		  																																									  																				    * ----------------------------------------------------------------------------- *//*
+																																																																																																																																																																																																																																																																																																																																								     Use SWIG_NO_COBJECT_TYPES to force the use of strings to represent
+																																																																																																																																																																																																																																																																																																																																								     C/C++ pointers in the python side. Very useful for debugging, but
+																																																																																																																																																																																																																																																																																																																																								     not always safe.
+																																																																																																																																																																																																																																																																																																																																								   */
 #if !defined(SWIG_NO_COBJECT_TYPES) && !defined(SWIG_COBJECT_TYPES)
 #  define SWIG_COBJECT_TYPES
 #endif
-
 /* Flags for pointer conversion */
 #define SWIG_POINTER_EXCEPTION     0x1
 #define SWIG_POINTER_DISOWN        0x2
-
-
 /* Add PyOS_snprintf for old Pythons */
 #if PY_VERSION_HEX < 0x02020000
 #define PyOS_snprintf snprintf
 #endif
-
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -632,507 +611,450 @@
 
 /* A crude PyString_FromFormat implementation for old Pythons */
 #if PY_VERSION_HEX < 0x02020000
-static PyObject *
-PyString_FromFormat(const char *fmt, ...) {
-  va_list ap;
-  char buf[SWIG_BUFFER_SIZE * 2];
-  int res;
-  va_start(ap, fmt);
-  res = vsnprintf(buf, sizeof(buf), fmt, ap);
-  va_end(ap);
-  return (res < 0 || res >= sizeof(buf)) ? 0 : PyString_FromString(buf);
-}
+	static PyObject *PyString_FromFormat(const char *fmt, ...) {
+		va_list ap;
+		char buf[SWIG_BUFFER_SIZE * 2];
+		int res;
+		    va_start(ap, fmt);
+		    res = vsnprintf(buf, sizeof(buf), fmt, ap);
+		    va_end(ap);
+		    return (res < 0 || res >= sizeof(buf)) ? 0 : PyString_FromString(buf);
+	}
 #endif
-
 #if PY_VERSION_HEX < 0x01060000
 #define PyObject_Del(op) PyMem_DEL((op))
 #endif
-
 #if defined(SWIG_COBJECT_TYPES)
 #if !defined(SWIG_COBJECT_PYTHON)
 /* -----------------------------------------------------------------------------
  * Implements a simple Swig Object type, and use it instead of PyCObject
- * ----------------------------------------------------------------------------- */
-
-typedef struct {
-  PyObject_HEAD
-  void *ptr;
-  const char *desc;
-} PySwigObject;
+ * ----------------------------------------------------------------------------- */ typedef struct {
+		PyObject_HEAD void *ptr;
+		const char *desc;
+	} PySwigObject;
 
 /* Declarations for objects of type PySwigObject */
 
-SWIGRUNTIME int
-PySwigObject_print(PySwigObject *v, FILE *fp, int flags)
-{
-  char result[SWIG_BUFFER_SIZE];
-  flags = flags;
-  if (SWIG_PackVoidPtr(result, v->ptr, v->desc, sizeof(result))) {
-    fputs("<Swig Object at ", fp); fputs(result, fp); fputs(">", fp);
-    return 0; 
-  } else {
-    return 1; 
-  }
-}
-  
-SWIGRUNTIME PyObject *
-PySwigObject_repr(PySwigObject *v)
-{
-  char result[SWIG_BUFFER_SIZE];
-  return SWIG_PackVoidPtr(result, v->ptr, v->desc, sizeof(result)) ?
-    PyString_FromFormat("<Swig Object at %s>", result) : 0;
-}
+	SWIGRUNTIME int
+	    PySwigObject_print(PySwigObject * v, FILE * fp, int flags) {
+		char result[SWIG_BUFFER_SIZE];
+		flags = flags;
+		if (SWIG_PackVoidPtr(result, v->ptr, v->desc, sizeof(result))) {
+			fputs("<Swig Object at ", fp);
+			fputs(result, fp);
+			fputs(">", fp);
+			return 0;
+		} else {
+			return 1;
+		}
+	}
 
-SWIGRUNTIME PyObject *
-PySwigObject_str(PySwigObject *v)
-{
-  char result[SWIG_BUFFER_SIZE];
-  return SWIG_PackVoidPtr(result, v->ptr, v->desc, sizeof(result)) ?
-    PyString_FromString(result) : 0;
-}
+	SWIGRUNTIME PyObject *PySwigObject_repr(PySwigObject * v) {
+		char result[SWIG_BUFFER_SIZE];
+		return SWIG_PackVoidPtr(result, v->ptr, v->desc, sizeof(result)) ? PyString_FromFormat("<Swig Object at %s>", result) : 0;
+	}
 
-SWIGRUNTIME PyObject *
-PySwigObject_long(PySwigObject *v)
-{
-  return PyLong_FromVoidPtr(v->ptr);
-}
+	SWIGRUNTIME PyObject *PySwigObject_str(PySwigObject * v) {
+		char result[SWIG_BUFFER_SIZE];
+		return SWIG_PackVoidPtr(result, v->ptr, v->desc, sizeof(result)) ? PyString_FromString(result) : 0;
+	}
 
-SWIGRUNTIME PyObject *
-PySwigObject_format(const char* fmt, PySwigObject *v)
-{
-  PyObject *res = NULL;
-  PyObject *args = PyTuple_New(1);
-  if (args && (PyTuple_SetItem(args, 0, PySwigObject_long(v)) == 0)) {
-    PyObject *ofmt = PyString_FromString(fmt);
-    if (ofmt) {
-      res = PyString_Format(ofmt,args);
-      Py_DECREF(ofmt);
-    }
-    Py_DECREF(args);
-  }  
-  return res;
-}
+	SWIGRUNTIME PyObject *PySwigObject_long(PySwigObject * v) {
+		return PyLong_FromVoidPtr(v->ptr);
+	}
 
-SWIGRUNTIME PyObject *
-PySwigObject_oct(PySwigObject *v)
-{
-  return PySwigObject_format("%o",v);
-}
+	SWIGRUNTIME PyObject *PySwigObject_format(const char *fmt, PySwigObject * v) {
+		PyObject *res = NULL;
+		PyObject *args = PyTuple_New(1);
+		if (args && (PyTuple_SetItem(args, 0, PySwigObject_long(v)) == 0)) {
+			PyObject *ofmt = PyString_FromString(fmt);
+			if (ofmt) {
+				res = PyString_Format(ofmt, args);
+				Py_DECREF(ofmt);
+			}
+			Py_DECREF(args);
+		}
+		return res;
+	}
 
-SWIGRUNTIME PyObject *
-PySwigObject_hex(PySwigObject *v)
-{
-  return PySwigObject_format("%x",v);
-}
+	SWIGRUNTIME PyObject *PySwigObject_oct(PySwigObject * v) {
+		return PySwigObject_format("%o", v);
+	}
 
-SWIGRUNTIME int
-PySwigObject_compare(PySwigObject *v, PySwigObject *w)
-{
-  int c = strcmp(v->desc, w->desc);
-  if (c) {
-    return (c > 0) ? 1 : -1;
-  } else {
-    void *i = v->ptr;
-    void *j = w->ptr;
-    return (i < j) ? -1 : ((i > j) ? 1 : 0);
-  }
-}
+	SWIGRUNTIME PyObject *PySwigObject_hex(PySwigObject * v) {
+		return PySwigObject_format("%x", v);
+	}
 
-SWIGRUNTIME void
-PySwigObject_dealloc(PySwigObject *self)
-{
-  PyObject_Del(self);
-}
+	SWIGRUNTIME int
+	    PySwigObject_compare(PySwigObject * v, PySwigObject * w) {
+		int c = strcmp(v->desc, w->desc);
+		if (c) {
+			return (c > 0) ? 1 : -1;
+		} else {
+			void *i = v->ptr;
+			void *j = w->ptr;
+			return (i < j) ? -1 : ((i > j) ? 1 : 0);
+		}
+	}
 
-SWIGRUNTIME PyTypeObject*
-PySwigObject_type(void) {
-  static char pyswigobject_type__doc__[] = 
-    "Swig object carries a C/C++ instance pointer";
-  
-  static PyNumberMethods PySwigObject_as_number = {
-    (binaryfunc)0, /*nb_add*/
-    (binaryfunc)0, /*nb_subtract*/
-    (binaryfunc)0, /*nb_multiply*/
-    (binaryfunc)0, /*nb_divide*/
-    (binaryfunc)0, /*nb_remainder*/
-    (binaryfunc)0, /*nb_divmod*/
-    (ternaryfunc)0,/*nb_power*/
-    (unaryfunc)0,  /*nb_negative*/
-    (unaryfunc)0,  /*nb_positive*/
-    (unaryfunc)0,  /*nb_absolute*/
-    (inquiry)0,    /*nb_nonzero*/
-    0,		   /*nb_invert*/
-    0,		   /*nb_lshift*/
-    0,		   /*nb_rshift*/
-    0,		   /*nb_and*/
-    0,		   /*nb_xor*/
-    0,		   /*nb_or*/
-    (coercion)0,   /*nb_coerce*/
-    (unaryfunc)PySwigObject_long, /*nb_int*/
-    (unaryfunc)PySwigObject_long, /*nb_long*/
-    (unaryfunc)0,                 /*nb_float*/
-    (unaryfunc)PySwigObject_oct,  /*nb_oct*/
-    (unaryfunc)PySwigObject_hex,  /*nb_hex*/
+	SWIGRUNTIME void
+	     PySwigObject_dealloc(PySwigObject * self) {
+		PyObject_Del(self);
+	}
+
+	SWIGRUNTIME PyTypeObject *PySwigObject_type(void) {
+		static char pyswigobject_type__doc__[] = "Swig object carries a C/C++ instance pointer";
+
+		static PyNumberMethods PySwigObject_as_number = {
+			(binaryfunc) 0,		/*nb_add */
+			(binaryfunc) 0,		/*nb_subtract */
+			(binaryfunc) 0,		/*nb_multiply */
+			(binaryfunc) 0,		/*nb_divide */
+			(binaryfunc) 0,		/*nb_remainder */
+			(binaryfunc) 0,		/*nb_divmod */
+			(ternaryfunc) 0,	/*nb_power */
+			(unaryfunc) 0,		/*nb_negative */
+			(unaryfunc) 0,		/*nb_positive */
+			(unaryfunc) 0,		/*nb_absolute */
+			(inquiry) 0,		/*nb_nonzero */
+			0,					/*nb_invert */
+			0,					/*nb_lshift */
+			0,					/*nb_rshift */
+			0,					/*nb_and */
+			0,					/*nb_xor */
+			0,					/*nb_or */
+			(coercion) 0,		/*nb_coerce */
+			(unaryfunc) PySwigObject_long,	/*nb_int */
+			(unaryfunc) PySwigObject_long,	/*nb_long */
+			(unaryfunc) 0,		/*nb_float */
+			(unaryfunc) PySwigObject_oct,	/*nb_oct */
+			(unaryfunc) PySwigObject_hex,	/*nb_hex */
 #if PY_VERSION_HEX >= 0x02020000
-    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_true_divide */ 
+			0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0	/* nb_inplace_add -> nb_inplace_true_divide */
 #elif PY_VERSION_HEX >= 0x02000000
-    0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_or */
+			0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0	/* nb_inplace_add -> nb_inplace_or */
 #endif
-  };
+		};
 
-  static PyTypeObject pyswigobject_type
+		static PyTypeObject pyswigobject_type
 #if !defined(__cplusplus)
-  ;  
-  static int type_init = 0;
-  if (!type_init) {
-    PyTypeObject tmp
-#endif
-    = {
-    PyObject_HEAD_INIT(&PyType_Type)
-    0,					/*ob_size*/
-    (char *)"PySwigObject",		/*tp_name*/
-    sizeof(PySwigObject),		/*tp_basicsize*/
-    0,					/*tp_itemsize*/
-    /* methods */
-    (destructor)PySwigObject_dealloc,	/*tp_dealloc*/
-    (printfunc)PySwigObject_print,	/*tp_print*/
-    (getattrfunc)0,			/*tp_getattr*/
-    (setattrfunc)0,			/*tp_setattr*/
-    (cmpfunc)PySwigObject_compare,	/*tp_compare*/
-    (reprfunc)PySwigObject_repr,	/*tp_repr*/
-    &PySwigObject_as_number,	        /*tp_as_number*/
-    0,					/*tp_as_sequence*/
-    0,					/*tp_as_mapping*/
-    (hashfunc)0,			/*tp_hash*/
-    (ternaryfunc)0,			/*tp_call*/
-    (reprfunc)PySwigObject_str,		/*tp_str*/
-    /* Space for future expansion */
-    0,0,0,0,
-    pyswigobject_type__doc__, 	        /* Documentation string */
+		            ;
+		static int type_init = 0;
+		if (!type_init) {
+			PyTypeObject tmp
+#endif
+				= {
+				PyObject_HEAD_INIT(&PyType_Type)
+					0,			/*ob_size */
+				(char *) "PySwigObject",	/*tp_name */
+				sizeof(PySwigObject),	/*tp_basicsize */
+				0,				/*tp_itemsize */
+				/* methods */
+				(destructor) PySwigObject_dealloc,	/*tp_dealloc */
+				(printfunc) PySwigObject_print,	/*tp_print */
+				(getattrfunc) 0,	/*tp_getattr */
+				(setattrfunc) 0,	/*tp_setattr */
+				(cmpfunc) PySwigObject_compare,	/*tp_compare */
+				(reprfunc) PySwigObject_repr,	/*tp_repr */
+				&PySwigObject_as_number,	/*tp_as_number */
+				0,				/*tp_as_sequence */
+				0,				/*tp_as_mapping */
+				(hashfunc) 0,	/*tp_hash */
+				(ternaryfunc) 0,	/*tp_call */
+				(reprfunc) PySwigObject_str,	/*tp_str */
+				/* Space for future expansion */
+				0, 0, 0, 0,
+				pyswigobject_type__doc__,	/* Documentation string */
 #if PY_VERSION_HEX >= 0x02000000
-    0,                                  /* tp_traverse */
-    0,                                  /* tp_clear */
+				0,				/* tp_traverse */
+				0,				/* tp_clear */
 #endif
 #if PY_VERSION_HEX >= 0x02010000
-    0,                                  /* tp_richcompare */
-    0,                                  /* tp_weaklistoffset */
+				0,				/* tp_richcompare */
+				0,				/* tp_weaklistoffset */
 #endif
 #if PY_VERSION_HEX >= 0x02020000
-    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* tp_iter -> tp_weaklist */
+				0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,	/* tp_iter -> tp_weaklist */
 #endif
 #if PY_VERSION_HEX >= 0x02030000
-    0,                                  /* tp_del */
+				0,				/* tp_del */
 #endif
 #ifdef COUNT_ALLOCS
-    0,0,0,0                             /* tp_alloc -> tp_next */
+				0, 0, 0, 0		/* tp_alloc -> tp_next */
 #endif
-    };
+			};
 #if !defined(__cplusplus)
-    pyswigobject_type = tmp;
-    type_init = 1;
-  }
+			pyswigobject_type = tmp;
+			type_init = 1;
+		}
 #endif
-  return &pyswigobject_type;
-}
+		return &pyswigobject_type;
+	}
 
-SWIGRUNTIME PyObject *
-PySwigObject_FromVoidPtrAndDesc(void *ptr, const char *desc)
-{
-  PySwigObject *self = PyObject_NEW(PySwigObject, PySwigObject_type());
-  if (self) {
-    self->ptr = ptr;
-    self->desc = desc;
-  }
-  return (PyObject *)self;
-}
+	SWIGRUNTIME PyObject *PySwigObject_FromVoidPtrAndDesc(void *ptr, const char *desc) {
+		PySwigObject *self = PyObject_NEW(PySwigObject, PySwigObject_type());
+		if (self) {
+			self->ptr = ptr;
+			self->desc = desc;
+		}
+		return (PyObject *) self;
+	}
 
-SWIGRUNTIMEINLINE void *
-PySwigObject_AsVoidPtr(PyObject *self)
-{
-  return ((PySwigObject *)self)->ptr;
-}
+	SWIGRUNTIMEINLINE void *PySwigObject_AsVoidPtr(PyObject * self) {
+		return ((PySwigObject *) self)->ptr;
+	}
 
-SWIGRUNTIMEINLINE const char *
-PySwigObject_GetDesc(PyObject *self)
-{
-  return ((PySwigObject *)self)->desc;
-}
+	SWIGRUNTIMEINLINE const char *PySwigObject_GetDesc(PyObject * self) {
+		return ((PySwigObject *) self)->desc;
+	}
 
-SWIGRUNTIMEINLINE int
-PySwigObject_Check(PyObject *op) {
-  return ((op)->ob_type == PySwigObject_type()) 
-    || (strcmp((op)->ob_type->tp_name,"PySwigObject") == 0);
-}
+	SWIGRUNTIMEINLINE int
+	    PySwigObject_Check(PyObject * op) {
+		return ((op)->ob_type == PySwigObject_type())
+			|| (strcmp((op)->ob_type->tp_name, "PySwigObject") == 0);
+	}
 
 /* -----------------------------------------------------------------------------
  * Implements a simple Swig Packed type, and use it instead of string
  * ----------------------------------------------------------------------------- */
 
-typedef struct {
-  PyObject_HEAD
-  void *pack;
-  const char *desc;
-  size_t size;
-} PySwigPacked;
+	typedef struct {
+		PyObject_HEAD void *pack;
+		const char *desc;
+		size_t size;
+	} PySwigPacked;
+
+	SWIGRUNTIME int
+	    PySwigPacked_print(PySwigPacked * v, FILE * fp, int flags) {
+		char result[SWIG_BUFFER_SIZE];
+		flags = flags;
+		fputs("<Swig Packed ", fp);
+		if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))) {
+			fputs("at ", fp);
+			fputs(result, fp);
+		}
+		fputs(v->desc, fp);
+		fputs(">", fp);
+		return 0;
+	}
 
-SWIGRUNTIME int
-PySwigPacked_print(PySwigPacked *v, FILE *fp, int flags)
-{
-  char result[SWIG_BUFFER_SIZE];
-  flags = flags;
-  fputs("<Swig Packed ", fp); 
-  if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))) {
-    fputs("at ", fp); 
-    fputs(result, fp); 
-  }
-  fputs(v->desc,fp); 
-  fputs(">", fp);
-  return 0; 
-}
-  
-SWIGRUNTIME PyObject *
-PySwigPacked_repr(PySwigPacked *v)
-{
-  char result[SWIG_BUFFER_SIZE];
-  if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))) {
-    return PyString_FromFormat("<Swig Packed at %s%s>", result, v->desc);
-  } else {
-    return PyString_FromFormat("<Swig Packed %s>", v->desc);
-  }  
-}
+	SWIGRUNTIME PyObject *PySwigPacked_repr(PySwigPacked * v) {
+		char result[SWIG_BUFFER_SIZE];
+		if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))) {
+			return PyString_FromFormat("<Swig Packed at %s%s>", result, v->desc);
+		} else {
+			return PyString_FromFormat("<Swig Packed %s>", v->desc);
+		}
+	}
 
-SWIGRUNTIME PyObject *
-PySwigPacked_str(PySwigPacked *v)
-{
-  char result[SWIG_BUFFER_SIZE];
-  if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))){
-    return PyString_FromFormat("%s%s", result, v->desc);
-  } else {
-    return PyString_FromString(v->desc);
-  }  
-}
+	SWIGRUNTIME PyObject *PySwigPacked_str(PySwigPacked * v) {
+		char result[SWIG_BUFFER_SIZE];
+		if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))) {
+			return PyString_FromFormat("%s%s", result, v->desc);
+		} else {
+			return PyString_FromString(v->desc);
+		}
+	}
 
-SWIGRUNTIME int
-PySwigPacked_compare(PySwigPacked *v, PySwigPacked *w)
-{
-  int c = strcmp(v->desc, w->desc);
-  if (c) {
-    return (c > 0) ? 1 : -1;
-  } else {
-    size_t i = v->size;
-    size_t j = w->size;
-    int s = (i < j) ? -1 : ((i > j) ? 1 : 0);
-    return s ? s : strncmp((char *)v->pack, (char *)w->pack, 2*v->size);
-  }
-}
+	SWIGRUNTIME int
+	    PySwigPacked_compare(PySwigPacked * v, PySwigPacked * w) {
+		int c = strcmp(v->desc, w->desc);
+		if (c) {
+			return (c > 0) ? 1 : -1;
+		} else {
+			size_t i = v->size;
+			size_t j = w->size;
+			int s = (i < j) ? -1 : ((i > j) ? 1 : 0);
+			return s ? s : strncmp((char *) v->pack, (char *) w->pack, 2 * v->size);
+		}
+	}
 
-SWIGRUNTIME void
-PySwigPacked_dealloc(PySwigPacked *self)
-{
-  free(self->pack);
-  PyObject_Del(self);
-}
+	SWIGRUNTIME void
+	     PySwigPacked_dealloc(PySwigPacked * self) {
+		free(self->pack);
+		PyObject_Del(self);
+	}
 
-SWIGRUNTIME PyTypeObject*
-PySwigPacked_type(void) {
-  static char pyswigpacked_type__doc__[] = 
-    "Swig object carries a C/C++ instance pointer";
-  static PyTypeObject pyswigpacked_type
+	SWIGRUNTIME PyTypeObject *PySwigPacked_type(void) {
+		static char pyswigpacked_type__doc__[] = "Swig object carries a C/C++ instance pointer";
+		static PyTypeObject pyswigpacked_type
 #if !defined(__cplusplus)
-  ;
-  static int type_init = 0;  
-  if (!type_init) {
-    PyTypeObject tmp
-#endif
-    = {
-    PyObject_HEAD_INIT(&PyType_Type)
-    0,					/*ob_size*/
-    (char *)"PySwigPacked",		/*tp_name*/
-    sizeof(PySwigPacked),		/*tp_basicsize*/
-    0,					/*tp_itemsize*/
-    /* methods */
-    (destructor)PySwigPacked_dealloc,	/*tp_dealloc*/
-    (printfunc)PySwigPacked_print,	/*tp_print*/
-    (getattrfunc)0,			/*tp_getattr*/
-    (setattrfunc)0,			/*tp_setattr*/
-    (cmpfunc)PySwigPacked_compare,	/*tp_compare*/
-    (reprfunc)PySwigPacked_repr,	/*tp_repr*/
-    0,	                                /*tp_as_number*/
-    0,					/*tp_as_sequence*/
-    0,					/*tp_as_mapping*/
-    (hashfunc)0,			/*tp_hash*/
-    (ternaryfunc)0,			/*tp_call*/
-    (reprfunc)PySwigPacked_str,		/*tp_str*/
-    /* Space for future expansion */
-    0,0,0,0,
-    pyswigpacked_type__doc__, 	        /* Documentation string */
+		            ;
+		static int type_init = 0;
+		if (!type_init) {
+			PyTypeObject tmp
+#endif
+				= {
+				PyObject_HEAD_INIT(&PyType_Type)
+					0,			/*ob_size */
+				(char *) "PySwigPacked",	/*tp_name */
+				sizeof(PySwigPacked),	/*tp_basicsize */
+				0,				/*tp_itemsize */
+				/* methods */
+				(destructor) PySwigPacked_dealloc,	/*tp_dealloc */
+				(printfunc) PySwigPacked_print,	/*tp_print */
+				(getattrfunc) 0,	/*tp_getattr */
+				(setattrfunc) 0,	/*tp_setattr */
+				(cmpfunc) PySwigPacked_compare,	/*tp_compare */
+				(reprfunc) PySwigPacked_repr,	/*tp_repr */
+				0,				/*tp_as_number */
+				0,				/*tp_as_sequence */
+				0,				/*tp_as_mapping */
+				(hashfunc) 0,	/*tp_hash */
+				(ternaryfunc) 0,	/*tp_call */
+				(reprfunc) PySwigPacked_str,	/*tp_str */
+				/* Space for future expansion */
+				0, 0, 0, 0,
+				pyswigpacked_type__doc__,	/* Documentation string */
 #if PY_VERSION_HEX >= 0x02000000
-    0,                                  /* tp_traverse */
-    0,                                  /* tp_clear */
+				0,				/* tp_traverse */
+				0,				/* tp_clear */
 #endif
 #if PY_VERSION_HEX >= 0x02010000
-    0,                                  /* tp_richcompare */
-    0,                                  /* tp_weaklistoffset */
+				0,				/* tp_richcompare */
+				0,				/* tp_weaklistoffset */
 #endif
-#if PY_VERSION_HEX >= 0x02020000         
-    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* tp_iter -> tp_weaklist */
+#if PY_VERSION_HEX >= 0x02020000
+				0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,	/* tp_iter -> tp_weaklist */
 #endif
 #if PY_VERSION_HEX >= 0x02030000
-    0,                                  /* tp_del */
+				0,				/* tp_del */
 #endif
 #ifdef COUNT_ALLOCS
-    0,0,0,0                             /* tp_alloc -> tp_next */
+				0, 0, 0, 0		/* tp_alloc -> tp_next */
 #endif
-    };
+			};
 #if !defined(__cplusplus)
-    pyswigpacked_type = tmp;
-    type_init = 1;
-  }
+			pyswigpacked_type = tmp;
+			type_init = 1;
+		}
 #endif
-  return &pyswigpacked_type;
-}
+		return &pyswigpacked_type;
+	}
 
-SWIGRUNTIME PyObject *
-PySwigPacked_FromDataAndDesc(void *ptr, size_t size, const char *desc)
-{
-  PySwigPacked *self = PyObject_NEW(PySwigPacked, PySwigPacked_type());
-  if (self == NULL) {
-    return NULL;
-  } else {
-    void *pack = malloc(size);
-    if (pack) {
-      memcpy(pack, ptr, size);
-      self->pack = pack;
-      self->desc = desc;
-      self->size = size;
-      return (PyObject *) self;
-    }
-    return NULL;
-  }
-}
+	SWIGRUNTIME PyObject *PySwigPacked_FromDataAndDesc(void *ptr, size_t size, const char *desc) {
+		PySwigPacked *self = PyObject_NEW(PySwigPacked, PySwigPacked_type());
+		if (self == NULL) {
+			return NULL;
+		} else {
+			void *pack = malloc(size);
+			if (pack) {
+				memcpy(pack, ptr, size);
+				self->pack = pack;
+				self->desc = desc;
+				self->size = size;
+				return (PyObject *) self;
+			}
+			return NULL;
+		}
+	}
 
-SWIGRUNTIMEINLINE const char *
-PySwigPacked_UnpackData(PyObject *obj, void *ptr, size_t size)
-{
-  PySwigPacked *self = (PySwigPacked *)obj;
-  if (self->size != size) return 0;
-  memcpy(ptr, self->pack, size);
-  return self->desc;
-}
+	SWIGRUNTIMEINLINE const char *PySwigPacked_UnpackData(PyObject * obj, void *ptr, size_t size) {
+		PySwigPacked *self = (PySwigPacked *) obj;
+		if (self->size != size)
+			return 0;
+		memcpy(ptr, self->pack, size);
+		return self->desc;
+	}
 
-SWIGRUNTIMEINLINE const char *
-PySwigPacked_GetDesc(PyObject *self)
-{
-  return ((PySwigPacked *)self)->desc;
-}
+	SWIGRUNTIMEINLINE const char *PySwigPacked_GetDesc(PyObject * self) {
+		return ((PySwigPacked *) self)->desc;
+	}
 
-SWIGRUNTIMEINLINE int
-PySwigPacked_Check(PyObject *op) {
-  return ((op)->ob_type == PySwigPacked_type()) 
-    || (strcmp((op)->ob_type->tp_name,"PySwigPacked") == 0);
-}
+	SWIGRUNTIMEINLINE int
+	    PySwigPacked_Check(PyObject * op) {
+		return ((op)->ob_type == PySwigPacked_type())
+			|| (strcmp((op)->ob_type->tp_name, "PySwigPacked") == 0);
+	}
 
 #else
 /* -----------------------------------------------------------------------------
  * Use the old Python PyCObject instead of PySwigObject
  * ----------------------------------------------------------------------------- */
-
 #define PySwigObject_GetDesc(obj)	           PyCObject_GetDesc(obj)
 #define PySwigObject_Check(obj)	           PyCObject_Check(obj)
 #define PySwigObject_AsVoidPtr(obj)	   PyCObject_AsVoidPtr(obj)
 #define PySwigObject_FromVoidPtrAndDesc(p, d)  PyCObject_FromVoidPtrAndDesc(p, d, NULL)
-
 #endif
-
 #endif
-
 /* -----------------------------------------------------------------------------
  * errors manipulation
- * ----------------------------------------------------------------------------- */
-
-SWIGRUNTIME void
-SWIG_Python_TypeError(const char *type, PyObject *obj)
-{
-  if (type) {
+ * ----------------------------------------------------------------------------- */ SWIGRUNTIME void
+	     SWIG_Python_TypeError(const char *type, PyObject * obj) {
+		if (type) {
 #if defined(SWIG_COBJECT_TYPES)
-    if (obj && PySwigObject_Check(obj)) {
-      const char *otype = (const char *) PySwigObject_GetDesc(obj);
-      if (otype) {
-	PyErr_Format(PyExc_TypeError, "a '%s' is expected, 'PySwigObject(%s)' is received",
-		     type, otype);
-	return;
-      }
-    } else 
-#endif      
-    {
-      const char *otype = (obj ? obj->ob_type->tp_name : 0); 
-      if (otype) {
-	PyObject *str = PyObject_Str(obj);
-	const char *cstr = str ? PyString_AsString(str) : 0;
-	if (cstr) {
-	  PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s(%s)' is received",
-		       type, otype, cstr);
-	} else {
-	  PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s' is received",
-		       type, otype);
+			if (obj && PySwigObject_Check(obj)) {
+				const char *otype = (const char *) PySwigObject_GetDesc(obj);
+				if (otype) {
+					PyErr_Format(PyExc_TypeError, "a '%s' is expected, 'PySwigObject(%s)' is received", type, otype);
+					return;
+				}
+			} else
+#endif
+			{
+				const char *otype = (obj ? obj->ob_type->tp_name : 0);
+				if (otype) {
+					PyObject *str = PyObject_Str(obj);
+					const char *cstr = str ? PyString_AsString(str) : 0;
+					if (cstr) {
+						PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s(%s)' is received", type, otype, cstr);
+					} else {
+						PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s' is received", type, otype);
+					}
+					Py_XDECREF(str);
+					return;
+				}
+			}
+			PyErr_Format(PyExc_TypeError, "a '%s' is expected", type);
+		} else {
+			PyErr_Format(PyExc_TypeError, "unexpected type is received");
+		}
 	}
-	Py_XDECREF(str);
-	return;
-      }
-    }   
-    PyErr_Format(PyExc_TypeError, "a '%s' is expected", type);
-  } else {
-    PyErr_Format(PyExc_TypeError, "unexpected type is received");
-  }
-}
 
-SWIGRUNTIMEINLINE void
-SWIG_Python_NullRef(const char *type)
-{
-  if (type) {
-    PyErr_Format(PyExc_TypeError, "null reference of type '%s' was received",type);
-  } else {
-    PyErr_Format(PyExc_TypeError, "null reference was received");
-  }
-}
+	SWIGRUNTIMEINLINE void
+	     SWIG_Python_NullRef(const char *type) {
+		if (type) {
+			PyErr_Format(PyExc_TypeError, "null reference of type '%s' was received", type);
+		} else {
+			PyErr_Format(PyExc_TypeError, "null reference was received");
+		}
+	}
 
-SWIGRUNTIME int
-SWIG_Python_AddErrMesg(const char* mesg, int infront)
-{
-  if (PyErr_Occurred()) {
-    PyObject *type = 0;
-    PyObject *value = 0;
-    PyObject *traceback = 0;
-    PyErr_Fetch(&type, &value, &traceback);
-    if (value) {
-      PyObject *old_str = PyObject_Str(value);
-      Py_XINCREF(type);
-      PyErr_Clear();
-      if (infront) {
-	PyErr_Format(type, "%s %s", mesg, PyString_AsString(old_str));
-      } else {
-	PyErr_Format(type, "%s %s", PyString_AsString(old_str), mesg);
-      }
-      Py_DECREF(old_str);
-    }
-    return 1;
-  } else {
-    return 0;
-  }
-}
+	SWIGRUNTIME int
+	    SWIG_Python_AddErrMesg(const char *mesg, int infront) {
+		if (PyErr_Occurred()) {
+			PyObject *type = 0;
+			PyObject *value = 0;
+			PyObject *traceback = 0;
+			PyErr_Fetch(&type, &value, &traceback);
+			if (value) {
+				PyObject *old_str = PyObject_Str(value);
+				Py_XINCREF(type);
+				PyErr_Clear();
+				if (infront) {
+					PyErr_Format(type, "%s %s", mesg, PyString_AsString(old_str));
+				} else {
+					PyErr_Format(type, "%s %s", PyString_AsString(old_str), mesg);
+				}
+				Py_DECREF(old_str);
+			}
+			return 1;
+		} else {
+			return 0;
+		}
+	}
 
-SWIGRUNTIME int
-SWIG_Python_ArgFail(int argnum)
-{
-  if (PyErr_Occurred()) {
-    /* add information about failing argument */
-    char mesg[256];
-    PyOS_snprintf(mesg, sizeof(mesg), "argument number %d:", argnum);
-    return SWIG_Python_AddErrMesg(mesg, 1);
-  } else {
-    return 0;
-  }
-}
+	SWIGRUNTIME int
+	    SWIG_Python_ArgFail(int argnum) {
+		if (PyErr_Occurred()) {
+			/* add information about failing argument */
+			char mesg[256];
+			PyOS_snprintf(mesg, sizeof(mesg), "argument number %d:", argnum);
+			return SWIG_Python_AddErrMesg(mesg, 1);
+		} else {
+			return 0;
+		}
+	}
 
 
 /* -----------------------------------------------------------------------------
@@ -1140,272 +1062,274 @@
  * ----------------------------------------------------------------------------- */
 
 /* Convert a pointer value */
-SWIGRUNTIME int
-SWIG_Python_ConvertPtr(PyObject *obj, void **ptr, swig_type_info *ty, int flags) {
-  swig_cast_info *tc;
-  const char *c = 0;
-  static PyObject *SWIG_this = 0;
-  int    newref = 0;
-  PyObject  *pyobj = 0;
-  void *vptr;
-  
-  if (!obj) return 0;
-  if (obj == Py_None) {
-    *ptr = 0;
-    return 0;
-  }
-
+	SWIGRUNTIME int
+	    SWIG_Python_ConvertPtr(PyObject * obj, void **ptr, swig_type_info * ty, int flags) {
+		swig_cast_info *tc;
+		const char *c = 0;
+		static PyObject *SWIG_this = 0;
+		int newref = 0;
+		PyObject *pyobj = 0;
+		void *vptr;
+
+		if (!obj)
+			return 0;
+		if (obj == Py_None) {
+			*ptr = 0;
+			return 0;
+		}
 #ifdef SWIG_COBJECT_TYPES
-  if (!(PySwigObject_Check(obj))) {
-    if (!SWIG_this)
-      SWIG_this = PyString_FromString("this");
-    pyobj = obj;
-    obj = PyObject_GetAttr(obj,SWIG_this);
-    newref = 1;
-    if (!obj) goto type_error;
-    if (!PySwigObject_Check(obj)) {
-      Py_DECREF(obj);
-      goto type_error;
-    }
-  }  
-  vptr = PySwigObject_AsVoidPtr(obj);
-  c = (const char *) PySwigObject_GetDesc(obj);
-  if (newref) { Py_DECREF(obj); }
-  goto type_check;
+		if (!(PySwigObject_Check(obj))) {
+			if (!SWIG_this)
+				SWIG_this = PyString_FromString("this");
+			pyobj = obj;
+			obj = PyObject_GetAttr(obj, SWIG_this);
+			newref = 1;
+			if (!obj)
+				goto type_error;
+			if (!PySwigObject_Check(obj)) {
+				Py_DECREF(obj);
+				goto type_error;
+			}
+		}
+		vptr = PySwigObject_AsVoidPtr(obj);
+		c = (const char *) PySwigObject_GetDesc(obj);
+		if (newref) {
+			Py_DECREF(obj);
+		}
+		goto type_check;
 #else
-  if (!(PyString_Check(obj))) {
-    if (!SWIG_this)
-      SWIG_this = PyString_FromString("this");
-    pyobj = obj;
-    obj = PyObject_GetAttr(obj,SWIG_this);
-    newref = 1;
-    if (!obj) goto type_error;
-    if (!PyString_Check(obj)) {
-      Py_DECREF(obj);
-      goto type_error;
-    }
-  } 
-  c = PyString_AsString(obj);
-  /* Pointer values must start with leading underscore */
-  c = SWIG_UnpackVoidPtr(c, &vptr, ty->name);
-  if (newref) { Py_DECREF(obj); }
-  if (!c) goto type_error;
-#endif
-
-type_check:
-  if (ty) {
-    tc = SWIG_TypeCheck(c,ty);
-    if (!tc) goto type_error;
-    *ptr = SWIG_TypeCast(tc,vptr);
-  } else {
-    *ptr = vptr;
-  }
-  if ((pyobj) && (flags & SWIG_POINTER_DISOWN)) {
-    PyObject_SetAttrString(pyobj,(char*)"thisown",Py_False);
-  }
-  return 0;
-
-type_error:
-  PyErr_Clear();
-  if (pyobj && !obj) {    
-    obj = pyobj;
-    if (PyCFunction_Check(obj)) {
-      /* here we get the method pointer for callbacks */
-      char *doc = (((PyCFunctionObject *)obj) -> m_ml -> ml_doc);
-      c = doc ? strstr(doc, "swig_ptr: ") : 0;
-      if (c) {
-	c = ty ? SWIG_UnpackVoidPtr(c + 10, &vptr, ty->name) : 0;
-	if (!c) goto type_error;
-	goto type_check;
-      }
-    }
-  }
-  if (flags & SWIG_POINTER_EXCEPTION) {
-    if (ty) {
-      SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj);
-    } else {
-      SWIG_Python_TypeError("C/C++ pointer", obj);
-    }
-  }
-  return -1;
-}
+		if (!(PyString_Check(obj))) {
+			if (!SWIG_this)
+				SWIG_this = PyString_FromString("this");
+			pyobj = obj;
+			obj = PyObject_GetAttr(obj, SWIG_this);
+			newref = 1;
+			if (!obj)
+				goto type_error;
+			if (!PyString_Check(obj)) {
+				Py_DECREF(obj);
+				goto type_error;
+			}
+		}
+		c = PyString_AsString(obj);
+		/* Pointer values must start with leading underscore */
+		c = SWIG_UnpackVoidPtr(c, &vptr, ty->name);
+		if (newref) {
+			Py_DECREF(obj);
+		}
+		if (!c)
+			goto type_error;
+#endif
+
+	  type_check:
+		if (ty) {
+			tc = SWIG_TypeCheck(c, ty);
+			if (!tc)
+				goto type_error;
+			*ptr = SWIG_TypeCast(tc, vptr);
+		} else {
+			*ptr = vptr;
+		}
+		if ((pyobj) && (flags & SWIG_POINTER_DISOWN)) {
+			PyObject_SetAttrString(pyobj, (char *) "thisown", Py_False);
+		}
+		return 0;
+
+	  type_error:
+		PyErr_Clear();
+		if (pyobj && !obj) {
+			obj = pyobj;
+			if (PyCFunction_Check(obj)) {
+				/* here we get the method pointer for callbacks */
+				char *doc = (((PyCFunctionObject *) obj)->m_ml->ml_doc);
+				c = doc ? strstr(doc, "swig_ptr: ") : 0;
+				if (c) {
+					c = ty ? SWIG_UnpackVoidPtr(c + 10, &vptr, ty->name) : 0;
+					if (!c)
+						goto type_error;
+					goto type_check;
+				}
+			}
+		}
+		if (flags & SWIG_POINTER_EXCEPTION) {
+			if (ty) {
+				SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj);
+			} else {
+				SWIG_Python_TypeError("C/C++ pointer", obj);
+			}
+		}
+		return -1;
+	}
 
 /* Convert a pointer value, signal an exception on a type mismatch */
-SWIGRUNTIME void *
-SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int argnum, int flags) {
-  void *result;
-  if (SWIG_Python_ConvertPtr(obj, &result, ty, flags) == -1) {
-    PyErr_Clear();
-    if (flags & SWIG_POINTER_EXCEPTION) {
-      SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj);
-      SWIG_Python_ArgFail(argnum);
-    }
-  }
-  return result;
-}
+	SWIGRUNTIME void *SWIG_Python_MustGetPtr(PyObject * obj, swig_type_info * ty, int argnum, int flags) {
+		void *result;
+		if (SWIG_Python_ConvertPtr(obj, &result, ty, flags) == -1) {
+			PyErr_Clear();
+			if (flags & SWIG_POINTER_EXCEPTION) {
+				SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj);
+				SWIG_Python_ArgFail(argnum);
+			}
+		}
+		return result;
+	}
 
 /* Convert a packed value value */
-SWIGRUNTIME int
-SWIG_Python_ConvertPacked(PyObject *obj, void *ptr, size_t sz, swig_type_info *ty, int flags) {
-  swig_cast_info *tc;
-  const char *c = 0;
+	SWIGRUNTIME int
+	    SWIG_Python_ConvertPacked(PyObject * obj, void *ptr, size_t sz, swig_type_info * ty, int flags) {
+		swig_cast_info *tc;
+		const char *c = 0;
 
 #if defined(SWIG_COBJECT_TYPES) && !defined(SWIG_COBJECT_PYTHON)
-  c = PySwigPacked_UnpackData(obj, ptr, sz);
+		c = PySwigPacked_UnpackData(obj, ptr, sz);
 #else
-  if ((!obj) || (!PyString_Check(obj))) goto type_error;
-  c = PyString_AsString(obj);
-  /* Pointer values must start with leading underscore */
-  c = SWIG_UnpackDataName(c, ptr, sz, ty->name);
-#endif
-  if (!c) goto type_error;
-  if (ty) {
-    tc = SWIG_TypeCheck(c,ty);
-    if (!tc) goto type_error;
-  }
-  return 0;
-
-type_error:
-  PyErr_Clear();
-  if (flags & SWIG_POINTER_EXCEPTION) {
-    if (ty) {
-      SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj);
-    } else {
-      SWIG_Python_TypeError("C/C++ packed data", obj);
-    }
-  }
-  return -1;
-}  
+		if ((!obj) || (!PyString_Check(obj)))
+			goto type_error;
+		c = PyString_AsString(obj);
+		/* Pointer values must start with leading underscore */
+		c = SWIG_UnpackDataName(c, ptr, sz, ty->name);
+#endif
+		if (!c)
+			goto type_error;
+		if (ty) {
+			tc = SWIG_TypeCheck(c, ty);
+			if (!tc)
+				goto type_error;
+		}
+		return 0;
+
+	  type_error:
+		PyErr_Clear();
+		if (flags & SWIG_POINTER_EXCEPTION) {
+			if (ty) {
+				SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj);
+			} else {
+				SWIG_Python_TypeError("C/C++ packed data", obj);
+			}
+		}
+		return -1;
+	}
 
 /* Create a new array object */
-SWIGRUNTIME PyObject *
-SWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int own) {
-  PyObject *robj = 0;
-  if (!type) {
-    if (!PyErr_Occurred()) {
-      PyErr_Format(PyExc_TypeError, "Swig: null type passed to NewPointerObj");
-    }
-    return robj;
-  }
-  if (!ptr) {
-    Py_INCREF(Py_None);
-    return Py_None;
-  }
+	SWIGRUNTIME PyObject *SWIG_Python_NewPointerObj(void *ptr, swig_type_info * type, int own) {
+		PyObject *robj = 0;
+		if (!type) {
+			if (!PyErr_Occurred()) {
+				PyErr_Format(PyExc_TypeError, "Swig: null type passed to NewPointerObj");
+			}
+			return robj;
+		}
+		if (!ptr) {
+			Py_INCREF(Py_None);
+			return Py_None;
+		}
 #ifdef SWIG_COBJECT_TYPES
-  robj = PySwigObject_FromVoidPtrAndDesc((void *) ptr, (char *)type->name);
+		robj = PySwigObject_FromVoidPtrAndDesc((void *) ptr, (char *) type->name);
 #else
-  {
-    char result[SWIG_BUFFER_SIZE];
-    robj = SWIG_PackVoidPtr(result, ptr, type->name, sizeof(result)) ?
-      PyString_FromString(result) : 0;
-  }
-#endif
-  if (!robj || (robj == Py_None)) return robj;
-  if (type->clientdata) {
-    PyObject *inst;
-    PyObject *args = Py_BuildValue((char*)"(O)", robj);
-    Py_DECREF(robj);
-    inst = PyObject_CallObject((PyObject *) type->clientdata, args);
-    Py_DECREF(args);
-    if (inst) {
-      if (own) {
-        PyObject_SetAttrString(inst,(char*)"thisown",Py_True);
-      }
-      robj = inst;
-    }
-  }
-  return robj;
-}
+		{
+			char result[SWIG_BUFFER_SIZE];
+			robj = SWIG_PackVoidPtr(result, ptr, type->name, sizeof(result)) ? PyString_FromString(result) : 0;
+		}
+#endif
+		if (!robj || (robj == Py_None))
+			return robj;
+		if (type->clientdata) {
+			PyObject *inst;
+			PyObject *args = Py_BuildValue((char *) "(O)", robj);
+			Py_DECREF(robj);
+			inst = PyObject_CallObject((PyObject *) type->clientdata, args);
+			Py_DECREF(args);
+			if (inst) {
+				if (own) {
+					PyObject_SetAttrString(inst, (char *) "thisown", Py_True);
+				}
+				robj = inst;
+			}
+		}
+		return robj;
+	}
 
-SWIGRUNTIME PyObject *
-SWIG_Python_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) {
-  PyObject *robj = 0;
-  if (!ptr) {
-    Py_INCREF(Py_None);
-    return Py_None;
-  }
+	SWIGRUNTIME PyObject *SWIG_Python_NewPackedObj(void *ptr, size_t sz, swig_type_info * type) {
+		PyObject *robj = 0;
+		if (!ptr) {
+			Py_INCREF(Py_None);
+			return Py_None;
+		}
 #if defined(SWIG_COBJECT_TYPES) && !defined(SWIG_COBJECT_PYTHON)
-  robj = PySwigPacked_FromDataAndDesc((void *) ptr, sz, (char *)type->name);
+		robj = PySwigPacked_FromDataAndDesc((void *) ptr, sz, (char *) type->name);
 #else
-  {
-    char result[SWIG_BUFFER_SIZE];
-    robj = SWIG_PackDataName(result, ptr, sz, type->name, sizeof(result)) ?
-      PyString_FromString(result) : 0;
-  }
+		{
+			char result[SWIG_BUFFER_SIZE];
+			robj = SWIG_PackDataName(result, ptr, sz, type->name, sizeof(result)) ? PyString_FromString(result) : 0;
+		}
 #endif
-  return robj;
-}
+		return robj;
+	}
 
 /* -----------------------------------------------------------------------------*
  *  Get type list 
  * -----------------------------------------------------------------------------*/
 
 #ifdef SWIG_LINK_RUNTIME
-void *SWIG_ReturnGlobalTypeList(void *);
+	void *SWIG_ReturnGlobalTypeList(void *);
 #endif
 
-SWIGRUNTIME swig_module_info *
-SWIG_Python_GetModule(void) {
-  static void *type_pointer = (void *)0;
-  /* first check if module already created */
-  if (!type_pointer) {
+	SWIGRUNTIME swig_module_info *SWIG_Python_GetModule(void) {
+		static void *type_pointer = (void *) 0;
+		/* first check if module already created */
+		if (!type_pointer) {
 #ifdef SWIG_LINK_RUNTIME
-    type_pointer = SWIG_ReturnGlobalTypeList((void *)0);
+			type_pointer = SWIG_ReturnGlobalTypeList((void *) 0);
 #else
-    type_pointer = PyCObject_Import((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION,
-				    (char*)"type_pointer" SWIG_TYPE_TABLE_NAME);
-    if (PyErr_Occurred()) {
-      PyErr_Clear();
-      type_pointer = (void *)0;
-    }
+			type_pointer = PyCObject_Import((char *) "swig_runtime_data" SWIG_RUNTIME_VERSION, (char *) "type_pointer" SWIG_TYPE_TABLE_NAME);
+			if (PyErr_Occurred()) {
+				PyErr_Clear();
+				type_pointer = (void *) 0;
+			}
 #endif
-  }
-  return (swig_module_info *) type_pointer;
-}
+		}
+		return (swig_module_info *) type_pointer;
+	}
 
 #if PY_MAJOR_VERSION < 2
 /* PyModule_AddObject function was introduced in Python 2.0.  The following function
 is copied out of Python/modsupport.c in python version 2.3.4 */
-SWIGINTERN int
-PyModule_AddObject(PyObject *m, char *name, PyObject *o)
-{
-  PyObject *dict;
-  if (!PyModule_Check(m)) {
-    PyErr_SetString(PyExc_TypeError,
-		    "PyModule_AddObject() needs module as first arg");
-    return -1;
-  }
-  if (!o) {
-    PyErr_SetString(PyExc_TypeError,
-		    "PyModule_AddObject() needs non-NULL value");
-    return -1;
-  }
-  
-  dict = PyModule_GetDict(m);
-  if (dict == NULL) {
-    /* Internal error -- modules must have a dict! */
-    PyErr_Format(PyExc_SystemError, "module '%s' has no __dict__",
-		 PyModule_GetName(m));
-    return -1;
-  }
-  if (PyDict_SetItemString(dict, name, o))
-    return -1;
-  Py_DECREF(o);
-  return 0;
-}
+	SWIGINTERN int
+	    PyModule_AddObject(PyObject * m, char *name, PyObject * o) {
+		PyObject *dict;
+		if (!PyModule_Check(m)) {
+			PyErr_SetString(PyExc_TypeError, "PyModule_AddObject() needs module as first arg");
+			return -1;
+		}
+		if (!o) {
+			PyErr_SetString(PyExc_TypeError, "PyModule_AddObject() needs non-NULL value");
+			return -1;
+		}
+
+		dict = PyModule_GetDict(m);
+		if (dict == NULL) {
+			/* Internal error -- modules must have a dict! */
+			PyErr_Format(PyExc_SystemError, "module '%s' has no __dict__", PyModule_GetName(m));
+			return -1;
+		}
+		if (PyDict_SetItemString(dict, name, o))
+			return -1;
+		Py_DECREF(o);
+		return 0;
+	}
 #endif
 
-SWIGRUNTIME void
-SWIG_Python_SetModule(swig_module_info *swig_module) {
-  static PyMethodDef swig_empty_runtime_method_table[] = { {NULL, NULL, 0, NULL} };/* Sentinel */
-
-  PyObject *module = Py_InitModule((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION,
-				   swig_empty_runtime_method_table);
-  PyObject *pointer = PyCObject_FromVoidPtr((void *) swig_module, NULL);
-  if (pointer && module) {
-    PyModule_AddObject(module, (char*)"type_pointer" SWIG_TYPE_TABLE_NAME, pointer);
-  }
-}
+	SWIGRUNTIME void
+	     SWIG_Python_SetModule(swig_module_info * swig_module) {
+		static PyMethodDef swig_empty_runtime_method_table[] = { {NULL, NULL, 0, NULL} };	/* Sentinel */
+
+		PyObject *module = Py_InitModule((char *) "swig_runtime_data" SWIG_RUNTIME_VERSION,
+										 swig_empty_runtime_method_table);
+		PyObject *pointer = PyCObject_FromVoidPtr((void *) swig_module, NULL);
+		if (pointer && module) {
+			PyModule_AddObject(module, (char *) "type_pointer" SWIG_TYPE_TABLE_NAME, pointer);
+		}
+	}
 
 #ifdef __cplusplus
 }
@@ -1424,7 +1348,8 @@
 #define SWIGTYPE_ptrdiff_t swig_types[7]
 #define SWIGTYPE_size_t swig_types[8]
 static swig_type_info *swig_types[10];
-static swig_module_info swig_module = {swig_types, 9, 0, 0, 0, 0};
+static swig_module_info swig_module = { swig_types, 9, 0, 0, 0, 0 };
+
 #define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name)
 #define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name)
 
@@ -1439,50 +1364,51 @@
 #define SWIG_name    "_freeswitch"
 
 /* returns SWIG_OLDOBJ if the input is a raw char*, SWIG_PYSTR if is a PyString */
-SWIGINTERN int
-SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize)
+SWIGINTERN int SWIG_AsCharPtrAndSize(PyObject * obj, char **cptr, size_t *psize)
 {
-  static swig_type_info* pchar_info = 0;
-  char* vptr = 0;
-  if (!pchar_info) pchar_info = SWIG_TypeQuery("char *");
-  if (SWIG_ConvertPtr(obj, (void**)&vptr, pchar_info, 0) != -1) {
-    if (cptr) *cptr = vptr;
-    if (psize) *psize = vptr ? (strlen(vptr) + 1) : 0;
-    return SWIG_OLDOBJ;
-  } else {
-    PyErr_Clear();
-    if (PyString_Check(obj)) {
-      if (cptr) {
-	*cptr = PyString_AS_STRING(obj);
-	if (psize) {
-	  *psize = PyString_GET_SIZE(obj) + 1;
-	}
-      }
-      return SWIG_PYSTR;
-    }
-  }
-  if (cptr) {
-    SWIG_type_error("char *", obj);
-  }
-  return 0;
+	static swig_type_info *pchar_info = 0;
+	char *vptr = 0;
+	if (!pchar_info)
+		pchar_info = SWIG_TypeQuery("char *");
+	if (SWIG_ConvertPtr(obj, (void **) &vptr, pchar_info, 0) != -1) {
+		if (cptr)
+			*cptr = vptr;
+		if (psize)
+			*psize = vptr ? (strlen(vptr) + 1) : 0;
+		return SWIG_OLDOBJ;
+	} else {
+		PyErr_Clear();
+		if (PyString_Check(obj)) {
+			if (cptr) {
+				*cptr = PyString_AS_STRING(obj);
+				if (psize) {
+					*psize = PyString_GET_SIZE(obj) + 1;
+				}
+			}
+			return SWIG_PYSTR;
+		}
+	}
+	if (cptr) {
+		SWIG_type_error("char *", obj);
+	}
+	return 0;
 }
 
 
-SWIGINTERNINLINE int
-SWIG_AsCharPtr(PyObject *obj, char **val)
+SWIGINTERNINLINE int SWIG_AsCharPtr(PyObject * obj, char **val)
 {
-  if (SWIG_AsCharPtrAndSize(obj, val, (size_t*)(0))) {
-    return 1;
-  }
-  if (val) {
-    PyErr_Clear();
-    SWIG_type_error("char *", obj);
-  }
-  return 0;
+	if (SWIG_AsCharPtrAndSize(obj, val, (size_t *) (0))) {
+		return 1;
+	}
+	if (val) {
+		PyErr_Clear();
+		SWIG_type_error("char *", obj);
+	}
+	return 0;
 }
 
 
-  /*@/usr/share/swig1.3/python/pymacros.swg,72,SWIG_define@*/
+  /*@/usr/share/swig1.3/python/pymacros.swg,72,SWIG_define@ */
 #define SWIG_From_int PyInt_FromLong
 /*@@*/
 
@@ -1490,117 +1416,109 @@
 #include <limits.h>
 
 
-SWIGINTERNINLINE int
-  SWIG_CheckUnsignedLongInRange(unsigned long value,
-				unsigned long max_value,
-				const char *errmsg) 
+SWIGINTERNINLINE int SWIG_CheckUnsignedLongInRange(unsigned long value, unsigned long max_value, const char *errmsg)
 {
-  if (value > max_value) {
-    if (errmsg) {
-      PyErr_Format(PyExc_OverflowError,
-		   "value %lu is greater than '%s' minimum %lu",
-		   value, errmsg, max_value);
-    }
-    return 0;
-  }
-  return 1;
- }
+	if (value > max_value) {
+		if (errmsg) {
+			PyErr_Format(PyExc_OverflowError, "value %lu is greater than '%s' minimum %lu", value, errmsg, max_value);
+		}
+		return 0;
+	}
+	return 1;
+}
 
 
-SWIGINTERN int
-  SWIG_AsVal_unsigned_SS_long(PyObject *obj, unsigned long *val) 
+SWIGINTERN int SWIG_AsVal_unsigned_SS_long(PyObject * obj, unsigned long *val)
 {
-  if (PyLong_Check(obj)) {
-    unsigned long v = PyLong_AsUnsignedLong(obj);
-    if (!PyErr_Occurred()) {
-      if (val) *val = v;
-      return 1;
-    } else {
-      if (!val) PyErr_Clear();
-      return 0;
-    }
-  } 
-  if (PyInt_Check(obj)) {
-    long v = PyInt_AsLong(obj);
-    if (v >= 0) {
-      if (val) *val = v;
-      return 1;
-    }   
-  }
-  if (val) {
-    SWIG_type_error("unsigned long", obj);
-  }
-  return 0;
+	if (PyLong_Check(obj)) {
+		unsigned long v = PyLong_AsUnsignedLong(obj);
+		if (!PyErr_Occurred()) {
+			if (val)
+				*val = v;
+			return 1;
+		} else {
+			if (!val)
+				PyErr_Clear();
+			return 0;
+		}
+	}
+	if (PyInt_Check(obj)) {
+		long v = PyInt_AsLong(obj);
+		if (v >= 0) {
+			if (val)
+				*val = v;
+			return 1;
+		}
+	}
+	if (val) {
+		SWIG_type_error("unsigned long", obj);
+	}
+	return 0;
 }
 
 
 #if UINT_MAX != ULONG_MAX
-SWIGINTERN int
-  SWIG_AsVal_unsigned_SS_int(PyObject *obj, unsigned int *val)
-{ 
-  const char* errmsg = val ? "unsigned int" : (char*)0;
-  unsigned long v;
-  if (SWIG_AsVal_unsigned_SS_long(obj, &v)) {
-    if (SWIG_CheckUnsignedLongInRange(v, INT_MAX, errmsg)) {
-      if (val) *val = (unsigned int)(v);
-      return 1;
-    }
-  } else {
-    PyErr_Clear();
-  }
-  if (val) {
-    SWIG_type_error(errmsg, obj);
-  }
-  return 0;    
+SWIGINTERN int SWIG_AsVal_unsigned_SS_int(PyObject * obj, unsigned int *val)
+{
+	const char *errmsg = val ? "unsigned int" : (char *) 0;
+	unsigned long v;
+	if (SWIG_AsVal_unsigned_SS_long(obj, &v)) {
+		if (SWIG_CheckUnsignedLongInRange(v, INT_MAX, errmsg)) {
+			if (val)
+				*val = (unsigned int) (v);
+			return 1;
+		}
+	} else {
+		PyErr_Clear();
+	}
+	if (val) {
+		SWIG_type_error(errmsg, obj);
+	}
+	return 0;
 }
 #else
-SWIGINTERNINLINE unsigned int
-  SWIG_AsVal_unsigned_SS_int(PyObject *obj, unsigned int *val)
+SWIGINTERNINLINE unsigned int SWIG_AsVal_unsigned_SS_int(PyObject * obj, unsigned int *val)
 {
-  return SWIG_AsVal_unsigned_SS_long(obj,(unsigned long *)val);
+	return SWIG_AsVal_unsigned_SS_long(obj, (unsigned long *) val);
 }
 #endif
 
 
-SWIGINTERNINLINE unsigned int
-SWIG_As_unsigned_SS_int(PyObject* obj)
+SWIGINTERNINLINE unsigned int SWIG_As_unsigned_SS_int(PyObject * obj)
 {
-  unsigned int v;
-  if (!SWIG_AsVal_unsigned_SS_int(obj, &v)) {
-    /*
-      this is needed to make valgrind/purify happier. 
-     */
-    memset((void*)&v, 0, sizeof(unsigned int));
-  }
-  return v;
+	unsigned int v;
+	if (!SWIG_AsVal_unsigned_SS_int(obj, &v)) {
+		/*
+		   this is needed to make valgrind/purify happier. 
+		 */
+		memset((void *) &v, 0, sizeof(unsigned int));
+	}
+	return v;
 }
 
-  
-SWIGINTERNINLINE int
-SWIG_Check_unsigned_SS_int(PyObject* obj)
+
+SWIGINTERNINLINE int SWIG_Check_unsigned_SS_int(PyObject * obj)
 {
-  return SWIG_AsVal_unsigned_SS_int(obj, (unsigned int*)0);
+	return SWIG_AsVal_unsigned_SS_int(obj, (unsigned int *) 0);
 }
 
 
-SWIGINTERN PyObject *
-SWIG_FromCharPtr(const char* cptr)
-{ 
-  if (cptr) {
-    size_t size = strlen(cptr);
-    if (size > INT_MAX) {
-      return SWIG_NewPointerObj((char*)(cptr), 
-				SWIG_TypeQuery("char *"), 0);
-    } else {
-      if (size != 0) {
-	return PyString_FromStringAndSize(cptr, size);
-      } else {
-	return PyString_FromString(cptr);
-      }
-    }
-  }
-  Py_INCREF(Py_None);
-  return Py_None;
+SWIGINTERN PyObject *SWIG_FromCharPtr(const char *cptr)
+{
+	if (cptr) {
+		size_t size = strlen(cptr);
+		if (size > INT_MAX) {
+			return SWIG_NewPointerObj((char *) (cptr), SWIG_TypeQuery("char *"), 0);
+		} else {
+			if (size != 0) {
+				return PyString_FromStringAndSize(cptr, size);
+			} else {
+				return PyString_FromString(cptr);
+			}
+		}
+	}
+	Py_INCREF(Py_None);
+	return Py_None;
 }
 
 
@@ -1609,867 +1527,978 @@
 #ifdef __cplusplus
 extern "C" {
 #endif
-static PyObject *_wrap_fs_core_set_globals(PyObject *self, PyObject *args) {
-    PyObject *resultobj = NULL;
-    
-    if(!PyArg_ParseTuple(args,(char *)":fs_core_set_globals")) goto fail;
-    fs_core_set_globals();
-    
-    Py_INCREF(Py_None); resultobj = Py_None;
-    return resultobj;
-    fail:
-    return NULL;
-}
+	static PyObject *_wrap_fs_core_set_globals(PyObject * self, PyObject * args) {
+		PyObject *resultobj = NULL;
 
-
-static PyObject *_wrap_fs_core_init(PyObject *self, PyObject *args) {
-    PyObject *resultobj = NULL;
-    char *arg1 = (char *) 0 ;
-    int result;
-    PyObject * obj0 = 0 ;
-    
-    if(!PyArg_ParseTuple(args,(char *)"O:fs_core_init",&obj0)) goto fail;
-    if (!SWIG_AsCharPtr(obj0, (char**)&arg1)) {
-        SWIG_arg_fail(1);SWIG_fail;
-    }
-    result = (int)fs_core_init(arg1);
-    
-    {
-        resultobj = SWIG_From_int((int)(result)); 
-    }
-    return resultobj;
-    fail:
-    return NULL;
-}
+		if       (!PyArg_ParseTuple(args, (char *) ":fs_core_set_globals"))
+			         goto fail;
+		         fs_core_set_globals();
+
+		         Py_INCREF(Py_None);
+		         resultobj = Py_None;
+		         return resultobj;
+		         fail:return NULL;
+	}
+	static PyObject *_wrap_fs_core_init(PyObject * self, PyObject * args) {
+		PyObject *resultobj = NULL;
+		char *arg1 = (char *) 0;
+		int result;
+		PyObject *obj0 = 0;
+
+		if (!PyArg_ParseTuple(args, (char *) "O:fs_core_init", &obj0))
+			goto fail;
+		if (!SWIG_AsCharPtr(obj0, (char **) &arg1)) {
+			SWIG_arg_fail(1);
+			SWIG_fail;
+		}
+		result = (int) fs_core_init(arg1);
+
+		{
+			resultobj = SWIG_From_int((int) (result));
+		}
+		return resultobj;
+	  fail:
+		return NULL;
+	}
 
 
-static PyObject *_wrap_fs_core_destroy(PyObject *self, PyObject *args) {
-    PyObject *resultobj = NULL;
-    int result;
-    
-    if(!PyArg_ParseTuple(args,(char *)":fs_core_destroy")) goto fail;
-    result = (int)fs_core_destroy();
-    
-    {
-        resultobj = SWIG_From_int((int)(result)); 
-    }
-    return resultobj;
-    fail:
-    return NULL;
-}
+	static PyObject *_wrap_fs_core_destroy(PyObject * self, PyObject * args) {
+		PyObject *resultobj = NULL;
+		int result;
+
+		if (!PyArg_ParseTuple(args, (char *) ":fs_core_destroy"))
+			goto fail;
+		result = (int) fs_core_destroy();
+
+		{
+			resultobj = SWIG_From_int((int) (result));
+		}
+		return resultobj;
+	  fail:
+		return NULL;
+	}
 
 
-static PyObject *_wrap_fs_loadable_module_init(PyObject *self, PyObject *args) {
-    PyObject *resultobj = NULL;
-    int result;
-    
-    if(!PyArg_ParseTuple(args,(char *)":fs_loadable_module_init")) goto fail;
-    result = (int)fs_loadable_module_init();
-    
-    {
-        resultobj = SWIG_From_int((int)(result)); 
-    }
-    return resultobj;
-    fail:
-    return NULL;
-}
+	static PyObject *_wrap_fs_loadable_module_init(PyObject * self, PyObject * args) {
+		PyObject *resultobj = NULL;
+		int result;
+
+		if (!PyArg_ParseTuple(args, (char *) ":fs_loadable_module_init"))
+			goto fail;
+		result = (int) fs_loadable_module_init();
+
+		{
+			resultobj = SWIG_From_int((int) (result));
+		}
+		return resultobj;
+	  fail:
+		return NULL;
+	}
 
 
-static PyObject *_wrap_fs_loadable_module_shutdown(PyObject *self, PyObject *args) {
-    PyObject *resultobj = NULL;
-    int result;
-    
-    if(!PyArg_ParseTuple(args,(char *)":fs_loadable_module_shutdown")) goto fail;
-    result = (int)fs_loadable_module_shutdown();
-    
-    {
-        resultobj = SWIG_From_int((int)(result)); 
-    }
-    return resultobj;
-    fail:
-    return NULL;
-}
+	static PyObject *_wrap_fs_loadable_module_shutdown(PyObject * self, PyObject * args) {
+		PyObject *resultobj = NULL;
+		int result;
+
+		if (!PyArg_ParseTuple(args, (char *) ":fs_loadable_module_shutdown"))
+			goto fail;
+		result = (int) fs_loadable_module_shutdown();
+
+		{
+			resultobj = SWIG_From_int((int) (result));
+		}
+		return resultobj;
+	  fail:
+		return NULL;
+	}
 
 
-static PyObject *_wrap_fs_console_loop(PyObject *self, PyObject *args) {
-    PyObject *resultobj = NULL;
-    int result;
-    
-    if(!PyArg_ParseTuple(args,(char *)":fs_console_loop")) goto fail;
-    result = (int)fs_console_loop();
-    
-    {
-        resultobj = SWIG_From_int((int)(result)); 
-    }
-    return resultobj;
-    fail:
-    return NULL;
-}
+	static PyObject *_wrap_fs_console_loop(PyObject * self, PyObject * args) {
+		PyObject *resultobj = NULL;
+		int result;
+
+		if (!PyArg_ParseTuple(args, (char *) ":fs_console_loop"))
+			goto fail;
+		result = (int) fs_console_loop();
+
+		{
+			resultobj = SWIG_From_int((int) (result));
+		}
+		return resultobj;
+	  fail:
+		return NULL;
+	}
 
 
-static PyObject *_wrap_fs_console_log(PyObject *self, PyObject *args) {
-    PyObject *resultobj = NULL;
-    char *arg1 = (char *) 0 ;
-    char *arg2 = (char *) 0 ;
-    PyObject * obj0 = 0 ;
-    PyObject * obj1 = 0 ;
-    
-    if(!PyArg_ParseTuple(args,(char *)"OO:fs_console_log",&obj0,&obj1)) goto fail;
-    if (!SWIG_AsCharPtr(obj0, (char**)&arg1)) {
-        SWIG_arg_fail(1);SWIG_fail;
-    }
-    if (!SWIG_AsCharPtr(obj1, (char**)&arg2)) {
-        SWIG_arg_fail(2);SWIG_fail;
-    }
-    fs_console_log(arg1,arg2);
-    
-    Py_INCREF(Py_None); resultobj = Py_None;
-    return resultobj;
-    fail:
-    return NULL;
-}
+	static PyObject *_wrap_fs_console_log(PyObject * self, PyObject * args) {
+		PyObject *resultobj = NULL;
+		char *arg1 = (char *) 0;
+		char *arg2 = (char *) 0;
+		PyObject *obj0 = 0;
+		PyObject *obj1 = 0;
+
+		if (!PyArg_ParseTuple(args, (char *) "OO:fs_console_log", &obj0, &obj1))
+			goto fail;
+		if (!SWIG_AsCharPtr(obj0, (char **) &arg1)) {
+			SWIG_arg_fail(1);
+			SWIG_fail;
+		}
+		if (!SWIG_AsCharPtr(obj1, (char **) &arg2)) {
+			SWIG_arg_fail(2);
+			SWIG_fail;
+		}
+		fs_console_log(arg1, arg2);
+
+		Py_INCREF(Py_None);
+		resultobj = Py_None;
+		return resultobj;
+	  fail:
+		return NULL;
+	}
 
 
-static PyObject *_wrap_fs_console_clean(PyObject *self, PyObject *args) {
-    PyObject *resultobj = NULL;
-    char *arg1 = (char *) 0 ;
-    PyObject * obj0 = 0 ;
-    
-    if(!PyArg_ParseTuple(args,(char *)"O:fs_console_clean",&obj0)) goto fail;
-    if (!SWIG_AsCharPtr(obj0, (char**)&arg1)) {
-        SWIG_arg_fail(1);SWIG_fail;
-    }
-    fs_console_clean(arg1);
-    
-    Py_INCREF(Py_None); resultobj = Py_None;
-    return resultobj;
-    fail:
-    return NULL;
-}
+	static PyObject *_wrap_fs_console_clean(PyObject * self, PyObject * args) {
+		PyObject *resultobj = NULL;
+		char *arg1 = (char *) 0;
+		PyObject *obj0 = 0;
+
+		if (!PyArg_ParseTuple(args, (char *) "O:fs_console_clean", &obj0))
+			goto fail;
+		if (!SWIG_AsCharPtr(obj0, (char **) &arg1)) {
+			SWIG_arg_fail(1);
+			SWIG_fail;
+		}
+		fs_console_clean(arg1);
+
+		Py_INCREF(Py_None);
+		resultobj = Py_None;
+		return resultobj;
+	  fail:
+		return NULL;
+	}
 
 
-static PyObject *_wrap_fs_core_session_locate(PyObject *self, PyObject *args) {
-    PyObject *resultobj = NULL;
-    char *arg1 = (char *) 0 ;
-    switch_core_session_t *result;
-    PyObject * obj0 = 0 ;
-    
-    if(!PyArg_ParseTuple(args,(char *)"O:fs_core_session_locate",&obj0)) goto fail;
-    if (!SWIG_AsCharPtr(obj0, (char**)&arg1)) {
-        SWIG_arg_fail(1);SWIG_fail;
-    }
-    result = (switch_core_session_t *)fs_core_session_locate(arg1);
-    
-    resultobj = SWIG_NewPointerObj((void*)(result), SWIGTYPE_p_switch_core_session_t, 0);
-    return resultobj;
-    fail:
-    return NULL;
-}
+	static PyObject *_wrap_fs_core_session_locate(PyObject * self, PyObject * args) {
+		PyObject *resultobj = NULL;
+		char *arg1 = (char *) 0;
+		switch_core_session_t *result;
+		PyObject *obj0 = 0;
+
+		if (!PyArg_ParseTuple(args, (char *) "O:fs_core_session_locate", &obj0))
+			goto fail;
+		if (!SWIG_AsCharPtr(obj0, (char **) &arg1)) {
+			SWIG_arg_fail(1);
+			SWIG_fail;
+		}
+		result = (switch_core_session_t *) fs_core_session_locate(arg1);
+
+		resultobj = SWIG_NewPointerObj((void *) (result), SWIGTYPE_p_switch_core_session_t, 0);
+		return resultobj;
+	  fail:
+		return NULL;
+	}
 
 
-static PyObject *_wrap_fs_channel_answer(PyObject *self, PyObject *args) {
-    PyObject *resultobj = NULL;
-    switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
-    PyObject * obj0 = 0 ;
-    
-    if(!PyArg_ParseTuple(args,(char *)"O:fs_channel_answer",&obj0)) goto fail;
-    SWIG_Python_ConvertPtr(obj0, (void **)&arg1, SWIGTYPE_p_switch_core_session_t, SWIG_POINTER_EXCEPTION | 0);
-    if (SWIG_arg_fail(1)) SWIG_fail;
-    fs_channel_answer(arg1);
-    
-    Py_INCREF(Py_None); resultobj = Py_None;
-    return resultobj;
-    fail:
-    return NULL;
-}
+	static PyObject *_wrap_fs_channel_answer(PyObject * self, PyObject * args) {
+		PyObject *resultobj = NULL;
+		switch_core_session_t *arg1 = (switch_core_session_t *) 0;
+		PyObject *obj0 = 0;
+
+		if (!PyArg_ParseTuple(args, (char *) "O:fs_channel_answer", &obj0))
+			goto fail;
+		SWIG_Python_ConvertPtr(obj0, (void **) &arg1, SWIGTYPE_p_switch_core_session_t, SWIG_POINTER_EXCEPTION | 0);
+		if (SWIG_arg_fail(1))
+			SWIG_fail;
+		fs_channel_answer(arg1);
+
+		Py_INCREF(Py_None);
+		resultobj = Py_None;
+		return resultobj;
+	  fail:
+		return NULL;
+	}
 
 
-static PyObject *_wrap_fs_channel_pre_answer(PyObject *self, PyObject *args) {
-    PyObject *resultobj = NULL;
-    switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
-    PyObject * obj0 = 0 ;
-    
-    if(!PyArg_ParseTuple(args,(char *)"O:fs_channel_pre_answer",&obj0)) goto fail;
-    SWIG_Python_ConvertPtr(obj0, (void **)&arg1, SWIGTYPE_p_switch_core_session_t, SWIG_POINTER_EXCEPTION | 0);
-    if (SWIG_arg_fail(1)) SWIG_fail;
-    fs_channel_pre_answer(arg1);
-    
-    Py_INCREF(Py_None); resultobj = Py_None;
-    return resultobj;
-    fail:
-    return NULL;
-}
+	static PyObject *_wrap_fs_channel_pre_answer(PyObject * self, PyObject * args) {
+		PyObject *resultobj = NULL;
+		switch_core_session_t *arg1 = (switch_core_session_t *) 0;
+		PyObject *obj0 = 0;
+
+		if (!PyArg_ParseTuple(args, (char *) "O:fs_channel_pre_answer", &obj0))
+			goto fail;
+		SWIG_Python_ConvertPtr(obj0, (void **) &arg1, SWIGTYPE_p_switch_core_session_t, SWIG_POINTER_EXCEPTION | 0);
+		if (SWIG_arg_fail(1))
+			SWIG_fail;
+		fs_channel_pre_answer(arg1);
+
+		Py_INCREF(Py_None);
+		resultobj = Py_None;
+		return resultobj;
+	  fail:
+		return NULL;
+	}
 
 
-static PyObject *_wrap_fs_channel_hangup(PyObject *self, PyObject *args) {
-    PyObject *resultobj = NULL;
-    switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
-    char *arg2 = (char *) 0 ;
-    PyObject * obj0 = 0 ;
-    PyObject * obj1 = 0 ;
-    
-    if(!PyArg_ParseTuple(args,(char *)"OO:fs_channel_hangup",&obj0,&obj1)) goto fail;
-    SWIG_Python_ConvertPtr(obj0, (void **)&arg1, SWIGTYPE_p_switch_core_session_t, SWIG_POINTER_EXCEPTION | 0);
-    if (SWIG_arg_fail(1)) SWIG_fail;
-    if (!SWIG_AsCharPtr(obj1, (char**)&arg2)) {
-        SWIG_arg_fail(2);SWIG_fail;
-    }
-    fs_channel_hangup(arg1,arg2);
-    
-    Py_INCREF(Py_None); resultobj = Py_None;
-    return resultobj;
-    fail:
-    return NULL;
-}
+	static PyObject *_wrap_fs_channel_hangup(PyObject * self, PyObject * args) {
+		PyObject *resultobj = NULL;
+		switch_core_session_t *arg1 = (switch_core_session_t *) 0;
+		char *arg2 = (char *) 0;
+		PyObject *obj0 = 0;
+		PyObject *obj1 = 0;
+
+		if (!PyArg_ParseTuple(args, (char *) "OO:fs_channel_hangup", &obj0, &obj1))
+			goto fail;
+		SWIG_Python_ConvertPtr(obj0, (void **) &arg1, SWIGTYPE_p_switch_core_session_t, SWIG_POINTER_EXCEPTION | 0);
+		if (SWIG_arg_fail(1))
+			SWIG_fail;
+		if (!SWIG_AsCharPtr(obj1, (char **) &arg2)) {
+			SWIG_arg_fail(2);
+			SWIG_fail;
+		}
+		fs_channel_hangup(arg1, arg2);
+
+		Py_INCREF(Py_None);
+		resultobj = Py_None;
+		return resultobj;
+	  fail:
+		return NULL;
+	}
 
 
-static PyObject *_wrap_fs_channel_set_variable(PyObject *self, PyObject *args) {
-    PyObject *resultobj = NULL;
-    switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
-    char *arg2 = (char *) 0 ;
-    char *arg3 = (char *) 0 ;
-    PyObject * obj0 = 0 ;
-    PyObject * obj1 = 0 ;
-    PyObject * obj2 = 0 ;
-    
-    if(!PyArg_ParseTuple(args,(char *)"OOO:fs_channel_set_variable",&obj0,&obj1,&obj2)) goto fail;
-    SWIG_Python_ConvertPtr(obj0, (void **)&arg1, SWIGTYPE_p_switch_core_session_t, SWIG_POINTER_EXCEPTION | 0);
-    if (SWIG_arg_fail(1)) SWIG_fail;
-    if (!SWIG_AsCharPtr(obj1, (char**)&arg2)) {
-        SWIG_arg_fail(2);SWIG_fail;
-    }
-    if (!SWIG_AsCharPtr(obj2, (char**)&arg3)) {
-        SWIG_arg_fail(3);SWIG_fail;
-    }
-    fs_channel_set_variable(arg1,arg2,arg3);
-    
-    Py_INCREF(Py_None); resultobj = Py_None;
-    return resultobj;
-    fail:
-    return NULL;
-}
+	static PyObject *_wrap_fs_channel_set_variable(PyObject * self, PyObject * args) {
+		PyObject *resultobj = NULL;
+		switch_core_session_t *arg1 = (switch_core_session_t *) 0;
+		char *arg2 = (char *) 0;
+		char *arg3 = (char *) 0;
+		PyObject *obj0 = 0;
+		PyObject *obj1 = 0;
+		PyObject *obj2 = 0;
+
+		if (!PyArg_ParseTuple(args, (char *) "OOO:fs_channel_set_variable", &obj0, &obj1, &obj2))
+			goto fail;
+		SWIG_Python_ConvertPtr(obj0, (void **) &arg1, SWIGTYPE_p_switch_core_session_t, SWIG_POINTER_EXCEPTION | 0);
+		if (SWIG_arg_fail(1))
+			SWIG_fail;
+		if (!SWIG_AsCharPtr(obj1, (char **) &arg2)) {
+			SWIG_arg_fail(2);
+			SWIG_fail;
+		}
+		if (!SWIG_AsCharPtr(obj2, (char **) &arg3)) {
+			SWIG_arg_fail(3);
+			SWIG_fail;
+		}
+		fs_channel_set_variable(arg1, arg2, arg3);
+
+		Py_INCREF(Py_None);
+		resultobj = Py_None;
+		return resultobj;
+	  fail:
+		return NULL;
+	}
 
 
-static PyObject *_wrap_fs_channel_get_variable(PyObject *self, PyObject *args) {
-    PyObject *resultobj = NULL;
-    switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
-    char *arg2 = (char *) 0 ;
-    PyObject * obj0 = 0 ;
-    PyObject * obj1 = 0 ;
-    
-    if(!PyArg_ParseTuple(args,(char *)"OO:fs_channel_get_variable",&obj0,&obj1)) goto fail;
-    SWIG_Python_ConvertPtr(obj0, (void **)&arg1, SWIGTYPE_p_switch_core_session_t, SWIG_POINTER_EXCEPTION | 0);
-    if (SWIG_arg_fail(1)) SWIG_fail;
-    if (!SWIG_AsCharPtr(obj1, (char**)&arg2)) {
-        SWIG_arg_fail(2);SWIG_fail;
-    }
-    fs_channel_get_variable(arg1,arg2);
-    
-    Py_INCREF(Py_None); resultobj = Py_None;
-    return resultobj;
-    fail:
-    return NULL;
-}
+	static PyObject *_wrap_fs_channel_get_variable(PyObject * self, PyObject * args) {
+		PyObject *resultobj = NULL;
+		switch_core_session_t *arg1 = (switch_core_session_t *) 0;
+		char *arg2 = (char *) 0;
+		PyObject *obj0 = 0;
+		PyObject *obj1 = 0;
+
+		if (!PyArg_ParseTuple(args, (char *) "OO:fs_channel_get_variable", &obj0, &obj1))
+			goto fail;
+		SWIG_Python_ConvertPtr(obj0, (void **) &arg1, SWIGTYPE_p_switch_core_session_t, SWIG_POINTER_EXCEPTION | 0);
+		if (SWIG_arg_fail(1))
+			SWIG_fail;
+		if (!SWIG_AsCharPtr(obj1, (char **) &arg2)) {
+			SWIG_arg_fail(2);
+			SWIG_fail;
+		}
+		fs_channel_get_variable(arg1, arg2);
+
+		Py_INCREF(Py_None);
+		resultobj = Py_None;
+		return resultobj;
+	  fail:
+		return NULL;
+	}
 
 
-static PyObject *_wrap_fs_channel_set_state(PyObject *self, PyObject *args) {
-    PyObject *resultobj = NULL;
-    switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
-    char *arg2 = (char *) 0 ;
-    PyObject * obj0 = 0 ;
-    PyObject * obj1 = 0 ;
-    
-    if(!PyArg_ParseTuple(args,(char *)"OO:fs_channel_set_state",&obj0,&obj1)) goto fail;
-    SWIG_Python_ConvertPtr(obj0, (void **)&arg1, SWIGTYPE_p_switch_core_session_t, SWIG_POINTER_EXCEPTION | 0);
-    if (SWIG_arg_fail(1)) SWIG_fail;
-    if (!SWIG_AsCharPtr(obj1, (char**)&arg2)) {
-        SWIG_arg_fail(2);SWIG_fail;
-    }
-    fs_channel_set_state(arg1,arg2);
-    
-    Py_INCREF(Py_None); resultobj = Py_None;
-    return resultobj;
-    fail:
-    return NULL;
-}
+	static PyObject *_wrap_fs_channel_set_state(PyObject * self, PyObject * args) {
+		PyObject *resultobj = NULL;
+		switch_core_session_t *arg1 = (switch_core_session_t *) 0;
+		char *arg2 = (char *) 0;
+		PyObject *obj0 = 0;
+		PyObject *obj1 = 0;
+
+		if (!PyArg_ParseTuple(args, (char *) "OO:fs_channel_set_state", &obj0, &obj1))
+			goto fail;
+		SWIG_Python_ConvertPtr(obj0, (void **) &arg1, SWIGTYPE_p_switch_core_session_t, SWIG_POINTER_EXCEPTION | 0);
+		if (SWIG_arg_fail(1))
+			SWIG_fail;
+		if (!SWIG_AsCharPtr(obj1, (char **) &arg2)) {
+			SWIG_arg_fail(2);
+			SWIG_fail;
+		}
+		fs_channel_set_state(arg1, arg2);
+
+		Py_INCREF(Py_None);
+		resultobj = Py_None;
+		return resultobj;
+	  fail:
+		return NULL;
+	}
 
 
-static PyObject *_wrap_fs_ivr_play_file(PyObject *self, PyObject *args) {
-    PyObject *resultobj = NULL;
-    switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
-    char *arg2 = (char *) 0 ;
-    char *arg3 = (char *) 0 ;
-    switch_input_callback_function_t arg4 ;
-    void *arg5 = (void *) 0 ;
-    unsigned int arg6 ;
-    int result;
-    PyObject * obj0 = 0 ;
-    PyObject * obj1 = 0 ;
-    PyObject * obj2 = 0 ;
-    PyObject * obj3 = 0 ;
-    PyObject * obj4 = 0 ;
-    PyObject * obj5 = 0 ;
-    
-    if(!PyArg_ParseTuple(args,(char *)"OOOOOO:fs_ivr_play_file",&obj0,&obj1,&obj2,&obj3,&obj4,&obj5)) goto fail;
-    SWIG_Python_ConvertPtr(obj0, (void **)&arg1, SWIGTYPE_p_switch_core_session_t, SWIG_POINTER_EXCEPTION | 0);
-    if (SWIG_arg_fail(1)) SWIG_fail;
-    if (!SWIG_AsCharPtr(obj1, (char**)&arg2)) {
-        SWIG_arg_fail(2);SWIG_fail;
-    }
-    if (!SWIG_AsCharPtr(obj2, (char**)&arg3)) {
-        SWIG_arg_fail(3);SWIG_fail;
-    }
-    {
-        switch_input_callback_function_t * argp;
-        SWIG_Python_ConvertPtr(obj3, (void **)&argp, SWIGTYPE_p_switch_input_callback_function_t, SWIG_POINTER_EXCEPTION);
-        if (SWIG_arg_fail(4)) SWIG_fail;
-        if (argp == NULL) {
-            SWIG_null_ref("switch_input_callback_function_t");
-        }
-        if (SWIG_arg_fail(4)) SWIG_fail;
-        arg4 = *argp;
-    }
-    {
-        if ((SWIG_ConvertPtr(obj4,(void **)(&arg5),0,SWIG_POINTER_EXCEPTION|0))== -1) {
-            SWIG_arg_fail(5);SWIG_fail;
-        }
-    }
-    {
-        arg6 = (unsigned int)(SWIG_As_unsigned_SS_int(obj5)); 
-        if (SWIG_arg_fail(6)) SWIG_fail;
-    }
-    result = (int)fs_ivr_play_file(arg1,arg2,arg3,arg4,arg5,arg6);
-    
-    {
-        resultobj = SWIG_From_int((int)(result)); 
-    }
-    return resultobj;
-    fail:
-    return NULL;
-}
+	static PyObject *_wrap_fs_ivr_play_file(PyObject * self, PyObject * args) {
+		PyObject *resultobj = NULL;
+		switch_core_session_t *arg1 = (switch_core_session_t *) 0;
+		char *arg2 = (char *) 0;
+		char *arg3 = (char *) 0;
+		switch_input_callback_function_t arg4;
+		void *arg5 = (void *) 0;
+		unsigned int arg6;
+		int result;
+		PyObject *obj0 = 0;
+		PyObject *obj1 = 0;
+		PyObject *obj2 = 0;
+		PyObject *obj3 = 0;
+		PyObject *obj4 = 0;
+		PyObject *obj5 = 0;
+
+		if (!PyArg_ParseTuple(args, (char *) "OOOOOO:fs_ivr_play_file", &obj0, &obj1, &obj2, &obj3, &obj4, &obj5))
+			goto fail;
+		SWIG_Python_ConvertPtr(obj0, (void **) &arg1, SWIGTYPE_p_switch_core_session_t, SWIG_POINTER_EXCEPTION | 0);
+		if (SWIG_arg_fail(1))
+			SWIG_fail;
+		if (!SWIG_AsCharPtr(obj1, (char **) &arg2)) {
+			SWIG_arg_fail(2);
+			SWIG_fail;
+		}
+		if (!SWIG_AsCharPtr(obj2, (char **) &arg3)) {
+			SWIG_arg_fail(3);
+			SWIG_fail;
+		}
+		{
+			switch_input_callback_function_t *argp;
+			SWIG_Python_ConvertPtr(obj3, (void **) &argp, SWIGTYPE_p_switch_input_callback_function_t, SWIG_POINTER_EXCEPTION);
+			if (SWIG_arg_fail(4))
+				SWIG_fail;
+			if (argp == NULL) {
+				SWIG_null_ref("switch_input_callback_function_t");
+			}
+			if (SWIG_arg_fail(4))
+				SWIG_fail;
+			arg4 = *argp;
+		}
+		{
+			if ((SWIG_ConvertPtr(obj4, (void **) (&arg5), 0, SWIG_POINTER_EXCEPTION | 0)) == -1) {
+				SWIG_arg_fail(5);
+				SWIG_fail;
+			}
+		}
+		{
+			arg6 = (unsigned int) (SWIG_As_unsigned_SS_int(obj5));
+			if (SWIG_arg_fail(6))
+				SWIG_fail;
+		}
+		result = (int) fs_ivr_play_file(arg1, arg2, arg3, arg4, arg5, arg6);
+
+		{
+			resultobj = SWIG_From_int((int) (result));
+		}
+		return resultobj;
+	  fail:
+		return NULL;
+	}
 
 
-static PyObject *_wrap_fs_switch_ivr_record_file(PyObject *self, PyObject *args) {
-    PyObject *resultobj = NULL;
-    switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
-    switch_file_handle_t *arg2 = (switch_file_handle_t *) 0 ;
-    char *arg3 = (char *) 0 ;
-    switch_input_callback_function_t arg4 ;
-    void *arg5 = (void *) 0 ;
-    unsigned int arg6 ;
-    int result;
-    PyObject * obj0 = 0 ;
-    PyObject * obj1 = 0 ;
-    PyObject * obj2 = 0 ;
-    PyObject * obj3 = 0 ;
-    PyObject * obj4 = 0 ;
-    PyObject * obj5 = 0 ;
-    
-    if(!PyArg_ParseTuple(args,(char *)"OOOOOO:fs_switch_ivr_record_file",&obj0,&obj1,&obj2,&obj3,&obj4,&obj5)) goto fail;
-    SWIG_Python_ConvertPtr(obj0, (void **)&arg1, SWIGTYPE_p_switch_core_session_t, SWIG_POINTER_EXCEPTION | 0);
-    if (SWIG_arg_fail(1)) SWIG_fail;
-    SWIG_Python_ConvertPtr(obj1, (void **)&arg2, SWIGTYPE_p_switch_file_handle_t, SWIG_POINTER_EXCEPTION | 0);
-    if (SWIG_arg_fail(2)) SWIG_fail;
-    if (!SWIG_AsCharPtr(obj2, (char**)&arg3)) {
-        SWIG_arg_fail(3);SWIG_fail;
-    }
-    {
-        switch_input_callback_function_t * argp;
-        SWIG_Python_ConvertPtr(obj3, (void **)&argp, SWIGTYPE_p_switch_input_callback_function_t, SWIG_POINTER_EXCEPTION);
-        if (SWIG_arg_fail(4)) SWIG_fail;
-        if (argp == NULL) {
-            SWIG_null_ref("switch_input_callback_function_t");
-        }
-        if (SWIG_arg_fail(4)) SWIG_fail;
-        arg4 = *argp;
-    }
-    {
-        if ((SWIG_ConvertPtr(obj4,(void **)(&arg5),0,SWIG_POINTER_EXCEPTION|0))== -1) {
-            SWIG_arg_fail(5);SWIG_fail;
-        }
-    }
-    {
-        arg6 = (unsigned int)(SWIG_As_unsigned_SS_int(obj5)); 
-        if (SWIG_arg_fail(6)) SWIG_fail;
-    }
-    result = (int)fs_switch_ivr_record_file(arg1,arg2,arg3,arg4,arg5,arg6);
-    
-    {
-        resultobj = SWIG_From_int((int)(result)); 
-    }
-    return resultobj;
-    fail:
-    return NULL;
-}
+	static PyObject *_wrap_fs_switch_ivr_record_file(PyObject * self, PyObject * args) {
+		PyObject *resultobj = NULL;
+		switch_core_session_t *arg1 = (switch_core_session_t *) 0;
+		switch_file_handle_t *arg2 = (switch_file_handle_t *) 0;
+		char *arg3 = (char *) 0;
+		switch_input_callback_function_t arg4;
+		void *arg5 = (void *) 0;
+		unsigned int arg6;
+		int result;
+		PyObject *obj0 = 0;
+		PyObject *obj1 = 0;
+		PyObject *obj2 = 0;
+		PyObject *obj3 = 0;
+		PyObject *obj4 = 0;
+		PyObject *obj5 = 0;
+
+		if (!PyArg_ParseTuple(args, (char *) "OOOOOO:fs_switch_ivr_record_file", &obj0, &obj1, &obj2, &obj3, &obj4, &obj5))
+			goto fail;
+		SWIG_Python_ConvertPtr(obj0, (void **) &arg1, SWIGTYPE_p_switch_core_session_t, SWIG_POINTER_EXCEPTION | 0);
+		if (SWIG_arg_fail(1))
+			SWIG_fail;
+		SWIG_Python_ConvertPtr(obj1, (void **) &arg2, SWIGTYPE_p_switch_file_handle_t, SWIG_POINTER_EXCEPTION | 0);
+		if (SWIG_arg_fail(2))
+			SWIG_fail;
+		if (!SWIG_AsCharPtr(obj2, (char **) &arg3)) {
+			SWIG_arg_fail(3);
+			SWIG_fail;
+		}
+		{
+			switch_input_callback_function_t *argp;
+			SWIG_Python_ConvertPtr(obj3, (void **) &argp, SWIGTYPE_p_switch_input_callback_function_t, SWIG_POINTER_EXCEPTION);
+			if (SWIG_arg_fail(4))
+				SWIG_fail;
+			if (argp == NULL) {
+				SWIG_null_ref("switch_input_callback_function_t");
+			}
+			if (SWIG_arg_fail(4))
+				SWIG_fail;
+			arg4 = *argp;
+		}
+		{
+			if ((SWIG_ConvertPtr(obj4, (void **) (&arg5), 0, SWIG_POINTER_EXCEPTION | 0)) == -1) {
+				SWIG_arg_fail(5);
+				SWIG_fail;
+			}
+		}
+		{
+			arg6 = (unsigned int) (SWIG_As_unsigned_SS_int(obj5));
+			if (SWIG_arg_fail(6))
+				SWIG_fail;
+		}
+		result = (int) fs_switch_ivr_record_file(arg1, arg2, arg3, arg4, arg5, arg6);
+
+		{
+			resultobj = SWIG_From_int((int) (result));
+		}
+		return resultobj;
+	  fail:
+		return NULL;
+	}
 
 
-static PyObject *_wrap_fs_switch_ivr_sleep(PyObject *self, PyObject *args) {
-    PyObject *resultobj = NULL;
-    switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
-    unsigned int arg2 ;
-    int result;
-    PyObject * obj0 = 0 ;
-    PyObject * obj1 = 0 ;
-    
-    if(!PyArg_ParseTuple(args,(char *)"OO:fs_switch_ivr_sleep",&obj0,&obj1)) goto fail;
-    SWIG_Python_ConvertPtr(obj0, (void **)&arg1, SWIGTYPE_p_switch_core_session_t, SWIG_POINTER_EXCEPTION | 0);
-    if (SWIG_arg_fail(1)) SWIG_fail;
-    {
-        arg2 = (unsigned int)(SWIG_As_unsigned_SS_int(obj1)); 
-        if (SWIG_arg_fail(2)) SWIG_fail;
-    }
-    result = (int)fs_switch_ivr_sleep(arg1,arg2);
-    
-    {
-        resultobj = SWIG_From_int((int)(result)); 
-    }
-    return resultobj;
-    fail:
-    return NULL;
-}
+	static PyObject *_wrap_fs_switch_ivr_sleep(PyObject * self, PyObject * args) {
+		PyObject *resultobj = NULL;
+		switch_core_session_t *arg1 = (switch_core_session_t *) 0;
+		unsigned int arg2;
+		int result;
+		PyObject *obj0 = 0;
+		PyObject *obj1 = 0;
+
+		if (!PyArg_ParseTuple(args, (char *) "OO:fs_switch_ivr_sleep", &obj0, &obj1))
+			goto fail;
+		SWIG_Python_ConvertPtr(obj0, (void **) &arg1, SWIGTYPE_p_switch_core_session_t, SWIG_POINTER_EXCEPTION | 0);
+		if (SWIG_arg_fail(1))
+			SWIG_fail;
+		{
+			arg2 = (unsigned int) (SWIG_As_unsigned_SS_int(obj1));
+			if (SWIG_arg_fail(2))
+				SWIG_fail;
+		}
+		result = (int) fs_switch_ivr_sleep(arg1, arg2);
+
+		{
+			resultobj = SWIG_From_int((int) (result));
+		}
+		return resultobj;
+	  fail:
+		return NULL;
+	}
 
 
-static PyObject *_wrap_fs_ivr_play_file2(PyObject *self, PyObject *args) {
-    PyObject *resultobj = NULL;
-    switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
-    char *arg2 = (char *) 0 ;
-    int result;
-    PyObject * obj0 = 0 ;
-    PyObject * obj1 = 0 ;
-    
-    if(!PyArg_ParseTuple(args,(char *)"OO:fs_ivr_play_file2",&obj0,&obj1)) goto fail;
-    SWIG_Python_ConvertPtr(obj0, (void **)&arg1, SWIGTYPE_p_switch_core_session_t, SWIG_POINTER_EXCEPTION | 0);
-    if (SWIG_arg_fail(1)) SWIG_fail;
-    if (!SWIG_AsCharPtr(obj1, (char**)&arg2)) {
-        SWIG_arg_fail(2);SWIG_fail;
-    }
-    result = (int)fs_ivr_play_file2(arg1,arg2);
-    
-    {
-        resultobj = SWIG_From_int((int)(result)); 
-    }
-    return resultobj;
-    fail:
-    return NULL;
-}
+	static PyObject *_wrap_fs_ivr_play_file2(PyObject * self, PyObject * args) {
+		PyObject *resultobj = NULL;
+		switch_core_session_t *arg1 = (switch_core_session_t *) 0;
+		char *arg2 = (char *) 0;
+		int result;
+		PyObject *obj0 = 0;
+		PyObject *obj1 = 0;
+
+		if (!PyArg_ParseTuple(args, (char *) "OO:fs_ivr_play_file2", &obj0, &obj1))
+			goto fail;
+		SWIG_Python_ConvertPtr(obj0, (void **) &arg1, SWIGTYPE_p_switch_core_session_t, SWIG_POINTER_EXCEPTION | 0);
+		if (SWIG_arg_fail(1))
+			SWIG_fail;
+		if (!SWIG_AsCharPtr(obj1, (char **) &arg2)) {
+			SWIG_arg_fail(2);
+			SWIG_fail;
+		}
+		result = (int) fs_ivr_play_file2(arg1, arg2);
+
+		{
+			resultobj = SWIG_From_int((int) (result));
+		}
+		return resultobj;
+	  fail:
+		return NULL;
+	}
 
 
-static PyObject *_wrap_fs_switch_ivr_collect_digits_callback(PyObject *self, PyObject *args) {
-    PyObject *resultobj = NULL;
-    switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
-    switch_input_callback_function_t arg2 ;
-    void *arg3 = (void *) 0 ;
-    unsigned int arg4 ;
-    unsigned int arg5 ;
-    int result;
-    PyObject * obj0 = 0 ;
-    PyObject * obj1 = 0 ;
-    PyObject * obj2 = 0 ;
-    PyObject * obj3 = 0 ;
-    PyObject * obj4 = 0 ;
-    
-    if(!PyArg_ParseTuple(args,(char *)"OOOOO:fs_switch_ivr_collect_digits_callback",&obj0,&obj1,&obj2,&obj3,&obj4)) goto fail;
-    SWIG_Python_ConvertPtr(obj0, (void **)&arg1, SWIGTYPE_p_switch_core_session_t, SWIG_POINTER_EXCEPTION | 0);
-    if (SWIG_arg_fail(1)) SWIG_fail;
-    {
-        switch_input_callback_function_t * argp;
-        SWIG_Python_ConvertPtr(obj1, (void **)&argp, SWIGTYPE_p_switch_input_callback_function_t, SWIG_POINTER_EXCEPTION);
-        if (SWIG_arg_fail(2)) SWIG_fail;
-        if (argp == NULL) {
-            SWIG_null_ref("switch_input_callback_function_t");
-        }
-        if (SWIG_arg_fail(2)) SWIG_fail;
-        arg2 = *argp;
-    }
-    {
-        if ((SWIG_ConvertPtr(obj2,(void **)(&arg3),0,SWIG_POINTER_EXCEPTION|0))== -1) {
-            SWIG_arg_fail(3);SWIG_fail;
-        }
-    }
-    {
-        arg4 = (unsigned int)(SWIG_As_unsigned_SS_int(obj3)); 
-        if (SWIG_arg_fail(4)) SWIG_fail;
-    }
-    {
-        arg5 = (unsigned int)(SWIG_As_unsigned_SS_int(obj4)); 
-        if (SWIG_arg_fail(5)) SWIG_fail;
-    }
-    result = (int)fs_switch_ivr_collect_digits_callback(arg1,arg2,arg3,arg4,arg5);
-    
-    {
-        resultobj = SWIG_From_int((int)(result)); 
-    }
-    return resultobj;
-    fail:
-    return NULL;
-}
+	static PyObject *_wrap_fs_switch_ivr_collect_digits_callback(PyObject * self, PyObject * args) {
+		PyObject *resultobj = NULL;
+		switch_core_session_t *arg1 = (switch_core_session_t *) 0;
+		switch_input_callback_function_t arg2;
+		void *arg3 = (void *) 0;
+		unsigned int arg4;
+		unsigned int arg5;
+		int result;
+		PyObject *obj0 = 0;
+		PyObject *obj1 = 0;
+		PyObject *obj2 = 0;
+		PyObject *obj3 = 0;
+		PyObject *obj4 = 0;
+
+		if (!PyArg_ParseTuple(args, (char *) "OOOOO:fs_switch_ivr_collect_digits_callback", &obj0, &obj1, &obj2, &obj3, &obj4))
+			goto fail;
+		SWIG_Python_ConvertPtr(obj0, (void **) &arg1, SWIGTYPE_p_switch_core_session_t, SWIG_POINTER_EXCEPTION | 0);
+		if (SWIG_arg_fail(1))
+			SWIG_fail;
+		{
+			switch_input_callback_function_t *argp;
+			SWIG_Python_ConvertPtr(obj1, (void **) &argp, SWIGTYPE_p_switch_input_callback_function_t, SWIG_POINTER_EXCEPTION);
+			if (SWIG_arg_fail(2))
+				SWIG_fail;
+			if (argp == NULL) {
+				SWIG_null_ref("switch_input_callback_function_t");
+			}
+			if (SWIG_arg_fail(2))
+				SWIG_fail;
+			arg2 = *argp;
+		}
+		{
+			if ((SWIG_ConvertPtr(obj2, (void **) (&arg3), 0, SWIG_POINTER_EXCEPTION | 0)) == -1) {
+				SWIG_arg_fail(3);
+				SWIG_fail;
+			}
+		}
+		{
+			arg4 = (unsigned int) (SWIG_As_unsigned_SS_int(obj3));
+			if (SWIG_arg_fail(4))
+				SWIG_fail;
+		}
+		{
+			arg5 = (unsigned int) (SWIG_As_unsigned_SS_int(obj4));
+			if (SWIG_arg_fail(5))
+				SWIG_fail;
+		}
+		result = (int) fs_switch_ivr_collect_digits_callback(arg1, arg2, arg3, arg4, arg5);
+
+		{
+			resultobj = SWIG_From_int((int) (result));
+		}
+		return resultobj;
+	  fail:
+		return NULL;
+	}
 
 
-static PyObject *_wrap_fs_switch_ivr_collect_digits_count(PyObject *self, PyObject *args) {
-    PyObject *resultobj = NULL;
-    switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
-    char *arg2 = (char *) 0 ;
-    unsigned int arg3 ;
-    unsigned int arg4 ;
-    char *arg5 = (char *) 0 ;
-    char *arg6 = (char *) 0 ;
-    unsigned int arg7 ;
-    int result;
-    PyObject * obj0 = 0 ;
-    PyObject * obj1 = 0 ;
-    PyObject * obj2 = 0 ;
-    PyObject * obj3 = 0 ;
-    PyObject * obj4 = 0 ;
-    PyObject * obj5 = 0 ;
-    PyObject * obj6 = 0 ;
-    
-    if(!PyArg_ParseTuple(args,(char *)"OOOOOOO:fs_switch_ivr_collect_digits_count",&obj0,&obj1,&obj2,&obj3,&obj4,&obj5,&obj6)) goto fail;
-    SWIG_Python_ConvertPtr(obj0, (void **)&arg1, SWIGTYPE_p_switch_core_session_t, SWIG_POINTER_EXCEPTION | 0);
-    if (SWIG_arg_fail(1)) SWIG_fail;
-    if (!SWIG_AsCharPtr(obj1, (char**)&arg2)) {
-        SWIG_arg_fail(2);SWIG_fail;
-    }
-    {
-        arg3 = (unsigned int)(SWIG_As_unsigned_SS_int(obj2)); 
-        if (SWIG_arg_fail(3)) SWIG_fail;
-    }
-    {
-        arg4 = (unsigned int)(SWIG_As_unsigned_SS_int(obj3)); 
-        if (SWIG_arg_fail(4)) SWIG_fail;
-    }
-    if (!SWIG_AsCharPtr(obj4, (char**)&arg5)) {
-        SWIG_arg_fail(5);SWIG_fail;
-    }
-    if (!SWIG_AsCharPtr(obj5, (char**)&arg6)) {
-        SWIG_arg_fail(6);SWIG_fail;
-    }
-    {
-        arg7 = (unsigned int)(SWIG_As_unsigned_SS_int(obj6)); 
-        if (SWIG_arg_fail(7)) SWIG_fail;
-    }
-    result = (int)fs_switch_ivr_collect_digits_count(arg1,arg2,arg3,arg4,(char const *)arg5,arg6,arg7);
-    
-    {
-        resultobj = SWIG_From_int((int)(result)); 
-    }
-    return resultobj;
-    fail:
-    return NULL;
-}
+	static PyObject *_wrap_fs_switch_ivr_collect_digits_count(PyObject * self, PyObject * args) {
+		PyObject *resultobj = NULL;
+		switch_core_session_t *arg1 = (switch_core_session_t *) 0;
+		char *arg2 = (char *) 0;
+		unsigned int arg3;
+		unsigned int arg4;
+		char *arg5 = (char *) 0;
+		char *arg6 = (char *) 0;
+		unsigned int arg7;
+		int result;
+		PyObject *obj0 = 0;
+		PyObject *obj1 = 0;
+		PyObject *obj2 = 0;
+		PyObject *obj3 = 0;
+		PyObject *obj4 = 0;
+		PyObject *obj5 = 0;
+		PyObject *obj6 = 0;
+
+		if (!PyArg_ParseTuple(args, (char *) "OOOOOOO:fs_switch_ivr_collect_digits_count", &obj0, &obj1, &obj2, &obj3, &obj4, &obj5, &obj6))
+			goto fail;
+		SWIG_Python_ConvertPtr(obj0, (void **) &arg1, SWIGTYPE_p_switch_core_session_t, SWIG_POINTER_EXCEPTION | 0);
+		if (SWIG_arg_fail(1))
+			SWIG_fail;
+		if (!SWIG_AsCharPtr(obj1, (char **) &arg2)) {
+			SWIG_arg_fail(2);
+			SWIG_fail;
+		}
+		{
+			arg3 = (unsigned int) (SWIG_As_unsigned_SS_int(obj2));
+			if (SWIG_arg_fail(3))
+				SWIG_fail;
+		}
+		{
+			arg4 = (unsigned int) (SWIG_As_unsigned_SS_int(obj3));
+			if (SWIG_arg_fail(4))
+				SWIG_fail;
+		}
+		if (!SWIG_AsCharPtr(obj4, (char **) &arg5)) {
+			SWIG_arg_fail(5);
+			SWIG_fail;
+		}
+		if (!SWIG_AsCharPtr(obj5, (char **) &arg6)) {
+			SWIG_arg_fail(6);
+			SWIG_fail;
+		}
+		{
+			arg7 = (unsigned int) (SWIG_As_unsigned_SS_int(obj6));
+			if (SWIG_arg_fail(7))
+				SWIG_fail;
+		}
+		result = (int) fs_switch_ivr_collect_digits_count(arg1, arg2, arg3, arg4, (char const *) arg5, arg6, arg7);
+
+		{
+			resultobj = SWIG_From_int((int) (result));
+		}
+		return resultobj;
+	  fail:
+		return NULL;
+	}
 
 
-static PyObject *_wrap_fs_switch_ivr_originate(PyObject *self, PyObject *args) {
-    PyObject *resultobj = NULL;
-    switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
-    switch_core_session_t **arg2 = (switch_core_session_t **) 0 ;
-    char *arg3 = (char *) 0 ;
-    unsigned int arg4 ;
-    int result;
-    PyObject * obj0 = 0 ;
-    PyObject * obj1 = 0 ;
-    PyObject * obj2 = 0 ;
-    PyObject * obj3 = 0 ;
-    
-    if(!PyArg_ParseTuple(args,(char *)"OOOO:fs_switch_ivr_originate",&obj0,&obj1,&obj2,&obj3)) goto fail;
-    SWIG_Python_ConvertPtr(obj0, (void **)&arg1, SWIGTYPE_p_switch_core_session_t, SWIG_POINTER_EXCEPTION | 0);
-    if (SWIG_arg_fail(1)) SWIG_fail;
-    SWIG_Python_ConvertPtr(obj1, (void **)&arg2, SWIGTYPE_p_p_switch_core_session_t, SWIG_POINTER_EXCEPTION | 0);
-    if (SWIG_arg_fail(2)) SWIG_fail;
-    if (!SWIG_AsCharPtr(obj2, (char**)&arg3)) {
-        SWIG_arg_fail(3);SWIG_fail;
-    }
-    {
-        arg4 = (unsigned int)(SWIG_As_unsigned_SS_int(obj3)); 
-        if (SWIG_arg_fail(4)) SWIG_fail;
-    }
-    result = (int)fs_switch_ivr_originate(arg1,arg2,arg3,arg4);
-    
-    {
-        resultobj = SWIG_From_int((int)(result)); 
-    }
-    return resultobj;
-    fail:
-    return NULL;
-}
+	static PyObject *_wrap_fs_switch_ivr_originate(PyObject * self, PyObject * args) {
+		PyObject *resultobj = NULL;
+		switch_core_session_t *arg1 = (switch_core_session_t *) 0;
+		switch_core_session_t **arg2 = (switch_core_session_t **) 0;
+		char *arg3 = (char *) 0;
+		unsigned int arg4;
+		int result;
+		PyObject *obj0 = 0;
+		PyObject *obj1 = 0;
+		PyObject *obj2 = 0;
+		PyObject *obj3 = 0;
+
+		if (!PyArg_ParseTuple(args, (char *) "OOOO:fs_switch_ivr_originate", &obj0, &obj1, &obj2, &obj3))
+			goto fail;
+		SWIG_Python_ConvertPtr(obj0, (void **) &arg1, SWIGTYPE_p_switch_core_session_t, SWIG_POINTER_EXCEPTION | 0);
+		if (SWIG_arg_fail(1))
+			SWIG_fail;
+		SWIG_Python_ConvertPtr(obj1, (void **) &arg2, SWIGTYPE_p_p_switch_core_session_t, SWIG_POINTER_EXCEPTION | 0);
+		if (SWIG_arg_fail(2))
+			SWIG_fail;
+		if (!SWIG_AsCharPtr(obj2, (char **) &arg3)) {
+			SWIG_arg_fail(3);
+			SWIG_fail;
+		}
+		{
+			arg4 = (unsigned int) (SWIG_As_unsigned_SS_int(obj3));
+			if (SWIG_arg_fail(4))
+				SWIG_fail;
+		}
+		result = (int) fs_switch_ivr_originate(arg1, arg2, arg3, arg4);
+
+		{
+			resultobj = SWIG_From_int((int) (result));
+		}
+		return resultobj;
+	  fail:
+		return NULL;
+	}
 
 
-static PyObject *_wrap_fs_switch_ivr_session_transfer(PyObject *self, PyObject *args) {
-    PyObject *resultobj = NULL;
-    switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
-    char *arg2 = (char *) 0 ;
-    char *arg3 = (char *) 0 ;
-    char *arg4 = (char *) 0 ;
-    int result;
-    PyObject * obj0 = 0 ;
-    PyObject * obj1 = 0 ;
-    PyObject * obj2 = 0 ;
-    PyObject * obj3 = 0 ;
-    
-    if(!PyArg_ParseTuple(args,(char *)"OOOO:fs_switch_ivr_session_transfer",&obj0,&obj1,&obj2,&obj3)) goto fail;
-    SWIG_Python_ConvertPtr(obj0, (void **)&arg1, SWIGTYPE_p_switch_core_session_t, SWIG_POINTER_EXCEPTION | 0);
-    if (SWIG_arg_fail(1)) SWIG_fail;
-    if (!SWIG_AsCharPtr(obj1, (char**)&arg2)) {
-        SWIG_arg_fail(2);SWIG_fail;
-    }
-    if (!SWIG_AsCharPtr(obj2, (char**)&arg3)) {
-        SWIG_arg_fail(3);SWIG_fail;
-    }
-    if (!SWIG_AsCharPtr(obj3, (char**)&arg4)) {
-        SWIG_arg_fail(4);SWIG_fail;
-    }
-    result = (int)fs_switch_ivr_session_transfer(arg1,arg2,arg3,arg4);
-    
-    {
-        resultobj = SWIG_From_int((int)(result)); 
-    }
-    return resultobj;
-    fail:
-    return NULL;
-}
+	static PyObject *_wrap_fs_switch_ivr_session_transfer(PyObject * self, PyObject * args) {
+		PyObject *resultobj = NULL;
+		switch_core_session_t *arg1 = (switch_core_session_t *) 0;
+		char *arg2 = (char *) 0;
+		char *arg3 = (char *) 0;
+		char *arg4 = (char *) 0;
+		int result;
+		PyObject *obj0 = 0;
+		PyObject *obj1 = 0;
+		PyObject *obj2 = 0;
+		PyObject *obj3 = 0;
+
+		if (!PyArg_ParseTuple(args, (char *) "OOOO:fs_switch_ivr_session_transfer", &obj0, &obj1, &obj2, &obj3))
+			goto fail;
+		SWIG_Python_ConvertPtr(obj0, (void **) &arg1, SWIGTYPE_p_switch_core_session_t, SWIG_POINTER_EXCEPTION | 0);
+		if (SWIG_arg_fail(1))
+			SWIG_fail;
+		if (!SWIG_AsCharPtr(obj1, (char **) &arg2)) {
+			SWIG_arg_fail(2);
+			SWIG_fail;
+		}
+		if (!SWIG_AsCharPtr(obj2, (char **) &arg3)) {
+			SWIG_arg_fail(3);
+			SWIG_fail;
+		}
+		if (!SWIG_AsCharPtr(obj3, (char **) &arg4)) {
+			SWIG_arg_fail(4);
+			SWIG_fail;
+		}
+		result = (int) fs_switch_ivr_session_transfer(arg1, arg2, arg3, arg4);
+
+		{
+			resultobj = SWIG_From_int((int) (result));
+		}
+		return resultobj;
+	  fail:
+		return NULL;
+	}
 
 
-static PyObject *_wrap_fs_switch_ivr_speak_text(PyObject *self, PyObject *args) {
-    PyObject *resultobj = NULL;
-    switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
-    char *arg2 = (char *) 0 ;
-    char *arg3 = (char *) 0 ;
-    char *arg4 = (char *) 0 ;
-    unsigned int arg5 ;
-    switch_input_callback_function_t arg6 ;
-    char *arg7 = (char *) 0 ;
-    void *arg8 = (void *) 0 ;
-    unsigned int arg9 ;
-    int result;
-    PyObject * obj0 = 0 ;
-    PyObject * obj1 = 0 ;
-    PyObject * obj2 = 0 ;
-    PyObject * obj3 = 0 ;
-    PyObject * obj4 = 0 ;
-    PyObject * obj5 = 0 ;
-    PyObject * obj6 = 0 ;
-    PyObject * obj7 = 0 ;
-    PyObject * obj8 = 0 ;
-    
-    if(!PyArg_ParseTuple(args,(char *)"OOOOOOOOO:fs_switch_ivr_speak_text",&obj0,&obj1,&obj2,&obj3,&obj4,&obj5,&obj6,&obj7,&obj8)) goto fail;
-    SWIG_Python_ConvertPtr(obj0, (void **)&arg1, SWIGTYPE_p_switch_core_session_t, SWIG_POINTER_EXCEPTION | 0);
-    if (SWIG_arg_fail(1)) SWIG_fail;
-    if (!SWIG_AsCharPtr(obj1, (char**)&arg2)) {
-        SWIG_arg_fail(2);SWIG_fail;
-    }
-    if (!SWIG_AsCharPtr(obj2, (char**)&arg3)) {
-        SWIG_arg_fail(3);SWIG_fail;
-    }
-    if (!SWIG_AsCharPtr(obj3, (char**)&arg4)) {
-        SWIG_arg_fail(4);SWIG_fail;
-    }
-    {
-        arg5 = (unsigned int)(SWIG_As_unsigned_SS_int(obj4)); 
-        if (SWIG_arg_fail(5)) SWIG_fail;
-    }
-    {
-        switch_input_callback_function_t * argp;
-        SWIG_Python_ConvertPtr(obj5, (void **)&argp, SWIGTYPE_p_switch_input_callback_function_t, SWIG_POINTER_EXCEPTION);
-        if (SWIG_arg_fail(6)) SWIG_fail;
-        if (argp == NULL) {
-            SWIG_null_ref("switch_input_callback_function_t");
-        }
-        if (SWIG_arg_fail(6)) SWIG_fail;
-        arg6 = *argp;
-    }
-    if (!SWIG_AsCharPtr(obj6, (char**)&arg7)) {
-        SWIG_arg_fail(7);SWIG_fail;
-    }
-    {
-        if ((SWIG_ConvertPtr(obj7,(void **)(&arg8),0,SWIG_POINTER_EXCEPTION|0))== -1) {
-            SWIG_arg_fail(8);SWIG_fail;
-        }
-    }
-    {
-        arg9 = (unsigned int)(SWIG_As_unsigned_SS_int(obj8)); 
-        if (SWIG_arg_fail(9)) SWIG_fail;
-    }
-    result = (int)fs_switch_ivr_speak_text(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9);
-    
-    {
-        resultobj = SWIG_From_int((int)(result)); 
-    }
-    return resultobj;
-    fail:
-    return NULL;
-}
+	static PyObject *_wrap_fs_switch_ivr_speak_text(PyObject * self, PyObject * args) {
+		PyObject *resultobj = NULL;
+		switch_core_session_t *arg1 = (switch_core_session_t *) 0;
+		char *arg2 = (char *) 0;
+		char *arg3 = (char *) 0;
+		char *arg4 = (char *) 0;
+		unsigned int arg5;
+		switch_input_callback_function_t arg6;
+		char *arg7 = (char *) 0;
+		void *arg8 = (void *) 0;
+		unsigned int arg9;
+		int result;
+		PyObject *obj0 = 0;
+		PyObject *obj1 = 0;
+		PyObject *obj2 = 0;
+		PyObject *obj3 = 0;
+		PyObject *obj4 = 0;
+		PyObject *obj5 = 0;
+		PyObject *obj6 = 0;
+		PyObject *obj7 = 0;
+		PyObject *obj8 = 0;
+
+		if (!PyArg_ParseTuple(args, (char *) "OOOOOOOOO:fs_switch_ivr_speak_text", &obj0, &obj1, &obj2, &obj3, &obj4, &obj5, &obj6, &obj7, &obj8))
+			goto fail;
+		SWIG_Python_ConvertPtr(obj0, (void **) &arg1, SWIGTYPE_p_switch_core_session_t, SWIG_POINTER_EXCEPTION | 0);
+		if (SWIG_arg_fail(1))
+			SWIG_fail;
+		if (!SWIG_AsCharPtr(obj1, (char **) &arg2)) {
+			SWIG_arg_fail(2);
+			SWIG_fail;
+		}
+		if (!SWIG_AsCharPtr(obj2, (char **) &arg3)) {
+			SWIG_arg_fail(3);
+			SWIG_fail;
+		}
+		if (!SWIG_AsCharPtr(obj3, (char **) &arg4)) {
+			SWIG_arg_fail(4);
+			SWIG_fail;
+		}
+		{
+			arg5 = (unsigned int) (SWIG_As_unsigned_SS_int(obj4));
+			if (SWIG_arg_fail(5))
+				SWIG_fail;
+		}
+		{
+			switch_input_callback_function_t *argp;
+			SWIG_Python_ConvertPtr(obj5, (void **) &argp, SWIGTYPE_p_switch_input_callback_function_t, SWIG_POINTER_EXCEPTION);
+			if (SWIG_arg_fail(6))
+				SWIG_fail;
+			if (argp == NULL) {
+				SWIG_null_ref("switch_input_callback_function_t");
+			}
+			if (SWIG_arg_fail(6))
+				SWIG_fail;
+			arg6 = *argp;
+		}
+		if (!SWIG_AsCharPtr(obj6, (char **) &arg7)) {
+			SWIG_arg_fail(7);
+			SWIG_fail;
+		}
+		{
+			if ((SWIG_ConvertPtr(obj7, (void **) (&arg8), 0, SWIG_POINTER_EXCEPTION | 0)) == -1) {
+				SWIG_arg_fail(8);
+				SWIG_fail;
+			}
+		}
+		{
+			arg9 = (unsigned int) (SWIG_As_unsigned_SS_int(obj8));
+			if (SWIG_arg_fail(9))
+				SWIG_fail;
+		}
+		result = (int) fs_switch_ivr_speak_text(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
+
+		{
+			resultobj = SWIG_From_int((int) (result));
+		}
+		return resultobj;
+	  fail:
+		return NULL;
+	}
 
 
-static PyObject *_wrap_fs_switch_ivr_speak_text2(PyObject *self, PyObject *args) {
-    PyObject *resultobj = NULL;
-    switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
-    char *arg2 = (char *) 0 ;
-    char *arg3 = (char *) 0 ;
-    char *arg4 = (char *) 0 ;
-    int result;
-    PyObject * obj0 = 0 ;
-    PyObject * obj1 = 0 ;
-    PyObject * obj2 = 0 ;
-    PyObject * obj3 = 0 ;
-    
-    if(!PyArg_ParseTuple(args,(char *)"OOOO:fs_switch_ivr_speak_text2",&obj0,&obj1,&obj2,&obj3)) goto fail;
-    SWIG_Python_ConvertPtr(obj0, (void **)&arg1, SWIGTYPE_p_switch_core_session_t, SWIG_POINTER_EXCEPTION | 0);
-    if (SWIG_arg_fail(1)) SWIG_fail;
-    if (!SWIG_AsCharPtr(obj1, (char**)&arg2)) {
-        SWIG_arg_fail(2);SWIG_fail;
-    }
-    if (!SWIG_AsCharPtr(obj2, (char**)&arg3)) {
-        SWIG_arg_fail(3);SWIG_fail;
-    }
-    if (!SWIG_AsCharPtr(obj3, (char**)&arg4)) {
-        SWIG_arg_fail(4);SWIG_fail;
-    }
-    result = (int)fs_switch_ivr_speak_text2(arg1,arg2,arg3,arg4);
-    
-    {
-        resultobj = SWIG_From_int((int)(result)); 
-    }
-    return resultobj;
-    fail:
-    return NULL;
-}
+	static PyObject *_wrap_fs_switch_ivr_speak_text2(PyObject * self, PyObject * args) {
+		PyObject *resultobj = NULL;
+		switch_core_session_t *arg1 = (switch_core_session_t *) 0;
+		char *arg2 = (char *) 0;
+		char *arg3 = (char *) 0;
+		char *arg4 = (char *) 0;
+		int result;
+		PyObject *obj0 = 0;
+		PyObject *obj1 = 0;
+		PyObject *obj2 = 0;
+		PyObject *obj3 = 0;
+
+		if (!PyArg_ParseTuple(args, (char *) "OOOO:fs_switch_ivr_speak_text2", &obj0, &obj1, &obj2, &obj3))
+			goto fail;
+		SWIG_Python_ConvertPtr(obj0, (void **) &arg1, SWIGTYPE_p_switch_core_session_t, SWIG_POINTER_EXCEPTION | 0);
+		if (SWIG_arg_fail(1))
+			SWIG_fail;
+		if (!SWIG_AsCharPtr(obj1, (char **) &arg2)) {
+			SWIG_arg_fail(2);
+			SWIG_fail;
+		}
+		if (!SWIG_AsCharPtr(obj2, (char **) &arg3)) {
+			SWIG_arg_fail(3);
+			SWIG_fail;
+		}
+		if (!SWIG_AsCharPtr(obj3, (char **) &arg4)) {
+			SWIG_arg_fail(4);
+			SWIG_fail;
+		}
+		result = (int) fs_switch_ivr_speak_text2(arg1, arg2, arg3, arg4);
+
+		{
+			resultobj = SWIG_From_int((int) (result));
+		}
+		return resultobj;
+	  fail:
+		return NULL;
+	}
 
 
-static PyObject *_wrap_fs_switch_channel_get_variable(PyObject *self, PyObject *args) {
-    PyObject *resultobj = NULL;
-    switch_channel_t *arg1 = (switch_channel_t *) 0 ;
-    char *arg2 = (char *) 0 ;
-    char *result;
-    PyObject * obj0 = 0 ;
-    PyObject * obj1 = 0 ;
-    
-    if(!PyArg_ParseTuple(args,(char *)"OO:fs_switch_channel_get_variable",&obj0,&obj1)) goto fail;
-    SWIG_Python_ConvertPtr(obj0, (void **)&arg1, SWIGTYPE_p_switch_channel_t, SWIG_POINTER_EXCEPTION | 0);
-    if (SWIG_arg_fail(1)) SWIG_fail;
-    if (!SWIG_AsCharPtr(obj1, (char**)&arg2)) {
-        SWIG_arg_fail(2);SWIG_fail;
-    }
-    result = (char *)fs_switch_channel_get_variable(arg1,arg2);
-    
-    resultobj = SWIG_FromCharPtr(result);
-    return resultobj;
-    fail:
-    return NULL;
-}
+	static PyObject *_wrap_fs_switch_channel_get_variable(PyObject * self, PyObject * args) {
+		PyObject *resultobj = NULL;
+		switch_channel_t *arg1 = (switch_channel_t *) 0;
+		char *arg2 = (char *) 0;
+		char *result;
+		PyObject *obj0 = 0;
+		PyObject *obj1 = 0;
+
+		if (!PyArg_ParseTuple(args, (char *) "OO:fs_switch_channel_get_variable", &obj0, &obj1))
+			goto fail;
+		SWIG_Python_ConvertPtr(obj0, (void **) &arg1, SWIGTYPE_p_switch_channel_t, SWIG_POINTER_EXCEPTION | 0);
+		if (SWIG_arg_fail(1))
+			SWIG_fail;
+		if (!SWIG_AsCharPtr(obj1, (char **) &arg2)) {
+			SWIG_arg_fail(2);
+			SWIG_fail;
+		}
+		result = (char *) fs_switch_channel_get_variable(arg1, arg2);
+
+		resultobj = SWIG_FromCharPtr(result);
+		return resultobj;
+	  fail:
+		return NULL;
+	}
 
 
-static PyObject *_wrap_fs_switch_channel_set_variable(PyObject *self, PyObject *args) {
-    PyObject *resultobj = NULL;
-    switch_channel_t *arg1 = (switch_channel_t *) 0 ;
-    char *arg2 = (char *) 0 ;
-    char *arg3 = (char *) 0 ;
-    int result;
-    PyObject * obj0 = 0 ;
-    PyObject * obj1 = 0 ;
-    PyObject * obj2 = 0 ;
-    
-    if(!PyArg_ParseTuple(args,(char *)"OOO:fs_switch_channel_set_variable",&obj0,&obj1,&obj2)) goto fail;
-    SWIG_Python_ConvertPtr(obj0, (void **)&arg1, SWIGTYPE_p_switch_channel_t, SWIG_POINTER_EXCEPTION | 0);
-    if (SWIG_arg_fail(1)) SWIG_fail;
-    if (!SWIG_AsCharPtr(obj1, (char**)&arg2)) {
-        SWIG_arg_fail(2);SWIG_fail;
-    }
-    if (!SWIG_AsCharPtr(obj2, (char**)&arg3)) {
-        SWIG_arg_fail(3);SWIG_fail;
-    }
-    result = (int)fs_switch_channel_set_variable(arg1,arg2,arg3);
-    
-    {
-        resultobj = SWIG_From_int((int)(result)); 
-    }
-    return resultobj;
-    fail:
-    return NULL;
-}
+	static PyObject *_wrap_fs_switch_channel_set_variable(PyObject * self, PyObject * args) {
+		PyObject *resultobj = NULL;
+		switch_channel_t *arg1 = (switch_channel_t *) 0;
+		char *arg2 = (char *) 0;
+		char *arg3 = (char *) 0;
+		int result;
+		PyObject *obj0 = 0;
+		PyObject *obj1 = 0;
+		PyObject *obj2 = 0;
+
+		if (!PyArg_ParseTuple(args, (char *) "OOO:fs_switch_channel_set_variable", &obj0, &obj1, &obj2))
+			goto fail;
+		SWIG_Python_ConvertPtr(obj0, (void **) &arg1, SWIGTYPE_p_switch_channel_t, SWIG_POINTER_EXCEPTION | 0);
+		if (SWIG_arg_fail(1))
+			SWIG_fail;
+		if (!SWIG_AsCharPtr(obj1, (char **) &arg2)) {
+			SWIG_arg_fail(2);
+			SWIG_fail;
+		}
+		if (!SWIG_AsCharPtr(obj2, (char **) &arg3)) {
+			SWIG_arg_fail(3);
+			SWIG_fail;
+		}
+		result = (int) fs_switch_channel_set_variable(arg1, arg2, arg3);
+
+		{
+			resultobj = SWIG_From_int((int) (result));
+		}
+		return resultobj;
+	  fail:
+		return NULL;
+	}
 
 
-static PyMethodDef SwigMethods[] = {
-	 { (char *)"fs_core_set_globals", _wrap_fs_core_set_globals, METH_VARARGS, NULL},
-	 { (char *)"fs_core_init", _wrap_fs_core_init, METH_VARARGS, NULL},
-	 { (char *)"fs_core_destroy", _wrap_fs_core_destroy, METH_VARARGS, NULL},
-	 { (char *)"fs_loadable_module_init", _wrap_fs_loadable_module_init, METH_VARARGS, NULL},
-	 { (char *)"fs_loadable_module_shutdown", _wrap_fs_loadable_module_shutdown, METH_VARARGS, NULL},
-	 { (char *)"fs_console_loop", _wrap_fs_console_loop, METH_VARARGS, NULL},
-	 { (char *)"fs_console_log", _wrap_fs_console_log, METH_VARARGS, NULL},
-	 { (char *)"fs_console_clean", _wrap_fs_console_clean, METH_VARARGS, NULL},
-	 { (char *)"fs_core_session_locate", _wrap_fs_core_session_locate, METH_VARARGS, NULL},
-	 { (char *)"fs_channel_answer", _wrap_fs_channel_answer, METH_VARARGS, NULL},
-	 { (char *)"fs_channel_pre_answer", _wrap_fs_channel_pre_answer, METH_VARARGS, NULL},
-	 { (char *)"fs_channel_hangup", _wrap_fs_channel_hangup, METH_VARARGS, NULL},
-	 { (char *)"fs_channel_set_variable", _wrap_fs_channel_set_variable, METH_VARARGS, NULL},
-	 { (char *)"fs_channel_get_variable", _wrap_fs_channel_get_variable, METH_VARARGS, NULL},
-	 { (char *)"fs_channel_set_state", _wrap_fs_channel_set_state, METH_VARARGS, NULL},
-	 { (char *)"fs_ivr_play_file", _wrap_fs_ivr_play_file, METH_VARARGS, NULL},
-	 { (char *)"fs_switch_ivr_record_file", _wrap_fs_switch_ivr_record_file, METH_VARARGS, NULL},
-	 { (char *)"fs_switch_ivr_sleep", _wrap_fs_switch_ivr_sleep, METH_VARARGS, NULL},
-	 { (char *)"fs_ivr_play_file2", _wrap_fs_ivr_play_file2, METH_VARARGS, NULL},
-	 { (char *)"fs_switch_ivr_collect_digits_callback", _wrap_fs_switch_ivr_collect_digits_callback, METH_VARARGS, NULL},
-	 { (char *)"fs_switch_ivr_collect_digits_count", _wrap_fs_switch_ivr_collect_digits_count, METH_VARARGS, NULL},
-	 { (char *)"fs_switch_ivr_originate", _wrap_fs_switch_ivr_originate, METH_VARARGS, NULL},
-	 { (char *)"fs_switch_ivr_session_transfer", _wrap_fs_switch_ivr_session_transfer, METH_VARARGS, NULL},
-	 { (char *)"fs_switch_ivr_speak_text", _wrap_fs_switch_ivr_speak_text, METH_VARARGS, NULL},
-	 { (char *)"fs_switch_ivr_speak_text2", _wrap_fs_switch_ivr_speak_text2, METH_VARARGS, NULL},
-	 { (char *)"fs_switch_channel_get_variable", _wrap_fs_switch_channel_get_variable, METH_VARARGS, NULL},
-	 { (char *)"fs_switch_channel_set_variable", _wrap_fs_switch_channel_set_variable, METH_VARARGS, NULL},
-	 { NULL, NULL, 0, NULL }
-};
+	static PyMethodDef SwigMethods[] = {
+		{(char *) "fs_core_set_globals", _wrap_fs_core_set_globals, METH_VARARGS, NULL},
+		{(char *) "fs_core_init", _wrap_fs_core_init, METH_VARARGS, NULL},
+		{(char *) "fs_core_destroy", _wrap_fs_core_destroy, METH_VARARGS, NULL},
+		{(char *) "fs_loadable_module_init", _wrap_fs_loadable_module_init, METH_VARARGS, NULL},
+		{(char *) "fs_loadable_module_shutdown", _wrap_fs_loadable_module_shutdown, METH_VARARGS, NULL},
+		{(char *) "fs_console_loop", _wrap_fs_console_loop, METH_VARARGS, NULL},
+		{(char *) "fs_console_log", _wrap_fs_console_log, METH_VARARGS, NULL},
+		{(char *) "fs_console_clean", _wrap_fs_console_clean, METH_VARARGS, NULL},
+		{(char *) "fs_core_session_locate", _wrap_fs_core_session_locate, METH_VARARGS, NULL},
+		{(char *) "fs_channel_answer", _wrap_fs_channel_answer, METH_VARARGS, NULL},
+		{(char *) "fs_channel_pre_answer", _wrap_fs_channel_pre_answer, METH_VARARGS, NULL},
+		{(char *) "fs_channel_hangup", _wrap_fs_channel_hangup, METH_VARARGS, NULL},
+		{(char *) "fs_channel_set_variable", _wrap_fs_channel_set_variable, METH_VARARGS, NULL},
+		{(char *) "fs_channel_get_variable", _wrap_fs_channel_get_variable, METH_VARARGS, NULL},
+		{(char *) "fs_channel_set_state", _wrap_fs_channel_set_state, METH_VARARGS, NULL},
+		{(char *) "fs_ivr_play_file", _wrap_fs_ivr_play_file, METH_VARARGS, NULL},
+		{(char *) "fs_switch_ivr_record_file", _wrap_fs_switch_ivr_record_file, METH_VARARGS, NULL},
+		{(char *) "fs_switch_ivr_sleep", _wrap_fs_switch_ivr_sleep, METH_VARARGS, NULL},
+		{(char *) "fs_ivr_play_file2", _wrap_fs_ivr_play_file2, METH_VARARGS, NULL},
+		{(char *) "fs_switch_ivr_collect_digits_callback", _wrap_fs_switch_ivr_collect_digits_callback, METH_VARARGS,
+		 NULL},
+		{(char *) "fs_switch_ivr_collect_digits_count", _wrap_fs_switch_ivr_collect_digits_count, METH_VARARGS, NULL},
+		{(char *) "fs_switch_ivr_originate", _wrap_fs_switch_ivr_originate, METH_VARARGS, NULL},
+		{(char *) "fs_switch_ivr_session_transfer", _wrap_fs_switch_ivr_session_transfer, METH_VARARGS, NULL},
+		{(char *) "fs_switch_ivr_speak_text", _wrap_fs_switch_ivr_speak_text, METH_VARARGS, NULL},
+		{(char *) "fs_switch_ivr_speak_text2", _wrap_fs_switch_ivr_speak_text2, METH_VARARGS, NULL},
+		{(char *) "fs_switch_channel_get_variable", _wrap_fs_switch_channel_get_variable, METH_VARARGS, NULL},
+		{(char *) "fs_switch_channel_set_variable", _wrap_fs_switch_channel_set_variable, METH_VARARGS, NULL},
+		{NULL, NULL, 0, NULL}
+	};
 
 
 /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */
 
-static swig_type_info _swigt__p_char = {"_p_char", "char *", 0, 0, 0};
-static swig_type_info _swigt__p_p_switch_core_session_t = {"_p_p_switch_core_session_t", "switch_core_session_t **", 0, 0, 0};
-static swig_type_info _swigt__p_switch_channel_state_t = {"_p_switch_channel_state_t", "enum switch_channel_state_t *|switch_channel_state_t *", 0, 0, 0};
-static swig_type_info _swigt__p_switch_channel_t = {"_p_switch_channel_t", "switch_channel_t *", 0, 0, 0};
-static swig_type_info _swigt__p_switch_core_session_t = {"_p_switch_core_session_t", "switch_core_session_t *", 0, 0, 0};
-static swig_type_info _swigt__p_switch_file_handle_t = {"_p_switch_file_handle_t", "switch_file_handle_t *", 0, 0, 0};
-static swig_type_info _swigt__p_switch_input_callback_function_t = {"_p_switch_input_callback_function_t", "switch_input_callback_function_t *", 0, 0, 0};
-static swig_type_info _swigt__ptrdiff_t = {"_ptrdiff_t", "ptrdiff_t", 0, 0, 0};
-static swig_type_info _swigt__size_t = {"_size_t", "size_t", 0, 0, 0};
-
-static swig_type_info *swig_type_initial[] = {
-  &_swigt__p_char,
-  &_swigt__p_p_switch_core_session_t,
-  &_swigt__p_switch_channel_state_t,
-  &_swigt__p_switch_channel_t,
-  &_swigt__p_switch_core_session_t,
-  &_swigt__p_switch_file_handle_t,
-  &_swigt__p_switch_input_callback_function_t,
-  &_swigt__ptrdiff_t,
-  &_swigt__size_t,
-};
-
-static swig_cast_info _swigc__p_char[] = {  {&_swigt__p_char, 0, 0, 0},{0, 0, 0, 0}};
-static swig_cast_info _swigc__p_p_switch_core_session_t[] = {  {&_swigt__p_p_switch_core_session_t, 0, 0, 0},{0, 0, 0, 0}};
-static swig_cast_info _swigc__p_switch_channel_state_t[] = {  {&_swigt__p_switch_channel_state_t, 0, 0, 0},{0, 0, 0, 0}};
-static swig_cast_info _swigc__p_switch_channel_t[] = {  {&_swigt__p_switch_channel_t, 0, 0, 0},{0, 0, 0, 0}};
-static swig_cast_info _swigc__p_switch_core_session_t[] = {  {&_swigt__p_switch_core_session_t, 0, 0, 0},{0, 0, 0, 0}};
-static swig_cast_info _swigc__p_switch_file_handle_t[] = {  {&_swigt__p_switch_file_handle_t, 0, 0, 0},{0, 0, 0, 0}};
-static swig_cast_info _swigc__p_switch_input_callback_function_t[] = {  {&_swigt__p_switch_input_callback_function_t, 0, 0, 0},{0, 0, 0, 0}};
-static swig_cast_info _swigc__ptrdiff_t[] = {  {&_swigt__ptrdiff_t, 0, 0, 0},{0, 0, 0, 0}};
-static swig_cast_info _swigc__size_t[] = {  {&_swigt__size_t, 0, 0, 0},{0, 0, 0, 0}};
-
-static swig_cast_info *swig_cast_initial[] = {
-  _swigc__p_char,
-  _swigc__p_p_switch_core_session_t,
-  _swigc__p_switch_channel_state_t,
-  _swigc__p_switch_channel_t,
-  _swigc__p_switch_core_session_t,
-  _swigc__p_switch_file_handle_t,
-  _swigc__p_switch_input_callback_function_t,
-  _swigc__ptrdiff_t,
-  _swigc__size_t,
-};
+	static swig_type_info _swigt__p_char = { "_p_char", "char *", 0, 0, 0 };
+	static swig_type_info _swigt__p_p_switch_core_session_t = { "_p_p_switch_core_session_t", "switch_core_session_t **", 0, 0, 0 };
+	static swig_type_info _swigt__p_switch_channel_state_t =
+		{ "_p_switch_channel_state_t", "enum switch_channel_state_t *|switch_channel_state_t *", 0, 0, 0 };
+	static swig_type_info _swigt__p_switch_channel_t = { "_p_switch_channel_t", "switch_channel_t *", 0, 0, 0 };
+	static swig_type_info _swigt__p_switch_core_session_t = { "_p_switch_core_session_t", "switch_core_session_t *", 0, 0, 0 };
+	static swig_type_info _swigt__p_switch_file_handle_t = { "_p_switch_file_handle_t", "switch_file_handle_t *", 0, 0, 0 };
+	static swig_type_info _swigt__p_switch_input_callback_function_t =
+		{ "_p_switch_input_callback_function_t", "switch_input_callback_function_t *", 0, 0, 0 };
+	static swig_type_info _swigt__ptrdiff_t = { "_ptrdiff_t", "ptrdiff_t", 0, 0, 0 };
+	static swig_type_info _swigt__size_t = { "_size_t", "size_t", 0, 0, 0 };
+
+	static swig_type_info *swig_type_initial[] = {
+		&_swigt__p_char,
+		&_swigt__p_p_switch_core_session_t,
+		&_swigt__p_switch_channel_state_t,
+		&_swigt__p_switch_channel_t,
+		&_swigt__p_switch_core_session_t,
+		&_swigt__p_switch_file_handle_t,
+		&_swigt__p_switch_input_callback_function_t,
+		&_swigt__ptrdiff_t,
+		&_swigt__size_t,
+	};
+
+	static swig_cast_info _swigc__p_char[] = { {&_swigt__p_char, 0, 0, 0}, {0, 0, 0, 0} };
+	static swig_cast_info _swigc__p_p_switch_core_session_t[] = { {&_swigt__p_p_switch_core_session_t, 0, 0, 0}, {0, 0, 0, 0} };
+	static swig_cast_info _swigc__p_switch_channel_state_t[] = { {&_swigt__p_switch_channel_state_t, 0, 0, 0}, {0, 0, 0, 0} };
+	static swig_cast_info _swigc__p_switch_channel_t[] = { {&_swigt__p_switch_channel_t, 0, 0, 0}, {0, 0, 0, 0} };
+	static swig_cast_info _swigc__p_switch_core_session_t[] = { {&_swigt__p_switch_core_session_t, 0, 0, 0}, {0, 0, 0, 0} };
+	static swig_cast_info _swigc__p_switch_file_handle_t[] = { {&_swigt__p_switch_file_handle_t, 0, 0, 0}, {0, 0, 0, 0} };
+	static swig_cast_info _swigc__p_switch_input_callback_function_t[] = { {&_swigt__p_switch_input_callback_function_t, 0, 0, 0}, {0, 0, 0, 0} };
+	static swig_cast_info _swigc__ptrdiff_t[] = { {&_swigt__ptrdiff_t, 0, 0, 0}, {0, 0, 0, 0} };
+	static swig_cast_info _swigc__size_t[] = { {&_swigt__size_t, 0, 0, 0}, {0, 0, 0, 0} };
+
+	static swig_cast_info *swig_cast_initial[] = {
+		_swigc__p_char,
+		_swigc__p_p_switch_core_session_t,
+		_swigc__p_switch_channel_state_t,
+		_swigc__p_switch_channel_t,
+		_swigc__p_switch_core_session_t,
+		_swigc__p_switch_file_handle_t,
+		_swigc__p_switch_input_callback_function_t,
+		_swigc__ptrdiff_t,
+		_swigc__size_t,
+	};
 
 
 /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (END) -------- */
 
-static swig_const_info swig_const_table[] = {
-{0, 0, 0, 0.0, 0, 0}};
+	static swig_const_info swig_const_table[] = {
+		{0, 0, 0, 0.0, 0, 0}
+	};
 
 #ifdef __cplusplus
 }
@@ -2518,108 +2547,109 @@
 #ifdef __cplusplus
 extern "C" {
 #endif
-    
-    SWIGRUNTIME void
-    SWIG_InitializeModule(void *clientdata) {
-        swig_type_info *type, *ret;
-        swig_cast_info *cast;
-        size_t i;
-        swig_module_info *module_head;
-        static int init_run = 0;
-        
-        clientdata = clientdata;
-        
-        if (init_run) return;
-        init_run = 1;
-        
-        /* Initialize the swig_module */
-        swig_module.type_initial = swig_type_initial;
-        swig_module.cast_initial = swig_cast_initial;
-        
-        /* Try and load any already created modules */
-        module_head = SWIG_GetModule(clientdata);
-        if (module_head) {
-            swig_module.next = module_head->next;
-            module_head->next = &swig_module;
-        } else {
-            /* This is the first module loaded */
-            swig_module.next = &swig_module;
-            SWIG_SetModule(clientdata, &swig_module);
-        }
-        
-        /* Now work on filling in swig_module.types */
-        for (i = 0; i < swig_module.size; ++i) {
-            type = 0;
-            
-            /* if there is another module already loaded */
-            if (swig_module.next != &swig_module) {
-                type = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, swig_module.type_initial[i]->name);
-            }
-            if (type) {
-                /* Overwrite clientdata field */
-                if (swig_module.type_initial[i]->clientdata) type->clientdata = swig_module.type_initial[i]->clientdata;
-            } else {
-                type = swig_module.type_initial[i];
-            }
-            
-            /* Insert casting types */
-            cast = swig_module.cast_initial[i];
-            while (cast->type) {
-                /* Don't need to add information already in the list */
-                ret = 0;
-                if (swig_module.next != &swig_module) {
-                    ret = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, cast->type->name);
-                }
-                if (ret && type == swig_module.type_initial[i]) {
-                    cast->type = ret;
-                    ret = 0;
-                }
-                
-                if (!ret) {
-                    if (type->cast) {
-                        type->cast->prev = cast;
-                        cast->next = type->cast;
-                    }
-                    type->cast = cast;
-                }
-                
-                cast++;
-            }
-            
-            /* Set entry in modules->types array equal to the type */
-            swig_module.types[i] = type;
-        }
-        swig_module.types[i] = 0;
-    }
-    
-    /* This function will propagate the clientdata field of type to
-    * any new swig_type_info structures that have been added into the list
-    * of equivalent types.  It is like calling
-    * SWIG_TypeClientData(type, clientdata) a second time.
-    */
-    SWIGRUNTIME void
-    SWIG_PropagateClientData(void) {
-        size_t i;
-        swig_cast_info *equiv;
-        static int init_run = 0;
-        
-        if (init_run) return;
-        init_run = 1;
-        
-        for (i = 0; i < swig_module.size; i++) {
-            if (swig_module.types[i]->clientdata) {
-                equiv = swig_module.types[i]->cast;
-                while (equiv) {
-                    if (!equiv->converter) {
-                        if (equiv->type && !equiv->type->clientdata)
-                        SWIG_TypeClientData(equiv->type, swig_module.types[i]->clientdata);
-                    }
-                    equiv = equiv->next;
-                }
-            }
-        }
-    }
-    
+
+	SWIGRUNTIME void SWIG_InitializeModule(void *clientdata) {
+		swig_type_info *type, *ret;
+		swig_cast_info *cast;
+		size_t i;
+		swig_module_info *module_head;
+		static int init_run = 0;
+
+		    clientdata = clientdata;
+
+		if  (init_run)
+			    return;
+		    init_run = 1;
+
+		/* Initialize the swig_module */
+		    swig_module.type_initial = swig_type_initial;
+		    swig_module.cast_initial = swig_cast_initial;
+
+		/* Try and load any already created modules */
+		    module_head = SWIG_GetModule(clientdata);
+		if  (module_head) {
+			swig_module.next = module_head->next;
+			module_head->next = &swig_module;
+		} else {
+			/* This is the first module loaded */
+			swig_module.next = &swig_module;
+			SWIG_SetModule(clientdata, &swig_module);
+		}
+
+		/* Now work on filling in swig_module.types */
+		for (i = 0; i < swig_module.size; ++i) {
+			type = 0;
+
+			/* if there is another module already loaded */
+			if (swig_module.next != &swig_module) {
+				type = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, swig_module.type_initial[i]->name);
+			}
+			if (type) {
+				/* Overwrite clientdata field */
+				if (swig_module.type_initial[i]->clientdata)
+					type->clientdata = swig_module.type_initial[i]->clientdata;
+			} else {
+				type = swig_module.type_initial[i];
+			}
+
+			/* Insert casting types */
+			cast = swig_module.cast_initial[i];
+			while (cast->type) {
+				/* Don't need to add information already in the list */
+				ret = 0;
+				if (swig_module.next != &swig_module) {
+					ret = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, cast->type->name);
+				}
+				if (ret && type == swig_module.type_initial[i]) {
+					cast->type = ret;
+					ret = 0;
+				}
+
+				if (!ret) {
+					if (type->cast) {
+						type->cast->prev = cast;
+						cast->next = type->cast;
+					}
+					type->cast = cast;
+				}
+
+				cast++;
+			}
+
+			/* Set entry in modules->types array equal to the type */
+			swig_module.types[i] = type;
+		}
+		swig_module.types[i] = 0;
+	}
+
+	/* This function will propagate the clientdata field of type to
+	 * any new swig_type_info structures that have been added into the list
+	 * of equivalent types.  It is like calling
+	 * SWIG_TypeClientData(type, clientdata) a second time.
+	 */
+	SWIGRUNTIME void SWIG_PropagateClientData(void) {
+		size_t i;
+		swig_cast_info *equiv;
+		static int init_run = 0;
+
+		if (init_run)
+			return;
+		init_run = 1;
+
+		for (i = 0; i < swig_module.size; i++) {
+			if (swig_module.types[i]->clientdata) {
+				equiv = swig_module.types[i]->cast;
+				while (equiv) {
+					if (!equiv->converter) {
+						if (equiv->type && !equiv->type->clientdata)
+							SWIG_TypeClientData(equiv->type, swig_module.types[i]->clientdata);
+					}
+					equiv = equiv->next;
+				}
+			}
+		}
+	}
+
 #ifdef __cplusplus
 }
 #endif
@@ -2629,251 +2659,237 @@
 #ifdef __cplusplus
 extern "C" {
 #endif
-    
-    /* Python-specific SWIG API */
+
+	/* Python-specific SWIG API */
 #define SWIG_newvarlink()                             SWIG_Python_newvarlink()
 #define SWIG_addvarlink(p, name, get_attr, set_attr)  SWIG_Python_addvarlink(p, name, get_attr, set_attr)
 #define SWIG_InstallConstants(d, constants)           SWIG_Python_InstallConstants(d, constants)
-    
-    /* -----------------------------------------------------------------------------
-     * global variable support code.
-     * ----------------------------------------------------------------------------- */
-    
-    typedef struct swig_globalvar {
-        char       *name;                  /* Name of global variable */
-        PyObject *(*get_attr)(void);       /* Return the current value */
-        int       (*set_attr)(PyObject *); /* Set the value */
-        struct swig_globalvar *next;
-    } swig_globalvar;
-    
-    typedef struct swig_varlinkobject {
-        PyObject_HEAD
-        swig_globalvar *vars;
-    } swig_varlinkobject;
-    
-    SWIGINTERN PyObject *
-    swig_varlink_repr(swig_varlinkobject *v) {
-        v = v;
-        return PyString_FromString("<Swig global variables>");
-    }
-    
-    SWIGINTERN int
-    swig_varlink_print(swig_varlinkobject *v, FILE *fp, int flags) {
-        swig_globalvar  *var;
-        flags = flags;
-        fprintf(fp,"Swig global variables { ");
-        for (var = v->vars; var; var=var->next) {
-            fprintf(fp,"%s", var->name);
-            if (var->next) fprintf(fp,", ");
-        }
-        fprintf(fp," }\n");
-        return 0;
-    }
-    
-    SWIGINTERN PyObject *
-    swig_varlink_getattr(swig_varlinkobject *v, char *n) {
-        swig_globalvar *var = v->vars;
-        while (var) {
-            if (strcmp(var->name,n) == 0) {
-                return (*var->get_attr)();
-            }
-            var = var->next;
-        }
-        PyErr_SetString(PyExc_NameError,"Unknown C global variable");
-        return NULL;
-    }
-    
-    SWIGINTERN int
-    swig_varlink_setattr(swig_varlinkobject *v, char *n, PyObject *p) {
-        swig_globalvar *var = v->vars;
-        while (var) {
-            if (strcmp(var->name,n) == 0) {
-                return (*var->set_attr)(p);
-            }
-            var = var->next;
-        }
-        PyErr_SetString(PyExc_NameError,"Unknown C global variable");
-        return 1;
-    }
-    
-    SWIGINTERN PyTypeObject*
-    swig_varlink_type(void) {
-        static char varlink__doc__[] = "Swig var link object";
-        static PyTypeObject varlink_type
+
+	/* -----------------------------------------------------------------------------
+	 * global variable support code.
+	 * ----------------------------------------------------------------------------- */
+
+	typedef struct swig_globalvar {
+		char *name;				/* Name of global variable */
+		PyObject *(*get_attr) (void);	/* Return the current value */
+		int (*set_attr) (PyObject *);	/* Set the value */
+		struct swig_globalvar *next;
+	} swig_globalvar;
+
+	typedef struct swig_varlinkobject {
+		PyObject_HEAD swig_globalvar *vars;
+	} swig_varlinkobject;
+
+	SWIGINTERN PyObject *swig_varlink_repr(swig_varlinkobject * v) {
+		v = v;
+		return PyString_FromString("<Swig global variables>");
+	}
+	SWIGINTERN int swig_varlink_print(swig_varlinkobject * v, FILE * fp, int flags) {
+		swig_globalvar *var;
+		flags = flags;
+		fprintf(fp, "Swig global variables { ");
+		for (var = v->vars; var; var = var->next) {
+			fprintf(fp, "%s", var->name);
+			if (var->next)
+				fprintf(fp, ", ");
+		}
+		fprintf(fp, " }\n");
+		return 0;
+	}
+
+	SWIGINTERN PyObject *swig_varlink_getattr(swig_varlinkobject * v, char *n) {
+		swig_globalvar *var = v->vars;
+		while (var) {
+			if (strcmp(var->name, n) == 0) {
+				return (*var->get_attr) ();
+			}
+			var = var->next;
+		}
+		PyErr_SetString(PyExc_NameError, "Unknown C global variable");
+		return NULL;
+	}
+
+	SWIGINTERN int swig_varlink_setattr(swig_varlinkobject * v, char *n, PyObject * p) {
+		swig_globalvar *var = v->vars;
+		while (var) {
+			if (strcmp(var->name, n) == 0) {
+				return (*var->set_attr) (p);
+			}
+			var = var->next;
+		}
+		PyErr_SetString(PyExc_NameError, "Unknown C global variable");
+		return 1;
+	}
+
+	SWIGINTERN PyTypeObject *swig_varlink_type(void) {
+		static char varlink__doc__[] = "Swig var link object";
+		static PyTypeObject varlink_type
 #if !defined(__cplusplus)
-        ;
-        static int type_init = 0;  
-        if (!type_init) {
-            PyTypeObject tmp
-#endif
-            = {
-                PyObject_HEAD_INIT(&PyType_Type)
-                0,                                  /* Number of items in variable part (ob_size) */
-                (char *)"swigvarlink",              /* Type name (tp_name) */
-                sizeof(swig_varlinkobject),         /* Basic size (tp_basicsize) */
-                0,                                  /* Itemsize (tp_itemsize) */
-                0,                                  /* Deallocator (tp_dealloc) */ 
-                (printfunc) swig_varlink_print,     /* Print (tp_print) */
-                (getattrfunc) swig_varlink_getattr, /* get attr (tp_getattr) */
-                (setattrfunc) swig_varlink_setattr, /* Set attr (tp_setattr) */
-                0,                                  /* tp_compare */
-                (reprfunc) swig_varlink_repr,       /* tp_repr */
-                0,                                  /* tp_as_number */
-                0,                                  /* tp_as_sequence */
-                0,                                  /* tp_as_mapping */
-                0,                                  /* tp_hash */
-                0,                                  /* tp_call */
-                0,                                  /* tp_str */
-                0,                                  /* tp_getattro */
-                0,                                  /* tp_setattro */
-                0,                                  /* tp_as_buffer */
-                0,                                  /* tp_flags */
-                varlink__doc__,                     /* tp_doc */
+		            ;
+		static int type_init = 0;
+		if (!type_init) {
+			PyTypeObject tmp
+#endif
+				= {
+				PyObject_HEAD_INIT(&PyType_Type)
+					0,			/* Number of items in variable part (ob_size) */
+				(char *) "swigvarlink",	/* Type name (tp_name) */
+				sizeof(swig_varlinkobject),	/* Basic size (tp_basicsize) */
+				0,				/* Itemsize (tp_itemsize) */
+				0,				/* Deallocator (tp_dealloc) */
+				(printfunc) swig_varlink_print,	/* Print (tp_print) */
+				(getattrfunc) swig_varlink_getattr,	/* get attr (tp_getattr) */
+				(setattrfunc) swig_varlink_setattr,	/* Set attr (tp_setattr) */
+				0,				/* tp_compare */
+				(reprfunc) swig_varlink_repr,	/* tp_repr */
+				0,				/* tp_as_number */
+				0,				/* tp_as_sequence */
+				0,				/* tp_as_mapping */
+				0,				/* tp_hash */
+				0,				/* tp_call */
+				0,				/* tp_str */
+				0,				/* tp_getattro */
+				0,				/* tp_setattro */
+				0,				/* tp_as_buffer */
+				0,				/* tp_flags */
+				varlink__doc__,	/* tp_doc */
 #if PY_VERSION_HEX >= 0x02000000
-                0,                                  /* tp_traverse */
-                0,                                  /* tp_clear */
+				0,				/* tp_traverse */
+				0,				/* tp_clear */
 #endif
 #if PY_VERSION_HEX >= 0x02010000
-                0,                                  /* tp_richcompare */
-                0,                                  /* tp_weaklistoffset */
+				0,				/* tp_richcompare */
+				0,				/* tp_weaklistoffset */
 #endif
 #if PY_VERSION_HEX >= 0x02020000
-                0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* tp_iter -> tp_weaklist */
+				0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,	/* tp_iter -> tp_weaklist */
 #endif
 #if PY_VERSION_HEX >= 0x02030000
-                0,                                  /* tp_del */
+				0,				/* tp_del */
 #endif
 #ifdef COUNT_ALLOCS
-                0,0,0,0                             /* tp_alloc -> tp_next */
+				0, 0, 0, 0		/* tp_alloc -> tp_next */
 #endif
-            };
+			};
 #if !defined(__cplusplus)
-            varlink_type = tmp;
-            type_init = 1;
-        }
-#endif
-        return &varlink_type;
-    }
-    
-    /* Create a variable linking object for use later */
-    SWIGINTERN PyObject *
-    SWIG_Python_newvarlink(void) {
-        swig_varlinkobject *result = PyObject_NEW(swig_varlinkobject, swig_varlink_type());
-        if (result) {
-            result->vars = 0;
-        }
-        return ((PyObject*) result);
-    }
-    
-    SWIGINTERN void 
-    SWIG_Python_addvarlink(PyObject *p, char *name, PyObject *(*get_attr)(void), int (*set_attr)(PyObject *p)) {
-        swig_varlinkobject *v = (swig_varlinkobject *) p;
-        swig_globalvar *gv = (swig_globalvar *) malloc(sizeof(swig_globalvar));
-        if (gv) {
-            size_t size = strlen(name)+1;
-            gv->name = (char *)malloc(size);
-            if (gv->name) {
-                strncpy(gv->name,name,size);
-                gv->get_attr = get_attr;
-                gv->set_attr = set_attr;
-                gv->next = v->vars;
-            }
-        }
-        v->vars = gv;
-    }
-    
-    /* -----------------------------------------------------------------------------
-     * constants/methods manipulation
-     * ----------------------------------------------------------------------------- */
-    
-    /* Install Constants */
-    SWIGINTERN void
-    SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]) {
-        PyObject *obj = 0;
-        size_t i;
-        for (i = 0; constants[i].type; ++i) {
-            switch(constants[i].type) {
-                case SWIG_PY_INT:
-                obj = PyInt_FromLong(constants[i].lvalue);
-                break;
-                case SWIG_PY_FLOAT:
-                obj = PyFloat_FromDouble(constants[i].dvalue);
-                break;
-                case SWIG_PY_STRING:
-                if (constants[i].pvalue) {
-                    obj = PyString_FromString((char *) constants[i].pvalue);
-                } else {
-                    Py_INCREF(Py_None);
-                    obj = Py_None;
-                }
-                break;
-                case SWIG_PY_POINTER:
-                obj = SWIG_NewPointerObj(constants[i].pvalue, *(constants[i]).ptype,0);
-                break;
-                case SWIG_PY_BINARY:
-                obj = SWIG_NewPackedObj(constants[i].pvalue, constants[i].lvalue, *(constants[i].ptype));
-                break;
-                default:
-                obj = 0;
-                break;
-            }
-            if (obj) {
-                PyDict_SetItemString(d,constants[i].name,obj);
-                Py_DECREF(obj);
-            }
-        }
-    }
-    
-    /* -----------------------------------------------------------------------------*/
-    /* Fix SwigMethods to carry the callback ptrs when needed */
-    /* -----------------------------------------------------------------------------*/
-    
-    SWIGINTERN void
-    SWIG_Python_FixMethods(PyMethodDef *methods,
-    swig_const_info *const_table,
-    swig_type_info **types,
-    swig_type_info **types_initial) {
-        size_t i;
-        for (i = 0; methods[i].ml_name; ++i) {
-            char *c = methods[i].ml_doc;
-            if (c && (c = strstr(c, "swig_ptr: "))) {
-                int j;
-                swig_const_info *ci = 0;
-                char *name = c + 10;
-                for (j = 0; const_table[j].type; ++j) {
-                    if (strncmp(const_table[j].name, name, 
-                    strlen(const_table[j].name)) == 0) {
-                        ci = &(const_table[j]);
-                        break;
-                    }
-                }
-                if (ci) {
-                    size_t shift = (ci->ptype) - types;
-                    swig_type_info *ty = types_initial[shift];
-                    size_t ldoc = (c - methods[i].ml_doc);
-                    size_t lptr = strlen(ty->name)+2*sizeof(void*)+2;
-                    char *ndoc = (char*)malloc(ldoc + lptr + 10);
-                    if (ndoc) {
-                        char *buff = ndoc;
-                        void *ptr = (ci->type == SWIG_PY_POINTER) ? ci->pvalue : 0;
-                        if (ptr) {
-                            strncpy(buff, methods[i].ml_doc, ldoc);
-                            buff += ldoc;
-                            strncpy(buff, "swig_ptr: ", 10);
-                            buff += 10;
-                            SWIG_PackVoidPtr(buff, ptr, ty->name, lptr);
-                            methods[i].ml_doc = ndoc;
-                        }
-                    }
-                }
-            }
-        }
-    }
-    
-    /* -----------------------------------------------------------------------------*
-     *  Initialize type list
-     * -----------------------------------------------------------------------------*/
-    
+			varlink_type = tmp;
+			type_init = 1;
+		}
+#endif
+		return &varlink_type;
+	}
+
+	/* Create a variable linking object for use later */
+	SWIGINTERN PyObject *SWIG_Python_newvarlink(void) {
+		swig_varlinkobject *result = PyObject_NEW(swig_varlinkobject, swig_varlink_type());
+		if (result) {
+			result->vars = 0;
+		}
+		return ((PyObject *) result);
+	}
+
+	SWIGINTERN void SWIG_Python_addvarlink(PyObject * p, char *name, PyObject * (*get_attr) (void), int (*set_attr) (PyObject * p)) {
+		swig_varlinkobject *v = (swig_varlinkobject *) p;
+		swig_globalvar *gv = (swig_globalvar *) malloc(sizeof(swig_globalvar));
+		if (gv) {
+			size_t size = strlen(name) + 1;
+			gv->name = (char *) malloc(size);
+			if (gv->name) {
+				strncpy(gv->name, name, size);
+				gv->get_attr = get_attr;
+				gv->set_attr = set_attr;
+				gv->next = v->vars;
+			}
+		}
+		v->vars = gv;
+	}
+
+	/* -----------------------------------------------------------------------------
+	 * constants/methods manipulation
+	 * ----------------------------------------------------------------------------- */
+
+	/* Install Constants */
+	SWIGINTERN void SWIG_Python_InstallConstants(PyObject * d, swig_const_info constants[]) {
+		PyObject *obj = 0;
+		size_t i;
+		for (i = 0; constants[i].type; ++i) {
+			switch (constants[i].type) {
+			case SWIG_PY_INT:
+				obj = PyInt_FromLong(constants[i].lvalue);
+				break;
+			case SWIG_PY_FLOAT:
+				obj = PyFloat_FromDouble(constants[i].dvalue);
+				break;
+			case SWIG_PY_STRING:
+				if (constants[i].pvalue) {
+					obj = PyString_FromString((char *) constants[i].pvalue);
+				} else {
+					Py_INCREF(Py_None);
+					obj = Py_None;
+				}
+				break;
+			case SWIG_PY_POINTER:
+				obj = SWIG_NewPointerObj(constants[i].pvalue, *(constants[i]).ptype, 0);
+				break;
+			case SWIG_PY_BINARY:
+				obj = SWIG_NewPackedObj(constants[i].pvalue, constants[i].lvalue, *(constants[i].ptype));
+				break;
+			default:
+				obj = 0;
+				break;
+			}
+			if (obj) {
+				PyDict_SetItemString(d, constants[i].name, obj);
+				Py_DECREF(obj);
+			}
+		}
+	}
+
+	/* ----------------------------------------------------------------------------- */
+	/* Fix SwigMethods to carry the callback ptrs when needed */
+	/* ----------------------------------------------------------------------------- */
+
+	SWIGINTERN void SWIG_Python_FixMethods(PyMethodDef * methods, swig_const_info * const_table, swig_type_info ** types, swig_type_info ** types_initial) {
+		size_t i;
+		for (i = 0; methods[i].ml_name; ++i) {
+			char *c = methods[i].ml_doc;
+			if (c && (c = strstr(c, "swig_ptr: "))) {
+				int j;
+				swig_const_info *ci = 0;
+				char *name = c + 10;
+				for (j = 0; const_table[j].type; ++j) {
+					if (strncmp(const_table[j].name, name, strlen(const_table[j].name)) == 0) {
+						ci = &(const_table[j]);
+						break;
+					}
+				}
+				if (ci) {
+					size_t shift = (ci->ptype) - types;
+					swig_type_info *ty = types_initial[shift];
+					size_t ldoc = (c - methods[i].ml_doc);
+					size_t lptr = strlen(ty->name) + 2 * sizeof(void *) + 2;
+					char *ndoc = (char *) malloc(ldoc + lptr + 10);
+					if (ndoc) {
+						char *buff = ndoc;
+						void *ptr = (ci->type == SWIG_PY_POINTER) ? ci->pvalue : 0;
+						if (ptr) {
+							strncpy(buff, methods[i].ml_doc, ldoc);
+							buff += ldoc;
+							strncpy(buff, "swig_ptr: ", 10);
+							buff += 10;
+							SWIG_PackVoidPtr(buff, ptr, ty->name, lptr);
+							methods[i].ml_doc = ndoc;
+						}
+					}
+				}
+			}
+		}
+	}
+
+	/* -----------------------------------------------------------------------------*
+	 *  Initialize type list
+	 * -----------------------------------------------------------------------------*/
+
 #ifdef __cplusplus
 }
 #endif
@@ -2885,49 +2901,50 @@
 #ifdef __cplusplus
 extern "C"
 #endif
-SWIGEXPORT void SWIG_init(void) {
-    static PyObject *SWIG_globals = 0; 
-    PyObject *m, *d;
-    if (!SWIG_globals) SWIG_globals = SWIG_newvarlink();
-    
-    /* Fix SwigMethods to carry the callback ptrs when needed */
-    SWIG_Python_FixMethods(SwigMethods, swig_const_table, swig_types, swig_type_initial);
-    
-    m = Py_InitModule((char *) SWIG_name, SwigMethods);
-    d = PyModule_GetDict(m);
-    
-    SWIG_InitializeModule(0);
-    SWIG_InstallConstants(d,swig_const_table);
-    
-    {
-        PyDict_SetItemString(d,"CS_NEW", SWIG_From_int((int)(CS_NEW))); 
-    }
-    {
-        PyDict_SetItemString(d,"CS_INIT", SWIG_From_int((int)(CS_INIT))); 
-    }
-    {
-        PyDict_SetItemString(d,"CS_RING", SWIG_From_int((int)(CS_RING))); 
-    }
-    {
-        PyDict_SetItemString(d,"CS_TRANSMIT", SWIG_From_int((int)(CS_TRANSMIT))); 
-    }
-    {
-        PyDict_SetItemString(d,"CS_EXECUTE", SWIG_From_int((int)(CS_EXECUTE))); 
-    }
-    {
-        PyDict_SetItemString(d,"CS_LOOPBACK", SWIG_From_int((int)(CS_LOOPBACK))); 
-    }
-    {
-        PyDict_SetItemString(d,"CS_HOLD", SWIG_From_int((int)(CS_HOLD))); 
-    }
-    {
-        PyDict_SetItemString(d,"CS_HIBERNATE", SWIG_From_int((int)(CS_HIBERNATE))); 
-    }
-    {
-        PyDict_SetItemString(d,"CS_HANGUP", SWIG_From_int((int)(CS_HANGUP))); 
-    }
-    {
-        PyDict_SetItemString(d,"CS_DONE", SWIG_From_int((int)(CS_DONE))); 
-    }
-}
+       SWIGEXPORT void SWIG_init(void)
+{
+	static PyObject *SWIG_globals = 0;
+	PyObject *m, *d;
+	if (!SWIG_globals)
+		SWIG_globals = SWIG_newvarlink();
+
+	/* Fix SwigMethods to carry the callback ptrs when needed */
+	SWIG_Python_FixMethods(SwigMethods, swig_const_table, swig_types, swig_type_initial);
 
+	m = Py_InitModule((char *) SWIG_name, SwigMethods);
+	d = PyModule_GetDict(m);
+
+	SWIG_InitializeModule(0);
+	SWIG_InstallConstants(d, swig_const_table);
+
+	{
+		PyDict_SetItemString(d, "CS_NEW", SWIG_From_int((int) (CS_NEW)));
+	}
+	{
+		PyDict_SetItemString(d, "CS_INIT", SWIG_From_int((int) (CS_INIT)));
+	}
+	{
+		PyDict_SetItemString(d, "CS_RING", SWIG_From_int((int) (CS_RING)));
+	}
+	{
+		PyDict_SetItemString(d, "CS_TRANSMIT", SWIG_From_int((int) (CS_TRANSMIT)));
+	}
+	{
+		PyDict_SetItemString(d, "CS_EXECUTE", SWIG_From_int((int) (CS_EXECUTE)));
+	}
+	{
+		PyDict_SetItemString(d, "CS_LOOPBACK", SWIG_From_int((int) (CS_LOOPBACK)));
+	}
+	{
+		PyDict_SetItemString(d, "CS_HOLD", SWIG_From_int((int) (CS_HOLD)));
+	}
+	{
+		PyDict_SetItemString(d, "CS_HIBERNATE", SWIG_From_int((int) (CS_HIBERNATE)));
+	}
+	{
+		PyDict_SetItemString(d, "CS_HANGUP", SWIG_From_int((int) (CS_HANGUP)));
+	}
+	{
+		PyDict_SetItemString(d, "CS_DONE", SWIG_From_int((int) (CS_DONE)));
+	}
+}

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c	Fri Mar 30 12:19:18 2007
@@ -41,9 +41,9 @@
 static const char modname[] = "mod_spidermonkey";
 
 
-static void session_destroy(JSContext *cx, JSObject *obj);
-static JSBool session_construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
-static JSBool session_originate(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
+static void session_destroy(JSContext * cx, JSObject * obj);
+static JSBool session_construct(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval);
+static JSBool session_originate(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval);
 static switch_api_interface_t js_run_interface;
 
 static struct {
@@ -59,16 +59,16 @@
 
 
 static JSClass global_class = {
-	"Global", JSCLASS_HAS_PRIVATE, 
-	JS_PropertyStub,  JS_PropertyStub,	JS_PropertyStub,  JS_PropertyStub, 
-	JS_EnumerateStub, JS_ResolveStub,	JS_ConvertStub,	  JS_FinalizeStub
+	"Global", JSCLASS_HAS_PRIVATE,
+	JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
+	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub
 };
 
 
 static struct {
 	switch_hash_t *mod_hash;
 	switch_hash_t *load_hash;
-    switch_memory_pool_t *pool;
+	switch_memory_pool_t *pool;
 } module_manager;
 
 struct sm_loadable_module {
@@ -96,7 +96,7 @@
 	jsval ret;
 	JSContext *cx;
 	JSObject *obj;
-    jsrefcount saveDepth;
+	jsrefcount saveDepth;
 	void *extra;
 };
 
@@ -117,7 +117,7 @@
 
 /* Event Object */
 /*********************************************************************************/
-static JSBool event_construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool event_construct(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	if (argc > 0) {
 		switch_event_t *event;
@@ -128,26 +128,26 @@
 		if ((eo = malloc(sizeof(*eo)))) {
 
 			if (switch_name_event(ename, &etype) != SWITCH_STATUS_SUCCESS) {
-				*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+				*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 				return JS_TRUE;
 			}
 
 			if (etype == SWITCH_EVENT_CUSTOM) {
 				char *subclass_name;
 				if (argc < 1) {
-					*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+					*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 					return JS_TRUE;
 				}
-				
+
 				subclass_name = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
 				if (switch_event_create_subclass(&event, etype, subclass_name) != SWITCH_STATUS_SUCCESS) {
-					*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+					*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 					return JS_TRUE;
 				}
 
 			} else {
 				if (!switch_event_create(&event, etype) != SWITCH_STATUS_SUCCESS) {
-					*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+					*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 					return JS_TRUE;
 				}
 			}
@@ -163,7 +163,7 @@
 	return JS_FALSE;
 }
 
-static void event_destroy(JSContext *cx, JSObject *obj)
+static void event_destroy(JSContext * cx, JSObject * obj)
 {
 	struct event_obj *eo = JS_GetPrivate(cx, obj);
 
@@ -175,12 +175,12 @@
 	}
 }
 
-static JSBool event_add_header(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool event_add_header(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct event_obj *eo = JS_GetPrivate(cx, obj);
 
 	if (!eo || eo->freed) {
-		*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 		return JS_TRUE;
 	}
 
@@ -188,90 +188,90 @@
 		char *hname = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
 		char *hval = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
 		switch_event_add_header(eo->event, SWITCH_STACK_BOTTOM, hname, "%s", hval);
-		*rval = BOOLEAN_TO_JSVAL( JS_TRUE );
+		*rval = BOOLEAN_TO_JSVAL(JS_TRUE);
 		return JS_TRUE;
 	}
 
-	*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+	*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 	return JS_TRUE;
 }
 
-static JSBool event_get_header(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool event_get_header(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct event_obj *eo = JS_GetPrivate(cx, obj);
 
 	if (!eo) {
-		*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 		return JS_TRUE;
 	}
 
 	if (argc > 0) {
 		char *hname = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
 		char *val = switch_event_get_header(eo->event, hname);
-		*rval = STRING_TO_JSVAL (JS_NewStringCopyZ(cx, val));
+		*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, val));
 		return JS_TRUE;
 	}
 
-	*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+	*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 	return JS_TRUE;
 }
 
-static JSBool event_add_body(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool event_add_body(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct event_obj *eo = JS_GetPrivate(cx, obj);
 
 	if (!eo || eo->freed) {
-		*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 		return JS_TRUE;
 	}
 
 	if (argc > 0) {
 		char *body = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
 		switch_event_add_body(eo->event, "%s", body);
-		*rval = BOOLEAN_TO_JSVAL( JS_TRUE );
+		*rval = BOOLEAN_TO_JSVAL(JS_TRUE);
 		return JS_TRUE;
 	}
 
-	*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+	*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 	return JS_TRUE;
 }
 
-static JSBool event_get_body(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool event_get_body(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct event_obj *eo = JS_GetPrivate(cx, obj);
 
 	if (!eo) {
-		*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 		return JS_TRUE;
 	}
 
-	*rval = STRING_TO_JSVAL (JS_NewStringCopyZ(cx, switch_event_get_body(eo->event)));
+	*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, switch_event_get_body(eo->event)));
 
 	return JS_TRUE;
 }
 
-static JSBool event_get_type(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool event_get_type(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct event_obj *eo = JS_GetPrivate(cx, obj);
 
 	if (!eo) {
-		*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 		return JS_TRUE;
 	}
 
-	*rval = STRING_TO_JSVAL (JS_NewStringCopyZ(cx, switch_event_name(eo->event->event_id)));
-	
+	*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, switch_event_name(eo->event->event_id)));
+
 	return JS_TRUE;
 }
 
-static JSBool event_serialize(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool event_serialize(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct event_obj *eo = JS_GetPrivate(cx, obj);
 	char *buf;
 	uint8_t isxml = 0;
 
 	if (!eo) {
-		*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 		return JS_TRUE;
 	}
 
@@ -285,17 +285,17 @@
 	if (isxml) {
 		switch_xml_t xml;
 		char *xmlstr;
-		if ((xml = switch_event_xmlize(eo->event, NULL))) {
-            xmlstr = switch_xml_toxml(xml);
-			*rval = STRING_TO_JSVAL (JS_NewStringCopyZ(cx, xmlstr));
+		if ((xml = switch_event_xmlize(eo->event, SWITCH_VA_NONE))) {
+			xmlstr = switch_xml_toxml(xml);
+			*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, xmlstr));
 			switch_xml_free(xml);
-            free(xmlstr);
+			free(xmlstr);
 		} else {
-			*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+			*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 		}
 	} else {
 		if (switch_event_serialize(eo->event, &buf) == SWITCH_STATUS_SUCCESS) {
-			*rval = STRING_TO_JSVAL (JS_NewStringCopyZ(cx, buf));
+			*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, buf));
 			switch_safe_free(buf);
 		}
 	}
@@ -303,7 +303,7 @@
 	return JS_TRUE;
 }
 
-static JSBool event_fire(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool event_fire(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct event_obj *eo = JS_GetPrivate(cx, obj);
 
@@ -311,29 +311,29 @@
 		switch_event_fire(&eo->event);
 		JS_SetPrivate(cx, obj, NULL);
 		switch_safe_free(eo);
-		*rval = BOOLEAN_TO_JSVAL( JS_TRUE );
+		*rval = BOOLEAN_TO_JSVAL(JS_TRUE);
 		return JS_TRUE;
 	}
 
-	*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+	*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 	return JS_TRUE;
 }
 
-static JSBool event_destroy_(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool event_destroy_(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct event_obj *eo = JS_GetPrivate(cx, obj);
-	
+
 	if (eo) {
 		if (!eo->freed) {
 			switch_event_destroy(&eo->event);
 		}
 		JS_SetPrivate(cx, obj, NULL);
 		switch_safe_free(eo);
-		*rval = BOOLEAN_TO_JSVAL( JS_TRUE );
+		*rval = BOOLEAN_TO_JSVAL(JS_TRUE);
 		return JS_TRUE;
 	}
 
-	*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+	*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 	return JS_TRUE;
 }
 
@@ -357,35 +357,35 @@
 
 
 static JSPropertySpec event_props[] = {
-	{"ready", EVENT_READY, JSPROP_READONLY|JSPROP_PERMANENT}, 
+	{"ready", EVENT_READY, JSPROP_READONLY | JSPROP_PERMANENT},
 	{0}
 };
 
 
-static JSBool event_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
+static JSBool event_getProperty(JSContext * cx, JSObject * obj, jsval id, jsval * vp)
 {
 	JSBool res = JS_TRUE;
 	switch_event_t *event = JS_GetPrivate(cx, obj);
 	char *name;
 	int param = 0;
 
-    if (!event) {
-        *vp = BOOLEAN_TO_JSVAL( JS_FALSE );
+	if (!event) {
+		*vp = BOOLEAN_TO_JSVAL(JS_FALSE);
 		return JS_TRUE;
-    }
+	}
+
 
-	
 	name = JS_GetStringBytes(JS_ValueToString(cx, id));
-    /* numbers are our props anything else is a method */
-    if (name[0] >= 48 && name[0] <= 57) {
-        param = atoi(name);
-    } else {
-        return JS_TRUE;
-    }
-	
-	switch(param) {
+	/* numbers are our props anything else is a method */
+	if (name[0] >= 48 && name[0] <= 57) {
+		param = atoi(name);
+	} else {
+		return JS_TRUE;
+	}
+
+	switch (param) {
 	case EVENT_READY:
-		*vp = BOOLEAN_TO_JSVAL( JS_TRUE );
+		*vp = BOOLEAN_TO_JSVAL(JS_TRUE);
 		break;
 	}
 
@@ -393,46 +393,38 @@
 }
 
 JSClass event_class = {
-	"Event", JSCLASS_HAS_PRIVATE, 
-	JS_PropertyStub,  JS_PropertyStub,	event_getProperty,  JS_PropertyStub, 
-	JS_EnumerateStub, JS_ResolveStub,	JS_ConvertStub,	  event_destroy, NULL, NULL, NULL,
+	"Event", JSCLASS_HAS_PRIVATE,
+	JS_PropertyStub, JS_PropertyStub, event_getProperty, JS_PropertyStub,
+	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, event_destroy, NULL, NULL, NULL,
 	event_construct
 };
 
 
 
 
-static void js_error(JSContext *cx, const char *message, JSErrorReport *report)
+static void js_error(JSContext * cx, const char *message, JSErrorReport * report)
 {
-    const char *filename = __FILE__;
-    int line = __LINE__;
-    const char *text = "";
-    char *ex = "";
-    
+	const char *filename = __FILE__;
+	int line = __LINE__;
+	const char *text = "";
+	char *ex = "";
+
 	if (message && report) {
-        if (report->filename) {
-            filename = report->filename;
-        }
-        line = report->lineno;
-        if (report->linebuf) {
-            text = report->linebuf;
-            ex = "near ";
-        }
-	}
-    
-    if (!message) {
-        message = "(N/A)";
-    }
-    
-    switch_log_printf(SWITCH_CHANNEL_ID_LOG, 
-                      filename,
-                      modname,
-                      line,
-                      SWITCH_LOG_ERROR,
-                      "%s %s%s\n",
-                      ex,
-                      message,
-                      text);
+		if (report->filename) {
+			filename = report->filename;
+		}
+		line = report->lineno;
+		if (report->linebuf) {
+			text = report->linebuf;
+			ex = "near ";
+		}
+	}
+
+	if (!message) {
+		message = "(N/A)";
+	}
+
+	switch_log_printf(SWITCH_CHANNEL_ID_LOG, filename, modname, line, SWITCH_LOG_ERROR, "%s %s%s\n", ex, message, text);
 
 }
 
@@ -462,13 +454,13 @@
 		}
 
 		status = switch_dso_sym(&function_handle, dso, "spidermonkey_init");
-		spidermonkey_init = (spidermonkey_init_t)(intptr_t) function_handle;
-			
+		spidermonkey_init = (spidermonkey_init_t) (intptr_t) function_handle;
+
 		if (spidermonkey_init == NULL) {
 			err = "Cannot Load";
 			break;
 		}
-		
+
 		if (spidermonkey_init(&module_interface) != SWITCH_STATUS_SUCCESS) {
 			err = "Module load routine returned an error";
 			break;
@@ -490,17 +482,17 @@
 	module->filename = switch_core_permanent_strdup(filename);
 	module->spidermonkey_init = spidermonkey_init;
 	module->module_interface = module_interface;
-	
+
 	module->lib = dso;
 
 	switch_core_hash_insert(module_manager.mod_hash, (char *) module->filename, (void *) module);
-	
+
 	for (mp = module->module_interface; mp; mp = mp->next) {
-		switch_core_hash_insert(module_manager.load_hash, (char *)mp->name, (void *) mp);
+		switch_core_hash_insert(module_manager.load_hash, (char *) mp->name, (void *) mp);
 	}
-	
+
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Successfully Loaded [%s]\n", module->filename);
-	
+
 	return SWITCH_STATUS_SUCCESS;
 
 }
@@ -541,7 +533,7 @@
 			snprintf(path, len, "%s%s%s%s", dir, SWITCH_PATH_SEPARATOR, file, ext);
 		}
 	}
-	
+
 	return sm_load_file(path);
 }
 
@@ -583,7 +575,7 @@
 			}
 		}
 		switch_xml_free(xml);
-		
+
 	} else {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "open of %s failed\n", cf);
 	}
@@ -598,14 +590,14 @@
 	globals.gErrFile = NULL;
 	globals.gOutFile = NULL;
 	globals.gStackChunkSize = 8192;
-	globals.gStackBase = (jsuword)&globals.stackDummy;
+	globals.gStackBase = (jsuword) & globals.stackDummy;
 	globals.gErrFile = stderr;
 	globals.gOutFile = stdout;
 
 	if (!(globals.rt = JS_NewRuntime(64L * 1024L * 1024L))) {
 		return SWITCH_STATUS_FALSE;
 	}
-	
+
 	if (load_modules() != SWITCH_STATUS_SUCCESS) {
 		return SWITCH_STATUS_FALSE;
 	}
@@ -613,7 +605,7 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-JSObject *new_js_event(switch_event_t *event, char *name, JSContext *cx, JSObject *obj)
+JSObject *new_js_event(switch_event_t *event, char *name, JSContext * cx, JSObject * obj)
 {
 	struct event_obj *eo;
 	JSObject *Event = NULL;
@@ -622,9 +614,7 @@
 		eo->event = event;
 		eo->freed = 1;
 		if ((Event = JS_DefineObject(cx, obj, name, &event_class, NULL, 0))) {
-			if ((JS_SetPrivate(cx, Event, eo) &&
-				 JS_DefineProperties(cx, Event, event_props) &&
-				 JS_DefineFunctions(cx, Event, event_methods))) {
+			if ((JS_SetPrivate(cx, Event, eo) && JS_DefineProperties(cx, Event, event_props) && JS_DefineFunctions(cx, Event, event_methods))) {
 			}
 		}
 	}
@@ -651,7 +641,7 @@
 	case SWITCH_INPUT_TYPE_EVENT:
 		if ((event = (switch_event_t *) input)) {
 			if ((Event = new_js_event(event, "_XX_EVENT_XX_", cb_state->cx, cb_state->obj))) {
-				argv[argc++] = STRING_TO_JSVAL (JS_NewStringCopyZ(cb_state->cx, "event"));
+				argv[argc++] = STRING_TO_JSVAL(JS_NewStringCopyZ(cb_state->cx, "event"));
 				argv[argc++] = OBJECT_TO_JSVAL(Event);
 			}
 		}
@@ -659,10 +649,10 @@
 			return SWITCH_STATUS_FALSE;
 		}
 		break;
-	case SWITCH_INPUT_TYPE_DTMF: 
+	case SWITCH_INPUT_TYPE_DTMF:
 		dtmf = (char *) input;
-		argv[argc++] = STRING_TO_JSVAL (JS_NewStringCopyZ(cb_state->cx, "dtmf"));
-		argv[argc++] = STRING_TO_JSVAL (JS_NewStringCopyZ(cb_state->cx, dtmf));
+		argv[argc++] = STRING_TO_JSVAL(JS_NewStringCopyZ(cb_state->cx, "dtmf"));
+		argv[argc++] = STRING_TO_JSVAL(JS_NewStringCopyZ(cb_state->cx, dtmf));
 		break;
 	}
 
@@ -670,9 +660,9 @@
 		argv[argc++] = cb_state->arg;
 	}
 
-    JS_ResumeRequest(cb_state->cx, cb_state->saveDepth);
+	JS_ResumeRequest(cb_state->cx, cb_state->saveDepth);
 	JS_CallFunction(cb_state->cx, cb_state->obj, cb_state->function, argc, argv, &cb_state->ret);
-    cb_state->saveDepth = JS_SuspendRequest(cb_state->cx);
+	cb_state->saveDepth = JS_SuspendRequest(cb_state->cx);
 
 	return SWITCH_STATUS_SUCCESS;
 }
@@ -693,7 +683,7 @@
 	if ((ret = JS_GetStringBytes(JS_ValueToString(cb_state->cx, cb_state->ret)))) {
 		if (!strncasecmp(ret, "speed", 4)) {
 			char *p;
-			
+
 			if ((p = strchr(ret, ':'))) {
 				p++;
 				if (*p == '+' || *p == '-') {
@@ -708,7 +698,7 @@
 				}
 				return SWITCH_STATUS_SUCCESS;
 			}
-			
+
 			return SWITCH_STATUS_FALSE;
 		} else if (!strcasecmp(ret, "pause")) {
 			if (switch_test_flag(fh, SWITCH_FILE_PAUSE)) {
@@ -738,7 +728,7 @@
 					}
 					if (step > 0) {
 						samps = step * (codec->implementation->samples_per_second / 1000);
-						switch_core_file_seek(fh, &pos, samps, SEEK_CUR);		
+						switch_core_file_seek(fh, &pos, samps, SEEK_CUR);
 					} else {
 						samps = step * (codec->implementation->samples_per_second / 1000);
 						switch_core_file_seek(fh, &pos, fh->pos - samps, SEEK_SET);
@@ -753,8 +743,8 @@
 		}
 
 		if (!strcmp(ret, "true") || !strcmp(ret, "undefined")) {
-            return SWITCH_STATUS_SUCCESS;
-        }
+			return SWITCH_STATUS_SUCCESS;
+		}
 
 		return SWITCH_STATUS_BREAK;
 
@@ -772,7 +762,7 @@
 	if ((status = js_common_callback(session, input, itype, buf, buflen)) != SWITCH_STATUS_SUCCESS) {
 		return status;
 	}
-	
+
 	if ((ret = JS_GetStringBytes(JS_ValueToString(cb_state->cx, cb_state->ret)))) {
 		if (!strcasecmp(ret, "pause")) {
 			if (switch_test_flag(fh, SWITCH_FILE_PAUSE)) {
@@ -789,8 +779,8 @@
 		}
 
 		if (!strcmp(ret, "true") || !strcmp(ret, "undefined")) {
-            return SWITCH_STATUS_SUCCESS;
-        }
+			return SWITCH_STATUS_SUCCESS;
+		}
 
 		return SWITCH_STATUS_BREAK;
 
@@ -818,7 +808,7 @@
 	return SWITCH_STATUS_BREAK;
 }
 
-static JSBool session_flush_digits(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool session_flush_digits(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct js_session *jss = JS_GetPrivate(cx, obj);
 	char buf[256];
@@ -827,46 +817,46 @@
 
 	if (!jss || !jss->session) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "You must call the session.originate method before calling this method!\n");
-		*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 		return JS_TRUE;
 	}
 
 	channel = switch_core_session_get_channel(jss->session);
-    assert(channel != NULL);
+	assert(channel != NULL);
 
 	while ((has = switch_channel_has_dtmf(channel))) {
 		switch_channel_dequeue_dtmf(channel, buf, sizeof(buf));
 	}
 
-	*rval = BOOLEAN_TO_JSVAL( JS_TRUE );
-    return JS_TRUE;
+	*rval = BOOLEAN_TO_JSVAL(JS_TRUE);
+	return JS_TRUE;
 }
 
-static JSBool session_flush_events(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool session_flush_events(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct js_session *jss = JS_GetPrivate(cx, obj);
 	switch_event_t *event;
-    switch_channel_t *channel;
+	switch_channel_t *channel;
 
 	if (!jss || !jss->session) {
-		*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 		return JS_TRUE;
 	}
 
-    channel = switch_core_session_get_channel(jss->session);
-    assert(channel != NULL);
+	channel = switch_core_session_get_channel(jss->session);
+	assert(channel != NULL);
 
 
 	while (switch_core_session_dequeue_event(jss->session, &event) == SWITCH_STATUS_SUCCESS) {
 		switch_event_destroy(&event);
 	}
-	
-	*rval = BOOLEAN_TO_JSVAL( JS_TRUE );
-    return JS_TRUE;
-	
+
+	*rval = BOOLEAN_TO_JSVAL(JS_TRUE);
+	return JS_TRUE;
+
 }
 
-static JSBool session_recordfile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool session_recordfile(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct js_session *jss = JS_GetPrivate(cx, obj);
 	switch_channel_t *channel;
@@ -874,28 +864,28 @@
 	void *bp = NULL;
 	int len = 0;
 	switch_input_callback_function_t dtmf_func = NULL;
-	struct input_callback_state cb_state = {0};
-	switch_file_handle_t fh = {0};
+	struct input_callback_state cb_state = { 0 };
+	switch_file_handle_t fh = { 0 };
 	JSFunction *function;
-    int32 limit = 0;
-    switch_input_args_t args = {0};
+	int32 limit = 0;
+	switch_input_args_t args = { 0 };
 
 	if (!jss || !jss->session) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "You must call the session.originate method before calling this method!\n");
-		*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 		return JS_TRUE;
 	}
 
 	channel = switch_core_session_get_channel(jss->session);
 	assert(channel != NULL);
 
-    if (!switch_channel_ready(channel)) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session is not active!\n");
-        *rval = BOOLEAN_TO_JSVAL( JS_FALSE );
-        return JS_TRUE;
-    }
+	if (!switch_channel_ready(channel)) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session is not active!\n");
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
+		return JS_TRUE;
+	}
+
 
-	
 	if (argc > 0) {
 		file_name = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
 		if (switch_strlen_zero(file_name)) {
@@ -908,49 +898,49 @@
 			cb_state.session_state = jss;
 			cb_state.function = function;
 			cb_state.cx = cx;
-            cb_state.obj = obj;
+			cb_state.obj = obj;
 			if (argc > 2) {
-                cb_state.arg = argv[2];
-            }
+				cb_state.arg = argv[2];
+			}
 
 			dtmf_func = js_record_input_callback;
 			bp = &cb_state;
 			len = sizeof(cb_state);
 		}
 
-        if (argc > 3) {
-            JS_ValueToInt32(cx, argv[3], &limit);
-        }
-
-        if (argc > 4) {
-            int32 thresh;
-            JS_ValueToInt32(cx, argv[4], &thresh);
-            fh.thresh = thresh;
-        }
-
-        if (argc > 5) {
-            int32 silence_hits;
-            JS_ValueToInt32(cx, argv[5], &silence_hits);
-            fh.silence_hits = silence_hits;
-        }
+		if (argc > 3) {
+			JS_ValueToInt32(cx, argv[3], &limit);
+		}
+
+		if (argc > 4) {
+			int32 thresh;
+			JS_ValueToInt32(cx, argv[4], &thresh);
+			fh.thresh = thresh;
+		}
+
+		if (argc > 5) {
+			int32 silence_hits;
+			JS_ValueToInt32(cx, argv[5], &silence_hits);
+			fh.silence_hits = silence_hits;
+		}
 	}
 
-    
+
 	cb_state.extra = &fh;
-	cb_state.ret = BOOLEAN_TO_JSVAL( JS_FALSE );
-    cb_state.saveDepth = JS_SuspendRequest(cx);
-    args.input_callback = dtmf_func;
-    args.buf = bp;
-    args.buflen = len;
+	cb_state.ret = BOOLEAN_TO_JSVAL(JS_FALSE);
+	cb_state.saveDepth = JS_SuspendRequest(cx);
+	args.input_callback = dtmf_func;
+	args.buf = bp;
+	args.buflen = len;
 	switch_ivr_record_file(jss->session, &fh, file_name, &args, limit);
-    JS_ResumeRequest(cx, cb_state.saveDepth);
+	JS_ResumeRequest(cx, cb_state.saveDepth);
 	*rval = cb_state.ret;
 
 	return JS_TRUE;
 }
 
 
-static JSBool session_collect_input(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool session_collect_input(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct js_session *jss = JS_GetPrivate(cx, obj);
 	switch_channel_t *channel;
@@ -958,39 +948,39 @@
 	int len = 0;
 	int32 to = 0;
 	switch_input_callback_function_t dtmf_func = NULL;
-	struct input_callback_state cb_state = {0};
+	struct input_callback_state cb_state = { 0 };
 	JSFunction *function;
-    switch_input_args_t args = {0};
+	switch_input_args_t args = { 0 };
 
 
 	if (!jss || !jss->session) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "You must call the session.originate method before calling this method!\n");
-		*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 		return JS_TRUE;
 	}
 
 	channel = switch_core_session_get_channel(jss->session);
 	assert(channel != NULL);
 
-    if (!switch_channel_ready(channel)) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session is not active!\n");
-        *rval = BOOLEAN_TO_JSVAL( JS_FALSE );
-        return JS_TRUE;
-    }
+	if (!switch_channel_ready(channel)) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session is not active!\n");
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
+		return JS_TRUE;
+	}
+
 
-	
 	if (argc > 0) {
 		if ((function = JS_ValueToFunction(cx, argv[0]))) {
 			memset(&cb_state, 0, sizeof(cb_state));
 			cb_state.function = function;
 
 			if (argc > 1) {
-                cb_state.arg = argv[1];
-            }
-			
+				cb_state.arg = argv[1];
+			}
+
 			cb_state.session_state = jss;
 			cb_state.cx = cx;
-            cb_state.obj = obj;
+			cb_state.obj = obj;
 			dtmf_func = js_collect_input_callback;
 			bp = &cb_state;
 			len = sizeof(cb_state);
@@ -1001,12 +991,12 @@
 		JS_ValueToInt32(jss->cx, argv[2], &to);
 	}
 
-    cb_state.saveDepth = JS_SuspendRequest(cx);
-    args.input_callback = dtmf_func;
-    args.buf = bp;
-    args.buflen = len;
+	cb_state.saveDepth = JS_SuspendRequest(cx);
+	args.input_callback = dtmf_func;
+	args.buf = bp;
+	args.buflen = len;
 	switch_ivr_collect_digits_callback(jss->session, &args, to);
-    JS_ResumeRequest(cx, cb_state.saveDepth);
+	JS_ResumeRequest(cx, cb_state.saveDepth);
 
 	*rval = cb_state.ret;
 
@@ -1015,37 +1005,37 @@
 
 /* session.sayphrase(phrase_name, phrase_data, language, dtmf_callback, dtmf_callback_args)*/
 
-static JSBool session_sayphrase(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool session_sayphrase(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct js_session *jss = JS_GetPrivate(cx, obj);
 	switch_channel_t *channel;
 	char *phrase_name = NULL;
-    char *phrase_data = NULL;
-    char *phrase_lang = NULL;
+	char *phrase_data = NULL;
+	char *phrase_lang = NULL;
 	//char *input_callback = NULL;
 	void *bp = NULL;
 	int len = 0;
 	switch_input_callback_function_t dtmf_func = NULL;
-	struct input_callback_state cb_state = {0};
+	struct input_callback_state cb_state = { 0 };
 	JSFunction *function;
-    switch_input_args_t args = {0};
+	switch_input_args_t args = { 0 };
 
 	if (!jss || !jss->session) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "You must call the session.originate method before calling this method!\n");
-		*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 		return JS_TRUE;
 	}
 
 	channel = switch_core_session_get_channel(jss->session);
 	assert(channel != NULL);
 
-    if (!switch_channel_ready(channel)) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session is not active!\n");
-        *rval = BOOLEAN_TO_JSVAL( JS_FALSE );
-        return JS_TRUE;
-    }
+	if (!switch_channel_ready(channel)) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session is not active!\n");
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
+		return JS_TRUE;
+	}
+
 
-	
 	if (argc > 0) {
 		phrase_name = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
 		if (switch_strlen_zero(phrase_name)) {
@@ -1056,13 +1046,13 @@
 	}
 
 
-    if (argc > 1) {
-        phrase_data = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
-    }
-
-    if (argc > 2) {
-        phrase_lang = JS_GetStringBytes(JS_ValueToString(cx, argv[2]));
-    }
+	if (argc > 1) {
+		phrase_data = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
+	}
+
+	if (argc > 2) {
+		phrase_lang = JS_GetStringBytes(JS_ValueToString(cx, argv[2]));
+	}
 
 	if (argc > 3) {
 		if ((function = JS_ValueToFunction(cx, argv[3]))) {
@@ -1082,27 +1072,27 @@
 		}
 	}
 
-	cb_state.ret = BOOLEAN_TO_JSVAL( JS_FALSE );
-    cb_state.saveDepth = JS_SuspendRequest(cx);
-    args.input_callback = dtmf_func;
-    args.buf = bp;
-    args.buflen = len;
+	cb_state.ret = BOOLEAN_TO_JSVAL(JS_FALSE);
+	cb_state.saveDepth = JS_SuspendRequest(cx);
+	args.input_callback = dtmf_func;
+	args.buf = bp;
+	args.buflen = len;
 
-    switch_ivr_phrase_macro(jss->session, phrase_name, phrase_data, phrase_lang, &args);
+	switch_ivr_phrase_macro(jss->session, phrase_name, phrase_data, phrase_lang, &args);
 
-    JS_ResumeRequest(cx, cb_state.saveDepth);
+	JS_ResumeRequest(cx, cb_state.saveDepth);
 	*rval = cb_state.ret;
-	
+
 	return JS_TRUE;
 }
 
 static void check_hangup_hook(struct js_session *jss)
 {
-	jsval argv[2] = {0};
+	jsval argv[2] = { 0 };
 	int argc = 0;
 	jsval ret;
-	if (jss->on_hangup ) {
-		argv[argc++] = OBJECT_TO_JSVAL(jss->obj);			
+	if (jss->on_hangup) {
+		argv[argc++] = OBJECT_TO_JSVAL(jss->obj);
 		JS_CallFunction(jss->cx, jss->obj, jss->on_hangup, argc, argv, &ret);
 	}
 }
@@ -1114,7 +1104,8 @@
 
 	channel = switch_core_session_get_channel(session);
 	assert(channel != NULL);
-	if (switch_channel_get_state(channel) == CS_HANGUP) {
+
+	if (switch_channel_get_state(channel) != CS_EXECUTE) {
 		if ((jss = switch_channel_get_private(channel, "jss"))) {
 			check_hangup_hook(jss);
 		}
@@ -1123,11 +1114,11 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static JSBool session_hanguphook(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool session_hanguphook(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	JSFunction *function;
 	struct js_session *jss;
-	*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+	*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 
 	if ((jss = JS_GetPrivate(cx, obj)) && jss->session) {
 		if (argc > 0) {
@@ -1136,8 +1127,8 @@
 				assert(channel != NULL);
 				jss->on_hangup = function;
 				switch_channel_set_private(channel, "jss", jss);
-				switch_core_session_add_event_hook_state_change(jss->session, hanguphook);
-				*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+				switch_core_event_hook_add_state_change(jss->session, hanguphook);
+				*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 			}
 		}
 	}
@@ -1145,7 +1136,7 @@
 	return JS_TRUE;
 }
 
-static JSBool session_streamfile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool session_streamfile(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct js_session *jss = JS_GetPrivate(cx, obj);
 	switch_channel_t *channel;
@@ -1154,27 +1145,27 @@
 	void *bp = NULL;
 	int len = 0;
 	switch_input_callback_function_t dtmf_func = NULL;
-	struct input_callback_state cb_state = {0};
-	switch_file_handle_t fh = {0};
+	struct input_callback_state cb_state = { 0 };
+	switch_file_handle_t fh = { 0 };
 	JSFunction *function;
-    switch_input_args_t args = {0};
+	switch_input_args_t args = { 0 };
 
 	if (!jss || !jss->session) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "You must call the session.originate method before calling this method!\n");
-		*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 		return JS_TRUE;
 	}
 
 	channel = switch_core_session_get_channel(jss->session);
 	assert(channel != NULL);
 
-    if (!switch_channel_ready(channel)) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session is not active!\n");
-        *rval = BOOLEAN_TO_JSVAL( JS_FALSE );
-        return JS_TRUE;
-    }
+	if (!switch_channel_ready(channel)) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session is not active!\n");
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
+		return JS_TRUE;
+	}
+
 
-	
 	if (argc > 0) {
 		file_name = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
 		if (switch_strlen_zero(file_name)) {
@@ -1200,38 +1191,38 @@
 		}
 	}
 
-    if (argc > 3) {
-        int32 samps;
-        JS_ValueToInt32(cx, argv[3], &samps);
-        fh.samples = samps;
-    }
+	if (argc > 3) {
+		int32 samps;
+		JS_ValueToInt32(cx, argv[3], &samps);
+		fh.samples = samps;
+	}
 
 	cb_state.extra = &fh;
-	cb_state.ret = BOOLEAN_TO_JSVAL( JS_FALSE );
-    cb_state.saveDepth = JS_SuspendRequest(cx);
-    args.input_callback = dtmf_func;
-    args.buf = bp;
-    args.buflen = len;
+	cb_state.ret = BOOLEAN_TO_JSVAL(JS_FALSE);
+	cb_state.saveDepth = JS_SuspendRequest(cx);
+	args.input_callback = dtmf_func;
+	args.buf = bp;
+	args.buflen = len;
 	switch_ivr_play_file(jss->session, &fh, file_name, &args);
-    JS_ResumeRequest(cx, cb_state.saveDepth);
+	JS_ResumeRequest(cx, cb_state.saveDepth);
 	*rval = cb_state.ret;
-	
+
 	return JS_TRUE;
 }
 
-static JSBool session_set_variable(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool session_set_variable(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct js_session *jss = JS_GetPrivate(cx, obj);
-    switch_channel_t *channel;
+	switch_channel_t *channel;
 
 	if (!jss || !jss->session) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "You must call the session.originate method before calling this method!\n");
-		*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 		return JS_TRUE;
 	}
 
 	channel = switch_core_session_get_channel(jss->session);
-    assert(channel != NULL);
+	assert(channel != NULL);
 
 	if (argc > 1) {
 		char *var, *val;
@@ -1239,47 +1230,47 @@
 		var = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
 		val = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
 		switch_channel_set_variable(channel, var, val);
-		*rval = BOOLEAN_TO_JSVAL( JS_TRUE );
+		*rval = BOOLEAN_TO_JSVAL(JS_TRUE);
 	} else {
-		*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 	}
- 	
+
 	return JS_TRUE;
 }
 
-static JSBool session_get_variable(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool session_get_variable(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct js_session *jss = JS_GetPrivate(cx, obj);
-    switch_channel_t *channel;
+	switch_channel_t *channel;
 
 	if (!jss || !jss->session) {
-		*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 		return JS_TRUE;
 	}
 
 	channel = switch_core_session_get_channel(jss->session);
-    assert(channel != NULL);
+	assert(channel != NULL);
 
 	if (argc > 0) {
 		char *var, *val;
-		
+
 		var = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
 		val = switch_channel_get_variable(channel, var);
 
 		if (val) {
-			*rval = STRING_TO_JSVAL (JS_NewStringCopyZ(cx, val));
+			*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, val));
 		} else {
-			*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+			*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 		}
 	} else {
-		*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 	}
- 	
+
 	return JS_TRUE;
 }
 
 
-static JSBool session_speak(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool session_speak(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct js_session *jss = JS_GetPrivate(cx, obj);
 	switch_channel_t *channel;
@@ -1289,32 +1280,32 @@
 	switch_codec_t *codec;
 	void *bp = NULL;
 	int len = 0;
-	struct input_callback_state cb_state = {0};
+	struct input_callback_state cb_state = { 0 };
 	switch_input_callback_function_t dtmf_func = NULL;
 	JSFunction *function;
-    switch_input_args_t args = {0};
+	switch_input_args_t args = { 0 };
 
 	if (!jss || !jss->session) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "You must call the session.originate method before calling this method!\n");
-		*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 		return JS_TRUE;
 	}
 
 	channel = switch_core_session_get_channel(jss->session);
 	assert(channel != NULL);
 
-    if (!switch_channel_ready(channel)) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session is not active!\n");
-        *rval = BOOLEAN_TO_JSVAL( JS_FALSE );
-        return JS_TRUE;
-    }
+	if (!switch_channel_ready(channel)) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session is not active!\n");
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
+		return JS_TRUE;
+	}
+
 
-	
 	if (argc > 0) {
 		tts_name = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
 	}
 	if (argc > 1) {
-		voice_name= JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
+		voice_name = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
 	}
 	if (argc > 2) {
 		text = JS_GetStringBytes(JS_ValueToString(cx, argv[2]));
@@ -1324,11 +1315,11 @@
 			memset(&cb_state, 0, sizeof(cb_state));
 			cb_state.function = function;
 			if (argc > 4) {
-                cb_state.arg = argv[4];
-            }
+				cb_state.arg = argv[4];
+			}
 
 			cb_state.cx = cx;
-            cb_state.obj = obj;
+			cb_state.obj = obj;
 			cb_state.session_state = jss;
 			dtmf_func = js_collect_input_callback;
 			bp = &cb_state;
@@ -1341,56 +1332,52 @@
 	}
 
 	codec = switch_core_session_get_read_codec(jss->session);
-	cb_state.ret = BOOLEAN_TO_JSVAL( JS_FALSE );
-    cb_state.saveDepth = JS_SuspendRequest(cx);
-    args.input_callback = dtmf_func;
-    args.buf = bp;
-    args.buflen = len;
-	switch_ivr_speak_text(jss->session,
-						  tts_name,
-						  voice_name && strlen(voice_name) ? voice_name : NULL, 
-						  codec->implementation->samples_per_second,
-						  text,
-                          &args);
-    JS_ResumeRequest(cx, cb_state.saveDepth);
+	cb_state.ret = BOOLEAN_TO_JSVAL(JS_FALSE);
+	cb_state.saveDepth = JS_SuspendRequest(cx);
+	args.input_callback = dtmf_func;
+	args.buf = bp;
+	args.buflen = len;
+	switch_ivr_speak_text(jss->session, tts_name, voice_name
+						  && strlen(voice_name) ? voice_name : NULL, codec->implementation->samples_per_second, text, &args);
+	JS_ResumeRequest(cx, cb_state.saveDepth);
 	*rval = cb_state.ret;
 
 	return JS_TRUE;
 }
 
-static JSBool session_get_digits(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool session_get_digits(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct js_session *jss = JS_GetPrivate(cx, obj);
 	char *terminators = NULL;
-	char buf[513] = {0};
+	char buf[513] = { 0 };
 	int32 digits = 0, timeout = 5000;
 	switch_channel_t *channel;
 
 	if (!jss || !jss->session) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "You must call the session.originate method before calling this method!\n");
-		*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 		return JS_TRUE;
 	}
 
 	channel = switch_core_session_get_channel(jss->session);
-    assert(channel != NULL);
+	assert(channel != NULL);
+
+	if (!switch_channel_ready(channel)) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session is not active!\n");
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
+		return JS_TRUE;
+	}
 
-    if (!switch_channel_ready(channel)) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session is not active!\n");
-        *rval = BOOLEAN_TO_JSVAL( JS_FALSE );
-        return JS_TRUE;
-    }
 
-	
 	if (argc > 0) {
 		char term;
 		JS_ValueToInt32(cx, argv[0], &digits);
 
 		if (digits > sizeof(buf) - 1) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Exceeded max digits of %"SWITCH_SIZE_T_FMT"\n",  sizeof(buf) - 1);
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Exceeded max digits of %" SWITCH_SIZE_T_FMT "\n", sizeof(buf) - 1);
 			return JS_FALSE;
 		}
-		
+
 		if (argc > 1) {
 			terminators = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
 		}
@@ -1400,24 +1387,24 @@
 
 
 		switch_ivr_collect_digits_count(jss->session, buf, sizeof(buf), digits, terminators, &term, timeout);
-		*rval = STRING_TO_JSVAL ( JS_NewStringCopyZ(cx, buf) );
+		*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, buf));
 		return JS_TRUE;
 	}
 
 	return JS_FALSE;
 }
 
-static JSBool session_autohangup(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool session_autohangup(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct js_session *jss = JS_GetPrivate(cx, obj);
 	*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 
 	if (!jss || !jss->session) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "You must call the session.originate method before calling this method!\n");
-		*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 		return JS_TRUE;
 	}
-	
+
 	if (argv[0]) {
 		JSBool tf;
 		JS_ValueToBoolean(cx, argv[0], &tf);
@@ -1432,25 +1419,25 @@
 	return JS_TRUE;
 }
 
-static JSBool session_answer(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool session_answer(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct js_session *jss = JS_GetPrivate(cx, obj);
 	switch_channel_t *channel;
 
 	if (!jss || !jss->session) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "You must call the session.originate method before calling this method!\n");
-		*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 		return JS_TRUE;
 	}
 
 	channel = switch_core_session_get_channel(jss->session);
 	assert(channel != NULL);
 
-    if (!switch_channel_ready(channel)) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session is not active!\n");
-        *rval = BOOLEAN_TO_JSVAL( JS_FALSE );
-        return JS_TRUE;
-    }
+	if (!switch_channel_ready(channel)) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session is not active!\n");
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
+		return JS_TRUE;
+	}
 
 
 	switch_channel_answer(channel);
@@ -1458,23 +1445,23 @@
 }
 
 
-static JSBool session_cdr(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool session_cdr(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct js_session *jss = JS_GetPrivate(cx, obj);
 	switch_xml_t cdr;
 
-	/*Always a pessimist... sheesh!*/
-	*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+	/*Always a pessimist... sheesh! */
+	*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 
 	if (!jss || !jss->session) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "You must call the session.originate method before calling this method!\n");
 		return JS_TRUE;
 	}
 
-    if (switch_ivr_generate_xml_cdr(jss->session, &cdr) == SWITCH_STATUS_SUCCESS) {
+	if (switch_ivr_generate_xml_cdr(jss->session, &cdr) == SWITCH_STATUS_SUCCESS) {
 		char *xml_text;
 		if ((xml_text = switch_xml_toxml(cdr))) {
-			*rval = STRING_TO_JSVAL (JS_NewStringCopyZ(cx, xml_text));
+			*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, xml_text));
 		}
 		switch_safe_free(xml_text);
 		switch_xml_free(cdr);
@@ -1483,28 +1470,28 @@
 	return JS_TRUE;
 }
 
-static JSBool session_ready(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool session_ready(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct js_session *jss = JS_GetPrivate(cx, obj);
 	switch_channel_t *channel;
 
 	if (!jss || !jss->session) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "You must call the session.originate method before calling this method!\n");
-		*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 		return JS_TRUE;
 	}
 
 	channel = switch_core_session_get_channel(jss->session);
 	assert(channel != NULL);
 
-	*rval = BOOLEAN_TO_JSVAL( switch_channel_ready(channel) ? JS_TRUE : JS_FALSE );
+	*rval = BOOLEAN_TO_JSVAL(switch_channel_ready(channel) ? JS_TRUE : JS_FALSE);
 
 	return JS_TRUE;
 }
 
 
 
-static JSBool session_wait_for_media(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool session_wait_for_media(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct js_session *jss = JS_GetPrivate(cx, obj);
 	switch_channel_t *channel;
@@ -1514,7 +1501,7 @@
 
 	if (!jss || !jss->session) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "You must call the session.originate method before calling this method!\n");
-		*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 		return JS_TRUE;
 	}
 
@@ -1527,25 +1514,27 @@
 		JS_ValueToInt32(cx, argv[0], &timeout);
 	}
 
-	for(;;) {
-		if (((elapsed = (unsigned int)((switch_time_now() - started) / 1000)) > (switch_time_t)timeout) || switch_channel_get_state(channel) >= CS_HANGUP) {
-			*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
-            break;
+	for (;;) {
+		if (((elapsed = (unsigned int) ((switch_time_now() - started) / 1000)) > (switch_time_t) timeout)
+			|| switch_channel_get_state(channel) >= CS_HANGUP) {
+			*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
+			break;
 		}
 
-		if (switch_channel_ready(channel) && (switch_channel_test_flag(channel, CF_ANSWERED) || switch_channel_test_flag(channel, CF_EARLY_MEDIA))) {
-			*rval = BOOLEAN_TO_JSVAL( JS_TRUE );
+		if (switch_channel_ready(channel)
+			&& (switch_channel_test_flag(channel, CF_ANSWERED) || switch_channel_test_flag(channel, CF_EARLY_MEDIA))) {
+			*rval = BOOLEAN_TO_JSVAL(JS_TRUE);
 			break;
 		}
-		
+
 		switch_yield(1000);
 	}
-	
+
 	return JS_TRUE;
 }
 
 
-static JSBool session_wait_for_answer(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool session_wait_for_answer(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct js_session *jss = JS_GetPrivate(cx, obj);
 	switch_channel_t *channel;
@@ -1555,7 +1544,7 @@
 
 	if (!jss || !jss->session) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "You must call the session.originate method before calling this method!\n");
-		*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 		return JS_TRUE;
 	}
 
@@ -1568,43 +1557,44 @@
 		JS_ValueToInt32(cx, argv[0], &timeout);
 	}
 
-	for(;;) {
-		if (((elapsed = (unsigned int)((switch_time_now() - started) / 1000)) > (switch_time_t)timeout) || switch_channel_get_state(channel) >= CS_HANGUP) {
-			*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
-            break;
+	for (;;) {
+		if (((elapsed = (unsigned int) ((switch_time_now() - started) / 1000)) > (switch_time_t) timeout)
+			|| switch_channel_get_state(channel) >= CS_HANGUP) {
+			*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
+			break;
 		}
 
 		if (switch_channel_ready(channel) && switch_channel_test_flag(channel, CF_ANSWERED)) {
-			*rval = BOOLEAN_TO_JSVAL( JS_TRUE );
+			*rval = BOOLEAN_TO_JSVAL(JS_TRUE);
 			break;
 		}
-		
+
 		switch_yield(1000);
 	}
-	
+
 	return JS_TRUE;
 }
 
-static JSBool session_execute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool session_execute(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	JSBool retval = JS_FALSE;
 	switch_channel_t *channel;
-    struct js_session *jss = JS_GetPrivate(cx, obj);
+	struct js_session *jss = JS_GetPrivate(cx, obj);
 
 	if (!jss || !jss->session) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "You must call the session.originate method before calling this method!\n");
-		*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 		return JS_TRUE;
 	}
 
 	channel = switch_core_session_get_channel(jss->session);
-    assert(channel != NULL);
+	assert(channel != NULL);
 
-    if (!switch_channel_ready(channel)) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session is not active!\n");
-        *rval = BOOLEAN_TO_JSVAL( JS_FALSE );
-        return JS_TRUE;
-    }
+	if (!switch_channel_ready(channel)) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session is not active!\n");
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
+		return JS_TRUE;
+	}
 
 
 	if (argc > 1) {
@@ -1616,7 +1606,7 @@
 
 		if (!jss || !jss->session) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "You must call the session.originate method before calling this method!\n");
-			*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+			*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 			return JS_TRUE;
 		}
 
@@ -1627,49 +1617,47 @@
 				JS_ResumeRequest(cx, saveDepth);
 				retval = JS_TRUE;
 			}
-		} 
+		}
 	}
-	
-	*rval = BOOLEAN_TO_JSVAL( retval );
+
+	*rval = BOOLEAN_TO_JSVAL(retval);
 	return JS_TRUE;
 }
 
-static JSBool session_get_event(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool session_get_event(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct js_session *jss = JS_GetPrivate(cx, obj);
 	switch_event_t *event;
 
 	if (!jss || !jss->session) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "You must call the session.originate method before calling this method!\n");
-		*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 		return JS_TRUE;
 	}
 
 	if (switch_core_session_dequeue_event(jss->session, &event) == SWITCH_STATUS_SUCCESS) {
 		JSObject *Event;
 		struct event_obj *eo;
-			
+
 		if ((eo = malloc(sizeof(*eo)))) {
 			eo->event = event;
 			eo->freed = 0;
 
 			if ((Event = JS_DefineObject(cx, obj, "__event__", &event_class, NULL, 0))) {
-				if ((JS_SetPrivate(cx, Event, eo) &&
-					 JS_DefineProperties(cx, Event, event_props) &&
-					 JS_DefineFunctions(cx, Event, event_methods))) {
-					*rval = OBJECT_TO_JSVAL ( Event );
+				if ((JS_SetPrivate(cx, Event, eo) && JS_DefineProperties(cx, Event, event_props) && JS_DefineFunctions(cx, Event, event_methods))) {
+					*rval = OBJECT_TO_JSVAL(Event);
 					return JS_TRUE;
 				}
 			}
 		}
 	}
-	
-	*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
-    return JS_TRUE;
-	
+
+	*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
+	return JS_TRUE;
+
 }
 
-static JSBool session_send_event(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool session_send_event(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct js_session *jss = JS_GetPrivate(cx, obj);
 	JSObject *Event;
@@ -1677,7 +1665,7 @@
 
 	if (!jss || !jss->session) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "You must call the session.originate method before calling this method!\n");
-		*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 		return JS_TRUE;
 	}
 
@@ -1685,7 +1673,7 @@
 		if (JS_ValueToObject(cx, argv[0], &Event)) {
 			if ((eo = JS_GetPrivate(cx, Event))) {
 				if (switch_core_session_receive_event(jss->session, &eo->event) != SWITCH_STATUS_SUCCESS) {
-					*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+					*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 					return JS_TRUE;
 				}
 
@@ -1694,13 +1682,13 @@
 		}
 	}
 
-	*rval = BOOLEAN_TO_JSVAL( JS_TRUE );
-    return JS_TRUE;
-	
+	*rval = BOOLEAN_TO_JSVAL(JS_TRUE);
+	return JS_TRUE;
+
 }
 
 
-static JSBool session_hangup(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool session_hangup(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct js_session *jss = JS_GetPrivate(cx, obj);
 	switch_channel_t *channel;
@@ -1709,18 +1697,18 @@
 
 	if (!jss || !jss->session) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "You must call the session.originate method before calling this method!\n");
-		*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 		return JS_TRUE;
 	}
 
 	channel = switch_core_session_get_channel(jss->session);
 	assert(channel != NULL);
 
-    if (!switch_channel_ready(channel)) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session is not active!\n");
-        *rval = BOOLEAN_TO_JSVAL( JS_FALSE );
-        return JS_TRUE;
-    }
+	if (!switch_channel_ready(channel)) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session is not active!\n");
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
+		return JS_TRUE;
+	}
 
 	if (argc > 1) {
 		cause_name = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
@@ -1758,7 +1746,7 @@
 				*nextline = '\0';
 				nextline++;
 			}
-			
+
 			if ((val = strchr(line, '='))) {
 				*val = '\0';
 				val++;
@@ -1766,14 +1754,14 @@
 					*val = '\0';
 					val++;
 				}
-				
+
 				for (p = line; p && *p == ' '; p++);
 				line = p;
-				for (p=line+strlen(line)-1;*p == ' '; p--)
+				for (p = line + strlen(line) - 1; *p == ' '; p--)
 					*p = '\0';
 				for (p = val; p && *p == ' '; p++);
 				val = p;
-				for (p=val+strlen(val)-1;*p == ' '; p--)
+				for (p = val + strlen(val) - 1; *p == ' '; p--)
 					*p = '\0';
 
 				snprintf(code, sizeof(code), "~%s[\"%s\"] = \"%s\"", config_data->name, line, val);
@@ -1783,7 +1771,7 @@
 
 			line = nextline;
 		}
-	} 
+	}
 	return realsize;
 
 }
@@ -1792,7 +1780,7 @@
 
 static size_t file_callback(void *ptr, size_t size, size_t nmemb, void *data)
 {
-	register unsigned int realsize = (unsigned int)(size * nmemb);
+	register unsigned int realsize = (unsigned int) (size * nmemb);
 	struct config_data *config_data = data;
 
 	write(config_data->fd, ptr, realsize);
@@ -1800,13 +1788,13 @@
 }
 
 
-static JSBool js_fetchurl_hash(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool js_fetchurl_hash(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	char *url = NULL, *name = NULL;
 	CURL *curl_handle = NULL;
 	struct config_data config_data;
-	
-	if ( argc > 1 ) {
+
+	if (argc > 1) {
 		url = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
 		name = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
 
@@ -1823,7 +1811,7 @@
 		}
 		curl_easy_setopt(curl_handle, CURLOPT_URL, url);
 		curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, hash_callback);
-		curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&config_data);
+		curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *) &config_data);
 		curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "freeswitch-js/1.0");
 		curl_easy_perform(curl_handle);
 		curl_easy_cleanup(curl_handle);
@@ -1837,13 +1825,13 @@
 
 
 
-static JSBool js_fetchurl_file(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool js_fetchurl_file(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	char *url = NULL, *filename = NULL;
 	CURL *curl_handle = NULL;
 	struct config_data config_data;
-	
-	if ( argc > 1 ) {
+
+	if (argc > 1) {
 		url = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
 		filename = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
 
@@ -1860,7 +1848,7 @@
 		if ((config_data.fd = open(filename, O_CREAT | O_RDWR | O_TRUNC)) > -1) {
 			curl_easy_setopt(curl_handle, CURLOPT_URL, url);
 			curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, file_callback);
-			curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&config_data);
+			curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *) &config_data);
 			curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "freeswitch-js/1.0");
 			curl_easy_perform(curl_handle);
 			curl_easy_cleanup(curl_handle);
@@ -1881,52 +1869,53 @@
 /*********************************************************************************/
 enum session_tinyid {
 	SESSION_NAME, SESSION_STATE,
-	PROFILE_DIALPLAN, PROFILE_CID_NAME, PROFILE_CID_NUM, PROFILE_IP, PROFILE_ANI, PROFILE_ANI_II, PROFILE_DEST, SESSION_UUID, SESSION_CAUSE
+	PROFILE_DIALPLAN, PROFILE_CID_NAME, PROFILE_CID_NUM, PROFILE_IP, PROFILE_ANI, PROFILE_ANI_II, PROFILE_DEST,
+	SESSION_UUID, SESSION_CAUSE
 };
 
 static JSFunctionSpec session_methods[] = {
-	{"originate", session_originate, 2}, 
-	{"setHangupHook", session_hanguphook, 1}, 
-	{"setAutoHangup", session_autohangup, 1}, 
-    {"sayPhrase", session_sayphrase, 1}, 
-    {"streamFile", session_streamfile, 1}, 
-	{"collectInput", session_collect_input, 1}, 
-	{"recordFile", session_recordfile, 1}, 
-	{"flushEvents", session_flush_events, 1}, 
-	{"flushDigits", session_flush_digits, 1}, 
-	{"speak", session_speak, 1}, 
-	{"setVariable", session_set_variable, 1}, 
-	{"getVariable", session_get_variable, 1}, 
+	{"originate", session_originate, 2},
+	{"setHangupHook", session_hanguphook, 1},
+	{"setAutoHangup", session_autohangup, 1},
+	{"sayPhrase", session_sayphrase, 1},
+	{"streamFile", session_streamfile, 1},
+	{"collectInput", session_collect_input, 1},
+	{"recordFile", session_recordfile, 1},
+	{"flushEvents", session_flush_events, 1},
+	{"flushDigits", session_flush_digits, 1},
+	{"speak", session_speak, 1},
+	{"setVariable", session_set_variable, 1},
+	{"getVariable", session_get_variable, 1},
 	{"getDigits", session_get_digits, 1},
-	{"answer", session_answer, 0}, 
-	{"generateXmlCdr", session_cdr, 0}, 
-	{"ready", session_ready, 0}, 
-	{"waitForAnswer", session_wait_for_answer, 0}, 
-	{"waitForMedia", session_wait_for_media, 0}, 
+	{"answer", session_answer, 0},
+	{"generateXmlCdr", session_cdr, 0},
+	{"ready", session_ready, 0},
+	{"waitForAnswer", session_wait_for_answer, 0},
+	{"waitForMedia", session_wait_for_media, 0},
 	{"getEvent", session_get_event, 0},
 	{"sendEvent", session_send_event, 0},
-	{"hangup", session_hangup, 0}, 
-	{"execute", session_execute, 0}, 
+	{"hangup", session_hangup, 0},
+	{"execute", session_execute, 0},
 	{0}
 };
 
 
 static JSPropertySpec session_props[] = {
-	{"name", SESSION_NAME, JSPROP_READONLY|JSPROP_PERMANENT}, 
-	{"state", SESSION_STATE, JSPROP_READONLY|JSPROP_PERMANENT}, 
-	{"dialplan", PROFILE_DIALPLAN, JSPROP_READONLY|JSPROP_PERMANENT},
-	{"caller_id_name", PROFILE_CID_NAME, JSPROP_READONLY|JSPROP_PERMANENT}, 
-	{"caller_id_num", PROFILE_CID_NUM, JSPROP_READONLY|JSPROP_PERMANENT}, 
-	{"network_addr", PROFILE_IP, JSPROP_READONLY|JSPROP_PERMANENT}, 
-	{"ani", PROFILE_ANI, JSPROP_READONLY|JSPROP_PERMANENT}, 
-	{"aniii", PROFILE_ANI_II, JSPROP_READONLY|JSPROP_PERMANENT}, 
-	{"destination", PROFILE_DEST, JSPROP_READONLY|JSPROP_PERMANENT}, 
-	{"uuid", SESSION_UUID, JSPROP_READONLY|JSPROP_PERMANENT}, 
-	{"cause", SESSION_CAUSE, JSPROP_READONLY|JSPROP_PERMANENT}, 
+	{"name", SESSION_NAME, JSPROP_READONLY | JSPROP_PERMANENT},
+	{"state", SESSION_STATE, JSPROP_READONLY | JSPROP_PERMANENT},
+	{"dialplan", PROFILE_DIALPLAN, JSPROP_READONLY | JSPROP_PERMANENT},
+	{"caller_id_name", PROFILE_CID_NAME, JSPROP_READONLY | JSPROP_PERMANENT},
+	{"caller_id_num", PROFILE_CID_NUM, JSPROP_READONLY | JSPROP_PERMANENT},
+	{"network_addr", PROFILE_IP, JSPROP_READONLY | JSPROP_PERMANENT},
+	{"ani", PROFILE_ANI, JSPROP_READONLY | JSPROP_PERMANENT},
+	{"aniii", PROFILE_ANI_II, JSPROP_READONLY | JSPROP_PERMANENT},
+	{"destination", PROFILE_DEST, JSPROP_READONLY | JSPROP_PERMANENT},
+	{"uuid", SESSION_UUID, JSPROP_READONLY | JSPROP_PERMANENT},
+	{"cause", SESSION_CAUSE, JSPROP_READONLY | JSPROP_PERMANENT},
 	{0}
 };
 
-static JSBool session_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
+static JSBool session_getProperty(JSContext * cx, JSObject * obj, jsval id, jsval * vp)
 {
 	struct js_session *jss = JS_GetPrivate(cx, obj);
 	int param = 0;
@@ -1950,9 +1939,9 @@
 	}
 
 	if (!channel) {
-		switch(param) {
+		switch (param) {
 		case SESSION_CAUSE:
-			*vp = STRING_TO_JSVAL (JS_NewStringCopyZ(cx, switch_channel_cause2str(jss->cause)));
+			*vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, switch_channel_cause2str(jss->cause)));
 			break;
 		default:
 			*vp = BOOLEAN_TO_JSVAL(JS_FALSE);
@@ -1960,9 +1949,9 @@
 		return JS_TRUE;
 	}
 
-	switch(param) {
+	switch (param) {
 	case SESSION_CAUSE:
-		*vp = STRING_TO_JSVAL (JS_NewStringCopyZ(cx, switch_channel_cause2str(switch_channel_get_cause(channel))));
+		*vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, switch_channel_cause2str(switch_channel_get_cause(channel))));
 		break;
 	case SESSION_NAME:
 		*vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, switch_channel_get_name(channel)));
@@ -2011,21 +2000,21 @@
 	default:
 		*vp = BOOLEAN_TO_JSVAL(JS_FALSE);
 		break;
-		
+
 	}
 
 	return JS_TRUE;
 }
 
 JSClass session_class = {
-	"Session", JSCLASS_HAS_PRIVATE, 
-	JS_PropertyStub,  JS_PropertyStub,	session_getProperty,  JS_PropertyStub, 
-	JS_EnumerateStub, JS_ResolveStub,	JS_ConvertStub,	  session_destroy, NULL, NULL, NULL,
+	"Session", JSCLASS_HAS_PRIVATE,
+	JS_PropertyStub, JS_PropertyStub, session_getProperty, JS_PropertyStub,
+	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, session_destroy, NULL, NULL, NULL,
 	session_construct
 };
 
 
-static JSObject *new_js_session(JSContext *cx, JSObject *obj, switch_core_session_t *session, struct js_session *jss, char *name, int flags) 
+static JSObject *new_js_session(JSContext * cx, JSObject * obj, switch_core_session_t *session, struct js_session *jss, char *name, int flags)
 {
 	JSObject *session_obj;
 	if ((session_obj = JS_DefineObject(cx, obj, name, &session_class, NULL, 0))) {
@@ -2035,19 +2024,18 @@
 		jss->cx = cx;
 		jss->obj = session_obj;
 		if ((JS_SetPrivate(cx, session_obj, jss) &&
-			 JS_DefineProperties(cx, session_obj, session_props) &&
-			 JS_DefineFunctions(cx, session_obj, session_methods))) {
+			 JS_DefineProperties(cx, session_obj, session_props) && JS_DefineFunctions(cx, session_obj, session_methods))) {
 			return session_obj;
 		}
 	}
-	
+
 	return NULL;
 }
 
 /* Session Object */
 /*********************************************************************************/
 
-static JSBool session_construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool session_construct(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct js_session *jss = NULL;
 
@@ -2062,7 +2050,7 @@
 	return JS_TRUE;
 }
 
-static JSBool session_originate(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool session_originate(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct js_session *jss = NULL;
 	switch_memory_pool_t *pool = NULL;
@@ -2141,25 +2129,16 @@
 		if (argc > 11) {
 			to = JS_GetStringBytes(JS_ValueToString(cx, argv[11]));
 		}
-		
+
 		if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "OH OH no pool\n");
 			return JS_FALSE;
 		}
 
 		caller_profile = switch_caller_profile_new(pool,
-												   username,
-												   dialplan,
-												   cid_name,
-												   cid_num,
-												   network_addr,
-												   ani,
-												   aniii,
-												   rdnis,
-												   (char *)modname,
-												   context,
+												   username, dialplan, cid_name, cid_num, network_addr, ani, aniii, rdnis, (char *) modname, context,
 												   dest);
-		
+
 		if (switch_ivr_originate(session, &peer_session, &jss->cause, dest, to ? atoi(to) : 60, NULL, NULL, NULL, caller_profile) != SWITCH_STATUS_SUCCESS) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cannot Create Outgoing Channel! [%s]\n", dest);
 			goto done;
@@ -2174,18 +2153,18 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Missing Args\n");
 	}
 
- done:
+  done:
 	return JS_TRUE;
 }
 
 
 
 
-static void session_destroy(JSContext *cx, JSObject *obj)
+static void session_destroy(JSContext * cx, JSObject * obj)
 {
 	struct js_session *jss;
 	switch_channel_t *channel = NULL;
-	
+
 	if (cx && obj) {
 		if ((jss = JS_GetPrivate(cx, obj))) {
 			if (jss->session) {
@@ -2202,13 +2181,13 @@
 			}
 		}
 	}
-		
+
 	return;
 }
 
 /* FileIO Object */
 /*********************************************************************************/
-static JSBool fileio_construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool fileio_construct(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	switch_memory_pool_t *pool;
 	switch_file_t *fd;
@@ -2219,7 +2198,7 @@
 	if (argc > 1) {
 		path = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
 		flags_str = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
-		
+
 		if (strchr(flags_str, 'r')) {
 			flags |= SWITCH_FOPEN_READ;
 		}
@@ -2239,10 +2218,10 @@
 			flags |= SWITCH_FOPEN_BINARY;
 		}
 		switch_core_new_memory_pool(&pool);
-		if (switch_file_open(&fd, path, flags, SWITCH_FPROT_UREAD|SWITCH_FPROT_UWRITE, pool) != SWITCH_STATUS_SUCCESS) {
+		if (switch_file_open(&fd, path, flags, SWITCH_FPROT_UREAD | SWITCH_FPROT_UWRITE, pool) != SWITCH_STATUS_SUCCESS) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Open File: %s\n", path);
 			switch_core_destroy_memory_pool(&pool);
-			*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+			*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 			return JS_TRUE;
 		}
 		fio = switch_core_alloc(pool, sizeof(*fio));
@@ -2256,13 +2235,13 @@
 
 	return JS_TRUE;
 }
-static void fileio_destroy(JSContext *cx, JSObject *obj)
+static void fileio_destroy(JSContext * cx, JSObject * obj)
 {
 	struct fileio_obj *fio = JS_GetPrivate(cx, obj);
 
 	if (fio) {
 		switch_memory_pool_t *pool;
-			if (fio->fd) {
+		if (fio->fd) {
 			switch_file_close(fio->fd);
 		}
 		pool = fio->pool;
@@ -2271,23 +2250,23 @@
 	}
 }
 
-static JSBool fileio_read(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool fileio_read(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct fileio_obj *fio = JS_GetPrivate(cx, obj);
 	int32 bytes = 0;
 	switch_size_t read = 0;
 
-	*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
-	
+	*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
+
 	if (!fio) {
-		*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 		return JS_TRUE;
 	}
 
 	if (!(fio->flags & SWITCH_FOPEN_READ)) {
 		return JS_TRUE;
 	}
-	
+
 	if (argc > 0) {
 		JS_ValueToInt32(cx, argv[0], &bytes);
 	}
@@ -2300,51 +2279,51 @@
 		read = bytes;
 		switch_file_read(fio->fd, fio->buf, &read);
 		fio->buflen = read;
-		*rval = BOOLEAN_TO_JSVAL( (read > 0) ? JS_TRUE : JS_FALSE );
-	} 
+		*rval = BOOLEAN_TO_JSVAL((read > 0) ? JS_TRUE : JS_FALSE);
+	}
 
 	return JS_TRUE;
 }
 
-static JSBool fileio_data(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool fileio_data(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct fileio_obj *fio = JS_GetPrivate(cx, obj);
 
 	if (!fio) {
-		*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 		return JS_TRUE;
 	}
 
-	*rval = STRING_TO_JSVAL (JS_NewStringCopyZ(cx, fio->buf));
+	*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, fio->buf));
 	return JS_TRUE;
 }
 
-static JSBool fileio_write(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool fileio_write(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct fileio_obj *fio = JS_GetPrivate(cx, obj);
 	switch_size_t wrote = 0;
 	char *data = NULL;
 
 	if (!fio) {
-		*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 		return JS_TRUE;
 	}
 
 	if (!(fio->flags & SWITCH_FOPEN_WRITE)) {
-		*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 		return JS_TRUE;
 	}
-	
+
 	if (argc > 0) {
 		data = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
 	}
 
 	if (data) {
 		wrote = strlen(data);
-		*rval = BOOLEAN_TO_JSVAL( (switch_file_write(fio->fd, data, &wrote) == SWITCH_STATUS_SUCCESS) ? JS_TRUE : JS_FALSE);
+		*rval = BOOLEAN_TO_JSVAL((switch_file_write(fio->fd, data, &wrote) == SWITCH_STATUS_SUCCESS) ? JS_TRUE : JS_FALSE);
 	}
 
-	*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+	*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 	return JS_TRUE;
 }
 
@@ -2361,37 +2340,37 @@
 
 
 static JSPropertySpec fileio_props[] = {
-	{"path", FILEIO_PATH, JSPROP_READONLY|JSPROP_PERMANENT}, 
-	{"open", FILEIO_OPEN, JSPROP_READONLY|JSPROP_PERMANENT}, 
+	{"path", FILEIO_PATH, JSPROP_READONLY | JSPROP_PERMANENT},
+	{"open", FILEIO_OPEN, JSPROP_READONLY | JSPROP_PERMANENT},
 	{0}
 };
 
 
-static JSBool fileio_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
+static JSBool fileio_getProperty(JSContext * cx, JSObject * obj, jsval id, jsval * vp)
 {
 	JSBool res = JS_TRUE;
 	struct fileio_obj *fio = JS_GetPrivate(cx, obj);
 	char *name;
 	int param = 0;
-	
+
 	name = JS_GetStringBytes(JS_ValueToString(cx, id));
-    /* numbers are our props anything else is a method */
-    if (name[0] >= 48 && name[0] <= 57) {
-        param = atoi(name);
-    } else {
-        return JS_TRUE;
-    }
-	
-	switch(param) {
+	/* numbers are our props anything else is a method */
+	if (name[0] >= 48 && name[0] <= 57) {
+		param = atoi(name);
+	} else {
+		return JS_TRUE;
+	}
+
+	switch (param) {
 	case FILEIO_PATH:
 		if (fio) {
 			*vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, fio->path));
 		} else {
-			*vp = BOOLEAN_TO_JSVAL( JS_FALSE );
+			*vp = BOOLEAN_TO_JSVAL(JS_FALSE);
 		}
 		break;
 	case FILEIO_OPEN:
-		*vp = BOOLEAN_TO_JSVAL( fio ? JS_TRUE : JS_FALSE );
+		*vp = BOOLEAN_TO_JSVAL(fio ? JS_TRUE : JS_FALSE);
 		break;
 	}
 
@@ -2399,21 +2378,21 @@
 }
 
 JSClass fileio_class = {
-	"FileIO", JSCLASS_HAS_PRIVATE, 
-	JS_PropertyStub,  JS_PropertyStub,	fileio_getProperty,  JS_PropertyStub, 
-	JS_EnumerateStub, JS_ResolveStub,	JS_ConvertStub,	  fileio_destroy, NULL, NULL, NULL,
+	"FileIO", JSCLASS_HAS_PRIVATE,
+	JS_PropertyStub, JS_PropertyStub, fileio_getProperty, JS_PropertyStub,
+	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, fileio_destroy, NULL, NULL, NULL,
 	fileio_construct
 };
 
 
 /* Built-In*/
 /*********************************************************************************/
-static JSBool js_exit(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool js_exit(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	return JS_FALSE;
 }
 
-static JSBool js_log(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool js_log(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	char *level_str, *msg;
 	switch_log_level_t level = SWITCH_LOG_DEBUG;
@@ -2421,14 +2400,14 @@
 	const char *file = __FILE__;
 	int line = __LINE__;
 	JSStackFrame *caller;
-	
+
 	caller = JS_GetScriptedCaller(cx, NULL);
 	script = JS_GetFrameScript(cx, caller);
 
 	if (script) {
 		file = JS_GetScriptFilename(cx, script);
 		line = JS_GetScriptBaseLineNumber(cx, script);
-	}	
+	}
 
 
 	if (argc > 1) {
@@ -2439,7 +2418,7 @@
 		if ((msg = JS_GetStringBytes(JS_ValueToString(cx, argv[1])))) {
 			switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, "console_log", line, level, "%s", msg);
 			return JS_TRUE;
-		} 
+		}
 	} else if (argc > 0) {
 		if ((msg = JS_GetStringBytes(JS_ValueToString(cx, argv[0])))) {
 			switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, "console_log", line, level, "%s", msg);
@@ -2450,10 +2429,10 @@
 	return JS_FALSE;
 }
 
-static JSBool js_include(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool js_include(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	char *code;
-	if ( argc > 0 && (code = JS_GetStringBytes(JS_ValueToString(cx, argv[0])))) {
+	if (argc > 0 && (code = JS_GetStringBytes(JS_ValueToString(cx, argv[0])))) {
 		if (eval_some_js(code, cx, obj, rval) < 0) {
 			return JS_FALSE;
 		}
@@ -2463,7 +2442,7 @@
 	return JS_FALSE;
 }
 
-static JSBool js_api_use(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool js_api_use(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	char *mod_name = NULL;
 
@@ -2481,17 +2460,17 @@
 	}
 
 	return JS_TRUE;
-	
+
 }
 
-static JSBool js_api_execute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool js_api_execute(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 
 	if (argc > 1) {
 		char *cmd = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
 		char *arg = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
 		switch_core_session_t *session = NULL;
-		switch_stream_handle_t stream = {0};
+		switch_stream_handle_t stream = { 0 };
 		char retbuf[2048] = "";
 
 		if (argc > 2) {
@@ -2503,30 +2482,30 @@
 				}
 			}
 		}
-		
-		
+
+
 		stream.data = retbuf;
 		stream.end = stream.data;
 		stream.data_size = sizeof(retbuf);
 		stream.write_function = switch_console_stream_write;
 		switch_api_execute(cmd, arg, session, &stream);
 
-		*rval = STRING_TO_JSVAL (JS_NewStringCopyZ(cx, retbuf));
+		*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, retbuf));
 	} else {
-		*rval = STRING_TO_JSVAL (JS_NewStringCopyZ(cx, ""));
+		*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, ""));
 	}
 
 	return JS_TRUE;
 }
 
-static JSBool js_bridge(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool js_bridge(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct js_session *jss_a = NULL, *jss_b = NULL;
 	JSObject *session_obj_a = NULL, *session_obj_b = NULL;
 	void *bp = NULL;
 	int len = 0;
 	switch_input_callback_function_t dtmf_func = NULL;
-	struct input_callback_state cb_state = {0};
+	struct input_callback_state cb_state = { 0 };
 	JSFunction *function;
 
 	if (argc > 1) {
@@ -2535,15 +2514,15 @@
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Find Session [1]\n");
 				return JS_FALSE;
 			}
-		} 
+		}
 		if (JS_ValueToObject(cx, argv[1], &session_obj_b)) {
 			if (!(jss_b = JS_GetPrivate(cx, session_obj_b))) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Find Session [1]\n");
 				return JS_FALSE;
 			}
-		} 
+		}
 	}
-	
+
 	if (!(jss_a && jss_b)) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failure! %s %s\n", jss_a ? "y" : "n", jss_b ? "y" : "n");
 		return JS_FALSE;
@@ -2556,12 +2535,12 @@
 			cb_state.function = function;
 
 			if (argc > 3) {
-                cb_state.arg = argv[3];
-            }
+				cb_state.arg = argv[3];
+			}
 
 			cb_state.cx = cx;
-            cb_state.obj = obj;
-			
+			cb_state.obj = obj;
+
 			cb_state.session_state = jss_a;
 			dtmf_func = js_collect_input_callback;
 			bp = &cb_state;
@@ -2569,37 +2548,37 @@
 		}
 	}
 
-    cb_state.saveDepth = JS_SuspendRequest(cx);
+	cb_state.saveDepth = JS_SuspendRequest(cx);
 	switch_ivr_multi_threaded_bridge(jss_a->session, jss_b->session, dtmf_func, bp, bp);
-    JS_ResumeRequest(cx, cb_state.saveDepth);
+	JS_ResumeRequest(cx, cb_state.saveDepth);
 
 
 	return JS_TRUE;
 }
 
 /* Replace this with more robust version later */
-static JSBool js_system(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool js_system(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
-    char *cmd;
-    *rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+	char *cmd;
+	*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 
-    if (argc > 0 && (cmd = JS_GetStringBytes(JS_ValueToString(cx, argv[0])))) {
-        *rval = INT_TO_JSVAL( system(cmd) );
-        return JS_TRUE;
-    }
+	if (argc > 0 && (cmd = JS_GetStringBytes(JS_ValueToString(cx, argv[0])))) {
+		*rval = INT_TO_JSVAL(system(cmd));
+		return JS_TRUE;
+	}
 
-    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Arguements\n");
-    return JS_FALSE;
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Arguements\n");
+	return JS_FALSE;
 }
 
 
-static JSBool js_file_unlink(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool js_file_unlink(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	const char *path;
-	*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
-	if ( argc > 0 && (path = (const char *)JS_GetStringBytes(JS_ValueToString(cx, argv[0])))) {
+	*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
+	if (argc > 0 && (path = (const char *) JS_GetStringBytes(JS_ValueToString(cx, argv[0])))) {
 		if ((switch_file_remove(path, NULL)) == SWITCH_STATUS_SUCCESS) {
-			*rval = BOOLEAN_TO_JSVAL( JS_TRUE );
+			*rval = BOOLEAN_TO_JSVAL(JS_TRUE);
 		}
 		return JS_TRUE;
 	}
@@ -2608,64 +2587,34 @@
 }
 
 static JSFunctionSpec fs_functions[] = {
-	{"console_log", js_log, 2}, 
-	{"exit", js_exit, 0}, 
-	{"include", js_include, 1}, 
+	{"console_log", js_log, 2},
+	{"exit", js_exit, 0},
+	{"include", js_include, 1},
 	{"bridge", js_bridge, 2},
 	{"apiExecute", js_api_execute, 2},
 	{"use", js_api_use, 1},
 	{"fileDelete", js_file_unlink, 1},
 	{"system", js_system, 1},
 #ifdef HAVE_CURL
-	{"fetchURLHash", js_fetchurl_hash, 1}, 
-	{"fetchURLFile", js_fetchurl_file, 1}, 
-#endif 
+	{"fetchURLHash", js_fetchurl_hash, 1},
+	{"fetchURLFile", js_fetchurl_file, 1},
+#endif
 	{0}
 };
 
 
-static int env_init(JSContext *cx, JSObject *javascript_object)
+static int env_init(JSContext * cx, JSObject * javascript_object)
 {
 
 	JS_DefineFunctions(cx, javascript_object, fs_functions);
 
 	JS_InitStandardClasses(cx, javascript_object);
 
-	JS_InitClass(cx,
-				 javascript_object,
-				 NULL,
-				 &session_class,
-				 session_construct,
-				 3,
-				 session_props,
-				 session_methods,
-				 session_props,
-				 session_methods
-				 );
-
-	JS_InitClass(cx,
-				 javascript_object,
-				 NULL,
-				 &fileio_class,
-				 fileio_construct,
-				 3,
-				 fileio_props,
-				 fileio_methods,
-				 fileio_props,
-				 fileio_methods
-				 );
-
-	JS_InitClass(cx,
-				 javascript_object,
-				 NULL,
-				 &event_class,
-				 event_construct,
-				 3,
-				 event_props,
-				 event_methods,
-				 event_props,
-				 event_methods
-				 );
+	JS_InitClass(cx, javascript_object, NULL, &session_class, session_construct, 3, session_props, session_methods, session_props, session_methods);
+
+	JS_InitClass(cx, javascript_object, NULL, &fileio_class, fileio_construct, 3, fileio_props, fileio_methods, fileio_props, fileio_methods);
+
+	JS_InitClass(cx, javascript_object, NULL, &event_class, event_construct, 3, event_props, event_methods, event_props, event_methods);
 
 	return 1;
 }
@@ -2680,7 +2629,7 @@
 	JSContext *cx = NULL;
 	jsval rval;
 
-	
+
 	if ((cx = JS_NewContext(globals.rt, globals.gStackChunkSize))) {
 		JS_BeginRequest(cx);
 		JS_SetErrorReporter(cx, js_error);
@@ -2703,8 +2652,8 @@
 		*arg++ = '\0';
 		argc = switch_separate_string(arg, ':', argv, (sizeof(argv) / sizeof(argv[0])));
 	}
-	
-	if (argc) { /* create a js doppleganger of this argc/argv*/
+
+	if (argc) {					/* create a js doppleganger of this argc/argv */
 		snprintf(buf, sizeof(buf), "~var argv = new Array(%d);", argc);
 		eval_some_js(buf, cx, javascript_global_object, &rval);
 		snprintf(buf, sizeof(buf), "~var argc = %d", argc);
@@ -2726,7 +2675,7 @@
 
 
 
-static void *SWITCH_THREAD_FUNC js_thread_run(switch_thread_t *thread, void *obj)
+static void *SWITCH_THREAD_FUNC js_thread_run(switch_thread_t * thread, void *obj)
 {
 	char *input_code = obj;
 
@@ -2753,7 +2702,7 @@
 			return;
 		}
 	}
-	
+
 	switch_threadattr_create(&thd_attr, module_pool);
 	switch_threadattr_detach_set(thd_attr, 1);
 	switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
@@ -2781,8 +2730,9 @@
 	/* long_desc */ "Run a javascript ivr on a channel",
 	/* short_desc */ "Launch JS ivr.",
 	/* syntax */ "<script> [additional_vars [...]]",
-	/* flags */ SAF_NONE, /* should we support no media mode here?  If so, we need to detect the mode, and either disable the media functions or indicate media if/when we need */
-	/*.next*/ NULL
+	/* flags */ SAF_NONE,
+	/* should we support no media mode here?  If so, we need to detect the mode, and either disable the media functions or indicate media if/when we need */
+	/*.next */ NULL
 };
 
 static switch_api_interface_t js_run_interface = {
@@ -2813,7 +2763,7 @@
 	if ((status = init_js()) != SWITCH_STATUS_SUCCESS) {
 		return status;
 	}
-	
+
 	/* connect my internal structure to the blank pointer passed to me */
 	*module_interface = &spidermonkey_module_interface;
 

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey/mod_spidermonkey.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey/mod_spidermonkey.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey/mod_spidermonkey.h	Fri Mar 30 12:19:18 2007
@@ -52,18 +52,14 @@
 #include "jsscript.h"
 
 SWITCH_BEGIN_EXTERN_C
-
 #define JS_BUFFER_SIZE 1024 * 32
 #define JS_BLOCK_SIZE JS_BUFFER_SIZE
-
 #ifdef __ICC
 #pragma warning (disable:310 193 1418)
 #endif
-
 #ifdef _MSC_VER
 #pragma warning(disable: 4311)
 #endif
-
 #ifdef WIN32
 #if defined(SWITCH_SM_DECLARE_STATIC)
 #define SWITCH_SM_DECLARE(type)		type __cdecl
@@ -75,8 +71,7 @@
 #else //not win32
 #define SWITCH_SM_DECLARE(type) type
 #endif
-
-int eval_some_js(char *code, JSContext *cx, JSObject *obj, jsval *rval)
+int eval_some_js(char *code, JSContext * cx, JSObject * obj, jsval * rval)
 {
 	JSScript *script = NULL;
 	char *cptr;
@@ -101,22 +96,22 @@
 			} else {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Open File: %s\n", script_name);
 			}
-		} 
+		}
 	}
-	
+
 	if (script) {
 		result = JS_ExecuteScript(cx, obj, script, rval) == JS_TRUE ? 1 : 0;
 		JS_DestroyScript(cx, script);
 	} else {
 		result = -1;
 	}
-	
+
 	switch_safe_free(path);
 	return result;
 }
 
 
-typedef switch_status_t(*spidermonkey_load_t)(JSContext *cx, JSObject *obj);
+typedef switch_status_t (*spidermonkey_load_t) (JSContext * cx, JSObject * obj);
 
 struct sm_module_interface {
 	const char *name;
@@ -125,7 +120,7 @@
 };
 
 typedef struct sm_module_interface sm_module_interface_t;
-typedef switch_status_t(*spidermonkey_init_t)(const sm_module_interface_t **module_interface);
+typedef switch_status_t (*spidermonkey_init_t) (const sm_module_interface_t ** module_interface);
 
 struct js_session {
 	switch_core_session_t *session;
@@ -139,6 +134,4 @@
 
 
 SWITCH_END_EXTERN_C
-
 #endif
-

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey_core_db/mod_spidermonkey_core_db.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey_core_db/mod_spidermonkey_core_db.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey_core_db/mod_spidermonkey_core_db.c	Fri Mar 30 12:19:18 2007
@@ -34,19 +34,19 @@
 static const char modname[] = "CoreDB";
 
 struct db_obj {
-    switch_memory_pool_t *pool;
-    switch_core_db_t *db;
-    switch_core_db_stmt_t *stmt;
-    char *dbname;
-    char code_buffer[2048];
-    JSContext *cx;
-    JSObject *obj;
+	switch_memory_pool_t *pool;
+	switch_core_db_t *db;
+	switch_core_db_stmt_t *stmt;
+	char *dbname;
+	char code_buffer[2048];
+	JSContext *cx;
+	JSObject *obj;
 };
 
 
 /* DB Object */
 /*********************************************************************************/
-static JSBool db_construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool db_construct(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	switch_memory_pool_t *pool;
 	switch_core_db_t *db;
@@ -55,7 +55,7 @@
 	if (argc > 0) {
 		char *dbname = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
 		switch_core_new_memory_pool(&pool);
-		if (! (db = switch_core_db_open_file(dbname))) {
+		if (!(db = switch_core_db_open_file(dbname))) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Open DB!\n");
 			switch_core_destroy_memory_pool(&pool);
 			return JS_FALSE;
@@ -73,10 +73,10 @@
 	return JS_FALSE;
 }
 
-static void db_destroy(JSContext *cx, JSObject *obj)
+static void db_destroy(JSContext * cx, JSObject * obj)
 {
 	struct db_obj *dbo = JS_GetPrivate(cx, obj);
-	
+
 	if (dbo) {
 		switch_memory_pool_t *pool = dbo->pool;
 		if (dbo->stmt) {
@@ -85,7 +85,7 @@
 		}
 		switch_core_db_close(dbo->db);
 		switch_core_destroy_memory_pool(&pool);
-        pool = NULL;
+		pool = NULL;
 	}
 }
 
@@ -100,7 +100,7 @@
 	snprintf(code, sizeof(code), "~var _Db_RoW_ = {}");
 	eval_some_js(code, dbo->cx, dbo->obj, &rval);
 
-	for(x=0; x < argc; x++) {
+	for (x = 0; x < argc; x++) {
 		snprintf(code, sizeof(code), "~_Db_RoW_[\"%s\"] = \"%s\"", columnNames[x], argv[x]);
 		eval_some_js(code, dbo->cx, dbo->obj, &rval);
 	}
@@ -110,51 +110,51 @@
 
 	snprintf(code, sizeof(code), "~delete _Db_RoW_");
 	eval_some_js(code, dbo->cx, dbo->obj, &rval);
-	
+
 	return 0;
 }
 
-static JSBool db_exec(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool db_exec(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
-    struct db_obj *dbo = JS_GetPrivate(cx, obj);
-    *rval = BOOLEAN_TO_JSVAL( JS_TRUE );
+	struct db_obj *dbo = JS_GetPrivate(cx, obj);
+	*rval = BOOLEAN_TO_JSVAL(JS_TRUE);
+
+	if (argc > 0) {
+		char *sql = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
+		char *err = NULL;
+		void *arg = NULL;
+		switch_core_db_callback_func_t cb_func = NULL;
+
+
+		if (argc > 1) {
+			char *js_func = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
+			switch_copy_string(dbo->code_buffer, js_func, sizeof(dbo->code_buffer));
+			cb_func = db_callback;
+			arg = dbo;
+		}
 
-    if (argc > 0) {
-        char *sql = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
-        char *err = NULL;
-        void *arg = NULL;
-        switch_core_db_callback_func_t cb_func = NULL;
-
-
-        if (argc > 1) {
-            char *js_func = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
-            switch_copy_string(dbo->code_buffer, js_func, sizeof(dbo->code_buffer));
-            cb_func = db_callback;
-            arg = dbo;
-        }
-
-        switch_core_db_exec(dbo->db, sql, cb_func, arg, &err);
-        if (err) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error %s\n", err);
-            switch_core_db_free(err);
-            *rval = BOOLEAN_TO_JSVAL( JS_FALSE );
-        }
-    }
-    return JS_TRUE;
+		switch_core_db_exec(dbo->db, sql, cb_func, arg, &err);
+		if (err) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error %s\n", err);
+			switch_core_db_free(err);
+			*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
+		}
+	}
+	return JS_TRUE;
 }
 
 
-static JSBool db_next(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool db_next(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct db_obj *dbo = JS_GetPrivate(cx, obj);
-	*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
+	*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 
-    if (dbo->stmt) {
+	if (dbo->stmt) {
 		int running = 1;
 		while (running < 5000) {
 			int result = switch_core_db_step(dbo->stmt);
 			if (result == SWITCH_CORE_DB_ROW) {
-				*rval = BOOLEAN_TO_JSVAL( JS_TRUE );	
+				*rval = BOOLEAN_TO_JSVAL(JS_TRUE);
 				break;
 			} else if (result == SWITCH_CORE_DB_BUSY) {
 				running++;
@@ -169,7 +169,7 @@
 	return JS_TRUE;
 }
 
-static JSBool db_fetch(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool db_fetch(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct db_obj *dbo = JS_GetPrivate(cx, obj);
 	int colcount = switch_core_db_column_count(dbo->stmt);
@@ -179,16 +179,15 @@
 	snprintf(code, sizeof(code), "~var _dB_RoW_DaTa_ = {}");
 	eval_some_js(code, dbo->cx, dbo->obj, rval);
 	if (*rval == JS_FALSE) {
-		return JS_TRUE; 
+		return JS_TRUE;
 	}
 	for (x = 0; x < colcount; x++) {
-		snprintf(code, sizeof(code), "~_dB_RoW_DaTa_[\"%s\"] = \"%s\"", 
-				 (char *) switch_core_db_column_name(dbo->stmt, x),
-				 (char *) switch_core_db_column_text(dbo->stmt, x));
+		snprintf(code, sizeof(code), "~_dB_RoW_DaTa_[\"%s\"] = \"%s\"",
+				 (char *) switch_core_db_column_name(dbo->stmt, x), (char *) switch_core_db_column_text(dbo->stmt, x));
 
 		eval_some_js(code, dbo->cx, dbo->obj, rval);
 		if (*rval == JS_FALSE) {
-			return JS_TRUE; 
+			return JS_TRUE;
 		}
 	}
 
@@ -198,11 +197,11 @@
 }
 
 
-static JSBool db_prepare(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool db_prepare(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct db_obj *dbo = JS_GetPrivate(cx, obj);
 
-	*rval = BOOLEAN_TO_JSVAL( JS_FALSE );	
+	*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 
 	if (dbo->stmt) {
 		switch_core_db_finalize(dbo->stmt);
@@ -211,10 +210,10 @@
 
 	if (argc > 0) {
 		char *sql = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
-		if(switch_core_db_prepare(dbo->db, sql, -1, &dbo->stmt, 0)) {
+		if (switch_core_db_prepare(dbo->db, sql, -1, &dbo->stmt, 0)) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error %s\n", switch_core_db_errmsg(dbo->db));
 		} else {
-			*rval = BOOLEAN_TO_JSVAL( JS_TRUE );
+			*rval = BOOLEAN_TO_JSVAL(JS_TRUE);
 		}
 	}
 	return JS_TRUE;
@@ -234,27 +233,27 @@
 
 
 static JSPropertySpec db_props[] = {
-	{"path", DB_NAME, JSPROP_READONLY|JSPROP_PERMANENT}, 
+	{"path", DB_NAME, JSPROP_READONLY | JSPROP_PERMANENT},
 	{0}
 };
 
 
-static JSBool db_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
+static JSBool db_getProperty(JSContext * cx, JSObject * obj, jsval id, jsval * vp)
 {
 	JSBool res = JS_TRUE;
 	struct db_obj *dbo = JS_GetPrivate(cx, obj);
 	char *name;
 	int param = 0;
-	
+
 	name = JS_GetStringBytes(JS_ValueToString(cx, id));
-    /* numbers are our props anything else is a method */
-    if (name[0] >= 48 && name[0] <= 57) {
-        param = atoi(name);
-    } else {
-        return JS_TRUE;
-    }
-	
-	switch(param) {
+	/* numbers are our props anything else is a method */
+	if (name[0] >= 48 && name[0] <= 57) {
+		param = atoi(name);
+	} else {
+		return JS_TRUE;
+	}
+
+	switch (param) {
 	case DB_NAME:
 		*vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, dbo->dbname));
 		break;
@@ -264,38 +263,28 @@
 }
 
 JSClass db_class = {
-	modname, JSCLASS_HAS_PRIVATE, 
-	JS_PropertyStub,  JS_PropertyStub,	db_getProperty,  JS_PropertyStub, 
-	JS_EnumerateStub, JS_ResolveStub,	JS_ConvertStub,	  db_destroy, NULL, NULL, NULL,
+	modname, JSCLASS_HAS_PRIVATE,
+	JS_PropertyStub, JS_PropertyStub, db_getProperty, JS_PropertyStub,
+	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, db_destroy, NULL, NULL, NULL,
 	db_construct
 };
 
 
-switch_status_t db_load(JSContext *cx, JSObject *obj)
+switch_status_t db_load(JSContext * cx, JSObject * obj)
 {
 
-	JS_InitClass(cx,
-				 obj,
-				 NULL,
-				 &db_class,
-				 db_construct,
-				 3,
-				 db_props,
-				 db_methods,
-				 db_props,
-				 db_methods
-				 );
+	JS_InitClass(cx, obj, NULL, &db_class, db_construct, 3, db_props, db_methods, db_props, db_methods);
 	return SWITCH_STATUS_SUCCESS;
 }
 
 
 const sm_module_interface_t DB_module_interface = {
 	/*.name = */ modname,
-	/*.spidermonkey_load*/ db_load,
-	/*.next*/ NULL
+	/*.spidermonkey_load */ db_load,
+	/*.next */ NULL
 };
 
-SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t **module_interface)
+SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t ** module_interface)
 {
 	*module_interface = &DB_module_interface;
 	return SWITCH_STATUS_SUCCESS;

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey_etpan/mod_spidermonkey_etpan.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey_etpan/mod_spidermonkey_etpan.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey_etpan/mod_spidermonkey_etpan.c	Fri Mar 30 12:19:18 2007
@@ -40,9 +40,10 @@
 #define B64BUFFLEN 1024
 static const char c64[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 
-static int write_buf(int fd, char *buf) {
+static int write_buf(int fd, char *buf)
+{
 
-	int len = (int)strlen(buf);
+	int len = (int) strlen(buf);
 	if (fd && write(fd, buf, len) != len) {
 		close(fd);
 		return 0;
@@ -53,17 +54,17 @@
 
 /* etpan Object */
 /*********************************************************************************/
-static JSBool etpan_construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool etpan_construct(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	return JS_TRUE;
 }
 
-static void etpan_destroy(JSContext *cx, JSObject *obj)
+static void etpan_destroy(JSContext * cx, JSObject * obj)
 {
 }
 
 #if 0
-static JSBool etpan_my_method(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool etpan_my_method(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	return JS_FALSE;
 }
@@ -73,27 +74,25 @@
 	etpan_NAME
 };
 
-static JSBool js_email(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool js_email(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	char *to = NULL, *from = NULL, *headers, *body = NULL, *file = NULL;
 	char *bound = "XXXX_boundary_XXXX";
 	char filename[80], buf[B64BUFFLEN];
 	int fd = 0, ifd = 0;
-	int x=0, y=0, bytes=0, ilen=0;
-	unsigned int b=0, l=0;
+	int x = 0, y = 0, bytes = 0, ilen = 0;
+	unsigned int b = 0, l = 0;
 	unsigned char in[B64BUFFLEN];
-	unsigned char out[B64BUFFLEN+512];
+	unsigned char out[B64BUFFLEN + 512];
 	char *path = NULL;
 
-	
-	if ( 
-		argc > 3 && 
+
+	if (argc > 3 &&
 		(from = JS_GetStringBytes(JS_ValueToString(cx, argv[0]))) &&
 		(to = JS_GetStringBytes(JS_ValueToString(cx, argv[1]))) &&
-		(headers = JS_GetStringBytes(JS_ValueToString(cx, argv[2]))) &&
-		(body = JS_GetStringBytes(JS_ValueToString(cx, argv[3]))) 
+		(headers = JS_GetStringBytes(JS_ValueToString(cx, argv[2]))) && (body = JS_GetStringBytes(JS_ValueToString(cx, argv[3])))
 		) {
-		if ( argc > 4) {
+		if (argc > 4) {
 			file = JS_GetStringBytes(JS_ValueToString(cx, argv[4]));
 		}
 		snprintf(filename, 80, "%smail.%ld%04x", SWITCH_GLOBAL_dirs.temp_dir, time(NULL), rand() & 0xffff);
@@ -110,63 +109,63 @@
 					return JS_FALSE;
 				}
 			}
-			
+
 			if (!write_buf(fd, headers))
 				return JS_FALSE;
 
 			if (!write_buf(fd, "\n\n"))
 				return JS_FALSE;
-			
+
 			if (file) {
 				snprintf(buf, B64BUFFLEN, "--%s\nContent-Type: text/plain\n\n", bound);
 				if (!write_buf(fd, buf))
 					return JS_FALSE;
 			}
-			
+
 			if (!write_buf(fd, body))
 				return JS_FALSE;
-			
+
 			if (file) {
 				snprintf(buf, B64BUFFLEN, "\n\n--%s\nContent-Type: application/octet-stream\n"
 						 "Content-Transfer-Encoding: base64\n"
-						 "Content-Description: Sound attachment.\n"
-						 "Content-Disposition: attachment; filename=\"%s\"\n\n", bound, file);
+						 "Content-Description: Sound attachment.\n" "Content-Disposition: attachment; filename=\"%s\"\n\n", bound, file);
 				if (!write_buf(fd, buf))
 					return JS_FALSE;
-				
-				while((ilen=read(ifd, in, B64BUFFLEN))) {
-					for (x=0;x<ilen;x++) {
-						b = (b<<8) + in[x];
+
+				while ((ilen = read(ifd, in, B64BUFFLEN))) {
+					for (x = 0; x < ilen; x++) {
+						b = (b << 8) + in[x];
 						l += 8;
 						while (l >= 6) {
-							out[bytes++] = c64[(b>>(l-=6))%64];
-							if (++y!=72)
+							out[bytes++] = c64[(b >> (l -= 6)) % 64];
+							if (++y != 72)
 								continue;
 							out[bytes++] = '\n';
-							y=0;
+							y = 0;
 						}
 					}
-					if (write(fd, &out, bytes) != bytes) { 
+					if (write(fd, &out, bytes) != bytes) {
 						return -1;
-					} else 
-						bytes=0;
-					
+					} else
+						bytes = 0;
+
 				}
-				
+
 				if (l > 0) {
-					out[bytes++] = c64[((b%16)<<(6-l))%64];
-				}
-				if (l != 0) while (l < 6) {
-					out[bytes++] = '=', l += 2;
+					out[bytes++] = c64[((b % 16) << (6 - l)) % 64];
 				}
-				if (write(fd, &out, bytes) != bytes) { 
+				if (l != 0)
+					while (l < 6) {
+						out[bytes++] = '=', l += 2;
+					}
+				if (write(fd, &out, bytes) != bytes) {
 					return -1;
 				}
 
 			}
-			
 
-			
+
+
 			if (file) {
 				snprintf(buf, B64BUFFLEN, "\n\n--%s--\n.\n", bound);
 				if (!write_buf(fd, buf))
@@ -192,23 +191,23 @@
 		}
 		return JS_TRUE;
 	}
-	
+
 
 	return JS_FALSE;
 }
 
 static JSFunctionSpec etpan_methods[] = {
-//	{"myMethod", odbc_my_method, 1},
+//  {"myMethod", odbc_my_method, 1},
 	{0}
 };
 
 static JSPropertySpec etpan_props[] = {
-//	{"name", etpan_NAME, JSPROP_READONLY|JSPROP_PERMANENT}, 
+//  {"name", etpan_NAME, JSPROP_READONLY|JSPROP_PERMANENT}, 
 	{0}
 };
 
 
-static JSBool etpan_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
+static JSBool etpan_getProperty(JSContext * cx, JSObject * obj, jsval id, jsval * vp)
 {
 	JSBool res = JS_TRUE;
 
@@ -216,44 +215,34 @@
 }
 
 JSClass etpan_class = {
-	modname, JSCLASS_HAS_PRIVATE, 
-	JS_PropertyStub,  JS_PropertyStub,	etpan_getProperty,  JS_PropertyStub, 
-	JS_EnumerateStub, JS_ResolveStub,	JS_ConvertStub,	  etpan_destroy, NULL, NULL, NULL,
+	modname, JSCLASS_HAS_PRIVATE,
+	JS_PropertyStub, JS_PropertyStub, etpan_getProperty, JS_PropertyStub,
+	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, etpan_destroy, NULL, NULL, NULL,
 	etpan_construct
 };
 
 
 static JSFunctionSpec etpan_functions[] = {
-	{"email", js_email, 2}, 
+	{"email", js_email, 2},
 	{0}
 };
 
-switch_status_t etpan_load(JSContext *cx, JSObject *obj)
+switch_status_t etpan_load(JSContext * cx, JSObject * obj)
 {
 	JS_DefineFunctions(cx, obj, etpan_functions);
 
-	JS_InitClass(cx,
-				 obj,
-				 NULL,
-				 &etpan_class,
-				 etpan_construct,
-				 3,
-				 etpan_props,
-				 etpan_methods,
-				 etpan_props,
-				 etpan_methods
-				 );
+	JS_InitClass(cx, obj, NULL, &etpan_class, etpan_construct, 3, etpan_props, etpan_methods, etpan_props, etpan_methods);
 	return SWITCH_STATUS_SUCCESS;
 }
 
 
 const sm_module_interface_t etpan_module_interface = {
 	/*.name = */ modname,
-	/*.spidermonkey_load*/ etpan_load,
-	/*.next*/ NULL
+	/*.spidermonkey_load */ etpan_load,
+	/*.next */ NULL
 };
 
-SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t **module_interface)
+SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t ** module_interface)
 {
 	*module_interface = &etpan_module_interface;
 	return SWITCH_STATUS_SUCCESS;
@@ -271,259 +260,252 @@
 int smtp_esmtp = 1;
 
 struct mem_message {
-  char *data;
-  size_t len;
-  MMAPString *mstring;
+	char *data;
+	size_t len;
+	MMAPString *mstring;
 };
 
 #define BLOCKSIZE 4096
 
-int collect(struct mem_message *message) {
-  struct stat sb;
-  int len;
+int collect(struct mem_message *message)
+{
+	struct stat sb;
+	int len;
 
-  memset(message, 0, sizeof(struct mem_message));
+	memset(message, 0, sizeof(struct mem_message));
 
 #ifndef MMAP_UNAVAILABLE
-  /* if stdin is a file whose size is known, try to mmap it */
-  if (!fstat(0, &sb) && S_ISREG(sb.st_mode) && sb.st_size >= 0) {
-    message->len = sb.st_size;
-    if ((message->data = mmap(NULL, message->len, PROT_READ, MAP_SHARED,
-			      STDIN_FILENO, 0)) != MAP_FAILED)
-      return 0;
-  }
+	/* if stdin is a file whose size is known, try to mmap it */
+	if (!fstat(0, &sb) && S_ISREG(sb.st_mode) && sb.st_size >= 0) {
+		message->len = sb.st_size;
+		if ((message->data = mmap(NULL, message->len, PROT_READ, MAP_SHARED, STDIN_FILENO, 0)) != MAP_FAILED)
+			return 0;
+	}
 #endif
 
-  /* read the buffer from stdin by blocks, until EOF or error.
-     save the message in a mmap_string */
-  if ((message->mstring = mmap_string_sized_new(BLOCKSIZE)) == NULL) {
-    perror("mmap_string_new");
-    goto error;
-  }
-  message->len = 0;
-
-  while ((len = read(STDIN_FILENO,
-		     message->mstring->str + message->len, BLOCKSIZE)) > 0) {
-    message->len += len;
-    /* reserve room for next block */
-    if ((mmap_string_set_size(message->mstring,
-			      message->len + BLOCKSIZE)) == NULL) {
-      perror("mmap_string_set_size");
-      goto error;
-    }
-  }
-
-  if (len == 0) {
-    message->data = message->mstring->str;
-    return 0; /* OK */
-  }
-
-  perror("read");
-
- error:
-  if (message->mstring != NULL)
-    mmap_string_free(message->mstring);
-  return -1;
+	/* read the buffer from stdin by blocks, until EOF or error.
+	   save the message in a mmap_string */
+	if ((message->mstring = mmap_string_sized_new(BLOCKSIZE)) == NULL) {
+		perror("mmap_string_new");
+		goto error;
+	}
+	message->len = 0;
+
+	while ((len = read(STDIN_FILENO, message->mstring->str + message->len, BLOCKSIZE)) > 0) {
+		message->len += len;
+		/* reserve room for next block */
+		if ((mmap_string_set_size(message->mstring, message->len + BLOCKSIZE)) == NULL) {
+			perror("mmap_string_set_size");
+			goto error;
+		}
+	}
+
+	if (len == 0) {
+		message->data = message->mstring->str;
+		return 0;				/* OK */
+	}
+
+	perror("read");
+
+  error:
+	if (message->mstring != NULL)
+		mmap_string_free(message->mstring);
+	return -1;
 }
 
-char *guessfrom() {
+char *guessfrom()
+{
 #ifndef _MSC_VER
-  uid_t uid;
-  struct passwd *pw;
-  char hostname[256];
-  int len;
-  char *gfrom;
-
-  if (gethostname(hostname, sizeof(hostname))) {
-    perror("gethostname");
-    return NULL;
-  }
-  hostname[sizeof(hostname) - 1] = '\0';
-
-  uid = getuid();
-  pw = getpwuid(uid);
-  
-  len = ((pw != NULL) ? strlen(pw->pw_name) : 12)
-    + strlen(hostname) + 2;
-
-  if ((gfrom = malloc(len)) == NULL) {
-    perror("malloc");
-    return NULL;
-  }
-  if (pw != NULL && pw->pw_name != NULL) 
-    snprintf(gfrom, len, "%s@%s", pw->pw_name, hostname);
-  else
-    snprintf(gfrom, len, "#%u@%s", uid, hostname);
-  return gfrom;
+	uid_t uid;
+	struct passwd *pw;
+	char hostname[256];
+	int len;
+	char *gfrom;
+
+	if (gethostname(hostname, sizeof(hostname))) {
+		perror("gethostname");
+		return NULL;
+	}
+	hostname[sizeof(hostname) - 1] = '\0';
+
+	uid = getuid();
+	pw = getpwuid(uid);
+
+	len = ((pw != NULL) ? strlen(pw->pw_name) : 12)
+		+ strlen(hostname) + 2;
+
+	if ((gfrom = malloc(len)) == NULL) {
+		perror("malloc");
+		return NULL;
+	}
+	if (pw != NULL && pw->pw_name != NULL)
+		snprintf(gfrom, len, "%s@%s", pw->pw_name, hostname);
+	else
+		snprintf(gfrom, len, "#%u@%s", uid, hostname);
+	return gfrom;
 #else
 	return NULL;
 #endif
 }
 
-void release(struct mem_message *message) {
-  if (message->mstring != NULL)
-    mmap_string_free(message->mstring);
+void release(struct mem_message *message)
+{
+	if (message->mstring != NULL)
+		mmap_string_free(message->mstring);
 #ifndef MMAP_UNAVAILABLE
-  else if (message->data != NULL)
-    munmap(message->data, message->len);
+	else if (message->data != NULL)
+		munmap(message->data, message->len);
 #endif
 }
 
-int send_message(char *data, size_t len, char**rcpts) {
-  int s = -1;
-  int ret;
-  char **r;
-  int esmtp = 0;
-  mailsmtp *smtp = NULL;
-
-  if ((smtp = mailsmtp_new(0, NULL)) == NULL) {
-    perror("mailsmtp_new");
-    goto error;
-  }
-
-  /* first open the stream */
-  if ((ret = mailsmtp_socket_connect(smtp, 
-				     (smtp_server != NULL ? smtp_server : "localhost"),
-				     smtp_port)) != MAILSMTP_NO_ERROR) {
-    fprintf(stderr, "mailsmtp_socket_connect: %s\n", mailsmtp_strerror(ret));
-    goto error;
-  }
-  
-  /* then introduce ourselves */
-  if (smtp_esmtp && (ret = mailesmtp_ehlo(smtp)) == MAILSMTP_NO_ERROR)
-    esmtp = 1;
-  else if (!smtp_esmtp || ret == MAILSMTP_ERROR_NOT_IMPLEMENTED)
-    ret = mailsmtp_helo(smtp);
-  if (ret != MAILSMTP_NO_ERROR) {
-    fprintf(stderr, "mailsmtp_helo: %s\n", mailsmtp_strerror(ret));
-    goto error;
-  }
-
-  if (esmtp && smtp_tls &&
-      (ret = mailsmtp_socket_starttls(smtp)) != MAILSMTP_NO_ERROR) {
-    fprintf(stderr, "mailsmtp_starttls: %s\n", mailsmtp_strerror(ret));
-    goto error;
-  }
-  
-  if (esmtp && smtp_user != NULL &&
-      (ret = mailsmtp_auth(smtp, smtp_user,
-			   (smtp_password != NULL) ? smtp_password : ""))
-      != MAILSMTP_NO_ERROR) {
-    fprintf(stderr, "mailsmtp_auth: %s: %s\n", smtp_user, mailsmtp_strerror(ret));
-    goto error;
-  }
-
-  /* source */
-  if ((ret = (esmtp ?
-	      mailesmtp_mail(smtp, smtp_from, 1, "etPanSMTPTest") :
-	      mailsmtp_mail(smtp, smtp_from))) != MAILSMTP_NO_ERROR) {
-    fprintf(stderr, "mailsmtp_mail: %s, %s\n", smtp_from, mailsmtp_strerror(ret));
-    goto error;
-  }
-  
-  /* recipients */
-  for (r = rcpts; *r != NULL; r++) {
-    if ((ret = (esmtp ?
-		mailesmtp_rcpt(smtp, *r,
-			       MAILSMTP_DSN_NOTIFY_FAILURE|MAILSMTP_DSN_NOTIFY_DELAY,
-			       NULL) :
-		mailsmtp_rcpt(smtp, *r))) != MAILSMTP_NO_ERROR) {
-      fprintf(stderr, "mailsmtp_rcpt: %s: %s\n", *r, mailsmtp_strerror(ret));
-      goto error;
-    }
-  }
-  
-  /* message */
-  if ((ret = mailsmtp_data(smtp)) != MAILSMTP_NO_ERROR) {
-    fprintf(stderr, "mailsmtp_data: %s\n", mailsmtp_strerror(ret));
-    goto error;
-  }
-  if ((ret = mailsmtp_data_message(smtp, data, len)) != MAILSMTP_NO_ERROR) {
-    fprintf(stderr, "mailsmtp_data_message: %s\n", mailsmtp_strerror(ret));
-    goto error;
-  }
-  mailsmtp_free(smtp);
-  return 0;
-
- error:
-  if (smtp != NULL)
-    mailsmtp_free(smtp);
-  if (s >= 0)
-    close(s);
-  return -1;
-}
-
-int main(int argc, char **argv) {
-  struct mem_message message;
-  int index, r;
-
-  static struct option long_options[] = {
-    {"server",   1, 0, 's'},
-    {"port",     1, 0, 'p'},
-    {"user",     1, 0, 'u'},
-    {"password", 1, 0, 'v'},
-    {"from",     1, 0, 'f'},
-    {"tls",      0, 0, 'S'},
-    {"no-esmtp", 0, 0, 'E'},
-  };
-
-  while(1) {
-    if ((r = getopt_long(argc, argv, "s:p:u:v:f:SE", long_options, &index)) < 0)
-      break;
-    switch (r) {
-    case 's':
-      if (smtp_server != NULL)
-	free(smtp_server);
-      smtp_server = strdup(optarg);
-      break;
-    case 'p':
-      smtp_port = (uint16_t) strtoul(optarg, NULL, 10);
-      break;
-    case 'u':
-      if (smtp_user != NULL)
-	free(smtp_user);
-      smtp_user = strdup(optarg);
-      break;
-    case 'v':
-      if (smtp_password != NULL)
-	free(smtp_password);
-      smtp_password = strdup(optarg);
-      break;
-    case 'f':
-      if (smtp_from != NULL)
-	free(smtp_from);
-      smtp_from = strdup(optarg);
-      break;
-    case 'S':
-      smtp_tls = 1;
-      break;
-    case 'E':
-      smtp_esmtp = 0;
-      break;
-    }
-  }
-
-  argc -= optind;
-  argv += optind;
-
-  if (argc < 1) {
-    fprintf(stderr, "usage: smtpsend [-f from] [-u user] [-v password] [-s server] [-p port] [-S] <rcpts>...\n");
-    return EXIT_FAILURE;
-  }
-
-  if (smtp_from == NULL && (smtp_from = guessfrom()) == NULL) {
-    fprintf(stderr, "can't guess a valid from, please use -f option.\n");
-    return EXIT_FAILURE;
-  }
-  
-  /* reads message from stdin */
-  if (collect(&message))
-    return EXIT_FAILURE;
-  
-  send_message(message.data, message.len, argv);
+int send_message(char *data, size_t len, char **rcpts)
+{
+	int s = -1;
+	int ret;
+	char **r;
+	int esmtp = 0;
+	mailsmtp *smtp = NULL;
+
+	if ((smtp = mailsmtp_new(0, NULL)) == NULL) {
+		perror("mailsmtp_new");
+		goto error;
+	}
+
+	/* first open the stream */
+	if ((ret = mailsmtp_socket_connect(smtp, (smtp_server != NULL ? smtp_server : "localhost"), smtp_port)) != MAILSMTP_NO_ERROR) {
+		fprintf(stderr, "mailsmtp_socket_connect: %s\n", mailsmtp_strerror(ret));
+		goto error;
+	}
+
+	/* then introduce ourselves */
+	if (smtp_esmtp && (ret = mailesmtp_ehlo(smtp)) == MAILSMTP_NO_ERROR)
+		esmtp = 1;
+	else if (!smtp_esmtp || ret == MAILSMTP_ERROR_NOT_IMPLEMENTED)
+		ret = mailsmtp_helo(smtp);
+	if (ret != MAILSMTP_NO_ERROR) {
+		fprintf(stderr, "mailsmtp_helo: %s\n", mailsmtp_strerror(ret));
+		goto error;
+	}
+
+	if (esmtp && smtp_tls && (ret = mailsmtp_socket_starttls(smtp)) != MAILSMTP_NO_ERROR) {
+		fprintf(stderr, "mailsmtp_starttls: %s\n", mailsmtp_strerror(ret));
+		goto error;
+	}
+
+	if (esmtp && smtp_user != NULL && (ret = mailsmtp_auth(smtp, smtp_user, (smtp_password != NULL) ? smtp_password : ""))
+		!= MAILSMTP_NO_ERROR) {
+		fprintf(stderr, "mailsmtp_auth: %s: %s\n", smtp_user, mailsmtp_strerror(ret));
+		goto error;
+	}
+
+	/* source */
+	if ((ret = (esmtp ? mailesmtp_mail(smtp, smtp_from, 1, "etPanSMTPTest") : mailsmtp_mail(smtp, smtp_from))) != MAILSMTP_NO_ERROR) {
+		fprintf(stderr, "mailsmtp_mail: %s, %s\n", smtp_from, mailsmtp_strerror(ret));
+		goto error;
+	}
+
+	/* recipients */
+	for (r = rcpts; *r != NULL; r++) {
+		if ((ret = (esmtp ?
+					mailesmtp_rcpt(smtp, *r, MAILSMTP_DSN_NOTIFY_FAILURE | MAILSMTP_DSN_NOTIFY_DELAY, NULL) : mailsmtp_rcpt(smtp,
+																															*r))) != MAILSMTP_NO_ERROR) {
+			fprintf(stderr, "mailsmtp_rcpt: %s: %s\n", *r, mailsmtp_strerror(ret));
+			goto error;
+		}
+	}
+
+	/* message */
+	if ((ret = mailsmtp_data(smtp)) != MAILSMTP_NO_ERROR) {
+		fprintf(stderr, "mailsmtp_data: %s\n", mailsmtp_strerror(ret));
+		goto error;
+	}
+	if ((ret = mailsmtp_data_message(smtp, data, len)) != MAILSMTP_NO_ERROR) {
+		fprintf(stderr, "mailsmtp_data_message: %s\n", mailsmtp_strerror(ret));
+		goto error;
+	}
+	mailsmtp_free(smtp);
+	return 0;
+
+  error:
+	if (smtp != NULL)
+		mailsmtp_free(smtp);
+	if (s >= 0)
+		close(s);
+	return -1;
+}
+
+int main(int argc, char **argv)
+{
+	struct mem_message message;
+	int index, r;
+
+	static struct option long_options[] = {
+		{"server", 1, 0, 's'},
+		{"port", 1, 0, 'p'},
+		{"user", 1, 0, 'u'},
+		{"password", 1, 0, 'v'},
+		{"from", 1, 0, 'f'},
+		{"tls", 0, 0, 'S'},
+		{"no-esmtp", 0, 0, 'E'},
+	};
+
+	while (1) {
+		if ((r = getopt_long(argc, argv, "s:p:u:v:f:SE", long_options, &index)) < 0)
+			break;
+		switch (r) {
+		case 's':
+			if (smtp_server != NULL)
+				free(smtp_server);
+			smtp_server = strdup(optarg);
+			break;
+		case 'p':
+			smtp_port = (uint16_t) strtoul(optarg, NULL, 10);
+			break;
+		case 'u':
+			if (smtp_user != NULL)
+				free(smtp_user);
+			smtp_user = strdup(optarg);
+			break;
+		case 'v':
+			if (smtp_password != NULL)
+				free(smtp_password);
+			smtp_password = strdup(optarg);
+			break;
+		case 'f':
+			if (smtp_from != NULL)
+				free(smtp_from);
+			smtp_from = strdup(optarg);
+			break;
+		case 'S':
+			smtp_tls = 1;
+			break;
+		case 'E':
+			smtp_esmtp = 0;
+			break;
+		}
+	}
+
+	argc -= optind;
+	argv += optind;
+
+	if (argc < 1) {
+		fprintf(stderr, "usage: smtpsend [-f from] [-u user] [-v password] [-s server] [-p port] [-S] <rcpts>...\n");
+		return EXIT_FAILURE;
+	}
+
+	if (smtp_from == NULL && (smtp_from = guessfrom()) == NULL) {
+		fprintf(stderr, "can't guess a valid from, please use -f option.\n");
+		return EXIT_FAILURE;
+	}
+
+	/* reads message from stdin */
+	if (collect(&message))
+		return EXIT_FAILURE;
+
+	send_message(message.data, message.len, argv);
 
-  release(&message);
-  return EXIT_SUCCESS;
+	release(&message);
+	return EXIT_SUCCESS;
 }
 
 #endif

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey_odbc/mod_spidermonkey_odbc.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey_odbc/mod_spidermonkey_odbc.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey_odbc/mod_spidermonkey_odbc.c	Fri Mar 30 12:19:18 2007
@@ -46,30 +46,30 @@
 static const char modname[] = "ODBC";
 
 struct odbc_obj {
-    char *dsn;
-    char *username;
-    char *password;
-    SQLHENV  env;
-    SQLHDBC  con;
-    SQLHSTMT stmt;
-    uint32_t state;
-    SQLCHAR *colbuf;
-    int32 cblen;
-    SQLCHAR *code;
-    int32 codelen;
+	char *dsn;
+	char *username;
+	char *password;
+	SQLHENV env;
+	SQLHDBC con;
+	SQLHSTMT stmt;
+	uint32_t state;
+	SQLCHAR *colbuf;
+	int32 cblen;
+	SQLCHAR *code;
+	int32 codelen;
 };
 
 typedef enum {
-    ODBC_STATE_INIT,
-    ODBC_STATE_DOWN,
-    ODBC_STATE_CONNECTED,
-    ODBC_STATE_ERROR
+	ODBC_STATE_INIT,
+	ODBC_STATE_DOWN,
+	ODBC_STATE_CONNECTED,
+	ODBC_STATE_ERROR
 } odbc_state_t;
 typedef struct odbc_obj odbc_obj_t;
 
 typedef enum {
-    ODBC_SUCCESS = 0,
-    ODBC_FAIL = -1
+	ODBC_SUCCESS = 0,
+	ODBC_FAIL = -1
 } odbc_status_t;
 
 
@@ -77,59 +77,59 @@
 {
 	odbc_obj_t *new_obj;
 
-    if (!(new_obj = malloc(sizeof(*new_obj)))) {
-        goto err;
-    }
-    
-    if (!(new_obj->dsn = strdup(dsn))) {
-        goto err;
-    }
-
-    if (!(new_obj->username = strdup(username))) {
-        goto err;
-    }
-
-    if (!(new_obj->password = strdup(password))) {
-        goto err;
-    }
+	if (!(new_obj = malloc(sizeof(*new_obj)))) {
+		goto err;
+	}
+
+	if (!(new_obj->dsn = strdup(dsn))) {
+		goto err;
+	}
+
+	if (!(new_obj->username = strdup(username))) {
+		goto err;
+	}
+
+	if (!(new_obj->password = strdup(password))) {
+		goto err;
+	}
 
 	new_obj->env = SQL_NULL_HANDLE;
 	new_obj->state = ODBC_STATE_INIT;
-    
+
 	return new_obj;
 
-err:
+  err:
 	if (new_obj) {
 		switch_safe_free(new_obj->dsn);
 		switch_safe_free(new_obj->username);
 		switch_safe_free(new_obj->password);
-		switch_safe_free(new_obj);	
+		switch_safe_free(new_obj);
 	}
 
 	return NULL;
 }
 
-odbc_status_t odbc_obj_disconnect(odbc_obj_t *obj)
+odbc_status_t odbc_obj_disconnect(odbc_obj_t * obj)
 {
 	int result;
 
-    if (obj->state == ODBC_STATE_CONNECTED) {
-        result = SQLDisconnect(obj->con);
-        if (result == ODBC_SUCCESS) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Disconnected %d from [%s]\n", result, obj->dsn);
-        } else {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Disconnectiong [%s]\n", obj->dsn);
-        }
-    } else {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "[%s] already disconnected\n", obj->dsn);
-    }
-    
+	if (obj->state == ODBC_STATE_CONNECTED) {
+		result = SQLDisconnect(obj->con);
+		if (result == ODBC_SUCCESS) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Disconnected %d from [%s]\n", result, obj->dsn);
+		} else {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Disconnectiong [%s]\n", obj->dsn);
+		}
+	} else {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "[%s] already disconnected\n", obj->dsn);
+	}
+
 	obj->state = ODBC_STATE_DOWN;
 
 	return ODBC_SUCCESS;
 }
 
-odbc_status_t odbc_obj_connect(odbc_obj_t *obj)
+odbc_status_t odbc_obj_connect(odbc_obj_t * obj)
 {
 	int result;
 	SQLINTEGER err;
@@ -140,14 +140,14 @@
 		result = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &obj->env);
 
 		if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error AllocHandle\n");
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error AllocHandle\n");
 			return ODBC_FAIL;
 		}
 
 		result = SQLSetEnvAttr(obj->env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
 
 		if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error SetEnv\n");
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error SetEnv\n");
 			SQLFreeHandle(SQL_HANDLE_ENV, obj->env);
 			return ODBC_FAIL;
 		}
@@ -155,7 +155,7 @@
 		result = SQLAllocHandle(SQL_HANDLE_DBC, obj->env, &obj->con);
 
 		if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error AllocHDB %d\n", result);
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error AllocHDB %d\n", result);
 			SQLFreeHandle(SQL_HANDLE_ENV, obj->env);
 			return ODBC_FAIL;
 		}
@@ -168,15 +168,12 @@
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connecting %s\n", obj->dsn);
 
-	result = SQLConnect(obj->con,
-                        (SQLCHAR *) obj->dsn, SQL_NTS,
-                        (SQLCHAR *) obj->username, SQL_NTS,
-                        (SQLCHAR *) obj->password, SQL_NTS);
-    
+	result = SQLConnect(obj->con, (SQLCHAR *) obj->dsn, SQL_NTS, (SQLCHAR *) obj->username, SQL_NTS, (SQLCHAR *) obj->password, SQL_NTS);
+
 	if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
 		SQLGetDiagRec(SQL_HANDLE_DBC, obj->con, 1, stat, &err, msg, 100, &mlen);
 		SQLFreeHandle(SQL_HANDLE_ENV, obj->env);
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error SQLConnect=%d errno=%d %s\n", result, (int)err, msg);
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error SQLConnect=%d errno=%d %s\n", result, (int) err, msg);
 		return ODBC_FAIL;
 	} else {
 
@@ -187,9 +184,9 @@
 	return ODBC_SUCCESS;
 }
 
-static void destroy_odbc_obj(odbc_obj_t **objp)
+static void destroy_odbc_obj(odbc_obj_t ** objp)
 {
-    odbc_obj_t *obj = *objp;
+	odbc_obj_t *obj = *objp;
 
 	odbc_obj_disconnect(obj);
 
@@ -198,282 +195,282 @@
 	SQLFreeHandle(SQL_HANDLE_ENV, obj->env);
 
 	switch_safe_free(obj->dsn);
-    switch_safe_free(obj->username);
-    switch_safe_free(obj->password);
+	switch_safe_free(obj->username);
+	switch_safe_free(obj->password);
 	switch_safe_free(obj->colbuf);
 	switch_safe_free(obj->code);
-    switch_safe_free(obj);
+	switch_safe_free(obj);
 }
 
 
 /* ODBC Object */
 /*********************************************************************************/
-static JSBool odbc_construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool odbc_construct(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
-    odbc_obj_t *odbc_obj = NULL;
-    char *dsn, *username, *password;
-    int32 blen = 1024;
-
-    if (argc < 3) {
-        return JS_FALSE;
-    } 
-
-    dsn = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
-    username = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
-    password = JS_GetStringBytes(JS_ValueToString(cx, argv[2]));
-
-    if (argc > 3) {
-        int32 len;
-        JS_ValueToInt32(cx, argv[3], &len);
-
-        if (len > 0) {
-            blen = len;
-        }
-    }
-    
-    if (dsn && username && password) {
-        odbc_obj = new_odbc_obj(dsn, username, password);
-    }
-
-    if (!odbc_obj) {
-        return JS_FALSE;
-    }
-
-    if (!(odbc_obj->colbuf = (SQLCHAR *) malloc(blen))) {
-        destroy_odbc_obj(&odbc_obj);
-        return JS_FALSE;
-    }
-
-    odbc_obj->cblen = blen;
-
-    blen += 1536;
-
-    if (!(odbc_obj->code = (SQLCHAR *) malloc(blen))) {
-        destroy_odbc_obj(&odbc_obj);
-        return JS_FALSE;
-    }
-    
-    odbc_obj->codelen = blen;
+	odbc_obj_t *odbc_obj = NULL;
+	char *dsn, *username, *password;
+	int32 blen = 1024;
+
+	if (argc < 3) {
+		return JS_FALSE;
+	}
+
+	dsn = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
+	username = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
+	password = JS_GetStringBytes(JS_ValueToString(cx, argv[2]));
+
+	if (argc > 3) {
+		int32 len;
+		JS_ValueToInt32(cx, argv[3], &len);
+
+		if (len > 0) {
+			blen = len;
+		}
+	}
+
+	if (dsn && username && password) {
+		odbc_obj = new_odbc_obj(dsn, username, password);
+	}
+
+	if (!odbc_obj) {
+		return JS_FALSE;
+	}
+
+	if (!(odbc_obj->colbuf = (SQLCHAR *) malloc(blen))) {
+		destroy_odbc_obj(&odbc_obj);
+		return JS_FALSE;
+	}
+
+	odbc_obj->cblen = blen;
+
+	blen += 1536;
+
+	if (!(odbc_obj->code = (SQLCHAR *) malloc(blen))) {
+		destroy_odbc_obj(&odbc_obj);
+		return JS_FALSE;
+	}
+
+	odbc_obj->codelen = blen;
 
 	JS_SetPrivate(cx, obj, odbc_obj);
 
 	return JS_TRUE;
 }
 
-static void odbc_destroy(JSContext *cx, JSObject *obj)
+static void odbc_destroy(JSContext * cx, JSObject * obj)
 {
-    odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
+	odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
 
-    if (odbc_obj) {
-        destroy_odbc_obj(&odbc_obj);
-    }
+	if (odbc_obj) {
+		destroy_odbc_obj(&odbc_obj);
+	}
 }
 
-static JSBool odbc_connect(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool odbc_connect(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
-    odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
-    JSBool tf = JS_TRUE;
+	odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
+	JSBool tf = JS_TRUE;
+
+	if (odbc_obj) {
+		if (odbc_obj_connect(odbc_obj) == ODBC_SUCCESS) {
+			tf = JS_TRUE;
+		} else {
+			tf = JS_FALSE;
+		}
+	}
 
-    if (odbc_obj) {
-        if (odbc_obj_connect(odbc_obj) == ODBC_SUCCESS) {
-            tf = JS_TRUE;
-        } else {
-            tf = JS_FALSE;
-        }
-    }
-    
-    *rval = BOOLEAN_TO_JSVAL( tf );
+	*rval = BOOLEAN_TO_JSVAL(tf);
 
 	return JS_TRUE;
 }
 
-static JSBool odbc_exec(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool odbc_exec(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
-    odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
-    char *sql;
-    JSBool tf = JS_FALSE;
-    int result;
+	odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
+	char *sql;
+	JSBool tf = JS_FALSE;
+	int result;
+
+	if (argc < 1) {
+		goto done;
+	}
+
+	if (odbc_obj->state != ODBC_STATE_CONNECTED) {
+		goto done;
+	}
 
-    if (argc < 1) {
-        goto done;
-    }
+	if (odbc_obj->stmt) {
+		SQLFreeHandle(SQL_HANDLE_STMT, odbc_obj->stmt);
+		odbc_obj->stmt = NULL;
+	}
 
-    if (odbc_obj->state != ODBC_STATE_CONNECTED) {
-        goto done;
-    }
+	sql = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
 
-    if (odbc_obj->stmt) {
-        SQLFreeHandle (SQL_HANDLE_STMT, odbc_obj->stmt);
-        odbc_obj->stmt = NULL;
-    }
-    
-    sql = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
+	if (SQLAllocHandle(SQL_HANDLE_STMT, odbc_obj->con, &odbc_obj->stmt) != SQL_SUCCESS) {
+		goto done;
+	}
 
-    if (SQLAllocHandle(SQL_HANDLE_STMT, odbc_obj->con, &odbc_obj->stmt) != SQL_SUCCESS) {
-        goto done;
-    }
+	if (SQLPrepare(odbc_obj->stmt, (unsigned char *) sql, SQL_NTS) != SQL_SUCCESS) {
+		goto done;
+	}
 
-    if (SQLPrepare(odbc_obj->stmt, (unsigned char *)sql, SQL_NTS) != SQL_SUCCESS) {
-        goto done;
-    }
+	result = SQLExecute(odbc_obj->stmt);
+
+	if (result != SQL_SUCCESS && result != SQL_SUCCESS_WITH_INFO) {
+		goto done;
+	}
 
-    result = SQLExecute(odbc_obj->stmt);
+	tf = JS_TRUE;
 
-    if (result != SQL_SUCCESS && result != SQL_SUCCESS_WITH_INFO) {
-        goto done;
-    }
-    
-    tf = JS_TRUE;
-    
- done:
+  done:
 
-    *rval = BOOLEAN_TO_JSVAL( tf );
+	*rval = BOOLEAN_TO_JSVAL(tf);
 
-    return JS_TRUE;
+	return JS_TRUE;
 }
 
-static JSBool odbc_num_rows(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool odbc_num_rows(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
-    odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
+	odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
 
-    SQLSMALLINT rows = 0;    
+	SQLSMALLINT rows = 0;
 
-    if (odbc_obj->state != ODBC_STATE_CONNECTED) {
-        goto done;
-    }
+	if (odbc_obj->state != ODBC_STATE_CONNECTED) {
+		goto done;
+	}
 
-    if (odbc_obj->stmt) {
-        SQLNumResultCols(odbc_obj->stmt, &rows);
-    }
+	if (odbc_obj->stmt) {
+		SQLNumResultCols(odbc_obj->stmt, &rows);
+	}
 
- done:
+  done:
 
-    *rval = INT_TO_JSVAL( rows );
+	*rval = INT_TO_JSVAL(rows);
 
-    return JS_TRUE;
+	return JS_TRUE;
 
 }
 
 
-static JSBool odbc_next_row(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool odbc_next_row(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
-    odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
-    int result = 0;
-    JSBool tf = JS_FALSE;
+	odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
+	int result = 0;
+	JSBool tf = JS_FALSE;
 
-    if (odbc_obj->state != ODBC_STATE_CONNECTED) {
-        goto done;
-    }
+	if (odbc_obj->state != ODBC_STATE_CONNECTED) {
+		goto done;
+	}
 
-    if (odbc_obj->stmt) {
-        if ((result = SQLFetch(odbc_obj->stmt) == SQL_SUCCESS)) {
-            tf = JS_TRUE;
-        }
-    }
+	if (odbc_obj->stmt) {
+		if ((result = SQLFetch(odbc_obj->stmt) == SQL_SUCCESS)) {
+			tf = JS_TRUE;
+		}
+	}
 
- done:
+  done:
 
-    *rval = BOOLEAN_TO_JSVAL( tf );
+	*rval = BOOLEAN_TO_JSVAL(tf);
 
-    return JS_TRUE;
+	return JS_TRUE;
 }
 
 static char *escape_data(char *in)
 {
-    switch_size_t nlen = strlen(in);
-    uint32_t qc = 0;
-    char *p, *q, *r;
-
-    for(p = in; p && *p; p++) {
-        if (*p == '"') {
-            qc += 2;
-        }
-    }
-    
-    nlen += qc + 1;
-
-    if (!(q = (char *) malloc(nlen))) {
-        return NULL;
-    }
-
-    r = q;
-    qc = 0;
-    for(p = in; p && *p; p++) {
-        if (*p == '"') {
-            *r++ = '\\';
-        }
-        *r++ = *p;
-        if (++qc > nlen) {
-            break;
-        }
-    }
-    
-    *r++ = '\0';
-
-    return q;
-    
-}
-
-
-static JSBool odbc_get_data(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
-{
-
-    odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
-    JSBool tf = JS_FALSE;
-
-    if (odbc_obj->state != ODBC_STATE_CONNECTED) {
-        goto done;
-    }
-
-    if (odbc_obj->stmt) {
-        SQLSMALLINT c = 0, x = 0;
-        int result;
-        char code[66560];
-
-        snprintf(code, sizeof(code), "~var _oDbC_dB_RoW_DaTa_ = {}");
-        eval_some_js(code, cx, obj, rval);
-        if (*rval == JS_FALSE) {
-            return JS_TRUE; 
-        }
-
-        result = SQLNumResultCols(odbc_obj->stmt, &c);
-        if (result == SQL_SUCCESS || result == SQL_SUCCESS_WITH_INFO) {
-            for (x = 1; x <= c; x++) {
-                SQLSMALLINT NameLength, DataType, DecimalDigits, Nullable;
-                SQLUINTEGER ColumnSize;
-                SQLCHAR name[1024] = "";
-                SQLCHAR *data = odbc_obj->colbuf;
-                SQLCHAR *esc = NULL;
-
-                SQLDescribeCol(odbc_obj->stmt, x, name, sizeof(name), &NameLength, &DataType, &ColumnSize, &DecimalDigits, &Nullable);
-                SQLGetData(odbc_obj->stmt, x, SQL_C_CHAR, odbc_obj->colbuf, odbc_obj->cblen, NULL);
-                
-                if (strchr((char *)odbc_obj->colbuf, '"')) { /* please don't */
-                    esc = (SQLCHAR *) escape_data((char *)odbc_obj->colbuf);
-                    data = esc;
-                }
-
-                snprintf((char *)odbc_obj->code, odbc_obj->codelen, "~_oDbC_dB_RoW_DaTa_[\"%s\"] = \"%s\"", name, data);
-                switch_safe_free(esc);
-
-                eval_some_js((char *)odbc_obj->code, cx, obj, rval);
-
-                if (*rval == JS_FALSE) {
-                    return JS_TRUE; 
-                }
-            }
-
-            JS_GetProperty(cx, obj, "_oDbC_dB_RoW_DaTa_", rval);
-            return JS_TRUE; 
-        }
+	switch_size_t nlen = strlen(in);
+	uint32_t qc = 0;
+	char *p, *q, *r;
+
+	for (p = in; p && *p; p++) {
+		if (*p == '"') {
+			qc += 2;
+		}
+	}
+
+	nlen += qc + 1;
+
+	if (!(q = (char *) malloc(nlen))) {
+		return NULL;
+	}
+
+	r = q;
+	qc = 0;
+	for (p = in; p && *p; p++) {
+		if (*p == '"') {
+			*r++ = '\\';
+		}
+		*r++ = *p;
+		if (++qc > nlen) {
+			break;
+		}
+	}
+
+	*r++ = '\0';
+
+	return q;
+
+}
+
+
+static JSBool odbc_get_data(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
+{
+
+	odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
+	JSBool tf = JS_FALSE;
 
-    }
+	if (odbc_obj->state != ODBC_STATE_CONNECTED) {
+		goto done;
+	}
+
+	if (odbc_obj->stmt) {
+		SQLSMALLINT c = 0, x = 0;
+		int result;
+		char code[66560];
+
+		snprintf(code, sizeof(code), "~var _oDbC_dB_RoW_DaTa_ = {}");
+		eval_some_js(code, cx, obj, rval);
+		if (*rval == JS_FALSE) {
+			return JS_TRUE;
+		}
+
+		result = SQLNumResultCols(odbc_obj->stmt, &c);
+		if (result == SQL_SUCCESS || result == SQL_SUCCESS_WITH_INFO) {
+			for (x = 1; x <= c; x++) {
+				SQLSMALLINT NameLength, DataType, DecimalDigits, Nullable;
+				SQLUINTEGER ColumnSize;
+				SQLCHAR name[1024] = "";
+				SQLCHAR *data = odbc_obj->colbuf;
+				SQLCHAR *esc = NULL;
+
+				SQLDescribeCol(odbc_obj->stmt, x, name, sizeof(name), &NameLength, &DataType, &ColumnSize, &DecimalDigits, &Nullable);
+				SQLGetData(odbc_obj->stmt, x, SQL_C_CHAR, odbc_obj->colbuf, odbc_obj->cblen, NULL);
+
+				if (strchr((char *) odbc_obj->colbuf, '"')) {	/* please don't */
+					esc = (SQLCHAR *) escape_data((char *) odbc_obj->colbuf);
+					data = esc;
+				}
+
+				snprintf((char *) odbc_obj->code, odbc_obj->codelen, "~_oDbC_dB_RoW_DaTa_[\"%s\"] = \"%s\"", name, data);
+				switch_safe_free(esc);
+
+				eval_some_js((char *) odbc_obj->code, cx, obj, rval);
+
+				if (*rval == JS_FALSE) {
+					return JS_TRUE;
+				}
+			}
+
+			JS_GetProperty(cx, obj, "_oDbC_dB_RoW_DaTa_", rval);
+			return JS_TRUE;
+		}
 
- done:
+	}
 
-    *rval = BOOLEAN_TO_JSVAL( tf );
+  done:
 
-    return JS_TRUE;
+	*rval = BOOLEAN_TO_JSVAL(tf);
+
+	return JS_TRUE;
 
 }
 
@@ -492,50 +489,40 @@
 
 
 static JSPropertySpec odbc_props[] = {
-//	{"name", odbc_NAME, JSPROP_READONLY|JSPROP_PERMANENT}, 
+//  {"name", odbc_NAME, JSPROP_READONLY|JSPROP_PERMANENT}, 
 	{0}
 };
 
 
-static JSBool odbc_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
+static JSBool odbc_getProperty(JSContext * cx, JSObject * obj, jsval id, jsval * vp)
 {
 	JSBool res = JS_TRUE;
-    
+
 	return res;
 }
 
 JSClass odbc_class = {
-	modname, JSCLASS_HAS_PRIVATE, 
-	JS_PropertyStub,  JS_PropertyStub,	odbc_getProperty,  JS_PropertyStub, 
-	JS_EnumerateStub, JS_ResolveStub,	JS_ConvertStub,	  odbc_destroy, NULL, NULL, NULL,
+	modname, JSCLASS_HAS_PRIVATE,
+	JS_PropertyStub, JS_PropertyStub, odbc_getProperty, JS_PropertyStub,
+	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, odbc_destroy, NULL, NULL, NULL,
 	odbc_construct
 };
 
 
-switch_status_t odbc_load(JSContext *cx, JSObject *obj)
+switch_status_t odbc_load(JSContext * cx, JSObject * obj)
 {
-	JS_InitClass(cx,
-				 obj,
-				 NULL,
-				 &odbc_class,
-				 odbc_construct,
-				 3,
-				 odbc_props,
-				 odbc_methods,
-				 odbc_props,
-				 odbc_methods
-				 );
+	JS_InitClass(cx, obj, NULL, &odbc_class, odbc_construct, 3, odbc_props, odbc_methods, odbc_props, odbc_methods);
 	return SWITCH_STATUS_SUCCESS;
 }
 
 
 const sm_module_interface_t odbc_module_interface = {
 	/*.name = */ modname,
-	/*.spidermonkey_load*/ odbc_load,
-	/*.next*/ NULL
+	/*.spidermonkey_load */ odbc_load,
+	/*.next */ NULL
 };
 
-SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t **module_interface)
+SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t ** module_interface)
 {
 	*module_interface = &odbc_module_interface;
 	return SWITCH_STATUS_SUCCESS;

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey_skel/mod_spidermonkey_skel.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey_skel/mod_spidermonkey_skel.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey_skel/mod_spidermonkey_skel.c	Fri Mar 30 12:19:18 2007
@@ -35,16 +35,16 @@
 
 /* Skel Object */
 /*********************************************************************************/
-static JSBool skel_construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool skel_construct(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	return JS_TRUE;
 }
 
-static void skel_destroy(JSContext *cx, JSObject *obj)
+static void skel_destroy(JSContext * cx, JSObject * obj)
 {
 }
 
-static JSBool skel_my_method(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool skel_my_method(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	return JS_FALSE;
 }
@@ -60,12 +60,12 @@
 
 
 static JSPropertySpec skel_props[] = {
-	{"name", SKEL_NAME, JSPROP_READONLY|JSPROP_PERMANENT}, 
+	{"name", SKEL_NAME, JSPROP_READONLY | JSPROP_PERMANENT},
 	{0}
 };
 
 
-static JSBool skel_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
+static JSBool skel_getProperty(JSContext * cx, JSObject * obj, jsval id, jsval * vp)
 {
 	JSBool res = JS_TRUE;
 
@@ -73,37 +73,27 @@
 }
 
 JSClass skel_class = {
-	modname, JSCLASS_HAS_PRIVATE, 
-	JS_PropertyStub,  JS_PropertyStub,	skel_getProperty,  JS_PropertyStub, 
-	JS_EnumerateStub, JS_ResolveStub,	JS_ConvertStub,	  skel_destroy, NULL, NULL, NULL,
+	modname, JSCLASS_HAS_PRIVATE,
+	JS_PropertyStub, JS_PropertyStub, skel_getProperty, JS_PropertyStub,
+	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, skel_destroy, NULL, NULL, NULL,
 	skel_construct
 };
 
 
-switch_status_t spidermonkey_load(JSContext *cx, JSObject *obj)
+switch_status_t spidermonkey_load(JSContext * cx, JSObject * obj)
 {
-	JS_InitClass(cx,
-				 obj,
-				 NULL,
-				 &skel_class,
-				 skel_construct,
-				 3,
-				 skel_props,
-				 skel_methods,
-				 skel_props,
-				 skel_methods
-				 );
+	JS_InitClass(cx, obj, NULL, &skel_class, skel_construct, 3, skel_props, skel_methods, skel_props, skel_methods);
 	return SWITCH_STATUS_SUCCESS;
 }
 
 
 const sm_module_interface_t skel_module_interface = {
 	/*.name = */ modname,
-	/*.spidermonkey_load*/ spidermonkey_load,
-	/*.next*/ NULL
+	/*.spidermonkey_load */ spidermonkey_load,
+	/*.next */ NULL
 };
 
-SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t **module_interface)
+SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t ** module_interface)
 {
 	*module_interface = &skel_module_interface;
 	return SWITCH_STATUS_SUCCESS;

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey_teletone/mod_spidermonkey_teletone.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey_teletone/mod_spidermonkey_teletone.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey_teletone/mod_spidermonkey_teletone.c	Fri Mar 30 12:19:18 2007
@@ -57,7 +57,7 @@
 };
 
 
-static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map_t *map)
+static int teletone_handler(teletone_generation_session_t * ts, teletone_tone_map_t * map)
 {
 	struct teletone_obj *tto = ts->user_data;
 	int wrote;
@@ -74,7 +74,7 @@
 
 /* TeleTone Object */
 /*********************************************************************************/
-static JSBool teletone_construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool teletone_construct(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	JSObject *session_obj;
 	struct teletone_obj *tto = NULL;
@@ -116,8 +116,7 @@
 							   read_codec->implementation->samples_per_second,
 							   read_codec->implementation->microseconds_per_frame / 1000,
 							   read_codec->implementation->number_of_channels,
-							   SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
-							   NULL, pool) == SWITCH_STATUS_SUCCESS) {
+							   SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, pool) == SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activated\n");
 	} else {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activation Failed\n");
@@ -129,8 +128,8 @@
 		if (switch_core_timer_init(&tto->timer_base,
 								   timer_name,
 								   ms,
-								   (read_codec->implementation->samples_per_second / 50) * read_codec->implementation->number_of_channels,
-								   pool) == SWITCH_STATUS_SUCCESS) {
+								   (read_codec->implementation->samples_per_second / 50) *
+								   read_codec->implementation->number_of_channels, pool) == SWITCH_STATUS_SUCCESS) {
 			tto->timer = &tto->timer_base;
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Timer INIT Success %u\n", ms);
 		} else {
@@ -149,7 +148,7 @@
 	return JS_TRUE;
 }
 
-static void teletone_destroy(JSContext *cx, JSObject *obj)
+static void teletone_destroy(JSContext * cx, JSObject * obj)
 {
 	struct teletone_obj *tto = JS_GetPrivate(cx, obj);
 	switch_memory_pool_t *pool;
@@ -169,26 +168,26 @@
 	}
 }
 
-static JSBool teletone_add_tone(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool teletone_add_tone(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct teletone_obj *tto = JS_GetPrivate(cx, obj);
-	if (argc > 2) { 
+	if (argc > 2) {
 		int x;
 		char *fval;
 		char *map_str;
 		map_str = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
 
-		for(x = 1; x < TELETONE_MAX_TONES; x++) {
+		for (x = 1; x < TELETONE_MAX_TONES; x++) {
 			fval = JS_GetStringBytes(JS_ValueToString(cx, argv[x]));
-			tto->ts.TONES[(int)*map_str].freqs[x-1] = strtod(fval, NULL);
+			tto->ts.TONES[(int) *map_str].freqs[x - 1] = strtod(fval, NULL);
 		}
 		return JS_TRUE;
 	}
-	
+
 	return JS_FALSE;
 }
 
-static JSBool teletone_on_dtmf(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool teletone_on_dtmf(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct teletone_obj *tto = JS_GetPrivate(cx, obj);
 	if (argc > 0) {
@@ -201,7 +200,7 @@
 	return JS_TRUE;
 }
 
-static JSBool teletone_generate(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool teletone_generate(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct teletone_obj *tto = JS_GetPrivate(cx, obj);
 	int32 loops = 0;
@@ -209,7 +208,7 @@
 	if (argc > 0) {
 		char *script;
 		switch_core_session_t *session;
-		switch_frame_t write_frame = {0};
+		switch_frame_t write_frame = { 0 };
 		unsigned char *fdata[1024];
 		switch_frame_t *read_frame;
 		int stream_id;
@@ -225,7 +224,7 @@
 			if (!tto->loop_buffer) {
 				switch_buffer_create_dynamic(&tto->loop_buffer, JS_BLOCK_SIZE, JS_BUFFER_SIZE, 0);
 			}
-		} 
+		}
 
 		if (tto->audio_buffer) {
 			switch_buffer_zero(tto->audio_buffer);
@@ -244,14 +243,14 @@
 		write_frame.data = fdata;
 
 		channel = switch_core_session_get_channel(session);
-		
+
 		if (tto->timer) {
 			for (stream_id = 0; stream_id < switch_core_session_get_stream_count(session); stream_id++) {
 				switch_core_service_session(session, &thread_session, stream_id);
 			}
 		}
 
-		for(;;) {
+		for (;;) {
 
 			if (switch_test_flag(tto, TTF_DTMF)) {
 				char dtmf[128];
@@ -262,7 +261,7 @@
 					jsval aargv[4];
 
 					switch_channel_dequeue_dtmf(channel, dtmf, sizeof(dtmf));
-					aargv[aargc++] = STRING_TO_JSVAL (JS_NewStringCopyZ(cx, dtmf));
+					aargv[aargc++] = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, dtmf));
 					JS_CallFunction(cx, obj, tto->function, aargc, aargv, &tto->ret);
 					ret = JS_GetStringBytes(JS_ValueToString(cx, tto->ret));
 					if (strcmp(ret, "true") && strcmp(ret, "undefined")) {
@@ -271,7 +270,7 @@
 					}
 				}
 			}
-			
+
 			if (tto->timer) {
 				if (switch_core_timer_next(tto->timer) != SWITCH_STATUS_SUCCESS) {
 					break;
@@ -280,23 +279,23 @@
 			} else {
 				switch_status_t status;
 				status = switch_core_session_read_frame(session, &read_frame, -1, 0);
-				
+
 				if (!SWITCH_READ_ACCEPTABLE(status)) {
 					break;
 				}
 			}
-			if ((write_frame.datalen = (uint32_t)switch_buffer_read(tto->audio_buffer, fdata, write_frame.codec->implementation->bytes_per_frame)) <= 0) {
-				if (loops) { 
+			if ((write_frame.datalen = (uint32_t) switch_buffer_read(tto->audio_buffer, fdata, write_frame.codec->implementation->bytes_per_frame)) <= 0) {
+				if (loops) {
 					switch_buffer_t *tmp;
 
-					/* Switcharoo*/
+					/* Switcharoo */
 					tmp = tto->audio_buffer;
 					tto->audio_buffer = tto->loop_buffer;
 					tto->loop_buffer = tmp;
 					loops--;
 					/* try again */
-					if ((write_frame.datalen = 
-						 (uint32_t)switch_buffer_read(tto->audio_buffer, fdata, write_frame.codec->implementation->bytes_per_frame)) <= 0) {
+					if ((write_frame.datalen =
+						 (uint32_t) switch_buffer_read(tto->audio_buffer, fdata, write_frame.codec->implementation->bytes_per_frame)) <= 0) {
 						break;
 					}
 				} else {
@@ -321,7 +320,7 @@
 		}
 		return JS_TRUE;
 	}
-	
+
 	return JS_FALSE;
 }
 
@@ -332,18 +331,18 @@
 static JSFunctionSpec teletone_methods[] = {
 	{"generate", teletone_generate, 1},
 	{"onDTMF", teletone_on_dtmf, 1},
-	{"addTone", teletone_add_tone, 10},	 
+	{"addTone", teletone_add_tone, 10},
 	{0}
 };
 
 
 static JSPropertySpec teletone_props[] = {
-	{"name", TELETONE_NAME, JSPROP_READONLY|JSPROP_PERMANENT}, 
+	{"name", TELETONE_NAME, JSPROP_READONLY | JSPROP_PERMANENT},
 	{0}
 };
 
 
-static JSBool teletone_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
+static JSBool teletone_getProperty(JSContext * cx, JSObject * obj, jsval id, jsval * vp)
 {
 	JSBool res = JS_TRUE;
 
@@ -351,37 +350,27 @@
 }
 
 JSClass teletone_class = {
-	modname, JSCLASS_HAS_PRIVATE, 
-	JS_PropertyStub,  JS_PropertyStub,	teletone_getProperty,  JS_PropertyStub, 
-	JS_EnumerateStub, JS_ResolveStub,	JS_ConvertStub,	  teletone_destroy, NULL, NULL, NULL,
+	modname, JSCLASS_HAS_PRIVATE,
+	JS_PropertyStub, JS_PropertyStub, teletone_getProperty, JS_PropertyStub,
+	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, teletone_destroy, NULL, NULL, NULL,
 	teletone_construct
 };
 
 
-switch_status_t teletone_load(JSContext *cx, JSObject *obj)
+switch_status_t teletone_load(JSContext * cx, JSObject * obj)
 {
-	JS_InitClass(cx,
-				 obj,
-				 NULL,
-				 &teletone_class,
-				 teletone_construct,
-				 3,
-				 teletone_props,
-				 teletone_methods,
-				 teletone_props,
-				 teletone_methods
-				 );
+	JS_InitClass(cx, obj, NULL, &teletone_class, teletone_construct, 3, teletone_props, teletone_methods, teletone_props, teletone_methods);
 	return SWITCH_STATUS_SUCCESS;
 }
 
 
 const sm_module_interface_t teletone_module_interface = {
 	/*.name = */ modname,
-	/*.spidermonkey_load*/ teletone_load,
-	/*.next*/ NULL
+	/*.spidermonkey_load */ teletone_load,
+	/*.next */ NULL
 };
 
-SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t **module_interface)
+SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t ** module_interface)
 {
 	*module_interface = &teletone_module_interface;
 	return SWITCH_STATUS_SUCCESS;

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/loggers/mod_console/mod_console.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/loggers/mod_console/mod_console.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/loggers/mod_console/mod_console.c	Fri Mar 30 12:19:18 2007
@@ -32,25 +32,26 @@
 #include <switch.h>
 
 static const char modname[] = "mod_console";
-static const uint8_t STATIC_LEVELS[] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
+static const uint8_t STATIC_LEVELS[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
 static int COLORIZE = 0;
 #ifdef WIN32
 static HANDLE hStdout;
 static WORD wOldColorAttrs;
 static CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
-static WORD COLORS[] =
-	{	FOREGROUND_RED | FOREGROUND_INTENSITY,
-		FOREGROUND_RED | FOREGROUND_INTENSITY,
-		FOREGROUND_RED | FOREGROUND_INTENSITY,
-		FOREGROUND_RED | FOREGROUND_INTENSITY,
-		FOREGROUND_BLUE | FOREGROUND_INTENSITY,
-		FOREGROUND_BLUE | FOREGROUND_INTENSITY,
-		FOREGROUND_GREEN | FOREGROUND_INTENSITY,
-		FOREGROUND_GREEN | FOREGROUND_INTENSITY,
-		FOREGROUND_GREEN | FOREGROUND_INTENSITY };
+static WORD COLORS[] = { FOREGROUND_RED | FOREGROUND_INTENSITY,
+	FOREGROUND_RED | FOREGROUND_INTENSITY,
+	FOREGROUND_RED | FOREGROUND_INTENSITY,
+	FOREGROUND_RED | FOREGROUND_INTENSITY,
+	FOREGROUND_BLUE | FOREGROUND_INTENSITY,
+	FOREGROUND_BLUE | FOREGROUND_INTENSITY,
+	FOREGROUND_GREEN | FOREGROUND_INTENSITY,
+	FOREGROUND_GREEN | FOREGROUND_INTENSITY,
+	FOREGROUND_GREEN | FOREGROUND_INTENSITY
+};
 #else
-static const char *COLORS[] = 
-	{ SWITCH_SEQ_FRED, SWITCH_SEQ_FRED, SWITCH_SEQ_FRED, SWITCH_SEQ_FRED, SWITCH_SEQ_FMAGEN, SWITCH_SEQ_FCYAN, SWITCH_SEQ_FGREEN, SWITCH_SEQ_FYELLOW, "" };
+static const char *COLORS[] = { SWITCH_SEQ_FRED, SWITCH_SEQ_FRED, SWITCH_SEQ_FRED, SWITCH_SEQ_FRED, SWITCH_SEQ_FMAGEN, SWITCH_SEQ_FCYAN,
+	SWITCH_SEQ_FGREEN, SWITCH_SEQ_FYELLOW, ""
+};
 #endif
 
 static switch_loadable_module_interface_t console_module_interface = {
@@ -71,7 +72,8 @@
 static switch_hash_t *name_hash = NULL;
 static int8_t all_level = -1;
 
-static void del_mapping(char *var) {
+static void del_mapping(char *var)
+{
 	if (!strcasecmp(var, "all")) {
 		all_level = -1;
 		return;
@@ -94,7 +96,7 @@
 	}
 
 	del_mapping(name);
-	switch_core_hash_insert(log_hash, name, (void *) &STATIC_LEVELS[(uint8_t)switch_log_str2level(val)]);
+	switch_core_hash_insert(log_hash, name, (void *) &STATIC_LEVELS[(uint8_t) switch_log_str2level(val)]);
 }
 
 static switch_status_t config_logger(void)
@@ -109,7 +111,7 @@
 
 	switch_core_hash_init(&log_hash, module_pool);
 	switch_core_hash_init(&name_hash, module_pool);
-	
+
 	if ((settings = switch_xml_child(cfg, "mappings"))) {
 		for (param = switch_xml_child(settings, "param"); param; param = param->next) {
 			char *var = (char *) switch_xml_attr_soft(param, "name");
@@ -127,8 +129,7 @@
 			if (!strcasecmp(var, "colorize") && switch_true(val)) {
 #ifdef WIN32
 				hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
-				if (switch_core_get_console() == stdout && hStdout != INVALID_HANDLE_VALUE 
-					&& GetConsoleScreenBufferInfo(hStdout, &csbiInfo)) {
+				if (switch_core_get_console() == stdout && hStdout != INVALID_HANDLE_VALUE && GetConsoleScreenBufferInfo(hStdout, &csbiInfo)) {
 					wOldColorAttrs = csbiInfo.wAttributes;
 					COLORIZE = 1;
 				}
@@ -150,11 +151,11 @@
 
 	if ((handle = switch_core_data_channel(SWITCH_CHANNEL_ID_LOG))) {
 		uint8_t *lookup = NULL;
-		switch_log_level_t level = SWITCH_LOG_DEBUG;		
+		switch_log_level_t level = SWITCH_LOG_DEBUG;
 
 		if (log_hash) {
 			lookup = switch_core_hash_find(log_hash, node->file);
-			
+
 			if (!lookup) {
 				lookup = switch_core_hash_find(log_hash, node->func);
 			}
@@ -164,13 +165,13 @@
 			level = (switch_log_level_t) *lookup;
 		} else if (all_level > -1) {
 			level = (switch_log_level_t) all_level;
-		} 
+		}
 
-		if (!log_hash || (((all_level > - 1) || lookup) && level >= node->level)) {
+		if (!log_hash || (((all_level > -1) || lookup) && level >= node->level)) {
 			if (COLORIZE) {
 #ifdef WIN32
 				SetConsoleTextAttribute(hStdout, COLORS[node->level]);
-				WriteFile(hStdout, node->data, (DWORD)strlen(node->data), NULL, NULL);
+				WriteFile(hStdout, node->data, (DWORD) strlen(node->data), NULL, NULL);
 				SetConsoleTextAttribute(hStdout, wOldColorAttrs);
 #else
 				fprintf(handle, "%s%s%s", COLORS[node->level], node->data, SWITCH_SEQ_DEFAULT_COLOR);
@@ -183,7 +184,7 @@
 		fprintf(stderr, "HELP I HAVE NO CONSOLE TO LOG TO!\n");
 		fflush(stderr);
 	}
-	
+
 	return SWITCH_STATUS_SUCCESS;
 }
 
@@ -200,7 +201,7 @@
 
 	/* setup my logger function */
 	switch_log_bind_logger(switch_console_logger, SWITCH_LOG_DEBUG);
-	
+
 	config_logger();
 
 	/* indicate that the module should continue to be loaded */

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/loggers/mod_syslog/mod_syslog.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/loggers/mod_syslog/mod_syslog.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/loggers/mod_syslog/mod_syslog.c	Fri Mar 30 12:19:18 2007
@@ -50,56 +50,56 @@
 } globals;
 
 SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_ident, globals.ident)
-SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_level, globals.level)
-SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_format, globals.format)
-SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_facility, globals.facility)
-
-static switch_loadable_module_interface_t console_module_interface = {
-	/*.module_name */ modname,
-	/*.endpoint_interface */ NULL,
-	/*.timer_interface */ NULL,
-	/*.dialplan_interface */ NULL,
-	/*.codec_interface */ NULL,
-	/*.application_interface */ NULL,
-	/*.api_interface */ NULL,
-	/*.file_interface */ NULL,
-	/*.speech_interface */ NULL,
-	/*.directory_interface */ NULL
-};
+	SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_level, globals.level)
+	SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_format, globals.format)
+	SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_facility, globals.facility)
+
+	 static switch_loadable_module_interface_t console_module_interface = {
+		 /*.module_name */ modname,
+		 /*.endpoint_interface */ NULL,
+		 /*.timer_interface */ NULL,
+		 /*.dialplan_interface */ NULL,
+		 /*.codec_interface */ NULL,
+		 /*.application_interface */ NULL,
+		 /*.api_interface */ NULL,
+		 /*.file_interface */ NULL,
+		 /*.speech_interface */ NULL,
+		 /*.directory_interface */ NULL
+	 };
 
 static switch_status_t mod_syslog_logger(const switch_log_node_t *node, switch_log_level_t level)
 {
 	char *message = NULL;
-	char line_no[sizeof(int)*8+1];
+	char line_no[sizeof(int) * 8 + 1];
 	char date[80] = "";
 	switch_time_exp_t time;
 	switch_size_t retsize;
 
-	message = (char *)malloc(strlen(globals.format)+2);
+	message = (char *) malloc(strlen(globals.format) + 2);
 
-	switch_copy_string(message, globals.format, strlen(globals.format)+1);
+	switch_copy_string(message, globals.format, strlen(globals.format) + 1);
 
 	message = switch_string_replace(message, "${message}", node->content);
-	
+
 	if (switch_time_exp_lt(&time, node->timestamp) != SWITCH_STATUS_SUCCESS) {
 		return SWITCH_STATUS_FALSE;
 	}
-	
+
 	switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &time);
 	message = switch_string_replace(message, "${time}", date);
-	
+
 	message = switch_string_replace(message, "${file}", node->file);
 	message = switch_string_replace(message, "${func}", node->func);
-	
+
 	snprintf(line_no, sizeof(line_no), "%d", node->line);
 	message = switch_string_replace(message, "${line}", line_no);
-	
+
 	if (!switch_strlen_zero(message)) {
 		syslog(LOG_ERR, "%s", message);
 	}
 
 	free(message);
-	
+
 	return SWITCH_STATUS_SUCCESS;
 }
 
@@ -125,7 +125,7 @@
 				} else if (!strcmp(var, "level")) {
 					set_global_level(val);;
 				}
-	
+
 			}
 		}
 		switch_xml_free(xml);
@@ -153,21 +153,21 @@
 	switch_status_t status;
 	*interface = &console_module_interface;
 
-	if ((status=load_config()) != SWITCH_STATUS_SUCCESS) {
+	if ((status = load_config()) != SWITCH_STATUS_SUCCESS) {
 		return status;
 	}
 
 	openlog(globals.ident, LOG_PID, LOG_USER);
 
 	switch_log_bind_logger(mod_syslog_logger, SWITCH_LOG_DEBUG);
-	
+
 	return SWITCH_STATUS_SUCCESS;
 }
 
 SWITCH_MOD_DECLARE(switch_status_t) switch_module_unload(const switch_loadable_module_interface_t **interface)
 {
 	closelog();
-	
+
 	return SWITCH_STATUS_SUCCESS;
 }
 

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/say/mod_say_en/mod_say_en.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/say/mod_say_en/mod_say_en.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/say/mod_say_en/mod_say_en.c	Fri Mar 30 12:19:18 2007
@@ -56,38 +56,27 @@
 		}}\
 
 
-static switch_status_t en_spell(switch_core_session_t *session,
-								char *tosay,
-								switch_say_type_t type,
-								switch_say_method_t method,
-								switch_input_args_t *args)
+static switch_status_t en_spell(switch_core_session_t *session, char *tosay, switch_say_type_t type, switch_say_method_t method, switch_input_args_t *args)
 {
 	char *p;
 
-	for(p = tosay; p && *p; p++) {
+	for (p = tosay; p && *p; p++) {
 		int a = tolower((int) *p);
-        if (a >= 48 && a <= 57) {
-            say_file("digits/%d.wav", a-48);
-        }
-        else {
-    		if (type == SST_NAME_SPELLED) {
-    			say_file("ascii/%d.wav", a);
-    		} else if (type == SST_NAME_PHONETIC) {
-    			say_file("phonetic-ascii/%d.wav", a);
-    		}
-        }
+		if (a >= 48 && a <= 57) {
+			say_file("digits/%d.wav", a - 48);
+		} else {
+			if (type == SST_NAME_SPELLED) {
+				say_file("ascii/%d.wav", a);
+			} else if (type == SST_NAME_PHONETIC) {
+				say_file("phonetic-ascii/%d.wav", a);
+			}
+		}
 	}
 
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t play_group(switch_say_method_t method,
-								  int a,
-								  int b,
-								  int c,
-								  char *what,
-								  switch_core_session_t *session,
-								  switch_input_args_t *args)
+static switch_status_t play_group(switch_say_method_t method, int a, int b, int c, char *what, switch_core_session_t *session, switch_input_args_t *args)
 {
 
 	if (a) {
@@ -118,14 +107,14 @@
 
 	return SWITCH_STATUS_SUCCESS;
 }
-					   
+
 static char *strip_commas(char *in, char *out, switch_size_t len)
 {
 	char *p = in, *q = out;
 	char *ret = out;
 	switch_size_t x = 0;
-	
-	for(;p && *p; p++) {
+
+	for (; p && *p; p++) {
 		if ((*p > 47 && *p < 58)) {
 			*q++ = *p;
 		} else if (*p != ',') {
@@ -148,10 +137,10 @@
 	char *ret = out;
 	switch_size_t x = 0;
 	// valid are 0 - 9, period (.), minus (-), and plus (+) - remove all others
-	for(;p && *p; p++) {
+	for (; p && *p; p++) {
 		if ((*p > 47 && *p < 58) || *p == '.' || *p == '-' || *p == '+') {
 			*q++ = *p;
-		} 
+		}
 
 		if (++x > len) {
 			ret = NULL;
@@ -163,17 +152,14 @@
 }
 
 static switch_status_t en_say_general_count(switch_core_session_t *session,
-											char *tosay,
-											switch_say_type_t type,
-											switch_say_method_t method,
-											switch_input_args_t *args)
+											char *tosay, switch_say_type_t type, switch_say_method_t method, switch_input_args_t *args)
 {
 	switch_channel_t *channel;
 	int in;
-	int x = 0, places[9] = {0};
+	int x = 0, places[9] = { 0 };
 	char sbuf[13] = "";
 	switch_status_t status;
-	
+
 	assert(session != NULL);
 	channel = switch_core_session_get_channel(session);
 	assert(channel != NULL);
@@ -186,13 +172,13 @@
 	in = atoi(tosay);
 
 	if (in != 0) {
-		for(x = 8; x >= 0; x--) {
-			int num = (int)pow(10, x);
+		for (x = 8; x >= 0; x--) {
+			int num = (int) pow(10, x);
 			if ((places[x] = in / num)) {
 				in -= places[x] * num;
 			}
 		}
-	
+
 		switch (method) {
 		case SSM_COUNTED:
 		case SSM_PRONOUNCED:
@@ -219,8 +205,7 @@
 		default:
 			break;
 		}
-	}
-	else {
+	} else {
 		say_file("digits/0.wav");
 	}
 
@@ -228,11 +213,7 @@
 }
 
 
-static switch_status_t en_ip(switch_core_session_t *session,
-								char *tosay,
-								switch_say_type_t type,
-								switch_say_method_t method,
-								switch_input_args_t *args)
+static switch_status_t en_ip(switch_core_session_t *session, char *tosay, switch_say_type_t type, switch_say_method_t method, switch_input_args_t *args)
 {
 	char *a, *b, *c, *d;
 	switch_status_t status = SWITCH_STATUS_SUCCESS;
@@ -269,23 +250,20 @@
 	say_file("digits/dot.wav");
 	say_num(atoi(d), method);
 
- done:
+  done:
 	switch_safe_free(a);
 	return status;
 }
 
 
-static switch_status_t en_say_time(switch_core_session_t *session,
-								   char *tosay,
-								   switch_say_type_t type,
-								   switch_say_method_t method,
+static switch_status_t en_say_time(switch_core_session_t *session, char *tosay, switch_say_type_t type, switch_say_method_t method,
 								   switch_input_args_t *args)
 {
 	int32_t t;
 	switch_time_t target = 0;
 	switch_time_exp_t tm;
 	uint8_t say_date = 0, say_time = 0;
-	
+
 	if (type == SST_TIME_MEASUREMENT) {
 		int64_t hours = 0;
 		int64_t minutes = 0;
@@ -295,7 +273,7 @@
 		if (strchr(tosay, ':')) {
 			char *tme = switch_core_session_strdup(session, tosay);
 			char *p;
-			
+
 			if ((p = strrchr(tme, ':'))) {
 				*p++ = '\0';
 				seconds = atoi(p);
@@ -305,10 +283,9 @@
 					if (tme) {
 						hours = atoi(tme);
 					}
+				} else {
+					minutes = atoi(tme);
 				}
-                else {
-                     minutes = atoi(tme);
-                }
 			}
 		} else {
 			if ((seconds = atoi(tosay)) <= 0) {
@@ -320,7 +297,7 @@
 				r = seconds % 60;
 				seconds = r;
 			}
-			
+
 			if (minutes >= 60) {
 				hours = minutes / 60;
 				r = minutes % 60;
@@ -330,45 +307,39 @@
 
 		if (hours) {
 			say_num(hours, SSM_PRONOUNCED);
-            if (hours == 1) {
-                say_file("time/hour.wav");  //TODO -- NEED TO GET "hour.wav" recorded
-            }
-            else {
-                say_file("time/hours.wav");
-            }
-		}
-        else {
-            say_file("digits/0.wav");
-            say_file("time/hours.wav");
-        }
+			if (hours == 1) {
+				say_file("time/hour.wav");	//TODO -- NEED TO GET "hour.wav" recorded
+			} else {
+				say_file("time/hours.wav");
+			}
+		} else {
+			say_file("digits/0.wav");
+			say_file("time/hours.wav");
+		}
 
 		if (minutes) {
 			say_num(minutes, SSM_PRONOUNCED);
-            if (minutes == 1) {
-                say_file("time/minute.wav");
-            }
-            else {
-                say_file("time/minutes.wav");
-            }
-		}
-        else {
-            say_file("digits/0.wav");
-            say_file("time/minutes.wav");
-        }
+			if (minutes == 1) {
+				say_file("time/minute.wav");
+			} else {
+				say_file("time/minutes.wav");
+			}
+		} else {
+			say_file("digits/0.wav");
+			say_file("time/minutes.wav");
+		}
 
 		if (seconds) {
 			say_num(seconds, SSM_PRONOUNCED);
-            if (seconds == 1) {
-                say_file("time/second.wav");
-            }
-            else {
-                say_file("time/seconds.wav");
-            }
-		}
-        else {
-            say_file("digits/0.wav");
-            say_file("time/seconds.wav");
-        }
+			if (seconds == 1) {
+				say_file("time/second.wav");
+			} else {
+				say_file("time/seconds.wav");
+			}
+		} else {
+			say_file("digits/0.wav");
+			say_file("time/seconds.wav");
+		}
 
 		return SWITCH_STATUS_SUCCESS;
 	}
@@ -379,8 +350,8 @@
 		target = switch_time_now();
 	}
 	switch_time_exp_lt(&tm, target);
-	
-	switch(type) {
+
+	switch (type) {
 	case SST_CURRENT_DATE_TIME:
 		say_date = say_time = 1;
 		break;
@@ -403,10 +374,10 @@
 
 	if (say_time) {
 		int32_t hour = tm.tm_hour, pm = 0;
-		
+
 		if (hour > 12) {
 			hour -= 12;
-            pm = 1;
+			pm = 1;
 		} else if (hour == 12) {
 			pm = 1;
 		} else if (hour == 0) {
@@ -432,22 +403,19 @@
 }
 
 
-static switch_status_t en_say_money(switch_core_session_t *session,
-											char *tosay,
-											switch_say_type_t type,
-											switch_say_method_t method,
-											switch_input_args_t *args)
+static switch_status_t en_say_money(switch_core_session_t *session, char *tosay, switch_say_type_t type, switch_say_method_t method,
+									switch_input_args_t *args)
 {
 	switch_channel_t *channel;
-		
-	char sbuf[16] = ""; /* enuough for 999,999,999,999.99 (w/o the commas or leading $) */
+
+	char sbuf[16] = "";			/* enuough for 999,999,999,999.99 (w/o the commas or leading $) */
 	char *dollars = NULL;
 	char *cents = NULL;
-		
+
 	assert(session != NULL);
 	channel = switch_core_session_get_channel(session);
 	assert(channel != NULL);
-			
+
 	if (strlen(tosay) > 15 || !(tosay = strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
 		return SWITCH_STATUS_GENERR;
@@ -457,64 +425,57 @@
 
 	if ((cents = strchr(sbuf, '.'))) {
 		*cents++ = '\0';
-        if (strlen(cents) > 2) {
-            cents[2] = '\0';
-        }
+		if (strlen(cents) > 2) {
+			cents[2] = '\0';
+		}
 	}
 
-    /* If positive sign - skip over" */
-    if (sbuf[0] == '+') {
-        dollars++;
-    }
+	/* If positive sign - skip over" */
+	if (sbuf[0] == '+') {
+		dollars++;
+	}
 
 	/* If negative say "negative" */
 	if (sbuf[0] == '-') {
 		say_file("currency/negative.wav");
 		dollars++;
 	}
-			
+
 	/* Say dollar amount */
 	en_say_general_count(session, dollars, type, method, args);
 	if (atoi(dollars) == 1) {
 		say_file("currency/dollar.wav");
-	}
-	else {
+	} else {
 		say_file("currency/dollars.wav");
 	}
-		
+
 	/* Say "and" */
 	say_file("currency/and.wav");
-	
-    /* Say cents */
-    if (cents) {
-        en_say_general_count(session, cents, type, method, args);
-        if (atoi(cents) == 1) {
-            say_file("currency/cent.wav");
-        }
-        else {
-            say_file("currency/cents.wav");
-        }
-    }
-    else {
-        say_file("digits/0.wav");
-        say_file("currency/cents.wav");
-    }
-	
+
+	/* Say cents */
+	if (cents) {
+		en_say_general_count(session, cents, type, method, args);
+		if (atoi(cents) == 1) {
+			say_file("currency/cent.wav");
+		} else {
+			say_file("currency/cents.wav");
+		}
+	} else {
+		say_file("digits/0.wav");
+		say_file("currency/cents.wav");
+	}
+
 	return SWITCH_STATUS_SUCCESS;
 }
 
 
 
-static switch_status_t en_say(switch_core_session_t *session,
-							  char *tosay,
-							  switch_say_type_t type,
-							  switch_say_method_t method,
-							  switch_input_args_t *args)
+static switch_status_t en_say(switch_core_session_t *session, char *tosay, switch_say_type_t type, switch_say_method_t method, switch_input_args_t *args)
 {
-	
+
 	switch_say_callback_t say_cb = NULL;
 
-	switch(type) {
+	switch (type) {
 	case SST_NUMBER:
 	case SST_ITEMS:
 	case SST_PERSONS:
@@ -541,15 +502,15 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unknown Say type=[%d]\n", type);
 		break;
 	}
-	
+
 	if (say_cb) {
 		return say_cb(session, tosay, type, method, args);
-	} 
+	}
 
 	return SWITCH_STATUS_FALSE;
 }
 
-static const switch_say_interface_t en_say_interface= {
+static const switch_say_interface_t en_say_interface = {
 	/*.name */ "en",
 	/*.say_function */ en_say,
 };
@@ -566,8 +527,8 @@
 	/*.speech_interface */ NULL,
 	/*.directory_interface */ NULL,
 	/*.chat_interface */ NULL,
-	/*.say_inteface*/ &en_say_interface,
-	/*.asr_interface*/ NULL
+	/*.say_inteface */ &en_say_interface,
+	/*.asr_interface */ NULL
 };
 
 SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/timers/mod_softtimer/mod_softtimer.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/timers/mod_softtimer/mod_softtimer.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/timers/mod_softtimer/mod_softtimer.c	Fri Mar 30 12:19:18 2007
@@ -50,8 +50,8 @@
 #define MAX_ELEMENTS 1000
 
 struct timer_private {
-    switch_size_t reference;
-    switch_size_t start;
+	switch_size_t reference;
+	switch_size_t start;
 	uint32_t roll;
 	uint32_t ready;
 };
@@ -64,7 +64,7 @@
 };
 typedef struct timer_matrix timer_matrix_t;
 
-static timer_matrix_t TIMER_MATRIX[MAX_ELEMENTS+1];
+static timer_matrix_t TIMER_MATRIX[MAX_ELEMENTS + 1];
 
 #define IDLE_SPEED 100
 
@@ -110,16 +110,16 @@
 
 	check_roll();
 	samples = timer->samples * (private_info->reference - private_info->start);
-	
+
 	if (samples > UINT32_MAX) {
 		private_info->start = private_info->reference;
 		samples = timer->samples;
 	}
-	
-	timer->samplecount = (uint32_t)samples;
-    private_info->reference++;
 
-    return SWITCH_STATUS_SUCCESS;
+	timer->samplecount = (uint32_t) samples;
+	private_info->reference++;
+
+	return SWITCH_STATUS_SUCCESS;
 }
 
 
@@ -129,12 +129,12 @@
 
 	timer_step(timer);
 
-	while (globals.RUNNING == 1 && private_info->ready  && TIMER_MATRIX[timer->interval].tick < private_info->reference) {
+	while (globals.RUNNING == 1 && private_info->ready && TIMER_MATRIX[timer->interval].tick < private_info->reference) {
 		check_roll();
 		switch_yield(1000);
 	}
 
-	if (globals.RUNNING == 1) {		
+	if (globals.RUNNING == 1) {
 		return SWITCH_STATUS_SUCCESS;
 	}
 
@@ -142,11 +142,10 @@
 }
 
 static inline switch_status_t timer_check(switch_timer_t *timer)
-
 {
 	timer_private_t *private_info = timer->private_info;
 	switch_status_t status = SWITCH_STATUS_SUCCESS;
-    switch_size_t diff;
+	switch_size_t diff;
 
 	if (globals.RUNNING != 1 || !private_info->ready) {
 		return SWITCH_STATUS_SUCCESS;
@@ -155,16 +154,16 @@
 	check_roll();
 
 	if (TIMER_MATRIX[timer->interval].tick < private_info->reference) {
-        diff = private_info->reference - TIMER_MATRIX[timer->interval].tick;
+		diff = private_info->reference - TIMER_MATRIX[timer->interval].tick;
 	} else {
-        diff = 0;
+		diff = 0;
 	}
 
-    if (diff) {
-        status = SWITCH_STATUS_FALSE;
-    } else {
-        timer_step(timer);
-    }
+	if (diff) {
+		status = SWITCH_STATUS_FALSE;
+	} else {
+		timer_step(timer);
+	}
 
 	return status;
 }
@@ -224,13 +223,13 @@
 	switch_time_t reference = switch_time_now();
 	uint32_t current_ms = 0;
 	uint32_t x;
-	
+
 	memset(&globals, 0, sizeof(globals));
 	switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, module_pool);
 
 	globals.RUNNING = 1;
 
-	while(globals.RUNNING == 1) {
+	while (globals.RUNNING == 1) {
 		reference += STEP_MIC;
 
 		while (switch_time_now() < reference) {
@@ -244,8 +243,8 @@
 			if (i == 0) {
 				i = 1;
 			}
-			
-			index = (current_ms % i == 0) ? i : 0; 
+
+			index = (current_ms % i == 0) ? i : 0;
 
 			if (TIMER_MATRIX[index].count) {
 				TIMER_MATRIX[index].tick++;
@@ -271,12 +270,12 @@
 
 SWITCH_MOD_DECLARE(switch_status_t) switch_module_shutdown(void)
 {
-	
+
 	if (globals.RUNNING) {
 		switch_mutex_lock(globals.mutex);
 		globals.RUNNING = -1;
 		switch_mutex_unlock(globals.mutex);
-		
+
 		while (globals.RUNNING) {
 			switch_yield(10000);
 		}

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c	Fri Mar 30 12:19:18 2007
@@ -37,7 +37,7 @@
 static switch_status_t my_on_hangup(switch_core_session_t *session)
 {
 	switch_xml_t cdr;
-	
+
 	if (switch_ivr_generate_xml_cdr(session, &cdr) == SWITCH_STATUS_SUCCESS) {
 		switch_channel_t *channel = switch_core_session_get_channel(session);
 		char *xml_text;
@@ -51,16 +51,16 @@
 		if ((alt = switch_channel_get_variable(channel, "xml_cdr_base"))) {
 			logdir = alt;
 		}
-		
+
 		if ((path = switch_mprintf("%s/xml_cdr/%s.cdr.xml", logdir, uuid_str))) {
 			if ((xml_text = switch_xml_toxml(cdr))) {
-				if ((fd = open(path, O_WRONLY | O_CREAT | O_TRUNC,  S_IRUSR | S_IWUSR)) > -1) {
-					write(fd, header, (unsigned)strlen(header));
-					write(fd, xml_text, (unsigned)strlen(xml_text));
+				if ((fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) > -1) {
+					write(fd, header, (unsigned) strlen(header));
+					write(fd, xml_text, (unsigned) strlen(xml_text));
 					close(fd);
 					fd = -1;
 				} else {
-					char ebuf[512] = {0};
+					char ebuf[512] = { 0 };
 #ifdef WIN32
 					strerror_s(ebuf, sizeof(ebuf), errno);
 #else
@@ -77,7 +77,7 @@
 	} else {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Generating Data!\n");
 	}
-	
+
 	return SWITCH_STATUS_SUCCESS;
 }
 

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/xml_int/mod_xml_curl/mod_xml_curl.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/xml_int/mod_xml_curl/mod_xml_curl.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/xml_int/mod_xml_curl/mod_xml_curl.c	Fri Mar 30 12:19:18 2007
@@ -36,7 +36,7 @@
 struct xml_binding {
 	char *url;
 	char *bindings;
-    char *cred;
+	char *cred;
 };
 
 typedef struct xml_binding xml_binding_t;
@@ -48,7 +48,7 @@
 
 static size_t file_callback(void *ptr, size_t size, size_t nmemb, void *data)
 {
-	register unsigned int realsize = (unsigned int)(size * nmemb);
+	register unsigned int realsize = (unsigned int) (size * nmemb);
 	struct config_data *config_data = data;
 
 	write(config_data->fd, ptr, realsize);
@@ -56,47 +56,42 @@
 }
 
 
-static switch_xml_t xml_url_fetch(const char *section,
-								  const char *tag_name,
-								  const char *key_name,
-								  const char *key_value,
-								  const char *params,
-                                  void *user_data)
+static switch_xml_t xml_url_fetch(const char *section, const char *tag_name, const char *key_name, const char *key_value, const char *params,
+								  void *user_data)
 {
 	char filename[512] = "";
 	CURL *curl_handle = NULL;
 	struct config_data config_data;
 	switch_xml_t xml = NULL;
-    char *data = NULL;
+	char *data = NULL;
 	switch_uuid_t uuid;
 	char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
-    xml_binding_t *binding = (xml_binding_t *) user_data;
-    char *file_url;
+	xml_binding_t *binding = (xml_binding_t *) user_data;
+	char *file_url;
 
-    if (!binding) {
-        return NULL;
-    }
-
-    if ((file_url = strstr(binding->url, "file:"))) {
-        file_url += 5;
-     
-        if (!(xml = switch_xml_parse_file(file_url))) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Parsing Result!\n");
-        }
-   
-        return xml;
-    }
-
-    if (!(data = switch_mprintf("section=%s&tag_name=%s&key_name=%s&key_value=%s%s%s", 
-                                section,
-                                tag_name ? tag_name : "",
-                                key_name ? key_name : "",
-                                key_value ? key_value : "",
-                                params ? strchr(params,'=') ? "&" : "&params=" : "", params ? params : ""))) {
-
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
-        return NULL;
-    }
+	if (!binding) {
+		return NULL;
+	}
+
+	if ((file_url = strstr(binding->url, "file:"))) {
+		file_url += 5;
+
+		if (!(xml = switch_xml_parse_file(file_url))) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Parsing Result!\n");
+		}
+
+		return xml;
+	}
+
+	if (!(data = switch_mprintf("section=%s&tag_name=%s&key_name=%s&key_value=%s%s%s",
+								section,
+								tag_name ? tag_name : "",
+								key_name ? key_name : "",
+								key_value ? key_value : "", params ? strchr(params, '=') ? "&" : "&params=" : "", params ? params : ""))) {
+
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
+		return NULL;
+	}
 
 	switch_uuid_get(&uuid);
 	switch_uuid_format(uuid_str, &uuid);
@@ -107,18 +102,18 @@
 		curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0);
 		curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0);
 	}
-		
+
 	config_data.name = filename;
 	if ((config_data.fd = open(filename, O_CREAT | O_RDWR | O_TRUNC)) > -1) {
-        if (!switch_strlen_zero(binding->cred)) {
-            curl_easy_setopt(curl_handle, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
-            curl_easy_setopt(curl_handle, CURLOPT_USERPWD, binding->cred);
-        }
-        curl_easy_setopt(curl_handle, CURLOPT_POST, 1);
-        curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, data);
+		if (!switch_strlen_zero(binding->cred)) {
+			curl_easy_setopt(curl_handle, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
+			curl_easy_setopt(curl_handle, CURLOPT_USERPWD, binding->cred);
+		}
+		curl_easy_setopt(curl_handle, CURLOPT_POST, 1);
+		curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, data);
 		curl_easy_setopt(curl_handle, CURLOPT_URL, binding->url);
 		curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, file_callback);
-		curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&config_data);
+		curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *) &config_data);
 		curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "freeswitch-xml/1.0");
 		curl_easy_perform(curl_handle);
 		curl_easy_cleanup(curl_handle);
@@ -127,14 +122,14 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error!\n");
 	}
 
-    switch_safe_free(data);
+	switch_safe_free(data);
 
 	if (!(xml = switch_xml_parse_file(filename))) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Parsing Result!\n");
 	}
 
 	unlink(filename);
-	
+
 	return xml;
 }
 
@@ -152,12 +147,12 @@
 	/*.directory_interface */ NULL
 };
 
-static switch_status_t do_config(void) 
+static switch_status_t do_config(void)
 {
 	char *cf = "xml_curl.conf";
 	switch_xml_t cfg, xml, bindings_tag, binding_tag, param;
-    xml_binding_t *binding = NULL;
-    int x = 0;
+	xml_binding_t *binding = NULL;
+	int x = 0;
 
 	if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
@@ -165,56 +160,54 @@
 	}
 
 	if (!(bindings_tag = switch_xml_child(cfg, "bindings"))) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing <bindings> tag!\n");
-        return SWITCH_STATUS_FALSE;
-    }
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing <bindings> tag!\n");
+		return SWITCH_STATUS_FALSE;
+	}
 
 	for (binding_tag = switch_xml_child(bindings_tag, "binding"); binding_tag; binding_tag = binding_tag->next) {
-        char *bname = (char *) switch_xml_attr_soft(binding_tag, "name");
-        char *url = NULL;
-        char *bind_cred = NULL;
-        char *bind_mask = NULL;
+		char *bname = (char *) switch_xml_attr_soft(binding_tag, "name");
+		char *url = NULL;
+		char *bind_cred = NULL;
+		char *bind_mask = NULL;
 
 		for (param = switch_xml_child(binding_tag, "param"); param; param = param->next) {
 			char *var = (char *) switch_xml_attr_soft(param, "name");
 			char *val = (char *) switch_xml_attr_soft(param, "value");
-            if (!strcasecmp(var, "gateway-url")) {
+			if (!strcasecmp(var, "gateway-url")) {
 				bind_mask = (char *) switch_xml_attr_soft(param, "bindings");
-                if (val) {
-                    url = val;
-                }
+				if (val) {
+					url = val;
+				}
 			} else if (!strcasecmp(var, "gateway-credentials")) {
-                bind_cred = val;
-            }
+				bind_cred = val;
+			}
 		}
-        
-        if (!url) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Binding has no url!\n");
-            continue;
-        }
-
-        if (!(binding = malloc(sizeof(*binding)))) {
-            return SWITCH_STATUS_FALSE;
-        }
-        memset(binding, 0, sizeof(*binding));
-
-        binding->url = strdup(url);
-
-        if (bind_mask) {
-            binding->bindings = strdup(bind_mask);
-        }
-
-        if (bind_cred) {
-            binding->cred = strdup(bind_cred);
-        }
-        
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Binding [%s] XML Fetch Function [%s] [%s]\n", 
-                          switch_strlen_zero(bname) ? "N/A" : bname,
-                          binding->url,
-                          binding->bindings ? binding->bindings : "all");
+
+		if (!url) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Binding has no url!\n");
+			continue;
+		}
+
+		if (!(binding = malloc(sizeof(*binding)))) {
+			return SWITCH_STATUS_FALSE;
+		}
+		memset(binding, 0, sizeof(*binding));
+
+		binding->url = strdup(url);
+
+		if (bind_mask) {
+			binding->bindings = strdup(bind_mask);
+		}
+
+		if (bind_cred) {
+			binding->cred = strdup(bind_cred);
+		}
+
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Binding [%s] XML Fetch Function [%s] [%s]\n",
+						  switch_strlen_zero(bname) ? "N/A" : bname, binding->url, binding->bindings ? binding->bindings : "all");
 		switch_xml_bind_search_function(xml_url_fetch, switch_xml_parse_section_string(binding->bindings), binding);
-        x++;
-        binding = NULL;
+		x++;
+		binding = NULL;
 	}
 
 	switch_xml_free(xml);
@@ -229,10 +222,10 @@
 	*module_interface = &xml_curl_module_interface;
 
 	if (do_config() == SWITCH_STATUS_SUCCESS) {
-        curl_global_init(CURL_GLOBAL_ALL);
-    } else {
-        return SWITCH_STATUS_FALSE;
-    }
+		curl_global_init(CURL_GLOBAL_ALL);
+	} else {
+		return SWITCH_STATUS_FALSE;
+	}
 
 	/* indicate that the module should continue to be loaded */
 	return SWITCH_STATUS_SUCCESS;

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c	Fri Mar 30 12:19:18 2007
@@ -66,10 +66,10 @@
 } globals;
 
 SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_realm, globals.realm)
-SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_user, globals.user)
-SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_pass, globals.pass)
+	SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_user, globals.user)
+	SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_pass, globals.pass)
 
-static switch_status_t do_config(void) 
+	 static switch_status_t do_config(void)
 {
 	char *cf = "xml_rpc.conf";
 	switch_xml_t cfg, xml, settings, param;
@@ -93,11 +93,11 @@
 			} else if (!strcasecmp(var, "auth-pass")) {
 				pass = val;
 			} else if (!strcasecmp(var, "http-port")) {
-				globals.port = (uint16_t)atoi(val);
+				globals.port = (uint16_t) atoi(val);
 			}
 		}
 	}
-	
+
 	if (!globals.port) {
 		globals.port = 8080;
 	}
@@ -119,7 +119,7 @@
 
 	memset(&globals, 0, sizeof(globals));
 
-    do_config();
+	do_config();
 
 	/* indicate that the module should continue to be loaded */
 	return SWITCH_STATUS_SUCCESS;
@@ -136,73 +136,82 @@
 	va_start(ap, fmt);
 	ret = switch_vasprintf(&data, fmt, ap);
 	va_end(ap);
-	
+
 	if (data) {
 		ret = 0;
-		HTTPWrite(r, data, (uint32_t)strlen(data));
+		HTTPWrite(r, data, (uint32_t) strlen(data));
 		free(data);
 	}
-	
+
 	return ret ? SWITCH_STATUS_FALSE : SWITCH_STATUS_SUCCESS;
 }
 
 
-abyss_bool HandleHook(TSession *r)
+abyss_bool HandleHook(TSession * r)
 {
-    char *m = "text/html";
-	switch_stream_handle_t stream = {0};
+	char *m = "text/html";
+	switch_stream_handle_t stream = { 0 };
 	char *command;
 
 	stream.data = r;
 	stream.write_function = http_stream_write;
 
 	if (globals.realm) {
-		if (!RequestAuth(r,globals.realm, globals.user, globals.pass)) {
+		if (!RequestAuth(r, globals.realm, globals.user, globals.pass)) {
 			return TRUE;
 		}
 	}
 
 
 
-	if(strncmp(r->uri, "/api/", 5)) {
+	if (strncmp(r->uri, "/api/", 5)) {
 		return FALSE;
 	}
 
 	if (switch_event_create(&stream.event, SWITCH_EVENT_API) == SWITCH_STATUS_SUCCESS) {
-		if (r->uri) switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-URI", "%s", r->uri);
-		if (r->query) switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-QUERY", "%s", r->query);
-		if (r->host) switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-HOST", "%s", r->host);
-		if (r->from) switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-FROM", "%s", r->from);
-		if (r->useragent) switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-USER-AGENT", "%s", r->useragent);
-		if (r->referer) switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-REFERER", "%s", r->referer);
-		if (r->requestline) switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-REQUESTLINE", "%s", r->requestline);
-		if (r->user) switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-USER", "%s", r->user);
-		if (r->port) switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-PORT", "%u", r->port);
+		if (r->uri)
+			switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-URI", "%s", r->uri);
+		if (r->query)
+			switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-QUERY", "%s", r->query);
+		if (r->host)
+			switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-HOST", "%s", r->host);
+		if (r->from)
+			switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-FROM", "%s", r->from);
+		if (r->useragent)
+			switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-USER-AGENT", "%s", r->useragent);
+		if (r->referer)
+			switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-REFERER", "%s", r->referer);
+		if (r->requestline)
+			switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-REQUESTLINE", "%s", r->requestline);
+		if (r->user)
+			switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-USER", "%s", r->user);
+		if (r->port)
+			switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-PORT", "%u", r->port);
 	}
 
 	command = r->uri + 5;
-	
+
 	ResponseChunked(r);
-	ResponseStatus(r,200);
+	ResponseStatus(r, 200);
 	ResponseContentType(r, m);
-    ResponseWrite(r);
+	ResponseWrite(r);
 	switch_api_execute(command, r->query, NULL, &stream);
 	HTTPWriteEnd(r);
-    return TRUE;
+	return TRUE;
 }
 
 
-static xmlrpc_value *freeswitch_api(xmlrpc_env *const envP, xmlrpc_value *const paramArrayP, void *const userData) 
+static xmlrpc_value *freeswitch_api(xmlrpc_env * const envP, xmlrpc_value * const paramArrayP, void *const userData)
 {
 	char *command, *arg;
-	switch_stream_handle_t stream = {0};
+	switch_stream_handle_t stream = { 0 };
 	xmlrpc_value *val = NULL;
 
 
-    /* Parse our argument array. */
-    xmlrpc_decompose_value(envP, paramArrayP, "(ss)", &command, &arg);
-    if (envP->fault_occurred) {
-        return NULL;
+	/* Parse our argument array. */
+	xmlrpc_decompose_value(envP, paramArrayP, "(ss)", &command, &arg);
+	if (envP->fault_occurred) {
+		return NULL;
 	}
 
 	SWITCH_STANDARD_STREAM(stream);
@@ -217,17 +226,17 @@
 	return val;
 }
 
-static xmlrpc_value *freeswitch_man(xmlrpc_env *const envP, xmlrpc_value *const paramArrayP, void *const userData) 
+static xmlrpc_value *freeswitch_man(xmlrpc_env * const envP, xmlrpc_value * const paramArrayP, void *const userData)
 {
 	char *oid, *relative_oid, *s_action, *data;
 	char buf[SWITCH_MAX_MANAGEMENT_BUFFER_LEN] = "";
 	switch_management_action_t action = SMA_NONE;
 	xmlrpc_value *val;
 
-    /* Parse our argument array. */
-    xmlrpc_decompose_value(envP, paramArrayP, "(sss)", &oid, &s_action, &data);
-    if (envP->fault_occurred) {
-        return NULL;
+	/* Parse our argument array. */
+	xmlrpc_decompose_value(envP, paramArrayP, "(sss)", &oid, &s_action, &data);
+	if (envP->fault_occurred) {
+		return NULL;
 	}
 
 	if (!strncasecmp(oid, FREESWITCH_OID_PREFIX, strlen(FREESWITCH_OID_PREFIX))) {
@@ -262,46 +271,46 @@
 		snprintf(buf, sizeof(buf), "Invalid Action %s\n", s_action);
 	}
 
-    /* Return our result. */
-    val = xmlrpc_build_value(envP, "s", buf);
+	/* Return our result. */
+	val = xmlrpc_build_value(envP, "s", buf);
 
 
 	return val;
 }
 
-SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void) 
+SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
 {
-    TServer abyssServer;
-    xmlrpc_registry * registryP;
-    xmlrpc_env env;
+	TServer abyssServer;
+	xmlrpc_registry *registryP;
+	xmlrpc_env env;
 	char logfile[512];
 
 	globals.running = 1;
-    
-    xmlrpc_env_init(&env);
 
-    registryP = xmlrpc_registry_new(&env);
-	
-    xmlrpc_registry_add_method(&env, registryP, NULL, "freeswitch.api", &freeswitch_api, NULL);
-	xmlrpc_registry_add_method(&env, registryP, NULL,"freeswitch_api", &freeswitch_api, NULL);
-    xmlrpc_registry_add_method(&env, registryP, NULL, "freeswitch.management", &freeswitch_man, NULL);
-	xmlrpc_registry_add_method(&env, registryP, NULL,"freeswitch_management", &freeswitch_man, NULL);
+	xmlrpc_env_init(&env);
+
+	registryP = xmlrpc_registry_new(&env);
 
-    MIMETypeInit();
+	xmlrpc_registry_add_method(&env, registryP, NULL, "freeswitch.api", &freeswitch_api, NULL);
+	xmlrpc_registry_add_method(&env, registryP, NULL, "freeswitch_api", &freeswitch_api, NULL);
+	xmlrpc_registry_add_method(&env, registryP, NULL, "freeswitch.management", &freeswitch_man, NULL);
+	xmlrpc_registry_add_method(&env, registryP, NULL, "freeswitch_management", &freeswitch_man, NULL);
+
+	MIMETypeInit();
 	MIMETypeAdd("text/html", "html");
 
 	snprintf(logfile, sizeof(logfile), "%s%s%s", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR, "freeswitch_http.log");
-    ServerCreate(&abyssServer, "XmlRpcServer", globals.port, SWITCH_GLOBAL_dirs.htdocs_dir, logfile);
-    
-    xmlrpc_server_abyss_set_handler(&env, &abyssServer, "/RPC2", registryP);
+	ServerCreate(&abyssServer, "XmlRpcServer", globals.port, SWITCH_GLOBAL_dirs.htdocs_dir, logfile);
+
+	xmlrpc_server_abyss_set_handler(&env, &abyssServer, "/RPC2", registryP);
 
-    ServerInit(&abyssServer);
+	ServerInit(&abyssServer);
 	ServerAddHandler(&abyssServer, HandleHook);
-	
+
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Starting HTTP Port %d, DocRoot [%s]\n", globals.port, SWITCH_GLOBAL_dirs.htdocs_dir);
-    while (globals.running) {
-        ServerRunOnce2(&abyssServer, ABYSS_FOREGROUND);
-    }
+	while (globals.running) {
+		ServerRunOnce2(&abyssServer, ABYSS_FOREGROUND);
+	}
 
 
 	return SWITCH_STATUS_SUCCESS;

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/switch.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/switch.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/switch.c	Fri Mar 30 12:19:18 2007
@@ -69,7 +69,7 @@
 static void handle_SIGHUP(int sig)
 {
 	uint32_t arg = 0;
-	if(sig);
+	if (sig);
 	/* send shutdown signal to the freeswitch core */
 	switch_core_session_ctl(SCSC_SHUTDOWN, &arg);
 	return;
@@ -78,9 +78,9 @@
 /* kill a freeswitch process running in background mode */
 static int freeswitch_kill_background()
 {
-	FILE *f;				/* FILE handle to open the pid file */
-	char path[256] = "";    /* full path of the PID file */
-	pid_t pid = 0;			/* pid from the pid file */
+	FILE *f;					/* FILE handle to open the pid file */
+	char path[256] = "";		/* full path of the PID file */
+	pid_t pid = 0;				/* pid from the pid file */
 
 	/* set the globals so we can use the global paths. */
 	switch_core_set_globals();
@@ -139,10 +139,9 @@
 SERVICE_STATUS status;
 
 /* Handler function for service start/stop from the service */
-void WINAPI ServiceCtrlHandler( DWORD control )
+void WINAPI ServiceCtrlHandler(DWORD control)
 {
-	switch( control )
-	{
+	switch (control) {
 	case SERVICE_CONTROL_SHUTDOWN:
 	case SERVICE_CONTROL_STOP:
 		/* Shutdown freeswitch */
@@ -159,24 +158,24 @@
 		break;
 	}
 
-	SetServiceStatus( hStatus, &status );
+	SetServiceStatus(hStatus, &status);
 }
 
 /* the main service entry point */
-void WINAPI service_main( DWORD numArgs, char **args )
+void WINAPI service_main(DWORD numArgs, char **args)
 {
 	const char *err = NULL;		/* error value for return from freeswitch initialization */
 	/*  we have to initialize the service-specific stuff */
-	memset( &status, 0, sizeof(SERVICE_STATUS) );
+	memset(&status, 0, sizeof(SERVICE_STATUS));
 	status.dwServiceType = SERVICE_WIN32;
 	status.dwCurrentState = SERVICE_START_PENDING;
 	status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
 
 	/* register our handler for service control messages */
-	hStatus = RegisterServiceCtrlHandler( SERVICENAME, &ServiceCtrlHandler );
+	hStatus = RegisterServiceCtrlHandler(SERVICENAME, &ServiceCtrlHandler);
 
 	/* update the service status */
-	SetServiceStatus( hStatus, &status );
+	SetServiceStatus(hStatus, &status);
 
 	/* run freeswitch with elevated priority */
 	set_high_priority();
@@ -191,7 +190,7 @@
 	}
 
 	/* update the service status */
-	SetServiceStatus( hStatus, &status );
+	SetServiceStatus(hStatus, &status);
 }
 
 #endif
@@ -206,50 +205,47 @@
 #endif
 	int nc = 0;					/* TRUE if we are running in noconsole mode */
 	FILE *f;					/* file handle to the pid file */
-	pid_t pid = 0;				
-	int x;						
-	int die = 0;				
-    char *usageDesc;
+	pid_t pid = 0;
+	int x;
+	int die = 0;
+	char *usageDesc;
 	int alt_dirs = 0;
 
 #ifdef WIN32
-	SERVICE_TABLE_ENTRY dispatchTable[] =
-	{
-		{ SERVICENAME, &service_main },
-		{ NULL, NULL }
+	SERVICE_TABLE_ENTRY dispatchTable[] = {
+		{SERVICENAME, &service_main},
+		{NULL, NULL}
 	};
-    usageDesc = "these are the optional arguments you can pass to freeswitch\n"
-        "\t-service         -- start freeswitch as a service, cannot be used if loaded as a console app\n"
-        "\t-install         -- install freeswitch as a service\n"
-        "\t-uninstall       -- remove freeswitch as a service\n"
-        "\t-hp              -- enable high priority settings\n"
-        "\t-stop            -- stop freeswitch\n"
-        "\t-nc              -- do not output to a console and background\n"
-        "\t-conf [confdir]  -- specify an alternate config dir\n"
-        "\t-log [logdir]    -- specify an alternate log dir\n"
-        "\t-db [dbdir]      -- specify an alternate db dir\n";
+	usageDesc = "these are the optional arguments you can pass to freeswitch\n"
+		"\t-service         -- start freeswitch as a service, cannot be used if loaded as a console app\n"
+		"\t-install         -- install freeswitch as a service\n"
+		"\t-uninstall       -- remove freeswitch as a service\n"
+		"\t-hp              -- enable high priority settings\n"
+		"\t-stop            -- stop freeswitch\n"
+		"\t-nc              -- do not output to a console and background\n"
+		"\t-conf [confdir]  -- specify an alternate config dir\n"
+		"\t-log [logdir]    -- specify an alternate log dir\n" "\t-db [dbdir]      -- specify an alternate db dir\n";
 #else
-    usageDesc = "these are the optional arguments you can pass to freeswitch\n"
-        "\t-help            -- this message\n"
-        "\t-nf              -- no forking\n"
-        "\t-hp              -- enable high priority settings\n"
-        "\t-stop            -- stop freeswitch\n"
-        "\t-nc              -- do not output to a console and background\n"
-        "\t-conf [confdir]  -- specify an alternate config dir\n"
-        "\t-log [logdir]    -- specify an alternate log dir\n"
-        "\t-db [dbdir]      -- specify an alternate db dir\n";
+	usageDesc = "these are the optional arguments you can pass to freeswitch\n"
+		"\t-help            -- this message\n"
+		"\t-nf              -- no forking\n"
+		"\t-hp              -- enable high priority settings\n"
+		"\t-stop            -- stop freeswitch\n"
+		"\t-nc              -- do not output to a console and background\n"
+		"\t-conf [confdir]  -- specify an alternate config dir\n"
+		"\t-log [logdir]    -- specify an alternate log dir\n" "\t-db [dbdir]      -- specify an alternate db dir\n";
 
 #endif
 
 	for (x = 1; x < argc; x++) {
 		if (argv[x] && !strcmp(argv[x], "-help")) {
-			printf("%s\n",usageDesc);
-            exit(0);
+			printf("%s\n", usageDesc);
+			exit(0);
 		}
 #ifdef WIN32
 		if (x == 1) {
 			if (argv[x] && !strcmp(argv[x], "-service")) {
-				if(StartServiceCtrlDispatcher( dispatchTable ) == 0 ) {
+				if (StartServiceCtrlDispatcher(dispatchTable) == 0) {
 					/* Not loaded as a service */
 					fprintf(stderr, "Error Freeswitch loaded as a console app with -service option\n");
 					fprintf(stderr, "To install the service load freeswitch with -install\n");
@@ -260,32 +256,22 @@
 				char exePath[1024];
 				char servicePath[1024];
 
-				SC_HANDLE handle = OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS );
-				GetModuleFileName( NULL, exePath, 1024 );
+				SC_HANDLE handle = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
+				GetModuleFileName(NULL, exePath, 1024);
 				snprintf(servicePath, sizeof(servicePath), "%s -service", exePath);
-				CreateService(
-					handle,
-					SERVICENAME,
-					SERVICENAME,
-					GENERIC_READ | GENERIC_EXECUTE,
-					SERVICE_WIN32_OWN_PROCESS,
-					SERVICE_AUTO_START,
-					SERVICE_ERROR_IGNORE,
-					servicePath,
-					NULL,
-					NULL,
-					NULL,
-					NULL,
-					NULL
-					);
+				CreateService(handle,
+							  SERVICENAME,
+							  SERVICENAME,
+							  GENERIC_READ | GENERIC_EXECUTE,
+							  SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_IGNORE, servicePath, NULL, NULL, NULL, NULL, NULL);
 				exit(0);
 			}
 			if (argv[x] && !strcmp(argv[x], "-uninstall")) {
-				SC_HANDLE handle = OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS );
-				SC_HANDLE service = OpenService( handle, SERVICENAME, DELETE );
-				if( service != NULL ) {
+				SC_HANDLE handle = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
+				SC_HANDLE service = OpenService(handle, SERVICENAME, DELETE);
+				if (service != NULL) {
 					/* remove the service! */
-					DeleteService( service );
+					DeleteService(service);
 				}
 				exit(0);
 			}
@@ -309,49 +295,49 @@
 		}
 
 
-        if (argv[x] && !strcmp(argv[x], "-conf")) {
-            x++;
-            if (argv[x] && strlen(argv[x])) {
-                SWITCH_GLOBAL_dirs.conf_dir = (char *) malloc(strlen(argv[x])+1);
-                strcpy(SWITCH_GLOBAL_dirs.conf_dir,argv[x]);
+		if (argv[x] && !strcmp(argv[x], "-conf")) {
+			x++;
+			if (argv[x] && strlen(argv[x])) {
+				SWITCH_GLOBAL_dirs.conf_dir = (char *) malloc(strlen(argv[x]) + 1);
+				strcpy(SWITCH_GLOBAL_dirs.conf_dir, argv[x]);
 				alt_dirs++;
-            } else {
-                fprintf(stderr, "When using -conf you must specify a config directory\n");
-                return 255;
-            }
-        }
-
-        if (argv[x] && !strcmp(argv[x], "-log")) {
-            x++;
-            if (argv[x] && strlen(argv[x])) {
-                SWITCH_GLOBAL_dirs.log_dir = (char *) malloc(strlen(argv[x])+1);
-                strcpy(SWITCH_GLOBAL_dirs.log_dir,argv[x]);
+			} else {
+				fprintf(stderr, "When using -conf you must specify a config directory\n");
+				return 255;
+			}
+		}
+
+		if (argv[x] && !strcmp(argv[x], "-log")) {
+			x++;
+			if (argv[x] && strlen(argv[x])) {
+				SWITCH_GLOBAL_dirs.log_dir = (char *) malloc(strlen(argv[x]) + 1);
+				strcpy(SWITCH_GLOBAL_dirs.log_dir, argv[x]);
 				alt_dirs++;
-            } else {
-                fprintf(stderr, "When using -log you must specify a log directory\n");
-                return 255;
-            }
-        }
-
-        if (argv[x] && !strcmp(argv[x], "-db")) {
-            x++;
-            if (argv[x] && strlen(argv[x])) {
-                SWITCH_GLOBAL_dirs.db_dir = (char *) malloc(strlen(argv[x])+1);
-                strcpy(SWITCH_GLOBAL_dirs.db_dir,argv[x]);
+			} else {
+				fprintf(stderr, "When using -log you must specify a log directory\n");
+				return 255;
+			}
+		}
+
+		if (argv[x] && !strcmp(argv[x], "-db")) {
+			x++;
+			if (argv[x] && strlen(argv[x])) {
+				SWITCH_GLOBAL_dirs.db_dir = (char *) malloc(strlen(argv[x]) + 1);
+				strcpy(SWITCH_GLOBAL_dirs.db_dir, argv[x]);
 				alt_dirs++;
-            } else {
-                fprintf(stderr, "When using -db you must specify a db directory\n");
-                return 255;
-            }
-        }
-            
+			} else {
+				fprintf(stderr, "When using -db you must specify a db directory\n");
+				return 255;
+			}
+		}
+
 	}
 
 	if (die) {
 		return freeswitch_kill_background();
 	}
 
-	if (alt_dirs && alt_dirs !=3) {
+	if (alt_dirs && alt_dirs != 3) {
 		fprintf(stderr, "You must use -conf, -log, and -db together\n");
 		return 255;
 	}
@@ -365,7 +351,7 @@
 		FreeConsole();
 #else
 		if (!nf && (pid = fork())) {
-			fprintf(stderr, "%d Backgrounding.\n", (int)pid);
+			fprintf(stderr, "%d Backgrounding.\n", (int) pid);
 			exit(0);
 		}
 #endif

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/switch_apr.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/switch_apr.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/switch_apr.c	Fri Mar 30 12:19:18 2007
@@ -72,17 +72,17 @@
 
 /* Hash tables */
 
-SWITCH_DECLARE(switch_hash_index_t *) switch_hash_first(switch_memory_pool_t *p, switch_hash_t *ht)
+SWITCH_DECLARE(switch_hash_index_t *) switch_hash_first(switch_memory_pool_t *p, switch_hash_t * ht)
 {
 	return apr_hash_first(p, ht);
 }
 
-SWITCH_DECLARE(switch_hash_index_t *) switch_hash_next(switch_hash_index_t *ht)
+SWITCH_DECLARE(switch_hash_index_t *) switch_hash_next(switch_hash_index_t * ht)
 {
 	return apr_hash_next(ht);
 }
 
-SWITCH_DECLARE(void) switch_hash_this(switch_hash_index_t *hi, const void **key, switch_ssize_t *klen, void **val)
+SWITCH_DECLARE(void) switch_hash_this(switch_hash_index_t * hi, const void **key, switch_ssize_t *klen, void **val)
 {
 	apr_hash_this(hi, key, klen, val);
 }
@@ -92,32 +92,29 @@
 	return apr_hashfunc_default(key, klen);
 }
 
-SWITCH_DECLARE(switch_memory_pool_t *) switch_hash_pool_get(switch_hash_t *ht)
+SWITCH_DECLARE(switch_memory_pool_t *) switch_hash_pool_get(switch_hash_t * ht)
 {
 	return apr_hash_pool_get(ht);
 }
 
 /* DSO functions */
 
-SWITCH_DECLARE(switch_status_t) switch_dso_load(switch_dso_handle_t **res_handle, 
-                                       const char *path, switch_memory_pool_t *ctx)
+SWITCH_DECLARE(switch_status_t) switch_dso_load(switch_dso_handle_t ** res_handle, const char *path, switch_memory_pool_t *ctx)
 {
 	return apr_dso_load(res_handle, path, ctx);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_dso_unload(switch_dso_handle_t *handle)
+SWITCH_DECLARE(switch_status_t) switch_dso_unload(switch_dso_handle_t * handle)
 {
 	return apr_dso_unload(handle);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_dso_sym(switch_dso_handle_sym_t *ressym, 
-                                      switch_dso_handle_t *handle,
-                                      const char *symname)
+SWITCH_DECLARE(switch_status_t) switch_dso_sym(switch_dso_handle_sym_t * ressym, switch_dso_handle_t * handle, const char *symname)
 {
 	return apr_dso_sym(ressym, handle, symname);
 }
 
-SWITCH_DECLARE(const char *) switch_dso_error(switch_dso_handle_t *dso, char *buf, size_t bufsize)
+SWITCH_DECLARE(const char *) switch_dso_error(switch_dso_handle_t * dso, char *buf, size_t bufsize)
 {
 	return apr_dso_error(dso, buf, bufsize);
 }
@@ -125,22 +122,18 @@
 
 /* string functions */
 
-SWITCH_DECLARE(switch_status_t) switch_strftime(char *s,
-												switch_size_t *retsize,
-												switch_size_t max,
-												const char *format,
-												switch_time_exp_t *tm)
+SWITCH_DECLARE(switch_status_t) switch_strftime(char *s, switch_size_t *retsize, switch_size_t max, const char *format, switch_time_exp_t * tm)
 {
-	return apr_strftime(s, retsize, max, format, (apr_time_exp_t *)tm);
+	return apr_strftime(s, retsize, max, format, (apr_time_exp_t *) tm);
 }
 
 SWITCH_DECLARE(int) switch_snprintf(char *buf, switch_size_t len, const char *format, ...)
 {
-    va_list ap;
+	va_list ap;
 	int ret;
 	va_start(ap, format);
 	ret = apr_vsnprintf(buf, len, format, ap);
-    va_end(ap);
+	va_end(ap);
 	return ret;
 }
 
@@ -156,72 +149,69 @@
 
 /* thread read write lock functions */
 
-SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_create(switch_thread_rwlock_t **rwlock,
-                                                  switch_memory_pool_t *pool)
+SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_create(switch_thread_rwlock_t ** rwlock, switch_memory_pool_t *pool)
 {
 	return apr_thread_rwlock_create(rwlock, pool);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_destroy(switch_thread_rwlock_t *rwlock)
+SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_destroy(switch_thread_rwlock_t * rwlock)
 {
 	return apr_thread_rwlock_destroy(rwlock);
 }
 
-SWITCH_DECLARE(switch_memory_pool_t *) switch_thread_rwlock_pool_get(switch_thread_rwlock_t *rwlock)
+SWITCH_DECLARE(switch_memory_pool_t *) switch_thread_rwlock_pool_get(switch_thread_rwlock_t * rwlock)
 {
 	return apr_thread_rwlock_pool_get(rwlock);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_rdlock(switch_thread_rwlock_t *rwlock)
+SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_rdlock(switch_thread_rwlock_t * rwlock)
 {
 	return apr_thread_rwlock_rdlock(rwlock);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_tryrdlock(switch_thread_rwlock_t *rwlock)
+SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_tryrdlock(switch_thread_rwlock_t * rwlock)
 {
 	return apr_thread_rwlock_tryrdlock(rwlock);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_wrlock(switch_thread_rwlock_t *rwlock)
+SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_wrlock(switch_thread_rwlock_t * rwlock)
 {
 	return apr_thread_rwlock_wrlock(rwlock);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_trywrlock(switch_thread_rwlock_t *rwlock)
+SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_trywrlock(switch_thread_rwlock_t * rwlock)
 {
 	return apr_thread_rwlock_trywrlock(rwlock);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock)
+SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_unlock(switch_thread_rwlock_t * rwlock)
 {
 	return apr_thread_rwlock_unlock(rwlock);
 }
 
 /* thread mutex functions */
 
-SWITCH_DECLARE(switch_status_t) switch_mutex_init(switch_mutex_t **lock,
-												unsigned int flags,
-												switch_memory_pool_t *pool)
+SWITCH_DECLARE(switch_status_t) switch_mutex_init(switch_mutex_t ** lock, unsigned int flags, switch_memory_pool_t *pool)
 {
 	return apr_thread_mutex_create(lock, flags, pool);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_mutex_destroy(switch_mutex_t *lock)
+SWITCH_DECLARE(switch_status_t) switch_mutex_destroy(switch_mutex_t * lock)
 {
 	return apr_thread_mutex_destroy(lock);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_mutex_lock(switch_mutex_t *lock)
+SWITCH_DECLARE(switch_status_t) switch_mutex_lock(switch_mutex_t * lock)
 {
 	return apr_thread_mutex_lock(lock);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_mutex_unlock(switch_mutex_t *lock)
+SWITCH_DECLARE(switch_status_t) switch_mutex_unlock(switch_mutex_t * lock)
 {
 	return apr_thread_mutex_unlock(lock);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_mutex_trylock(switch_mutex_t *lock)
+SWITCH_DECLARE(switch_status_t) switch_mutex_trylock(switch_mutex_t * lock)
 {
 	return apr_thread_mutex_trylock(lock);
 }
@@ -230,27 +220,27 @@
 
 SWITCH_DECLARE(switch_time_t) switch_time_now(void)
 {
-	return (switch_time_t)apr_time_now();
+	return (switch_time_t) apr_time_now();
 }
 
-SWITCH_DECLARE(switch_status_t) switch_time_exp_gmt_get(switch_time_t *result, switch_time_exp_t *input)
+SWITCH_DECLARE(switch_status_t) switch_time_exp_gmt_get(switch_time_t * result, switch_time_exp_t * input)
 {
-	return apr_time_exp_gmt_get(result, (apr_time_exp_t *)input);
+	return apr_time_exp_gmt_get(result, (apr_time_exp_t *) input);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_time_exp_get(switch_time_t *result, switch_time_exp_t *input)
+SWITCH_DECLARE(switch_status_t) switch_time_exp_get(switch_time_t * result, switch_time_exp_t * input)
 {
-	return apr_time_exp_get(result, (apr_time_exp_t *)input);
+	return apr_time_exp_get(result, (apr_time_exp_t *) input);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_time_exp_lt(switch_time_exp_t *result, switch_time_t input)
+SWITCH_DECLARE(switch_status_t) switch_time_exp_lt(switch_time_exp_t * result, switch_time_t input)
 {
-	return apr_time_exp_lt((apr_time_exp_t *)result, input);
+	return apr_time_exp_lt((apr_time_exp_t *) result, input);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_time_exp_gmt(switch_time_exp_t *result, switch_time_t input)
+SWITCH_DECLARE(switch_status_t) switch_time_exp_gmt(switch_time_exp_t * result, switch_time_t input)
 {
-	return apr_time_exp_gmt((apr_time_exp_t *)result, input);
+	return apr_time_exp_gmt((apr_time_exp_t *) result, input);
 }
 
 SWITCH_DECLARE(void) switch_sleep(switch_interval_time_t t)
@@ -258,7 +248,7 @@
 #if defined(HAVE_USLEEP)
 	usleep(t);
 #elif defined(WIN32)
-	Sleep((DWORD)((t) / 1000));
+	Sleep((DWORD) ((t) / 1000));
 #else
 	apr_sleep(t);
 #endif
@@ -272,59 +262,60 @@
 
 SWITCH_DECLARE(switch_time_t) switch_time_make(switch_time_t sec, int32_t usec)
 {
-	return ((switch_time_t)(sec) * APR_USEC_PER_SEC + (switch_time_t)(usec));
+	return ((switch_time_t) (sec) * APR_USEC_PER_SEC + (switch_time_t) (usec));
 }
 
 
 /* Thread condition locks */
 
-SWITCH_DECLARE(switch_status_t) switch_thread_cond_create(switch_thread_cond_t **cond, switch_memory_pool_t *pool)
+SWITCH_DECLARE(switch_status_t) switch_thread_cond_create(switch_thread_cond_t ** cond, switch_memory_pool_t *pool)
 {
 	return apr_thread_cond_create(cond, pool);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_thread_cond_wait(switch_thread_cond_t *cond, switch_mutex_t *mutex)
+SWITCH_DECLARE(switch_status_t) switch_thread_cond_wait(switch_thread_cond_t * cond, switch_mutex_t * mutex)
 {
 	return apr_thread_cond_wait(cond, mutex);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_thread_cond_timedwait(switch_thread_cond_t *cond, switch_mutex_t *mutex, switch_interval_time_t timeout)
+SWITCH_DECLARE(switch_status_t) switch_thread_cond_timedwait(switch_thread_cond_t * cond, switch_mutex_t * mutex, switch_interval_time_t timeout)
 {
 	return apr_thread_cond_timedwait(cond, mutex, timeout);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_thread_cond_signal(switch_thread_cond_t *cond)
+SWITCH_DECLARE(switch_status_t) switch_thread_cond_signal(switch_thread_cond_t * cond)
 {
 	return apr_thread_cond_signal(cond);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_thread_cond_broadcast(switch_thread_cond_t *cond)
+SWITCH_DECLARE(switch_status_t) switch_thread_cond_broadcast(switch_thread_cond_t * cond)
 {
 	return apr_thread_cond_broadcast(cond);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_thread_cond_destroy(switch_thread_cond_t *cond)
+SWITCH_DECLARE(switch_status_t) switch_thread_cond_destroy(switch_thread_cond_t * cond)
 {
 	return apr_thread_cond_destroy(cond);
 }
 
 /* file i/o stubs */
 
-SWITCH_DECLARE(switch_status_t) switch_file_open(switch_file_t **newf, const char *fname, int32_t flag, switch_fileperms_t perm, switch_memory_pool_t *pool)
+SWITCH_DECLARE(switch_status_t) switch_file_open(switch_file_t ** newf, const char *fname, int32_t flag, switch_fileperms_t perm,
+												 switch_memory_pool_t *pool)
 {
 	return apr_file_open(newf, fname, flag, perm, pool);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_file_seek(switch_file_t *thefile, switch_seek_where_t where, int64_t *offset)
+SWITCH_DECLARE(switch_status_t) switch_file_seek(switch_file_t * thefile, switch_seek_where_t where, int64_t *offset)
 {
 	apr_status_t rv;
-	apr_off_t off = (apr_off_t)(*offset);
+	apr_off_t off = (apr_off_t) (*offset);
 	rv = apr_file_seek(thefile, where, &off);
-	*offset = (int64_t)off;
+	*offset = (int64_t) off;
 	return rv;
 }
 
-SWITCH_DECLARE(switch_status_t) switch_file_close(switch_file_t *thefile)
+SWITCH_DECLARE(switch_status_t) switch_file_close(switch_file_t * thefile)
 {
 	return apr_file_close(thefile);
 }
@@ -334,12 +325,12 @@
 	return apr_file_remove(path, pool);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_file_read(switch_file_t *thefile, void *buf, switch_size_t *nbytes)
+SWITCH_DECLARE(switch_status_t) switch_file_read(switch_file_t * thefile, void *buf, switch_size_t *nbytes)
 {
 	return apr_file_read(thefile, buf, nbytes);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_file_write(switch_file_t *thefile, const void *buf, switch_size_t *nbytes)
+SWITCH_DECLARE(switch_status_t) switch_file_write(switch_file_t * thefile, const void *buf, switch_size_t *nbytes)
 {
 	return apr_file_write(thefile, buf, nbytes);
 }
@@ -347,7 +338,7 @@
 SWITCH_DECLARE(switch_status_t) switch_file_exists(const char *filename)
 {
 	int32_t wanted = APR_FINFO_TYPE;
-	apr_finfo_t info = {0};
+	apr_finfo_t info = { 0 };
 	if (filename) {
 		apr_stat(&info, filename, wanted, NULL);
 		if (info.filetype != APR_NOFILE) {
@@ -360,101 +351,103 @@
 /* thread stubs */
 
 
-SWITCH_DECLARE(switch_status_t) switch_threadattr_create(switch_threadattr_t **new_attr, switch_memory_pool_t *pool)
+SWITCH_DECLARE(switch_status_t) switch_threadattr_create(switch_threadattr_t ** new_attr, switch_memory_pool_t *pool)
 {
 	return apr_threadattr_create(new_attr, pool);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_threadattr_detach_set(switch_threadattr_t *attr, int32_t on)
+SWITCH_DECLARE(switch_status_t) switch_threadattr_detach_set(switch_threadattr_t * attr, int32_t on)
 {
 	return apr_threadattr_detach_set(attr, on);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_threadattr_stacksize_set(switch_threadattr_t *attr, switch_size_t stacksize)
+SWITCH_DECLARE(switch_status_t) switch_threadattr_stacksize_set(switch_threadattr_t * attr, switch_size_t stacksize)
 {
 	return apr_threadattr_stacksize_set(attr, stacksize);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_thread_create(switch_thread_t **new_thread, switch_threadattr_t *attr, switch_thread_start_t func, void *data, switch_memory_pool_t *cont)
+SWITCH_DECLARE(switch_status_t) switch_thread_create(switch_thread_t ** new_thread, switch_threadattr_t * attr,
+													 switch_thread_start_t func, void *data, switch_memory_pool_t *cont)
 {
 	return apr_thread_create(new_thread, attr, func, data, cont);
 }
 
 /* socket stubs */
 
-SWITCH_DECLARE(switch_status_t) switch_socket_create(switch_socket_t **new_sock, int family, int type, int protocol, switch_memory_pool_t *pool)
+SWITCH_DECLARE(switch_status_t) switch_socket_create(switch_socket_t ** new_sock, int family, int type, int protocol, switch_memory_pool_t *pool)
 {
 	return apr_socket_create(new_sock, family, type, protocol, pool);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_socket_shutdown(switch_socket_t *sock, switch_shutdown_how_e how)
+SWITCH_DECLARE(switch_status_t) switch_socket_shutdown(switch_socket_t * sock, switch_shutdown_how_e how)
 {
 	return apr_socket_shutdown(sock, how);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_socket_close(switch_socket_t *sock)
+SWITCH_DECLARE(switch_status_t) switch_socket_close(switch_socket_t * sock)
 {
 	return apr_socket_close(sock);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_socket_bind(switch_socket_t *sock, switch_sockaddr_t *sa)
+SWITCH_DECLARE(switch_status_t) switch_socket_bind(switch_socket_t * sock, switch_sockaddr_t * sa)
 {
 	return apr_socket_bind(sock, sa);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_socket_listen(switch_socket_t *sock, int32_t backlog)
+SWITCH_DECLARE(switch_status_t) switch_socket_listen(switch_socket_t * sock, int32_t backlog)
 {
 	return apr_socket_listen(sock, backlog);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_socket_accept(switch_socket_t **new_sock, switch_socket_t *sock, switch_memory_pool_t *pool)
+SWITCH_DECLARE(switch_status_t) switch_socket_accept(switch_socket_t ** new_sock, switch_socket_t * sock, switch_memory_pool_t *pool)
 {
 	return apr_socket_accept(new_sock, sock, pool);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_socket_connect(switch_socket_t *sock, switch_sockaddr_t *sa)
+SWITCH_DECLARE(switch_status_t) switch_socket_connect(switch_socket_t * sock, switch_sockaddr_t * sa)
 {
 	return apr_socket_connect(sock, sa);
 }
 
 
-SWITCH_DECLARE(switch_status_t) switch_socket_send(switch_socket_t *sock, const char *buf, switch_size_t *len)
+SWITCH_DECLARE(switch_status_t) switch_socket_send(switch_socket_t * sock, const char *buf, switch_size_t *len)
 {
 	return apr_socket_send(sock, buf, len);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_socket_sendto(switch_socket_t *sock, switch_sockaddr_t *where, int32_t flags, const char *buf, switch_size_t *len)
+SWITCH_DECLARE(switch_status_t) switch_socket_sendto(switch_socket_t * sock, switch_sockaddr_t * where, int32_t flags, const char *buf, switch_size_t *len)
 {
 	return apr_socket_sendto(sock, where, flags, buf, len);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_socket_recv(switch_socket_t *sock, char *buf, switch_size_t *len)
+SWITCH_DECLARE(switch_status_t) switch_socket_recv(switch_socket_t * sock, char *buf, switch_size_t *len)
 {
 	return apr_socket_recv(sock, buf, len);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_sockaddr_info_get(switch_sockaddr_t **sa, const char *hostname, int32_t family, switch_port_t port, int32_t flags, switch_memory_pool_t *pool)
+SWITCH_DECLARE(switch_status_t) switch_sockaddr_info_get(switch_sockaddr_t ** sa, const char *hostname, int32_t family,
+														 switch_port_t port, int32_t flags, switch_memory_pool_t *pool)
 {
 	return apr_sockaddr_info_get(sa, hostname, family, port, flags, pool);
 }
 
 
-SWITCH_DECLARE(switch_status_t) switch_socket_opt_set(switch_socket_t *sock, int32_t opt, int32_t on)
+SWITCH_DECLARE(switch_status_t) switch_socket_opt_set(switch_socket_t * sock, int32_t opt, int32_t on)
 {
 	return apr_socket_opt_set(sock, opt, on);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_socket_timeout_set(switch_socket_t *sock, switch_interval_time_t t)
+SWITCH_DECLARE(switch_status_t) switch_socket_timeout_set(switch_socket_t * sock, switch_interval_time_t t)
 {
 	return apr_socket_timeout_set(sock, t);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_sockaddr_ip_get(char **addr, switch_sockaddr_t *sa)
+SWITCH_DECLARE(switch_status_t) switch_sockaddr_ip_get(char **addr, switch_sockaddr_t * sa)
 {
 	return apr_sockaddr_ip_get(addr, sa);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_mcast_join(switch_socket_t *sock, switch_sockaddr_t *join, switch_sockaddr_t *iface, switch_sockaddr_t *source)
+SWITCH_DECLARE(switch_status_t) switch_mcast_join(switch_socket_t * sock, switch_sockaddr_t * join, switch_sockaddr_t * iface, switch_sockaddr_t * source)
 {
 	return apr_mcast_join(sock, join, iface, source);
 }
@@ -462,25 +455,23 @@
 
 /* socket functions */
 
-SWITCH_DECLARE(char *) switch_get_addr(char *buf, switch_size_t len, switch_sockaddr_t *in)
+SWITCH_DECLARE(char *) switch_get_addr(char *buf, switch_size_t len, switch_sockaddr_t * in)
 {
-    return get_addr(buf, len, &in->sa.sin.sin_addr);
+	return get_addr(buf, len, &in->sa.sin.sin_addr);
 }
 
 
-SWITCH_DECLARE(uint16_t) switch_sockaddr_get_port(switch_sockaddr_t *sa)
+SWITCH_DECLARE(uint16_t) switch_sockaddr_get_port(switch_sockaddr_t * sa)
 {
 	return sa->port;
 }
 
-SWITCH_DECLARE(int32_t) switch_sockaddr_get_family(switch_sockaddr_t *sa)
+SWITCH_DECLARE(int32_t) switch_sockaddr_get_family(switch_sockaddr_t * sa)
 {
 	return sa->family;
 }
 
-SWITCH_DECLARE(switch_status_t) switch_socket_recvfrom(switch_sockaddr_t *from, switch_socket_t *sock,
-                                                    int32_t flags, char *buf, 
-                                                    size_t *len)
+SWITCH_DECLARE(switch_status_t) switch_socket_recvfrom(switch_sockaddr_t * from, switch_socket_t * sock, int32_t flags, char *buf, size_t *len)
 {
 	apr_status_t r;
 
@@ -497,30 +488,22 @@
 
 /* poll stubs */
 
-SWITCH_DECLARE(switch_status_t) switch_pollset_create(switch_pollset_t **pollset,
-													  uint32_t size,
-													  switch_memory_pool_t *p,
-													  uint32_t flags)
+SWITCH_DECLARE(switch_status_t) switch_pollset_create(switch_pollset_t ** pollset, uint32_t size, switch_memory_pool_t *p, uint32_t flags)
 {
 	return apr_pollset_create(pollset, size, p, flags);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_pollset_add(switch_pollset_t *pollset,
-												   const switch_pollfd_t *descriptor)
+SWITCH_DECLARE(switch_status_t) switch_pollset_add(switch_pollset_t * pollset, const switch_pollfd_t * descriptor)
 {
 	return apr_pollset_add(pollset, descriptor);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_poll(switch_pollfd_t *aprset,
-											int32_t numsock,
-											int32_t *nsds,
-											switch_interval_time_t timeout)
+SWITCH_DECLARE(switch_status_t) switch_poll(switch_pollfd_t * aprset, int32_t numsock, int32_t *nsds, switch_interval_time_t timeout)
 {
 	return apr_poll(aprset, numsock, nsds, timeout);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_socket_create_pollfd(switch_pollfd_t **poll, switch_socket_t *sock,
-                                                            int16_t flags, switch_memory_pool_t *pool)
+SWITCH_DECLARE(switch_status_t) switch_socket_create_pollfd(switch_pollfd_t ** poll, switch_socket_t * sock, int16_t flags, switch_memory_pool_t *pool)
 {
 	switch_pollset_t *pollset;
 
@@ -558,52 +541,50 @@
 /* UUID Handling (apr-util) */
 
 
-SWITCH_DECLARE(void) switch_uuid_format(char *buffer, const switch_uuid_t *uuid)
+SWITCH_DECLARE(void) switch_uuid_format(char *buffer, const switch_uuid_t * uuid)
 {
-	apr_uuid_format(buffer, (const apr_uuid_t *)uuid);
+	apr_uuid_format(buffer, (const apr_uuid_t *) uuid);
 }
 
-SWITCH_DECLARE(void) switch_uuid_get(switch_uuid_t *uuid)
+SWITCH_DECLARE(void) switch_uuid_get(switch_uuid_t * uuid)
 {
-	apr_uuid_get((apr_uuid_t *)uuid);
+	apr_uuid_get((apr_uuid_t *) uuid);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_uuid_parse(switch_uuid_t *uuid, const char *uuid_str)
+SWITCH_DECLARE(switch_status_t) switch_uuid_parse(switch_uuid_t * uuid, const char *uuid_str)
 {
-	return apr_uuid_parse((apr_uuid_t *)uuid, uuid_str);
+	return apr_uuid_parse((apr_uuid_t *) uuid, uuid_str);
 }
 
 
 /* FIFO queues (apr-util) */
 
-SWITCH_DECLARE(switch_status_t) switch_queue_create(switch_queue_t **queue,
-                                           unsigned int queue_capacity, 
-                                           switch_memory_pool_t *pool)
+SWITCH_DECLARE(switch_status_t) switch_queue_create(switch_queue_t ** queue, unsigned int queue_capacity, switch_memory_pool_t *pool)
 {
 	return apr_queue_create(queue, queue_capacity, pool);
 }
 
-SWITCH_DECLARE(unsigned int) switch_queue_size(switch_queue_t *queue)
+SWITCH_DECLARE(unsigned int) switch_queue_size(switch_queue_t * queue)
 {
 	return apr_queue_size(queue);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_queue_pop(switch_queue_t *queue, void **data)
+SWITCH_DECLARE(switch_status_t) switch_queue_pop(switch_queue_t * queue, void **data)
 {
 	return apr_queue_pop(queue, data);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_queue_push(switch_queue_t *queue, void *data)
+SWITCH_DECLARE(switch_status_t) switch_queue_push(switch_queue_t * queue, void *data)
 {
 	return apr_queue_push(queue, data);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_queue_trypop(switch_queue_t *queue, void **data)
+SWITCH_DECLARE(switch_status_t) switch_queue_trypop(switch_queue_t * queue, void **data)
 {
 	return apr_queue_trypop(queue, data);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_queue_trypush(switch_queue_t *queue, void *data)
+SWITCH_DECLARE(switch_status_t) switch_queue_trypush(switch_queue_t * queue, void *data)
 {
 	return apr_queue_trypush(queue, data);
 }
@@ -611,7 +592,7 @@
 SWITCH_DECLARE(int) switch_vasprintf(char **ret, const char *fmt, va_list ap)
 {
 #ifdef HAVE_VASPRINTF
-    return vasprintf(ret, fmt, ap);
+	return vasprintf(ret, fmt, ap);
 #else
 	char *buf;
 	int len;
@@ -626,7 +607,7 @@
 
 	len = vsnprintf(NULL, 0, fmt, ap2);
 
-	if (len > 0 && (buf = malloc((buflen = (size_t)(len + 1)))) != NULL) {
+	if (len > 0 && (buf = malloc((buflen = (size_t) (len + 1)))) != NULL) {
 		len = vsnprintf(buf, buflen, fmt, ap);
 		*ret = buf;
 	} else {

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/switch_buffer.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/switch_buffer.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/switch_buffer.c	Fri Mar 30 12:19:18 2007
@@ -35,7 +35,7 @@
 static uint32_t buffer_id = 0;
 
 typedef enum {
-	SWITCH_BUFFER_FLAG_DYNAMIC = (1 <<  0)
+	SWITCH_BUFFER_FLAG_DYNAMIC = (1 << 0)
 } switch_buffer_flag_t;
 
 struct switch_buffer {
@@ -54,8 +54,7 @@
 {
 	switch_buffer_t *new_buffer;
 
-	if ((new_buffer = switch_core_alloc(pool, sizeof(switch_buffer_t))) != 0
-		&& (new_buffer->data = switch_core_alloc(pool, max_len)) != 0) {
+	if ((new_buffer = switch_core_alloc(pool, sizeof(switch_buffer_t))) != 0 && (new_buffer->data = switch_core_alloc(pool, max_len)) != 0) {
 		new_buffer->datalen = max_len;
 		new_buffer->id = buffer_id++;
 		new_buffer->head = new_buffer->data;
@@ -65,9 +64,7 @@
 	return SWITCH_STATUS_MEMERR;
 }
 
-SWITCH_DECLARE(switch_status_t) switch_buffer_create_dynamic(switch_buffer_t **buffer,
-															 switch_size_t blocksize,
-															 switch_size_t start_len,
+SWITCH_DECLARE(switch_status_t) switch_buffer_create_dynamic(switch_buffer_t **buffer, switch_size_t blocksize, switch_size_t start_len,
 															 switch_size_t max_len)
 {
 	switch_buffer_t *new_buffer;
@@ -89,7 +86,7 @@
 		new_buffer->blocksize = blocksize;
 		new_buffer->head = new_buffer->data;
 		switch_set_flag(new_buffer, SWITCH_BUFFER_FLAG_DYNAMIC);
-		
+
 		*buffer = new_buffer;
 		return SWITCH_STATUS_SUCCESS;
 	}
@@ -144,8 +141,8 @@
 		reading = buffer->used;
 	}
 
-    buffer->used -= reading;
-    buffer->head += reading;
+	buffer->used -= reading;
+	buffer->head += reading;
 
 	return buffer->used;
 }
@@ -182,7 +179,7 @@
 	assert(buffer != NULL);
 	assert(data != NULL);
 	assert(buffer->data != NULL);
-	
+
 	if (!datalen) {
 		return buffer->used;
 	}
@@ -198,11 +195,11 @@
 	freespace = buffer->datalen - buffer->used;
 
 	/*
-	if (buffer->data != buffer->head) {
-		memmove(buffer->data, buffer->head, buffer->used);
-		buffer->head = buffer->data;
-	}
-	*/
+	   if (buffer->data != buffer->head) {
+	   memmove(buffer->data, buffer->head, buffer->used);
+	   buffer->head = buffer->data;
+	   }
+	 */
 	if (switch_test_flag(buffer, SWITCH_BUFFER_FLAG_DYNAMIC)) {
 		if (freespace < datalen) {
 			switch_size_t new_size, new_block_size;
@@ -221,7 +218,7 @@
 			buffer->datalen = new_size;
 		}
 	}
-	
+
 	freespace = buffer->datalen - buffer->used;
 
 	if (freespace < datalen) {
@@ -239,7 +236,7 @@
 SWITCH_DECLARE(void) switch_buffer_zero(switch_buffer_t *buffer)
 {
 	assert(buffer != NULL);
-    assert(buffer->data != NULL);
+	assert(buffer->data != NULL);
 
 	buffer->used = 0;
 	buffer->head = buffer->data;

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/switch_caller.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/switch_caller.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/switch_caller.c	Fri Mar 30 12:19:18 2007
@@ -39,10 +39,8 @@
 																	const char *caller_id_number,
 																	const char *network_addr,
 																	const char *ani,
-																	const char *aniii, 
-																	const char *rdnis,
-																	const char *source,
-																	const char *context,
+																	const char *aniii,
+																	const char *rdnis, const char *source, const char *context,
 																	const char *destination_number)
 {
 
@@ -72,7 +70,6 @@
 
 
 SWITCH_DECLARE(switch_caller_profile_t *) switch_caller_profile_clone(switch_core_session_t *session, switch_caller_profile_t *tocopy)
-																	
 {
 	switch_caller_profile_t *profile = NULL;
 	if ((profile = switch_core_session_alloc(session, sizeof(switch_caller_profile_t))) != 0) {
@@ -139,8 +136,7 @@
 	return NULL;
 }
 
-SWITCH_DECLARE(void) switch_caller_profile_event_set_data(switch_caller_profile_t *caller_profile, char *prefix,
-														  switch_event_t *event)
+SWITCH_DECLARE(void) switch_caller_profile_event_set_data(switch_caller_profile_t *caller_profile, char *prefix, switch_event_t *event)
 {
 	char header_name[1024];
 
@@ -211,8 +207,7 @@
 
 }
 
-SWITCH_DECLARE(switch_caller_extension_t *) switch_caller_extension_new(switch_core_session_t *session,
-																	  char *extension_name, char *extension_number)
+SWITCH_DECLARE(switch_caller_extension_t *) switch_caller_extension_new(switch_core_session_t *session, char *extension_name, char *extension_number)
 {
 	switch_caller_extension_t *caller_extension = NULL;
 
@@ -227,8 +222,7 @@
 
 
 SWITCH_DECLARE(void) switch_caller_extension_add_application(switch_core_session_t *session,
-															 switch_caller_extension_t *caller_extension,
-															 char *application_name, char *application_data)
+															 switch_caller_extension_t *caller_extension, char *application_name, char *application_data)
 {
 	switch_caller_application_t *caller_application = NULL;
 

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/switch_channel.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/switch_channel.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/switch_channel.c	Fri Mar 30 12:19:18 2007
@@ -39,64 +39,64 @@
 };
 
 static struct switch_cause_table CAUSE_CHART[] = {
-	{ "UNALLOCATED", SWITCH_CAUSE_UNALLOCATED },
-	{ "SUCCESS", SWITCH_CAUSE_SUCCESS },
-	{ "NO_ROUTE_TRANSIT_NET", SWITCH_CAUSE_NO_ROUTE_TRANSIT_NET },
-	{ "NO_ROUTE_DESTINATION", SWITCH_CAUSE_NO_ROUTE_DESTINATION },
-	{ "CHANNEL_UNACCEPTABLE", SWITCH_CAUSE_CHANNEL_UNACCEPTABLE },
-	{ "CALL_AWARDED_DELIVERED", SWITCH_CAUSE_CALL_AWARDED_DELIVERED },
-	{ "NORMAL_CLEARING", SWITCH_CAUSE_NORMAL_CLEARING },
-	{ "USER_BUSY", SWITCH_CAUSE_USER_BUSY },
-	{ "NO_USER_RESPONSE", SWITCH_CAUSE_NO_USER_RESPONSE },
-	{ "NO_ANSWER", SWITCH_CAUSE_NO_ANSWER },
-	{ "SUBSCRIBER_ABSENT", SWITCH_CAUSE_SUBSCRIBER_ABSENT },
-	{ "CALL_REJECTED", SWITCH_CAUSE_CALL_REJECTED },
-	{ "NUMBER_CHANGED", SWITCH_CAUSE_NUMBER_CHANGED },
-	{ "REDIRECTION_TO_NEW_DESTINATION", SWITCH_CAUSE_REDIRECTION_TO_NEW_DESTINATION },
-	{ "EXCHANGE_ROUTING_ERROR", SWITCH_CAUSE_EXCHANGE_ROUTING_ERROR },
-	{ "DESTINATION_OUT_OF_ORDER", SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER },
-	{ "INVALID_NUMBER_FORMAT", SWITCH_CAUSE_INVALID_NUMBER_FORMAT },
-	{ "FACILITY_REJECTED", SWITCH_CAUSE_FACILITY_REJECTED },
-	{ "RESPONSE_TO_STATUS_ENQUIRY", SWITCH_CAUSE_RESPONSE_TO_STATUS_ENQUIRY },
-	{ "NORMAL_UNSPECIFIED", SWITCH_CAUSE_NORMAL_UNSPECIFIED },
-	{ "NORMAL_CIRCUIT_CONGESTION", SWITCH_CAUSE_NORMAL_CIRCUIT_CONGESTION },
-	{ "NETWORK_OUT_OF_ORDER", SWITCH_CAUSE_NETWORK_OUT_OF_ORDER },
-	{ "NORMAL_TEMPORARY_FAILURE", SWITCH_CAUSE_NORMAL_TEMPORARY_FAILURE },
-	{ "SWITCH_CONGESTION", SWITCH_CAUSE_SWITCH_CONGESTION },
-	{ "ACCESS_INFO_DISCARDED", SWITCH_CAUSE_ACCESS_INFO_DISCARDED },
-	{ "REQUESTED_CHAN_UNAVAIL", SWITCH_CAUSE_REQUESTED_CHAN_UNAVAIL },
-	{ "PRE_EMPTED", SWITCH_CAUSE_PRE_EMPTED },
-	{ "FACILITY_NOT_SUBSCRIBED", SWITCH_CAUSE_FACILITY_NOT_SUBSCRIBED },
-	{ "OUTGOING_CALL_BARRED", SWITCH_CAUSE_OUTGOING_CALL_BARRED },
-	{ "INCOMING_CALL_BARRED", SWITCH_CAUSE_INCOMING_CALL_BARRED },
-	{ "BEARERCAPABILITY_NOTAUTH", SWITCH_CAUSE_BEARERCAPABILITY_NOTAUTH },
-	{ "BEARERCAPABILITY_NOTAVAIL", SWITCH_CAUSE_BEARERCAPABILITY_NOTAVAIL },
-	{ "SERVICE_UNAVAILABLE", SWITCH_CAUSE_SERVICE_UNAVAILABLE },
-	{ "CHAN_NOT_IMPLEMENTED", SWITCH_CAUSE_CHAN_NOT_IMPLEMENTED },
-	{ "FACILITY_NOT_IMPLEMENTED", SWITCH_CAUSE_FACILITY_NOT_IMPLEMENTED },
-	{ "SERVICE_NOT_IMPLEMENTED", SWITCH_CAUSE_SERVICE_NOT_IMPLEMENTED },
-	{ "INVALID_CALL_REFERENCE", SWITCH_CAUSE_INVALID_CALL_REFERENCE },
-	{ "INCOMPATIBLE_DESTINATION", SWITCH_CAUSE_INCOMPATIBLE_DESTINATION },
-	{ "INVALID_MSG_UNSPECIFIED", SWITCH_CAUSE_INVALID_MSG_UNSPECIFIED },
-	{ "MANDATORY_IE_MISSING", SWITCH_CAUSE_MANDATORY_IE_MISSING },
-	{ "MESSAGE_TYPE_NONEXIST", SWITCH_CAUSE_MESSAGE_TYPE_NONEXIST },
-	{ "WRONG_MESSAGE", SWITCH_CAUSE_WRONG_MESSAGE },
-	{ "IE_NONEXIST", SWITCH_CAUSE_IE_NONEXIST },
-	{ "INVALID_IE_CONTENTS", SWITCH_CAUSE_INVALID_IE_CONTENTS },
-	{ "WRONG_CALL_STATE", SWITCH_CAUSE_WRONG_CALL_STATE },
-	{ "RECOVERY_ON_TIMER_EXPIRE", SWITCH_CAUSE_RECOVERY_ON_TIMER_EXPIRE },
-	{ "MANDATORY_IE_LENGTH_ERROR", SWITCH_CAUSE_MANDATORY_IE_LENGTH_ERROR },
-	{ "PROTOCOL_ERROR", SWITCH_CAUSE_PROTOCOL_ERROR },
-	{ "INTERWORKING", SWITCH_CAUSE_INTERWORKING },
-	{ "ORIGINATOR_CANCEL", SWITCH_CAUSE_ORIGINATOR_CANCEL },
-	{ "CRASH", SWITCH_CAUSE_CRASH },
-	{ "SYSTEM_SHUTDOWN", SWITCH_CAUSE_SYSTEM_SHUTDOWN },
-	{ "LOSE_RACE", SWITCH_CAUSE_LOSE_RACE },
-	{ "MANAGER_REQUEST", SWITCH_CAUSE_MANAGER_REQUEST },
-	{ "BLIND_TRANSFER", SWITCH_CAUSE_BLIND_TRANSFER },
-	{ "ATTENDED_TRANSFER", SWITCH_CAUSE_ATTENDED_TRANSFER },
-	{ "ALLOTTED_TIMEOUT", SWITCH_CAUSE_ALLOTTED_TIMEOUT},
-	{ NULL, 0 }
+	{"UNALLOCATED", SWITCH_CAUSE_UNALLOCATED},
+	{"SUCCESS", SWITCH_CAUSE_SUCCESS},
+	{"NO_ROUTE_TRANSIT_NET", SWITCH_CAUSE_NO_ROUTE_TRANSIT_NET},
+	{"NO_ROUTE_DESTINATION", SWITCH_CAUSE_NO_ROUTE_DESTINATION},
+	{"CHANNEL_UNACCEPTABLE", SWITCH_CAUSE_CHANNEL_UNACCEPTABLE},
+	{"CALL_AWARDED_DELIVERED", SWITCH_CAUSE_CALL_AWARDED_DELIVERED},
+	{"NORMAL_CLEARING", SWITCH_CAUSE_NORMAL_CLEARING},
+	{"USER_BUSY", SWITCH_CAUSE_USER_BUSY},
+	{"NO_USER_RESPONSE", SWITCH_CAUSE_NO_USER_RESPONSE},
+	{"NO_ANSWER", SWITCH_CAUSE_NO_ANSWER},
+	{"SUBSCRIBER_ABSENT", SWITCH_CAUSE_SUBSCRIBER_ABSENT},
+	{"CALL_REJECTED", SWITCH_CAUSE_CALL_REJECTED},
+	{"NUMBER_CHANGED", SWITCH_CAUSE_NUMBER_CHANGED},
+	{"REDIRECTION_TO_NEW_DESTINATION", SWITCH_CAUSE_REDIRECTION_TO_NEW_DESTINATION},
+	{"EXCHANGE_ROUTING_ERROR", SWITCH_CAUSE_EXCHANGE_ROUTING_ERROR},
+	{"DESTINATION_OUT_OF_ORDER", SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER},
+	{"INVALID_NUMBER_FORMAT", SWITCH_CAUSE_INVALID_NUMBER_FORMAT},
+	{"FACILITY_REJECTED", SWITCH_CAUSE_FACILITY_REJECTED},
+	{"RESPONSE_TO_STATUS_ENQUIRY", SWITCH_CAUSE_RESPONSE_TO_STATUS_ENQUIRY},
+	{"NORMAL_UNSPECIFIED", SWITCH_CAUSE_NORMAL_UNSPECIFIED},
+	{"NORMAL_CIRCUIT_CONGESTION", SWITCH_CAUSE_NORMAL_CIRCUIT_CONGESTION},
+	{"NETWORK_OUT_OF_ORDER", SWITCH_CAUSE_NETWORK_OUT_OF_ORDER},
+	{"NORMAL_TEMPORARY_FAILURE", SWITCH_CAUSE_NORMAL_TEMPORARY_FAILURE},
+	{"SWITCH_CONGESTION", SWITCH_CAUSE_SWITCH_CONGESTION},
+	{"ACCESS_INFO_DISCARDED", SWITCH_CAUSE_ACCESS_INFO_DISCARDED},
+	{"REQUESTED_CHAN_UNAVAIL", SWITCH_CAUSE_REQUESTED_CHAN_UNAVAIL},
+	{"PRE_EMPTED", SWITCH_CAUSE_PRE_EMPTED},
+	{"FACILITY_NOT_SUBSCRIBED", SWITCH_CAUSE_FACILITY_NOT_SUBSCRIBED},
+	{"OUTGOING_CALL_BARRED", SWITCH_CAUSE_OUTGOING_CALL_BARRED},
+	{"INCOMING_CALL_BARRED", SWITCH_CAUSE_INCOMING_CALL_BARRED},
+	{"BEARERCAPABILITY_NOTAUTH", SWITCH_CAUSE_BEARERCAPABILITY_NOTAUTH},
+	{"BEARERCAPABILITY_NOTAVAIL", SWITCH_CAUSE_BEARERCAPABILITY_NOTAVAIL},
+	{"SERVICE_UNAVAILABLE", SWITCH_CAUSE_SERVICE_UNAVAILABLE},
+	{"CHAN_NOT_IMPLEMENTED", SWITCH_CAUSE_CHAN_NOT_IMPLEMENTED},
+	{"FACILITY_NOT_IMPLEMENTED", SWITCH_CAUSE_FACILITY_NOT_IMPLEMENTED},
+	{"SERVICE_NOT_IMPLEMENTED", SWITCH_CAUSE_SERVICE_NOT_IMPLEMENTED},
+	{"INVALID_CALL_REFERENCE", SWITCH_CAUSE_INVALID_CALL_REFERENCE},
+	{"INCOMPATIBLE_DESTINATION", SWITCH_CAUSE_INCOMPATIBLE_DESTINATION},
+	{"INVALID_MSG_UNSPECIFIED", SWITCH_CAUSE_INVALID_MSG_UNSPECIFIED},
+	{"MANDATORY_IE_MISSING", SWITCH_CAUSE_MANDATORY_IE_MISSING},
+	{"MESSAGE_TYPE_NONEXIST", SWITCH_CAUSE_MESSAGE_TYPE_NONEXIST},
+	{"WRONG_MESSAGE", SWITCH_CAUSE_WRONG_MESSAGE},
+	{"IE_NONEXIST", SWITCH_CAUSE_IE_NONEXIST},
+	{"INVALID_IE_CONTENTS", SWITCH_CAUSE_INVALID_IE_CONTENTS},
+	{"WRONG_CALL_STATE", SWITCH_CAUSE_WRONG_CALL_STATE},
+	{"RECOVERY_ON_TIMER_EXPIRE", SWITCH_CAUSE_RECOVERY_ON_TIMER_EXPIRE},
+	{"MANDATORY_IE_LENGTH_ERROR", SWITCH_CAUSE_MANDATORY_IE_LENGTH_ERROR},
+	{"PROTOCOL_ERROR", SWITCH_CAUSE_PROTOCOL_ERROR},
+	{"INTERWORKING", SWITCH_CAUSE_INTERWORKING},
+	{"ORIGINATOR_CANCEL", SWITCH_CAUSE_ORIGINATOR_CANCEL},
+	{"CRASH", SWITCH_CAUSE_CRASH},
+	{"SYSTEM_SHUTDOWN", SWITCH_CAUSE_SYSTEM_SHUTDOWN},
+	{"LOSE_RACE", SWITCH_CAUSE_LOSE_RACE},
+	{"MANAGER_REQUEST", SWITCH_CAUSE_MANAGER_REQUEST},
+	{"BLIND_TRANSFER", SWITCH_CAUSE_BLIND_TRANSFER},
+	{"ATTENDED_TRANSFER", SWITCH_CAUSE_ATTENDED_TRANSFER},
+	{"ALLOTTED_TIMEOUT", SWITCH_CAUSE_ALLOTTED_TIMEOUT},
+	{NULL, 0}
 };
 
 struct switch_channel {
@@ -123,7 +123,7 @@
 	uint8_t x;
 	char *str = "UNKNOWN";
 
-	for(x = 0; CAUSE_CHART[x].name; x++) {
+	for (x = 0; CAUSE_CHART[x].name; x++) {
 		if (CAUSE_CHART[x].cause == cause) {
 			str = (char *) CAUSE_CHART[x].name;
 		}
@@ -137,7 +137,7 @@
 	uint8_t x;
 	switch_call_cause_t cause = SWITCH_CAUSE_UNALLOCATED;
 
-	for(x = 0; CAUSE_CHART[x].name; x++) {
+	for (x = 0; CAUSE_CHART[x].name; x++) {
 		if (!strcasecmp(CAUSE_CHART[x].name, str)) {
 			cause = CAUSE_CHART[x].cause;
 		}
@@ -153,14 +153,14 @@
 
 SWITCH_DECLARE(switch_channel_timetable_t *) switch_channel_get_timetable(switch_channel_t *channel)
 {
-    switch_channel_timetable_t *times = NULL;
+	switch_channel_timetable_t *times = NULL;
 
 	assert(channel != NULL);
-    if (channel->caller_profile) {
-        switch_mutex_lock(channel->profile_mutex);
-        times = channel->caller_profile->times;
-        switch_mutex_unlock(channel->profile_mutex);
-    }
+	if (channel->caller_profile) {
+		switch_mutex_lock(channel->profile_mutex);
+		times = channel->caller_profile->times;
+		switch_mutex_unlock(channel->profile_mutex);
+	}
 
 	return times;
 }
@@ -210,13 +210,13 @@
 
 	inuse = switch_buffer_inuse(channel->dtmf_buffer);
 	len = strlen(dtmf);
-	
+
 	if (len + inuse > switch_buffer_len(channel->dtmf_buffer)) {
 		switch_buffer_toss(channel->dtmf_buffer, strlen(dtmf));
 	}
 
 	p = dtmf;
-	while(wr < len && p) {
+	while (wr < len && p) {
 		if (is_dtmf(*p)) {
 			wr++;
 		} else {
@@ -259,9 +259,8 @@
 	switch_buffer_destroy(&channel->dtmf_buffer);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_channel_init(switch_channel_t *channel,
-												  switch_core_session_t *session,
-												  switch_channel_state_t state, uint32_t flags)
+SWITCH_DECLARE(switch_status_t) switch_channel_init(switch_channel_t *channel, switch_core_session_t *session, switch_channel_state_t state,
+													uint32_t flags)
 {
 	assert(channel != NULL);
 	channel->state = state;
@@ -307,7 +306,7 @@
 	char *v = NULL;
 	assert(channel != NULL);
 
-	if (!(v=switch_core_hash_find(channel->variables, varname))) {
+	if (!(v = switch_core_hash_find(channel->variables, varname))) {
 		if (!channel->caller_profile || !(v = switch_caller_get_field_by_name(channel->caller_profile, varname))) {
 			if (!strcmp(varname, "base_dir")) {
 				return SWITCH_GLOBAL_dirs.base_dir;
@@ -315,7 +314,7 @@
 			v = switch_core_get_variable(varname);
 		}
 	}
-	
+
 	return v;
 }
 
@@ -460,7 +459,7 @@
 SWITCH_DECLARE(switch_channel_state_t) switch_channel_name_state(char *name)
 {
 	uint32_t x = 0;
-	for(x = 0; state_names[x]; x++) {
+	for (x = 0; state_names[x]; x++) {
 		if (!strcasecmp(state_names[x], name)) {
 			return (switch_channel_state_t) x;
 		}
@@ -470,10 +469,7 @@
 }
 
 SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_set_state(switch_channel_t *channel,
-                                                                        const char *file,
-                                                                        const char *func,
-                                                                        int line,
-                                                                        switch_channel_state_t state)
+																		const char *file, const char *func, int line, switch_channel_state_t state)
 {
 	switch_channel_state_t last_state;
 	int ok = 0;
@@ -491,7 +487,7 @@
 	if (last_state >= CS_HANGUP && state < last_state) {
 		goto done;
 	}
-	
+
 	/* STUB for more dev
 	   case CS_INIT:
 	   switch(state) {
@@ -629,12 +625,10 @@
 
 	if (ok) {
 		if (state > CS_RING) {
-			switch_channel_presence(channel, "unknown", (char*)state_names[state]);
+			switch_channel_presence(channel, "unknown", (char *) state_names[state]);
 		}
-		switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, SWITCH_LOG_DEBUG, "%s State Change %s -> %s\n", 
-						  channel->name,
-						  state_names[last_state], 
-						  state_names[state]);
+		switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, SWITCH_LOG_DEBUG, "%s State Change %s -> %s\n",
+						  channel->name, state_names[last_state], state_names[state]);
 		switch_mutex_lock(channel->flag_mutex);
 		channel->state = state;
 		switch_mutex_unlock(channel->flag_mutex);
@@ -658,16 +652,14 @@
 				switch_event_fire(&event);
 			}
 		}
-				
+
 		if (state < CS_DONE) {
 			switch_core_session_signal_state_change(channel->session);
 		}
-		
+
 	} else {
-		switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, SWITCH_LOG_WARNING, "%s Invalid State Change %s -> %s\n", 
-						  channel->name,
-						  state_names[last_state],
-						  state_names[state]);
+		switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, SWITCH_LOG_WARNING,
+						  "%s Invalid State Change %s -> %s\n", channel->name, state_names[last_state], state_names[state]);
 
 		/* we won't tolerate an invalid state change so we can make sure we are as robust as a nice cup of dark coffee! */
 		if (channel->state < CS_HANGUP) {
@@ -675,8 +667,8 @@
 			assert(0);
 		}
 	}
- done:
-	
+  done:
+
 	if (channel->state_flags) {
 		channel->flags |= channel->state_flags;
 		channel->state_flags = 0;
@@ -696,21 +688,21 @@
 	char state_num[25];
 
 	if ((caller_profile = switch_channel_get_caller_profile(channel))) {
-        originator_caller_profile = caller_profile->originator_caller_profile;
-        originatee_caller_profile = caller_profile->originatee_caller_profile;
-    }
+		originator_caller_profile = caller_profile->originator_caller_profile;
+		originatee_caller_profile = caller_profile->originatee_caller_profile;
+	}
 
 	switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-State", "%s", switch_channel_state_name(channel->state));
 	snprintf(state_num, sizeof(state_num), "%d", channel->state);
 	switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-State-Number", "%s", state_num);
 	switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Name", "%s", switch_channel_get_name(channel));
 	switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Unique-ID", "%s", switch_core_session_get_uuid(channel->session));
-	
+
 	if ((codec = switch_core_session_get_read_codec(channel->session))) {
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Read-Codec-Name", "%s", switch_str_nil(codec->implementation->iananame));
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Read-Codec-Rate", "%u", codec->implementation->samples_per_second);
 	}
-	
+
 	if ((codec = switch_core_session_get_write_codec(channel->session))) {
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Write-Codec-Name", "%s", switch_str_nil(codec->implementation->iananame));
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Write-Codec-Rate", "%u", codec->implementation->samples_per_second);
@@ -732,13 +724,12 @@
 	}
 
 	/* Index Variables */
-	for (hi = switch_hash_first(switch_core_session_get_pool(channel->session), channel->variables); hi;
-		 hi = switch_hash_next(hi)) {
+	for (hi = switch_hash_first(switch_core_session_get_pool(channel->session), channel->variables); hi; hi = switch_hash_next(hi)) {
 		char buf[1024];
 		switch_hash_this(hi, &var, NULL, &val);
 		if (var && val) {
-			snprintf(buf, sizeof(buf), "variable_%s", (char *)var);
-			switch_event_add_header(event, SWITCH_STACK_BOTTOM, buf, "%s", (char *)val);
+			snprintf(buf, sizeof(buf), "variable_%s", (char *) var);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, buf, "%s", (char *) val);
 		}
 	}
 
@@ -772,15 +763,15 @@
 			switch_channel_event_set_data(channel, event);
 			switch_event_fire(&event);
 		}
-	} 
-    
-    caller_profile->times = (switch_channel_timetable_t *) switch_core_session_alloc(channel->session, sizeof(*caller_profile->times));
+	}
+
+	caller_profile->times = (switch_channel_timetable_t *) switch_core_session_alloc(channel->session, sizeof(*caller_profile->times));
 	caller_profile->times->created = switch_time_now();
 
-    if (channel->caller_profile && channel->caller_profile->times) {
-        channel->caller_profile->times->transferred = switch_time_now();
-        caller_profile->times->answered = channel->caller_profile->times->answered;
-    }
+	if (channel->caller_profile && channel->caller_profile->times) {
+		channel->caller_profile->times->transferred = switch_time_now();
+		caller_profile->times->answered = channel->caller_profile->times->answered;
+	}
 
 	caller_profile->next = channel->caller_profile;
 	channel->caller_profile = caller_profile;
@@ -800,28 +791,26 @@
 	return profile;
 }
 
-SWITCH_DECLARE(void) switch_channel_set_originator_caller_profile(switch_channel_t *channel,
-																  switch_caller_profile_t *caller_profile)
+SWITCH_DECLARE(void) switch_channel_set_originator_caller_profile(switch_channel_t *channel, switch_caller_profile_t *caller_profile)
 {
 	assert(channel != NULL);
-    if (channel->caller_profile) {
-        switch_mutex_lock(channel->profile_mutex);
-        caller_profile->next = channel->caller_profile->originator_caller_profile;
-        channel->caller_profile->originator_caller_profile = caller_profile;
-        switch_mutex_unlock(channel->profile_mutex);
-    }
+	if (channel->caller_profile) {
+		switch_mutex_lock(channel->profile_mutex);
+		caller_profile->next = channel->caller_profile->originator_caller_profile;
+		channel->caller_profile->originator_caller_profile = caller_profile;
+		switch_mutex_unlock(channel->profile_mutex);
+	}
 }
 
-SWITCH_DECLARE(void) switch_channel_set_originatee_caller_profile(switch_channel_t *channel,
-																  switch_caller_profile_t *caller_profile)
+SWITCH_DECLARE(void) switch_channel_set_originatee_caller_profile(switch_channel_t *channel, switch_caller_profile_t *caller_profile)
 {
 	assert(channel != NULL);
-    if (channel->caller_profile) {
-        switch_mutex_lock(channel->profile_mutex);
-        caller_profile->next = channel->caller_profile->originatee_caller_profile;
-        channel->caller_profile->originatee_caller_profile = caller_profile;
-        switch_mutex_unlock(channel->profile_mutex);
-    }
+	if (channel->caller_profile) {
+		switch_mutex_lock(channel->profile_mutex);
+		caller_profile->next = channel->caller_profile->originatee_caller_profile;
+		channel->caller_profile->originatee_caller_profile = caller_profile;
+		switch_mutex_unlock(channel->profile_mutex);
+	}
 }
 
 SWITCH_DECLARE(switch_caller_profile_t *) switch_channel_get_originator_caller_profile(switch_channel_t *channel)
@@ -829,11 +818,11 @@
 	switch_caller_profile_t *profile = NULL;
 	assert(channel != NULL);
 
-    if (channel->caller_profile) {
-        switch_mutex_lock(channel->profile_mutex);
-        profile = channel->caller_profile->originator_caller_profile;
-        switch_mutex_unlock(channel->profile_mutex);
-    }
+	if (channel->caller_profile) {
+		switch_mutex_lock(channel->profile_mutex);
+		profile = channel->caller_profile->originator_caller_profile;
+		switch_mutex_unlock(channel->profile_mutex);
+	}
 
 	return profile;
 }
@@ -843,11 +832,11 @@
 	switch_caller_profile_t *profile = NULL;
 	assert(channel != NULL);
 
-    if (channel->caller_profile) {
-        switch_mutex_lock(channel->profile_mutex);
-        profile = channel->caller_profile->originatee_caller_profile;
-        switch_mutex_unlock(channel->profile_mutex);
-    }
+	if (channel->caller_profile) {
+		switch_mutex_lock(channel->profile_mutex);
+		profile = channel->caller_profile->originatee_caller_profile;
+		switch_mutex_unlock(channel->profile_mutex);
+	}
 
 	return profile;
 }
@@ -859,8 +848,7 @@
 	return switch_core_session_get_uuid(channel->session);
 }
 
-SWITCH_DECLARE(int) switch_channel_add_state_handler(switch_channel_t *channel,
-													 const switch_state_handler_table_t *state_handler)
+SWITCH_DECLARE(int) switch_channel_add_state_handler(switch_channel_t *channel, const switch_state_handler_table_t *state_handler)
 {
 	int x, index;
 
@@ -878,10 +866,10 @@
 		index = -1;
 		goto end;
 	}
-	
+
 	channel->state_handlers[index] = state_handler;
 
- end:
+  end:
 	switch_mutex_unlock(channel->flag_mutex);
 	return index;
 }
@@ -906,7 +894,7 @@
 SWITCH_DECLARE(void) switch_channel_clear_state_handler(switch_channel_t *channel, const switch_state_handler_table_t *state_handler)
 {
 	int index, i = channel->state_handler_index;
-	const switch_state_handler_table_t *new_handlers[SWITCH_MAX_STATE_HANDLERS] = {0};
+	const switch_state_handler_table_t *new_handlers[SWITCH_MAX_STATE_HANDLERS] = { 0 };
 
 
 	switch_mutex_lock(channel->flag_mutex);
@@ -935,8 +923,7 @@
 
 }
 
-SWITCH_DECLARE(void) switch_channel_set_caller_extension(switch_channel_t *channel,
-														 switch_caller_extension_t *caller_extension)
+SWITCH_DECLARE(void) switch_channel_set_caller_extension(switch_channel_t *channel, switch_caller_extension_t *caller_extension)
 {
 	assert(channel != NULL);
 
@@ -949,31 +936,28 @@
 
 SWITCH_DECLARE(switch_caller_extension_t *) switch_channel_get_caller_extension(switch_channel_t *channel)
 {
-    switch_caller_extension_t *extension = NULL;
+	switch_caller_extension_t *extension = NULL;
 
 	assert(channel != NULL);
 	switch_mutex_lock(channel->profile_mutex);
 	if (channel->caller_profile) {
 		extension = channel->caller_profile->caller_extension;
 	}
-    switch_mutex_unlock(channel->profile_mutex);
-    return extension;
+	switch_mutex_unlock(channel->profile_mutex);
+	return extension;
 }
 
 
-SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_hangup(switch_channel_t *channel, 
-                                                                     const char *file,
-                                                                     const char *func,
-                                                                     int line,
-                                                                     switch_call_cause_t hangup_cause)
+SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_hangup(switch_channel_t *channel,
+																	 const char *file, const char *func, int line, switch_call_cause_t hangup_cause)
 {
 	assert(channel != NULL);
 	switch_mutex_lock(channel->flag_mutex);
 
 	if (channel->caller_profile && channel->caller_profile->times && !channel->caller_profile->times->hungup) {
-        switch_mutex_lock(channel->profile_mutex);
+		switch_mutex_lock(channel->profile_mutex);
 		channel->caller_profile->times->hungup = switch_time_now();
-        switch_mutex_unlock(channel->profile_mutex);
+		switch_mutex_unlock(channel->profile_mutex);
 	}
 
 	if (channel->state < CS_HANGUP) {
@@ -981,15 +965,14 @@
 		switch_channel_state_t last_state = channel->state;
 		channel->state = CS_HANGUP;
 		channel->hangup_cause = hangup_cause;
-		switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, SWITCH_LOG_NOTICE, "Hangup %s [%s] [%s]\n", 
-						  channel->name,
-						  state_names[last_state], switch_channel_cause2str(channel->hangup_cause));
+		switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, SWITCH_LOG_NOTICE, "Hangup %s [%s] [%s]\n",
+						  channel->name, state_names[last_state], switch_channel_cause2str(channel->hangup_cause));
 		if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_HANGUP) == SWITCH_STATUS_SUCCESS) {
 			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Hangup-Cause", "%s", switch_channel_cause2str(channel->hangup_cause));
 			switch_channel_event_set_data(channel, event);
 			switch_event_fire(&event);
 		}
-		
+
 		switch_channel_set_variable(channel, "hangup_cause", switch_channel_cause2str(channel->hangup_cause));
 		switch_channel_presence(channel, "unavailable", switch_channel_cause2str(channel->hangup_cause));
 
@@ -1002,13 +985,10 @@
 }
 
 
-SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_ring_ready(switch_channel_t *channel,
-																	   const char *file,
-																	   const char *func,
-																	   int line)
+SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_ring_ready(switch_channel_t *channel, const char *file, const char *func, int line)
 {
 	if (!switch_channel_test_flag(channel, CF_RING_READY)) {
-        switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, SWITCH_LOG_NOTICE, "Ring-Ready %s!\n", channel->name);
+		switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, SWITCH_LOG_NOTICE, "Ring-Ready %s!\n", channel->name);
 		switch_channel_set_flag(channel, CF_RING_READY);
 		return SWITCH_STATUS_SUCCESS;
 	}
@@ -1018,49 +998,44 @@
 
 
 
-SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_pre_answered(switch_channel_t *channel,
-																		 const char *file,
-																		 const char *func,
-																		 int line)
+SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_pre_answered(switch_channel_t *channel, const char *file, const char *func, int line)
 {
-    switch_event_t *event;
+	switch_event_t *event;
 
 	switch_channel_mark_ring_ready(channel);
 
-    if (!switch_channel_test_flag(channel, CF_EARLY_MEDIA)) {
-        char *uuid;
-        switch_core_session_t *other_session;
-
-        switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, SWITCH_LOG_NOTICE, "Pre-Answer %s!\n", channel->name);
-        switch_channel_set_flag(channel, CF_EARLY_MEDIA);
-        switch_channel_set_variable(channel, "endpoint_disposition", "EARLY MEDIA");
-        if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_PROGRESS) == SWITCH_STATUS_SUCCESS) {
-            switch_channel_event_set_data(channel, event);
-            switch_event_fire(&event);
-        }
-
-        /* if we're the child of another channel and the other channel is in a blocking read they will never realize we have answered so send 
-           a SWITCH_SIG_BREAK to interrupt any blocking reads on that channel
-        */
-        if ((uuid = switch_channel_get_variable(channel, SWITCH_ORIGINATOR_VARIABLE)) && (other_session = switch_core_session_locate(uuid))) {
-            switch_core_session_kill_channel(other_session, SWITCH_SIG_BREAK);
-            switch_core_session_rwunlock(other_session);
-        }
-        return SWITCH_STATUS_SUCCESS;
-    }
-    
-    return SWITCH_STATUS_FALSE;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_channel_perform_pre_answer(switch_channel_t *channel,
-                                                                  const char *file,
-                                                                  const char *func,
-                                                                  int line)
+	if (!switch_channel_test_flag(channel, CF_EARLY_MEDIA)) {
+		char *uuid;
+		switch_core_session_t *other_session;
+
+		switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, SWITCH_LOG_NOTICE, "Pre-Answer %s!\n", channel->name);
+		switch_channel_set_flag(channel, CF_EARLY_MEDIA);
+		switch_channel_set_variable(channel, "endpoint_disposition", "EARLY MEDIA");
+		if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_PROGRESS) == SWITCH_STATUS_SUCCESS) {
+			switch_channel_event_set_data(channel, event);
+			switch_event_fire(&event);
+		}
+
+		/* if we're the child of another channel and the other channel is in a blocking read they will never realize we have answered so send 
+		   a SWITCH_SIG_BREAK to interrupt any blocking reads on that channel
+		 */
+		if ((uuid = switch_channel_get_variable(channel, SWITCH_ORIGINATOR_VARIABLE))
+			&& (other_session = switch_core_session_locate(uuid))) {
+			switch_core_session_kill_channel(other_session, SWITCH_SIG_BREAK);
+			switch_core_session_rwunlock(other_session);
+		}
+		return SWITCH_STATUS_SUCCESS;
+	}
+
+	return SWITCH_STATUS_FALSE;
+}
+
+SWITCH_DECLARE(switch_status_t) switch_channel_perform_pre_answer(switch_channel_t *channel, const char *file, const char *func, int line)
 {
 	switch_core_session_message_t msg;
 	char *uuid = switch_core_session_get_uuid(channel->session);
 	switch_status_t status;
-	
+
 	assert(channel != NULL);
 
 	if (channel->hangup_cause || channel->state >= CS_HANGUP) {
@@ -1078,23 +1053,20 @@
 	msg.message_id = SWITCH_MESSAGE_INDICATE_PROGRESS;
 	msg.from = channel->name;
 	status = switch_core_session_message_send(uuid, &msg);
-	
+
 	if (status == SWITCH_STATUS_SUCCESS) {
-        status = switch_channel_perform_mark_pre_answered(channel, file, func, line);
+		status = switch_channel_perform_mark_pre_answered(channel, file, func, line);
 	}
 
 	return status;
 }
 
-SWITCH_DECLARE(switch_status_t) switch_channel_perform_ring_ready(switch_channel_t *channel,
-																  const char *file,
-																  const char *func,
-																  int line)
+SWITCH_DECLARE(switch_status_t) switch_channel_perform_ring_ready(switch_channel_t *channel, const char *file, const char *func, int line)
 {
 	switch_core_session_message_t msg;
 	char *uuid = switch_core_session_get_uuid(channel->session);
 	switch_status_t status;
-	
+
 	assert(channel != NULL);
 
 	if (channel->hangup_cause || channel->state >= CS_HANGUP) {
@@ -1120,16 +1092,13 @@
 	return status;
 }
 
-SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_answered(switch_channel_t *channel,
-                                                                     const char *file,
-                                                                     const char *func,
-                                                                     int line)
-{
-    switch_event_t *event;
-    char *uuid;
-    switch_core_session_t *other_session;
+SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_answered(switch_channel_t *channel, const char *file, const char *func, int line)
+{
+	switch_event_t *event;
+	char *uuid;
+	switch_core_session_t *other_session;
 
-    assert(channel != NULL);
+	assert(channel != NULL);
 
 	if (channel->hangup_cause || channel->state >= CS_HANGUP) {
 		return SWITCH_STATUS_FALSE;
@@ -1139,37 +1108,35 @@
 		return SWITCH_STATUS_SUCCESS;
 	}
 
-    if (channel->caller_profile && channel->caller_profile->times) {
-        switch_mutex_lock(channel->profile_mutex);
-        channel->caller_profile->times->answered = switch_time_now();
-        switch_mutex_unlock(channel->profile_mutex);
-    }
-    
-    switch_channel_set_flag(channel, CF_ANSWERED);
-    
-    if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_ANSWER) == SWITCH_STATUS_SUCCESS) {
-        switch_channel_event_set_data(channel, event);
-        switch_event_fire(&event);
-    }
-	
-    /* if we're the child of another channel and the other channel is in a blocking read they will never realize we have answered so send 
-       a SWITCH_SIG_BREAK to interrupt any blocking reads on that channel
-     */
-    if ((uuid = switch_channel_get_variable(channel, SWITCH_ORIGINATOR_VARIABLE)) && (other_session = switch_core_session_locate(uuid))) {
-        switch_core_session_kill_channel(other_session, SWITCH_SIG_BREAK);
-        switch_core_session_rwunlock(other_session);
-    }
-
-    switch_channel_set_variable(channel, "endpoint_disposition", "ANSWER");
-    switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, SWITCH_LOG_NOTICE, "Channel [%s] has been answered\n", channel->name);
-    
-    return SWITCH_STATUS_SUCCESS;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_channel_perform_answer(switch_channel_t *channel,
-                                                              const char *file,
-                                                              const char *func,
-                                                              int line)
+	if (channel->caller_profile && channel->caller_profile->times) {
+		switch_mutex_lock(channel->profile_mutex);
+		channel->caller_profile->times->answered = switch_time_now();
+		switch_mutex_unlock(channel->profile_mutex);
+	}
+
+	switch_channel_set_flag(channel, CF_ANSWERED);
+
+	if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_ANSWER) == SWITCH_STATUS_SUCCESS) {
+		switch_channel_event_set_data(channel, event);
+		switch_event_fire(&event);
+	}
+
+	/* if we're the child of another channel and the other channel is in a blocking read they will never realize we have answered so send 
+	   a SWITCH_SIG_BREAK to interrupt any blocking reads on that channel
+	 */
+	if ((uuid = switch_channel_get_variable(channel, SWITCH_ORIGINATOR_VARIABLE))
+		&& (other_session = switch_core_session_locate(uuid))) {
+		switch_core_session_kill_channel(other_session, SWITCH_SIG_BREAK);
+		switch_core_session_rwunlock(other_session);
+	}
+
+	switch_channel_set_variable(channel, "endpoint_disposition", "ANSWER");
+	switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, SWITCH_LOG_NOTICE, "Channel [%s] has been answered\n", channel->name);
+
+	return SWITCH_STATUS_SUCCESS;
+}
+
+SWITCH_DECLARE(switch_status_t) switch_channel_perform_answer(switch_channel_t *channel, const char *file, const char *func, int line)
 {
 	assert(channel != NULL);
 
@@ -1182,7 +1149,7 @@
 	}
 
 	if (switch_core_session_answer_channel(channel->session) == SWITCH_STATUS_SUCCESS) {
-        return switch_channel_perform_mark_answered(channel, file, func, line);
+		return switch_channel_perform_mark_answered(channel, file, func, line);
 	}
 
 	return SWITCH_STATUS_FALSE;
@@ -1216,14 +1183,14 @@
 	if ((data = malloc(olen))) {
 		memset(data, 0, olen);
 		c = data;
-		for(p = indup; *p; p++) {
+		for (p = indup; *p; p++) {
 			vtype = 0;
 
 			if (*p == '$') {
 				vtype = 1;
-                if (*(p+1) != '{') {
-                    vtype = 2;
-                }
+				if (*(p + 1) != '{') {
+					vtype = 2;
+				}
 			}
 
 			if (vtype) {
@@ -1265,14 +1232,14 @@
 					e++;
 				}
 				p = e;
-				
+
 				if (vtype == 1) {
 					sub_val = switch_channel_get_variable(channel, vname);
 				} else {
-					switch_stream_handle_t stream = {0};
+					switch_stream_handle_t stream = { 0 };
 
 					SWITCH_STANDARD_STREAM(stream);
-					
+
 					if (stream.data) {
 						if (switch_api_execute(vname, vval, channel->session, &stream) == SWITCH_STATUS_SUCCESS) {
 							func_val = stream.data;
@@ -1289,22 +1256,22 @@
 				}
 				if ((nlen = sub_val ? strlen(sub_val) : 0)) {
 					if (len + nlen >= olen) {
-                        resize(nlen);
+						resize(nlen);
 					}
 
 					len += nlen;
 					strcat(c, sub_val);
 					c += nlen;
 				}
-				
+
 				switch_safe_free(func_val);
-                sub_val = NULL;
-                vname = NULL;
-                vtype = 0;
+				sub_val = NULL;
+				vname = NULL;
+				vtype = 0;
+			}
+			if (len + 1 >= olen) {
+				resize(1);
 			}
-            if (len + 1 >= olen) {
-                resize(1);
-            }
 
 			if (sp) {
 				*c++ = ' ';
@@ -1317,7 +1284,7 @@
 			} else {
 				*c++ = *p;
 				len++;
-			} 
+			}
 		}
 	}
 	free(indup);

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/switch_config.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/switch_config.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/switch_config.c	Fri Mar 30 12:19:18 2007
@@ -32,7 +32,7 @@
 #include <switch.h>
 #include <switch_config.h>
 
-SWITCH_DECLARE(int) switch_config_open_file(switch_config_t *cfg, char *file_path)
+SWITCH_DECLARE(int) switch_config_open_file(switch_config_t * cfg, char *file_path)
 {
 	FILE *f;
 	char *path = NULL;
@@ -88,7 +88,7 @@
 }
 
 
-SWITCH_DECLARE(void) switch_config_close_file(switch_config_t *cfg)
+SWITCH_DECLARE(void) switch_config_close_file(switch_config_t * cfg)
 {
 
 	if (cfg->file) {
@@ -100,7 +100,7 @@
 
 
 
-SWITCH_DECLARE(int) switch_config_next_pair(switch_config_t *cfg, char **var, char **val)
+SWITCH_DECLARE(int) switch_config_next_pair(switch_config_t * cfg, char **var, char **val)
 {
 	int ret = 0;
 	char *p, *end;
@@ -171,7 +171,7 @@
 		}
 		*var = p;
 
-		
+
 		if ((*val = strchr(*var, '=')) == 0) {
 			ret = -1;
 			/* log_printf(0, server.log, "Invalid syntax on %s: line %d\n", cfg->path, cfg->lineno); */

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/switch_console.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/switch_console.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/switch_console.c	Fri Mar 30 12:19:18 2007
@@ -50,12 +50,12 @@
 	va_start(ap, fmt);
 	ret = switch_vasprintf(&data, fmt, ap);
 	va_end(ap);
-	
+
 	if (data) {
 		switch_size_t remaining = handle->data_size - handle->data_len;
 		switch_size_t need = strlen(data) + 1;
-		
-		
+
+
 		if ((remaining < need) && handle->alloc_len) {
 			switch_size_t new_len;
 			void *new_data;
@@ -63,10 +63,10 @@
 			new_len = handle->data_size + need + handle->alloc_chunk;
 			if ((new_data = realloc(handle->data, new_len))) {
 				handle->data_size = handle->alloc_len = new_len;
-                handle->data = new_data;
+				handle->data = new_data;
 				buf = handle->data;
 				remaining = handle->data_size - handle->data_len;
-				handle->end = (uint8_t *)(handle->data) + handle->data_len;
+				handle->end = (uint8_t *) (handle->data) + handle->data_len;
 				end = handle->end;
 			} else {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
@@ -81,11 +81,11 @@
 			ret = 0;
 			snprintf(end, remaining, "%s", data);
 			handle->data_len = strlen(buf);
-			handle->end = (uint8_t *)(handle->data) + handle->data_len;
+			handle->end = (uint8_t *) (handle->data) + handle->data_len;
 		}
 		free(data);
 	}
-	
+
 	return ret ? SWITCH_STATUS_FALSE : SWITCH_STATUS_SUCCESS;
 }
 
@@ -93,7 +93,7 @@
 static int switch_console_process(char *cmd)
 {
 	char *arg = NULL;
-	switch_stream_handle_t stream = {0};
+	switch_stream_handle_t stream = { 0 };
 
 	if (!strcmp(cmd, "shutdown") || !strcmp(cmd, "...")) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Bye!\n");
@@ -103,18 +103,18 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_CONSOLE, "FreeSwitch Version %s\n", SWITCH_VERSION_FULL);
 		return 1;
 	}
-	if ((arg = strchr(cmd, '\r')) != 0  || (arg = strchr(cmd, '\n')) != 0 )  {
+	if ((arg = strchr(cmd, '\r')) != 0 || (arg = strchr(cmd, '\n')) != 0) {
 		*arg = '\0';
 		arg = NULL;
 	}
 	if ((arg = strchr(cmd, ' ')) != 0) {
 		*arg++ = '\0';
 	}
-	
+
 	SWITCH_STANDARD_STREAM(stream);
 	if (stream.data) {
 		if (switch_api_execute(cmd, arg, NULL, &stream) == SWITCH_STATUS_SUCCESS) {
-			switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_CONSOLE, "API CALL [%s(%s)] output:\n%s\n", cmd, arg ? arg : "", (char *)stream.data);
+			switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_CONSOLE, "API CALL [%s(%s)] output:\n%s\n", cmd, arg ? arg : "", (char *) stream.data);
 		} else {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Unknown Command: %s\n", cmd);
 		}
@@ -126,8 +126,7 @@
 	return 1;
 }
 
-SWITCH_DECLARE(void) switch_console_printf(switch_text_channel_t channel, const char *file, const char *func, int line,
-										   const char *fmt, ...)
+SWITCH_DECLARE(void) switch_console_printf(switch_text_channel_t channel, const char *file, const char *func, int line, const char *fmt, ...)
 {
 	char *data = NULL;
 	int ret = 0;
@@ -160,8 +159,7 @@
 			}
 
 			else if (channel == SWITCH_CHANNEL_ID_EVENT &&
-					 switch_event_running() == SWITCH_STATUS_SUCCESS &&
-					 switch_event_create(&event, SWITCH_EVENT_LOG) == SWITCH_STATUS_SUCCESS) {
+					 switch_event_running() == SWITCH_STATUS_SUCCESS && switch_event_create(&event, SWITCH_EVENT_LOG) == SWITCH_STATUS_SUCCESS) {
 
 				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Data", "%s", data);
 				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-File", "%s", filep);
@@ -171,7 +169,7 @@
 			}
 		}
 	}
-	if(data) {
+	if (data) {
 		free(data);
 	}
 	fflush(handle);
@@ -186,11 +184,11 @@
 
 	gethostname(hostname, sizeof(hostname));
 
-	while(running) {
+	while (running) {
 		uint32_t arg;
 #ifndef _MSC_VER
 		fd_set rfds, efds;
-		struct timeval tv = {0, 20000};
+		struct timeval tv = { 0, 20000 };
 #endif
 
 		switch_core_session_ctl(SCSC_CHECK_RUNNING, &arg);
@@ -202,7 +200,7 @@
 			switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_CONSOLE, "\nfreeswitch@%s> ", hostname);
 		}
 #ifdef _MSC_VER
-		activity = WaitForSingleObject(GetStdHandle(STD_INPUT_HANDLE),20);
+		activity = WaitForSingleObject(GetStdHandle(STD_INPUT_HANDLE), 20);
 
 		if (activity == 102) {
 			fflush(stdout);
@@ -213,9 +211,9 @@
 		FD_ZERO(&efds);
 		FD_SET(fileno(stdin), &rfds);
 		FD_SET(fileno(stdin), &efds);
-		if ((activity = select(fileno(stdin)+1, &rfds, NULL, &efds, &tv)) < 0) {
-            break;
-        }
+		if ((activity = select(fileno(stdin) + 1, &rfds, NULL, &efds, &tv)) < 0) {
+			break;
+		}
 
 		if (activity == 0) {
 			fflush(stdout);
@@ -225,13 +223,13 @@
 
 
 		memset(&cmd, 0, sizeof(cmd));
-		for (x = 0; x < (sizeof(cmd)-1); x++) {
-            int c = getchar();
-            if (c < 0) {
-                int y = read(fileno(stdin), cmd, sizeof(cmd));
-                cmd[y-1] = '\0';
-                break;
-            }
+		for (x = 0; x < (sizeof(cmd) - 1); x++) {
+			int c = getchar();
+			if (c < 0) {
+				int y = read(fileno(stdin), cmd, sizeof(cmd));
+				cmd[y - 1] = '\0';
+				break;
+			}
 
 			cmd[x] = (char) c;
 
@@ -240,12 +238,12 @@
 				break;
 			}
 		}
-	
+
 		if (cmd[0]) {
 			running = switch_console_process(cmd);
 		}
 	}
-	
+
 
 }
 

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/switch_core.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/switch_core.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/switch_core.c	Fri Mar 30 12:19:18 2007
@@ -34,184 +34,24 @@
 
 #include <switch.h>
 #include <switch_version.h>
-#ifndef WIN32
-#include <switch_private.h>
-#endif
-
-/* for apr_pool_create and apr_pool_destroy */
-/* functions only used in this file so not exposed */
-#include <apr_pools.h>
-
-/* for apr_hash_make, apr_hash_pool_get, apr_hash_set */
-/* functions only used in this file so not exposed */
-#include <apr_hash.h>
-
-/* for apr_pvsprintf */
-/* function only used in this file so not exposed */
-#include <apr_strings.h>
-
-/* for apr_initialize and apr_terminate */
-/* function only used in this file so not exposed */
-#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>
-#endif
-
-/* #define DEBUG_ALLOC */
-#define DO_EVENTS
-
-#ifdef CRASH_PROT
-#define __CP "ENABLED"
-#else
-#define __CP "DISABLED"
-#endif
-
-#define SWITCH_EVENT_QUEUE_LEN 256
-#define SWITCH_MESSAGE_QUEUE_LEN 256
-#define SWITCH_SQL_QUEUE_LEN 2000
-
-#define SWITCH_BUFFER_BLOCK_FRAMES 25
-#define SWITCH_BUFFER_START_FRAMES 50
-
-struct switch_media_bug {
-	switch_buffer_t *raw_write_buffer;
-	switch_buffer_t *raw_read_buffer;
-    switch_frame_t *replace_frame_in;
-    switch_frame_t *replace_frame_out;
-	switch_media_bug_callback_t callback;
-	switch_mutex_t *read_mutex;
-	switch_mutex_t *write_mutex;
-	switch_core_session_t *session;
-	void *user_data;
-	uint32_t flags;
-    uint8_t ready;
-	struct switch_media_bug *next;
-};
-
-typedef enum {
-    SSF_NONE = 0,
-    SSF_DESTROYED = (1 << 0)
-} switch_session_flag_t;
-
-struct switch_core_session {
-	uint32_t id;
-	char name[80];
-    switch_session_flag_t flags;
-	int thread_running;
-	switch_memory_pool_t *pool;
-	switch_channel_t *channel;
-	switch_thread_t *thread;
-	const switch_endpoint_interface_t *endpoint_interface;
-	switch_io_event_hooks_t event_hooks;
-	switch_codec_t *read_codec;
-	switch_codec_t *write_codec;
-
-	switch_buffer_t *raw_write_buffer;
-	switch_frame_t raw_write_frame;
-	switch_frame_t enc_write_frame;
-	uint8_t raw_write_buf[SWITCH_RECOMMENDED_BUFFER_SIZE];
-	uint8_t enc_write_buf[SWITCH_RECOMMENDED_BUFFER_SIZE];
-
-	switch_buffer_t *raw_read_buffer;
-	switch_frame_t raw_read_frame;
-	switch_frame_t enc_read_frame;
-	uint8_t raw_read_buf[SWITCH_RECOMMENDED_BUFFER_SIZE];
-	uint8_t enc_read_buf[SWITCH_RECOMMENDED_BUFFER_SIZE];
-
-
-	switch_audio_resampler_t *read_resampler;
-	switch_audio_resampler_t *write_resampler;
-
-	switch_mutex_t *mutex;
-	switch_thread_cond_t *cond;
-
-	switch_thread_rwlock_t *rwlock;
-
-	void *streams[SWITCH_MAX_STREAMS];
-	int stream_count;
+#include "private/switch_core.h"
 
-	char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
-	void *private_info;
-	switch_queue_t *event_queue;
-	switch_queue_t *message_queue;
-	switch_queue_t *private_event_queue;
-	switch_thread_rwlock_t *bug_rwlock;
-	switch_media_bug_t *bugs;
-};
-
-SWITCH_DECLARE_DATA switch_directories SWITCH_GLOBAL_dirs = {0};
-
-struct switch_core_scheduler_task_container {
-	switch_core_scheduler_task_t task;
-	time_t executed;
-	int in_thread;
-	int destroyed;
-	switch_core_scheduler_func_t func;
-	switch_memory_pool_t *pool;
-	uint32_t flags;
-	char *desc;
-	struct switch_core_scheduler_task_container *next;
-};
-typedef struct switch_core_scheduler_task_container switch_core_scheduler_task_container_t;
+SWITCH_DECLARE_DATA switch_directories SWITCH_GLOBAL_dirs = { 0 };
 
-struct switch_core_runtime {
+/* The main runtime obj we keep this hidden for ourselves */
+static struct {
 	switch_time_t initiated;
-	uint32_t session_id;
-	apr_pool_t *memory_pool;
-	switch_hash_t *session_table;
 	switch_hash_t *global_vars;
-	switch_mutex_t *session_table_mutex;
-#ifdef CRASH_PROT
-	switch_hash_t *stack_table;
-#endif
-	switch_core_db_t *db;
-	switch_core_db_t *event_db;
+	switch_memory_pool_t *memory_pool;
 	const switch_state_handler_table_t *state_handlers[SWITCH_MAX_STATE_HANDLERS];
-    int state_handler_index;
+	int state_handler_index;
 	FILE *console;
-	uint32_t session_count;
-	uint32_t session_limit;
-	switch_queue_t *sql_queue;
-	uint32_t no_new_sessions;
-	uint32_t shutting_down;
 	uint8_t running;
 	char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
-	switch_core_scheduler_task_container_t *task_list;
-	switch_mutex_t *task_mutex;
-	uint32_t task_id;
-	int task_thread_running;
-};
-
-/* Prototypes */
-static void *SWITCH_THREAD_FUNC switch_core_session_thread(switch_thread_t *thread, void *obj);
-static void switch_core_standard_on_init(switch_core_session_t *session);
-static void switch_core_standard_on_hangup(switch_core_session_t *session);
-static void switch_core_standard_on_ring(switch_core_session_t *session);
-static void switch_core_standard_on_execute(switch_core_session_t *session);
-static void switch_core_standard_on_loopback(switch_core_session_t *session);
-static void switch_core_standard_on_transmit(switch_core_session_t *session);
-static void switch_core_standard_on_hold(switch_core_session_t *session);
-
-
-/* The main runtime obj we keep this hidden for ourselves */
-static struct switch_core_runtime runtime;
-
-static void db_pick_path(char *dbname, char *buf, switch_size_t size)
-{
+	uint32_t no_new_sessions;
+	uint32_t shutting_down;
+} runtime;
 
-	memset(buf, 0, size);
-	if (strchr(dbname, '/')) {
-		strncpy(buf, dbname, size);
-	} else {
-		snprintf(buf, size, "%s%s%s.db", SWITCH_GLOBAL_dirs.db_dir, SWITCH_PATH_SEPARATOR, dbname);
-	}
-}
 
 static void send_heartbeat(void)
 {
@@ -219,10 +59,10 @@
 	switch_core_time_duration_t duration;
 
 	switch_core_measure_time(switch_core_uptime(), &duration);
-	
+
 	if (switch_event_create(&event, SWITCH_EVENT_HEARTBEAT) == SWITCH_STATUS_SUCCESS) {
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Event-Info", "System Ready");
-		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Up-Time", 
+		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Up-Time",
 								"%u year%s, "
 								"%u day%s, "
 								"%u hour%s, "
@@ -232,4372 +72,203 @@
 								"%u microsecond%s\n",
 								duration.yr, duration.yr == 1 ? "" : "s",
 								duration.day, duration.day == 1 ? "" : "s",
-								duration.hr, duration.hr == 1 ? "" : "s",
-								duration.min, duration.min == 1 ? "" : "s",
-								duration.sec, duration.sec == 1 ? "" : "s",
-								duration.ms, duration.ms == 1 ? "" : "s",
-								duration.mms, duration.mms == 1 ? "" : "s"
-								);
-
-		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Session-Count", "%u", switch_core_session_count());
-		switch_event_fire(&event);
-	}
-}
-
-static void heartbeat_callback(switch_core_scheduler_task_t *task)
-{
-	send_heartbeat();
-
-	/* reschedule this task */
-	task->runtime += 20;
-}
-
-static void switch_core_scheduler_execute(switch_core_scheduler_task_container_t *tp)
-{
-	//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Executing task %u %s (%s)\n", tp->task.task_id, tp->desc, switch_str_nil(tp->task.group));
-	
-	tp->func(&tp->task);
-
-	if (tp->task.runtime > tp->executed) {
-		tp->executed = 0;
-	} else {
-		tp->destroyed = 1;
-	}
-}
-
-static void *SWITCH_THREAD_FUNC task_own_thread(switch_thread_t *thread, void *obj)
-{
-	switch_core_scheduler_task_container_t *tp = (switch_core_scheduler_task_container_t *) obj;
-	switch_memory_pool_t *pool;
-
-	pool = tp->pool;
-	tp->pool = NULL;
-	
-	switch_core_scheduler_execute(tp);
-	switch_core_destroy_memory_pool(&pool);
-	tp->in_thread = 0;
-
-	return NULL;
-}
-
-static int task_thread_loop(int done)
-{
-	switch_core_scheduler_task_container_t *tofree, *tp, *last = NULL;
-
-
-	switch_mutex_lock(runtime.task_mutex);
-	for (tp = runtime.task_list; tp; tp = tp->next) {
-		if (done) {
-			tp->destroyed = 1;
-		} else {
-			time_t now = time(NULL);
-			if (now >= tp->task.runtime && !tp->in_thread) {
-				tp->executed = now;
-				if (switch_test_flag(tp, SSHF_OWN_THREAD)) {
-					switch_thread_t *thread;
-					switch_threadattr_t *thd_attr;
-					assert(switch_core_new_memory_pool(&tp->pool) == SWITCH_STATUS_SUCCESS);
-					switch_threadattr_create(&thd_attr, tp->pool);
-					switch_threadattr_detach_set(thd_attr, 1);
-					tp->in_thread = 1;
-					switch_thread_create(&thread, thd_attr, task_own_thread, tp, tp->pool);
-				} else {
-					switch_core_scheduler_execute(tp);
-				}
-			}
-		}
-	}
-	switch_mutex_unlock(runtime.task_mutex);
-	switch_mutex_lock(runtime.task_mutex);
-	for (tp = runtime.task_list; tp; ) {
-		if (tp->destroyed && !tp->in_thread) {
-			tofree = tp;
-			tp = tp->next;
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Deleting task %u %s (%s)\n", 
-							  tofree->task.task_id, tofree->desc, switch_str_nil(tofree->task.group));
-			if (last) {
-				last->next = tofree->next;
-			} else {
-				runtime.task_list = tofree->next;
-			}
-			switch_safe_free(tofree->task.group);
-			if (tofree->task.cmd_arg && switch_test_flag(tofree, SSHF_FREE_ARG)) {
-				free(tofree->task.cmd_arg);
-			}
-			switch_safe_free(tofree->desc);
-			free(tofree);
-		} else {
-			last = tp;
-			tp = tp->next;
-		}
-	}
-	switch_mutex_unlock(runtime.task_mutex);
-
-	return done;
-}
-
-static void *SWITCH_THREAD_FUNC switch_core_task_thread(switch_thread_t *thread, void *obj)
-{
-
-	runtime.task_thread_running = 1;
-
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Starting task thread\n");
-	while(runtime.task_thread_running == 1) {
-		if (task_thread_loop(0)) {
-			break;
-		}
-		switch_yield(500000);
-	}
-
-	task_thread_loop(1);
-
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Task thread ending\n");
-	runtime.task_thread_running = 0;
-	
-	return NULL;
-}
-
-static void switch_core_task_thread_launch(void) 
-{
-	switch_thread_t *thread;
-	switch_threadattr_t *thd_attr;
-	switch_threadattr_create(&thd_attr, runtime.memory_pool);
-	switch_threadattr_detach_set(thd_attr, 1);
-	switch_thread_create(&thread, thd_attr, switch_core_task_thread, NULL, runtime.memory_pool);
-}
-
-SWITCH_DECLARE(uint32_t) switch_core_scheduler_add_task(time_t task_runtime,
-														switch_core_scheduler_func_t func,
-														char *desc,
-														char *group,
-														uint32_t cmd_id,
-														void *cmd_arg,
-														switch_scheduler_flag_t flags)
-{
-	switch_core_scheduler_task_container_t *container, *tp;
-	
-	switch_mutex_lock(runtime.task_mutex);
-	assert((container = malloc(sizeof(*container))));
-	memset(container, 0, sizeof(*container));
-	assert(func);
-	container->func = func;	
-	time(&container->task.created);
-	container->task.runtime = task_runtime;
-	container->task.group = strdup(group ? group : "none");
-	container->task.cmd_id = cmd_id;
-	container->task.cmd_arg = cmd_arg;
-	container->flags = flags;
-	container->desc = strdup(desc ? desc : "none");
-	
-	for (tp = runtime.task_list; tp && tp->next; tp = tp->next);
-
-	if (tp) {
-		tp->next = container;
-	} else {
-		runtime.task_list = container;
-	}
-
-	for (container->task.task_id = 0; !container->task.task_id; container->task.task_id = ++runtime.task_id);
-
-	switch_mutex_unlock(runtime.task_mutex);
-	
-	tp = container;
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Added task %u %s (%s) to run at %"TIME_T_FMT"\n", 
-					  tp->task.task_id, tp->desc, switch_str_nil(tp->task.group), task_runtime);
-
-	
-	return container->task.task_id;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_scheduler_del_task_id(uint32_t task_id)
-{
-	switch_core_scheduler_task_container_t *tp;
-	switch_status_t status = SWITCH_STATUS_FALSE;
-	
-	switch_mutex_lock(runtime.task_mutex);
-    for (tp = runtime.task_list; tp; tp = tp->next) {
-		if (tp->task.task_id == task_id) {
-			tp->destroyed++;
-			status = SWITCH_STATUS_SUCCESS;
-			break;
-		}
-	}
-	switch_mutex_unlock(runtime.task_mutex);
-
-	return status;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_scheduler_del_task_group(char *group)
-{
-	switch_core_scheduler_task_container_t *tp;
-	switch_status_t status = SWITCH_STATUS_FALSE;
-	
-	switch_mutex_lock(runtime.task_mutex);
-    for (tp = runtime.task_list; tp; tp = tp->next) {
-		if (!strcmp(tp->task.group, group)) {
-			tp->destroyed++;
-			status = SWITCH_STATUS_SUCCESS;
-		}
-	}
-	switch_mutex_unlock(runtime.task_mutex);
-
-	return status;
-}
-
-
-static void switch_core_media_bug_destroy(switch_media_bug_t *bug)
-{
-	switch_buffer_destroy(&bug->raw_read_buffer);
-	switch_buffer_destroy(&bug->raw_write_buffer);
-}
-
-
-SWITCH_DECLARE(switch_frame_t *) switch_core_media_bug_get_replace_frame(switch_media_bug_t *bug)
-{
-    return bug->replace_frame_in;
-}
-
-SWITCH_DECLARE(void) switch_core_media_bug_set_replace_frame(switch_media_bug_t *bug, switch_frame_t *frame)
-{
-    bug->replace_frame_out = frame;
-}
-
-SWITCH_DECLARE(void *) switch_core_media_bug_get_user_data(switch_media_bug_t *bug)
-{
-	return bug->user_data;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_media_bug_read(switch_media_bug_t *bug, switch_frame_t *frame)
-{
-	uint32_t bytes = 0;
-	uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE] = {0};
-	uint32_t datalen = 0;
-	int16_t *dp, *fp;
-	uint32_t x;
-	size_t rlen = 0;
-	size_t wlen = 0;
-	uint32_t blen;
-	size_t rdlen = 0;
-	uint32_t maxlen;
-	switch_codec_t *read_codec = switch_core_session_get_read_codec(bug->session);
-	
-	if (bug->raw_read_buffer) {
-		rlen = switch_buffer_inuse(bug->raw_read_buffer);
-	}
-
-	if (bug->raw_write_buffer) {
-		wlen = switch_buffer_inuse(bug->raw_write_buffer);
-	}
-
-	if ((bug->raw_read_buffer && bug->raw_write_buffer) && (!rlen && !wlen)) {
-		return SWITCH_STATUS_FALSE;
-	}
-
-
-	maxlen = sizeof(data) > frame->buflen ? frame->buflen :  sizeof(data);
-	if ((rdlen = rlen > wlen ? wlen : rlen) > maxlen) {
-		rdlen = maxlen;
-	}
-
-	if (!rdlen) {
-		rdlen = maxlen;
-	}
-
-	frame->datalen = 0;
-
-	if (rlen) {
-		switch_mutex_lock(bug->read_mutex);
-		
-		frame->datalen = (uint32_t) switch_buffer_read(bug->raw_read_buffer,
-													   frame->data,
-													   rdlen);
-		switch_mutex_unlock(bug->read_mutex);
-	}
-
-	if (wlen) {
-		switch_mutex_lock(bug->write_mutex);
-		datalen = (uint32_t) switch_buffer_read(bug->raw_write_buffer,
-												data,
-												rdlen);
-		switch_mutex_unlock(bug->write_mutex);
-	}
-
-
-	bytes = (datalen > frame->datalen) ? datalen : frame->datalen;
-
-	if (bytes) {
-		dp = (int16_t *) data;
-		fp = (int16_t *) frame->data;
-		
-		rlen = frame->datalen / 2;
-		wlen = datalen / 2;
-		blen = bytes / 2;
-		
-		for(x = 0; x < blen; x++) {
-			int32_t z = 0;
-
-			if (x < rlen) {
-				z += (int32_t) *(fp+x);
-			}
-			if (x < wlen) {
-				z += (int32_t)*(dp+x);
-			}
-			switch_normalize_to_16bit(z);
-			*(fp+x) = (int16_t) z;
-		}
-
-		frame->datalen = bytes;
-		frame->samples = bytes / sizeof(int16_t);
-		frame->rate = read_codec->implementation->samples_per_second;
-		
-		return SWITCH_STATUS_SUCCESS;
-	}
-
-	return SWITCH_STATUS_FALSE;
-}
-
-#define MAX_BUG_BUFFER 1024 * 512
-SWITCH_DECLARE(switch_status_t) switch_core_media_bug_add(switch_core_session_t *session,
-														  switch_media_bug_callback_t callback,
-														  void *user_data,
-														  switch_media_bug_flag_t flags,
-														  switch_media_bug_t **new_bug)
-
-{
-	switch_media_bug_t *bug, *bp;
-	switch_size_t bytes;
-
-    if (flags & SMBF_WRITE_REPLACE) {
-        switch_thread_rwlock_wrlock(session->bug_rwlock);
-        for (bp = session->bugs; bp; bp = bp->next) {
-            if (switch_test_flag(bp, SMBF_WRITE_REPLACE)) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Only one bug of this type allowed!\n");
-                switch_thread_rwlock_unlock(session->bug_rwlock);
-                return SWITCH_STATUS_GENERR;
-            }
-        }
-        switch_thread_rwlock_unlock(session->bug_rwlock);
-    }
-
-	if (!(bug = switch_core_session_alloc(session, sizeof(*bug)))) {
-		return SWITCH_STATUS_MEMERR;
-	}
-
-	bug->callback = callback;
-	bug->user_data = user_data;
-	bug->session = session;
-	bug->flags = flags;
-    bug->ready = 1;
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Attaching BUG to %s\n", switch_channel_get_name(session->channel));
-	bytes = session->read_codec->implementation->bytes_per_frame;
-
-	if (!bug->flags) {
-		bug->flags = (SMBF_READ_STREAM | SMBF_WRITE_STREAM);
-	}
-
-	if (switch_test_flag(bug, SMBF_READ_STREAM)) {
-		switch_buffer_create_dynamic(&bug->raw_read_buffer, bytes * SWITCH_BUFFER_BLOCK_FRAMES, bytes * SWITCH_BUFFER_START_FRAMES, MAX_BUG_BUFFER);
-		switch_mutex_init(&bug->read_mutex, SWITCH_MUTEX_NESTED, session->pool);
-	}
-
-	bytes = session->write_codec->implementation->bytes_per_frame;
-
-	if (switch_test_flag(bug, SMBF_WRITE_STREAM)) {
-		switch_buffer_create_dynamic(&bug->raw_write_buffer, bytes * SWITCH_BUFFER_BLOCK_FRAMES, bytes * SWITCH_BUFFER_START_FRAMES, MAX_BUG_BUFFER);
-		switch_mutex_init(&bug->write_mutex, SWITCH_MUTEX_NESTED, session->pool);
-	}
-
-	switch_thread_rwlock_wrlock(session->bug_rwlock);
-	bug->next = session->bugs;
-	session->bugs = bug;
-	switch_thread_rwlock_unlock(session->bug_rwlock);
-	*new_bug = bug;
-
-	if (bug->callback) {
-		switch_bool_t result = bug->callback(bug, bug->user_data, SWITCH_ABC_TYPE_INIT);
-		if (result == SWITCH_FALSE) {
-			return switch_core_media_bug_remove(session, new_bug);
-		}
-	}
-
-	return SWITCH_STATUS_SUCCESS;
-}
-
-
-SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove_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) {
-			if (bp->callback) {
-				bp->callback(bp, bp->user_data, SWITCH_ABC_TYPE_CLOSE);
-			}
-			switch_core_media_bug_destroy(bp);
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Removing BUG from %s\n", switch_channel_get_name(session->channel));
-		}
-		switch_thread_rwlock_unlock(session->bug_rwlock);
-		session->bugs = NULL;
-		return SWITCH_STATUS_SUCCESS;
-	}
-
-	return SWITCH_STATUS_FALSE;
-}
-
-static switch_status_t switch_core_media_bug_close(switch_media_bug_t **bug)
-{
-	switch_media_bug_t *bp = *bug;
-	if (bp) {
-		if (bp->callback) {
-			bp->callback(bp, bp->user_data, SWITCH_ABC_TYPE_CLOSE);
-			bp->ready = 0;
-		}
-		switch_core_media_bug_destroy(bp);
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Removing BUG from %s\n", switch_channel_get_name(bp->session->channel));
-		*bug = NULL;
-		return SWITCH_STATUS_SUCCESS;
-	}
-
-	return SWITCH_STATUS_FALSE;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove(switch_core_session_t *session, switch_media_bug_t **bug)
-{
-	switch_media_bug_t *bp = NULL, *last = NULL;
-	switch_status_t status = SWITCH_STATUS_FALSE;
-
-	if (session->bugs) {
-		switch_thread_rwlock_wrlock(session->bug_rwlock);
-		for (bp = session->bugs; bp; bp = bp->next) {
-            if (!bp->ready) {
-                continue;
-            }
-			if (bp == *bug) {
-				if (last) {
-					last->next = bp->next;
-				} else {
-					session->bugs = bp->next;
-				}
-				break;
-			}
-			last = bp;
-		}
-		switch_thread_rwlock_unlock(session->bug_rwlock);
-		status = switch_core_media_bug_close(&bp);
-	}
-
-	return status;
-}
-
-struct switch_core_port_allocator {
-	switch_port_t start;
-	switch_port_t end;
-	switch_port_t next;
-	uint8_t inc;
-	switch_mutex_t *mutex;
-	switch_memory_pool_t *pool;
-};
-
-SWITCH_DECLARE(switch_status_t) switch_core_port_allocator_new(switch_port_t start,
-															   switch_port_t end,
-															   uint8_t inc,
-															   switch_core_port_allocator_t **new_allocator)
-{
-	switch_status_t status;
-	switch_memory_pool_t *pool;
-	switch_core_port_allocator_t *alloc;
-
-	if ((status = switch_core_new_memory_pool(&pool)) != SWITCH_STATUS_SUCCESS) {
-		return status;
-	}
-
-	if (!(alloc = switch_core_alloc(pool, sizeof(*alloc)))) {
-		switch_core_destroy_memory_pool(&pool);
-		return SWITCH_STATUS_MEMERR;
-	}
-	
-	alloc->start = start;
-	alloc->next = start;
-	alloc->end = end;
-	if (!(alloc->inc = inc)) {
-		alloc->inc = 2;
-	}
-	switch_mutex_init(&alloc->mutex, SWITCH_MUTEX_NESTED, pool);
-	alloc->pool = pool;
-	*new_allocator = alloc;
-
-	return SWITCH_STATUS_SUCCESS;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_management_exec(char *relative_oid,
-															switch_management_action_t action,
-															char *data,
-															switch_size_t datalen)
-{
-	const switch_management_interface_t *ptr;
-	switch_status_t status = SWITCH_STATUS_FALSE;
-
-	if ((ptr = switch_loadable_module_get_management_interface(relative_oid))) {
-		status = ptr->management_function(relative_oid, action, data, datalen);
-	}
-
-	return status;
-}
-
-
-
-SWITCH_DECLARE(switch_port_t) switch_core_port_allocator_request_port(switch_core_port_allocator_t *alloc)
-{
-	switch_port_t port;
-
-	switch_mutex_lock(alloc->mutex);
-	port = alloc->next;
-	alloc->next = alloc->next + alloc->inc;
-	if (alloc->next > alloc->end) {
-		alloc->next = alloc->start;
-	}
-	switch_mutex_unlock(alloc->mutex);
-	return port;
-}
-
-SWITCH_DECLARE(void) switch_core_port_allocator_destroy(switch_core_port_allocator_t **alloc)
-{
-	switch_memory_pool_t *pool = (*alloc)->pool;
-	switch_core_destroy_memory_pool(&pool);
-	*alloc = NULL;
-}
-
-SWITCH_DECLARE(switch_core_db_t *) switch_core_db_open_file(char *filename)
-{
-	switch_core_db_t *db;
-	char path[1024];
-
-	db_pick_path(filename, path, sizeof(path));
-	if (switch_core_db_open(path, &db)) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR [%s]\n", switch_core_db_errmsg(db));
-		switch_core_db_close(db);
-		db = NULL;
-	}
-	return db;
-}
-
-
-SWITCH_DECLARE(void) switch_core_db_test_reactive(switch_core_db_t *db, char *test_sql, char *reactive_sql) 
-{
-    char *errmsg;
-
-    if(db) {
-        if(test_sql) {
-            switch_core_db_exec(
-                         db,
-                         test_sql,
-                         NULL,
-                         NULL,
-                         &errmsg
-                         );
-
-            if (errmsg) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SQL ERR [%s]\n[%s]\nAuto Generating Table!\n", errmsg, test_sql);
-                switch_core_db_free(errmsg);
-                errmsg = NULL;
-                switch_core_db_exec(
-									db,
-                             reactive_sql,
-                             NULL,
-                             NULL,
-                             &errmsg
-                             );
-                if (errmsg) {
-                    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SQL ERR [%s]\n[%s]\n", errmsg, reactive_sql);
-                    switch_core_db_free(errmsg);
-                    errmsg = NULL;
-                }
-            }
-        }
-    }
-
-}
-
-
-
-SWITCH_DECLARE(switch_status_t) switch_core_set_console(char *console)
-{
-	if ((runtime.console = fopen(console, "a")) == 0) {
-		fprintf(stderr, "Cannot open output file %s.\n", console);
-		return SWITCH_STATUS_FALSE;
-	}
-	
-	return SWITCH_STATUS_SUCCESS;
-}
-
-SWITCH_DECLARE(FILE *) switch_core_get_console(void)
-{
-	return runtime.console;
-}
-
-SWITCH_DECLARE(FILE *) switch_core_data_channel(switch_text_channel_t channel)
-{
-	FILE *handle = stdout;
-
-	switch (channel) {
-	case SWITCH_CHANNEL_ID_LOG:
-	case SWITCH_CHANNEL_ID_LOG_CLEAN:
-		handle = runtime.console;
-		break;
-	default:
-		handle = runtime.console;
-		break;
-	}
-
-	return handle;
-}
-
-SWITCH_DECLARE(int) switch_core_add_state_handler(const switch_state_handler_table_t *state_handler)
-{
-	int index = runtime.state_handler_index++;
-
-	if (runtime.state_handler_index >= SWITCH_MAX_STATE_HANDLERS) {
-		return -1;
-	}
-
-	runtime.state_handlers[index] = state_handler;
-	return index;
-}
-
-SWITCH_DECLARE(const switch_state_handler_table_t *) switch_core_get_state_handler(int index)
-{
-
-	if (index > SWITCH_MAX_STATE_HANDLERS || index > runtime.state_handler_index) {
-		return NULL;
-	}
-
-	return runtime.state_handlers[index];
-}
-
-#ifdef SWITCH_DEBUG_RWLOCKS
-SWITCH_DECLARE(switch_status_t) switch_core_session_perform_read_lock(switch_core_session_t *session,
-                                                                      const char *file,
-                                                                      const char *func,
-                                                                      int line)
-#else
-SWITCH_DECLARE(switch_status_t) switch_core_session_read_lock(switch_core_session_t *session)
-#endif
-{
-	switch_status_t status = SWITCH_STATUS_FALSE;
-
-    if (session->rwlock) {
-        if (switch_test_flag(session, SSF_DESTROYED)) {
-            status = SWITCH_STATUS_FALSE;
-#ifdef SWITCH_DEBUG_RWLOCKS
-            switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, SWITCH_LOG_ERROR, "%s Read lock FAIL\n", 
-                              switch_channel_get_name(session->channel));
-#endif
-        } else {
-            status = (switch_status_t) switch_thread_rwlock_tryrdlock(session->rwlock);
-#ifdef SWITCH_DEBUG_RWLOCKS
-            switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, SWITCH_LOG_ERROR, "%s Read lock AQUIRED\n", 
-                              switch_channel_get_name(session->channel));
-#endif
-        }	
-    }
-
-	return status;
-}
-
-#ifdef SWITCH_DEBUG_RWLOCKS
-SWITCH_DECLARE(void) switch_core_session_perform_write_lock(switch_core_session_t *session,
-                                                            const char *file,
-                                                            const char *func,
-                                                            int line)
-{
-
-    switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, SWITCH_LOG_ERROR, "%s Write lock AQUIRED\n", 
-                      switch_channel_get_name(session->channel));
-#else
-SWITCH_DECLARE(void) switch_core_session_write_lock(switch_core_session_t *session)
-{
-#endif
-	switch_thread_rwlock_wrlock(session->rwlock);
-}
-
-#ifdef SWITCH_DEBUG_RWLOCKS
-SWITCH_DECLARE(void) switch_core_session_perform_rwunlock(switch_core_session_t *session,
-                                                  const char *file,
-                                                  const char *func,
-                                                  int line)
-{
-    switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, SWITCH_LOG_ERROR, "%s Read/Write lock CLEARED\n", 
-                      switch_channel_get_name(session->channel));
-#else
-SWITCH_DECLARE(void) switch_core_session_rwunlock(switch_core_session_t *session)
-{
-#endif
-	switch_thread_rwlock_unlock(session->rwlock);
-    
-}
-
-SWITCH_DECLARE(char *) switch_core_get_variable(char *varname)
-{
-	return (char *) switch_core_hash_find(runtime.global_vars, varname);
-}
-
-SWITCH_DECLARE(void) switch_core_set_variable(char *varname, char *value)
-{
-    switch_core_hash_insert(runtime.global_vars, switch_core_strdup(runtime.memory_pool, varname), switch_core_strdup(runtime.memory_pool, value));
-}
-
-
-#ifdef SWITCH_DEBUG_RWLOCKS
-SWITCH_DECLARE(switch_core_session_t *) switch_core_session_perform_locate(char *uuid_str,
-                                                                           const char *file,
-                                                                           const char *func,
-                                                                           int line)
-#else
-SWITCH_DECLARE(switch_core_session_t *) switch_core_session_locate(char *uuid_str)
-#endif
-{
-	switch_core_session_t *session = NULL;
-
-	if (uuid_str) {
-		switch_mutex_lock(runtime.session_table_mutex);
-		if ((session = switch_core_hash_find(runtime.session_table, uuid_str))) {
-			/* Acquire a read lock on the session */
-#ifdef SWITCH_DEBUG_RWLOCKS
-			if (switch_core_session_perform_read_lock(session, file, func, line) != SWITCH_STATUS_SUCCESS) {
-#else
-            if (switch_core_session_read_lock(session) != SWITCH_STATUS_SUCCESS) {
-#endif
-				/* not available, forget it */
-				session = NULL;
-			}
-		}
-		switch_mutex_unlock(runtime.session_table_mutex);
-	}
-
-    /* if its not NULL, now it's up to you to rwunlock this */
-    return session;
-}
-
-SWITCH_DECLARE(void) switch_core_session_hupall(switch_call_cause_t cause)
-{
-	switch_hash_index_t *hi;
-	void *val;
-	switch_core_session_t *session;
-	switch_channel_t *channel;
-    uint32_t loops = 0;
-
-	switch_mutex_lock(runtime.session_table_mutex);
-	for (hi = switch_hash_first(runtime.memory_pool, runtime.session_table); hi; hi = switch_hash_next(hi)) {
-        switch_hash_this(hi, NULL, NULL, &val);
-		if (val) {
-			session = (switch_core_session_t *) val;
-			channel = switch_core_session_get_channel(session);
-			switch_channel_hangup(channel, cause);
-			switch_core_session_kill_channel(session, SWITCH_SIG_KILL);
-		}
-	}
-	switch_mutex_unlock(runtime.session_table_mutex);
-
-	while(runtime.session_count > 0) {
-		switch_yield(100000);
-        if (++loops == 100) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Giving up with %d session%s remaining\n", 
-                              runtime.session_count, runtime.session_count == 1 ? "" : "s");
-            break;
-        }
-	}
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_session_message_send(char *uuid_str, switch_core_session_message_t *message)
-{
-	switch_core_session_t *session = NULL;
-	switch_status_t status = SWITCH_STATUS_FALSE;
-
-	switch_mutex_lock(runtime.session_table_mutex);
-	if ((session = switch_core_hash_find(runtime.session_table, uuid_str)) != 0) {
-		/* Acquire a read lock on the session or forget it the channel is dead */
-		if (switch_core_session_read_lock(session) == SWITCH_STATUS_SUCCESS) {
-			if (switch_channel_get_state(session->channel) < CS_HANGUP) {
-				status = switch_core_session_receive_message(session, message);
-			}
-            switch_core_session_rwunlock(session);
-		}
-	}
-	switch_mutex_unlock(runtime.session_table_mutex);
-
-	return status;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_session_event_send(char *uuid_str, switch_event_t **event)
-{
-	switch_core_session_t *session = NULL;
-	switch_status_t status = SWITCH_STATUS_FALSE;
-
-	switch_mutex_lock(runtime.session_table_mutex);
-	if ((session = switch_core_hash_find(runtime.session_table, uuid_str)) != 0) {
-		/* Acquire a read lock on the session or forget it the channel is dead */
-		if (switch_core_session_read_lock(session) == SWITCH_STATUS_SUCCESS) {
-			if (switch_channel_get_state(session->channel) < CS_HANGUP) {
-				status = switch_core_session_queue_event(session, event);
-			}
-            switch_core_session_rwunlock(session);
-		}
-	}
-	switch_mutex_unlock(runtime.session_table_mutex);
-
-	return status;
-}
-
-SWITCH_DECLARE(char *) switch_core_get_uuid(void)
-{
-	return runtime.uuid_str;
-}
-
-SWITCH_DECLARE(char *) switch_core_session_get_uuid(switch_core_session_t *session)
-{
-	return session->uuid_str;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_session_set_read_codec(switch_core_session_t *session, switch_codec_t *codec)
-{
-	switch_event_t *event;
-
-	assert(session != NULL);
-
-	if (switch_event_create(&event, SWITCH_EVENT_CODEC) == SWITCH_STATUS_SUCCESS) {
-		switch_channel_event_set_data(session->channel, event);
-		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-read-codec-name", "%s", codec->implementation->iananame);
-		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-read-codec-rate", "%d", codec->implementation->samples_per_second);
-		switch_event_fire(&event);
-	}
-				
-	session->read_codec = codec;
-	return SWITCH_STATUS_SUCCESS;
-}
-
-SWITCH_DECLARE(switch_codec_t *) switch_core_session_get_read_codec(switch_core_session_t *session)
-{
-	return session->read_codec;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_session_set_write_codec(switch_core_session_t *session, switch_codec_t *codec)
-{
-	switch_event_t *event;
-	assert(session != NULL);
-
-	if (switch_event_create(&event, SWITCH_EVENT_CODEC) == SWITCH_STATUS_SUCCESS) {
-		switch_channel_event_set_data(session->channel, event);
-		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-write-codec-name", "%s", codec->implementation->iananame);
-		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-write-codec-rate", "%d", codec->implementation->samples_per_second);
-		switch_event_fire(&event);
-	}
-
-	session->write_codec = codec;
-	return SWITCH_STATUS_SUCCESS;
-}
-
-SWITCH_DECLARE(switch_codec_t *) switch_core_session_get_write_codec(switch_core_session_t *session)
-{
-	return session->write_codec;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_codec_init(switch_codec_t *codec, char *codec_name, char *fmtp, 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;
-	const switch_codec_implementation_t *iptr, *implementation = NULL;
-	char *mode = fmtp; 
-
-	assert(codec != NULL);
-	assert(codec_name != NULL);
-
-	memset(codec, 0, sizeof(*codec));
-
-	if ((codec_interface = switch_loadable_module_get_codec_interface(codec_name)) == 0) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "invalid codec %s!\n", codec_name);
-		return SWITCH_STATUS_GENERR;
-	}
-
-	if (!strcasecmp(codec_name, "ilbc") && mode && strncasecmp(mode, "mode=", 5)) {
-		int mms;
-		mode += 5;
-		if (mode) {
-			mms = atoi(mode);
-			if (mms > 0 && mms < 120) {
-				ms = mms;
-			}
-		}
-	}
-	
-    /* If no specific codec interval is requested opt for 20ms above all else because lots of stuff assumes it */
-    if (!ms) {
-        for (iptr = codec_interface->implementations; iptr; iptr = iptr->next) {
-            if ((!rate || rate == iptr->samples_per_second) &&
-                (20 == (iptr->microseconds_per_frame / 1000)) &&
-                (!channels || channels == iptr->number_of_channels)) {
-                implementation = iptr;
-                goto found;
-            }
-        }
-    }
-
-    /* Either looking for a specific interval or there was no interval specified and there wasn't one @20ms available*/
-	for (iptr = codec_interface->implementations; iptr; iptr = iptr->next) {
-		if ((!rate || rate == iptr->samples_per_second) &&
-			(!ms || ms == (iptr->microseconds_per_frame / 1000)) &&
-			(!channels || channels == iptr->number_of_channels)) {
-			implementation = iptr;
-			break;
-		}
-	}
-
- found:
-
-	if (implementation) {
-		switch_status_t status;
-		codec->codec_interface = codec_interface;
-		codec->implementation = implementation;
-		codec->flags = flags;
-		
-		if (pool) {
-			codec->memory_pool = pool;
-		} else {
-			if ((status = switch_core_new_memory_pool(&codec->memory_pool)) != SWITCH_STATUS_SUCCESS) {
-				return status;
-			}
-			switch_set_flag(codec, SWITCH_CODEC_FLAG_FREE_POOL);
-		}
-
-		if (fmtp) {
-			codec->fmtp_in = switch_core_strdup(codec->memory_pool, fmtp);
-		}
-
-		implementation->init(codec, flags, codec_settings);
-
-		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);
-	}
-
-	return SWITCH_STATUS_NOTIMPL;
-
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_codec_encode(switch_codec_t *codec,
-													   switch_codec_t *other_codec,
-													   void *decoded_data,
-													   uint32_t decoded_data_len,
-													   uint32_t decoded_rate,
-													   void *encoded_data,
-													   uint32_t *encoded_data_len, uint32_t *encoded_rate, unsigned int *flag)
-{
-	assert(codec != NULL);
-	assert(encoded_data != NULL);
-	assert(decoded_data != NULL);
-
-	if (!codec->implementation) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec is not initilized!\n");
-		return SWITCH_STATUS_GENERR;
-	}
-
-	if (!switch_test_flag(codec, SWITCH_CODEC_FLAG_ENCODE)) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec's encoder is not initilized!\n");
-		return SWITCH_STATUS_GENERR;
-	}
-
-
-	return codec->implementation->encode(codec,
-										 other_codec,
-										 decoded_data,
-										 decoded_data_len,
-										 decoded_rate, encoded_data, encoded_data_len, encoded_rate, flag);
-
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_codec_decode(switch_codec_t *codec,
-													   switch_codec_t *other_codec,
-													   void *encoded_data,
-													   uint32_t encoded_data_len,
-													   uint32_t encoded_rate,
-													   void *decoded_data,
-													   uint32_t *decoded_data_len, 
-													   uint32_t *decoded_rate, 
-													   unsigned int *flag)
-{
-
-	assert(codec != NULL);
-	assert(encoded_data != NULL);
-	assert(decoded_data != NULL);
-
-
-
-	if (!codec->implementation) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec is not initilized!\n");
-		return SWITCH_STATUS_GENERR;
-	}
-
-	if (!switch_test_flag(codec, SWITCH_CODEC_FLAG_DECODE)) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec's decoder is not initilized!\n");
-		return SWITCH_STATUS_GENERR;
-	}
-
-
-	return codec->implementation->decode(codec,
-										 other_codec,
-										 encoded_data,
-										 encoded_data_len,
-										 encoded_rate, decoded_data, decoded_data_len, decoded_rate, flag);
-
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_codec_destroy(switch_codec_t *codec)
-{
-	assert(codec != NULL);
-
-	if (!codec->implementation) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Codec is not initilized!\n");
-		return SWITCH_STATUS_GENERR;
-	}
-
-	codec->implementation->destroy(codec);
-
-	if (switch_test_flag(codec, SWITCH_CODEC_FLAG_FREE_POOL)) {
-		switch_core_destroy_memory_pool(&codec->memory_pool);
-	}
-
-	return SWITCH_STATUS_SUCCESS;
- }
-
-SWITCH_DECLARE(switch_status_t) switch_core_file_open(switch_file_handle_t *fh, 
-													  char *file_path, 
-													  uint8_t channels,
-													  uint32_t rate,
-													  unsigned int flags,
-													  switch_memory_pool_t *pool)
-{
-	char *ext;
-	switch_status_t status;
-	char stream_name[128] = "";
-	char *rhs = NULL;
-	
-	if ((rhs = strstr(file_path, SWITCH_URL_SEPARATOR))) {
-		switch_copy_string(stream_name, file_path, (rhs+1) - file_path);
-		ext = stream_name;
-		file_path = rhs + 3;
-	} else {
-		if ((ext = strrchr(file_path, '.')) == 0) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Format\n");
-			return SWITCH_STATUS_FALSE;
-		}
-		ext++;
-	}
-
-	if ((fh->file_interface = switch_loadable_module_get_file_interface(ext)) == 0) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "invalid file format [%s]!\n", ext);
-		return SWITCH_STATUS_GENERR;
-	}
-
-	fh->flags = flags;
-	if (pool) {
-		fh->memory_pool = pool;
-	} else {
-		if ((status = switch_core_new_memory_pool(&fh->memory_pool)) != SWITCH_STATUS_SUCCESS) {
-			return status;
-		}
-		switch_set_flag(fh, SWITCH_FILE_FLAG_FREE_POOL);
-	}
-
-	if (rhs) {
-		fh->handler = switch_core_strdup(fh->memory_pool, rhs);
-	}
-
-	if (rate) {
-		fh->samplerate = rate;
-	} else {
-		rate = 8000;
-	}
-	
-	if (channels) {
-		fh->channels = channels;
-	} else {
-		fh->channels = 1;
-	}
-
-	if ((status = fh->file_interface->file_open(fh, file_path)) == SWITCH_STATUS_SUCCESS) {
-		switch_set_flag(fh, SWITCH_FILE_OPEN);
-	}
-
-	return status;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_file_read(switch_file_handle_t *fh, void *data, switch_size_t *len)
-{
-	assert(fh != NULL);
-
-	return fh->file_interface->file_read(fh, data, len);
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_file_write(switch_file_handle_t *fh, void *data, switch_size_t *len)
-{
-	assert(fh != NULL);
-
-	return fh->file_interface->file_write(fh, data, len);
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_file_seek(switch_file_handle_t *fh, unsigned int *cur_pos, int64_t samples,
-													int whence)
-{
-	assert(fh != NULL);
-
-	switch_set_flag(fh, SWITCH_FILE_SEEK);
-	return fh->file_interface->file_seek(fh, cur_pos, samples, whence);
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_file_set_string(switch_file_handle_t *fh, switch_audio_col_t col, const char *string)
-{
-	assert(fh != NULL);
-
-	return fh->file_interface->file_set_string(fh, col, string);
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_file_get_string(switch_file_handle_t *fh, switch_audio_col_t col, const char **string)
-{
-	assert(fh != NULL);
-	
-	return fh->file_interface->file_get_string(fh, col, string);
-
-}
-
-
-SWITCH_DECLARE(switch_status_t) switch_core_file_close(switch_file_handle_t *fh)
-{
-	switch_clear_flag(fh, SWITCH_FILE_OPEN);
-	return fh->file_interface->file_close(fh);
-
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_directory_open(switch_directory_handle_t *dh, 
-														 char *module_name, 
-														 char *source,
-														 char *dsn,
-														 char *passwd,
-														 switch_memory_pool_t *pool)
-{
-	switch_status_t status;
-
-	if ((dh->directory_interface = switch_loadable_module_get_directory_interface(module_name)) == 0) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "invalid directory module [%s]!\n", module_name);
-		return SWITCH_STATUS_GENERR;
-	}
-
-	if (pool) {
-		dh->memory_pool = pool;
-	} else {
-		if ((status = switch_core_new_memory_pool(&dh->memory_pool)) != SWITCH_STATUS_SUCCESS) {
-			return status;
-		}
-		switch_set_flag(dh, SWITCH_DIRECTORY_FLAG_FREE_POOL);
-	}
-
-	return dh->directory_interface->directory_open(dh, source, dsn, passwd);
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_directory_query(switch_directory_handle_t *dh, char *base, char *query)
-{
-	return dh->directory_interface->directory_query(dh, base, query);
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_directory_next(switch_directory_handle_t *dh)
-{
-	return dh->directory_interface->directory_next(dh);
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_directory_next_pair(switch_directory_handle_t *dh, char **var, char **val)
-{
-	return dh->directory_interface->directory_next_pair(dh, var, val);
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_directory_close(switch_directory_handle_t *dh)
-{
-	return dh->directory_interface->directory_close(dh);
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_speech_open(switch_speech_handle_t *sh, 
-														char *module_name, 
-														char *voice_name,
-														unsigned int rate,
-														switch_speech_flag_t *flags,
-														switch_memory_pool_t *pool)
-{
-	switch_status_t status;
-
-	if ((sh->speech_interface = switch_loadable_module_get_speech_interface(module_name)) == 0) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "invalid speech module [%s]!\n", module_name);
-		return SWITCH_STATUS_GENERR;
-	}
-
-	switch_copy_string(sh->engine, module_name, sizeof(sh->engine));
-	sh->flags = *flags;
-	if (pool) {
-		sh->memory_pool = pool;
-	} else {
-		if ((status = switch_core_new_memory_pool(&sh->memory_pool)) != SWITCH_STATUS_SUCCESS) {
-			return status;
-		}
-		switch_set_flag(sh, SWITCH_SPEECH_FLAG_FREE_POOL);
-	}
-	sh->rate = rate;
-	sh->name = switch_core_strdup(pool, module_name);
-	return sh->speech_interface->speech_open(sh, voice_name, rate, flags);
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_asr_open(switch_asr_handle_t *ah,
-													 char *module_name,
-													 char *codec,
-													 int rate,
-													 char *dest,
-													 switch_asr_flag_t *flags,
-													 switch_memory_pool_t *pool)
-{
-	switch_status_t status;
-
-	assert(ah != NULL);
-
-	if ((ah->asr_interface = switch_loadable_module_get_asr_interface(module_name)) == 0) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "invalid asr module [%s]!\n", module_name);
-		return SWITCH_STATUS_GENERR;
-	}
-	
-	ah->flags = *flags;
-
-	if (pool) {
-		ah->memory_pool = pool;
-	} else {
-		if ((status = switch_core_new_memory_pool(&ah->memory_pool)) != SWITCH_STATUS_SUCCESS) {
-			return status;
-		}
-		switch_set_flag(ah, SWITCH_ASR_FLAG_FREE_POOL);
-	}
-
-	ah->rate = rate;
-	ah->name = switch_core_strdup(ah->memory_pool, module_name);
-
-	return ah->asr_interface->asr_open(ah, codec, rate, dest, flags);
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_asr_load_grammar(switch_asr_handle_t *ah, char *grammar, char *path)
-{
-	char *epath = NULL;
-	switch_status_t status;
-
-	assert(ah != NULL);
-
-	if (*path != '/') {
-		epath = switch_mprintf("%s%s%s", SWITCH_GLOBAL_dirs.grammar_dir, SWITCH_PATH_SEPARATOR, path);
-		path = epath;
-	}
-
-	status = ah->asr_interface->asr_load_grammar(ah, grammar, path);
-	switch_safe_free(epath);
-
-	return status;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_asr_unload_grammar(switch_asr_handle_t *ah, char *grammar)
-{
-	switch_status_t status;
-
-	assert(ah != NULL);
-	status = ah->asr_interface->asr_unload_grammar(ah, grammar);
-
-	return status;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_asr_pause(switch_asr_handle_t *ah)
-{
-	assert(ah != NULL);
-
-	return ah->asr_interface->asr_pause(ah);
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_asr_resume(switch_asr_handle_t *ah)
-{
-	assert(ah != NULL);
-
-	return ah->asr_interface->asr_resume(ah);
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_asr_close(switch_asr_handle_t *ah, switch_asr_flag_t *flags)
-{
-	assert(ah != NULL);
-
-	return ah->asr_interface->asr_close(ah, flags);
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_asr_feed(switch_asr_handle_t *ah, void *data, unsigned int len, switch_asr_flag_t *flags)
-{
-	assert(ah != NULL);
-	
-	return ah->asr_interface->asr_feed(ah, data, len, flags);
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_asr_check_results(switch_asr_handle_t *ah, switch_asr_flag_t *flags)
-{
-	assert(ah != NULL);
-	
-	return ah->asr_interface->asr_check_results(ah, flags);
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_asr_get_results(switch_asr_handle_t *ah, char **xmlstr, switch_asr_flag_t *flags)
-{
-	assert(ah != NULL);
-	
-	return ah->asr_interface->asr_get_results(ah, xmlstr, flags);
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_speech_feed_tts(switch_speech_handle_t *sh, char *text, switch_speech_flag_t *flags)
-{
-	assert(sh != NULL);
-
-	return sh->speech_interface->speech_feed_tts(sh, text, flags);
-}
-
-SWITCH_DECLARE(void) switch_core_speech_flush_tts(switch_speech_handle_t *sh)
-{
-	assert(sh != NULL);
-
-	if (sh->speech_interface->speech_flush_tts) {
-		sh->speech_interface->speech_flush_tts(sh);
-	}
-}
-
-SWITCH_DECLARE(void) switch_core_speech_text_param_tts(switch_speech_handle_t *sh, char *param, char *val)
-{
-	assert(sh != NULL);
-
-	if (sh->speech_interface->speech_text_param_tts) {
-		sh->speech_interface->speech_text_param_tts(sh, param, val);
-	}
-}
-
-SWITCH_DECLARE(void) switch_core_speech_numeric_param_tts(switch_speech_handle_t *sh, char *param, int val)
-{
-	assert(sh != NULL);
-
-	if (sh->speech_interface->speech_numeric_param_tts) {
-		sh->speech_interface->speech_numeric_param_tts(sh, param, val);
-	}
-}
-
-SWITCH_DECLARE(void) switch_core_speech_float_param_tts(switch_speech_handle_t *sh, char *param, double val)
-{
-	assert(sh != NULL);
-
-	if (sh->speech_interface->speech_float_param_tts) {
-		sh->speech_interface->speech_float_param_tts(sh, param, val);
-	}
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_speech_read_tts(switch_speech_handle_t *sh, 
-														  void *data,
-														  switch_size_t *datalen,
-														  uint32_t *rate,
-														  switch_speech_flag_t *flags)
-{
-	assert(sh != NULL);
-
-	return sh->speech_interface->speech_read_tts(sh, data, datalen, rate, flags);
-}
-
-
-SWITCH_DECLARE(switch_status_t) switch_core_speech_close(switch_speech_handle_t *sh, switch_speech_flag_t *flags)
-{
-	return sh->speech_interface->speech_close(sh, flags);
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_timer_init(switch_timer_t *timer, char *timer_name, int interval, int samples,
-													 switch_memory_pool_t *pool)
-{
-	switch_timer_interface_t *timer_interface;
-	switch_status_t status;
-	memset(timer, 0, sizeof(*timer));
-	if ((timer_interface = switch_loadable_module_get_timer_interface(timer_name)) == 0) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "invalid timer %s!\n", timer_name);
-		return SWITCH_STATUS_GENERR;
-	}
-
-	timer->interval = interval;
-	timer->samples = samples;
-	timer->samplecount = 0;
-	timer->timer_interface = timer_interface;
-
-	if (pool) {
-		timer->memory_pool = pool;
-	} else {
-		if ((status = switch_core_new_memory_pool(&timer->memory_pool)) != SWITCH_STATUS_SUCCESS) {
-			return status;
-		}
-		switch_set_flag(timer, SWITCH_TIMER_FLAG_FREE_POOL);
-	}
-
-	timer->timer_interface->timer_init(timer);
-	return SWITCH_STATUS_SUCCESS;
-
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_timer_next(switch_timer_t *timer)
-{
-	if (!timer->timer_interface) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer is not initilized!\n");
-		return SWITCH_STATUS_GENERR;
-	}
-
-	if (timer->timer_interface->timer_next(timer) == SWITCH_STATUS_SUCCESS) {
-		return SWITCH_STATUS_SUCCESS;
-	} else {
-		return SWITCH_STATUS_GENERR;
-	}
-
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_timer_step(switch_timer_t *timer)
-{
-	if (!timer->timer_interface) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer is not initilized!\n");
-		return SWITCH_STATUS_GENERR;
-	}
-
-	return timer->timer_interface->timer_step(timer);
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_timer_check(switch_timer_t *timer)
-{
-	if (!timer->timer_interface) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer is not initilized!\n");
-		return SWITCH_STATUS_GENERR;
-	}
-
-	return timer->timer_interface->timer_check(timer);
-}
-
-
-SWITCH_DECLARE(switch_status_t) switch_core_timer_destroy(switch_timer_t *timer)
-{
-	if (!timer->timer_interface) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer is not initilized!\n");
-		return SWITCH_STATUS_GENERR;
-	}
-
-	timer->timer_interface->timer_destroy(timer);
-
-	if (switch_test_flag(timer, SWITCH_TIMER_FLAG_FREE_POOL)) {
-		switch_core_destroy_memory_pool(&timer->memory_pool);
-	}
-
-	return SWITCH_STATUS_SUCCESS;
-}
-
-static void *switch_core_service_thread(switch_thread_t *thread, void *obj)
-{
-	switch_core_thread_session_t *data = obj;
-	switch_core_session_t *session = data->objs[0];
-	int *stream_id_p = data->objs[1];
-	switch_channel_t *channel;
-	switch_frame_t *read_frame;
-	int stream_id = *stream_id_p;
-
-	assert(thread != NULL);
-	assert(session != NULL);
-	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
-
-	switch_channel_set_flag(channel, CF_SERVICE);
-	while (data->running > 0) {
-		switch (switch_core_session_read_frame(session, &read_frame, -1, stream_id)) {
-		case SWITCH_STATUS_SUCCESS:
-		case SWITCH_STATUS_TIMEOUT:
-		case SWITCH_STATUS_BREAK:
-			break;
-		default:
-			data->running = -1;
-			continue;
-		}
-	}
-
-	switch_channel_clear_flag(channel, CF_SERVICE);
-	data->running = 0;
-	return NULL;
-}
-
-/* Either add a timeout here or make damn sure the thread cannot get hung somehow (my preference) */
-SWITCH_DECLARE(void) switch_core_thread_session_end(switch_core_thread_session_t *thread_session)
-{
-	if (thread_session->running > 0) {
-		thread_session->running = -1;
-
-		while (thread_session->running) {
-			switch_yield(1000);
-		}
-	}
-}
-
-SWITCH_DECLARE(void) switch_core_service_session(switch_core_session_t *session,
-												 switch_core_thread_session_t *thread_session, int stream_id)
-{
-	thread_session->running = 1;
-	thread_session->objs[0] = session;
-	thread_session->objs[1] = &stream_id;
-	switch_core_session_launch_thread(session, switch_core_service_thread, thread_session);
-}
-
-SWITCH_DECLARE(switch_memory_pool_t *) switch_core_session_get_pool(switch_core_session_t *session)
-{
-	return session->pool;
-}
-
-/* **ONLY** alloc things with this function that **WILL NOT** outlive
-   the session itself or expect an earth shattering KABOOM!*/
-SWITCH_DECLARE(void *) switch_core_session_alloc(switch_core_session_t *session, switch_size_t memory)
-{
-	void *ptr = NULL;
-	assert(session != NULL);
-	assert(session->pool != NULL);
-
-#ifdef DEBUG_ALLOC
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Allocate %d\n", memory);
-#endif
-
-
-	if ((ptr = apr_palloc(session->pool, memory)) != 0) {
-		memset(ptr, 0, memory);
-	}
-	return ptr;
-}
-
-/* **ONLY** alloc things with these functions that **WILL NOT** need
-   to be freed *EVER* ie this is for *PERMANENT* memory allocation */
-
-SWITCH_DECLARE(void *) switch_core_permanent_alloc(switch_size_t memory)
-{
-	void *ptr = NULL;
-	assert(runtime.memory_pool != NULL);
-
-#ifdef DEBUG_ALLOC
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Perm Allocate %d\n", memory);
-#endif
-
-	if ((ptr = apr_palloc(runtime.memory_pool, memory)) != 0) {
-		memset(ptr, 0, memory);
-	}
-	return ptr;
-}
-
-SWITCH_DECLARE(char *) switch_core_permanent_strdup(const char *todup)
-{
-	char *duped = NULL;
-	switch_size_t len;
-
-	assert(runtime.memory_pool != NULL);
-
-	if (!todup)
-		return NULL;
-
-	len = strlen(todup) + 1;
-
-#ifdef DEBUG_ALLOC
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Perm Allocate %d\n", len);
-#endif
-
-	if (todup && (duped = apr_palloc(runtime.memory_pool, len)) != 0) {
-		strncpy(duped, todup, len);
-	}
-	return duped;
-}
-
-SWITCH_DECLARE(char *) switch_core_session_sprintf(switch_core_session_t *session, const char *fmt, ...)
-{
-	va_list ap;
-	char *result = NULL;
-
-	assert(session != NULL);
-	assert(session->pool != NULL);
-	va_start(ap, fmt);
-	
-	result = apr_pvsprintf(session->pool ,fmt, ap);
-
-	va_end(ap);
-
-	return result;
-}
-
-SWITCH_DECLARE(char *) switch_core_sprintf(switch_memory_pool_t *pool, const char *fmt, ...)
-{
-	va_list ap;
-	char *result = NULL;
-
-	assert(pool != NULL);
-	va_start(ap, fmt);
-	
-	result = apr_pvsprintf(pool ,fmt, ap);
-
-	va_end(ap);
-
-	return result;
-}
-
-
-SWITCH_DECLARE(char *) switch_core_session_strdup(switch_core_session_t *session, const char *todup)
-{
-	char *duped = NULL;
-	switch_size_t len;
-	assert(session != NULL);
-	assert(session->pool != NULL);
-
-	if (!todup) {
-		return NULL;
-	}
-	len = strlen(todup) + 1;
-
-#ifdef DEBUG_ALLOC
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Allocate %d\n", len);
-#endif
-
-	if (todup && (duped = apr_palloc(session->pool, len)) != 0) {
-		strncpy(duped, todup, len);
-	}
-	return duped;
-}
-
-
-SWITCH_DECLARE(char *) switch_core_strdup(switch_memory_pool_t *pool, const char *todup)
-{
-	char *duped = NULL;
-	switch_size_t len;
-	assert(pool != NULL);
-
-	if (!todup) {
-		return NULL;
-	}
-	
-	len = strlen(todup) + 1;
-
-#ifdef DEBUG_ALLOC
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Allocate %d\n", len);
-#endif
-
-	if (todup && (duped = apr_palloc(pool, len)) != 0) {
-		strncpy(duped, todup, len);
-	}
-	return duped;
-}
-
-SWITCH_DECLARE(void *) switch_core_session_get_private(switch_core_session_t *session)
-{
-	assert(session != NULL);
-	return session->private_info;
-}
-
-
-SWITCH_DECLARE(switch_status_t) switch_core_session_set_private(switch_core_session_t *session, void *private_info)
-{
-	assert(session != NULL);
-	session->private_info = private_info;
-	return SWITCH_STATUS_SUCCESS;
-}
-
-SWITCH_DECLARE(int) switch_core_session_add_stream(switch_core_session_t *session, void *private_info)
-{
-	session->streams[session->stream_count++] = private_info;
-	return session->stream_count - 1;
-}
-
-SWITCH_DECLARE(void *) switch_core_session_get_stream(switch_core_session_t *session, int index)
-{
-	return session->streams[index];
-}
-
-
-SWITCH_DECLARE(int) switch_core_session_get_stream_count(switch_core_session_t *session)
-{
-	return session->stream_count;
-}
-
-SWITCH_DECLARE(switch_call_cause_t) switch_core_session_outgoing_channel(switch_core_session_t *session,
-																		 char *endpoint_name,
-																		 switch_caller_profile_t *caller_profile,
-																		 switch_core_session_t **new_session,
-																		 switch_memory_pool_t **pool)
-{
-	switch_io_event_hook_outgoing_channel_t *ptr;
-	switch_status_t status = SWITCH_STATUS_FALSE;
-	const switch_endpoint_interface_t *endpoint_interface;
-	switch_channel_t *channel = NULL;
-	switch_caller_profile_t *outgoing_profile = caller_profile;
-	switch_call_cause_t cause = SWITCH_CAUSE_REQUESTED_CHAN_UNAVAIL;
-
-	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);
-		return SWITCH_CAUSE_CHAN_NOT_IMPLEMENTED;
-	}
-
-	if (endpoint_interface->io_routines->outgoing_channel) {
-		if (session) {
-			channel = switch_core_session_get_channel(session);
-			if (caller_profile) {			
-				char *ecaller_id_name = NULL, *ecaller_id_number = NULL;
-
-				ecaller_id_name = switch_channel_get_variable(channel, "effective_caller_id_name");
-				ecaller_id_number = switch_channel_get_variable(channel, "effective_caller_id_number");
-
-				if (ecaller_id_name || ecaller_id_number) {
-                    if (!ecaller_id_name) {
-                        ecaller_id_name = caller_profile->caller_id_name;
-                    }
-                    if (!ecaller_id_number) {
-                        ecaller_id_number = caller_profile->caller_id_number;
-                    }
-					outgoing_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
-																 caller_profile->username,
-																 caller_profile->dialplan,
-																 ecaller_id_name,
-																 ecaller_id_number,
-																 caller_profile->network_addr,
-																 caller_profile->ani,
-																 caller_profile->aniii, 
-																 caller_profile->rdnis,
-																 caller_profile->source,
-																 caller_profile->context,
-																 caller_profile->destination_number);
-					outgoing_profile->flags = caller_profile->flags;
-				} 
-			}
-			if (!outgoing_profile) {
-				outgoing_profile = switch_channel_get_caller_profile(channel);
-			}
-		}
-		
-		if ((cause = endpoint_interface->io_routines->outgoing_channel(session,
-																	   outgoing_profile,
-																	   new_session,
-																	   pool)) == SWITCH_CAUSE_SUCCESS) {
-			if (session) {
-				for (ptr = session->event_hooks.outgoing_channel; ptr; ptr = ptr->next) {
-					if ((status = ptr->outgoing_channel(session, caller_profile, *new_session)) != SWITCH_STATUS_SUCCESS) {
-						break;
-					}
-				}
-			}
-		} else {
-			return cause;
-		}
-	} else {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not locate outgoing channel interface for %s\n", endpoint_name);
-		return SWITCH_CAUSE_CHAN_NOT_IMPLEMENTED;
-	}
-
-	if (*new_session) {
-		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);
-
-		
-		if (session && channel) {
-			profile = switch_channel_get_caller_profile(channel);
-		}
-		if (peer_channel) {
-			peer_profile = switch_channel_get_caller_profile(peer_channel);
-		}
-
-		if (channel && peer_channel) {
-			char *export_vars, *val;
-            switch_codec_t *read_codec = switch_core_session_get_read_codec(session);
-
-            if (read_codec) {
-                char tmp[80];
-                switch_codec2str(read_codec, tmp, sizeof(tmp));
-                switch_channel_set_variable(peer_channel, SWITCH_ORIGINATOR_CODEC_VARIABLE, tmp);
-            }
-
-			switch_channel_set_variable(peer_channel, SWITCH_ORIGINATOR_VARIABLE, switch_core_session_get_uuid(session));
-			switch_channel_set_variable(peer_channel, SWITCH_SIGNAL_BOND_VARIABLE, switch_core_session_get_uuid(session));
-			switch_channel_set_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE, switch_core_session_get_uuid(*new_session));
-
-            /* A comma (,) separated list of variable names that should ne propagated from originator to originatee */
-			if ((export_vars = switch_channel_get_variable(channel, SWITCH_EXPORT_VARS_VARIABLE))) {
-				char *cptmp = switch_core_session_strdup(session, export_vars);
-				int argc;
-				char *argv[256];
-
-				if ((argc = switch_separate_string(cptmp, ',', argv, (sizeof(argv) / sizeof(argv[0]))))) {
-					int x;
-
-					for (x = 0; x < argc; x++) {
-						char *val;
-						if ((val = switch_channel_get_variable(channel, argv[x]))) {
-							switch_channel_set_variable(peer_channel, argv[x], val);
-						}
-					}
-				}
-			}
-
-			if ((val = switch_channel_get_variable(channel, SWITCH_R_SDP_VARIABLE))) {
-				switch_channel_set_variable(peer_channel, SWITCH_B_SDP_VARIABLE, val);
-			}
-
-			if ((val = switch_channel_get_variable(channel, SWITCH_MAX_FORWARDS_VARIABLE))) {
-				switch_channel_set_variable(peer_channel, SWITCH_MAX_FORWARDS_VARIABLE, val);
-			}
-			
-			if (switch_channel_test_flag(channel, CF_NOMEDIA)) {
-				switch_channel_set_flag(peer_channel, CF_NOMEDIA);
-			}
-
-			if (profile) {
-				if ((cloned_profile = switch_caller_profile_clone(*new_session, profile)) != 0) {
-					switch_channel_set_originator_caller_profile(peer_channel, cloned_profile);
-				}
-			}
-
-			if (peer_profile) {
-				if (session && (cloned_profile = switch_caller_profile_clone(session, peer_profile)) != 0) {
-					switch_channel_set_originatee_caller_profile(channel, cloned_profile);
-				}
-			}
-		}
-
-		if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_OUTGOING) == SWITCH_STATUS_SUCCESS) {
-			switch_channel_event_set_data(peer_channel, event);
-			switch_event_fire(&event);
-		}
-	}
-
-	return cause;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_session_answer_channel(switch_core_session_t *session)
-{
-	switch_io_event_hook_answer_channel_t *ptr;
-	switch_status_t status = SWITCH_STATUS_SUCCESS;
-
-	assert(session != NULL);
-
-	if (session->endpoint_interface->io_routines->answer_channel) {
-		status = session->endpoint_interface->io_routines->answer_channel(session);
-	}
-
-	if (status == SWITCH_STATUS_SUCCESS) {
-		for (ptr = session->event_hooks.answer_channel; ptr; ptr = ptr->next) {
-			if ((status = ptr->answer_channel(session)) != SWITCH_STATUS_SUCCESS) {
-				break;
-			}
-		}
-	}
-	 
-
-	return status;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_session_receive_message(switch_core_session_t *session, switch_core_session_message_t *message)
-{
-	switch_io_event_hook_receive_message_t *ptr;
-	switch_status_t status = SWITCH_STATUS_SUCCESS;
-
-	assert(session != NULL);
-
-	if (session->endpoint_interface->io_routines->receive_message) {
-		status = session->endpoint_interface->io_routines->receive_message(session, message);
-		
-	}
-
-	if (status == SWITCH_STATUS_SUCCESS) {
-		for (ptr = session->event_hooks.receive_message; ptr; ptr = ptr->next) {
-			if ((status = ptr->receive_message(session, message)) != SWITCH_STATUS_SUCCESS) {
-				break;
-			}
-		}
-	}
-
-	switch_core_session_kill_channel(session, SWITCH_SIG_BREAK);
-	return status;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_session_queue_indication(switch_core_session_t *session, switch_core_session_message_types_t indication)
-{
-	switch_core_session_message_t *msg;
-
-	if ((msg = malloc(sizeof(*msg)))) {
-		memset(msg, 0, sizeof(*msg));
-		msg->message_id = indication;
-		msg->from = __FILE__;
-		switch_core_session_queue_message(session, msg);
-		switch_set_flag(msg, SCSMF_DYNAMIC);
-		return SWITCH_STATUS_SUCCESS;
-	}
-	
-	return SWITCH_STATUS_FALSE;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_session_queue_message(switch_core_session_t *session, switch_core_session_message_t *message)
-{
-	switch_status_t status = SWITCH_STATUS_FALSE;
-
-	assert(session != NULL);
-
-	if (!session->message_queue) {
-		switch_queue_create(&session->message_queue, SWITCH_MESSAGE_QUEUE_LEN, session->pool);
-	}
-
-	if (session->message_queue) {
-		if (switch_queue_trypush(session->message_queue, message) == SWITCH_STATUS_SUCCESS) {
-			status = SWITCH_STATUS_SUCCESS;
-		}
-	}
-
-	return status;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_session_dequeue_message(switch_core_session_t *session, switch_core_session_message_t **message)
-{
-	switch_status_t status = SWITCH_STATUS_FALSE;
-	void *pop;
-
-	assert(session != NULL);
-	
-	if (session->message_queue) {
-		if ((status = (switch_status_t) switch_queue_trypop(session->message_queue, &pop)) == SWITCH_STATUS_SUCCESS) {
-			*message = (switch_core_session_message_t *) pop;
-		}
-	}
-
-	return status;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_session_flush_message(switch_core_session_t *session)
-{
-    switch_core_session_message_t *message;
-
-    if (switch_core_session_dequeue_message(session, &message) == SWITCH_STATUS_SUCCESS) {
-        if (switch_test_flag(message, SCSMF_DYNAMIC)) {
-            switch_safe_free(message);
-        } else {
-            message = NULL;
-        }
-    }
-    
-    return SWITCH_STATUS_SUCCESS;
-}
-
-
-SWITCH_DECLARE(switch_status_t) switch_core_session_receive_event(switch_core_session_t *session, switch_event_t **event)
-	 
-{
-	switch_io_event_hook_receive_event_t *ptr;
-	switch_status_t status = SWITCH_STATUS_FALSE;
-
-	assert(session != NULL);
-
-	/* Acquire a read lock on the session or forget it the channel is dead */
-	if (switch_core_session_read_lock(session) == SWITCH_STATUS_SUCCESS) {
-		if (switch_channel_get_state(session->channel) < CS_HANGUP) {
-			if (session->endpoint_interface->io_routines->receive_event) {
-				status = session->endpoint_interface->io_routines->receive_event(session, *event);
-			} 
-	
-			if (status == SWITCH_STATUS_SUCCESS) {
-				for (ptr = session->event_hooks.receive_event; ptr; ptr = ptr->next) {
-					if ((status = ptr->receive_event(session, *event)) != SWITCH_STATUS_SUCCESS) {
-						break;
-					}
-				}
-			}
-
-			if (status == SWITCH_STATUS_BREAK) {
-				status = SWITCH_STATUS_SUCCESS;
-			}
-
-			if (status == SWITCH_STATUS_SUCCESS) {
-				switch_event_destroy(event);
-			}
-		}
-        switch_core_session_rwunlock(session);
-	}
-
-	switch_core_session_kill_channel(session, SWITCH_SIG_BREAK);
-
-	return status;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_session_queue_event(switch_core_session_t *session, switch_event_t **event)
-{
-	switch_status_t status = SWITCH_STATUS_FALSE;
-
-	assert(session != NULL);
-
-	if (!session->event_queue) {
-		switch_queue_create(&session->event_queue, SWITCH_EVENT_QUEUE_LEN, session->pool);
-	}
-
-	if (session->event_queue) {
-		if (switch_queue_trypush(session->event_queue, *event) == SWITCH_STATUS_SUCCESS) {
-			*event = NULL;
-			status = SWITCH_STATUS_SUCCESS;
-		}
-	} 
-
-	return status;
-}
-
-SWITCH_DECLARE(int32_t) switch_core_session_event_count(switch_core_session_t *session)
-{
-	if (session->event_queue) {
-		return (int32_t) switch_queue_size(session->event_queue);
-	}
-
-	return -1;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_session_dequeue_event(switch_core_session_t *session, switch_event_t **event)
-	 
-{
-	switch_status_t status = SWITCH_STATUS_FALSE;
-	void *pop;
-
-	assert(session != NULL);
-	
-	if (session->event_queue) {
-		if ((status = (switch_status_t) switch_queue_trypop(session->event_queue, &pop)) == SWITCH_STATUS_SUCCESS) {
-			*event = (switch_event_t *) pop;
-		}
-	}
-
-	return status;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_session_queue_private_event(switch_core_session_t *session, switch_event_t **event)
-{
-	switch_status_t status = SWITCH_STATUS_FALSE;
-
-	assert(session != NULL);
-	
-	if (!session->private_event_queue) {
-		switch_queue_create(&session->private_event_queue, SWITCH_EVENT_QUEUE_LEN, session->pool);
-	}
-
-	if (session->private_event_queue) {
-		(*event)->event_id = SWITCH_EVENT_PRIVATE_COMMAND;
-		if (switch_queue_trypush(session->private_event_queue, *event) == SWITCH_STATUS_SUCCESS) {
-			*event = NULL;
-			switch_core_session_kill_channel(session, SWITCH_SIG_BREAK);
-			status = SWITCH_STATUS_SUCCESS;
-		}
-	} 
-
-	return status;
-}
-
-SWITCH_DECLARE(int32_t) switch_core_session_private_event_count(switch_core_session_t *session)
-{
-	if (session->private_event_queue) {
-		return (int32_t) switch_queue_size(session->private_event_queue);
-	}
-
-	return -1;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_session_dequeue_private_event(switch_core_session_t *session, switch_event_t **event)
-	 
-{
-	switch_status_t status = SWITCH_STATUS_FALSE;
-	void *pop;
-	switch_channel_t *channel;
-
-	assert(session != NULL);
-
-	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
-	
-	if (switch_channel_test_flag(channel, CF_EVENT_PARSE)) {
-		return status;
-	}
-
-	
-	if (session->private_event_queue) {
-		if ((status = (switch_status_t) switch_queue_trypop(session->private_event_queue, &pop)) == SWITCH_STATUS_SUCCESS) {
-			*event = (switch_event_t *) pop;
-		}
-	}
-
-	return status;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_session_t *session, switch_frame_t **frame,
-															 int timeout, int stream_id)
-{
-	switch_io_event_hook_read_frame_t *ptr;
-	switch_status_t status;
-	int need_codec, perfect, do_bugs = 0;
-	unsigned int flag = 0;
- top:
-	
-	status = SWITCH_STATUS_FALSE;
-	need_codec = perfect = 0;
-	
-	assert(session != NULL);
-	*frame = NULL;
-
-	if (switch_channel_test_flag(session->channel, CF_HOLD)) {
-		status = SWITCH_STATUS_BREAK;
-		goto done;
-	}
-
-	if (session->endpoint_interface->io_routines->read_frame) {
-		if ((status = session->endpoint_interface->io_routines->read_frame(session,
-																		   frame,
-																		   timeout,
-																		   SWITCH_IO_FLAG_NOOP,
-																		   stream_id)) == SWITCH_STATUS_SUCCESS) {
-			for (ptr = session->event_hooks.read_frame; ptr; ptr = ptr->next) {
-				if ((status =
-					 ptr->read_frame(session, frame, timeout, SWITCH_IO_FLAG_NOOP,
-									 stream_id)) != SWITCH_STATUS_SUCCESS) {
-					break;
-				}
-			}
-		}
-	}
-
-	if (status != SWITCH_STATUS_SUCCESS) {
-		goto done;
-	}
-
-	if (!(*frame)) {
-		goto done;
-	}
-
-	assert(session != NULL);
-	assert(*frame != NULL);
-	
-	if (switch_test_flag(*frame, SFF_CNG)) {
-		status = SWITCH_STATUS_SUCCESS;
-		goto done;
-	}
-
-	if ((session->read_codec && (*frame)->codec && session->read_codec->implementation != (*frame)->codec->implementation)) {
-		need_codec = TRUE;
-	}
-
-	if (session->read_codec && !(*frame)->codec) {
-		need_codec = TRUE;
-	}
-
-	if (!session->read_codec && (*frame)->codec) {
-		status = SWITCH_STATUS_FALSE;
-        goto done;
-	}
-
-	if (session->bugs && !need_codec) {
-		do_bugs = 1;
-		need_codec = 1;
-	}
-
-	if (status == SWITCH_STATUS_SUCCESS && need_codec) {
-		switch_frame_t *enc_frame, *read_frame = *frame;
-
-		if (read_frame->codec) {
-			session->raw_read_frame.datalen = session->raw_read_frame.buflen;
-			status = switch_core_codec_decode(read_frame->codec,
-											  session->read_codec,
-											  read_frame->data,
-											  read_frame->datalen,
-											  session->read_codec->implementation->samples_per_second,
-											  session->raw_read_frame.data,
-											  &session->raw_read_frame.datalen,
-											  &session->raw_read_frame.rate,
-											  &flag);
-
-			switch (status) {
-			case SWITCH_STATUS_RESAMPLE:
-				if (!session->read_resampler) {
-					if (switch_resample_create(&session->read_resampler,
-										   read_frame->codec->implementation->samples_per_second,
-										   read_frame->codec->implementation->bytes_per_frame * 20,
-										   session->read_codec->implementation->samples_per_second,
-										   session->read_codec->implementation->bytes_per_frame * 20, session->pool) != SWITCH_STATUS_SUCCESS) {
-						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to allocate resampler\n");
-						status = SWITCH_STATUS_FALSE;
-						goto done;
-					}
-				}
-			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;
-				read_frame = &session->raw_read_frame;
-				break;
-			case SWITCH_STATUS_NOOP:
-				status = SWITCH_STATUS_SUCCESS;
-				break;
-			default:
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec %s decoder error!\n",
-								  session->read_codec->codec_interface->interface_name);
-				goto done;
-			}
-		}
-		if (session->read_resampler) {
-			short *data = read_frame->data;
-
-			session->read_resampler->from_len =
-				switch_short_to_float(data, session->read_resampler->from, (int) read_frame->datalen / 2);
-			session->read_resampler->to_len =
-				switch_resample_process(session->read_resampler, session->read_resampler->from,
-										session->read_resampler->from_len, session->read_resampler->to,
-										session->read_resampler->to_size, 0);
-			switch_float_to_short(session->read_resampler->to, data, read_frame->datalen);
-			read_frame->samples = session->read_resampler->to_len;
-			read_frame->datalen = session->read_resampler->to_len * 2;
-			read_frame->rate = session->read_resampler->to_rate;
-		}
-
-		if (session->bugs) {
-			switch_media_bug_t *bp, *dp, *last = NULL;
-			
-			switch_thread_rwlock_rdlock(session->bug_rwlock);
-			for (bp = session->bugs; bp; bp = bp->next) {
-				if (bp->ready && switch_test_flag(bp, SMBF_READ_STREAM)) {
-					switch_mutex_lock(bp->read_mutex);
-					switch_buffer_write(bp->raw_read_buffer, read_frame->data, read_frame->datalen);
-					if (bp->callback) {
-						if (bp->callback(bp, bp->user_data, SWITCH_ABC_TYPE_READ) == SWITCH_FALSE) {
-							bp->ready = 0;
-							if (last) {
-								last->next = bp->next;
-							} else {
-								session->bugs = bp->next;
-							}
-							switch_mutex_unlock(bp->read_mutex);
-							dp = bp;
-							bp = last;
-							switch_core_media_bug_close(&dp);
-							if (!bp) {
-								break;
-							}
-							continue;
-						}
-					}
-					switch_mutex_unlock(bp->read_mutex);
-				}
-				last = bp;
-			}
-			switch_thread_rwlock_unlock(session->bug_rwlock);
-		}
-
-		if (do_bugs) {
-			goto done;
-		}
-
-		if (session->read_codec) {
-			if ((*frame)->datalen == session->read_codec->implementation->bytes_per_frame) {
-				perfect = TRUE;
-			} else {
-				if (!session->raw_read_buffer) {
-					switch_size_t bytes = session->read_codec->implementation->bytes_per_frame;
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Engaging Read Buffer at %u bytes\n", (uint32_t)bytes);
-					switch_buffer_create_dynamic(&session->raw_read_buffer, bytes * SWITCH_BUFFER_BLOCK_FRAMES, bytes * SWITCH_BUFFER_START_FRAMES, 0);
-				}
-				if (!switch_buffer_write(session->raw_read_buffer, read_frame->data, read_frame->datalen)) {
-					status = SWITCH_STATUS_MEMERR;
-					goto done;
-				}
-			}
-
-			if (perfect || switch_buffer_inuse(session->raw_read_buffer) >= session->read_codec->implementation->bytes_per_frame) {
-				if (perfect) {
-					enc_frame = *frame;
-					session->raw_read_frame.rate = (*frame)->rate;
-				} else {
-					session->raw_read_frame.datalen = (uint32_t)switch_buffer_read(session->raw_read_buffer,
-																				   session->raw_read_frame.data,
-																				   session->read_codec->implementation->bytes_per_frame);
-					
-					session->raw_read_frame.rate = session->read_codec->implementation->samples_per_second;
-					enc_frame = &session->raw_read_frame;
-				}
-				session->enc_read_frame.datalen = session->enc_read_frame.buflen;
-				assert(session->read_codec != NULL);				
-				assert(enc_frame != NULL);
-				assert(enc_frame->data != NULL);
-				
-				status = switch_core_codec_encode(session->read_codec,
-												  enc_frame->codec,
-												  enc_frame->data,
-												  enc_frame->datalen,
-												  session->read_codec->implementation->samples_per_second,
-												  session->enc_read_frame.data,
-												  &session->enc_read_frame.datalen,
-												  &session->enc_read_frame.rate, 
-												  &flag);
-				
-
-				switch (status) {
-				case SWITCH_STATUS_RESAMPLE:
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "fixme 1\n");
-				case SWITCH_STATUS_SUCCESS:
-					session->enc_read_frame.codec = session->read_codec;
-					session->enc_read_frame.samples = session->read_codec->implementation->bytes_per_frame / sizeof(int16_t);
-					session->enc_read_frame.timestamp = read_frame->timestamp;
-					session->enc_read_frame.payload = session->read_codec->implementation->ianacode;
-					*frame = &session->enc_read_frame;
-					break;
-				case SWITCH_STATUS_NOOP:
-					session->raw_read_frame.codec = session->read_codec;
-					session->raw_read_frame.samples = enc_frame->codec->implementation->samples_per_frame;
-					session->raw_read_frame.timestamp = read_frame->timestamp;
-					session->raw_read_frame.payload = enc_frame->codec->implementation->ianacode;
-					*frame = &session->raw_read_frame;
-					status = SWITCH_STATUS_SUCCESS;
-					break;
-				default:
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec %s encoder error!\n",
-										  session->read_codec->codec_interface->interface_name);
-					*frame = NULL;
-					status = SWITCH_STATUS_GENERR;
-					break;
-				}
-			} else {
-				goto top;
-			}
-		}
-	}
-
- done:
-	if (!(*frame)) {
-		status = SWITCH_STATUS_FALSE;
-	} else {
-		if (flag & SFF_CNG) {
-			switch_set_flag((*frame), SFF_CNG);
-		}
-	}
-
-	return status;
-}
-
-static switch_status_t perform_write(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flags, int stream_id)
-{
-	switch_io_event_hook_write_frame_t *ptr;
-	switch_status_t status = SWITCH_STATUS_FALSE;
-
-	if (session->endpoint_interface->io_routines->write_frame) {
-
-		if ((status =
-			 session->endpoint_interface->io_routines->write_frame(session, frame, timeout, flags,
-																   stream_id)) == SWITCH_STATUS_SUCCESS) {
-			for (ptr = session->event_hooks.write_frame; ptr; ptr = ptr->next) {
-				if ((status = ptr->write_frame(session, frame, timeout, flags, stream_id)) != SWITCH_STATUS_SUCCESS) {
-					break;
-				}
-			}
-		}
-	}
-	return status;
-}
-
-SWITCH_DECLARE(void) switch_core_session_reset(switch_core_session_t *session)
-{
-	switch_channel_t *channel;
-	char buf[256];
-	switch_size_t has;
-
-	/* sweep theese under the rug, they wont be leaked they will be reclaimed
-	   when the session ends.
-	*/
-	session->read_resampler = NULL;
-	session->write_resampler = NULL;
-
-    /* clear indications */
-    switch_core_session_flush_message(session);
-
-	/* wipe theese, they will be recreated if need be */
-	switch_buffer_destroy(&session->raw_read_buffer);
-	switch_buffer_destroy(&session->raw_write_buffer);
-
-	/* flush dtmf */
-	channel = switch_core_session_get_channel(session);
-
-	while ((has = switch_channel_has_dtmf(channel))) {
-        switch_channel_dequeue_dtmf(channel, buf, sizeof(buf));
-    }
-
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_session_t *session, switch_frame_t *frame,
-															  int timeout, int stream_id)
-{
-
-	switch_status_t status = SWITCH_STATUS_FALSE;
-	switch_frame_t *enc_frame = NULL, *write_frame = frame;
-	unsigned int flag = 0, need_codec = 0, perfect = 0, do_bugs = 0, do_write = 0;
-	switch_io_flag_t io_flag = SWITCH_IO_FLAG_NOOP;
-
-	assert(session != NULL);
-	assert(frame != NULL);
-
-
-	if (switch_channel_test_flag(session->channel, CF_HOLD)) {
-		return SWITCH_STATUS_SUCCESS;
-	}
-
-	if (switch_test_flag(frame, SFF_CNG)) {
-
-		if (switch_channel_test_flag(session->channel, CF_ACCEPT_CNG)) { 
-			return perform_write(session, frame, timeout, flag, stream_id);
-		}
-
-		return SWITCH_STATUS_SUCCESS;
-	}
-
-	assert(frame->codec != NULL);
-
-	if ((session->write_codec && frame->codec && session->write_codec->implementation != frame->codec->implementation)) {
-		need_codec = TRUE;
-	}
-
-	if (session->write_codec && !frame->codec) {
-		need_codec = TRUE;
-	}
-
-	if (!session->write_codec && frame->codec) {
-		return SWITCH_STATUS_FALSE;
-	}
-
-	if (session->bugs && !need_codec) {
-		do_bugs = 1;
-		need_codec = 1;
-	}
-
-	if (need_codec) {
-		if (frame->codec) {
-			session->raw_write_frame.datalen = session->raw_write_frame.buflen;
-			status = switch_core_codec_decode(frame->codec,
-											  session->write_codec,
-											  frame->data,
-											  frame->datalen,
-											  session->write_codec->implementation->samples_per_second,
-											  session->raw_write_frame.data,
-											  &session->raw_write_frame.datalen, &session->raw_write_frame.rate, &flag);
-			
-			
-			switch (status) {
-			case SWITCH_STATUS_RESAMPLE:
-				write_frame = &session->raw_write_frame;
-				if (!session->write_resampler) {
-					status = switch_resample_create(&session->write_resampler,
-													frame->codec->implementation->samples_per_second,
-													frame->codec->implementation->bytes_per_frame * 20,
-													session->write_codec->implementation->samples_per_second,
-													session->write_codec->implementation->bytes_per_frame * 20,
-													session->pool);
-					if (status != SWITCH_STATUS_SUCCESS) {
-						goto done;
-					}
-				}
-				break;
-			case SWITCH_STATUS_SUCCESS:
-				session->raw_write_frame.samples = session->raw_write_frame.datalen / sizeof(int16_t);
-				session->raw_write_frame.timestamp = frame->timestamp;
-				session->raw_write_frame.rate = frame->rate;
-				write_frame = &session->raw_write_frame;
-				break;
-			case SWITCH_STATUS_BREAK:
-				return SWITCH_STATUS_SUCCESS;
-			case SWITCH_STATUS_NOOP:
-				write_frame = frame;
-				status = SWITCH_STATUS_SUCCESS;
-				break;
-			default:
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec %s decoder error!\n",
-									  frame->codec->codec_interface->interface_name);
-				return status;
-			}
-		}
-		if (session->write_resampler) {
-			short *data = write_frame->data;
-
-			session->write_resampler->from_len = write_frame->datalen / 2;
-			switch_short_to_float(data, session->write_resampler->from, session->write_resampler->from_len);
-
-
-
-			session->write_resampler->to_len = (uint32_t)
-				switch_resample_process(session->write_resampler, session->write_resampler->from,
-										session->write_resampler->from_len, session->write_resampler->to,
-										session->write_resampler->to_size, 0);
-			
-
-			switch_float_to_short(session->write_resampler->to, data, session->write_resampler->to_len);
-
-			write_frame->samples = session->write_resampler->to_len;
-			write_frame->datalen = write_frame->samples * 2;
-			write_frame->rate = session->write_resampler->to_rate;
-		}
-
-		if (session->bugs) {
-			switch_media_bug_t *bp, *dp, *last = NULL;
-
-			switch_thread_rwlock_rdlock(session->bug_rwlock);
-			for (bp = session->bugs; bp; bp = bp->next) {
-				switch_bool_t ok = SWITCH_TRUE;
-                if (!bp->ready) {
-                    continue;
-                }
-				if (switch_test_flag(bp, SMBF_WRITE_STREAM)) {
-					switch_mutex_lock(bp->write_mutex);
-					switch_buffer_write(bp->raw_write_buffer, write_frame->data, write_frame->datalen);
-					switch_mutex_unlock(bp->write_mutex);
-					if (bp->callback) {
-						ok = bp->callback(bp, bp->user_data, SWITCH_ABC_TYPE_WRITE);
-					}
-				} else if (switch_test_flag(bp, SMBF_WRITE_REPLACE)) {
-                    do_bugs = 0;
-					if (bp->callback) {
-                        bp->replace_frame_in = frame;
-                        bp->replace_frame_out = NULL;
-						if ((ok = bp->callback(bp, bp->user_data, SWITCH_ABC_TYPE_WRITE_REPLACE)) == SWITCH_TRUE) {
-							write_frame = bp->replace_frame_out;
-						}
-					}
-				}
-
-				if (ok == SWITCH_FALSE) {
-					bp->ready = 0;
-					if (last) {
-						last->next = bp->next;
-					} else {
-						session->bugs = bp->next;
-					}
-					dp = bp;
-					bp = last;
-					switch_core_media_bug_close(&dp);
-					if (!bp) {
-						break;
-					}
-					continue;
-				}
-				last = bp;
-			}
-			switch_thread_rwlock_unlock(session->bug_rwlock);
-		}
-
-		if (do_bugs) {
-            do_write = 1;
-            write_frame = frame;
-            goto done;
-		}
-
-		if (session->write_codec) {
-			if (write_frame->datalen == session->write_codec->implementation->bytes_per_frame) {
-				perfect = TRUE;
-			} else {
-				if (!session->raw_write_buffer) {
-					switch_size_t bytes = session->write_codec->implementation->bytes_per_frame;
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
-									  "Engaging Write Buffer at %u bytes to accomodate %u->%u\n",
-									  (uint32_t)bytes,
-									  write_frame->datalen, session->write_codec->implementation->bytes_per_frame);
-					if ((status =switch_buffer_create_dynamic(&session->raw_write_buffer,
-															  bytes * SWITCH_BUFFER_BLOCK_FRAMES,
-															  bytes * SWITCH_BUFFER_START_FRAMES,
-															  0)) != SWITCH_STATUS_SUCCESS) {
-						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Write Buffer Failed!\n");
-						return status;
-					}
-				}
-
-				if (!(switch_buffer_write(session->raw_write_buffer, write_frame->data, write_frame->datalen))) {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Write Buffer %u bytes Failed!\n", write_frame->datalen);
-					return SWITCH_STATUS_MEMERR;
-				}
-			}
-
-			
-			if (perfect) {
-				enc_frame = write_frame;
-				session->enc_write_frame.datalen = session->enc_write_frame.buflen;
-
-				status = switch_core_codec_encode(session->write_codec,
-												  frame->codec,
-												  enc_frame->data,
-												  enc_frame->datalen,
-												  session->write_codec->implementation->samples_per_second,
-												  session->enc_write_frame.data,
-												  &session->enc_write_frame.datalen,
-												  &session->enc_write_frame.rate, &flag);
-				
-				switch (status) {
-				case SWITCH_STATUS_RESAMPLE:
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "fixme 2\n");
-				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;
-					session->enc_write_frame.payload = session->write_codec->implementation->ianacode;
-					write_frame = &session->enc_write_frame;
-					break;
-				case SWITCH_STATUS_NOOP:
-					enc_frame->codec = session->write_codec;
-					enc_frame->samples = enc_frame->datalen / sizeof(int16_t);
-					enc_frame->timestamp = frame->timestamp;
-					enc_frame->payload = enc_frame->codec->implementation->ianacode;
-					write_frame = enc_frame;
-					status = SWITCH_STATUS_SUCCESS;
-					break;
-				default:
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec %s encoder error!\n",
-										  session->read_codec->codec_interface->interface_name);
-					write_frame = NULL;
-					return status;
-				}
-				if (flag & SFF_CNG) {
-					switch_set_flag(write_frame, SFF_CNG);
-				}
-				status = perform_write(session, write_frame, timeout, io_flag, stream_id);
-				return status;
-			} else {
-				switch_size_t used = switch_buffer_inuse(session->raw_write_buffer);
-				uint32_t bytes = session->write_codec->implementation->bytes_per_frame;
-				switch_size_t frames = (used / bytes);
-				
-				status = SWITCH_STATUS_SUCCESS;
-				if (!frames) {
-					return status;
-				} else {
-					switch_size_t x;
-					for (x = 0; x < frames; x++) {
-						if ((session->raw_write_frame.datalen = (uint32_t)
-							 switch_buffer_read(session->raw_write_buffer, session->raw_write_frame.data, bytes)) != 0) {
-							enc_frame = &session->raw_write_frame;
-							session->raw_write_frame.rate = session->write_codec->implementation->samples_per_second;
-							session->enc_write_frame.datalen = session->enc_write_frame.buflen;
-
-
-							status = switch_core_codec_encode(session->write_codec,
-															  frame->codec,
-															  enc_frame->data,
-															  enc_frame->datalen,
-															  frame->codec->implementation->samples_per_second,
-															  session->enc_write_frame.data,
-															  &session->enc_write_frame.datalen,
-															  &session->enc_write_frame.rate, &flag);
-
-							
-							switch (status) {
-							case SWITCH_STATUS_RESAMPLE:
-								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;
-								session->enc_write_frame.payload = session->write_codec->implementation->ianacode;
-								write_frame = &session->enc_write_frame;
-								if (!session->read_resampler) {
-									status = switch_resample_create(&session->read_resampler,
-																	frame->codec->implementation->samples_per_second,
-																	frame->codec->implementation->bytes_per_frame * 20,
-																	session->write_codec->implementation->samples_per_second,
-																	session->write_codec->implementation->bytes_per_frame * 20,
-																	session->pool);
-									if (status != SWITCH_STATUS_SUCCESS) {
-										goto done;
-									}
-								}
-								break;
-							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;
-								session->enc_write_frame.payload = session->write_codec->implementation->ianacode;
-								write_frame = &session->enc_write_frame;
-								break;
-							case SWITCH_STATUS_NOOP:
-								enc_frame->codec = session->write_codec;
-								enc_frame->samples = enc_frame->datalen / sizeof(int16_t);
-								enc_frame->timestamp = frame->timestamp;
-								enc_frame->payload = enc_frame->codec->implementation->ianacode;
-								write_frame = enc_frame;
-								status = SWITCH_STATUS_SUCCESS;
-								break;
-							default:
-								switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec %s encoder error %d!\n",
-													  session->read_codec->codec_interface->interface_name, status);
-								write_frame = NULL;
-								return status;
-							}
-
-							if (session->read_resampler) {
-								short *data = write_frame->data;
-
-								session->read_resampler->from_len = switch_short_to_float(data,
-																						  session->read_resampler->from,
-																						  (int) write_frame->datalen /
-																						  2);
-								session->read_resampler->to_len = (uint32_t)
-									switch_resample_process(session->read_resampler, session->read_resampler->from,
-															session->read_resampler->from_len,
-															session->read_resampler->to,
-															session->read_resampler->to_size, 0);
-								switch_float_to_short(session->read_resampler->to, data, write_frame->datalen * 2);
-								write_frame->samples = session->read_resampler->to_len;
-								write_frame->datalen = session->read_resampler->to_len * 2;
-								write_frame->rate = session->read_resampler->to_rate;
-							}
-							if (flag & SFF_CNG) {
-								switch_set_flag(write_frame, SFF_CNG);
-							}
-							if ((status = perform_write(session, write_frame, timeout, io_flag, stream_id)) != SWITCH_STATUS_SUCCESS) {
-								break;
-							}
-						}
-					}
-					return status;
-				}
-			}
-		}
-	} else {
-		do_write = 1;
-	}
-
- done:
-	if (do_write) {
-		return perform_write(session, frame, timeout, io_flag, stream_id);
-	}
-
-	return status;
-}
-
-static char *SIG_NAMES[] = {
-	"NONE",
-	"KILL",
-	"XFER",
-    "BREAK",
-	NULL
-};
-
-SWITCH_DECLARE(switch_status_t) switch_core_session_perform_kill_channel(switch_core_session_t *session, 
-                                                                         const char *file, 
-                                                                         const char *func, 
-                                                                         int line, 
-                                                                         switch_signal_t sig)
-{
-	switch_io_event_hook_kill_channel_t *ptr;
-	switch_status_t status = SWITCH_STATUS_FALSE;
-	
-	switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, SWITCH_LOG_INFO, "Kill %s [%s]\n", switch_channel_get_name(session->channel), SIG_NAMES[sig]);
-	
-	if (session->endpoint_interface->io_routines->kill_channel) {
-		if ((status = session->endpoint_interface->io_routines->kill_channel(session, sig)) == SWITCH_STATUS_SUCCESS) {
-			for (ptr = session->event_hooks.kill_channel; ptr; ptr = ptr->next) {
-				if ((status = ptr->kill_channel(session, sig)) != SWITCH_STATUS_SUCCESS) {
-					break;
-				}
-			}
-		}
-	}
-
-	return status;
-
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_session_waitfor_read(switch_core_session_t *session, int timeout, int stream_id)
-{
-	switch_io_event_hook_waitfor_read_t *ptr;
-	switch_status_t status = SWITCH_STATUS_FALSE;
-
-	if (session->endpoint_interface->io_routines->waitfor_read) {
-		if ((status =
-			 session->endpoint_interface->io_routines->waitfor_read(session, timeout,
-																	stream_id)) == SWITCH_STATUS_SUCCESS) {
-			for (ptr = session->event_hooks.waitfor_read; ptr; ptr = ptr->next) {
-				if ((status = ptr->waitfor_read(session, timeout, stream_id)) != SWITCH_STATUS_SUCCESS) {
-					break;
-				}
-			}
-		}
-	}
-
-	return status;
-
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_session_waitfor_write(switch_core_session_t *session, int timeout,
-																int stream_id)
-{
-	switch_io_event_hook_waitfor_write_t *ptr;
-	switch_status_t status = SWITCH_STATUS_FALSE;
-
-	if (session->endpoint_interface->io_routines->waitfor_write) {
-		if ((status =
-			 session->endpoint_interface->io_routines->waitfor_write(session, timeout,
-																	 stream_id)) == SWITCH_STATUS_SUCCESS) {
-			for (ptr = session->event_hooks.waitfor_write; ptr; ptr = ptr->next) {
-				if ((status = ptr->waitfor_write(session, timeout, stream_id)) != SWITCH_STATUS_SUCCESS) {
-					break;
-				}
-			}
-		}
-	}
-
-	return status;
-}
-
-
-SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf(switch_core_session_t *session, char *dtmf)
-{
-	switch_io_event_hook_send_dtmf_t *ptr;
-	switch_status_t status = SWITCH_STATUS_FALSE;
-
-	if (session->endpoint_interface->io_routines->send_dtmf) {
-        if (strchr(dtmf, 'w') || strchr(dtmf, 'W')) {
-            char *d;
-            for (d = dtmf; d && *d; d++) {
-				char digit[2] = {0};
-                
-                if (*d == 'w') {
-                    switch_yield(500000);
-                    continue;
-                } else if (*d == 'W') {
-                    switch_yield(1000000);
-                    continue;
-                }
-
-                digit[0] = *d;
-                if ((status = session->endpoint_interface->io_routines->send_dtmf(session, digit)) != SWITCH_STATUS_SUCCESS) {
-                    return status;
-                }
-            }
-        } else {
-            status = session->endpoint_interface->io_routines->send_dtmf(session, dtmf);
-        }
-
-        if (status == SWITCH_STATUS_SUCCESS) {
-            for (ptr = session->event_hooks.send_dtmf; ptr; ptr = ptr->next) {
-                if ((status = ptr->send_dtmf(session, dtmf)) != SWITCH_STATUS_SUCCESS) {
-                    break;
-                }
-            }
-        }
-	}
-
-	return status;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_session_add_event_hook_outgoing(switch_core_session_t *session,
-																		  switch_outgoing_channel_hook_t outgoing_channel)
-{
-	switch_io_event_hook_outgoing_channel_t *hook, *ptr;
-
-	assert(outgoing_channel != NULL);
-	if ((hook = switch_core_session_alloc(session, sizeof(*hook))) != 0) {
-		hook->outgoing_channel = outgoing_channel;
-		if (!session->event_hooks.outgoing_channel) {
-			session->event_hooks.outgoing_channel = hook;
-		} else {
-			for (ptr = session->event_hooks.outgoing_channel; ptr && ptr->next; ptr = ptr->next);
-			ptr->next = hook;
-
-		}
-
-		return SWITCH_STATUS_SUCCESS;
-	}
-
-	return SWITCH_STATUS_MEMERR;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_session_add_event_hook_answer_channel(switch_core_session_t *session,
-																				switch_answer_channel_hook_t
-																				answer_channel)
-{
-	switch_io_event_hook_answer_channel_t *hook, *ptr;
-
-	assert(answer_channel != NULL);
-	if ((hook = switch_core_session_alloc(session, sizeof(*hook))) != 0) {
-		hook->answer_channel = answer_channel;
-		if (!session->event_hooks.answer_channel) {
-			session->event_hooks.answer_channel = hook;
-		} else {
-			for (ptr = session->event_hooks.answer_channel; ptr && ptr->next; ptr = ptr->next);
-			ptr->next = hook;
-
-		}
-
-		return SWITCH_STATUS_SUCCESS;
-	}
-
-	return SWITCH_STATUS_MEMERR;
-
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_session_add_event_hook_state_change(switch_core_session_t *session,
-																				switch_answer_channel_hook_t state_change)
-																				  
-
-{
-	switch_io_event_hook_state_change_t *hook, *ptr;
-
-	assert(state_change != NULL);
-	if ((hook = switch_core_session_alloc(session, sizeof(*hook))) != 0) {
-		hook->state_change = state_change;
-		if (!session->event_hooks.state_change) {
-			session->event_hooks.state_change = hook;
-		} else {
-			for (ptr = session->event_hooks.state_change; ptr && ptr->next; ptr = ptr->next);
-			ptr->next = hook;
-
-		}
-
-		return SWITCH_STATUS_SUCCESS;
-	}
-
-	return SWITCH_STATUS_MEMERR;
-
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_session_add_event_hook_read_frame(switch_core_session_t *session,
-																			switch_read_frame_hook_t read_frame)
-{
-	switch_io_event_hook_read_frame_t *hook, *ptr;
-
-	assert(read_frame != NULL);
-	if ((hook = switch_core_session_alloc(session, sizeof(*hook))) != 0) {
-		hook->read_frame = read_frame;
-		if (!session->event_hooks.read_frame) {
-			session->event_hooks.read_frame = hook;
-		} else {
-			for (ptr = session->event_hooks.read_frame; ptr && ptr->next; ptr = ptr->next);
-			ptr->next = hook;
-
-		}
-
-		return SWITCH_STATUS_SUCCESS;
-	}
-
-	return SWITCH_STATUS_MEMERR;
-
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_session_add_event_hook_write_frame(switch_core_session_t *session,
-																			 switch_write_frame_hook_t write_frame)
-{
-	switch_io_event_hook_write_frame_t *hook, *ptr;
-
-	assert(write_frame != NULL);
-	if ((hook = switch_core_session_alloc(session, sizeof(*hook))) != 0) {
-		hook->write_frame = write_frame;
-		if (!session->event_hooks.write_frame) {
-			session->event_hooks.write_frame = hook;
-		} else {
-			for (ptr = session->event_hooks.write_frame; ptr && ptr->next; ptr = ptr->next);
-			ptr->next = hook;
-
-		}
-
-		return SWITCH_STATUS_SUCCESS;
-	}
-
-	return SWITCH_STATUS_MEMERR;
-
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_session_add_event_hook_kill_channel(switch_core_session_t *session,
-																			  switch_kill_channel_hook_t kill_channel)
-{
-	switch_io_event_hook_kill_channel_t *hook, *ptr;
-
-	assert(kill_channel != NULL);
-	if ((hook = switch_core_session_alloc(session, sizeof(*hook))) != 0) {
-		hook->kill_channel = kill_channel;
-		if (!session->event_hooks.kill_channel) {
-			session->event_hooks.kill_channel = hook;
-		} else {
-			for (ptr = session->event_hooks.kill_channel; ptr && ptr->next; ptr = ptr->next);
-			ptr->next = hook;
-
-		}
-
-		return SWITCH_STATUS_SUCCESS;
-	}
-
-	return SWITCH_STATUS_MEMERR;
-
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_session_add_event_hook_waitfor_read(switch_core_session_t *session,
-																			  switch_waitfor_read_hook_t waitfor_read)
-{
-	switch_io_event_hook_waitfor_read_t *hook, *ptr;
-
-	assert(waitfor_read != NULL);
-	if ((hook = switch_core_session_alloc(session, sizeof(*hook))) != 0) {
-		hook->waitfor_read = waitfor_read;
-		if (!session->event_hooks.waitfor_read) {
-			session->event_hooks.waitfor_read = hook;
-		} else {
-			for (ptr = session->event_hooks.waitfor_read; ptr && ptr->next; ptr = ptr->next);
-			ptr->next = hook;
-
-		}
-
-		return SWITCH_STATUS_SUCCESS;
-	}
-
-	return SWITCH_STATUS_MEMERR;
-
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_session_add_event_hook_waitfor_write(switch_core_session_t *session,
-																			   switch_waitfor_write_hook_t waitfor_write)
-{
-	switch_io_event_hook_waitfor_write_t *hook, *ptr;
-
-	assert(waitfor_write != NULL);
-	if ((hook = switch_core_session_alloc(session, sizeof(*hook))) != 0) {
-		hook->waitfor_write = waitfor_write;
-		if (!session->event_hooks.waitfor_write) {
-			session->event_hooks.waitfor_write = hook;
-		} else {
-			for (ptr = session->event_hooks.waitfor_write; ptr && ptr->next; ptr = ptr->next);
-			ptr->next = hook;
-
-		}
-
-		return SWITCH_STATUS_SUCCESS;
-	}
-
-	return SWITCH_STATUS_MEMERR;
-
-}
-
-
-SWITCH_DECLARE(switch_status_t) switch_core_session_add_event_hook_send_dtmf(switch_core_session_t *session,
-																		   switch_send_dtmf_hook_t send_dtmf)
-{
-	switch_io_event_hook_send_dtmf_t *hook, *ptr;
-
-	assert(send_dtmf != NULL);
-	if ((hook = switch_core_session_alloc(session, sizeof(*hook))) != 0) {
-		hook->send_dtmf = send_dtmf;
-		if (!session->event_hooks.send_dtmf) {
-			session->event_hooks.send_dtmf = hook;
-		} else {
-			for (ptr = session->event_hooks.send_dtmf; ptr && ptr->next; ptr = ptr->next);
-			ptr->next = hook;
-
-		}
-
-		return SWITCH_STATUS_SUCCESS;
-	}
-
-	return SWITCH_STATUS_MEMERR;
-
-}
-
-
-SWITCH_DECLARE(switch_status_t) switch_core_new_memory_pool(switch_memory_pool_t **pool)
-{
-
-	assert(runtime.memory_pool != NULL);
-
-	if ((apr_pool_create(pool, NULL)) != SWITCH_STATUS_SUCCESS) {
-		*pool = NULL;
-		return SWITCH_STATUS_MEMERR;
-	}
-	return SWITCH_STATUS_SUCCESS;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_destroy_memory_pool(switch_memory_pool_t **pool)
-{
-	apr_pool_destroy(*pool);
-	return SWITCH_STATUS_SUCCESS;
-}
-
-SWITCH_DECLARE(switch_channel_t *) switch_core_session_get_channel(switch_core_session_t *session)
-{
-	return session->channel;
-}
-
-static void switch_core_standard_on_init(switch_core_session_t *session)
-{
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Standard INIT %s\n", switch_channel_get_name(session->channel));
-}
-
-static void switch_core_standard_on_hangup(switch_core_session_t *session)
-{
-
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Standard HANGUP %s, cause: %s\n", switch_channel_get_name(session->channel),switch_channel_cause2str(switch_channel_get_cause(session->channel)));
-
-}
-
-static void switch_core_standard_on_ring(switch_core_session_t *session)
-{
-	switch_dialplan_interface_t *dialplan_interface = NULL;
-	switch_caller_profile_t *caller_profile;
-	switch_caller_extension_t *extension = NULL;
-
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Standard RING %s\n", switch_channel_get_name(session->channel));
-
-	if ((caller_profile = switch_channel_get_caller_profile(session->channel)) == 0) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't get profile!\n");
-		switch_channel_hangup(session->channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-        return;
-	} else {
-		char *dp[25];
-        char *dpstr;
-		int argc, x, count = 0;
-
-		if (!switch_strlen_zero(caller_profile->dialplan)) {
-            if ((dpstr = switch_core_session_strdup(session, caller_profile->dialplan))) {
-                argc = switch_separate_string(dpstr, ',', dp, (sizeof(dp) / sizeof(dp[0]))); 
-                for (x = 0; x < argc; x++) {
-                    char *dpname = dp[x];
-                    char *dparg = NULL;
-
-                    if (dpname) {
-                        if ((dparg = strchr(dpname, ':'))) {
-                            *dparg++ = '\0';
-                        }
-                    }
-                    if (!(dialplan_interface = switch_loadable_module_get_dialplan_interface(dpname))) {
-                        continue;
-                    }
-
-                    count++;
-
-                    if ((extension = dialplan_interface->hunt_function(session, dparg)) != 0) {
-                        switch_channel_set_caller_extension(session->channel, extension);
-                        return;
-                    }
-                }
-            }
-        }
-
-		if (!count) {
-			if (switch_channel_test_flag(session->channel, CF_OUTBOUND)) {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "No Dialplan, changing state to HOLD\n");
-				switch_channel_set_state(session->channel, CS_HOLD);
-				return;
-			} 
-		}
-	}
-
-	if (!extension) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "No Route, Aborting\n");
-        switch_channel_hangup(session->channel, SWITCH_CAUSE_NO_ROUTE_DESTINATION);
-    }
-}
-
-static void switch_core_standard_on_execute(switch_core_session_t *session)
-{
-	switch_caller_extension_t *extension;
-	switch_event_t *event;
-	const switch_application_interface_t *application_interface;
-
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Standard EXECUTE\n");
-
-	if ((extension = switch_channel_get_caller_extension(session->channel)) == 0) {
-		switch_channel_hangup(session->channel, SWITCH_CAUSE_NORMAL_CLEARING);
-		return;
-	}
-
-	while (switch_channel_get_state(session->channel) == CS_EXECUTE && extension->current_application) {
-		char *expanded = NULL;
-
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Execute %s(%s)\n",
-							  extension->current_application->application_name,
-							  switch_str_nil(extension->current_application->application_data));
-		if (
-			(application_interface =
-			 switch_loadable_module_get_application_interface(extension->current_application->application_name)) == 0) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Application %s\n",
-								  extension->current_application->application_name);
-			switch_channel_hangup(session->channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-			return;
-		}
-
-		if (!application_interface->application_function) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Function for %s\n",
-								  extension->current_application->application_name);
-			switch_channel_hangup(session->channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-			return;
-		}
-		
-		if ((expanded = switch_channel_expand_variables(session->channel, extension->current_application->application_data)) != 
-			extension->current_application->application_data) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Expanded String %s(%s)\n",
-							  extension->current_application->application_name,
-							  expanded);
-		}
-
-		if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_EXECUTE) == SWITCH_STATUS_SUCCESS) {
-			switch_channel_event_set_data(session->channel, event);
-			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Application", "%s", extension->current_application->application_name);
-			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Application-Data-Orig", "%s", extension->current_application->application_data);
-			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Application-Data", "%s", expanded);
-			switch_event_fire(&event);
-		}
-		
-
-		if (switch_channel_get_variable(session->channel, "presence_id")) {
-			char *arg = switch_mprintf("%s(%s)", extension->current_application->application_name, expanded);
-			if (arg) {
-				switch_channel_presence(session->channel, "unknown", arg);
-				switch_safe_free(arg);
-			}
-		}
-
-		application_interface->application_function(session, expanded);
-
-		if (expanded != extension->current_application->application_data) {
-			switch_safe_free(expanded);
-		}
-		extension->current_application = extension->current_application->next;
-	}
-	
-	if (switch_channel_get_state(session->channel) == CS_EXECUTE) {
-		switch_channel_hangup(session->channel, SWITCH_CAUSE_NORMAL_CLEARING);
-	}
-}
-
-static void switch_core_standard_on_loopback(switch_core_session_t *session)
-{
-	switch_frame_t *frame;
-	int stream_id;
-
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Standard LOOPBACK\n");
-
-	while (switch_channel_get_state(session->channel) == CS_LOOPBACK) {
-		for (stream_id = 0; stream_id < session->stream_count; stream_id++) {
-			if (switch_core_session_read_frame(session, &frame, -1, stream_id) == SWITCH_STATUS_SUCCESS) {
-				switch_core_session_write_frame(session, frame, -1, stream_id);
-			}
-		}
-	}
-}
-
-static void switch_core_standard_on_transmit(switch_core_session_t *session)
-{
-	assert(session != NULL);
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Standard TRANSMIT\n");
-}
-
-static void switch_core_standard_on_hold(switch_core_session_t *session)
-{
-	assert(session != NULL);
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Standard HOLD\n");
-}
-
-static void switch_core_standard_on_hibernate(switch_core_session_t *session)
-{
-	assert(session != NULL);
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Standard HIBERNATE\n");
-}
-
-SWITCH_DECLARE(void) switch_core_session_signal_state_change(switch_core_session_t *session)
-{
-	switch_status_t status = SWITCH_STATUS_SUCCESS;
-	switch_io_event_hook_state_change_t *ptr;
-
-	/* If trylock fails the signal is already awake so we needn't bother */
-	if (switch_mutex_trylock(session->mutex) == SWITCH_STATUS_SUCCESS) {
-		switch_thread_cond_signal(session->cond);
-		switch_mutex_unlock(session->mutex);
-	} 
-
-	if (session->endpoint_interface->io_routines->state_change) {
-		status = session->endpoint_interface->io_routines->state_change(session);
-	}
-
-	if (status == SWITCH_STATUS_SUCCESS) {
-		for (ptr = session->event_hooks.state_change; ptr; ptr = ptr->next) {
-			if ((status = ptr->state_change(session)) != SWITCH_STATUS_SUCCESS) {
-				break;
-			}
-		}
-	}
-}
-
-SWITCH_DECLARE(unsigned int) switch_core_session_running(switch_core_session_t *session)
-{
-	return session->thread_running;
-}
-#ifdef CRASH_PROT
-#if defined (__GNUC__) && defined (LINUX)
-#include <execinfo.h>
-#include <stdio.h>
-#include <stdlib.h>
-#define STACK_LEN 10
-
-/* Obtain a backtrace and print it to stdout. */
-static void print_trace (void)
-{
-	void *array[STACK_LEN];
-	size_t size;
-	char **strings;
-	size_t i;
-
-	size = backtrace (array, STACK_LEN);
-	strings = backtrace_symbols (array, size);
-
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Obtained %zd stack frames.\n", size);
-	
-	for (i = 0; i < size; i++) {
-		switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_CRIT, "%s\n", strings[i]);
-	}
-
-	free (strings);
-}
-#else
-static void print_trace (void)
-{
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Trace not avaliable =(\n");
-}
-#endif
-
-
-static void handle_fatality(int sig)
-{
-	switch_thread_id_t thread_id;
-	jmp_buf *env;
-
-	if (sig && (thread_id = switch_thread_self()) && (env = (jmp_buf *) apr_hash_get(runtime.stack_table, &thread_id, sizeof(thread_id)))) {
-		print_trace();
-		longjmp(*env, sig);
-	} else {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Caught signal %d for unmapped thread!", sig);
-		abort();
-	}
-}
-#endif
-
-SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session)
-{
-	switch_channel_state_t state = CS_NEW, laststate = CS_HANGUP, midstate = CS_DONE, endstate;
-	const switch_endpoint_interface_t *endpoint_interface;
-	const switch_state_handler_table_t *driver_state_handler = NULL;
-	const switch_state_handler_table_t *application_state_handler = NULL;
-
-#ifdef CRASH_PROT
-	switch_thread_id_t thread_id = switch_thread_self();
-	jmp_buf env;
-	int sig;
-
-	signal(SIGSEGV, handle_fatality);
-	signal(SIGFPE, handle_fatality);
-#ifndef WIN32
-	signal(SIGBUS, handle_fatality);
-#endif
-
-	if ((sig = setjmp(env)) != 0) {
-		switch_event_t *event;
-
-		if (switch_event_create(&event, SWITCH_EVENT_SESSION_CRASH) == SWITCH_STATUS_SUCCESS) {
-			switch_channel_event_set_data(session->channel, event);
-			switch_event_fire(&event);
-		}
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Thread has crashed for channel %s\n", switch_channel_get_name(session->channel));
-		switch_channel_hangup(session->channel, SWITCH_CAUSE_CRASH);
-	} else {
-		apr_hash_set(runtime.stack_table, &thread_id, sizeof(thread_id), &env);
-	}
-#endif
-	/*
-	   Life of the channel. you have channel and pool in your session
-	   everywhere you go you use the session to malloc with
-	   switch_core_session_alloc(session, <size>)
-
-	   The enpoint module gets the first crack at implementing the state
-	   if it wants to, it can cancel the default behaviour by returning SWITCH_STATUS_FALSE
-
-	   Next comes the channel's event handler table that can be set by an application
-	   which also can veto the next behaviour in line by returning SWITCH_STATUS_FALSE
-
-	   Finally the default state behaviour is called.
-
-
-	 */
-	assert(session != NULL);
-	
-	session->thread_running = 1;
-	endpoint_interface = session->endpoint_interface;
-	assert(endpoint_interface != NULL);
-
-	driver_state_handler = endpoint_interface->state_handler;
-	assert(driver_state_handler != NULL);
-
-	switch_mutex_lock(session->mutex);
-
-	while ((state = switch_channel_get_state(session->channel)) != CS_DONE) {
-        uint8_t exception = 0;        
-        if (switch_channel_test_flag(session->channel, CF_REPEAT_STATE)) {
-            switch_channel_clear_flag(session->channel, CF_REPEAT_STATE);
-            exception = 1;
-        }
-		if (state != laststate || state == CS_HANGUP || exception) {
-			int index = 0;
-			int proceed = 1;
-			midstate = state;
-
-			switch (state) {
-			case CS_NEW:		/* Just created, Waiting for first instructions */
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) State NEW\n", switch_channel_get_name(session->channel));
-				break;
-			case CS_DONE:
-				goto done;
-			case CS_HANGUP:	/* Deactivate and end the thread */
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) State HANGUP\n", switch_channel_get_name(session->channel));
-				if (!driver_state_handler->on_hangup ||
-					(driver_state_handler->on_hangup &&
-					 driver_state_handler->on_hangup(session) == SWITCH_STATUS_SUCCESS &&
-					 midstate == switch_channel_get_state(session->channel))) {
-					while((application_state_handler = switch_channel_get_state_handler(session->channel, index++)) != 0) {
-						if (!application_state_handler || !application_state_handler->on_hangup ||
-							(application_state_handler->on_hangup &&
-							 application_state_handler->on_hangup(session) == SWITCH_STATUS_SUCCESS &&
-							 midstate == switch_channel_get_state(session->channel))) {
-							proceed++;
-							continue;
-						} else {
-							proceed = 0;
-							break;
-						}
-					}
-					index = 0;
-					while(proceed && (application_state_handler = switch_core_get_state_handler(index++)) != 0) {
-						if (!application_state_handler || !application_state_handler->on_hangup ||
-							(application_state_handler->on_hangup &&
-							 application_state_handler->on_hangup(session) == SWITCH_STATUS_SUCCESS &&
-							 midstate == switch_channel_get_state(session->channel))) {
-							proceed++;
-							continue;
-						} else {
-							proceed = 0;
-							break;
-						}
-					}
-
-					if (proceed) {
-						switch_core_standard_on_hangup(session);
-					}
-				}
-				goto done;
-			case CS_INIT:		/* Basic setup tasks */
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) State INIT\n", switch_channel_get_name(session->channel));
-				if (!driver_state_handler->on_init ||
-					(driver_state_handler->on_init &&
-					 driver_state_handler->on_init(session) == SWITCH_STATUS_SUCCESS &&
-					 midstate == switch_channel_get_state(session->channel))) {
-					while((application_state_handler = switch_channel_get_state_handler(session->channel, index++)) != 0) {
-						if (!application_state_handler || !application_state_handler->on_init ||
-							(application_state_handler->on_init &&
-							 application_state_handler->on_init(session) == SWITCH_STATUS_SUCCESS &&
-							 midstate == switch_channel_get_state(session->channel))) {
-							proceed++;
-							continue;
-						} else {
-							proceed = 0;
-							break;
-						}
-					}
-					index = 0;
-					while(proceed && (application_state_handler = switch_core_get_state_handler(index++)) != 0) {
-						if (!application_state_handler || !application_state_handler->on_init ||
-							(application_state_handler->on_init &&
-							 application_state_handler->on_init(session) == SWITCH_STATUS_SUCCESS &&
-							 midstate == switch_channel_get_state(session->channel))) {
-							proceed++;
-							continue;
-						} else {
-							proceed = 0;
-							break;
-						}
-					}
-					if (proceed) {
-						switch_core_standard_on_init(session);
-					}
-				}
-				break;
-			case CS_RING:		/* Look for a dialplan and find something to do */
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) State RING\n", switch_channel_get_name(session->channel));
-				if (!driver_state_handler->on_ring ||
-					(driver_state_handler->on_ring &&
-					 driver_state_handler->on_ring(session) == SWITCH_STATUS_SUCCESS &&
-					 midstate == switch_channel_get_state(session->channel))) {
-					while((application_state_handler = switch_channel_get_state_handler(session->channel, index++)) != 0) {
-						if (!application_state_handler || !application_state_handler->on_ring ||
-							(application_state_handler->on_ring &&
-							 application_state_handler->on_ring(session) == SWITCH_STATUS_SUCCESS &&
-							 midstate == switch_channel_get_state(session->channel))) {
-							proceed++;
-							continue;
-						} else {
-							proceed = 0;
-							break;
-						}
-					}
-					index = 0;
-					while(proceed && (application_state_handler = switch_core_get_state_handler(index++)) != 0) {
-						if (!application_state_handler || !application_state_handler->on_ring ||
-							(application_state_handler->on_ring &&
-							 application_state_handler->on_ring(session) == SWITCH_STATUS_SUCCESS &&
-							 midstate == switch_channel_get_state(session->channel))) {
-							proceed++;
-							continue;
-						} else {
-							proceed = 0;
-							break;
-						}
-					}
-					if (proceed) {
-						switch_core_standard_on_ring(session);
-					}
-				}
-				break;
-			case CS_EXECUTE:	/* Execute an Operation */
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) State EXECUTE\n", switch_channel_get_name(session->channel));
-				if (!driver_state_handler->on_execute ||
-					(driver_state_handler->on_execute &&
-					 driver_state_handler->on_execute(session) == SWITCH_STATUS_SUCCESS &&
-					 midstate == switch_channel_get_state(session->channel))) {
-					while((application_state_handler = switch_channel_get_state_handler(session->channel, index++)) != 0) {
-						if (!application_state_handler || !application_state_handler->on_execute ||
-							(application_state_handler->on_execute &&
-							 application_state_handler->on_execute(session) == SWITCH_STATUS_SUCCESS &&
-							 midstate == switch_channel_get_state(session->channel))) {
-							proceed++;
-							continue;
-						} else {
-							proceed = 0;
-							break;
-						}
-					}
-					index = 0;
-					while(proceed && (application_state_handler = switch_core_get_state_handler(index++)) != 0) {
-						if (!application_state_handler || !application_state_handler->on_execute ||
-							(application_state_handler->on_execute &&
-							 application_state_handler->on_execute(session) == SWITCH_STATUS_SUCCESS &&
-							 midstate == switch_channel_get_state(session->channel))) {
-							proceed++;
-							continue;
-						} else {
-							proceed = 0;
-							break;
-						}
-					}
-					if (proceed) {
-						switch_core_standard_on_execute(session);
-					}
-				}
-				break;
-			case CS_LOOPBACK:	/* loop all data back to source */
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) State LOOPBACK\n", switch_channel_get_name(session->channel));
-				if (!driver_state_handler->on_loopback ||
-					(driver_state_handler->on_loopback &&
-					 driver_state_handler->on_loopback(session) == SWITCH_STATUS_SUCCESS &&
-					 midstate == switch_channel_get_state(session->channel))) {
-					while((application_state_handler = switch_channel_get_state_handler(session->channel, index++)) != 0) {
-						if (!application_state_handler || !application_state_handler->on_loopback ||
-							(application_state_handler->on_loopback &&
-							 application_state_handler->on_loopback(session) == SWITCH_STATUS_SUCCESS &&
-							 midstate == switch_channel_get_state(session->channel))) {
-							proceed++;
-							continue;
-						} else {
-							proceed = 0;
-							break;
-						}
-					}
-					index = 0;
-					while(proceed && (application_state_handler = switch_core_get_state_handler(index++)) != 0) {
-						if (!application_state_handler || !application_state_handler->on_loopback ||
-							(application_state_handler->on_loopback &&
-							 application_state_handler->on_loopback(session) == SWITCH_STATUS_SUCCESS &&
-							 midstate == switch_channel_get_state(session->channel))) {
-							proceed++;
-							continue;
-						} else {
-							proceed = 0;
-							break;
-						}
-					}
-					if (proceed) {
-						switch_core_standard_on_loopback(session);
-					}
-				}
-				break;
-			case CS_TRANSMIT:	/* send/recieve data to/from another channel */
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) State TRANSMIT\n", switch_channel_get_name(session->channel));
-				if (!driver_state_handler->on_transmit ||
-					(driver_state_handler->on_transmit &&
-					 driver_state_handler->on_transmit(session) == SWITCH_STATUS_SUCCESS &&
-					 midstate == switch_channel_get_state(session->channel))) {
-
-					while((application_state_handler = switch_channel_get_state_handler(session->channel, index++)) != 0) {
-						if (!application_state_handler || !application_state_handler->on_transmit ||
-							(application_state_handler->on_transmit &&
-							 application_state_handler->on_transmit(session) == SWITCH_STATUS_SUCCESS &&
-							 midstate == switch_channel_get_state(session->channel))) {
-							proceed++;
-							continue;
-						} else {
-							proceed = 0;
-							break;
-						}
-					}
-					index = 0;
-					while(proceed && (application_state_handler = switch_core_get_state_handler(index++)) != 0) {
-						if (!application_state_handler || !application_state_handler->on_transmit ||
-							(application_state_handler->on_transmit &&
-							 application_state_handler->on_transmit(session) == SWITCH_STATUS_SUCCESS &&
-							 midstate == switch_channel_get_state(session->channel))) {
-							proceed++;
-							continue;
-						} else {
-							proceed = 0;
-							break;
-						}
-					}
-					if (proceed) {
-						switch_core_standard_on_transmit(session);
-					}
-				}
-				break;
-			case CS_HOLD:	/* wait in limbo */
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) State HOLD\n", switch_channel_get_name(session->channel));
-				if (!driver_state_handler->on_hold ||
-					(driver_state_handler->on_hold &&
-					 driver_state_handler->on_hold(session) == SWITCH_STATUS_SUCCESS &&
-					 midstate == switch_channel_get_state(session->channel))) {
-
-					while((application_state_handler = switch_channel_get_state_handler(session->channel, index++)) != 0) {
-						if (!application_state_handler || !application_state_handler->on_hold ||
-							(application_state_handler->on_hold &&
-							 application_state_handler->on_hold(session) == SWITCH_STATUS_SUCCESS &&
-							 midstate == switch_channel_get_state(session->channel))) {
-							proceed++;
-							continue;
-						} else {
-							proceed = 0;
-							break;
-						}
-					}
-					index = 0;
-					while(proceed && (application_state_handler = switch_core_get_state_handler(index++)) != 0) {
-						if (!application_state_handler || !application_state_handler->on_hold ||
-							(application_state_handler->on_hold &&
-							 application_state_handler->on_hold(session) == SWITCH_STATUS_SUCCESS &&
-							 midstate == switch_channel_get_state(session->channel))) {
-							proceed++;
-							continue;
-						} else {
-							proceed = 0;
-							break;
-						}
-					}
-					if (proceed) {
-						switch_core_standard_on_hold(session);
-					}
-				}
-				break;
-			case CS_HIBERNATE:	/* wait in limbo */
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) State HIBERNATE\n", switch_channel_get_name(session->channel));
-				if (!driver_state_handler->on_hibernate ||
-					(driver_state_handler->on_hibernate &&
-					 driver_state_handler->on_hibernate(session) == SWITCH_STATUS_SUCCESS &&
-					 midstate == switch_channel_get_state(session->channel))) {
-
-					while((application_state_handler = switch_channel_get_state_handler(session->channel, index++)) != 0) {
-						if (!application_state_handler || !application_state_handler->on_hibernate ||
-							(application_state_handler->on_hibernate &&
-							 application_state_handler->on_hibernate(session) == SWITCH_STATUS_SUCCESS &&
-							 midstate == switch_channel_get_state(session->channel))) {
-							proceed++;
-							continue;
-						} else {
-							proceed = 0;
-							break;
-						}
-					}
-					index = 0;
-					while(proceed && (application_state_handler = switch_core_get_state_handler(index++)) != 0) {
-						if (!application_state_handler || !application_state_handler->on_hibernate ||
-							(application_state_handler->on_hibernate &&
-							 application_state_handler->on_hibernate(session) == SWITCH_STATUS_SUCCESS &&
-							 midstate == switch_channel_get_state(session->channel))) {
-							proceed++;
-							continue;
-						} else {
-							proceed = 0;
-							break;
-						}
-					}
-					if (proceed) {
-						switch_core_standard_on_hibernate(session);
-					}
-				}
-				break;
-			}
-
-			if (midstate == CS_DONE) {
-				break;
-			}
-
-			laststate = midstate;
-		}
-		
-
-		endstate = switch_channel_get_state(session->channel);
-
-
-		if (midstate == endstate) {
-			switch_thread_cond_wait(session->cond, session->mutex);
-		}
-
-	}
- done:
-	switch_mutex_unlock(session->mutex);
-
-#ifdef CRASH_PROT
-	apr_hash_set(runtime.stack_table, &thread_id, sizeof(thread_id), NULL);
-#endif
-	session->thread_running = 0;
-
-}
-
-SWITCH_DECLARE(void) switch_core_session_destroy(switch_core_session_t **session)
-{
-	switch_memory_pool_t *pool;
-	switch_event_t *event;
-
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Close Channel %s\n", switch_channel_get_name((*session)->channel));
-	
-	switch_core_scheduler_del_task_group((*session)->uuid_str);
-
-	switch_mutex_lock(runtime.session_table_mutex);
-	switch_core_hash_delete(runtime.session_table, (*session)->uuid_str);
-	if (runtime.session_count) {
-		runtime.session_count--;
-	}
-	switch_mutex_unlock(runtime.session_table_mutex);
-
-	if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_DESTROY) == SWITCH_STATUS_SUCCESS) {
-		switch_channel_event_set_data((*session)->channel, event);
-		switch_event_fire(&event);
-	}
-
-	switch_core_media_bug_remove_all(*session);
-	switch_buffer_destroy(&(*session)->raw_read_buffer);
-	switch_buffer_destroy(&(*session)->raw_write_buffer);
-	switch_channel_uninit((*session)->channel);
-
-	pool = (*session)->pool;
-	*session = NULL;
-	apr_pool_destroy(pool);
-	pool = NULL;
-
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_hash_init(switch_hash_t **hash, switch_memory_pool_t *pool)
-{
-	assert(pool != NULL);
-
-	if ((*hash = apr_hash_make(pool)) != 0) {
-		return SWITCH_STATUS_SUCCESS;
-	}
-
-	return SWITCH_STATUS_GENERR;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_hash_destroy(switch_hash_t *hash)
-{
-	assert(hash != NULL);
-	return SWITCH_STATUS_SUCCESS;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_dup(switch_hash_t *hash, const char *key, const void *data)
-{
-	apr_hash_set(hash, switch_core_strdup(apr_hash_pool_get(hash), key), APR_HASH_KEY_STRING, data);
-	return SWITCH_STATUS_SUCCESS;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_hash_insert(switch_hash_t *hash, const char *key, const void *data)
-{
-	apr_hash_set(hash, key, APR_HASH_KEY_STRING, data);
-	return SWITCH_STATUS_SUCCESS;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_core_hash_delete(switch_hash_t *hash, const char *key)
-{
-	apr_hash_set(hash, key, APR_HASH_KEY_STRING, NULL);
-	return SWITCH_STATUS_SUCCESS;
-}
-
-SWITCH_DECLARE(void *) switch_core_hash_find(switch_hash_t *hash, const char *key)
-{
-	return apr_hash_get(hash, key, APR_HASH_KEY_STRING);
-}
-
-/* This function abstracts the thread creation for modules by allowing you to pass a function ptr and
-   a void object and trust that that the function will be run in a thread with arg  This lets
-   you request and activate a thread without giving up any knowledge about what is in the thread
-   neither the core nor the calling module know anything about each other.
-
-   This thread is expected to never exit until the application exits so the func is responsible
-   to make sure that is the case.
-
-   The typical use for this is so switch_loadable_module.c can start up a thread for each module
-   passing the table of module methods as a session obj into the core without actually allowing
-   the core to have any clue and keeping switch_loadable_module.c from needing any thread code.
-
-*/
-
-SWITCH_DECLARE(void) switch_core_launch_thread(switch_thread_start_t func, void *obj, switch_memory_pool_t *pool)
-{
-	switch_thread_t *thread;
-	switch_threadattr_t *thd_attr = NULL;
-	switch_core_thread_session_t *ts;
-	int mypool;
-
-	mypool = pool ? 0 : 1;
-
-	if (!pool && switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Could not allocate memory pool\n");
-		return;
-	}
-
-	switch_threadattr_create(&thd_attr, pool);
-	switch_threadattr_detach_set(thd_attr, 1);
-
-	if ((ts = switch_core_alloc(pool, sizeof(*ts))) == 0) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Could not allocate memory\n");
-	} else {
-		if (mypool) {
-			ts->pool = pool;
-		}
-		ts->objs[0] = obj;
-		switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
-		switch_thread_create(&thread, thd_attr, func, ts, pool);
-	}
+								duration.hr, duration.hr == 1 ? "" : "s",
+								duration.min, duration.min == 1 ? "" : "s",
+								duration.sec, duration.sec == 1 ? "" : "s",
+								duration.ms, duration.ms == 1 ? "" : "s", duration.mms, duration.mms == 1 ? "" : "s");
 
+		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Session-Count", "%u", switch_core_session_count());
+		switch_event_fire(&event);
+	}
 }
 
-static void *SWITCH_THREAD_FUNC switch_core_session_thread(switch_thread_t *thread, void *obj)
+static void heartbeat_callback(switch_scheduler_task_t *task)
 {
-	switch_core_session_t *session = obj;
-	session->thread = thread;
-
-
-
-	switch_core_session_run(session);
-	switch_core_media_bug_remove_all(session);
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Session %u (%s) Locked, Waiting on external entities\n", session->id, switch_channel_get_name(session->channel));
-	switch_core_session_write_lock(session);
-    switch_set_flag(session, SSF_DESTROYED);
-	switch_core_session_rwunlock(session);
+	send_heartbeat();
 
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Session %u (%s) Ended\n", session->id, switch_channel_get_name(session->channel));
-	switch_core_session_destroy(&session);
-	return NULL;
+	/* reschedule this task */
+	task->runtime += 20;
 }
 
 
-SWITCH_DECLARE(void) switch_core_session_thread_launch(switch_core_session_t *session)
+SWITCH_DECLARE(switch_status_t) switch_core_set_console(char *console)
 {
-	switch_thread_t *thread;
-	switch_threadattr_t *thd_attr;;
-	switch_threadattr_create(&thd_attr, session->pool);
-	switch_threadattr_detach_set(thd_attr, 1);
-
-	if (! session->thread_running) {
-		switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
-		if (switch_thread_create(&thread, thd_attr, switch_core_session_thread, session, session->pool) != SWITCH_STATUS_SUCCESS) {
-			switch_core_session_destroy(&session);
-		}
+	if ((runtime.console = fopen(console, "a")) == 0) {
+		fprintf(stderr, "Cannot open output file %s.\n", console);
+		return SWITCH_STATUS_FALSE;
 	}
-}
 
+	return SWITCH_STATUS_SUCCESS;
+}
 
-SWITCH_DECLARE(void) switch_core_session_launch_thread(switch_core_session_t *session, switch_thread_start_t func,
-													   void *obj)
+SWITCH_DECLARE(FILE *) switch_core_get_console(void)
 {
-	switch_thread_t *thread;
-	switch_threadattr_t *thd_attr = NULL;
-	switch_threadattr_create(&thd_attr, session->pool);
-	switch_threadattr_detach_set(thd_attr, 1);
-
-	switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
-	switch_thread_create(&thread, thd_attr, func, obj, session->pool);
-
+	return runtime.console;
 }
 
-
-SWITCH_DECLARE(void *) switch_core_alloc(switch_memory_pool_t *pool, switch_size_t memory)
+SWITCH_DECLARE(FILE *) switch_core_data_channel(switch_text_channel_t channel)
 {
-	void *ptr = NULL;
-	assert(pool != NULL);
-
-#ifdef DEBUG_ALLOC
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Allocate %d\n", memory);
-	/* assert(memory < 600000); */
-#endif
+	FILE *handle = stdout;
 
-	if ((ptr = apr_palloc(pool, memory)) != 0) {
-		memset(ptr, 0, memory);
+	switch (channel) {
+	case SWITCH_CHANNEL_ID_LOG:
+	case SWITCH_CHANNEL_ID_LOG_CLEAN:
+		handle = runtime.console;
+		break;
+	default:
+		handle = runtime.console;
+		break;
 	}
-	return ptr;
+
+	return handle;
 }
 
-SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request(const switch_endpoint_interface_t *endpoint_interface, switch_memory_pool_t **pool)
-																	
+SWITCH_DECLARE(int) switch_core_add_state_handler(const switch_state_handler_table_t *state_handler)
 {
-	switch_memory_pool_t *usepool;
-	switch_core_session_t *session;
-	switch_uuid_t uuid;
-	uint32_t count = 0;
-
-	assert(endpoint_interface != NULL);
-
-	switch_mutex_lock(runtime.session_table_mutex);
-	count = runtime.session_count;
-	switch_mutex_unlock(runtime.session_table_mutex);
-
-	if ((count + 1) > runtime.session_limit) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Over Session Limit!\n");
-		return NULL;
-	}
+	int index = runtime.state_handler_index++;
 
-	if (runtime.no_new_sessions || runtime.shutting_down) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Read my lips: no new sessions!\n");
-		return NULL;
+	if (runtime.state_handler_index >= SWITCH_MAX_STATE_HANDLERS) {
+		return -1;
 	}
 
-	if (pool && *pool) {
-		usepool = *pool;
-		*pool = NULL;
-	} else if (switch_core_new_memory_pool(&usepool) != SWITCH_STATUS_SUCCESS) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Could not allocate memory pool\n");
-		return NULL;
-	}
+	runtime.state_handlers[index] = state_handler;
+	return index;
+}
 
-	if ((session = switch_core_alloc(usepool, sizeof(switch_core_session_t))) == 0) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Could not allocate session\n");
-		apr_pool_destroy(usepool);
-		return NULL;
-	}
+SWITCH_DECLARE(const switch_state_handler_table_t *) switch_core_get_state_handler(int index)
+{
 
-	if (switch_channel_alloc(&session->channel, usepool) != SWITCH_STATUS_SUCCESS) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not allocate channel structure\n");
-		apr_pool_destroy(usepool);
+	if (index > SWITCH_MAX_STATE_HANDLERS || index > runtime.state_handler_index) {
 		return NULL;
 	}
 
-	switch_channel_init(session->channel, session, CS_NEW, 0);
-
-	/* 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);
-
-	session->pool = usepool;
-	session->endpoint_interface = endpoint_interface;
-
-	session->raw_write_frame.data = session->raw_write_buf;
-	session->raw_write_frame.buflen = sizeof(session->raw_write_buf);
-	session->raw_read_frame.data = session->raw_read_buf;
-	session->raw_read_frame.buflen = sizeof(session->raw_read_buf);
-
-
-	session->enc_write_frame.data = session->enc_write_buf;
-	session->enc_write_frame.buflen = sizeof(session->enc_write_buf);
-	session->enc_read_frame.data = session->enc_read_buf;
-	session->enc_read_frame.buflen = sizeof(session->enc_read_buf);
-
-	switch_mutex_init(&session->mutex, SWITCH_MUTEX_NESTED, session->pool);
-	switch_thread_rwlock_create(&session->bug_rwlock, session->pool);
-	switch_thread_cond_create(&session->cond, session->pool);
-	switch_thread_rwlock_create(&session->rwlock, session->pool);
-
-	snprintf(session->name, sizeof(session->name), "%u", session->id);
-	switch_mutex_lock(runtime.session_table_mutex);
-	session->id = runtime.session_id++;
-	switch_core_hash_insert(runtime.session_table, session->uuid_str, session);
-	runtime.session_count++;
-	switch_mutex_unlock(runtime.session_table_mutex);
-
-	return session;
+	return runtime.state_handlers[index];
 }
 
-SWITCH_DECLARE(uint32_t) switch_core_session_count(void)
+
+SWITCH_DECLARE(char *) switch_core_get_variable(char *varname)
 {
-	return runtime.session_count;
+	return (char *) switch_core_hash_find(runtime.global_vars, varname);
 }
 
-SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request_by_name(char *endpoint_name, switch_memory_pool_t **pool)
+SWITCH_DECLARE(void) switch_core_set_variable(char *varname, char *value)
 {
-	const 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);
-		return NULL;
-	}
-
-	return switch_core_session_request(endpoint_interface, pool);
+	switch_core_hash_insert(runtime.global_vars, switch_core_strdup(runtime.memory_pool, varname), switch_core_strdup(runtime.memory_pool, value));
 }
 
-static switch_status_t switch_core_db_persistant_execute_trans(switch_core_db_t *db, char *sql, uint32_t retries)
+SWITCH_DECLARE(char *) switch_core_get_uuid(void)
 {
-	char *errmsg;
-	switch_status_t status = SWITCH_STATUS_FALSE;
-	uint8_t forever = 0;
-	unsigned begin_retries = 100;
-	uint8_t again = 0;
-
-	if (!retries) {
-		forever = 1;
-		retries = 1000;
-	}
-
- again:
-
-	while(begin_retries > 0) {
-		again = 0;
-		
-		switch_core_db_exec(
-							db,
-							"begin transaction",
-							NULL,
-							NULL,
-							&errmsg
-							);
-	
-        if (errmsg) {
-			begin_retries--;
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR [%s]\n", errmsg);
-			if (strstr(errmsg, "cannot start a transaction within a transaction")) {
-				again = 1;
-			}
-            switch_core_db_free(errmsg);
-
-			if (again) {
-				switch_core_db_exec(db, "end transaction", NULL, NULL, &errmsg);
-				goto again;
-			}
-
-            switch_yield(100000);
-
-			if(begin_retries == 0) {
-				goto done;
-			} 
-        } else {
-            break;
-        }
-
-	}
+	return runtime.uuid_str;
+}
 
-	while(retries > 0) {
 
+static void *switch_core_service_thread(switch_thread_t * thread, void *obj)
+{
+	switch_core_thread_session_t *data = obj;
+	switch_core_session_t *session = data->objs[0];
+	int *stream_id_p = data->objs[1];
+	switch_channel_t *channel;
+	switch_frame_t *read_frame;
+	int stream_id = *stream_id_p;
 
+	assert(thread != NULL);
+	assert(session != NULL);
+	channel = switch_core_session_get_channel(session);
+	assert(channel != NULL);
 
-		switch_core_db_exec(
-							db,
-							sql,
-							NULL,
-							NULL,
-							&errmsg
-							);		
-		if (errmsg) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR [%s]\n", errmsg);
-			switch_core_db_free(errmsg);
-			switch_yield(100000);
-			retries--;
-			if (retries == 0 && forever) {
-				retries = 1000;
-				continue;
-			}
-		} else {
-			status = SWITCH_STATUS_SUCCESS;
+	switch_channel_set_flag(channel, CF_SERVICE);
+	while (data->running > 0) {
+		switch (switch_core_session_read_frame(session, &read_frame, -1, stream_id)) {
+		case SWITCH_STATUS_SUCCESS:
+		case SWITCH_STATUS_TIMEOUT:
+		case SWITCH_STATUS_BREAK:
 			break;
+		default:
+			data->running = -1;
+			continue;
 		}
 	}
 
-
- done:
-
-	switch_core_db_exec(
-						db,
-						"end transaction",
-						NULL,
-						NULL,
-						&errmsg
-						);
-
-	return status;
+	switch_channel_clear_flag(channel, CF_SERVICE);
+	data->running = 0;
+	return NULL;
 }
 
-SWITCH_DECLARE(switch_status_t) switch_core_db_persistant_execute(switch_core_db_t *db, char *sql, uint32_t retries)
+/* Either add a timeout here or make damn sure the thread cannot get hung somehow (my preference) */
+SWITCH_DECLARE(void) switch_core_thread_session_end(switch_core_thread_session_t *thread_session)
 {
-	char *errmsg;
-	switch_status_t status = SWITCH_STATUS_FALSE;
-	uint8_t forever = 0;
-
-	if (!retries) {
-		forever = 1;
-		retries = 1000;
-	}
+	if (thread_session->running > 0) {
+		thread_session->running = -1;
 
-	while(retries > 0) {
-		switch_core_db_exec(
-							db,
-							sql,
-							NULL,
-							NULL,
-							&errmsg
-							);		
-		if (errmsg) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR [%s]\n", errmsg);
-			switch_core_db_free(errmsg);
-			switch_yield(100000);
-			retries--;
-			if (retries == 0 && forever) {
-				retries = 1000;
-				continue;
-			}
-		} else {
-			status = SWITCH_STATUS_SUCCESS;
-			break;
+		while (thread_session->running) {
+			switch_yield(1000);
 		}
 	}
-
-	return status;
 }
 
-#ifdef DO_EVENTS
-#define SQLLEN 1024 * 64
-static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread, void *obj)
+SWITCH_DECLARE(void) switch_core_service_session(switch_core_session_t *session, switch_core_thread_session_t *thread_session, int stream_id)
 {
-	void *pop;
-	uint32_t itterations = 0;
-	uint8_t trans = 0, nothing_in_queue = 0;
-	uint32_t target = 1000;
-	switch_size_t len = 0, sql_len = SQLLEN;
-	char *sqlbuf = (char *) malloc(sql_len);
-	char *sql;
-	switch_size_t newlen;
-	
-	if (!runtime.event_db) {
-		runtime.event_db = switch_core_db_handle();
-	}
-	switch_queue_create(&runtime.sql_queue, SWITCH_SQL_QUEUE_LEN, runtime.memory_pool);
-
+	thread_session->running = 1;
+	thread_session->objs[0] = session;
+	thread_session->objs[1] = &stream_id;
+	switch_core_session_launch_thread(session, switch_core_service_thread, thread_session);
+}
 
 
-	for(;;) {
-		if (switch_queue_trypop(runtime.sql_queue, &pop) == SWITCH_STATUS_SUCCESS) {
-			sql = (char *) pop;
+/* This function abstracts the thread creation for modules by allowing you to pass a function ptr and
+   a void object and trust that that the function will be run in a thread with arg  This lets
+   you request and activate a thread without giving up any knowledge about what is in the thread
+   neither the core nor the calling module know anything about each other.
 
-			if (sql) {
-				newlen = strlen(sql) + 2;
-				
-				if (itterations == 0) {
-					trans = 1;
-				}
+   This thread is expected to never exit until the application exits so the func is responsible
+   to make sure that is the case.
 
-				/* ignore abnormally large strings sql strings as potential buffer overflow */
-				if (newlen < SQLLEN) {
-					itterations++;
-					if (len + newlen > sql_len) {
-						sql_len = len + SQLLEN;
-						if (!(sqlbuf = realloc(sqlbuf, sql_len))) {
-							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "SQL thread ending on mem err\n");
-							break;
-						}
-					}
-					sprintf(sqlbuf + len, "%s;\n", sql); 
-					len += newlen;
+   The typical use for this is so switch_loadable_module.c can start up a thread for each module
+   passing the table of module methods as a session obj into the core without actually allowing
+   the core to have any clue and keeping switch_loadable_module.c from needing any thread code.
 
-				}
-				switch_core_db_free(sql);
-			} else {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "SQL thread ending\n");
-				break;
-			}
-		} else {
-			nothing_in_queue = 1;
-		}
+*/
 
+SWITCH_DECLARE(void) switch_core_launch_thread(switch_thread_start_t func, void *obj, switch_memory_pool_t *pool)
+{
+	switch_thread_t *thread;
+	switch_threadattr_t *thd_attr = NULL;
+	switch_core_thread_session_t *ts;
+	int mypool;
 
-		if (trans && ((itterations == target) || nothing_in_queue)) {
-			if (switch_core_db_persistant_execute_trans(runtime.event_db, sqlbuf, 1000) != SWITCH_STATUS_SUCCESS) {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "SQL thread unable to commit transaction, records lost!\n");
-			}
-			itterations = 0;
-			trans = 0;
-			nothing_in_queue = 0;
-			len = 0;
-			*sqlbuf = '\0';
-		}
+	mypool = pool ? 0 : 1;
 
-		if (nothing_in_queue) {
-			switch_yield(1000);
-		}
+	if (!pool && switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Could not allocate memory pool\n");
+		return;
 	}
 
-
-	free(sqlbuf);
-	return NULL;
-}
-
-
-static void switch_core_sql_thread_launch(void)
-{
-	switch_thread_t *thread;
-	switch_threadattr_t *thd_attr;;
-	
-	assert(runtime.memory_pool != NULL);
-
-	switch_threadattr_create(&thd_attr, runtime.memory_pool);
+	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, switch_core_sql_thread, NULL, runtime.memory_pool);
-	
-}
 
-static void core_event_handler(switch_event_t *event)
-{
-	char *sql = NULL;
-
-	switch (event->event_id) {
-	case SWITCH_EVENT_CHANNEL_DESTROY:
-		sql = switch_mprintf("delete from channels where uuid='%s'", switch_event_get_header(event, "unique-id"));
-		break;
-	case SWITCH_EVENT_CHANNEL_CREATE:
-		sql = switch_mprintf("insert into channels (uuid,created,name,state) values('%q','%q','%q','%q')",
-									 switch_event_get_header(event, "unique-id"),
-									 switch_event_get_header(event, "event-date-local"),
-									 switch_event_get_header(event, "channel-name"),
-									 switch_event_get_header(event, "channel-state")
-									 );
-		break;
-	case SWITCH_EVENT_CODEC:
-		sql = switch_mprintf("update channels set read_codec='%q',read_rate='%q',write_codec='%q',write_rate='%q' where uuid='%q'",
-									 switch_event_get_header(event, "channel-read-codec-name"),
-									 switch_event_get_header(event, "channel-read-codec-rate"),
-									 switch_event_get_header(event, "channel-write-codec-name"),
-									 switch_event_get_header(event, "channel-write-codec-rate"),
-									 switch_event_get_header(event, "unique-id"));
-		break;
-	case SWITCH_EVENT_CHANNEL_EXECUTE:
-		sql = switch_mprintf("update channels set application='%q',application_data='%q' where uuid='%q'",
-									 switch_event_get_header(event, "application"),
-									 switch_event_get_header(event, "application-data"),
-									 switch_event_get_header(event, "unique-id")
-									 );
-		break;
-	case SWITCH_EVENT_CHANNEL_STATE:
-		if (event) {
-			char *state = switch_event_get_header(event, "channel-state-number");
-			switch_channel_state_t state_i = atoi(state);
-
-			switch(state_i) {
-			case CS_HANGUP:
-			case CS_DONE:
-				break;
-			case CS_RING:
-				sql = switch_mprintf("update channels set state='%s',cid_name='%q',cid_num='%q',ip_addr='%s',dest='%q'"
-											 "where uuid='%s'",
-											 switch_event_get_header(event, "channel-state"),
-											 switch_event_get_header(event, "caller-caller-id-name"),
-											 switch_event_get_header(event, "caller-caller-id-number"),
-											 switch_event_get_header(event, "caller-network-addr"),
-											 switch_event_get_header(event, "caller-destination-number"),
-											 switch_event_get_header(event, "unique-id")
-											 );
-				break;
-			default:
-				sql = switch_mprintf("update channels set state='%s' where uuid='%s'", 
-											 switch_event_get_header(event, "channel-state"),
-											 switch_event_get_header(event, "unique-id")
-											 );
-				break;
-			}
-		
-		}
-		break;
-	case SWITCH_EVENT_CHANNEL_BRIDGE:
-		sql = switch_mprintf("insert into calls values ('%s','%q','%q','%q','%q','%s','%q','%q','%q','%q','%s')",
-									 switch_event_get_header(event, "event-calling-function"),
-									 switch_event_get_header(event, "caller-caller-id-name"),
-									 switch_event_get_header(event, "caller-caller-id-number"),
-									 switch_event_get_header(event, "caller-destination-number"),
-									 switch_event_get_header(event, "caller-channel-name"),
-									 switch_event_get_header(event, "caller-unique-id"),
-									 switch_event_get_header(event, "originatee-caller-id-name"),
-									 switch_event_get_header(event, "originatee-caller-id-number"),
-									 switch_event_get_header(event, "originatee-destination-number"),
-									 switch_event_get_header(event, "originatee-channel-name"),
-									 switch_event_get_header(event, "originatee-unique-id")
-									 );
-		break;
-	case SWITCH_EVENT_CHANNEL_UNBRIDGE:
-		sql = switch_mprintf("delete from calls where caller_uuid='%s'", switch_event_get_header(event, "caller-unique-id"));
-		break;
-	case SWITCH_EVENT_SHUTDOWN:
-		sql = switch_mprintf("delete from channels;delete from interfaces;delete from calls");
-		break;
-	case SWITCH_EVENT_LOG:
-		return;
-	case SWITCH_EVENT_MODULE_LOAD:
-		{
-			const char *type = switch_event_get_header(event, "type");
-			const char *name = switch_event_get_header(event, "name");
-			const char *description = switch_event_get_header(event, "description");
-			const char *syntax = switch_event_get_header(event, "syntax");
-			if(!switch_strlen_zero(type) && !switch_strlen_zero(name)) {
-				sql = switch_mprintf("insert into interfaces (type,name,description,syntax) values('%q','%q','%q','%q')",
-											 type,
-											 name,
-											 switch_str_nil(description),
-											 switch_str_nil(syntax)
-											 );
-			}
-		break;
+	if ((ts = switch_core_alloc(pool, sizeof(*ts))) == 0) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Could not allocate memory\n");
+	} else {
+		if (mypool) {
+			ts->pool = pool;
 		}
-	default:
-		break;
+		ts->objs[0] = obj;
+		switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
+		switch_thread_create(&thread, thd_attr, func, ts, pool);
 	}
 
-	if (sql) {
-		switch_queue_push(runtime.sql_queue, sql);
-		sql = NULL;
-	}
 }
-#endif
-
-#ifndef SWITCH_PREFIX_DIR
-#define SWITCH_PREFIX_DIR "."
-#endif
 
 SWITCH_DECLARE(void) switch_core_set_globals(void)
 {
 #define BUFSIZE 1024
 #ifdef WIN32
-    char lpPathBuffer[BUFSIZE];
-	DWORD dwBufSize=BUFSIZE;
+	char lpPathBuffer[BUFSIZE];
+	DWORD dwBufSize = BUFSIZE;
 	char base_dir[1024];
 	char *lastbacklash;
-	GetModuleFileName( NULL, base_dir, BUFSIZE );
-	lastbacklash = strrchr( base_dir, '\\');
+	GetModuleFileName(NULL, base_dir, BUFSIZE);
+	lastbacklash = strrchr(base_dir, '\\');
 	base_dir[(lastbacklash - base_dir)] = '\0';
 #else
 	char base_dir[1024] = SWITCH_PREFIX_DIR;
@@ -4679,24 +350,14 @@
 }
 
 
-SWITCH_DECLARE(uint32_t) switch_core_session_limit(uint32_t new_limit)
-{
-	if (new_limit) {
-		runtime.session_limit = new_limit;
-	}
-	
-	return runtime.session_limit;
-}
-
-
 SWITCH_DECLARE(int32_t) set_high_priority(void)
 {
 #ifdef __linux__
-	struct sched_param sched = {0};
+	struct sched_param sched = { 0 };
 	sched.sched_priority = 1;
 	if (sched_setscheduler(0, SCHED_RR, &sched)) {
-        sched.sched_priority = 0;
-        if (sched_setscheduler(0, SCHED_OTHER, &sched)) {
+		sched.sched_priority = 0;
+		if (sched_setscheduler(0, SCHED_OTHER, &sched)) {
 			return -1;
 		}
 	}
@@ -4711,7 +372,7 @@
 #define USE_MLOCKALL
 #ifdef HAVE_MLOCKALL
 #ifdef USE_MLOCKALL
-	mlockall(MCL_CURRENT|MCL_FUTURE);
+	mlockall(MCL_CURRENT | MCL_FUTURE);
 #endif
 #endif
 	return 0;
@@ -4727,15 +388,15 @@
 		bg = 0;
 #ifdef WIN32
 		snprintf(path, sizeof(path), "Global\\Freeswitch.%d", getpid());
-		shutdown_event = CreateEvent(NULL, FALSE, FALSE, path);		
+		shutdown_event = CreateEvent(NULL, FALSE, FALSE, path);
 		WaitForSingleObject(shutdown_event, INFINITE);
 #else
 		runtime.running = 1;
-		while(runtime.running) {
+		while (runtime.running) {
 			switch_yield(1000000);
 		}
 #endif
-	}  else {
+	} else {
 		/* wait for console input */
 		switch_console_loop();
 	}
@@ -4747,25 +408,26 @@
 	switch_xml_t xml = NULL, cfg = NULL;
 	switch_uuid_t uuid;
 	memset(&runtime, 0, sizeof(runtime));
-	runtime.session_limit = 1000;
-
-	switch_core_set_globals();
 
 	/* INIT APR and Create the pool context */
 	if (apr_initialize() != SWITCH_STATUS_SUCCESS) {
-		apr_terminate();
 		*err = "FATAL ERROR! Could not initilize APR\n";
 		return SWITCH_STATUS_MEMERR;
 	}
 
-	if (apr_pool_create(&runtime.memory_pool, NULL) != SWITCH_STATUS_SUCCESS) {
-		apr_terminate();
-		*err = "FATAL ERROR! Could not allocate memory pool\n";
+	if (!(runtime.memory_pool = switch_core_memory_init())) {
+		*err = "FATAL ERROR! Could noat allocate memory pool\n";
 		return SWITCH_STATUS_MEMERR;
 	}
+	assert(runtime.memory_pool != NULL);
 
+	switch_core_set_globals();
+	switch_core_session_init(runtime.memory_pool);
+	switch_core_state_machine_init(runtime.memory_pool);
 	switch_core_hash_init(&runtime.global_vars, runtime.memory_pool);
 
+
+
 	if (switch_xml_init(runtime.memory_pool, err) != SWITCH_STATUS_SUCCESS) {
 		apr_terminate();
 		return SWITCH_STATUS_MEMERR;
@@ -4774,14 +436,14 @@
 
 	if ((xml = switch_xml_open_cfg("switch.conf", &cfg, NULL))) {
 		switch_xml_t settings, param;
-		
+
 		if ((settings = switch_xml_child(cfg, "settings"))) {
 			for (param = switch_xml_child(settings, "param"); param; param = param->next) {
 				const char *var = switch_xml_attr_soft(param, "name");
 				const char *val = switch_xml_attr_soft(param, "value");
-				
+
 				if (!strcasecmp(var, "max-sessions")) {
-					runtime.session_limit = atoi(val);
+					switch_core_session_limit(atoi(val));
 				}
 			}
 		}
@@ -4802,7 +464,7 @@
 
 	*err = NULL;
 
-	if(console) {
+	if (console) {
 		if (*console != '/') {
 			char path[265];
 			snprintf(path, sizeof(path), "%s%s%s", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR, console);
@@ -4819,88 +481,16 @@
 
 	assert(runtime.memory_pool != NULL);
 	switch_log_init(runtime.memory_pool);
-
-#ifdef DO_EVENTS
-	switch_core_sql_thread_launch();
-#endif
-
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Allocated memory pool. Sessions are %u bytes\n", (uint32_t)sizeof(switch_core_session_t));
 	switch_event_init(runtime.memory_pool);
+	switch_core_sqldb_start(runtime.memory_pool);
 	switch_rtp_init(runtime.memory_pool);
-
-	/* Activate SQL database */
-	if ((runtime.db = switch_core_db_handle()) == 0 ) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB!\n");
-	} else {
-		char create_channels_sql[] =
-			"CREATE TABLE channels (\n"
-			"   uuid  VARCHAR(255),\n"
-			"   created  VARCHAR(255),\n"
-			"   name  VARCHAR(255),\n"
-			"   state  VARCHAR(255),\n"
-			"   cid_name  VARCHAR(255),\n"
-			"   cid_num  VARCHAR(255),\n"
-			"   ip_addr  VARCHAR(255),\n"
-			"   dest  VARCHAR(255),\n"
-			"   application  VARCHAR(255),\n"
-			"   application_data  VARCHAR(255),\n"
-			"   read_codec  VARCHAR(255),\n"
-			"   read_rate  VARCHAR(255),\n"
-			"   write_codec  VARCHAR(255),\n"
-			"   write_rate  VARCHAR(255)\n"
-			");\n";
-		char create_calls_sql[] =
-			"CREATE TABLE calls (\n"
-			"   function  VARCHAR(255),\n"
-			"   caller_cid_name  VARCHAR(255),\n"
-			"   caller_cid_num   VARCHAR(255),\n"
-			"   caller_dest_num  VARCHAR(255),\n"
-			"   caller_chan_name VARCHAR(255),\n"
-			"   caller_uuid      VARCHAR(255),\n"
-			"   callee_cid_name  VARCHAR(255),\n"
-			"   callee_cid_num   VARCHAR(255),\n"
-			"   callee_dest_num  VARCHAR(255),\n"
-			"   callee_chan_name VARCHAR(255),\n"
-			"   callee_uuid      VARCHAR(255)\n"
-			");\n";
-		char create_interfaces_sql[] =
-			"CREATE TABLE interfaces (\n"
-			"   type             VARCHAR(255),\n"
-			"   name             VARCHAR(255),\n"
-			"   description      VARCHAR(255),\n"
-			"   syntax           VARCHAR(255)\n"
-			");\n";
-
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Opening DB\n");
-		switch_core_db_exec(runtime.db, "drop table channels", NULL, NULL, NULL);
-		switch_core_db_exec(runtime.db, "drop table calls", NULL, NULL, NULL);
-		switch_core_db_exec(runtime.db, "drop table interfaces", NULL, NULL, NULL);
-		switch_core_db_exec(runtime.db, create_channels_sql, NULL, NULL, NULL);
-		switch_core_db_exec(runtime.db, create_calls_sql, NULL, NULL, NULL);
-		switch_core_db_exec(runtime.db, create_interfaces_sql, NULL, NULL, NULL);
-#ifdef DO_EVENTS		
-		if (switch_event_bind("core_db", SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, core_event_handler, NULL) !=
-			SWITCH_STATUS_SUCCESS) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind event handler!\n");
-		}
-#endif
-	}
-
-	runtime.session_id = 1;
 	runtime.running = 1;
-	switch_core_hash_init(&runtime.session_table, runtime.memory_pool);
-	switch_mutex_init(&runtime.session_table_mutex, SWITCH_MUTEX_NESTED, runtime.memory_pool);
-	switch_mutex_init(&runtime.task_mutex, SWITCH_MUTEX_NESTED, runtime.memory_pool);
-#ifdef CRASH_PROT
-	switch_core_hash_init(&runtime.stack_table, runtime.memory_pool);
-#endif
 
-	
-	switch_core_task_thread_launch();
+	switch_scheduler_task_thread_start();
 	runtime.initiated = switch_time_now();
 
-	switch_core_scheduler_add_task(time(NULL), heartbeat_callback, "heartbeat", "core", 0, NULL, SSHF_NONE); 
-	
+	switch_scheduler_add_task(time(NULL), heartbeat_callback, "heartbeat", "core", 0, NULL, SSHF_NONE | SSHF_NO_DEL);
+
 
 	switch_uuid_get(&uuid);
 	switch_uuid_format(runtime.uuid_str, &uuid);
@@ -4911,7 +501,7 @@
 #ifdef SIGPIPE
 static void handle_SIGPIPE(int sig)
 {
-	if(sig);
+	if (sig);
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Sig Pipe!\n");
 	return;
 }
@@ -4920,7 +510,7 @@
 #ifdef SIGPOLL
 static void handle_SIGPOLL(int sig)
 {
-	if(sig);
+	if (sig);
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Sig Poll!\n");
 	return;
 }
@@ -4929,7 +519,7 @@
 #ifdef SIGIO
 static void handle_SIGIO(int sig)
 {
-	if(sig);
+	if (sig);
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Sig I/O!\n");
 	return;
 }
@@ -4970,7 +560,7 @@
 #ifdef TRAP_BUS
 	signal(SIGBUS, handle_SIGBUS);
 #endif
-	
+
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Bringing up environment.\n");
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Loading Modules.\n");
 	if (switch_loadable_module_init() != SWITCH_STATUS_SUCCESS) {
@@ -4984,26 +574,28 @@
 		switch_event_fire(&event);
 	}
 
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\nFreeSWITCH Version %s Started.\nCrash Protection [%s]\nMax Sessions[%u]\n\n", SWITCH_VERSION_FULL, __CP, switch_core_session_limit(0));
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE,
+					  "\nFreeSWITCH Version %s Started.\nCrash Protection [%s]\nMax Sessions[%u]\n\n", SWITCH_VERSION_FULL, __CP,
+					  switch_core_session_limit(0));
 	return SWITCH_STATUS_SUCCESS;
 
 }
 
 SWITCH_DECLARE(void) switch_core_measure_time(switch_time_t total_ms, switch_core_time_duration_t *duration)
 {
-    switch_time_t temp = total_ms / 1000;
+	switch_time_t temp = total_ms / 1000;
 	memset(duration, 0, sizeof(*duration));
-	duration->mms = (uint32_t)(total_ms % 1000);
-	duration->ms = (uint32_t)(temp % 1000);
-    temp = temp / 1000;
-    duration->sec = (uint32_t)(temp % 60);
-    temp = temp / 60;
-    duration->min = (uint32_t)(temp % 60);
+	duration->mms = (uint32_t) (total_ms % 1000);
+	duration->ms = (uint32_t) (temp % 1000);
+	temp = temp / 1000;
+	duration->sec = (uint32_t) (temp % 60);
 	temp = temp / 60;
-	duration->hr = (uint32_t)(temp % 24);
+	duration->min = (uint32_t) (temp % 60);
+	temp = temp / 60;
+	duration->hr = (uint32_t) (temp % 24);
 	temp = temp / 24;
-	duration->day = (uint32_t)(temp % 365);
-	duration->yr = (uint32_t)(temp / 365);
+	duration->day = (uint32_t) (temp % 365);
+	duration->yr = (uint32_t) (temp / 365);
 }
 
 SWITCH_DECLARE(switch_time_t) switch_core_uptime(void)
@@ -5011,7 +603,7 @@
 	return switch_time_now() - runtime.initiated;
 }
 
-SWITCH_DECLARE(int32_t) switch_core_session_ctl(switch_session_ctl_t cmd, uint32_t *val)
+SWITCH_DECLARE(int32_t) switch_core_session_ctl(switch_session_ctl_t cmd, uint32_t * val)
 {
 
 	if (runtime.shutting_down) {
@@ -5036,6 +628,12 @@
 	return 0;
 }
 
+SWITCH_DECLARE(switch_bool_t) switch_core_ready(void)
+{
+	return (runtime.shutting_down || runtime.no_new_sessions) ? SWITCH_FALSE : SWITCH_TRUE;
+}
+
+
 SWITCH_DECLARE(switch_status_t) switch_core_destroy(void)
 {
 	switch_event_t *event;
@@ -5046,6 +644,7 @@
 	runtime.shutting_down = 1;
 	runtime.no_new_sessions = 1;
 
+
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "End existing sessions\n");
 	switch_core_session_hupall(SWITCH_CAUSE_SYSTEM_SHUTDOWN);
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Clean up modules.\n");
@@ -5053,43 +652,21 @@
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Closing Event Engine.\n");
 	switch_event_shutdown();
-	
-	switch_queue_push(runtime.sql_queue, NULL);
-
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Waiting for unfinished SQL transactions\n");
-	while (switch_queue_size(runtime.sql_queue) > 0) {
-		switch_yield(10000);
-	}
 
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Stopping Task Thread\n");
-	if (runtime.task_thread_running == 1) {
-		int sanity = 0;
-		
-		runtime.task_thread_running = -1;
-
-		while(runtime.task_thread_running) {
-			switch_yield(100000);
-			if (++sanity > 10) {
-				break;
-			}
-		}
-	}
+	switch_core_sqldb_stop();
+	switch_scheduler_task_thread_stop();
 
-	switch_core_db_close(runtime.db);
-	switch_core_db_close(runtime.event_db);
 	switch_xml_destroy();
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Finalizing Shutdown.\n");
 	switch_log_shutdown();
 
 
-	
-	if(runtime.console != stdout && runtime.console != stderr) {
+
+	if (runtime.console != stdout && runtime.console != stderr) {
 		fclose(runtime.console);
 		runtime.console = NULL;
 	}
 
-    switch_yield(1000000);
-
 	switch_safe_free(SWITCH_GLOBAL_dirs.base_dir);
 	switch_safe_free(SWITCH_GLOBAL_dirs.mod_dir);
 	switch_safe_free(SWITCH_GLOBAL_dirs.conf_dir);
@@ -5108,13 +685,6 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-SWITCH_DECLARE(uint8_t) switch_core_session_compare(switch_core_session_t *a, switch_core_session_t *b)
-{
-	assert(a != NULL);
-	assert(b != NULL);
-
-	return (uint8_t)(a->endpoint_interface == b->endpoint_interface);
-}
 
 /* For Emacs:
  * Local Variables:

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/switch_core_db.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/switch_core_db.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/switch_core_db.c	Fri Mar 30 12:19:18 2007
@@ -31,8 +31,22 @@
  */
 
 #include <switch.h>
+#include "private/switch_core.h"
+
 #include <sqlite3.h>
 
+static void db_pick_path(char *dbname, char *buf, switch_size_t size)
+{
+
+	memset(buf, 0, size);
+	if (strchr(dbname, '/')) {
+		strncpy(buf, dbname, size);
+	} else {
+		snprintf(buf, size, "%s%s%s.db", SWITCH_GLOBAL_dirs.db_dir, SWITCH_PATH_SEPARATOR, dbname);
+	}
+}
+
+
 SWITCH_DECLARE(int) switch_core_db_open(const char *filename, switch_core_db_t **ppDb)
 {
 	return sqlite3_open(filename, ppDb);
@@ -43,12 +57,12 @@
 	return sqlite3_close(db);
 }
 
-SWITCH_DECLARE(const unsigned char *)switch_core_db_column_text(switch_core_db_stmt_t *stmt, int iCol)
+SWITCH_DECLARE(const unsigned char *) switch_core_db_column_text(switch_core_db_stmt_t *stmt, int iCol)
 {
 	return sqlite3_column_text(stmt, iCol);
 }
 
-SWITCH_DECLARE(const char *)switch_core_db_column_name(switch_core_db_stmt_t *stmt, int N)
+SWITCH_DECLARE(const char *) switch_core_db_column_name(switch_core_db_stmt_t *stmt, int N)
 {
 	return sqlite3_column_name(stmt, N);
 }
@@ -58,16 +72,12 @@
 	return sqlite3_column_count(pStmt);
 }
 
-SWITCH_DECLARE(const char *)switch_core_db_errmsg(switch_core_db_t *db)
+SWITCH_DECLARE(const char *) switch_core_db_errmsg(switch_core_db_t *db)
 {
 	return sqlite3_errmsg(db);
 }
 
-SWITCH_DECLARE(int) switch_core_db_exec(switch_core_db_t *db,
-										const char *sql,
-										switch_core_db_callback_func_t callback,
-										void *data,
-										char **errmsg)
+SWITCH_DECLARE(int) switch_core_db_exec(switch_core_db_t *db, const char *sql, switch_core_db_callback_func_t callback, void *data, char **errmsg)
 {
 	return sqlite3_exec(db, sql, callback, data, errmsg);
 }
@@ -77,11 +87,7 @@
 	return sqlite3_finalize(pStmt);
 }
 
-SWITCH_DECLARE(int) switch_core_db_prepare(switch_core_db_t *db,
-										   const char *zSql,
-										   int nBytes,
-										   switch_core_db_stmt_t **ppStmt,
-										   const char **pzTail)
+SWITCH_DECLARE(int) switch_core_db_prepare(switch_core_db_t *db, const char *zSql, int nBytes, switch_core_db_stmt_t **ppStmt, const char **pzTail)
 {
 	return sqlite3_prepare(db, zSql, nBytes, ppStmt, pzTail);
 }
@@ -136,16 +142,56 @@
 	sqlite3_free(z);
 }
 
-SWITCH_DECLARE(char *)switch_mprintf(const char *zFormat,...)
+SWITCH_DECLARE(char *) switch_mprintf(const char *zFormat, ...)
 {
-  va_list ap;
-  char *z;
-  va_start(ap, zFormat);
-  z = sqlite3_vmprintf(zFormat, ap);
-  va_end(ap);
-  return z;
+	va_list ap;
+	char *z;
+	va_start(ap, zFormat);
+	z = sqlite3_vmprintf(zFormat, ap);
+	va_end(ap);
+	return z;
+}
+
+SWITCH_DECLARE(switch_core_db_t *) switch_core_db_open_file(char *filename)
+{
+	switch_core_db_t *db;
+	char path[1024];
+
+	db_pick_path(filename, path, sizeof(path));
+	if (switch_core_db_open(path, &db)) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR [%s]\n", switch_core_db_errmsg(db));
+		switch_core_db_close(db);
+		db = NULL;
+	}
+	return db;
 }
 
+
+SWITCH_DECLARE(void) switch_core_db_test_reactive(switch_core_db_t *db, char *test_sql, char *reactive_sql)
+{
+	char *errmsg;
+
+	if (db) {
+		if (test_sql) {
+			switch_core_db_exec(db, test_sql, NULL, NULL, &errmsg);
+
+			if (errmsg) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SQL ERR [%s]\n[%s]\nAuto Generating Table!\n", errmsg, test_sql);
+				switch_core_db_free(errmsg);
+				errmsg = NULL;
+				switch_core_db_exec(db, reactive_sql, NULL, NULL, &errmsg);
+				if (errmsg) {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SQL ERR [%s]\n[%s]\n", errmsg, reactive_sql);
+					switch_core_db_free(errmsg);
+					errmsg = NULL;
+				}
+			}
+		}
+	}
+
+}
+
+
 /* For Emacs:
  * Local Variables:
  * mode:c

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/switch_event.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/switch_event.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/switch_event.c	Fri Mar 30 12:19:18 2007
@@ -44,7 +44,7 @@
 /* static switch_memory_pool_t *APOOL = NULL; */
 /* static switch_memory_pool_t *BPOOL = NULL; */
 static switch_memory_pool_t *THRUNTIME_POOL = NULL;
-static switch_queue_t *EVENT_QUEUE[3] = {0,0,0};
+static switch_queue_t *EVENT_QUEUE[3] = { 0, 0, 0 };
 static int POOL_COUNT_MAX = SWITCH_CORE_QUEUE_LEN;
 
 static switch_hash_t *CUSTOM_HASH = NULL;
@@ -133,6 +133,10 @@
 	"PRIVATE_COMMAND",
 	"HEARTBEAT",
 	"TRAP",
+	"ADD_SCHEDULE",
+	"DEL_SCHEDULE",
+	"EXE_SCHEDULE",
+	"RE_SCHEDULE",
 	"ALL"
 };
 
@@ -176,13 +180,13 @@
 	return match;
 }
 
-static void *SWITCH_THREAD_FUNC switch_event_thread(switch_thread_t *thread, void *obj)
+static void *SWITCH_THREAD_FUNC switch_event_thread(switch_thread_t * thread, void *obj)
 {
 	switch_event_t *out_event = NULL;
 	switch_queue_t *queue = NULL;
-	switch_queue_t *queues[3] = {0,0,0};
+	switch_queue_t *queues[3] = { 0, 0, 0 };
 	void *pop;
-	int i, len[3] = {0,0,0};
+	int i, len[3] = { 0, 0, 0 };
 
 	assert(thread != NULL);
 	assert(obj == NULL);
@@ -192,14 +196,14 @@
 	assert(EVENT_QUEUE_HAVEMORE_MUTEX != NULL);
 	assert(EVENT_QUEUE_CONDITIONAL != NULL);
 	THREAD_RUNNING = 1;
-	
+
 	queues[0] = EVENT_QUEUE[SWITCH_PRIORITY_HIGH];
 	queues[1] = EVENT_QUEUE[SWITCH_PRIORITY_NORMAL];
 	queues[2] = EVENT_QUEUE[SWITCH_PRIORITY_LOW];
 
 	switch_mutex_lock(EVENT_QUEUE_MUTEX);
-	
-	for(;;) {
+
+	for (;;) {
 		int any;
 
 
@@ -208,13 +212,13 @@
 		len[0] = switch_queue_size(EVENT_QUEUE[SWITCH_PRIORITY_HIGH]);
 		any = len[1] + len[2] + len[0];
 
-	
+
 		if (!any) {
 			/* lock on havemore so we are the only ones poking at it while we check it
 			 * see if we saw anything in the queues or have a check again flag
 			 */
 			switch_mutex_lock(EVENT_QUEUE_HAVEMORE_MUTEX);
-			if(!EVENT_QUEUE_HAVEMORE) {
+			if (!EVENT_QUEUE_HAVEMORE) {
 				/* See if we need to quit */
 				if (THREAD_RUNNING != 1) {
 					/* give up our lock */
@@ -243,10 +247,10 @@
 			continue;
 		}
 
-		for(i = 0; i < 3; i++) {
+		for (i = 0; i < 3; i++) {
 			if (len[i]) {
 				queue = queues[i];
-				while(queue) {
+				while (queue) {
 					if (switch_queue_trypop(queue, &pop) == SWITCH_STATUS_SUCCESS) {
 						out_event = pop;
 						switch_event_deliver(&out_event);
@@ -307,14 +311,14 @@
 	switch_event_types_t x;
 	assert(BLOCK != NULL);
 	assert(RUNTIME_POOL != NULL);
-	
+
 	for (x = 0; x <= SWITCH_EVENT_ALL; x++) {
 		if (!strcasecmp(name, EVENT_NAMES[x])) {
 			*type = x;
 			return SWITCH_STATUS_SUCCESS;
 		}
 	}
-	
+
 	return SWITCH_STATUS_FALSE;
 
 }
@@ -356,7 +360,7 @@
 		 */
 		switch_mutex_lock(EVENT_QUEUE_HAVEMORE_MUTEX);
 		/* see if the event thread is sitting */
-		if(switch_mutex_trylock(EVENT_QUEUE_MUTEX) == SWITCH_STATUS_SUCCESS) {
+		if (switch_mutex_trylock(EVENT_QUEUE_MUTEX) == SWITCH_STATUS_SUCCESS) {
 			/* we don't need havemore anymore, the thread was sitting already */
 			switch_mutex_unlock(EVENT_QUEUE_HAVEMORE_MUTEX);
 
@@ -365,7 +369,7 @@
 
 			/* give up our lock */
 			switch_mutex_unlock(EVENT_QUEUE_MUTEX);
-		} else { 
+		} else {
 			/* it wasn't waiting which means we might have updated a queue it already looked at
 			 * set a flag so it knows to read the queues again
 			 */
@@ -402,11 +406,11 @@
 		return SWITCH_STATUS_MEMERR;
 	}
 	/*
-	if (switch_core_new_memory_pool(&BPOOL) != SWITCH_STATUS_SUCCESS) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Could not allocate memory pool\n");
-		return SWITCH_STATUS_MEMERR;
-	}
-	*/
+	   if (switch_core_new_memory_pool(&BPOOL) != SWITCH_STATUS_SUCCESS) {
+	   switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Could not allocate memory pool\n");
+	   return SWITCH_STATUS_MEMERR;
+	   }
+	 */
 	/* THRUNTIME_POOL = APOOL; */
 	switch_queue_create(&EVENT_QUEUE[0], POOL_COUNT_MAX + 10, THRUNTIME_POOL);
 	switch_queue_create(&EVENT_QUEUE[1], POOL_COUNT_MAX + 10, THRUNTIME_POOL);
@@ -429,9 +433,7 @@
 
 }
 
-SWITCH_DECLARE(switch_status_t) switch_event_create_subclass(switch_event_t **event,
-														   switch_event_types_t event_id,
-														   const char *subclass_name)
+SWITCH_DECLARE(switch_status_t) switch_event_create_subclass(switch_event_t **event, switch_event_types_t event_id, const char *subclass_name)
 {
 
 	if (event_id != SWITCH_EVENT_CUSTOM && subclass_name) {
@@ -482,8 +484,7 @@
 	return NULL;
 }
 
-SWITCH_DECLARE(switch_status_t) switch_event_add_header(switch_event_t *event, switch_stack_t stack, const char *header_name,
-													  const char *fmt, ...)
+SWITCH_DECLARE(switch_status_t) switch_event_add_header(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *fmt, ...)
 {
 	int ret = 0;
 	char data[2048];
@@ -613,8 +614,8 @@
 	switch_event_header_t *hp;
 	switch_size_t llen = 0, dlen = 0, blocksize = 512, encode_len = 1536, new_len = 0;
 	char *buf;
-    char *encode_buf = NULL; /* used for url encoding of variables to make sure unsafe things stay out of the serialzed copy */
-	
+	char *encode_buf = NULL;	/* used for url encoding of variables to make sure unsafe things stay out of the serialzed copy */
+
 	*str = NULL;
 
 	dlen = blocksize * 2;
@@ -623,55 +624,55 @@
 		return SWITCH_STATUS_MEMERR;
 	}
 
-    /* go ahead and give ourselves some space to work with, should save a few reallocs */
-    if(!(encode_buf = malloc(encode_len))) {
-        return SWITCH_STATUS_MEMERR;
-    }
+	/* go ahead and give ourselves some space to work with, should save a few reallocs */
+	if (!(encode_buf = malloc(encode_len))) {
+		return SWITCH_STATUS_MEMERR;
+	}
 
-    /* switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "hit serialze!.\n"); */
+	/* switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "hit serialze!.\n"); */
 	for (hp = event->headers; hp; hp = hp->next) {
-        /*
-         * grab enough memory to store 3x the string (url encode takes one char and turns it into %XX)
-         * so we could end up with a string that is 3 times the original's length, unlikely but rather
-         * be safe than destroy the string, also add one for the null.  And try to be smart about using 
-         * the memory, allocate and only reallocate if we need more.  This avoids an alloc, free CPU
-         * destroying loop.
-         */
-
-        new_len = (strlen(hp->value) * 3) + 1;
-
-        if(encode_len < new_len) {
-            char* tmp;
-	        /* switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Allocing %d was %d.\n", ((strlen(hp->value) * 3) + 1), encode_len); */
-            /* we can use realloc for initial alloc as well, if encode_buf is zero it treats it as a malloc */
-
-            /* keep track of the size of our allocation */
-            encode_len = new_len;
-            
-            if(!(tmp = realloc(encode_buf, encode_len))) {
-                /* oh boy, ram's gone, give back what little we grabbed and bail */
-                switch_safe_free(buf);
-                switch_safe_free(encode_buf);
-                return SWITCH_STATUS_MEMERR;
-            }
-            
-            encode_buf = tmp;
-        }
+		/*
+		 * grab enough memory to store 3x the string (url encode takes one char and turns it into %XX)
+		 * so we could end up with a string that is 3 times the original's length, unlikely but rather
+		 * be safe than destroy the string, also add one for the null.  And try to be smart about using 
+		 * the memory, allocate and only reallocate if we need more.  This avoids an alloc, free CPU
+		 * destroying loop.
+		 */
+
+		new_len = (strlen(hp->value) * 3) + 1;
+
+		if (encode_len < new_len) {
+			char *tmp;
+			/* switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Allocing %d was %d.\n", ((strlen(hp->value) * 3) + 1), encode_len); */
+			/* we can use realloc for initial alloc as well, if encode_buf is zero it treats it as a malloc */
 
-        /* handle any bad things in the string like newlines : etc that screw up the serialized format */
-        switch_url_encode(hp->value, encode_buf, encode_len - 1);
+			/* keep track of the size of our allocation */
+			encode_len = new_len;
+
+			if (!(tmp = realloc(encode_buf, encode_len))) {
+				/* oh boy, ram's gone, give back what little we grabbed and bail */
+				switch_safe_free(buf);
+				switch_safe_free(encode_buf);
+				return SWITCH_STATUS_MEMERR;
+			}
+
+			encode_buf = tmp;
+		}
+
+		/* handle any bad things in the string like newlines : etc that screw up the serialized format */
+		switch_url_encode(hp->value, encode_buf, encode_len - 1);
 
 		llen = strlen(hp->name) + strlen(encode_buf) + 8;
-		
+
 		if ((len + llen) > dlen) {
 			char *m;
 			dlen += (blocksize + (len + llen));
 			if ((m = realloc(buf, dlen))) {
 				buf = m;
 			} else {
-                /* we seem to be out of memory trying to resize the serialize string, give back what we already have and give up */
+				/* we seem to be out of memory trying to resize the serialize string, give back what we already have and give up */
 				switch_safe_free(buf);
-                switch_safe_free(encode_buf);
+				switch_safe_free(encode_buf);
 				return SWITCH_STATUS_MEMERR;
 			}
 		}
@@ -681,8 +682,8 @@
 
 	}
 
-    /* we are done with the memory we used for encoding, give it back */
-    switch_safe_free(encode_buf);
+	/* we are done with the memory we used for encoding, give it back */
+	switch_safe_free(encode_buf);
 
 	if (event->body) {
 		int blen = (int) strlen(event->body);
@@ -693,7 +694,7 @@
 		} else {
 			llen += 5;
 		}
-		
+
 		if ((len + llen) > dlen) {
 			char *m;
 			dlen += (blocksize + (len + llen));
@@ -704,7 +705,7 @@
 				return SWITCH_STATUS_MEMERR;
 			}
 		}
-		
+
 		if (blen) {
 			snprintf(buf + len, dlen - len, "Content-Length: %d\n\n%s", blen, event->body);
 		} else {
@@ -715,7 +716,7 @@
 	}
 
 	*str = buf;
-	
+
 	return SWITCH_STATUS_SUCCESS;
 }
 
@@ -726,13 +727,13 @@
 
 	if ((header = switch_xml_add_child_d(xml, "header", offset))) {
 		switch_xml_set_attr_d(header, "name", name);
-		switch_xml_set_attr_d(header, "value", value);	
+		switch_xml_set_attr_d(header, "value", value);
 	}
 
 	return header;
 }
 
-SWITCH_DECLARE(switch_xml_t) switch_event_xmlize(switch_event_t *event, const char *fmt, ...)
+SWITCH_DECLARE(switch_xml_t) switch_event_xmlize(switch_event_t *event, const char *fmt,...)
 {
 	switch_event_header_t *hp;
 	char *data = NULL, *body = NULL;
@@ -759,7 +760,7 @@
 		}
 	}
 
-	
+
 	for (hp = event->headers; hp; hp = hp->next) {
 		add_xml_header(xml, hp->name, hp->value, off++);
 	}
@@ -783,7 +784,7 @@
 			}
 		}
 	}
-	
+
 	if (data) {
 		free(data);
 	}
@@ -792,8 +793,7 @@
 }
 
 
-SWITCH_DECLARE(switch_status_t) switch_event_fire_detailed(char *file, char *func, int line, switch_event_t **event,
-														 void *user_data)
+SWITCH_DECLARE(switch_status_t) switch_event_fire_detailed(char *file, char *func, int line, switch_event_t **event, void *user_data)
 {
 
 	switch_time_exp_t tm;
@@ -840,7 +840,7 @@
 	 */
 	switch_mutex_lock(EVENT_QUEUE_HAVEMORE_MUTEX);
 	/* see if the event thread is sitting */
-	if(switch_mutex_trylock(EVENT_QUEUE_MUTEX) == SWITCH_STATUS_SUCCESS) {
+	if (switch_mutex_trylock(EVENT_QUEUE_MUTEX) == SWITCH_STATUS_SUCCESS) {
 		/* we don't need havemore anymore, the thread was sitting already */
 		switch_mutex_unlock(EVENT_QUEUE_HAVEMORE_MUTEX);
 
@@ -849,7 +849,7 @@
 
 		/* give up our lock */
 		switch_mutex_unlock(EVENT_QUEUE_MUTEX);
-	} else { 
+	} else {
 		/* it wasn't waiting which means we might have updated a queue it already looked at
 		 * set a flag so it knows to read the queues again
 		 */
@@ -858,15 +858,15 @@
 		/* variable updated, give up the mutex */
 		switch_mutex_unlock(EVENT_QUEUE_HAVEMORE_MUTEX);
 	}
-		
+
 
 	*event = NULL;
 
 	return SWITCH_STATUS_SUCCESS;
 }
 
-SWITCH_DECLARE(switch_status_t) switch_event_bind(char *id, switch_event_types_t event, char *subclass_name,
-												switch_event_callback_t callback, void *user_data)
+SWITCH_DECLARE(switch_status_t) switch_event_bind(char *id, switch_event_types_t event, char *subclass_name, switch_event_callback_t callback,
+												  void *user_data)
 {
 	switch_event_node_t *event_node;
 	switch_event_subclass_t *subclass = NULL;

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/switch_ivr.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/switch_ivr.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/switch_ivr.c	Fri Mar 30 12:19:18 2007
@@ -34,15 +34,8 @@
  */
 #include <switch.h>
 #include <switch_ivr.h>
-#include <libteletone.h>
 
-static const switch_state_handler_table_t audio_bridge_peer_state_handlers;
-static const switch_state_handler_table_t originate_state_handlers;
 
-typedef enum {
-	IDX_CANCEL = -2,
-	IDX_NADA = -1
-} abort_t;
 
 SWITCH_DECLARE(switch_status_t) switch_ivr_sleep(switch_core_session_t *session, uint32_t ms)
 {
@@ -51,15 +44,15 @@
 	switch_time_t start, now, done = switch_time_now() + (ms * 1000);
 	switch_frame_t *read_frame;
 	int32_t left, elapsed;
-	
+
 	channel = switch_core_session_get_channel(session);
-    assert(channel != NULL);
+	assert(channel != NULL);
 
 	start = switch_time_now();
 
-	for(;;) {
+	for (;;) {
 		now = switch_time_now();
-		elapsed = (int32_t)((now - start) / 1000);
+		elapsed = (int32_t) ((now - start) / 1000);
 		left = ms - elapsed;
 
 		if (!switch_channel_ready(channel)) {
@@ -71,8 +64,8 @@
 			break;
 		}
 
-		if (switch_channel_test_flag(channel, CF_SERVICE) || 
-            (!switch_channel_test_flag(channel, CF_ANSWERED) && !switch_channel_test_flag(channel, CF_EARLY_MEDIA))) {
+		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);
 		} else {
 			status = switch_core_session_read_frame(session, &read_frame, left, 0);
@@ -81,7 +74,7 @@
 			}
 		}
 	}
-	
+
 
 	return status;
 }
@@ -96,50 +89,50 @@
 	unsigned long CMD_EXECUTE = switch_hashfunc_default("execute", &hlen);
 	unsigned long CMD_HANGUP = switch_hashfunc_default("hangup", &hlen);
 	unsigned long CMD_NOMEDIA = switch_hashfunc_default("nomedia", &hlen);
-	
-    assert(channel != NULL);
+
+	assert(channel != NULL);
 	assert(event != NULL);
 
 	if (switch_strlen_zero(cmd)) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Command!\n");
-        return SWITCH_STATUS_FALSE;
-    }
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Command!\n");
+		return SWITCH_STATUS_FALSE;
+	}
 
 	hlen = (switch_size_t) strlen(cmd);
 	cmd_hash = switch_hashfunc_default(cmd, &hlen);
 
 	switch_channel_set_flag(channel, CF_EVENT_PARSE);
-	
 
-    if (cmd_hash == CMD_EXECUTE) {
-        const 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");
-						
-        if (app_name && app_arg) {
-            if ((application_interface = switch_loadable_module_get_application_interface(app_name))) {
-                if (application_interface->application_function) {
-                    application_interface->application_function(session, app_arg);
-                }
-            }
-        }
-    } else if (cmd_hash == CMD_HANGUP) {
-        char *cause_name = switch_event_get_header(event, "hangup-cause");
-        switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING;
-
-        if (cause_name) {
-            cause = switch_channel_str2cause(cause_name);
-        }
-		
-        switch_channel_hangup(channel, cause);
-    } else if (cmd_hash == CMD_NOMEDIA) {
-        char *uuid = switch_event_get_header(event, "nomedia-uuid");
-        switch_ivr_nomedia(uuid, SMF_REBRIDGE);
-    } 
-	
+
+	if (cmd_hash == CMD_EXECUTE) {
+		const 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");
+
+		if (app_name && app_arg) {
+			if ((application_interface = switch_loadable_module_get_application_interface(app_name))) {
+				if (application_interface->application_function) {
+					application_interface->application_function(session, app_arg);
+				}
+			}
+		}
+	} else if (cmd_hash == CMD_HANGUP) {
+		char *cause_name = switch_event_get_header(event, "hangup-cause");
+		switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING;
+
+		if (cause_name) {
+			cause = switch_channel_str2cause(cause_name);
+		}
+
+		switch_channel_hangup(channel, cause);
+	} else if (cmd_hash == CMD_NOMEDIA) {
+		char *uuid = switch_event_get_header(event, "nomedia-uuid");
+		switch_ivr_nomedia(uuid, SMF_REBRIDGE);
+	}
+
 
 	switch_channel_clear_flag(channel, CF_EVENT_PARSE);
-    return SWITCH_STATUS_SUCCESS;
+	return SWITCH_STATUS_SUCCESS;
 
 }
 
@@ -150,9 +143,9 @@
 	switch_frame_t *frame;
 	int stream_id = 0;
 	switch_event_t *event;
-	
+
 	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);	
+	assert(channel != NULL);
 
 	switch_channel_answer(channel);
 
@@ -163,29 +156,29 @@
 
 	switch_channel_set_flag(channel, CF_CONTROLLED);
 	while (switch_channel_ready(channel) && switch_channel_test_flag(channel, CF_CONTROLLED)) {
-        
-        if ((status = switch_core_session_read_frame(session, &frame, -1, stream_id)) == SWITCH_STATUS_SUCCESS) {
-            if (!SWITCH_READ_ACCEPTABLE(status)) {
-                break;
-            }
-            
-            if (switch_core_session_dequeue_private_event(session, &event) == SWITCH_STATUS_SUCCESS) {
-                switch_ivr_parse_event(session, event);
+
+		if ((status = switch_core_session_read_frame(session, &frame, -1, stream_id)) == SWITCH_STATUS_SUCCESS) {
+			if (!SWITCH_READ_ACCEPTABLE(status)) {
+				break;
+			}
+
+			if (switch_core_session_dequeue_private_event(session, &event) == SWITCH_STATUS_SUCCESS) {
+				switch_ivr_parse_event(session, event);
 				switch_channel_event_set_data(switch_core_session_get_channel(session), event);
-                switch_event_fire(&event);
-            }
+				switch_event_fire(&event);
+			}
 
 			if (switch_channel_has_dtmf(channel)) {
-                char dtmf[128];
-                switch_channel_dequeue_dtmf(channel, dtmf, sizeof(dtmf));
+				char dtmf[128];
+				switch_channel_dequeue_dtmf(channel, dtmf, sizeof(dtmf));
 				if (args && args->input_callback) {
 					if ((status = args->input_callback(session, dtmf, SWITCH_INPUT_TYPE_DTMF, args->buf, args->buflen)) != SWITCH_STATUS_SUCCESS) {
 						break;
 					}
 				}
-            }
+			}
 
-            if (switch_core_session_dequeue_event(session, &event) == SWITCH_STATUS_SUCCESS) {
+			if (switch_core_session_dequeue_event(session, &event) == SWITCH_STATUS_SUCCESS) {
 				if (args && args->input_callback) {
 					if ((status = args->input_callback(session, event, SWITCH_INPUT_TYPE_EVENT, args->buf, args->buflen)) != SWITCH_STATUS_SUCCESS) {
 						break;
@@ -194,9 +187,9 @@
 					switch_channel_event_set_data(channel, event);
 					switch_event_fire(&event);
 				}
-            }
-        }
-		
+			}
+		}
+
 	}
 	switch_channel_clear_flag(channel, CF_CONTROLLED);
 
@@ -208,9 +201,7 @@
 	return status;
 }
 
-SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_callback(switch_core_session_t *session,
-                                                                   switch_input_args_t *args,
-																   uint32_t timeout)
+SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_callback(switch_core_session_t *session, switch_input_args_t *args, uint32_t timeout)
 {
 	switch_channel_t *channel;
 	switch_status_t status = SWITCH_STATUS_SUCCESS;
@@ -228,13 +219,13 @@
 		started = switch_time_now();
 	}
 
-	while(switch_channel_ready(channel)) {
+	while (switch_channel_ready(channel)) {
 		switch_frame_t *read_frame;
 		switch_event_t *event;
 		char dtmf[128];
 
 		if (timeout) {
-			elapsed = (uint32_t)((switch_time_now() - started) / 1000);
+			elapsed = (uint32_t) ((switch_time_now() - started) / 1000);
 			if (elapsed >= timeout) {
 				break;
 			}
@@ -251,7 +242,7 @@
 		}
 
 		if (switch_core_session_dequeue_event(session, &event) == SWITCH_STATUS_SUCCESS) {
-			status = args->input_callback(session, event, SWITCH_INPUT_TYPE_EVENT, args->buf, args->buflen);			
+			status = args->input_callback(session, event, SWITCH_INPUT_TYPE_EVENT, args->buf, args->buflen);
 			switch_event_destroy(&event);
 		}
 
@@ -277,12 +268,9 @@
 SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_session_t *session,
 																char *buf,
 																uint32_t buflen,
-																uint32_t maxdigits,
-																const char *terminators,
-																char *terminator,
-																uint32_t timeout)
+																uint32_t maxdigits, const char *terminators, char *terminator, uint32_t timeout)
 {
-	uint32_t i = 0, x =  (uint32_t) strlen(buf);
+	uint32_t i = 0, x = (uint32_t) strlen(buf);
 	switch_channel_t *channel;
 	switch_status_t status = SWITCH_STATUS_FALSE;
 	switch_time_t started = 0;
@@ -295,7 +283,7 @@
 		*terminator = '\0';
 
 	if (!switch_strlen_zero(terminators)) {
-		for (i = 0 ; i < x; i++) {
+		for (i = 0; i < x; i++) {
 			if (strchr(terminators, buf[i]) && terminator != NULL) {
 				*terminator = buf[i];
 				return SWITCH_STATUS_SUCCESS;
@@ -307,27 +295,27 @@
 		started = switch_time_now();
 	}
 
-	while(switch_channel_ready(channel)) {
+	while (switch_channel_ready(channel)) {
 		switch_frame_t *read_frame;
 		switch_event_t *event;
 
 		if (timeout) {
-			elapsed = (uint32_t)((switch_time_now() - started) / 1000);
+			elapsed = (uint32_t) ((switch_time_now() - started) / 1000);
 			if (elapsed >= timeout) {
 				break;
 			}
 		}
-		
+
 		if (switch_core_session_dequeue_private_event(session, &event) == SWITCH_STATUS_SUCCESS) {
 			switch_ivr_parse_event(session, event);
 			switch_event_destroy(&event);
 		}
-		
+
 		if (switch_channel_has_dtmf(channel)) {
 			char dtmf[128];
 
 			switch_channel_dequeue_dtmf(channel, dtmf, maxdigits);
-			for(i =0 ; i < (uint32_t) strlen(dtmf); i++) {
+			for (i = 0; i < (uint32_t) strlen(dtmf); i++) {
 
 				if (!switch_strlen_zero(terminators) && strchr(terminators, dtmf[i]) && terminator != NULL) {
 					*terminator = dtmf[i];
@@ -356,3610 +344,219 @@
 }
 
 
-
-SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *session, 
-                                                       switch_file_handle_t *fh,
-                                                       char *file,
-                                                       switch_input_args_t *args,
-                                                       uint32_t limit)
+SWITCH_DECLARE(switch_status_t) switch_ivr_hold(switch_core_session_t *session)
 {
+	switch_core_session_message_t msg = { 0 };
 	switch_channel_t *channel;
-    char dtmf[128];
-	switch_file_handle_t lfh = {0};
-	switch_frame_t *read_frame;
-	switch_codec_t codec, *read_codec;
-	char *codec_name;
-	switch_status_t status = SWITCH_STATUS_SUCCESS;
-	char *p;
-	const char *vval;
-    time_t start = 0;
-	uint32_t org_silence_hits = 0;
 
-	if (!fh) {
-		fh = &lfh;
-	}
+	msg.message_id = SWITCH_MESSAGE_INDICATE_HOLD;
+	msg.from = __FILE__;
 
 	channel = switch_core_session_get_channel(session);
-    assert(channel != NULL);
-
-	read_codec = switch_core_session_get_read_codec(session);
-	assert(read_codec != NULL);
+	assert(channel != NULL);
 
-	fh->channels = read_codec->implementation->number_of_channels;
-	fh->samplerate = read_codec->implementation->samples_per_second;
+	switch_channel_set_flag(channel, CF_HOLD);
+	switch_channel_set_flag(channel, CF_SUSPEND);
 
+	switch_core_session_receive_message(session, &msg);
 
-	if (switch_core_file_open(fh,
-							  file,
-							  read_codec->implementation->number_of_channels,
-							  read_codec->implementation->samples_per_second,
-							  SWITCH_FILE_FLAG_WRITE | SWITCH_FILE_DATA_SHORT,
-							  switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
-		switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-		switch_core_session_reset(session);
-		return SWITCH_STATUS_GENERR;
-	}
+	return SWITCH_STATUS_SUCCESS;
+}
 
-	switch_channel_answer(channel);
+SWITCH_DECLARE(switch_status_t) switch_ivr_hold_uuid(char *uuid)
+{
+	switch_core_session_t *session;
 
-	if ((p = switch_channel_get_variable(channel, "RECORD_TITLE"))) {
-		vval = (const char *) switch_core_session_strdup(session, p);
-		switch_core_file_set_string(fh, SWITCH_AUDIO_COL_STR_TITLE, vval);
-		switch_channel_set_variable(channel, "RECORD_TITLE", NULL);
-	}
-
-	if ((p = switch_channel_get_variable(channel, "RECORD_COPYRIGHT"))) {
-		vval = (const char *) switch_core_session_strdup(session, p);
-		switch_core_file_set_string(fh, SWITCH_AUDIO_COL_STR_COPYRIGHT, vval);
-		switch_channel_set_variable(channel, "RECORD_COPYRIGHT", NULL);
-	}
-
-	if ((p = switch_channel_get_variable(channel, "RECORD_SOFTWARE"))) {
-		vval = (const char *) switch_core_session_strdup(session, p);
-		switch_core_file_set_string(fh, SWITCH_AUDIO_COL_STR_SOFTWARE, vval);
-		switch_channel_set_variable(channel, "RECORD_SOFTWARE", NULL);
-	}
-
-	if ((p = switch_channel_get_variable(channel, "RECORD_ARTIST"))) {
-		vval = (const char *) switch_core_session_strdup(session, p);
-		switch_core_file_set_string(fh, SWITCH_AUDIO_COL_STR_ARTIST, vval);
-		switch_channel_set_variable(channel, "RECORD_ARTIST", NULL);
-	}
-
-	if ((p = switch_channel_get_variable(channel, "RECORD_COMMENT"))) {
-		vval = (const char *) switch_core_session_strdup(session, p);
-		switch_core_file_set_string(fh, SWITCH_AUDIO_COL_STR_COMMENT, vval);
-		switch_channel_set_variable(channel, "RECORD_COMMENT", NULL);
-	}
-
-	if ((p = switch_channel_get_variable(channel, "RECORD_DATE"))) {
-		vval = (const char *) switch_core_session_strdup(session, p);
-		switch_core_file_set_string(fh, SWITCH_AUDIO_COL_STR_DATE, vval);
-		switch_channel_set_variable(channel, "RECORD_DATE", NULL);
-	}
-	
-	codec_name = "L16";
-	if (switch_core_codec_init(&codec,
-							   codec_name,
-							   NULL,
-							   read_codec->implementation->samples_per_second,
-							   read_codec->implementation->microseconds_per_frame / 1000,
-							   read_codec->implementation->number_of_channels,
-							   SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
-							   NULL, switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activated\n");
-		switch_core_session_set_read_codec(session, &codec);		
-	} else {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Raw Codec Activation Failed %s@%uhz %u channels %dms\n",
-							  codec_name, fh->samplerate, fh->channels, read_codec->implementation->microseconds_per_frame / 1000);
-		switch_core_file_close(fh);
-		switch_core_session_reset(session);
-		return SWITCH_STATUS_GENERR;
-	}
-	
-    if (limit) {
-        start = time(NULL);
-    }
-
-    if (fh->thresh) {
-        if (fh->silence_hits) {
-			fh->silence_hits = fh->samplerate * fh->silence_hits / read_codec->implementation->samples_per_frame;
-		} else {
-            fh->silence_hits = fh->samplerate * 3 / read_codec->implementation->samples_per_frame;
-        }
-		org_silence_hits = fh->silence_hits;
+	if ((session = switch_core_session_locate(uuid))) {
+		switch_ivr_hold(session);
+		switch_core_session_rwunlock(session);
 	}
 
-	while(switch_channel_ready(channel)) {
-		switch_size_t len;
-		switch_event_t *event;
-
-        if (switch_core_session_dequeue_private_event(session, &event) == SWITCH_STATUS_SUCCESS) {
-			switch_ivr_parse_event(session, event);
-			switch_event_destroy(&event);
-		}
+	return SWITCH_STATUS_SUCCESS;
+}
 
-        if (start && (time(NULL) - start) > limit) {
-            break;
-        }
-
-		if (args && (args->input_callback || args->buf || args->buflen)) {
-			/*
-			  dtmf handler function you can hook up to be executed when a digit is dialed during playback 
-			  if you return anything but SWITCH_STATUS_SUCCESS the playback will stop.
-			*/
-			if (switch_channel_has_dtmf(channel)) {
-				if (!args->input_callback && !args->buf) {
-					status = SWITCH_STATUS_BREAK;
-					break;
-				}
-				switch_channel_dequeue_dtmf(channel, dtmf, sizeof(dtmf));
-				if (args->input_callback) {
-					status = args->input_callback(session, dtmf, SWITCH_INPUT_TYPE_DTMF, args->buf, args->buflen);
-				} else {
-					switch_copy_string((char *)args->buf, dtmf, args->buflen);
-					status = SWITCH_STATUS_BREAK;
-				}
-			}
+SWITCH_DECLARE(switch_status_t) switch_ivr_unhold(switch_core_session_t *session)
+{
+	switch_core_session_message_t msg = { 0 };
+	switch_channel_t *channel;
 
-			if (args->input_callback) {
-				if (switch_core_session_dequeue_event(session, &event) == SWITCH_STATUS_SUCCESS) {
-					status = args->input_callback(session, event, SWITCH_INPUT_TYPE_EVENT, args->buf, args->buflen);			
-					switch_event_destroy(&event);
-				}
-			}
+	msg.message_id = SWITCH_MESSAGE_INDICATE_UNHOLD;
+	msg.from = __FILE__;
 
+	channel = switch_core_session_get_channel(session);
+	assert(channel != NULL);
 
-			if (status != SWITCH_STATUS_SUCCESS) {
-				break;
-			}
-		}
-		
-		status = switch_core_session_read_frame(session, &read_frame, -1, 0);
-		if (!SWITCH_READ_ACCEPTABLE(status)) {
-			break;
-		}
+	switch_channel_clear_flag(channel, CF_HOLD);
+	switch_channel_clear_flag(channel, CF_SUSPEND);
 
-        if (fh->thresh) {
-            int16_t *fdata = (int16_t *) read_frame->data;
-            uint32_t samples = read_frame->datalen / sizeof(*fdata);
-            uint32_t score, count = 0, j = 0;
-            double energy = 0;
-
-            for (count = 0; count < samples; count++) {
-                energy += abs(fdata[j]);
-                j += read_codec->implementation->number_of_channels;
-            }
-		
-            score = (uint32_t)(energy / samples);
-            if (score < fh->thresh) {
-                if (!--fh->silence_hits) {
-                    break;
-                }
-			} else {
-				fh->silence_hits = org_silence_hits;
-			}
-        }
-		
-		if (!switch_test_flag(fh, SWITCH_FILE_PAUSE)) {
-			len = (switch_size_t) read_frame->datalen / 2;
-			if (switch_core_file_write(fh, read_frame->data, &len) != SWITCH_STATUS_SUCCESS) {
-				break;
-			}
-		}
-	}
+	switch_core_session_receive_message(session, &msg);
 
-	switch_core_session_set_read_codec(session, read_codec);
-	switch_core_file_close(fh);
-	switch_core_session_reset(session);
-	return status;
+	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_bool_t record_callback(switch_media_bug_t *bug, void *user_data, switch_abc_type_t type)
+SWITCH_DECLARE(switch_status_t) switch_ivr_unhold_uuid(char *uuid)
 {
-	switch_file_handle_t *fh = (switch_file_handle_t *) user_data;
-	uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE];
-	switch_frame_t frame = {0};
-
-	frame.data = data;
-	frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE;
-	
-	switch(type) {
-	case SWITCH_ABC_TYPE_INIT:
-		break;
-	case SWITCH_ABC_TYPE_CLOSE:
-        if (fh) {
-            switch_core_file_close(fh);
-        }
-        break;
-	case SWITCH_ABC_TYPE_READ:
-		if (fh) {
-			switch_size_t len;
-
-			if (switch_core_media_bug_read(bug, &frame) == SWITCH_STATUS_SUCCESS) {
-				len = (switch_size_t) frame.datalen / 2;
-				switch_core_file_write(fh, frame.data, &len);
-			}
-		}
-		break;
-	case SWITCH_ABC_TYPE_WRITE:
-    default:
-		break;
+	switch_core_session_t *session;
+
+	if ((session = switch_core_session_locate(uuid))) {
+		switch_ivr_unhold(session);
+		switch_core_session_rwunlock(session);
 	}
 
-	return SWITCH_TRUE;
+	return SWITCH_STATUS_SUCCESS;
 }
 
-SWITCH_DECLARE(switch_status_t) switch_ivr_stop_record_session(switch_core_session_t *session, char *file) 
+SWITCH_DECLARE(switch_status_t) switch_ivr_media(char *uuid, switch_media_flag_t flags)
 {
-	switch_media_bug_t *bug;
-	switch_channel_t *channel = switch_core_session_get_channel(session);
+	char *other_uuid = NULL;
+	switch_channel_t *channel, *other_channel = NULL;
+	switch_core_session_t *session, *other_session;
+	switch_core_session_message_t msg = { 0 };
+	switch_status_t status = SWITCH_STATUS_GENERR;
+	uint8_t swap = 0;
 
-	assert(channel != NULL);
-	if ((bug = switch_channel_get_private(channel, file))) {
-		switch_channel_set_private(channel, file, NULL);
-		switch_core_media_bug_remove(session, &bug);
-		return SWITCH_STATUS_SUCCESS;
-	}
-	
-	return SWITCH_STATUS_FALSE;
-	
-}
+	msg.message_id = SWITCH_MESSAGE_INDICATE_MEDIA;
+	msg.from = __FILE__;
 
-SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t *session, char *file,  switch_file_handle_t *fh)
-{
-	switch_channel_t *channel;
-	switch_codec_t *read_codec;
-	char *p;
-	const char *vval;
-	switch_media_bug_t *bug;
-	switch_status_t status;
-
-	if (!fh) {
-		if (!(fh = switch_core_session_alloc(session, sizeof(*fh)))) {
-			return SWITCH_STATUS_MEMERR;
+	if ((session = switch_core_session_locate(uuid))) {
+		channel = switch_core_session_get_channel(session);
+		assert(channel != NULL);
+		if ((flags & SMF_REBRIDGE) && !switch_channel_test_flag(channel, CF_ORIGINATOR)) {
+			swap = 1;
 		}
-	}
-
-	channel = switch_core_session_get_channel(session);
-    assert(channel != NULL);
-
-    read_codec = switch_core_session_get_read_codec(session);
-    assert(read_codec != NULL);
 
-    fh->channels = read_codec->implementation->number_of_channels;
-    fh->samplerate = read_codec->implementation->samples_per_second;
-
-
-    if (switch_core_file_open(fh,
-                              file,
-							  read_codec->implementation->number_of_channels,
-                              read_codec->implementation->samples_per_second,
-                              SWITCH_FILE_FLAG_WRITE | SWITCH_FILE_DATA_SHORT,
-                              switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
-        switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-        switch_core_session_reset(session);
-        return SWITCH_STATUS_GENERR;
-    }
-
-    switch_channel_answer(channel);
-
-	if ((p = switch_channel_get_variable(channel, "RECORD_TITLE"))) {
-		vval = (const char *) switch_core_session_strdup(session, p);
-		switch_core_file_set_string(fh, SWITCH_AUDIO_COL_STR_TITLE, vval);
-		switch_channel_set_variable(channel, "RECORD_TITLE", NULL);
-	}
-
-	if ((p = switch_channel_get_variable(channel, "RECORD_COPYRIGHT"))) {
-		vval = (const char *) switch_core_session_strdup(session, p);
-		switch_core_file_set_string(fh, SWITCH_AUDIO_COL_STR_COPYRIGHT, vval);
-		switch_channel_set_variable(channel, "RECORD_COPYRIGHT", NULL);
-	}
+		if (switch_channel_test_flag(channel, CF_NOMEDIA)) {
+			status = SWITCH_STATUS_SUCCESS;
+			switch_channel_clear_flag(channel, CF_NOMEDIA);
+			switch_core_session_receive_message(session, &msg);
 
-	if ((p = switch_channel_get_variable(channel, "RECORD_SOFTWARE"))) {
-		vval = (const char *) switch_core_session_strdup(session, p);
-		switch_core_file_set_string(fh, SWITCH_AUDIO_COL_STR_SOFTWARE, vval);
-		switch_channel_set_variable(channel, "RECORD_SOFTWARE", NULL);
-	}
+			if ((flags & SMF_REBRIDGE)
+				&& (other_uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BRIDGE_VARIABLE))
+				&& (other_session = switch_core_session_locate(other_uuid))) {
+				other_channel = switch_core_session_get_channel(other_session);
+				assert(other_channel != NULL);
+				switch_core_session_receive_message(other_session, &msg);
+				switch_channel_clear_state_handler(other_channel, NULL);
+				switch_core_session_rwunlock(other_session);
+			}
+			if (other_channel) {
+				switch_channel_clear_state_handler(channel, NULL);
+			}
+		}
 
-	if ((p = switch_channel_get_variable(channel, "RECORD_ARTIST"))) {
-		vval = (const char *) switch_core_session_strdup(session, p);
-		switch_core_file_set_string(fh, SWITCH_AUDIO_COL_STR_ARTIST, vval);
-		switch_channel_set_variable(channel, "RECORD_ARTIST", NULL);
-	}
+		switch_core_session_rwunlock(session);
 
-	if ((p = switch_channel_get_variable(channel, "RECORD_COMMENT"))) {
-		vval = (const char *) switch_core_session_strdup(session, p);
-		switch_core_file_set_string(fh, SWITCH_AUDIO_COL_STR_COMMENT, vval);
-		switch_channel_set_variable(channel, "RECORD_COMMENT", NULL);
+		if (other_channel) {
+			if (swap) {
+				switch_ivr_uuid_bridge(other_uuid, uuid);
+			} else {
+				switch_ivr_uuid_bridge(uuid, other_uuid);
+			}
+		}
 	}
 
-	if ((p = switch_channel_get_variable(channel, "RECORD_DATE"))) {
-		vval = (const char *) switch_core_session_strdup(session, p);
-		switch_core_file_set_string(fh, SWITCH_AUDIO_COL_STR_DATE, vval);
-		switch_channel_set_variable(channel, "RECORD_DATE", NULL);
-	}
+	return status;
+}
 
-	
 
-	if ((status = switch_core_media_bug_add(session,
-											record_callback,
-											fh,
-											SMBF_BOTH,
-											&bug)) != SWITCH_STATUS_SUCCESS) {
-		switch_core_file_close(fh);
-		return status;
-	}
+SWITCH_DECLARE(switch_status_t) switch_ivr_nomedia(char *uuid, switch_media_flag_t flags)
+{
+	char *other_uuid;
+	switch_channel_t *channel, *other_channel = NULL;
+	switch_core_session_t *session, *other_session = NULL;
+	switch_core_session_message_t msg = { 0 };
+	switch_status_t status = SWITCH_STATUS_GENERR;
+	uint8_t swap = 0;
 
-	switch_channel_set_private(channel, file, bug);
-	
-	return SWITCH_STATUS_SUCCESS;
-}
+	msg.message_id = SWITCH_MESSAGE_INDICATE_NOMEDIA;
+	msg.from = __FILE__;
 
-typedef struct {
-	switch_core_session_t *session;
-	teletone_dtmf_detect_state_t dtmf_detect;
-} switch_inband_dtmf_t;
+	if ((session = switch_core_session_locate(uuid))) {
+		status = SWITCH_STATUS_SUCCESS;
+		channel = switch_core_session_get_channel(session);
+		assert(channel != NULL);
 
-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};
-	char digit_str[80];
-	switch_channel_t *channel = switch_core_session_get_channel(pvt->session);
+		if ((flags & SMF_REBRIDGE) && !switch_channel_test_flag(channel, CF_ORIGINATOR)) {
+			swap = 1;
+		}
 
-	assert(channel != NULL);
-	frame.data = data;
-	frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE;
+		if ((flags & SMF_FORCE) || !switch_channel_test_flag(channel, CF_NOMEDIA)) {
+			switch_channel_set_flag(channel, CF_NOMEDIA);
+			switch_core_session_receive_message(session, &msg);
+			if ((flags & SMF_REBRIDGE) && (other_uuid = switch_channel_get_variable(channel, SWITCH_BRIDGE_VARIABLE)) &&
+				(other_session = switch_core_session_locate(other_uuid))) {
+				other_channel = switch_core_session_get_channel(other_session);
+				assert(other_channel != NULL);
+				switch_core_session_receive_message(other_session, &msg);
+				switch_channel_clear_state_handler(other_channel, NULL);
 
-	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);
-				teletone_dtmf_get(&pvt->dtmf_detect, digit_str, sizeof(digit_str));
-				if(digit_str[0]) {
-					switch_channel_queue_dtmf(channel, digit_str);
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "DTMF DETECTED: [%s]\n", digit_str);
+			}
+			if (other_channel) {
+				switch_channel_clear_state_handler(channel, NULL);
+				if (swap) {
+					switch_ivr_signal_bridge(other_session, session);
+				} else {
+					switch_ivr_signal_bridge(session, other_session);
 				}
+				switch_core_session_rwunlock(other_session);
 			}
-			break;
-		case SWITCH_ABC_TYPE_WRITE:
-		default:
-			break;
+		}
+		switch_core_session_rwunlock(session);
 	}
 
-	return SWITCH_TRUE;
+	return status;
 }
 
-SWITCH_DECLARE(switch_status_t) switch_ivr_stop_inband_dtmf_session(switch_core_session_t *session) 
+SWITCH_DECLARE(switch_status_t) switch_ivr_session_transfer(switch_core_session_t *session, char *extension, char *dialplan, char *context)
 {
-	switch_media_bug_t *bug;
-	switch_channel_t *channel = switch_core_session_get_channel(session);
-
-	assert(channel != NULL);
-	if ((bug = switch_channel_get_private(channel, "dtmf"))) {
-		switch_channel_set_private(channel, "dtmf", NULL);
-		switch_core_media_bug_remove(session, &bug);
-		return SWITCH_STATUS_SUCCESS;
-	}
+	switch_channel_t *channel;
+	switch_caller_profile_t *profile, *new_profile;
+	switch_core_session_message_t msg = { 0 };
+	switch_core_session_t *other_session;
+	switch_channel_t *other_channel = NULL;
+	char *uuid = NULL;
 
-	return SWITCH_STATUS_FALSE;
+	assert(session != NULL);
+	assert(extension != NULL);
 
-}
+	switch_core_session_reset(session);
 
-SWITCH_DECLARE(switch_status_t) switch_ivr_inband_dtmf_session(switch_core_session_t *session)
-{
-	switch_channel_t *channel;
-	switch_codec_t *read_codec;
-	switch_media_bug_t *bug;
-	switch_status_t status;
-	switch_inband_dtmf_t *pvt;
 
 	channel = switch_core_session_get_channel(session);
 	assert(channel != NULL);
 
-	read_codec = switch_core_session_get_read_codec(session);
-	assert(read_codec != NULL);
-
-	if (!(pvt = switch_core_session_alloc(session, sizeof(*pvt)))) {
-		return SWITCH_STATUS_MEMERR;
-	}
+	/* clear all state handlers */
+	switch_channel_clear_state_handler(channel, NULL);
 
-	teletone_dtmf_detect_init(&pvt->dtmf_detect, read_codec->implementation->samples_per_second);
+	if ((profile = switch_channel_get_caller_profile(channel))) {
+		new_profile = switch_caller_profile_clone(session, profile);
+		new_profile->destination_number = switch_core_session_strdup(session, extension);
 
-	pvt->session = session;
+		if (!switch_strlen_zero(dialplan)) {
+			new_profile->dialplan = switch_core_session_strdup(session, dialplan);
+		} else {
+			dialplan = new_profile->dialplan;
+		}
 
-	switch_channel_answer(channel);	
+		if (!switch_strlen_zero(context)) {
+			new_profile->context = switch_core_session_strdup(session, context);
+		} else {
+			context = new_profile->context;
+		}
 
-	if ((status = switch_core_media_bug_add(session,
-		inband_dtmf_callback,
-		pvt,
-		SMBF_READ_STREAM,
-		&bug)) != SWITCH_STATUS_SUCCESS) {
-			return status;
-	}
 
-	switch_channel_set_private(channel, "dtmf", bug);
+		switch_channel_set_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE, NULL);
+		if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))
+			&& (other_session = switch_core_session_locate(uuid))) {
+			switch_channel_set_variable(other_channel, SWITCH_SIGNAL_BOND_VARIABLE, NULL);
+			switch_core_session_rwunlock(other_session);
+		}
 
-	return SWITCH_STATUS_SUCCESS;
-}
-
-struct speech_thread_handle {
-	switch_core_session_t *session;
-	switch_asr_handle_t *ah;
-	switch_media_bug_t *bug;
-	switch_mutex_t *mutex;
-	switch_thread_cond_t *cond;
-	switch_memory_pool_t *pool;
-};
-
-static void *SWITCH_THREAD_FUNC speech_thread(switch_thread_t *thread, void *obj)
-{
-	struct speech_thread_handle *sth = (struct speech_thread_handle *) obj;
-	switch_channel_t *channel = switch_core_session_get_channel(sth->session);
-	switch_asr_flag_t flags = SWITCH_ASR_FLAG_NONE;
-	switch_status_t status;
-
-	switch_thread_cond_create(&sth->cond, sth->pool);
-	switch_mutex_init(&sth->mutex, SWITCH_MUTEX_NESTED, sth->pool);
-	
-
-	switch_core_session_read_lock(sth->session);
-	switch_mutex_lock(sth->mutex);
-	
-	while (switch_channel_ready(channel) && !switch_test_flag(sth->ah, SWITCH_ASR_FLAG_CLOSED)) {
-		char *xmlstr = NULL;
-		
-		switch_thread_cond_wait(sth->cond, sth->mutex);
-		if (switch_core_asr_check_results(sth->ah, &flags) == SWITCH_STATUS_SUCCESS) {
-			switch_event_t *event;
-
-			status = switch_core_asr_get_results(sth->ah, &xmlstr, &flags);
-		
-			if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
-				goto done;
-			}
-
-
-			if (switch_event_create(&event, SWITCH_EVENT_DETECTED_SPEECH) == SWITCH_STATUS_SUCCESS) {
-				if (status == SWITCH_STATUS_SUCCESS) {
-					switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Speech-Type", "detected-speech");
-					switch_event_add_body(event, "%s", xmlstr);
-				} else {
-					switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Speech-Type", "begin-speaking");
-				}
-
-				if (switch_test_flag(sth->ah, SWITCH_ASR_FLAG_FIRE_EVENTS)) {
-					switch_event_t *dup;
-
-					if (switch_event_dup(&dup, event) == SWITCH_STATUS_SUCCESS) {
-						switch_event_fire(&dup);
-					}
-						
-				}
-				
-				if (switch_core_session_queue_event(sth->session, &event) != SWITCH_STATUS_SUCCESS) {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Event queue failed!\n");
-					switch_event_add_header(event, SWITCH_STACK_BOTTOM, "delivery-failure", "true");
-					switch_event_fire(&event);
-				}
-			}
-			
-			switch_safe_free(xmlstr);
-		}
-	}
- done:
-	
-	switch_mutex_unlock(sth->mutex);
-	switch_core_session_rwunlock(sth->session);
-
-	return NULL;
-}
-
-static switch_bool_t speech_callback(switch_media_bug_t *bug, void *user_data, switch_abc_type_t type)
-{
-	struct speech_thread_handle *sth = (struct speech_thread_handle *) user_data;
-	uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE];
-	switch_frame_t frame = {0};
-	switch_asr_flag_t flags = SWITCH_ASR_FLAG_NONE;
-
-	frame.data = data;
-	frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE;
-	
-	switch(type) {
-	case SWITCH_ABC_TYPE_INIT: {
-		switch_thread_t *thread;
-		switch_threadattr_t *thd_attr = NULL;
-
-		switch_threadattr_create(&thd_attr, sth->pool);
-		switch_threadattr_detach_set(thd_attr, 1);
-		switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
-        switch_thread_create(&thread, thd_attr, speech_thread, sth, sth->pool);
-		
-	}
-		break;
-	case SWITCH_ABC_TYPE_CLOSE: {
-		switch_core_asr_close(sth->ah, &flags);
-		switch_mutex_lock(sth->mutex);
-		switch_thread_cond_signal(sth->cond);
-		switch_mutex_unlock(sth->mutex);
-    }
-        break;
-	case SWITCH_ABC_TYPE_READ:
-		if (sth->ah) {
-			if (switch_core_media_bug_read(bug, &frame) == SWITCH_STATUS_SUCCESS) {
-				if (switch_core_asr_feed(sth->ah, frame.data, frame.datalen, &flags) != SWITCH_STATUS_SUCCESS) {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error Feeding Data\n");
-					return SWITCH_FALSE;
-				}
-				if (switch_core_asr_check_results(sth->ah, &flags) == SWITCH_STATUS_SUCCESS) {
-					switch_mutex_lock(sth->mutex);
-					switch_thread_cond_signal(sth->cond);
-					switch_mutex_unlock(sth->mutex);
-				}
-			}
-		}
-		break;
-	case SWITCH_ABC_TYPE_WRITE:
-    default:
-		break;
-	}
-
-	return SWITCH_TRUE;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_ivr_stop_detect_speech(switch_core_session_t *session) 
-{
-	switch_channel_t *channel = switch_core_session_get_channel(session);
-	struct speech_thread_handle *sth;
-
-	assert(channel != NULL);
-	if ((sth = switch_channel_get_private(channel, SWITCH_SPEECH_KEY))) {
-		switch_channel_set_private(channel, SWITCH_SPEECH_KEY, NULL);
-		switch_core_media_bug_remove(session, &sth->bug);
-		return SWITCH_STATUS_SUCCESS;
-	}
-	
-	return SWITCH_STATUS_FALSE;
-	
-}
-
-
-
-SWITCH_DECLARE(switch_status_t) switch_ivr_pause_detect_speech(switch_core_session_t *session) 
-{
-	switch_channel_t *channel = switch_core_session_get_channel(session);
-	struct speech_thread_handle *sth;
-
-	assert(channel != NULL);
-	if ((sth = switch_channel_get_private(channel, SWITCH_SPEECH_KEY))) {
-		switch_core_asr_pause(sth->ah);
-		return SWITCH_STATUS_SUCCESS;
-	}
-	
-	return SWITCH_STATUS_FALSE;
-	
-}
-
-SWITCH_DECLARE(switch_status_t) switch_ivr_resume_detect_speech(switch_core_session_t *session) 
-{
-	switch_channel_t *channel = switch_core_session_get_channel(session);
-	struct speech_thread_handle *sth;
-
-	assert(channel != NULL);
-	if ((sth = switch_channel_get_private(channel, SWITCH_SPEECH_KEY))) {
-		switch_core_asr_resume(sth->ah);
-		return SWITCH_STATUS_SUCCESS;
-	}
-	
-	return SWITCH_STATUS_FALSE;
-	
-}
-
-
-SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech_load_grammar(switch_core_session_t *session, char *grammar, char *path) 
-{
-	switch_channel_t *channel = switch_core_session_get_channel(session);
-	switch_asr_flag_t flags = SWITCH_ASR_FLAG_NONE;
-	struct speech_thread_handle *sth;
-
-	assert(channel != NULL);
-	if ((sth = switch_channel_get_private(channel, SWITCH_SPEECH_KEY))) {		
-		if (switch_core_asr_load_grammar(sth->ah, grammar, path) != SWITCH_STATUS_SUCCESS) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error loading Grammar\n");
-			switch_core_asr_close(sth->ah, &flags);
-			switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-			return SWITCH_STATUS_FALSE;
-		}
-
-		return SWITCH_STATUS_SUCCESS;
-	}
-
-	return SWITCH_STATUS_FALSE;
-}
-
-
-SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech_unload_grammar(switch_core_session_t *session, char *grammar) 
-{
-	switch_channel_t *channel = switch_core_session_get_channel(session);
-	switch_asr_flag_t flags = SWITCH_ASR_FLAG_NONE;
-	struct speech_thread_handle *sth;
-
-	assert(channel != NULL);
-	if ((sth = switch_channel_get_private(channel, SWITCH_SPEECH_KEY))) {		
-		if (switch_core_asr_unload_grammar(sth->ah, grammar) != SWITCH_STATUS_SUCCESS) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error unloading Grammar\n");
-			switch_core_asr_close(sth->ah, &flags);
-			switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-			return SWITCH_STATUS_FALSE;
-		}
-
-		return SWITCH_STATUS_SUCCESS;
-	}
-
-	return SWITCH_STATUS_FALSE;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech(switch_core_session_t *session,
-														 char *mod_name,
-														 char *grammar,
-														 char *path,
-														 char *dest,
-														 switch_asr_handle_t *ah)
-{
-	switch_channel_t *channel;
-	switch_codec_t *read_codec;
-	switch_status_t status;
-	switch_asr_flag_t flags = SWITCH_ASR_FLAG_NONE;
-	struct speech_thread_handle *sth;
-	char *val;
-
-	if (!ah) {
-		if (!(ah = switch_core_session_alloc(session, sizeof(*ah)))) {
-			return SWITCH_STATUS_MEMERR;
-		}
-	}
-
-	channel = switch_core_session_get_channel(session);
-    assert(channel != NULL);
-
-    read_codec = switch_core_session_get_read_codec(session);
-    assert(read_codec != NULL);
-
-
-	if ((val = switch_channel_get_variable(channel, "fire_asr_events"))) {
-		switch_set_flag(ah, SWITCH_ASR_FLAG_FIRE_EVENTS);
-	}
-
-	if ((sth = switch_channel_get_private(channel, SWITCH_SPEECH_KEY))) {
-		if (switch_core_asr_load_grammar(sth->ah, grammar, path) != SWITCH_STATUS_SUCCESS) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error loading Grammar\n");
-            switch_core_asr_close(sth->ah, &flags);
-            return SWITCH_STATUS_FALSE;
-        }
-
-        return SWITCH_STATUS_SUCCESS;
-	}
-	
-	if (switch_core_asr_open(ah, 
-							 mod_name,
-							 "L16",
-							 read_codec->implementation->samples_per_second,
-							 dest,
-							 &flags,
-							 switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
-
-		if (switch_core_asr_load_grammar(ah, grammar, path) != SWITCH_STATUS_SUCCESS) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error loading Grammar\n");
-			switch_core_asr_close(ah, &flags);
-			switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-			return SWITCH_STATUS_FALSE;
-		}
-	} else {
-		switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-		return SWITCH_STATUS_FALSE;
-	}
-
-
-	sth = switch_core_session_alloc(session, sizeof(*sth));
-	sth->pool = switch_core_session_get_pool(session);
-	sth->session = session;
-	sth->ah = ah;
-	
-	if ((status = switch_core_media_bug_add(session,
-											speech_callback,
-											sth,
-											SMBF_READ_STREAM,
-											&sth->bug)) != SWITCH_STATUS_SUCCESS) {
-		switch_core_asr_close(ah, &flags);
-		switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-		return status;
-	}
-
-	switch_channel_set_private(channel, SWITCH_SPEECH_KEY, sth);
-	
-	return SWITCH_STATUS_SUCCESS;
-}
-
-#define FILE_STARTSAMPLES 1024 * 32
-#define FILE_BLOCKSIZE 1024 * 8
-#define FILE_BUFSIZE 1024 * 64
-
-SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *session, 
-                                                     switch_file_handle_t *fh,
-                                                     char *file,
-                                                     switch_input_args_t *args)
-{
-	switch_channel_t *channel;
-	int16_t abuf[FILE_STARTSAMPLES];
-	char dtmf[128];
-	uint32_t interval = 0, samples = 0, framelen, sample_start = 0;
-	uint32_t ilen = 0;
-	switch_size_t olen = 0, llen = 0;
-	switch_frame_t write_frame = {0};
-	switch_timer_t timer = {0};
-	switch_core_thread_session_t thread_session;
-	switch_codec_t codec;
-	switch_memory_pool_t *pool = switch_core_session_get_pool(session);
-	char *codec_name;
-	int stream_id = 0;
-	switch_status_t status = SWITCH_STATUS_SUCCESS;
-	switch_file_handle_t lfh;
-	switch_codec_t *read_codec = switch_core_session_get_read_codec(session);
-	const char *p;
-	char *title = "", *copyright = "", *software = "", *artist = "", *comment = "", *date = "";
-	uint8_t asis = 0;
-	char *ext;
-    char *prefix;
-    char *timer_name;
-
-	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
-
-    prefix = switch_channel_get_variable(channel, "sound_prefix");
-    timer_name = switch_channel_get_variable(channel, "timer_name");
-	
-	if (!file) {
-		return SWITCH_STATUS_FALSE;
-	}
-
-	if (!strstr(file, SWITCH_URL_SEPARATOR)) {
-		if (prefix && *file != '/' && *file != '\\' && *(file+1) != ':') {
-			char *new_file;
-			uint32_t len;
-			len = (uint32_t)strlen(file) + (uint32_t)strlen(prefix) + 10;
-			new_file = switch_core_session_alloc(session, len);
-			snprintf(new_file, len, "%s/%s", prefix, file);
-			file = new_file;
-		}
-
-		if ((ext = strrchr(file, '.'))) {
-			ext++;
-		} else {
-			char *new_file;
-			uint32_t len;
-			ext = read_codec->implementation->iananame;
-			len = (uint32_t)strlen(file) + (uint32_t)strlen(ext) + 2;
-			new_file = switch_core_session_alloc(session, len);
-			snprintf(new_file, len, "%s.%s", file, ext);
-			file = new_file;
-			asis = 1;
-		}
-	}
-	
-
-	if (!fh) {
-		fh = &lfh;
-		memset(fh, 0, sizeof(lfh));
-	}
-
-
-	if (fh->samples > 0) {
-		sample_start = fh->samples;
-		fh->samples = 0;
-	}
-	
-	if (switch_core_file_open(fh,
-							  file,
-							  read_codec->implementation->number_of_channels,
-                              read_codec->implementation->samples_per_second,
-							  SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT,
-							  switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
-		switch_core_session_reset(session);
-		return SWITCH_STATUS_NOTFOUND;
-	}
-	if (switch_test_flag(fh, SWITCH_FILE_NATIVE)) {
-		asis = 1;
-	}
-
-
-	write_frame.data = abuf;
-	write_frame.buflen = sizeof(abuf);
-
-    if (sample_start > 0) {
-        uint32_t pos = 0;
-        switch_core_file_seek(fh, &pos, sample_start, SEEK_CUR);
-    }
-	
-	if (switch_core_file_get_string(fh, SWITCH_AUDIO_COL_STR_TITLE, &p) == SWITCH_STATUS_SUCCESS) {
-		title = switch_core_session_strdup(session, p);
-		switch_channel_set_variable(channel, "RECORD_TITLE", p);
-	}
-	
-	if (switch_core_file_get_string(fh, SWITCH_AUDIO_COL_STR_COPYRIGHT, &p) == SWITCH_STATUS_SUCCESS) {
-		copyright = switch_core_session_strdup(session, p);
-		switch_channel_set_variable(channel, "RECORD_COPYRIGHT", p);
-	}
-	
-	if (switch_core_file_get_string(fh, SWITCH_AUDIO_COL_STR_SOFTWARE, &p) == SWITCH_STATUS_SUCCESS) {
-		software = switch_core_session_strdup(session, p);
-		switch_channel_set_variable(channel, "RECORD_SOFTWARE", p);
-	}
-	
-	if (switch_core_file_get_string(fh, SWITCH_AUDIO_COL_STR_ARTIST, &p) == SWITCH_STATUS_SUCCESS) {
-		artist = switch_core_session_strdup(session, p);
-		switch_channel_set_variable(channel, "RECORD_ARTIST", p);
-	}
-	
-	if (switch_core_file_get_string(fh, SWITCH_AUDIO_COL_STR_COMMENT, &p) == SWITCH_STATUS_SUCCESS) {
-		comment = switch_core_session_strdup(session, p);
-		switch_channel_set_variable(channel, "RECORD_COMMENT", p);
-	}
-	
-	if (switch_core_file_get_string(fh, SWITCH_AUDIO_COL_STR_DATE, &p) == SWITCH_STATUS_SUCCESS) {
-		date = switch_core_session_strdup(session, p);
-		switch_channel_set_variable(channel, "RECORD_DATE", p);
-	}
-#if 0
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, 
-					  "OPEN FILE %s %uhz %u channels\n"
-					  "TITLE=%s\n"
-					  "COPYRIGHT=%s\n"
-					  "SOFTWARE=%s\n"
-					  "ARTIST=%s\n"
-					  "COMMENT=%s\n"
-					  "DATE=%s\n", file, fh->samplerate, fh->channels,
-					  title,
-					  copyright,
-					  software,
-					  artist,
-					  comment,
-					  date);
-#endif
-
-	assert(read_codec != NULL);
-	interval = read_codec->implementation->microseconds_per_frame / 1000;
-
-	if (!fh->audio_buffer) {
-		switch_buffer_create_dynamic(&fh->audio_buffer, FILE_BLOCKSIZE, FILE_BUFSIZE, 0);
-		if (!fh->audio_buffer) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "setup buffer failed\n");
-
-			switch_core_file_close(fh);
-			switch_core_session_reset(session);
-			
-			return SWITCH_STATUS_GENERR;
-		}
-	} 
-
-	if (asis) {
-		write_frame.codec = read_codec;
-		samples = read_codec->implementation->samples_per_frame;
-		framelen = read_codec->implementation->encoded_bytes_per_frame;
-	} else {
-		codec_name = "L16";
-
-		if (switch_core_codec_init(&codec,
-								   codec_name,
-								   NULL,
-								   fh->samplerate,
-								   interval,
-								   fh->channels,
-								   SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
-								   NULL, pool) == SWITCH_STATUS_SUCCESS) {
-			switch_log_printf(SWITCH_CHANNEL_LOG,
-							  SWITCH_LOG_DEBUG,
-							  "Codec Activated %s@%uhz %u channels %dms\n",
-							  codec_name,
-							  fh->samplerate,
-							  fh->channels,
-							  interval);
-
-			write_frame.codec = &codec;
-		} else {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activation Failed %s@%uhz %u channels %dms\n",
-							  codec_name, fh->samplerate, fh->channels, interval);
-			switch_core_file_close(fh);
-			switch_core_session_reset(session);
-			return SWITCH_STATUS_GENERR;
-		}
-		samples = codec.implementation->samples_per_frame;
-		framelen = codec.implementation->bytes_per_frame;
-	}
-
-
-	if (timer_name) {
-		uint32_t len;
-
-		len = samples * 2;
-		if (switch_core_timer_init(&timer, timer_name, interval, samples, pool) != SWITCH_STATUS_SUCCESS) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "setup timer failed!\n");
-			switch_core_codec_destroy(&codec);
-			switch_core_file_close(fh);
-			switch_core_session_reset(session);
-			return SWITCH_STATUS_GENERR;
-		}
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "setup timer success %u bytes per %d ms!\n", len, interval);
-	}
-	write_frame.rate = fh->samplerate;
-
-	if (timer_name) {
-		/* start a thread to absorb incoming audio */
-		for (stream_id = 0; stream_id < switch_core_session_get_stream_count(session); stream_id++) {
-			switch_core_service_session(session, &thread_session, stream_id);
-		}
-	}
-
-	ilen = samples;
-
-	while(switch_channel_ready(channel)) {
-		int done = 0;
-		int do_speed = 1;
-		int last_speed = -1;
-		switch_event_t *event;
-	
-
-		if (switch_core_session_dequeue_private_event(session, &event) == SWITCH_STATUS_SUCCESS) {
-			switch_ivr_parse_event(session, event);
-			switch_event_destroy(&event);
-		}
-
-		if (args && (args->input_callback || args->buf || args->buflen)) {
-			/*
-			  dtmf handler function you can hook up to be executed when a digit is dialed during playback 
-			  if you return anything but SWITCH_STATUS_SUCCESS the playback will stop.
-			*/
-			if (switch_channel_has_dtmf(channel)) {
-				if (!args->input_callback && !args->buf) {
-					status = SWITCH_STATUS_BREAK;
-					done = 1;
-					break;
-				}
-				switch_channel_dequeue_dtmf(channel, dtmf, sizeof(dtmf));
-				if (args->input_callback) {
-					status = args->input_callback(session, dtmf, SWITCH_INPUT_TYPE_DTMF, args->buf, args->buflen);
-				} else {
-					switch_copy_string((char *)args->buf, dtmf, args->buflen);
-					status = SWITCH_STATUS_BREAK;
-				}
-			}
-
-			if (args->input_callback) {
-				if (switch_core_session_dequeue_event(session, &event) == SWITCH_STATUS_SUCCESS) {
-					status = args->input_callback(session, event, SWITCH_INPUT_TYPE_EVENT, args->buf, args->buflen);			
-					switch_event_destroy(&event);
-				}
-			}
-			
-			if (status != SWITCH_STATUS_SUCCESS) {
-				done = 1;
-				break;
-			}
-		}
-		
-		if (switch_test_flag(fh, SWITCH_FILE_PAUSE)) {
-			memset(abuf, 0, framelen);
-			olen = ilen;
-            do_speed = 0;
-		} else if (fh->audio_buffer && (switch_buffer_inuse(fh->audio_buffer) > (switch_size_t)(framelen))) {
-			switch_buffer_read(fh->audio_buffer, abuf, framelen);
-			olen = asis ? framelen : ilen;
-			do_speed = 0;
-		} else {
-			olen = sizeof(abuf);
-			if (!asis) {
-				olen /= 2;
-			}
-			switch_core_file_read(fh, abuf, &olen);
-			switch_buffer_write(fh->audio_buffer, abuf, asis ? olen : olen * 2);
-			olen = switch_buffer_read(fh->audio_buffer, abuf, framelen);
-			if (!asis) {
-				olen /= 2;
-			} 
-		}
-
-		if (done || olen <= 0) {
-			break;
-		}
-
-		if (!asis) {
-			if (fh->speed > 2) {
-				fh->speed = 2;
-			} else if (fh->speed < -2) {
-				fh->speed = -2;
-			}
-		}
-		
-		if (!asis && fh->audio_buffer && last_speed > -1 && last_speed != fh->speed) {
-			switch_buffer_zero(fh->audio_buffer);
-		}
-
-		if (switch_test_flag(fh, SWITCH_FILE_SEEK)) {
-			/* file position has changed flush the buffer */
-			switch_buffer_zero(fh->audio_buffer);
-			switch_clear_flag(fh, SWITCH_FILE_SEEK);
-		}
-
-		
-		if (!asis && fh->speed && do_speed) {
-			float factor = 0.25f * abs(fh->speed);
-			switch_size_t newlen, supplement, step;
-			short *bp = write_frame.data;
-			switch_size_t wrote = 0;
-			
-			
-			supplement = (int) (factor * olen);
-			newlen = (fh->speed > 0) ? olen - supplement : olen + supplement;
-			step = (fh->speed > 0) ? (newlen / supplement) : (olen / supplement);
-			
-			while ((wrote + step) < newlen) {
-				switch_buffer_write(fh->audio_buffer, bp, step * 2);
-				wrote += step;
-				bp += step;
-				if (fh->speed > 0) {
-					bp++;
-				} else {
-					float f;
-					short s;
-					f = (float)(*bp + *(bp+1) + *(bp-1));
-					f /= 3;
-					s = (short) f;
-					switch_buffer_write(fh->audio_buffer, &s, 2);
-					wrote++;
-				}
-			}
-			if (wrote < newlen) {
-				switch_size_t r = newlen - wrote;
-				switch_buffer_write(fh->audio_buffer, bp, r*2);
-				wrote += r;
-			}
-			last_speed = fh->speed;
-			continue;
-		}
-		if (olen < llen) {
-            uint8_t *dp = (uint8_t *) write_frame.data;
-            memset(dp + (int)olen, 0, (int)(llen - olen));
-            olen = llen;
-        }
-
-		write_frame.datalen = (uint32_t)(olen * (asis ? 1 : 2));
-		write_frame.samples = (uint32_t)olen;
-
-		llen = olen;
-
-		if (timer_name) {
-			write_frame.timestamp = timer.samplecount;
-		}
-#ifndef WIN32
-#if __BYTE_ORDER == __BIG_ENDIAN
-		if (!asis) {switch_swap_linear(write_frame.data, (int) write_frame.datalen / 2);}
-#endif
-#endif
-		stream_id = 0; 
-
-        status = switch_core_session_write_frame(session, &write_frame, -1, stream_id);
-        
-        if (status == SWITCH_STATUS_MORE_DATA) {
-            status = SWITCH_STATUS_SUCCESS;
-            continue;
-        } else if (status != SWITCH_STATUS_SUCCESS) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Bad Write\n");
-            done = 1;
-            break;
-        }
-
-        if (done) {
-            break;
-        }
-    
-		
-		if (timer_name) {
-			if (switch_core_timer_next(&timer) != SWITCH_STATUS_SUCCESS) {
-				break;
-			}
-		} else { /* time off the channel (if you must) */
-			switch_frame_t *read_frame;
-			switch_status_t status; 
-			while (switch_channel_ready(channel) && switch_channel_test_flag(channel, CF_HOLD)) {
-				switch_yield(10000);
-			}
-			status = switch_core_session_read_frame(session, &read_frame, -1, 0);
-			if (!SWITCH_READ_ACCEPTABLE(status)) {
-				break;
-			}
-		}
-	}
-
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "done playing file\n");
-	switch_core_file_close(fh);
-	switch_buffer_destroy(&fh->audio_buffer);
-	if (!asis) {
-		switch_core_codec_destroy(&codec);
-	}
-	if (timer_name) {
-		/* End the audio absorbing thread */
-		switch_core_thread_session_end(&thread_session);
-		switch_core_timer_destroy(&timer);
-	}
-
-	switch_core_session_reset(session);
-	return status;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_play_and_get_digits(switch_core_session_t *session,
-														   uint32_t min_digits,
-														   uint32_t max_digits,
-														   uint32_t max_tries,
-														   uint32_t timeout,
-														   char* valid_terminators,
-														   char* prompt_audio_file,
-														   char* bad_input_audio_file,
-														   void* digit_buffer,
-														   uint32_t digit_buffer_length,
-														   char* digits_regex) 
-{
-
-	char terminator;			//used to hold terminator recieved from  
-	switch_channel_t *channel;	//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);
-
-	//Get the channel
-	channel = switch_core_session_get_channel(session);
-
-	//Make sure somebody is home
-	assert(channel != NULL);
-
-	//Answer the channel if it hasn't already been answered
-	switch_channel_answer(channel);
-
-	//Start pestering the user for input
-	for(;(switch_channel_get_state(channel) == CS_EXECUTE) && max_tries > 0; max_tries--) {
-        switch_input_args_t args = {0};
-		//make the buffer so fresh and so clean clean
-		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", (char *) digit_buffer);
-
-		//Make sure we made it out alive
-		if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
-			switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
-			break;
-		}
-
-		//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) {
-							switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
-							break;
-						}
-					}
-				}
-			} 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);
-
-		//Make sure we made it out alive
-		if (status != SWITCH_STATUS_SUCCESS) {
-			//Bail
-			switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
-			break;
-		}
-
-		//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 (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) {
-							switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
-							break;
-						}
-					}
-				}
-			} else {
-				//Jobs done
-				return SWITCH_STATUS_SUCCESS;
-			}
-		}
-	}
-
-	//if we got here, we got no digits or lost the channel
-	digit_buffer = "\0";
-	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)
-{
-	switch_channel_t *channel;
-	short abuf[960];
-	char dtmf[128];
-	uint32_t len = 0;
-	switch_size_t ilen = 0;
-	switch_frame_t write_frame = {0};
-	int x;
-	int stream_id = 0;
-	int done = 0;
-	int lead_in_out = 10;
-	switch_status_t status = SWITCH_STATUS_SUCCESS;
-	switch_speech_flag_t flags = SWITCH_SPEECH_FLAG_NONE;
-	uint32_t rate = 0, samples = 0;
-
-	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
-
-	if (!sh) {
-		return SWITCH_STATUS_FALSE;
-	}
-
-	switch_channel_answer(channel);
-
-	write_frame.data = abuf;
-	write_frame.buflen = sizeof(abuf);
-
-	samples = (uint32_t)(sh->rate / 50);
-	len = samples * 2;
-
-	flags = 0;
-	switch_sleep(200000);
-	switch_core_speech_feed_tts(sh, text, &flags);
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Speaking text: %s\n", text);
-
-	write_frame.rate = sh->rate;
-
-	memset(write_frame.data, 0, len);
-	write_frame.datalen = len;
-	write_frame.samples = len / 2;
-	write_frame.codec = codec;
-
-	for( x = 0; !done && x < lead_in_out; x++) {
-		switch_yield(codec->implementation->microseconds_per_frame);
-		if (timer) {
-			write_frame.timestamp = timer->samplecount;
-		}
-        if (switch_core_session_write_frame(session, &write_frame, -1, stream_id) != SWITCH_STATUS_SUCCESS) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Bad Write\n");
-            done = 1;
-            break;
-        }		
-	}
-
-	ilen = len;
-	while(switch_channel_ready(channel)) {
-		switch_event_t *event;
-
-		if (switch_core_session_dequeue_private_event(session, &event) == SWITCH_STATUS_SUCCESS) {
-			switch_ivr_parse_event(session, event);
-			switch_event_destroy(&event);
-		}
-
-		if (args && (args->input_callback || args->buf || args->buflen)) {
-			/*
-			dtmf handler function you can hook up to be executed when a digit is dialed during playback 
-			if you return anything but SWITCH_STATUS_SUCCESS the playback will stop.
-			*/
-			if (switch_channel_has_dtmf(channel)) {
-				if (!args->input_callback && !args->buf) {
-					status = SWITCH_STATUS_BREAK;
-					done = 1;
-					break;
-				}
-				if (args->buf && !strcasecmp(args->buf, "_break_")) {
-					status = SWITCH_STATUS_BREAK;
-				} else {
-					switch_channel_dequeue_dtmf(channel, dtmf, sizeof(dtmf));
-					if (args->input_callback) {
-						status = args->input_callback(session, dtmf, SWITCH_INPUT_TYPE_DTMF, args->buf, args->buflen);
-					} else {
-						switch_copy_string((char *)args->buf, dtmf, args->buflen);
-						status = SWITCH_STATUS_BREAK;
-					}
-				}
-			}
-
-			if (args->input_callback) {
-				if (switch_core_session_dequeue_event(session, &event) == SWITCH_STATUS_SUCCESS) {
-					status = args->input_callback(session, event, SWITCH_INPUT_TYPE_EVENT, args->buf, args->buflen);			
-					switch_event_destroy(&event);
-				}
-			}
-
-			if (status != SWITCH_STATUS_SUCCESS) {
-				done = 1;
-				break;
-			}
-		}
-
-		if (switch_test_flag(sh, SWITCH_SPEECH_FLAG_PAUSE)) {
-			if (timer) {
-				if (switch_core_timer_next(timer) != SWITCH_STATUS_SUCCESS) {
-					break;
-				}
-			} else {
-				switch_frame_t *read_frame;
-				switch_status_t status = switch_core_session_read_frame(session, &read_frame, -1, 0);
-
-				while (switch_channel_ready(channel) && switch_channel_test_flag(channel, CF_HOLD)) {
-					switch_yield(10000);
-				}
-
-				if (!SWITCH_READ_ACCEPTABLE(status)) {
-					break;
-				}
-			}
-			continue;
-		}
-
-		flags = SWITCH_SPEECH_FLAG_BLOCKING;
-		status = switch_core_speech_read_tts(sh,
-			abuf,
-			&ilen,
-			&rate,
-			&flags);
-
-		if (status != SWITCH_STATUS_SUCCESS) {
-			for( x = 0; !done && x < lead_in_out; x++) {
-				switch_yield(codec->implementation->microseconds_per_frame);
-				if (timer) {
-					write_frame.timestamp = timer->samplecount;
-				}
-                if (switch_core_session_write_frame(session, &write_frame, -1, stream_id) != SWITCH_STATUS_SUCCESS) {
-                    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Bad Write\n");
-                    done = 1;
-                    break;
-                }
-			}
-			if (status == SWITCH_STATUS_BREAK) {
-				status = SWITCH_STATUS_SUCCESS;
-			}
-			done = 1;
-		}
-
-		if (done) {
-			break;
-		}
-
-		write_frame.datalen = (uint32_t)ilen;
-		write_frame.samples = (uint32_t)(ilen / 2);
-		if (timer) {
-			write_frame.timestamp = timer->samplecount;
-		}
-        if (switch_core_session_write_frame(session, &write_frame, -1, stream_id) != SWITCH_STATUS_SUCCESS) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Bad Write\n");
-            done = 1;
-            break;
-        }
-
-        if (done) {
-            break;
-        }
-
-		if (timer) {
-			if (switch_core_timer_next(timer) != SWITCH_STATUS_SUCCESS) {
-				break;
-			}
-		} else { /* time off the channel (if you must) */
-			switch_frame_t *read_frame;
-			switch_status_t status = switch_core_session_read_frame(session, &read_frame, -1, 0);
-
-			while (switch_channel_ready(channel) && switch_channel_test_flag(channel, CF_HOLD)) {
-				switch_yield(10000);
-			}
-
-			if (!SWITCH_READ_ACCEPTABLE(status)) {
-				break;
-			}
-		}
-
-	}
-
-
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "done speaking text\n");
-	flags = 0;	
-	switch_core_speech_flush_tts(sh);
-	return status;
-}
-
-
-SWITCH_DECLARE(switch_status_t) switch_ivr_speak_text(switch_core_session_t *session, 
-													  char *tts_name,
-													  char *voice_name,
-													  uint32_t rate,
-													  char *text,
-                                                      switch_input_args_t *args)
-{
-	switch_channel_t *channel;
-	int interval = 0;
-	uint32_t samples = 0;
-	uint32_t len = 0;
-	switch_frame_t write_frame = {0};
-	switch_timer_t timer;
-	switch_core_thread_session_t thread_session;
-	switch_codec_t codec;
-	switch_memory_pool_t *pool = switch_core_session_get_pool(session);
-	char *codec_name;
-	int stream_id = 0;
-	switch_status_t status = SWITCH_STATUS_SUCCESS;
-	switch_speech_handle_t sh;
-	switch_speech_flag_t flags = SWITCH_SPEECH_FLAG_NONE;
-	switch_codec_t *read_codec;
-    char *timer_name;
-
-	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
-
-    timer_name = switch_channel_get_variable(channel, "timer_name");
-
-	if (rate == 0) {
-		read_codec = switch_core_session_get_read_codec(session);
-		rate = read_codec->implementation->samples_per_second;
-	}
-
-	memset(&sh, 0, sizeof(sh));
-	if (switch_core_speech_open(&sh,
-								tts_name,
-								voice_name,
-								(uint32_t)rate,
-								&flags,
-								switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid TTS module!\n");
-		switch_core_session_reset(session);
-		return SWITCH_STATUS_FALSE;
-	}
-		
-	switch_channel_answer(channel);
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "OPEN TTS %s\n", tts_name);
-	
-	interval = 20;
-	samples = (uint32_t)(rate / 50);
-	len = samples * 2;
-
-	codec_name = "L16";
-
-	if (switch_core_codec_init(&codec,
-							   codec_name,
-							   NULL,
-							   (int)rate,
-							   interval,
-							   1,
-							   SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
-							   NULL, pool) == SWITCH_STATUS_SUCCESS) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activated\n");
-		write_frame.codec = &codec;
-	} else {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activation Failed %s@%uhz 1 channel %dms\n",
-							  codec_name, rate, interval);
-		flags = 0;
-		switch_core_speech_close(&sh, &flags);
-		switch_core_session_reset(session);
-		return SWITCH_STATUS_GENERR;
-	}
-
-	if (timer_name) {
-		if (switch_core_timer_init(&timer, timer_name, interval, (int)samples, pool) != SWITCH_STATUS_SUCCESS) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "setup timer failed!\n");
-			switch_core_codec_destroy(&codec);
-			flags = 0;
-			switch_core_speech_close(&sh, &flags);
-
-			switch_core_session_reset(session);
-			return SWITCH_STATUS_GENERR;
-		}
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "setup timer success %u bytes per %d ms!\n", len, interval);
-
-		/* start a thread to absorb incoming audio */
-		for (stream_id = 0; stream_id < switch_core_session_get_stream_count(session); stream_id++) {
-			switch_core_service_session(session, &thread_session, stream_id);
-		}
-	}
-
-	status = switch_ivr_speak_text_handle(session, &sh, &codec, timer_name ? &timer : NULL, text, args);
-	flags = 0;	
-	switch_core_speech_close(&sh, &flags);
-	switch_core_codec_destroy(&codec);
-
-	if (timer_name) {
-		/* End the audio absorbing thread */
-		switch_core_thread_session_end(&thread_session);
-		switch_core_timer_destroy(&timer);
-	}
-
-	switch_core_session_reset(session);
-	return status;
-}
-
-
-/* Bridge Related Stuff*/
-/*********************************************************************************/
-struct audio_bridge_data {
-	switch_core_session_t *session_a;
-	switch_core_session_t *session_b;
-	int running;
-};
-
-static void *audio_bridge_thread(switch_thread_t *thread, void *obj)
-{
-	switch_core_thread_session_t *his_thread, *data = obj;
-	int *stream_id_p;
-	int stream_id = 0, pre_b = 0, ans_a = 0, ans_b = 0, originator = 0;
-	switch_input_callback_function_t input_callback;
-	switch_core_session_message_t *message, msg = {0};
-	void *user_data;
-
-	switch_channel_t *chan_a, *chan_b;
-	switch_frame_t *read_frame;
-	switch_core_session_t *session_a, *session_b;
-
-	assert(!thread || thread);
-
-	session_a = data->objs[0];
-	session_b = data->objs[1];
-
-	stream_id_p = data->objs[2];
-	input_callback = data->input_callback;
-	user_data = data->objs[4];
-	his_thread = data->objs[5];
-
-	if (stream_id_p) {
-		stream_id = *stream_id_p;
-	}
-
-	chan_a = switch_core_session_get_channel(session_a);
-	chan_b = switch_core_session_get_channel(session_b);
-
-	ans_a = switch_channel_test_flag(chan_a, CF_ANSWERED);
-	if ((originator = switch_channel_test_flag(chan_a, CF_ORIGINATOR))) {
-		pre_b = switch_channel_test_flag(chan_a, CF_EARLY_MEDIA);
-		ans_b = switch_channel_test_flag(chan_b, CF_ANSWERED);
-	}
-	switch_core_session_read_lock(session_a);
-	switch_core_session_read_lock(session_b);
-
-	switch_channel_set_flag(chan_a, CF_BRIDGED);
-
-	while (switch_channel_ready(chan_a) && data->running > 0 && his_thread->running > 0) {
-		switch_channel_state_t b_state = switch_channel_get_state(chan_b);
-		switch_status_t status;
-		switch_event_t *event;
-
-		switch (b_state) {
-		case CS_HANGUP:
-		case CS_DONE:
-			switch_mutex_lock(data->mutex);
-			data->running = -1;
-			switch_mutex_unlock(data->mutex);
-			continue;
-		default:
-			break;
-		}
-
-		if (switch_channel_test_flag(chan_a, CF_TRANSFER)) {
-			switch_channel_clear_flag(chan_a, CF_HOLD);
-			switch_channel_clear_flag(chan_a, CF_SUSPEND);
-			break;
-		}
-		
-		if (switch_core_session_dequeue_private_event(session_a, &event) == SWITCH_STATUS_SUCCESS) {
-			switch_channel_set_flag(chan_b, CF_SUSPEND);
-			switch_ivr_parse_event(session_a, event);
-			switch_channel_clear_flag(chan_b, CF_SUSPEND);
-			switch_event_destroy(&event);
-		}
-
-		/* if 1 channel has DTMF pass it to the other */
-		if (switch_channel_has_dtmf(chan_a)) {
-			char dtmf[128];
-			switch_channel_dequeue_dtmf(chan_a, dtmf, sizeof(dtmf));
-			switch_core_session_send_dtmf(session_b, dtmf);
-			
-			if (input_callback) {
-				if (input_callback(session_a, dtmf, SWITCH_INPUT_TYPE_DTMF, user_data, 0) != SWITCH_STATUS_SUCCESS) {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s ended call via DTMF\n", switch_channel_get_name(chan_a));
-					switch_mutex_lock(data->mutex);
-					data->running = -1;
-					switch_mutex_unlock(data->mutex);
-					break;
-				}
-			}
-		}
-
-		if (switch_core_session_dequeue_event(session_a, &event) == SWITCH_STATUS_SUCCESS) {
-			if (input_callback) {
-				status = input_callback(session_a, event, SWITCH_INPUT_TYPE_EVENT, user_data, 0);
-			}
-
-			if (event->event_id != SWITCH_EVENT_MESSAGE || switch_core_session_receive_event(session_b, &event) != SWITCH_STATUS_SUCCESS) {
-				switch_event_destroy(&event);
-			}
-
-		}
-
-		if (switch_core_session_dequeue_message(session_b, &message) == SWITCH_STATUS_SUCCESS) {
-			switch_core_session_receive_message(session_a, message);
-			if (switch_test_flag(message, SCSMF_DYNAMIC)) {
-				switch_safe_free(message);
-			} else {
-				message = NULL;
-			}
-		}
-
-		if (!ans_a && originator) {
-
-			if (!ans_b && switch_channel_test_flag(chan_b, CF_ANSWERED)) {
-				switch_channel_answer(chan_a);
-				ans_a++;
-			} else if (!pre_b && switch_channel_test_flag(chan_b, CF_EARLY_MEDIA)) {
-				switch_channel_pre_answer(chan_a);
-				pre_b++;
-			}
-			if (!pre_b) {
-				switch_yield(10000);
-				continue;
-			}
-		}
-
-
-		if (switch_channel_test_flag(chan_a, CF_SUSPEND) || switch_channel_test_flag(chan_b, CF_SUSPEND)) {
-			switch_yield(10000);
-			continue;
-		}
-
-		/* read audio from 1 channel and write it to the other */
-		status = switch_core_session_read_frame(session_a, &read_frame, -1, stream_id);
-
-		if (SWITCH_READ_ACCEPTABLE(status)) {
-			if (status != SWITCH_STATUS_BREAK && !switch_channel_test_flag(chan_a, CF_HOLD)) {
-				if (switch_core_session_write_frame(session_b, read_frame, -1, stream_id) != SWITCH_STATUS_SUCCESS) {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "write: %s Bad Frame....[%u] Bubye!\n",
-									  switch_channel_get_name(chan_b), read_frame->datalen);
-					switch_mutex_lock(data->mutex);
-					data->running = -1;
-					switch_mutex_unlock(data->mutex);
-				}
-			} 
-		} else {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "read: %s Bad Frame.... Bubye!\n", switch_channel_get_name(chan_a));
-			switch_mutex_lock(data->mutex);
-			data->running = -1;
-			switch_mutex_unlock(data->mutex);
-		}
-	}
-
-    switch_core_session_kill_channel(session_b, SWITCH_SIG_BREAK);
-	
-	msg.message_id = SWITCH_MESSAGE_INDICATE_UNBRIDGE;
-	msg.from = __FILE__;
-	switch_core_session_receive_message(session_a, &msg);
-
-	switch_channel_set_variable(chan_a, SWITCH_BRIDGE_VARIABLE, NULL);
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "BRIDGE THREAD DONE [%s]\n", switch_channel_get_name(chan_a));
-
-	switch_channel_clear_flag(chan_a, CF_BRIDGED);
-	switch_mutex_lock(data->mutex);
-	data->running = 0;
-	switch_mutex_unlock(data->mutex);
-
-	switch_core_session_rwunlock(session_a);
-	switch_core_session_rwunlock(session_b);
-	return NULL;
-}
-
-static switch_status_t audio_bridge_on_loopback(switch_core_session_t *session)
-{
-	switch_channel_t *channel = NULL;
-	void *arg;
-
-	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
-
-	if ((arg = switch_channel_get_private(channel, "_bridge_"))) {
-		switch_channel_set_private(channel, "_bridge_", NULL);
-		audio_bridge_thread(NULL, (void *) arg);
-	} else {
-		switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-	}
-	switch_channel_clear_state_handler(channel, &audio_bridge_peer_state_handlers);
-
-	if (!switch_channel_test_flag(channel, CF_TRANSFER)) {
-		switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
-	}
-	
-	return SWITCH_STATUS_FALSE;
-}
-
-
-static switch_status_t audio_bridge_on_ring(switch_core_session_t *session)
-{
-	switch_channel_t *channel = NULL;
-
-	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
-
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CUSTOM RING\n");
-
-	/* put the channel in a passive state so we can loop audio to it */
-	switch_channel_set_state(channel, CS_HOLD);
-	return SWITCH_STATUS_FALSE;
-}
-
-static switch_status_t audio_bridge_on_hold(switch_core_session_t *session)
-{
-	switch_channel_t *channel = NULL;
-
-	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
-
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CUSTOM HOLD\n");
-
-	/* put the channel in a passive state so we can loop audio to it */
-	return SWITCH_STATUS_FALSE;
-}
-
-static const switch_state_handler_table_t audio_bridge_peer_state_handlers = {
-	/*.on_init */ NULL,
-	/*.on_ring */ audio_bridge_on_ring,
-	/*.on_execute */ NULL,
-	/*.on_hangup */ NULL,
-	/*.on_loopback */ audio_bridge_on_loopback,
-	/*.on_transmit */ NULL,
-	/*.on_hold */ audio_bridge_on_hold,
-};
-
-
-
-static switch_status_t originate_on_ring(switch_core_session_t *session)
-{
-	switch_channel_t *channel = NULL;
-
-	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
-
-	/* put the channel in a passive state so we can loop audio to it */
-
-	/* clear this handler so it only works once (next time (a.k.a. Transfer) we will do the real ring state) */
-	switch_channel_clear_state_handler(channel, &originate_state_handlers);
-
-	switch_channel_set_state(channel, CS_HOLD);
-
-	return SWITCH_STATUS_FALSE;
-}
-
-static const switch_state_handler_table_t originate_state_handlers = {
-	/*.on_init */ NULL,
-	/*.on_ring */ originate_on_ring,
-	/*.on_execute */ NULL,
-	/*.on_hangup */ NULL,
-	/*.on_loopback */ NULL,
-	/*.on_transmit */ NULL,
-	/*.on_hold */ NULL
-};
-
-
-static switch_status_t uuid_bridge_on_transmit(switch_core_session_t *session)
-{
-	switch_channel_t *channel = NULL;
-	switch_core_session_t *other_session;
-
-	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
-
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CUSTOM TRANSMIT\n");
-	switch_channel_clear_state_handler(channel, NULL);
-
-
-	if (!switch_channel_test_flag(channel, CF_ORIGINATOR)) {
-		return SWITCH_STATUS_FALSE;
-	}
-
-	if ((other_session = switch_channel_get_private(channel, SWITCH_UUID_BRIDGE))) {
-		switch_channel_t *other_channel = switch_core_session_get_channel(other_session);
-		switch_channel_state_t state = switch_channel_get_state(other_channel);
-		switch_channel_state_t mystate = switch_channel_get_state(channel);
-		switch_event_t *event;
-		uint8_t ready_a, ready_b;
-		switch_caller_profile_t *profile, *new_profile;
-
-
-		switch_channel_clear_flag(channel, CF_TRANSFER);
-		switch_channel_set_private(channel, SWITCH_UUID_BRIDGE, NULL);
-
-		while (mystate <= CS_HANGUP && state <= CS_HANGUP && !switch_channel_test_flag(other_channel, CF_TAGGED)) {
-			switch_yield(1000);
-			state = switch_channel_get_state(other_channel);
-			mystate = switch_channel_get_state(channel);
-		}
-
-		switch_channel_clear_flag(other_channel, CF_TRANSFER);
-		switch_channel_clear_flag(other_channel, CF_TAGGED);
-		
-
-		switch_core_session_reset(session);
-		switch_core_session_reset(other_session);
-		
-		ready_a = switch_channel_ready(channel);
-		ready_b = switch_channel_ready(other_channel);
-
-		if (!ready_a || !ready_b) {
-			if (!ready_a) {
-				switch_channel_hangup(other_channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-			}
-
-			if (!ready_b) {
-				switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-			}
-			return SWITCH_STATUS_FALSE;
-		}
-		
-		/* add another profile to both sessions for CDR's sake */
-		if ((profile = switch_channel_get_caller_profile(channel))) {
-			new_profile = switch_caller_profile_clone(session, profile);
-			new_profile->destination_number = switch_core_session_strdup(session, switch_core_session_get_uuid(other_session));
-			switch_channel_set_caller_profile(channel, new_profile);
-		} 
-
-		if ((profile = switch_channel_get_caller_profile(other_channel))) {
-			new_profile = switch_caller_profile_clone(other_session, profile);
-			new_profile->destination_number = switch_core_session_strdup(other_session, switch_core_session_get_uuid(session));
-			switch_channel_set_caller_profile(other_channel, new_profile);
-		} 
-
-		/* fire events that will change the data table from "show channels" */
-		if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_EXECUTE) == SWITCH_STATUS_SUCCESS) {
-			switch_channel_event_set_data(channel, event);
-			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Application", "uuid_bridge");
-			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Application-Data", "%s", switch_core_session_get_uuid(other_session));
-			switch_event_fire(&event);
-		}
-
-		if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_EXECUTE) == SWITCH_STATUS_SUCCESS) {
-			switch_channel_event_set_data(other_channel, event);
-			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Application", "uuid_bridge");
-			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Application-Data", "%s", switch_core_session_get_uuid(session));
-			switch_event_fire(&event);
-		}
-
-		switch_ivr_multi_threaded_bridge(session, other_session, NULL, NULL, NULL);
-	} else {
-		switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-	}
-
-
-
-	return SWITCH_STATUS_FALSE;
-}
-
-static const switch_state_handler_table_t uuid_bridge_state_handlers = {
-	/*.on_init */ NULL,
-	/*.on_ring */ NULL,
-	/*.on_execute */ NULL,
-	/*.on_hangup */ NULL,
-	/*.on_loopback */ NULL,
-	/*.on_transmit */ uuid_bridge_on_transmit,
-	/*.on_hold */ NULL
-};
-
-struct key_collect {
-	char *key;
-	char *file;
-	switch_core_session_t *session;
-};
-
-
-static void *SWITCH_THREAD_FUNC collect_thread_run(switch_thread_t *thread, void *obj)
-{
-	struct key_collect *collect = (struct key_collect *) obj;
-	switch_channel_t *channel = switch_core_session_get_channel(collect->session);
-	char buf[10] = "";
-	char *p, term;
-
-
-	if (!strcasecmp(collect->key, "exec")) {
-		char *data;
-		const switch_application_interface_t *application_interface;
-		char *app_name, *app_data;
-
-		if (!(data = collect->file)) {
-			goto wbreak;
-		}
-
-		app_name = data;
-
-		if ((app_data = strchr(app_name, ' '))) {
-			*app_data++ = '\0';
-		}
-		
-		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);
-			goto wbreak;
-		}
-
-		if (!application_interface->application_function) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Function for %s\n", app_name);
-			switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-			goto wbreak;
-		}
-
-		application_interface->application_function(collect->session, app_data);
-		if (switch_channel_get_state(channel) < CS_HANGUP) {
-			switch_channel_set_flag(channel, CF_WINNER);
-		}
-		goto wbreak;
-	}
-
-	if (!switch_channel_ready(channel)) {
-		switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-		goto wbreak;
-	}
-
-	while(switch_channel_ready(channel)) {
-		memset(buf, 0, sizeof(buf));
-
-		if (collect->file) {
-            switch_input_args_t args = {0};
-            args.buf = buf;
-            args.buflen = sizeof(buf);
-			switch_ivr_play_file(collect->session, NULL, collect->file, &args);
-		} else {
-			switch_ivr_collect_digits_count(collect->session, buf, sizeof(buf), 1, "", &term, 0);
-		}
-
-		for(p = buf; *p; p++) {
-			if (*collect->key == *p) {
-				switch_channel_set_flag(channel, CF_WINNER);
-				goto wbreak;
-			}
-		}
-	}
- wbreak:
-
-	return NULL;
-}
-
-static void launch_collect_thread(struct key_collect *collect)
-{
-	switch_thread_t *thread;
-	switch_threadattr_t *thd_attr = NULL;
-	
-	switch_threadattr_create(&thd_attr, switch_core_session_get_pool(collect->session));
-	switch_threadattr_detach_set(thd_attr, 1);
-	switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
-	switch_thread_create(&thread, thd_attr, collect_thread_run, collect, switch_core_session_get_pool(collect->session));
-}
-
-static uint8_t check_channel_status(switch_channel_t **peer_channels,
-									switch_core_session_t **peer_sessions,
-									uint32_t len,
-									int32_t *idx,
-									uint32_t *hups,
-									char *file,
-									char *key,
-									uint8_t early_ok,
-									uint8_t *ring_ready)
-{
-
-	uint32_t i;
-	*hups = 0;
-	*idx = IDX_NADA;
-	
-	for (i = 0; i < len; i++) {
-		if (!peer_channels[i]) {
-			continue;
-		}
-		if (!*ring_ready && switch_channel_test_flag(peer_channels[i], CF_RING_READY)) {
-			*ring_ready = 1;
-		}
-		if (switch_channel_get_state(peer_channels[i]) >= CS_HANGUP) {
-			(*hups)++;
-		} else if ((switch_channel_test_flag(peer_channels[i], CF_ANSWERED) || 
-                    (early_ok && len == 1 && switch_channel_test_flag(peer_channels[i], CF_EARLY_MEDIA))) && 
-				   !switch_channel_test_flag(peer_channels[i], CF_TAGGED)) {
-
-			if (key) {
-				struct key_collect *collect;
-				
-				if ((collect = switch_core_session_alloc(peer_sessions[i], sizeof(*collect)))) {
-					switch_channel_set_flag(peer_channels[i], CF_TAGGED);
-					collect->key = key;
-					if (file) {
-						collect->file = switch_core_session_strdup(peer_sessions[i], file);
-					}
-				
-					collect->session = peer_sessions[i];
-					launch_collect_thread(collect);
-				}
-			} else {
-				*idx = i;
-				return 0;
-					
-			}
-		} else if (switch_channel_test_flag(peer_channels[i], CF_WINNER)) {
-			*idx = i;
-			return 0;
-		}
-	}
-
-	if (*hups == len) {
-		return 0;
-	} else {
-		return 1;
-	}
-	
-}
-
-struct ringback {
-	switch_buffer_t *audio_buffer;
-    switch_buffer_t *loop_buffer;
-	teletone_generation_session_t ts;	
-	switch_file_handle_t fhb;
-	switch_file_handle_t *fh;
-	uint8_t asis;
-};
-
-typedef struct ringback ringback_t;
-
-static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map_t *map)
-{
-	ringback_t *tto = ts->user_data;
-	int wrote;
-
-	if (!tto) {
-		return -1;
-	}
-	wrote = teletone_mux_tones(ts, map);
-	switch_buffer_write(tto->audio_buffer, ts->buffer, wrote * 2);
-
-	return 0;
-}
-
-#define MAX_PEERS 256
-SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *session,
-													 switch_core_session_t **bleg,
-													 switch_call_cause_t *cause,
-													 char *bridgeto,
-													 uint32_t timelimit_sec,
-													 const switch_state_handler_table_t *table,
-													 char *cid_name_override,
-													 char *cid_num_override,
-													 switch_caller_profile_t *caller_profile_override
-													 )
-										  
-{
-	char *pipe_names[MAX_PEERS] = {0};
-	char *data = NULL;
-	switch_status_t status = SWITCH_STATUS_SUCCESS;
-	switch_channel_t *caller_channel = NULL;
-	char *peer_names[MAX_PEERS] = {0};
-	switch_core_session_t *peer_session, *peer_sessions[MAX_PEERS] = {0};
-	switch_caller_profile_t *caller_profiles[MAX_PEERS] = {0}, *caller_caller_profile;
-	char *chan_type = NULL, *chan_data;
-	switch_channel_t *peer_channel = NULL, *peer_channels[MAX_PEERS] = {0};
-	ringback_t ringback = {0};
-	time_t start;
-	switch_frame_t *read_frame = NULL;
-	switch_memory_pool_t *pool = NULL;
-	int r = 0, i, and_argc = 0, or_argc = 0;
-	int32_t sleep_ms = 1000, try =0, retries = 1, idx = IDX_NADA;
-	switch_codec_t write_codec = {0};
-	switch_frame_t write_frame = {0};
-	uint8_t fdata[1024], pass = 0;
-	char *file = NULL, *key = NULL, *odata, *var;
-	switch_call_cause_t reason = SWITCH_CAUSE_UNALLOCATED;
-	uint8_t to = 0;
-	char *var_val, *vars = NULL, *ringback_data = NULL;
-	switch_codec_t *read_codec = NULL;
-	uint8_t sent_ring = 0, early_ok = 1;
-	switch_core_session_message_t *message = NULL;
-    switch_event_t *var_event = NULL;
-	uint8_t fail_on_single_reject = 0;
-	uint8_t ring_ready = 0;
-	char *loop_data = NULL;
-
-	write_frame.data = fdata;
-	
-	*bleg = NULL;
-	odata = strdup(bridgeto);
-	data = odata;
-
-    /* strip leading spaces */
-    while (data && *data && *data == ' ') {
-        data++;
-    }
-
-    if (*data == '{') {
-        vars = data + 1;
-        if (!(data = strchr(data, '}'))) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
-            status = SWITCH_STATUS_GENERR;
-            goto done;
-        }
-        *data++ = '\0';
-    }
-
-    /* strip leading spaces (again)*/
-    while (data && *data && *data == ' ') {
-        data++;
-    }
-    
-    if (switch_strlen_zero(data)) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
-        status = SWITCH_STATUS_GENERR;
-        goto done;
-    }
-    
-    /* Some channel are created from an originating channel and some aren't so not all outgoing calls have a way to get params
-       so we will normalize dialstring params and channel variables (when there is an originator) into an event that we 
-       will use as a pseudo hash to consult for params as needed.
-     */
-    if (switch_event_create(&var_event, SWITCH_EVENT_MESSAGE) != SWITCH_STATUS_SUCCESS) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error!\n");
-        status = SWITCH_STATUS_MEMERR;
-        goto done;
-    }
-    
-	if (session) {
-        switch_hash_index_t *hi;
-        void *vval;
-        const void *vvar;
-        
-        caller_channel = switch_core_session_get_channel(session);
-		assert(caller_channel != NULL);
-
-        /* Copy all the channel variables into the event */
-        for (hi = switch_channel_variable_first(caller_channel, switch_core_session_get_pool(session)); hi; hi = switch_hash_next(hi)) {
-            switch_hash_this(hi, &vvar, NULL, &vval);
-            if (vvar && vval) {
-                switch_event_add_header(var_event, SWITCH_STACK_BOTTOM, (void *)vvar, "%s", (char *)vval);
-            }
-        }
-
-    }
-
-    if (vars) { /* Parse parameters specified from the dialstring */
-        char *var_array[1024] = {0};
-        int var_count = 0;
-        if ((var_count = switch_separate_string(vars, ',', var_array, (sizeof(var_array) / sizeof(var_array[0]))))) {
-            int x = 0;
-            for (x = 0; x < var_count; x++) {
-                char *inner_var_array[2];
-                int inner_var_count;
-                if ((inner_var_count = 
-                     switch_separate_string(var_array[x], '=', inner_var_array, (sizeof(inner_var_array) / sizeof(inner_var_array[0])))) == 2) {
-                    
-                    switch_event_add_header(var_event, SWITCH_STACK_BOTTOM, inner_var_array[0], "%s", inner_var_array[1]);
-                    if (caller_channel) {
-                        switch_channel_set_variable(caller_channel, inner_var_array[0], inner_var_array[1]);
-                    }
-                }
-            }
-        }
-    }
-
-
-    if (caller_channel) { /* ringback is only useful when there is an originator */
-		ringback_data = switch_channel_get_variable(caller_channel, "ringback");
-		switch_channel_set_variable(caller_channel, "originate_disposition", "failure");
-	}
-	
-    if ((var = switch_event_get_header(var_event, "group_confirm_key"))) {
-        key = switch_core_session_strdup(session, var);
-        if ((var = switch_event_get_header(var_event, "group_confirm_file"))) {
-            file = switch_core_session_strdup(session, var);
-        }
-    }
-
-	// When using the AND operator, the fail_on_single_reject flag may be set in order to indicate that a single
-	// rejections should terminate the attempt rather than a timeout, answer, or rejection by all.
-	if ((var = switch_event_get_header(var_event, "fail_on_single_reject")) && switch_true(var)) {
-		fail_on_single_reject = 1;
-	}
-
-	if (file && !strcmp(file, "undef")) {
-		file = NULL;
-	}
-
-    if ((var_val = switch_event_get_header(var_event, "ignore_early_media")) && switch_true(var_val)) {
-        early_ok = 0;
-    }
-
-    if ((var_val = switch_event_get_header(var_event, "originate_retries")) && switch_true(var_val)) {
-		int32_t tmp;
-		tmp = atoi(var_val);
-		if (tmp > 0 && tmp < 101) {
-			retries = tmp;
-		} else {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, 
-							  "Invalid originate_retries setting of %d ignored, value must be between 1 and 100\n", tmp);
-		}
-    }
-
-    if ((var_val = switch_event_get_header(var_event, "originate_retry_sleep_ms")) && switch_true(var_val)) {
-		int32_t tmp;
-		tmp = atoi(var_val);
-		if (tmp > 500 && tmp < 60000) {
-			sleep_ms = tmp;
-		} else {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, 
-							  "Invalid originate_retry_sleep_ms setting of %d ignored, value must be between 500 and 60000\n", tmp);
-		}
-    }
-	
-    if (!cid_name_override) {
-        cid_name_override = switch_event_get_header(var_event, "origination_caller_id_name");
-    }
-
-    if (!cid_num_override) {
-        cid_num_override = switch_event_get_header(var_event, "origination_caller_id_number");
-    }
-                                                        
-
-
-	for (try = 0; try < retries; try++) {
-		switch_safe_free(loop_data);
-		assert(loop_data = strdup(data));
-		or_argc = switch_separate_string(loop_data, '|', pipe_names, (sizeof(pipe_names) / sizeof(pipe_names[0])));
-		
-		if (caller_channel && or_argc > 1 && !ringback_data) {
-			switch_channel_ring_ready(caller_channel);
-			sent_ring = 1;
-		}
-
-		for (r = 0; r < or_argc; r++) {
-			uint32_t hups;
-			reason = SWITCH_CAUSE_UNALLOCATED;
-			memset(peer_names, 0, sizeof(peer_names));
-			peer_session = NULL;
-			memset(peer_sessions, 0, sizeof(peer_sessions));
-			memset(peer_channels, 0, sizeof(peer_channels));
-			memset(caller_profiles, 0, sizeof(caller_profiles));
-			chan_type = NULL;
-			chan_data = NULL;
-			peer_channel = NULL;
-			start = 0;
-			read_frame = NULL;
-			pool = NULL;
-			pass = 0;
-			file = NULL;
-			key = NULL;
-			var = NULL;
-			to = 0;
-			
-			if (try > 0) {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Originate attempt %d/%d in %d ms\n", try + 1, retries, sleep_ms);
-				switch_yield(sleep_ms * 1000);
-			}
-
-			and_argc = switch_separate_string(pipe_names[r], ',', peer_names, (sizeof(peer_names) / sizeof(peer_names[0])));
-	
-			if (caller_channel && !sent_ring && and_argc > 1 && !ringback_data) {
-				switch_channel_ring_ready(caller_channel);
-				sent_ring = 1;
-			}
-
-			for (i = 0; i < and_argc; i++) {
-		
-				chan_type = peer_names[i];
-				if ((chan_data = strchr(chan_type, '/')) != 0) {
-					*chan_data = '\0';
-					chan_data++;
-				}
-	
-				if (session) {
-					if (!switch_channel_ready(caller_channel)) {
-						status = SWITCH_STATUS_FALSE;
-						goto done;
-					}
-
-					caller_caller_profile = caller_profile_override ? caller_profile_override : switch_channel_get_caller_profile(caller_channel);
-                
-					if (!cid_name_override) {
-						cid_name_override = caller_caller_profile->caller_id_name;
-					}
-					if (!cid_num_override) {
-						cid_num_override = caller_caller_profile->caller_id_number;
-					}
-
-					caller_profiles[i] = switch_caller_profile_new(switch_core_session_get_pool(session),
-																   caller_caller_profile->username,
-																   caller_caller_profile->dialplan,
-																   cid_name_override,
-																   cid_num_override,
-																   caller_caller_profile->network_addr,
-																   NULL,
-																   NULL,
-																   caller_caller_profile->rdnis,
-																   caller_caller_profile->source,
-																   caller_caller_profile->context,
-																   chan_data);
-					caller_profiles[i]->flags = caller_caller_profile->flags;
-					pool = NULL;
-				} else {
-					if (!cid_name_override) {
-						cid_name_override = "FreeSWITCH";
-					}
-					if (!cid_num_override) {
-						cid_num_override = "0000000000";
-					}
-
-					if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
-						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "OH OH no pool\n");
-						status = SWITCH_STATUS_TERM;
-						goto done;
-					}
-
-					if (caller_profile_override) {
-						caller_profiles[i] = switch_caller_profile_new(pool,
-																	   caller_profile_override->username,
-																	   caller_profile_override->dialplan,
-																	   caller_profile_override->caller_id_name,
-																	   caller_profile_override->caller_id_number,
-																	   caller_profile_override->network_addr, 
-																	   caller_profile_override->ani,
-																	   caller_profile_override->aniii,
-																	   caller_profile_override->rdnis,
-																	   caller_profile_override->source,
-																	   caller_profile_override->context,
-																	   chan_data);
-					} else {
-						caller_profiles[i] = switch_caller_profile_new(pool,
-																	   NULL,
-																	   NULL,
-																	   cid_name_override,
-																	   cid_num_override,
-																	   NULL,
-																	   NULL, 
-																	   NULL,
-																	   NULL,
-																	   __FILE__,
-																	   NULL,
-																	   chan_data);
-					}
-				}
-
-				if ((reason = switch_core_session_outgoing_channel(session, chan_type, caller_profiles[i], &peer_sessions[i], &pool)) != SWITCH_CAUSE_SUCCESS) {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Create Outgoing Channel! cause: %s\n", switch_channel_cause2str(reason));
-					if (pool) {
-						switch_core_destroy_memory_pool(&pool);
-					}
-					caller_profiles[i] = NULL;
-					peer_channels[i] = NULL;
-					peer_sessions[i] = NULL;
-					continue;
-				}
-			
-				switch_core_session_read_lock(peer_sessions[i]);
-				pool = NULL;
-	
-				peer_channels[i] = switch_core_session_get_channel(peer_sessions[i]);
-				assert(peer_channels[i] != NULL);
-
-				if (!table) {
-					table = &originate_state_handlers;
-				}
-
-				if (table) {
-					switch_channel_add_state_handler(peer_channels[i], table);
-				}
-
-				if (switch_core_session_running(peer_sessions[i])) {
-					switch_channel_set_state(peer_channels[i], CS_RING);
-				} else {
-					switch_core_session_thread_launch(peer_sessions[i]);
-				}
-			}
-
-			time(&start);
-
-			for (;;) {
-				uint32_t valid_channels = 0;
-				for (i = 0; i < and_argc; i++) {
-					int state;
-
-					if (!peer_channels[i]) {
-						continue;
-					}
-					valid_channels++;
-					state = switch_channel_get_state(peer_channels[i]);
-			
-					if (state >= CS_HANGUP) {
-						goto notready;
-					} else if (state >= CS_RING) {
-						goto endfor1;
-					}
-		
-					if (caller_channel && !switch_channel_ready(caller_channel)) {
-						goto notready;
-					}
-				
-					if ((time(NULL) - start) > (time_t)timelimit_sec) {
-						to++;
-						idx = IDX_CANCEL;
-						goto notready;
-					}
-					switch_yield(1000);
-				}
-
-				if (valid_channels == 0) {
-					status = SWITCH_STATUS_GENERR;
-					goto done;
-				}
-
-			}
-		endfor1:
-
-			if (ringback_data && !switch_channel_test_flag(caller_channel, CF_ANSWERED) && !switch_channel_test_flag(caller_channel, CF_EARLY_MEDIA)) {
-				switch_channel_pre_answer(caller_channel);
-			}
-
-			if (session && (read_codec = switch_core_session_get_read_codec(session)) && 
-				(ringback_data || !switch_channel_test_flag(caller_channel, CF_NOMEDIA))) {
-
-				if (!(pass = (uint8_t)switch_test_flag(read_codec, SWITCH_CODEC_FLAG_PASSTHROUGH))) {
-					if (switch_core_codec_init(&write_codec,
-											   "L16",
-											   NULL,
-											   read_codec->implementation->samples_per_second,
-											   read_codec->implementation->microseconds_per_frame / 1000,
-											   1,
-											   SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
-											   NULL,
-											   pool) == SWITCH_STATUS_SUCCESS) {
-					
-					
-						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activation Success L16@%uhz 1 channel %dms\n",
-										  read_codec->implementation->samples_per_second,
-										  read_codec->implementation->microseconds_per_frame / 1000);
-						write_frame.codec = &write_codec;
-						write_frame.datalen = read_codec->implementation->bytes_per_frame;
-						write_frame.samples = write_frame.datalen / 2;
-						memset(write_frame.data, 255, write_frame.datalen);
-					
-						if (ringback_data) {
-							char *tmp_data = NULL;
-						
-							switch_buffer_create_dynamic(&ringback.audio_buffer, 512, 1024, 0);
-							switch_buffer_create_dynamic(&ringback.loop_buffer, 512, 1024, 0);
-
-							if (*ringback_data == '/') {
-								char *ext;
-							
-								if ((ext = strrchr(ringback_data, '.'))) {
-									switch_core_session_set_read_codec(session, &write_codec);
-									ext++;
-								} else {
-									ringback.asis++;
-									write_frame.codec = read_codec;
-									ext = read_codec->implementation->iananame;
-									tmp_data = switch_mprintf("%s.%s", ringback_data, ext);
-									ringback_data = tmp_data;
-								}
-
-								switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Play Ringback File [%s]\n", ringback_data);
-
-								ringback.fhb.channels = read_codec->implementation->number_of_channels;
-								ringback.fhb.samplerate = read_codec->implementation->samples_per_second;
-								if (switch_core_file_open(&ringback.fhb,
-														  ringback_data,
-														  read_codec->implementation->number_of_channels,
-														  read_codec->implementation->samples_per_second,
-														  SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT,
-														  switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
-									switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Playing File\n");
-									switch_safe_free(tmp_data);
-									goto notready;
-								}
-								ringback.fh = &ringback.fhb;
-
-							
-							} else {
-								teletone_init_session(&ringback.ts, 0, teletone_handler, &ringback);
-								switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Play Ringback Tone [%s]\n", ringback_data);
-								//ringback.ts.debug = 1;
-								//ringback.ts.debug_stream = switch_core_get_console();
-								if (teletone_run(&ringback.ts, ringback_data)) {
-									switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Playing Tone\n");
-									teletone_destroy_session(&ringback.ts);
-									switch_buffer_destroy(&ringback.audio_buffer);
-									switch_buffer_destroy(&ringback.loop_buffer);
-									ringback_data = NULL;
-								}
-							}
-							switch_safe_free(tmp_data);
-						}
-					} else {
-						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec Error!");
-						switch_channel_hangup(caller_channel, SWITCH_CAUSE_NORMAL_TEMPORARY_FAILURE);
-						read_codec = NULL;
-					}
-				}
-			}
-        
-			if (ringback_data) {
-				early_ok = 0;
-			}
-
-			while ((!caller_channel || switch_channel_ready(caller_channel)) && 
-				   check_channel_status(peer_channels, peer_sessions, and_argc, &idx, &hups, file, key, early_ok, &ring_ready)) {
-
-				// When the AND operator is being used, and fail_on_single_reject is set, a hangup indicates that the call should fail.
-				if ((to = (uint8_t)((time(NULL) - start) >= (time_t)timelimit_sec)) || (fail_on_single_reject && hups)) {
-					idx = IDX_CANCEL;
-					goto notready;
-				}
-
-				if (peer_sessions[0] && switch_core_session_dequeue_message(peer_sessions[0], &message) == SWITCH_STATUS_SUCCESS) {
-					if (session && !ringback_data && or_argc == 1 && and_argc == 1) { /* when there is only 1 channel to call and bridge and no ringback */
-						switch_core_session_receive_message(session, message);
-					}
-				
-					if (switch_test_flag(message, SCSMF_DYNAMIC)) {
-						switch_safe_free(message);
-					} else {
-						message = NULL;
-					}
-				}
-
-				/* read from the channel while we wait if the audio is up on it */
-				if (session && (ringback_data || !switch_channel_test_flag(caller_channel, CF_NOMEDIA)) && 
-					(switch_channel_test_flag(caller_channel, CF_ANSWERED) || switch_channel_test_flag(caller_channel, CF_EARLY_MEDIA))) {
-					switch_status_t status = switch_core_session_read_frame(session, &read_frame, 1000, 0);
-			
-					if (!SWITCH_READ_ACCEPTABLE(status)) {
-						break;
-					}
-				
-					if (ring_ready && read_frame && !pass && !switch_test_flag(read_frame, SFF_CNG) && read_frame->datalen > 1) {
-						if (ringback.fh) {
-							uint8_t abuf[1024];
-							switch_size_t mlen, olen;
-							unsigned int pos = 0;
-
-							if (ringback.asis) {
-								mlen = read_frame->datalen;
-							} else {
-								mlen = read_frame->datalen  / 2;
-							}
-
-							olen = mlen;
-							switch_core_file_read(ringback.fh, abuf, &olen);
-						
-							if (olen == 0) {
-								olen = mlen;
-								ringback.fh->speed = 0;
-								switch_core_file_seek(ringback.fh, &pos, 0, SEEK_SET);
-								switch_core_file_read(ringback.fh, abuf, &olen);
-								if (olen == 0) {
-									break;
-								}
-							}
-							write_frame.data = abuf;
-							write_frame.datalen = (uint32_t) (ringback.asis ? olen : olen * 2);
-							if (switch_core_session_write_frame(session, &write_frame, 1000, 0) != SWITCH_STATUS_SUCCESS) {
-								break;
-							}
-						} else if (ringback.audio_buffer) {
-							if ((write_frame.datalen = (uint32_t)switch_buffer_read(ringback.audio_buffer,
-																					write_frame.data,
-																					write_frame.codec->implementation->bytes_per_frame)) <= 0) {
-								switch_buffer_t *tmp;
-								tmp = ringback.audio_buffer;
-								ringback.audio_buffer = ringback.loop_buffer;
-								ringback.loop_buffer = tmp;
-								if ((write_frame.datalen = (uint32_t)switch_buffer_read(ringback.audio_buffer,
-																						write_frame.data,
-																						write_frame.codec->implementation->bytes_per_frame)) <= 0) {
-									break;
-								}
-							}
-						}
-
-						if (switch_core_session_write_frame(session, &write_frame, 1000, 0) != SWITCH_STATUS_SUCCESS) {
-							break;
-						}
-						if (ringback.loop_buffer) {
-							switch_buffer_write(ringback.loop_buffer, write_frame.data, write_frame.datalen);
-						}
-					}
-
-				} else {
-					switch_yield(1000);
-				}
-		
-			}
-
-		notready:
-
-			if (caller_channel && !switch_channel_ready(caller_channel)) {
-				idx = IDX_CANCEL;
-			}
-
-			if (session && (ringback_data || !switch_channel_test_flag(caller_channel, CF_NOMEDIA))) {
-				switch_core_session_reset(session);
-			}
-
-			for (i = 0; i < and_argc; i++) {
-				if (!peer_channels[i]) {
-					continue;
-				}
-				if (i != idx) {
-					if (idx == IDX_CANCEL) {
-						if (to) {
-							reason = SWITCH_CAUSE_NO_ANSWER;
-						} else {
-							reason = SWITCH_CAUSE_ORIGINATOR_CANCEL;
-						}
-					} else {
-						if (to) {
-							reason = SWITCH_CAUSE_NO_ANSWER;
-						} else if (and_argc > 1) {
-							reason = SWITCH_CAUSE_LOSE_RACE;
-						} else {
-							reason = SWITCH_CAUSE_NO_ANSWER;
-						}
-					}
-
-				
-					switch_channel_hangup(peer_channels[i], reason);
-				}
-			}
-
-
-			if (idx > IDX_NADA) {
-				peer_session = peer_sessions[idx];
-				peer_channel = peer_channels[idx];
-			} else {
-				status = SWITCH_STATUS_FALSE;
-				goto done;
-			}
-
-			if (caller_channel) {
-				if (switch_channel_test_flag(peer_channel, CF_ANSWERED)) {
-					switch_channel_answer(caller_channel);
-				} else if (switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA)) {
-					switch_channel_pre_answer(caller_channel);
-				}
-			}
-
-			if (switch_channel_test_flag(peer_channel, CF_ANSWERED) || switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA)) {
-				*bleg = peer_session;
-				status = SWITCH_STATUS_SUCCESS;
-			} else {
-				status = SWITCH_STATUS_FALSE;
-			}
-
-		done:
-			*cause = SWITCH_CAUSE_UNALLOCATED;
-        
-			if (var_event) {
-				if (peer_channel && !caller_channel) { /* install the vars from the {} params */
-					switch_event_header_t *header;
-					for (header = var_event->headers; header; header = header->next) {
-						switch_channel_set_variable(peer_channel, header->name, header->value);
-					}
-				}
-				switch_event_destroy(&var_event);
-			}
-
-			if (status == SWITCH_STATUS_SUCCESS) {
-				if (caller_channel) {
-					switch_channel_set_variable(caller_channel, "originate_disposition", "call accepted");
-				} 
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Originate Resulted in Success: [%s]\n", switch_channel_get_name(peer_channel));
-				*cause = SWITCH_CAUSE_SUCCESS;
-            
-			} else {
-				if (peer_channel) {
-					*cause = switch_channel_get_cause(peer_channel);
-				} else {
-					for (i = 0; i < and_argc; i++) {
-						if (!peer_channels[i]) {
-							continue;
-						}
-						*cause = switch_channel_get_cause(peer_channels[i]);
-						break;
-					}
-				}
-
-				if (!*cause) {
-					if (reason) {
-						*cause = reason;
-					} else if (caller_channel) {
-						*cause = switch_channel_get_cause(caller_channel);
-					} else {
-						*cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
-					}
-				}
-
-				if (idx == IDX_CANCEL) {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Originate Cancelled by originator termination Cause: %d [%s]\n",
-									  *cause, switch_channel_cause2str(*cause));
-                
-				} else {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Originate Resulted in Error Cause: %d [%s]\n",
-									  *cause, switch_channel_cause2str(*cause));
-				}
-			}
-        
-			if (caller_channel) {
-				switch_channel_set_variable(caller_channel, "originate_disposition", switch_channel_cause2str(*cause));
-			}
-
-			if (!pass && write_codec.implementation) {
-				switch_core_codec_destroy(&write_codec);
-			}
-
-			if (ringback.fh) {
-				switch_core_file_close(ringback.fh);
-				ringback.fh = NULL;
-				if (read_codec && !ringback.asis) {
-					switch_core_session_set_read_codec(session, read_codec);
-					switch_core_session_reset(session);
-				}
-			} else if (ringback.audio_buffer) {
-				teletone_destroy_session(&ringback.ts);
-				switch_buffer_destroy(&ringback.audio_buffer);
-				switch_buffer_destroy(&ringback.loop_buffer);
-			}
-
-			for (i = 0; i < and_argc; i++) {
-				if (!peer_channels[i]) {
-					continue;
-				}
-				switch_core_session_rwunlock(peer_sessions[i]);
-			}
-			
-			if (status == SWITCH_STATUS_SUCCESS) {
-				goto outer_for;
-			}
-		}
-	}
- outer_for:
-	switch_safe_free(loop_data);
-	switch_safe_free(odata);
-	return status;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_ivr_hold(switch_core_session_t *session)
-{
-	switch_core_session_message_t msg = {0};
-	switch_channel_t *channel;
-
-	msg.message_id = SWITCH_MESSAGE_INDICATE_HOLD;
-	msg.from = __FILE__;
-	
-	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
-		
-	switch_channel_set_flag(channel, CF_HOLD);
-	switch_channel_set_flag(channel, CF_SUSPEND);
-
-	switch_core_session_receive_message(session, &msg);
-
-	return SWITCH_STATUS_SUCCESS;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_ivr_hold_uuid(char *uuid)
-{
-	switch_core_session_t *session;
-
-	if ((session = switch_core_session_locate(uuid))) {
-		switch_ivr_hold(session);
-		switch_core_session_rwunlock(session);
-	}
-	
-	return SWITCH_STATUS_SUCCESS;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_ivr_unhold(switch_core_session_t *session)
-{
-	switch_core_session_message_t msg = {0};
-	switch_channel_t *channel;
-		
-	msg.message_id = SWITCH_MESSAGE_INDICATE_UNHOLD;
-	msg.from = __FILE__;
-	
-	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
-		
-	switch_channel_clear_flag(channel, CF_HOLD);
-	switch_channel_clear_flag(channel, CF_SUSPEND);
-	
-	switch_core_session_receive_message(session, &msg);
-
-	return SWITCH_STATUS_SUCCESS;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_ivr_unhold_uuid(char *uuid)
-{
-	switch_core_session_t *session;
-
-	if ((session = switch_core_session_locate(uuid))) {
-		switch_ivr_unhold(session);
-		switch_core_session_rwunlock(session);
-	}
-
-	return SWITCH_STATUS_SUCCESS;
-}
-
-struct hangup_helper {
-	char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
-	switch_bool_t bleg;
-	switch_call_cause_t cause;
-};
-
-static void sch_hangup_callback(switch_core_scheduler_task_t *task)
-{
-	struct hangup_helper *helper;
-	switch_core_session_t *session, *other_session;
-	char *other_uuid;
-
-	assert(task);
-
-	helper = (struct hangup_helper *) task->cmd_arg;
-	
-	if ((session = switch_core_session_locate(helper->uuid_str))) {
-		switch_channel_t *channel = switch_core_session_get_channel(session);
-
-		if (helper->bleg) {
-			if ((other_uuid = switch_channel_get_variable(channel, SWITCH_BRIDGE_VARIABLE)) &&
-				(other_session = switch_core_session_locate(other_uuid))) {
-				switch_channel_t *other_channel = switch_core_session_get_channel(other_session);
-				switch_channel_hangup(other_channel, helper->cause);
-				switch_core_session_rwunlock(other_session);
-			} else {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "No channel to hangup\n");
-			}
-		} else {
-			switch_channel_hangup(channel, helper->cause);
-		}
-
-		switch_core_session_rwunlock(session);
-	}
-}
-
-SWITCH_DECLARE(uint32_t) switch_ivr_schedule_hangup(time_t runtime, char *uuid, switch_call_cause_t cause, switch_bool_t bleg)
-{
-	struct hangup_helper *helper;
-	size_t len = sizeof(*helper);
-
-	assert((helper = malloc(len)));
-	memset(helper, 0, len);
-	
-	switch_copy_string(helper->uuid_str, uuid, sizeof(helper->uuid_str));
-	helper->cause = cause;
-	helper->bleg = bleg;
-	
-	return switch_core_scheduler_add_task(runtime, sch_hangup_callback, (char *)__SWITCH_FUNC__, uuid, 0, helper, SSHF_FREE_ARG); 
-}
-
-struct transfer_helper {
-	char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
-	char *extension;
-	char *dialplan;
-	char *context;
-};
-
-static void sch_transfer_callback(switch_core_scheduler_task_t *task)
-{
-	struct transfer_helper *helper;
-	switch_core_session_t *session;
-
-	assert(task);
-
-	helper = (struct transfer_helper *) task->cmd_arg;
-	
-	if ((session = switch_core_session_locate(helper->uuid_str))) {
-		switch_ivr_session_transfer(session, helper->extension, helper->dialplan, helper->context);
-		switch_core_session_rwunlock(session);
-	}
-
-}
-
-SWITCH_DECLARE(uint32_t) switch_ivr_schedule_transfer(time_t runtime, char *uuid, char *extension, char *dialplan, char *context)
-{
-	struct transfer_helper *helper;
-	size_t len = sizeof(*helper);
-	char *cur = NULL;
-
-	if (extension) {
-		len += strlen(extension) + 1;
-	}
-
-	if (dialplan) {
-		len += strlen(dialplan) + 1;
-	}
-
-	if (context) {
-		len += strlen(context) + 1;
-	}
-
-	assert((helper = malloc(len)));
-	memset(helper, 0, len);
-	
-	switch_copy_string(helper->uuid_str, uuid, sizeof(helper->uuid_str));
-	
-	cur = (char *) helper + sizeof(*helper);
-
-	if (extension) {
-		helper->extension = cur;
-		switch_copy_string(helper->extension, extension, strlen(extension) + 1);
-		cur += strlen(helper->extension) + 1;
-	}
-
-	if (dialplan) {
-		helper->dialplan = cur;
-		switch_copy_string(helper->dialplan, dialplan, strlen(dialplan) + 1);
-		cur += strlen(helper->dialplan) + 1;
-	}
-
-	if (context) {
-		helper->context = cur;
-		switch_copy_string(helper->context, context, strlen(context)+1);
-	}
-	
-	return switch_core_scheduler_add_task(runtime, sch_transfer_callback, (char *)__SWITCH_FUNC__, uuid, 0, helper, SSHF_FREE_ARG); 
-}
-
-
-struct broadcast_helper {
-	char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
-	char *path;
-	switch_media_flag_t flags;
-};
-
-static void sch_broadcast_callback(switch_core_scheduler_task_t *task)
-{
-	struct broadcast_helper *helper;
-	assert(task);
-
-	helper = (struct broadcast_helper *) task->cmd_arg;
-	switch_ivr_broadcast(helper->uuid_str, helper->path, helper->flags);
-}
-
-SWITCH_DECLARE(uint32_t) switch_ivr_schedule_broadcast(time_t runtime, char *uuid, char *path, switch_media_flag_t flags)
-{
-	struct broadcast_helper *helper;
-	size_t len = sizeof(*helper) + strlen(path) + 1;
-
-	assert((helper = malloc(len)));
-	memset(helper, 0, len);
-	
-	switch_copy_string(helper->uuid_str, uuid, sizeof(helper->uuid_str));
-	helper->flags = flags;
-	helper->path = (char *) helper + sizeof(*helper);
-	switch_copy_string(helper->path, path, len - sizeof(helper));
-
-	
-	return switch_core_scheduler_add_task(runtime, sch_broadcast_callback, (char *)__SWITCH_FUNC__, uuid, 0, helper, SSHF_FREE_ARG); 
-}
-
-SWITCH_DECLARE(switch_status_t) switch_ivr_broadcast(char *uuid, char *path, switch_media_flag_t flags)
-{
-    switch_channel_t *channel;
-	int nomedia;
-	switch_core_session_t *session, *master;
-	switch_event_t *event;
-	switch_core_session_t *other_session = NULL;
-	char *other_uuid = NULL;
-	char *app = "playback";
-
-	assert(path);
-
-	if ((session = switch_core_session_locate(uuid))) {
-		char *cause = NULL;
-		char *mypath = strdup(path);
-		char *p;
-		
-		master = session;
-
-		channel = switch_core_session_get_channel(session);
-		assert(channel != NULL);
-
-		if ((nomedia = switch_channel_test_flag(channel, CF_NOMEDIA))) {
-			switch_ivr_media(uuid, SMF_REBRIDGE);
-		}
-		
-		if ((p = strchr(mypath, ':'))) {
-			app = mypath;
-			*p++ = '\0';
-			path = p;
-		}
-		
-		if ((cause = strchr(app, '!'))) {
-			*cause++ = '\0';
-			if (!cause) {
-				cause = "normal_clearing";
-			}
-		}
-		
-		if ((flags & SMF_ECHO_BLEG) && (other_uuid = switch_channel_get_variable(channel, SWITCH_BRIDGE_VARIABLE))
-			&& (other_session = switch_core_session_locate(other_uuid))) {
-			if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
-				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "call-command", "execute");
-				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "execute-app-name", "%s", app);
-				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "execute-app-arg", "%s", path);
-				switch_core_session_queue_private_event(other_session, &event);
-			}
-			switch_core_session_rwunlock(other_session);
-			master = other_session;
-			other_session = NULL;
-		}
-		
-		if ((flags & SMF_ECHO_ALEG)) {
-			if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
-				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "call-command", "execute");
-				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "execute-app-name", "%s", app);
-				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "execute-app-arg", "%s", path);
-				switch_core_session_queue_private_event(session, &event);
-			}
-			master = session;
-		}
-
-		if (nomedia) {
-			if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
-				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "call-command", "nomedia");
-				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "nomedia-uuid", "%s", uuid);
-				switch_core_session_queue_private_event(master, &event);
-			}
-		}
-		
-		if (cause) {
-			if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
-				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "call-command", "execute");
-				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "execute-app-name", "hangup");
-				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "execute-app-arg", "%s", cause);
-
-				switch_core_session_queue_private_event(session, &event);
-			}
-		}
-
-		switch_core_session_rwunlock(session);
-		switch_safe_free(mypath);
-	}
-
-
-	return SWITCH_STATUS_SUCCESS;
-	
-}
-
-SWITCH_DECLARE(switch_status_t) switch_ivr_media(char *uuid, switch_media_flag_t flags)
-{
-	char *other_uuid = NULL;
-	switch_channel_t *channel, *other_channel = NULL;
-    switch_core_session_t *session, *other_session;
-	switch_core_session_message_t msg = {0};
-	switch_status_t status = SWITCH_STATUS_GENERR;
-	uint8_t swap = 0;
-
-	msg.message_id = SWITCH_MESSAGE_INDICATE_MEDIA;
-	msg.from = __FILE__;
-
-	if ((session = switch_core_session_locate(uuid))) {
-		channel = switch_core_session_get_channel(session);
-		assert(channel != NULL);
-		if ((flags & SMF_REBRIDGE) && !switch_channel_test_flag(channel, CF_ORIGINATOR)) {
-			swap = 1;
-		}
-		
-		if (switch_channel_test_flag(channel, CF_NOMEDIA)) {
-			status = SWITCH_STATUS_SUCCESS;
-			switch_channel_clear_flag(channel, CF_NOMEDIA);
-			switch_core_session_receive_message(session, &msg);
-
-			if ((flags & SMF_REBRIDGE) && (other_uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BRIDGE_VARIABLE)) 
-				&& (other_session = switch_core_session_locate(other_uuid))) {
-				other_channel = switch_core_session_get_channel(other_session);
-				assert(other_channel != NULL);
-				switch_core_session_receive_message(other_session, &msg);
-				switch_channel_clear_state_handler(other_channel, NULL);
-				switch_core_session_rwunlock(other_session);
-			}
-			if (other_channel) {
-				switch_channel_clear_state_handler(channel, NULL);
-			}
-		}
-		
-		switch_core_session_rwunlock(session);
-
-		if (other_channel) {
-			if (swap) {
-				switch_ivr_uuid_bridge(other_uuid, uuid);
-			} else {
-				switch_ivr_uuid_bridge(uuid, other_uuid);
-			}
-		}
-	}
-
-	return status;
-}
-
-
-SWITCH_DECLARE(switch_status_t) switch_ivr_nomedia(char *uuid, switch_media_flag_t flags)
-{
-	char *other_uuid;
-	switch_channel_t *channel, *other_channel = NULL;
-    switch_core_session_t *session, *other_session = NULL;
-	switch_core_session_message_t msg = {0};
-	switch_status_t status = SWITCH_STATUS_GENERR;
-	uint8_t swap = 0;
-
-	msg.message_id = SWITCH_MESSAGE_INDICATE_NOMEDIA;
-	msg.from = __FILE__;
-
-	if ((session = switch_core_session_locate(uuid))) {
-		status = SWITCH_STATUS_SUCCESS;
-		channel = switch_core_session_get_channel(session);
-		assert(channel != NULL);
-
-		if ((flags & SMF_REBRIDGE) && !switch_channel_test_flag(channel, CF_ORIGINATOR)) {
-			swap = 1;
-		}
-
-		if ((flags & SMF_FORCE) || !switch_channel_test_flag(channel, CF_NOMEDIA)) {
-			switch_channel_set_flag(channel, CF_NOMEDIA);
-			switch_core_session_receive_message(session, &msg);
-			if ((flags & SMF_REBRIDGE) && (other_uuid = switch_channel_get_variable(channel, SWITCH_BRIDGE_VARIABLE)) &&
-				(other_session = switch_core_session_locate(other_uuid))) {
-				other_channel = switch_core_session_get_channel(other_session);
-				assert(other_channel != NULL);
-				switch_core_session_receive_message(other_session, &msg);
-				switch_channel_clear_state_handler(other_channel, NULL);
-
-			}
-			if (other_channel) {
-				switch_channel_clear_state_handler(channel, NULL);
-				if (swap) {
-					switch_ivr_signal_bridge(other_session, session);
-				} else {
-					switch_ivr_signal_bridge(session, other_session);
-				}
-				switch_core_session_rwunlock(other_session);
-			}
-		}
-		switch_core_session_rwunlock(session);
-	}
-
-	return status;
-}
-
-static switch_status_t signal_bridge_on_hibernate(switch_core_session_t *session)
-{
-	switch_channel_t *channel = NULL;
-
-	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
-	switch_channel_clear_flag(channel, CF_TRANSFER);
-
-	switch_channel_set_variable(channel, SWITCH_BRIDGE_VARIABLE, switch_channel_get_variable(channel, SWITCH_SIGNAL_BRIDGE_VARIABLE));
-
-	return SWITCH_STATUS_SUCCESS;
-}
-
-static switch_status_t signal_bridge_on_hangup(switch_core_session_t *session)
-{
-	char *uuid;
-	switch_channel_t *channel = NULL;
-    switch_core_session_t *other_session;
-	switch_event_t *event;
-
-    channel = switch_core_session_get_channel(session);
-    assert(channel != NULL);
-
-	if (switch_channel_test_flag(channel, CF_ORIGINATOR)) {
-		switch_channel_clear_flag(channel, CF_ORIGINATOR);
-		if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_UNBRIDGE) == SWITCH_STATUS_SUCCESS) {
-			switch_channel_event_set_data(channel, event);
-			switch_event_fire(&event);
-		}
-	}
-
-	
-	if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BRIDGE_VARIABLE)) && (other_session = switch_core_session_locate(uuid))) {
-		switch_channel_t *other_channel = NULL;
-
-		other_channel = switch_core_session_get_channel(other_session);
-		assert(other_channel != NULL);
-
-		switch_channel_set_variable(channel, SWITCH_SIGNAL_BRIDGE_VARIABLE, NULL);
-		switch_channel_set_variable(other_channel, SWITCH_SIGNAL_BRIDGE_VARIABLE, NULL);
-
-		switch_channel_set_variable(channel, SWITCH_BRIDGE_VARIABLE, NULL);
-		switch_channel_set_variable(other_channel, SWITCH_BRIDGE_VARIABLE, NULL);
-
-		if (switch_channel_get_state(other_channel) < CS_HANGUP && 
-			switch_true(switch_channel_get_variable(other_channel, SWITCH_HANGUP_AFTER_BRIDGE_VARIABLE))) {
-			switch_channel_hangup(other_channel, switch_channel_get_cause(channel));
-		} else {
-			switch_channel_set_state(other_channel, CS_EXECUTE);
-		}
-		switch_core_session_rwunlock(other_session);
-	}
-
-	
-	return SWITCH_STATUS_SUCCESS;
-}
-
-static const switch_state_handler_table_t signal_bridge_state_handlers = {
-	/*.on_init */ NULL,
-	/*.on_ring */ NULL,
-	/*.on_execute */ NULL,
-	/*.on_hangup */ signal_bridge_on_hangup,
-	/*.on_loopback */ NULL,
-	/*.on_transmit */ NULL,
-	/*.on_hold */ NULL,
-	/*.on_hibernate*/ signal_bridge_on_hibernate
-};
-
-SWITCH_DECLARE(switch_status_t) switch_ivr_signal_bridge(switch_core_session_t *session, switch_core_session_t *peer_session)
-{
-	switch_channel_t *caller_channel, *peer_channel;
-	switch_event_t *event;
-
-	caller_channel = switch_core_session_get_channel(session);
-	assert(caller_channel != NULL);
-
-	peer_channel = switch_core_session_get_channel(peer_session);
-	assert(peer_channel != NULL);
-
-	if (!switch_channel_ready(peer_channel)) {
-		switch_channel_hangup(caller_channel, switch_channel_get_cause(peer_channel));
-		return SWITCH_STATUS_FALSE;
-	}
-
-	if (!switch_channel_ready(caller_channel)) {
-		switch_channel_hangup(peer_channel, SWITCH_CAUSE_ORIGINATOR_CANCEL);
-		return SWITCH_STATUS_FALSE;
-	}
-
-	switch_channel_set_variable(caller_channel, SWITCH_SIGNAL_BRIDGE_VARIABLE, switch_core_session_get_uuid(peer_session));
-	switch_channel_set_variable(peer_channel, SWITCH_SIGNAL_BRIDGE_VARIABLE, switch_core_session_get_uuid(session));
-
-	switch_channel_set_flag(caller_channel, CF_ORIGINATOR);
-	
-	switch_channel_clear_state_handler(caller_channel, NULL);
-	switch_channel_clear_state_handler(peer_channel, NULL);
-
-	switch_channel_add_state_handler(caller_channel, &signal_bridge_state_handlers);
-	switch_channel_add_state_handler(peer_channel, &signal_bridge_state_handlers);
-
-
-	/* fire events that will change the data table from "show channels" */
-	if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_EXECUTE) == SWITCH_STATUS_SUCCESS) {
-		switch_channel_event_set_data(caller_channel, event);
-		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Application", "signal_bridge");
-		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Application-Data", "%s", switch_core_session_get_uuid(peer_session));
-		switch_event_fire(&event);
-	}
-
-	if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_EXECUTE) == SWITCH_STATUS_SUCCESS) {
-		switch_channel_event_set_data(peer_channel, event);
-		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Application", "signal_bridge");
-		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Application-Data", "%s", switch_core_session_get_uuid(session));
-		switch_event_fire(&event);
-	}
-
-	if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_BRIDGE) == SWITCH_STATUS_SUCCESS) {
-		switch_channel_event_set_data(caller_channel, event);
-		switch_event_fire(&event);
-	}
-	
-	switch_channel_set_state_flag(caller_channel, CF_TRANSFER);
-	switch_channel_set_state_flag(peer_channel, CF_TRANSFER);
-
-
-	switch_channel_set_state(caller_channel, CS_HIBERNATE);
-	switch_channel_set_state(peer_channel, CS_HIBERNATE);
-
-	return SWITCH_STATUS_SUCCESS;
-}
-
-
-SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_session_t *session, 
-																 switch_core_session_t *peer_session,
-																 switch_input_callback_function_t input_callback,
-																 void *session_data,
-																 void *peer_session_data)
-	 
-
-															   
-{
-	switch_core_thread_session_t *this_audio_thread, *other_audio_thread;
-	switch_channel_t *caller_channel, *peer_channel;
-	int stream_id = 0;
-	switch_status_t status = SWITCH_STATUS_SUCCESS;
-	
-	caller_channel = switch_core_session_get_channel(session);
-	assert(caller_channel != NULL);
-
-	switch_channel_set_flag(caller_channel, CF_ORIGINATOR);
-
-	peer_channel = switch_core_session_get_channel(peer_session);
-	assert(peer_channel != NULL);
-
-	other_audio_thread = switch_core_session_alloc(peer_session, sizeof(switch_core_thread_session_t));
-	this_audio_thread = switch_core_session_alloc(peer_session, sizeof(switch_core_thread_session_t));
-
-	other_audio_thread->objs[0] = session;
-	other_audio_thread->objs[1] = peer_session;
-	other_audio_thread->objs[2] = &stream_id;
-	other_audio_thread->input_callback = input_callback;
-	other_audio_thread->objs[4] = session_data;
-	other_audio_thread->objs[5] = this_audio_thread;
-	other_audio_thread->running = 5;
-	switch_mutex_init(&other_audio_thread->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
-
-	this_audio_thread->objs[0] = peer_session;
-	this_audio_thread->objs[1] = session;
-	this_audio_thread->objs[2] = &stream_id;
-	this_audio_thread->input_callback = input_callback;
-	this_audio_thread->objs[4] = peer_session_data;
-	this_audio_thread->objs[5] = other_audio_thread;
-	this_audio_thread->running = 2;
-	switch_mutex_init(&this_audio_thread->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(peer_session));
-
-	switch_channel_add_state_handler(peer_channel, &audio_bridge_peer_state_handlers);
-
-	if (switch_channel_test_flag(peer_channel, CF_ANSWERED) && !switch_channel_test_flag(caller_channel, CF_ANSWERED)) {
-		switch_channel_answer(caller_channel);
-	}
-
-	if (switch_channel_test_flag(peer_channel, CF_ANSWERED) || switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA)) {
-		switch_event_t *event;
-		switch_core_session_message_t msg = {0};
-		
-		switch_channel_set_state(peer_channel, CS_HOLD);
-
-		if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_BRIDGE) == SWITCH_STATUS_SUCCESS) {
-			switch_channel_event_set_data(caller_channel, event);
-			switch_event_fire(&event);
-		}
-		
-		if (switch_core_session_read_lock(peer_session) == SWITCH_STATUS_SUCCESS) {
-			switch_channel_set_variable(caller_channel, SWITCH_BRIDGE_VARIABLE, switch_core_session_get_uuid(peer_session));
-			switch_channel_set_variable(peer_channel, SWITCH_BRIDGE_VARIABLE, switch_core_session_get_uuid(session));
-
-			msg.message_id = SWITCH_MESSAGE_INDICATE_BRIDGE;
-			msg.from = __FILE__;
-			msg.pointer_arg = session;
-
-			switch_core_session_receive_message(peer_session, &msg);
-
-			if (!msg.pointer_arg) {
-				status = SWITCH_STATUS_FALSE;
-				switch_core_session_rwunlock(peer_session);
-				goto done;
-			}
-
-			msg.pointer_arg = peer_session;
-			switch_core_session_receive_message(session, &msg);
-
-			if (!msg.pointer_arg) {
-				status = SWITCH_STATUS_FALSE;
-				switch_core_session_rwunlock(peer_session);
-				goto done;
-			}
-
-			
-			switch_channel_set_private(peer_channel, "_bridge_", other_audio_thread);
-			switch_channel_set_state(peer_channel, CS_LOOPBACK);
-			audio_bridge_thread(NULL, (void *) this_audio_thread);
-
-			if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_UNBRIDGE) == SWITCH_STATUS_SUCCESS) {
-				switch_channel_event_set_data(caller_channel, event);
-				switch_event_fire(&event);
-			}
-
-            this_audio_thread->objs[0] = NULL;
-			this_audio_thread->objs[1] = NULL;
-			this_audio_thread->objs[2] = NULL;
-			this_audio_thread->input_callback = NULL;
-			this_audio_thread->objs[4] = NULL;
-			this_audio_thread->objs[5] = NULL;
-			switch_mutex_lock(this_audio_thread->mutex);
-			this_audio_thread->running = 0;
-			switch_mutex_unlock(this_audio_thread->mutex);
-			
-			switch_channel_clear_flag(caller_channel, CF_ORIGINATOR);
-
-			if (other_audio_thread->running > 0) {
-				switch_mutex_lock(other_audio_thread->mutex);
-				other_audio_thread->running = -1;
-				switch_mutex_unlock(other_audio_thread->mutex);
-				while (other_audio_thread->running) {
-					switch_yield(1000);
-				}
-			}
-
-			switch_core_session_rwunlock(peer_session);
-			
-		} else {
-			status = SWITCH_STATUS_FALSE;
-		}
-	} else {
-		status = SWITCH_STATUS_FALSE;
-	}
-
-	if (status != SWITCH_STATUS_SUCCESS) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Bridge Failed %s->%s\n", 
-						  switch_channel_get_name(caller_channel),
-						  switch_channel_get_name(peer_channel)
-						  );
-		switch_channel_hangup(peer_channel, SWITCH_CAUSE_NO_ANSWER);
-	} 
-
- done:
-
-    if (switch_channel_get_state(caller_channel) < 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));
-    }
-
-	return status;
-}
-
-
-SWITCH_DECLARE(switch_status_t) switch_ivr_uuid_bridge(char *originator_uuid, char *originatee_uuid)
-{
-	switch_core_session_t *originator_session, *originatee_session;
-	switch_channel_t *originator_channel, *originatee_channel;
-	switch_status_t status = SWITCH_STATUS_FALSE;
-
-	if ((originator_session = switch_core_session_locate(originator_uuid))) {
-		if ((originatee_session = switch_core_session_locate(originatee_uuid))) { 
-			originator_channel = switch_core_session_get_channel(originator_session);
-			originatee_channel = switch_core_session_get_channel(originatee_session);
-
-			/* override transmit state for originator_channel to bridge to originatee_channel 
-			 * install pointer to originatee_session into originator_channel
-			 * set CF_TRANSFER on both channels and change state to CS_TRANSMIT to
-			 * inturrupt anything they are already doing.
-			 * originatee_session will fall asleep and originator_session will bridge to it
-			 */
-			
-			switch_channel_clear_state_handler(originator_channel, NULL);
-			switch_channel_clear_state_handler(originatee_channel, NULL);
-			switch_channel_set_flag(originator_channel, CF_ORIGINATOR);
-			switch_channel_add_state_handler(originator_channel, &uuid_bridge_state_handlers);
-			switch_channel_add_state_handler(originatee_channel, &uuid_bridge_state_handlers);
-			switch_channel_set_flag(originatee_channel, CF_TAGGED);
-			switch_channel_set_private(originator_channel, SWITCH_UUID_BRIDGE, originatee_session);
-
-			/* switch_channel_set_state_flag sets flags you want to be set when the next state change happens */
-			switch_channel_set_state_flag(originator_channel, CF_TRANSFER);
-			switch_channel_set_state_flag(originatee_channel, CF_TRANSFER);
-
-			/* release the read locks we have on the channels */
-			switch_core_session_rwunlock(originator_session);
-			switch_core_session_rwunlock(originatee_session);
-
-			/* change the states and let the chips fall where they may */
-			switch_channel_set_state(originator_channel, CS_TRANSMIT);
-			switch_channel_set_state(originatee_channel, CS_TRANSMIT);
-
-			status = SWITCH_STATUS_SUCCESS;
-			
-			while(switch_channel_get_state(originatee_channel) < CS_HANGUP && switch_channel_test_flag(originatee_channel, CF_TAGGED)) {
-				switch_yield(20000);
-			}
-		} else {
-			switch_core_session_rwunlock(originator_session);
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "no channel for originatee uuid %s\n", originatee_uuid);
-		}
-	} else {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "no channel for originator uuid %s\n", originator_uuid);
-	}
-
-	return status;
-
-}
-
-SWITCH_DECLARE(switch_status_t) switch_ivr_session_transfer(switch_core_session_t *session, char *extension, char *dialplan, char *context)
-{
-	switch_channel_t *channel;
-	switch_caller_profile_t *profile, *new_profile;
-	switch_core_session_message_t msg = {0};
-	switch_core_session_t *other_session;
-	switch_channel_t *other_channel = NULL;
-	char *uuid = NULL;
-
-	assert(session != NULL);
-	assert(extension != NULL);
-
-	switch_core_session_reset(session);
-
-
-	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
-
-	/* clear all state handlers */
-	switch_channel_clear_state_handler(channel, NULL);
-
-	if ((profile = switch_channel_get_caller_profile(channel))) {
-		new_profile = switch_caller_profile_clone(session, profile);
-		new_profile->destination_number = switch_core_session_strdup(session, extension);
-
-		if (!switch_strlen_zero(dialplan)) {
-			new_profile->dialplan = switch_core_session_strdup(session, dialplan);
-		} else {
-			dialplan = new_profile->dialplan;
-		}
-
-		if (!switch_strlen_zero(context)) {
-			new_profile->context = switch_core_session_strdup(session, context);
-		} else {
-			context = new_profile->context;
-		}
-
-		
-		switch_channel_set_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE, NULL);
-		if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE)) && (other_session = switch_core_session_locate(uuid))) {
-			switch_channel_set_variable(other_channel, SWITCH_SIGNAL_BOND_VARIABLE, NULL);
-			switch_core_session_rwunlock(other_session);
-		}
-
-		if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BRIDGE_VARIABLE)) && (other_session = switch_core_session_locate(uuid))) {
+		if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BRIDGE_VARIABLE))
+			&& (other_session = switch_core_session_locate(uuid))) {
 			other_channel = switch_core_session_get_channel(other_session);
 			assert(other_channel != NULL);
-			
+
 			switch_channel_set_variable(channel, SWITCH_SIGNAL_BRIDGE_VARIABLE, NULL);
 			switch_channel_set_variable(other_channel, SWITCH_SIGNAL_BRIDGE_VARIABLE, NULL);
 
@@ -3968,7 +565,7 @@
 
 			switch_channel_hangup(other_channel, SWITCH_CAUSE_BLIND_TRANSFER);
 			switch_ivr_media(uuid, SMF_NONE);
-			
+
 			switch_core_session_rwunlock(other_session);
 		}
 
@@ -3980,10 +577,10 @@
 		msg.from = __FILE__;
 		switch_core_session_receive_message(session, &msg);
 
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Transfer %s to %s[%s@%s]\n", 
-						  switch_channel_get_name(channel), dialplan, extension, context); 
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Transfer %s to %s[%s@%s]\n", switch_channel_get_name(channel), dialplan, extension,
+						  context);
 		return SWITCH_STATUS_SUCCESS;
-	} 
+	}
 
 	return SWITCH_STATUS_FALSE;
 }
@@ -4012,7 +609,7 @@
 
 		for (hi = switch_channel_variable_first(chana, switch_core_session_get_pool(sessa)); hi; hi = switch_hash_next(hi)) {
 			switch_hash_this(hi, &vvar, NULL, &vval);
-			if (vvar && vval && (!prefix || (var && !strncmp((char *)vvar, var, strlen(var))))) {
+			if (vvar && vval && (!prefix || (var && !strncmp((char *) vvar, var, strlen(var))))) {
 				switch_channel_set_variable(chanb, (char *) vvar, (char *) vval);
 			}
 		}
@@ -4038,10 +635,11 @@
 	switch_time_t last_digit_time;
 };
 
-SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_new(switch_memory_pool_t *pool, switch_ivr_digit_stream_parser_t **parser)
-{	switch_status_t status = SWITCH_STATUS_FALSE;
+SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_new(switch_memory_pool_t *pool, switch_ivr_digit_stream_parser_t ** parser)
+{
+	switch_status_t status = SWITCH_STATUS_FALSE;
 
-	if(parser != NULL) {
+	if (parser != NULL) {
 		int pool_auto_created = 0;
 
 		// if the caller didn't provide a pool, make one
@@ -4052,1210 +650,302 @@
 				pool_auto_created = 1;
 			}
 		}
-
 		// if we have a pool, make a parser object
 		if (pool != NULL) {
-			*parser = (switch_ivr_digit_stream_parser_t *)switch_core_alloc(pool,sizeof(switch_ivr_digit_stream_parser_t));
+			*parser = (switch_ivr_digit_stream_parser_t *) switch_core_alloc(pool, sizeof(switch_ivr_digit_stream_parser_t));
 		}
-
 		// if we have parser object, initialize it for the caller
 		if (*parser != NULL) {
-			memset(*parser,0,sizeof(switch_ivr_digit_stream_parser_t));
+			memset(*parser, 0, sizeof(switch_ivr_digit_stream_parser_t));
 			(*parser)->pool_auto_created = pool_auto_created;
 			(*parser)->pool = pool;
 			(*parser)->digit_timeout_ms = 1000;
-			switch_core_hash_init(&(*parser)->hash,(*parser)->pool);
+			switch_core_hash_init(&(*parser)->hash, (*parser)->pool);
 
 			status = SWITCH_STATUS_SUCCESS;
 		} else {
-			status = SWITCH_STATUS_MEMERR;
-			// if we can't create a parser object,clean up the pool if we created it
-			if (pool != NULL && pool_auto_created) {
-				switch_core_destroy_memory_pool(&pool);
-			}
-		}
-	}
-
-	return status;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_destroy(switch_ivr_digit_stream_parser_t *parser)
-{	switch_status_t status = SWITCH_STATUS_FALSE;
-
-	if (parser != NULL) {
-		if (parser->hash != NULL) {
-			switch_core_hash_destroy(parser->hash);
-			parser->hash = NULL;
-		}
-		// free the memory pool if we created it
-		if (parser->pool_auto_created && parser->pool != NULL) {
-			status = switch_core_destroy_memory_pool(&parser->pool);
-		}
-	}
-
-	return status;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_new(switch_ivr_digit_stream_parser_t *parser, switch_ivr_digit_stream_t **stream)
-{	switch_status_t status = SWITCH_STATUS_FALSE;
-
-	// if we have a paser object memory pool and a stream object pointer that is null
-	if (parser != NULL && parser->pool && stream != NULL && *stream == NULL) {
-		*stream = (switch_ivr_digit_stream_t *)switch_core_alloc(parser->pool,sizeof(switch_ivr_digit_stream_t));
-		if (*stream != NULL) {
-			memset(*stream,0,sizeof(switch_ivr_digit_stream_t));
-			status = SWITCH_STATUS_SUCCESS;
-		}
-	}
-
-	return status;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_destroy(switch_ivr_digit_stream_t *stream)
-{	switch_status_t status = SWITCH_STATUS_FALSE;
-
-	if (stream == NULL && stream->digits != NULL) {
-		free(stream->digits);
-		stream->digits = NULL;
-		status = SWITCH_STATUS_SUCCESS;
-	}
-
-	return status;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_set_event(switch_ivr_digit_stream_parser_t *parser, char *digits, void *data)
-{	switch_status_t status = SWITCH_STATUS_FALSE;
-
-	if (parser != NULL && digits != NULL && *digits && parser->hash != NULL) {
-
-		status = switch_core_hash_insert_dup(parser->hash,digits,data);
-		if (status == SWITCH_STATUS_SUCCESS) {
-			switch_size_t len = strlen(digits);
-
-			// if we don't have a terminator, then we have to try and
-			// figure out when a digit set is completed, therefore we
-			// keep track of the min and max digit lengths
-			if (parser->terminator == '\0') {
-				if (len > parser->maxlen) {
-					parser->maxlen = len;
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "max len %u\n", (uint32_t) parser->maxlen);
-				}
-				if (parser->minlen == 0 || len < parser->minlen) {
-					parser->minlen = len;
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "min len %u\n", (uint32_t) parser->minlen);
-				}
-			} else {
-				// since we have a terminator, reset min and max
-				parser->minlen = 0;
-				parser->maxlen = 0;
-			}
-
-		}
-	}
-	if (status != SWITCH_STATUS_SUCCESS) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "unable to add hash for '%s'\n",digits);
-	}
-
-	return status;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_del_event(switch_ivr_digit_stream_parser_t *parser, char *digits)
-{	switch_status_t status = SWITCH_STATUS_FALSE;
-
-	if (parser != NULL && digits != NULL && *digits) {
-		status = switch_core_hash_delete(parser->hash,digits);
-	}
-
-	if (status != SWITCH_STATUS_SUCCESS) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "unable to del hash for '%s'\n",digits);
-	}
-
-	return status;
-}
-
-SWITCH_DECLARE(void *) switch_ivr_digit_stream_parser_feed(switch_ivr_digit_stream_parser_t *parser, switch_ivr_digit_stream_t *stream, char digit)
-{	void *result = NULL;
-
-	if (parser != NULL && stream != NULL) {
-		switch_size_t len = (stream->digits != NULL ? strlen(stream->digits) : 0);
-
-		// handle new digit arrivals
-		if(digit != '\0') {
-
-			// if it's not a terminator digit, add it to the collected digits
-			if (digit != parser->terminator) {
-				// if collected digits length >= the max length of the keys
-				// in the hash table, then left shift the digit string
-				if (len > 0 && parser->maxlen != 0 && len >= parser->maxlen) {
-					char *src = stream->digits + 1;
-					char *dst = stream->digits;
-
-					while (*src) {
-						*(dst++) = *(src++);
-					}
-					*dst = digit;
-				} else {
-					stream->digits = realloc(stream->digits,len+2);
-					*(stream->digits+(len++)) = digit;
-					*(stream->digits+len) = '\0';
-					stream->last_digit_time = switch_time_now() / 1000;
-				}
-			}
-		}
-
-		// don't allow collected digit string testing if there are varying sized keys until timeout
-		if ( parser->maxlen - parser->minlen > 0
-			&& (switch_time_now() / 1000) - stream->last_digit_time < parser->digit_timeout_ms
-		) {
-			len = 0;
-		}
-
-		// if we have digits to test
-		if (len) {
-			result = switch_core_hash_find(parser->hash, stream->digits);
-			// if we matched the digit string, or this digit is the terminator
-			// reset the collected digits for next digit string
-			if (result != NULL || parser->terminator == digit) {
-				free(stream->digits);
-				stream->digits = NULL;
-			}
-		}
-}
-
-	return result;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_reset(switch_ivr_digit_stream_t *stream)
-{	switch_status_t status = SWITCH_STATUS_FALSE;
-
-	if (stream != NULL && stream->digits != NULL) {
-		free(stream->digits);
-		stream->digits = NULL;
-		stream->last_digit_time = 0;
-		status = SWITCH_STATUS_SUCCESS;
-	}
-
-	return status;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_set_terminator(switch_ivr_digit_stream_parser_t *parser, char digit)
-{	switch_status_t status = SWITCH_STATUS_FALSE;
-
-	if (parser != NULL) {
-		parser->terminator = digit;
-		// since we have a terminator, reset min and max
-		parser->minlen = 0;
-		parser->maxlen = 0;
-		status = SWITCH_STATUS_SUCCESS;
-	}
-
-	return status;
-}
-
-/******************************************************************************************************/
-
-struct switch_ivr_menu_action;
-
-struct switch_ivr_menu {
-	char *name;
-	char *greeting_sound;
-	char *short_greeting_sound;
-	char *invalid_sound;
-	char *exit_sound;
-	char *tts_engine;
-	char *tts_voice;
-	char *phrase_lang;
-	char *buf;
-	char *ptr;
-	int max_failures;
-	int timeout;
-	uint32_t inlen;
-	uint32_t flags;
-	struct switch_ivr_menu_action *actions;
-	struct switch_ivr_menu *next;
-	switch_memory_pool_t *pool;
-};
-
-struct switch_ivr_menu_action {
-	switch_ivr_menu_action_function_t *function;
-	switch_ivr_action_t ivr_action;
-	char *arg;
-	char *bind;
-	struct switch_ivr_menu_action *next;
-};
-
-static switch_ivr_menu_t *switch_ivr_menu_find(switch_ivr_menu_t *stack, const char *name) {
-	switch_ivr_menu_t *ret;
-	for(ret = stack; ret ; ret = ret->next) {
-		if (!name || !strcmp(ret->name, name))
-			break;
-	}
-	return ret;
-}
-
-static void switch_ivr_menu_stack_add(switch_ivr_menu_t **top, switch_ivr_menu_t *bottom) 
-{
-	switch_ivr_menu_t *ptr;
-
-	for(ptr = *top ; ptr && ptr->next ; ptr = ptr->next);
-
-	if (ptr) {
-		ptr->next = bottom;
-	} else {
-		*top = bottom;
-	}
-
-}
-
-SWITCH_DECLARE(switch_status_t) switch_ivr_menu_init(switch_ivr_menu_t **new_menu,
-													 switch_ivr_menu_t *main,
-													 const char *name, 
-													 const char *greeting_sound, 
-													 const char *short_greeting_sound,
-													 const char *invalid_sound, 
-													 const char *exit_sound,
-													 const char *tts_engine,
-													 const char *tts_voice,
-													 const char *phrase_lang,
-													 int timeout,
-													 int max_failures, 
-													 switch_memory_pool_t *pool)
-{
-	switch_ivr_menu_t *menu;
-	uint8_t newpool = 0;
-
-	if (!pool) {
-		if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "OH OH no pool\n");
-			return SWITCH_STATUS_MEMERR;
-		}
-		newpool = 1;
-	}
-	
-	if (!(menu = switch_core_alloc(pool, sizeof(*menu)))) {
-		if (newpool) {
-			switch_core_destroy_memory_pool(&pool);
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
-			return SWITCH_STATUS_MEMERR;
-		}
-	}
-
-	menu->pool = pool;
-
-	if (!switch_strlen_zero(name)) {
-		menu->name = switch_core_strdup(menu->pool, name);
-	}
-
-	if (!switch_strlen_zero(greeting_sound)) {
-		menu->greeting_sound = switch_core_strdup(menu->pool, greeting_sound);
-	}
-
-	if (!switch_strlen_zero(short_greeting_sound)) {
-		menu->short_greeting_sound = switch_core_strdup(menu->pool, short_greeting_sound);
-	}
-
-	if (!switch_strlen_zero(invalid_sound)) {
-		menu->invalid_sound = switch_core_strdup(menu->pool, invalid_sound);
-	}
-
-	if (!switch_strlen_zero(exit_sound)) {
-		menu->exit_sound = switch_core_strdup(menu->pool, exit_sound);
-	}
-
-	if (!switch_strlen_zero(tts_engine)) {
-		menu->tts_engine = switch_core_strdup(menu->pool, tts_engine);
-	}
-
-	if (!switch_strlen_zero(tts_voice)) {
-		menu->tts_voice = switch_core_strdup(menu->pool, tts_voice);
-	}
-
-	if (!switch_strlen_zero(phrase_lang)) {
-		menu->phrase_lang = switch_core_strdup(menu->pool, phrase_lang);
-	}
-
-	menu->max_failures = max_failures;
-
-	menu->timeout = timeout;
-
-	menu->actions = NULL;
-
-	if (newpool) {
-		menu->flags |= SWITCH_IVR_MENU_FLAG_FREEPOOL;
-	}
-
-	if (menu->timeout <= 0) {
-		menu->timeout = 10000;
+			status = SWITCH_STATUS_MEMERR;
+			// if we can't create a parser object,clean up the pool if we created it
+			if (pool != NULL && pool_auto_created) {
+				switch_core_destroy_memory_pool(&pool);
+			}
+		}
 	}
 
-	if (main) {
-		switch_ivr_menu_stack_add(&main, menu);
-	} else {
-		menu->flags |= SWITCH_IVR_MENU_FLAG_STACK;
-	}
-	
-	*new_menu = menu;
-	
-	return SWITCH_STATUS_SUCCESS;
+	return status;
 }
 
-SWITCH_DECLARE(switch_status_t) switch_ivr_menu_bind_action(switch_ivr_menu_t *menu, switch_ivr_action_t ivr_action, const char *arg, const char *bind)
+SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_destroy(switch_ivr_digit_stream_parser_t * parser)
 {
-	switch_ivr_menu_action_t *action;
-	uint32_t len;
+	switch_status_t status = SWITCH_STATUS_FALSE;
 
-	if ((action = switch_core_alloc(menu->pool, sizeof(*action)))) {
-		action->bind = switch_core_strdup(menu->pool, bind);
-		action->next = menu->actions;
-		action->arg = switch_core_strdup(menu->pool, arg);
-		len = (uint32_t)strlen(action->bind) + 1;
-		if (len > menu->inlen) {
-			menu->inlen = len;
+	if (parser != NULL) {
+		if (parser->hash != NULL) {
+			switch_core_hash_destroy(parser->hash);
+			parser->hash = NULL;
+		}
+		// free the memory pool if we created it
+		if (parser->pool_auto_created && parser->pool != NULL) {
+			status = switch_core_destroy_memory_pool(&parser->pool);
 		}
-		action->ivr_action = ivr_action;
-		menu->actions = action;
-		return SWITCH_STATUS_SUCCESS;
 	}
 
-	return SWITCH_STATUS_MEMERR;
+	return status;
 }
 
-SWITCH_DECLARE(switch_status_t) switch_ivr_menu_bind_function(switch_ivr_menu_t *menu, switch_ivr_menu_action_function_t *function, const char *arg, const char *bind)
+SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_new(switch_ivr_digit_stream_parser_t * parser, switch_ivr_digit_stream_t ** stream)
 {
-	switch_ivr_menu_action_t *action;
-	uint32_t len;
+	switch_status_t status = SWITCH_STATUS_FALSE;
 
-	if ((action = switch_core_alloc(menu->pool, sizeof(*action)))) {
-		action->bind = switch_core_strdup(menu->pool,bind);
-		action->next = menu->actions;
-		action->arg = switch_core_strdup(menu->pool, arg);
-		len = (uint32_t)strlen(action->bind) + 1;
-		if (len > menu->inlen) {
-			menu->inlen = len;
+	// if we have a paser object memory pool and a stream object pointer that is null
+	if (parser != NULL && parser->pool && stream != NULL && *stream == NULL) {
+		*stream = (switch_ivr_digit_stream_t *) switch_core_alloc(parser->pool, sizeof(switch_ivr_digit_stream_t));
+		if (*stream != NULL) {
+			memset(*stream, 0, sizeof(switch_ivr_digit_stream_t));
+			status = SWITCH_STATUS_SUCCESS;
 		}
-		action->function = function;
-		menu->actions = action;
-		return SWITCH_STATUS_SUCCESS;
 	}
 
-	return SWITCH_STATUS_MEMERR;
+	return status;
 }
 
-SWITCH_DECLARE(switch_status_t) switch_ivr_menu_stack_free(switch_ivr_menu_t *stack) 
+SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_destroy(switch_ivr_digit_stream_t * stream)
 {
 	switch_status_t status = SWITCH_STATUS_FALSE;
 
-	if (stack != NULL && stack->pool != NULL) {
-		if (switch_test_flag(stack, SWITCH_IVR_MENU_FLAG_STACK) && switch_test_flag(stack, SWITCH_IVR_MENU_FLAG_FREEPOOL)) {
-			switch_memory_pool_t *pool = stack->pool;
-			status = switch_core_destroy_memory_pool(&pool);
-		} else {
-			status = SWITCH_STATUS_SUCCESS;
-		}
+	if (stream == NULL && stream->digits != NULL) {
+		free(stream->digits);
+		stream->digits = NULL;
+		status = SWITCH_STATUS_SUCCESS;
 	}
 
 	return status;
 }
 
-static switch_status_t play_or_say(switch_core_session_t *session, switch_ivr_menu_t *menu, char *sound, uint32_t need)
+SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_set_event(switch_ivr_digit_stream_parser_t * parser, char *digits, void *data)
 {
-	char terminator;
-	uint32_t len;
-	char *ptr;
 	switch_status_t status = SWITCH_STATUS_FALSE;
-	switch_input_args_t args= {0};
 
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "play_or_say sound=[%s]\n",sound);
-
-	if (session != NULL && menu != NULL && !switch_strlen_zero(sound)) {
-		memset(menu->buf, 0, menu->inlen);
-		menu->ptr = menu->buf;
+	if (parser != NULL && digits != NULL && *digits && parser->hash != NULL) {
 
-		if (!need) {
-			len = 1;
-			ptr = NULL;
-		} else {
-			len = menu->inlen;
-			ptr = menu->ptr;
-		}
-		args.buf = ptr;
-		args.buflen = len;
+		status = switch_core_hash_insert_dup(parser->hash, digits, data);
+		if (status == SWITCH_STATUS_SUCCESS) {
+			switch_size_t len = strlen(digits);
 
-		if (*sound == '/' || *sound == '\\') {
-			status = switch_ivr_play_file(session, NULL, sound, &args);
-		} else {
-			if (strlen(sound) > 4 && strncmp(sound, "say:", 4) == 0) {
-				if (menu->tts_engine && menu->tts_voice) {
-					status = switch_ivr_speak_text(session, menu->tts_engine, menu->tts_voice, 0, sound+4, &args);
-				} else {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No TTS engine to play sound\n");
+			// if we don't have a terminator, then we have to try and
+			// figure out when a digit set is completed, therefore we
+			// keep track of the min and max digit lengths
+			if (parser->terminator == '\0') {
+				if (len > parser->maxlen) {
+					parser->maxlen = len;
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "max len %u\n", (uint32_t) parser->maxlen);
 				}
-			} else {
-				if (strlen(sound) > 7 && strncmp(sound, "phrase:", 7) == 0) {
-						status = switch_ivr_phrase_macro(session, sound+7, "", menu->phrase_lang, &args);
-				} else {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "play_or_say: no player for [%s]. Use say: or phrase:\n", sound);
+				if (parser->minlen == 0 || len < parser->minlen) {
+					parser->minlen = len;
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "min len %u\n", (uint32_t) parser->minlen);
 				}
+			} else {
+				// since we have a terminator, reset min and max
+				parser->minlen = 0;
+				parser->maxlen = 0;
 			}
-		}
 
-		if (need) {
-			menu->ptr += strlen(menu->buf);
-			if (strlen(menu->buf) < need) {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "waiting for %u digits\n",need);
-				status = switch_ivr_collect_digits_count(session, menu->ptr, menu->inlen - strlen(menu->buf), need, "#", &terminator, menu->timeout);
-			}
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "digits '%s'\n",menu->buf);
 		}
 	}
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "play_or_say returning [%d]\n",status);
+	if (status != SWITCH_STATUS_SUCCESS) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "unable to add hash for '%s'\n", digits);
+	}
 
 	return status;
 }
 
-SWITCH_DECLARE(switch_status_t) switch_ivr_menu_execute(switch_core_session_t *session, switch_ivr_menu_t *stack, char *name, void *obj)
+SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_del_event(switch_ivr_digit_stream_parser_t * parser, char *digits)
 {
-	int reps = 0, errs = 0, match = 0, running = 1;
-	char *greeting_sound = NULL, *aptr = NULL;
-	char arg[512];
-	switch_ivr_action_t todo = SWITCH_IVR_ACTION_DIE;
-	switch_ivr_menu_action_t *ap;
-	switch_ivr_menu_t *menu;
-	switch_channel_t *channel;
-	switch_status_t status = SWITCH_STATUS_SUCCESS;
+	switch_status_t status = SWITCH_STATUS_FALSE;
 
-	if (session == NULL || stack == NULL || switch_strlen_zero(name)) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid menu context\n");
-		return SWITCH_STATUS_FALSE;
+	if (parser != NULL && digits != NULL && *digits) {
+		status = switch_core_hash_delete(parser->hash, digits);
 	}
 
-	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
-
-	if (!(menu = switch_ivr_menu_find(stack, name))) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Menu!\n");
-		return SWITCH_STATUS_FALSE;
-	}
-	
-	if (!(menu->buf = malloc(menu->inlen))) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Memory!\n");
-		return SWITCH_STATUS_FALSE;
+	if (status != SWITCH_STATUS_SUCCESS) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "unable to del hash for '%s'\n", digits);
 	}
-	
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Executing IVR menu %s\n", menu->name);
-
-	for (reps = 0 ; (running && status == SWITCH_STATUS_SUCCESS && errs < menu->max_failures) ; reps++) {
-		if (!switch_channel_ready(channel)) {
-			break;
-		}
 
-		if (reps > 0 && menu->short_greeting_sound) {
-			greeting_sound = menu->short_greeting_sound;
-		} else {
-			greeting_sound = menu->greeting_sound;
-		}
-
-		match = 0;
-		aptr = NULL;
+	return status;
+}
 
-		memset(arg, 0, sizeof(arg));
+SWITCH_DECLARE(void *) switch_ivr_digit_stream_parser_feed(switch_ivr_digit_stream_parser_t * parser, switch_ivr_digit_stream_t * stream, char digit)
+{
+	void *result = NULL;
 
-		memset(menu->buf, 0, menu->inlen);
-		status = play_or_say(session, menu, greeting_sound, menu->inlen - 1);
-
-		if (!switch_strlen_zero(menu->buf)) {
-			for(ap = menu->actions; ap ; ap = ap->next) {
-				if (!strcmp(menu->buf, ap->bind)) {
-					char *membuf;
-                    
-					match++;
-					errs = 0;
-					if (ap->function) {
-						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "IVR function on menu '%s' matched '%s' param '%s'\n", menu->name, menu->buf, ap->arg);
-						todo = ap->function(menu, ap->arg, arg, sizeof(arg), obj);
-						aptr = arg;
-					} else {
-						todo = ap->ivr_action;
-						aptr = ap->arg;
-						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "IVR action on menu '%s' matched '%s' param '%s'\n", menu->name, menu->buf,aptr);
-					}
+	if (parser != NULL && stream != NULL) {
+		switch_size_t len = (stream->digits != NULL ? strlen(stream->digits) : 0);
 
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "switch_ivr_menu_execute todo=[%d]\n", todo);
+		// handle new digit arrivals
+		if (digit != '\0') {
 
-					switch(todo) {
-					case SWITCH_IVR_ACTION_DIE:
-						status = SWITCH_STATUS_FALSE;
-						break;
-					case SWITCH_IVR_ACTION_PLAYSOUND:
-						status = switch_ivr_play_file(session, NULL, aptr, NULL);
-						break;
-					case SWITCH_IVR_ACTION_SAYTEXT:
-						status = switch_ivr_speak_text(session, menu->tts_engine, menu->tts_voice, 0, aptr, NULL);
-						break;
-					case SWITCH_IVR_ACTION_SAYPHRASE:
-						status = switch_ivr_phrase_macro(session, aptr, "", menu->phrase_lang, NULL);
-						break;
-					case SWITCH_IVR_ACTION_TRANSFER:
-						switch_ivr_session_transfer(session, aptr, NULL, NULL);
-						running = 0;
-						break;
-					case SWITCH_IVR_ACTION_EXECMENU:
-						reps = -1;
-						status = switch_ivr_menu_execute(session, stack, aptr, obj);
-						break;
-					case SWITCH_IVR_ACTION_EXECAPP: {
-						const switch_application_interface_t *application_interface;
+			// if it's not a terminator digit, add it to the collected digits
+			if (digit != parser->terminator) {
+				// if collected digits length >= the max length of the keys
+				// in the hash table, then left shift the digit string
+				if (len > 0 && parser->maxlen != 0 && len >= parser->maxlen) {
+					char *src = stream->digits + 1;
+					char *dst = stream->digits;
 
-						if ((membuf = strdup(aptr))) {
-							char *app_name = membuf;
-							char *app_arg = strchr(app_name, ' ');
-
-							if (app_arg) {
-								*app_arg = '\0';
-								app_arg++;
-							}
-
-							if (app_name && app_arg) {
-								if ((application_interface = switch_loadable_module_get_application_interface(app_name))) {
-									if (application_interface->application_function) {
-										application_interface->application_function(session, app_arg);
-									}
-								}
-							}
-						}
-					}
-						break;
-					case SWITCH_IVR_ACTION_BACK:
-						running = 0;
-						status = SWITCH_STATUS_SUCCESS;
-						break;
-					case SWITCH_IVR_ACTION_TOMAIN:
-						switch_set_flag(stack, SWITCH_IVR_MENU_FLAG_FALLTOMAIN);
-						status = SWITCH_STATUS_BREAK;
-						break;
-					case SWITCH_IVR_ACTION_NOOP:
-						status = SWITCH_STATUS_SUCCESS;
-						break;
-					default:
-						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid TODO!\n");
-						break;
+					while (*src) {
+						*(dst++) = *(src++);
 					}
-				}
-			}
-
-
-			if (switch_test_flag(menu, SWITCH_IVR_MENU_FLAG_STACK)) { // top level
-				if (switch_test_flag(stack, SWITCH_IVR_MENU_FLAG_FALLTOMAIN)) { // catch the fallback and recover
-					switch_clear_flag(stack, SWITCH_IVR_MENU_FLAG_FALLTOMAIN);
-					status = SWITCH_STATUS_SUCCESS;
-					running = 1;
-					continue;
+					*dst = digit;
+				} else {
+					stream->digits = realloc(stream->digits, len + 2);
+					*(stream->digits + (len++)) = digit;
+					*(stream->digits + len) = '\0';
+					stream->last_digit_time = switch_time_now() / 1000;
 				}
 			}
 		}
-		if (!match) {
-			if (*menu->buf) {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "IVR menu '%s' caught invalid input '%s'\n", menu->name, menu->buf);
-				if (menu->invalid_sound) {
-					play_or_say(session, menu, menu->invalid_sound, 0);
-				}
-			}
-			else {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "IVR menu '%s' no input detected\n", menu->name);
-			}
-			errs++;
-			if (status == SWITCH_STATUS_SUCCESS) {
-				status = switch_ivr_sleep(session, 1000);
-			}
-			/* breaks are ok too */
-			if (SWITCH_STATUS_IS_BREAK(status)) {
-				status = SWITCH_STATUS_SUCCESS;
+		// don't allow collected digit string testing if there are varying sized keys until timeout
+		if (parser->maxlen - parser->minlen > 0 && (switch_time_now() / 1000) - stream->last_digit_time < parser->digit_timeout_ms) {
+			len = 0;
+		}
+		// if we have digits to test
+		if (len) {
+			result = switch_core_hash_find(parser->hash, stream->digits);
+			// if we matched the digit string, or this digit is the terminator
+			// reset the collected digits for next digit string
+			if (result != NULL || parser->terminator == digit) {
+				free(stream->digits);
+				stream->digits = NULL;
 			}
 		}
 	}
 
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "exit-sound '%s'\n",menu->exit_sound);
-	if (!switch_strlen_zero(menu->exit_sound)) {
-		play_or_say(session, menu, menu->exit_sound, 0);
-	}
-
-	switch_safe_free(menu->buf);
-
-	return status;
+	return result;
 }
 
-/******************************************************************************************************/
-
-typedef struct switch_ivr_menu_xml_map {
-	char *name;
-	switch_ivr_action_t action;
-	switch_ivr_menu_action_function_t *function;
-	struct switch_ivr_menu_xml_map *next;
-} switch_ivr_menu_xml_map_t;
-
-struct switch_ivr_menu_xml_ctx {
-	switch_memory_pool_t *pool;
-	struct switch_ivr_menu_xml_map *map;
-	int autocreated;
-};
-
-static switch_ivr_menu_xml_map_t *switch_ivr_menu_stack_xml_find(switch_ivr_menu_xml_ctx_t *xml_ctx, char *name)
+SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_reset(switch_ivr_digit_stream_t * stream)
 {
-	switch_ivr_menu_xml_map_t *map = (xml_ctx != NULL ? xml_ctx->map : NULL);
-	int rc = -1;
+	switch_status_t status = SWITCH_STATUS_FALSE;
 
-	while (map != NULL && (rc = strcasecmp(map->name,name)) != 0) {
-		map =  map->next;
+	if (stream != NULL && stream->digits != NULL) {
+		free(stream->digits);
+		stream->digits = NULL;
+		stream->last_digit_time = 0;
+		status = SWITCH_STATUS_SUCCESS;
 	}
 
-	return (rc == 0 ? map : NULL);
+	return status;
 }
 
-static switch_status_t switch_ivr_menu_stack_xml_add(switch_ivr_menu_xml_ctx_t *xml_ctx, char*name, int action, switch_ivr_menu_action_function_t *function)
+SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_set_terminator(switch_ivr_digit_stream_parser_t * parser, char digit)
 {
 	switch_status_t status = SWITCH_STATUS_FALSE;
 
-	// if this action/function does not exist yet
-	if (xml_ctx != NULL && name != NULL && xml_ctx->pool != NULL && switch_ivr_menu_stack_xml_find(xml_ctx,name) == NULL) {
-		switch_ivr_menu_xml_map_t *map = switch_core_alloc(xml_ctx->pool,sizeof(switch_ivr_menu_xml_map_t));
-
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "switch_ivr_menu_stack_xml_add bindng '%s'\n",name);
-		// and we have memory
-		if (map != NULL) {
-			map->name = switch_core_strdup(xml_ctx->pool,name);
-			map->action = action;
-			map->function = function;
-
-			if (map->name != NULL) {
-				// insert map item at top of list
-				map->next = xml_ctx->map;
-				xml_ctx->map = map;
-				status = SWITCH_STATUS_SUCCESS;
-			} else {
-				status = SWITCH_STATUS_MEMERR;
-			}
-		} else {
-			status = SWITCH_STATUS_MEMERR;
-		}
+	if (parser != NULL) {
+		parser->terminator = digit;
+		// since we have a terminator, reset min and max
+		parser->minlen = 0;
+		parser->maxlen = 0;
+		status = SWITCH_STATUS_SUCCESS;
 	}
 
 	return status;
 }
 
-SWITCH_DECLARE(switch_status_t) switch_ivr_menu_stack_xml_init(switch_ivr_menu_xml_ctx_t **xml_menu_ctx, switch_memory_pool_t *pool)
+static int set_profile_data(switch_xml_t xml, switch_caller_profile_t *caller_profile, int off)
 {
-	switch_status_t status	= SWITCH_STATUS_FALSE;
-	int autocreated = 0;
+	switch_xml_t param;
 
-	// build a memory pool ?
-	if (pool == NULL) {
-		status = switch_core_new_memory_pool(&pool);
-		autocreated = 1;
-	}
-
-	// allocate the xml context
-	if (xml_menu_ctx != NULL && pool != NULL) {
-		*xml_menu_ctx = switch_core_alloc(pool,sizeof(switch_ivr_menu_xml_ctx_t));
-		if (*xml_menu_ctx != NULL) {
-			(*xml_menu_ctx)->pool = pool;
-			(*xml_menu_ctx)->autocreated = autocreated;
-			(*xml_menu_ctx)->map = NULL;
-			status = SWITCH_STATUS_SUCCESS;
-		} else {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to alloc xml_ctx\n");
-			status = SWITCH_STATUS_FALSE;
-		}
+	if (!(param = switch_xml_add_child_d(xml, "username", off++))) {
+		return -1;
 	}
+	switch_xml_set_txt(param, caller_profile->username);
 
-	// build the standard/default xml menu handler mappings
-	if (status == SWITCH_STATUS_SUCCESS && xml_menu_ctx != NULL && *xml_menu_ctx != NULL) {
-		struct iam_s {
-			char *name;
-			switch_ivr_action_t action;
-		} iam [] = {
-			{"menu-exit",		SWITCH_IVR_ACTION_DIE},
-			{"menu-sub",		SWITCH_IVR_ACTION_EXECMENU},
-			{"menu-exec-api",	SWITCH_IVR_ACTION_EXECAPP},
-			{"menu-play-sound",	SWITCH_IVR_ACTION_PLAYSOUND},
-			{"menu-say-text",	SWITCH_IVR_ACTION_SAYTEXT},
-			{"menu-say-phrase",	SWITCH_IVR_ACTION_SAYPHRASE},
-			{"menu-back",		SWITCH_IVR_ACTION_BACK},
-			{"menu-top",		SWITCH_IVR_ACTION_TOMAIN},
-			{"menu-call-transfer",	SWITCH_IVR_ACTION_TRANSFER},
-		};
-		int iam_qty = (sizeof(iam)/sizeof(iam[0]));
-		int i;
-
-		for(i=0; i<iam_qty && status == SWITCH_STATUS_SUCCESS; i++) {
-			status = switch_ivr_menu_stack_xml_add(*xml_menu_ctx,iam[i].name,iam[i].action,NULL);
-		}
+	if (!(param = switch_xml_add_child_d(xml, "dialplan", off++))) {
+		return -1;
 	}
+	switch_xml_set_txt(param, caller_profile->dialplan);
 
-	return status;
-}
-
-SWITCH_DECLARE(switch_status_t) switch_ivr_menu_stack_xml_add_custom(switch_ivr_menu_xml_ctx_t *xml_menu_ctx, char *name, switch_ivr_menu_action_function_t *function)
-{	
-	return switch_ivr_menu_stack_xml_add(xml_menu_ctx, name, -1, function);
-}
-
-SWITCH_DECLARE(switch_status_t) switch_ivr_menu_stack_xml_build(switch_ivr_menu_xml_ctx_t *xml_menu_ctx,
-                                                                switch_ivr_menu_t **menu_stack,
-                                                                switch_xml_t xml_menus,
-                                                                switch_xml_t xml_menu)
-
-{
-	switch_status_t status	= SWITCH_STATUS_FALSE;
-
-	if (xml_menu_ctx != NULL && menu_stack  != NULL && xml_menu != NULL) {
-		const char *menu_name		= switch_xml_attr_soft(xml_menu,"name");		// if the attr doesn't exist, return ""
-		const char *greet_long	= switch_xml_attr(xml_menu,"greet-long");		// if the attr doesn't exist, return NULL
-		const char *greet_short	= switch_xml_attr(xml_menu,"greet-short");		// if the attr doesn't exist, return NULL
-		const char *invalid_sound	= switch_xml_attr(xml_menu,"invalid-sound");		// if the attr doesn't exist, return NULL
-		const char *exit_sound	= switch_xml_attr(xml_menu,"exit-sound");		// if the attr doesn't exist, return NULL
-		const char *tts_engine	= switch_xml_attr(xml_menu,"tts-engine");		// if the attr doesn't exist, return NULL
-		const char *tts_voice		= switch_xml_attr(xml_menu,"tts-voice");		// if the attr doesn't exist, return NULL
-		const char *phrase_lang		= switch_xml_attr(xml_menu,"phrase-lang");		// if the attr doesn't exist, return NULL
-		const char *timeout		= switch_xml_attr_soft(xml_menu,"timeout");		// if the attr doesn't exist, return ""
-		const char *max_failures	= switch_xml_attr_soft(xml_menu,"max-failures");	// if the attr doesn't exist, return ""
-		switch_ivr_menu_t *menu	= NULL;
-
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "building menu '%s'\n",menu_name);
-		status = switch_ivr_menu_init(&menu,
-									*menu_stack,
-									menu_name,
-									greet_long,
-									greet_short,
-									invalid_sound,
-									exit_sound,
-									tts_engine,
-									tts_voice,
-									phrase_lang,
-									atoi(timeout)*1000,
-									atoi(max_failures),
-									xml_menu_ctx->pool
-									);
-		// set the menu_stack for the caller
-		if (status == SWITCH_STATUS_SUCCESS && *menu_stack == NULL) {
-			*menu_stack = menu;
-		}
-
-		if (status == SWITCH_STATUS_SUCCESS && menu != NULL) {
-			switch_xml_t xml_kvp;
-
-			// build menu entries
-			for(xml_kvp = switch_xml_child(xml_menu, "entry"); xml_kvp != NULL && status == SWITCH_STATUS_SUCCESS; xml_kvp = xml_kvp->next) {
-				const char *action	= switch_xml_attr(xml_kvp, "action");
-				const char *digits	= switch_xml_attr(xml_kvp, "digits");
-				const char *param	= switch_xml_attr_soft(xml_kvp, "param");
-
-				if (!switch_strlen_zero(action) && !switch_strlen_zero(digits)) {
-					switch_ivr_menu_xml_map_t *xml_map = xml_menu_ctx->map;
-					int found = 0;
-
-					// find and appropriate xml handler
-					while(xml_map != NULL && !found) {
-						if (!(found = (strcasecmp(xml_map->name,action) == 0))) {
-							xml_map = xml_map->next;
-						}
-					}
-
-					if (found && xml_map != NULL) {
-						// do we need to build a new sub-menu ?
-						if (xml_map->action == SWITCH_IVR_ACTION_EXECMENU && switch_ivr_menu_find(*menu_stack, param) == NULL) {
-							if ((xml_menu = switch_xml_find_child(xml_menus, "menu", "name", param)) != NULL) {
-								status = switch_ivr_menu_stack_xml_build(xml_menu_ctx, menu_stack, xml_menus, xml_menu);
-							}
-						}
-
-						// finally bind the menu entry
-						if (status == SWITCH_STATUS_SUCCESS) {
-							if (xml_map->function != NULL) {
-								switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
-									"binding menu caller control '%s'/'%s' to '%s'\n", xml_map->name, param, digits);
-								status = switch_ivr_menu_bind_function(menu, xml_map->function, param, digits);
-							} else {
-								switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
-									"binding menu action '%s' to '%s'\n", xml_map->name, digits);
-								status = switch_ivr_menu_bind_action(menu, xml_map->action, param, digits);
-							}
-						}
-					}
-				} else {
-					status = SWITCH_STATUS_FALSE;
-				}
-			}
-		}
+	if (!(param = switch_xml_add_child_d(xml, "caller_id_name", off++))) {
+		return -1;
 	}
+	switch_xml_set_txt(param, caller_profile->caller_id_name);
 
-	if (status != SWITCH_STATUS_SUCCESS) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to build xml menu\n");
+	if (!(param = switch_xml_add_child_d(xml, "ani", off++))) {
+		return -1;
 	}
+	switch_xml_set_txt(param, caller_profile->ani);
 
-	return status;
-}
-
-
-static char *SAY_METHOD_NAMES[] = {
-    "N/A",
-    "PRONOUNCED",
-    "ITERATED",
-    "COUNTED",
-    NULL
-};
-
-static char *SAY_TYPE_NAMES[] = {
-	"NUMBER",
-	"ITEMS",
-	"PERSONS",
-	"MESSAGES",
-	"CURRENCY",
-	"TIME_MEASUREMENT",
-	"CURRENT_DATE",
-	"CURRENT_TIME",
-	"CURRENT_DATE_TIME",
-	"TELEPHONE_NUMBER",
-	"TELEPHONE_EXTENSION",
-	"URL",
-    "IP_ADDRESS",
-	"EMAIL_ADDRESS",
-	"POSTAL_ADDRESS",
-	"ACCOUNT_NUMBER",
-	"NAME_SPELLED",
-	"NAME_PHONETIC",
-    NULL
-};
-
-
-static switch_say_method_t get_say_method_by_name(char *name)
-{
-    int x = 0;
-    for (x = 0; SAY_METHOD_NAMES[x]; x++) {
-        if (!strcasecmp(SAY_METHOD_NAMES[x], name)) {
-            break;
-        }
-    }
-
-    return (switch_say_method_t) x;
-}
-
-static switch_say_method_t get_say_type_by_name(char *name)
-{
-    int x = 0;
-    for (x = 0; SAY_TYPE_NAMES[x]; x++) {
-        if (!strcasecmp(SAY_TYPE_NAMES[x], name)) {
-            break;
-        }
-    }
-    
-    return (switch_say_method_t) x;
-}
-
-
-SWITCH_DECLARE(switch_status_t) switch_ivr_phrase_macro(switch_core_session_t *session,
-                                                        char *macro_name,
-                                                        char *data,
-                                                        char *lang,
-                                                        switch_input_args_t *args)
-
-{
-	switch_xml_t cfg, xml = NULL, language, macros, macro, input, action;
-    char *lname = NULL, *mname = NULL, hint_data[1024] = "", enc_hint[1024] = "";
-    switch_status_t status = SWITCH_STATUS_GENERR;
-    char *old_sound_prefix = NULL, *sound_path = NULL, *tts_engine = NULL, *tts_voice = NULL, *chan_lang = NULL; 
-    switch_channel_t *channel;
-    uint8_t done = 0;
-
-    channel = switch_core_session_get_channel(session);
-    assert(channel != NULL);
-
-	if (!macro_name) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No phrase macro specified.\n");
-		return status;
-	}
-
-	if (!lang) {
-        chan_lang = switch_channel_get_variable(channel, "default_language");
-        if (!chan_lang) {
-            chan_lang = "en";
-        } 
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "No language specified - Using [%s]\n", chan_lang);
-	} else {
-        chan_lang = lang;
-    }
-
-	if (!data) {
-		data = "";
+	if (!(param = switch_xml_add_child_d(xml, "aniii", off++))) {
+		return -1;
 	}
+	switch_xml_set_txt(param, caller_profile->aniii);
 
-    switch_url_encode(data, enc_hint, sizeof(enc_hint));
-    snprintf(hint_data, sizeof(hint_data), "macro_name=%s&lang=%s&data=%s", macro_name, chan_lang, enc_hint);
-    
-	if (switch_xml_locate("phrases", NULL, NULL, NULL, &xml, &cfg, hint_data) != SWITCH_STATUS_SUCCESS) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of phrases failed.\n");
-        goto done;
-	}
-
-    if (!(macros = switch_xml_child(cfg, "macros"))) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "can't find macros tag.\n");
-        goto done;
-    }
-
-    if (!(language = switch_xml_child(macros, "language"))) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "can't find language tag.\n");
-        goto done;
-    }
-
-    while(language) {
-        if ((lname = (char *) switch_xml_attr(language, "name")) && !strcasecmp(lname, chan_lang)) {
-            break;
-        }
-        language = language->next;
-    }
-
-    if (!language) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "can't find language %s.\n", chan_lang);
-        goto done;
-    }
-
-    sound_path = (char *) switch_xml_attr_soft(language, "sound_path");
-    tts_engine = (char *) switch_xml_attr_soft(language, "tts_engine");
-    tts_voice = (char *) switch_xml_attr_soft(language, "tts_voice");
-
-    old_sound_prefix = switch_channel_get_variable(channel, "sound_prefix");    
-    switch_channel_set_variable(channel, "sound_prefix", sound_path);
-
-    if (!(macro = switch_xml_child(language, "macro"))) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "can't find any macro tags.\n");
-        goto done;
-    }
-    
-    while(macro) {
-        if ((mname = (char *) switch_xml_attr(macro, "name")) && !strcasecmp(mname, macro_name)) {
-            break;
-        }
-        macro = macro->next;
-    }
-    
-    if (!macro) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "can't find macro %s.\n", macro_name);
-        goto done;
-    }
-
-    if (!(input = switch_xml_child(macro, "input"))) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "can't find any input tags.\n");
-        goto done;
-    }
-
-    switch_channel_pre_answer(channel);
-
-    while(input && !done) {
-        char *pattern = (char *) switch_xml_attr(input, "pattern");
-
-        if (pattern) {
-            switch_regex_t *re = NULL;
-            int proceed = 0, ovector[30];
-            char *substituted = NULL;
-            uint32_t len = 0;
-            char *odata = NULL;
-            char *expanded = NULL;
-            switch_xml_t match = NULL;
-            
-            if ((proceed = switch_regex_perform(data, pattern, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
-                match = switch_xml_child(input, "match");
-            } else {
-                match = switch_xml_child(input, "nomatch");
-            }
-
-            if (match) {
-				status = SWITCH_STATUS_SUCCESS;
-                for (action = switch_xml_child(match, "action"); action && status == SWITCH_STATUS_SUCCESS; action = action->next) {
-                    char *adata = (char *) switch_xml_attr_soft(action, "data");
-                    char *func = (char *) switch_xml_attr_soft(action, "function");
-
-                    if (strchr(pattern, '(') && strchr(adata, '$')) {
-                        len = (uint32_t)(strlen(data) + strlen(adata) + 10);
-                        if (!(substituted = malloc(len))) {
-                            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error!\n");
-                            switch_regex_safe_free(re);
-                            switch_safe_free(expanded);
-                            goto done;
-                        }
-                        memset(substituted, 0, len);
-                        switch_perform_substitution(re, proceed, adata, data, substituted, len, ovector);
-                        odata = substituted;
-                    } else {
-                        odata = adata;
-                    }
-                    
-                    expanded = switch_channel_expand_variables(channel, odata);
-
-                    if (expanded == odata) {
-                        expanded = NULL;
-                    } else {
-                        odata = expanded;
-                    }
-                    
-                    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Handle %s:[%s] (%s)\n", func, odata, chan_lang);
-
-                    if (!strcasecmp(func, "play-file")) {
-                        status = switch_ivr_play_file(session, NULL, odata, args);
-                    } else if (!strcasecmp(func, "break")) {
-                        done = 1;
-                        break;
-                    } else if (!strcasecmp(func, "execute")) {
-
-                    } else if (!strcasecmp(func, "say")) {
-                        switch_say_interface_t *si;
-                        if ((si = switch_loadable_module_get_say_interface(chan_lang))) {
-                            char *say_type = (char *) switch_xml_attr_soft(action, "type");
-                            char *say_method = (char *) switch_xml_attr_soft(action, "method");
-                            
-                            status = si->say_function(session, odata, get_say_type_by_name(say_type), get_say_method_by_name(say_method), args);
-                        } else {
-                            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid SAY Interface [%s]!\n", chan_lang);
-                        }
-                    } else if (!strcasecmp(func, "speak-text")) {
-                        switch_codec_t *read_codec;
-                        if ((read_codec = switch_core_session_get_read_codec(session))) {
-                            
-                            status = switch_ivr_speak_text(session,
-														   tts_engine,
-														   tts_voice,
-														   read_codec->implementation->samples_per_second,
-														   odata,
-														   args);
-                        }
-                    }
-                }
-            }
-            
-            switch_regex_safe_free(re);
-            switch_safe_free(expanded);
-            switch_safe_free(substituted);
-        }
-
-		if (status != SWITCH_STATUS_SUCCESS) {
-            done = 1;
-			break;
-		}
-
-        input = input->next;
-    }
-
- done:
-
-	switch_channel_set_variable(channel, "sound_prefix", old_sound_prefix);
+	if (!(param = switch_xml_add_child_d(xml, "caller_id_number", off++))) {
+		return -1;
+	}
+	switch_xml_set_txt(param, caller_profile->caller_id_number);
 
-    if (xml) {
-        switch_xml_free(xml);
-    }
-    return status;
-}
+	if (!(param = switch_xml_add_child_d(xml, "network_addr", off++))) {
+		return -1;
+	}
+	switch_xml_set_txt(param, caller_profile->network_addr);
 
+	if (!(param = switch_xml_add_child_d(xml, "rdnis", off++))) {
+		return -1;
+	}
+	switch_xml_set_txt(param, caller_profile->rdnis);
 
-static int set_profile_data(switch_xml_t xml, switch_caller_profile_t *caller_profile, int off)
-{
-	switch_xml_t param;
+	if (!(param = switch_xml_add_child_d(xml, "destination_number", off++))) {
+		return -1;
+	}
+	switch_xml_set_txt(param, caller_profile->destination_number);
 
-	if (!(param = switch_xml_add_child_d(xml, "username", off++))) {
+	if (!(param = switch_xml_add_child_d(xml, "uuid", off++))) {
 		return -1;
 	}
-	switch_xml_set_txt(param, caller_profile->username);
+	switch_xml_set_txt(param, caller_profile->uuid);
 
-	if (!(param = switch_xml_add_child_d(xml, "dialplan", off++))) {
+	if (!(param = switch_xml_add_child_d(xml, "source", off++))) {
 		return -1;
 	}
-	switch_xml_set_txt(param, caller_profile->dialplan);
+	switch_xml_set_txt(param, caller_profile->source);
 
-	if (!(param = switch_xml_add_child_d(xml, "caller_id_name", off++))) {
+	if (!(param = switch_xml_add_child_d(xml, "context", off++))) {
 		return -1;
 	}
-	switch_xml_set_txt(param, caller_profile->caller_id_name);
+	switch_xml_set_txt(param, caller_profile->context);
 
-    if (!(param = switch_xml_add_child_d(xml, "ani", off++))) {
-        return -1;
-    }
-    switch_xml_set_txt(param, caller_profile->ani);
-
-    if (!(param = switch_xml_add_child_d(xml, "aniii", off++))) {
-        return -1;
-    }
-    switch_xml_set_txt(param, caller_profile->aniii);
-
-    if (!(param = switch_xml_add_child_d(xml, "caller_id_number", off++))) {
-        return -1;
-    }
-    switch_xml_set_txt(param, caller_profile->caller_id_number);
-
-    if (!(param = switch_xml_add_child_d(xml, "network_addr", off++))) {
-        return -1;
-    }
-    switch_xml_set_txt(param, caller_profile->network_addr);
-
-    if (!(param = switch_xml_add_child_d(xml, "rdnis", off++))) {
-        return -1;
-    }
-    switch_xml_set_txt(param, caller_profile->rdnis);
-
-    if (!(param = switch_xml_add_child_d(xml, "destination_number", off++))) {
-        return -1;
-    }
-    switch_xml_set_txt(param, caller_profile->destination_number);
-
-    if (!(param = switch_xml_add_child_d(xml, "uuid", off++))) {
-        return -1;
-    }
-    switch_xml_set_txt(param, caller_profile->uuid);
-
-    if (!(param = switch_xml_add_child_d(xml, "source", off++))) {
-        return -1;
-    }
-    switch_xml_set_txt(param, caller_profile->source);
-
-    if (!(param = switch_xml_add_child_d(xml, "context", off++))) {
-        return -1;
-    }
-    switch_xml_set_txt(param, caller_profile->context);
-
-    if (!(param = switch_xml_add_child_d(xml, "chan_name", off++))) {
-        return -1;
-    }
-    switch_xml_set_txt(param, caller_profile->chan_name);
+	if (!(param = switch_xml_add_child_d(xml, "chan_name", off++))) {
+		return -1;
+	}
+	switch_xml_set_txt(param, caller_profile->chan_name);
 
 	return 0;
 }
 
-SWITCH_DECLARE(switch_status_t) switch_ivr_generate_xml_cdr(switch_core_session_t *session, switch_xml_t *xml_cdr)
+SWITCH_DECLARE(switch_status_t) switch_ivr_generate_xml_cdr(switch_core_session_t *session, switch_xml_t * xml_cdr)
 {
 	switch_channel_t *channel;
 	switch_caller_profile_t *caller_profile;
 	switch_hash_index_t *hi;
 	void *vval;
 	const void *vvar;
-	switch_xml_t variable,
-		variables,
-		cdr,
-		x_caller_profile,
-		x_caller_extension,
-		x_times,
-		time_tag,
-		x_application,
-		x_callflow;
+	switch_xml_t variable, variables, cdr, x_caller_profile, x_caller_extension, x_times, time_tag, x_application, x_callflow;
 	char tmp[512];
 	int cdr_off = 0, v_off = 0;
 
 	channel = switch_core_session_get_channel(session);
-    assert(channel != NULL);
+	assert(channel != NULL);
 
 	if (!(cdr = switch_xml_new("cdr"))) {
-        return SWITCH_STATUS_SUCCESS;
-    }
+		return SWITCH_STATUS_SUCCESS;
+	}
 
 	if (!(variables = switch_xml_add_child_d(cdr, "variables", cdr_off++))) {
 		goto error;
 	}
-	
+
 	for (hi = switch_channel_variable_first(channel, switch_core_session_get_pool(session)); hi; hi = switch_hash_next(hi)) {
 		switch_hash_this(hi, &vvar, NULL, &vval);
 		if (vvar && vval) {
@@ -5265,7 +955,7 @@
 				switch_size_t dlen = strlen(value) * 3;
 
 				if ((data = switch_core_session_alloc(session, dlen))) {
-					switch_url_encode(value, data, dlen);					
+					switch_url_encode(value, data, dlen);
 					switch_xml_set_txt_d(variable, data);
 				}
 			}
@@ -5273,14 +963,14 @@
 	}
 
 	caller_profile = switch_channel_get_caller_profile(channel);
-	
+
 	while (caller_profile) {
 		int cf_off = 0;
-		
+
 		if (!(x_callflow = switch_xml_add_child_d(cdr, "callflow", cdr_off++))) {
 			goto error;
 		}
-		
+
 		if (caller_profile->caller_extension) {
 			switch_caller_application_t *ap;
 			int app_off = 0;
@@ -5294,7 +984,7 @@
 				switch_xml_set_attr_d(x_caller_extension, "current_app", caller_profile->caller_extension->current_application->application_name);
 			}
 
-			for(ap = caller_profile->caller_extension->applications; ap; ap = ap->next) {
+			for (ap = caller_profile->caller_extension->applications; ap; ap = ap->next) {
 				if (!(x_application = switch_xml_add_child_d(x_caller_extension, "application", app_off++))) {
 					goto error;
 				}
@@ -5305,7 +995,7 @@
 				switch_xml_set_attr_d(x_application, "app_data", ap->application_data);
 			}
 		}
-		
+
 		if (!(x_caller_profile = switch_xml_add_child_d(x_callflow, "caller_profile", cf_off++))) {
 			goto error;
 		}
@@ -5334,25 +1024,25 @@
 			if (!(time_tag = switch_xml_add_child_d(x_times, "created_time", t_off++))) {
 				goto error;
 			}
-			snprintf(tmp, sizeof(tmp), "%"SWITCH_TIME_T_FMT, caller_profile->times->created);
+			snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->created);
 			switch_xml_set_txt_d(time_tag, tmp);
 
 			if (!(time_tag = switch_xml_add_child_d(x_times, "answered_time", t_off++))) {
 				goto error;
 			}
-			snprintf(tmp, sizeof(tmp), "%"SWITCH_TIME_T_FMT, caller_profile->times->answered);
+			snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->answered);
 			switch_xml_set_txt_d(time_tag, tmp);
 
 			if (!(time_tag = switch_xml_add_child_d(x_times, "hangup_time", t_off++))) {
 				goto error;
 			}
-			snprintf(tmp, sizeof(tmp), "%"SWITCH_TIME_T_FMT, caller_profile->times->hungup);
+			snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->hungup);
 			switch_xml_set_txt_d(time_tag, tmp);
 
 			if (!(time_tag = switch_xml_add_child_d(x_times, "transfer_time", t_off++))) {
 				goto error;
 			}
-			snprintf(tmp, sizeof(tmp), "%"SWITCH_TIME_T_FMT, caller_profile->times->transferred);
+			snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->transferred);
 			switch_xml_set_txt_d(time_tag, tmp);
 		}
 
@@ -5360,15 +1050,15 @@
 	}
 
 	*xml_cdr = cdr;
-	
-	return SWITCH_STATUS_SUCCESS;	
 
- error:
+	return SWITCH_STATUS_SUCCESS;
+
+  error:
 
 	if (cdr) {
 		switch_xml_free(cdr);
 	}
-	
+
 	return SWITCH_STATUS_FALSE;
 }
 

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/switch_loadable_module.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/switch_loadable_module.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/switch_loadable_module.c	Fri Mar 30 12:19:18 2007
@@ -69,7 +69,7 @@
 
 static struct switch_loadable_module_container loadable_modules;
 
-static void *switch_loadable_module_exec(switch_thread_t *thread, void *obj)
+static void *switch_loadable_module_exec(switch_thread_t * thread, void *obj)
 {
 
 
@@ -105,7 +105,7 @@
 	for (hi = switch_hash_first(loadable_modules.pool, loadable_modules.module_hash); hi; hi = switch_hash_next(hi)) {
 		switch_hash_this(hi, NULL, NULL, &val);
 		module = (switch_loadable_module_t *) val;
-		
+
 		if (module->switch_module_runtime) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Starting runtime thread for %s\n", module->module_interface->module_name);
 			switch_core_launch_thread(switch_loadable_module_exec, module, loadable_modules.pool);
@@ -136,7 +136,7 @@
 		const switch_codec_interface_t *ptr;
 
 		for (ptr = new_module->module_interface->codec_interface; ptr; ptr = ptr->next) {
-			if (!ptr->interface_name)  {
+			if (!ptr->interface_name) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to load codec interface from %s due to no interface name.\n", key);
 			} else {
 				unsigned load_interface = 1;
@@ -147,14 +147,13 @@
 					}
 				}
 				if (!load_interface) {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to load codec interface %s from %s due to no iana name in an implementation.\n", ptr->interface_name, key);
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
+									  "Failed to load codec interface %s from %s due to no iana name in an implementation.\n", ptr->interface_name, key);
 				} else {
 					for (impl = ptr->implementations; impl; impl = impl->next) {
 						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE,
 										  "Adding Codec '%s' (%s) %dhz %dms\n",
-										  impl->iananame,
-										  ptr->interface_name,
-										  impl->samples_per_second, impl->microseconds_per_frame / 1000);
+										  impl->iananame, ptr->interface_name, impl->samples_per_second, impl->microseconds_per_frame / 1000);
 						if (!switch_core_hash_find(loadable_modules.codec_hash, impl->iananame)) {
 							switch_core_hash_insert(loadable_modules.codec_hash, impl->iananame, (const void *) ptr);
 						}
@@ -166,7 +165,7 @@
 					}
 				}
 			}
-		} 
+		}
 	}
 
 	if (new_module->module_interface->dialplan_interface) {
@@ -255,11 +254,11 @@
 				int i;
 				for (i = 0; ptr->extens[i]; i++) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Adding File Format '%s'\n", ptr->extens[i]);
-				if (switch_event_create(&event, SWITCH_EVENT_MODULE_LOAD) == SWITCH_STATUS_SUCCESS) {
-					switch_event_add_header(event, SWITCH_STACK_BOTTOM, "type", "file");
-					switch_event_add_header(event, SWITCH_STACK_BOTTOM, "name", "%s", ptr->extens[i]);
-					switch_event_fire(&event);
-				}
+					if (switch_event_create(&event, SWITCH_EVENT_MODULE_LOAD) == SWITCH_STATUS_SUCCESS) {
+						switch_event_add_header(event, SWITCH_STACK_BOTTOM, "type", "file");
+						switch_event_add_header(event, SWITCH_STACK_BOTTOM, "name", "%s", ptr->extens[i]);
+						switch_event_fire(&event);
+					}
 					switch_core_hash_insert(loadable_modules.file_hash, ptr->extens[i], (const void *) ptr);
 				}
 			}
@@ -367,7 +366,7 @@
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
 									  "Failed to load management interface %s. OID %s already exists\n", key, ptr->relative_oid);
 				} else {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, 
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE,
 									  "Adding Management interface '%s' OID[%s.%s]\n", key, FREESWITCH_OID_PREFIX, ptr->relative_oid);
 					switch_core_hash_insert(loadable_modules.management_hash, ptr->relative_oid, (const void *) ptr);
 					if (switch_event_create(&event, SWITCH_EVENT_MODULE_LOAD) == SWITCH_STATUS_SUCCESS) {
@@ -376,11 +375,11 @@
 						switch_event_fire(&event);
 					}
 				}
-				
+
 			}
 		}
 	}
-	
+
 
 	return SWITCH_STATUS_SUCCESS;
 
@@ -413,7 +412,7 @@
 		}
 
 		status = switch_dso_sym(&load_function_handle, dso, "switch_module_load");
-		load_func_ptr = (switch_module_load_t)(intptr_t) load_function_handle;
+		load_func_ptr = (switch_module_load_t) (intptr_t) load_function_handle;
 
 		if (load_func_ptr == NULL) {
 			err = "Cannot locate symbol 'switch_module_load' please make sure this is a vaild module.";
@@ -444,9 +443,9 @@
 	module->switch_module_load = load_func_ptr;
 
 	switch_dso_sym(&shutdown_function_handle, dso, "switch_module_shutdown");
-	module->switch_module_shutdown = (switch_module_shutdown_t)(intptr_t) shutdown_function_handle;
+	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->switch_module_runtime = (switch_module_runtime_t) (intptr_t) runtime_function_handle;
 
 	module->lib = dso;
 
@@ -496,10 +495,10 @@
 		}
 	}
 
-    if (switch_core_hash_find(loadable_modules.module_hash, file)) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Module %s Already Loaded!\n", file);
-        return SWITCH_STATUS_FALSE;
-    }
+	if (switch_core_hash_find(loadable_modules.module_hash, file)) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Module %s Already Loaded!\n", file);
+		return SWITCH_STATUS_FALSE;
+	}
 
 	if ((status = switch_loadable_module_load_file(path, &new_module) == SWITCH_STATUS_SUCCESS)) {
 		if ((status = switch_loadable_module_process((char *) file, new_module)) == SWITCH_STATUS_SUCCESS && runtime) {
@@ -510,83 +509,81 @@
 	}
 
 	return status;
-	
+
 }
 
 SWITCH_DECLARE(switch_status_t) switch_loadable_module_build_dynamic(char *filename,
-																   switch_module_load_t switch_module_load,
-																   switch_module_runtime_t switch_module_runtime,
-																   switch_module_shutdown_t switch_module_shutdown)
-{ 
-	switch_loadable_module_t *module = NULL; 
-	switch_module_load_t load_func_ptr = NULL; 
-	int loading = 1; 
-	const char *err = NULL; 
-	switch_loadable_module_interface_t *module_interface = NULL; 
-
-	if ((module = switch_core_permanent_alloc(sizeof(switch_loadable_module_t))) == 0) { 
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Couldn't allocate memory\n"); 
-		return SWITCH_STATUS_GENERR; 
-	} 
-
-	while (loading) { 
-  		load_func_ptr = (switch_module_load_t) switch_module_load; 
-  
-		if (load_func_ptr == NULL) { 
-			err = "Cannot Load"; 
-			break; 
-		} 
-  
-		if (load_func_ptr(&module_interface, filename) != SWITCH_STATUS_SUCCESS) { 
-			err = "Module load routine returned an error"; 
-			module_interface = NULL; 
-			break; 
-		} 
-  
-		if ((module = switch_core_permanent_alloc(sizeof(switch_loadable_module_t))) == 0) { 
-			err = "Could not allocate memory\n"; 
-			break; 
-		} 
-  
-		loading = 0; 
-	}
-  
-	if (err) { 
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Error Loading module %s\n**%s**\n", filename, err); 
-		return SWITCH_STATUS_GENERR; 
-	} 
-  
-	module->filename = switch_core_permanent_strdup(filename); 
-	module->module_interface = module_interface; 
-	module->switch_module_load = load_func_ptr; 
-  
-	if (switch_module_shutdown) { 
-		module->switch_module_shutdown = switch_module_shutdown; 
-	} 
-	if (switch_module_runtime) { 
-		module->switch_module_runtime = switch_module_runtime; 
-	} 
-	if (module->switch_module_runtime) { 
-		switch_core_launch_thread(switch_loadable_module_exec, module, loadable_modules.pool); 
-	} 
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Successfully Loaded [%s]\n", module_interface->module_name); 
+																	 switch_module_load_t switch_module_load,
+																	 switch_module_runtime_t switch_module_runtime,
+																	 switch_module_shutdown_t switch_module_shutdown)
+{
+	switch_loadable_module_t *module = NULL;
+	switch_module_load_t load_func_ptr = NULL;
+	int loading = 1;
+	const char *err = NULL;
+	switch_loadable_module_interface_t *module_interface = NULL;
+
+	if ((module = switch_core_permanent_alloc(sizeof(switch_loadable_module_t))) == 0) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Couldn't allocate memory\n");
+		return SWITCH_STATUS_GENERR;
+	}
+
+	while (loading) {
+		load_func_ptr = (switch_module_load_t) switch_module_load;
+
+		if (load_func_ptr == NULL) {
+			err = "Cannot Load";
+			break;
+		}
+
+		if (load_func_ptr(&module_interface, filename) != SWITCH_STATUS_SUCCESS) {
+			err = "Module load routine returned an error";
+			module_interface = NULL;
+			break;
+		}
+
+		if ((module = switch_core_permanent_alloc(sizeof(switch_loadable_module_t))) == 0) {
+			err = "Could not allocate memory\n";
+			break;
+		}
+
+		loading = 0;
+	}
+
+	if (err) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Error Loading module %s\n**%s**\n", filename, err);
+		return SWITCH_STATUS_GENERR;
+	}
+
+	module->filename = switch_core_permanent_strdup(filename);
+	module->module_interface = module_interface;
+	module->switch_module_load = load_func_ptr;
+
+	if (switch_module_shutdown) {
+		module->switch_module_shutdown = switch_module_shutdown;
+	}
+	if (switch_module_runtime) {
+		module->switch_module_runtime = switch_module_runtime;
+	}
+	if (module->switch_module_runtime) {
+		switch_core_launch_thread(switch_loadable_module_exec, module, loadable_modules.pool);
+	}
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Successfully Loaded [%s]\n", module_interface->module_name);
 	return switch_loadable_module_process((char *) module->filename, module);
-} 
+}
 
 #ifdef WIN32
 static void switch_loadable_module_path_init()
 {
-	char *path =NULL, *working =NULL;
+	char *path = NULL, *working = NULL;
 	apr_dir_t *perl_dir_handle = NULL;
 
 	apr_env_get(&path, "path", loadable_modules.pool);
-	apr_filepath_get(&working, APR_FILEPATH_NATIVE , loadable_modules.pool);
+	apr_filepath_get(&working, APR_FILEPATH_NATIVE, loadable_modules.pool);
 
 	if (apr_dir_open(&perl_dir_handle, ".\\perl", loadable_modules.pool) == APR_SUCCESS) {
-			apr_dir_close(perl_dir_handle);
-			apr_env_set("path", 
-						apr_pstrcat(loadable_modules.pool, path, ";", working, "\\perl", NULL), 
-						loadable_modules.pool);
+		apr_dir_close(perl_dir_handle);
+		apr_env_set("path", apr_pstrcat(loadable_modules.pool, path, ";", working, "\\perl", NULL), loadable_modules.pool);
 	}
 }
 #endif
@@ -594,7 +591,7 @@
 SWITCH_DECLARE(switch_status_t) switch_loadable_module_init()
 {
 
-	apr_finfo_t finfo = {0};
+	apr_finfo_t finfo = { 0 };
 	apr_dir_t *module_dir_handle = NULL;
 	apr_int32_t finfo_flags = APR_FINFO_DIRENT | APR_FINFO_TYPE | APR_FINFO_NAME;
 	char *cf = "modules.conf";
@@ -652,7 +649,7 @@
 			}
 		}
 		switch_xml_free(xml);
-		
+
 	} else {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "open of %s failed\n", cf);
 	}
@@ -672,7 +669,7 @@
 			}
 		}
 		switch_xml_free(xml);
-		
+
 	} else {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "open of %s failed\n", pcf);
 	}
@@ -681,7 +678,7 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "No modules loaded assuming 'load all'\n");
 		all = 1;
 	}
-	
+
 	if (all) {
 		if (apr_dir_open(&module_dir_handle, SWITCH_GLOBAL_dirs.mod_dir, loadable_modules.pool) != APR_SUCCESS) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Can't open directory: %s\n", SWITCH_GLOBAL_dirs.mod_dir);
@@ -753,14 +750,14 @@
 	char altname[256] = "";
 	switch_codec_interface_t *codec;
 	switch_size_t x;
-	
+
 	if (!(codec = switch_core_hash_find(loadable_modules.codec_hash, name))) {
-		for(x = 0; x < strlen(name); x++) {
-			altname[x] = (char)toupper((int)name[x]);
+		for (x = 0; x < strlen(name); x++) {
+			altname[x] = (char) toupper((int) name[x]);
 		}
 		if (!(codec = switch_core_hash_find(loadable_modules.codec_hash, altname))) {
-			for(x = 0; x < strlen(name); x++) {
-				altname[x] = (char)tolower((int)name[x]);
+			for (x = 0; x < strlen(name); x++) {
+				altname[x] = (char) tolower((int) name[x]);
 			}
 			codec = switch_core_hash_find(loadable_modules.codec_hash, altname);
 		}
@@ -823,29 +820,28 @@
 	return switch_core_hash_find(loadable_modules.management_hash, relative_oid);
 }
 
-SWITCH_DECLARE(int) switch_loadable_module_get_codecs(switch_memory_pool_t *pool, const switch_codec_implementation_t **array,
-													  int arraylen)
+SWITCH_DECLARE(int) switch_loadable_module_get_codecs(switch_memory_pool_t *pool, const switch_codec_implementation_t **array, int arraylen)
 {
 	switch_hash_index_t *hi;
 	void *val;
 	switch_codec_interface_t *codec_interface;
 	int i = 0;
-    const switch_codec_implementation_t *imp;
+	const switch_codec_implementation_t *imp;
 
 	for (hi = switch_hash_first(pool, loadable_modules.codec_hash); hi; hi = switch_hash_next(hi)) {
 		switch_hash_this(hi, NULL, NULL, &val);
 		codec_interface = (switch_codec_interface_t *) val;
-        /* Look for a 20ms implementation because it's the safest choice */
-        for (imp = codec_interface->implementations; imp; imp = imp->next) {
-            if (imp->microseconds_per_frame / 1000 == 20) {
-                array[i++] = imp;
-                goto found;
-            }
-        }
-        /* oh well we will use what we have */
+		/* Look for a 20ms implementation because it's the safest choice */
+		for (imp = codec_interface->implementations; imp; imp = imp->next) {
+			if (imp->microseconds_per_frame / 1000 == 20) {
+				array[i++] = imp;
+				goto found;
+			}
+		}
+		/* oh well we will use what we have */
 		array[i++] = codec_interface->implementations;
 
-    found:
+	  found:
 
 		if (i > arraylen) {
 			break;
@@ -856,14 +852,13 @@
 
 }
 
-SWITCH_DECLARE(int) switch_loadable_module_get_codecs_sorted(const switch_codec_implementation_t **array,
-															 int arraylen, char **prefs, int preflen)
+SWITCH_DECLARE(int) switch_loadable_module_get_codecs_sorted(const switch_codec_implementation_t **array, int arraylen, char **prefs, int preflen)
 {
 	int x, i = 0;
 	switch_codec_interface_t *codec_interface;
 	const switch_codec_implementation_t *imp;
 
-    for (x = 0; x < preflen; x++) {
+	for (x = 0; x < preflen; x++) {
 		char *cur, *last = NULL, *next = NULL, *name, *p, buf[256];
 		uint32_t interval = 0, rate = 0;
 
@@ -888,52 +883,52 @@
 			cur = next;
 		}
 
-        if ((codec_interface = switch_loadable_module_get_codec_interface(name)) != 0 ) {
-            /* If no specific codec interval is requested opt for 20ms above all else because lots of stuff assumes it */
-            if (!interval) {
-                for (imp = codec_interface->implementations; imp; imp = imp->next) {
-                    uint8_t match = 1;
-
-                    if ((uint32_t)(imp->microseconds_per_frame / 1000) != 20) {
-                        match = 0;
-                    }
-
-                    if (match && rate && (uint32_t)imp->samples_per_second != rate) {
-                        match = 0;
-                    }
-
-                    if (match) {
-                        array[i++] = imp;
-                        goto found;
-                    }
-                }
-            }
+		if ((codec_interface = switch_loadable_module_get_codec_interface(name)) != 0) {
+			/* If no specific codec interval is requested opt for 20ms above all else because lots of stuff assumes it */
+			if (!interval) {
+				for (imp = codec_interface->implementations; imp; imp = imp->next) {
+					uint8_t match = 1;
 
-            /* Either looking for a specific interval or there was no interval specified and there wasn't one @20ms available*/
+					if ((uint32_t) (imp->microseconds_per_frame / 1000) != 20) {
+						match = 0;
+					}
+
+					if (match && rate && (uint32_t) imp->samples_per_second != rate) {
+						match = 0;
+					}
+
+					if (match) {
+						array[i++] = imp;
+						goto found;
+					}
+				}
+			}
+
+			/* Either looking for a specific interval or there was no interval specified and there wasn't one @20ms available */
 			for (imp = codec_interface->implementations; imp; imp = imp->next) {
 				uint8_t match = 1;
 
-				if (interval && (uint32_t)(imp->microseconds_per_frame / 1000) != interval) {
+				if (interval && (uint32_t) (imp->microseconds_per_frame / 1000) != interval) {
 					match = 0;
 				}
 
-				if (match && rate && (uint32_t)imp->samples_per_second != rate) {
+				if (match && rate && (uint32_t) imp->samples_per_second != rate) {
 					match = 0;
 				}
 
 				if (match) {
 					array[i++] = imp;
-                    goto found;
+					goto found;
 				}
 			}
 
-        found:
+		  found:
 
-            if (i > arraylen) {
-                break;
-            }
-        }
-    }
+			if (i > arraylen) {
+				break;
+			}
+		}
+	}
 
 	return i;
 }

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/switch_log.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/switch_log.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/switch_log.c	Fri Mar 30 12:19:18 2007
@@ -33,14 +33,14 @@
 
 
 static const char *LEVELS[] = {
-	"EMERG"  , 
-	"ALERT"  , 
-	"CRIT"   , 
-	"ERR"    , 
-	"WARNING", 
-	"NOTICE" , 
-	"INFO"   , 
-	"DEBUG"  , 
+	"EMERG",
+	"ALERT",
+	"CRIT",
+	"ERR",
+	"WARNING",
+	"NOTICE",
+	"INFO",
+	"DEBUG",
 	"CONSOLE",
 	NULL
 };
@@ -69,7 +69,7 @@
 {
 	int x = 0;
 	switch_log_level_t level = SWITCH_LOG_DEBUG;
-	for(x = 0;;x++) {
+	for (x = 0;; x++) {
 		if (!LEVELS[x]) {
 			break;
 		}
@@ -91,7 +91,7 @@
 		return SWITCH_STATUS_MEMERR;
 	}
 
-	if ((uint8_t)level > MAX_LEVEL) {
+	if ((uint8_t) level > MAX_LEVEL) {
 		MAX_LEVEL = level;
 	}
 
@@ -111,30 +111,30 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static void *SWITCH_THREAD_FUNC log_thread(switch_thread_t *thread, void *obj)
+static void *SWITCH_THREAD_FUNC log_thread(switch_thread_t * thread, void *obj)
 {
 
 	/* To Be or Not To Be */
 	assert(obj == NULL || obj != NULL);
 	THREAD_RUNNING = 1;
 
-	while(THREAD_RUNNING == 1) {
+	while (THREAD_RUNNING == 1) {
 		void *pop = NULL;
 		switch_log_node_t *node = NULL;
 		switch_log_binding_t *binding;
-		
+
 		if (switch_queue_pop(LOG_QUEUE, &pop) != SWITCH_STATUS_SUCCESS) {
 			break;
 		}
-		
+
 		if (!pop) {
 			break;
 		}
-		
+
 		node = (switch_log_node_t *) pop;
 
 		switch_mutex_lock(BINDLOCK);
-		for(binding = BINDINGS; binding; binding = binding->next) {
+		for (binding = BINDINGS; binding; binding = binding->next) {
 			if (binding->level >= node->level) {
 				binding->function(node, node->level);
 			}
@@ -162,14 +162,15 @@
 	return NULL;
 }
 
-SWITCH_DECLARE(void) switch_log_printf(switch_text_channel_t channel, const char *file, const char *func, int line, switch_log_level_t level, const char *fmt, ...)
+SWITCH_DECLARE(void) switch_log_printf(switch_text_channel_t channel, const char *file, const char *func, int line,
+									   switch_log_level_t level, const char *fmt, ...)
 {
 	char *data = NULL;
 	char *new_fmt = NULL;
 	int ret = 0;
 	va_list ap;
 	FILE *handle;
-	const char *filep = (file ? switch_cut_path(file): "");
+	const char *filep = (file ? switch_cut_path(file) : "");
 	const char *funcp = (func ? func : "");
 	char *content = NULL;
 	switch_time_t now = switch_time_now();
@@ -186,9 +187,9 @@
 
 		switch_time_exp_lt(&tm, now);
 		switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
-		
-		len = (uint32_t)(strlen(extra_fmt) + strlen(date) + strlen(filep) + 32 + strlen(funcp) + strlen(fmt));
-		new_fmt = malloc(len+1);
+
+		len = (uint32_t) (strlen(extra_fmt) + strlen(date) + strlen(filep) + 32 + strlen(funcp) + strlen(fmt));
+		new_fmt = malloc(len + 1);
 		snprintf(new_fmt, len, extra_fmt, date, LEVELS[level], filep, line, funcp, 128, fmt);
 		fmt = new_fmt;
 	}
@@ -208,15 +209,15 @@
 		}
 
 		if (channel == SWITCH_CHANNEL_ID_EVENT) {
-				switch_event_t *event;
-				if (switch_event_running() == SWITCH_STATUS_SUCCESS && switch_event_create(&event, SWITCH_EVENT_LOG) == SWITCH_STATUS_SUCCESS) {
-					switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Data", "%s", data);
-					switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-File", "%s", filep);
-					switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Function", "%s", funcp);
-					switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Line", "%d", line);
-					switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Level", "%d", (int)level);
-					switch_event_fire(&event);
-				}
+			switch_event_t *event;
+			if (switch_event_running() == SWITCH_STATUS_SUCCESS && switch_event_create(&event, SWITCH_EVENT_LOG) == SWITCH_STATUS_SUCCESS) {
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Data", "%s", data);
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-File", "%s", filep);
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Function", "%s", funcp);
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Line", "%d", line);
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Level", "%d", (int) level);
+				switch_event_fire(&event);
+			}
 		} else {
 			if (level == SWITCH_LOG_CONSOLE || !LOG_QUEUE || !THREAD_RUNNING) {
 				fprintf(handle, "%s", data);
@@ -236,7 +237,7 @@
 				} else {
 					free(data);
 				}
-			} 
+			}
 		}
 	}
 

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/switch_regex.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/switch_regex.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/switch_regex.c	Fri Mar 30 12:19:18 2007
@@ -32,49 +32,35 @@
 
 #include <switch.h>
 #include <pcre.h>
-
-
-SWITCH_DECLARE(switch_regex_t *) switch_regex_compile(const char *pattern,
-													  int options,
-													  const char **errorptr,
-													  int *erroroffset,
-													  const unsigned char *tables)
-{
-	return pcre_compile(pattern, options, errorptr, erroroffset, tables);
-
-}
-
-SWITCH_DECLARE(int) switch_regex_copy_substring(const char *subject,
-												int *ovector,
-												int stringcount,
-												int stringnumber,
-												char *buffer,
-												int size)
+
 
SWITCH_DECLARE(switch_regex_t *) switch_regex_compile(const char *pattern,
+														 int options, const char **errorptr, int *erroroffset, 
const unsigned char *tables) 
+{
+	
return pcre_compile(pattern, options, errorptr, erroroffset, tables);
+
}
+

SWITCH_DECLARE(int) switch_regex_copy_substring(const char *subject, int *ovector, int stringcount, int stringnumber, char *buffer, int size)
 {
 	return pcre_copy_substring(subject, ovector, stringcount, stringnumber, buffer, size);
 }
 
 SWITCH_DECLARE(void) switch_regex_free(void *data)
 {
-	pcre_free(data);
-}
-
-SWITCH_DECLARE(int) switch_regex_perform(char *field, char *expression, switch_regex_t **new_re, int *ovector, uint32_t olen)
+	pcre_free(data);
+
} 

SWITCH_DECLARE(int) switch_regex_perform(char *field, char *expression, switch_regex_t **new_re, int *ovector, uint32_t olen)
 {
 	const char *error = NULL;
 	int erroffset = 0;
 	pcre *re = NULL;
 	int match_count = 0;
-	
+
 	if (!(field && expression)) {
 		return 0;
 	}
 
-	re = pcre_compile(expression, /* the pattern */
-					  0,		  /* default options */
-					  &error,	  /* for error message */
-					  &erroffset, /* for error offset */
-					  NULL);	  /* use default character tables */
+	re = pcre_compile(expression,	/* the pattern */
+					  0,		/* default options */
+					  &error,	/* for error message */
+					  &erroffset,	/* for error offset */
+					  NULL);	/* use default character tables */
 	if (error) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "COMPILE ERROR: %d [%s]\n", erroffset, error);
 		switch_regex_safe_free(re);
@@ -84,35 +70,36 @@
 	match_count = pcre_exec(re,	/* result of pcre_compile() */
 							NULL,	/* we didn't study the pattern */
 							field,	/* the subject string */
-							(int) strlen(field), /* the length of the subject string */
+							(int) strlen(field),	/* the length of the subject string */
 							0,	/* start at offset 0 in the subject */
 							0,	/* default options */
 							ovector,	/* vector of integers for substring information */
-							olen); /* number of elements (NOT size in bytes) */
+							olen);	/* number of elements (NOT size in bytes) */
 
 	if (match_count <= 0) {
 		switch_regex_safe_free(re);
 		match_count = 0;
 	}
 
-	*new_re = (switch_regex_t *)re;
+	*new_re = (switch_regex_t *) re;
 
 	return match_count;
 }
 
 
-SWITCH_DECLARE(void) switch_perform_substitution(switch_regex_t *re, int match_count, char *data, char *field_data, char *substituted, uint32_t len, int *ovector)
+SWITCH_DECLARE(void) switch_perform_substitution(switch_regex_t *re, int match_count, char *data, char *field_data,
+												 char *substituted, uint32_t len, int *ovector)
 {
 	char index[10] = "";
 	char replace[1024] = "";
 	uint32_t x, y = 0, z = 0, num = 0;
 
-	for (x = 0; x < (len-1) && x < strlen(data);) {
+	for (x = 0; x < (len - 1) && x < strlen(data);) {
 		if (data[x] == '$') {
 			x++;
-			
+
 			if (!(data[x] > 47 && data[x] < 58)) {
-				substituted[y++] = data[x-1];
+				substituted[y++] = data[x - 1];
 				continue;
 			}
 
@@ -123,13 +110,8 @@
 			index[z++] = '\0';
 			z = 0;
 			num = atoi(index);
-			
-			if (pcre_copy_substring(field_data,
-									ovector,
-									match_count,
-									num,
-									replace,
-									sizeof(replace)) > 0) {
+
+			if (pcre_copy_substring(field_data, ovector, match_count, num, replace, sizeof(replace)) > 0) {
 				unsigned int r;
 				for (r = 0; r < strlen(replace); r++) {
 					substituted[y++] = replace[r];
@@ -142,14 +124,14 @@
 	}
 	substituted[y++] = '\0';
 }
-
-SWITCH_DECLARE(switch_status_t) switch_regex_match(char *target, char *expression) {
-	const char* error	= NULL;		//Used to hold any errors
-	int error_offset	= 0;		//Holds the offset of an error
-	pcre* pcre_prepared	= NULL;		//Holds the compiled regex
-	int match_count		= 0;		//Number of times the regex was matched
-	int offset_vectors[2];			//not used, but has to exist or pcre won't even try to find a match
-	
+
SWITCH_DECLARE(switch_status_t) switch_regex_match(char *target, char *expression)
+{
+	const char *error = NULL;	//Used to hold any errors
+	int error_offset = 0;		//Holds the offset of an error
+	pcre *pcre_prepared = NULL;	//Holds the compiled regex
+	int match_count = 0;		//Number of times the regex was matched
+	int offset_vectors[2];		//not used, but has to exist or pcre won't even try to find a match
+
 	//Compile the expression
 	pcre_prepared = pcre_compile(expression, 0, &error, &error_offset, NULL);
 
@@ -159,15 +141,14 @@
 		if (pcre_prepared) {
 			pcre_free(pcre_prepared);
 			pcre_prepared = NULL;
-		}	       
-
-		//Note our error	
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Regular Expression Error expression[%s] error[%s] location[%d]\n", expression, error, error_offset);
+		}
+		//Note our error    
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
+						  "Regular Expression Error expression[%s] error[%s] location[%d]\n", expression, error, error_offset);
 
 		//We definitely didn't match anything
 		return SWITCH_STATUS_FALSE;
 	}
-
 	//So far so good, run the regex
 	match_count = pcre_exec(pcre_prepared, NULL, target, (int) strlen(target), 0, 0, offset_vectors, sizeof(offset_vectors) / sizeof(offset_vectors[0]));
 

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/switch_resample.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/switch_resample.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/switch_resample.c	Fri Mar 30 12:19:18 2007
@@ -53,9 +53,7 @@
 
 
 SWITCH_DECLARE(switch_status_t) switch_resample_create(switch_audio_resampler_t **new_resampler,
-													 int from_rate,
-													 switch_size_t from_size,
-													 int to_rate, uint32_t to_size, switch_memory_pool_t *pool)
+													   int from_rate, switch_size_t from_size, int to_rate, uint32_t to_size, switch_memory_pool_t *pool)
 {
 #ifdef DISABLE_RESAMPLE
 	*new_resampler = NULL;
@@ -75,8 +73,8 @@
 	resampler->factor = (lto_rate / lfrom_rate);
 
 	resampler->resampler = resample_open(QUALITY, resampler->factor, resampler->factor);
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Activate Resampler %d->%d %f\n", resampler->from_rate,
-						  resampler->to_rate, resampler->factor);
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Activate Resampler %d->%d %f\n", resampler->from_rate, resampler->to_rate,
+					  resampler->factor);
 	resampler->from_size = from_size;
 	resampler->from = (float *) switch_core_alloc(pool, resampler->from_size);
 	resampler->to_size = to_size;
@@ -88,8 +86,7 @@
 }
 
 
-SWITCH_DECLARE(uint32_t) switch_resample_process(switch_audio_resampler_t *resampler, float *src, int srclen, float *dst,
-											uint32_t dstlen, int last)
+SWITCH_DECLARE(uint32_t) switch_resample_process(switch_audio_resampler_t *resampler, float *src, int srclen, float *dst, uint32_t dstlen, int last)
 {
 #ifdef DISABLE_RESAMPLE
 	return 0;
@@ -99,8 +96,7 @@
 	for (;;) {
 		int srcBlock = MIN(srclen - srcpos, srclen);
 		int lastFlag = (last && (srcBlock == srclen - srcpos));
-		o = resample_process(resampler->resampler, resampler->factor, &src[srcpos], srcBlock, lastFlag, &srcused,
-							 &dst[out], dstlen - out);
+		o = resample_process(resampler->resampler, resampler->factor, &src[srcpos], srcBlock, lastFlag, &srcused, &dst[out], dstlen - out);
 		/* printf("resampling %d/%d (%d) %d %f\n",  srcpos, srclen,  MIN(dstlen-out, dstlen), srcused, factor); */
 
 		srcpos += srcused;
@@ -206,14 +202,14 @@
 	int sum_rnd = 0;
 
 	assert(divisor);
-	
-	for(i = 0; i < samples; i++, sum_rnd = 0) {
-		for(x = 0; x < 7; x++) {
+
+	for (i = 0; i < samples; i++, sum_rnd = 0) {
+		for (x = 0; x < 7; x++) {
 			rnd = (int16_t) (rand() * sizeof(int16_t));
 			sum_rnd += rnd;
 		}
 		switch_normalize_to_16bit(sum_rnd);
-		*data = (int16_t)((int16_t)sum_rnd / (int)divisor);
+		*data = (int16_t) ((int16_t) sum_rnd / (int) divisor);
 
 		data++;
 	}
@@ -222,8 +218,8 @@
 
 SWITCH_DECLARE(void) switch_change_sln_volume(int16_t *data, uint32_t samples, int32_t vol)
 {
-    double newrate = 0;
-    int div = 0;
+	double newrate = 0;
+	int div = 0;
 
 	switch_normalize_volume(vol);
 
@@ -248,7 +244,7 @@
 		for (x = 0; x < samples; x++) {
 			tmp = (int32_t) (div ? fp[x] / newrate : fp[x] * newrate);
 			switch_normalize_to_16bit(tmp);
-			fp[x] = (int16_t)tmp;
+			fp[x] = (int16_t) tmp;
 		}
 	}
 }

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/switch_rtp.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/switch_rtp.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/switch_rtp.c	Fri Mar 30 12:19:18 2007
@@ -66,8 +66,8 @@
 
 
 typedef struct {
-	srtp_hdr_t header;        
-	char body[SWITCH_RTP_MAX_BUF_LEN];  
+	srtp_hdr_t header;
+	char body[SWITCH_RTP_MAX_BUF_LEN];
 } rtp_msg_t;
 
 
@@ -126,7 +126,7 @@
 	switch_sockaddr_t *remote_addr;
 	rtp_msg_t recv_msg;
 	srtp_ctx_t *recv_ctx;
-	
+
 	uint16_t seq;
 	uint16_t rseq;
 	switch_payload_t payload;
@@ -144,7 +144,7 @@
 
 	char *ice_user;
 	char *user_ice;
-    char *timer_name;
+	char *timer_name;
 	switch_time_t last_stun;
 	uint32_t samples_per_interval;
 	uint32_t conf_samples_per_interval;
@@ -173,13 +173,13 @@
 	assert(rtp_session->ice_user != NULL);
 
 	if (rtp_session->stuncount == 0) {
-		uint8_t buf[256] = {0};
+		uint8_t buf[256] = { 0 };
 		switch_stun_packet_t *packet;
 		unsigned int elapsed;
 		switch_size_t bytes;
 
 		if (rtp_session->last_stun) {
-			elapsed = (unsigned int)((switch_time_now() - rtp_session->last_stun) / 1000);
+			elapsed = (unsigned int) ((switch_time_now() - rtp_session->last_stun) / 1000);
 
 			if (elapsed > 30000) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No stun for a long time (PUNT!)\n");
@@ -190,7 +190,7 @@
 		packet = switch_stun_packet_build_header(SWITCH_STUN_BINDING_REQUEST, NULL, buf);
 		switch_stun_packet_attribute_add_username(packet, rtp_session->ice_user, 32);
 		bytes = switch_stun_packet_length(packet);
-		switch_socket_sendto(rtp_session->sock, rtp_session->remote_addr, 0, (void *)packet, &bytes);
+		switch_socket_sendto(rtp_session->sock, rtp_session->remote_addr, 0, (void *) packet, &bytes);
 		rtp_session->stuncount = 25;
 	} else {
 		rtp_session->stuncount--;
@@ -202,18 +202,18 @@
 {
 	switch_stun_packet_t *packet;
 	switch_stun_packet_attribute_t *attr;
-	char username[33] = {0};
-	unsigned char buf[512] = {0};
+	char username[33] = { 0 };
+	unsigned char buf[512] = { 0 };
 
 	memcpy(buf, data, len);
 	packet = switch_stun_packet_parse(buf, sizeof(buf));
 	rtp_session->last_stun = switch_time_now();
-	
+
 
 	switch_stun_packet_first_attribute(packet, attr);
 
 	do {
-		switch(attr->type) {
+		switch (attr->type) {
 		case SWITCH_STUN_ATTR_MAPPED_ADDRESS:
 			if (attr->type) {
 				char ip[16];
@@ -222,7 +222,7 @@
 			}
 			break;
 		case SWITCH_STUN_ATTR_USERNAME:
-			if(attr->type) {
+			if (attr->type) {
 				switch_stun_packet_attribute_get_username(attr, username, 32);
 			}
 			break;
@@ -230,24 +230,24 @@
 	} while (switch_stun_packet_next_attribute(attr));
 
 	/* printf("[%s] [%s] [%s]\n", rtp_session->user_ice, username, !strcmp(rtp_session->user_ice, username) ? "yes" : "no"); */
-	if ((packet->header.type == SWITCH_STUN_BINDING_REQUEST)  && !strcmp(rtp_session->user_ice, username)) {
+	if ((packet->header.type == SWITCH_STUN_BINDING_REQUEST) && !strcmp(rtp_session->user_ice, username)) {
 		uint8_t buf[512];
 		switch_stun_packet_t *rpacket;
 		char *remote_ip;
 		switch_size_t bytes;
 		char ipbuf[25];
-		
+
 		memset(buf, 0, sizeof(buf));
 		rpacket = switch_stun_packet_build_header(SWITCH_STUN_BINDING_RESPONSE, packet->header.id, buf);
 		switch_stun_packet_attribute_add_username(rpacket, username, 32);
 		/* switch_sockaddr_ip_get(&remote_ip, rtp_session->from_addr); */
 
 		remote_ip = switch_get_addr(ipbuf, sizeof(ipbuf), rtp_session->from_addr);
-		
+
 
 		switch_stun_packet_attribute_add_binded_address(rpacket, remote_ip, switch_sockaddr_get_port(rtp_session->from_addr));
 		bytes = switch_stun_packet_length(rpacket);
-		switch_socket_sendto(rtp_session->sock, rtp_session->from_addr, 0, (void*)rpacket, &bytes);
+		switch_socket_sendto(rtp_session->sock, rtp_session->from_addr, 0, (void *) rpacket, &bytes);
 	}
 }
 
@@ -258,9 +258,9 @@
 		return;
 	}
 
-  srtp_init();
-  switch_mutex_init(&port_lock, SWITCH_MUTEX_NESTED, pool);
-  global_init = 1;
+	srtp_init();
+	switch_mutex_init(&port_lock, SWITCH_MUTEX_NESTED, pool);
+	global_init = 1;
 }
 
 SWITCH_DECLARE(switch_port_t) switch_rtp_request_port(void)
@@ -283,7 +283,7 @@
 	switch_socket_t *new_sock = NULL, *old_sock = NULL;
 	switch_status_t status = SWITCH_STATUS_FALSE;
 	*err = NULL;
-	
+
 	if (switch_sockaddr_info_get(&rtp_session->local_addr, host, SWITCH_UNSPEC, port, 0, rtp_session->pool) != SWITCH_STATUS_SUCCESS) {
 		*err = "Local Address Error!";
 		goto done;
@@ -292,7 +292,7 @@
 	if (rtp_session->sock) {
 		switch_rtp_kill_socket(rtp_session);
 	}
-	
+
 	if (switch_socket_create(&new_sock, AF_INET, SOCK_DGRAM, 0, rtp_session->pool) != SWITCH_STATUS_SUCCESS) {
 		*err = "Socket Error!";
 		goto done;
@@ -312,7 +312,8 @@
 	rtp_session->sock = new_sock;
 	new_sock = NULL;
 
-	if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_USE_TIMER) || switch_test_flag(rtp_session, SWITCH_RTP_FLAG_NOBLOCK)) {
+	if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_USE_TIMER)
+		|| switch_test_flag(rtp_session, SWITCH_RTP_FLAG_NOBLOCK)) {
 		switch_socket_opt_set(rtp_session->sock, SWITCH_SO_NONBLOCK, TRUE);
 		switch_set_flag_locked(rtp_session, SWITCH_RTP_FLAG_NOBLOCK);
 	}
@@ -321,7 +322,7 @@
 	*err = "Success";
 	switch_set_flag_locked(rtp_session, SWITCH_RTP_FLAG_IO);
 
- done:
+  done:
 
 	if (status != SWITCH_STATUS_SUCCESS) {
 		rtp_session->ready = 0;
@@ -356,10 +357,7 @@
 												  switch_payload_t payload,
 												  uint32_t samples_per_interval,
 												  uint32_t ms_per_packet,
-												  switch_rtp_flag_t flags, 
-												  char *crypto_key,
-												  char *timer_name,
-												  const char **err,
+												  switch_rtp_flag_t flags, char *crypto_key, char *timer_name, const char **err,
 												  switch_memory_pool_t *pool)
 {
 	switch_rtp_t *rtp_session = NULL;
@@ -368,7 +366,7 @@
 	uint32_t ssrc = rand() & 0xffff;
 
 	*new_rtp_session = NULL;
-	
+
 	if (samples_per_interval > SWITCH_RTP_MAX_BUF_LEN) {
 		*err = "Packet Size Too Large!";
 		return SWITCH_STATUS_FALSE;
@@ -390,7 +388,7 @@
 	switch_buffer_create_dynamic(&rtp_session->dtmf_data.dtmf_buffer, 128, 128, 0);
 	/* for from address on recvfrom calls */
 	switch_sockaddr_info_get(&rtp_session->from_addr, NULL, SWITCH_UNSPEC, 0, 0, rtp_session->pool);
-	
+
 	memset(&policy, 0, sizeof(policy));
 	if (crypto_key) {
 		int len;
@@ -398,9 +396,9 @@
 		switch_set_flag_locked(rtp_session, SWITCH_RTP_FLAG_SECURE);
 		crypto_policy_set_rtp_default(&policy.rtp);
 		crypto_policy_set_rtcp_default(&policy.rtcp);
-		policy.ssrc.type  = ssrc_any_inbound;
+		policy.ssrc.type = ssrc_any_inbound;
 		policy.ssrc.value = ssrc;
-		policy.key  = (uint8_t *) key;
+		policy.key = (uint8_t *) key;
 		policy.next = NULL;
 		policy.rtp.sec_serv = sec_serv_conf_and_auth;
 		policy.rtcp.sec_serv = sec_serv_none;
@@ -408,26 +406,23 @@
 		/*
 		 * read key from hexadecimal on command line into an octet string
 		 */
-		len = hex_string_to_octet_string(key, crypto_key, MASTER_KEY_LEN*2);
-    
+		len = hex_string_to_octet_string(key, crypto_key, MASTER_KEY_LEN * 2);
+
 		/* check that hex string is the right length */
-		if (len < MASTER_KEY_LEN*2) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, 
-								  "error: too few digits in key/salt "
-								  "(should be %d hexadecimal digits, found %d)\n",
-								  MASTER_KEY_LEN*2, len);
+		if (len < MASTER_KEY_LEN * 2) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
+							  "error: too few digits in key/salt " "(should be %d hexadecimal digits, found %d)\n", MASTER_KEY_LEN * 2, len);
 			*err = "Crypt Error";
 			return SWITCH_STATUS_FALSE;
-		} 
-		if (strlen(crypto_key) > MASTER_KEY_LEN*2) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, 
-								  "error: too many digits in key/salt "
-								  "(should be %d hexadecimal digits, found %u)\n",
-								  MASTER_KEY_LEN*2, (unsigned)strlen(crypto_key));
+		}
+		if (strlen(crypto_key) > MASTER_KEY_LEN * 2) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
+							  "error: too many digits in key/salt "
+							  "(should be %d hexadecimal digits, found %u)\n", MASTER_KEY_LEN * 2, (unsigned) strlen(crypto_key));
 			*err = "Crypt Error";
 			return SWITCH_STATUS_FALSE;
 		}
-    
+
 		/* switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "set master key/salt to %s/", octet_string_hex_string(key, 16));
 		 * switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_DEBUG, "%s\n", octet_string_hex_string(key+16, 14));
 		 */
@@ -435,30 +430,30 @@
 	}
 
 	rtp_session->seq = (uint16_t) rand();
-	rtp_session->send_msg.header.ssrc    = htonl(ssrc);
-	rtp_session->send_msg.header.ts      = 0;
+	rtp_session->send_msg.header.ssrc = htonl(ssrc);
+	rtp_session->send_msg.header.ts = 0;
 	//rtp_session->send_msg.header.seq     = (uint16_t) rand();
-	rtp_session->send_msg.header.m       = 0;
-	rtp_session->send_msg.header.pt      = (switch_payload_t)htonl(payload);
+	rtp_session->send_msg.header.m = 0;
+	rtp_session->send_msg.header.pt = (switch_payload_t) htonl(payload);
 	rtp_session->send_msg.header.version = 2;
-	rtp_session->send_msg.header.p       = 0;
-	rtp_session->send_msg.header.x       = 0;
-	rtp_session->send_msg.header.cc      = 0;
-
-	rtp_session->recv_msg.header.ssrc    = htonl(ssrc);
-	rtp_session->recv_msg.header.ts      = 0;
-	rtp_session->recv_msg.header.seq     = 0;
-	rtp_session->recv_msg.header.m       = 0;
-	rtp_session->recv_msg.header.pt      = (switch_payload_t)htonl(payload);
+	rtp_session->send_msg.header.p = 0;
+	rtp_session->send_msg.header.x = 0;
+	rtp_session->send_msg.header.cc = 0;
+
+	rtp_session->recv_msg.header.ssrc = htonl(ssrc);
+	rtp_session->recv_msg.header.ts = 0;
+	rtp_session->recv_msg.header.seq = 0;
+	rtp_session->recv_msg.header.m = 0;
+	rtp_session->recv_msg.header.pt = (switch_payload_t) htonl(payload);
 	rtp_session->recv_msg.header.version = 2;
-	rtp_session->recv_msg.header.p       = 0;
-	rtp_session->recv_msg.header.x       = 0;
-	rtp_session->recv_msg.header.cc      = 0;
+	rtp_session->recv_msg.header.p = 0;
+	rtp_session->recv_msg.header.x = 0;
+	rtp_session->recv_msg.header.cc = 0;
 
 	rtp_session->payload = payload;
 	rtp_session->ms_per_packet = ms_per_packet;
 	rtp_session->samples_per_interval = rtp_session->conf_samples_per_interval = samples_per_interval;
-    rtp_session->timer_name = switch_core_strdup(rtp_session->pool, timer_name);
+	rtp_session->timer_name = switch_core_strdup(rtp_session->pool, timer_name);
 
 	if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_SECURE)) {
 		err_status_t stat;
@@ -484,8 +479,10 @@
 	}
 
 	if (!switch_strlen_zero(timer_name)) {
-		if (switch_core_timer_init(&rtp_session->timer, timer_name, ms_per_packet / 1000, samples_per_interval, rtp_session->pool) == SWITCH_STATUS_SUCCESS) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Starting timer [%s] %d bytes per %dms\n", timer_name, samples_per_interval, ms_per_packet);
+		if (switch_core_timer_init(&rtp_session->timer, timer_name, ms_per_packet / 1000, samples_per_interval, rtp_session->pool) ==
+			SWITCH_STATUS_SUCCESS) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Starting timer [%s] %d bytes per %dms\n", timer_name, samples_per_interval,
+							  ms_per_packet);
 		} else {
 			memset(&rtp_session->timer, 0, sizeof(rtp_session->timer));
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error starting timer [%s], async RTP disabled\n", timer_name);
@@ -498,18 +495,14 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-SWITCH_DECLARE(switch_rtp_t *)switch_rtp_new(char *rx_host,
-											 switch_port_t rx_port,
-											 char *tx_host,
-											 switch_port_t tx_port,
-											 switch_payload_t payload,
-											 uint32_t samples_per_interval,
-											 uint32_t ms_per_packet,
-											 switch_rtp_flag_t flags,
-											 char *crypto_key,
-											 char *timer_name,
-											 const char **err,
-											 switch_memory_pool_t *pool) 
+SWITCH_DECLARE(switch_rtp_t *) switch_rtp_new(char *rx_host,
+											  switch_port_t rx_port,
+											  char *tx_host,
+											  switch_port_t tx_port,
+											  switch_payload_t payload,
+											  uint32_t samples_per_interval,
+											  uint32_t ms_per_packet,
+											  switch_rtp_flag_t flags, char *crypto_key, char *timer_name, const char **err, switch_memory_pool_t *pool)
 {
 	switch_rtp_t *rtp_session;
 
@@ -524,9 +517,9 @@
 	if (switch_rtp_set_local_address(rtp_session, rx_host, rx_port, err) != SWITCH_STATUS_SUCCESS) {
 		return NULL;
 	}
-    
+
 	rtp_session->ready = 1;
-	
+
 	return rtp_session;
 }
 
@@ -589,7 +582,7 @@
 	(*rtp_session)->ready = 0;
 
 	switch_mutex_lock((*rtp_session)->flag_mutex);
-	
+
 	if ((*rtp_session)->dtmf_data.dtmf_buffer) {
 		switch_buffer_destroy(&(*rtp_session)->dtmf_data.dtmf_buffer);
 	}
@@ -617,7 +610,7 @@
 	return;
 }
 
-SWITCH_DECLARE(switch_socket_t *)switch_rtp_get_rtp_socket(switch_rtp_t *rtp_session)
+SWITCH_DECLARE(switch_socket_t *) switch_rtp_get_rtp_socket(switch_rtp_t *rtp_session)
 {
 	return rtp_session->sock;
 }
@@ -647,23 +640,23 @@
 	rtp_session->invalid_handler = on_invalid;
 }
 
-SWITCH_DECLARE(void) switch_rtp_set_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flags) 
+SWITCH_DECLARE(void) switch_rtp_set_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flags)
 {
-	
+
 	switch_set_flag_locked(rtp_session, flags);
 
 }
 
-SWITCH_DECLARE(uint8_t) switch_rtp_test_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flags) 
+SWITCH_DECLARE(uint8_t) switch_rtp_test_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flags)
 {
-	
+
 	return (uint8_t) switch_test_flag(rtp_session, flags);
-	
+
 }
 
-SWITCH_DECLARE(void) switch_rtp_clear_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flags) 
+SWITCH_DECLARE(void) switch_rtp_clear_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flags)
 {
-	
+
 	switch_clear_flag_locked(rtp_session, flags);
 
 }
@@ -687,29 +680,23 @@
 			duration = rtp_session->dtmf_data.out_digit_sofar;
 		}
 
-		
+
 		rtp_session->dtmf_data.out_digit_packet[2] = (unsigned char) (duration >> 8);
 		rtp_session->dtmf_data.out_digit_packet[3] = (unsigned char) duration;
-		
+
 
 		for (x = 0; x < loops; x++) {
 			rtp_session->dtmf_data.out_digit_seq++;
-			switch_rtp_write_manual(rtp_session, 
+			switch_rtp_write_manual(rtp_session,
 									rtp_session->dtmf_data.out_digit_packet,
 									4,
 									0,
 									rtp_session->te,
-									rtp_session->dtmf_data.timestamp_dtmf,
-									rtp_session->dtmf_data.out_digit_seq,
-									rtp_session->dtmf_data.out_digit_ssrc,
+									rtp_session->dtmf_data.timestamp_dtmf, rtp_session->dtmf_data.out_digit_seq, rtp_session->dtmf_data.out_digit_ssrc,
 									&flags);
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Send %s packet for [%c] ts=%d sofar=%u dur=%d seq=%d\n", 
-							  loops == 1 ? "middle" : "end",
-							  rtp_session->dtmf_data.out_digit,
-							  rtp_session->dtmf_data.timestamp_dtmf, 
-							  rtp_session->dtmf_data.out_digit_sofar,
-							  duration,
-							  rtp_session->dtmf_data.out_digit_seq);
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Send %s packet for [%c] ts=%d sofar=%u dur=%d seq=%d\n",
+							  loops == 1 ? "middle" : "end", rtp_session->dtmf_data.out_digit, rtp_session->dtmf_data.timestamp_dtmf,
+							  rtp_session->dtmf_data.out_digit_sofar, duration, rtp_session->dtmf_data.out_digit_seq);
 
 		}
 
@@ -729,7 +716,7 @@
 			rtp_session->dtmf_data.out_digit_sofar = 0;
 			rtp_session->dtmf_data.out_digit_dur = rdigit->duration;
 			rtp_session->dtmf_data.out_digit = rdigit->digit;
-			rtp_session->dtmf_data.out_digit_packet[0] = (unsigned char)switch_char_to_rfc2833(rdigit->digit);
+			rtp_session->dtmf_data.out_digit_packet[0] = (unsigned char) switch_char_to_rfc2833(rdigit->digit);
 			rtp_session->dtmf_data.out_digit_packet[1] = 7;
 
 			if (rtp_session->timer.timer_interface) {
@@ -740,27 +727,22 @@
 
 			rtp_session->dtmf_data.out_digit_seq = rtp_session->last_write_seq;
 			rtp_session->dtmf_data.out_digit_ssrc = rtp_session->last_write_ssrc;
-			
+
 
 			for (x = 0; x < 3; x++) {
 				//rtp_session->dtmf_data.out_digit_seq++;
 				switch_rtp_write_manual(rtp_session,
 										rtp_session->dtmf_data.out_digit_packet,
 										4,
- 										switch_test_flag(rtp_session, SWITCH_RTP_FLAG_BUGGY_2833) ? 0 : 1,
+										switch_test_flag(rtp_session, SWITCH_RTP_FLAG_BUGGY_2833) ? 0 : 1,
 										rtp_session->te,
 										rtp_session->dtmf_data.timestamp_dtmf,
-										rtp_session->dtmf_data.out_digit_seq,
-										rtp_session->dtmf_data.out_digit_ssrc,
-										&flags);
+										rtp_session->dtmf_data.out_digit_seq, rtp_session->dtmf_data.out_digit_ssrc, &flags);
 				switch_log_printf(SWITCH_CHANNEL_LOG,
 								  SWITCH_LOG_DEBUG,
 								  "Send start packet for [%c] ts=%d sofar=%u dur=%d seq=%d\n",
 								  rtp_session->dtmf_data.out_digit,
-								  rtp_session->dtmf_data.timestamp_dtmf,
-								  rtp_session->dtmf_data.out_digit_sofar,
-								  0,
-								  rtp_session->dtmf_data.out_digit_seq);
+								  rtp_session->dtmf_data.timestamp_dtmf, rtp_session->dtmf_data.out_digit_sofar, 0, rtp_session->dtmf_data.out_digit_seq);
 			}
 
 			free(rdigit);
@@ -778,58 +760,57 @@
 		rtp_session->last_time = switch_time_now();
 	}
 
-	while(switch_rtp_ready(rtp_session)) {
-		bytes = sizeof(rtp_msg_t);	
-		status = switch_socket_recvfrom(rtp_session->from_addr, rtp_session->sock, 0, (void *)&rtp_session->recv_msg, &bytes);
+	while (switch_rtp_ready(rtp_session)) {
+		bytes = sizeof(rtp_msg_t);
+		status = switch_socket_recvfrom(rtp_session->from_addr, rtp_session->sock, 0, (void *) &rtp_session->recv_msg, &bytes);
 
 		if (!SWITCH_STATUS_IS_BREAK(status) && rtp_session->timer.interval) {
 			switch_core_timer_step(&rtp_session->timer);
 		}
-		
+
 		if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_IO)) {
 			return -1;
 		}
-		
+
 
 		if (!bytes && switch_test_flag(rtp_session, SWITCH_RTP_FLAG_BREAK)) {
 			switch_clear_flag_locked(rtp_session, SWITCH_RTP_FLAG_BREAK);
 
-            memset(&rtp_session->recv_msg.body, 0, 2);
+			memset(&rtp_session->recv_msg.body, 0, 2);
 			rtp_session->recv_msg.body[0] = 127;
-            rtp_session->recv_msg.header.pt = SWITCH_RTP_CNG_PAYLOAD;
-            *flags |= SFF_CNG;
-            /* Return a CNG frame */
-            *payload_type = SWITCH_RTP_CNG_PAYLOAD;
-            return 2 + rtp_header_len;
+			rtp_session->recv_msg.header.pt = SWITCH_RTP_CNG_PAYLOAD;
+			*flags |= SFF_CNG;
+			/* Return a CNG frame */
+			*payload_type = SWITCH_RTP_CNG_PAYLOAD;
+			return 2 + rtp_header_len;
 		}
 
 		if (bytes < 0) {
-			return (int)bytes;
+			return (int) bytes;
 		} else if (bytes > 0 && switch_test_flag(rtp_session, SWITCH_RTP_FLAG_SECURE)) {
-			int sbytes = (int)bytes;
+			int sbytes = (int) bytes;
 			err_status_t stat;
 
 			stat = srtp_unprotect(rtp_session->recv_ctx, &rtp_session->recv_msg.header, &sbytes);
 			if (stat) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
 								  "error: srtp unprotection failed with code %d%s\n", stat,
-								  stat == err_status_replay_fail ? " (replay check failed)" :
-								  stat == err_status_auth_fail ? " (auth check failed)" : "");
+								  stat == err_status_replay_fail ? " (replay check failed)" : stat == err_status_auth_fail ? " (auth check failed)" : "");
 				return -1;
 			}
 			bytes = sbytes;
-		} 
+		}
 
 		if (bytes && rtp_session->cng_pt && rtp_session->recv_msg.header.pt == rtp_session->cng_pt) {
 			continue;
 		}
 
 		if (rtp_session->timer.interval) {
-			check = (uint8_t)(switch_core_timer_check(&rtp_session->timer) == SWITCH_STATUS_SUCCESS);
-			
-			if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_AUTO_CNG) && 
+			check = (uint8_t) (switch_core_timer_check(&rtp_session->timer) == SWITCH_STATUS_SUCCESS);
+
+			if (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[2] = {0};
+				uint8_t data[2] = { 0 };
 				switch_frame_flag_t flags = SFF_NONE;
 				data[0] = 65;
 				rtp_session->cn++;
@@ -843,7 +824,7 @@
 			do_2833(rtp_session);
 
 			if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_USE_TIMER)) {
-				/* We're late! We're Late!*/
+				/* We're late! We're Late! */
 				if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_NOBLOCK) && status == SWITCH_STATUS_BREAK) {
 					switch_yield(1000);
 					continue;
@@ -855,8 +836,8 @@
 				*payload_type = SWITCH_RTP_CNG_PAYLOAD;
 				return SWITCH_RTP_CNG_PAYLOAD + rtp_header_len;
 			}
-		}		
-		
+		}
+
 		if (status == SWITCH_STATUS_BREAK || bytes == 0) {
 			if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_DATAWAIT)) {
 				switch_yield((rtp_session->ms_per_packet / 1000) * 750);
@@ -867,20 +848,23 @@
 
 
 		if (rtp_session->recv_msg.header.version) {
-			if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_AUTOADJ) && switch_sockaddr_get_port(rtp_session->from_addr)) {
-                char *tx_host;
-                char *old_host;
-                char bufa[30], bufb[30];
-                tx_host = switch_get_addr(bufa, sizeof(bufa), rtp_session->from_addr);
-                old_host = switch_get_addr(bufb, sizeof(bufb), rtp_session->remote_addr);
+			if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_AUTOADJ)
+				&& switch_sockaddr_get_port(rtp_session->from_addr)) {
+				char *tx_host;
+				char *old_host;
+				char bufa[30], bufb[30];
+				tx_host = switch_get_addr(bufa, sizeof(bufa), rtp_session->from_addr);
+				old_host = switch_get_addr(bufb, sizeof(bufb), rtp_session->remote_addr);
 
-				if ((switch_sockaddr_get_port(rtp_session->from_addr) != rtp_session->remote_port) || strcmp(tx_host, old_host)) {
+				if ((switch_sockaddr_get_port(rtp_session->from_addr) != rtp_session->remote_port)
+					|| strcmp(tx_host, old_host)) {
 					const char *err;
 					uint32_t old = rtp_session->remote_port;
 
 					if (!switch_strlen_zero(tx_host) && switch_sockaddr_get_port(rtp_session->from_addr) > 0) {
-						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Auto Changing port from %s:%u to %s:%u\n",
-										  old_host, old, tx_host, switch_sockaddr_get_port(rtp_session->from_addr));
+						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
+										  "Auto Changing port from %s:%u to %s:%u\n", old_host, old, tx_host,
+										  switch_sockaddr_get_port(rtp_session->from_addr));
 						switch_rtp_set_remote_address(rtp_session, tx_host, switch_sockaddr_get_port(rtp_session->from_addr), &err);
 					}
 				}
@@ -892,12 +876,12 @@
 			if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_GOOGLEHACK) && rtp_session->recv_msg.header.pt == 102) {
 				rtp_session->recv_msg.header.pt = 97;
 			}
-			rtp_session->rseq = ntohs((uint16_t)rtp_session->recv_msg.header.seq);
-			rtp_session->rpayload = (switch_payload_t)rtp_session->recv_msg.header.pt;
+			rtp_session->rseq = ntohs((uint16_t) rtp_session->recv_msg.header.seq);
+			rtp_session->rpayload = (switch_payload_t) rtp_session->recv_msg.header.pt;
 		} else {
 			if (rtp_session->recv_msg.header.version == 0 && rtp_session->ice_user) {
 				handle_ice(rtp_session, (void *) &rtp_session->recv_msg, bytes);
-			}	
+			}
 
 			if (rtp_session->invalid_handler) {
 				rtp_session->invalid_handler(rtp_session, rtp_session->sock, (void *) &rtp_session->recv_msg, bytes, rtp_session->from_addr);
@@ -905,25 +889,26 @@
 			return 0;
 		}
 
-		/* RFC2833 ... TBD try harder to honor the duration etc.*/
-		if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_PASS_RFC2833) && rtp_session->recv_msg.header.pt == rtp_session->te) {
+		/* RFC2833 ... TBD try harder to honor the duration etc. */
+		if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_PASS_RFC2833)
+			&& rtp_session->recv_msg.header.pt == rtp_session->te) {
 			unsigned char *packet = (unsigned char *) rtp_session->recv_msg.body;
-			int end = packet[1]&0x80;
-			int duration = (packet[2]<<8) + packet[3];
+			int end = packet[1] & 0x80;
+			int duration = (packet[2] << 8) + packet[3];
 			char key = switch_rfc2833_to_char(packet[0]);
-			uint16_t in_digit_seq = ntohs((uint16_t)rtp_session->recv_msg.header.seq);
+			uint16_t in_digit_seq = ntohs((uint16_t) rtp_session->recv_msg.header.seq);
 
-			/* SHEESH.... Curse you RFC2833 inventors!!!!*/
+			/* SHEESH.... Curse you RFC2833 inventors!!!! */
 			if ((time(NULL) - rtp_session->dtmf_data.last_digit_time) > 2) {
 				rtp_session->dtmf_data.last_digit = 0;
 				rtp_session->dtmf_data.dc = 0;
 			}
 			if (in_digit_seq > rtp_session->dtmf_data.in_digit_seq) {
 				rtp_session->dtmf_data.in_digit_seq = in_digit_seq;
-			
+
 				if (duration && end) {
 					if (key != rtp_session->dtmf_data.last_digit) {
-						char digit_str[] = {key, 0};
+						char digit_str[] = { key, 0 };
 						time(&rtp_session->dtmf_data.last_digit_time);
 						switch_rtp_queue_dtmf(rtp_session, digit_str);
 					}
@@ -946,13 +931,13 @@
 		break;
 	}
 
-	*payload_type = (switch_payload_t)rtp_session->recv_msg.header.pt;
+	*payload_type = (switch_payload_t) rtp_session->recv_msg.header.pt;
 
 
 	if (*payload_type == SWITCH_RTP_CNG_PAYLOAD) {
 		*flags |= SFF_CNG;
 	}
-	
+
 	if (bytes > 0) {
 		do_2833(rtp_session);
 	}
@@ -990,13 +975,13 @@
 
 	inuse = switch_buffer_inuse(rtp_session->dtmf_data.dtmf_buffer);
 	len = strlen(dtmf);
-	
+
 	if (len + inuse > switch_buffer_len(rtp_session->dtmf_data.dtmf_buffer)) {
 		switch_buffer_toss(rtp_session->dtmf_data.dtmf_buffer, strlen(dtmf));
 	}
 
 	p = dtmf;
-	while(wr < len && p) {
+	while (wr < len && p) {
 		if (is_dtmf(*p)) {
 			wr++;
 		} else {
@@ -1043,7 +1028,7 @@
 		switch_queue_create(&rtp_session->dtmf_data.dtmf_queue, 100, rtp_session->pool);
 	}
 
-	for(c = digits; *c; c++) {
+	for (c = digits; *c; c++) {
 		struct rfc2833_digit *rdigit;
 
 		if ((rdigit = malloc(sizeof(*rdigit))) != 0) {
@@ -1059,7 +1044,8 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-SWITCH_DECLARE(switch_status_t) switch_rtp_read(switch_rtp_t *rtp_session, void *data, uint32_t *datalen, switch_payload_t *payload_type, switch_frame_flag_t *flags)
+SWITCH_DECLARE(switch_status_t) switch_rtp_read(switch_rtp_t *rtp_session, void *data, uint32_t * datalen,
+												switch_payload_t *payload_type, switch_frame_flag_t *flags)
 {
 	int bytes = 0;
 
@@ -1068,7 +1054,7 @@
 	}
 
 	bytes = rtp_common_read(rtp_session, payload_type, flags);
-	
+
 	if (bytes < 0) {
 		*datalen = 0;
 		return SWITCH_STATUS_GENERR;
@@ -1083,7 +1069,7 @@
 
 	memcpy(data, rtp_session->recv_msg.body, bytes);
 
-	return SWITCH_STATUS_SUCCESS;	
+	return SWITCH_STATUS_SUCCESS;
 }
 
 SWITCH_DECLARE(switch_status_t) switch_rtp_zerocopy_read_frame(switch_rtp_t *rtp_session, switch_frame_t *frame)
@@ -1101,7 +1087,7 @@
 	frame->packetlen = bytes;
 	frame->source = __FILE__;
 	frame->flags |= SFF_RAW_RTP;
-	frame->timestamp =  ntohl(rtp_session->recv_msg.header.ts);
+	frame->timestamp = ntohl(rtp_session->recv_msg.header.ts);
 
 	if (bytes < 0) {
 		frame->datalen = 0;
@@ -1119,10 +1105,7 @@
 
 
 SWITCH_DECLARE(switch_status_t) switch_rtp_zerocopy_read(switch_rtp_t *rtp_session,
-														 void **data,
-														 uint32_t *datalen,
-														 switch_payload_t *payload_type,
-														 switch_frame_flag_t *flags)
+														 void **data, uint32_t * datalen, switch_payload_t *payload_type, switch_frame_flag_t *flags)
 {
 
 	int bytes = 0;
@@ -1156,8 +1139,8 @@
 		return SWITCH_STATUS_FALSE;
 	}
 
-	fwd = (uint8_t)(!flags || (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_RAW_WRITE) && (*flags & SFF_RAW_RTP)));
-		
+	fwd = (uint8_t) (!flags || (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_RAW_WRITE) && (*flags & SFF_RAW_RTP)));
+
 	if (fwd) {
 		bytes = datalen;
 		send_msg = (rtp_msg_t *) data;
@@ -1177,13 +1160,13 @@
 		rtp_session->seq++;
 		rtp_session->send_msg.header.seq = htons(rtp_session->seq);
 		rtp_session->send_msg.header.ts = htonl(rtp_session->ts);
-		
-        memcpy(send_msg->body, data, datalen);
-		bytes = datalen + rtp_header_len;	
+
+		memcpy(send_msg->body, data, datalen);
+		bytes = datalen + rtp_header_len;
 	}
 
 	if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_SECURE)) {
-		int sbytes = (int)bytes;
+		int sbytes = (int) bytes;
 		err_status_t stat;
 
 		stat = srtp_protect(rtp_session->send_ctx, &send_msg->header, &sbytes);
@@ -1198,18 +1181,18 @@
 		rtp_session->recv_msg.header.pt = 102;
 	}
 
-	if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_VAD) && 
+	if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_VAD) &&
 		rtp_session->recv_msg.header.pt == rtp_session->vad_data.read_codec->implementation->ianacode &&
-		((datalen == rtp_session->vad_data.read_codec->implementation->encoded_bytes_per_frame) || 
+		((datalen == rtp_session->vad_data.read_codec->implementation->encoded_bytes_per_frame) ||
 		 (datalen > SWITCH_RTP_CNG_PAYLOAD && rtp_session->vad_data.read_codec->implementation->encoded_bytes_per_frame == 0))) {
-		int16_t decoded[SWITCH_RECOMMENDED_BUFFER_SIZE/sizeof(int16_t)];
+		int16_t decoded[SWITCH_RECOMMENDED_BUFFER_SIZE / sizeof(int16_t)];
 		uint32_t rate;
 		uint32_t flags;
 		uint32_t len = sizeof(decoded);
 		time_t now = time(NULL);
 		send = 0;
 
-        
+
 		if (rtp_session->vad_data.scan_freq && rtp_session->vad_data.next_scan <= now) {
 			rtp_session->vad_data.bg_count = rtp_session->vad_data.bg_level = 0;
 			rtp_session->vad_data.next_scan = now + rtp_session->vad_data.scan_freq;
@@ -1221,10 +1204,7 @@
 									 data,
 									 datalen,
 									 rtp_session->vad_data.read_codec->implementation->samples_per_second,
-									 decoded,
-									 &len,
-									 &rate,
-									 &flags) == SWITCH_STATUS_SUCCESS) {
+									 decoded, &len, &rate, &flags) == SWITCH_STATUS_SUCCESS) {
 
 			uint32_t energy = 0;
 			uint32_t x, y = 0, z = len / sizeof(int16_t);
@@ -1235,7 +1215,7 @@
 					energy += abs(decoded[y]);
 					y += rtp_session->vad_data.read_codec->implementation->number_of_channels;
 				}
-				
+
 				if (++rtp_session->vad_data.start_count < rtp_session->vad_data.start) {
 					send = 1;
 				} else {
@@ -1269,7 +1249,7 @@
 										switch_event_fire(&event);
 									}
 								}
-							} 
+							}
 						} else {
 							if (rtp_session->vad_data.hangunder_hits) {
 								rtp_session->vad_data.hangunder_hits--;
@@ -1284,18 +1264,19 @@
 											switch_channel_t *channel = switch_core_session_get_channel(rtp_session->vad_data.session);
 											switch_channel_event_set_data(channel, event);
 											switch_event_fire(&event);
-										}					
+										}
 									}
 								}
 							}
 						}
 					}
 				}
-				
+
 				if (switch_test_flag(&rtp_session->vad_data, SWITCH_VAD_FLAG_TALKING)) {
 					send = 1;
 				} else {
-					if (switch_test_flag(&rtp_session->vad_data, SWITCH_VAD_FLAG_CNG) && ++rtp_session->vad_data.cng_count >= rtp_session->vad_data.cng_freq) {
+					if (switch_test_flag(&rtp_session->vad_data, SWITCH_VAD_FLAG_CNG)
+						&& ++rtp_session->vad_data.cng_count >= rtp_session->vad_data.cng_freq) {
 						rtp_session->send_msg.header.pt = SWITCH_RTP_CNG_PAYLOAD;
 						memset(rtp_session->send_msg.body, 255, SWITCH_RTP_CNG_PAYLOAD);
 						/* rtp_session->send_msg.header.ts = htonl(rtp_session->vad_data.ts);
@@ -1306,7 +1287,7 @@
 						rtp_session->vad_data.cng_count = 0;
 					}
 				}
-					   
+
 			}
 		} else {
 			return SWITCH_STATUS_GENERR;
@@ -1326,7 +1307,7 @@
 			switch_core_timer_check(&rtp_session->timer);
 			rtp_session->last_write_samplecount = rtp_session->timer.samplecount;
 		}
-        switch_socket_sendto(rtp_session->sock, rtp_session->remote_addr, 0, (void*)send_msg, &bytes);
+		switch_socket_sendto(rtp_session->sock, rtp_session->remote_addr, 0, (void *) send_msg, &bytes);
 	}
 
 	if (rtp_session->ice_user) {
@@ -1335,7 +1316,7 @@
 		}
 	}
 
-	return (int)bytes;
+	return (int) bytes;
 
 }
 
@@ -1355,7 +1336,8 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-SWITCH_DECLARE(switch_status_t) switch_rtp_enable_vad(switch_rtp_t *rtp_session, switch_core_session_t *session, switch_codec_t *codec, switch_vad_flag_t flags)
+SWITCH_DECLARE(switch_status_t) switch_rtp_enable_vad(switch_rtp_t *rtp_session, switch_core_session_t *session, switch_codec_t *codec,
+													  switch_vad_flag_t flags)
 {
 
 	if (!switch_rtp_ready(rtp_session)) {
@@ -1366,16 +1348,14 @@
 		return SWITCH_STATUS_GENERR;
 	}
 	memset(&rtp_session->vad_data, 0, sizeof(rtp_session->vad_data));
-	
+
 	if (switch_core_codec_init(&rtp_session->vad_data.vad_codec,
 							   codec->implementation->iananame,
 							   NULL,
 							   codec->implementation->samples_per_second,
 							   codec->implementation->microseconds_per_frame / 1000,
 							   codec->implementation->number_of_channels,
-							   SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
-							   NULL, 
-							   rtp_session->pool) != SWITCH_STATUS_SUCCESS) {
+							   SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, rtp_session->pool) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n");
 		return SWITCH_STATUS_FALSE;
 	}
@@ -1435,7 +1415,7 @@
 	uint32_t len;
 	switch_payload_t payload;
 
-	
+
 	if (!switch_rtp_ready(rtp_session)) {
 		return -1;
 	}
@@ -1446,7 +1426,7 @@
 	if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_IO) || !rtp_session->remote_addr) {
 		return -1;
 	}
-	
+
 	assert(frame != NULL);
 
 	if (switch_test_flag(frame, SFF_CNG)) {
@@ -1485,14 +1465,9 @@
 SWITCH_DECLARE(int) switch_rtp_write_manual(switch_rtp_t *rtp_session,
 											void *data,
 											uint16_t datalen,
-											uint8_t m,
-											switch_payload_t payload,
-											uint32_t ts,
-											uint16_t mseq,
-											uint32_t ssrc,
-											switch_frame_flag_t *flags)
+											uint8_t m, switch_payload_t payload, uint32_t ts, uint16_t mseq, uint32_t ssrc, switch_frame_flag_t *flags)
 {
-	rtp_msg_t send_msg = {{0}};
+	rtp_msg_t send_msg = { {0} };
 	switch_size_t bytes;
 
 	if (!switch_rtp_ready(rtp_session)) {
@@ -1516,7 +1491,7 @@
 
 
 	if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_SECURE)) {
-		int sbytes = (int)bytes;
+		int sbytes = (int) bytes;
 		err_status_t stat;
 
 		stat = srtp_protect(rtp_session->send_ctx, &send_msg.header, &sbytes);
@@ -1528,7 +1503,7 @@
 	}
 
 
-	if (switch_socket_sendto(rtp_session->sock, rtp_session->remote_addr, 0, (void*)&send_msg, &bytes) != SWITCH_STATUS_SUCCESS) {
+	if (switch_socket_sendto(rtp_session->sock, rtp_session->remote_addr, 0, (void *) &send_msg, &bytes) != SWITCH_STATUS_SUCCESS) {
 		return -1;
 	}
 	return (int) bytes;
@@ -1546,7 +1521,7 @@
 	rtp_session->private_data = private_data;
 }
 
-SWITCH_DECLARE(void *)switch_rtp_get_private(switch_rtp_t *rtp_session)
+SWITCH_DECLARE(void *) switch_rtp_get_private(switch_rtp_t *rtp_session)
 {
 	return rtp_session->private_data;
 }

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/switch_stun.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/switch_stun.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/switch_stun.c	Fri Mar 30 12:19:18 2007
@@ -38,55 +38,58 @@
 };
 
 static const struct value_mapping PACKET_TYPES[] = {
-	{ SWITCH_STUN_BINDING_REQUEST, "BINDING_REQUEST" },
-	{ SWITCH_STUN_BINDING_RESPONSE, "BINDING_RESPONSE" },
-	{ SWITCH_STUN_BINDING_ERROR_RESPONSE, "BINDING_ERROR_RESPONSE" },
-	{ SWITCH_STUN_SHARED_SECRET_REQUEST, "SHARED_SECRET_REQUEST" },
-	{ SWITCH_STUN_SHARED_SECRET_RESPONSE, "SHARED_SECRET_RESPONSE" },
-	{ SWITCH_STUN_SHARED_SECRET_ERROR_RESPONSE, "SHARED_SECRET_ERROR_RESPONSE" },
-	{ SWITCH_STUN_ALLOCATE_REQUEST, "ALLOCATE_REQUEST" },
-	{ SWITCH_STUN_ALLOCATE_RESPONSE, "ALLOCATE_RESPONSE" },
-	{ SWITCH_STUN_ALLOCATE_ERROR_RESPONSE, "ALLOCATE_ERROR_RESPONSE" },
-	{ SWITCH_STUN_SEND_REQUEST, "SEND_REQUEST" },
-	{ SWITCH_STUN_SEND_RESPONSE, "SEND_RESPONSE" },
-	{ SWITCH_STUN_SEND_ERROR_RESPONSE, "SEND_ERROR_RESPONSE" },
-	{ SWITCH_STUN_DATA_INDICATION , "DATA_INDICATION"},
-	{ 0, 0} };
+	{SWITCH_STUN_BINDING_REQUEST, "BINDING_REQUEST"},
+	{SWITCH_STUN_BINDING_RESPONSE, "BINDING_RESPONSE"},
+	{SWITCH_STUN_BINDING_ERROR_RESPONSE, "BINDING_ERROR_RESPONSE"},
+	{SWITCH_STUN_SHARED_SECRET_REQUEST, "SHARED_SECRET_REQUEST"},
+	{SWITCH_STUN_SHARED_SECRET_RESPONSE, "SHARED_SECRET_RESPONSE"},
+	{SWITCH_STUN_SHARED_SECRET_ERROR_RESPONSE, "SHARED_SECRET_ERROR_RESPONSE"},
+	{SWITCH_STUN_ALLOCATE_REQUEST, "ALLOCATE_REQUEST"},
+	{SWITCH_STUN_ALLOCATE_RESPONSE, "ALLOCATE_RESPONSE"},
+	{SWITCH_STUN_ALLOCATE_ERROR_RESPONSE, "ALLOCATE_ERROR_RESPONSE"},
+	{SWITCH_STUN_SEND_REQUEST, "SEND_REQUEST"},
+	{SWITCH_STUN_SEND_RESPONSE, "SEND_RESPONSE"},
+	{SWITCH_STUN_SEND_ERROR_RESPONSE, "SEND_ERROR_RESPONSE"},
+	{SWITCH_STUN_DATA_INDICATION, "DATA_INDICATION"},
+	{0, 0}
+};
 
 static const struct value_mapping ATTR_TYPES[] = {
-	{ SWITCH_STUN_ATTR_MAPPED_ADDRESS, "MAPPED_ADDRESS" },
-	{ SWITCH_STUN_ATTR_RESPONSE_ADDRESS, "RESPONSE_ADDRESS" },
-	{ SWITCH_STUN_ATTR_CHANGE_REQUEST, "CHANGE_REQUEST" },
-	{ SWITCH_STUN_ATTR_SOURCE_ADDRESS, "SOURCE_ADDRESS" },
-	{ SWITCH_STUN_ATTR_CHANGED_ADDRESS, "CHANGED_ADDRESS" },
-	{ SWITCH_STUN_ATTR_USERNAME, "USERNAME" },
-	{ SWITCH_STUN_ATTR_PASSWORD, "PASSWORD" },
-	{ SWITCH_STUN_ATTR_MESSAGE_INTEGRITY, "MESSAGE_INTEGRITY" },
-	{ SWITCH_STUN_ATTR_ERROR_CODE, "ERROR_CODE" },
-	{ SWITCH_STUN_ATTR_UNKNOWN_ATTRIBUTES, "UNKNOWN_ATTRIBUTES" },
-	{ SWITCH_STUN_ATTR_REFLECTED_FROM, "REFLECTED_FROM" },
-	{ SWITCH_STUN_ATTR_TRANSPORT_PREFERENCES, "TRANSPORT_PREFERENCES" },
-	{ SWITCH_STUN_ATTR_LIFETIME, "LIFETIME" },
-	{ SWITCH_STUN_ATTR_ALTERNATE_SERVER, "ALTERNATE_SERVER" },
-	{ SWITCH_STUN_ATTR_MAGIC_COOKIE, "MAGIC_COOKIE" },
-	{ SWITCH_STUN_ATTR_BANDWIDTH, "BANDWIDTH" },
-	{ SWITCH_STUN_ATTR_DESTINATION_ADDRESS, "DESTINATION_ADDRESS" },
-	{ SWITCH_STUN_ATTR_SOURCE_ADDRESS2, "SOURCE_ADDRESS2" },
-	{ SWITCH_STUN_ATTR_DATA, "DATA" },
-	{ SWITCH_STUN_ATTR_OPTIONS, "OPTIONS" },
-	{ 0, 0} };
+	{SWITCH_STUN_ATTR_MAPPED_ADDRESS, "MAPPED_ADDRESS"},
+	{SWITCH_STUN_ATTR_RESPONSE_ADDRESS, "RESPONSE_ADDRESS"},
+	{SWITCH_STUN_ATTR_CHANGE_REQUEST, "CHANGE_REQUEST"},
+	{SWITCH_STUN_ATTR_SOURCE_ADDRESS, "SOURCE_ADDRESS"},
+	{SWITCH_STUN_ATTR_CHANGED_ADDRESS, "CHANGED_ADDRESS"},
+	{SWITCH_STUN_ATTR_USERNAME, "USERNAME"},
+	{SWITCH_STUN_ATTR_PASSWORD, "PASSWORD"},
+	{SWITCH_STUN_ATTR_MESSAGE_INTEGRITY, "MESSAGE_INTEGRITY"},
+	{SWITCH_STUN_ATTR_ERROR_CODE, "ERROR_CODE"},
+	{SWITCH_STUN_ATTR_UNKNOWN_ATTRIBUTES, "UNKNOWN_ATTRIBUTES"},
+	{SWITCH_STUN_ATTR_REFLECTED_FROM, "REFLECTED_FROM"},
+	{SWITCH_STUN_ATTR_TRANSPORT_PREFERENCES, "TRANSPORT_PREFERENCES"},
+	{SWITCH_STUN_ATTR_LIFETIME, "LIFETIME"},
+	{SWITCH_STUN_ATTR_ALTERNATE_SERVER, "ALTERNATE_SERVER"},
+	{SWITCH_STUN_ATTR_MAGIC_COOKIE, "MAGIC_COOKIE"},
+	{SWITCH_STUN_ATTR_BANDWIDTH, "BANDWIDTH"},
+	{SWITCH_STUN_ATTR_DESTINATION_ADDRESS, "DESTINATION_ADDRESS"},
+	{SWITCH_STUN_ATTR_SOURCE_ADDRESS2, "SOURCE_ADDRESS2"},
+	{SWITCH_STUN_ATTR_DATA, "DATA"},
+	{SWITCH_STUN_ATTR_OPTIONS, "OPTIONS"},
+	{0, 0}
+};
 
 static const struct value_mapping ERROR_TYPES[] = {
-	{ SWITCH_STUN_ERROR_BAD_REQUEST, "BAD_REQUEST" },
-	{ SWITCH_STUN_ERROR_UNAUTHORIZED, "UNAUTHORIZED" },
-	{ SWITCH_STUN_ERROR_UNKNOWN_ATTRIBUTE, "UNKNOWN_ATTRIBUTE" },
-	{ SWITCH_STUN_ERROR_STALE_CREDENTIALS, "STALE_CREDENTIALS" },
-	{ SWITCH_STUN_ERROR_INTEGRITY_CHECK_FAILURE, "INTEGRITY_CHECK_FAILURE" },
-	{ SWITCH_STUN_ERROR_MISSING_USERNAME, "MISSING_USERNAME" },
-	{ SWITCH_STUN_ERROR_USE_TLS, "USE_TLS" },
-	{ SWITCH_STUN_ERROR_SERVER_ERROR, "SERVER_ERROR" },
-	{ SWITCH_STUN_ERROR_GLOBAL_FAILURE, "GLOBAL_FAILURE" }, 
-	{ 0, 0 }};
+	{SWITCH_STUN_ERROR_BAD_REQUEST, "BAD_REQUEST"},
+	{SWITCH_STUN_ERROR_UNAUTHORIZED, "UNAUTHORIZED"},
+	{SWITCH_STUN_ERROR_UNKNOWN_ATTRIBUTE, "UNKNOWN_ATTRIBUTE"},
+	{SWITCH_STUN_ERROR_STALE_CREDENTIALS, "STALE_CREDENTIALS"},
+	{SWITCH_STUN_ERROR_INTEGRITY_CHECK_FAILURE, "INTEGRITY_CHECK_FAILURE"},
+	{SWITCH_STUN_ERROR_MISSING_USERNAME, "MISSING_USERNAME"},
+	{SWITCH_STUN_ERROR_USE_TLS, "USE_TLS"},
+	{SWITCH_STUN_ERROR_SERVER_ERROR, "SERVER_ERROR"},
+	{SWITCH_STUN_ERROR_GLOBAL_FAILURE, "GLOBAL_FAILURE"},
+	{0, 0}
+};
 
 SWITCH_DECLARE(void) switch_stun_random_string(char *buf, uint16_t len, char *set)
 {
@@ -98,19 +101,19 @@
 		set = chars;
 	}
 
-	max = (int)strlen(set);
+	max = (int) strlen(set);
 
-	srand((unsigned int)switch_time_now());
+	srand((unsigned int) switch_time_now());
 
-	for(x = 0; x < len; x++) {
-		int j = (int)(max*1.0*rand()/(RAND_MAX+1.0));
+	for (x = 0; x < len; x++) {
+		int j = (int) (max * 1.0 * rand() / (RAND_MAX + 1.0));
 		buf[x] = set[j];
 	}
 }
 
 
 
-SWITCH_DECLARE(switch_stun_packet_t *)switch_stun_packet_parse(uint8_t *buf, uint32_t len)
+SWITCH_DECLARE(switch_stun_packet_t *) switch_stun_packet_parse(uint8_t * buf, uint32_t len)
 {
 	switch_stun_packet_t *packet;
 	switch_stun_packet_attribute_t *attr;
@@ -129,7 +132,7 @@
 		if (!attr->length) {
 			break;
 		}
-		switch(attr->type) {
+		switch (attr->type) {
 		case SWITCH_STUN_ATTR_MAPPED_ADDRESS:
 			if (attr->type) {
 				switch_stun_ip_t *ip;
@@ -143,8 +146,7 @@
 	return packet;
 }
 
-SWITCH_DECLARE(const char *)switch_stun_value_to_name(int32_t type, uint32_t value)
-
+SWITCH_DECLARE(const char *) switch_stun_value_to_name(int32_t type, uint32_t value)
 {
 	uint32_t x = 0;
 	const struct value_mapping *map = NULL;
@@ -164,26 +166,26 @@
 	}
 
 	if (map) {
-		for(x = 0; map[x].value; x++) {
+		for (x = 0; map[x].value; x++) {
 			if (map[x].value == value) {
 				return map[x].name;
 			}
 		}
 	}
-	
+
 	return "INVALID";
 }
 
-SWITCH_DECLARE(uint8_t) switch_stun_packet_attribute_get_mapped_address(switch_stun_packet_attribute_t *attribute, char *ipstr, uint16_t *port)
+SWITCH_DECLARE(uint8_t) switch_stun_packet_attribute_get_mapped_address(switch_stun_packet_attribute_t *attribute, char *ipstr, uint16_t * port)
 {
 	switch_stun_ip_t *ip;
 	uint8_t x, *i;
 	char *p = ipstr;
-	
+
 	ip = (switch_stun_ip_t *) attribute->value;
-	i = (uint8_t *) &ip->address;
+	i = (uint8_t *) & ip->address;
 	*ipstr = 0;
-	for(x =0; x < 4; x++) {
+	for (x = 0; x < 4; x++) {
 		sprintf(p, "%u%s", i[x], x == 3 ? "" : ".");
 		p = ipstr + strlen(ipstr);
 	}
@@ -191,7 +193,7 @@
 	return 1;
 }
 
-SWITCH_DECLARE(char *)switch_stun_packet_attribute_get_username(switch_stun_packet_attribute_t *attribute, char *username, uint16_t len)
+SWITCH_DECLARE(char *) switch_stun_packet_attribute_get_username(switch_stun_packet_attribute_t *attribute, char *username, uint16_t len)
 {
 	uint16_t cpylen;
 
@@ -199,18 +201,15 @@
 	return memcpy(username, attribute->value, cpylen);
 }
 
-SWITCH_DECLARE(switch_stun_packet_t *)switch_stun_packet_build_header(switch_stun_message_t type,
-																	  char *id,
-																	  uint8_t *buf
-																	  )
+SWITCH_DECLARE(switch_stun_packet_t *) switch_stun_packet_build_header(switch_stun_message_t type, char *id, uint8_t * buf)
 {
 	switch_stun_packet_header_t *header;
 
-	
+
 	header = (switch_stun_packet_header_t *) buf;
 	header->type = htons(type);
 	header->length = 0;
-	
+
 	if (id) {
 		memcpy(header->id, id, 16);
 	} else {
@@ -220,24 +219,24 @@
 	return (switch_stun_packet_t *) buf;
 }
 
-SWITCH_DECLARE(uint8_t) switch_stun_packet_attribute_add_binded_address(switch_stun_packet_t *packet, char *ipstr,  uint16_t port)
+SWITCH_DECLARE(uint8_t) switch_stun_packet_attribute_add_binded_address(switch_stun_packet_t *packet, char *ipstr, uint16_t port)
 {
 	switch_stun_packet_attribute_t *attribute;
 	switch_stun_ip_t *ip;
 	uint8_t *i, x;
 	char *p = ipstr;
 
-	attribute = (switch_stun_packet_attribute_t *) ((uint8_t *) &packet->first_attribute + ntohs(packet->header.length));
+	attribute = (switch_stun_packet_attribute_t *) ((uint8_t *) & packet->first_attribute + ntohs(packet->header.length));
 	attribute->type = htons(SWITCH_STUN_ATTR_MAPPED_ADDRESS);
 	attribute->length = htons(8);
 	ip = (switch_stun_ip_t *) attribute->value;
 
 	ip->port = htons(port);
 	ip->family = 1;
-	i = (uint8_t *) &ip->address;
+	i = (uint8_t *) & ip->address;
 
-	for(x = 0; x < 4 ; x++) {
-		i[x] = (uint8_t)atoi(p);
+	for (x = 0; x < 4; x++) {
+		i[x] = (uint8_t) atoi(p);
 		if ((p = strchr(p, '.'))) {
 			p++;
 		} else {
@@ -256,34 +255,29 @@
 	if (ulen % 4 != 0) {
 		return 0;
 	}
-	attribute = (switch_stun_packet_attribute_t *) ((uint8_t *) &packet->first_attribute + ntohs(packet->header.length));
+	attribute = (switch_stun_packet_attribute_t *) ((uint8_t *) & packet->first_attribute + ntohs(packet->header.length));
 	attribute->type = htons(SWITCH_STUN_ATTR_USERNAME);
 	attribute->length = htons(ulen);
 	if (username) {
 		memcpy(attribute->value, username, ulen);
 	} else {
 		switch_stun_random_string(attribute->value, ulen, NULL);
-	} 
+	}
 
 	packet->header.length += htons(sizeof(switch_stun_packet_attribute_t)) + attribute->length;
 	return 1;
 }
 
-SWITCH_DECLARE(switch_status_t) switch_stun_lookup (char **ip, 
-												  switch_port_t *port,
-												  char *stunip,
-												  switch_port_t stunport,
-												  char **err,
-												  switch_memory_pool_t *pool)
-	 
+SWITCH_DECLARE(switch_status_t) switch_stun_lookup(char **ip,
+												   switch_port_t *port, char *stunip, switch_port_t stunport, char **err, switch_memory_pool_t *pool)
 {
 	switch_sockaddr_t *local_addr = NULL, *remote_addr = NULL, *from_addr = NULL;
 	switch_socket_t *sock = NULL;
-	uint8_t buf[256] = {0};
+	uint8_t buf[256] = { 0 };
 	switch_stun_packet_t *packet;
 	switch_stun_packet_attribute_t *attr;
 	switch_size_t bytes = 0;
-	char username[33] = {0};
+	char username[33] = { 0 };
 	char rip[16];
 	uint16_t rport = 0;
 	switch_time_t started = 0;
@@ -307,31 +301,31 @@
 		*err = "Socket Error!";
 		return SWITCH_STATUS_FALSE;
 	}
-	
+
 	if (switch_socket_bind(sock, local_addr) != SWITCH_STATUS_SUCCESS) {
 		*err = "Bind Error!";
 		return SWITCH_STATUS_FALSE;
 	}
-	
+
 	switch_socket_opt_set(sock, SWITCH_SO_NONBLOCK, TRUE);
 	packet = switch_stun_packet_build_header(SWITCH_STUN_BINDING_REQUEST, NULL, buf);
 	switch_stun_random_string(username, 32, NULL);
 	switch_stun_packet_attribute_add_username(packet, username, 32);
 	bytes = switch_stun_packet_length(packet);
-	switch_socket_sendto(sock, remote_addr, 0, (void *)packet, &bytes);
+	switch_socket_sendto(sock, remote_addr, 0, (void *) packet, &bytes);
 	started = switch_time_now();
-	
+
 	*ip = NULL;
 	*port = 0;
 
 
-	for(;;) {
+	for (;;) {
 		bytes = sizeof(buf);
-		if (switch_socket_recvfrom(from_addr, sock, 0, (char *)&buf, &bytes) == SWITCH_STATUS_SUCCESS && bytes > 0) {
+		if (switch_socket_recvfrom(from_addr, sock, 0, (char *) &buf, &bytes) == SWITCH_STATUS_SUCCESS && bytes > 0) {
 			break;
 		}
 
-		if ((elapsed = (unsigned int)((switch_time_now() - started) / 1000)) > 5000) {
+		if ((elapsed = (unsigned int) ((switch_time_now() - started) / 1000)) > 5000) {
 			*err = "Timeout";
 			switch_socket_shutdown(sock, SWITCH_SHUTDOWN_READWRITE);
 			switch_socket_close(sock);
@@ -345,14 +339,14 @@
 	switch_stun_packet_first_attribute(packet, attr);
 
 	do {
-		switch(attr->type) {
+		switch (attr->type) {
 		case SWITCH_STUN_ATTR_MAPPED_ADDRESS:
 			if (attr->type) {
 				switch_stun_packet_attribute_get_mapped_address(attr, rip, &rport);
 			}
 			break;
 		case SWITCH_STUN_ATTR_USERNAME:
-			if(attr->type) {
+			if (attr->type) {
 				switch_stun_packet_attribute_get_username(attr, username, 32);
 			}
 			break;
@@ -366,7 +360,7 @@
 	} else {
 		*err = "Invalid Reply";
 	}
-	
+
 
 	return SWITCH_STATUS_FALSE;
 }

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/switch_swig.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/switch_swig.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/switch_swig.c	Fri Mar 30 12:19:18 2007
@@ -80,7 +80,7 @@
 	return 1;
 }
 
-int fs_console_loop(void) 
+int fs_console_loop(void)
 {
 	switch_console_loop();
 	return 0;
@@ -88,17 +88,17 @@
 
 void fs_consol_log(char *level_str, char *msg)
 {
-    switch_log_level_t level = SWITCH_LOG_DEBUG;
-    if (level_str) {
-        level = switch_log_str2level(level_str);
+	switch_log_level_t level = SWITCH_LOG_DEBUG;
+	if (level_str) {
+		level = switch_log_str2level(level_str);
 	}
-      
-    switch_log_printf(SWITCH_CHANNEL_LOG, level, msg);
+
+	switch_log_printf(SWITCH_CHANNEL_LOG, level, msg);
 }
-	
+
 void fs_consol_clean(char *msg)
 {
-    switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_DEBUG, msg);
+	switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_DEBUG, msg);
 }
 
 switch_core_session_t *fs_core_session_locate(char *uuid)
@@ -157,71 +157,54 @@
   IVR Routines!  You can do IVR in PHP NOW!
 */
 
-int fs_ivr_play_file(switch_core_session_t *session,
-                     switch_file_handle_t *fh,
-					 char *file,
-                     switch_input_args_t *args)
+int fs_ivr_play_file(switch_core_session_t *session, switch_file_handle_t *fh, char *file, switch_input_args_t *args)
 {
 	switch_status_t status;
-	
+
 	status = switch_ivr_play_file(session, fh, file, args);
 	return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
 }
 
-int fs_switch_ivr_record_file(switch_core_session_t *session,
-                              switch_file_handle_t *fh,
-                              char *file,
-                              switch_input_args_t *args,
-                              unsigned int limit
-                              )
-{  
-	switch_status_t status;
-	
-    status = switch_ivr_record_file(session, fh, file, args, limit);
-    return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
+int fs_switch_ivr_record_file(switch_core_session_t *session, switch_file_handle_t *fh, char *file, switch_input_args_t *args, unsigned int limit)
+{
+	switch_status_t status;
+
+	status = switch_ivr_record_file(session, fh, file, args, limit);
+	return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
 }
 
-int fs_switch_ivr_sleep(switch_core_session_t *session,
-                        uint32_t ms)
+int fs_switch_ivr_sleep(switch_core_session_t *session, uint32_t ms)
 {
 	switch_status_t status;
 	status = switch_ivr_sleep(session, ms);
 	return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
 }
 
-int fs_ivr_play_file2(switch_core_session_t *session,
-					  char *file)
-
+int fs_ivr_play_file2(switch_core_session_t *session, char *file)
 {
 	switch_status_t status;
-	
+
 	status = switch_ivr_play_file(session, NULL, file, NULL);
 	return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
 }
 
 
-int fs_switch_ivr_collect_digits_callback (switch_core_session_t *session,
-                                           switch_input_args_t *args,
-										   unsigned int timeout)
+int fs_switch_ivr_collect_digits_callback(switch_core_session_t *session, switch_input_args_t *args, unsigned int timeout)
 {
-    switch_status_t status;
+	switch_status_t status;
 
-    status = switch_ivr_collect_digits_callback(session, args, timeout);
-    return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
+	status = switch_ivr_collect_digits_callback(session, args, timeout);
+	return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
 }
 
-int fs_switch_ivr_collect_digits_count  	(switch_core_session_t *session,
-                                             char *buf,
-                                             unsigned int buflen,
-                                             unsigned int maxdigits,
-                                             const char *terminators,
-                                             char *terminator,
-                                             unsigned int timeout)  
+int fs_switch_ivr_collect_digits_count(switch_core_session_t *session,
+									   char *buf, unsigned int buflen, unsigned int maxdigits, const char *terminators, char *terminator,
+									   unsigned int timeout)
 {
-    switch_status_t status;
+	switch_status_t status;
 
-    status = switch_ivr_collect_digits_count(session, buf, buflen, maxdigits, terminators, terminator, timeout);
-    return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
+	status = switch_ivr_collect_digits_count(session, buf, buflen, maxdigits, terminators, terminator, timeout);
+	return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
 }
 
 /*int fs_switch_ivr_multi_threaded_bridge   (switch_core_session_t *session,
@@ -237,61 +220,51 @@
   }
 */
 
-int fs_switch_ivr_originate       (switch_core_session_t *session,
-                                   switch_core_session_t **bleg,
-                                   char *  	bridgeto,
-                                   uint32_t  	timelimit_sec)
+int fs_switch_ivr_originate(switch_core_session_t *session, switch_core_session_t **bleg, char *bridgeto, uint32_t timelimit_sec)
 /*const switch_state_handler_table_t *table,
   char *  	cid_name_override,
   char *  	cid_num_override,
   switch_caller_profile_t *caller_profile_override)  */
 {
 
-    switch_channel_t *caller_channel;
-    switch_core_session_t *peer_session;
-    unsigned int timelimit = 60;
-    char *var;
-    switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING;
+	switch_channel_t *caller_channel;
+	switch_core_session_t *peer_session;
+	unsigned int timelimit = 60;
+	char *var;
+	switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING;
+
+	caller_channel = switch_core_session_get_channel(session);
+	assert(caller_channel != NULL);
 
-    caller_channel = switch_core_session_get_channel(session);
-    assert(caller_channel != NULL);
+	if ((var = switch_channel_get_variable(caller_channel, "call_timeout"))) {
+		timelimit = atoi(var);
+	}
 
-    if ((var = switch_channel_get_variable(caller_channel, "call_timeout"))) {
-        timelimit = atoi(var);
-    }
-        
-    if (switch_ivr_originate(session, &peer_session, &cause, bridgeto, timelimit, NULL, NULL, NULL, NULL) != SWITCH_STATUS_SUCCESS) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Create Outgoing Channel!\n");
-        switch_channel_hangup(caller_channel, SWITCH_CAUSE_REQUESTED_CHAN_UNAVAIL);
-        return;
-    } else {
-        switch_ivr_multi_threaded_bridge(session, peer_session, NULL, NULL, NULL);
-    }
+	if (switch_ivr_originate(session, &peer_session, &cause, bridgeto, timelimit, NULL, NULL, NULL, NULL) != SWITCH_STATUS_SUCCESS) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Create Outgoing Channel!\n");
+		switch_channel_hangup(caller_channel, SWITCH_CAUSE_REQUESTED_CHAN_UNAVAIL);
+		return;
+	} else {
+		switch_ivr_multi_threaded_bridge(session, peer_session, NULL, NULL, NULL);
+	}
 
 
 }
 
-int fs_switch_ivr_session_transfer(switch_core_session_t *session,
-                                   char *extension,
-                                   char *dialplan,
-                                   char *context)  
+int fs_switch_ivr_session_transfer(switch_core_session_t *session, char *extension, char *dialplan, char *context)
 {
-    switch_status_t status;
+	switch_status_t status;
 
-    status = switch_ivr_session_transfer(session,extension,dialplan,context);
-    return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
+	status = switch_ivr_session_transfer(session, extension, dialplan, context);
+	return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
 }
 
-int fs_switch_ivr_speak_text      (switch_core_session_t *session,
-                                   char *tts_name,
-                                   char *voice_name,
-                                   uint32_t  	rate,
-                                   char *text)
+int fs_switch_ivr_speak_text(switch_core_session_t *session, char *tts_name, char *voice_name, uint32_t rate, char *text)
 {
-    switch_status_t status;
+	switch_status_t status;
 
-    status = switch_ivr_speak_text(session,tts_name,voice_name,rate,text,NULL);
-    return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
+	status = switch_ivr_speak_text(session, tts_name, voice_name, rate, text, NULL);
+	return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
 }
 
 
@@ -301,7 +274,7 @@
 
 */
 
-char* fs_switch_channel_get_variable(switch_channel_t *channel, char *varname)
+char *fs_switch_channel_get_variable(switch_channel_t *channel, char *varname)
 {
 	return switch_channel_get_variable(channel, varname);
 }
@@ -309,11 +282,11 @@
 
 int fs_switch_channel_set_variable(switch_channel_t *channel, char *varname, char *value)
 {
-    switch_status_t status;
+	switch_status_t status;
 
-    status = switch_channel_set_variable(channel, varname, value);
-    return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
-}  
+	status = switch_channel_set_variable(channel, varname, value);
+	return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
+}
 
 /* For Emacs:
  * Local Variables:

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/switch_utils.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/switch_utils.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/switch_utils.c	Fri Mar 30 12:19:18 2007
@@ -36,216 +36,202 @@
 
 SWITCH_DECLARE(switch_status_t) switch_find_local_ip(char *buf, int len, int family)
 {
-    switch_status_t status = SWITCH_STATUS_FALSE;
-    char *base;
+	switch_status_t status = SWITCH_STATUS_FALSE;
+	char *base;
 
 #ifdef WIN32
-    SOCKET tmp_socket;
-    SOCKADDR_STORAGE l_address;
-    int l_address_len;
-    struct addrinfo *address_info;
+	SOCKET tmp_socket;
+	SOCKADDR_STORAGE l_address;
+	int l_address_len;
+	struct addrinfo *address_info;
 #else
 #ifdef __Darwin__
-    int ilen;
+	int ilen;
 #else
-    unsigned int ilen;
+	unsigned int ilen;
 #endif
-    int tmp_socket = -1, on = 1;
-    char abuf[25] = "";
+	int tmp_socket = -1, on = 1;
+	char abuf[25] = "";
 #endif
 
-    switch_copy_string(buf, "127.0.0.1", len);
+	switch_copy_string(buf, "127.0.0.1", len);
 
-    switch(family) {
-    case AF_INET:
-        base = "82.45.148.209";
-        break;
-    case AF_INET6:
-        base = "52.2d.94.d1";
-        break;
+	switch (family) {
+	case AF_INET:
+		base = "82.45.148.209";
+		break;
+	case AF_INET6:
+		base = "52.2d.94.d1";
+		break;
 	default:
 		base = "127.0.0.1";
 		break;
-    }
+	}
 
 
 #ifdef WIN32
-    tmp_socket = socket(family, SOCK_DGRAM, 0);
+	tmp_socket = socket(family, SOCK_DGRAM, 0);
+
+	getaddrinfo(base, NULL, NULL, &address_info);
+
+	if (WSAIoctl(tmp_socket,
+				 SIO_ROUTING_INTERFACE_QUERY,
+				 address_info->ai_addr, (DWORD) address_info->ai_addrlen, &l_address, sizeof(l_address), (LPDWORD) & l_address_len, NULL, NULL)) {
+
+		closesocket(tmp_socket);
+		freeaddrinfo(address_info);
+		return status;
+	}
+
+	closesocket(tmp_socket);
+	freeaddrinfo(address_info);
+
+	if (!getnameinfo((const struct sockaddr *) &l_address, l_address_len, buf, len, NULL, 0, NI_NUMERICHOST)) {
 
-    getaddrinfo(base, NULL, NULL, &address_info);
-  
-    if (WSAIoctl(tmp_socket,
-                 SIO_ROUTING_INTERFACE_QUERY,
-                 address_info->ai_addr,
-                 (DWORD)address_info->ai_addrlen,
-                 &l_address,
-                 sizeof(l_address),
-                 (LPDWORD)&l_address_len,
-                 NULL,
-                 NULL)) {
-        
-        closesocket(tmp_socket);
-        freeaddrinfo(address_info);
-        return status;
-    }
-  
-    closesocket(tmp_socket);
-    freeaddrinfo(address_info);
-  
-    if(!getnameinfo((const struct sockaddr*)&l_address,
-                    l_address_len,
-                    buf,
-                    len,
-                    NULL,
-                    0,
-                    NI_NUMERICHOST)) {
-
-        status = SWITCH_STATUS_SUCCESS;
-        
-    }
+		status = SWITCH_STATUS_SUCCESS;
 
+	}
 #else
 
-    switch(family) {
-    case AF_INET:
-        {
-            struct sockaddr_in iface_out;
-            struct sockaddr_in remote;          
-            memset (&remote, 0, sizeof (struct sockaddr_in));
-
-            remote.sin_family = AF_INET;
-            remote.sin_addr.s_addr = inet_addr (base);
-            remote.sin_port = htons (4242);
-
-            memset (&iface_out, 0, sizeof (iface_out));
-            tmp_socket = socket (AF_INET, SOCK_DGRAM, 0);
-            
-            if (setsockopt (tmp_socket, SOL_SOCKET, SO_BROADCAST, &on, sizeof (on)) == -1) {
-                goto doh;
-            }
-
-            if (connect (tmp_socket, (struct sockaddr *) &remote, sizeof (struct sockaddr_in)) == -1) {
-                goto doh;
-            }
-
-            ilen = sizeof (iface_out);
-            if (getsockname (tmp_socket, (struct sockaddr *) &iface_out, &ilen) == -1) {
-                goto doh;
-            }
-
-            if (iface_out.sin_addr.s_addr == 0) {
-                goto doh;
-            }
-            
-            switch_copy_string(buf, get_addr(abuf, sizeof(abuf), &iface_out.sin_addr), len);
-            status = SWITCH_STATUS_SUCCESS;
-        }
-        break;
-        case AF_INET6:
-        {
-            struct sockaddr_in6 iface_out;
-            struct sockaddr_in6 remote;
-            memset (&remote, 0, sizeof (struct sockaddr_in6));
-
-            remote.sin6_family = AF_INET6;
-            inet_pton (AF_INET6, buf, &remote.sin6_addr);
-            remote.sin6_port = htons (4242);
-
-            memset (&iface_out, 0, sizeof (iface_out));
-            tmp_socket = socket (AF_INET6, SOCK_DGRAM, 0);
-
-            if (setsockopt (tmp_socket, SOL_SOCKET, SO_BROADCAST, &on, sizeof (on)) == -1) {
-                goto doh;
-            }
-
-            if (connect (tmp_socket, (struct sockaddr *) &remote, sizeof (struct sockaddr_in)) == -1) {
-                goto doh;
-            }
-
-            ilen = sizeof (iface_out);
-            if (getsockname (tmp_socket, (struct sockaddr *) &iface_out, &ilen) == -1) {
-                goto doh;
-            }
-            
-            if (iface_out.sin6_addr.s6_addr == 0) {
-                goto doh;
-            }
-
-            inet_ntop (AF_INET6, (const void *) &iface_out.sin6_addr, buf, len - 1);
-            status = SWITCH_STATUS_SUCCESS;
-        }
-        break;
-    }
-
-
- doh:
-    if (tmp_socket > 0) {
-        close (tmp_socket);
-        tmp_socket = -1;
-    }
+	switch (family) {
+	case AF_INET:
+		{
+			struct sockaddr_in iface_out;
+			struct sockaddr_in remote;
+			memset(&remote, 0, sizeof(struct sockaddr_in));
+
+			remote.sin_family = AF_INET;
+			remote.sin_addr.s_addr = inet_addr(base);
+			remote.sin_port = htons(4242);
+
+			memset(&iface_out, 0, sizeof(iface_out));
+			tmp_socket = socket(AF_INET, SOCK_DGRAM, 0);
+
+			if (setsockopt(tmp_socket, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on)) == -1) {
+				goto doh;
+			}
+
+			if (connect(tmp_socket, (struct sockaddr *) &remote, sizeof(struct sockaddr_in)) == -1) {
+				goto doh;
+			}
+
+			ilen = sizeof(iface_out);
+			if (getsockname(tmp_socket, (struct sockaddr *) &iface_out, &ilen) == -1) {
+				goto doh;
+			}
+
+			if (iface_out.sin_addr.s_addr == 0) {
+				goto doh;
+			}
+
+			switch_copy_string(buf, get_addr(abuf, sizeof(abuf), &iface_out.sin_addr), len);
+			status = SWITCH_STATUS_SUCCESS;
+		}
+		break;
+	case AF_INET6:
+		{
+			struct sockaddr_in6 iface_out;
+			struct sockaddr_in6 remote;
+			memset(&remote, 0, sizeof(struct sockaddr_in6));
+
+			remote.sin6_family = AF_INET6;
+			inet_pton(AF_INET6, buf, &remote.sin6_addr);
+			remote.sin6_port = htons(4242);
+
+			memset(&iface_out, 0, sizeof(iface_out));
+			tmp_socket = socket(AF_INET6, SOCK_DGRAM, 0);
+
+			if (setsockopt(tmp_socket, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on)) == -1) {
+				goto doh;
+			}
+
+			if (connect(tmp_socket, (struct sockaddr *) &remote, sizeof(struct sockaddr_in)) == -1) {
+				goto doh;
+			}
+
+			ilen = sizeof(iface_out);
+			if (getsockname(tmp_socket, (struct sockaddr *) &iface_out, &ilen) == -1) {
+				goto doh;
+			}
+
+			if (iface_out.sin6_addr.s6_addr == 0) {
+				goto doh;
+			}
+
+			inet_ntop(AF_INET6, (const void *) &iface_out.sin6_addr, buf, len - 1);
+			status = SWITCH_STATUS_SUCCESS;
+		}
+		break;
+	}
+
 
+  doh:
+	if (tmp_socket > 0) {
+		close(tmp_socket);
+		tmp_socket = -1;
+	}
 #endif
 
-    return status;
- 
+	return status;
+
 }
 
 
 SWITCH_DECLARE(switch_time_t) switch_str_time(char *in)
 {
-    switch_time_exp_t tm = {0};
-    int proceed = 0, ovector[30];
-    switch_regex_t *re = NULL;
-    char replace[1024] = "";
-    switch_time_t ret = 0;
-    char *pattern = "^(\\d+)-(\\d+)-(\\d+)\\s*(\\d*):{0,1}(\\d*):{0,1}(\\d*)";
-
-    switch_time_exp_lt(&tm, switch_time_now());
-    tm.tm_year = tm.tm_mon = tm.tm_mday = tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
-
-    if ((proceed = switch_regex_perform(in, pattern, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
-
-        if (proceed > 1) {
-            switch_regex_copy_substring(in, ovector, proceed, 1, replace, sizeof(replace));
-            tm.tm_year = atoi(replace) - 1900;
-        }
-
-        if (proceed > 2) {
-            switch_regex_copy_substring(in, ovector, proceed, 2, replace, sizeof(replace));
-            tm.tm_mon = atoi(replace) - 1;
-        }
-
-        if (proceed > 3) {
-            switch_regex_copy_substring(in, ovector, proceed, 3, replace, sizeof(replace));
-            tm.tm_mday = atoi(replace);
-        }
-        
-        if (proceed > 4) {
-            switch_regex_copy_substring(in, ovector, proceed, 4, replace, sizeof(replace));
-            tm.tm_hour = atoi(replace);
-        }
-
-        if (proceed > 5) {
-            switch_regex_copy_substring(in, ovector, proceed, 5, replace, sizeof(replace));
-            tm.tm_min = atoi(replace);
-        }
-
-        if (proceed > 6) {
-            switch_regex_copy_substring(in, ovector, proceed, 6, replace, sizeof(replace));
-            tm.tm_sec = atoi(replace);
-        }
-
-        switch_time_exp_gmt_get(&ret, &tm);
-        return ret;
-    } /* possible else with more patterns later */
-    
-    return ret;
+	switch_time_exp_t tm = { 0 };
+	int proceed = 0, ovector[30];
+	switch_regex_t *re = NULL;
+	char replace[1024] = "";
+	switch_time_t ret = 0;
+	char *pattern = "^(\\d+)-(\\d+)-(\\d+)\\s*(\\d*):{0,1}(\\d*):{0,1}(\\d*)";
+
+	switch_time_exp_lt(&tm, switch_time_now());
+	tm.tm_year = tm.tm_mon = tm.tm_mday = tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
+
+	if ((proceed = switch_regex_perform(in, pattern, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
+
+		if (proceed > 1) {
+			switch_regex_copy_substring(in, ovector, proceed, 1, replace, sizeof(replace));
+			tm.tm_year = atoi(replace) - 1900;
+		}
+
+		if (proceed > 2) {
+			switch_regex_copy_substring(in, ovector, proceed, 2, replace, sizeof(replace));
+			tm.tm_mon = atoi(replace) - 1;
+		}
+
+		if (proceed > 3) {
+			switch_regex_copy_substring(in, ovector, proceed, 3, replace, sizeof(replace));
+			tm.tm_mday = atoi(replace);
+		}
+
+		if (proceed > 4) {
+			switch_regex_copy_substring(in, ovector, proceed, 4, replace, sizeof(replace));
+			tm.tm_hour = atoi(replace);
+		}
+
+		if (proceed > 5) {
+			switch_regex_copy_substring(in, ovector, proceed, 5, replace, sizeof(replace));
+			tm.tm_min = atoi(replace);
+		}
+
+		if (proceed > 6) {
+			switch_regex_copy_substring(in, ovector, proceed, 6, replace, sizeof(replace));
+			tm.tm_sec = atoi(replace);
+		}
+
+		switch_time_exp_gmt_get(&ret, &tm);
+		return ret;
+	}
+	/* possible else with more patterns later */
+	return ret;
 
 }
 
 SWITCH_DECLARE(char *) switch_priority_name(switch_priority_t priority)
 {
-	switch(priority) { /*lol*/
+	switch (priority) {			/*lol */
 	case SWITCH_PRIORITY_NORMAL:
 		return "NORMAL";
 	case SWITCH_PRIORITY_LOW:
@@ -268,7 +254,7 @@
 	i = (uint8_t *) in;
 
 	memset(buf, 0, len);
-	for(x =0; x < 4; x++) {
+	for (x = 0; x < 4; x++) {
 		sprintf(p, "%u%s", i[x], x == 3 ? "" : ".");
 		p = buf + strlen(buf);
 	}
@@ -285,55 +271,55 @@
 
 SWITCH_DECLARE(unsigned char) switch_char_to_rfc2833(char key)
 {
-    char *c;
+	char *c;
 	unsigned char counter = 0;
 
-    key = (char)toupper(key);
-    for (c = RFC2833_CHARS; *c ; c++) {
-        if (*c == key) {
-            return counter;
-        }
+	key = (char) toupper(key);
+	for (c = RFC2833_CHARS; *c; c++) {
+		if (*c == key) {
+			return counter;
+		}
 		counter++;
 	}
-    return '\0';
+	return '\0';
 }
 
 SWITCH_DECLARE(char *) switch_escape_char(switch_memory_pool_t *pool, char *in, char *delim, char esc)
 {
-    char *data, *p, *d;
-    int count = 1, i = 0;
+	char *data, *p, *d;
+	int count = 1, i = 0;
 
-    p = in;
-    while(*p) {
-        d = delim;
-        while (*d) {
-            if (*p == *d) {
-                count++;
-            }
-            d++;
-        }
-        p++;
-    }
+	p = in;
+	while (*p) {
+		d = delim;
+		while (*d) {
+			if (*p == *d) {
+				count++;
+			}
+			d++;
+		}
+		p++;
+	}
 
 	if (count == 1) {
 		return in;
 	}
 
 	data = switch_core_alloc(pool, strlen(in) + count);
-	
-    p = in;
-    while(*p) {
-        d = delim;
-        while (*d) {
-            if (*p == *d) {
-                data[i++] = esc;
-            }
-            d++;
-        }
-        data[i++] = *p;
-        p++;
-    }
-    return data;
+
+	p = in;
+	while (*p) {
+		d = delim;
+		while (*d) {
+			if (*p == *d) {
+				data[i++] = esc;
+			}
+			d++;
+		}
+		data[i++] = *p;
+		p++;
+	}
+	return data;
 }
 
 
@@ -375,7 +361,7 @@
 	}
 
 	/* strip quotes */
-	for(x = 0; x < argc; x++) {
+	for (x = 0; x < argc; x++) {
 		if (*(array[x]) == qc) {
 			(array[x])++;
 			if ((e = strchr(array[x], qc))) {
@@ -415,8 +401,8 @@
 		if (string[i] != search[i]) {
 			return SWITCH_STATUS_FALSE;
 		}
-	}	
-	
+	}
+
 	if (i == search_len) {
 		return SWITCH_STATUS_SUCCESS;
 	}
@@ -432,21 +418,21 @@
 	size_t i, n;
 	size_t dest_len = 0;
 	char *dest;
-  
-	dest = (char *)malloc(sizeof(char));
+
+	dest = (char *) malloc(sizeof(char));
 
 	for (i = 0; i < string_len; i++) {
 		if (switch_string_match(string + i, string_len - i, search, search_len) == SWITCH_STATUS_SUCCESS) {
 			for (n = 0; n < replace_len; n++) {
 				dest[dest_len] = replace[n];
 				dest_len++;
-				dest = (char *)realloc(dest, sizeof(char)*(dest_len+1));
+				dest = (char *) realloc(dest, sizeof(char) * (dest_len + 1));
 			}
-			i += search_len-1;
+			i += search_len - 1;
 		} else {
 			dest[dest_len] = string[i];
 			dest_len++;
-			dest = (char *)realloc(dest, sizeof(char)*(dest_len+1));
+			dest = (char *) realloc(dest, sizeof(char) * (dest_len + 1));
 		}
 	}
 
@@ -454,7 +440,7 @@
 	return dest;
 }
 
-SWITCH_DECLARE(int) switch_socket_waitfor(switch_pollfd_t *poll, int ms)
+SWITCH_DECLARE(int) switch_socket_waitfor(switch_pollfd_t * poll, int ms)
 {
 	int nsds = 0;
 
@@ -466,37 +452,37 @@
 
 SWITCH_DECLARE(size_t) switch_url_encode(char *url, char *buf, size_t len)
 {
-    char *p;
-    size_t x = 0;
-    const char urlunsafe[] = "\r\n \"#%&+:;<=>?@[\\]^`{|}";
-    const char hex[] = "0123456789ABCDEF";
+	char *p;
+	size_t x = 0;
+	const char urlunsafe[] = "\r\n \"#%&+:;<=>?@[\\]^`{|}";
+	const char hex[] = "0123456789ABCDEF";
 
 	if (!buf) {
 		return 0;
 	}
 
-    memset(buf, 0, len);
+	memset(buf, 0, len);
 
 	if (!url) {
 		return 0;
 	}
 
-    for( p = url ; *p ; p++) {
-        if (*p < ' ' || *p > '~' || strchr(urlunsafe, *p)) {
-            if ((x + 3) > len) {
-                break;
-            }
-            buf[x++] = '%';
-            buf[x++] = hex[*p >> 4];
-            buf[x++] = hex[*p & 0x0f];
-        } else {
-            buf[x++] = *p;
-        }
-        if (x == len) {
-            break;
-        }
-    }
-    return x;
+	for (p = url; *p; p++) {
+		if (*p < ' ' || *p > '~' || strchr(urlunsafe, *p)) {
+			if ((x + 3) > len) {
+				break;
+			}
+			buf[x++] = '%';
+			buf[x++] = hex[*p >> 4];
+			buf[x++] = hex[*p & 0x0f];
+		} else {
+			buf[x++] = *p;
+		}
+		if (x == len) {
+			break;
+		}
+	}
+	return x;
 }
 
 SWITCH_DECLARE(char *) switch_url_decode(char *s)
@@ -506,7 +492,7 @@
 
 	for (o = s; *s; s++, o++) {
 		if (*s == '%' && strlen(s) > 2 && sscanf(s + 1, "%2x", &tmp) == 1) {
-			*o = (char)tmp;
+			*o = (char) tmp;
 			s += 2;
 		} else {
 			*o = *s;

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/switch_xml.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/switch_xml.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/switch_xml.c	Fri Mar 30 12:19:18 2007
@@ -62,32 +62,32 @@
 #include <sys/mman.h>
 #endif
 
-#define SWITCH_XML_WS   "\t\r\n "  // whitespace
-#define SWITCH_XML_ERRL 128        // maximum error string length
+#define SWITCH_XML_WS   "\t\r\n "	// whitespace
+#define SWITCH_XML_ERRL 128		// maximum error string length
 
 typedef struct switch_xml_root *switch_xml_root_t;
-struct switch_xml_root {       // additional data for the root tag
-    struct switch_xml xml;     // is a super-struct built on top of switch_xml struct
-    switch_xml_t cur;          // current xml tree insertion point
-    char *m;              // original xml string
-    switch_size_t len;    // length of allocated memory for mmap
+struct switch_xml_root {		// additional data for the root tag
+	struct switch_xml xml;		// is a super-struct built on top of switch_xml struct
+	switch_xml_t cur;			// current xml tree insertion point
+	char *m;					// original xml string
+	switch_size_t len;			// length of allocated memory for mmap
 	uint8_t dynamic;
-    char *u;              // UTF-8 conversion of string if original was UTF-16
-    char *s;              // start of work area
-    char *e;              // end of work area
-    char **ent;           // general entities (ampersand sequences)
-    char ***attr;         // default attributes
-    char ***pi;           // processing instructions
-    short standalone;     // non-zero if <?xml standalone="yes"?>
-    char err[SWITCH_XML_ERRL]; // error string
+	char *u;					// UTF-8 conversion of string if original was UTF-16
+	char *s;					// start of work area
+	char *e;					// end of work area
+	char **ent;					// general entities (ampersand sequences)
+	char ***attr;				// default attributes
+	char ***pi;					// processing instructions
+	short standalone;			// non-zero if <?xml standalone="yes"?>
+	char err[SWITCH_XML_ERRL];	// error string
 };
 
-char *SWITCH_XML_NIL[] = { NULL }; // empty, null terminated array of strings
+char *SWITCH_XML_NIL[] = { NULL };	// empty, null terminated array of strings
 
 struct switch_xml_binding {
 	switch_xml_search_function_t function;
 	switch_xml_section_t sections;
-    void *user_data;
+	void *user_data;
 	struct switch_xml_binding *next;
 };
 
@@ -106,12 +106,12 @@
 
 
 static struct xml_section_t SECTIONS[] = {
-	{ "result", SWITCH_XML_SECTION_RESULT},
-	{ "config", SWITCH_XML_SECTION_CONFIG},
-	{ "directory", SWITCH_XML_SECTION_DIRECTORY},
-	{ "dialplan", SWITCH_XML_SECTION_DIALPLAN},
-	{ "phrases", SWITCH_XML_SECTION_PHRASES},
-	{ NULL, 0}
+	{"result", SWITCH_XML_SECTION_RESULT},
+	{"config", SWITCH_XML_SECTION_CONFIG},
+	{"directory", SWITCH_XML_SECTION_DIRECTORY},
+	{"dialplan", SWITCH_XML_SECTION_DIALPLAN},
+	{"phrases", SWITCH_XML_SECTION_PHRASES},
+	{NULL, 0}
 };
 
 SWITCH_DECLARE(switch_xml_section_t) switch_xml_parse_section_string(const char *str)
@@ -121,10 +121,10 @@
 	switch_xml_section_t sections = SWITCH_XML_SECTION_RESULT;
 
 	if (str) {
-		for(x = 0; x < strlen(str); x++) {
-			buf[x] = (char)tolower((int)str[x]);
+		for (x = 0; x < strlen(str); x++) {
+			buf[x] = (char) tolower((int) str[x]);
 		}
-		for(x = 0;;x++) {
+		for (x = 0;; x++) {
 			if (!SECTIONS[x].name) {
 				break;
 			}
@@ -147,7 +147,7 @@
 
 	binding->function = function;
 	binding->sections = sections;
-    binding->user_data = user_data;
+	binding->user_data = user_data;
 
 	switch_mutex_lock(XML_LOCK);
 	for (ptr = BINDINGS; ptr && ptr->next; ptr = ptr->next);
@@ -158,7 +158,7 @@
 		BINDINGS = binding;
 	}
 	switch_mutex_unlock(XML_LOCK);
-	
+
 	return SWITCH_STATUS_SUCCESS;
 }
 
@@ -184,17 +184,19 @@
 // returns the first child tag with the given name or NULL if not found
 SWITCH_DECLARE(switch_xml_t) switch_xml_child(switch_xml_t xml, const char *name)
 {
-    xml = (xml) ? xml->child : NULL;
-    while (xml && strcmp(name, xml->name)) xml = xml->sibling;
-    return xml;
+	xml = (xml) ? xml->child : NULL;
+	while (xml && strcmp(name, xml->name))
+		xml = xml->sibling;
+	return xml;
 }
 
 // returns the Nth tag with the same name in the same subsection or NULL if not
 // found
 switch_xml_t switch_xml_idx(switch_xml_t xml, int idx)
 {
-    for (; xml && idx; idx--) xml = xml->next;
-    return xml;
+	for (; xml && idx; idx--)
+		xml = xml->next;
+	return xml;
 }
 
 // returns the value of the requested tag attribute or "" if not found
@@ -208,31 +210,37 @@
 // returns the value of the requested tag attribute or NULL if not found
 SWITCH_DECLARE(const char *) switch_xml_attr(switch_xml_t xml, const char *attr)
 {
-    int i = 0, j = 1;
-    switch_xml_root_t root = (switch_xml_root_t)xml;
+	int i = 0, j = 1;
+	switch_xml_root_t root = (switch_xml_root_t) xml;
 
-    if (! xml || ! xml->attr) return NULL;
-    while (xml->attr[i] && strcmp(attr, xml->attr[i])) i += 2;
-    if (xml->attr[i]) return xml->attr[i + 1]; // found attribute
-
-    while (root->xml.parent) root = (switch_xml_root_t)root->xml.parent; // root tag
-    for (i = 0; root->attr[i] && strcmp(xml->name, root->attr[i][0]); i++);
-    if (! root->attr[i]) return NULL; // no matching default attributes
-    while (root->attr[i][j] && strcmp(attr, root->attr[i][j])) j += 3;
-    return (root->attr[i][j]) ? root->attr[i][j + 1] : NULL; // found default
+	if (!xml || !xml->attr)
+		return NULL;
+	while (xml->attr[i] && strcmp(attr, xml->attr[i]))
+		i += 2;
+	if (xml->attr[i])
+		return xml->attr[i + 1];	// found attribute
+
+	while (root->xml.parent)
+		root = (switch_xml_root_t) root->xml.parent;	// root tag
+	for (i = 0; root->attr[i] && strcmp(xml->name, root->attr[i][0]); i++);
+	if (!root->attr[i])
+		return NULL;			// no matching default attributes
+	while (root->attr[i][j] && strcmp(attr, root->attr[i][j]))
+		j += 3;
+	return (root->attr[i][j]) ? root->attr[i][j + 1] : NULL;	// found default
 }
 
 // same as switch_xml_get but takes an already initialized va_list
 static switch_xml_t switch_xml_vget(switch_xml_t xml, va_list ap)
 {
-    char *name = va_arg(ap, char *);
-    int idx = -1;
+	char *name = va_arg(ap, char *);
+	int idx = -1;
 
-    if (name && *name) {
-        idx = va_arg(ap, int);    
-        xml = switch_xml_child(xml, name);
-    }
-    return (idx < 0) ? xml : switch_xml_vget(switch_xml_idx(xml, idx), ap);
+	if (name && *name) {
+		idx = va_arg(ap, int);
+		xml = switch_xml_child(xml, name);
+	}
+	return (idx < 0) ? xml : switch_xml_vget(switch_xml_idx(xml, idx), ap);
 }
 
 // Traverses the xml tree to retrieve a specific subtag. Takes a variable
@@ -241,45 +249,50 @@
 // title = switch_xml_get(library, "shelf", 0, "book", 2, "title", -1);
 // This retrieves the title of the 3rd book on the 1st shelf of library.
 // Returns NULL if not found.
-SWITCH_DECLARE(switch_xml_t) switch_xml_get(switch_xml_t xml, ...)
+SWITCH_DECLARE(switch_xml_t) switch_xml_get(switch_xml_t xml,...)
 {
-    va_list ap;
-    switch_xml_t r;
+	va_list ap;
+	switch_xml_t r;
 
-    va_start(ap, xml);
-    r = switch_xml_vget(xml, ap);
-    va_end(ap);
-    return r;
+	va_start(ap, xml);
+	r = switch_xml_vget(xml, ap);
+	va_end(ap);
+	return r;
 }
 
 // returns a null terminated array of processing instructions for the given
 // target
 SWITCH_DECLARE(const char **) switch_xml_pi(switch_xml_t xml, const char *target)
 {
-    switch_xml_root_t root = (switch_xml_root_t)xml;
-    int i = 0;
+	switch_xml_root_t root = (switch_xml_root_t) xml;
+	int i = 0;
 
-    if (! root) return (const char **)SWITCH_XML_NIL;
-    while (root->xml.parent) root = (switch_xml_root_t)root->xml.parent; // root tag
-    while (root->pi[i] && strcmp(target, root->pi[i][0])) i++; // find target
-    return (const char **)((root->pi[i]) ? root->pi[i] + 1 : SWITCH_XML_NIL);
+	if (!root)
+		return (const char **) SWITCH_XML_NIL;
+	while (root->xml.parent)
+		root = (switch_xml_root_t) root->xml.parent;	// root tag
+	while (root->pi[i] && strcmp(target, root->pi[i][0]))
+		i++;					// find target
+	return (const char **) ((root->pi[i]) ? root->pi[i] + 1 : SWITCH_XML_NIL);
 }
 
 // set an error string and return root
 static switch_xml_t switch_xml_err(switch_xml_root_t root, char *s, const char *err, ...)
 {
-    va_list ap;
-    int line = 1;
-    char *t, fmt[SWITCH_XML_ERRL];
-    
-    for (t = root->s; t && t < s; t++) if (*t == '\n') line++;
-    snprintf(fmt, SWITCH_XML_ERRL, "[error near line %d]: %s", line, err);
-
-    va_start(ap, err);
-    vsnprintf(root->err, SWITCH_XML_ERRL, fmt, ap);
-    va_end(ap);
+	va_list ap;
+	int line = 1;
+	char *t, fmt[SWITCH_XML_ERRL];
+
+	for (t = root->s; t && t < s; t++)
+		if (*t == '\n')
+			line++;
+	snprintf(fmt, SWITCH_XML_ERRL, "[error near line %d]: %s", line, err);
+
+	va_start(ap, err);
+	vsnprintf(root->err, SWITCH_XML_ERRL, fmt, ap);
+	va_end(ap);
 
-    return &root->xml;
+	return &root->xml;
 }
 
 // Recursively decodes entity and character references and normalizes new lines
@@ -290,467 +303,540 @@
 // s, returns a malloced string that must be freed.
 static char *switch_xml_decode(char *s, char **ent, char t)
 {
-    char *e, *r = s, *m = s;
-    long b, c, d, l;
+	char *e, *r = s, *m = s;
+	long b, c, d, l;
+
+	for (; *s; s++) {			// normalize line endings
+		while (*s == '\r') {
+			*(s++) = '\n';
+			if (*s == '\n')
+				memmove(s, (s + 1), strlen(s));
+		}
+	}
+
+	for (s = r;;) {
+		while (*s && *s != '&' && (*s != '%' || t != '%') && !isspace((int) (*s)))
+			s++;
+
+		if (!*s)
+			break;
+		else if (t != 'c' && !strncmp(s, "&#", 2)) {	// character reference
+			if (s[2] == 'x')
+				c = strtol(s + 3, &e, 16);	// base 16
+			else
+				c = strtol(s + 2, &e, 10);	// base 10
+			if (!c || *e != ';') {
+				s++;
+				continue;
+			}					// not a character ref
+
+			if (c < 0x80)
+				*(s++) = (char) c;	// US-ASCII subset
+			else {				// multi-byte UTF-8 sequence
+				for (b = 0, d = c; d; d /= 2)
+					b++;		// number of bits in c
+				b = (b - 2) / 5;	// number of bytes in payload
+				*(s++) = (char) ((0xFF << (7 - b)) | (c >> (6 * b)));	// head
+				while (b)
+					*(s++) = (char) (0x80 | ((c >> (6 * --b)) & 0x3F));	// payload
+			}
+
+			memmove(s, strchr(s, ';') + 1, strlen(strchr(s, ';')));
+		} else if ((*s == '&' && (t == '&' || t == ' ' || t == '*')) || (*s == '%' && t == '%')) {	// entity reference
+			for (b = 0; ent[b] && strncmp(s + 1, ent[b], strlen(ent[b])); b += 2);	// find entity in entity list
+
+			if (ent[b++]) {		// found a match
+				if ((c = (long) strlen(ent[b])) - 1 > (e = strchr(s, ';')) - s) {
+					l = (d = (long) (s - r)) + c + (long) strlen(e);	// new length
+					r = (r == m) ? strcpy(malloc(l), r) : realloc(r, l);
+					e = strchr((s = r + d), ';');	// fix up pointers
+				}
+
+				memmove(s + c, e + 1, strlen(e));	// shift rest of string
+				strncpy(s, ent[b], c);	// copy in replacement text
+			} else
+				s++;			// not a known entity
+		} else if ((t == ' ' || t == '*') && isspace((int) (*s)))
+			*(s++) = ' ';
+		else
+			s++;				// no decoding needed
+	}
 
-    for (; *s; s++) { // normalize line endings
-        while (*s == '\r') {
-            *(s++) = '\n';
-            if (*s == '\n') memmove(s, (s + 1), strlen(s));
-        }
-    }
-    
-    for (s = r; ; ) {
-        while (*s && *s != '&' && (*s != '%' || t != '%') && !isspace((int)(*s))) s++;
-
-        if (! *s) break;
-        else if (t != 'c' && ! strncmp(s, "&#", 2)) { // character reference
-            if (s[2] == 'x') c = strtol(s + 3, &e, 16); // base 16
-            else c = strtol(s + 2, &e, 10); // base 10
-            if (! c || *e != ';') { s++; continue; } // not a character ref
-
-            if (c < 0x80) *(s++) = (char)c; // US-ASCII subset
-            else { // multi-byte UTF-8 sequence
-                for (b = 0, d = c; d; d /= 2) b++; // number of bits in c
-                b = (b - 2) / 5; // number of bytes in payload
-                *(s++) = (char)((0xFF << (7 - b)) | (c >> (6 * b))); // head
-                while (b) *(s++) = (char)(0x80 | ((c >> (6 * --b)) & 0x3F)); // payload
-            }
-
-            memmove(s, strchr(s, ';') + 1, strlen(strchr(s, ';')));
-        }
-        else if ((*s == '&' && (t == '&' || t == ' ' || t == '*')) ||
-                 (*s == '%' && t == '%')) { // entity reference
-            for (b = 0; ent[b] && strncmp(s + 1, ent[b], strlen(ent[b]));
-                 b += 2); // find entity in entity list
-
-            if (ent[b++]) { // found a match
-                if ((c = (long)strlen(ent[b])) - 1 > (e = strchr(s, ';')) - s) {
-                    l = (d = (long)(s - r)) + c + (long)strlen(e); // new length
-                    r = (r == m) ? strcpy(malloc(l), r) : realloc(r, l);
-                    e = strchr((s = r + d), ';'); // fix up pointers
-                }
-
-                memmove(s + c, e + 1, strlen(e)); // shift rest of string
-                strncpy(s, ent[b], c); // copy in replacement text
-            }
-            else s++; // not a known entity
-        }
-        else if ((t == ' ' || t == '*') && isspace((int)(*s))) *(s++) = ' ';
-        else s++; // no decoding needed
-    }
-
-    if (t == '*') { // normalize spaces for non-cdata attributes
-        for (s = r; *s; s++) {
-            if ((l = (long)strspn(s, " "))) memmove(s, s + l, strlen(s + l) + 1);
-            while (*s && *s != ' ') s++;
-        }
-        if (--s >= r && *s == ' ') *s = '\0'; // trim any trailing space
-    }
-    return r;
+	if (t == '*') {				// normalize spaces for non-cdata attributes
+		for (s = r; *s; s++) {
+			if ((l = (long) strspn(s, " ")))
+				memmove(s, s + l, strlen(s + l) + 1);
+			while (*s && *s != ' ')
+				s++;
+		}
+		if (--s >= r && *s == ' ')
+			*s = '\0';			// trim any trailing space
+	}
+	return r;
 }
 
 // called when parser finds start of new tag
 static void switch_xml_open_tag(switch_xml_root_t root, char *name, char **attr)
 {
-    switch_xml_t xml = root->cur;
-    
-    if (xml->name) xml = switch_xml_add_child(xml, name, strlen(xml->txt));
-    else xml->name = name; // first open tag
+	switch_xml_t xml = root->cur;
+
+	if (xml->name)
+		xml = switch_xml_add_child(xml, name, strlen(xml->txt));
+	else
+		xml->name = name;		// first open tag
 
-    xml->attr = attr;
-    root->cur = xml; // update tag insertion point
+	xml->attr = attr;
+	root->cur = xml;			// update tag insertion point
 }
 
 // called when parser finds character content between open and closing tag
 static void switch_xml_char_content(switch_xml_root_t root, char *s, switch_size_t len, char t)
 {
-    switch_xml_t xml = root->cur;
-    char *m = s;
-    switch_size_t l;
-
-    if (! xml || ! xml->name || ! len) return; // sanity check
-
-    s[len] = '\0'; // null terminate text (calling functions anticipate this)
-    len = strlen(s = switch_xml_decode(s, root->ent, t)) + 1;
-
-    if (! *(xml->txt)) xml->txt = s; // initial character content
-    else { // allocate our own memory and make a copy
-        xml->txt = (xml->flags & SWITCH_XML_TXTM) // allocate some space
-                   ? realloc(xml->txt, (l = strlen(xml->txt)) + len)
-                   : strcpy(malloc((l = strlen(xml->txt)) + len), xml->txt);
-        strcpy(xml->txt + l, s); // add new char content
-        if (s != m) free(s); // free s if it was malloced by switch_xml_decode()
-    }
+	switch_xml_t xml = root->cur;
+	char *m = s;
+	switch_size_t l;
+
+	if (!xml || !xml->name || !len)
+		return;					// sanity check
+
+	s[len] = '\0';				// null terminate text (calling functions anticipate this)
+	len = strlen(s = switch_xml_decode(s, root->ent, t)) + 1;
+
+	if (!*(xml->txt))
+		xml->txt = s;			// initial character content
+	else {						// allocate our own memory and make a copy
+		xml->txt = (xml->flags & SWITCH_XML_TXTM)	// allocate some space
+			? realloc(xml->txt, (l = strlen(xml->txt)) + len)
+			: strcpy(malloc((l = strlen(xml->txt)) + len), xml->txt);
+		strcpy(xml->txt + l, s);	// add new char content
+		if (s != m)
+			free(s);			// free s if it was malloced by switch_xml_decode()
+	}
 
-    if (xml->txt != m) switch_xml_set_flag(xml, SWITCH_XML_TXTM);
+	if (xml->txt != m)
+		switch_xml_set_flag(xml, SWITCH_XML_TXTM);
 }
 
 // called when parser finds closing tag
 static switch_xml_t switch_xml_close_tag(switch_xml_root_t root, char *name, char *s)
 {
-    if (! root->cur || ! root->cur->name || strcmp(name, root->cur->name))
-        return switch_xml_err(root, s, "unexpected closing tag </%s>", name);
+	if (!root->cur || !root->cur->name || strcmp(name, root->cur->name))
+		return switch_xml_err(root, s, "unexpected closing tag </%s>", name);
 
-    root->cur = root->cur->parent;
-    return NULL;
+	root->cur = root->cur->parent;
+	return NULL;
 }
 
 // checks for circular entity references, returns non-zero if no circular
 // references are found, zero otherwise
 static int switch_xml_ent_ok(char *name, char *s, char **ent)
 {
-    int i;
+	int i;
 
-    for (; ; s++) {
-        while (*s && *s != '&') s++; // find next entity reference
-        if (! *s) return 1;
-        if (! strncmp(s + 1, name, strlen(name))) return 0; // circular ref.
-        for (i = 0; ent[i] && strncmp(ent[i], s + 1, strlen(ent[i])); i += 2);
-        if (ent[i] && ! switch_xml_ent_ok(name, ent[i + 1], ent)) return 0;
-    }
+	for (;; s++) {
+		while (*s && *s != '&')
+			s++;				// find next entity reference
+		if (!*s)
+			return 1;
+		if (!strncmp(s + 1, name, strlen(name)))
+			return 0;			// circular ref.
+		for (i = 0; ent[i] && strncmp(ent[i], s + 1, strlen(ent[i])); i += 2);
+		if (ent[i] && !switch_xml_ent_ok(name, ent[i + 1], ent))
+			return 0;
+	}
 }
 
 // called when the parser finds a processing instruction
 static void switch_xml_proc_inst(switch_xml_root_t root, char *s, switch_size_t len)
 {
-    int i = 0, j = 1;
-    char *target = s;
+	int i = 0, j = 1;
+	char *target = s;
+
+	s[len] = '\0';				// null terminate instruction
+	if (*(s += strcspn(s, SWITCH_XML_WS))) {
+		*s = '\0';				// null terminate target
+		s += strspn(s + 1, SWITCH_XML_WS) + 1;	// skip whitespace after target
+	}
 
-    s[len] = '\0'; // null terminate instruction
-    if (*(s += strcspn(s, SWITCH_XML_WS))) {
-        *s = '\0'; // null terminate target
-        s += strspn(s + 1, SWITCH_XML_WS) + 1; // skip whitespace after target
-    }
-
-    if (! strcmp(target, "xml")) { // <?xml ... ?>
-        if ((s = strstr(s, "standalone")) && ! strncmp(s + strspn(s + 10,
-            SWITCH_XML_WS "='\"") + 10, "yes", 3)) root->standalone = 1;
-        return;
-    }
-
-    if (! root->pi[0]) *(root->pi = malloc(sizeof(char **))) = NULL; //first pi
-
-    while (root->pi[i] && strcmp(target, root->pi[i][0])) i++; // find target
-    if (! root->pi[i]) { // new target
-        root->pi = realloc(root->pi, sizeof(char **) * (i + 2));
-        root->pi[i] = malloc(sizeof(char *) * 3);
-        root->pi[i][0] = target;
-        root->pi[i][1] = (char *)(root->pi[i + 1] = NULL); // terminate pi list
-        root->pi[i][2] = strdup(""); // empty document position list
-    }
-
-    while (root->pi[i][j]) j++; // find end of instruction list for this target
-    root->pi[i] = realloc(root->pi[i], sizeof(char *) * (j + 3));
-    root->pi[i][j + 2] = realloc(root->pi[i][j + 1], j + 1);
-    strcpy(root->pi[i][j + 2] + j - 1, (root->xml.name) ? ">" : "<");
-    root->pi[i][j + 1] = NULL; // null terminate pi list for this target
-    root->pi[i][j] = s; // set instruction
+	if (!strcmp(target, "xml")) {	// <?xml ... ?>
+		if ((s = strstr(s, "standalone")) && !strncmp(s + strspn(s + 10, SWITCH_XML_WS "='\"") + 10, "yes", 3))
+			root->standalone = 1;
+		return;
+	}
+
+	if (!root->pi[0])
+		*(root->pi = malloc(sizeof(char **))) = NULL;	//first pi
+
+	while (root->pi[i] && strcmp(target, root->pi[i][0]))
+		i++;					// find target
+	if (!root->pi[i]) {			// new target
+		root->pi = realloc(root->pi, sizeof(char **) * (i + 2));
+		root->pi[i] = malloc(sizeof(char *) * 3);
+		root->pi[i][0] = target;
+		root->pi[i][1] = (char *) (root->pi[i + 1] = NULL);	// terminate pi list
+		root->pi[i][2] = strdup("");	// empty document position list
+	}
+
+	while (root->pi[i][j])
+		j++;					// find end of instruction list for this target
+	root->pi[i] = realloc(root->pi[i], sizeof(char *) * (j + 3));
+	root->pi[i][j + 2] = realloc(root->pi[i][j + 1], j + 1);
+	strcpy(root->pi[i][j + 2] + j - 1, (root->xml.name) ? ">" : "<");
+	root->pi[i][j + 1] = NULL;	// null terminate pi list for this target
+	root->pi[i][j] = s;			// set instruction
 }
 
 // called when the parser finds an internal doctype subset
 static short switch_xml_internal_dtd(switch_xml_root_t root, char *s, switch_size_t len)
 {
-    char q, *c, *t, *n = NULL, *v, **ent, **pe;
-    int i, j;
-    
-    pe = memcpy(malloc(sizeof(SWITCH_XML_NIL)), SWITCH_XML_NIL, sizeof(SWITCH_XML_NIL));
-
-    for (s[len] = '\0'; s; ) {
-        while (*s && *s != '<' && *s != '%') s++; // find next declaration
-
-        if (! *s) break;
-        else if (! strncmp(s, "<!ENTITY", 8)) { // parse entity definitions
-            c = s += strspn(s + 8, SWITCH_XML_WS) + 8; // skip white space separator
-            n = s + strspn(s, SWITCH_XML_WS "%"); // find name
-            *(s = n + strcspn(n, SWITCH_XML_WS)) = ';'; // append ; to name
-
-            v = s + strspn(s + 1, SWITCH_XML_WS) + 1; // find value
-            if ((q = *(v++)) != '"' && q != '\'') { // skip externals
-                s = strchr(s, '>');
-                continue;
-            }
-
-            for (i = 0, ent = (*c == '%') ? pe : root->ent; ent[i]; i++);
-            ent = realloc(ent, (i + 3) * sizeof(char *)); // space for next ent
-            if (*c == '%') pe = ent;
-            else root->ent = ent;
-
-            *(++s) = '\0'; // null terminate name
-            if ((s = strchr(v, q))) *(s++) = '\0'; // null terminate value
-            ent[i + 1] = switch_xml_decode(v, pe, '%'); // set value
-            ent[i + 2] = NULL; // null terminate entity list
-            if (! switch_xml_ent_ok(n, ent[i + 1], ent)) { // circular reference
-                if (ent[i + 1] != v) free(ent[i + 1]);
-                switch_xml_err(root, v, "circular entity declaration &%s", n);
-                break;
-            }
-            else ent[i] = n; // set entity name
-        }
-        else if (! strncmp(s, "<!ATTLIST", 9)) { // parse default attributes
-            t = s + strspn(s + 9, SWITCH_XML_WS) + 9; // skip whitespace separator
-            if (! *t) { switch_xml_err(root, t, "unclosed <!ATTLIST"); break; }
-            if (*(s = t + strcspn(t, SWITCH_XML_WS ">")) == '>') continue;
-            else *s = '\0'; // null terminate tag name
-            for (i = 0; root->attr[i] && strcmp(n, root->attr[i][0]); i++);
-
-            while (*(n = ++s + strspn(s, SWITCH_XML_WS)) && *n != '>') {
-                if (*(s = n + strcspn(n, SWITCH_XML_WS))) *s = '\0'; // attr name
-                else { switch_xml_err(root, t, "malformed <!ATTLIST"); break; }
-
-                s += strspn(s + 1, SWITCH_XML_WS) + 1; // find next token
-                c = (strncmp(s, "CDATA", 5)) ? "*" : " "; // is it cdata?
-                if (! strncmp(s, "NOTATION", 8))
-                    s += strspn(s + 8, SWITCH_XML_WS) + 8;
-                s = (*s == '(') ? strchr(s, ')') : s + strcspn(s, SWITCH_XML_WS);
-                if (! s) { switch_xml_err(root, t, "malformed <!ATTLIST"); break; }
-
-                s += strspn(s, SWITCH_XML_WS ")"); // skip white space separator
-                if (! strncmp(s, "#FIXED", 6))
-                    s += strspn(s + 6, SWITCH_XML_WS) + 6;
-                if (*s == '#') { // no default value
-                    s += strcspn(s, SWITCH_XML_WS ">") - 1;
-                    if (*c == ' ') continue; // cdata is default, nothing to do
-                    v = NULL;
-                }
-                else if ((*s == '"' || *s == '\'')  &&  // default value
-                         (s = strchr(v = s + 1, *s))) *s = '\0';
-                else { switch_xml_err(root, t, "malformed <!ATTLIST"); break; }
-
-                if (! root->attr[i]) { // new tag name
-                    root->attr = (! i) ? malloc(2 * sizeof(char **))
-                                       : realloc(root->attr,
-                                                 (i + 2) * sizeof(char **));
-                    root->attr[i] = malloc(2 * sizeof(char *));
-                    root->attr[i][0] = t; // set tag name
-                    root->attr[i][1] = (char *)(root->attr[i + 1] = NULL);
-                }
-
-                for (j = 1; root->attr[i][j]; j += 3); // find end of list
-                root->attr[i] = realloc(root->attr[i],
-                                        (j + 4) * sizeof(char *));
-
-                root->attr[i][j + 3] = NULL; // null terminate list
-                root->attr[i][j + 2] = c; // is it cdata?
-                root->attr[i][j + 1] = (v) ? switch_xml_decode(v, root->ent, *c)
-                                           : NULL;
-                root->attr[i][j] = n; // attribute name 
-            }
-        }
-        else if (! strncmp(s, "<!--", 4)) s = strstr(s + 4, "-->"); // comments
-        else if (! strncmp(s, "<?", 2)) { // processing instructions
-            if ((s = strstr(c = s + 2, "?>")))
-                switch_xml_proc_inst(root, c, s++ - c);
-        }
-        else if (*s == '<') s = strchr(s, '>'); // skip other declarations
-        else if (*(s++) == '%' && ! root->standalone) break;
-    }
+	char q, *c, *t, *n = NULL, *v, **ent, **pe;
+	int i, j;
+
+	pe = memcpy(malloc(sizeof(SWITCH_XML_NIL)), SWITCH_XML_NIL, sizeof(SWITCH_XML_NIL));
+
+	for (s[len] = '\0'; s;) {
+		while (*s && *s != '<' && *s != '%')
+			s++;				// find next declaration
 
-    free(pe);
-    return ! *root->err;
+		if (!*s)
+			break;
+		else if (!strncmp(s, "<!ENTITY", 8)) {	// parse entity definitions
+			c = s += strspn(s + 8, SWITCH_XML_WS) + 8;	// skip white space separator
+			n = s + strspn(s, SWITCH_XML_WS "%");	// find name
+			*(s = n + strcspn(n, SWITCH_XML_WS)) = ';';	// append ; to name
+
+			v = s + strspn(s + 1, SWITCH_XML_WS) + 1;	// find value
+			if ((q = *(v++)) != '"' && q != '\'') {	// skip externals
+				s = strchr(s, '>');
+				continue;
+			}
+
+			for (i = 0, ent = (*c == '%') ? pe : root->ent; ent[i]; i++);
+			ent = realloc(ent, (i + 3) * sizeof(char *));	// space for next ent
+			if (*c == '%')
+				pe = ent;
+			else
+				root->ent = ent;
+
+			*(++s) = '\0';		// null terminate name
+			if ((s = strchr(v, q)))
+				*(s++) = '\0';	// null terminate value
+			ent[i + 1] = switch_xml_decode(v, pe, '%');	// set value
+			ent[i + 2] = NULL;	// null terminate entity list
+			if (!switch_xml_ent_ok(n, ent[i + 1], ent)) {	// circular reference
+				if (ent[i + 1] != v)
+					free(ent[i + 1]);
+				switch_xml_err(root, v, "circular entity declaration &%s", n);
+				break;
+			} else
+				ent[i] = n;		// set entity name
+		} else if (!strncmp(s, "<!ATTLIST", 9)) {	// parse default attributes
+			t = s + strspn(s + 9, SWITCH_XML_WS) + 9;	// skip whitespace separator
+			if (!*t) {
+				switch_xml_err(root, t, "unclosed <!ATTLIST");
+				break;
+			}
+			if (*(s = t + strcspn(t, SWITCH_XML_WS ">")) == '>')
+				continue;
+			else
+				*s = '\0';		// null terminate tag name
+			for (i = 0; root->attr[i] && strcmp(n, root->attr[i][0]); i++);
+
+			while (*(n = ++s + strspn(s, SWITCH_XML_WS)) && *n != '>') {
+				if (*(s = n + strcspn(n, SWITCH_XML_WS)))
+					*s = '\0';	// attr name
+				else {
+					switch_xml_err(root, t, "malformed <!ATTLIST");
+					break;
+				}
+
+				s += strspn(s + 1, SWITCH_XML_WS) + 1;	// find next token
+				c = (strncmp(s, "CDATA", 5)) ? "*" : " ";	// is it cdata?
+				if (!strncmp(s, "NOTATION", 8))
+					s += strspn(s + 8, SWITCH_XML_WS) + 8;
+				s = (*s == '(') ? strchr(s, ')') : s + strcspn(s, SWITCH_XML_WS);
+				if (!s) {
+					switch_xml_err(root, t, "malformed <!ATTLIST");
+					break;
+				}
+
+				s += strspn(s, SWITCH_XML_WS ")");	// skip white space separator
+				if (!strncmp(s, "#FIXED", 6))
+					s += strspn(s + 6, SWITCH_XML_WS) + 6;
+				if (*s == '#') {	// no default value
+					s += strcspn(s, SWITCH_XML_WS ">") - 1;
+					if (*c == ' ')
+						continue;	// cdata is default, nothing to do
+					v = NULL;
+				} else if ((*s == '"' || *s == '\'') &&	// default value
+						   (s = strchr(v = s + 1, *s)))
+					*s = '\0';
+				else {
+					switch_xml_err(root, t, "malformed <!ATTLIST");
+					break;
+				}
+
+				if (!root->attr[i]) {	// new tag name
+					root->attr = (!i) ? malloc(2 * sizeof(char **))
+						: realloc(root->attr, (i + 2) * sizeof(char **));
+					root->attr[i] = malloc(2 * sizeof(char *));
+					root->attr[i][0] = t;	// set tag name
+					root->attr[i][1] = (char *) (root->attr[i + 1] = NULL);
+				}
+
+				for (j = 1; root->attr[i][j]; j += 3);	// find end of list
+				root->attr[i] = realloc(root->attr[i], (j + 4) * sizeof(char *));
+
+				root->attr[i][j + 3] = NULL;	// null terminate list
+				root->attr[i][j + 2] = c;	// is it cdata?
+				root->attr[i][j + 1] = (v) ? switch_xml_decode(v, root->ent, *c)
+					: NULL;
+				root->attr[i][j] = n;	// attribute name 
+			}
+		} else if (!strncmp(s, "<!--", 4))
+			s = strstr(s + 4, "-->");	// comments
+		else if (!strncmp(s, "<?", 2)) {	// processing instructions
+			if ((s = strstr(c = s + 2, "?>")))
+				switch_xml_proc_inst(root, c, s++ - c);
+		} else if (*s == '<')
+			s = strchr(s, '>');	// skip other declarations
+		else if (*(s++) == '%' && !root->standalone)
+			break;
+	}
+
+	free(pe);
+	return !*root->err;
 }
 
 // Converts a UTF-16 string to UTF-8. Returns a new string that must be freed
 // or NULL if no conversion was needed.
 static char *switch_xml_str2utf8(char **s, switch_size_t *len)
 {
-    char *u;
-    switch_size_t l = 0, sl, max = *len;
-    long c, d;
-    int b, be = (**s == '\xFE') ? 1 : (**s == '\xFF') ? 0 : -1;
-
-    if (be == -1) return NULL; // not UTF-16
-
-    u = malloc(max);
-    for (sl = 2; sl < *len - 1; sl += 2) {
-        c = (be) ? (((*s)[sl] & 0xFF) << 8) | ((*s)[sl + 1] & 0xFF)  //UTF-16BE
-                 : (((*s)[sl + 1] & 0xFF) << 8) | ((*s)[sl] & 0xFF); //UTF-16LE
-        if (c >= 0xD800 && c <= 0xDFFF && (sl += 2) < *len - 1) { // high-half
-            d = (be) ? (((*s)[sl] & 0xFF) << 8) | ((*s)[sl + 1] & 0xFF)
-                     : (((*s)[sl + 1] & 0xFF) << 8) | ((*s)[sl] & 0xFF);
-            c = (((c & 0x3FF) << 10) | (d & 0x3FF)) + 0x10000;
-        }
-
-        while (l + 6 > max) u = realloc(u, max += SWITCH_XML_BUFSIZE);
-        if (c < 0x80) u[l++] = (char)c; // US-ASCII subset
-        else { // multi-byte UTF-8 sequence
-            for (b = 0, d = c; d; d /= 2) b++; // bits in c
-            b = (b - 2) / 5; // bytes in payload
-            u[l++] = (char)((0xFF << (7 - b)) | (c >> (6 * b))); // head
-            while (b) u[l++] = (char)(0x80 | ((c >> (6 * --b)) & 0x3F)); // payload
-        }
-    }
-    return *s = realloc(u, *len = l);
+	char *u;
+	switch_size_t l = 0, sl, max = *len;
+	long c, d;
+	int b, be = (**s == '\xFE') ? 1 : (**s == '\xFF') ? 0 : -1;
+
+	if (be == -1)
+		return NULL;			// not UTF-16
+
+	u = malloc(max);
+	for (sl = 2; sl < *len - 1; sl += 2) {
+		c = (be) ? (((*s)[sl] & 0xFF) << 8) | ((*s)[sl + 1] & 0xFF)	//UTF-16BE
+			: (((*s)[sl + 1] & 0xFF) << 8) | ((*s)[sl] & 0xFF);	//UTF-16LE
+		if (c >= 0xD800 && c <= 0xDFFF && (sl += 2) < *len - 1) {	// high-half
+			d = (be) ? (((*s)[sl] & 0xFF) << 8) | ((*s)[sl + 1] & 0xFF)
+				: (((*s)[sl + 1] & 0xFF) << 8) | ((*s)[sl] & 0xFF);
+			c = (((c & 0x3FF) << 10) | (d & 0x3FF)) + 0x10000;
+		}
+
+		while (l + 6 > max)
+			u = realloc(u, max += SWITCH_XML_BUFSIZE);
+		if (c < 0x80)
+			u[l++] = (char) c;	// US-ASCII subset
+		else {					// multi-byte UTF-8 sequence
+			for (b = 0, d = c; d; d /= 2)
+				b++;			// bits in c
+			b = (b - 2) / 5;	// bytes in payload
+			u[l++] = (char) ((0xFF << (7 - b)) | (c >> (6 * b)));	// head
+			while (b)
+				u[l++] = (char) (0x80 | ((c >> (6 * --b)) & 0x3F));	// payload
+		}
+	}
+	return *s = realloc(u, *len = l);
 }
 
 // frees a tag attribute list
-static void switch_xml_free_attr(char **attr) {
-    int i = 0;
-    char *m;
-    
-    if (! attr || attr == SWITCH_XML_NIL) return; // nothing to free
-    while (attr[i]) i += 2; // find end of attribute list
-    m = attr[i + 1]; // list of which names and values are malloced
-    for (i = 0; m[i]; i++) {
-        if (m[i] & SWITCH_XML_NAMEM) free(attr[i * 2]);
-        if (m[i] & SWITCH_XML_TXTM) free(attr[(i * 2) + 1]);
-    }
-    free(m);
-    free(attr);
+static void switch_xml_free_attr(char **attr)
+{
+	int i = 0;
+	char *m;
+
+	if (!attr || attr == SWITCH_XML_NIL)
+		return;					// nothing to free
+	while (attr[i])
+		i += 2;					// find end of attribute list
+	m = attr[i + 1];			// list of which names and values are malloced
+	for (i = 0; m[i]; i++) {
+		if (m[i] & SWITCH_XML_NAMEM)
+			free(attr[i * 2]);
+		if (m[i] & SWITCH_XML_TXTM)
+			free(attr[(i * 2) + 1]);
+	}
+	free(m);
+	free(attr);
 }
 
 // parse the given xml string and return an switch_xml structure
 SWITCH_DECLARE(switch_xml_t) switch_xml_parse_str(char *s, switch_size_t len)
 {
-    switch_xml_root_t root = (switch_xml_root_t)switch_xml_new(NULL);
-    char q, e, *d, **attr, **a = NULL; // initialize a to avoid compile warning
-    int l, i, j;
-
-    root->m = s;
-    if (! len) return switch_xml_err(root, s, "root tag missing");
-    root->u = switch_xml_str2utf8(&s, &len); // convert utf-16 to utf-8
-    root->e = (root->s = s) + len; // record start and end of work area
-    
-    e = s[len - 1]; // save end char
-    s[len - 1] = '\0'; // turn end char into null terminator
-
-    while (*s && *s != '<') s++; // find first tag
-    if (! *s) return switch_xml_err(root, s, "root tag missing");
-
-    for (; ; ) {
-        attr = (char **)SWITCH_XML_NIL;
-        d = ++s;
-        
-        if (isalpha((int)(*s)) || *s == '_' || *s == ':' || (int8_t) *s < '\0') { // new tag
-            if (! root->cur)
-                return switch_xml_err(root, d, "markup outside of root element");
-
-            s += strcspn(s, SWITCH_XML_WS "/>");
-            while (isspace((int)(*s))) *(s++) = '\0'; // null terminate tag name
-  
-            if (*s && *s != '/' && *s != '>') // find tag in default attr list
-                for (i = 0; (a = root->attr[i]) && strcmp(a[0], d); i++);
-
-            for (l = 0; *s && *s != '/' && *s != '>'; l += 2) { // new attrib
-                attr = (l) ? realloc(attr, (l + 4) * sizeof(char *))
-                           : malloc(4 * sizeof(char *)); // allocate space
-                attr[l + 3] = (l) ? realloc(attr[l + 1], (l / 2) + 2)
-                                  : malloc(2); // mem for list of maloced vals
-                strcpy(attr[l + 3] + (l / 2), " "); // value is not malloced
-                attr[l + 2] = NULL; // null terminate list
-                attr[l + 1] = ""; // temporary attribute value
-                attr[l] = s; // set attribute name
-
-                s += strcspn(s, SWITCH_XML_WS "=/>");
-                if (*s == '=' || isspace((int)(*s))) { 
-                    *(s++) = '\0'; // null terminate tag attribute name
-                    q = *(s += strspn(s, SWITCH_XML_WS "="));
-                    if (q == '"' || q == '\'') { // attribute value
-                        attr[l + 1] = ++s;
-                        while (*s && *s != q) s++;
-                        if (*s) *(s++) = '\0'; // null terminate attribute val
-                        else {
-                            switch_xml_free_attr(attr);
-                            return switch_xml_err(root, d, "missing %c", q);
-                        }
-
-                        for (j = 1; a && a[j] && strcmp(a[j], attr[l]); j +=3);
-                        attr[l + 1] = switch_xml_decode(attr[l + 1], root->ent, (a
-                                                   && a[j]) ? *a[j + 2] : ' ');
-                        if (attr[l + 1] < d || attr[l + 1] > s)
-                            attr[l + 3][l / 2] = SWITCH_XML_TXTM; // value malloced
-                    }
-                }
-                while (isspace((int)(*s))) s++;
-            }
-
-            if (*s == '/') { // self closing tag
-                *(s++) = '\0';
-                if ((*s && *s != '>') || (! *s && e != '>')) {
-                    if (l) switch_xml_free_attr(attr);
-                    return switch_xml_err(root, d, "missing >");
-                }
-                switch_xml_open_tag(root, d, attr);
-                switch_xml_close_tag(root, d, s);
-            }
-            else if ((q = *s) == '>' || (! *s && e == '>')) { // open tag
-                *s = '\0'; // temporarily null terminate tag name
-                switch_xml_open_tag(root, d, attr);
-                *s = q;
-            }
-            else {
-                if (l) switch_xml_free_attr(attr);
-                return switch_xml_err(root, d, "missing >"); 
-            }
-        }
-        else if (*s == '/') { // close tag
-            s += strcspn(d = s + 1, SWITCH_XML_WS ">") + 1;
-            if (! (q = *s) && e != '>') return switch_xml_err(root, d, "missing >");
-            *s = '\0'; // temporarily null terminate tag name
-            if (switch_xml_close_tag(root, d, s)) return &root->xml;
-            if (isspace((int)(*s = q))) s += strspn(s, SWITCH_XML_WS);
-        }
-        else if (! strncmp(s, "!--", 3)) { // xml comment
-            if (! (s = strstr(s + 3, "--")) || (*(s += 2) != '>' && *s) ||
-                (! *s && e != '>')) return switch_xml_err(root, d, "unclosed <!--");
-        }
-        else if (! strncmp(s, "![CDATA[", 8)) { // cdata
-            if ((s = strstr(s, "]]>")))
-                switch_xml_char_content(root, d + 8, (s += 2) - d - 10, 'c');
-            else return switch_xml_err(root, d, "unclosed <![CDATA[");
-        }
-        else if (! strncmp(s, "!DOCTYPE", 8)) { // dtd
-            for (l = 0; *s && ((! l && *s != '>') || (l && (*s != ']' || 
-                 *(s + strspn(s + 1, SWITCH_XML_WS) + 1) != '>')));
-                 l = (*s == '[') ? 1 : l) s += strcspn(s + 1, "[]>") + 1;
-            if (! *s && e != '>')
-                return switch_xml_err(root, d, "unclosed <!DOCTYPE");
-            d = (l) ? strchr(d, '[') + 1 : d;
-            if (l && ! switch_xml_internal_dtd(root, d, s++ - d)) return &root->xml;
-        }
-        else if (*s == '?') { // <?...?> processing instructions
-            do { s = strchr(s, '?'); } while (s && *(++s) && *s != '>');
-            if (! s || (! *s && e != '>')) 
-                return switch_xml_err(root, d, "unclosed <?");
-            else switch_xml_proc_inst(root, d + 1, s - d - 2);
-        }
-        else return switch_xml_err(root, d, "unexpected <");
-        
-        if (! s || ! *s) break;
-        *s = '\0';
-        d = ++s;
-        if (*s && *s != '<') { // tag character content
-            while (*s && *s != '<') s++;
-            if (*s) switch_xml_char_content(root, d, s - d, '&');
-            else break;
-        }
-        else if (! *s) break;
-    }
-
-    if (! root->cur) return &root->xml;
-    else if (! root->cur->name) return switch_xml_err(root, d, "root tag missing");
-    else return switch_xml_err(root, d, "unclosed tag <%s>", root->cur->name);
+	switch_xml_root_t root = (switch_xml_root_t) switch_xml_new(NULL);
+	char q, e, *d, **attr, **a = NULL;	// initialize a to avoid compile warning
+	int l, i, j;
+
+	root->m = s;
+	if (!len)
+		return switch_xml_err(root, s, "root tag missing");
+	root->u = switch_xml_str2utf8(&s, &len);	// convert utf-16 to utf-8
+	root->e = (root->s = s) + len;	// record start and end of work area
+
+	e = s[len - 1];				// save end char
+	s[len - 1] = '\0';			// turn end char into null terminator
+
+	while (*s && *s != '<')
+		s++;					// find first tag
+	if (!*s)
+		return switch_xml_err(root, s, "root tag missing");
+
+	for (;;) {
+		attr = (char **) SWITCH_XML_NIL;
+		d = ++s;
+
+		if (isalpha((int) (*s)) || *s == '_' || *s == ':' || (int8_t) *s < '\0') {	// new tag
+			if (!root->cur)
+				return switch_xml_err(root, d, "markup outside of root element");
+
+			s += strcspn(s, SWITCH_XML_WS "/>");
+			while (isspace((int) (*s)))
+				*(s++) = '\0';	// null terminate tag name
+
+			if (*s && *s != '/' && *s != '>')	// find tag in default attr list
+				for (i = 0; (a = root->attr[i]) && strcmp(a[0], d); i++);
+
+			for (l = 0; *s && *s != '/' && *s != '>'; l += 2) {	// new attrib
+				attr = (l) ? realloc(attr, (l + 4) * sizeof(char *))
+					: malloc(4 * sizeof(char *));	// allocate space
+				attr[l + 3] = (l) ? realloc(attr[l + 1], (l / 2) + 2)
+					: malloc(2);	// mem for list of maloced vals
+				strcpy(attr[l + 3] + (l / 2), " ");	// value is not malloced
+				attr[l + 2] = NULL;	// null terminate list
+				attr[l + 1] = "";	// temporary attribute value
+				attr[l] = s;	// set attribute name
+
+				s += strcspn(s, SWITCH_XML_WS "=/>");
+				if (*s == '=' || isspace((int) (*s))) {
+					*(s++) = '\0';	// null terminate tag attribute name
+					q = *(s += strspn(s, SWITCH_XML_WS "="));
+					if (q == '"' || q == '\'') {	// attribute value
+						attr[l + 1] = ++s;
+						while (*s && *s != q)
+							s++;
+						if (*s)
+							*(s++) = '\0';	// null terminate attribute val
+						else {
+							switch_xml_free_attr(attr);
+							return switch_xml_err(root, d, "missing %c", q);
+						}
+
+						for (j = 1; a && a[j] && strcmp(a[j], attr[l]); j += 3);
+						attr[l + 1] = switch_xml_decode(attr[l + 1], root->ent, (a && a[j]) ? *a[j + 2] : ' ');
+						if (attr[l + 1] < d || attr[l + 1] > s)
+							attr[l + 3][l / 2] = SWITCH_XML_TXTM;	// value malloced
+					}
+				}
+				while (isspace((int) (*s)))
+					s++;
+			}
+
+			if (*s == '/') {	// self closing tag
+				*(s++) = '\0';
+				if ((*s && *s != '>') || (!*s && e != '>')) {
+					if (l)
+						switch_xml_free_attr(attr);
+					return switch_xml_err(root, d, "missing >");
+				}
+				switch_xml_open_tag(root, d, attr);
+				switch_xml_close_tag(root, d, s);
+			} else if ((q = *s) == '>' || (!*s && e == '>')) {	// open tag
+				*s = '\0';		// temporarily null terminate tag name
+				switch_xml_open_tag(root, d, attr);
+				*s = q;
+			} else {
+				if (l)
+					switch_xml_free_attr(attr);
+				return switch_xml_err(root, d, "missing >");
+			}
+		} else if (*s == '/') {	// close tag
+			s += strcspn(d = s + 1, SWITCH_XML_WS ">") + 1;
+			if (!(q = *s) && e != '>')
+				return switch_xml_err(root, d, "missing >");
+			*s = '\0';			// temporarily null terminate tag name
+			if (switch_xml_close_tag(root, d, s))
+				return &root->xml;
+			if (isspace((int) (*s = q)))
+				s += strspn(s, SWITCH_XML_WS);
+		} else if (!strncmp(s, "!--", 3)) {	// xml comment
+			if (!(s = strstr(s + 3, "--")) || (*(s += 2) != '>' && *s) || (!*s && e != '>'))
+				return switch_xml_err(root, d, "unclosed <!--");
+		} else if (!strncmp(s, "![CDATA[", 8)) {	// cdata
+			if ((s = strstr(s, "]]>")))
+				switch_xml_char_content(root, d + 8, (s += 2) - d - 10, 'c');
+			else
+				return switch_xml_err(root, d, "unclosed <![CDATA[");
+		} else if (!strncmp(s, "!DOCTYPE", 8)) {	// dtd
+			for (l = 0; *s && ((!l && *s != '>') || (l && (*s != ']' || *(s + strspn(s + 1, SWITCH_XML_WS) + 1) != '>'))); l = (*s == '[') ? 1 : l)
+				s += strcspn(s + 1, "[]>") + 1;
+			if (!*s && e != '>')
+				return switch_xml_err(root, d, "unclosed <!DOCTYPE");
+			d = (l) ? strchr(d, '[') + 1 : d;
+			if (l && !switch_xml_internal_dtd(root, d, s++ - d))
+				return &root->xml;
+		} else if (*s == '?') {	// <?...?> processing instructions
+			do {
+				s = strchr(s, '?');
+			} while (s && *(++s) && *s != '>');
+			if (!s || (!*s && e != '>'))
+				return switch_xml_err(root, d, "unclosed <?");
+			else
+				switch_xml_proc_inst(root, d + 1, s - d - 2);
+		} else
+			return switch_xml_err(root, d, "unexpected <");
+
+		if (!s || !*s)
+			break;
+		*s = '\0';
+		d = ++s;
+		if (*s && *s != '<') {	// tag character content
+			while (*s && *s != '<')
+				s++;
+			if (*s)
+				switch_xml_char_content(root, d, s - d, '&');
+			else
+				break;
+		} else if (!*s)
+			break;
+	}
+
+	if (!root->cur)
+		return &root->xml;
+	else if (!root->cur->name)
+		return switch_xml_err(root, d, "root tag missing");
+	else
+		return switch_xml_err(root, d, "unclosed tag <%s>", root->cur->name);
 }
 
 // Wrapper for switch_xml_parse_str() that accepts a file stream. Reads the entire
 // stream into memory and then parses it. For xml files, use switch_xml_parse_file()
 // or switch_xml_parse_fd()
-SWITCH_DECLARE(switch_xml_t) switch_xml_parse_fp(FILE *fp)
+SWITCH_DECLARE(switch_xml_t) switch_xml_parse_fp(FILE * fp)
 {
-    switch_xml_root_t root;
-    switch_size_t l, len = 0;
-    char *s;
-
-    if (! (s = malloc(SWITCH_XML_BUFSIZE))) return NULL;
-    do {
-        len += (l = fread((s + len), 1, SWITCH_XML_BUFSIZE, fp));
-        if (l == SWITCH_XML_BUFSIZE) s = realloc(s, len + SWITCH_XML_BUFSIZE);
-    } while (s && l == SWITCH_XML_BUFSIZE);
-
-    if (! s) return NULL;
-    root = (switch_xml_root_t)switch_xml_parse_str(s, len);
-    root->dynamic = 1; // so we know to free s in switch_xml_free()
-    return &root->xml;
+	switch_xml_root_t root;
+	switch_size_t l, len = 0;
+	char *s;
+
+	if (!(s = malloc(SWITCH_XML_BUFSIZE)))
+		return NULL;
+	do {
+		len += (l = fread((s + len), 1, SWITCH_XML_BUFSIZE, fp));
+		if (l == SWITCH_XML_BUFSIZE)
+			s = realloc(s, len + SWITCH_XML_BUFSIZE);
+	} while (s && l == SWITCH_XML_BUFSIZE);
+
+	if (!s)
+		return NULL;
+	root = (switch_xml_root_t) switch_xml_parse_str(s, len);
+	root->dynamic = 1;			// so we know to free s in switch_xml_free()
+	return &root->xml;
 }
 
 // A wrapper for switch_xml_parse_str() that accepts a file descriptor. First
@@ -758,247 +844,244 @@
 // Returns NULL on failure.
 SWITCH_DECLARE(switch_xml_t) switch_xml_parse_fd(int fd)
 {
-    switch_xml_root_t root;
-    struct stat st;
-    switch_size_t l;
-    void *m;
-
-    if (fd < 0) return NULL;
-    fstat(fd, &st);
+	switch_xml_root_t root;
+	struct stat st;
+	switch_size_t l;
+	void *m;
+
+	if (fd < 0)
+		return NULL;
+	fstat(fd, &st);
 
 #ifdef HAVE_MMAP
-    l = (st.st_size + sysconf(_SC_PAGESIZE) - 1) & ~(sysconf(_SC_PAGESIZE) -1);
-    if ((m = mmap(NULL, l, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0)) !=
-        MAP_FAILED) {
-        madvise(m, l, MADV_SEQUENTIAL); // optimize for sequential access
-        root = (switch_xml_root_t)switch_xml_parse_str(m, st.st_size);
-        madvise(m, root->len = l, MADV_NORMAL); // put it back to normal
-    }
-    else { // mmap failed, read file into memory
+	l = (st.st_size + sysconf(_SC_PAGESIZE) - 1) & ~(sysconf(_SC_PAGESIZE) - 1);
+	if ((m = mmap(NULL, l, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0)) != MAP_FAILED) {
+		madvise(m, l, MADV_SEQUENTIAL);	// optimize for sequential access
+		root = (switch_xml_root_t) switch_xml_parse_str(m, st.st_size);
+		madvise(m, root->len = l, MADV_NORMAL);	// put it back to normal
+	} else {					// mmap failed, read file into memory
 #endif // HAVE_MMAP
-        l = read(fd, m = malloc(st.st_size), st.st_size);
-        root = (switch_xml_root_t)switch_xml_parse_str(m, l);
-        root->dynamic = 1; // so we know to free s in switch_xml_free()
+		l = read(fd, m = malloc(st.st_size), st.st_size);
+		root = (switch_xml_root_t) switch_xml_parse_str(m, l);
+		root->dynamic = 1;		// so we know to free s in switch_xml_free()
 #ifdef HAVE_MMAP
-    }
+	}
 #endif // HAVE_MMAP
-    return &root->xml;
+	return &root->xml;
 }
 
-static switch_size_t read_line(int fd, char *buf, switch_size_t len) {
-    char c, *p;
-    int cur;
-    switch_size_t total = 0;
-    
-    p = buf;
-    while (total + sizeof(c) < len && (cur = read(fd, &c, sizeof(c))) > 0) {
-        total += cur;
-        *p++ = c;
-        if (c == '\n') {
-            break;
-        }
-    }
+static switch_size_t read_line(int fd, char *buf, switch_size_t len)
+{
+	char c, *p;
+	int cur;
+	switch_size_t total = 0;
+
+	p = buf;
+	while (total + sizeof(c) < len && (cur = read(fd, &c, sizeof(c))) > 0) {
+		total += cur;
+		*p++ = c;
+		if (c == '\n') {
+			break;
+		}
+	}
 
-    *p++ = '\0';
-    return total;
+	*p++ = '\0';
+	return total;
 }
 
 static char *expand_vars(char *buf, char *ebuf, switch_size_t elen, switch_size_t *newlen)
 {
-    char *var, *val;
-    char *rp = buf;
-    char *wp = ebuf;
-    char *ep = ebuf + elen - 1;
-
-    if (!(var = strstr(rp, "$${"))) {
-        *newlen = strlen(buf);
-        return buf;
-    }
-
-    while(*rp && wp < ep) {
-
-        if (*rp == '$' && *(rp+1) == '$' && *(rp+2) == '{') {
-            char *e = strchr(rp, '}');
-
-            if (e) {
-                rp += 3;
-                var = rp;
-                *e++ = '\0';
-                rp = e;
-                if ((val = switch_core_get_variable(var))) {
-                    char *p;
-                    for(p = val; p && *p && wp <= ep; p++) {
-                        *wp++ = *p;
-                    }
-                }
-            }
-
-        }
-
-        *wp++ = *rp++;
-    }
-    *wp++ = '\0';
-    *newlen = strlen(ebuf);
+	char *var, *val;
+	char *rp = buf;
+	char *wp = ebuf;
+	char *ep = ebuf + elen - 1;
+
+	if (!(var = strstr(rp, "$${"))) {
+		*newlen = strlen(buf);
+		return buf;
+	}
+
+	while (*rp && wp < ep) {
+
+		if (*rp == '$' && *(rp + 1) == '$' && *(rp + 2) == '{') {
+			char *e = strchr(rp, '}');
+
+			if (e) {
+				rp += 3;
+				var = rp;
+				*e++ = '\0';
+				rp = e;
+				if ((val = switch_core_get_variable(var))) {
+					char *p;
+					for (p = val; p && *p && wp <= ep; p++) {
+						*wp++ = *p;
+					}
+				}
+			}
+
+		}
+
+		*wp++ = *rp++;
+	}
+	*wp++ = '\0';
+	*newlen = strlen(ebuf);
+
+	return ebuf;
 
-    return ebuf;
-    
 }
 
 static int preprocess(const char *file, int write_fd, int rlevel)
 {
-    int read_fd = -1;
-    switch_size_t cur = 0, ml = 0;
-    char *q, *cmd, buf[2048], ebuf[8192];
-
-    if ((read_fd = open(file, O_RDONLY, 0)) < 0) {
-        return read_fd;
-    }
-
-    if (rlevel > 100) {
-        return -1;
-    }
-
-    while((cur = read_line(read_fd, buf, sizeof(buf))) > 0) {
-        char *arg, *e;
-        char *bp = expand_vars(buf, ebuf, sizeof(ebuf), &cur);
-
-        /* we ignore <include> or </include> for the sake of validators */
-        if (strstr(buf, "<include>") || strstr(buf, "</include>")) {
-            continue;
-        }
-
-        if (ml) {
-            if ((e = strstr(buf, "-->"))) {
-                ml = 0;
-                bp = e + 3;
-                cur = strlen(bp);
-            } else {
-                continue;
-            }
-        }
-
-        if ((cmd = strstr(bp, "<!--#"))) {
-            write(write_fd, bp, (unsigned)(cmd - bp));
-            if ((e = strstr(cmd, "-->"))) {
-                *e = '\0';
-                e += 3;
-                write(write_fd, e, (unsigned)strlen(e));
-            } else {
-                ml++;
-            }
-            
-            cmd += 5;
-            if ((e = strchr(cmd, '\r')) || (e = strchr(cmd, '\n'))) {
-                *e = '\0';
-            }
-
-            if ((arg = strchr(cmd, ' '))) {
-                *arg++ = '\0';
-                if ((q = strchr(arg, '"'))) {
-                    char *qq = q+1;
-
-                    if ((qq = strchr(qq, '"'))) {
-                        *qq = '\0';
-                        arg = q+1;
-                    }
-                }
-
-                if (!strcasecmp(cmd, "set")) {
-                    char *name = arg;
-                    char *val = strchr(name, '=');
-
-                    if (val) {
-                        char *ve = val++;
-                        while(*val && *val == ' ') {
-                            val++;
-                        }
-                        *ve-- = '\0';
-                        while(*ve && *ve == ' ') {
-                            *ve-- = '\0';
-                        }
-                    }
-                
-                    if (name && val) {
-                        switch_core_set_variable(name, val);
-                    }
-                
-                } else if (!strcasecmp(cmd, "include")) {
-                    char *fme = NULL, *ifile = arg;
-                
-                    if (!switch_is_file_path(ifile)) {
-                        fme = switch_mprintf("%s%s%s", SWITCH_GLOBAL_dirs.conf_dir, SWITCH_PATH_SEPARATOR, arg);
-                        ifile = fme;
-                    }
-                    if (preprocess(ifile, write_fd, rlevel + 1) < 0) {
-                        fprintf(stderr, "Error including %s (%s)\n", ifile, strerror(errno));
-                    }
-                    switch_safe_free(fme);
-                } /* else NO OP */
-            }
+	int read_fd = -1;
+	switch_size_t cur = 0, ml = 0;
+	char *q, *cmd, buf[2048], ebuf[8192];
 
-            continue;
-        }
+	if ((read_fd = open(file, O_RDONLY, 0)) < 0) {
+		return read_fd;
+	}
+
+	if (rlevel > 100) {
+		return -1;
+	}
 
-        write(write_fd, bp, (unsigned)cur);
-    }
+	while ((cur = read_line(read_fd, buf, sizeof(buf))) > 0) {
+		char *arg, *e;
+		char *bp = expand_vars(buf, ebuf, sizeof(ebuf), &cur);
 
-    close(read_fd);
-    return write_fd;
+		/* we ignore <include> or </include> for the sake of validators */
+		if (strstr(buf, "<include>") || strstr(buf, "</include>")) {
+			continue;
+		}
+
+		if (ml) {
+			if ((e = strstr(buf, "-->"))) {
+				ml = 0;
+				bp = e + 3;
+				cur = strlen(bp);
+			} else {
+				continue;
+			}
+		}
+
+		if ((cmd = strstr(bp, "<!--#"))) {
+			write(write_fd, bp, (unsigned) (cmd - bp));
+			if ((e = strstr(cmd, "-->"))) {
+				*e = '\0';
+				e += 3;
+				write(write_fd, e, (unsigned) strlen(e));
+			} else {
+				ml++;
+			}
+
+			cmd += 5;
+			if ((e = strchr(cmd, '\r')) || (e = strchr(cmd, '\n'))) {
+				*e = '\0';
+			}
+
+			if ((arg = strchr(cmd, ' '))) {
+				*arg++ = '\0';
+				if ((q = strchr(arg, '"'))) {
+					char *qq = q + 1;
+
+					if ((qq = strchr(qq, '"'))) {
+						*qq = '\0';
+						arg = q + 1;
+					}
+				}
+
+				if (!strcasecmp(cmd, "set")) {
+					char *name = arg;
+					char *val = strchr(name, '=');
+
+					if (val) {
+						char *ve = val++;
+						while (*val && *val == ' ') {
+							val++;
+						}
+						*ve-- = '\0';
+						while (*ve && *ve == ' ') {
+							*ve-- = '\0';
+						}
+					}
+
+					if (name && val) {
+						switch_core_set_variable(name, val);
+					}
+
+				} else if (!strcasecmp(cmd, "include")) {
+					char *fme = NULL, *ifile = arg;
+
+					if (!switch_is_file_path(ifile)) {
+						fme = switch_mprintf("%s%s%s", SWITCH_GLOBAL_dirs.conf_dir, SWITCH_PATH_SEPARATOR, arg);
+						ifile = fme;
+					}
+					if (preprocess(ifile, write_fd, rlevel + 1) < 0) {
+						fprintf(stderr, "Error including %s (%s)\n", ifile, strerror(errno));
+					}
+					switch_safe_free(fme);
+				}				/* else NO OP */
+			}
+
+			continue;
+		}
+
+		write(write_fd, bp, (unsigned) cur);
+	}
+
+	close(read_fd);
+	return write_fd;
 }
 
 // a wrapper for switch_xml_parse_fd that accepts a file name
 SWITCH_DECLARE(switch_xml_t) switch_xml_parse_file(const char *file)
 {
-    int fd = -1, write_fd = -1;
-    switch_xml_t xml = NULL;
-    char *new_file = NULL;
-    const char *abs;
-
-    if ((abs = strrchr(file, '/')) || (abs = strrchr(file, '\\'))) {
-        abs++;
-    } else {
-        abs = file;
-    }
-    
-    if (!(new_file = switch_mprintf("%s%s%s.fsxml", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR, abs))) {
-        return NULL;
-    }
-
-    if ((write_fd = open(new_file, O_WRONLY | O_CREAT | O_TRUNC,  S_IRUSR | S_IWUSR)) < 0) {
-        goto done;
-    }
-
-    if (preprocess(file, write_fd, 0) > -1) {
-        close(write_fd);
-        write_fd = -1;
-        if ((fd = open(new_file, O_RDONLY, 0)) > -1) {
-            if ((xml = switch_xml_parse_fd(fd))) {
-                xml->free_path = new_file;
-                new_file = NULL;
-            }
-            close(fd);
-            fd = -1;
-        }
-    }
-
- done:
-    if (write_fd > -1) {
-        close(write_fd);
-    }
-    if (fd > -1) {
-        close(fd);
-    }
-    switch_safe_free(new_file);
-    return xml;
+	int fd = -1, write_fd = -1;
+	switch_xml_t xml = NULL;
+	char *new_file = NULL;
+	const char *abs;
+
+	if ((abs = strrchr(file, '/')) || (abs = strrchr(file, '\\'))) {
+		abs++;
+	} else {
+		abs = file;
+	}
+
+	if (!(new_file = switch_mprintf("%s%s%s.fsxml", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR, abs))) {
+		return NULL;
+	}
+
+	if ((write_fd = open(new_file, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) < 0) {
+		goto done;
+	}
+
+	if (preprocess(file, write_fd, 0) > -1) {
+		close(write_fd);
+		write_fd = -1;
+		if ((fd = open(new_file, O_RDONLY, 0)) > -1) {
+			if ((xml = switch_xml_parse_fd(fd))) {
+				xml->free_path = new_file;
+				new_file = NULL;
+			}
+			close(fd);
+			fd = -1;
+		}
+	}
+
+  done:
+	if (write_fd > -1) {
+		close(write_fd);
+	}
+	if (fd > -1) {
+		close(fd);
+	}
+	switch_safe_free(new_file);
+	return xml;
 }
 
 
 SWITCH_DECLARE(switch_status_t) switch_xml_locate(const char *section,
 												  const char *tag_name,
-												  const char *key_name,
-												  const char *key_value,
-												  switch_xml_t *root,
-												  switch_xml_t *node,
+												  const char *key_name, const char *key_value, switch_xml_t * root, switch_xml_t * node,
 												  const char *params)
 {
 	switch_xml_t conf = NULL;
@@ -1009,7 +1092,7 @@
 
 	switch_mutex_lock(XML_LOCK);
 
-	for(binding = BINDINGS; binding; binding = binding->next) {
+	for (binding = BINDINGS; binding; binding = binding->next) {
 		switch_xml_section_t sections = switch_xml_parse_section_string(section);
 
 		if (binding->sections && !(sections & binding->sections)) {
@@ -1018,7 +1101,7 @@
 
 		if ((xml = binding->function(section, tag_name, key_name, key_value, params, binding->user_data))) {
 			const char *err = NULL;
-			
+
 			err = switch_xml_error(xml);
 			if (switch_strlen_zero(err)) {
 				if ((conf = switch_xml_find_child(xml, "section", "name", "result"))) {
@@ -1044,7 +1127,7 @@
 	}
 	switch_mutex_unlock(XML_LOCK);
 
-	for(;;) {
+	for (;;) {
 		if (!xml) {
 			if (!(xml = switch_xml_root())) {
 				*node = NULL;
@@ -1053,8 +1136,7 @@
 			}
 		}
 
-		if ((conf = switch_xml_find_child(xml, "section", "name", section)) && 
-			(tag = switch_xml_find_child(conf, tag_name, key_name, key_value))) {
+		if ((conf = switch_xml_find_child(xml, "section", "name", section)) && (tag = switch_xml_find_child(conf, tag_name, key_name, key_value))) {
 			*node = tag;
 			*root = xml;
 			return SWITCH_STATUS_SUCCESS;
@@ -1139,7 +1221,7 @@
 
 	assert(pool != NULL);
 
-	if((xml=switch_xml_open_root(FALSE, err))) {
+	if ((xml = switch_xml_open_root(FALSE, err))) {
 		switch_xml_free(xml);
 		return SWITCH_STATUS_SUCCESS;
 	} else {
@@ -1159,7 +1241,7 @@
 	return SWITCH_STATUS_FALSE;
 }
 
-SWITCH_DECLARE(switch_xml_t) switch_xml_open_cfg(const char *file_path, switch_xml_t *node, const char *params)
+SWITCH_DECLARE(switch_xml_t) switch_xml_open_cfg(const char *file_path, switch_xml_t * node, const char *params)
 {
 	switch_xml_t xml = NULL, cfg = NULL;
 
@@ -1171,8 +1253,8 @@
 		*node = cfg;
 	}
 
-	return xml;	
-	
+	return xml;
+
 }
 
 
@@ -1180,78 +1262,95 @@
 // if length excedes max. a is non-zero for attribute encoding. Returns *dst
 static char *switch_xml_ampencode(const char *s, switch_size_t len, char **dst, switch_size_t *dlen, switch_size_t *max, short a)
 {
-    const char *e = NULL;
+	const char *e = NULL;
 
 	if (len) {
 		e = s + len;
 	}
-    
-    while (s != e) {
-        while (*dlen + 10 > *max) *dst = realloc(*dst, *max += SWITCH_XML_BUFSIZE);
-
-        switch (*s) {
-        case '\0': return *dst;
-        case '&': *dlen += sprintf(*dst + *dlen, "&amp;"); break;
-        case '<': *dlen += sprintf(*dst + *dlen, "&lt;"); break;
-        case '>': *dlen += sprintf(*dst + *dlen, "&gt;"); break;
-        case '"': *dlen += sprintf(*dst + *dlen, (a) ? "&quot;" : "\""); break;
-        case '\n': *dlen += sprintf(*dst + *dlen, (a) ? "&#xA;" : "\n"); break;
-        case '\t': *dlen += sprintf(*dst + *dlen, (a) ? "&#x9;" : "\t"); break;
-        case '\r': *dlen += sprintf(*dst + *dlen, "&#xD;"); break;
-        default: (*dst)[(*dlen)++] = *s;
-        }
+
+	while (s != e) {
+		while (*dlen + 10 > *max)
+			*dst = realloc(*dst, *max += SWITCH_XML_BUFSIZE);
+
+		switch (*s) {
+		case '\0':
+			return *dst;
+		case '&':
+			*dlen += sprintf(*dst + *dlen, "&amp;");
+			break;
+		case '<':
+			*dlen += sprintf(*dst + *dlen, "&lt;");
+			break;
+		case '>':
+			*dlen += sprintf(*dst + *dlen, "&gt;");
+			break;
+		case '"':
+			*dlen += sprintf(*dst + *dlen, (a) ? "&quot;" : "\"");
+			break;
+		case '\n':
+			*dlen += sprintf(*dst + *dlen, (a) ? "&#xA;" : "\n");
+			break;
+		case '\t':
+			*dlen += sprintf(*dst + *dlen, (a) ? "&#x9;" : "\t");
+			break;
+		case '\r':
+			*dlen += sprintf(*dst + *dlen, "&#xD;");
+			break;
+		default:
+			(*dst)[(*dlen)++] = *s;
+		}
 		s++;
-    }
-    return *dst;
+	}
+	return *dst;
 }
 
 #define XML_INDENT "  "
 // Recursively converts each tag to xml appending it to *s. Reallocates *s if
 // its length excedes max. start is the location of the previous tag in the
 // parent tag's character content. Returns *s.
-static char *switch_xml_toxml_r(switch_xml_t xml, char **s, switch_size_t *len, switch_size_t *max,
-                    switch_size_t start, char ***attr, uint32_t *count)
+static char *switch_xml_toxml_r(switch_xml_t xml, char **s, switch_size_t *len, switch_size_t *max, switch_size_t start, char ***attr, uint32_t * count)
 {
-    int i, j;
-    char *txt = (xml->parent) ? xml->parent->txt : "";
-    switch_size_t off = 0;
+	int i, j;
+	char *txt = (xml->parent) ? xml->parent->txt : "";
+	switch_size_t off = 0;
 	uint32_t lcount = 0;
-	
-    // parent character content up to this tag
-    *s = switch_xml_ampencode(txt + start, xml->off - start, s, len, max, 0);
 
-    while (*len + strlen(xml->name) + 5 + (strlen(XML_INDENT) * (*count)) + 1 > *max) // reallocate s
-        *s = realloc(*s, *max += SWITCH_XML_BUFSIZE);
+	// parent character content up to this tag
+	*s = switch_xml_ampencode(txt + start, xml->off - start, s, len, max, 0);
+
+	while (*len + strlen(xml->name) + 5 + (strlen(XML_INDENT) * (*count)) + 1 > *max)	// reallocate s
+		*s = realloc(*s, *max += SWITCH_XML_BUFSIZE);
 
-	if (*(*s+(*len)-1) == '>') {
-		*len += sprintf(*s + *len, "\n"); // indent
+	if (*(*s + (*len) - 1) == '>') {
+		*len += sprintf(*s + *len, "\n");	// indent
 	}
 	for (lcount = 0; lcount < *count; lcount++) {
-		*len += sprintf(*s + *len, "%s", XML_INDENT); // indent
+		*len += sprintf(*s + *len, "%s", XML_INDENT);	// indent
+	}
+
+	*len += sprintf(*s + *len, "<%s", xml->name);	// open tag
+	for (i = 0; xml->attr[i]; i += 2) {	// tag attributes
+		if (switch_xml_attr(xml, xml->attr[i]) != xml->attr[i + 1])
+			continue;
+		while (*len + strlen(xml->attr[i]) + 7 + (strlen(XML_INDENT) * (*count)) > *max)	// reallocate s
+			*s = realloc(*s, *max += SWITCH_XML_BUFSIZE);
+
+		*len += sprintf(*s + *len, " %s=\"", xml->attr[i]);
+		switch_xml_ampencode(xml->attr[i + 1], 0, s, len, max, 1);
+		*len += sprintf(*s + *len, "\"");
+	}
+
+	for (i = 0; attr[i] && strcmp(attr[i][0], xml->name); i++);
+	for (j = 1; attr[i] && attr[i][j]; j += 3) {	// default attributes
+		if (!attr[i][j + 1] || switch_xml_attr(xml, attr[i][j]) != attr[i][j + 1])
+			continue;			// skip duplicates and non-values
+		while (*len + strlen(attr[i][j]) + 8 + (strlen(XML_INDENT) * (*count)) > *max)	// reallocate s
+			*s = realloc(*s, *max += SWITCH_XML_BUFSIZE);
+
+		*len += sprintf(*s + *len, " %s=\"", attr[i][j]);
+		switch_xml_ampencode(attr[i][j + 1], 0, s, len, max, 1);
+		*len += sprintf(*s + *len, "\"");
 	}
-	
-    *len += sprintf(*s + *len, "<%s", xml->name); // open tag
-    for (i = 0; xml->attr[i]; i += 2) { // tag attributes
-        if (switch_xml_attr(xml, xml->attr[i]) != xml->attr[i + 1]) continue;
-        while (*len + strlen(xml->attr[i]) + 7 + (strlen(XML_INDENT) * (*count)) > *max) // reallocate s
-            *s = realloc(*s, *max += SWITCH_XML_BUFSIZE);
-
-        *len += sprintf(*s + *len, " %s=\"", xml->attr[i]);
-        switch_xml_ampencode(xml->attr[i + 1], 0, s, len, max, 1);
-        *len += sprintf(*s + *len, "\"");
-    }
-
-    for (i = 0; attr[i] && strcmp(attr[i][0], xml->name); i++);
-    for (j = 1; attr[i] && attr[i][j]; j += 3) { // default attributes
-        if (! attr[i][j + 1] || switch_xml_attr(xml, attr[i][j]) != attr[i][j + 1])
-            continue; // skip duplicates and non-values
-        while (*len + strlen(attr[i][j]) + 8 + (strlen(XML_INDENT) * (*count)) > *max) // reallocate s
-            *s = realloc(*s, *max += SWITCH_XML_BUFSIZE);
-
-        *len += sprintf(*s + *len, " %s=\"", attr[i][j]);
-        switch_xml_ampencode(attr[i][j + 1], 0, s, len, max, 1);
-        *len += sprintf(*s + *len, "\"");
-    }
 
 	*len += sprintf(*s + *len, (xml->child || xml->txt) ? ">" : "/>\n");
 
@@ -1260,23 +1359,24 @@
 		*s = switch_xml_toxml_r(xml->child, s, len, max, 0, attr, count);
 
 	} else {
-		*s = switch_xml_ampencode(xml->txt, 0, s, len, max, 0);  //data
+		*s = switch_xml_ampencode(xml->txt, 0, s, len, max, 0);	//data
 	}
-	
-    while (*len + strlen(xml->name) + 5 + (strlen(XML_INDENT) * (*count)) > *max) // reallocate s
-        *s = realloc(*s, *max += SWITCH_XML_BUFSIZE);
+
+	while (*len + strlen(xml->name) + 5 + (strlen(XML_INDENT) * (*count)) > *max)	// reallocate s
+		*s = realloc(*s, *max += SWITCH_XML_BUFSIZE);
 
 
 	if (xml->child || xml->txt) {
-		if (*(*s+(*len)-1) == '\n') {
+		if (*(*s + (*len) - 1) == '\n') {
 			for (lcount = 0; lcount < *count; lcount++) {
-				*len += sprintf(*s + *len, "%s", XML_INDENT); // indent
+				*len += sprintf(*s + *len, "%s", XML_INDENT);	// indent
 			}
 		}
-		*len += sprintf(*s + (*len), "</%s>\n", xml->name); // close tag
+		*len += sprintf(*s + (*len), "</%s>\n", xml->name);	// close tag
 	}
 
-    while (txt[off] && off < xml->off) off++; // make sure off is within bounds
+	while (txt[off] && off < xml->off)
+		off++;					// make sure off is within bounds
 
 	if (xml->ordered) {
 		return switch_xml_toxml_r(xml->ordered, s, len, max, off, attr, count);
@@ -1292,52 +1392,57 @@
 // must be freed
 SWITCH_DECLARE(char *) switch_xml_toxml(switch_xml_t xml)
 {
-    switch_xml_t p = (xml) ? xml->parent : NULL, o = (xml) ? xml->ordered : NULL;
-    switch_xml_root_t root = (switch_xml_root_t)xml;
-    switch_size_t len = 0, max = SWITCH_XML_BUFSIZE;
-    char *s = strcpy(malloc(max), ""), *t, *n;
-    int i, j, k;
+	switch_xml_t p = (xml) ? xml->parent : NULL, o = (xml) ? xml->ordered : NULL;
+	switch_xml_root_t root = (switch_xml_root_t) xml;
+	switch_size_t len = 0, max = SWITCH_XML_BUFSIZE;
+	char *s = strcpy(malloc(max), ""), *t, *n;
+	int i, j, k;
 	uint32_t count = 0;
 
-    if (! xml || ! xml->name) return realloc(s, len + 1);
-    while (root->xml.parent) root = (switch_xml_root_t)root->xml.parent; // root tag
+	if (!xml || !xml->name)
+		return realloc(s, len + 1);
+	while (root->xml.parent)
+		root = (switch_xml_root_t) root->xml.parent;	// root tag
+
+	for (i = 0; !p && root->pi[i]; i++) {	// pre-root processing instructions
+		for (k = 2; root->pi[i][k - 1]; k++);
+		for (j = 1; (n = root->pi[i][j]); j++) {
+			if (root->pi[i][k][j - 1] == '>')
+				continue;		// not pre-root
+			while (len + strlen(t = root->pi[i][0]) + strlen(n) + 7 > max)
+				s = realloc(s, max += SWITCH_XML_BUFSIZE);
+			len += sprintf(s + len, "<?%s%s%s?>", t, *n ? " " : "", n);
+		}
+	}
 
-    for (i = 0; ! p && root->pi[i]; i++) { // pre-root processing instructions
-        for (k = 2; root->pi[i][k - 1]; k++);
-        for (j = 1; (n = root->pi[i][j]); j++) {
-            if (root->pi[i][k][j - 1] == '>') continue; // not pre-root
-            while (len + strlen(t = root->pi[i][0]) + strlen(n) + 7 > max)
-                s = realloc(s, max += SWITCH_XML_BUFSIZE);
-            len += sprintf(s + len, "<?%s%s%s?>", t, *n ? " " : "", n);
-        }
-    }
-
-    xml->parent = xml->ordered = NULL;
-    s = switch_xml_toxml_r(xml, &s, &len, &max, 0, root->attr, &count);
-    xml->parent = p;
-    xml->ordered = o;
-
-    for (i = 0; ! p && root->pi[i]; i++) { // post-root processing instructions
-        for (k = 2; root->pi[i][k - 1]; k++);
-        for (j = 1; (n = root->pi[i][j]); j++) {
-            if (root->pi[i][k][j - 1] == '<') continue; // not post-root
-            while (len + strlen(t = root->pi[i][0]) + strlen(n) + 7 > max)
-                s = realloc(s, max += SWITCH_XML_BUFSIZE);
-            len += sprintf(s + len, "\n<?%s%s%s?>", t, *n ? " " : "", n);
-        }
-    }
-    return realloc(s, len + 1);
+	xml->parent = xml->ordered = NULL;
+	s = switch_xml_toxml_r(xml, &s, &len, &max, 0, root->attr, &count);
+	xml->parent = p;
+	xml->ordered = o;
+
+	for (i = 0; !p && root->pi[i]; i++) {	// post-root processing instructions
+		for (k = 2; root->pi[i][k - 1]; k++);
+		for (j = 1; (n = root->pi[i][j]); j++) {
+			if (root->pi[i][k][j - 1] == '<')
+				continue;		// not post-root
+			while (len + strlen(t = root->pi[i][0]) + strlen(n) + 7 > max)
+				s = realloc(s, max += SWITCH_XML_BUFSIZE);
+			len += sprintf(s + len, "\n<?%s%s%s?>", t, *n ? " " : "", n);
+		}
+	}
+	return realloc(s, len + 1);
 }
 
 // free the memory allocated for the switch_xml structure
 SWITCH_DECLARE(void) switch_xml_free(switch_xml_t xml)
 {
-    switch_xml_root_t root = (switch_xml_root_t)xml;
-    int i, j;
-    char **a, *s;
+	switch_xml_root_t root = (switch_xml_root_t) xml;
+	int i, j;
+	char **a, *s;
 
 
-    if (! xml ) return;
+	if (!xml)
+		return;
 
 	if (switch_test_flag(xml, SWITCH_XML_ROOT)) {
 		if (lock_count > 0) {
@@ -1348,179 +1453,197 @@
 
 	if (xml == MAIN_XML_ROOT) {
 		return;
-	} 
+	}
+
+	if (xml->free_path) {
+		unlink(xml->free_path);
+		switch_safe_free(xml->free_path);
+	}
+
+	switch_xml_free(xml->child);
+	switch_xml_free(xml->ordered);
+
+	if (!xml->parent) {			// free root tag allocations
+		for (i = 10; root->ent[i]; i += 2)	// 0 - 9 are default entites (<>&"')
+			if ((s = root->ent[i + 1]) < root->s || s > root->e)
+				free(s);
+		free(root->ent);		// free list of general entities
+
+		for (i = 0; (a = root->attr[i]); i++) {
+			for (j = 1; a[j++]; j += 2)	// free malloced attribute values
+				if (a[j] && (a[j] < root->s || a[j] > root->e))
+					free(a[j]);
+			free(a);
+		}
+		if (root->attr[0])
+			free(root->attr);	// free default attribute list
 
-    if (xml->free_path) {
-        unlink(xml->free_path);
-        switch_safe_free(xml->free_path);
-    }
-
-    switch_xml_free(xml->child);
-    switch_xml_free(xml->ordered);
-
-    if (! xml->parent) { // free root tag allocations
-        for (i = 10; root->ent[i]; i += 2) // 0 - 9 are default entites (<>&"')
-            if ((s = root->ent[i + 1]) < root->s || s > root->e) free(s);
-        free(root->ent); // free list of general entities
-
-        for (i = 0; (a = root->attr[i]); i++) {
-            for (j = 1; a[j++]; j += 2) // free malloced attribute values
-                if (a[j] && (a[j] < root->s || a[j] > root->e)) free(a[j]);
-            free(a);
-        }
-        if (root->attr[0]) free(root->attr); // free default attribute list
-
-        for (i = 0; root->pi[i]; i++) {
-            for (j = 1; root->pi[i][j]; j++);
-            free(root->pi[i][j + 1]);
-            free(root->pi[i]);
-        }            
-        if (root->pi[0]) free(root->pi); // free processing instructions
+		for (i = 0; root->pi[i]; i++) {
+			for (j = 1; root->pi[i][j]; j++);
+			free(root->pi[i][j + 1]);
+			free(root->pi[i]);
+		}
+		if (root->pi[0])
+			free(root->pi);		// free processing instructions
 
-        if (root->dynamic == 1) free(root->m); // malloced xml data
+		if (root->dynamic == 1)
+			free(root->m);		// malloced xml data
 #ifdef HAVE_MMAP
-        else if (root->len) munmap(root->m, root->len); // mem mapped xml data
+		else if (root->len)
+			munmap(root->m, root->len);	// mem mapped xml data
 #endif // HAVE_MMAP
-        if (root->u) free(root->u); // utf8 conversion
-    }
+		if (root->u)
+			free(root->u);		// utf8 conversion
+	}
 
-    switch_xml_free_attr(xml->attr); // tag attributes
-    if ((xml->flags & SWITCH_XML_TXTM)) free(xml->txt); // character content
-    if ((xml->flags & SWITCH_XML_NAMEM)) free(xml->name); // tag name
-    free(xml);
+	switch_xml_free_attr(xml->attr);	// tag attributes
+	if ((xml->flags & SWITCH_XML_TXTM))
+		free(xml->txt);			// character content
+	if ((xml->flags & SWITCH_XML_NAMEM))
+		free(xml->name);		// tag name
+	free(xml);
 }
 
 // return parser error message or empty string if none
 SWITCH_DECLARE(const char *) switch_xml_error(switch_xml_t xml)
 {
-    while (xml && xml->parent) xml = xml->parent; // find root tag
-    return (xml) ? ((switch_xml_root_t)xml)->err : "";
+	while (xml && xml->parent)
+		xml = xml->parent;		// find root tag
+	return (xml) ? ((switch_xml_root_t) xml)->err : "";
 }
 
 // returns a new empty switch_xml structure with the given root tag name
 SWITCH_DECLARE(switch_xml_t) switch_xml_new(const char *name)
 {
-    static char *ent[] = { "lt;", "&#60;", "gt;", "&#62;", "quot;", "&#34;",
-                           "apos;", "&#39;", "amp;", "&#38;", NULL };
-    switch_xml_root_t root = (switch_xml_root_t)memset(malloc(sizeof(struct switch_xml_root)), 
-                                             '\0', sizeof(struct switch_xml_root));
-    root->xml.name = (char *)name;
-    root->cur = &root->xml;
-    strcpy(root->err, root->xml.txt = "");
-    root->ent = memcpy(malloc(sizeof(ent)), ent, sizeof(ent));
-    root->attr = root->pi = (char ***)(root->xml.attr = SWITCH_XML_NIL);
-    return &root->xml;
+	static char *ent[] = { "lt;", "&#60;", "gt;", "&#62;", "quot;", "&#34;",
+		"apos;", "&#39;", "amp;", "&#38;", NULL
+	};
+	switch_xml_root_t root = (switch_xml_root_t) memset(malloc(sizeof(struct switch_xml_root)),
+														'\0', sizeof(struct switch_xml_root));
+	root->xml.name = (char *) name;
+	root->cur = &root->xml;
+	strcpy(root->err, root->xml.txt = "");
+	root->ent = memcpy(malloc(sizeof(ent)), ent, sizeof(ent));
+	root->attr = root->pi = (char ***) (root->xml.attr = SWITCH_XML_NIL);
+	return &root->xml;
 }
 
 // inserts an existing tag into an switch_xml structure
 SWITCH_DECLARE(switch_xml_t) switch_xml_insert(switch_xml_t xml, switch_xml_t dest, switch_size_t off)
 {
-    switch_xml_t cur, prev, head;
+	switch_xml_t cur, prev, head;
 
-    xml->next = xml->sibling = xml->ordered = NULL;
-    xml->off = off;
-    xml->parent = dest;
-
-    if ((head = dest->child)) { // already have sub tags
-        if (head->off <= off) { // not first subtag
-            for (cur = head; cur->ordered && cur->ordered->off <= off;
-                 cur = cur->ordered);
-            xml->ordered = cur->ordered;
-            cur->ordered = xml;
-        }
-        else { // first subtag
-            xml->ordered = head;
-            dest->child = xml;
-        }
-
-        for (cur = head, prev = NULL; cur && strcmp(cur->name, xml->name);
-             prev = cur, cur = cur->sibling); // find tag type
-        if (cur && cur->off <= off) { // not first of type
-            while (cur->next && cur->next->off <= off) cur = cur->next;
-            xml->next = cur->next;
-            cur->next = xml;
-        }
-        else { // first tag of this type
-            if (prev && cur) prev->sibling = cur->sibling; // remove old first
-            xml->next = cur; // old first tag is now next
-            for (cur = head, prev = NULL; cur && cur->off <= off;
-                 prev = cur, cur = cur->sibling); // new sibling insert point
-            xml->sibling = cur;
-            if (prev) prev->sibling = xml;
-        }
-    }
-    else dest->child = xml; // only sub tag
+	xml->next = xml->sibling = xml->ordered = NULL;
+	xml->off = off;
+	xml->parent = dest;
+
+	if ((head = dest->child)) {	// already have sub tags
+		if (head->off <= off) {	// not first subtag
+			for (cur = head; cur->ordered && cur->ordered->off <= off; cur = cur->ordered);
+			xml->ordered = cur->ordered;
+			cur->ordered = xml;
+		} else {				// first subtag
+			xml->ordered = head;
+			dest->child = xml;
+		}
+
+		for (cur = head, prev = NULL; cur && strcmp(cur->name, xml->name); prev = cur, cur = cur->sibling);	// find tag type
+		if (cur && cur->off <= off) {	// not first of type
+			while (cur->next && cur->next->off <= off)
+				cur = cur->next;
+			xml->next = cur->next;
+			cur->next = xml;
+		} else {				// first tag of this type
+			if (prev && cur)
+				prev->sibling = cur->sibling;	// remove old first
+			xml->next = cur;	// old first tag is now next
+			for (cur = head, prev = NULL; cur && cur->off <= off; prev = cur, cur = cur->sibling);	// new sibling insert point
+			xml->sibling = cur;
+			if (prev)
+				prev->sibling = xml;
+		}
+	} else
+		dest->child = xml;		// only sub tag
 
-    return xml;
+	return xml;
 }
 
 // Adds a child tag. off is the offset of the child tag relative to the start
 // of the parent tag's character content. Returns the child tag
 switch_xml_t switch_xml_add_child(switch_xml_t xml, const char *name, switch_size_t off)
 {
-    switch_xml_t child;
+	switch_xml_t child;
 
-    if (! xml) return NULL;
-    child = (switch_xml_t)memset(malloc(sizeof(struct switch_xml)), '\0',
-                            sizeof(struct switch_xml));
-    child->name = (char *)name;
-    child->attr = SWITCH_XML_NIL;
-    child->off = off;
-    child->parent = xml;
-    child->txt = "";
+	if (!xml)
+		return NULL;
+	child = (switch_xml_t) memset(malloc(sizeof(struct switch_xml)), '\0', sizeof(struct switch_xml));
+	child->name = (char *) name;
+	child->attr = SWITCH_XML_NIL;
+	child->off = off;
+	child->parent = xml;
+	child->txt = "";
 
-    return switch_xml_insert(child, xml, off);
+	return switch_xml_insert(child, xml, off);
 }
 
 // sets the character content for the given tag and returns the tag
 switch_xml_t switch_xml_set_txt(switch_xml_t xml, const char *txt)
 {
-    if (! xml) return NULL;
-    if (xml->flags & SWITCH_XML_TXTM) free(xml->txt); // existing txt was malloced
-    xml->flags &= ~SWITCH_XML_TXTM;
-    xml->txt = (char *)txt;
-    return xml;
+	if (!xml)
+		return NULL;
+	if (xml->flags & SWITCH_XML_TXTM)
+		free(xml->txt);			// existing txt was malloced
+	xml->flags &= ~SWITCH_XML_TXTM;
+	xml->txt = (char *) txt;
+	return xml;
 }
 
 // Sets the given tag attribute or adds a new attribute if not found. A value
 // of NULL will remove the specified attribute.  Returns the tag given
 SWITCH_DECLARE(switch_xml_t) switch_xml_set_attr(switch_xml_t xml, const char *name, const char *value)
 {
-    int l = 0, c;
+	int l = 0, c;
 
-    if (! xml) return NULL;
-    while (xml->attr[l] && strcmp(xml->attr[l], name)) l += 2;
-    if (! xml->attr[l]) { // not found, add as new attribute
-        if (! value) return xml; // nothing to do
-        if (xml->attr == SWITCH_XML_NIL) { // first attribute
-            xml->attr = malloc(4 * sizeof(char *));
-            xml->attr[1] = strdup(""); // empty list of malloced names/vals
-        }
-        else xml->attr = realloc(xml->attr, (l + 4) * sizeof(char *));
-
-        xml->attr[l] = (char *)name; // set attribute name
-        xml->attr[l + 2] = NULL; // null terminate attribute list
-        xml->attr[l + 3] = realloc(xml->attr[l + 1],
-                                   (c = (int)strlen(xml->attr[l + 1])) + 2);
-        strcpy(xml->attr[l + 3] + c, " "); // set name/value as not malloced
-        if (xml->flags & SWITCH_XML_DUP) xml->attr[l + 3][c] = SWITCH_XML_NAMEM;
-    }
-    else if (xml->flags & SWITCH_XML_DUP) free((char *)name); // name was strduped
-
-    for (c = l; xml->attr[c]; c += 2); // find end of attribute list
-    if (xml->attr[c + 1][l / 2] & SWITCH_XML_TXTM) free(xml->attr[l + 1]); //old val
-    if (xml->flags & SWITCH_XML_DUP) xml->attr[c + 1][l / 2] |= SWITCH_XML_TXTM;
-    else xml->attr[c + 1][l / 2] &= ~SWITCH_XML_TXTM;
-
-    if (value) xml->attr[l + 1] = (char *)value; // set attribute value
-    else { // remove attribute
-        if (xml->attr[c + 1][l / 2] & SWITCH_XML_NAMEM) free(xml->attr[l]);
-        memmove(xml->attr + l, xml->attr + l + 2, (c - l + 2) * sizeof(char*));
-        xml->attr = realloc(xml->attr, (c + 2) * sizeof(char *));
-        memmove(xml->attr[c + 1] + (l / 2), xml->attr[c + 1] + (l / 2) + 1,
-                (c / 2) - (l / 2)); // fix list of which name/vals are malloced
-    }
-    xml->flags &= ~SWITCH_XML_DUP; // clear strdup() flag
+	if (!xml)
+		return NULL;
+	while (xml->attr[l] && strcmp(xml->attr[l], name))
+		l += 2;
+	if (!xml->attr[l]) {		// not found, add as new attribute
+		if (!value)
+			return xml;			// nothing to do
+		if (xml->attr == SWITCH_XML_NIL) {	// first attribute
+			xml->attr = malloc(4 * sizeof(char *));
+			xml->attr[1] = strdup("");	// empty list of malloced names/vals
+		} else
+			xml->attr = realloc(xml->attr, (l + 4) * sizeof(char *));
+
+		xml->attr[l] = (char *) name;	// set attribute name
+		xml->attr[l + 2] = NULL;	// null terminate attribute list
+		xml->attr[l + 3] = realloc(xml->attr[l + 1], (c = (int) strlen(xml->attr[l + 1])) + 2);
+		strcpy(xml->attr[l + 3] + c, " ");	// set name/value as not malloced
+		if (xml->flags & SWITCH_XML_DUP)
+			xml->attr[l + 3][c] = SWITCH_XML_NAMEM;
+	} else if (xml->flags & SWITCH_XML_DUP)
+		free((char *) name);	// name was strduped
+
+	for (c = l; xml->attr[c]; c += 2);	// find end of attribute list
+	if (xml->attr[c + 1][l / 2] & SWITCH_XML_TXTM)
+		free(xml->attr[l + 1]);	//old val
+	if (xml->flags & SWITCH_XML_DUP)
+		xml->attr[c + 1][l / 2] |= SWITCH_XML_TXTM;
+	else
+		xml->attr[c + 1][l / 2] &= ~SWITCH_XML_TXTM;
+
+	if (value)
+		xml->attr[l + 1] = (char *) value;	// set attribute value
+	else {						// remove attribute
+		if (xml->attr[c + 1][l / 2] & SWITCH_XML_NAMEM)
+			free(xml->attr[l]);
+		memmove(xml->attr + l, xml->attr + l + 2, (c - l + 2) * sizeof(char *));
+		xml->attr = realloc(xml->attr, (c + 2) * sizeof(char *));
+		memmove(xml->attr[c + 1] + (l / 2), xml->attr[c + 1] + (l / 2) + 1, (c / 2) - (l / 2));	// fix list of which name/vals are malloced
+	}
+	xml->flags &= ~SWITCH_XML_DUP;	// clear strdup() flag
 
 	return xml;
 }
@@ -1528,42 +1651,48 @@
 // sets a flag for the given tag and returns the tag
 SWITCH_DECLARE(switch_xml_t) switch_xml_set_flag(switch_xml_t xml, switch_xml_flag_t flag)
 {
-    if (xml) xml->flags |= flag;
-    return xml;
+	if (xml)
+		xml->flags |= flag;
+	return xml;
 }
 
 // removes a tag along with its subtags without freeing its memory
 SWITCH_DECLARE(switch_xml_t) switch_xml_cut(switch_xml_t xml)
 {
-    switch_xml_t cur;
+	switch_xml_t cur;
 
-    if (! xml) return NULL; // nothing to do
-    if (xml->next) xml->next->sibling = xml->sibling; // patch sibling list
+	if (!xml)
+		return NULL;			// nothing to do
+	if (xml->next)
+		xml->next->sibling = xml->sibling;	// patch sibling list
+
+	if (xml->parent) {			// not root tag
+		cur = xml->parent->child;	// find head of subtag list
+		if (cur == xml)
+			xml->parent->child = xml->ordered;	// first subtag
+		else {					// not first subtag
+			while (cur->ordered != xml)
+				cur = cur->ordered;
+			cur->ordered = cur->ordered->ordered;	// patch ordered list
+
+			cur = xml->parent->child;	// go back to head of subtag list
+			if (strcmp(cur->name, xml->name)) {	// not in first sibling list
+				while (strcmp(cur->sibling->name, xml->name))
+					cur = cur->sibling;
+				if (cur->sibling == xml) {	// first of a sibling list
+					cur->sibling = (xml->next) ? xml->next : cur->sibling->sibling;
+				} else
+					cur = cur->sibling;	// not first of a sibling list
+			}
 
-    if (xml->parent) { // not root tag
-        cur = xml->parent->child; // find head of subtag list
-        if (cur == xml) xml->parent->child = xml->ordered; // first subtag
-        else { // not first subtag
-            while (cur->ordered != xml) cur = cur->ordered;
-            cur->ordered = cur->ordered->ordered; // patch ordered list
-
-            cur = xml->parent->child; // go back to head of subtag list
-            if (strcmp(cur->name, xml->name)) { // not in first sibling list
-                while (strcmp(cur->sibling->name, xml->name))
-                    cur = cur->sibling;
-                if (cur->sibling == xml) { // first of a sibling list
-                    cur->sibling = (xml->next) ? xml->next
-                                               : cur->sibling->sibling;
-                }
-                else cur = cur->sibling; // not first of a sibling list
-            }
-
-            while (cur->next && cur->next != xml) cur = cur->next;
-            if (cur->next) cur->next = cur->next->next; // patch next list
-        }        
-    }
-	xml->ordered = xml->sibling = xml->next =  NULL; // prevent switch_xml_free() from clobbering ordered list
-    return xml;
+			while (cur->next && cur->next != xml)
+				cur = cur->next;
+			if (cur->next)
+				cur->next = cur->next->next;	// patch next list
+		}
+	}
+	xml->ordered = xml->sibling = xml->next = NULL;	// prevent switch_xml_free() from clobbering ordered list
+	return xml;
 }
 
 /* For Emacs:

Modified: freeswitch/branches/mikej/sofiasip-upgrade/w32/Library/FreeSwitchCore.vcproj
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/w32/Library/FreeSwitchCore.vcproj	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/w32/Library/FreeSwitchCore.vcproj	Fri Mar 30 12:19:18 2007
@@ -248,10 +248,74 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\src\switch_core_asr.c"
+				>
+			</File>
+			<File
+				RelativePath="..\..\src\switch_core_codec.c"
+				>
+			</File>
+			<File
 				RelativePath="..\..\src\switch_core_db.c"
 				>
 			</File>
 			<File
+				RelativePath="..\..\src\switch_core_directory.c"
+				>
+			</File>
+			<File
+				RelativePath="..\..\src\switch_core_event_hook.c"
+				>
+			</File>
+			<File
+				RelativePath="..\..\src\switch_core_file.c"
+				>
+			</File>
+			<File
+				RelativePath="..\..\src\switch_core_hash.c"
+				>
+			</File>
+			<File
+				RelativePath="..\..\src\switch_core_io.c"
+				>
+			</File>
+			<File
+				RelativePath="..\..\src\switch_core_media_bug.c"
+				>
+			</File>
+			<File
+				RelativePath="..\..\src\switch_core_memory.c"
+				>
+			</File>
+			<File
+				RelativePath="..\..\src\switch_core_port_allocator.c"
+				>
+			</File>
+			<File
+				RelativePath="..\..\src\switch_core_rwlock.c"
+				>
+			</File>
+			<File
+				RelativePath="..\..\src\switch_core_session.c"
+				>
+			</File>
+			<File
+				RelativePath="..\..\src\switch_core_speech.c"
+				>
+			</File>
+			<File
+				RelativePath="..\..\src\switch_core_sqldb.c"
+				>
+			</File>
+			<File
+				RelativePath="..\..\src\switch_core_state_machine.c"
+				>
+			</File>
+			<File
+				RelativePath="..\..\src\switch_core_timer.c"
+				>
+			</File>
+			<File
 				RelativePath="..\..\src\switch_event.c"
 				>
 			</File>
@@ -260,6 +324,26 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\src\switch_ivr_async.c"
+				>
+			</File>
+			<File
+				RelativePath="..\..\src\switch_ivr_bridge.c"
+				>
+			</File>
+			<File
+				RelativePath="..\..\src\switch_ivr_menu.c"
+				>
+			</File>
+			<File
+				RelativePath="..\..\src\switch_ivr_originate.c"
+				>
+			</File>
+			<File
+				RelativePath="..\..\src\switch_ivr_play_say.c"
+				>
+			</File>
+			<File
 				RelativePath="..\..\src\switch_loadable_module.c"
 				>
 			</File>
@@ -280,6 +364,10 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\src\switch_scheduler.c"
+				>
+			</File>
+			<File
 				RelativePath="..\..\src\switch_stun.c"
 				>
 			</File>
@@ -306,6 +394,10 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\src\include\switch_bitpack.h"
+				>
+			</File>
+			<File
 				RelativePath="..\..\src\include\switch_buffer.h"
 				>
 			</File>
@@ -318,6 +410,10 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\src\include\switch_config.h"
+				>
+			</File>
+			<File
 				RelativePath="..\..\src\include\switch_console.h"
 				>
 			</File>
@@ -326,10 +422,18 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\src\include\private\switch_core.h"
+				>
+			</File>
+			<File
 				RelativePath="..\..\src\include\switch_core_db.h"
 				>
 			</File>
 			<File
+				RelativePath="..\..\src\include\switch_core_event_hook.h"
+				>
+			</File>
+			<File
 				RelativePath="..\..\src\include\switch_event.h"
 				>
 			</File>
@@ -370,6 +474,14 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\src\include\switch_scheduler.h"
+				>
+			</File>
+			<File
+				RelativePath="..\..\src\include\switch_sqlite.h"
+				>
+			</File>
+			<File
 				RelativePath="..\..\src\include\switch_stun.h"
 				>
 			</File>
@@ -382,6 +494,10 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\src\include\switch_version.h"
+				>
+			</File>
+			<File
 				RelativePath="..\..\src\include\switch_xml.h"
 				>
 			</File>



More information about the Freeswitch-branches mailing list