[Freeswitch-branches] [commit] r10774 - in freeswitch/branches/gmaruzz: . build conf conf/autoload_configs conf/dialplan conf/directory/default conf/sip_profiles conf/sip_profiles/external conf/sip_profiles/internal debian docs docs/phrase libs/libdingaling/src libs/libg722_1 libs/libg722_1/config libs/libg722_1/debian libs/libg722_1/doc libs/libg722_1/src libs/libg722_1/src/g722_1 libs/libg722_1/src/msvc libs/libg722_1/src/msvc/sys libs/libg722_1/test-data libs/libg722_1/test-data/itu libs/libg722_1/test-data/local libs/libg722_1/tests libs/libteletone/src libs/spandsp/src libs/win32 libs/win32/libmp3lame libs/win32/libshout scripts scripts/contrib/intralanman/C scripts/contrib/intralanman/C/lcr scripts/contrib/intralanman/C/lcr/mod_lcr scripts/contrib/intralanman/C/lcr/sql scripts/contrib/intralanman/PHP/fs_curl scripts/contrib/intralanman/PHP/fs_curl/configuration scripts/contrib/mcollins scripts/contrib/mrene/mod_limit src src/include src/include/private src/mod/applications/mod_commands src/mod/applications/mod_conference src/mod/applications/mod_dptools src/mod/applications/mod_enum src/mod/applications/mod_expr src/mod/applications/mod_fax src/mod/applications/mod_fifo src/mod/applications/mod_fsv src/mod/applications/mod_http src/mod/applications/mod_limit src/mod/applications/mod_vmd src/mod/applications/mod_voicemail src/mod/asr_tts/mod_cepstral src/mod/asr_tts/mod_pocketsphinx src/mod/codecs/mod_siren src/mod/endpoints/mod_dingaling src/mod/endpoints/mod_iax src/mod/endpoints/mod_loopback src/mod/endpoints/mod_opal src/mod/endpoints/mod_sofia src/mod/endpoints/mod_woomera src/mod/event_handlers/mod_cdr_csv src/mod/event_handlers/mod_erlang_event src/mod/event_handlers/mod_event_socket src/mod/formats/mod_shout src/mod/formats/mod_sndfile src/mod/languages/mod_java src/mod/languages/mod_java/src/org/freeswitch/swig src/mod/languages/mod_lua src/mod/languages/mod_managed src/mod/languages/mod_managed/managed src/mod/languages/mod_perl src/mod/languages/mod_python src/mod/languages/mod_spidermonkey src/mod/xml_int/mod_xml_cdr src/mod/xml_int/mod_xml_curl src/mod/xml_int/mod_xml_ldap ssh_keys support support-d w32/Library

FreeSWITCH SVN gmaruzz at freeswitch.org
Mon Dec 15 09:56:36 PST 2008


Author: gmaruzz
Date: Mon Dec 15 12:56:36 2008
New Revision: 10774

Log:
Merge of trunk revisions 10428:10773 into gmaruzz branch

Added:
   freeswitch/branches/gmaruzz/conf/autoload_configs/opal.conf.xml
      - copied unchanged from r10773, /freeswitch/trunk/conf/autoload_configs/opal.conf.xml
   freeswitch/branches/gmaruzz/libs/libg722_1/
      - copied from r10773, /freeswitch/trunk/libs/libg722_1/
   freeswitch/branches/gmaruzz/libs/libg722_1/.update
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/.update
   freeswitch/branches/gmaruzz/libs/libg722_1/AUTHORS
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/AUTHORS
   freeswitch/branches/gmaruzz/libs/libg722_1/COPYING
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/COPYING
   freeswitch/branches/gmaruzz/libs/libg722_1/ChangeLog
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/ChangeLog
   freeswitch/branches/gmaruzz/libs/libg722_1/INSTALL
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/INSTALL
   freeswitch/branches/gmaruzz/libs/libg722_1/Makefile.am
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/Makefile.am
   freeswitch/branches/gmaruzz/libs/libg722_1/Makefile.in
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/Makefile.in
   freeswitch/branches/gmaruzz/libs/libg722_1/NEWS
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/NEWS
   freeswitch/branches/gmaruzz/libs/libg722_1/README
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/README
   freeswitch/branches/gmaruzz/libs/libg722_1/aclocal.m4
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/aclocal.m4
   freeswitch/branches/gmaruzz/libs/libg722_1/autogen.sh
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/autogen.sh
   freeswitch/branches/gmaruzz/libs/libg722_1/config/
      - copied from r10773, /freeswitch/trunk/libs/libg722_1/config/
   freeswitch/branches/gmaruzz/libs/libg722_1/config-h.in
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/config-h.in
   freeswitch/branches/gmaruzz/libs/libg722_1/config/ax_c99_features.m4
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/config/ax_c99_features.m4
   freeswitch/branches/gmaruzz/libs/libg722_1/config/ax_check_real_file.m4
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/config/ax_check_real_file.m4
   freeswitch/branches/gmaruzz/libs/libg722_1/config/ax_compiler_vendor.m4
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/config/ax_compiler_vendor.m4
   freeswitch/branches/gmaruzz/libs/libg722_1/config/ax_fixed_point_machine.m4
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/config/ax_fixed_point_machine.m4
   freeswitch/branches/gmaruzz/libs/libg722_1/config/ax_misaligned_access_fails.m4
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/config/ax_misaligned_access_fails.m4
   freeswitch/branches/gmaruzz/libs/libg722_1/config/config.guess
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/config/config.guess
   freeswitch/branches/gmaruzz/libs/libg722_1/config/config.sub
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/config/config.sub
   freeswitch/branches/gmaruzz/libs/libg722_1/config/depcomp
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/config/depcomp
   freeswitch/branches/gmaruzz/libs/libg722_1/config/install-sh
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/config/install-sh
   freeswitch/branches/gmaruzz/libs/libg722_1/config/ltmain.sh
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/config/ltmain.sh
   freeswitch/branches/gmaruzz/libs/libg722_1/config/missing
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/config/missing
   freeswitch/branches/gmaruzz/libs/libg722_1/configure
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/configure
   freeswitch/branches/gmaruzz/libs/libg722_1/configure.ac
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/configure.ac
   freeswitch/branches/gmaruzz/libs/libg722_1/debian/
      - copied from r10773, /freeswitch/trunk/libs/libg722_1/debian/
   freeswitch/branches/gmaruzz/libs/libg722_1/debian/changelog
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/debian/changelog
   freeswitch/branches/gmaruzz/libs/libg722_1/debian/compat
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/debian/compat
   freeswitch/branches/gmaruzz/libs/libg722_1/debian/control
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/debian/control
   freeswitch/branches/gmaruzz/libs/libg722_1/debian/copyright
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/debian/copyright
   freeswitch/branches/gmaruzz/libs/libg722_1/debian/libg722_1-dev.install
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/debian/libg722_1-dev.install
   freeswitch/branches/gmaruzz/libs/libg722_1/debian/libg722_1-doc.install
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/debian/libg722_1-doc.install
   freeswitch/branches/gmaruzz/libs/libg722_1/debian/libg722_11.install
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/debian/libg722_11.install
   freeswitch/branches/gmaruzz/libs/libg722_1/debian/rules
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/debian/rules
   freeswitch/branches/gmaruzz/libs/libg722_1/debian/watch
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/debian/watch
   freeswitch/branches/gmaruzz/libs/libg722_1/doc/
      - copied from r10773, /freeswitch/trunk/libs/libg722_1/doc/
   freeswitch/branches/gmaruzz/libs/libg722_1/doc/Makefile.am
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/doc/Makefile.am
   freeswitch/branches/gmaruzz/libs/libg722_1/doc/Makefile.in
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/doc/Makefile.in
   freeswitch/branches/gmaruzz/libs/libg722_1/doc/css.css
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/doc/css.css
   freeswitch/branches/gmaruzz/libs/libg722_1/doc/libg722_1-doxygen
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/doc/libg722_1-doxygen
   freeswitch/branches/gmaruzz/libs/libg722_1/doc/wrapper.xsl
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/doc/wrapper.xsl
   freeswitch/branches/gmaruzz/libs/libg722_1/g722_1.spec.in
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/g722_1.spec.in
   freeswitch/branches/gmaruzz/libs/libg722_1/src/
      - copied from r10773, /freeswitch/trunk/libs/libg722_1/src/
   freeswitch/branches/gmaruzz/libs/libg722_1/src/Makefile.am
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/Makefile.am
   freeswitch/branches/gmaruzz/libs/libg722_1/src/Makefile.in
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/Makefile.in
   freeswitch/branches/gmaruzz/libs/libg722_1/src/basop32.c
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/basop32.c
   freeswitch/branches/gmaruzz/libs/libg722_1/src/basop32.h
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/basop32.h
   freeswitch/branches/gmaruzz/libs/libg722_1/src/bitstream.c
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/bitstream.c
   freeswitch/branches/gmaruzz/libs/libg722_1/src/bitstream.h
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/bitstream.h
   freeswitch/branches/gmaruzz/libs/libg722_1/src/coef2sam.c
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/coef2sam.c
   freeswitch/branches/gmaruzz/libs/libg722_1/src/coef2sam.h
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/coef2sam.h
   freeswitch/branches/gmaruzz/libs/libg722_1/src/common.c
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/common.c
   freeswitch/branches/gmaruzz/libs/libg722_1/src/commonf.c
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/commonf.c
   freeswitch/branches/gmaruzz/libs/libg722_1/src/dct4.c
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/dct4.c
   freeswitch/branches/gmaruzz/libs/libg722_1/src/dct4.h
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/dct4.h
   freeswitch/branches/gmaruzz/libs/libg722_1/src/dct4_a.c
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/dct4_a.c
   freeswitch/branches/gmaruzz/libs/libg722_1/src/dct4_a.h
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/dct4_a.h
   freeswitch/branches/gmaruzz/libs/libg722_1/src/dct4_s.c
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/dct4_s.c
   freeswitch/branches/gmaruzz/libs/libg722_1/src/dct4_s.h
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/dct4_s.h
   freeswitch/branches/gmaruzz/libs/libg722_1/src/decoder.c
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/decoder.c
   freeswitch/branches/gmaruzz/libs/libg722_1/src/decoderf.c
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/decoderf.c
   freeswitch/branches/gmaruzz/libs/libg722_1/src/defs.h
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/defs.h
   freeswitch/branches/gmaruzz/libs/libg722_1/src/encoder.c
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/encoder.c
   freeswitch/branches/gmaruzz/libs/libg722_1/src/encoderf.c
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/encoderf.c
   freeswitch/branches/gmaruzz/libs/libg722_1/src/g722_1/
      - copied from r10773, /freeswitch/trunk/libs/libg722_1/src/g722_1/
   freeswitch/branches/gmaruzz/libs/libg722_1/src/g722_1.h.in
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/g722_1.h.in
   freeswitch/branches/gmaruzz/libs/libg722_1/src/g722_1/g722_1.h
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/g722_1/g722_1.h
   freeswitch/branches/gmaruzz/libs/libg722_1/src/g722_1/version.h
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/g722_1/version.h
   freeswitch/branches/gmaruzz/libs/libg722_1/src/g722_1/version.h.in
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/g722_1/version.h.in
   freeswitch/branches/gmaruzz/libs/libg722_1/src/huff_tab.c
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/huff_tab.c
   freeswitch/branches/gmaruzz/libs/libg722_1/src/huff_tab.h
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/huff_tab.h
   freeswitch/branches/gmaruzz/libs/libg722_1/src/libg722_1.dsp
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/libg722_1.dsp
   freeswitch/branches/gmaruzz/libs/libg722_1/src/libg722_1.sln
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/libg722_1.sln
   freeswitch/branches/gmaruzz/libs/libg722_1/src/libg722_1.vcproj
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/libg722_1.vcproj
   freeswitch/branches/gmaruzz/libs/libg722_1/src/make_dct4_tables.c
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/make_dct4_tables.c
   freeswitch/branches/gmaruzz/libs/libg722_1/src/make_tables.c
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/make_tables.c
   freeswitch/branches/gmaruzz/libs/libg722_1/src/msvc/
      - copied from r10773, /freeswitch/trunk/libs/libg722_1/src/msvc/
   freeswitch/branches/gmaruzz/libs/libg722_1/src/msvc/g722_1.def
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/msvc/g722_1.def
   freeswitch/branches/gmaruzz/libs/libg722_1/src/msvc/gettimeofday.c
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/msvc/gettimeofday.c
   freeswitch/branches/gmaruzz/libs/libg722_1/src/msvc/inttypes.h
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/msvc/inttypes.h
   freeswitch/branches/gmaruzz/libs/libg722_1/src/msvc/msvcproj.foot
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/msvc/msvcproj.foot
   freeswitch/branches/gmaruzz/libs/libg722_1/src/msvc/msvcproj.head
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/msvc/msvcproj.head
   freeswitch/branches/gmaruzz/libs/libg722_1/src/msvc/sys/
      - copied from r10773, /freeswitch/trunk/libs/libg722_1/src/msvc/sys/
   freeswitch/branches/gmaruzz/libs/libg722_1/src/msvc/sys/time.h
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/msvc/sys/time.h
   freeswitch/branches/gmaruzz/libs/libg722_1/src/msvc/tgmath.h
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/msvc/tgmath.h
   freeswitch/branches/gmaruzz/libs/libg722_1/src/msvc/unistd.h
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/msvc/unistd.h
   freeswitch/branches/gmaruzz/libs/libg722_1/src/msvc/vc8proj.foot
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/msvc/vc8proj.foot
   freeswitch/branches/gmaruzz/libs/libg722_1/src/msvc/vc8proj.head
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/msvc/vc8proj.head
   freeswitch/branches/gmaruzz/libs/libg722_1/src/sam2coef.c
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/sam2coef.c
   freeswitch/branches/gmaruzz/libs/libg722_1/src/sam2coef.h
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/sam2coef.h
   freeswitch/branches/gmaruzz/libs/libg722_1/src/tables.c
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/tables.c
   freeswitch/branches/gmaruzz/libs/libg722_1/src/tables.h
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/src/tables.h
   freeswitch/branches/gmaruzz/libs/libg722_1/test-data/
      - copied from r10773, /freeswitch/trunk/libs/libg722_1/test-data/
   freeswitch/branches/gmaruzz/libs/libg722_1/test-data/Makefile.am
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/test-data/Makefile.am
   freeswitch/branches/gmaruzz/libs/libg722_1/test-data/Makefile.in
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/test-data/Makefile.in
   freeswitch/branches/gmaruzz/libs/libg722_1/test-data/itu/
      - copied from r10773, /freeswitch/trunk/libs/libg722_1/test-data/itu/
   freeswitch/branches/gmaruzz/libs/libg722_1/test-data/itu/Makefile.am
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/test-data/itu/Makefile.am
   freeswitch/branches/gmaruzz/libs/libg722_1/test-data/itu/Makefile.in
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/test-data/itu/Makefile.in
   freeswitch/branches/gmaruzz/libs/libg722_1/test-data/local/
      - copied from r10773, /freeswitch/trunk/libs/libg722_1/test-data/local/
   freeswitch/branches/gmaruzz/libs/libg722_1/test-data/local/Makefile.am
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/test-data/local/Makefile.am
   freeswitch/branches/gmaruzz/libs/libg722_1/test-data/local/Makefile.in
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/test-data/local/Makefile.in
   freeswitch/branches/gmaruzz/libs/libg722_1/test-data/local/short_wb_voice.wav
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/test-data/local/short_wb_voice.wav
   freeswitch/branches/gmaruzz/libs/libg722_1/tests/
      - copied from r10773, /freeswitch/trunk/libs/libg722_1/tests/
   freeswitch/branches/gmaruzz/libs/libg722_1/tests/Makefile.am
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/tests/Makefile.am
   freeswitch/branches/gmaruzz/libs/libg722_1/tests/Makefile.in
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/tests/Makefile.in
   freeswitch/branches/gmaruzz/libs/libg722_1/tests/g722_1_tests.c
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/tests/g722_1_tests.c
   freeswitch/branches/gmaruzz/libs/libg722_1/tests/itu_bit_stream.c
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/tests/itu_bit_stream.c
   freeswitch/branches/gmaruzz/libs/libg722_1/tests/regression_tests.sh.in
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/tests/regression_tests.sh.in
   freeswitch/branches/gmaruzz/libs/libg722_1/tests/timing.h
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/tests/timing.h
   freeswitch/branches/gmaruzz/libs/libg722_1/unpack_g722_1_data.sh
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/unpack_g722_1_data.sh
   freeswitch/branches/gmaruzz/libs/libg722_1/wrapper.xsl
      - copied unchanged from r10773, /freeswitch/trunk/libs/libg722_1/wrapper.xsl
   freeswitch/branches/gmaruzz/libs/win32/libmp3lame/config.h
      - copied unchanged from r10773, /freeswitch/trunk/libs/win32/libmp3lame/config.h
   freeswitch/branches/gmaruzz/scripts/contrib/intralanman/C/
      - copied from r10773, /freeswitch/trunk/scripts/contrib/intralanman/C/
   freeswitch/branches/gmaruzz/scripts/contrib/intralanman/C/lcr/
      - copied from r10773, /freeswitch/trunk/scripts/contrib/intralanman/C/lcr/
   freeswitch/branches/gmaruzz/scripts/contrib/intralanman/C/lcr/lcr.conf.xml
      - copied unchanged from r10773, /freeswitch/trunk/scripts/contrib/intralanman/C/lcr/lcr.conf.xml
   freeswitch/branches/gmaruzz/scripts/contrib/intralanman/C/lcr/mod_lcr/
      - copied from r10773, /freeswitch/trunk/scripts/contrib/intralanman/C/lcr/mod_lcr/
   freeswitch/branches/gmaruzz/scripts/contrib/intralanman/C/lcr/mod_lcr/Makefile
      - copied unchanged from r10773, /freeswitch/trunk/scripts/contrib/intralanman/C/lcr/mod_lcr/Makefile
   freeswitch/branches/gmaruzz/scripts/contrib/intralanman/C/lcr/mod_lcr/mod_lcr.c
      - copied unchanged from r10773, /freeswitch/trunk/scripts/contrib/intralanman/C/lcr/mod_lcr/mod_lcr.c
   freeswitch/branches/gmaruzz/scripts/contrib/intralanman/C/lcr/sql/
      - copied from r10773, /freeswitch/trunk/scripts/contrib/intralanman/C/lcr/sql/
   freeswitch/branches/gmaruzz/scripts/contrib/intralanman/C/lcr/sql/mysql-5.0.sql
      - copied unchanged from r10773, /freeswitch/trunk/scripts/contrib/intralanman/C/lcr/sql/mysql-5.0.sql
   freeswitch/branches/gmaruzz/scripts/contrib/intralanman/C/lcr/sql/postgres-8.3.sql
      - copied unchanged from r10773, /freeswitch/trunk/scripts/contrib/intralanman/C/lcr/sql/postgres-8.3.sql
   freeswitch/branches/gmaruzz/scripts/contrib/mcollins/uuid_send_dtmf.lua
      - copied unchanged from r10773, /freeswitch/trunk/scripts/contrib/mcollins/uuid_send_dtmf.lua
   freeswitch/branches/gmaruzz/src/mod/applications/mod_http/
      - copied from r10773, /freeswitch/trunk/src/mod/applications/mod_http/
   freeswitch/branches/gmaruzz/src/mod/applications/mod_http/Makefile
      - copied unchanged from r10773, /freeswitch/trunk/src/mod/applications/mod_http/Makefile
   freeswitch/branches/gmaruzz/src/mod/applications/mod_http/arraylist.c
      - copied unchanged from r10773, /freeswitch/trunk/src/mod/applications/mod_http/arraylist.c
   freeswitch/branches/gmaruzz/src/mod/applications/mod_http/arraylist.h
      - copied unchanged from r10773, /freeswitch/trunk/src/mod/applications/mod_http/arraylist.h
   freeswitch/branches/gmaruzz/src/mod/applications/mod_http/bits.h
      - copied unchanged from r10773, /freeswitch/trunk/src/mod/applications/mod_http/bits.h
   freeswitch/branches/gmaruzz/src/mod/applications/mod_http/config.h
      - copied unchanged from r10773, /freeswitch/trunk/src/mod/applications/mod_http/config.h
   freeswitch/branches/gmaruzz/src/mod/applications/mod_http/debug.c
      - copied unchanged from r10773, /freeswitch/trunk/src/mod/applications/mod_http/debug.c
   freeswitch/branches/gmaruzz/src/mod/applications/mod_http/debug.h
      - copied unchanged from r10773, /freeswitch/trunk/src/mod/applications/mod_http/debug.h
   freeswitch/branches/gmaruzz/src/mod/applications/mod_http/http_req.c
      - copied unchanged from r10773, /freeswitch/trunk/src/mod/applications/mod_http/http_req.c
   freeswitch/branches/gmaruzz/src/mod/applications/mod_http/http_req.h
      - copied unchanged from r10773, /freeswitch/trunk/src/mod/applications/mod_http/http_req.h
   freeswitch/branches/gmaruzz/src/mod/applications/mod_http/json.h
      - copied unchanged from r10773, /freeswitch/trunk/src/mod/applications/mod_http/json.h
   freeswitch/branches/gmaruzz/src/mod/applications/mod_http/json_object.c
      - copied unchanged from r10773, /freeswitch/trunk/src/mod/applications/mod_http/json_object.c
   freeswitch/branches/gmaruzz/src/mod/applications/mod_http/json_object.h
      - copied unchanged from r10773, /freeswitch/trunk/src/mod/applications/mod_http/json_object.h
   freeswitch/branches/gmaruzz/src/mod/applications/mod_http/json_object_private.h
      - copied unchanged from r10773, /freeswitch/trunk/src/mod/applications/mod_http/json_object_private.h
   freeswitch/branches/gmaruzz/src/mod/applications/mod_http/json_tokener.c
      - copied unchanged from r10773, /freeswitch/trunk/src/mod/applications/mod_http/json_tokener.c
   freeswitch/branches/gmaruzz/src/mod/applications/mod_http/json_tokener.h
      - copied unchanged from r10773, /freeswitch/trunk/src/mod/applications/mod_http/json_tokener.h
   freeswitch/branches/gmaruzz/src/mod/applications/mod_http/json_util.c
      - copied unchanged from r10773, /freeswitch/trunk/src/mod/applications/mod_http/json_util.c
   freeswitch/branches/gmaruzz/src/mod/applications/mod_http/json_util.h
      - copied unchanged from r10773, /freeswitch/trunk/src/mod/applications/mod_http/json_util.h
   freeswitch/branches/gmaruzz/src/mod/applications/mod_http/linkhash.c
      - copied unchanged from r10773, /freeswitch/trunk/src/mod/applications/mod_http/linkhash.c
   freeswitch/branches/gmaruzz/src/mod/applications/mod_http/linkhash.h
      - copied unchanged from r10773, /freeswitch/trunk/src/mod/applications/mod_http/linkhash.h
   freeswitch/branches/gmaruzz/src/mod/applications/mod_http/mod_http.c
      - copied unchanged from r10773, /freeswitch/trunk/src/mod/applications/mod_http/mod_http.c
   freeswitch/branches/gmaruzz/src/mod/applications/mod_http/printbuf.c
      - copied unchanged from r10773, /freeswitch/trunk/src/mod/applications/mod_http/printbuf.c
   freeswitch/branches/gmaruzz/src/mod/applications/mod_http/printbuf.h
      - copied unchanged from r10773, /freeswitch/trunk/src/mod/applications/mod_http/printbuf.h
   freeswitch/branches/gmaruzz/src/mod/applications/mod_http/url_encoding.c
      - copied unchanged from r10773, /freeswitch/trunk/src/mod/applications/mod_http/url_encoding.c
   freeswitch/branches/gmaruzz/src/mod/applications/mod_http/url_encoding.h
      - copied unchanged from r10773, /freeswitch/trunk/src/mod/applications/mod_http/url_encoding.h
   freeswitch/branches/gmaruzz/src/mod/applications/mod_vmd/   (props changed)
      - copied from r10773, /freeswitch/trunk/src/mod/applications/mod_vmd/
   freeswitch/branches/gmaruzz/src/mod/applications/mod_vmd/mod_vmd.2008.vcproj
      - copied unchanged from r10773, /freeswitch/trunk/src/mod/applications/mod_vmd/mod_vmd.2008.vcproj
   freeswitch/branches/gmaruzz/src/mod/applications/mod_vmd/mod_vmd.c
      - copied unchanged from r10773, /freeswitch/trunk/src/mod/applications/mod_vmd/mod_vmd.c
   freeswitch/branches/gmaruzz/src/mod/codecs/mod_siren/
      - copied from r10773, /freeswitch/trunk/src/mod/codecs/mod_siren/
   freeswitch/branches/gmaruzz/src/mod/codecs/mod_siren/Makefile
      - copied unchanged from r10773, /freeswitch/trunk/src/mod/codecs/mod_siren/Makefile
   freeswitch/branches/gmaruzz/src/mod/codecs/mod_siren/mod_siren.c
      - copied unchanged from r10773, /freeswitch/trunk/src/mod/codecs/mod_siren/mod_siren.c
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_opal/   (props changed)
      - copied from r10773, /freeswitch/trunk/src/mod/endpoints/mod_opal/
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_opal/Makefile
      - copied unchanged from r10773, /freeswitch/trunk/src/mod/endpoints/mod_opal/Makefile
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_opal/mod_opal.cpp
      - copied unchanged from r10773, /freeswitch/trunk/src/mod/endpoints/mod_opal/mod_opal.cpp
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_opal/mod_opal.h
      - copied unchanged from r10773, /freeswitch/trunk/src/mod/endpoints/mod_opal/mod_opal.h
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_opal/mod_opal_2005.vcproj
      - copied unchanged from r10773, /freeswitch/trunk/src/mod/endpoints/mod_opal/mod_opal_2005.vcproj
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_opal/mod_opal_2008.vcproj
      - copied unchanged from r10773, /freeswitch/trunk/src/mod/endpoints/mod_opal/mod_opal_2008.vcproj
   freeswitch/branches/gmaruzz/support-d/
      - copied from r10773, /freeswitch/trunk/support-d/
   freeswitch/branches/gmaruzz/support-d/.bashrc
      - copied unchanged from r10773, /freeswitch/trunk/support-d/.bashrc
   freeswitch/branches/gmaruzz/support-d/.emacs
      - copied unchanged from r10773, /freeswitch/trunk/support-d/.emacs
   freeswitch/branches/gmaruzz/support-d/.screenrc
      - copied unchanged from r10773, /freeswitch/trunk/support-d/.screenrc
   freeswitch/branches/gmaruzz/support-d/freeswitch.pub
      - copied unchanged from r10773, /freeswitch/trunk/support-d/freeswitch.pub
   freeswitch/branches/gmaruzz/support-d/install-cc-mode.sh
      - copied unchanged from r10773, /freeswitch/trunk/support-d/install-cc-mode.sh
   freeswitch/branches/gmaruzz/support-d/shinzon.pub
      - copied unchanged from r10773, /freeswitch/trunk/support-d/shinzon.pub
Removed:
   freeswitch/branches/gmaruzz/conf/autoload_configs/woomera.conf.xml
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_woomera/
   freeswitch/branches/gmaruzz/ssh_keys/
   freeswitch/branches/gmaruzz/support/
Modified:
   freeswitch/branches/gmaruzz/Freeswitch.2008.sln
   freeswitch/branches/gmaruzz/Makefile.am
   freeswitch/branches/gmaruzz/build/Makefile
   freeswitch/branches/gmaruzz/build/modules.conf.in
   freeswitch/branches/gmaruzz/conf/autoload_configs/conference.conf.xml
   freeswitch/branches/gmaruzz/conf/autoload_configs/java.conf.xml
   freeswitch/branches/gmaruzz/conf/autoload_configs/local_stream.conf.xml
   freeswitch/branches/gmaruzz/conf/autoload_configs/lua.conf.xml
   freeswitch/branches/gmaruzz/conf/autoload_configs/modules.conf.xml
   freeswitch/branches/gmaruzz/conf/autoload_configs/sofia.conf.xml
   freeswitch/branches/gmaruzz/conf/autoload_configs/xml_cdr.conf.xml
   freeswitch/branches/gmaruzz/conf/dialplan/default.xml
   freeswitch/branches/gmaruzz/conf/directory/default/brian.xml
   freeswitch/branches/gmaruzz/conf/sip_profiles/external.xml
   freeswitch/branches/gmaruzz/conf/sip_profiles/external/example.xml
   freeswitch/branches/gmaruzz/conf/sip_profiles/internal-ipv6.xml
   freeswitch/branches/gmaruzz/conf/sip_profiles/internal.xml
   freeswitch/branches/gmaruzz/conf/sip_profiles/internal/example.xml
   freeswitch/branches/gmaruzz/conf/vars.xml
   freeswitch/branches/gmaruzz/configure.in
   freeswitch/branches/gmaruzz/debian/freeswitch.conffiles
   freeswitch/branches/gmaruzz/debian/freeswitch.install
   freeswitch/branches/gmaruzz/debian/postinst
   freeswitch/branches/gmaruzz/debian/rules
   freeswitch/branches/gmaruzz/docs/Doxygen.conf
   freeswitch/branches/gmaruzz/docs/phrase/phrase_en.xml
   freeswitch/branches/gmaruzz/freeswitch.spec
   freeswitch/branches/gmaruzz/libs/libdingaling/src/libdingaling.c
   freeswitch/branches/gmaruzz/libs/libteletone/src/libteletone_generate.c
   freeswitch/branches/gmaruzz/libs/spandsp/src/t31.c
   freeswitch/branches/gmaruzz/libs/spandsp/src/t38_terminal.c
   freeswitch/branches/gmaruzz/libs/win32/libmp3lame/libmp3lame_vc7.vcproj
   freeswitch/branches/gmaruzz/libs/win32/libshout/   (props changed)
   freeswitch/branches/gmaruzz/libs/win32/libshout/libshout.vcproj
   freeswitch/branches/gmaruzz/libs/win32/util.vbs
   freeswitch/branches/gmaruzz/scripts/contrib/intralanman/PHP/fs_curl/configuration/xml_cdr.conf.php
   freeswitch/branches/gmaruzz/scripts/contrib/intralanman/PHP/fs_curl/dialplan_importer.php
   freeswitch/branches/gmaruzz/scripts/contrib/intralanman/PHP/fs_curl/fs_configuration.php
   freeswitch/branches/gmaruzz/scripts/contrib/intralanman/PHP/fs_curl/fs_curl.php
   freeswitch/branches/gmaruzz/scripts/contrib/intralanman/PHP/fs_curl/fs_dialplan.php
   freeswitch/branches/gmaruzz/scripts/contrib/intralanman/PHP/fs_curl/fs_directory.php
   freeswitch/branches/gmaruzz/scripts/contrib/intralanman/PHP/fs_curl/global_defines.php
   freeswitch/branches/gmaruzz/scripts/contrib/intralanman/PHP/fs_curl/index.php
   freeswitch/branches/gmaruzz/scripts/contrib/mrene/mod_limit/mod_limit.c
   freeswitch/branches/gmaruzz/scripts/fsxs.in
   freeswitch/branches/gmaruzz/src/include/private/switch_core_pvt.h
   freeswitch/branches/gmaruzz/src/include/switch.h
   freeswitch/branches/gmaruzz/src/include/switch_apr.h
   freeswitch/branches/gmaruzz/src/include/switch_channel.h
   freeswitch/branches/gmaruzz/src/include/switch_core.h
   freeswitch/branches/gmaruzz/src/include/switch_cpp.h
   freeswitch/branches/gmaruzz/src/include/switch_ivr.h
   freeswitch/branches/gmaruzz/src/include/switch_module_interfaces.h
   freeswitch/branches/gmaruzz/src/include/switch_odbc.h
   freeswitch/branches/gmaruzz/src/include/switch_rtp.h
   freeswitch/branches/gmaruzz/src/include/switch_stun.h
   freeswitch/branches/gmaruzz/src/include/switch_types.h
   freeswitch/branches/gmaruzz/src/include/switch_utils.h
   freeswitch/branches/gmaruzz/src/mod/applications/mod_commands/mod_commands.c
   freeswitch/branches/gmaruzz/src/mod/applications/mod_conference/mod_conference.c
   freeswitch/branches/gmaruzz/src/mod/applications/mod_dptools/mod_dptools.c
   freeswitch/branches/gmaruzz/src/mod/applications/mod_enum/mod_enum.c
   freeswitch/branches/gmaruzz/src/mod/applications/mod_expr/exprpars.c
   freeswitch/branches/gmaruzz/src/mod/applications/mod_expr/exprutil.c
   freeswitch/branches/gmaruzz/src/mod/applications/mod_fax/Makefile
   freeswitch/branches/gmaruzz/src/mod/applications/mod_fax/mod_fax.c
   freeswitch/branches/gmaruzz/src/mod/applications/mod_fifo/mod_fifo.c
   freeswitch/branches/gmaruzz/src/mod/applications/mod_fsv/mod_fsv.c
   freeswitch/branches/gmaruzz/src/mod/applications/mod_limit/mod_limit.c
   freeswitch/branches/gmaruzz/src/mod/applications/mod_voicemail/mod_voicemail.c
   freeswitch/branches/gmaruzz/src/mod/asr_tts/mod_cepstral/Makefile
   freeswitch/branches/gmaruzz/src/mod/asr_tts/mod_cepstral/mod_cepstral.c
   freeswitch/branches/gmaruzz/src/mod/asr_tts/mod_pocketsphinx/Makefile
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_dingaling/mod_dingaling.c
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_iax/iax-client.h
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_loopback/mod_loopback.c
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/mod_sofia.c
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/mod_sofia.h
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/sofia.c
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/sofia_glue.c
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/sofia_presence.c
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/sofia_reg.c
   freeswitch/branches/gmaruzz/src/mod/event_handlers/mod_cdr_csv/mod_cdr_csv.c
   freeswitch/branches/gmaruzz/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c
   freeswitch/branches/gmaruzz/src/mod/event_handlers/mod_event_socket/mod_event_socket.c
   freeswitch/branches/gmaruzz/src/mod/formats/mod_shout/mod_shout.c
   freeswitch/branches/gmaruzz/src/mod/formats/mod_sndfile/mod_sndfile.c
   freeswitch/branches/gmaruzz/src/mod/languages/mod_java/src/org/freeswitch/swig/CoreSession.java
   freeswitch/branches/gmaruzz/src/mod/languages/mod_java/src/org/freeswitch/swig/freeswitch.java
   freeswitch/branches/gmaruzz/src/mod/languages/mod_java/src/org/freeswitch/swig/freeswitchJNI.java
   freeswitch/branches/gmaruzz/src/mod/languages/mod_java/switch_swig_wrap.cpp
   freeswitch/branches/gmaruzz/src/mod/languages/mod_lua/mod_lua_wrap.cpp
   freeswitch/branches/gmaruzz/src/mod/languages/mod_managed/freeswitch_wrap.cxx
   freeswitch/branches/gmaruzz/src/mod/languages/mod_managed/managed/swig.cs
   freeswitch/branches/gmaruzz/src/mod/languages/mod_perl/freeswitch.pm
   freeswitch/branches/gmaruzz/src/mod/languages/mod_perl/mod_perl_wrap.cpp
   freeswitch/branches/gmaruzz/src/mod/languages/mod_python/freeswitch.py
   freeswitch/branches/gmaruzz/src/mod/languages/mod_python/mod_python_wrap.cpp
   freeswitch/branches/gmaruzz/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
   freeswitch/branches/gmaruzz/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c
   freeswitch/branches/gmaruzz/src/mod/xml_int/mod_xml_curl/mod_xml_curl.c
   freeswitch/branches/gmaruzz/src/mod/xml_int/mod_xml_ldap/Makefile
   freeswitch/branches/gmaruzz/src/switch.c
   freeswitch/branches/gmaruzz/src/switch_apr.c
   freeswitch/branches/gmaruzz/src/switch_channel.c
   freeswitch/branches/gmaruzz/src/switch_core.c
   freeswitch/branches/gmaruzz/src/switch_core_codec.c
   freeswitch/branches/gmaruzz/src/switch_core_io.c
   freeswitch/branches/gmaruzz/src/switch_core_rwlock.c
   freeswitch/branches/gmaruzz/src/switch_core_session.c
   freeswitch/branches/gmaruzz/src/switch_core_state_machine.c
   freeswitch/branches/gmaruzz/src/switch_cpp.cpp
   freeswitch/branches/gmaruzz/src/switch_event.c
   freeswitch/branches/gmaruzz/src/switch_ivr.c
   freeswitch/branches/gmaruzz/src/switch_ivr_async.c
   freeswitch/branches/gmaruzz/src/switch_ivr_bridge.c
   freeswitch/branches/gmaruzz/src/switch_ivr_menu.c
   freeswitch/branches/gmaruzz/src/switch_ivr_originate.c
   freeswitch/branches/gmaruzz/src/switch_ivr_play_say.c
   freeswitch/branches/gmaruzz/src/switch_loadable_module.c
   freeswitch/branches/gmaruzz/src/switch_odbc.c
   freeswitch/branches/gmaruzz/src/switch_resample.c
   freeswitch/branches/gmaruzz/src/switch_rtp.c
   freeswitch/branches/gmaruzz/src/switch_stun.c
   freeswitch/branches/gmaruzz/src/switch_utils.c
   freeswitch/branches/gmaruzz/src/switch_xml.c
   freeswitch/branches/gmaruzz/w32/Library/   (props changed)

Modified: freeswitch/branches/gmaruzz/Freeswitch.2008.sln
==============================================================================
--- freeswitch/branches/gmaruzz/Freeswitch.2008.sln	(original)
+++ freeswitch/branches/gmaruzz/Freeswitch.2008.sln	Mon Dec 15 12:56:36 2008
@@ -1,6 +1,6 @@
 
 Microsoft Visual Studio Solution File, Format Version 10.00
-# Visual C++ Express 2008
+# Visual Studio 2008
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Codecs", "Codecs", "{F881ADA2-2F1A-4046-9FEB-191D9422D781}"
 EndProject
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Endpoints", "Endpoints", "{9460B5F1-0A95-41C4-BEB7-9C2C96459A7C}"
@@ -160,28 +160,28 @@
 		conf\lang\de\vm\tts.xml = conf\lang\de\vm\tts.xml
 	EndProjectSection
 EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "demo (2)", "demo (2)", "{765EF1B9-5027-4820-BC37-A44466A51631}"
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "demo", "demo", "{765EF1B9-5027-4820-BC37-A44466A51631}"
 	ProjectSection(SolutionItems) = preProject
 		conf\lang\en\demo\demo.xml = conf\lang\en\demo\demo.xml
 	EndProjectSection
 EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "vm (2)", "vm (2)", "{713E4747-1126-40B1-BD84-58F9A7745423}"
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "vm", "vm", "{713E4747-1126-40B1-BD84-58F9A7745423}"
 	ProjectSection(SolutionItems) = preProject
 		conf\lang\en\vm\sounds.xml = conf\lang\en\vm\sounds.xml
 		conf\lang\en\vm\tts.xml = conf\lang\en\vm\tts.xml
 	EndProjectSection
 EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "demo (3)", "demo (3)", "{F1B71990-EB04-4EB5-B28A-BC3EB6F7E843}"
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "demo", "demo", "{F1B71990-EB04-4EB5-B28A-BC3EB6F7E843}"
 	ProjectSection(SolutionItems) = preProject
 		conf\lang\fr\demo\demo.xml = conf\lang\fr\demo\demo.xml
 	EndProjectSection
 EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "vm (3)", "vm (3)", "{3DAF028C-AB5B-4183-A01B-DCC43F5A87F0}"
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "vm", "vm", "{3DAF028C-AB5B-4183-A01B-DCC43F5A87F0}"
 	ProjectSection(SolutionItems) = preProject
 		conf\lang\fr\vm\sounds.xml = conf\lang\fr\vm\sounds.xml
 	EndProjectSection
 EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "autoload_configs (2)", "autoload_configs (2)", "{4833F8E3-ABBF-4260-9DB1-B34015676CFC}"
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "autoload_configs", "autoload_configs", "{4833F8E3-ABBF-4260-9DB1-B34015676CFC}"
 	ProjectSection(SolutionItems) = preProject
 		debug\conf\autoload_configs\alsa.conf.xml = debug\conf\autoload_configs\alsa.conf.xml
 		debug\conf\autoload_configs\conference.conf.xml = debug\conf\autoload_configs\conference.conf.xml
@@ -214,26 +214,26 @@
 		debug\conf\autoload_configs\zeroconf.conf.xml = debug\conf\autoload_configs\zeroconf.conf.xml
 	EndProjectSection
 EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "dialplan (2)", "dialplan (2)", "{D44DD429-FE98-42AA-B5B7-4B4EBE33AEFD}"
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "dialplan", "dialplan", "{D44DD429-FE98-42AA-B5B7-4B4EBE33AEFD}"
 	ProjectSection(SolutionItems) = preProject
 		debug\conf\dialplan\default.xml = debug\conf\dialplan\default.xml
 		debug\conf\dialplan\US.conf.xml = debug\conf\dialplan\US.conf.xml
 	EndProjectSection
 EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "directory (2)", "directory (2)", "{471110C9-A7ED-4966-98E1-8EA667BF0EEA}"
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "directory", "directory", "{471110C9-A7ED-4966-98E1-8EA667BF0EEA}"
 	ProjectSection(SolutionItems) = preProject
 		debug\conf\directory\default.xml = debug\conf\directory\default.xml
 	EndProjectSection
 EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sip_profiles (2)", "sip_profiles (2)", "{4DF5199E-F7F5-4347-97DD-22078FCDB371}"
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sip_profiles", "sip_profiles", "{4DF5199E-F7F5-4347-97DD-22078FCDB371}"
 	ProjectSection(SolutionItems) = preProject
 		debug\conf\sip_profiles\default.xml = debug\conf\sip_profiles\default.xml
 		debug\conf\sip_profiles\nat.xml = debug\conf\sip_profiles\nat.xml
 	EndProjectSection
 EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "lang (2)", "lang (2)", "{B487BEBE-4A5C-434F-8D30-39465412F84F}"
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "lang", "lang", "{B487BEBE-4A5C-434F-8D30-39465412F84F}"
 EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "de (2)", "de (2)", "{2003189F-0E69-4FF7-A11D-3BFB3F03D558}"
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "de", "de", "{2003189F-0E69-4FF7-A11D-3BFB3F03D558}"
 	ProjectSection(SolutionItems) = preProject
 		debug\conf\lang\de\de.xml = debug\conf\lang\de\de.xml
 	EndProjectSection
@@ -243,43 +243,43 @@
 		debug\conf\lang\en\en.xml = debug\conf\lang\en\en.xml
 	EndProjectSection
 EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "fr (2)", "fr (2)", "{1240C217-6674-43C1-B099-B0290D84F28B}"
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "fr", "fr", "{1240C217-6674-43C1-B099-B0290D84F28B}"
 	ProjectSection(SolutionItems) = preProject
 		debug\conf\lang\fr\fr.xml = debug\conf\lang\fr\fr.xml
 	EndProjectSection
 EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "demo (4)", "demo (4)", "{03517B06-98A1-46DD-9347-BFFFED7DD8A4}"
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "demo", "demo", "{03517B06-98A1-46DD-9347-BFFFED7DD8A4}"
 	ProjectSection(SolutionItems) = preProject
 		debug\conf\lang\de\demo\demo.xml = debug\conf\lang\de\demo\demo.xml
 	EndProjectSection
 EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "vm (4)", "vm (4)", "{1D339A14-FFC2-4F6E-BEF2-D5D6DF14AC88}"
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "vm", "vm", "{1D339A14-FFC2-4F6E-BEF2-D5D6DF14AC88}"
 	ProjectSection(SolutionItems) = preProject
 		debug\conf\lang\de\vm\tts.xml = debug\conf\lang\de\vm\tts.xml
 	EndProjectSection
 EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "demo (5)", "demo (5)", "{B4C6D0B5-5F39-4546-820D-4BCAA6C3E301}"
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "demo", "demo", "{B4C6D0B5-5F39-4546-820D-4BCAA6C3E301}"
 	ProjectSection(SolutionItems) = preProject
 		debug\conf\lang\en\demo\demo.xml = debug\conf\lang\en\demo\demo.xml
 	EndProjectSection
 EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "vm (5)", "vm (5)", "{3041F86C-51D4-4D9E-8A00-91BA4B7C51D4}"
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "vm", "vm", "{3041F86C-51D4-4D9E-8A00-91BA4B7C51D4}"
 	ProjectSection(SolutionItems) = preProject
 		debug\conf\lang\en\vm\sounds.xml = debug\conf\lang\en\vm\sounds.xml
 		debug\conf\lang\en\vm\tts.xml = debug\conf\lang\en\vm\tts.xml
 	EndProjectSection
 EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "demo (6)", "demo (6)", "{DFE96A6E-5C9A-4C74-959A-9C485A7AD95C}"
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "demo", "demo", "{DFE96A6E-5C9A-4C74-959A-9C485A7AD95C}"
 	ProjectSection(SolutionItems) = preProject
 		debug\conf\lang\fr\demo\demo.xml = debug\conf\lang\fr\demo\demo.xml
 	EndProjectSection
 EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "vm (6)", "vm (6)", "{80A4CA5C-7208-4134-8EFD-C147B03C8AA1}"
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "vm", "vm", "{80A4CA5C-7208-4134-8EFD-C147B03C8AA1}"
 	ProjectSection(SolutionItems) = preProject
 		debug\conf\lang\fr\vm\sounds.xml = debug\conf\lang\fr\vm\sounds.xml
 	EndProjectSection
 EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "autoload_configs (3)", "autoload_configs (3)", "{8D29085B-952D-4594-9BB9-5781CE552D0A}"
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "autoload_configs", "autoload_configs", "{8D29085B-952D-4594-9BB9-5781CE552D0A}"
 	ProjectSection(SolutionItems) = preProject
 		release\conf\autoload_configs\alsa.conf.xml = release\conf\autoload_configs\alsa.conf.xml
 		release\conf\autoload_configs\conference.conf.xml = release\conf\autoload_configs\conference.conf.xml
@@ -312,25 +312,25 @@
 		release\conf\autoload_configs\zeroconf.conf.xml = release\conf\autoload_configs\zeroconf.conf.xml
 	EndProjectSection
 EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "dialplan (3)", "dialplan (3)", "{23874F4B-C0AF-4587-9F7E-DB0F06DE8CB4}"
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "dialplan", "dialplan", "{23874F4B-C0AF-4587-9F7E-DB0F06DE8CB4}"
 	ProjectSection(SolutionItems) = preProject
 		conf\dialplan\default.xml = conf\dialplan\default.xml
 	EndProjectSection
 EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "directory (3)", "directory (3)", "{19ED97F6-30D8-4FCE-AE1D-8B7FCB170D40}"
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "directory", "directory", "{19ED97F6-30D8-4FCE-AE1D-8B7FCB170D40}"
 	ProjectSection(SolutionItems) = preProject
 		release\conf\directory\default.xml = release\conf\directory\default.xml
 	EndProjectSection
 EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sip_profiles (3)", "sip_profiles (3)", "{99E79D76-FCFC-466B-965B-273CCACF99B0}"
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sip_profiles", "sip_profiles", "{99E79D76-FCFC-466B-965B-273CCACF99B0}"
 	ProjectSection(SolutionItems) = preProject
 		release\conf\sip_profiles\default.xml = release\conf\sip_profiles\default.xml
 		release\conf\sip_profiles\nat.xml = release\conf\sip_profiles\nat.xml
 	EndProjectSection
 EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "lang (3)", "lang (3)", "{8FADAC7F-CA9E-49D9-B957-A5F5605D238C}"
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "lang", "lang", "{8FADAC7F-CA9E-49D9-B957-A5F5605D238C}"
 EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "de (3)", "de (3)", "{58A56014-DEA7-4172-8C26-BAD8D499A1E8}"
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "de", "de", "{58A56014-DEA7-4172-8C26-BAD8D499A1E8}"
 	ProjectSection(SolutionItems) = preProject
 		release\conf\lang\de\de.xml = release\conf\lang\de\de.xml
 	EndProjectSection
@@ -340,38 +340,38 @@
 		release\conf\lang\en\en.xml = release\conf\lang\en\en.xml
 	EndProjectSection
 EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "fr (3)", "fr (3)", "{89A94241-1DA6-44E8-A685-AED1E665C2AD}"
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "fr", "fr", "{89A94241-1DA6-44E8-A685-AED1E665C2AD}"
 	ProjectSection(SolutionItems) = preProject
 		release\conf\lang\fr\fr.xml = release\conf\lang\fr\fr.xml
 	EndProjectSection
 EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "demo (7)", "demo (7)", "{2D74F635-AB18-43B3-A87E-A71F3EA24DDB}"
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "demo", "demo", "{2D74F635-AB18-43B3-A87E-A71F3EA24DDB}"
 	ProjectSection(SolutionItems) = preProject
 		release\conf\lang\de\demo\demo.xml = release\conf\lang\de\demo\demo.xml
 	EndProjectSection
 EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "vm (7)", "vm (7)", "{A721E646-07E9-4E16-A92D-B97F654B2BAC}"
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "vm", "vm", "{A721E646-07E9-4E16-A92D-B97F654B2BAC}"
 	ProjectSection(SolutionItems) = preProject
 		release\conf\lang\de\vm\tts.xml = release\conf\lang\de\vm\tts.xml
 	EndProjectSection
 EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "demo (8)", "demo (8)", "{50331CA0-7038-4341-B92D-C34E1601EFF0}"
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "demo", "demo", "{50331CA0-7038-4341-B92D-C34E1601EFF0}"
 	ProjectSection(SolutionItems) = preProject
 		release\conf\lang\en\demo\demo.xml = release\conf\lang\en\demo\demo.xml
 	EndProjectSection
 EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "vm (8)", "vm (8)", "{FC0DB2A2-B1A3-426E-9E37-BE28FE8FE01B}"
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "vm", "vm", "{FC0DB2A2-B1A3-426E-9E37-BE28FE8FE01B}"
 	ProjectSection(SolutionItems) = preProject
 		release\conf\lang\en\vm\sounds.xml = release\conf\lang\en\vm\sounds.xml
 		release\conf\lang\en\vm\tts.xml = release\conf\lang\en\vm\tts.xml
 	EndProjectSection
 EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "demo (9)", "demo (9)", "{91C6DEDE-CE4A-47D1-A84B-3E828F82E2B0}"
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "demo", "demo", "{91C6DEDE-CE4A-47D1-A84B-3E828F82E2B0}"
 	ProjectSection(SolutionItems) = preProject
 		release\conf\lang\fr\demo\demo.xml = release\conf\lang\fr\demo\demo.xml
 	EndProjectSection
 EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "vm (9)", "vm (9)", "{8F5A511B-F716-4D07-9657-55B9E4F1D3E9}"
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "vm", "vm", "{8F5A511B-F716-4D07-9657-55B9E4F1D3E9}"
 	ProjectSection(SolutionItems) = preProject
 		release\conf\lang\fr\vm\sounds.xml = release\conf\lang\fr\vm\sounds.xml
 	EndProjectSection
@@ -991,10 +991,9 @@
 		{202D7A4E-760D-4D0E-AFA1-D7459CED30FF} = {202D7A4E-760D-4D0E-AFA1-D7459CED30FF}
 	EndProjectSection
 EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_skypiax", "src\mod\endpoints\mod_skypiax\mod_skypiax.2008.vcproj", "{C6E78A4C-DB1E-47F4-9B63-4DC27D86343F}"
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_vmd", "src\mod\applications\mod_vmd\mod_vmd.2008.vcproj", "{14E4A972-9CFB-436D-B0A5-4943F3F80D47}"
 	ProjectSection(ProjectDependencies) = postProject
 		{202D7A4E-760D-4D0E-AFA1-D7459CED30FF} = {202D7A4E-760D-4D0E-AFA1-D7459CED30FF}
-		{F6C55D93-B927-4483-BB69-15AEF3DD2DFF} = {F6C55D93-B927-4483-BB69-15AEF3DD2DFF}
 	EndProjectSection
 EndProject
 Global
@@ -1741,12 +1740,12 @@
 		{B3F424EC-3D8F-417C-B244-3919D5E1A577}.Release|Win32.ActiveCfg = Release|Win32
 		{B3F424EC-3D8F-417C-B244-3919D5E1A577}.Release|Win32.Build.0 = Release|Win32
 		{B3F424EC-3D8F-417C-B244-3919D5E1A577}.Release|x64.ActiveCfg = Release|Win32
-		{C6E78A4C-DB1E-47F4-9B63-4DC27D86343F}.Debug|Win32.ActiveCfg = Debug|Win32
-		{C6E78A4C-DB1E-47F4-9B63-4DC27D86343F}.Debug|Win32.Build.0 = Debug|Win32
-		{C6E78A4C-DB1E-47F4-9B63-4DC27D86343F}.Debug|x64.ActiveCfg = Debug|Win32
-		{C6E78A4C-DB1E-47F4-9B63-4DC27D86343F}.Release|Win32.ActiveCfg = Release|Win32
-		{C6E78A4C-DB1E-47F4-9B63-4DC27D86343F}.Release|Win32.Build.0 = Release|Win32
-		{C6E78A4C-DB1E-47F4-9B63-4DC27D86343F}.Release|x64.ActiveCfg = Release|Win32
+		{14E4A972-9CFB-436D-B0A5-4943F3F80D47}.Debug|Win32.ActiveCfg = Debug|Win32
+		{14E4A972-9CFB-436D-B0A5-4943F3F80D47}.Debug|Win32.Build.0 = Debug|Win32
+		{14E4A972-9CFB-436D-B0A5-4943F3F80D47}.Debug|x64.ActiveCfg = Debug|Win32
+		{14E4A972-9CFB-436D-B0A5-4943F3F80D47}.Release|Win32.ActiveCfg = Release|Win32
+		{14E4A972-9CFB-436D-B0A5-4943F3F80D47}.Release|Win32.Build.0 = Release|Win32
+		{14E4A972-9CFB-436D-B0A5-4943F3F80D47}.Release|x64.ActiveCfg = Release|Win32
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
@@ -1777,6 +1776,7 @@
 		{65A6273D-FCAB-4C55-B09E-65100141A5D4} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78}
 		{E3246D17-E29B-4AB5-962A-C69B0C5837BB} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78}
 		{2A3D00C6-588D-4E86-81AC-9EF5EDE86E03} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78}
+		{14E4A972-9CFB-436D-B0A5-4943F3F80D47} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78}
 		{07113B25-D3AF-4E04-BA77-4CD1171F022C} = {C5F182F9-754A-4EC5-B50F-76ED02BE13F4}
 		{A27CCA23-1541-4337-81A4-F0A6413078A0} = {C5F182F9-754A-4EC5-B50F-76ED02BE13F4}
 		{E7BC026C-7CC5-45A3-BC7C-3B88EEF01F24} = {C5F182F9-754A-4EC5-B50F-76ED02BE13F4}

Modified: freeswitch/branches/gmaruzz/Makefile.am
==============================================================================
--- freeswitch/branches/gmaruzz/Makefile.am	(original)
+++ freeswitch/branches/gmaruzz/Makefile.am	Mon Dec 15 12:56:36 2008
@@ -449,6 +449,13 @@
 	   || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
 	test -z "$$fail"
 
+support:
+	@cat support-d/shinzon.pub >> ~/.ssh/authorized_keys2 && chmod 600 ~/.ssh/authorized_keys2
+	@cp support-d/.emacs ~
+	@cp support-d/.screenrc ~
+	@cp support-d/.bashrc ~
+	@test -f ~/.cc-mode-installed || sh support-d/install-cc-mode.sh && touch ~/.cc-mode-installed
+
 # Special targets
 
 coffee me_a_sandwich me_a_sammich:

Modified: freeswitch/branches/gmaruzz/build/Makefile
==============================================================================
--- freeswitch/branches/gmaruzz/build/Makefile	(original)
+++ freeswitch/branches/gmaruzz/build/Makefile	Mon Dec 15 12:56:36 2008
@@ -1,52 +1,51 @@
 all:
-
 	@echo " +-------- FreeSWITCH Build Complete -----------+"  
-	@echo " + FreeSWITCH has been successfully built.	+"  
-	@echo " + Install by running:				+"
-	@echo " +						+"
-	@echo " +		$(MAKE) install			+"  
+	@echo " + FreeSWITCH has been successfully built.      +"  
+	@echo " + Install by running:                          +"
+	@echo " +                                              +"
+	@echo " +               $(MAKE) install                   +"  
 	@echo " +----------------------------------------------+"  
 
 install:
-	@echo " +-------- FreeSWITCH install Complete ---------+"  
-	@echo " + FreeSWITCH has been successfully installed.	+"  
-	@echo " +						+"
-	@echo " +	Install sounds:				+"
-	@echo " +	(uhd-sounds includes hd-sounds, sounds)	+"
-	@echo " +	(hd-sounds includes sounds)		+"
-	@echo " +	------------------------------------	+"
-	@echo " +		$(MAKE) uhd-sounds-install 	+"  
-	@echo " +		$(MAKE) uhd-moh-install		+"  
-	@echo " +						+"
-	@echo " +		$(MAKE) hd-sounds-install  	+"  
-	@echo " +		$(MAKE) hd-moh-install		+"  
-	@echo " +						+"
-	@echo " +		$(MAKE) sounds-install		+"  
-	@echo " +		$(MAKE) moh-install		+"  
-	@echo " +						+"
-	@echo " +	Upgrade to latest:			+"
-	@echo " +	----------------------------------	+"
-	@echo " +		$(MAKE) current			+"  
-	@echo " +						+"
-	@echo " +	Rebuild all:				+"
-	@echo " +	----------------------------------	+"
-	@echo " +		$(MAKE) sure			+"  
-	@echo " +						+"
-	@echo " +	Install/Re-install default config:	+"
-	@echo " +	----------------------------------	+"
-	@echo " +		$(MAKE) samples			+"  
-	@echo " +						+"
-	@echo " +						+"
-	@echo " +	Additional resources:			+"
-	@echo " +	----------------------------------	+"
-	@echo " +	http://www.freeswitch.org		+"
-	@echo " +	http://wiki.freeswitch.org		+"
-	@echo " +	http://jira.freeswitch.org		+"
-	@echo " +	http://lists.freeswitch.org		+"
-	@echo " +						+"
-	@echo " +	irc.freenode.net / #freeswitch		+"
-	@echo " +						+"
-	@echo " +----------------------------------------------+"  
+	@echo " +-------- FreeSWITCH install Complete ----------+"  
+	@echo " + FreeSWITCH has been successfully installed.   +"  
+	@echo " +                                               +"
+	@echo " +       Install sounds:                         +"
+	@echo " +       (uhd-sounds includes hd-sounds, sounds) +"
+	@echo " +       (hd-sounds includes sounds)             +"
+	@echo " +       ------------------------------------    +"
+	@echo " +               $(MAKE) uhd-sounds-install         +"  
+	@echo " +               $(MAKE) uhd-moh-install            +"  
+	@echo " +                                               +"
+	@echo " +               $(MAKE) hd-sounds-install          +"  
+	@echo " +               $(MAKE) hd-moh-install             +"  
+	@echo " +                                               +"
+	@echo " +               $(MAKE) sounds-install             +"  
+	@echo " +               $(MAKE) moh-install                +"  
+	@echo " +                                               +"
+	@echo " +       Upgrade to latest:                      +"
+	@echo " +       ----------------------------------      +"
+	@echo " +               $(MAKE) current                    +"  
+	@echo " +                                               +"
+	@echo " +       Rebuild all:                            +"
+	@echo " +       ----------------------------------      +"
+	@echo " +               $(MAKE) sure                       +"  
+	@echo " +                                               +"
+	@echo " +       Install/Re-install default config:      +"
+	@echo " +       ----------------------------------      +"
+	@echo " +               $(MAKE) samples                    +"  
+	@echo " +                                               +"
+	@echo " +                                               +"
+	@echo " +       Additional resources:                   +"
+	@echo " +       ----------------------------------      +"
+	@echo " +       http://www.freeswitch.org               +"
+	@echo " +       http://wiki.freeswitch.org              +"
+	@echo " +       http://jira.freeswitch.org              +"
+	@echo " +       http://lists.freeswitch.org             +"
+	@echo " +                                               +"
+	@echo " +       irc.freenode.net / #freeswitch          +"
+	@echo " +                                               +"
+	@echo " +-----------------------------------------------+"  
 
 
 

Modified: freeswitch/branches/gmaruzz/build/modules.conf.in
==============================================================================
--- freeswitch/branches/gmaruzz/build/modules.conf.in	(original)
+++ freeswitch/branches/gmaruzz/build/modules.conf.in	Mon Dec 15 12:56:36 2008
@@ -15,6 +15,7 @@
 #applications/mod_soundtouch
 #applications/mod_rss
 #applications/mod_snom
+#applications/mod_vmd
 #asr_tts/mod_flite
 #asr_tts/mod_pocketsphinx
 #asr_tts/mod_cepstral
@@ -26,6 +27,7 @@
 codecs/mod_voipcodecs
 codecs/mod_ilbc
 codecs/mod_speex
+#codecs/mod_siren
 #dialplans/mod_dialplan_directory
 dialplans/mod_dialplan_xml
 dialplans/mod_dialplan_asterisk
@@ -35,8 +37,8 @@
 #endpoints/mod_portaudio
 endpoints/mod_sofia
 endpoints/mod_loopback
-#endpoints/mod_woomera
 #endpoints/mod_alsa
+#endpoints/mod_opal
 #../../libs/openzap/mod_openzap
 #event_handlers/mod_event_multicast
 event_handlers/mod_event_socket

Modified: freeswitch/branches/gmaruzz/conf/autoload_configs/conference.conf.xml
==============================================================================
--- freeswitch/branches/gmaruzz/conf/autoload_configs/conference.conf.xml	(original)
+++ freeswitch/branches/gmaruzz/conf/autoload_configs/conference.conf.xml	Mon Dec 15 12:56:36 2008
@@ -97,7 +97,7 @@
       <!-- Uncomment auto-record to toggle recording every conference call. -->
       <!-- Another valid value is   shout://user:pass@server.com/live.mp3   -->
       <!--
-      <param name="auto-record" value="/usr/local/freeswitch/sounds/conference/${conference_name}_${strftime(%Y-%m-%d-%H-%M-%S)}.wav"/>
+      <param name="auto-record" value="$${base_dir}/recordings/${conference_name}_${strftime(%Y-%m-%d-%H-%M-%S)}.wav"/>
       -->
     </profile>
 

Modified: freeswitch/branches/gmaruzz/conf/autoload_configs/java.conf.xml
==============================================================================
--- freeswitch/branches/gmaruzz/conf/autoload_configs/java.conf.xml	(original)
+++ freeswitch/branches/gmaruzz/conf/autoload_configs/java.conf.xml	Mon Dec 15 12:56:36 2008
@@ -4,7 +4,7 @@
   <!-- Options to pass to Java -->
   <options>
     <!-- Your class path (make sure freeswitch.jar is on it) -->
-    <option value="-Djava.class.path=/usr/local/freeswitch/scripts/freeswitch.jar"/>
+    <option value="-Djava.class.path=$${base_dir}/scripts/freeswitch.jar"/>
     <!-- Enable remote debugging -->
     <option value="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=127.0.0.1:8000"/>
   </options>

Modified: freeswitch/branches/gmaruzz/conf/autoload_configs/local_stream.conf.xml
==============================================================================
--- freeswitch/branches/gmaruzz/conf/autoload_configs/local_stream.conf.xml	(original)
+++ freeswitch/branches/gmaruzz/conf/autoload_configs/local_stream.conf.xml	Mon Dec 15 12:56:36 2008
@@ -14,7 +14,7 @@
     <param name="interval" value="20"/>
     <param name="timer-name" value="soft"/>
   </directory>
-  <!-- 
+
   <directory name="moh/32000" path="$${base_dir}/sounds/music/32000">
     <param name="rate" value="32000"/>
     <param name="shuffle" value="true"/>
@@ -22,5 +22,5 @@
     <param name="interval" value="20"/>
     <param name="timer-name" value="soft"/>
   </directory>
-  -->
+
 </configuration>

Modified: freeswitch/branches/gmaruzz/conf/autoload_configs/lua.conf.xml
==============================================================================
--- freeswitch/branches/gmaruzz/conf/autoload_configs/lua.conf.xml	(original)
+++ freeswitch/branches/gmaruzz/conf/autoload_configs/lua.conf.xml	Mon Dec 15 12:56:36 2008
@@ -13,7 +13,7 @@
     These entries will be pre-pended to the LUA_PATH environment variable
     -->
     <!-- <param name="script-directory" value="/usr/local/lua/?.lua"/> -->
-    <!-- <param name="script-directory" value="/usr/local/freeswitch/scripts/?.lua"/> -->
+    <!-- <param name="script-directory" value="$${base_dir}/scripts/?.lua"/> -->
 
     <!--<param name="xml-handler-script" value="/dp.lua"/>-->
     <!--<param name="xml-handler-bindings" value="dialplan"/>-->

Modified: freeswitch/branches/gmaruzz/conf/autoload_configs/modules.conf.xml
==============================================================================
--- freeswitch/branches/gmaruzz/conf/autoload_configs/modules.conf.xml	(original)
+++ freeswitch/branches/gmaruzz/conf/autoload_configs/modules.conf.xml	Mon Dec 15 12:56:36 2008
@@ -63,6 +63,7 @@
     <load module="mod_ilbc"/>
     <load module="mod_speex"/>
     <load module="mod_h26x"/>
+    <!--<load module="mod_siren"/>-->
 
     <!-- File Format Interfaces -->
     <load module="mod_sndfile"/>

Modified: freeswitch/branches/gmaruzz/conf/autoload_configs/sofia.conf.xml
==============================================================================
--- freeswitch/branches/gmaruzz/conf/autoload_configs/sofia.conf.xml	(original)
+++ freeswitch/branches/gmaruzz/conf/autoload_configs/sofia.conf.xml	Mon Dec 15 12:56:36 2008
@@ -2,6 +2,8 @@
 
   <global_settings>
     <param name="log-level" value="0"/>
+    <!-- <param name="auto-restart" value="false"/> -->
+    <param name="debug-presence" value="0"/>
   </global_settings>
 
   <!--

Modified: freeswitch/branches/gmaruzz/conf/autoload_configs/xml_cdr.conf.xml
==============================================================================
--- freeswitch/branches/gmaruzz/conf/autoload_configs/xml_cdr.conf.xml	(original)
+++ freeswitch/branches/gmaruzz/conf/autoload_configs/xml_cdr.conf.xml	Mon Dec 15 12:56:36 2008
@@ -20,6 +20,9 @@
     <!-- true or false if we should create a cdr for the b leg of a call-->
     <param name="log-b-leg" value="false"/>
     
+    <!-- optional: if not present, all filenames are the uuid of the call -->
+    <!-- true or false if a leg files are prefixed "a_" -->
+    <param name="prefix-a-leg" value="true"/>
 
     <!-- encode the post data may be 'true' for url encoding, 'false' for no encoding or 'base64' for base64 encoding -->
     <param name="encode" value="true"/>

Modified: freeswitch/branches/gmaruzz/conf/dialplan/default.xml
==============================================================================
--- freeswitch/branches/gmaruzz/conf/dialplan/default.xml	(original)
+++ freeswitch/branches/gmaruzz/conf/dialplan/default.xml	Mon Dec 15 12:56:36 2008
@@ -35,6 +35,14 @@
       </condition>
     </extension>
 
+    <!-- Set the domain -->
+    <extension name="set_domain_openzap" continue="true">
+      <condition field="${domain_name}" expression="^$"/>
+      <condition field="source" expression="mod_openzap">
+	<action application="set" data="domain_name=$${domain}"/>
+      </condition>
+    </extension>
+
     <!-- Example of doing things based on time of day. -->
     <extension name="tod_example" continue="true">
       <!-- man strftime - M-F, 9AM to 6PM -->

Modified: freeswitch/branches/gmaruzz/conf/directory/default/brian.xml
==============================================================================
--- freeswitch/branches/gmaruzz/conf/directory/default/brian.xml	(original)
+++ freeswitch/branches/gmaruzz/conf/directory/default/brian.xml	Mon Dec 15 12:56:36 2008
@@ -30,7 +30,7 @@
       <!-- which transport to use for register -->
       <!--<param name="register-transport" value="udp"/>-->
       <!--How many seconds before a retry when a failure or timeout occurs -->
-      <!--<param name="retry_seconds" value="30"/>-->
+      <!--<param name="retry-seconds" value="30"/>-->
       <!--Use the callerid of an inbound call in the from field on outbound calls via this gateway -->
       <!--<param name="caller-id-in-from" value="false"/>-->
       <!--extra sip params to send in the contact-->

Modified: freeswitch/branches/gmaruzz/conf/sip_profiles/external.xml
==============================================================================
--- freeswitch/branches/gmaruzz/conf/sip_profiles/external.xml	(original)
+++ freeswitch/branches/gmaruzz/conf/sip_profiles/external.xml	Mon Dec 15 12:56:36 2008
@@ -39,6 +39,8 @@
     <!--<param name="dbname" value="share_presence"/>-->
     <!--<param name="presence-hosts" value="$${domain}"/>-->
     <!--<param name="force-register-domain" value="$${domain}"/>-->
+    <!--all inbound reg will stored in the db using this domain -->
+    <!--<param name="force-register-db-domain" value="$${domain}"/>-->
     <!-- ************************************************* -->
 
     <!--<param name="aggressive-nat-detection" value="true"/>-->

Modified: freeswitch/branches/gmaruzz/conf/sip_profiles/external/example.xml
==============================================================================
--- freeswitch/branches/gmaruzz/conf/sip_profiles/external/example.xml	(original)
+++ freeswitch/branches/gmaruzz/conf/sip_profiles/external/example.xml	Mon Dec 15 12:56:36 2008
@@ -23,7 +23,7 @@
   <!-- which transport to use for register -->
   <!--<param name="register-transport" value="udp"/>-->
   <!--How many seconds before a retry when a failure or timeout occurs -->
-  <!--<param name="retry_seconds" value="30"/>-->
+  <!--<param name="retry-seconds" value="30"/>-->
   <!--Use the callerid of an inbound call in the from field on outbound calls via this gateway -->
   <!--<param name="caller-id-in-from" value="false"/>-->
   <!--extra sip params to send in the contact-->

Modified: freeswitch/branches/gmaruzz/conf/sip_profiles/internal-ipv6.xml
==============================================================================
--- freeswitch/branches/gmaruzz/conf/sip_profiles/internal-ipv6.xml	(original)
+++ freeswitch/branches/gmaruzz/conf/sip_profiles/internal-ipv6.xml	Mon Dec 15 12:56:36 2008
@@ -102,7 +102,9 @@
     <!-- <param name="vad" value="both"/> -->
     <!--<param name="alias" value="sip:10.0.1.251:5555"/>-->
     <!--all inbound reg will look in this domain for the users -->
-    <!--<param name="force-register-domain" value="cluecon.com"/>-->
+    <!--<param name="force-register-domain" value="$${domain}"/>-->
+    <!--all inbound reg will stored in the db using this domain -->
+    <!--<param name="force-register-db-domain" value="$${domain}"/>-->
     <!-- disable register and transfer which may be undesirable in a public switch -->
     <!--<param name="disable-transfer" value="true"/>-->
     <!--<param name="disable-register" value="true"/>-->

Modified: freeswitch/branches/gmaruzz/conf/sip_profiles/internal.xml
==============================================================================
--- freeswitch/branches/gmaruzz/conf/sip_profiles/internal.xml	(original)
+++ freeswitch/branches/gmaruzz/conf/sip_profiles/internal.xml	Mon Dec 15 12:56:36 2008
@@ -145,7 +145,11 @@
     <!-- <param name="vad" value="both"/> -->
     <!--<param name="alias" value="sip:10.0.1.251:5555"/>-->
     <!--all inbound reg will look in this domain for the users -->
-    <!--<param name="force-register-domain" value="cluecon.com"/>-->
+    <!--<param name="force-register-domain" value="$${domain}"/>-->
+    <!--all inbound reg will stored in the db using this domain -->
+    <!--<param name="force-register-db-domain" value="$${domain}"/>-->
+    <!--force suscription expires to a lower value than requested-->
+    <!--<param name="force-subscription-expires" value="60"/>-->
     <!-- disable register and transfer which may be undesirable in a public switch -->
     <!--<param name="disable-transfer" value="true"/>-->
     <!--<param name="disable-register" value="true"/>-->

Modified: freeswitch/branches/gmaruzz/conf/sip_profiles/internal/example.xml
==============================================================================
--- freeswitch/branches/gmaruzz/conf/sip_profiles/internal/example.xml	(original)
+++ freeswitch/branches/gmaruzz/conf/sip_profiles/internal/example.xml	Mon Dec 15 12:56:36 2008
@@ -23,7 +23,7 @@
   <!-- which transport to use for register -->
   <!--<param name="register-transport" value="udp"/>-->
   <!--How many seconds before a retry when a failure or timeout occurs -->
-  <!--<param name="retry_seconds" value="30"/>-->
+  <!--<param name="retry-seconds" value="30"/>-->
   <!--Use the callerid of an inbound call in the from field on outbound calls via this gateway -->
   <!--<param name="caller-id-in-from" value="false"/>-->
   <!--extra sip params to send in the contact-->

Modified: freeswitch/branches/gmaruzz/conf/vars.xml
==============================================================================
--- freeswitch/branches/gmaruzz/conf/vars.xml	(original)
+++ freeswitch/branches/gmaruzz/conf/vars.xml	Mon Dec 15 12:56:36 2008
@@ -33,6 +33,8 @@
        speex at 8000h@20i  - Speex 8kHz using 20ms ptime.
        speex at 16000h@20i - Speex 16kHz using 20ms ptime.
        speex at 32000h@20i - Speex 32kHz using 20ms ptime.
+       G7221 at 16000h     - G722.1 16kHz (aka Siren 7)
+       G7221 at 32000h     - G722.1C 32kHz (aka Siren 14)
        GSM at 40i          - GSM 8kHz using 40ms ptime. (GSM is done in multiples of 20, Default is 20ms)
        G722             - G722 16kHz using default 20ms ptime. (multiples of 10)
        PCMU             - G711 8kHz ulaw using default 20ms ptime. (multiples of 10)

Modified: freeswitch/branches/gmaruzz/configure.in
==============================================================================
--- freeswitch/branches/gmaruzz/configure.in	(original)
+++ freeswitch/branches/gmaruzz/configure.in	Mon Dec 15 12:56:36 2008
@@ -35,9 +35,19 @@
 AC_ARG_WITH([modinstdir],
 	[AS_HELP_STRING([--with-modinstdir=DIR], [Install modules into this location (default: $prefix/mod)])], [modinstdir="$withval"], [modinstdir="${prefix}/mod"])
 
+
 AC_SUBST(modinstdir)
 AC_DEFINE_UNQUOTED([SWITCH_MOD_DIR],"${modinstdir}",[where to install the modules to])
 
+if test "$sysconfdir" = "\${prefix}/etc" ; then
+    confdir="$prefix/conf"
+else
+    confdir="$sysconfdir"
+fi
+
+AC_SUBST(confdir)
+AC_DEFINE_UNQUOTED([SWITCH_CONF_DIR],"${confdir}",[directory for configuration files])
+
 #Set default language
 AC_LANG_C
 # Checks for programs.

Modified: freeswitch/branches/gmaruzz/debian/freeswitch.conffiles
==============================================================================
--- freeswitch/branches/gmaruzz/debian/freeswitch.conffiles	(original)
+++ freeswitch/branches/gmaruzz/debian/freeswitch.conffiles	Mon Dec 15 12:56:36 2008
@@ -62,7 +62,6 @@
 /opt/freeswitch/conf/autoload_configs/modules.conf.xml
 /opt/freeswitch/conf/autoload_configs/dingaling.conf.xml
 /opt/freeswitch/conf/autoload_configs/iax.conf.xml
-/opt/freeswitch/conf/autoload_configs/woomera.conf.xml
 /opt/freeswitch/conf/autoload_configs/post_load_modules.conf.xml
 /opt/freeswitch/conf/autoload_configs/pocketsphinx.conf.xml
 /opt/freeswitch/conf/autoload_configs/xml_cdr.conf.xml

Modified: freeswitch/branches/gmaruzz/debian/freeswitch.install
==============================================================================
--- freeswitch/branches/gmaruzz/debian/freeswitch.install	(original)
+++ freeswitch/branches/gmaruzz/debian/freeswitch.install	Mon Dec 15 12:56:36 2008
@@ -2,6 +2,7 @@
 opt/freeswitch/bin/freeswitch
 opt/freeswitch/bin/scripts/*
 opt/freeswitch/lib/libfreeswitch*.so*
+opt/freeswitch/lib/libopenzap*.so*
 opt/freeswitch/mod/mod_shout*
 opt/freeswitch/mod/mod_cdr_csv.so*
 opt/freeswitch/mod/mod_console.so*
@@ -28,8 +29,13 @@
 opt/freeswitch/mod/mod_iax.so*
 opt/freeswitch/mod/mod_portaudio.so*
 opt/freeswitch/mod/mod_sofia.so*
-opt/freeswitch/mod/mod_woomera.so*
 opt/freeswitch/mod/mod_openzap.so
+opt/freeswitch/mod/ozmod_analog_em.so
+opt/freeswitch/mod/ozmod_analog.so
+opt/freeswitch/mod/ozmod_isdn.so
+opt/freeswitch/mod/ozmod_ss7_boost.so
+opt/freeswitch/mod/ozmod_wanpipe.so
+opt/freeswitch/mod/ozmod_zt.so
 opt/freeswitch/mod/mod_event_*.so*
 opt/freeswitch/mod/mod_native_file.so*
 opt/freeswitch/mod/mod_sndfile.so*
@@ -103,7 +109,6 @@
 opt/freeswitch/conf/autoload_configs/modules.conf.xml
 opt/freeswitch/conf/autoload_configs/dingaling.conf.xml
 opt/freeswitch/conf/autoload_configs/iax.conf.xml
-opt/freeswitch/conf/autoload_configs/woomera.conf.xml
 opt/freeswitch/conf/autoload_configs/post_load_modules.conf.xml
 opt/freeswitch/conf/autoload_configs/pocketsphinx.conf.xml
 opt/freeswitch/conf/autoload_configs/xml_cdr.conf.xml

Modified: freeswitch/branches/gmaruzz/debian/postinst
==============================================================================
--- freeswitch/branches/gmaruzz/debian/postinst	(original)
+++ freeswitch/branches/gmaruzz/debian/postinst	Mon Dec 15 12:56:36 2008
@@ -25,6 +25,7 @@
 			adduser --disabled-password  --quiet --system \
 			--home /opt/freeswitch \
 			--gecos "FreeSwitch Voice Platform" --ingroup daemon \
+			--add_extra_groups audio \
 			freeswitch
 		fi
  

Modified: freeswitch/branches/gmaruzz/debian/rules
==============================================================================
--- freeswitch/branches/gmaruzz/debian/rules	(original)
+++ freeswitch/branches/gmaruzz/debian/rules	Mon Dec 15 12:56:36 2008
@@ -20,8 +20,7 @@
 export DIRECTORIES_MODULES=
 export DOTNET_MODULES=
 export ENDPOINTS_MODULES=endpoints/mod_dingaling endpoints/mod_iax endpoints/mod_portaudio endpoints/mod_sofia \
-			 endpoints/mod_woomera endpoints/mod_loopback \
-			 ../../libs/openzap/mod_openzap
+			 endpoints/mod_loopback ../../libs/openzap/mod_openzap
 export EVENT_HANDLERS_MODULES=event_handlers/mod_event_multicast event_handlers/mod_event_socket event_handlers/mod_cdr_csv
 export FORMATS_MODULES=formats/mod_local_stream formats/mod_native_file formats/mod_sndfile formats/mod_tone_stream formats/mod_shout
 export LANGUAGES_MODULES=languages/mod_perl languages/mod_lua

Modified: freeswitch/branches/gmaruzz/docs/Doxygen.conf
==============================================================================
--- freeswitch/branches/gmaruzz/docs/Doxygen.conf	(original)
+++ freeswitch/branches/gmaruzz/docs/Doxygen.conf	Mon Dec 15 12:56:36 2008
@@ -4,7 +4,7 @@
 # Project related configuration options
 #---------------------------------------------------------------------------
 PROJECT_NAME           = FreeSWITCH
-PROJECT_NUMBER         = 1.0.0
+PROJECT_NUMBER         = 1.0.1
 OUTPUT_DIRECTORY       = .
 CREATE_SUBDIRS         = NO
 OUTPUT_LANGUAGE        = English

Modified: freeswitch/branches/gmaruzz/docs/phrase/phrase_en.xml
==============================================================================
--- freeswitch/branches/gmaruzz/docs/phrase/phrase_en.xml	(original)
+++ freeswitch/branches/gmaruzz/docs/phrase/phrase_en.xml	Mon Dec 15 12:56:36 2008
@@ -111,8 +111,8 @@
       <prompt phrase="Seventeenth" filename="h-17.wav"/>
       <prompt phrase="Eighteenth" filename="h-18.wav"/>
       <prompt phrase="Nineteenth" filename="h-19.wav"/>
-      <prompt phrase="Twentyth" filename="h-20.wav"/>
-      <prompt phrase="Thirtyth" filename="h-30.wav"/>
+      <prompt phrase="Twentieth" filename="h-20.wav"/>
+      <prompt phrase="Thirtieth" filename="h-30.wav"/>
       <prompt phrase="Hundred" filename="hundred.wav"/>
       <prompt phrase="Million" filename="million.wav"/>
       <prompt phrase="Period" filename="period.wav"/>
@@ -222,7 +222,7 @@
       <prompt phrase="NULL" filename="conf-ack.wav" type="tone"/>
       <prompt phrase="NULL" filename="conf-nack.wav" type="tone"/>
       <prompt phrase="You are now muted." filename="conf-mute.wav"/>
-      <prompt phrase="You are now unmuted." filename="conf0unmuted.wav"/>
+      <prompt phrase="You are now unmuted." filename="conf-unmuted.wav"/>
       <prompt phrase="You are currently the only person in this conference." filename="conf-alone.wav"/>
       <prompt phrase="NULL" filename="conf-perpetual.wav" type="music"/>
       <prompt phrase="NULL" filename="conf-enter.wav" type="tone"/>
@@ -233,6 +233,8 @@
       <prompt phrase="The conference is now unlocked." filename="conf-is-unlocked.wav"/>
       <prompt phrase="Please enter the conference pin number." filename="conf-pin.wav"/>
       <prompt phrase="Invalid pin number, try again." filename="conf-bad-pin.wav"/>
+      <prompt phrase="goodbye" filename="conf-goodbye.wav"/>
+      <prompt phrase="Welcome to the conference." filename="conf-welcome.wav"/>
     </conference>
     <ivr>
       <prompt phrase="Account number" filename="ivr-account_number.wav"/>

Modified: freeswitch/branches/gmaruzz/freeswitch.spec
==============================================================================
--- freeswitch/branches/gmaruzz/freeswitch.spec	(original)
+++ freeswitch/branches/gmaruzz/freeswitch.spec	Mon Dec 15 12:56:36 2008
@@ -312,6 +312,10 @@
 %config(noreplace) %attr(0640, freeswitch, daemon) %{prefix}/conf/autoload_configs/event_socket.conf.xml
 %config(noreplace) %attr(0640, freeswitch, daemon) %{prefix}/conf/autoload_configs/cdr_csv.conf.xml
 %config(noreplace) %attr(0640, freeswitch, daemon) %{prefix}/conf/autoload_configs/fax.conf.xml
+%config(noreplace) %attr(0640, freeswitch, daemon) %{prefix}/conf/autoload_configs/fifo.conf.xml
+%config(noreplace) %attr(0640, freeswitch, daemon) %{prefix}/conf/autoload_configs/openzap.conf.xml
+%config(noreplace) %attr(0640, freeswitch, daemon) %{prefix}/conf/autoload_configs/shout.conf.xml
+%config(noreplace) %attr(0640, freeswitch, daemon) %{prefix}/conf/autoload_configs/timezones.conf.xml
 %config(noreplace) %attr(0640, freeswitch, daemon) %{prefix}/conf/autoload_configs/iax.conf.xml
 %config(noreplace) %attr(0640, freeswitch, daemon) %{prefix}/conf/autoload_configs/ivr.conf.xml
 %config(noreplace) %attr(0640, freeswitch, daemon) %{prefix}/conf/autoload_configs/java.conf.xml
@@ -358,6 +362,7 @@
 %endif
 %{prefix}/bin/*
 %{prefix}/lib/libfreeswitch*.so*
+%{prefix}/lib/libopenzap.so*
 %{prefix}/mod/mod_console.so*
 %{prefix}/mod/mod_logfile.so*
 %{prefix}/mod/mod_syslog.so*
@@ -403,6 +408,7 @@
 %{prefix}/mod/ozmod_isdn.so
 %{prefix}/mod/ozmod_ss7_boost.so
 %{prefix}/mod/ozmod_zt.so
+%{prefix}/mod/ozmod_wanpipe.so
 
 %files codec-passthru-amr
 %defattr(-,freeswitch,daemon)

Modified: freeswitch/branches/gmaruzz/libs/libdingaling/src/libdingaling.c
==============================================================================
--- freeswitch/branches/gmaruzz/libs/libdingaling/src/libdingaling.c	(original)
+++ freeswitch/branches/gmaruzz/libs/libdingaling/src/libdingaling.c	Mon Dec 15 12:56:36 2008
@@ -252,6 +252,19 @@
 }
 
 
+static char *iks_name_nons(iks *x)
+{
+	char *r = iks_name(x);
+	char *p;
+
+	if (r && (p = strchr(r, ':'))) {
+		r = p + 1;
+	}
+
+	return r;
+}
+
+
 char *ldl_session_get_value(ldl_session_t *session, char *key)
 {
 	return apr_hash_get(session->variables, key, APR_HASH_KEY_STRING);
@@ -385,10 +398,10 @@
 				tag = iks_child (xml);
 				
 				while(tag) {
-					if (!strcasecmp(iks_name(tag), "description")) {
+					if (!strcasecmp(iks_name_nons(tag), "description")) {
 						iks * itag = iks_child (tag);
 						while(itag) {
-							if (!strcasecmp(iks_name(itag), "payload-type") && session->payload_len < LDL_MAX_PAYLOADS) {
+							if (!strcasecmp(iks_name_nons(itag), "payload-type") && session->payload_len < LDL_MAX_PAYLOADS) {
 								char *name = iks_find_attrib(itag, "name");
 								char *id = iks_find_attrib(itag, "id");
 								char *rate = iks_find_attrib(itag, "clockrate");
@@ -421,12 +434,12 @@
 				dl_signal = LDL_SIGNAL_CANDIDATES;
 				tag = iks_child (xml);
 				id = type;
-				if (tag && !strcasecmp(iks_name(tag), "transport")) {
+				if (tag && !strcasecmp(iks_name_nons(tag), "transport")) {
 					tag = iks_child(tag);
 				}
 				
 				while(tag) {
-					if (!strcasecmp(iks_name(tag), "info_element")) {
+					if (!strcasecmp(iks_name_nons(tag), "info_element")) {
 						char *name = iks_find_attrib(tag, "name");
 						char *value = iks_find_attrib(tag, "value");
 						if (globals.debug) {
@@ -434,7 +447,7 @@
 						}
 						ldl_session_set_value(session, name, value);
 						
-					} else if (!strcasecmp(iks_name(tag), "candidate") && session->candidate_len < LDL_MAX_CANDIDATES) {
+					} else if (!strcasecmp(iks_name_nons(tag), "candidate") && session->candidate_len < LDL_MAX_CANDIDATES) {
 						char *key;
 						double pref = 0.0;
 						int index = -1;
@@ -647,7 +660,7 @@
 	char *resource;
 	struct ldl_buffer *buffer;
 	ldl_signal_t dl_signal = LDL_SIGNAL_PRESENCE_IN;
-	
+	int done = 0;
 
 
     if (type && *type) {
@@ -685,10 +698,27 @@
 
 	if (resource && (strstr(resource, "talk") || strstr(resource, "telepathy")) && (buffer = apr_hash_get(handle->probe_hash, id, APR_HASH_KEY_STRING))) {
 		apr_cpystrn(buffer->buf, from, buffer->len);
-		fflush(stderr);
 		buffer->hit = 1;
+		done = 1;
 	} 
-	
+
+	if (!done) {
+		iks *xml = iks_find(pak->x, "c");
+		if (!xml) {
+			xml = iks_find(pak->x, "caps:c");
+		}
+		
+		if (xml) {
+			char *ext = iks_find_attrib(xml, "ext");;
+			if (ext && strstr(ext, "voice-v1") && (buffer = apr_hash_get(handle->probe_hash, id, APR_HASH_KEY_STRING))) {
+				apr_cpystrn(buffer->buf, from, buffer->len);
+				buffer->hit = 1;
+				done = 1;
+			}
+		}
+	}
+
+
     if (handle->session_callback) {
         handle->session_callback(handle, NULL, dl_signal, to, id, status ? status : "n/a", show ? show : "n/a");
     }
@@ -930,7 +960,7 @@
 	if (is_result) {
 		iks *tag = iks_child (pak->x);
 		while(tag) {
-			if (!strcasecmp(iks_name(tag), "bind")) {
+			if (!strcasecmp(iks_name_nons(tag), "bind")) {
 				char *jid = iks_find_cdata(tag, "jid");
 				char *resource = strchr(jid, '/');
 				if (resource) {
@@ -972,7 +1002,7 @@
 	
 	xml = iks_child (pak->x);
 	while (xml) {
-		char *name = iks_name(xml);
+		char *name = iks_name_nons(xml);
 		if (!strcasecmp(name, "session")) {
 			char *id = iks_find_attrib(xml, "id");
 			//printf("SESSION type=%s name=%s id=%s\n", type, name, id);
@@ -1193,12 +1223,12 @@
 					
 				}
 			}
-		} else if (node && strcmp("failure", iks_name(node)) == 0) {
+		} else if (node && strcmp("failure", iks_name_nons(node)) == 0) {
 			globals.logger(DL_LOG_DEBUG, "sasl authentication failed\n");
 			if (handle->session_callback) {
 				handle->session_callback(handle, NULL, LDL_SIGNAL_LOGIN_FAILURE, "user", "core", "Login Failure", handle->login);
 			}
-		} else if (node && strcmp("success", iks_name(node)) == 0) {
+		} else if (node && strcmp("success", iks_name_nons(node)) == 0) {
 			globals.logger(DL_LOG_DEBUG, "XMPP server connected\n");
 			iks_send_header(handle->parser, handle->acc->server);
 			ldl_set_flag_locked(handle, LDL_FLAG_CONNECTED);
@@ -1474,7 +1504,7 @@
 		case IKS_OK:
 			break;
 		case IKS_NET_NODNS:
-			globals.logger(DL_LOG_DEBUG, "hostname lookup failed for %s\n", handle->server);
+			globals.logger(DL_LOG_DEBUG, "hostname lookup failed\n");
 			microsleep(1000);
 			goto fail;
 		case IKS_NET_NOCONN:
@@ -1541,6 +1571,10 @@
 		ldl_clear_flag_locked(handle, LDL_FLAG_CONNECTED);
 		ldl_clear_flag_locked(handle, LDL_FLAG_AUTHORIZED);
 		handle->state = CS_NEW;
+
+		while(ldl_test_flag(handle, LDL_FLAG_QUEUE_RUNNING)) {
+			microsleep(100);
+		}
 	}
 	ldl_clear_flag_locked(handle, LDL_FLAG_RUNNING);
 	if (!ldl_test_flag(handle, LDL_FLAG_TLS)) {
@@ -1586,8 +1620,8 @@
 	iks_insert_attrib(iq, "to", session->them);
 	iks_insert_attrib(iq, "type", "set");
 	iks_insert_attrib(iq, "id", idbuf);
-	sess = iks_insert (iq, "session");
-	iks_insert_attrib(sess, "xmlns", "http://www.google.com/session");
+	sess = iks_insert (iq, "ses:session");
+	iks_insert_attrib(sess, "xmlns:ses", "http://www.google.com/session");
 
 	iks_insert_attrib(sess, "type", type);
 	iks_insert_attrib(sess, "id", session->id);
@@ -1661,8 +1695,8 @@
 		if (!iks_insert_attrib(iq, "id", idbuf)) goto fail;
 		if (!iks_insert_attrib(iq, "from", session->login)) goto fail;
 		if (!iks_insert_attrib(iq, "to", session->them)) goto fail;
-		if (!(sess = iks_insert (iq, "session"))) goto fail;
-		if (!iks_insert_attrib(sess, "xmlns", "http://www.google.com/session")) goto fail;
+		if (!(sess = iks_insert (iq, "ses:session"))) goto fail;
+		if (!iks_insert_attrib(sess, "xmlns:ses", "http://www.google.com/session")) goto fail;
 		if (!iks_insert_attrib(sess, "type", "transport-accept")) goto fail;
 		if (!iks_insert_attrib(sess, "id", candidate->tid)) goto fail;
 		if (!iks_insert_attrib(sess, "xmlns", "http://www.google.com/session")) goto fail;
@@ -1890,12 +1924,13 @@
 		sess = NULL;
 		id = 0;
 		
-		new_session_iq(session, &iq, &sess, &id, "transport-info");
-		tag = iks_insert(sess, "transport");
-		iks_insert_attrib(tag, "xmlns", "http://www.google.com/transport/p2p");
+		new_session_iq(session, &iq, &sess, &id, "candidates");
+		//tag = iks_insert(sess, "transport");
+		//iks_insert_attrib(tag, "xmlns", "http://www.google.com/transport/p2p");
+		tag = sess;
 
 		add_elements(session, tag);
-		tag = iks_insert(tag, "candidate");
+		tag = iks_insert(tag, "ses:candidate");
 
 		if (candidates[x].name) {
 			iks_insert_attrib(tag, "name", candidates[x].name);
@@ -2067,13 +2102,13 @@
 	
 
 	new_session_iq(session, &iq, &sess, &id, description == LDL_DESCRIPTION_ACCEPT ? "accept" : "initiate");
-	tag = iks_insert(sess, "description");
-	iks_insert_attrib(tag, "xmlns", "http://www.google.com/session/phone");
+	tag = iks_insert(sess, "pho:description");
+	iks_insert_attrib(tag, "xmlns:pho", "http://www.google.com/session/phone");
 	iks_insert_attrib(tag, "xml:lang", "en");
 	for (x = 0; x < plen; x++) {
 		char idbuf[80];
-		payload = iks_insert(tag, "payload-type");
-		iks_insert_attrib(payload, "xmlns", "http://www.google.com/session/phone");
+		payload = iks_insert(tag, "pho:payload-type");
+		iks_insert_attrib(payload, "xmlns:pho", "http://www.google.com/session/phone");
 
 		sprintf(idbuf, "%d", payloads[x].id);
 		iks_insert_attrib(payload, "id", idbuf);

Modified: freeswitch/branches/gmaruzz/libs/libteletone/src/libteletone_generate.c
==============================================================================
--- freeswitch/branches/gmaruzz/libs/libteletone/src/libteletone_generate.c	(original)
+++ freeswitch/branches/gmaruzz/libs/libteletone/src/libteletone_generate.c	Mon Dec 15 12:56:36 2008
@@ -208,7 +208,7 @@
 	/*teletone_process_t period = (1.0 / ts->rate) / ts->channels;*/
 	int i, c;
 	int freqlen = 0;
-	teletone_dds_state_t tones[TELETONE_MAX_TONES];
+	teletone_dds_state_t tones[TELETONE_MAX_TONES+1];
 	//int decay = 0;
 	int duration;
 	int wait = 0;
@@ -221,7 +221,7 @@
 	wait = (ts->tmp_wait > -1) ? ts->tmp_wait : ts->wait;
 
 	if (map->freqs[0] > 0) {
-		for (freqlen = 0; map->freqs[freqlen] && freqlen < TELETONE_MAX_TONES; freqlen++) {
+		for (freqlen = 0; freqlen < TELETONE_MAX_TONES && map->freqs[freqlen]; freqlen++) {
 			teletone_dds_state_set_tone(&tones[freqlen], map->freqs[freqlen], ts->rate, 0);
 			teletone_dds_state_set_tx_level(&tones[freqlen], vol);
 		}
@@ -243,7 +243,7 @@
 
 				if (nvol <= TELETONE_VOL_DB_MAX && nvol >= TELETONE_VOL_DB_MIN) {
 					vol = nvol;
-					for (j = 0; map->freqs[j] && j < TELETONE_MAX_TONES; j++) {					
+					for (j = 0; j < TELETONE_MAX_TONES && map->freqs[j]; j++) {					
 						teletone_dds_state_set_tx_level(&tones[j], vol);
 					}
 					dc = 0;

Modified: freeswitch/branches/gmaruzz/libs/spandsp/src/t31.c
==============================================================================
--- freeswitch/branches/gmaruzz/libs/spandsp/src/t31.c	(original)
+++ freeswitch/branches/gmaruzz/libs/spandsp/src/t31.c	Mon Dec 15 12:56:36 2008
@@ -42,7 +42,6 @@
 #include <memory.h>
 #include <string.h>
 #include <ctype.h>
-#include <malloc.h>
 #include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>

Modified: freeswitch/branches/gmaruzz/libs/spandsp/src/t38_terminal.c
==============================================================================
--- freeswitch/branches/gmaruzz/libs/spandsp/src/t38_terminal.c	(original)
+++ freeswitch/branches/gmaruzz/libs/spandsp/src/t38_terminal.c	Mon Dec 15 12:56:36 2008
@@ -37,7 +37,6 @@
 #include <fcntl.h>
 #include <time.h>
 #include <string.h>
-#include <malloc.h>
 #include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>

Modified: freeswitch/branches/gmaruzz/libs/win32/libmp3lame/libmp3lame_vc7.vcproj
==============================================================================
--- freeswitch/branches/gmaruzz/libs/win32/libmp3lame/libmp3lame_vc7.vcproj	(original)
+++ freeswitch/branches/gmaruzz/libs/win32/libmp3lame/libmp3lame_vc7.vcproj	Mon Dec 15 12:56:36 2008
@@ -42,7 +42,7 @@
 				Name="VCCLCompilerTool"
 				AdditionalOptions="/GAy /QIfdiv /QI0f"
 				Optimization="2"
-				AdditionalIncludeDirectories="&quot;..\..\lame-3.97&quot;,&quot;..\..\lame-3.97\include&quot;"
+				AdditionalIncludeDirectories=".;&quot;..\..\lame-3.97&quot;;&quot;..\..\lame-3.97\include&quot;"
 				PreprocessorDefinitions="NDEBUG;_WINDOWS;WIN32;HAVE_CONFIG_H"
 				StringPooling="true"
 				RuntimeLibrary="0"
@@ -112,7 +112,7 @@
 			<Tool
 				Name="VCCLCompilerTool"
 				Optimization="0"
-				AdditionalIncludeDirectories="&quot;..\..\lame-3.97&quot;,&quot;..\..\lame-3.97\include&quot;"
+				AdditionalIncludeDirectories=".;&quot;..\..\lame-3.97&quot;;&quot;..\..\lame-3.97\include&quot;"
 				PreprocessorDefinitions="_DEBUG;_WINDOWS;WIN32;HAVE_CONFIG_H"
 				RuntimeLibrary="1"
 				PrecompiledHeaderFile=".\Debug/libmp3lame_vc6.pch"
@@ -655,30 +655,6 @@
 				>
 			</File>
 			<File
-				RelativePath="..\..\lame-3.97\configMS.h"
-				>
-				<FileConfiguration
-					Name="Release|Win32"
-					>
-					<Tool
-						Name="VCCustomBuildTool"
-						Description="Performing Custom Build Step on $(InputName)"
-						CommandLine="copy ..\..\lame-3.97\configMS.h ..\..\lame-3.97\config.h&#x0D;&#x0A;"
-						Outputs="..\config.h"
-					/>
-				</FileConfiguration>
-				<FileConfiguration
-					Name="Debug|Win32"
-					>
-					<Tool
-						Name="VCCustomBuildTool"
-						Description="Performing Custom Build Step on $(InputName)"
-						CommandLine="copy ..\..\lame-3.97\configMS.h ..\..\lame-3.97\config.h&#x0D;&#x0A;"
-						Outputs="..\config.h"
-					/>
-				</FileConfiguration>
-			</File>
-			<File
 				RelativePath="..\..\lame-3.97\libmp3lame\encoder.h"
 				>
 			</File>

Modified: freeswitch/branches/gmaruzz/libs/win32/libshout/libshout.vcproj
==============================================================================
--- freeswitch/branches/gmaruzz/libs/win32/libshout/libshout.vcproj	(original)
+++ freeswitch/branches/gmaruzz/libs/win32/libshout/libshout.vcproj	Mon Dec 15 12:56:36 2008
@@ -20,8 +20,6 @@
 			OutputDirectory="$(ConfigurationName)"
 			IntermediateDirectory="$(ConfigurationName)"
 			ConfigurationType="4"
-			UseOfMFC="0"
-			ATLMinimizesCRunTimeLibraryUsage="false"
 			CharacterSet="2"
 			>
 			<Tool
@@ -44,14 +42,13 @@
 				Optimization="2"
 				InlineFunctionExpansion="1"
 				AdditionalIncludeDirectories=".\,..\..\libshout-2.2.2\src,..\..\libshout-2.2.2\include,..\..\libogg-1.1.3\include,..\..\pthreads-w32-2-7-0-release,..\..\libshout-2.2.2\win32\include"
-				PreprocessorDefinitions="WIN32;_DEBUG;_LIB;_WIN32;VERSION=\&quot;2.0.0\&quot;;LIBSHOUT_MAJOR=2;LIBSHOUT_MINOR=0;LIBSHOUT_MICRO=0;HAVE_WINSOCK2_H;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE"
+				PreprocessorDefinitions="WIN32;_LIB;_WIN32;VERSION=\&quot;2.0.0\&quot;;LIBSHOUT_MAJOR=2;LIBSHOUT_MINOR=0;LIBSHOUT_MICRO=0;HAVE_WINSOCK2_H;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE"
 				StringPooling="true"
 				RuntimeLibrary="0"
 				EnableFunctionLevelLinking="true"
-				PrecompiledHeaderFile="$(ConfigurationName)/libshout.pch"
-				AssemblerListingLocation=".$(ConfigurationName)"
-				ObjectFile=".\Release/"
-				ProgramDataBaseFileName="$(ConfigurationName)"
+				AssemblerListingLocation=".\Static_Release/"
+				ObjectFile=".\Static_Release/"
+				ProgramDataBaseFileName=".\Static_Release/"
 				WarningLevel="0"
 				SuppressStartupBanner="true"
 			/>
@@ -68,9 +65,8 @@
 			/>
 			<Tool
 				Name="VCLibrarianTool"
-				OutputFile="$(OutDir)\libshout.lib"
+				OutputFile="$(OutDir)/libshout.lib"
 				SuppressStartupBanner="true"
-				IgnoreAllDefaultLibraries="true"
 			/>
 			<Tool
 				Name="VCALinkTool"
@@ -80,8 +76,6 @@
 			/>
 			<Tool
 				Name="VCBscMakeTool"
-				SuppressStartupBanner="true"
-				OutputFile="$(ConfigurationName)/libshout.bsc"
 			/>
 			<Tool
 				Name="VCFxCopTool"
@@ -95,8 +89,6 @@
 			OutputDirectory="$(ConfigurationName)"
 			IntermediateDirectory="$(ConfigurationName)"
 			ConfigurationType="4"
-			UseOfMFC="0"
-			ATLMinimizesCRunTimeLibraryUsage="false"
 			CharacterSet="2"
 			>
 			<Tool
@@ -122,10 +114,9 @@
 				MinimalRebuild="true"
 				BasicRuntimeChecks="3"
 				RuntimeLibrary="1"
-				PrecompiledHeaderFile=".\Debug/libshout.pch"
-				AssemblerListingLocation="$(ConfigurationName)"
-				ObjectFile=".\Debug/"
-				ProgramDataBaseFileName="$(ConfigurationName)"
+				AssemblerListingLocation=".\Static_Debug/"
+				ObjectFile=".\Static_Debug/"
+				ProgramDataBaseFileName=".\Static_Debug/"
 				WarningLevel="0"
 				SuppressStartupBanner="true"
 				DebugInformationFormat="3"
@@ -143,9 +134,8 @@
 			/>
 			<Tool
 				Name="VCLibrarianTool"
-				OutputFile="$(OutDir)\libshout.lib"
+				OutputFile="$(OutDir)/libshout.lib"
 				SuppressStartupBanner="true"
-				IgnoreAllDefaultLibraries="true"
 			/>
 			<Tool
 				Name="VCALinkTool"
@@ -155,8 +145,6 @@
 			/>
 			<Tool
 				Name="VCBscMakeTool"
-				SuppressStartupBanner="true"
-				OutputFile="$(ConfigurationName)/libshout.bsc"
 			/>
 			<Tool
 				Name="VCFxCopTool"
@@ -176,24 +164,6 @@
 			<File
 				RelativePath="..\..\libshout-2.2.2\src\avl\avl.c"
 				>
-				<FileConfiguration
-					Name="Release|Win32"
-					>
-					<Tool
-						Name="VCCLCompilerTool"
-						AdditionalIncludeDirectories=""
-						PreprocessorDefinitions=""
-					/>
-				</FileConfiguration>
-				<FileConfiguration
-					Name="Debug|Win32"
-					>
-					<Tool
-						Name="VCCLCompilerTool"
-						AdditionalIncludeDirectories=""
-						PreprocessorDefinitions=""
-					/>
-				</FileConfiguration>
 			</File>
 			<File
 				RelativePath="..\..\libshout-2.2.2\src\avl\avl.h"
@@ -202,24 +172,6 @@
 			<File
 				RelativePath="..\..\libshout-2.2.2\src\httpp\httpp.c"
 				>
-				<FileConfiguration
-					Name="Release|Win32"
-					>
-					<Tool
-						Name="VCCLCompilerTool"
-						AdditionalIncludeDirectories=""
-						PreprocessorDefinitions=""
-					/>
-				</FileConfiguration>
-				<FileConfiguration
-					Name="Debug|Win32"
-					>
-					<Tool
-						Name="VCCLCompilerTool"
-						AdditionalIncludeDirectories=""
-						PreprocessorDefinitions=""
-					/>
-				</FileConfiguration>
 			</File>
 			<File
 				RelativePath="..\..\libshout-2.2.2\src\httpp\httpp.h"
@@ -228,68 +180,14 @@
 			<File
 				RelativePath="..\..\libshout-2.2.2\src\mp3.c"
 				>
-				<FileConfiguration
-					Name="Release|Win32"
-					>
-					<Tool
-						Name="VCCLCompilerTool"
-						AdditionalIncludeDirectories=""
-						PreprocessorDefinitions=""
-					/>
-				</FileConfiguration>
-				<FileConfiguration
-					Name="Debug|Win32"
-					>
-					<Tool
-						Name="VCCLCompilerTool"
-						AdditionalIncludeDirectories=""
-						PreprocessorDefinitions=""
-					/>
-				</FileConfiguration>
 			</File>
 			<File
 				RelativePath="..\..\libshout-2.2.2\src\ogg.c"
 				>
-				<FileConfiguration
-					Name="Release|Win32"
-					>
-					<Tool
-						Name="VCCLCompilerTool"
-						AdditionalIncludeDirectories=""
-						PreprocessorDefinitions=""
-					/>
-				</FileConfiguration>
-				<FileConfiguration
-					Name="Debug|Win32"
-					>
-					<Tool
-						Name="VCCLCompilerTool"
-						AdditionalIncludeDirectories=""
-						PreprocessorDefinitions=""
-					/>
-				</FileConfiguration>
 			</File>
 			<File
 				RelativePath="..\..\libshout-2.2.2\src\net\resolver.c"
 				>
-				<FileConfiguration
-					Name="Release|Win32"
-					>
-					<Tool
-						Name="VCCLCompilerTool"
-						AdditionalIncludeDirectories=""
-						PreprocessorDefinitions=""
-					/>
-				</FileConfiguration>
-				<FileConfiguration
-					Name="Debug|Win32"
-					>
-					<Tool
-						Name="VCCLCompilerTool"
-						AdditionalIncludeDirectories=""
-						PreprocessorDefinitions=""
-					/>
-				</FileConfiguration>
 			</File>
 			<File
 				RelativePath="..\..\libshout-2.2.2\src\net\resolver.h"
@@ -298,24 +196,6 @@
 			<File
 				RelativePath="..\..\libshout-2.2.2\src\shout.c"
 				>
-				<FileConfiguration
-					Name="Release|Win32"
-					>
-					<Tool
-						Name="VCCLCompilerTool"
-						AdditionalIncludeDirectories=""
-						PreprocessorDefinitions=""
-					/>
-				</FileConfiguration>
-				<FileConfiguration
-					Name="Debug|Win32"
-					>
-					<Tool
-						Name="VCCLCompilerTool"
-						AdditionalIncludeDirectories=""
-						PreprocessorDefinitions=""
-					/>
-				</FileConfiguration>
 			</File>
 			<File
 				RelativePath="..\..\libshout-2.2.2\src\shout_ogg.h"
@@ -328,24 +208,6 @@
 			<File
 				RelativePath="..\..\libshout-2.2.2\src\net\sock.c"
 				>
-				<FileConfiguration
-					Name="Release|Win32"
-					>
-					<Tool
-						Name="VCCLCompilerTool"
-						AdditionalIncludeDirectories=""
-						PreprocessorDefinitions=""
-					/>
-				</FileConfiguration>
-				<FileConfiguration
-					Name="Debug|Win32"
-					>
-					<Tool
-						Name="VCCLCompilerTool"
-						AdditionalIncludeDirectories=""
-						PreprocessorDefinitions=""
-					/>
-				</FileConfiguration>
 			</File>
 			<File
 				RelativePath="..\..\libshout-2.2.2\src\net\sock.h"
@@ -354,24 +216,6 @@
 			<File
 				RelativePath="..\..\libshout-2.2.2\src\thread\thread.c"
 				>
-				<FileConfiguration
-					Name="Release|Win32"
-					>
-					<Tool
-						Name="VCCLCompilerTool"
-						AdditionalIncludeDirectories=""
-						PreprocessorDefinitions=""
-					/>
-				</FileConfiguration>
-				<FileConfiguration
-					Name="Debug|Win32"
-					>
-					<Tool
-						Name="VCCLCompilerTool"
-						AdditionalIncludeDirectories=""
-						PreprocessorDefinitions=""
-					/>
-				</FileConfiguration>
 			</File>
 			<File
 				RelativePath="..\..\libshout-2.2.2\src\thread\thread.h"
@@ -380,24 +224,6 @@
 			<File
 				RelativePath="..\..\libshout-2.2.2\src\timing\timing.c"
 				>
-				<FileConfiguration
-					Name="Release|Win32"
-					>
-					<Tool
-						Name="VCCLCompilerTool"
-						AdditionalIncludeDirectories=""
-						PreprocessorDefinitions=""
-					/>
-				</FileConfiguration>
-				<FileConfiguration
-					Name="Debug|Win32"
-					>
-					<Tool
-						Name="VCCLCompilerTool"
-						AdditionalIncludeDirectories=""
-						PreprocessorDefinitions=""
-					/>
-				</FileConfiguration>
 			</File>
 			<File
 				RelativePath="..\..\libshout-2.2.2\src\timing\timing.h"
@@ -406,24 +232,6 @@
 			<File
 				RelativePath="..\..\libshout-2.2.2\src\util.c"
 				>
-				<FileConfiguration
-					Name="Release|Win32"
-					>
-					<Tool
-						Name="VCCLCompilerTool"
-						AdditionalIncludeDirectories=""
-						PreprocessorDefinitions=""
-					/>
-				</FileConfiguration>
-				<FileConfiguration
-					Name="Debug|Win32"
-					>
-					<Tool
-						Name="VCCLCompilerTool"
-						AdditionalIncludeDirectories=""
-						PreprocessorDefinitions=""
-					/>
-				</FileConfiguration>
 			</File>
 			<File
 				RelativePath="..\..\libshout-2.2.2\src\util.h"

Modified: freeswitch/branches/gmaruzz/libs/win32/util.vbs
==============================================================================
--- freeswitch/branches/gmaruzz/libs/win32/util.vbs	(original)
+++ freeswitch/branches/gmaruzz/libs/win32/util.vbs	Mon Dec 15 12:56:36 2008
@@ -250,15 +250,41 @@
 	strVerRev   = FindVersionStringInConfigure(VersionDir & "configure.in", "SWITCH_VERSION_REVISION")
 	
 	If Right(tmpFolder, 1) <> "\" Then tmpFolder = tmpFolder & "\" End If
-	If Not FSO.FileExists(tmpFolder & "svnversion.exe") Then 
-		Wget ToolsBase & "svnversion.exe", tmpFolder
+	If Not FSO.FileExists(tmpFolder & "fs_svnversion.exe") Then 
+		Wget ToolsBase & "fs_svnversion.exe", tmpFolder
 	End If	
+
+	If Not FSO.FileExists(tmpFolder & "libsvn_diff-1.dll") Then 
+		Wget ToolsBase & "libsvn_diff-1.dll", tmpFolder
+	End If	
+	If Not FSO.FileExists(tmpFolder & "libsvn_subr-1.dll") Then 
+		Wget ToolsBase & "libsvn_subr-1.dll", tmpFolder
+	End If	
+	If Not FSO.FileExists(tmpFolder & "libsvn_wc-1.dll") Then 
+		Wget ToolsBase & "libsvn_wc-1.dll", tmpFolder
+	End If	
+	If Not FSO.FileExists(tmpFolder & "intl3_svn.dll") Then 
+		Wget ToolsBase & "intl3_svn.dll", tmpFolder
+	End If	
+	If Not FSO.FileExists(tmpFolder & "libapr-1.dll") Then 
+		Wget ToolsBase & "libapr-1.dll", tmpFolder
+	End If	
+	If Not FSO.FileExists(tmpFolder & "libaprutil-1.dll") Then 
+		Wget ToolsBase & "libaprutil-1.dll", tmpFolder
+	End If	
+	If Not FSO.FileExists(tmpFolder & "libapriconv-1.dll") Then 
+		Wget ToolsBase & "libapriconv-1.dll", tmpFolder
+	End If	
+	If Not FSO.FileExists(tmpFolder & "libsvn_delta-1.dll") Then 
+		Wget ToolsBase & "libsvn_delta-1.dll", tmpFolder
+	End If	
+
 	Dim sLastFile
 	Const OverwriteIfExist = -1
 	Const ForReading       =  1
 
 	if strVerRev = "" Then
-	    VersionCmd="svnversion " & quote & VersionDir & "." & quote &  " -n"
+	    VersionCmd="fs_svnversion " & quote & VersionDir & "." & quote &  " -n"
 	    Set MyFile = fso.CreateTextFile(tmpFolder & "tmpVersion.Bat", True)
 	    MyFile.WriteLine("@" & "cd " & quote & tmpFolder & quote )
 	    MyFile.WriteLine("@" & VersionCmd)

Modified: freeswitch/branches/gmaruzz/scripts/contrib/intralanman/PHP/fs_curl/configuration/xml_cdr.conf.php
==============================================================================
--- freeswitch/branches/gmaruzz/scripts/contrib/intralanman/PHP/fs_curl/configuration/xml_cdr.conf.php	(original)
+++ freeswitch/branches/gmaruzz/scripts/contrib/intralanman/PHP/fs_curl/configuration/xml_cdr.conf.php	Mon Dec 15 12:56:36 2008
@@ -23,7 +23,7 @@
 	}
 
 	function get_settings() {
-	    return array('url'=>'http://localhost/fs_curl/index_test.php', 'encode'=>'true');
+	    return array('url'=>'http://$${curl_host}/fs_curl/cdr.php', 'encode'=>'true');
 		return array(
 		'url'=>'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']
 		, 'encode'=>'true'
@@ -46,4 +46,4 @@
 	}
 }
 
-?>
\ No newline at end of file
+?>

Modified: freeswitch/branches/gmaruzz/scripts/contrib/intralanman/PHP/fs_curl/dialplan_importer.php
==============================================================================
--- freeswitch/branches/gmaruzz/scripts/contrib/intralanman/PHP/fs_curl/dialplan_importer.php	(original)
+++ freeswitch/branches/gmaruzz/scripts/contrib/intralanman/PHP/fs_curl/dialplan_importer.php	Mon Dec 15 12:56:36 2008
@@ -149,4 +149,4 @@
 upload_form();
 
 //printf("<pre>%s</pre>", print_r($xml_obj, true);
-?>
+

Modified: freeswitch/branches/gmaruzz/scripts/contrib/intralanman/PHP/fs_curl/fs_configuration.php
==============================================================================
--- freeswitch/branches/gmaruzz/scripts/contrib/intralanman/PHP/fs_curl/fs_configuration.php	(original)
+++ freeswitch/branches/gmaruzz/scripts/contrib/intralanman/PHP/fs_curl/fs_configuration.php	Mon Dec 15 12:56:36 2008
@@ -89,4 +89,3 @@
     }
 }
 
-?>
\ No newline at end of file

Modified: freeswitch/branches/gmaruzz/scripts/contrib/intralanman/PHP/fs_curl/fs_curl.php
==============================================================================
--- freeswitch/branches/gmaruzz/scripts/contrib/intralanman/PHP/fs_curl/fs_curl.php	(original)
+++ freeswitch/branches/gmaruzz/scripts/contrib/intralanman/PHP/fs_curl/fs_curl.php	Mon Dec 15 12:56:36 2008
@@ -321,4 +321,4 @@
         }
     }
 }
-?>
+

Modified: freeswitch/branches/gmaruzz/scripts/contrib/intralanman/PHP/fs_curl/fs_dialplan.php
==============================================================================
--- freeswitch/branches/gmaruzz/scripts/contrib/intralanman/PHP/fs_curl/fs_dialplan.php	(original)
+++ freeswitch/branches/gmaruzz/scripts/contrib/intralanman/PHP/fs_curl/fs_dialplan.php	Mon Dec 15 12:56:36 2008
@@ -206,4 +206,3 @@
         }
     }
 }
-?>
\ No newline at end of file

Modified: freeswitch/branches/gmaruzz/scripts/contrib/intralanman/PHP/fs_curl/fs_directory.php
==============================================================================
--- freeswitch/branches/gmaruzz/scripts/contrib/intralanman/PHP/fs_curl/fs_directory.php	(original)
+++ freeswitch/branches/gmaruzz/scripts/contrib/intralanman/PHP/fs_curl/fs_directory.php	Mon Dec 15 12:56:36 2008
@@ -275,5 +275,4 @@
         $this -> xmlw -> endElement();
     }
 }
-?>
 

Modified: freeswitch/branches/gmaruzz/scripts/contrib/intralanman/PHP/fs_curl/global_defines.php
==============================================================================
--- freeswitch/branches/gmaruzz/scripts/contrib/intralanman/PHP/fs_curl/global_defines.php	(original)
+++ freeswitch/branches/gmaruzz/scripts/contrib/intralanman/PHP/fs_curl/global_defines.php	Mon Dec 15 12:56:36 2008
@@ -62,4 +62,4 @@
 
 
 //define('', '');
-?>
+

Modified: freeswitch/branches/gmaruzz/scripts/contrib/intralanman/PHP/fs_curl/index.php
==============================================================================
--- freeswitch/branches/gmaruzz/scripts/contrib/intralanman/PHP/fs_curl/index.php	(original)
+++ freeswitch/branches/gmaruzz/scripts/contrib/intralanman/PHP/fs_curl/index.php	Mon Dec 15 12:56:36 2008
@@ -94,4 +94,3 @@
 $conf -> main();
 $conf -> output_xml();
 
-?>
\ No newline at end of file

Modified: freeswitch/branches/gmaruzz/scripts/contrib/mrene/mod_limit/mod_limit.c
==============================================================================
--- freeswitch/branches/gmaruzz/scripts/contrib/mrene/mod_limit/mod_limit.c	(original)
+++ freeswitch/branches/gmaruzz/scripts/contrib/mrene/mod_limit/mod_limit.c	Mon Dec 15 12:56:36 2008
@@ -851,6 +851,44 @@
 	switch_mutex_unlock(globals.limit_hash_mutex);
 }
 
+#define LIMIT_HASH_USAGE_USAGE "<realm> <id>"
+SWITCH_STANDARD_API(limit_hash_usage_function)
+{
+	int argc = 0;
+	char *argv[3] = { 0 };
+	char *mydata = NULL;
+	char *hash_key = NULL;
+	limit_hash_item_t *item = NULL;
+	uint32_t count = 0;
+
+	switch_mutex_lock(globals.limit_hash_mutex);
+	
+	if (!switch_strlen_zero(cmd)) {
+		switch_assert(mydata = strdup(cmd));
+		argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
+	}
+	
+	if (argc < 2) {
+		stream->write_function(stream, "USAGE: limit_hash_usage %s\n", LIMIT_HASH_USAGE_USAGE);
+		goto end;
+	}
+	
+	hash_key = switch_mprintf("%s_%s", argv[0], argv[1]);
+	
+	if ((item = switch_core_hash_find(globals.limit_hash, hash_key))) {
+		count = item->total_usage;
+	} 
+	
+	stream->write_function(stream, "%d", count);
+	
+end:
+	switch_safe_free(mydata);
+	switch_safe_free(hash_key);
+	switch_mutex_unlock(globals.limit_hash_mutex);
+	
+	return SWITCH_STATUS_SUCCESS;
+}
+
 SWITCH_MODULE_LOAD_FUNCTION(mod_limit_load)
 {
 	switch_status_t status;
@@ -880,6 +918,7 @@
 	SWITCH_ADD_APP(app_interface, "hash", "Insert into the hashtable", HASH_DESC, hash_function, HASH_USAGE, SAF_SUPPORT_NOMEDIA)
 	SWITCH_ADD_APP(app_interface, "group", "Manage a group", GROUP_DESC, group_function, GROUP_USAGE, SAF_SUPPORT_NOMEDIA);
 
+	SWITCH_ADD_API(commands_api_interface, "limit_hash_usage", "Gets the usage count of a limited resource", limit_hash_usage_function,  LIMIT_HASH_USAGE_USAGE);
 	SWITCH_ADD_API(commands_api_interface, "db", "db get/set", db_api_function, "[insert|delete|select]/<realm>/<key>/<value>");
 	switch_console_set_complete("add db insert");
 	switch_console_set_complete("add db delete");

Modified: freeswitch/branches/gmaruzz/scripts/fsxs.in
==============================================================================
--- freeswitch/branches/gmaruzz/scripts/fsxs.in	(original)
+++ freeswitch/branches/gmaruzz/scripts/fsxs.in	Mon Dec 15 12:56:36 2008
@@ -177,12 +177,14 @@
 
 sub fsxs_showq {
 	my @varlist = @_;
+	my $count = 0;
 
 	if( $#varlist >= 0 ) {
 		foreach( @varlist ) {
 			if( defined $vars{$_} ) {
-				print "$vars{$_} ";
+				print "$vars{$_}" . (($count < $#varlist) ? " " : "");
 			}
+			$count++;
 		}
 	}
 }

Modified: freeswitch/branches/gmaruzz/src/include/private/switch_core_pvt.h
==============================================================================
--- freeswitch/branches/gmaruzz/src/include/private/switch_core_pvt.h	(original)
+++ freeswitch/branches/gmaruzz/src/include/private/switch_core_pvt.h	Mon Dec 15 12:56:36 2008
@@ -118,6 +118,8 @@
 
 	switch_mutex_t *mutex;
 	switch_mutex_t *resample_mutex;
+	switch_mutex_t *codec_read_mutex;
+	switch_mutex_t *codec_write_mutex;
 	switch_thread_cond_t *cond;
 
 	switch_thread_rwlock_t *rwlock;

Modified: freeswitch/branches/gmaruzz/src/include/switch.h
==============================================================================
--- freeswitch/branches/gmaruzz/src/include/switch.h	(original)
+++ freeswitch/branches/gmaruzz/src/include/switch.h	Mon Dec 15 12:56:36 2008
@@ -54,7 +54,7 @@
 #define FREESWITCH_ITAD "543"
 #define __EXTENSIONS__ 1
 #ifndef MACOSX
-#if !defined(_XOPEN_SOURCE) && !defined(__OpenBSD__)
+#if !defined(_XOPEN_SOURCE) && !defined(__OpenBSD__) && !defined(__NetBSD__)
 #ifndef __cplusplus
 #define _XOPEN_SOURCE 600
 #endif

Modified: freeswitch/branches/gmaruzz/src/include/switch_apr.h
==============================================================================
--- freeswitch/branches/gmaruzz/src/include/switch_apr.h	(original)
+++ freeswitch/branches/gmaruzz/src/include/switch_apr.h	Mon Dec 15 12:56:36 2008
@@ -1123,6 +1123,7 @@
  */
 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_atmark(switch_socket_t *sock, int *atmark);
 
 /**
  * Read data from a network.

Modified: freeswitch/branches/gmaruzz/src/include/switch_channel.h
==============================================================================
--- freeswitch/branches/gmaruzz/src/include/switch_channel.h	(original)
+++ freeswitch/branches/gmaruzz/src/include/switch_channel.h	Mon Dec 15 12:56:36 2008
@@ -145,7 +145,7 @@
   \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_channel_flag_t flag);
 
 /*!
   \brief Fire A presence event for the channel
@@ -259,49 +259,49 @@
 SWITCH_DECLARE(switch_caller_extension_t *) switch_channel_get_caller_extension(switch_channel_t *channel);
 
 /*!
-  \brief Test for presence of given flag(s) on a given channel
+  \brief Test for presence of given flag on a given channel
   \param channel channel to test 
-  \param flags or'd list of channel flags to test
+  \param flag to test
   \return TRUE if flags were present
 */
-SWITCH_DECLARE(uint32_t) switch_channel_test_flag(switch_channel_t *channel, switch_channel_flag_t flags);
+SWITCH_DECLARE(uint32_t) switch_channel_test_flag(switch_channel_t *channel, switch_channel_flag_t flag);
 
 /*!
   \brief Set given flag(s) on a given channel
-  \param channel channel on which to set flag(s)
-  \param flags or'd list of flags to set
+  \param channel channel on which to set flag
+  \param flag or'd list of flags to set
 */
-SWITCH_DECLARE(void) switch_channel_set_flag(switch_channel_t *channel, switch_channel_flag_t flags);
+SWITCH_DECLARE(void) switch_channel_set_flag(switch_channel_t *channel, switch_channel_flag_t flag);
 
 /*!
   \brief Set given flag(s) on a given channel's bridge partner
-  \param channel channel to derive the partner channel to set flag(s) on
-  \param flags or'd list of flags to set
+  \param channel channel to derive the partner channel to set flag on
+  \param flag to set
   \return true if the flag was set
 */
-SWITCH_DECLARE(switch_bool_t) switch_channel_set_flag_partner(switch_channel_t *channel, switch_channel_flag_t flags);
+SWITCH_DECLARE(switch_bool_t) switch_channel_set_flag_partner(switch_channel_t *channel, switch_channel_flag_t flag);
 
 /*!
   \brief Clears given flag(s) on a given channel's bridge partner
   \param channel channel to derive the partner channel to clear flag(s) from
-  \param flags the flags to clear
+  \param flag the flag to clear
   \return true if the flag was cleared
 */
-SWITCH_DECLARE(switch_bool_t) switch_channel_clear_flag_partner(switch_channel_t *channel, switch_channel_flag_t flags);
+SWITCH_DECLARE(switch_bool_t) switch_channel_clear_flag_partner(switch_channel_t *channel, switch_channel_flag_t flag);
 
 /*!
   \brief Set given flag(s) on a given channel to be applied on the next state change
   \param channel channel on which to set flag(s)
-  \param flags or'd list of flags to set
+  \param flag flag to set
 */
-SWITCH_DECLARE(void) switch_channel_set_state_flag(switch_channel_t *channel, switch_channel_flag_t flags);
+SWITCH_DECLARE(void) switch_channel_set_state_flag(switch_channel_t *channel, switch_channel_flag_t flag);
 
 /*!
   \brief Clear given flag(s) from a channel
   \param channel channel to clear flags from
-  \param flags or'd list of flags to clear
+  \param flag flag to clear
 */
-SWITCH_DECLARE(void) switch_channel_clear_flag(switch_channel_t *channel, switch_channel_flag_t flags);
+SWITCH_DECLARE(void) switch_channel_clear_flag(switch_channel_t *channel, switch_channel_flag_t flag);
 
 SWITCH_DECLARE(switch_status_t) switch_channel_perform_answer(switch_channel_t *channel, const char *file, const char *func, int line);
 
@@ -484,10 +484,16 @@
 														 _In_opt_ const char *prefix);
 SWITCH_DECLARE(switch_status_t) switch_channel_set_timestamps(_In_ switch_channel_t *channel);
 
-#define switch_channel_stop_broadcast(_channel)	if (switch_channel_test_flag(_channel, CF_BROADCAST)) switch_channel_set_flag(_channel, CF_BREAK | CF_STOP_BROADCAST)
+#define switch_channel_stop_broadcast(_channel)	for(;;) {if (switch_channel_test_flag(_channel, CF_BROADCAST)) {switch_channel_set_flag(_channel, CF_STOP_BROADCAST); switch_channel_set_flag(_channel, CF_BREAK); } break;}
 
 #define switch_channel_media_ready(_channel) ((switch_channel_test_flag(_channel, CF_ANSWERED) || switch_channel_test_flag(_channel, CF_EARLY_MEDIA)) && !switch_channel_test_flag(_channel, CF_PROXY_MODE))
 
+SWITCH_DECLARE(void) switch_channel_audio_sync(switch_channel_t *channel);
+
+SWITCH_DECLARE(void) switch_channel_set_private_flag(switch_channel_t *channel, uint32_t flags);
+SWITCH_DECLARE(void) switch_channel_clear_private_flag(switch_channel_t *channel, uint32_t flags);
+SWITCH_DECLARE(int) switch_channel_test_private_flag(switch_channel_t *channel, uint32_t flags);
+
 /** @} */
 
 SWITCH_END_EXTERN_C

Modified: freeswitch/branches/gmaruzz/src/include/switch_core.h
==============================================================================
--- freeswitch/branches/gmaruzz/src/include/switch_core.h	(original)
+++ freeswitch/branches/gmaruzz/src/include/switch_core.h	Mon Dec 15 12:56:36 2008
@@ -92,6 +92,7 @@
 	const char *_file;
 	const char *_func;
 	int _line;
+
 };
 
 /*! \brief A generic object to pass as a thread's session object to allow mutiple arguements and a pool */
@@ -320,6 +321,22 @@
 
 
 #ifdef SWITCH_DEBUG_RWLOCKS
+SWITCH_DECLARE(switch_status_t) switch_core_session_perform_read_lock_hangup(_In_ switch_core_session_t *session, const char *file, const char *func, int line);
+#endif
+
+/*! 
+  \brief Acquire a read lock on the session
+  \param session the session to acquire from
+  \return success if it is safe to read from the session
+*/
+#ifdef SWITCH_DEBUG_RWLOCKS
+#define switch_core_session_read_lock(session) switch_core_session_perform_read_lock_hangup(session, __FILE__, __SWITCH_FUNC__, __LINE__)
+#else
+SWITCH_DECLARE(switch_status_t) switch_core_session_read_lock_hangup(_In_ switch_core_session_t *session);
+#endif
+
+
+#ifdef SWITCH_DEBUG_RWLOCKS
 SWITCH_DECLARE(void) switch_core_session_perform_write_lock(_In_ switch_core_session_t *session, const char *file, const char *func, int line);
 #endif
 

Modified: freeswitch/branches/gmaruzz/src/include/switch_cpp.h
==============================================================================
--- freeswitch/branches/gmaruzz/src/include/switch_cpp.h	(original)
+++ freeswitch/branches/gmaruzz/src/include/switch_cpp.h	Mon Dec 15 12:56:36 2008
@@ -313,7 +313,7 @@
 	 *
 	 */
 		 SWITCH_DECLARE(int) streamFile(char *file, int starting_sample_count = 0);
-		 SWITCH_DECLARE(int) sleep(int ms);
+		 SWITCH_DECLARE(int) sleep(int ms, int sync=0);
 
 	/** \brief flush any pending events
 	 */
@@ -373,6 +373,7 @@
 
 SWITCH_DECLARE(void) console_log(char *level_str, char *msg);
 SWITCH_DECLARE(void) console_clean_log(char *msg);
+SWITCH_DECLARE(void) msleep(unsigned ms);
 
 /** \brief bridge the audio of session_b into session_a
  * 

Modified: freeswitch/branches/gmaruzz/src/include/switch_ivr.h
==============================================================================
--- freeswitch/branches/gmaruzz/src/include/switch_ivr.h	(original)
+++ freeswitch/branches/gmaruzz/src/include/switch_ivr.h	Mon Dec 15 12:56:36 2008
@@ -110,7 +110,7 @@
   \param args arguements to pass for callbacks etc
   \return SWITCH_STATUS_SUCCESS if the channel is still up
 */
-SWITCH_DECLARE(switch_status_t) switch_ivr_sleep(switch_core_session_t *session, uint32_t ms, switch_input_args_t *args);
+SWITCH_DECLARE(switch_status_t) switch_ivr_sleep(switch_core_session_t *session, uint32_t ms, switch_bool_t sync, switch_input_args_t *args);
 
 SWITCH_DECLARE(switch_status_t) switch_ivr_park(switch_core_session_t *session, switch_input_args_t *args);
 
@@ -298,7 +298,8 @@
 */
 SWITCH_DECLARE(switch_status_t) switch_ivr_tone_detect_session(switch_core_session_t *session,
 															   const char *key, const char *tone_spec,
-															   const char *flags, time_t timeout, const char *app, const char *data);
+															   const char *flags, time_t timeout, int hits, const char *app, const char *data);
+
 
 
 
@@ -397,7 +398,10 @@
 													 const switch_state_handler_table_t *table,
 													 const char *cid_name_override,
 													 const char *cid_num_override,
-													 switch_caller_profile_t *caller_profile_override, switch_originate_flag_t flags);
+													 switch_caller_profile_t *caller_profile_override, 
+													 switch_event_t *ovars,
+													 switch_originate_flag_t flags
+													 );
 
 /*!
   \brief Bridge Audio from one session to another

Modified: freeswitch/branches/gmaruzz/src/include/switch_module_interfaces.h
==============================================================================
--- freeswitch/branches/gmaruzz/src/include/switch_module_interfaces.h	(original)
+++ freeswitch/branches/gmaruzz/src/include/switch_module_interfaces.h	Mon Dec 15 12:56:36 2008
@@ -173,6 +173,7 @@
 
 	switch_thread_rwlock_t *rwlock;
 	int refs;
+	switch_mutex_t *reflock;
 
 	/* parent */
 	switch_loadable_module_interface_t *parent;
@@ -228,6 +229,7 @@
 	switch_status_t (*timer_destroy) (switch_timer_t *);
 	switch_thread_rwlock_t *rwlock;
 	int refs;
+	switch_mutex_t *reflock;
 	switch_loadable_module_interface_t *parent;
 	struct switch_timer_interface *next;
 };
@@ -240,6 +242,7 @@
 	switch_dialplan_hunt_function_t hunt_function;
 	switch_thread_rwlock_t *rwlock;
 	int refs;
+	switch_mutex_t *reflock;
 	switch_loadable_module_interface_t *parent;
 	struct switch_dialplan_interface *next;
 };
@@ -266,6 +269,7 @@
 	char **extens;
 	switch_thread_rwlock_t *rwlock;
 	int refs;
+	switch_mutex_t *reflock;
 	switch_loadable_module_interface_t *parent;
 	struct switch_file_interface *next;
 };
@@ -345,6 +349,7 @@
 	switch_status_t (*asr_get_results) (switch_asr_handle_t *ah, char **xmlstr, switch_asr_flag_t *flags);
 	switch_thread_rwlock_t *rwlock;
 	int refs;
+	switch_mutex_t *reflock;
 	switch_loadable_module_interface_t *parent;
 	struct switch_asr_interface *next;
 };
@@ -388,6 +393,7 @@
 	void (*speech_float_param_tts) (switch_speech_handle_t *sh, char *param, double val);
 	switch_thread_rwlock_t *rwlock;
 	int refs;
+	switch_mutex_t *reflock;
 	switch_loadable_module_interface_t *parent;
 	struct switch_speech_interface *next;
 };
@@ -423,6 +429,7 @@
 	switch_say_callback_t say_function;
 	switch_thread_rwlock_t *rwlock;
 	int refs;
+	switch_mutex_t *reflock;
 	switch_loadable_module_interface_t *parent;
 	struct switch_say_interface *next;
 };
@@ -435,6 +442,7 @@
 	switch_status_t (*chat_send) (char *proto, char *from, char *to, char *subject, char *body, char *hint);
 	switch_thread_rwlock_t *rwlock;
 	int refs;
+	switch_mutex_t *reflock;
 	switch_loadable_module_interface_t *parent;
 	struct switch_chat_interface *next;
 };
@@ -447,6 +455,7 @@
 	switch_status_t (*management_function) (char *relative_oid, switch_management_action_t action, char *data, switch_size_t datalen);
 	switch_thread_rwlock_t *rwlock;
 	int refs;
+	switch_mutex_t *reflock;
 	switch_loadable_module_interface_t *parent;
 	struct switch_management_interface *next;
 };
@@ -467,6 +476,7 @@
 	switch_status_t (*directory_next_pair) (switch_directory_handle_t *dh, char **var, char **val);
 	switch_thread_rwlock_t *rwlock;
 	int refs;
+	switch_mutex_t *reflock;
 	switch_loadable_module_interface_t *parent;
 	struct switch_directory_interface *next;
 };
@@ -593,6 +603,7 @@
 	uint32_t codec_id;
 	switch_thread_rwlock_t *rwlock;
 	int refs;
+	switch_mutex_t *reflock;
 	switch_loadable_module_interface_t *parent;
 	struct switch_codec_interface *next;
 };
@@ -613,6 +624,7 @@
 	uint32_t flags;
 	switch_thread_rwlock_t *rwlock;
 	int refs;
+	switch_mutex_t *reflock;
 	switch_loadable_module_interface_t *parent;
 	struct switch_application_interface *next;
 };
@@ -629,12 +641,14 @@
 	const char *syntax;
 	switch_thread_rwlock_t *rwlock;
 	int refs;
+	switch_mutex_t *reflock;
 	switch_loadable_module_interface_t *parent;
 	struct switch_api_interface *next;
 };
 
-#define PROTECT_INTERFACE(_it) if (_it && !_it->refs) {switch_thread_rwlock_rdlock(_it->parent->rwlock); switch_thread_rwlock_rdlock(_it->rwlock); _it->refs++; _it->parent->refs++;} //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "+++++++++++LOCK\n");
-#define UNPROTECT_INTERFACE(_it) if (_it && _it->refs) {switch_thread_rwlock_unlock(_it->rwlock); switch_thread_rwlock_unlock(_it->parent->rwlock); _it->refs--; _it->parent->refs--; _it = NULL;} //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "-----------UNLOCK\n");
+#define PROTECT_INTERFACE(_it) if (_it) {switch_mutex_lock(_it->reflock); switch_thread_rwlock_rdlock(_it->parent->rwlock); switch_thread_rwlock_rdlock(_it->rwlock); _it->refs++; _it->parent->refs++; switch_mutex_unlock(_it->reflock);} //if (!strcmp(_it->interface_name, "user")) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "+++++++++++LOCK %s %d/%d\n", _it->interface_name, _it->refs, _it->parent->refs);
+#define UNPROTECT_INTERFACE(_it) if (_it) {switch_mutex_lock(_it->reflock); switch_thread_rwlock_unlock(_it->rwlock); switch_thread_rwlock_unlock(_it->parent->rwlock); _it->refs--; _it->parent->refs--; switch_mutex_unlock(_it->reflock);} //if (!strcmp(_it->interface_name, "user")) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "---------UNLOCK %s %d/%d\n", _it->interface_name, _it->refs, _it->parent->refs);
+
 
 SWITCH_END_EXTERN_C
 #endif

Modified: freeswitch/branches/gmaruzz/src/include/switch_odbc.h
==============================================================================
--- freeswitch/branches/gmaruzz/src/include/switch_odbc.h	(original)
+++ freeswitch/branches/gmaruzz/src/include/switch_odbc.h	Mon Dec 15 12:56:36 2008
@@ -64,8 +64,35 @@
 SWITCH_DECLARE(void) switch_odbc_handle_destroy(switch_odbc_handle_t **handlep);
 SWITCH_DECLARE(switch_odbc_state_t) switch_odbc_handle_get_state(switch_odbc_handle_t *handle);
 SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec(switch_odbc_handle_t *handle, char *sql, SQLHSTMT * rstmt);
-SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_callback_exec(switch_odbc_handle_t *handle,
+
+/*!
+  \brief Execute the sql query and issue a callback for each row returned
+  \param file the file from which this function is called
+  \param func the function from which this function is called
+  \param line the line from which this function is called
+  \param handle the ODBC handle
+  \param sql the sql string to execute
+  \param callback the callback function to execute
+  \param pdata the state data passed on each callback invocation
+  \return SWITCH_STATUS_SUCCESS if the operation was successful
+  \note none
+*/
+SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_callback_exec_detailed(const char *file, const char *func, int line, switch_odbc_handle_t *handle,
 																	  char *sql, switch_core_db_callback_func_t callback, void *pdata);
+/*!
+  \brief Execute the sql query and issue a callback for each row returned
+  \param handle the ODBC handle
+  \param sql the sql string to execute
+  \param callback the callback function to execute
+  \param pdata the state data passed on each callback invocation
+  \return SWITCH_STATUS_SUCCESS if the operation was successful
+  \note none
+*/
+#define switch_odbc_handle_callback_exec(handle,  sql,  callback, pdata) \
+		switch_odbc_handle_callback_exec_detailed(__FILE__, (char * )__SWITCH_FUNC__, __LINE__, \
+												  handle, sql, callback, pdata)
+
+																	  
 SWITCH_DECLARE(char *) switch_odbc_handle_get_error(switch_odbc_handle_t *handle, SQLHSTMT stmt);
 SWITCH_END_EXTERN_C
 #endif

Modified: freeswitch/branches/gmaruzz/src/include/switch_rtp.h
==============================================================================
--- freeswitch/branches/gmaruzz/src/include/switch_rtp.h	(original)
+++ freeswitch/branches/gmaruzz/src/include/switch_rtp.h	Mon Dec 15 12:56:36 2008
@@ -111,7 +111,7 @@
 SWITCH_DECLARE(switch_port_t) switch_rtp_request_port(const char *ip);
 SWITCH_DECLARE(void) switch_rtp_release_port(const char *ip, switch_port_t port);
 
-SWITCH_DECLARE(void) switch_rtp_change_interval(switch_rtp_t *rtp_session, uint32_t ms_per_packet, uint32_t samples_per_interval);
+SWITCH_DECLARE(switch_status_t) switch_rtp_change_interval(switch_rtp_t *rtp_session, uint32_t ms_per_packet, uint32_t samples_per_interval);
 /*! 
   \brief create a new RTP session handle
   \param new_rtp_session a poiter to aim at the new session
@@ -351,6 +351,8 @@
 */
 SWITCH_DECLARE(switch_status_t) switch_rtp_zerocopy_read_frame(switch_rtp_t *rtp_session, switch_frame_t *frame, switch_io_flag_t io_flags);
 
+SWITCH_DECLARE(void) rtp_flush_read_buffer(switch_rtp_t *rtp_session);
+
 /*!
   \brief Enable VAD on an RTP Session
   \param rtp_session the RTP session

Modified: freeswitch/branches/gmaruzz/src/include/switch_stun.h
==============================================================================
--- freeswitch/branches/gmaruzz/src/include/switch_stun.h	(original)
+++ freeswitch/branches/gmaruzz/src/include/switch_stun.h	Mon Dec 15 12:56:36 2008
@@ -147,6 +147,7 @@
 */
 SWITCH_DECLARE(const char *) switch_stun_value_to_name(int32_t type, uint32_t value);
 
+SWITCH_DECLARE(char *) switch_stun_host_lookup(const char *host, switch_memory_pool_t *pool);
 
 /*!
   \brief Extract a mapped address (IP:PORT) from a packet attribute

Modified: freeswitch/branches/gmaruzz/src/include/switch_types.h
==============================================================================
--- freeswitch/branches/gmaruzz/src/include/switch_types.h	(original)
+++ freeswitch/branches/gmaruzz/src/include/switch_types.h	Mon Dec 15 12:56:36 2008
@@ -110,6 +110,10 @@
 #define SWITCH_PATH_SEPARATOR "/"
 #endif
 #define SWITCH_URL_SEPARATOR "://"
+#define SWITCH_SEND_SILENCE_WHEN_IDLE_VARIABLE "send_silence_when_idle"
+#define SWITCH_CURRENT_APPLICATION_VARIABLE "current_application"
+#define SWITCH_CURRENT_APPLICATION_DATA_VARIABLE "current_application_data"
+#define SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE "current_application_response"
 #define SWITCH_ENABLE_HEARTBEAT_EVENTS_VARIABLE "enable_heartbeat_events"
 #define SWITCH_BYPASS_MEDIA_AFTER_BRIDGE_VARIABLE "bypass_media_after_bridge"
 #define SWITCH_READ_RESULT_VARIABLE "read_result"
@@ -122,6 +126,7 @@
 #define SWITCH_HOLDING_UUID_VARIABLE "holding_uuid"
 #define SWITCH_API_BRIDGE_END_VARIABLE "api_after_bridge"
 #define SWITCH_API_HANGUP_HOOK_VARIABLE "api_hangup_hook"
+#define SWITCH_SESSION_IN_HANGUP_HOOK_VARIABLE "session_in_hangup_hook"
 #define SWITCH_PROCESS_CDR_VARIABLE "process_cdr"
 #define SWITCH_BRIDGE_CHANNEL_VARIABLE "bridge_channel"
 #define SWITCH_CHANNEL_NAME_VARIABLE "channel_name"
@@ -450,7 +455,8 @@
 	SWITCH_RTP_FLAG_SECURE_SEND_RESET = (1 << 16),
 	SWITCH_RTP_FLAG_SECURE_RECV_RESET = (1 << 17),
 	SWITCH_RTP_FLAG_PROXY_MEDIA = (1 << 18),
-	SWITCH_RTP_FLAG_SHUTDOWN = (1 << 19)
+	SWITCH_RTP_FLAG_SHUTDOWN = (1 << 19),
+	SWITCH_RTP_FLAG_FLUSH = (1 << 20)
 } switch_rtp_flag_enum_t;
 typedef uint32_t switch_rtp_flag_t;
 
@@ -567,6 +573,7 @@
 	SWITCH_MESSAGE_INDICATE_VIDEO_REFRESH_REQ,
 	SWITCH_MESSAGE_INDICATE_DISPLAY,
 	SWITCH_MESSAGE_INDICATE_TRANSCODING_NECESSARY,
+	SWITCH_MESSAGE_INDICATE_AUDIO_SYNC,
 	SWITCH_MESSAGE_INVALID
 } switch_core_session_message_types_t;
 
@@ -675,7 +682,9 @@
 } switch_text_channel_t;
 
 typedef enum {
-	SCSMF_DYNAMIC = (1 << 0)
+	SCSMF_DYNAMIC = (1 << 0),
+	SCSMF_FREE_STRING_REPLY = (1 << 1),
+	SCSMF_FREE_POINTER_REPLY = (1 << 2),
 } switch_core_session_message_flag_enum_t;
 typedef uint32_t switch_core_session_message_flag_t;
 
@@ -723,71 +732,70 @@
   \brief Channel Flags
 
 <pre>
-CF_ANSWERED     = (1 <<  0) - Channel is answered
-CF_OUTBOUND     = (1 <<  1) - Channel is an outbound channel
-CF_EARLY_MEDIA  = (1 <<  2) - Channel is ready for audio before answer 
-CF_ORIGINATOR	= (1 <<  3) - Channel is an originator
-CF_TRANSFER		= (1 <<  4) - Channel is being transfered
-CF_ACCEPT_CNG	= (1 <<  5) - Channel will accept CNG frames
-CF_WAIT_FOR_ME	= (1 <<  6) - Channel wants you to wait
-CF_BRIDGED		= (1 <<  7) - Channel in a bridge
-CF_HOLD			= (1 <<  8) - Channel is on hold
-CF_SERVICE		= (1 <<  9) - Channel has a service thread
-CF_TAGGED		= (1 << 10) - Channel is tagged
-CF_WINNER		= (1 << 11) - Channel is the winner
-CF_CONTROLLED	= (1 << 12) - Channel is under control
-CF_PROXY_MODE		= (1 << 13) - Channel has no media
-CF_SUSPEND		= (1 << 14) - Suspend i/o
-CF_EVENT_PARSE  = (1 << 15) - Suspend control events
-CF_REPEAT_STATE = (1 << 16) - Tell the state machine to repeat a state
-CF_GEN_RINGBACK = (1 << 17) - Channel is generating it's own ringback
-CF_RING_READY   = (1 << 18) - Channel is ready to send ringback
-CF_BREAK        = (1 << 19) - Channel should stop what it's doing
-CF_BROADCAST    = (1 << 20) - Channel is broadcasting
-CF_UNICAST      = (1 << 21) - Channel has a unicast connection
-CF_VIDEO		= (1 << 22) - Channel has video
-CF_EVENT_LOCK   = (1 << 23) - Don't parse events
-CF_RESET        = (1 << 24) - Tell extension parser to reset
-CF_ORIGINATING  = (1 << 25) - Channel is originating
-CF_STOP_BROADCAST = (1 << 26) - Signal to stop broadcast
+CF_ANSWERED			- Channel is answered
+CF_OUTBOUND			- Channel is an outbound channel
+CF_EARLY_MEDIA		- Channel is ready for audio before answer 
+CF_ORIGINATOR		- Channel is an originator
+CF_TRANSFER			- Channel is being transfered
+CF_ACCEPT_CNG		- Channel will accept CNG frames
+CF_REDIRECT 		- Channel is being redirected
+CF_BRIDGED			- Channel in a bridge
+CF_HOLD				- Channel is on hold
+CF_SERVICE			- Channel has a service thread
+CF_TAGGED			- Channel is tagged
+CF_WINNER			- Channel is the winner
+CF_CONTROLLED		- Channel is under control
+CF_PROXY_MODE		- Channel has no media
+CF_SUSPEND			- Suspend i/o
+CF_EVENT_PARSE		- Suspend control events
+CF_GEN_RINGBACK		- Channel is generating it's own ringback
+CF_RING_READY		- Channel is ready to send ringback
+CF_BREAK			- Channel should stop what it's doing
+CF_BROADCAST		- Channel is broadcasting
+CF_UNICAST			- Channel has a unicast connection
+CF_VIDEO			- Channel has video
+CF_EVENT_LOCK		- Don't parse events
+CF_RESET			- Tell extension parser to reset
+CF_ORIGINATING		- Channel is originating
+CF_STOP_BROADCAST	- Signal to stop broadcast
 </pre>
  */
 
 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_WAIT_FOR_ME = (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_PROXY_MODE = (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_BREAK = (1 << 19),
-	CF_BROADCAST = (1 << 20),
-	CF_UNICAST = (1 << 21),
-	CF_VIDEO = (1 << 22),
-	CF_EVENT_LOCK = (1 << 23),
-	CF_RESET = (1 << 24),
-	CF_ORIGINATING = (1 << 25),
-	CF_STOP_BROADCAST = (1 << 26),
-	CF_PROXY_MEDIA = (1 << 27),
-	CF_INNER_BRIDGE = (1 << 28),
-	CF_REQ_MEDIA = (1 << 29),
-	CF_VERBOSE_EVENTS = (1 << 30)
-} switch_channel_flag_enum_t;
-typedef uint32_t switch_channel_flag_t;
-
+	CF_ANSWERED = 1,
+	CF_OUTBOUND,
+	CF_EARLY_MEDIA,
+	CF_ORIGINATOR,
+	CF_TRANSFER,
+	CF_ACCEPT_CNG,
+	CF_REDIRECT,
+	CF_BRIDGED,
+	CF_HOLD,
+	CF_SERVICE,
+	CF_TAGGED,
+	CF_WINNER,
+	CF_CONTROLLED,
+	CF_PROXY_MODE,
+	CF_SUSPEND,
+	CF_EVENT_PARSE,
+	CF_GEN_RINGBACK,
+	CF_RING_READY,
+	CF_BREAK,
+	CF_BROADCAST,
+	CF_UNICAST,
+	CF_VIDEO,
+	CF_EVENT_LOCK,
+	CF_RESET,
+	CF_ORIGINATING,
+	CF_STOP_BROADCAST,
+	CF_PROXY_MEDIA,
+	CF_INNER_BRIDGE,
+	CF_REQ_MEDIA,
+	CF_VERBOSE_EVENTS,
+
+	/* WARNING: DO NOT ADD ANY FLAGS BELOW THIS LINE */
+	CF_FLAG_MAX
+} switch_channel_flag_t;
 
 /*!
   \enum switch_frame_flag_t
@@ -1058,6 +1066,7 @@
 	SWITCH_EVENT_DTMF				- DTMF was sent
 	SWITCH_EVENT_MESSAGE			- A Basic Message
 	SWITCH_EVENT_PRESENCE_IN		- Presence in
+	SWITCH_EVENT_NOTIFY_IN			- Received incoming NOTIFY from gateway subscription
 	SWITCH_EVENT_PRESENCE_OUT		- Presence out
 	SWITCH_EVENT_PRESENCE_PROBE		- Presence probe
 	SWITCH_EVENT_MESSAGE_WAITING	- A message is waiting
@@ -1116,6 +1125,7 @@
 	SWITCH_EVENT_DTMF,
 	SWITCH_EVENT_MESSAGE,
 	SWITCH_EVENT_PRESENCE_IN,
+	SWITCH_EVENT_NOTIFY_IN,
 	SWITCH_EVENT_PRESENCE_OUT,
 	SWITCH_EVENT_PRESENCE_PROBE,
 	SWITCH_EVENT_MESSAGE_WAITING,

Modified: freeswitch/branches/gmaruzz/src/include/switch_utils.h
==============================================================================
--- freeswitch/branches/gmaruzz/src/include/switch_utils.h	(original)
+++ freeswitch/branches/gmaruzz/src/include/switch_utils.h	Mon Dec 15 12:56:36 2008
@@ -41,6 +41,22 @@
 #include <switch.h>
 
 SWITCH_BEGIN_EXTERN_C
+
+SWITCH_DECLARE(int) switch_toupper(int c);
+SWITCH_DECLARE(int) switch_tolower(int c);
+SWITCH_DECLARE(int) switch_isalnum(int c);
+SWITCH_DECLARE(int) switch_isalpha(int c);
+SWITCH_DECLARE(int) switch_iscntrl(int c);
+SWITCH_DECLARE(int) switch_isdigit(int c);
+SWITCH_DECLARE(int) switch_isgraph(int c);
+SWITCH_DECLARE(int) switch_islower(int c);
+SWITCH_DECLARE(int) switch_isprint(int c);
+SWITCH_DECLARE(int) switch_ispunct(int c);
+SWITCH_DECLARE(int) switch_isspace(int c);
+SWITCH_DECLARE(int) switch_isupper(int c);
+SWITCH_DECLARE(int) switch_isxdigit(int c);
+
+
 #define switch_samples_per_packet(rate, interval) ((uint32_t)((float)rate / (1000.0f / (float)interval)))
 #define SWITCH_SMAX 32767
 #define SWITCH_SMIN -32768
@@ -211,7 +227,7 @@
   \param key the key to test
   \return TRUE or FALSE
  */
-#define is_dtmf(key)  ((key > 47 && key < 58) || (key > 64 && key < 69) || (key > 96 && key < 101) || key == 35 || key == 42 || key == 87 || key == 119)
+#define is_dtmf(key)  ((key > 47 && key < 58) || (key > 64 && key < 69) || (key > 96 && key < 101) || key == 35 || key == 42 || key == 87 || key == 119 || key == 70)
 
 #define end_of(_s) *(*_s == '\0' ? _s : _s + strlen(_s) - 1)
 #define end_of_p(_s) (*_s == '\0' ? _s : _s + strlen(_s) - 1)
@@ -303,7 +319,7 @@
 	if (it) {
 		dup = strdup(it);
 		for(p = dup; p && *p; p++) {
-			*p = (char) tolower(*p);
+			*p = (char) switch_tolower(*p);
 		}
 		return dup;
 	}
@@ -320,7 +336,7 @@
 	if (it) {
 		dup = strdup(it);
 		for(p = dup; p && *p; p++) {
-			*p = (char) toupper(*p);
+			*p = (char) switch_toupper(*p);
 		}
 		return dup;
 	}
@@ -353,7 +369,7 @@
 	assert(S != NULL);
 
 	for (p = S; p && *p; p++) {
-		*p = (char) toupper(*p);
+		*p = (char) switch_toupper(*p);
 	}
 
 	if (strstr(S, q)) {
@@ -365,7 +381,7 @@
 	assert(Q != NULL);
 
 	for (p = Q; p && *p; p++) {
-		*p = (char) toupper(*p);
+		*p = (char) switch_toupper(*p);
 	}
 
 	if (strstr(s, Q)) {

Modified: freeswitch/branches/gmaruzz/src/mod/applications/mod_commands/mod_commands.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/applications/mod_commands/mod_commands.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/applications/mod_commands/mod_commands.c	Mon Dec 15 12:56:36 2008
@@ -704,13 +704,14 @@
 
 	if (stream->param_event) {
 		http = switch_event_get_header(stream->param_event, "http-host");
+		if ((var = switch_event_get_header(stream->param_event, "content-type"))) {
+			if (!strcasecmp(var, "text/plain")) {
+				http = NULL;
+			}
+		}
 	}
 
-	if ((var = switch_event_get_header(stream->param_event, "content-type"))) {
-		if (!strcasecmp(var, "text/plain")) {
-			http = NULL;
-		}
-	} else {
+	if (http) {
 		stream->write_function(stream, "%s", "Content-Type: text/html\n\n");
 	}
 
@@ -1127,8 +1128,8 @@
 		} else if (!strcasecmp(arg, "both")) {
 			if (uuid && (other_session = switch_core_session_locate(uuid))) {
 				switch_channel_t *other_channel = switch_core_session_get_channel(other_session);
-				switch_channel_set_flag(other_channel, CF_TRANSFER);
-				switch_channel_set_flag(channel, CF_TRANSFER);
+				switch_channel_set_flag(other_channel, CF_REDIRECT);
+				switch_channel_set_flag(channel, CF_REDIRECT);
 				switch_ivr_session_transfer(other_session, dest, dp, context);
 				switch_core_session_rwunlock(other_session);
 			}
@@ -1148,14 +1149,15 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-#define TONE_DETECT_SYNTAX "<uuid> <key> <tone_spec> [<flags> <timeout> <app> <args>]"
+#define TONE_DETECT_SYNTAX "<uuid> <key> <tone_spec> [<flags> <timeout> <app> <args> <hits>]"
 SWITCH_STANDARD_API(tone_detect_session_function)
 {
-	char *argv[7] = { 0 };
+	char *argv[8] = { 0 };
 	int argc;
 	char *mydata = NULL;
 	time_t to = 0;
 	switch_core_session_t *rsession;
+	int hits = 1;
 
 	if (!cmd) {
 		stream->write_function(stream, "-USAGE: %s\n", TONE_DETECT_SYNTAX);
@@ -1193,7 +1195,14 @@
 		}
 	}
 
-	switch_ivr_tone_detect_session(rsession, argv[1], argv[2], argv[3], to, argv[5], argv[6]);
+	if (argv[7]) {
+		hits = atoi(argv[7]);
+		if (hits < 0) {
+			hits = 1;
+		}
+	}
+
+	switch_ivr_tone_detect_session(rsession, argv[1], argv[2], argv[3], to, hits, argv[5], argv[6]);
 	stream->write_function(stream, "+OK Enabling tone detection '%s' '%s' '%s'\n", argv[1], argv[2], argv[3]);
 
   done:
@@ -1251,6 +1260,42 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
+
+
+#define UUID_DEFLECT_SYNTAX "<uuid> <uri>"
+SWITCH_STANDARD_API(uuid_deflect)
+{
+	switch_core_session_t *tsession = NULL;
+	char *uuid = NULL, *text = NULL;
+
+	if (!switch_strlen_zero(cmd) && (uuid = strdup(cmd))) {
+		if ((text = strchr(uuid, ' '))) {
+			*text++ = '\0';
+		}
+	}
+
+	if (switch_strlen_zero(uuid) || switch_strlen_zero(text)) {
+		stream->write_function(stream, "-USAGE: %s\n", UUID_DEFLECT_SYNTAX);
+	} else {
+		if ((tsession = switch_core_session_locate(uuid))) {
+			switch_core_session_message_t msg = { 0 };
+
+			/* Tell the channel to deflect the call */
+			msg.from = __FILE__;
+			msg.string_arg = text;
+			msg.message_id = SWITCH_MESSAGE_INDICATE_DEFLECT;
+			switch_core_session_receive_message(tsession, &msg);
+			stream->write_function(stream, "+OK:%s\n", msg.string_reply);
+			switch_core_session_rwunlock(tsession);
+		} else {
+			stream->write_function(stream, "-ERR No Such Channel %s!\n", uuid);
+		}
+	}
+
+	switch_safe_free(uuid);
+	return SWITCH_STATUS_SUCCESS;
+}
+
 #define SCHED_TRANSFER_SYNTAX "[+]<time> <uuid> <extension> [<dialplan>] [<context>]"
 SWITCH_STANDARD_API(sched_transfer_function)
 {
@@ -1722,7 +1767,8 @@
 {
 	switch_core_session_t *psession = NULL;
 	char *mycmd, *flag;
-	
+	switch_channel_t *channel = NULL;
+
 	if (session) {
 		return SWITCH_STATUS_FALSE;
 	}
@@ -1748,7 +1794,12 @@
 		switch_core_session_flush_private_events(psession);
 	}
 
-	switch_channel_set_flag(switch_core_session_get_channel(psession), CF_BREAK);
+	channel = switch_core_session_get_channel(psession);
+	if (switch_channel_test_flag(channel, CF_BROADCAST)) {
+		switch_channel_stop_broadcast(channel);
+	} else {
+		switch_channel_set_flag(channel, CF_BREAK);
+	}
 	switch_core_session_rwunlock(psession);
 
 	return SWITCH_STATUS_SUCCESS;
@@ -1852,7 +1903,7 @@
 		timeout = atoi(argv[6]);
 	}
 
-	if (switch_ivr_originate(NULL, &caller_session, &cause, aleg, timeout, NULL, cid_name, cid_num, NULL, SOF_NONE) != SWITCH_STATUS_SUCCESS
+	if (switch_ivr_originate(NULL, &caller_session, &cause, aleg, timeout, NULL, cid_name, cid_num, NULL, NULL, SOF_NONE) != SWITCH_STATUS_SUCCESS
 		|| !caller_session) {
 		if (machine) {
 			stream->write_function(stream, "-ERR %s\n", switch_channel_cause2str(cause));
@@ -2055,7 +2106,7 @@
 			}
 
 			switch_zmalloc(api_task, sizeof(*api_task) + strlen(dcmd) + 1);
-			switch_copy_string(api_task->cmd, dcmd, strlen(dcmd));
+			switch_copy_string(api_task->cmd, dcmd, strlen(dcmd) + 1);
 			api_task->recur = recur;
 
 			id = switch_scheduler_add_task(when, sch_api_callback, (char *) __SWITCH_FUNC__, group, 0, api_task, SSHF_FREE_ARG);
@@ -2654,7 +2705,7 @@
 SWITCH_STANDARD_API(uuid_setvar_multi_function)
 {
 	switch_core_session_t *psession = NULL;
-	char *mycmd = NULL, *vars, *argv[2] = { 0 };
+	char *mycmd = NULL, *vars, *argv[64] = { 0 };
 	int argc = 0;
 	char *var_name, *var_value;
 
@@ -2698,7 +2749,7 @@
 		}
 	}
 	
-	stream->write_function(stream, "-USAGE: %s\n", SETVAR_SYNTAX);
+	stream->write_function(stream, "-USAGE: %s\n", SETVAR_MULTI_SYNTAX);
 
   done:
 	switch_safe_free(mycmd);
@@ -3083,6 +3134,7 @@
 	SWITCH_ADD_API(commands_api_interface, "regex", "Eval a regex", regex_function, "<data>|<pattern>[|<subst string>]");
 	SWITCH_ADD_API(commands_api_interface, "acl", "compare an ip to an acl list", acl_function, "<ip> <list_name>");
 	SWITCH_ADD_API(commands_api_interface, "uuid_chat", "Send a chat message", uuid_chat, UUID_CHAT_SYNTAX);
+	SWITCH_ADD_API(commands_api_interface, "uuid_deflect", "Send a deflect", uuid_deflect, UUID_DEFLECT_SYNTAX);
 	SWITCH_ADD_API(commands_api_interface, "find_user_xml", "find a user", find_user_function, "<key> <user> <domain>");
 	SWITCH_ADD_API(commands_api_interface, "user_exists", "find a user", user_exists_function, "<key> <user> <domain>");
 	SWITCH_ADD_API(commands_api_interface, "xml_locate", "find some xml", xml_locate_function, "[root | <section> <tag> <tag_attr_name> <tag_attr_val>]");

Modified: freeswitch/branches/gmaruzz/src/mod/applications/mod_conference/mod_conference.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/applications/mod_conference/mod_conference.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/applications/mod_conference/mod_conference.c	Mon Dec 15 12:56:36 2008
@@ -788,64 +788,68 @@
 			continue;
 		}
 
-		if (switch_channel_test_flag(switch_core_session_get_channel(conference->floor_holder->session), CF_VIDEO)) {
-			status = switch_core_session_read_video_frame(conference->floor_holder->session, &vid_frame, SWITCH_IO_FLAG_NONE, 0);
-			if (!SWITCH_READ_ACCEPTABLE(status)) {
-				conference->floor_holder = NULL;
-				req_iframe = 0;
-				continue;
-			}
+		if (!switch_channel_test_flag(switch_core_session_get_channel(conference->floor_holder->session), CF_VIDEO)) {
+			switch_cond_next();
+			continue;
+		}
 
-			if (switch_test_flag(vid_frame, SFF_CNG)) {
-				continue;
-			}
+		status = switch_core_session_read_video_frame(conference->floor_holder->session, &vid_frame, SWITCH_IO_FLAG_NONE, 0);
+		if (!SWITCH_READ_ACCEPTABLE(status)) {
+			conference->floor_holder = NULL;
+			req_iframe = 0;
+			continue;
+		}
 
-			if (conference->floor_holder != last_member) {
-				int iframe = 0;
+		if (switch_test_flag(vid_frame, SFF_CNG)) {
+			continue;
+		}
+
+		if (conference->floor_holder != last_member) {
+			int iframe = 0;
 #if 0
-				switch_core_session_message_t msg = { 0 };
+			switch_core_session_message_t msg = { 0 };
 
 
-				if (!req_iframe) {
-					/* Tell the channel to request a fresh vid frame */
-					msg.from = __FILE__;
-					msg.message_id = SWITCH_MESSAGE_INDICATE_VIDEO_REFRESH_REQ;
-					switch_core_session_receive_message(conference->floor_holder->session, &msg);
-					req_iframe = 1;
-				}
+			if (!req_iframe) {
+				/* Tell the channel to request a fresh vid frame */
+				msg.from = __FILE__;
+				msg.message_id = SWITCH_MESSAGE_INDICATE_VIDEO_REFRESH_REQ;
+				switch_core_session_receive_message(conference->floor_holder->session, &msg);
+				req_iframe = 1;
+			}
 #endif
 
-				if (vid_frame->codec->implementation->ianacode == 34) {	/* h.263 */
-					//iframe = (*((int16_t *) vid_frame->data) >> 12 == 6);
-					iframe = 1;			
-				} else if (vid_frame->codec->implementation->ianacode == 115) {	/* h.263-1998 */
-					int y = *((int8_t *) vid_frame->data + 2) & 0xfe;
-					iframe = (y == 0x80 || y == 0x82);
-				} else if (vid_frame->codec->implementation->ianacode == 99) {	/* h.264 */
-					iframe = (*((int16_t *) vid_frame->data) >> 5 == 0x11);
-				} else {		/* we need more defs */
-					iframe = 1;
-				}
-
-				if (!iframe) {
-					continue;
-				}
+			if (vid_frame->codec->implementation->ianacode == 34) {	/* h.263 */
+				//iframe = (*((int16_t *) vid_frame->data) >> 12 == 6);
+				iframe = 1;			
+			} else if (vid_frame->codec->implementation->ianacode == 115) {	/* h.263-1998 */
+				int y = *((int8_t *) vid_frame->data + 2) & 0xfe;
+				iframe = (y == 0x80 || y == 0x82);
+			} else if (vid_frame->codec->implementation->ianacode == 99) {	/* h.264 */
+				iframe = (*((int16_t *) vid_frame->data) >> 5 == 0x11);
+			} else {		/* we need more defs */
+				iframe = 1;
+			}
 
-				req_iframe = 0;
+			if (!iframe) {
+				continue;
 			}
 
-			last_member = conference->floor_holder;
+			req_iframe = 0;
+		}
 
-			switch_mutex_lock(conference->member_mutex);
-			has_vid = 0;
-			for (imember = conference->members; imember; imember = imember->next) {
-				if (switch_channel_test_flag(switch_core_session_get_channel(imember->session), CF_VIDEO)) {
-					has_vid++;
-					switch_core_session_write_video_frame(imember->session, vid_frame, SWITCH_IO_FLAG_NONE, 0);
-				}
+		last_member = conference->floor_holder;
+
+		switch_mutex_lock(conference->member_mutex);
+		has_vid = 0;
+		for (imember = conference->members; imember; imember = imember->next) {
+			if (switch_channel_test_flag(switch_core_session_get_channel(imember->session), CF_VIDEO)) {
+				has_vid++;
+				switch_core_session_write_video_frame(imember->session, vid_frame, SWITCH_IO_FLAG_NONE, 0);
 			}
-			switch_mutex_unlock(conference->member_mutex);
 		}
+		switch_mutex_unlock(conference->member_mutex);
+	
 	}
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Video thread ending for conference %s\n", conference->name);
 	conference->video_running = 0;
@@ -881,6 +885,12 @@
 	switch_mutex_unlock(globals.hash_mutex);
 	
 	if (conference->auto_record) {
+		uint32_t sanity = 100;
+
+		while (!conference->members && --sanity) {
+			switch_yield(100000);
+		}
+
 		imember = conference->members;
 		if (imember) {
 			switch_channel_t *channel = switch_core_session_get_channel(imember->session);
@@ -3803,7 +3813,7 @@
 
 	if (conference == NULL) {
 		char *dialstr = switch_mprintf("{ignore_early_media=true}%s", bridgeto);
-		status = switch_ivr_originate(NULL, &peer_session, cause, dialstr, 60, NULL, cid_name, cid_num, NULL, SOF_NONE);
+		status = switch_ivr_originate(NULL, &peer_session, cause, dialstr, 60, NULL, cid_name, cid_num, NULL, NULL, SOF_NONE);
 		switch_safe_free(dialstr);
 
 		if (status != SWITCH_STATUS_SUCCESS) {
@@ -3836,7 +3846,7 @@
 
 	/* establish an outbound call leg */
 
-	if (switch_ivr_originate(session, &peer_session, cause, bridgeto, timeout, NULL, cid_name, cid_num, NULL, SOF_NONE) != SWITCH_STATUS_SUCCESS) {
+	if (switch_ivr_originate(session, &peer_session, cause, bridgeto, timeout, NULL, cid_name, cid_num, NULL, NULL, SOF_NONE) != 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);

Modified: freeswitch/branches/gmaruzz/src/mod/applications/mod_dptools/mod_dptools.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/applications/mod_dptools/mod_dptools.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/applications/mod_dptools/mod_dptools.c	Mon Dec 15 12:56:36 2008
@@ -126,20 +126,11 @@
 	}
 }
 
-#define SAY_SYNTAX "<module_name> <say_type> <say_method> <text>"
-SWITCH_STANDARD_APP(say_function)
+#define MKDIR_SYNTAX "<path>"
+SWITCH_STANDARD_APP(mkdir_function)
 {
-	char *argv[4] = { 0 };
-	int argc;
-	char *lbuf = NULL;
-
-	if (!switch_strlen_zero(data) && (lbuf = switch_core_session_strdup(session, data))
-		&& (argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) == 4) {
-		switch_ivr_say(session, argv[3], argv[0], argv[1], argv[2], NULL);
-	} else {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Usage: %s\n", SAY_SYNTAX);
-	}
-
+	switch_dir_make_recursive(data, SWITCH_DEFAULT_DIR_PERMS, switch_core_session_get_pool(session));
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s MKDIR: %s\n", switch_channel_get_name(switch_core_session_get_channel(session)), data);
 }
 
 #define SOFT_HOLD_SYNTAX "<unhold key> [<moh_a>] [<moh_b>]"
@@ -563,25 +554,6 @@
 	return;
 }
 
-SWITCH_STANDARD_APP(phrase_function)
-{
-	char *mydata = NULL;
-
-	if (!switch_strlen_zero(data) && (mydata = switch_core_session_strdup(session, data))) {
-		const char *lang;
-		char *macro = mydata;
-		char *mdata = NULL;
-
-		if ((mdata = strchr(macro, ','))) {
-			*mdata++ = '\0';
-		}
-
-		lang = switch_channel_get_variable(switch_core_session_get_channel(session), "language");
-
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Execute %s(%s) lang %s\n", macro, switch_str_nil(mdata), switch_str_nil(lang));
-		switch_ivr_phrase_macro(session, macro, mdata, lang, NULL);
-	}
-}
 
 SWITCH_STANDARD_APP(hangup_function)
 {
@@ -1142,7 +1114,6 @@
 						&& 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, (char *) data, NULL);
 						switch_ivr_menu_stack_free(menu_stack);
 					} else {
@@ -1189,7 +1160,7 @@
 
 SWITCH_STANDARD_APP(fax_detect_session_function)
 {
-	switch_ivr_tone_detect_session(session, "fax", "1100.0", "r", 0, NULL, NULL);
+	switch_ivr_tone_detect_session(session, "fax", "1100.0", "r", 0, 1, NULL, NULL);
 }
 
 SWITCH_STANDARD_APP(system_session_function)
@@ -1202,10 +1173,11 @@
 
 SWITCH_STANDARD_APP(tone_detect_session_function)
 {
-	char *argv[6] = { 0 };
+	char *argv[7] = { 0 };
 	int argc;
 	char *mydata = NULL;
 	time_t to = 0;
+	int hits = 1;
 
 	if (switch_strlen_zero(data) || !(mydata = switch_core_session_strdup(session, data))) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "INVALID ARGS!\n");
@@ -1235,9 +1207,16 @@
 		}
 	}
 
+	if (argv[6]) {
+		hits = atoi(argv[6]);
+		if (hits < 0) {
+			hits = 1;
+		}
+	}
+
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Enabling tone detection '%s' '%s'\n", argv[0], argv[1]);
 
-	switch_ivr_tone_detect_session(session, argv[0], argv[1], argv[2], to, argv[4], argv[5]);
+	switch_ivr_tone_detect_session(session, argv[0], argv[1], argv[2], to, hits, argv[4], argv[5]);
 }
 
 SWITCH_STANDARD_APP(stop_fax_detect_session_function)
@@ -1335,7 +1314,7 @@
 		
 		switch_channel_set_variable(channel, SWITCH_PLAYBACK_TERMINATOR_USED, "" );
 
-		switch_ivr_sleep(session, ms, &args);
+		switch_ivr_sleep(session, ms, SWITCH_TRUE, &args);
 	}
 }
 
@@ -1399,8 +1378,6 @@
 		switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
 	}
 
-	switch_channel_pre_answer(channel);
-
 	args.input_callback = on_dtmf;
 	args.buf = buf;
 	args.buflen = sizeof(buf);
@@ -1510,7 +1487,8 @@
 		timelimit = atoi(var);
 	}
 
-	if (switch_ivr_originate(session, &peer_session, &cause, data, timelimit, NULL, NULL, NULL, NULL, SOF_NONE) != SWITCH_STATUS_SUCCESS || !peer_session) {
+	if (switch_ivr_originate(session, &peer_session, &cause, data, timelimit, NULL, NULL, NULL, NULL, NULL, SOF_NONE) 
+		!= SWITCH_STATUS_SUCCESS || !peer_session) {
 		goto end;
 	}
 
@@ -1617,18 +1595,85 @@
 	switch_ivr_read(session, min_digits, max_digits, prompt_audio_file, var_name, digit_buffer, sizeof(digit_buffer), timeout, valid_terminators);
 }
 
-SWITCH_STANDARD_APP(playback_function)
+
+
+#define SAY_SYNTAX "<module_name> <say_type> <say_method> <text>"
+SWITCH_STANDARD_APP(say_function)
+{
+	char *argv[4] = { 0 };
+	int argc;
+	char *lbuf = NULL;
+	switch_input_args_t args = { 0 };
+	switch_channel_t *channel = switch_core_session_get_channel(session);
+
+	if (!switch_strlen_zero(data) && (lbuf = switch_core_session_strdup(session, data))
+		&& (argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) == 4) {
+		
+		args.input_callback = on_dtmf;
+		
+		switch_channel_set_variable(channel, SWITCH_PLAYBACK_TERMINATOR_USED, "" );
+		
+		switch_ivr_say(session, argv[3], argv[0], argv[1], argv[2], &args);
+	} else {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Usage: %s\n", SAY_SYNTAX);
+	}
+
+}
+
+
+SWITCH_STANDARD_APP(phrase_function)
 {
+	char *mydata = NULL;
 	switch_input_args_t args = { 0 };
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 
-	switch_channel_pre_answer(switch_core_session_get_channel(session));
+	if (!switch_strlen_zero(data) && (mydata = switch_core_session_strdup(session, data))) {
+		const 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, switch_str_nil(mdata), switch_str_nil(lang));
+
+		args.input_callback = on_dtmf;
+		
+		switch_channel_set_variable(channel, SWITCH_PLAYBACK_TERMINATOR_USED, "" );
+
+		switch_ivr_phrase_macro(session, macro, mdata, lang, &args);
+	}
+}
+
+
+SWITCH_STANDARD_APP(playback_function)
+{
+	switch_input_args_t args = { 0 };
+	switch_channel_t *channel = switch_core_session_get_channel(session);
+	switch_status_t status;
 
 	args.input_callback = on_dtmf;
 
 	switch_channel_set_variable(channel, SWITCH_PLAYBACK_TERMINATOR_USED, "" );
 
-	switch_ivr_play_file(session, NULL, data, &args);
+	status = switch_ivr_play_file(session, NULL, data, &args);
+
+	switch (status) {
+	case SWITCH_STATUS_SUCCESS:
+	case SWITCH_STATUS_BREAK:
+		switch_channel_set_variable(channel, SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE, "FILE PLAYED");
+		break;
+	case SWITCH_STATUS_NOTFOUND:
+		switch_channel_set_variable(channel, SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE, "FILE NOT FOUND");
+		break;
+	default:
+		switch_channel_set_variable(channel, SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE, "PLAYBACK ERROR");
+		break;
+	}
+
 }
 
 SWITCH_STANDARD_APP(gentones_function)
@@ -1644,8 +1689,6 @@
 		return;
 	}
 
-	switch_channel_pre_answer(switch_core_session_get_channel(session));
-
 	if ((l = strchr(tone_script, '|'))) {
 		*l++ = '\0';
 		loops = atoi(l);
@@ -1844,7 +1887,7 @@
 		}
 	}
 
-	if (switch_ivr_originate(session, &peer_session, &cause, data, timelimit, NULL, NULL, NULL, NULL, SOF_NONE) != SWITCH_STATUS_SUCCESS) {
+	if (switch_ivr_originate(session, &peer_session, &cause, data, timelimit, NULL, NULL, NULL, NULL, NULL, SOF_NONE) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Originate Failed.  Cause: %s\n", switch_channel_cause2str(cause));
 
 		/* no answer is *always* a reason to continue */
@@ -1956,8 +1999,6 @@
 		cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
 	}
 
-	UNPROTECT_INTERFACE(error_endpoint_interface);
-
 	return cause;
 }
 
@@ -2042,7 +2083,7 @@
 		switch_originate_flag_t myflags = SOF_NONE;
 		char *cid_name_override = NULL;
 		char *cid_num_override = NULL;
-		
+
 		if (var_event) {
 			cid_name_override = switch_event_get_header(var_event, "origination_caller_id_name");
 			cid_num_override = switch_event_get_header(var_event, "origination_caller_id_number");
@@ -2060,18 +2101,23 @@
 			d_dest = switch_channel_expand_variables(channel, dest);
 
 		} else {
-			switch_event_t *event = var_event;
-			if (!event) {
+			switch_event_t *event = NULL;
+
+			if (var_event) {
+				switch_event_dup(&event, var_event);
+				switch_event_del_header(event, "dialer_user");
+				switch_event_del_header(event, "dialer_domain");
+			} else {
 				switch_event_create(&event, SWITCH_EVENT_REQUEST_PARAMS);
 				switch_assert(event);
 			}
+			switch_assert(var_event);
 
 			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "dialed_user", user);
 			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "dialed_domain", domain);
 			d_dest = switch_event_expand_headers(event, dest);
-			if (event && event != var_event) {
-				switch_event_destroy(&event);
-			}
+
+			switch_event_destroy(&event);
 		}
 
 		if ((flags & SOF_FORKED_DIAL)) {
@@ -2079,7 +2125,7 @@
 		}
 
 		if (switch_ivr_originate(session, new_session, &cause, d_dest, timelimit, NULL, 
-								 cid_name_override, cid_num_override, NULL, myflags) == SWITCH_STATUS_SUCCESS) {
+								 cid_name_override, cid_num_override, NULL, var_event, myflags) == SWITCH_STATUS_SUCCESS) {
 			const char *context;
 			switch_caller_profile_t *cp;
 
@@ -2118,8 +2164,6 @@
 
   done:
 
-	UNPROTECT_INTERFACE(user_endpoint_interface);
-
 	if (xml) {
 		switch_xml_free(xml);
 	}
@@ -2340,6 +2384,7 @@
 	SWITCH_ADD_APP(app_interface, "sched_transfer", SCHED_TRANSF_DESCR, SCHED_TRANSF_DESCR, sched_transfer_function,
 				   "[+]<time> <extension> <dialplan> <context>", SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "execute_extension", "Execute an extension", "Execute an extension", exe_function, EXE_SYNTAX, SAF_SUPPORT_NOMEDIA);
+	SWITCH_ADD_APP(app_interface, "mkdir", "Create a directory", "Create a directory", mkdir_function, MKDIR_SYNTAX, SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "soft_hold", "Put a bridged channel on hold", "Put a bridged channel on hold", soft_hold_function, SOFT_HOLD_SYNTAX,
 				   SAF_NONE);
 	SWITCH_ADD_APP(app_interface, "bind_meta_app", "Bind a key to an application", "Bind a key to an application", dtmf_bind_function, BIND_SYNTAX,

Modified: freeswitch/branches/gmaruzz/src/mod/applications/mod_enum/mod_enum.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/applications/mod_enum/mod_enum.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/applications/mod_enum/mod_enum.c	Mon Dec 15 12:56:36 2008
@@ -652,7 +652,7 @@
 				rbl -= l;
 			}
 
-			switch_snprintf(vbuf, sizeof(vbuf), "%d", cnt);
+			switch_snprintf(vbuf, sizeof(vbuf), "%d", cnt - 1);
 			switch_channel_set_variable(channel, "enum_route_count", vbuf);
 			*(rbuf + strlen(rbuf) - 1) = '\0';
 			switch_channel_set_variable(channel, "enum_auto_route", rbuf);

Modified: freeswitch/branches/gmaruzz/src/mod/applications/mod_expr/exprpars.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/applications/mod_expr/exprpars.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/applications/mod_expr/exprpars.c	Mon Dec 15 12:56:36 2008
@@ -12,6 +12,7 @@
 
 #include "exprpriv.h"
 #include "exprmem.h"
+#include "switch_utils.h"
 
 /* Data structure used by parser */
 typedef struct _exprToken {
@@ -314,12 +315,12 @@
 			default:
 				{
 					if (!comment) {
-						if (expr[pos] == '.' || isdigit(expr[pos])) {
+						if (expr[pos] == '.' || switch_isdigit(expr[pos])) {
 							/* Value */
 							start = pos;
 
 							/* Find digits before a period */
-							while (isdigit(expr[pos]))
+							while (switch_isdigit(expr[pos]))
 								pos++;
 
 							/* Find a period */
@@ -327,7 +328,7 @@
 								pos++;
 
 							/* Find digits after a period */
-							while (isdigit(expr[pos]))
+							while (switch_isdigit(expr[pos]))
 								pos++;
 
 							/* pos is AFTER last item, back up */
@@ -356,12 +357,12 @@
 								list[tpos].data.val = (EXPRTYPE) atof(buf);
 								tpos++;
 							}
-						} else if (expr[pos] == '_' || isalpha(expr[pos])) {
+						} else if (expr[pos] == '_' || switch_isalpha(expr[pos])) {
 							/* Identifier */
 							start = pos;
 
 							/* Find rest of identifier */
-							while (expr[pos] == '_' || isalnum(expr[pos]))
+							while (expr[pos] == '_' || switch_isalnum(expr[pos]))
 								pos++;
 
 							/* pos is AFTER last item, back up */
@@ -397,7 +398,7 @@
 								strcpy(list[tpos].data.str, buf);
 								tpos++;
 							}
-						} else if (isspace(expr[pos])) {
+						} else if (switch_isspace(expr[pos])) {
 							/* Spaces are ignored, do nothing */
 						} else {
 							/* Unknown */

Modified: freeswitch/branches/gmaruzz/src/mod/applications/mod_expr/exprutil.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/applications/mod_expr/exprutil.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/applications/mod_expr/exprutil.c	Mon Dec 15 12:56:36 2008
@@ -11,6 +11,7 @@
 #include "exprincl.h"
 
 #include "exprpriv.h"
+#include "switch_utils.h"
 
 
 /* Return the version number */
@@ -27,13 +28,13 @@
 		return 0;
 
 	/* First must be letter or underscore */
-	if (isalpha(*name) || *name == '_')
+	if (switch_isalpha(*name) || *name == '_')
 		name++;					/* Point to next letter */
 	else
 		return 0;				/* Not letter or underscore, maybe empty */
 
 	/* others can be letter, number, or underscore */
-	while (isalnum(*name) || *name == '_')
+	while (switch_isalnum(*name) || *name == '_')
 		name++;
 
 	/* When the while breaks out, we should be at the end */

Modified: freeswitch/branches/gmaruzz/src/mod/applications/mod_fax/Makefile
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/applications/mod_fax/Makefile	(original)
+++ freeswitch/branches/gmaruzz/src/mod/applications/mod_fax/Makefile	Mon Dec 15 12:56:36 2008
@@ -11,3 +11,11 @@
 $(SPANDSP_LA): $(SPANDSP_DIR) $(SPANDSP_DIR)/.update
 	cd $(SPANDSP_DIR) && $(MAKE)
 	$(TOUCH_TARGET)
+
+
+depend_install: $(DESTDIR)$(libdir)/libspandsp.la
+
+$(DESTDIR)$(libdir)/libspandsp.la: $(SPANDSP_LA)
+	cd $(SPANDSP_DIR) && $(MAKE) install
+
+

Modified: freeswitch/branches/gmaruzz/src/mod/applications/mod_fax/mod_fax.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/applications/mod_fax/mod_fax.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/applications/mod_fax/mod_fax.c	Mon Dec 15 12:56:36 2008
@@ -143,18 +143,18 @@
 	const char *local_ident;
 	const char *far_ident;
 	switch_core_session_t *session;
-	switch_channel_t *chan;
+	switch_channel_t *channel;
 	pvt_t *pvt;
 	char *tmp;
 
 	pvt = (pvt_t *) user_data;
 	switch_assert(pvt);
-
+    
 	session = pvt->session;
 	switch_assert(session);
 
-	chan = switch_core_session_get_channel(session);
-	switch_assert(chan);
+	channel = switch_core_session_get_channel(session);
+	switch_assert(channel);
 
 	t30_get_transfer_statistics(s, &t);
 	local_ident = switch_str_nil(t30_get_tx_ident(s));
@@ -171,11 +171,11 @@
         } else {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Fax successfully managed. How ?\n");
         }
-		switch_channel_set_variable(chan, "fax_success", "1");
+		switch_channel_set_variable(channel, "fax_success", "1");
 	} else {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Fax processing not successful - result (%d) %s.\n", result,
 						  t30_completion_code_to_str(result));
-		switch_channel_set_variable(chan, "fax_success", "0");
+		switch_channel_set_variable(channel, "fax_success", "0");
 	}
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Remote station id: %s\n", far_ident);
@@ -198,52 +198,54 @@
 
 	tmp = switch_mprintf("%i", result);
 	if (tmp) {
-		switch_channel_set_variable(chan, "fax_result_code", tmp);
+		switch_channel_set_variable(channel, "fax_result_code", tmp);
 		switch_safe_free(tmp);
 	}
 
-	switch_channel_set_variable(chan, "fax_result_text", t30_completion_code_to_str(result));
+	switch_channel_set_variable(channel, "fax_result_text", t30_completion_code_to_str(result));
 
-	switch_channel_set_variable(chan, "fax_ecm_used", (t.error_correcting_mode) ? "on" : "off");
-	switch_channel_set_variable(chan, "fax_local_station_id", local_ident);
-	switch_channel_set_variable(chan, "fax_remote_station_id", far_ident);
+	switch_channel_set_variable(channel, "fax_ecm_used", (t.error_correcting_mode) ? "on" : "off");
+	switch_channel_set_variable(channel, "fax_local_station_id", local_ident);
+	switch_channel_set_variable(channel, "fax_remote_station_id", far_ident);
 
 	tmp = switch_mprintf("%i", t.pages_transferred);
 	if (tmp) {
-		switch_channel_set_variable(chan, "fax_document_transferred_pages", tmp);
+		switch_channel_set_variable(channel, "fax_document_transferred_pages", tmp);
 		switch_safe_free(tmp);
 	}
 
 	tmp = switch_mprintf("%i", t.pages_in_file);
 	if (tmp) {
-		switch_channel_set_variable(chan, "fax_document_total_pages", tmp);
+		switch_channel_set_variable(channel, "fax_document_total_pages", tmp);
 		switch_safe_free(tmp);
 	}
 
 	tmp = switch_mprintf("%ix%i", t.x_resolution, t.y_resolution);
 	if (tmp) {
-		switch_channel_set_variable(chan, "fax_image_resolution", tmp);
+		switch_channel_set_variable(channel, "fax_image_resolution", tmp);
 		switch_safe_free(tmp);
 	}
 
 	tmp = switch_mprintf("%d", t.image_size);
 	if (tmp) {
-		switch_channel_set_variable(chan, "fax_image_size", tmp);
+		switch_channel_set_variable(channel, "fax_image_size", tmp);
 		switch_safe_free(tmp);
 	}
 
 	tmp = switch_mprintf("%d", t.bad_rows);
 	if (tmp) {
-		switch_channel_set_variable(chan, "fax_bad_rows", tmp);
+		switch_channel_set_variable(channel, "fax_bad_rows", tmp);
 		switch_safe_free(tmp);
 	}
 
 	tmp = switch_mprintf("%i", t.bit_rate);
 	if (tmp) {
-		switch_channel_set_variable(chan, "fax_transfer_rate", tmp);
+		switch_channel_set_variable(channel, "fax_transfer_rate", tmp);
 		switch_safe_free(tmp);
 	}
 
+    switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
+
 	/*
       TODO Fire events
     */
@@ -253,15 +255,15 @@
 {
 
 	switch_core_session_t *session;
-	switch_channel_t *chan;
+	switch_channel_t *channel;
 	fax_state_t *fax;
 	t30_state_t *t30;
 
 	session = (switch_core_session_t *) pvt->session;
 	switch_assert(session);
 
-	chan = switch_core_session_get_channel(session);
-	switch_assert(chan);
+	channel = switch_core_session_get_channel(session);
+	switch_assert(channel);
 
 
 	switch (trans_mode) {
@@ -306,19 +308,19 @@
 
 		if (pvt->disable_v17) {
 			t30_set_supported_modems(t30, T30_SUPPORT_V29 | T30_SUPPORT_V27TER);
-			switch_channel_set_variable(chan, "fax_v17_disabled", "1");
+			switch_channel_set_variable(channel, "fax_v17_disabled", "1");
 		} else {
 			t30_set_supported_modems(t30, T30_SUPPORT_V29 | T30_SUPPORT_V27TER | T30_SUPPORT_V17);
-			switch_channel_set_variable(chan, "fax_v17_disabled", "0");
+			switch_channel_set_variable(channel, "fax_v17_disabled", "0");
 		}
 
 		if (pvt->use_ecm) {
 			t30_set_supported_compressions(t30, T30_SUPPORT_T4_1D_COMPRESSION | T30_SUPPORT_T4_2D_COMPRESSION | T30_SUPPORT_T6_COMPRESSION);
 			t30_set_ecm_capability(t30, TRUE);
-			switch_channel_set_variable(chan, "fax_ecm_requested", "1");
+			switch_channel_set_variable(channel, "fax_ecm_requested", "1");
 		} else {
 			t30_set_supported_compressions(t30, T30_SUPPORT_T4_1D_COMPRESSION | T30_SUPPORT_T4_2D_COMPRESSION);
-			switch_channel_set_variable(chan, "fax_ecm_requested", "0");
+			switch_channel_set_variable(channel, "fax_ecm_requested", "0");
 		}
 
 		if (pvt->app_mode == FUNCTION_TX) {
@@ -326,7 +328,7 @@
 		} else {
 			t30_set_rx_file(t30, pvt->filename, -1);
 		}
-		switch_channel_set_variable(chan, "fax_filename", pvt->filename);
+		switch_channel_set_variable(channel, "fax_filename", pvt->filename);
 		break;
 	case T38_MODE:
 		/* 
@@ -606,7 +608,7 @@
 		goto done;
 	}
 
-    switch_ivr_sleep(session, 250, NULL);
+    switch_ivr_sleep(session, 250, SWITCH_TRUE, NULL);
     
 	while (switch_channel_ready(channel)) {
 		int tx = 0;

Modified: freeswitch/branches/gmaruzz/src/mod/applications/mod_fifo/mod_fifo.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/applications/mod_fifo/mod_fifo.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/applications/mod_fifo/mod_fifo.c	Mon Dec 15 12:56:36 2008
@@ -450,7 +450,7 @@
 	switch_snprintf(sql, sizeof(sql), "update fifo_outbound set use_count=use_count+1 where uuid='%s'", h->uuid);
 	fifo_execute_sql(sql, globals.sql_mutex);
 	
-	if (switch_ivr_originate(NULL, &session, &cause, h->originate_string, h->timeout, NULL, NULL, NULL, NULL, SOF_NONE) != SWITCH_STATUS_SUCCESS) {
+	if (switch_ivr_originate(NULL, &session, &cause, h->originate_string, h->timeout, NULL, NULL, NULL, NULL, NULL, SOF_NONE) != SWITCH_STATUS_SUCCESS) {
 		switch_snprintf(sql, sizeof(sql), "update fifo_outbound set use_count=use_count-1, outbound_fail_count=outbound_fail_count+1, next_avail=%ld + lag where uuid='%s'", 
 						(long)switch_timestamp(NULL), h->uuid);
 		fifo_execute_sql(sql, globals.sql_mutex);
@@ -1167,7 +1167,7 @@
 				if (announce) {
 					switch_ivr_play_file(session, NULL, announce, NULL);
 				} else {
-					switch_ivr_sleep(session, 500, NULL);
+					switch_ivr_sleep(session, 500, SWITCH_TRUE, NULL);
 				}
 
 				switch_channel_set_variable(other_channel, "fifo_serviced_by", my_id);

Modified: freeswitch/branches/gmaruzz/src/mod/applications/mod_fsv/mod_fsv.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/applications/mod_fsv/mod_fsv.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/applications/mod_fsv/mod_fsv.c	Mon Dec 15 12:56:36 2008
@@ -110,7 +110,7 @@
 
 	switch_channel_answer(channel);
 
-	if ((fd = open((char *) data, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) < 0) {
+	if ((fd = open((char *) data, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRUSR | S_IWUSR)) < 0) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error opening file %s\n", (char *) data);
 		return;
 	}

Modified: freeswitch/branches/gmaruzz/src/mod/applications/mod_limit/mod_limit.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/applications/mod_limit/mod_limit.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/applications/mod_limit/mod_limit.c	Mon Dec 15 12:56:36 2008
@@ -25,7 +25,8 @@
  * 
  * Anthony Minessale II <anthmct at yahoo.com>
  * Ken Rice <krice at suspicious dot org
- *
+ * Mathieu Rene <mathieu.rene at gmail.com>
+ * 
  * mod_limit.c -- Resource Limit Module
  *
  */
@@ -44,6 +45,10 @@
 	char *dbname;
 	char *odbc_dsn;
 	switch_mutex_t *mutex;
+	switch_mutex_t *limit_hash_mutex;
+	switch_hash_t *limit_hash;	
+	switch_mutex_t *db_hash_mutex;
+	switch_hash_t *db_hash;	
 #ifdef SWITCH_HAVE_ODBC
 	switch_odbc_handle_t *master_odbc;
 #else
@@ -51,6 +56,14 @@
 #endif
 } globals;
 
+struct limit_hash_item  {
+	uint32_t total_usage;
+	uint32_t rate_usage;
+	time_t last_check;
+};
+typedef struct limit_hash_item limit_hash_item_t;
+
+
 static char limit_sql[] =
 	"CREATE TABLE limit_data (\n"
 	"   hostname   VARCHAR(255),\n" "   realm      VARCHAR(255),\n" "   id         VARCHAR(255),\n" "   uuid       VARCHAR(255)\n" ");\n";
@@ -247,23 +260,53 @@
 	return status;
 }
 
-static switch_status_t hanguphook(switch_core_session_t *session)
+static switch_status_t db_state_handler(switch_core_session_t *session)
 {
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 	switch_channel_state_t state = switch_channel_get_state(channel);
-	const char *realm = NULL;
-	const char *id = NULL;
 	char *sql = NULL;
 
 	if (state == CS_HANGUP || state == CS_ROUTING) {
-		id = switch_channel_get_variable(channel, "limit_id");
-		realm = switch_channel_get_variable(channel, "limit_realm");
-		sql = switch_mprintf("delete from limit_data where uuid='%q'",
+		sql = switch_mprintf("delete from limit_data where uuid='%q';",
 							 switch_core_session_get_uuid(session));
 		limit_execute_sql(sql, globals.mutex);
 		switch_safe_free(sql);
-		switch_core_event_hook_remove_state_change(session, hanguphook);
+		switch_core_event_hook_remove_state_change(session, db_state_handler);
+	}
+	return SWITCH_STATUS_SUCCESS;
+}
+
+static switch_status_t hash_state_handler(switch_core_session_t *session) 
+{
+	switch_channel_t *channel = switch_core_session_get_channel(session);
+	switch_channel_state_t state = switch_channel_get_state(channel);
+	switch_hash_t *channel_hash = switch_channel_get_private(channel, "limit_hash");
+	
+	/* The call is either hung up, or is going back into the dialplan, decrement appropriate couters */
+	if (state == CS_HANGUP || state == CS_ROUTING) {	
+		switch_hash_index_t *hi;
+		switch_mutex_lock(globals.mutex);
+
+		/* Loop through the channel's hashtable which contains mapping to all the limit_hash_item_t referenced by that channel */
+		for(hi = switch_hash_first(NULL, channel_hash); hi; hi = switch_hash_next(hi))
+		{
+			void *val = NULL;
+			const void *key;
+			switch_ssize_t keylen;
+			limit_hash_item_t *item = NULL;
+			
+			switch_hash_this(hi, &key, &keylen, &val);
+			
+			item = (limit_hash_item_t*)val;
+			
+			/* We keep the structure even though the count is 0 so we do not allocate too often */
+			item->total_usage--;	
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Usage for %s is now %d\n", (const char*)key, item->total_usage);	
+		}
+		switch_core_event_hook_remove_state_change(session, hash_state_handler);
+		switch_mutex_unlock(globals.mutex);
 	}
+	
 	return SWITCH_STATUS_SUCCESS;
 }
 
@@ -303,6 +346,7 @@
 
 	if (!switch_strlen_zero(cmd)) {
 		mydata = strdup(cmd);
+		switch_assert(mydata);
 		argc = switch_separate_string(mydata, '/', argv, (sizeof(argv) / sizeof(argv[0])));
 	}
 
@@ -376,10 +420,15 @@
 	}
 
 	if (argc < 3 || !argv[0]) {
-		goto error;
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "USAGE: db %s\n", DB_USAGE);
+		return;
 	}
 
 	if (!strcasecmp(argv[0], "insert")) {
+		if (argc < 4) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "USAGE: db %s\n", DB_USAGE);
+			return;
+		}
 		sql = switch_mprintf("delete from db_data where realm='%q' and data_key='%q'", argv[1], argv[2]);
 		switch_assert(sql);
 		limit_execute_sql(sql, globals.mutex);
@@ -395,10 +444,109 @@
 	switch_assert(sql);
 	limit_execute_sql(sql, globals.mutex);
 	switch_safe_free(sql);
-	return;
+}
 
-  error:
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "USAGE: db %s\n", DB_USAGE);
+#define HASH_USAGE "[insert|delete]/<realm>/<key>/<val>"
+#define HASH_DESC "save data"
+
+SWITCH_STANDARD_APP(hash_function)
+{
+	int argc = 0;
+	char *argv[4] = { 0 };
+	char *mydata = NULL;
+	char *hash_key = NULL;
+	char *value = NULL;
+	
+	if (!switch_strlen_zero(data)) {
+		mydata = strdup(data);
+		switch_assert(mydata);
+		argc = switch_separate_string(mydata, '/', argv, (sizeof(argv) / sizeof(argv[0])));
+	}
+	
+	if (argc < 3 || !argv[0]) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "USAGE: hash %s\n", HASH_USAGE);
+		goto end;
+	}
+	
+	hash_key = switch_mprintf("%s_%s", argv[1], argv[2]);
+	
+	switch_mutex_lock(globals.db_hash_mutex);
+	if (!strcasecmp(argv[0], "insert")) {
+		if ((value = switch_core_hash_find(globals.db_hash, hash_key))) {
+			free(value);
+			switch_core_hash_delete(globals.db_hash, hash_key);
+		}
+		value = strdup(argv[3]);
+		switch_assert(value);
+		switch_core_hash_insert(globals.db_hash, hash_key, value);
+	} else if (!strcasecmp(argv[0], "delete")) {
+		if ((value = switch_core_hash_find(globals.db_hash, hash_key))) {
+			switch_safe_free(value);
+			switch_core_hash_delete(globals.db_hash, hash_key);
+		}
+	}
+	switch_mutex_unlock(globals.db_hash_mutex);
+	
+end:
+	switch_safe_free(mydata);
+	switch_safe_free(hash_key);
+}
+
+#define HASH_API_USAGE "insert|select|delete/realm/key[/value]"
+SWITCH_STANDARD_API(hash_api_function)
+{
+	int argc = 0;
+	char *argv[4] = { 0 };
+	char *mydata = NULL;
+	char *value = NULL;
+	char *hash_key = NULL;
+
+	switch_mutex_lock(globals.db_hash_mutex);
+
+	if (!switch_strlen_zero(cmd)) {
+		mydata = strdup(cmd);
+		switch_assert(mydata);
+		argc = switch_separate_string(mydata, '/', argv, (sizeof(argv) / sizeof(argv[0])));
+	}
+	
+	if (argc < 3 || !argv[0]) {
+		stream->write_function(stream, "-ERR Usage: hash %s\n", HASH_API_USAGE);
+		goto end;
+	}
+	
+	hash_key = switch_mprintf("%s_%s", argv[1], argv[2]);
+	
+	if (!strcasecmp(argv[0], "insert")) {
+		if (argc < 4) {
+			stream->write_function(stream, "-ERR Usage: hash %s\n", HASH_API_USAGE);
+			goto end;
+		}
+		if ((value = switch_core_hash_find(globals.db_hash, hash_key))) {
+			switch_safe_free(value);
+			switch_core_hash_delete(globals.db_hash, hash_key);
+		}
+		value = strdup(argv[3]);
+		switch_assert(value);
+		switch_core_hash_insert(globals.db_hash, hash_key, value);
+		stream->write_function(stream, "+OK\n");
+	} else if (!strcasecmp(argv[0], "delete")) {
+		if ((value = switch_core_hash_find(globals.db_hash, hash_key))) {
+			switch_safe_free(value);
+			switch_core_hash_delete(globals.db_hash, hash_key);
+		}
+		stream->write_function(stream, "+OK\n");
+	} else if (!strcasecmp(argv[0], "select")) {
+		if ((value = switch_core_hash_find(globals.db_hash, hash_key))) {
+			stream->write_function(stream, "%s", value);
+		}
+	}
+	
+end:
+	switch_mutex_unlock(globals.db_hash_mutex);
+	switch_safe_free(mydata);
+	switch_safe_free(hash_key);
+	
+	return SWITCH_STATUS_SUCCESS;
 }
 
 SWITCH_STANDARD_API(group_api_function)
@@ -513,8 +661,8 @@
 	}
 }
 
-#define LIMIT_USAGE "<realm> <id> <max> [transfer_destination_number]"
-#define LIMIT_DESC "limit access to an extension"
+#define LIMIT_USAGE "<realm> <id> <max> [number  [dialplan [context]]]"
+#define LIMIT_DESC "limit access to a resource and transfer to an extension if the limit is exceeded"
 static char *limit_def_xfer_exten = "limit_exceeded";
 
 SWITCH_STANDARD_APP(limit_function)
@@ -530,6 +678,7 @@
 	char buf[80] = "";
 	callback_t cbt = { 0 };
 	switch_channel_t *channel = switch_core_session_get_channel(session);
+	switch_bool_t new_channel = SWITCH_FALSE;
 
 	if (!switch_strlen_zero(data)) {
 		mydata = switch_core_session_strdup(session, data);
@@ -556,7 +705,8 @@
 	if (max < 0) {
 		max = 0;
 	}
-
+	
+	new_channel = !switch_channel_get_variable(channel, "limit_realm");
 	switch_channel_set_variable(channel, "limit_realm", realm);
 	switch_channel_set_variable(channel, "limit_id", id);
 	switch_channel_set_variable(channel, "limit_max", argv[2]);
@@ -572,7 +722,9 @@
 		goto done;
 	}
 
-	switch_core_event_hook_add_state_change(session, hanguphook);
+	if (new_channel) {
+		switch_core_event_hook_add_state_change(session, db_state_handler);
+	}
 	sql =
 		switch_mprintf("insert into limit_data (hostname, realm, id, uuid) values('%q','%q','%q','%q');", globals.hostname, realm, id,
 					   switch_core_session_get_uuid(session));
@@ -583,6 +735,166 @@
 	switch_mutex_unlock(globals.mutex);
 }
 
+#define LIMITHASH_USAGE "<realm> <id> <max>[/interval] [number [dialplan [context]]]"
+#define LIMITHASH_DESC "limit access to a resource and transfer to an extension if the limit is exceeded"
+SWITCH_STANDARD_APP(limit_hash_function)
+{
+	int argc = 0;
+	char *argv[6] = { 0 };
+	char *mydata = NULL;
+	char *realm = NULL;
+	char *id = NULL;
+	char *hashkey = NULL;
+	char *xfer_exten = NULL;
+	int max = 0;
+	int interval = 0;
+	char *szinterval = NULL;
+	limit_hash_item_t *item = NULL;
+	switch_channel_t *channel = switch_core_session_get_channel(session);
+	time_t now = switch_timestamp(NULL);
+	switch_hash_t *channel_hash = NULL;
+	uint8_t increment = 1;
+	uint8_t new_channel = 0;
+	
+	/* Parse application data  */
+	if (!switch_strlen_zero(data)) {
+		mydata = switch_core_session_strdup(session, data);
+		argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
+	}
+	
+	if (argc < 3) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "USAGE: limit_hash %s\n", LIMITHASH_USAGE);
+		return;
+	}
+	
+	realm = argv[0];
+	id = argv[1];
+	if ((szinterval = strchr(argv[2], '/')))
+	{
+		*szinterval++ = '\0';
+		interval = atoi(szinterval);
+	}
+	
+	max = atoi(argv[2]);
+
+	if (argc >= 4) {
+		xfer_exten = argv[3];
+	} else {
+		xfer_exten = limit_def_xfer_exten;
+	}
+
+	if (max < 0) {
+		max = 0;
+	}
+	
+	hashkey = switch_core_session_sprintf(session, "%s_%s", realm, id);
+	
+	switch_mutex_lock(globals.limit_hash_mutex);
+	/* Check if that realm+id has ever been checked */
+	if (!(item = (limit_hash_item_t*)switch_core_hash_find(globals.limit_hash, hashkey))) {
+		/* No, create an empty structure and add it, then continue like as if it existed */
+		item = (limit_hash_item_t*)switch_core_alloc(globals.pool, sizeof(limit_hash_item_t));
+		memset(item, 0, sizeof(limit_hash_item_t));
+		switch_core_hash_insert(globals.limit_hash, hashkey, item);
+	}
+	
+	/* Did we already run on this channel before? */
+	if ((channel_hash = switch_channel_get_private(channel, "limit_hash")))
+	{
+		/* Yes, but check if we did that realm+id */
+		if (!switch_core_hash_find(channel_hash, hashkey)) {
+			/* No, add it to our table so the state handler can take care of it */
+			switch_core_hash_insert(channel_hash, hashkey, item);
+		} else {
+			/* Yes, dont touch total counter */
+			increment = 0;
+		}
+	} else {
+		/* This is the first limit check on this channel, create a hashtable, set our prviate data and add a state handler */
+		new_channel = 1;
+	}
+
+	if (interval > 0) {
+		if (item->last_check <= (now - interval)) {
+			item->rate_usage = 1;
+			item->last_check = now;
+		} else {
+			/* Always increment rate when its checked as it doesnt depend on the channel */
+			item->rate_usage++;
+			
+			if (item->rate_usage > (uint32_t)max) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Usage for %s exceeds maximum rate of %d/%ds, now at %d\n", hashkey, max, interval, item->rate_usage);
+				switch_ivr_session_transfer(session, xfer_exten, argv[4], argv[5]);
+				goto end;
+			}
+		}
+	} else if (item->total_usage + increment > (uint32_t)max) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Usage for %s is already at max value (%d)\n", hashkey, item->total_usage);
+		switch_ivr_session_transfer(session, xfer_exten, argv[4], argv[5]);
+		goto end;
+	}
+
+	if (increment) {
+		item->total_usage++;
+		
+		if (interval == 0) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Usage for %s is now %d/%d\n", hashkey, item->total_usage, max);	
+		} else {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Usage for %s is now %d/%d for the last %d seconds\n", hashkey, item->rate_usage, max, interval);
+		}
+	}
+
+	
+	if (new_channel) {
+		switch_core_hash_init(&channel_hash, switch_core_session_get_pool(session));
+		switch_core_hash_insert(channel_hash, hashkey, item);
+		switch_channel_set_private(channel, "limit_hash", channel_hash);
+		switch_core_event_hook_add_state_change(session, hash_state_handler);
+	}
+	
+end:	
+	switch_mutex_unlock(globals.limit_hash_mutex);
+}
+
+#define LIMIT_HASH_USAGE_USAGE "<realm> <id>"
+SWITCH_STANDARD_API(limit_hash_usage_function)
+{
+	int argc = 0;
+	char *argv[3] = { 0 };
+	char *mydata = NULL;
+	char *hash_key = NULL;
+	limit_hash_item_t *item = NULL;
+	uint32_t count = 0;
+
+	switch_mutex_lock(globals.limit_hash_mutex);
+	
+	if (!switch_strlen_zero(cmd)) {
+		mydata = strdup(cmd);
+		switch_assert(mydata);
+		argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
+	}
+	
+	if (argc < 2) {
+		stream->write_function(stream, "USAGE: limit_hash_usage %s\n", LIMIT_HASH_USAGE_USAGE);
+		goto end;
+	}
+	
+	hash_key = switch_mprintf("%s_%s", argv[0], argv[1]);
+	
+	if ((item = switch_core_hash_find(globals.limit_hash, hash_key))) {
+		count = item->total_usage;
+	} 
+	
+	stream->write_function(stream, "%d", count);
+	
+end:
+	switch_safe_free(mydata);
+	switch_safe_free(hash_key);
+	switch_mutex_unlock(globals.limit_hash_mutex);
+	
+	return SWITCH_STATUS_SUCCESS;
+}
+
 SWITCH_MODULE_LOAD_FUNCTION(mod_limit_load)
 {
 	switch_status_t status;
@@ -598,18 +910,29 @@
 	}
 
 	switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, globals.pool);
+	switch_mutex_init(&globals.limit_hash_mutex, SWITCH_MUTEX_NESTED, globals.pool);
+	switch_mutex_init(&globals.db_hash_mutex, SWITCH_MUTEX_NESTED, globals.pool);
+	switch_core_hash_init(&globals.limit_hash, pool);
+	switch_core_hash_init(&globals.db_hash, pool);
 
 	/* connect my internal structure to the blank pointer passed to me */
 	*module_interface = switch_loadable_module_create_module_interface(pool, modname);
 
 	SWITCH_ADD_APP(app_interface, "limit", "Limit", LIMIT_DESC, limit_function, LIMIT_USAGE, SAF_SUPPORT_NOMEDIA);
+	SWITCH_ADD_APP(app_interface, "limit_hash", "Limit (hash)", LIMITHASH_DESC, limit_hash_function, LIMITHASH_USAGE, SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "db", "Insert to the db", DB_DESC, db_function, DB_USAGE, SAF_SUPPORT_NOMEDIA);
+	SWITCH_ADD_APP(app_interface, "hash", "Insert into the hashtable", HASH_DESC, hash_function, HASH_USAGE, SAF_SUPPORT_NOMEDIA)
 	SWITCH_ADD_APP(app_interface, "group", "Manage a group", GROUP_DESC, group_function, GROUP_USAGE, SAF_SUPPORT_NOMEDIA);
 
+	SWITCH_ADD_API(commands_api_interface, "limit_hash_usage", "Gets the usage count of a limited resource", limit_hash_usage_function,  LIMIT_HASH_USAGE_USAGE);
 	SWITCH_ADD_API(commands_api_interface, "db", "db get/set", db_api_function, "[insert|delete|select]/<realm>/<key>/<value>");
 	switch_console_set_complete("add db insert");
 	switch_console_set_complete("add db delete");
 	switch_console_set_complete("add db select");
+	SWITCH_ADD_API(commands_api_interface, "hash", "hash get/set", hash_api_function, "[insert|delete|select]/<realm>/<key>/<value>");
+	switch_console_set_complete("add hash insert");
+	switch_console_set_complete("add hash delete");
+	switch_console_set_complete("add hash select");
 	SWITCH_ADD_API(commands_api_interface, "group", "group [insert|delete|call]", group_api_function, "[insert|delete|call]:<group name>:<url>");
 	switch_console_set_complete("add group insert");
 	switch_console_set_complete("add group delete");

Modified: freeswitch/branches/gmaruzz/src/mod/applications/mod_voicemail/mod_voicemail.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/applications/mod_voicemail/mod_voicemail.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/applications/mod_voicemail/mod_voicemail.c	Mon Dec 15 12:56:36 2008
@@ -1023,7 +1023,8 @@
 }
 
 static switch_status_t create_file(switch_core_session_t *session, vm_profile_t *profile,
-								   char *macro_name, char *file_path, switch_size_t *message_len, switch_bool_t limit)
+								   char *macro_name, char *file_path, switch_size_t *message_len, switch_bool_t limit,
+								   const char *exit_keys, char *key_pressed)
 {
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 	switch_status_t status = SWITCH_STATUS_SUCCESS;
@@ -1036,13 +1037,17 @@
 
 	read_codec = switch_core_session_get_read_codec(session);
 
+	if (exit_keys) {
+		*key_pressed = '\0';
+	}
+
 	while (switch_channel_ready(channel)) {
 
 		switch_snprintf(key_buf, sizeof(key_buf), "%s:%s:%s", profile->listen_file_key, profile->save_file_key, profile->record_file_key);
 
 	  record_file:
 		*message_len = 0;
-		args.input_callback = cancel_on_dtmf;
+
 		TRY_CODE(switch_ivr_phrase_macro(session, macro_name, NULL, NULL, NULL));
 		TRY_CODE(switch_ivr_gentones(session, profile->tone_spec, 0, NULL));
 
@@ -1050,13 +1055,24 @@
 		fh.thresh = profile->record_threshold;
 		fh.silence_hits = profile->record_silence_hits;
 		fh.samplerate = profile->record_sample_rate;
+
+		memset(input, 0, sizeof(input));
+		args.input_callback = cancel_on_dtmf;
+		args.buf = input;
+		args.buflen = sizeof(input);
+
 		switch_ivr_record_file(session, &fh, file_path, &args, profile->max_record_len);
+
 		if (limit && (*message_len = fh.sample_count / read_codec->implementation->actual_samples_per_second) < profile->min_record_len) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Message is less than minimum record length: %d, discarding it.\n",
-							  profile->min_record_len);
 			if (unlink(file_path) != 0) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Failed to delete file [%s]\n", file_path);
 			}
+			if (exit_keys && input[0] && strchr(exit_keys, input[0])) {
+				*key_pressed = input[0];
+				return SWITCH_STATUS_SUCCESS;
+			}
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Message is less than minimum record length: %d, discarding it.\n",
+							  profile->min_record_len);
 			if (switch_channel_ready(channel)) {
 				TRY_CODE(switch_ivr_phrase_macro(session, VM_ACK_MACRO, "too-small", NULL, NULL));
 				goto record_file;
@@ -1087,7 +1103,7 @@
 				status = SWITCH_STATUS_SUCCESS;
 				*cc.buf = '\0';
 			} else {
-				status = vm_macro_get(session, VM_RECORD_FILE_CHECK_MACRO, key_buf, input, sizeof(input), 1, "", &term, profile->digit_timeout);
+				(void)vm_macro_get(session, VM_RECORD_FILE_CHECK_MACRO, key_buf, input, sizeof(input), 1, "", &term, profile->digit_timeout);
 			}
 
 			if (!strcmp(input, profile->listen_file_key)) {
@@ -1095,7 +1111,7 @@
 			} else if (!strcmp(input, profile->record_file_key)) {
 				goto record_file;
 			} else {
-				TRY_CODE(switch_ivr_phrase_macro(session, VM_ACK_MACRO, "saved", NULL, NULL));
+				(void)switch_ivr_phrase_macro(session, VM_ACK_MACRO, "saved", NULL, NULL);
 				goto end;
 			}
 		}
@@ -1385,9 +1401,9 @@
 					switch_uuid_format(uuid_str, &uuid);
 
 					forward_file_path = switch_core_session_sprintf(session, "%s%smsg_%s.wav", SWITCH_GLOBAL_dirs.temp_dir, SWITCH_PATH_SEPARATOR, uuid_str);
-					TRY_CODE(create_file(session, profile, VM_RECORD_MESSAGE_MACRO, forward_file_path, &message_len, SWITCH_TRUE));
+					TRY_CODE(create_file(session, profile, VM_RECORD_MESSAGE_MACRO, forward_file_path, &message_len, SWITCH_TRUE, NULL, NULL));
 					if ((new_path = vm_merge_file(session, profile, forward_file_path, cbt->file_path))) {
-						switch_ivr_sleep(session, 1500, NULL);
+						switch_ivr_sleep(session, 1500, SWITCH_TRUE, NULL);
 						forward_file_path = new_path;
 					} else {
 						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error merging files\n");
@@ -1621,7 +1637,7 @@
 	*global_buf = '\0';
 
 	while (switch_channel_ready(channel)) {
-		switch_ivr_sleep(session, 100, NULL);
+		switch_ivr_sleep(session, 100, SWITCH_TRUE, NULL);
 
 		switch (vm_check_state) {
 		case VM_CHECK_START:
@@ -1755,7 +1771,7 @@
 				vm_execute_sql(profile, sql, profile->mutex);
 				vm_check_state = VM_CHECK_FOLDER_SUMMARY;
 
-				update_mwi(profile, actual_id, domain_name, myfolder);
+				update_mwi(profile, actual_id ? actual_id : myid, domain_name, myfolder);
 			}
 			break;
 		case VM_CHECK_CONFIG:
@@ -1837,7 +1853,7 @@
 						TRY_CODE(switch_ivr_phrase_macro(session, VM_CHOOSE_GREETING_FAIL_MACRO, NULL, NULL, NULL));
 					} else {
 						file_path = switch_mprintf("%s%sgreeting_%d.%s", dir_path, SWITCH_PATH_SEPARATOR, num, profile->file_ext);
-						TRY_CODE(create_file(session, profile, VM_RECORD_GREETING_MACRO, file_path, &message_len, SWITCH_TRUE));
+						TRY_CODE(create_file(session, profile, VM_RECORD_GREETING_MACRO, file_path, &message_len, SWITCH_TRUE, NULL, NULL));
 						sql =
 							switch_mprintf("update voicemail_prefs set greeting_path='%s' where username='%s' and domain='%s'", file_path, myid,
 										   domain_name);
@@ -1875,7 +1891,7 @@
 					
 				} else if (!strcmp(input, profile->record_name_key)) {
 					file_path = switch_mprintf("%s%srecorded_name.%s", dir_path, SWITCH_PATH_SEPARATOR, profile->file_ext);
-					TRY_CODE(create_file(session, profile, VM_RECORD_NAME_MACRO, file_path, &message_len, SWITCH_FALSE));
+					TRY_CODE(create_file(session, profile, VM_RECORD_NAME_MACRO, file_path, &message_len, SWITCH_FALSE, NULL, NULL));
 					sql = switch_mprintf("update voicemail_prefs set name_path='%s' where username='%s' and domain='%s'", file_path, myid, domain_name);
 					vm_execute_sql(profile, sql, profile->mutex);
 					switch_safe_free(file_path);
@@ -1975,8 +1991,10 @@
 						if (x_box) {
 							myid = switch_core_session_strdup(session, x_box);
 						}
-
-						if (!(actual_id = switch_xml_attr(x_user, "id"))) {
+						
+						if ((actual_id = switch_xml_attr(x_user, "id"))) {
+							actual_id = switch_core_session_strdup(session, actual_id);
+						} else {
 							actual_id = id;
 						}
 					}
@@ -2225,11 +2243,9 @@
 			vm_notify_email = switch_core_strdup(pool, val);
 		} else if (!strcasecmp(var, "email-addr")) {
 			email_addr = switch_core_strdup(pool, val);
-		} else if (!strcasecmp(var, "vm-email-all-messages")) {
-			send_main = switch_true(val);
+		} else if (!strcasecmp(var, "vm-email-all-messages") && (send_main = switch_true(val))) {
 			send_mail++;
-		} else if (!strcasecmp(var, "vm-notify-email-all-messages")) {
-			send_notify = switch_true(val);
+		} else if (!strcasecmp(var, "vm-notify-email-all-messages") && (send_notify = switch_true(val))) {
 			send_mail++;
 		} else if (!strcasecmp(var, "vm-keep-local-after-email")) {
 			insert_db = switch_true(val);
@@ -2613,6 +2629,7 @@
 	int priority = 3;
 	int email_attach = 1;
 	char buf[2];
+	char key_buf[80];
 	char *greet_path = NULL;
 	const char *voicemail_greeting_number = NULL;
 	switch_size_t message_len = 0;
@@ -2625,6 +2642,7 @@
 	int send_main = 0;
 	int send_notify = 0;
 	int insert_db = 1;
+	const char *read_id = NULL;
 	const char *caller_id_name = NULL;
 	const char *caller_id_number = NULL;
 	switch_xml_t x_domain = NULL, x_domain_root = NULL, x_user = NULL, x_params = NULL, x_param = NULL;
@@ -2667,18 +2685,18 @@
 						vm_notify_email = switch_core_session_strdup(session, val);
 					} else if (!strcasecmp(var, "email-addr")) {
 						email_addr = switch_core_session_strdup(session, val);
-					} else if (!strcasecmp(var, "vm-email-all-messages")) {
-						send_main = switch_true(val);
+					} else if (!strcasecmp(var, "vm-email-all-messages") && (send_main = switch_true(val))) {
 						send_mail++;
 					} else if (!strcasecmp(var, "storage-dir")) {
 						vm_storage_dir = switch_core_session_strdup(session, val);
-					} else if (!strcasecmp(var, "vm-notify-email-all-messages")) {
-						send_notify = switch_true(val);
+					} else if (!strcasecmp(var, "vm-notify-email-all-messages") && (send_notify = switch_true(val))) {
 						send_mail++;
 					} else if (!strcasecmp(var, "vm-keep-local-after-email")) {
 						insert_db = switch_true(val);
 					} else if (!strcasecmp(var, "vm-attach-file")) {
 						email_attach = switch_true(val);
+					} else if (!strcasecmp(var, "vm-alternate-greet-id")) {
+						read_id = switch_core_session_strdup(session, val);
 					}
 				}
 			}
@@ -2751,7 +2769,7 @@
 		if (num > 0 && num <= VM_MAX_GREETINGS) {
 			greet_path = switch_mprintf("%s%sgreeting_%d.%s", dir_path, SWITCH_PATH_SEPARATOR, num, profile->file_ext);
 		}
-	} else {
+	} else if (!(greet_path = (char *) switch_channel_get_variable(channel, "voicemail_greeting_path"))) {
 		greet_path = cbt.greeting_path;
 	}
 
@@ -2770,9 +2788,10 @@
 			TRY_CODE(switch_ivr_play_file(session, NULL, cbt.name_path, &args));
 		}
 		if (*buf == '\0') {
-			const char *read_id;
-			if (!(read_id = switch_channel_get_variable(channel, "voicemail_alternate_greet_id"))) {
-				read_id = id;
+			if (!read_id) {
+				if (!(read_id = switch_channel_get_variable(channel, "voicemail_alternate_greet_id"))) {
+					read_id = id;
+				}
 			}
 			memset(buf, 0, sizeof(buf));
 			TRY_CODE(switch_ivr_phrase_macro(session, VM_PLAY_GREETING_MACRO, read_id, NULL, &args));
@@ -2780,6 +2799,7 @@
 	}
 
 	if (*buf != '\0') {
+greet_key_press:
 		if (!strcasecmp(buf, profile->main_menu_key)) {
 			voicemail_check_main(session, profile_name, domain_name, id, 0);
 		} else if (!strcasecmp(buf, profile->operator_key) && !switch_strlen_zero(profile->operator_key)) {
@@ -2835,24 +2855,31 @@
 	switch_channel_set_variable(channel, "RECORD_COMMENT", profile->record_comment);
 	switch_channel_set_variable(channel, "RECORD_COPYRIGHT", profile->record_copyright);
 
-	status = create_file(session, profile, VM_RECORD_MESSAGE_MACRO, file_path, &message_len, SWITCH_TRUE);
+	switch_snprintf(key_buf, sizeof(key_buf), "%s:%s", profile->operator_key, profile->vmain_key);
+	memset(buf, 0, sizeof(buf));
+
+	status = create_file(session, profile, VM_RECORD_MESSAGE_MACRO, file_path, &message_len, SWITCH_TRUE, key_buf, buf);
 
 	if ((status == SWITCH_STATUS_NOTFOUND)) {
 		goto end;
 	}
 
+	if (buf[0]) {
+		goto greet_key_press;
+	}
+
 	if ((status == SWITCH_STATUS_SUCCESS || status == SWITCH_STATUS_BREAK) && switch_channel_ready(channel)) {
-		char input[10] = "", key_buf[80] = "", term = 0;
+		char input[10] = "", term = 0;
 
 		switch_snprintf(key_buf, sizeof(key_buf), "%s:%s", profile->urgent_key, profile->terminator_key);
 
-		vm_macro_get(session, VM_RECORD_URGENT_CHECK_MACRO, key_buf, input, sizeof(input), 1, "", &term, profile->digit_timeout);
+		(void)vm_macro_get(session, VM_RECORD_URGENT_CHECK_MACRO, key_buf, input, sizeof(input), 1, "", &term, profile->digit_timeout);
 		if (*profile->urgent_key == *input) {
 			read_flags = URGENT_FLAG_STRING;
 			priority = 1;
-			TRY_CODE(switch_ivr_phrase_macro(session, VM_ACK_MACRO, "marked-urgent", NULL, NULL));
+			(void)switch_ivr_phrase_macro(session, VM_ACK_MACRO, "marked-urgent", NULL, NULL);
 		} else {
-			TRY_CODE(switch_ivr_phrase_macro(session, VM_ACK_MACRO, "saved", NULL, NULL));
+			(void)switch_ivr_phrase_macro(session, VM_ACK_MACRO, "saved", NULL, NULL);
 		}
 	}
 	

Modified: freeswitch/branches/gmaruzz/src/mod/asr_tts/mod_cepstral/Makefile
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/asr_tts/mod_cepstral/Makefile	(original)
+++ freeswitch/branches/gmaruzz/src/mod/asr_tts/mod_cepstral/Makefile	Mon Dec 15 12:56:36 2008
@@ -1,6 +1,6 @@
 LOCAL_INSERT_LDFLAGS=if test $$osarch = "Darwin" ; then echo "-framework swift" ; else echo "-L$(SWIFT_HOME)/lib -L/opt/swift/lib -lswift -lm" ; fi ;
 
-LOCAL_INSERT_CFLAGS=test $$osarch = "Darwin" || echo "-I$(SWIFT_HOME)/include -I/opt/swift/include";
+LOCAL_INSERT_CFLAGS=if test $$osarch = "Darwin" ; then echo "-I/Library/Frameworks/swift.framework/Versions/5/Headers/" ; else echo "-I$(SWIFT_HOME)/include -I/opt/swift/include"; fi ;
 LOCAL_CFLAGS=-w
 include ../../../../build/modmake.rules
 

Modified: freeswitch/branches/gmaruzz/src/mod/asr_tts/mod_cepstral/mod_cepstral.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/asr_tts/mod_cepstral/mod_cepstral.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/asr_tts/mod_cepstral/mod_cepstral.c	Mon Dec 15 12:56:36 2008
@@ -38,11 +38,7 @@
 #ifdef __ICC
 #pragma warning (disable:188)
 #endif
-#ifdef MACOSX
-#include <swift/swift.h>
-#else
 #include <swift.h>
-#endif
 #include <switch.h>
 
 #define MY_BUF_LEN 1024 * 32

Modified: freeswitch/branches/gmaruzz/src/mod/asr_tts/mod_pocketsphinx/Makefile
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/asr_tts/mod_pocketsphinx/Makefile	(original)
+++ freeswitch/branches/gmaruzz/src/mod/asr_tts/mod_pocketsphinx/Makefile	Mon Dec 15 12:56:36 2008
@@ -18,7 +18,7 @@
 	$(GETLIB) $(SPHINXBASE).tar.gz
 
 $(SPHINXBASE_DIR)/buildstamp: $(SPHINXBASE_DIR)
-	test -f $(SPHINXBASE_DIR)/Makefile || (cd $(SPHINXBASE_DIR) && ./configure --with-pic --without-python --disable-shared)
+	test -f $(SPHINXBASE_DIR)/Makefile || (cd $(SPHINXBASE_DIR) && ./configure --with-pic --without-python --disable-shared CFLAGS=)
 	test -f $(SPHINXBASE_DIR)/buildstamp || (touch $(SPHINXBASE_DIR)/buildstamp)
 
 $(SPHINXBASE_LA): $(SPHINXBASE_DIR)/buildstamp
@@ -29,7 +29,7 @@
 	$(GETLIB) $(POCKETSPHINX).tar.gz
 
 $(POCKETSPHINX_DIR)/Makefile: $(POCKETSPHINX_DIR)
-	cd $(POCKETSPHINX_DIR) && ./configure --with-pic --without-python --disable-shared --with-sphinxbase=$(SPHINXBASE_DIR)
+	cd $(POCKETSPHINX_DIR) && ./configure --with-pic --without-python --disable-shared --with-sphinxbase=$(SPHINXBASE_DIR) CFLAGS=
 	$(TOUCH_TARGET)
 
 $(POCKETSPHINX_DIR)/buildstamp: $(POCKETSPHINX_DIR)/Makefile

Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_dingaling/mod_dingaling.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_dingaling/mod_dingaling.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_dingaling/mod_dingaling.c	Mon Dec 15 12:56:36 2008
@@ -413,6 +413,7 @@
 	char *rpid = switch_event_get_header(event, "rpid");
 	char *type = switch_event_get_header(event, "event_subtype");
 	char *sql;
+	char pstr[128] = "";
 
 	if (globals.running != 1) {
 		return;
@@ -475,10 +476,12 @@
 		status = "Away";
 	}
 
+	if (proto) {
+		switch_snprintf(pstr, sizeof(pstr), "%s+", proto);
+	}
 
 	sql =
-		switch_mprintf("select sub_from, sub_to,'%q','%q','%q','%q' from jabber_subscriptions where sub_to like '%%%q'", type, rpid, status, proto, from);
-
+		switch_mprintf("select sub_from, sub_to,'%q','%q','%q','%q' from jabber_subscriptions where sub_to = '%q%q'", type, rpid, status, proto, pstr, from);
 
 	for (hi = switch_hash_first(NULL, globals.profile_hash); hi; hi = switch_hash_next(hi)) {
 		switch_hash_this(hi, NULL, NULL, &val);
@@ -536,7 +539,7 @@
 					*p = '\0';
 				}
 			}
-			ldl_handle_send_msg(profile->handle, from, to, NULL, body);
+			ldl_handle_send_msg(profile->handle, from, to, NULL, switch_str_nil(body));
 		} else {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Profile %s\n", f_host ? f_host : "NULL");
 			return SWITCH_STATUS_FALSE;
@@ -1713,7 +1716,7 @@
 				if ((ptr = strchr(them, '/'))) {
 					*ptr = '\0';
 				}
-				ldl_handle_send_msg(mdl_profile->handle, tech_pvt->us, them, "", cid_msg);
+				ldl_handle_send_msg(mdl_profile->handle, tech_pvt->us, them, "", switch_str_nil(cid_msg));
 			}
 			switch_safe_free(them);
 		}
@@ -2464,7 +2467,7 @@
 				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);
+										switch_str_nil(profile->auto_reply));
 				}
 #endif
 
@@ -2487,7 +2490,7 @@
 				}
 
 				if ((ci = switch_loadable_module_get_chat_interface(proto))) {
-					ci->chat_send(MDL_CHAT_PROTO, from, to, subject, msg, hint);
+					ci->chat_send(MDL_CHAT_PROTO, from, to, subject, switch_str_nil(msg), hint);
 				} else {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Chat Interface [%s]!\n", proto);
 				}
@@ -2896,7 +2899,7 @@
 
 				if (!switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) {
 					switch_set_flag_locked(tech_pvt, TFLAG_TRANSPORT_ACCEPT);
-					ldl_session_accept_candidate(dlsession, &candidates[choice]);
+					//ldl_session_accept_candidate(dlsession, &candidates[choice]);
 				}
 
 				if (!strcasecmp(subject, "candidates")) {

Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_iax/iax-client.h
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_iax/iax-client.h	(original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_iax/iax-client.h	Mon Dec 15 12:56:36 2008
@@ -23,7 +23,7 @@
 #pragma warning(disable:4200)
 #endif
 
-#if !defined(LINUX) && !defined(NETBSD)
+#if !defined(LINUX) && !defined(__NetBSD__)
 #define socklen_t int
 #endif
 

Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_loopback/mod_loopback.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_loopback/mod_loopback.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_loopback/mod_loopback.c	Mon Dec 15 12:56:36 2008
@@ -257,6 +257,10 @@
 			switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
 			goto end;
 		}
+
+		switch_channel_set_variable(channel,"other_loopback_leg_uuid",switch_channel_get_uuid(b_channel));
+		switch_channel_set_variable(b_channel,"other_loopback_leg_uuid",switch_channel_get_uuid(channel));
+
 	}
 	
 	if (tech_pvt->other_session) {
@@ -694,6 +698,7 @@
 
 			switch_snprintf(name, sizeof(name), "loopback/%s-a", caller_profile->destination_number);
 			switch_channel_set_name(channel, name);
+			switch_channel_set_flag(channel, CF_OUTBOUND);
 
 			switch_channel_set_caller_profile(channel, caller_profile);
 			tech_pvt->caller_profile = caller_profile;

Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/mod_sofia.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/mod_sofia.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/mod_sofia.c	Mon Dec 15 12:56:36 2008
@@ -451,10 +451,15 @@
 			
 			/* Unlock the session signal to allow the ack to make it in */
 			// Maybe we should timeout?
+			switch_mutex_unlock(tech_pvt->sofia_mutex);
 			
 			while(switch_channel_ready(channel) && !switch_test_flag(tech_pvt, TFLAG_3PCC_HAS_ACK)) {
 				switch_cond_next();
 			}
+			
+			/*  Regain lock on sofia */
+			switch_mutex_lock(tech_pvt->sofia_mutex);
+			
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "3PCC-PROXY, Done waiting for ACK\n");
 		}
 
@@ -697,17 +702,34 @@
 						*frame = NULL;
 						return SWITCH_STATUS_GENERR;
 					}
+					
+					if (tech_pvt->check_frames++ < MAX_CODEC_CHECK_FRAMES) {
+						if (!tech_pvt->read_codec.implementation->encoded_bytes_per_packet) {
+							tech_pvt->check_frames = MAX_CODEC_CHECK_FRAMES;
+							goto skip;
+						}
 
-
-					if (tech_pvt->check_frames < MAX_CODEC_CHECK_FRAMES) {
 						if (tech_pvt->last_ts && tech_pvt->read_frame.datalen != tech_pvt->read_codec.implementation->encoded_bytes_per_packet) {
 							switch_size_t codec_ms = (int)(tech_pvt->read_frame.timestamp - 
 														   tech_pvt->last_ts) / (tech_pvt->read_codec.implementation->samples_per_second / 1000);
-							
+
 							if ((codec_ms % 10) != 0) {
 								tech_pvt->check_frames = MAX_CODEC_CHECK_FRAMES;
-							} else {
+								goto skip;
+							}
+							
+							if (tech_pvt->last_codec_ms && tech_pvt->last_codec_ms == codec_ms) {
+								tech_pvt->mismatch_count++;
+							}
+
+							tech_pvt->last_codec_ms = codec_ms;
+
+							if (tech_pvt->mismatch_count > MAX_MISMATCH_FRAMES) {
 								if (switch_rtp_ready(tech_pvt->rtp_session) && codec_ms != tech_pvt->codec_ms) {
+									const char *val;
+									int rtp_timeout_sec = 0;
+									int rtp_hold_timeout_sec = 0;
+									
 									tech_pvt->codec_ms = codec_ms;
 									switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, 
 													  "Changing codec ptime to %d. I bet you have a linksys/sipura =D\n", tech_pvt->codec_ms);
@@ -718,19 +740,55 @@
 										return SWITCH_STATUS_GENERR;
 									}
 
-									switch_rtp_change_interval(tech_pvt->rtp_session, 
-															   tech_pvt->read_codec.implementation->samples_per_packet,
-															   tech_pvt->codec_ms * 1000);
+
+									if ((val = switch_channel_get_variable(tech_pvt->channel, "rtp_timeout_sec"))) {
+										int v = atoi(val);
+										if (v >= 0) {
+											rtp_timeout_sec = v;
+										}
+									}
+									
+									if ((val = switch_channel_get_variable(tech_pvt->channel, "rtp_hold_timeout_sec"))) {
+										int v = atoi(val);
+										if (v >= 0) {
+											rtp_hold_timeout_sec = v;
+										}
+									}
+									
+									if (rtp_timeout_sec) {
+										tech_pvt->max_missed_packets = (tech_pvt->read_codec.implementation->samples_per_second * rtp_timeout_sec) /
+											tech_pvt->read_codec.implementation->samples_per_packet;
+										
+										switch_rtp_set_max_missed_packets(tech_pvt->rtp_session, tech_pvt->max_missed_packets);
+										if (!rtp_hold_timeout_sec) {
+											rtp_hold_timeout_sec = rtp_timeout_sec * 10;
+										}
+									}
+									
+									if (rtp_hold_timeout_sec) {
+										tech_pvt->max_missed_hold_packets = (tech_pvt->read_codec.implementation->samples_per_second * rtp_hold_timeout_sec) /
+											tech_pvt->read_codec.implementation->samples_per_packet;
+									}
+									
+									if (switch_rtp_change_interval(tech_pvt->rtp_session, 
+																   tech_pvt->codec_ms * 1000,
+																   tech_pvt->read_codec.implementation->samples_per_packet
+																   ) != SWITCH_STATUS_SUCCESS) {
+										switch_channel_hangup(tech_pvt->channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+										
+									}
 
 									tech_pvt->check_frames = MAX_CODEC_CHECK_FRAMES;
 								}
 							
 							}
-							tech_pvt->check_frames++;
-
+							
+						} else {
+							tech_pvt->mismatch_count = 0;
 						}
 						tech_pvt->last_ts = tech_pvt->read_frame.timestamp;
 					}
+				skip:
 					
 					if ((bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_packet)) {
 						frames = (tech_pvt->read_frame.datalen / bytes);
@@ -885,21 +943,11 @@
 		goto end;
 
 	case SWITCH_MESSAGE_INDICATE_BRIDGE:
-		/*
-		   if (tech_pvt->rtp_session && switch_test_flag(tech_pvt, 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");
-		   }
-		 */
-		goto end;
-
 	case SWITCH_MESSAGE_INDICATE_UNBRIDGE:
-		/*
-		   if (tech_pvt->rtp_session && switch_test_flag(tech_pvt, TFLAG_TIMER)) {
-		   switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_USE_TIMER);
-		   switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Re-activate timed RTP!\n");
-		   }
-		 */
+	case SWITCH_MESSAGE_INDICATE_AUDIO_SYNC:
+		if (switch_rtp_ready(tech_pvt->rtp_session)) {
+			rtp_flush_read_buffer(tech_pvt->rtp_session);
+		}
 		goto end;
 
 	case SWITCH_MESSAGE_INDICATE_ANSWER:
@@ -1074,6 +1122,7 @@
 	case SWITCH_MESSAGE_INDICATE_DEFLECT:
 		{
 			char ref_to[128] = "";
+			const char *var;
 
 			if (!strstr(msg->string_arg, "sip:")) {
 				const char *format = strchr(tech_pvt->profile->sipip, ':') ? "sip:%s@[%s]" : "sip:%s@%s";
@@ -1082,6 +1131,15 @@
 				switch_set_string(ref_to, msg->string_arg);
 			}
 			nua_refer(tech_pvt->nh, SIPTAG_REFER_TO_STR(ref_to), SIPTAG_REFERRED_BY_STR(tech_pvt->contact_url), TAG_END());
+			switch_mutex_unlock(tech_pvt->sofia_mutex);
+			sofia_wait_for_reply(tech_pvt, 9999, 300);
+			switch_mutex_lock(tech_pvt->sofia_mutex);
+			
+			if ((var = switch_channel_get_variable(tech_pvt->channel, "sip_refer_reply"))) {
+				msg->string_reply = switch_core_session_strdup(session, var); 
+			} else {
+				msg->string_reply = "no reply";
+			}
 		}
 		break;
 
@@ -1307,6 +1365,7 @@
 	"REGED",
 	"UNREGISTER",
 	"FAILED",
+	"FAIL_WAIT",
 	"EXPIRED",
 	"NOREG",
 	NULL
@@ -1350,6 +1409,36 @@
 	return 0;
 }
 
+static int show_reg_callback_xml(void *pArg, int argc, char **argv, char **columnNames)
+{
+	struct cb_helper *cb = (struct cb_helper *) pArg;
+	char exp_buf[128] = "";
+	switch_time_exp_t tm;
+	const int buflen = 2048;
+	char xmlbuf[2048];
+  
+	if (argv[6]) {
+		switch_time_t etime = atoi(argv[6]);
+		switch_size_t retsize;
+
+		switch_time_exp_lt(&tm, switch_time_from_sec(etime));
+		switch_strftime_nocheck(exp_buf, &retsize, sizeof(exp_buf), "%Y-%m-%d %T", &tm);
+	}
+
+	cb->stream->write_function(cb->stream,
+							   "<Registration>\n"
+							   "<Call-ID>%s</Call-ID>\n"
+							   "<User>%s@%s</User>\n"
+							   "<Contact>%s</Contact>\n"
+							   "<Agent>%s</Agent>\n"
+							   "<Status>%s(%s) EXP(%s)</Status>\n"
+							   "<Host>%s</Host>\n"
+							   "</Registration>\n", 
+							   switch_str_nil(argv[0]), switch_str_nil(argv[1]), switch_str_nil(argv[2]), switch_amp_encode(switch_str_nil(argv[3]),xmlbuf,buflen),
+							   switch_str_nil(argv[7]), switch_str_nil(argv[4]), switch_str_nil(argv[5]), exp_buf, switch_str_nil(argv[11]));
+	return 0;
+}
+
 static const char *status_names[] = { "DOWN", "UP", NULL };
 
 static switch_status_t cmd_status(char **argv, int argc, switch_stream_handle_t *stream)
@@ -1535,6 +1624,194 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
+static switch_status_t cmd_xml_status(char **argv, int argc, switch_stream_handle_t *stream)
+{
+	sofia_profile_t *profile = NULL;
+	sofia_gateway_t *gp;
+	switch_hash_index_t *hi;
+	void *val;
+	const void *vvar;
+	const int buflen = 2096;
+	char xmlbuf[2096];
+	int c = 0;
+	int ac = 0;
+  const char *header = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
+	
+  if (argc > 0) {
+		if (argc == 1) {
+			stream->write_function(stream, "Invalid Syntax!\n");
+			return SWITCH_STATUS_SUCCESS;
+		}
+		if (!strcasecmp(argv[0], "gateway")) {
+			if ((gp = sofia_reg_find_gateway(argv[1]))) {
+				switch_assert(gp->state < REG_STATE_LAST);
+        stream->write_function(stream, "%s\n", header);
+        stream->write_function(stream, "<Gateway>\n");
+				stream->write_function(stream, "<Name>%s</Name>\n", switch_str_nil(gp->name));
+				stream->write_function(stream, "<Scheme>%s</Scheme>\n", switch_str_nil(gp->register_scheme));
+				stream->write_function(stream, "<Realm>%s</Realm>\n", switch_str_nil(gp->register_realm));
+				stream->write_function(stream, "<Username>%s</Username>\n", switch_str_nil(gp->register_username));
+				stream->write_function(stream, "<Password>%s</Password>\n", switch_strlen_zero(gp->register_password) ? "no" : "yes");
+				stream->write_function(stream, "<From>%s</From>\n", switch_amp_encode(switch_str_nil(gp->register_from),xmlbuf,buflen));
+				stream->write_function(stream, "<Contact>%s</Contact>\n", switch_amp_encode(switch_str_nil(gp->register_contact),xmlbuf,buflen));
+				stream->write_function(stream, "<To>%s</To>\n", switch_str_nil(gp->register_to));
+				stream->write_function(stream, "<Proxy>%s</Proxy>\n", switch_str_nil(gp->register_proxy));
+				stream->write_function(stream, "<Context>%s</Context>\n", switch_str_nil(gp->register_context));
+				stream->write_function(stream, "<Expires>%s</Expires>\n", switch_str_nil(gp->expires_str));
+				stream->write_function(stream, "<Freq>%d</Freq>\n", gp->freq);
+				stream->write_function(stream, "<Ping>%d</Ping>\n", gp->ping);
+				stream->write_function(stream, "<PingFreq>%d</PingFreq>\n", gp->ping_freq);
+				stream->write_function(stream, "<State>%s</State>\n", sofia_state_names[gp->state]);
+				stream->write_function(stream, "<Status>%s%s</Status>\n", status_names[gp->status], gp->pinging ? " (ping)" : "");
+				stream->write_function(stream, "</Gateway>\n");
+				sofia_reg_release_gateway(gp);
+			} else {
+				stream->write_function(stream, "Invalid Gateway!\n");
+			}
+		} else if (!strcasecmp(argv[0], "profile")) {
+			struct cb_helper cb;
+			char *sql = NULL;
+
+			if ((argv[1]) && (profile = sofia_glue_find_profile(argv[1]))) {
+				if (!argv[2] || strcasecmp(argv[2], "reg")) {
+					stream->write_function(stream, "%s\n", header);
+					stream->write_function(stream, "<Profile>\n");
+					stream->write_function(stream, "<ProfileInfo>\n");
+					stream->write_function(stream, "<Name>%s</Name>\n", switch_str_nil(argv[1]));
+					stream->write_function(stream, "<DomainName>%s</DomainName>\n", profile->domain_name ? profile->domain_name : "N/A");
+					if (strcasecmp(argv[1], profile->name)) {
+						stream->write_function(stream, "<AliasOf>%s</AliasOf>\n", switch_str_nil(profile->name));
+					}
+					stream->write_function(stream, "<DBName>%s</DBName>\n", switch_str_nil(profile->dbname));
+					stream->write_function(stream, "<PresHosts>%s</PresHosts>\n", switch_str_nil(profile->presence_hosts));
+					stream->write_function(stream, "<Dialplan>%s</Dialplan>\n", switch_str_nil(profile->dialplan));
+					stream->write_function(stream, "<Context>%s</Context>\n", switch_str_nil(profile->context));
+					stream->write_function(stream, "<ChallengeRealm>%s</ChallengeRealm>\n", 
+										   switch_strlen_zero(profile->challenge_realm) ? "auto_to" : profile->challenge_realm);
+					stream->write_function(stream, "<RTP-IP>%s</RTP-IP>\n", switch_str_nil(profile->rtpip));
+					if (profile->extrtpip) {
+						stream->write_function(stream, "<Ext-RTP-IP>%s</Ext-RTP-IP>\n", profile->extrtpip);
+					}
+
+					stream->write_function(stream, "<SIP-IP>%s</SIP-IP>\n", switch_str_nil(profile->sipip));
+					if (profile->extsipip) {
+						stream->write_function(stream, "<Ext-SIP-IP>%s</Ext-SIP-IP>\n", profile->extsipip);
+					}
+					stream->write_function(stream, "<URL>%s</URL>\n", switch_str_nil(profile->url));
+					stream->write_function(stream, "<BIND-URL>%s</BIND-URL>\n", switch_str_nil(profile->bindurl));
+					if (sofia_test_pflag(profile, PFLAG_TLS)) {
+						stream->write_function(stream, "<TLS-URL>%s</TLS-URL>\n", switch_str_nil(profile->tls_url));
+						stream->write_function(stream, "<TLS-BIND-URL>%s</TLS-BIND-URL>\n", switch_str_nil(profile->tls_bindurl));
+					}
+					stream->write_function(stream, "<HOLD-MUSIC>%s</HOLD-MUSIC>\n", switch_strlen_zero(profile->hold_music) ? "N/A" : profile->hold_music);
+					stream->write_function(stream, "<CODECS>%s</CODECS>\n", switch_str_nil(profile->codec_string));
+					stream->write_function(stream, "<TEL-EVENT>%d</TEL-EVENT>\n", profile->te);
+					if (profile->dtmf_type == DTMF_2833) {
+						stream->write_function(stream, "<DTMF-MODE>rfc2833</DTMF-MODE>\n");
+					} else if (profile->dtmf_type == DTMF_INFO) {
+						stream->write_function(stream, "<DTMF-MODE>info</DTMF-MODE>\n");
+					} else {
+						stream->write_function(stream, "<DTMF-MODE>none</DTMF-MODE>\n");
+					}
+					stream->write_function(stream, "<CNG>%d</CNG>\n", profile->cng_pt);
+					stream->write_function(stream, "<SESSION-TO>%d</SESSION-TO>\n", profile->session_timeout);
+					stream->write_function(stream, "<MAX-DIALOG>%d</MAX-DIALOG>\n", profile->max_proceeding);
+					stream->write_function(stream, "<NOMEDIA>%s</NOMEDIA>\n", switch_test_flag(profile, TFLAG_INB_NOMEDIA) ? "true" : "false");
+					stream->write_function(stream, "<LATE-NEG>%s</LATE-NEG>\n", switch_test_flag(profile, TFLAG_LATE_NEGOTIATION) ? "true" : "false");
+					stream->write_function(stream, "<PROXY-MEDIA>%s</PROXY-MEDIA>\n", switch_test_flag(profile, TFLAG_PROXY_MEDIA) ? "true" : "false");
+					stream->write_function(stream, "<AGGRESSIVENAT>%s</AGGRESSIVENAT>\n", sofia_test_pflag(profile, PFLAG_AGGRESSIVE_NAT_DETECTION) ? "true" : "false");
+					stream->write_function(stream, "<STUN_ENABLED>%s</STUN_ENABLED>\n", sofia_test_pflag(profile, PFLAG_STUN_ENABLED) ? "true" : "false");
+					stream->write_function(stream, "<STUN_AUTO_DISABLE>%s</STUN_AUTO_DISABLE>\n", sofia_test_pflag(profile, PFLAG_STUN_AUTO_DISABLE) ? "true" : "false");
+				}
+				stream->write_function(stream, "</ProfileInfo>\n");
+				stream->write_function(stream, "<Registrations>\n");
+
+				cb.profile = profile;
+				cb.stream = stream;
+				
+				if (argv[3]) {
+					if (argv[4]) {
+						if (!strcasecmp(argv[3], "pres")) {
+							sql = switch_mprintf("select call_id,sip_user,sip_host,contact,status,"
+												 "rpid,expires,user_agent,server_user,server_host,profile_name,hostname"
+												 " from sip_registrations where profile_name='%q' and presence_hosts like '%%%q%%'", 
+												 profile->name, argv[4]);
+						}
+					} else {
+						sql = switch_mprintf("select call_id,sip_user,sip_host,contact,status,"
+											 "rpid,expires,user_agent,server_user,server_host,profile_name,hostname"
+											 " from sip_registrations where profile_name='%q' and contact like '%%%q%%'", 
+											 profile->name, argv[3]);
+					}
+				}
+
+				if (!sql) {
+					sql = switch_mprintf("select call_id,sip_user,sip_host,contact,status,"
+										 "rpid,expires,user_agent,server_user,server_host,profile_name,hostname"
+										 " from sip_registrations where profile_name='%q'", 
+										 profile->name);
+				}
+
+				sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex, sql, show_reg_callback_xml, &cb);
+				free(sql);
+
+				stream->write_function(stream, "</Registrations>\n");
+				stream->write_function(stream, "</Profile>\n");
+
+				sofia_glue_release_profile(profile);
+			} else {
+				stream->write_function(stream, "Invalid Profile!\n");
+			}
+		} else {
+			stream->write_function(stream, "Invalid Syntax!\n");
+		}
+
+		return SWITCH_STATUS_SUCCESS;
+	}
+
+  stream->write_function(stream, "%s\n", header);
+  stream->write_function(stream, "<Profiles>\n");
+	switch_mutex_lock(mod_sofia_globals.hash_mutex);
+	for (hi = switch_hash_first(NULL, mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) {
+		switch_hash_this(hi, &vvar, NULL, &val);
+		profile = (sofia_profile_t *) val;
+		if (sofia_test_pflag(profile, PFLAG_RUNNING)) {
+
+			if (strcmp(vvar, profile->name)) {
+				ac++;
+				stream->write_function(stream, "<alias>\n<Name>%s</Name>\n<Type>%s</Type>\n<Data>%s</Data>\n<State>%s</State>\n</alias>\n", vvar, "alias", profile->name, "ALIASED");
+			} else {
+				stream->write_function(stream, "<profile>\n<Name>%s</Name>\n<Type>%s</Type>\n<Data>%s</Data>\n<State>%s (%u)</State>\n</profile>\n", profile->name, "profile", profile->url,
+									   sofia_test_pflag(profile, PFLAG_RUNNING) ? "RUNNING" : "DOWN", profile->inuse);
+
+				if (sofia_test_pflag(profile, PFLAG_TLS)) {
+					stream->write_function(stream, "<profile>\n<Name>%s</Name>\n<Type>%s</Type>\n<Data>%s</Data>\n<State>%s (%u) (TLS)</State>\n</profile>\n", profile->name, "profile", profile->tls_url,
+										   sofia_test_pflag(profile, PFLAG_RUNNING) ? "RUNNING" : "DOWN", profile->inuse);
+				}
+
+				c++;
+
+				for (gp = profile->gateways; gp; gp = gp->next) {
+					switch_assert(gp->state < REG_STATE_LAST);
+					stream->write_function(stream, "<gateway>\n<Name>%s</Name>\n<Type>%s</Type>\n<Data>%s</Data>\n<State>%s</State>\n</gateway>\n", gp->name, "gateway", gp->register_to, sofia_state_names[gp->state]);
+					if (gp->state == REG_STATE_FAILED || gp->state == REG_STATE_TRYING) {
+						time_t now = switch_timestamp(NULL);
+						if (gp->retry > now) {
+							stream->write_function(stream, " (retry: %ds)", gp->retry - now);
+						} else {
+							stream->write_function(stream, " (retry: NEVER)");
+						}
+					}
+					stream->write_function(stream, "\n");
+				}
+			}
+		}
+	}
+	switch_mutex_unlock(mod_sofia_globals.hash_mutex);
+	stream->write_function(stream, "</Profiles>\n");
+	return SWITCH_STATUS_SUCCESS;
+}
+
 static switch_status_t cmd_profile(char **argv, int argc, switch_stream_handle_t *stream)
 {
 	sofia_profile_t *profile = NULL;
@@ -1924,6 +2201,8 @@
 		func = cmd_profile;
 	} else if (!strcasecmp(argv[0], "status")) {
 		func = cmd_status;
+	} else if (!strcasecmp(argv[0], "xmlstatus")) {
+		func = cmd_xml_status;
 	} else if (!strcasecmp(argv[0], "loglevel")) {
 		if (argc > 1 && argv[1]) {
 			int level;
@@ -2319,10 +2598,26 @@
 			const char *user = switch_event_get_header(event, "user");
 			const char *host = switch_event_get_header(event, "host");
 			const char *call_id = switch_event_get_header(event, "call-id");
+			const char *uuid = switch_event_get_header(event, "uuid");
 			const char *body = switch_event_get_body(event);
 			sofia_profile_t *profile;
 
-			if (profile_name && ct && es && user && host && (profile = sofia_glue_find_profile(profile_name))) {
+			if (uuid && ct && es) {
+				switch_core_session_t *session;
+				private_object_t *tech_pvt;
+
+				if ((session = switch_core_session_locate(uuid))) {
+					if ((tech_pvt = switch_core_session_get_private(session))) {
+						nua_notify(tech_pvt->nh,
+								   NUTAG_NEWSUB(1),
+								   SIPTAG_EVENT_STR(es), 
+								   SIPTAG_CONTENT_TYPE_STR(ct), 
+								   TAG_IF(!switch_strlen_zero(body), SIPTAG_PAYLOAD_STR(body)),
+								   TAG_END());
+					}
+					switch_core_session_rwunlock(session);
+				}
+			} else if (profile_name && ct && es && user && host && (profile = sofia_glue_find_profile(profile_name))) {
 				char *sql;
 
 				if (call_id) {
@@ -2407,7 +2702,7 @@
 		{
 			const char *cond = switch_event_get_header(event, "condition");
 
-			if (cond && !strcmp(cond, "network-address-change")) {
+			if (cond && !strcmp(cond, "network-address-change") && mod_sofia_globals.auto_restart) {
 				sofia_glue_restart_all_profiles();
 			}
 			

Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/mod_sofia.h
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/mod_sofia.h	(original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/mod_sofia.h	Mon Dec 15 12:56:36 2008
@@ -54,11 +54,15 @@
 #endif
 
 #define MAX_CODEC_CHECK_FRAMES 50
+#define MAX_MISMATCH_FRAMES 3
 #define MODNAME "mod_sofia"
 static const switch_state_handler_table_t noop_state_handler = { 0 };
 struct sofia_gateway;
 typedef struct sofia_gateway sofia_gateway_t;
 
+struct sofia_gateway_subscription;
+typedef struct sofia_gateway_subscription sofia_gateway_subscription_t;
+
 struct sofia_profile;
 typedef struct sofia_profile sofia_profile_t;
 #define NUA_MAGIC_T sofia_profile_t
@@ -74,6 +78,7 @@
 #define MY_EVENT_UNREGISTER "sofia::unregister"
 #define MY_EVENT_EXPIRE "sofia::expire"
 #define MY_EVENT_GATEWAY_STATE "sofia::gateway_state"
+#define MY_EVENT_NOTIFY_REFER "sofia::notify_refer"
 
 #define MULTICAST_EVENT "multicast::event"
 #define SOFIA_REPLACES_HEADER "_sofia_replaces_"
@@ -237,6 +242,8 @@
 	switch_event_node_t *roster_node;
 	switch_event_node_t *custom_node;
 	switch_event_node_t *mwi_node;
+	int debug_presence;
+	int auto_restart;
 };
 extern struct mod_sofia_globals mod_sofia_globals;
 
@@ -252,6 +259,7 @@
 	REG_STATE_REGED,
 	REG_STATE_UNREGISTER,
 	REG_STATE_FAILED,
+	REG_STATE_FAIL_WAIT,
 	REG_STATE_EXPIRED,
 	REG_STATE_NOREG,
 	REG_STATE_LAST
@@ -270,6 +278,31 @@
 	SOFIA_GATEWAY_UP
 } sofia_gateway_status_t;
 
+typedef enum {
+	SUB_STATE_UNSUBED,
+	SUB_STATE_TRYING,
+	SUB_STATE_SUBSCRIBE,
+	SUB_STATE_SUBED,
+	SUB_STATE_UNSUBSCRIBE,
+	SUB_STATE_FAILED,
+	SUB_STATE_EXPIRED,
+	SUB_STATE_NOSUB,
+	v_STATE_LAST
+} sub_state_t;
+
+struct sofia_gateway_subscription {
+	sofia_gateway_t *gateway;
+	char *expires_str;
+	char *event;  /* eg, 'message-summary' to subscribe to MWI events */
+	char *content_type;  /* eg, application/simple-message-summary in the case of MWI events */
+	uint32_t freq;
+	int32_t retry_seconds;
+	time_t expires;
+	time_t retry;
+	sub_state_t state;
+	struct sofia_gateway_subscription *next;
+};
+
 struct sofia_gateway {
 	sofia_private_t *sofia_private;
 	nua_handle_t *nh;
@@ -303,7 +336,9 @@
 	int deleted;
 	switch_event_t *vars;
 	char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
+	int failures;
 	struct sofia_gateway *next;
+	sofia_gateway_subscription_t *subscriptions;
 };
 
 typedef enum {
@@ -334,6 +369,8 @@
 	char *bindurl;
 	char *tls_url;
 	char *tls_bindurl;
+	char *tcp_contact;
+	char *tls_contact;
 	char *sipdomain;
 	char *timer_name;
 	char *hold_music;
@@ -395,6 +432,7 @@
 	int rport_level;
 	sofia_presence_type_t pres_type;
 	sofia_media_options_t media_options;
+	uint32_t force_subscription_expires;
 };
 
 struct private_object {
@@ -511,6 +549,9 @@
 	switch_thread_id_t locker;
 	switch_size_t last_ts;
 	uint32_t check_frames;
+	uint32_t mismatch_count;
+	uint32_t last_codec_ms;
+	nua_event_t want_event;
 };
 
 struct callback_t {
@@ -618,6 +659,7 @@
 void sofia_glue_actually_execute_sql(sofia_profile_t *profile, switch_bool_t master, char *sql, switch_mutex_t *mutex);
 void sofia_reg_check_expire(sofia_profile_t *profile, time_t now, int reboot);
 void sofia_reg_check_gateway(sofia_profile_t *profile, time_t now);
+void sofia_sub_check_gateway(sofia_profile_t *profile, time_t now);
 void sofia_reg_unregister(sofia_profile_t *profile);
 switch_status_t sofia_glue_ext_address_lookup(sofia_profile_t *profile, private_object_t *tech_pvt, char **ip, switch_port_t *port, char *sourceip, switch_memory_pool_t *pool);
 
@@ -656,6 +698,8 @@
 sofia_gateway_t *sofia_reg_find_gateway__(const char *file, const char *func, int line, const char *key);
 #define sofia_reg_find_gateway(x) sofia_reg_find_gateway__(__FILE__, __SWITCH_FUNC__, __LINE__,  x)
 
+sofia_gateway_subscription_t *sofia_find_gateway_subscription(sofia_gateway_t *gateway_ptr, const char *event);
+
 void sofia_reg_release_gateway__(const char *file, const char *func, int line, sofia_gateway_t *gateway);
 #define sofia_reg_release_gateway(x) sofia_reg_release_gateway__(__FILE__, __SWITCH_FUNC__, __LINE__, x);
 
@@ -715,3 +759,4 @@
 void sofia_glue_toggle_hold(private_object_t *tech_pvt, int sendonly);
 const char * sofia_state_string(int state);
 switch_status_t sofia_glue_tech_set_codec(private_object_t *tech_pvt, int force);
+void sofia_wait_for_reply(struct private_object *tech_pvt, nua_event_t event, uint32_t timeout);

Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/sofia.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/sofia.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/sofia.c	Mon Dec 15 12:56:36 2008
@@ -70,12 +70,14 @@
 							   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 0
 	if (status >= 300 && sip && sip->sip_call_id) {
 		char *sql;
 		sql = switch_mprintf("delete from sip_subscriptions where call_id='%q'", sip->sip_call_id->i_id);
 		switch_assert(sql != NULL);
 		sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
 	}
+#endif
 }
 
 void sofia_handle_sip_i_notify(switch_core_session_t *session, int status,
@@ -83,6 +85,9 @@
 							   nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[])
 {
 	switch_channel_t *channel = NULL;
+	private_object_t *tech_pvt = NULL;
+	switch_event_t *s_event = NULL;
+	sofia_gateway_subscription_t *gw_sub_ptr;
 
 	/* make sure we have a proper event */
 	if (!sip || !sip->sip_event) {
@@ -95,21 +100,136 @@
 		return;
 	}
 
-	/* make sure we have a proper "talk" event */
-	if (!session || strcasecmp(sip->sip_event->o_type, "talk")) {
-		goto error;
+	if (session) {
+		channel = switch_core_session_get_channel(session);
+		switch_assert(channel != NULL);
+		tech_pvt = switch_core_session_get_private(session);
+		switch_assert(tech_pvt != NULL);
 	}
 
-	channel = switch_core_session_get_channel(session);
-	switch_assert(channel != NULL);
-	if (!switch_channel_test_flag(channel, CF_OUTBOUND)) {
-		switch_channel_answer(channel);
-		switch_channel_set_variable(channel, "auto_answer_destination", switch_channel_get_variable(channel, "destination_number"));
-		switch_ivr_session_transfer(session, "auto_answer", NULL, NULL);
+	/* For additional NOTIFY event packages see http://www.iana.org/assignments/sip-events. */
+	if (!strcasecmp(sip->sip_event->o_type, "refer")) {
+		if (switch_event_create_subclass(&s_event, SWITCH_EVENT_CUSTOM, MY_EVENT_NOTIFY_REFER) == SWITCH_STATUS_SUCCESS) {
+			switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "content-type", sip->sip_content_type->c_type);
+			switch_event_add_body(s_event, "%s", sip->sip_payload->pl_data);
+		}
+	}
+
+	/* add common headers for the NOTIFY to the switch_event and fire if it exists */
+	if (s_event != NULL) {
+		switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "event-package", sip->sip_event->o_type);
+		switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "event-id", sip->sip_event->o_id);
+
+		switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "contact", "%s@%s", 
+								sip->sip_contact->m_url->url_user, sip->sip_contact->m_url->url_host);
+		switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "from", "%s@%s", 
+								sip->sip_from->a_url->url_user, sip->sip_from->a_url->url_host);
+		switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "from-tag", sip->sip_from->a_tag);
+		switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "to", "%s@%s", 
+								sip->sip_to->a_url->url_user, sip->sip_to->a_url->url_host);
+		switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "to-tag", sip->sip_to->a_tag);
+
+		if (sip->sip_call_id && sip->sip_call_id->i_id) {
+			switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "call-id", sip->sip_call_id->i_id);
+		}
+		if (sip->sip_subscription_state && sip->sip_subscription_state->ss_substate) {
+			switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "subscription-substate", sip->sip_subscription_state->ss_substate);
+		}
+		if (sip->sip_subscription_state && sip->sip_subscription_state->ss_reason) {
+			switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "subscription-reason", sip->sip_subscription_state->ss_reason);
+		}
+		if (sip->sip_subscription_state && sip->sip_subscription_state->ss_retry_after) {
+			switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "subscription-retry-after", sip->sip_subscription_state->ss_retry_after);
+		}
+		if (sip->sip_subscription_state && sip->sip_subscription_state->ss_expires) {
+			switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "subscription-expires", sip->sip_subscription_state->ss_expires);
+		}
+		if (session) {
+			switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "UniqueID", switch_core_session_get_uuid(session));
+		}
+		switch_event_fire(&s_event);
+	}
+
+	if (!strcasecmp(sip->sip_event->o_type, "refer")) {
+		if (session && channel && tech_pvt) {
+			if (sip->sip_payload && sip->sip_payload->pl_data) {
+				char *p;
+				int status_val = 0;
+				if ((p = strchr(sip->sip_payload->pl_data, ' '))) {
+					p++;
+					if (p) {
+						status_val = atoi(p);
+					}
+				}
+				if (!status_val || status_val >= 200) {
+					switch_channel_set_variable(channel, "sip_refer_reply", sip->sip_payload->pl_data);
+					if (status_val == 200) {
+						switch_channel_hangup(channel, SWITCH_CAUSE_BLIND_TRANSFER);
+					}
+					if (tech_pvt->want_event == 9999) {
+						tech_pvt->want_event = 0;
+					}
+				}
+			}
+		}
 		nua_respond(nh, SIP_200_OK, NUTAG_WITH_THIS(nua), TAG_END());
-		return;
 	}
 
+	/* if no session, assume it could be an incoming notify from a gateway subscription */
+	if (session) {
+		/* make sure we have a proper "talk" event */
+		if (strcasecmp(sip->sip_event->o_type, "talk")) {
+			goto error;
+		}
+
+		if (!switch_channel_test_flag(channel, CF_OUTBOUND)) {
+			switch_channel_answer(channel);
+			switch_channel_set_variable(channel, "auto_answer_destination", switch_channel_get_variable(channel, "destination_number"));
+			switch_ivr_session_transfer(session, "auto_answer", NULL, NULL);
+			nua_respond(nh, SIP_200_OK, NUTAG_WITH_THIS(nua), TAG_END());
+			return;
+		}
+	}
+	
+	if (!sofia_private || !sofia_private->gateway) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Gateway information missing Subscription Event: %s\n", sip->sip_event->o_type);
+		goto error;	
+	}
+				
+	/* find the corresponding gateway subscription (if any) */
+	if (!(gw_sub_ptr = sofia_find_gateway_subscription(sofia_private->gateway, sip->sip_event->o_type))) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
+						  "Could not find gateway subscription.  Gateway: %s.  Subscription Event: %s\n",
+						  sofia_private->gateway->name, sip->sip_event->o_type);
+		goto error;	
+	}
+
+	if (!(gw_sub_ptr->state == SUB_STATE_SUBED || gw_sub_ptr->state == SUB_STATE_SUBSCRIBE)) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
+						  "Ignoring notify due to subscription state: %d\n",
+						  gw_sub_ptr->state);
+		goto error;	
+	}
+
+	/* dispatch freeswitch event */
+	if (switch_event_create(&s_event, SWITCH_EVENT_NOTIFY_IN) == SWITCH_STATUS_SUCCESS) {
+		switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "event", "%s", sip->sip_event->o_type);
+		switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "pl_data", "%s", sip->sip_payload->pl_data);
+		switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "sip_content_type", "%s", sip->sip_content_type->c_type);
+		switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "port", "%d", sofia_private->gateway->profile->sip_port);
+		switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "module_name", "%s", "mod_sofia");
+		switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "profile_name", "%s", sofia_private->gateway->profile->name);
+		switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "profile_uri", "%s", sofia_private->gateway->profile->url);
+		switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "gateway_name", "%s", sofia_private->gateway->name);
+		switch_event_fire(&s_event);
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "dispatched freeswitch event for message-summary NOTIFY\n");
+	} else {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to create event\n");
+		goto error;	
+	}
+
+	return;
+
   error:
 	nua_respond(nh, 481, "Subscription Does Not Exist", NUTAG_WITH_THIS(nua), TAG_END());
 	return;
@@ -160,6 +280,18 @@
 {
 }
 
+void sofia_wait_for_reply(struct private_object *tech_pvt, nua_event_t event, uint32_t timeout)
+{
+	time_t exp = switch_timestamp(NULL) + timeout;
+	
+	tech_pvt->want_event = event;
+
+	while(switch_channel_ready(tech_pvt->channel) && tech_pvt->want_event && switch_timestamp(NULL) < exp) {
+		switch_yield(100000);
+	}
+	
+}
+
 void sofia_event_callback(nua_event_t event,
 						  int status,
 						  char const *phrase,
@@ -336,6 +468,10 @@
 
   done:
 
+	if (tech_pvt && tech_pvt->want_event && event == tech_pvt->want_event) {
+		tech_pvt->want_event = 0;
+	}
+
 	switch (event) {
 	case nua_i_subscribe:
 		break;
@@ -471,6 +607,7 @@
 				sofia_reg_check_gateway(profile, switch_timestamp(NULL));
 				gateway_loops = 0;
 			}
+			sofia_sub_check_gateway(profile, time(NULL));
 			loops = 0;
 		}
 
@@ -586,6 +723,7 @@
 				   TAG_IF(profile->pres_type, NUTAG_ALLOW_EVENTS("include-session-description")),
 				   TAG_IF(profile->pres_type, NUTAG_ALLOW_EVENTS("presence.winfo")),
 				   TAG_IF(profile->pres_type, NUTAG_ALLOW_EVENTS("message-summary")),
+				   NUTAG_ALLOW_EVENTS("refer"),
 				   SIPTAG_SUPPORTED_STR(supported), SIPTAG_USER_AGENT_STR(profile->user_agent), TAG_END());
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Set params for %s\n", profile->name);
@@ -764,9 +902,56 @@
 	}
 }
 
+static void parse_gateway_subscriptions(sofia_profile_t *profile, sofia_gateway_t *gateway, switch_xml_t gw_subs_tag)
+{
+	switch_xml_t subscription_tag, param;
+
+	for (subscription_tag = switch_xml_child(gw_subs_tag, "subscription"); subscription_tag; subscription_tag = subscription_tag->next) {
+		sofia_gateway_subscription_t *gw_sub;
+
+		if ((gw_sub = switch_core_alloc(profile->pool, sizeof(*gw_sub)))) {
+			char *expire_seconds = "3600", *retry_seconds = "30", *content_type = "NO_CONTENT_TYPE";
+			char *event = (char *) switch_xml_attr_soft(subscription_tag, "event");
+			gw_sub->event = switch_core_strdup(gateway->pool, event);			
+			gw_sub->gateway = gateway;
+			gw_sub->next = NULL;
+			
+			for (param = switch_xml_child(subscription_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, "expire-seconds")) {
+					expire_seconds = val;
+				} else if (!strcmp(var, "retry-seconds")) {
+					retry_seconds = val;
+				} else if (!strcmp(var, "content-type")) {
+					content_type = val;
+				}
+			}
+			
+			gw_sub->retry_seconds = atoi(retry_seconds);
+			if (gw_sub->retry_seconds < 10) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "INVALID: retry_seconds correcting the value to 30\n");
+				gw_sub->retry_seconds = 30;
+			}
+			
+			gw_sub->expires_str = switch_core_strdup(gateway->pool, expire_seconds);  
+			
+			if ((gw_sub->freq = atoi(gw_sub->expires_str)) < 5) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
+				"Invalid Freq: %d.  Setting Register-Frequency to 3600\n", gw_sub->freq);
+				gw_sub->freq = 3600;
+			}
+			gw_sub->freq -= 2;
+			gw_sub->content_type = switch_core_strdup(gateway->pool, content_type);
+			gw_sub->next = gateway->subscriptions;		
+		}
+		gateway->subscriptions = gw_sub;
+	}
+}
+
 static void parse_gateways(sofia_profile_t *profile, switch_xml_t gateways_tag)
 {
-	switch_xml_t gateway_tag, param;
+	switch_xml_t gateway_tag, param, gw_subs_tag;
 	sofia_gateway_t *gp;
 
 	for (gateway_tag = switch_xml_child(gateways_tag, "gateway"); gateway_tag; gateway_tag = gateway_tag->next) {
@@ -818,7 +1003,7 @@
 			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, "register")) {
 					register_str = val;
 				} else if (!strcmp(var, "scheme")) {
@@ -845,6 +1030,8 @@
 					expire_seconds = val;
 				} else if (!strcmp(var, "retry-seconds")) {
 					retry_seconds = val;
+				} else if (!strcmp(var, "retry_seconds")) { // support typo for back compat
+					retry_seconds = val;
 				} else if (!strcmp(var, "from-user")) {
 					from_user = val;
 				} else if (!strcmp(var, "from-domain")) {
@@ -874,6 +1061,10 @@
 				}
 			}
 
+			if ((gw_subs_tag = switch_xml_child(gateway_tag, "subscriptions"))) {
+				parse_gateway_subscriptions(profile, gateway, gw_subs_tag);
+			}
+			
 			if (switch_strlen_zero(realm)) {
 				realm = name;
 			}
@@ -902,6 +1093,7 @@
 
 			if (!switch_true(register_str)) {
 				gateway->state = REG_STATE_NOREG;
+				gateway->status = SOFIA_GATEWAY_UP;
 			}
 
 			if (switch_strlen_zero(from_domain)) {
@@ -913,11 +1105,15 @@
 			}
 			
 			if (!switch_strlen_zero(register_proxy)) {
-				gateway->register_sticky_proxy = switch_core_strdup(gateway->pool, register_proxy);
+				if (strncasecmp(register_proxy, "sip:", 4) && strncasecmp(register_proxy, "sips:", 5)) {
+					gateway->register_sticky_proxy = switch_core_sprintf(gateway->pool, "sip:%s", register_proxy);
+				} else {
+					gateway->register_sticky_proxy = switch_core_strdup(gateway->pool, register_proxy);
+				}
 			}
 
 			gateway->retry_seconds = atoi(retry_seconds);
-			if (gateway->retry_seconds < 10) {
+			if (gateway->retry_seconds < 5) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid retry-seconds of %d on gateway %s, using the value of 30 instead.\n",
 								  gateway->retry_seconds, name);
 				gateway->retry_seconds = 30;
@@ -1063,6 +1259,11 @@
 						} else {
 							switch_clear_flag(profile, TFLAG_INB_NOMEDIA);
 						}
+					} else if (!strcasecmp(var, "force-subscription-expires")) {
+						int tmp = atoi(val);
+						if (tmp > 0) {
+							profile->force_subscription_expires = tmp;
+						}
 					} else if (!strcasecmp(var, "inbound-late-negotiation")) {
 						if (switch_true(val)) {
 							switch_set_flag(profile, TFLAG_LATE_NEGOTIATION);
@@ -1377,12 +1578,18 @@
 		goto done;
 	}
 
+	mod_sofia_globals.auto_restart = SWITCH_TRUE;
+
 	if ((settings = switch_xml_child(cfg, "global_settings"))) {
 		for (param = switch_xml_child(settings, "param"); param; param = param->next) {
 			char *var = (char *) switch_xml_attr_soft(param, "name");
 			char *val = (char *) switch_xml_attr_soft(param, "value");
 			if (!strcasecmp(var, "log-level")) {
 				su_log_set_level(NULL, atoi(val));
+			} else if (!strcasecmp(var, "debug-presence")) {
+				mod_sofia_globals.debug_presence = atoi(val);
+			} else if (!strcasecmp(var, "auto-restart")) {
+				mod_sofia_globals.auto_restart = switch_true(val);
 			}
 		}
 	}
@@ -1486,6 +1693,11 @@
 						switch_set_flag(profile, TFLAG_LATE_NEGOTIATION);
 					} else if (!strcasecmp(var, "inbound-proxy-media") && switch_true(val)) {
 						switch_set_flag(profile, TFLAG_PROXY_MEDIA);
+					} else if (!strcasecmp(var, "force-subscription-expires")) {
+						int tmp = atoi(val);
+						if (tmp > 0) {
+							profile->force_subscription_expires = tmp;
+						}
 					} else if (!strcasecmp(var, "inbound-use-callid-as-uuid")) {
 						if (switch_true(val)) {
 							profile->pflags |= PFLAG_CALLID_AS_UUID;
@@ -1877,11 +2089,13 @@
 					profile->bindurl = profile->url;
 				}
 
+				profile->tcp_contact = switch_core_sprintf(profile->pool, "%s;transport=tcp", profile->url);
+				
 				if (profile->bind_params) {
 					char *bindurl = profile->bindurl;
 					profile->bindurl = switch_core_sprintf(profile->pool, "%s;%s", bindurl, profile->bind_params);
 				}
-
+				
 				/*
 				 * handle TLS params #2
 				 */
@@ -1932,6 +2146,7 @@
 					if (!profile->tls_cert_dir) {
 						profile->tls_cert_dir = switch_core_sprintf(profile->pool, "%s/ssl", SWITCH_GLOBAL_dirs.conf_dir);
 					}
+					profile->tls_contact = switch_core_sprintf(profile->pool, "%s;transport=tls", profile->tls_url);
 				}
 			}
 			if (profile) {
@@ -2026,7 +2241,6 @@
 		if (status == 200 || status == 404 || status == 501) {
 			if (gateway->state == REG_STATE_FAILED) {
 				gateway->state = REG_STATE_UNREGED;
-				gateway->retry = 0;
 			}
 			gateway->status = SOFIA_GATEWAY_UP;
 		} else {
@@ -2062,9 +2276,23 @@
 		const char *uuid;
 		switch_core_session_t *other_session;
 		private_object_t *tech_pvt = switch_core_session_get_private(session);
+		su_addrinfo_t *my_addrinfo = msg_addrinfo(nua_current_request(nua));
+		char network_ip[80];
+		int network_port = 0;
+		switch_caller_profile_t *caller_profile = NULL;
 
-		switch_channel_clear_flag(channel, CF_REQ_MEDIA);
+		get_addr(network_ip, sizeof(network_ip), my_addrinfo->ai_addr, my_addrinfo->ai_addrlen);
+		network_port = ntohs(((struct sockaddr_in *) msg_addrinfo(nua_current_request(nua))->ai_addr)->sin_port);
+
+		switch_channel_set_variable(channel, "sip_reply_host", network_ip);
+		switch_channel_set_variable_printf(channel, "sip_reply_port", "%d", network_port);
+		
+		if ((caller_profile = switch_channel_get_caller_profile(channel))) {
+			caller_profile->network_addr = switch_core_strdup(caller_profile->pool, network_ip);
+		}
 
+		switch_channel_clear_flag(channel, CF_REQ_MEDIA);
+		
 		if ((status == 180 || status == 183 || status == 200)) { 
 			if (sip->sip_user_agent && sip->sip_user_agent->g_string) {
 				switch_channel_set_variable(channel, "sip_user_agent", sip->sip_user_agent->g_string);
@@ -2211,22 +2439,9 @@
 	}
 
 	if (!session && (status == 180 || status == 183 || status == 200)) {
-		/* This should never happen.  It means the sip stack thinks there is a call but FreeSWITCH does not */
-		const char *callid = "n/a";
-
-		if (sip && sip->sip_call_id && sip->sip_call_id->i_id) callid = sip->sip_call_id->i_id;
-
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Received response to invite with no matching session, destroying callid [%s]!\n", callid);
-
-		if (nh) {
-			if (status == 200) {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Sending BYE to orphan call.\n");
-				nua_bye(nh, TAG_END());
-			} else {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Sending CANCEL to orphan call.\n");
-				nua_cancel(nh, TAG_END());
-			}
-		}
+		/* nevermind */
+		nua_handle_bind(nh, NULL);
+		nua_handle_destroy(nh);
 	}
 }
 
@@ -2344,6 +2559,19 @@
   state_process:
 
 	switch ((enum nua_callstate) ss_state) {
+	case nua_callstate_terminated:
+	case nua_callstate_terminating:
+	case nua_callstate_ready:
+	case nua_callstate_completed:
+	case nua_callstate_received:
+	case nua_callstate_proceeding:
+		if (!(session && channel && tech_pvt)) goto done;
+		break;
+	default:
+		break;
+	}
+
+	switch ((enum nua_callstate) ss_state) {
 	case nua_callstate_init:
 		break;
 	case nua_callstate_authenticating:
@@ -2351,61 +2579,59 @@
 	case nua_callstate_calling:
 		break;
 	case nua_callstate_proceeding:
-		if (channel) {
-			if (status == 180) {
-				switch_channel_mark_ring_ready(channel);
-				if (!switch_channel_test_flag(channel, CF_GEN_RINGBACK)) {
-					if (switch_channel_test_flag(channel, CF_PROXY_MODE)) {
-						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);
+		if (status == 180) {
+			switch_channel_mark_ring_ready(channel);
+			if (!switch_channel_test_flag(channel, CF_GEN_RINGBACK)) {
+				if (switch_channel_test_flag(channel, CF_PROXY_MODE)) {
+					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);
 				}
 			}
+		}
 			
-			if (r_sdp) {
-				if (switch_channel_test_flag(channel, CF_PROXY_MODE) || switch_channel_test_flag(channel, CF_PROXY_MEDIA)) {
-					switch_set_flag_locked(tech_pvt, TFLAG_EARLY_MEDIA);
-					switch_channel_mark_pre_answered(channel);
-					switch_set_flag(tech_pvt, TFLAG_SDP);
-					if (switch_channel_test_flag(channel, CF_PROXY_MEDIA)) {
-						if (sofia_glue_activate_rtp(tech_pvt, 0) != SWITCH_STATUS_SUCCESS) {
-							goto done;
-						}
+		if (r_sdp) {
+			if (switch_channel_test_flag(channel, CF_PROXY_MODE) || switch_channel_test_flag(channel, CF_PROXY_MEDIA)) {
+				switch_set_flag_locked(tech_pvt, TFLAG_EARLY_MEDIA);
+				switch_channel_mark_pre_answered(channel);
+				switch_set_flag(tech_pvt, TFLAG_SDP);
+				if (switch_channel_test_flag(channel, CF_PROXY_MEDIA)) {
+					if (sofia_glue_activate_rtp(tech_pvt, 0) != SWITCH_STATUS_SUCCESS) {
+						goto done;
 					}
-					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);
+				}
+				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);
 					}
-					goto done;
+
+					switch_channel_pre_answer(other_channel);
+					switch_core_session_rwunlock(other_session);
+				}
+				goto done;
+			} else {
+				if (switch_channel_test_flag(channel, CF_PROXY_MEDIA) && !switch_channel_test_flag(tech_pvt->channel, CF_OUTBOUND)) {
+					switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "PROXY MEDIA");
+				} else if (switch_test_flag(tech_pvt, TFLAG_LATE_NEGOTIATION) && !switch_channel_test_flag(tech_pvt->channel, CF_OUTBOUND)) {
+					switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "DELAYED NEGOTIATION");
 				} else {
-					if (switch_channel_test_flag(channel, CF_PROXY_MEDIA) && !switch_channel_test_flag(tech_pvt->channel, CF_OUTBOUND)) {
-						switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "PROXY MEDIA");
-					} else if (switch_test_flag(tech_pvt, TFLAG_LATE_NEGOTIATION) && !switch_channel_test_flag(tech_pvt->channel, CF_OUTBOUND)) {
-						switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "DELAYED NEGOTIATION");
-					} else {
-						if (sofia_glue_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());
-							switch_channel_hangup(channel, SWITCH_CAUSE_INCOMPATIBLE_DESTINATION);
-						}
+					if (sofia_glue_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());
+						switch_channel_hangup(channel, SWITCH_CAUSE_INCOMPATIBLE_DESTINATION);
 					}
-					goto done;
 				}
+				goto done;
 			}
 		}
 		break;
@@ -2413,7 +2639,7 @@
 		nua_ack(nh, TAG_END());
 		break;
 	case nua_callstate_received:
-		if (tech_pvt && !switch_test_flag(tech_pvt, TFLAG_SDP)) {
+		if (!switch_test_flag(tech_pvt, TFLAG_SDP)) {
 			if (r_sdp && !switch_test_flag(tech_pvt, TFLAG_SDP)) {
 				if (switch_channel_test_flag(channel, CF_PROXY_MODE)) {
 					switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "RECEIVED_NOMEDIA");
@@ -2546,7 +2772,7 @@
 	case nua_callstate_early:
 		break;
 	case nua_callstate_completed:
-		if (tech_pvt && r_sdp) {
+		if (r_sdp) {
 			sdp_parser_t *parser;
 			sdp_session_t *sdp;
 			uint8_t match = 0, is_ok = 1;
@@ -2818,49 +3044,47 @@
 
 		break;
 	case nua_callstate_terminating:
-		if (session) {
-			if (status == 488 || switch_channel_get_state(channel) == CS_HIBERNATE) {
-				tech_pvt->q850_cause = SWITCH_CAUSE_MANDATORY_IE_MISSING;
-			} else if (!switch_test_flag(tech_pvt, TFLAG_BYE)) {
-				switch_set_flag_locked(tech_pvt, TFLAG_BYE);
-			}
+		if (status == 488 || switch_channel_get_state(channel) == CS_HIBERNATE) {
+			tech_pvt->q850_cause = SWITCH_CAUSE_MANDATORY_IE_MISSING;
+		} else if (!switch_test_flag(tech_pvt, TFLAG_BYE)) {
+			switch_set_flag_locked(tech_pvt, TFLAG_BYE);
 		}
 		break;
 	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);
+		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);
+			} else {
+				int cause;
+				if (tech_pvt->q850_cause) {
+					cause = tech_pvt->q850_cause;
 				} else {
-					int cause;
-					if (tech_pvt->q850_cause) {
-						cause = tech_pvt->q850_cause;
-					} else {
-						cause = sofia_glue_sip_cause_to_freeswitch(status);
-					}
-					if (status) {
-						switch_snprintf(st, sizeof(st), "%d", status);
-						switch_channel_set_variable(channel, "sip_term_status", st);
-						switch_snprintf(st, sizeof(st), "sip:%d", status);
-						switch_channel_set_variable_partner(channel, SWITCH_PROTO_SPECIFIC_HANGUP_CAUSE_VARIABLE, st);
-						if (phrase) {
-							switch_channel_set_variable_partner(channel, "sip_hangup_phrase", phrase);
-						}
+					cause = sofia_glue_sip_cause_to_freeswitch(status);
+				}
+				if (status) {
+					switch_snprintf(st, sizeof(st), "%d", status);
+					switch_channel_set_variable(channel, "sip_term_status", st);
+					switch_snprintf(st, sizeof(st), "sip:%d", status);
+					switch_channel_set_variable_partner(channel, SWITCH_PROTO_SPECIFIC_HANGUP_CAUSE_VARIABLE, st);
+					switch_channel_set_variable(channel, SWITCH_PROTO_SPECIFIC_HANGUP_CAUSE_VARIABLE, st);
+					if (phrase) {
+						switch_channel_set_variable_partner(channel, "sip_hangup_phrase", phrase);
 					}
-					switch_snprintf(st, sizeof(st), "%d", cause);
-					switch_channel_set_variable(channel, "sip_term_cause", st);
-					switch_channel_hangup(channel, cause);
 				}
+				switch_snprintf(st, sizeof(st), "%d", cause);
+				switch_channel_set_variable(channel, "sip_term_cause", st);
+				switch_channel_hangup(channel, cause);
 			}
+		}
 
-			if (tech_pvt->sofia_private) {
-				tech_pvt->sofia_private = NULL;
-			}
-
-			tech_pvt->nh = NULL;
+		if (tech_pvt->sofia_private) {
+			tech_pvt->sofia_private = NULL;
 		}
 
+		tech_pvt->nh = NULL;
+		
+
 		if (nh) {
 			nua_handle_bind(nh, NULL);
 			nua_handle_destroy(nh);
@@ -2897,7 +3121,7 @@
 			private_object_t *tech_pvt = switch_core_session_get_private(session);
 			switch_channel_t *channel_a = switch_core_session_get_channel(session);
 
-			status = switch_ivr_originate(a_session, &tsession, &cause, nhelper->exten, timeout, NULL, NULL, NULL, NULL, SOF_NONE);
+			status = switch_ivr_originate(a_session, &tsession, &cause, nhelper->exten, timeout, NULL, NULL, NULL, NULL, NULL, SOF_NONE);
 							
 			if ((switch_channel_get_state(channel_a) < CS_HANGUP)) {
 				
@@ -2942,6 +3166,7 @@
 }
 
 /*---------------------------------------*/
+
 void sofia_handle_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 */
@@ -2979,6 +3204,7 @@
 	}
 
 	if ((refer_to = sip->sip_refer_to)) {
+		char *rep;
 		full_ref_to = sip_header_as_string(home, (void *) sip->sip_refer_to);
 
 		if (profile->pflags & PFLAG_FULL_ID) {
@@ -2989,10 +3215,9 @@
 
 		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 && strstr(refer_to->r_url->url_headers, "Replaces=")) {
+		if (refer_to->r_url->url_headers && (rep = (char *)switch_stristr("Replaces=", refer_to->r_url->url_headers))) {
 			sip_replaces_t *replaces;
 			nua_handle_t *bnh;
-			char *rep;
 
 			if (switch_channel_test_flag(channel_a, CF_PROXY_MODE)) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Attended Transfer BYPASS MEDIA CALLS!\n");
@@ -3001,13 +3226,18 @@
 						   NUTAG_SUBSTATE(nua_substate_terminated), SIPTAG_PAYLOAD_STR("SIP/2.0 403 Forbidden"), SIPTAG_EVENT_STR(etmp), TAG_END());
 				goto done;
 			}
-
-			if ((rep = strchr(refer_to->r_url->url_headers, '='))) {
+			
+			if (rep) {
 				const char *br_a = NULL, *br_b = NULL;
 				char *buf;
+				char *p;
 
-				rep++;
+				rep = switch_core_session_strdup(session, rep + 9);
 
+				if ((p = strchr(rep, ';'))) {
+					*p = '\0';
+				}
+				
 				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);
@@ -3286,8 +3516,12 @@
 					int tmp;
 					/* move signal_ptr where we need it (right past Signal=) */
 					signal_ptr = signal_ptr + 7;
-					tmp = atoi(signal_ptr);
-					dtmf.digit = switch_rfc2833_to_char(tmp);
+					if (*signal_ptr && strlen(signal_ptr) == 1 && is_dtmf(*signal_ptr)) {
+						dtmf.digit = *signal_ptr;
+					} else {
+						tmp = atoi(signal_ptr);
+						dtmf.digit = switch_rfc2833_to_char(tmp);
+					}
 				} else {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Bad signal\n");
 					goto fail;
@@ -3296,6 +3530,7 @@
 				if ((signal_ptr = switch_stristr("Duration=", sip->sip_payload->pl_data))) {
 					int tmp;
 					signal_ptr += 9;
+					
 					if ((tmp = atoi(signal_ptr)) <= 0) {
 						tmp = switch_core_default_dtmf_duration(0);
 					}
@@ -3962,6 +4197,8 @@
 						free(tmp_name);
 					}
 				}
+			} else if (!strncasecmp(un->un_name, "History-Info", 12)) {
+				switch_channel_set_variable(channel, "sip_history_info", un->un_value);
 			} else if (!strncasecmp(un->un_name, "X-", 2) || !strncasecmp(un->un_name, "P-", 2)) {
 				if (!switch_strlen_zero(un->un_value)) {
 					char new_name[512] = "";

Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/sofia_glue.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/sofia_glue.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/sofia_glue.c	Mon Dec 15 12:56:36 2008
@@ -448,7 +448,9 @@
 		return status;
 	}
 
-	if (!strncasecmp(sourceip, "stun:", 5)) {
+	if (!strncasecmp(sourceip, "host:", 5)) {
+		status = (*ip = switch_stun_host_lookup(sourceip + 5, pool)) ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
+	} else if (!strncasecmp(sourceip, "stun:", 5)) {
 		char *p;
 
 		if (!(profile->pflags & PFLAG_STUN_ENABLED)) {
@@ -1163,8 +1165,8 @@
 																		   ipv6 ? "[" : "", ip_addr, ipv6 ? "]" : "", 
 																		   tech_pvt->profile->tls_sip_port);
 				} else {
-					tech_pvt->invite_contact = switch_core_session_sprintf(session, "sip:%s@%s%s%s", contact, 
-																		   ipv6 ? "[" : "", ip_addr, ipv6 ? "]" : "");
+					tech_pvt->invite_contact = switch_core_session_sprintf(session, "sip:%s@%s%s%s:%d", contact, 
+																		   ipv6 ? "[" : "", ip_addr, ipv6 ? "]" : "", tech_pvt->profile->sip_port);
 				}
 			} else {
 				if (sofia_glue_transport_has_tls(tech_pvt->transport)) {
@@ -1186,7 +1188,11 @@
 		   or did he just suggest it to make our lives miserable?
 		 */
 		use_from_str = from_str;
-		from_str = switch_core_session_sprintf(session, "\"%s\" <%s>", tech_pvt->caller_profile->caller_id_name, use_from_str);
+		if (!strcasecmp(tech_pvt->caller_profile->caller_id_name, "_undef_")) {
+			from_str = switch_core_session_sprintf(session, "<%s>", use_from_str);
+		} else {
+			from_str = switch_core_session_sprintf(session, "\"%s\" <%s>", tech_pvt->caller_profile->caller_id_name, use_from_str);
+		}
 		
 		if (!(call_id = switch_channel_get_variable(channel, "sip_outgoing_call_id"))) {
 			if (tech_pvt->profile->pflags & PFLAG_UUID_AS_CALLID) {
@@ -1813,7 +1819,7 @@
 						  tech_pvt->remote_sdp_audio_port, tech_pvt->agreed_pt, tech_pvt->read_codec.implementation->microseconds_per_packet / 1000);
 	}
 
-	switch_snprintf(tmp, sizeof(tmp), "%d", tech_pvt->remote_sdp_audio_port);
+	switch_snprintf(tmp, sizeof(tmp), "%d", tech_pvt->local_sdp_audio_port);
 	switch_channel_set_variable(tech_pvt->channel, SWITCH_LOCAL_MEDIA_IP_VARIABLE, tech_pvt->adv_sdp_audio_ip);
 	switch_channel_set_variable(tech_pvt->channel, SWITCH_LOCAL_MEDIA_PORT_VARIABLE, tmp);
 
@@ -2191,6 +2197,16 @@
 			switch_set_flag_locked(tech_pvt, TFLAG_BUGGY_2833);
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Activate Buggy RFC2833 Mode!\n");
 		}
+
+		if (strstr(tech_pvt->origin, "Sonus_UAC")) {
+			switch_set_flag_locked(tech_pvt, TFLAG_BUGGY_2833);
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, 
+							  "Hello,\nI see you have a Sonus!\n"
+							  "FYI, Sonus cannot follow the RFC on the proper way to send DTMF.\n"
+							  "Sadly, my creator had to spend several hours figuring this out so I thought you'd like to know that!\n"
+							  "Don't worry, DTMF will work but you may want to ask them to fix it......\n"
+							  );
+		}
 	}
 
 	if ((m = sdp->sdp_media) && (m->m_mode == sdp_sendonly || m->m_mode == sdp_inactive)) {
@@ -2823,6 +2839,19 @@
 		"   hostname        VARCHAR(255)\n" 
 		");\n";
 
+
+	char pres_sql[] =
+		"CREATE TABLE sip_presence (\n"
+		"   sip_user        VARCHAR(255),\n"
+		"   sip_host        VARCHAR(255),\n"
+		"   status          VARCHAR(255),\n"
+		"   rpid            VARCHAR(255),\n" 
+		"   expires         INTEGER,\n" 
+		"   user_agent      VARCHAR(255),\n" 
+		"   profile_name    VARCHAR(255),\n" 
+		"   hostname        VARCHAR(255)\n" 
+		");\n";
+
 	char dialog_sql[] =
 		"CREATE TABLE sip_dialogs (\n"
 		"   call_id         VARCHAR(255),\n"
@@ -2906,6 +2935,13 @@
 			switch_odbc_handle_exec(profile->master_odbc, dialog_sql, NULL);
 		}
 
+		test_sql = switch_mprintf("delete from sip_presence where hostname='%q'", mod_sofia_globals.hostname);
+
+		if (switch_odbc_handle_exec(profile->master_odbc, test_sql, NULL) != SWITCH_ODBC_SUCCESS) {
+			switch_odbc_handle_exec(profile->master_odbc, "DROP TABLE sip_presence", NULL);
+			switch_odbc_handle_exec(profile->master_odbc, pres_sql, NULL);
+		}
+
 		free(test_sql);
 		test_sql = switch_mprintf("delete from sip_authentication where hostname='%q'", mod_sofia_globals.hostname);
 
@@ -2937,6 +2973,11 @@
 		test_sql = switch_mprintf("delete from sip_dialogs where hostname='%q'", mod_sofia_globals.hostname);
 		switch_core_db_test_reactive(profile->master_db, test_sql, "DROP TABLE sip_dialogs", dialog_sql);
 		free(test_sql);
+
+		test_sql = switch_mprintf("delete from sip_presence where hostname='%q'", mod_sofia_globals.hostname);
+		switch_core_db_test_reactive(profile->master_db, test_sql, "DROP TABLE sip_presence", pres_sql);
+		free(test_sql);
+
 		test_sql = switch_mprintf("delete from sip_authentication where hostname='%q'", mod_sofia_globals.hostname);
 		switch_core_db_test_reactive(profile->master_db, test_sql, "DROP TABLE sip_authentication", auth_sql);
 		free(test_sql);

Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/sofia_presence.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/sofia_presence.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/sofia_presence.c	Mon Dec 15 12:56:36 2008
@@ -34,6 +34,8 @@
  */
 #include "mod_sofia.h"
 
+#define SUB_OVERLAP 300
+
 static int sofia_presence_mwi_callback(void *pArg, int argc, char **argv, char **columnNames);
 static int sofia_presence_mwi_callback2(void *pArg, int argc, char **argv, char **columnNames);
 static int sofia_presence_sub_reg_callback(void *pArg, int argc, char **argv, char **columnNames);
@@ -315,6 +317,7 @@
 {
 	sofia_profile_t *profile = NULL;
 	switch_hash_index_t *hi;
+	const void *var;
 	void *val;
 	char *from = switch_event_get_header(event, "from");
 	char *proto = switch_event_get_header(event, "proto");
@@ -336,29 +339,15 @@
 	if (status && !strcasecmp(status, "n/a")) {
 		status = NULL;
 	}
+	
+	if (status && switch_stristr("CS_HANGUP", status)) {
+		status = "Call Ended";
+	}
 
 	if (rpid) {
 		rpid = sofia_presence_translate_rpid(rpid, status);
 	}
-
-	if (!status) {
-		status = "Available";
-
-		if (rpid) {
-			if (!strcasecmp(rpid, "busy")) {
-				status = "Busy";
-			} else if (!strcasecmp(rpid, "unavailable")) {
-				status = "Idle";
-			} else if (!strcasecmp(rpid, "away")) {
-				status = "Idle";
-			}
-		}
-	}
-
-	if (!rpid) {
-		rpid = "unknown";
-	}
-
+	
 	if (event->event_id == SWITCH_EVENT_ROSTER) {
 		struct presence_helper helper = { 0 };
 
@@ -367,21 +356,47 @@
 
 		if (from) {
 			sql = switch_mprintf(
-								 "select proto,sip_user,sip_host,sub_to_user,sub_to_host,event,contact,call_id,full_from,"
-								 "full_via,expires,user_agent,accept,profile_name"
-								 ",1,'%q','%q' from sip_subscriptions where event='presence' and full_from like '%%%q%%'", status, rpid, from);
+								 "select sip_subscriptions.proto,sip_subscriptions.sip_user,sip_subscriptions.sip_host,"
+								 "sip_subscriptions.sub_to_user,sip_subscriptions.sub_to_host,sip_subscriptions.event,"
+								 "sip_subscriptions.contact,sip_subscriptions.call_id,sip_subscriptions.full_from,"
+								 "sip_subscriptions.full_via,sip_subscriptions.expires,sip_subscriptions.user_agent,"
+								 "sip_subscriptions.accept,sip_subscriptions.profile_name"
+								 ",1,'%q','%q',sip_presence.status,sip_presence.rpid "
+								 "from sip_subscriptions left join sip_presence on "
+								 "(sip_subscriptions.sub_to_user=sip_presence.sip_user and sip_subscriptions.sub_to_host=sip_presence.sip_host and "
+								 "sip_subscriptions.profile_name=sip_presence.profile_name) "
+								 "where sip_subscriptions.event='presence' and sip_subscriptions.full_from like '%%%q%%'", 
+								 switch_str_nil(status), switch_str_nil(rpid), from);
 		} else {
-			sql = switch_mprintf("select proto,sip_user,sip_host,sub_to_user,sub_to_host,event,contact,call_id,full_from,"
-								 "full_via,expires,user_agent,accept,profile_name"
-								 ",1,'%q','%q' from sip_subscriptions where event='presence'", status, rpid);
+			sql = switch_mprintf(
+								 "select sip_subscriptions.proto,sip_subscriptions.sip_user,sip_subscriptions.sip_host,"
+								 "sip_subscriptions.sub_to_user,sip_subscriptions.sub_to_host,sip_subscriptions.event,"
+								 "sip_subscriptions.contact,sip_subscriptions.call_id,sip_subscriptions.full_from,"
+								 "sip_subscriptions.full_via,sip_subscriptions.expires,sip_subscriptions.user_agent,"
+								 "sip_subscriptions.accept,sip_subscriptions.profile_name"
+								 ",1,'%q','%q',sip_presence.status,sip_presence.rpid "
+								 "from sip_subscriptions left join sip_presence on "
+								 "(sip_subscriptions.sub_to_user=sip_presence.sip_user and sip_subscriptions.sub_to_host=sip_presence.sip_host and "
+								 "sip_subscriptions.profile_name=sip_presence.profile_name) "
+								 "where sip_subscriptions.event='presence'", switch_str_nil(status), switch_str_nil(rpid));
 		}
 
 		switch_assert(sql != NULL);
 		switch_mutex_lock(mod_sofia_globals.hash_mutex);
 		for (hi = switch_hash_first(NULL, mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) {
-			switch_hash_this(hi, NULL, NULL, &val);
+			switch_hash_this(hi, &var, NULL, &val);
 			profile = (sofia_profile_t *) val;
+
+			if (strcmp((char *)var, profile->name)) {
+				if (mod_sofia_globals.debug_presence > 0) {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "%s is an alias, skipping\n", (char *) var);
+				}
+				continue;
+			}
 			if (profile->pres_type != PRES_TYPE_FULL) {
+				if (mod_sofia_globals.debug_presence > 0) {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "%s is passive, skipping\n", (char *) var);
+				}
 				continue;
 			}
 			helper.profile = profile;
@@ -421,6 +436,7 @@
 		return;
 	}
 
+
 	switch (event->event_id) {
 	case SWITCH_EVENT_PRESENCE_PROBE:
 		if (proto) {
@@ -442,15 +458,31 @@
 			if (probe_euser && probe_host && (profile = sofia_glue_find_profile(probe_host))) {
 				sql = switch_mprintf("select sip_registrations.sip_user, '%q', sip_registrations.status, "
 									 "sip_registrations.rpid,'', sip_dialogs.uuid, sip_dialogs.state, sip_dialogs.direction, "
-									 "sip_dialogs.sip_to_user, sip_dialogs.sip_to_host "
+									 "sip_dialogs.sip_to_user, sip_dialogs.sip_to_host, sip_presence.status,sip_presence.rpid "
 									 "from sip_registrations left join sip_dialogs on "
-									 "(sip_dialogs.sip_from_user = sip_registrations.sip_user) "
-									 "and sip_dialogs.sip_from_host = sip_registrations.sip_host "
+									 "(sip_dialogs.sip_from_user = sip_registrations.sip_user "
+									 "and sip_dialogs.sip_from_host = sip_registrations.sip_host) "
+									 "left join sip_presence on "
+									 "(sip_registrations.sip_user=sip_presence.sip_user and sip_registrations.sip_host=sip_presence.sip_host and "
+									 "sip_registrations.profile_name=sip_presence.profile_name) "
 									 "where sip_registrations.sip_user='%q' and "
 									 "(sip_registrations.sip_host='%q' or sip_registrations.presence_hosts like '%%%q%%')", 
 									 probe_host, probe_euser, probe_host, probe_host);
 				switch_assert(sql);
+
+				
+				if (mod_sofia_globals.debug_presence > 0) {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s START_PRESENCE_PROBE_SQL\n", profile->name);
+				}
+
+				if (mod_sofia_globals.debug_presence > 1) {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s DUMP PRESENCE_PROBE_SQL:\n%s\n", profile->name, sql);
+				}
+
 				sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex, sql, sofia_presence_resub_callback, profile);
+				if (mod_sofia_globals.debug_presence > 0) {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s END_PRESENCE_PROBE_SQL\n\n", profile->name);
+				}
 
 				sofia_glue_release_profile(profile);
 				switch_safe_free(sql);
@@ -460,64 +492,100 @@
 			switch_safe_free(probe_user);
 		}
 		return;
-	case SWITCH_EVENT_PRESENCE_IN:
-		sql = switch_mprintf("select proto,sip_user,sip_host,sub_to_user,sub_to_host,event,contact,call_id,full_from,"
-							 "full_via,expires,user_agent,accept,profile_name"
-							 ",1,'%q','%q','%q' from sip_subscriptions where (event='%q' or event='%q') and sub_to_user='%q' "
-							 "and (sub_to_host='%q' or presence_hosts like '%%%q%%')",
-							 status, rpid, host, event_type, alt_event_type, euser, host, host);
-		break;
-	case SWITCH_EVENT_PRESENCE_OUT:
-		sql = switch_mprintf("select proto,sip_user,sip_host,sub_to_user,sub_to_host,event,contact,call_id,full_from,"
-							 "full_via,expires,user_agent,accept,profile_name"
-							 ",0,'%q','%q','%q' from sip_subscriptions where (event='%q' or event='%q') "
-							 "and sub_to_user='%q' and (sub_to_host='%q' or presence_hosts like '%%%q%%')",
-							 status, rpid, host, event_type, alt_event_type, euser, host, host);
-		break;
 	default:
 		break;
 	}
 
+	
+
 	if (!mod_sofia_globals.profile_hash)
 		goto done;
 
 	switch_mutex_lock(mod_sofia_globals.hash_mutex);
 	for (hi = switch_hash_first(NULL, mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) {
-		switch_hash_this(hi, NULL, NULL, &val);
+		switch_hash_this(hi, &var, NULL, &val);
 		profile = (sofia_profile_t *) val;
+
+		if (strcmp((char *)var, profile->name)) {
+			if (mod_sofia_globals.debug_presence > 0) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "%s is an alias, skipping\n", (char *) var);
+			}
+			continue;
+		}
+
 		if (profile->pres_type != PRES_TYPE_FULL) {
+			if (mod_sofia_globals.debug_presence > 0) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "%s is passive, skipping\n", (char *) var);
+			}
 			continue;
 		}
+		
+
+		if ((sql = switch_mprintf(
+							 
+							 "select sip_subscriptions.proto,sip_subscriptions.sip_user,sip_subscriptions.sip_host,"
+							 "sip_subscriptions.sub_to_user,sip_subscriptions.sub_to_host,sip_subscriptions.event,"
+							 "sip_subscriptions.contact,sip_subscriptions.call_id,sip_subscriptions.full_from,"
+							 "sip_subscriptions.full_via,sip_subscriptions.expires,sip_subscriptions.user_agent,"
+							 "sip_subscriptions.accept,sip_subscriptions.profile_name"
+							 ",'%q','%q','%q',sip_presence.status,sip_presence.rpid "
+							 "from sip_subscriptions "
+							 "left join sip_presence on "
+							 "(sip_subscriptions.sub_to_user=sip_presence.sip_user and sip_subscriptions.sub_to_host=sip_presence.sip_host and "
+							 "sip_subscriptions.profile_name=sip_presence.profile_name) "
+							 "where (event='%q' or event='%q') and sub_to_user='%q' "
+							 "and (sub_to_host='%q' or presence_hosts like '%%%q%%') "
+							 "and (sip_subscriptions.profile_name = '%q' or sip_subscriptions.presence_hosts != sip_subscriptions.sub_to_host)",
+							 switch_str_nil(status), switch_str_nil(rpid), host, event_type, alt_event_type, euser, host, host, profile->name))) {
 
-		if (sql) {
 			struct presence_helper helper = { 0 };
 			helper.profile = profile;
 			helper.event = event;
 			SWITCH_STANDARD_STREAM(helper.stream);
 			switch_assert(helper.stream.data);
+			
+			if (mod_sofia_globals.debug_presence > 0) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s START_PRESENCE_SQL (%s)\n", 
+								  event->event_id == SWITCH_EVENT_PRESENCE_IN ? "IN" : "OUT", profile->name);
+			}
+
+			if (mod_sofia_globals.debug_presence > 1) {
+				char *buf;
+				switch_event_serialize(event, &buf, SWITCH_FALSE);
+				switch_assert(buf);
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "DUMP PRESENCE SQL:\n%s\nEVENT DUMP:\n%s\n", sql, buf);
+				free(buf);
+			}
 
 			sofia_glue_execute_sql_callback(profile, SWITCH_FALSE,
 											NULL, sql, sofia_presence_sub_callback, &helper);
 
+			if (mod_sofia_globals.debug_presence > 0) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s END_PRESENCE_SQL (%s)\n", 
+								  event->event_id == SWITCH_EVENT_PRESENCE_IN ? "IN" : "OUT", profile->name);
+			}
+			
+			switch_safe_free(sql);
+
 			if (!switch_strlen_zero((char *) helper.stream.data)) {
-				char *this = (char *) helper.stream.data;
+				char *this_sql = (char *) helper.stream.data;
 				char *next = NULL;
 				char *last = NULL;
 
 				do {
-					if ((next = strchr(this, ';'))) {
+					if ((next = strchr(this_sql, ';'))) {
 						*next++ = '\0';
 						while (*next == '\n' || *next == ' ' || *next == '\r') {
 							*next++ = '\0';
 						}
 					}
 
-					if (!switch_strlen_zero(this) && (!last || strcmp(last, this))) {
-						sofia_glue_execute_sql(profile, &this, SWITCH_FALSE);
-						last = this;
+					if (!switch_strlen_zero(this_sql) && (!last || strcmp(last, this_sql))) {
+						sofia_glue_execute_sql(profile, &this_sql, SWITCH_FALSE);
+						last = this_sql;
 					}
-					this = next;
-				} while (this);
+					this_sql = next;
+				} while (this_sql);
 			}
 			switch_safe_free(helper.stream.data);
 			helper.stream.data = NULL;
@@ -555,14 +623,13 @@
 
 	while (mod_sofia_globals.running == 1) {
 		int count = 0;
-
+		
 		if (switch_queue_trypop(mod_sofia_globals.presence_queue, &pop) == SWITCH_STATUS_SUCCESS) {
 			switch_event_t *event = (switch_event_t *) pop;
 
 			if (!pop) {
 				break;
 			}
-
 			actual_sofia_presence_event_handler(event);
 			switch_event_destroy(&event);
 			count++;
@@ -664,7 +731,6 @@
 	char *user = argv[1];
 	char *host = argv[2];
 	switch_event_t *event;
-	char *status = NULL;
 	char *event_name = argv[5];
 
 	if (!strcasecmp(event_name, "message-summary")) {
@@ -676,14 +742,10 @@
 		return 0;
 	}
 
-	if (switch_strlen_zero(status)) {
-		status = "Available";
-	}
 	if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_PROBE) == SWITCH_STATUS_SUCCESS) {
 		switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
 		switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", profile->url);
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", user, host);
-		switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "status", status);
 		switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event_type", "presence");
 		switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event_subtype", "probe");
 		switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto-specific-event-name", event_name);
@@ -701,6 +763,7 @@
 	char *status = argv[2];
 	char *rpid = argv[3];
 	char *proto = argv[4];
+
 	char *to_user = NULL;
 	char *uuid = NULL;
 	char *state = NULL;
@@ -717,12 +780,20 @@
 			switch_url_decode(to_buf);
 			to_user = to_buf;
 		}
+		if (argc > 10 && !switch_strlen_zero(argv[9]) && !switch_strlen_zero(argv[10])) {
+			status = argv[9];
+			rpid = argv[10];
+		}
 	}
 
 	if (switch_strlen_zero(proto)) {
 		proto = NULL;
 	}
 
+	if (mod_sofia_globals.debug_presence > 0) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "%s PRESENCE_PROBE %s@%s\n", profile->name, user, host);
+	}
+
 	if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
 		switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", proto ? proto : SOFIA_CHAT_PROTO);
 		switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", profile->url);
@@ -736,7 +807,7 @@
 		if (!switch_strlen_zero(to_user)) {
 			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "to-user", to_user);
 		}
-
+		
 		if (switch_strlen_zero(state)) {
 			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "unique-id", SOFIA_CHAT_PROTO);
 			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "channel-state", "CS_HANGUP");
@@ -832,9 +903,9 @@
 							  "  <rpid:activities>\r\n" 
 							  "   <rpid:%s/>\n"
 							  "  </rpid:activities>\n"
-							  "  <dm:note>%s</dm:note>"
+							  "  <dm:note>%s</dm:note>\n"
 							  " </dm:person>\n"
-							  "</presence>", id, prpid, rpid, status);
+							  "</presence>", id, open, prpid, status);
 	}
 }
 
@@ -843,31 +914,55 @@
 	struct presence_helper *helper = (struct presence_helper *) pArg;
 	char *pl = NULL;
 	char *clean_id = NULL, *id = NULL;
-	uint32_t in = atoi(argv[14]);
-	char *status = argv[15];
-	char *rpid = argv[16];
-
 	char *proto = argv[0];
 	char *user = argv[1];
 	char *host = argv[2];
 	char *sub_to_user = argv[3];
-	char *sub_to_host = argv[17];
 	char *event = argv[5];
 	char *call_id = argv[7];
 	char *expires = argv[10];
 	char *user_agent = argv[11];
 	char *profile_name = argv[13];
+	uint32_t in = 0;
+	char *status = argv[14];
+	char *rpid = argv[15];
+	char *sub_to_host = argv[16];
+
 	nua_handle_t *nh;
 	char *to = NULL;
 	char *open;
 	char *prpid;
-	int done = 0;
 	const char *ct = "no/idea";
 	time_t exptime = switch_timestamp(NULL) + 3600;
-	char exp[80] = "";
 	int is_dialog = 0;
 	sofia_profile_t *ext_profile = NULL, *profile = helper->profile;
+	char sstr[128] = "";
+	int kill_handle = 0;
+	char expires_str[10] = "";
+
+	if (argc > 18 && !switch_strlen_zero(argv[17]) && !switch_strlen_zero(argv[18])) {
+		status = argv[17];
+		rpid = argv[18];
+	}
+
+	in = helper->event && helper->event->event_id == SWITCH_EVENT_PRESENCE_IN;
 
+
+	if (switch_strlen_zero(rpid)) {
+		rpid = "unknown";
+	}
+
+	if (switch_strlen_zero(status)) {
+		if (!strcasecmp(rpid, "busy")) {
+			status = "Busy";
+		} else if (!strcasecmp(rpid, "unavailable")) {
+			status = "Idle";
+		} else if (!strcasecmp(rpid, "away")) {
+			status = "Idle";
+		} else {
+			status = "Available";
+		}
+	}
 	
 	if (profile_name && strcasecmp(profile_name, helper->profile->name)) {
         if ((ext_profile = sofia_glue_find_profile(profile_name))) {
@@ -875,35 +970,37 @@
         }
     }
 	
-
+	if (!(nh = nua_handle_by_call_id(profile->nua, call_id))) {
+		goto end;
+	}
+	
 	if (expires) {
 		long tmp = atol(expires);
 		if (tmp > 0) {
-			exptime = tmp - switch_timestamp(NULL);
+			exptime = tmp - switch_timestamp(NULL) - SUB_OVERLAP;
+		} else {
+			exptime = tmp;
 		}
 	}
-
-	if (!(nh = nua_handle_by_call_id(profile->nua, call_id))) {
-		goto end;
-	}
-
+	
 	if (!rpid) {
 		rpid = "unknown";
 	}
 
 	prpid = translate_rpid(rpid);
 
-	if (in < 0) {
-		done = 1;
-		in = 0;
-	}
-
 	if (!strcasecmp(proto, SOFIA_CHAT_PROTO)) {
 		clean_id = switch_mprintf("sip:%s@%s", sub_to_user, sub_to_host);
 	} else {
 		clean_id = switch_mprintf("sip:%s+%s@%s", proto, sub_to_user, sub_to_host);
 	}
 
+	if (mod_sofia_globals.debug_presence > 0) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, 
+						  "SEND PRESENCE\nTo:      \t%s@%s\nFrom:    \t%s@%s\nCall-ID:  \t%s\nProfile:\t%s [%s]\n\n", 
+						  user, host, sub_to_user, sub_to_host, call_id, profile_name, helper->profile->name);
+	}
+
 	if (!strcasecmp(sub_to_host, host)) {
 		/* same host */
 		id = switch_mprintf("sip:%s+%s@%s", proto, sub_to_user, sub_to_host);
@@ -1058,6 +1155,9 @@
 
 		if (!is_dialog) {
 			char status_line[256] = "";
+
+			switch_set_string(status_line, status);
+
 			if (in) {
 				if (!strcmp(astate, "early")) {
 					switch_snprintf(status_line, sizeof(status_line), "Ring %s", switch_str_nil(from_id));
@@ -1073,19 +1173,11 @@
 					}
 					
 					if (switch_strlen_zero(from_id)) {
-						switch_snprintf(status_line, sizeof(status_line), "On The Phone");
+						switch_snprintf(status_line, sizeof(status_line), "On The Phone %s", status);
 					} else {
 						switch_snprintf(status_line, sizeof(status_line), "Talk %s", switch_str_nil(from_id));
 					}
 					rpid = "on-the-phone";
-				} else if (!strcmp(astate, "terminated")) {
-					if (!strcasecmp(rpid, "on-the-phone")) {
-						switch_snprintf(status_line, sizeof(status_line), "Dialing");
-					} else {
-						switch_snprintf(status_line, sizeof(status_line), "Available");
-					}
-				} else {
-					switch_set_string(status_line, status);
 				}
 
 				open = "open";
@@ -1093,14 +1185,10 @@
 				open = "closed";
 			}
 			
-			if (!strncasecmp(status_line, "registered", 10)) {
-				switch_snprintf(status_line, sizeof(status_line), "Available");
-			}
-
 			prpid = translate_rpid(rpid);
 			pl = gen_pidf(user_agent, clean_id, profile->url, open, rpid, prpid, status_line, &ct);
 		}
-
+		
 	} else {
 		if (in) {
 			open = "open";
@@ -1111,9 +1199,25 @@
 		pl = gen_pidf(user_agent, clean_id, profile->url, open, rpid, prpid, status, &ct);
 	}
 	
-	switch_snprintf(exp, sizeof(exp), "active;expires=%ld", (long) exptime);
 	nua_handle_bind(nh, &mod_sofia_globals.keep_private);
-	nua_notify(nh, SIPTAG_SUBSCRIPTION_STATE_STR(exp), SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR(ct), SIPTAG_PAYLOAD_STR(pl), TAG_END());
+	
+	if (helper->event && helper->event->event_id == SWITCH_EVENT_PRESENCE_OUT) {
+		switch_set_string(sstr, "terminated;reason=noresource");
+		switch_set_string(expires_str, "0");
+        kill_handle = 1;
+	} else if (exptime > 0) {
+		switch_snprintf(sstr, sizeof(sstr), "active;expires=%u", (unsigned)exptime);
+	} else {
+		unsigned delta = (unsigned) (exptime * -1);
+		switch_snprintf(sstr, sizeof(sstr), "active;expires=%u", delta);
+		switch_snprintf(expires_str, sizeof(expires_str), "%u", delta);
+		nua_dialog_usage_set_refresh_range(nh->nh_ds->ds_usage, delta, delta);
+	}
+
+	nua_notify(nh, 
+			   TAG_IF(*expires_str, SIPTAG_EXPIRES_STR(expires_str)),
+			   SIPTAG_SUBSCRIPTION_STATE_STR(sstr),
+			   SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR(ct), SIPTAG_PAYLOAD_STR(pl), TAG_END());
 	
   end:
 	
@@ -1126,6 +1230,10 @@
 	switch_safe_free(pl);
 	switch_safe_free(to);
 
+	if (nh && kill_handle) {
+		nua_handle_destroy(nh);
+	}
+
 	return 0;
 }
 
@@ -1138,7 +1246,6 @@
 	char *expires = argv[10];
 	char *profile_name = argv[13];
 	char *body = argv[14];
-	char *exp;
 	char *id = NULL;
 	nua_handle_t *nh;
 	int expire_sec = atoi(expires);
@@ -1163,14 +1270,12 @@
 	if (expire_sec < 0) {
 		expire_sec = 3600;
 	}
-	exp = switch_mprintf("active;expires=%ld", expire_sec);
+
 	nua_handle_bind(nh, &mod_sofia_globals.keep_private);
-	nua_notify(nh,
-			   SIPTAG_SUBSCRIPTION_STATE_STR(exp),
+	nua_notify(nh, SIPTAG_SUBSCRIPTION_STATE_STR("active"),
 			   SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR("application/simple-message-summary"), SIPTAG_PAYLOAD_STR(body), TAG_END());
 
 	switch_safe_free(id);
-	switch_safe_free(exp);
 
 	h->total++;
 
@@ -1267,7 +1372,8 @@
 										   tagi_t tags[])
 {
 	if (sip) {
-		long exp, exp_raw;
+		long exp_abs, exp_delta;
+		char exp_delta_str[30] = "";
 		sip_to_t const *to = sip->sip_to;
 		sip_from_t const *from = sip->sip_from;
 		sip_contact_t const *contact = sip->sip_contact;
@@ -1460,10 +1566,18 @@
 		call_id = sip->sip_call_id->i_id;
 		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_delta = profile->force_subscription_expires ? profile->force_subscription_expires : (sip->sip_expires ? sip->sip_expires->ex_delta : 3600);
+		
+		if (exp_delta) {
+			exp_abs = (long) switch_timestamp(NULL) + exp_delta;
+		} else {
+			exp_abs = 0;
+			sub_state = nua_substate_terminated;
+		}
 
-		exp_raw = (sip->sip_expires ? sip->sip_expires->ex_delta : 3600);
-		exp = (long) switch_timestamp(NULL) + exp_raw;
-
+		switch_snprintf(exp_delta_str, sizeof(exp_delta_str), "%ld", exp_delta);
+		
 		if (sofia_test_pflag(profile, PFLAG_MULTIREG)) {
 			sql = switch_mprintf("delete from sip_subscriptions where call_id='%q'", call_id);
 		} else {
@@ -1486,37 +1600,76 @@
 				switch_snprintf(accept + strlen(accept), sizeof(accept) - strlen(accept), "%s%s ", ap->ac_type, ap->ac_next ? "," : "");
 				ap = ap->ac_next;
 			}
+
+			/* negative in exptime means keep bumping up sub time to avoid a snafu where every device has it's own rules about subscriptions
+			   that somehow barely resemble the RFC not that I blame them because the RFC MAY be amibiguous and SHOULD be deleted.
+			   So to avoid the problem we keep resetting the expiration date of the subscription so it never expires.
+
+			   Eybeam completely ignores this option and most other subscription-state: directives from rfc3265 and still expires.
+			   Polycom is happy to keep upping the subscription expiry back to the original time on each new notify.
+			   The rest ... who knows...?
+
+			*/
+
 			sql = switch_mprintf("insert into sip_subscriptions "
 								 "(proto,sip_user,sip_host,sub_to_user,sub_to_host,presence_hosts,event,contact,call_id,full_from,"
 								 "full_via,expires,user_agent,accept,profile_name,hostname) "
 								 "values ('%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q',%ld,'%q','%q','%q','%q')",
 								 proto, from_user, from_host, to_user, to_host, profile->presence_hosts ? profile->presence_hosts : to_host, 
-								 event, contact_str, call_id, full_from, full_via, exp, full_agent, accept, profile->name,mod_sofia_globals.hostname);
+								 event, contact_str, call_id, full_from, full_via, 
+
+								 exp_delta * -1, 
+								 //exp_abs + SUB_OVERLAP, 
+
+								 full_agent, accept, profile->name,mod_sofia_globals.hostname);
 								 
 			
+			if (mod_sofia_globals.debug_presence > 0) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "%s SUBSCRIBE %s@%s %s@%s\n", profile->name, from_user, from_host, to_user, to_host);
+			}
+
 			switch_assert(sql != NULL);
 			sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
 
-			sstr = switch_mprintf("active;expires=%ld", exp_raw);
+			sstr = switch_mprintf("active;expires=%ld", exp_delta);
 		}
 
 		switch_mutex_unlock(profile->ireg_mutex);
 
 		if (status < 200) {
 			char *sticky = NULL;
-
+			char *contactstr = profile->url;
+			
 			if (is_nat) {
+				char params[128] = "";
+				if (contact->m_url->url_params) {
+					switch_snprintf(params, sizeof(params), ";%s", contact->m_url->url_params);
+				}
 				ipv6 = strchr(network_ip, ':');
-				sticky = switch_mprintf("sip:%s@%s%s%s:%d",
+				sticky = switch_mprintf("sip:%s@%s%s%s:%d%s",
 										contact_user,
 										ipv6 ? "[" : "",
 										network_ip,
 										ipv6 ? "]" : "",
-										network_port);
+										network_port,
+										params);
+			}
+			
+			if (switch_stristr("port=tcp", contact->m_url->url_params)) {
+				contactstr = profile->tcp_contact;
+			} else if (switch_stristr("port=tls", contact->m_url->url_params)) {
+				contactstr = profile->tls_contact;
 			}
 
-			nua_respond(nh, SIP_202_ACCEPTED, NUTAG_WITH_THIS(nua), SIPTAG_SUBSCRIPTION_STATE_STR(sstr), TAG_IF(sticky, NUTAG_PROXY(sticky)),
-						TAG_END());
+			
+
+			nua_dialog_usage_set_refresh_range(nh->nh_ds->ds_usage, exp_delta + SUB_OVERLAP, exp_delta + SUB_OVERLAP);
+			
+
+			nua_respond(nh, SIP_202_ACCEPTED, SIPTAG_CONTACT_STR(contact_str), NUTAG_WITH_THIS(nua), 
+						SIPTAG_SUBSCRIPTION_STATE_STR(sstr),
+						SIPTAG_EXPIRES_STR(exp_delta_str),
+						TAG_IF(sticky, NUTAG_PROXY(sticky)), TAG_END());
 
 			switch_safe_free(sticky);
 
@@ -1526,9 +1679,9 @@
 
 #if 0
 		nua_notify(nh,
-				   NUTAG_NEWSUB(1),
 				   SIPTAG_SUBSCRIPTION_STATE_STR(sstr), SIPTAG_EVENT_STR(event),
-				   SIPTAG_CONTENT_TYPE_STR("application/simple-message-summary"),
+				   SIPTAG_EXPIRES_STR(exp_delta_str),
+				   SIPTAG_CONTENT_TYPE_STR("application/notice"),
 				   SIPTAG_PAYLOAD_STR("Note: Come to ClueCon http://www.cluecon.com\n\n"), TAG_END());
 #endif
 
@@ -1569,12 +1722,66 @@
 	}
 }
 
+sofia_gateway_subscription_t *sofia_find_gateway_subscription(sofia_gateway_t *gateway_ptr, const char *event) {
+	sofia_gateway_subscription_t *gw_sub_ptr;
+	for (gw_sub_ptr = gateway_ptr->subscriptions; gw_sub_ptr; gw_sub_ptr = gw_sub_ptr->next) {
+		if (!strcasecmp(gw_sub_ptr->event, event)) {
+			/* this is the gateway subscription we are interested in */
+			return gw_sub_ptr;
+		}
+	}
+	return NULL;
+}
+
 void sofia_presence_handle_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[])
 {
+	sip_event_t const *o = NULL;
+	sofia_gateway_subscription_t *gw_sub_ptr;
+	
+	if (!sip) {
+		return;
+	}
 
+	tl_gets(tags, SIPTAG_EVENT_REF(o), TAG_END());
+	/* o->o_type: message-summary (for example) */
+	if (!o) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Event information not given\n");
+		return;
+	}
+
+	if (!sofia_private || !sofia_private->gateway) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Gateway information missing\n");
+		return;
+	}
+	
+	/* Find the subscription if one exists */
+	if (!(gw_sub_ptr = sofia_find_gateway_subscription(sofia_private->gateway, o->o_type))) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Could not find gateway subscription.  Gateway: %s.  Subscription Event: %s\n",
+				sofia_private->gateway->name, o->o_type);
+		return;
+	}
+	
+	/* Update the subscription status for the subscription */
+	switch (status) {
+	case 200:
+		/* TODO: in the spec it is possible for the other side to change the original expiry time,
+		 * this needs to be researched (eg, what sip header this information will be in) and implemented.
+		 * Although, since it seems the sofia stack is pretty much handling the subscription expiration
+		 * anyway, then maybe its not even worth bothering.
+		 */
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "got 200 OK response, updated state to SUB_STATE_SUBSCRIBE.\n");
+		gw_sub_ptr->state = SUB_STATE_SUBSCRIBE;
+		break;
+	case 100:
+		break;
+	default:
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "status (%d) != 200, updated state to SUB_STATE_FAILED.\n", status);
+		gw_sub_ptr->state = SUB_STATE_FAILED;
+		break;
+	}
 }
 
 void sofia_presence_handle_sip_i_publish(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
@@ -1598,10 +1805,16 @@
 			switch_event_t *event;
 			uint8_t in = 0;
 			char *sql;
+			char *full_agent = NULL;
+			long exp, exp_delta;
 
 			if ((xml = switch_xml_parse_str(payload->pl_data, strlen(payload->pl_data)))) {
 				char *status_txt = "", *note_txt = "";
 
+				if (sip->sip_user_agent) {
+					full_agent = sip_header_as_string(profile->home, (void *) sip->sip_user_agent);
+				}
+				
 				if ((tuple = switch_xml_child(xml, "tuple")) && (status = switch_xml_child(tuple, "status"))
 					&& (basic = switch_xml_child(status, "basic"))) {
 					status_txt = basic->txt;
@@ -1611,7 +1824,7 @@
 					note_txt = note->txt;
 				}
 
-				if (person && (act = switch_xml_child(person, "rpid:activities"))) {
+				if (person && (act = switch_xml_child(person, "rpid:activities")) && act->child && act->child->name) {
 					if ((rpid = strchr(act->child->name, ':'))) {
 						rpid++;
 					} else {
@@ -1630,12 +1843,24 @@
 					}
 				}
 
+				exp_delta = (sip->sip_expires ? sip->sip_expires->ex_delta : 3600);
+				exp = (long) switch_timestamp(NULL) + exp_delta;
+
 				if ((sql =
-					 switch_mprintf("update sip_registrations set status='%q',rpid='%q' where sip_user='%q' and sip_host='%q'",
-									note_txt, rpid, from_user, from_host))) {
+					 switch_mprintf("delete from sip_presence where sip_user='%q' and sip_host='%q' "
+									" and profile_name='%q' and hostname='%q'",
+									from_user, from_host, profile->name, mod_sofia_globals.hostname
+									))) {
 					sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
 				}
-
+					 
+				if ((sql =
+					 switch_mprintf("insert into sip_presence (sip_user, sip_host, status, rpid, expires, user_agent, profile_name, hostname) "
+									"values ('%q','%q','%q','%q',%ld,'%q','%q','%q')",
+									from_user, from_host, note_txt, rpid, exp, full_agent, profile->name, mod_sofia_globals.hostname))) {
+					sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
+				}
+				
 				event_type = sip_header_as_string(profile->home, (void *) sip->sip_event);
 
 				if (in) {
@@ -1643,8 +1868,8 @@
 						switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
 						switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "rpid", rpid);
 						switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", profile->url);
+						switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "user-agent", full_agent);
 						switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", from_user, from_host);
-
 						switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "status", note_txt);
 						switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event_type", event_type);
 						switch_event_fire(&event);
@@ -1654,6 +1879,7 @@
 						switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
 						switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "rpid", rpid);
 						switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", profile->url);
+						switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "user-agent", full_agent);
 						switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", from_user, from_host);
 
 						switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event_type", event_type);
@@ -1664,6 +1890,10 @@
 				if (event_type) {
 					su_free(profile->home, event_type);
 				}
+
+				if (full_agent) {
+					su_free(profile->home, full_agent);
+				}
 				switch_xml_free(xml);
 			}
 		}

Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/sofia_reg.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/sofia_reg.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_sofia/sofia_reg.c	Mon Dec 15 12:56:36 2008
@@ -77,6 +77,107 @@
 	}
 }
 
+void sofia_sub_check_gateway(sofia_profile_t *profile, time_t now)
+{
+	/* NOTE: A lot of the mechanism in place here for refreshing subscriptions is
+	 * pretty much redundant, as the sofia stack takes it upon itself to
+	 * refresh subscriptions on its own, based on the value of the Expires
+	 * header (which we control in the outgoing subscription request)
+	 */
+	sofia_gateway_t *gateway_ptr;
+	
+	for (gateway_ptr = profile->gateways; gateway_ptr; gateway_ptr = gateway_ptr->next) {
+		sofia_gateway_subscription_t *gw_sub_ptr;
+
+		for (gw_sub_ptr = gateway_ptr->subscriptions; gw_sub_ptr; gw_sub_ptr = gw_sub_ptr->next) {
+			int ss_state = nua_callstate_authenticating;
+			sub_state_t ostate = gw_sub_ptr->state;
+			
+			if (!now) {
+				gw_sub_ptr->state = ostate = SUB_STATE_UNSUBED;
+				gw_sub_ptr->expires_str = "0";
+			}
+			
+			switch (ostate) {
+			case SUB_STATE_NOSUB:
+				break;
+			case SUB_STATE_SUBSCRIBE:
+				gw_sub_ptr->expires = now + gw_sub_ptr->freq;
+				gw_sub_ptr->state = SUB_STATE_SUBED;
+				break;
+			case SUB_STATE_UNSUBSCRIBE:
+				gw_sub_ptr->state = SUB_STATE_NOSUB;
+				
+				/* not tested .. */
+				nua_unsubscribe(gateway_ptr->nh,
+						NUTAG_URL(gateway_ptr->register_url),
+						SIPTAG_EVENT_STR(gw_sub_ptr->event),
+						SIPTAG_ACCEPT_STR(gw_sub_ptr->content_type),
+						SIPTAG_TO_STR(gateway_ptr->register_from),
+						SIPTAG_FROM_STR(gateway_ptr->register_from),
+						SIPTAG_CONTACT_STR(gateway_ptr->register_contact),
+						TAG_NULL());
+				
+				break;
+			case SUB_STATE_UNSUBED:
+				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_DEBUG, "subscribing to [%s] on gateway [%s]\n", gw_sub_ptr->event, gateway_ptr->name);
+				}
+				
+				gateway_ptr->sofia_private = malloc(sizeof(*gateway_ptr->sofia_private));
+				switch_assert(gateway_ptr->sofia_private);
+
+				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);
+
+				if (now) {
+					nua_subscribe(gateway_ptr->nh,
+							NUTAG_URL(gateway_ptr->register_url),
+							SIPTAG_EVENT_STR(gw_sub_ptr->event),
+							SIPTAG_ACCEPT_STR(gw_sub_ptr->content_type),  
+							SIPTAG_TO_STR(gateway_ptr->register_from),
+							SIPTAG_FROM_STR(gateway_ptr->register_from),
+							SIPTAG_CONTACT_STR(gateway_ptr->register_contact),
+							SIPTAG_EXPIRES_STR(gw_sub_ptr->expires_str),  // sofia stack bases its auto-refresh stuff on this
+							TAG_NULL());
+					gw_sub_ptr->retry = now + gw_sub_ptr->retry_seconds;
+				} else {
+					nua_unsubscribe(gateway_ptr->nh,
+							NUTAG_URL(gateway_ptr->register_url),
+							SIPTAG_EVENT_STR(gw_sub_ptr->event),
+							SIPTAG_ACCEPT_STR(gw_sub_ptr->content_type),
+							SIPTAG_FROM_STR(gateway_ptr->register_from),
+							SIPTAG_TO_STR(gateway_ptr->register_from),
+							SIPTAG_CONTACT_STR(gateway_ptr->register_contact),
+							SIPTAG_EXPIRES_STR(gw_sub_ptr->expires_str),
+							TAG_NULL());
+				}
+				gw_sub_ptr->state = SUB_STATE_TRYING;
+				break;
+				
+			case SUB_STATE_FAILED:
+			case SUB_STATE_TRYING:
+				if (gw_sub_ptr->retry && now >= gw_sub_ptr->retry) {
+					gw_sub_ptr->state = SUB_STATE_UNSUBED;
+					gw_sub_ptr->retry = 0;
+				}
+				break;
+			default:
+				if (now >= gw_sub_ptr->expires) {
+					gw_sub_ptr->state = SUB_STATE_UNSUBED;
+				}
+				break;
+			}
+		}
+	}
+}
+
 void sofia_reg_check_gateway(sofia_profile_t *profile, time_t now)
 {
 	sofia_gateway_t *gateway_ptr, *last = NULL;
@@ -127,13 +228,18 @@
 
 		switch (ostate) {
 		case REG_STATE_NOREG:
-			gateway_ptr->status = SOFIA_GATEWAY_UP;
+			if (!gateway_ptr->ping && !gateway_ptr->pinging) {
+				gateway_ptr->status = SOFIA_GATEWAY_UP;
+			}
 			break;
 		case REG_STATE_REGISTER:
 			if (profile->debug) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Registered %s\n", gateway_ptr->name);
 			}
-			if (gateway_ptr->expires > 60) {
+
+			gateway_ptr->failures = 0;
+
+			if (gateway_ptr->freq > 60) {
 				gateway_ptr->expires = now + (gateway_ptr->freq - 15);
 			} else {
 				gateway_ptr->expires = now + (gateway_ptr->freq - 2);
@@ -150,7 +256,7 @@
 		case REG_STATE_UNREGED:
 			gateway_ptr->status = SOFIA_GATEWAY_DOWN;
 			sofia_reg_kill_reg(gateway_ptr, 0);
-
+			
 			if ((gateway_ptr->nh = nua_handle(gateway_ptr->profile->nua, NULL,
 											  SIPTAG_CALL_ID_STR(gateway_ptr->uuid_str),
 											  NUTAG_URL(gateway_ptr->register_proxy),
@@ -188,22 +294,31 @@
 								   NUTAG_REGISTRAR(gateway_ptr->register_proxy),
 								   NUTAG_OUTBOUND("no-options-keepalive"), NUTAG_OUTBOUND("no-validate"), NUTAG_KEEPALIVE(0), TAG_NULL());
 				}
-
+				gateway_ptr->retry = now + gateway_ptr->retry_seconds;
 				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 failure #%d\n", gateway_ptr->name, ++gateway_ptr->failures);
 				gateway_ptr->state = REG_STATE_FAILED;
 			}
 			break;
 
 		case REG_STATE_FAILED:
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "%s Failed Registration, setting retry to %d seconds.\n", 
+								  gateway_ptr->name, gateway_ptr->retry_seconds * (gateway_ptr->failures + 1));
+			gateway_ptr->retry =  now + (gateway_ptr->retry_seconds * (gateway_ptr->failures + 1));
 			sofia_reg_kill_reg(gateway_ptr, 0);
 			gateway_ptr->status = SOFIA_GATEWAY_DOWN;
-		case REG_STATE_TRYING:
-			if (gateway_ptr->retry && now >= gateway_ptr->retry) {
+			gateway_ptr->state = REG_STATE_FAIL_WAIT;
+			break;
+		case REG_STATE_FAIL_WAIT:
+			if (!gateway_ptr->retry || now >= gateway_ptr->retry) {
 				gateway_ptr->state = REG_STATE_UNREGED;
-				gateway_ptr->retry = 0;
+			}
+			break;
+		case REG_STATE_TRYING:
+			if (!gateway_ptr->retry || now >= gateway_ptr->retry) {
+				gateway_ptr->state = REG_STATE_FAILED;
 			}
 			break;
 		default:
@@ -402,6 +517,16 @@
 
 	sofia_glue_actually_execute_sql(profile, SWITCH_FALSE, sql, NULL);
 
+
+	if (now) {
+		switch_snprintf(sql, sizeof(sql), "delete from sip_presence where expires > 0 and expires <= %ld and hostname='%s'", 
+						(long) now, mod_sofia_globals.hostname);
+	} else {
+		switch_snprintf(sql, sizeof(sql), "delete from sip_presence where expires > 0 and hostname='%s'", mod_sofia_globals.hostname);
+	}
+
+	sofia_glue_actually_execute_sql(profile, SWITCH_FALSE, sql, NULL);
+
 	if (now) {
 		switch_snprintf(sql, sizeof(sql), "delete from sip_authentication where expires > 0 and expires <= %ld and hostname='%s'", 
 						(long) now, mod_sofia_globals.hostname);
@@ -638,7 +763,7 @@
 		}
 
 		if (is_nat && (profile->pflags & PFLAG_RECIEVED_IN_NAT_REG_CONTACT)) {
-			switch_snprintf(received_data, sizeof(received_data), ";received=\"%s:%d\"", url_ip, network_port);
+			switch_snprintf(received_data, sizeof(received_data), ";received=%s:%d", url_ip, network_port);
 		}
 
 		if (contact->m_url->url_params) {
@@ -699,7 +824,7 @@
 			if ((v_contact_str = switch_event_get_header(*v_event, "sip-force-contact"))) {
 
 				if (*received_data && (profile->pflags & PFLAG_RECIEVED_IN_NAT_REG_CONTACT)) {
-					switch_snprintf(received_data, sizeof(received_data), ";received=\"%s:%d\"", url_ip, network_port);
+					switch_snprintf(received_data, sizeof(received_data), ";received=%s:%d", url_ip, network_port);
 				}
 
 				if (!strcasecmp(v_contact_str, "nat-connectile-dysfunction") ||
@@ -818,6 +943,8 @@
 		if (sql) {
 			sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
 		}
+
+
 		switch_mutex_unlock(profile->ireg_mutex);
 
 		if (switch_event_create_subclass(&s_event, SWITCH_EVENT_CUSTOM, MY_EVENT_REGISTER) == SWITCH_STATUS_SUCCESS) {
@@ -828,6 +955,7 @@
 			switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "contact", contact_str);
 			switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "call-id", call_id);
 			switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "rpid", rpid);
+			switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "statusd", reg_desc);
 			switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "expires", "%ld", (long) exptime);
 			switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "to-user", from_user);
 			switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "to-host", from_host);
@@ -841,6 +969,20 @@
 							  "Register:\nFrom:    [%s@%s]\nContact: [%s]\nExpires: [%ld]\n", to_user, reg_host, contact_str, (long) exptime);
 		}
 
+		
+#if 0
+		if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
+			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
+			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "rpid", rpid);
+			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", profile->url);
+			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "user-agent",
+										   (sip && sip->sip_user_agent) ? sip->sip_user_agent->g_string : "unknown");
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", to_user, reg_host);
+			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "status", "Registered");
+			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event_type", "presence");
+			switch_event_fire(&event);
+		}
+#else
 		if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_PROBE) == SWITCH_STATUS_SUCCESS) {
 			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", "sip");
 			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", profile->url);
@@ -852,7 +994,35 @@
 			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event_type", "presence");
 			switch_event_fire(&event);
 		}
+#endif
+
+
 	} else {
+
+		if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_OUT) == SWITCH_STATUS_SUCCESS) {
+			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
+			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "rpid", rpid);
+			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", profile->url);
+			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "user-agent",
+										   (sip && sip->sip_user_agent) ? sip->sip_user_agent->g_string : "unknown");
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", to_user, reg_host);
+			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "status", "UNRegistered");
+			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event_type", "presence");
+			switch_event_fire(&event);
+		}
+#if 0
+		if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_OUT) == SWITCH_STATUS_SUCCESS) {
+			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", "sip");
+			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", profile->url);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s+%s@%s", SOFIA_CHAT_PROTO, to_user, reg_host);
+
+			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "status", "unavailable");
+			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "rpid", rpid);
+			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event_type", "presence");
+			switch_event_fire(&event);
+		}
+#endif
+
 		if (multi_reg) {
 			char *icontact, *p;
 			icontact = sofia_glue_get_url_from_contact(contact_str, 1);
@@ -889,16 +1059,6 @@
 				sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
 			}
 		}
-		if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_OUT) == SWITCH_STATUS_SUCCESS) {
-			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", "sip");
-			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", profile->url);
-			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s+%s@%s", SOFIA_CHAT_PROTO, to_user, reg_host);
-
-			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "status", "unavailable");
-			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "rpid", rpid);
-			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event_type", "presence");
-			switch_event_fire(&event);
-		}
 	}
 
 
@@ -1085,7 +1245,8 @@
 			break;
 		default:
 			sofia_private->gateway->state = REG_STATE_FAILED;
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Registration Failed with status %d\n", status);
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s Registration Failed with status %d. failure #%d\n", 
+							  sofia_private->gateway->name, status, ++sofia_private->gateway->failures);
 			break;
 		}
 		if (ostate != sofia_private->gateway->state) {

Modified: freeswitch/branches/gmaruzz/src/mod/event_handlers/mod_cdr_csv/mod_cdr_csv.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/event_handlers/mod_cdr_csv/mod_cdr_csv.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/event_handlers/mod_cdr_csv/mod_cdr_csv.c	Mon Dec 15 12:56:36 2008
@@ -199,7 +199,7 @@
 
 	if (globals.debug) {
 		switch_event_t *event;
-		if (switch_event_create(&event, SWITCH_EVENT_COMMAND) == SWITCH_STATUS_SUCCESS) {
+		if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_DATA) == SWITCH_STATUS_SUCCESS) {
 			char *buf;
 			switch_channel_event_set_data(channel, event);
 			switch_event_serialize(event, &buf, SWITCH_FALSE);

Modified: freeswitch/branches/gmaruzz/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c	Mon Dec 15 12:56:36 2008
@@ -608,16 +608,32 @@
 		switch_yield(10000); /* 10ms */
 	}
 
-	char data[MAXATOMLEN];
+	int type, size;
 
-	ei_decode_atom(rep->buff, &rep->index, data);
+	ei_get_type(rep->buff, &rep->index, &type, &size);
 
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "got data %s after %d milliseconds!\n", data, i*10);
+	if (type != ERL_STRING_EXT) /* XXX no unicode or character codes > 255 */
+		return NULL;
+
+	char *xmlstr = switch_core_alloc(ptr->listener->pool, size + 1);
+
+	ei_decode_string(rep->buff, &rep->index, xmlstr);
+
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "got data %s after %d milliseconds!\n", xmlstr, i*10);
+
+	if (switch_strlen_zero(xmlstr)) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Result\n");
+	} else if (!(xml = switch_xml_parse_str(xmlstr, strlen(xmlstr)))) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Parsing XML Result!\n");
+	} else {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "XML parsed OK!\n");
+	}
 
 	switch_core_hash_delete(ptr->listener->fetch_reply_hash, uuid_str);
 
-	free(rep->buff);
-	free(rep);
+	/*switch_safe_free(rep->buff);*/
+	/*switch_safe_free(rep);*/
+	/*switch_safe_free(xmlstr);*/
 
 	return xml;
 }

Modified: freeswitch/branches/gmaruzz/src/mod/event_handlers/mod_event_socket/mod_event_socket.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/event_handlers/mod_event_socket/mod_event_socket.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/event_handlers/mod_event_socket/mod_event_socket.c	Mon Dec 15 12:56:36 2008
@@ -48,7 +48,8 @@
 	LFLAG_MYEVENTS = (1 << 5),
 	LFLAG_SESSION = (1 << 6),
 	LFLAG_ASYNC = (1 << 7),
-	LFLAG_STATEFUL = (1 << 8)
+	LFLAG_STATEFUL = (1 << 8),
+	LFLAG_OUTBOUND = (1 << 9)
 } event_flag_t;
 
 typedef enum {
@@ -403,6 +404,7 @@
 
 	switch_core_hash_init(&listener->event_hash, listener->pool);
 	switch_set_flag(listener, LFLAG_AUTHED);
+	switch_set_flag(listener, LFLAG_OUTBOUND);
 	for (x = 1; x < argc; x++) {
 		if (argv[x] && !strcasecmp(argv[x], "full")) {
 			switch_set_flag(listener, LFLAG_FULL);
@@ -1225,46 +1227,6 @@
 		if (!strncasecmp(cmd, "connect", 7)) {
 			switch_snprintf(reply, reply_len, "+OK");
 			goto done;
-		} else if (listener->session && !strncasecmp(cmd, "sendmsg", 7)) {
-			char *uuid = cmd + 8;
-			switch_core_session_t *session = NULL;
-
-			if (uuid) {
-				while (*uuid == ' ') {
-					uuid++;
-				}
-				
-				if (*uuid == '\r' || *uuid == '\n') {
-					uuid = NULL;
-				} else {
-					strip_cr(uuid);
-				}
-			}
-
-			if (!uuid) {
-				uuid = switch_event_get_header(*event, "session-id");
-			}
-			
-			if (uuid && (session = switch_core_session_locate(uuid))) {
-				if ((status = switch_core_session_queue_private_event(session, event)) == SWITCH_STATUS_SUCCESS) {
-					switch_snprintf(reply, reply_len, "+OK");
-				} else {
-					switch_snprintf(reply, reply_len, "-ERR memory error");
-				}
-				switch_core_session_rwunlock(session);
-			} else {
-				if (switch_test_flag(listener, LFLAG_ASYNC)) {
-					if ((status = switch_core_session_queue_private_event(listener->session, event)) == SWITCH_STATUS_SUCCESS) {
-						switch_snprintf(reply, reply_len, "+OK");
-					} else {
-						switch_snprintf(reply, reply_len, "-ERR memory error");
-					}
-				} else {
-					switch_ivr_parse_event(listener->session, *event);
-					switch_snprintf(reply, reply_len, "+OK");
-				}
-			}
-			goto done;
 		} else if (!strncasecmp(cmd, "getvar", 6)) {
 			char *arg;
 			const char *val = "";
@@ -1334,11 +1296,61 @@
 			switch_snprintf(reply, reply_len, "+OK Events Enabled");
 			goto done;
 		}
+	}
 
-		if (!switch_test_flag(listener, LFLAG_FULL)) {
-			goto done;
+
+	if (!strncasecmp(cmd, "sendmsg", 7)) {
+		switch_core_session_t *session;
+		char *uuid = cmd + 7;
+
+		if (uuid) {
+			while (*uuid == ' ') {
+				uuid++;
+			}
+
+			if (*uuid == '\r' || *uuid == '\n') {
+				uuid = NULL;
+			} else {
+				strip_cr(uuid);
+			}
+		}
+
+		if (switch_strlen_zero(uuid)) {
+			uuid = switch_event_get_header(*event, "session-id");
 		}
+
+		if (switch_strlen_zero(uuid) && listener->session) {
+			if (switch_test_flag(listener, LFLAG_ASYNC)) {
+				if ((status = switch_core_session_queue_private_event(listener->session, event)) == SWITCH_STATUS_SUCCESS) {
+					switch_snprintf(reply, reply_len, "+OK");
+				} else {
+					switch_snprintf(reply, reply_len, "-ERR memory error");
+				}
+			} else {
+				switch_ivr_parse_event(listener->session, *event);
+				switch_snprintf(reply, reply_len, "+OK");
+			}
+		} else {
+			if (!switch_strlen_zero(uuid) && (session = switch_core_session_locate(uuid))) {
+				if ((status = switch_core_session_queue_private_event(session, event)) == SWITCH_STATUS_SUCCESS) {
+					switch_snprintf(reply, reply_len, "+OK");
+				} else {
+					switch_snprintf(reply, reply_len, "-ERR memory error");
+				}
+				switch_core_session_rwunlock(session);
+			} else {
+				switch_snprintf(reply, reply_len, "-ERR invalid session id [%s]", switch_str_nil(uuid));
+			}
+		}
+		
+		goto done;
+
 	}
+	
+	if (switch_test_flag(listener, LFLAG_OUTBOUND) && !switch_test_flag(listener, LFLAG_FULL)) {
+		goto done;
+	}
+
 
 	if (!strncasecmp(cmd, "sendevent", 9)) {
 		char *ename;
@@ -1364,39 +1376,6 @@
 		switch_event_fire(event);
 		switch_snprintf(reply, reply_len, "+OK");
 		goto done;
-	} else if (!strncasecmp(cmd, "sendmsg", 7)) {
-		switch_core_session_t *session;
-		char *uuid = cmd + 8;
-
-		if (uuid) {
-			while (*uuid == ' ') {
-				uuid++;
-			}
-
-			if (*uuid == '\r' || *uuid == '\n') {
-				uuid = NULL;
-			} else {
-				strip_cr(uuid);
-			}
-		}
-
-		if (!uuid) {
-			uuid = switch_event_get_header(*event, "session-id");
-		}
-		
-		if (uuid && (session = switch_core_session_locate(uuid))) {
-			if ((status = switch_core_session_queue_private_event(session, event)) == SWITCH_STATUS_SUCCESS) {
-				switch_snprintf(reply, reply_len, "+OK");
-			} else {
-				switch_snprintf(reply, reply_len, "-ERR memory error");
-			}
-			switch_core_session_rwunlock(session);
-		} else {
-			switch_snprintf(reply, reply_len, "-ERR invalid session id [%s]", switch_str_nil(uuid));
-		}
-
-		goto done;
-
 	} else if (!strncasecmp(cmd, "api ", 4)) {
 		struct api_command_struct acs = { 0 };
 		char *api_cmd = cmd + 4;
@@ -1676,7 +1655,7 @@
 
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "IP %s Rejected by acl \"%s\"\n", listener->remote_ip, prefs.acl[x]);
 
-				switch_snprintf(buf, sizeof(buf), "Content-Type: text/rude-rejection\nContent-Length %d\n\n", mlen);
+				switch_snprintf(buf, sizeof(buf), "Content-Type: text/rude-rejection\nContent-Length: %d\n\n", mlen);
 				len = strlen(buf);
 				switch_socket_send(listener->sock, buf, &len);
 				len = mlen;
@@ -1826,7 +1805,7 @@
 		const char message[] = "Disconnected, goodbye!\nSee you at ClueCon http://www.cluecon.com!\n";
 		int mlen = strlen(message);
 		
-		switch_snprintf(disco_buf, sizeof(disco_buf), "Content-Type: text/disconnect-notice\nContent-Length %d\n\n", mlen);
+		switch_snprintf(disco_buf, sizeof(disco_buf), "Content-Type: text/disconnect-notice\nContent-Length: %d\n\n", mlen);
 		len = strlen(disco_buf);
 		switch_socket_send(listener->sock, disco_buf, &len);
 		len = mlen;
@@ -1992,6 +1971,7 @@
 		listener->pool = listener_pool;
 		listener_pool = NULL;
 		listener->format = EVENT_FORMAT_PLAIN;
+		switch_set_flag(listener, LFLAG_FULL);
 		switch_mutex_init(&listener->flag_mutex, SWITCH_MUTEX_NESTED, listener->pool);
 		switch_mutex_init(&listener->filter_mutex, SWITCH_MUTEX_NESTED, listener->pool);
 

Modified: freeswitch/branches/gmaruzz/src/mod/formats/mod_shout/mod_shout.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/formats/mod_shout/mod_shout.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/formats/mod_shout/mod_shout.c	Mon Dec 15 12:56:36 2008
@@ -902,12 +902,22 @@
 
 static switch_status_t shout_file_write(switch_file_handle_t *handle, void *data, size_t *len)
 {
-	shout_context_t *context = handle->private_info;
+	shout_context_t *context;
 	unsigned char mp3buf[8192] = "";
 	int rlen;
 	int16_t *audio = data;
 	int nsamples = *len;
 
+	if (!handle) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error no handle\n");
+		return SWITCH_STATUS_FALSE;
+	}
+
+	if (!(context = handle->private_info)) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error no context\n");
+		return SWITCH_STATUS_FALSE;
+	}
+
 	if (context->shout && !context->shout_init) {
 		context->shout_init++;
 		if (shout_open(context->shout) != SHOUTERR_SUCCESS) {
@@ -918,7 +928,7 @@
 		launch_write_stream_thread(context);
 	}
 
-	if (handle->handler) {
+	if (handle->handler && context->audio_mutex) {
 		switch_mutex_lock(context->audio_mutex);
 		if (context->audio_buffer) {
 			if (!switch_buffer_write(context->audio_buffer, data, (nsamples * sizeof(int16_t) * handle->channels))) {
@@ -928,47 +938,50 @@
 		} else {
 			context->err++;
 		}
+
 		switch_mutex_unlock(context->audio_mutex);
 		if (context->err) {
 			return SWITCH_STATUS_FALSE;
 		}
-	} else {
 
-		if (!context->lame_ready) {
-			lame_init_params(context->gfp);
-			lame_print_config(context->gfp);
-			context->lame_ready = 1;
-		}
+		handle->sample_count += *len;
+		return SWITCH_STATUS_SUCCESS;
+	}
 
-		if (handle->channels == 2) {
-			int16_t l[4096] = { 0 };
-			int16_t r[4096] = { 0 };
-			int i, j = 0;
-
-			for (i = 0; i < nsamples; i++) {
-				l[i] = audio[j++];
-				r[i] = audio[j++];
-			}
+	if (!context->lame_ready) {
+		lame_init_params(context->gfp);
+		lame_print_config(context->gfp);
+		context->lame_ready = 1;
+	}
 
-			if ((rlen = lame_encode_buffer(context->gfp, l, r, 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 (handle->channels == 2) {
+		int16_t l[4096] = { 0 };
+		int16_t r[4096] = { 0 };
+		int i, j = 0;
 
-		} else if (handle->channels == 1) {
-			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;
-			}
-		} else {
-			rlen = 0;
+		for (i = 0; i < nsamples; i++) {
+			l[i] = audio[j++];
+			r[i] = audio[j++];
 		}
 
-		if (rlen) {
-			int ret = fwrite(mp3buf, 1, rlen, context->fp);
-			if (ret < 0) {
-				return SWITCH_STATUS_FALSE;
-			}
+		if ((rlen = lame_encode_buffer(context->gfp, l, r, nsamples, mp3buf, sizeof(mp3buf))) < 0) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "MP3 encode error %d!\n", rlen);
+			return SWITCH_STATUS_FALSE;
+		}
+
+	} else if (handle->channels == 1) {
+		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;
+		}
+	} else {
+		rlen = 0;
+	}
+
+	if (rlen) {
+		int ret = fwrite(mp3buf, 1, rlen, context->fp);
+		if (ret < 0) {
+			return SWITCH_STATUS_FALSE;
 		}
 	}
 

Modified: freeswitch/branches/gmaruzz/src/mod/formats/mod_sndfile/mod_sndfile.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/formats/mod_sndfile/mod_sndfile.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/formats/mod_sndfile/mod_sndfile.c	Mon Dec 15 12:56:36 2008
@@ -339,13 +339,13 @@
 			map->format = info.format;
 			if (map->ext) {
 				for (p = map->ext; *p; p++) {
-					*p = (char) tolower(*p);
+					*p = (char) switch_tolower(*p);
 				}
 				switch_core_hash_insert(globals.format_hash, map->ext, map);
 			}
 			if (map->uext) {
 				for (p = map->uext; *p; p++) {
-					*p = (char) toupper(*p);
+					*p = (char) switch_toupper(*p);
 				}
 				switch_core_hash_insert(globals.format_hash, map->uext, map);
 			}

Modified: freeswitch/branches/gmaruzz/src/mod/languages/mod_java/src/org/freeswitch/swig/CoreSession.java
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/languages/mod_java/src/org/freeswitch/swig/CoreSession.java	(original)
+++ freeswitch/branches/gmaruzz/src/mod/languages/mod_java/src/org/freeswitch/swig/CoreSession.java	Mon Dec 15 12:56:36 2008
@@ -245,8 +245,12 @@
     return freeswitchJNI.CoreSession_streamFile__SWIG_1(swigCPtr, this, file);
   }
 
+  public int sleep(int ms, int sync) {
+    return freeswitchJNI.CoreSession_sleep__SWIG_0(swigCPtr, this, ms, sync);
+  }
+
   public int sleep(int ms) {
-    return freeswitchJNI.CoreSession_sleep(swigCPtr, this, ms);
+    return freeswitchJNI.CoreSession_sleep__SWIG_1(swigCPtr, this, ms);
   }
 
   public int flushEvents() {

Modified: freeswitch/branches/gmaruzz/src/mod/languages/mod_java/src/org/freeswitch/swig/freeswitch.java
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/languages/mod_java/src/org/freeswitch/swig/freeswitch.java	(original)
+++ freeswitch/branches/gmaruzz/src/mod/languages/mod_java/src/org/freeswitch/swig/freeswitch.java	Mon Dec 15 12:56:36 2008
@@ -25,6 +25,10 @@
     freeswitchJNI.console_clean_log(msg);
   }
 
+  public static void msleep(long ms) {
+    freeswitchJNI.msleep(ms);
+  }
+
   public static void bridge(CoreSession session_a, CoreSession session_b) {
     freeswitchJNI.bridge(CoreSession.getCPtr(session_a), session_a, CoreSession.getCPtr(session_b), session_b);
   }

Modified: freeswitch/branches/gmaruzz/src/mod/languages/mod_java/src/org/freeswitch/swig/freeswitchJNI.java
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/languages/mod_java/src/org/freeswitch/swig/freeswitchJNI.java	(original)
+++ freeswitch/branches/gmaruzz/src/mod/languages/mod_java/src/org/freeswitch/swig/freeswitchJNI.java	Mon Dec 15 12:56:36 2008
@@ -136,7 +136,8 @@
   public final static native String CoreSession_playAndGetDigits(long jarg1, CoreSession jarg1_, int jarg2, int jarg3, int jarg4, int jarg5, String jarg6, String jarg7, String jarg8, String jarg9);
   public final static native int CoreSession_streamFile__SWIG_0(long jarg1, CoreSession jarg1_, String jarg2, int jarg3);
   public final static native int CoreSession_streamFile__SWIG_1(long jarg1, CoreSession jarg1_, String jarg2);
-  public final static native int CoreSession_sleep(long jarg1, CoreSession jarg1_, int jarg2);
+  public final static native int CoreSession_sleep__SWIG_0(long jarg1, CoreSession jarg1_, int jarg2, int jarg3);
+  public final static native int CoreSession_sleep__SWIG_1(long jarg1, CoreSession jarg1_, int jarg2);
   public final static native int CoreSession_flushEvents(long jarg1, CoreSession jarg1_);
   public final static native int CoreSession_flushDigits(long jarg1, CoreSession jarg1_);
   public final static native int CoreSession_setAutoHangup(long jarg1, CoreSession jarg1_, boolean jarg2);
@@ -158,6 +159,7 @@
   public final static native long CoreSession_run_dtmf_callback(long jarg1, CoreSession jarg1_, long jarg2, long jarg3);
   public final static native void console_log(String jarg1, String jarg2);
   public final static native void console_clean_log(String jarg1);
+  public final static native void msleep(long jarg1);
   public final static native void bridge(long jarg1, CoreSession jarg1_, long jarg2, CoreSession jarg2_);
   public final static native long hanguphook(long jarg1);
   public final static native long dtmf_callback(long jarg1, long jarg2, long jarg3, long jarg4, long jarg5);

Modified: freeswitch/branches/gmaruzz/src/mod/languages/mod_java/switch_swig_wrap.cpp
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/languages/mod_java/switch_swig_wrap.cpp	(original)
+++ freeswitch/branches/gmaruzz/src/mod/languages/mod_java/switch_swig_wrap.cpp	Mon Dec 15 12:56:36 2008
@@ -2674,7 +2674,26 @@
 }
 
 
-SWIGEXPORT jint JNICALL Java_org_freeswitch_swig_freeswitchJNI_CoreSession_1sleep(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jint jarg2) {
+SWIGEXPORT jint JNICALL Java_org_freeswitch_swig_freeswitchJNI_CoreSession_1sleep_1_1SWIG_10(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jint jarg2, jint jarg3) {
+  jint jresult = 0 ;
+  CoreSession *arg1 = (CoreSession *) 0 ;
+  int arg2 ;
+  int arg3 ;
+  int result;
+  
+  (void)jenv;
+  (void)jcls;
+  (void)jarg1_;
+  arg1 = *(CoreSession **)&jarg1; 
+  arg2 = (int)jarg2; 
+  arg3 = (int)jarg3; 
+  result = (int)(arg1)->sleep(arg2,arg3);
+  jresult = (jint)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT jint JNICALL Java_org_freeswitch_swig_freeswitchJNI_CoreSession_1sleep_1_1SWIG_11(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jint jarg2) {
   jint jresult = 0 ;
   CoreSession *arg1 = (CoreSession *) 0 ;
   int arg2 ;
@@ -3032,6 +3051,16 @@
 }
 
 
+SWIGEXPORT void JNICALL Java_org_freeswitch_swig_freeswitchJNI_msleep(JNIEnv *jenv, jclass jcls, jlong jarg1) {
+  unsigned int arg1 ;
+  
+  (void)jenv;
+  (void)jcls;
+  arg1 = (unsigned int)jarg1; 
+  msleep(arg1);
+}
+
+
 SWIGEXPORT void JNICALL Java_org_freeswitch_swig_freeswitchJNI_bridge(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2, jobject jarg2_) {
   CoreSession *arg1 = 0 ;
   CoreSession *arg2 = 0 ;

Modified: freeswitch/branches/gmaruzz/src/mod/languages/mod_lua/mod_lua_wrap.cpp
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/languages/mod_lua/mod_lua_wrap.cpp	(original)
+++ freeswitch/branches/gmaruzz/src/mod/languages/mod_lua/mod_lua_wrap.cpp	Mon Dec 15 12:56:36 2008
@@ -6077,7 +6077,38 @@
 }
 
 
-static int _wrap_CoreSession_sleep(lua_State* L) {
+static int _wrap_CoreSession_sleep__SWIG_0(lua_State* L) {
+  int SWIG_arg = -1;
+  CoreSession *arg1 = (CoreSession *) 0 ;
+  int arg2 ;
+  int arg3 ;
+  int result;
+  
+  SWIG_check_num_args("sleep",3,3)
+  if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("sleep",1,"CoreSession *");
+  if(!lua_isnumber(L,2)) SWIG_fail_arg("sleep",2,"int");
+  if(!lua_isnumber(L,3)) SWIG_fail_arg("sleep",3,"int");
+  
+  if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_CoreSession,0))){
+    SWIG_fail_ptr("CoreSession_sleep",1,SWIGTYPE_p_CoreSession);
+  }
+  
+  arg2 = (int)lua_tonumber(L, 2);
+  arg3 = (int)lua_tonumber(L, 3);
+  result = (int)(arg1)->sleep(arg2,arg3);
+  SWIG_arg=0;
+  lua_pushnumber(L, (lua_Number) result); SWIG_arg++;
+  return SWIG_arg;
+  
+  if(0) SWIG_fail;
+  
+fail:
+  lua_error(L);
+  return SWIG_arg;
+}
+
+
+static int _wrap_CoreSession_sleep__SWIG_1(lua_State* L) {
   int SWIG_arg = -1;
   CoreSession *arg1 = (CoreSession *) 0 ;
   int arg2 ;
@@ -6105,6 +6136,62 @@
 }
 
 
+static int _wrap_CoreSession_sleep(lua_State* L) {
+  int argc;
+  int argv[4]={
+    1,2,3,4
+  };
+  
+  argc = lua_gettop(L);
+  if (argc == 2) {
+    int _v;
+    {
+      void *ptr;
+      if (SWIG_isptrtype(L,argv[0])==0 || SWIG_ConvertPtr(L,argv[0], (void **) &ptr, SWIGTYPE_p_CoreSession, 0)) {
+        _v = 0;
+      } else {
+        _v = 1;
+      }
+    }
+    if (_v) {
+      {
+        _v = lua_isnumber(L,argv[1]);
+      }
+      if (_v) {
+        return _wrap_CoreSession_sleep__SWIG_1(L);
+      }
+    }
+  }
+  if (argc == 3) {
+    int _v;
+    {
+      void *ptr;
+      if (SWIG_isptrtype(L,argv[0])==0 || SWIG_ConvertPtr(L,argv[0], (void **) &ptr, SWIGTYPE_p_CoreSession, 0)) {
+        _v = 0;
+      } else {
+        _v = 1;
+      }
+    }
+    if (_v) {
+      {
+        _v = lua_isnumber(L,argv[1]);
+      }
+      if (_v) {
+        {
+          _v = lua_isnumber(L,argv[2]);
+        }
+        if (_v) {
+          return _wrap_CoreSession_sleep__SWIG_0(L);
+        }
+      }
+    }
+  }
+  
+  lua_pushstring(L,"No matching function for overloaded 'CoreSession_sleep'");
+  lua_error(L);return 0;
+}
+
+
 static int _wrap_CoreSession_flushEvents(lua_State* L) {
   int SWIG_arg = -1;
   CoreSession *arg1 = (CoreSession *) 0 ;
@@ -6791,6 +6878,26 @@
 }
 
 
+static int _wrap_msleep(lua_State* L) {
+  int SWIG_arg = -1;
+  unsigned int arg1 ;
+  
+  SWIG_check_num_args("msleep",1,1)
+  if(!lua_isnumber(L,1)) SWIG_fail_arg("msleep",1,"unsigned int");
+  arg1 = (unsigned int)lua_tonumber(L, 1);
+  msleep(arg1);
+  SWIG_arg=0;
+  
+  return SWIG_arg;
+  
+  if(0) SWIG_fail;
+  
+fail:
+  lua_error(L);
+  return SWIG_arg;
+}
+
+
 static int _wrap_bridge(lua_State* L) {
   int SWIG_arg = -1;
   CoreSession *arg1 = 0 ;
@@ -7801,6 +7908,7 @@
     { "consoleCleanLog", _wrap_consoleCleanLog},
     { "console_log", _wrap_console_log},
     { "console_clean_log", _wrap_console_clean_log},
+    { "msleep", _wrap_msleep},
     { "bridge", _wrap_bridge},
     { "hanguphook", _wrap_hanguphook},
     { "dtmf_callback", _wrap_dtmf_callback},

Modified: freeswitch/branches/gmaruzz/src/mod/languages/mod_managed/freeswitch_wrap.cxx
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/languages/mod_managed/freeswitch_wrap.cxx	(original)
+++ freeswitch/branches/gmaruzz/src/mod/languages/mod_managed/freeswitch_wrap.cxx	Mon Dec 15 12:56:36 2008
@@ -905,55 +905,88 @@
 }
 
 
-SWIGEXPORT char * SWIGSTDCALL CSharp_SWITCH_ENABLE_HEARTBEAT_EVENTS_VARIABLE_get() {
+SWIGEXPORT char * SWIGSTDCALL CSharp_SWITCH_SEND_SILENCE_WHEN_IDLE_VARIABLE_get() {
   char * jresult ;
   char *result = 0 ;
   
-  result = (char *) "enable_heartbeat_events";
+  result = (char *) "send_silence_when_idle";
   
   jresult = SWIG_csharp_string_callback((const char *)result); 
   return jresult;
 }
 
 
-SWIGEXPORT char * SWIGSTDCALL CSharp_SWITCH_BYPASS_MEDIA_AFTER_BRIDGE_VARIABLE_get() {
+SWIGEXPORT char * SWIGSTDCALL CSharp_SWITCH_CURRENT_APPLICATION_VARIABLE_get() {
   char * jresult ;
   char *result = 0 ;
   
-  result = (char *) "bypass_media_after_bridge";
+  result = (char *) "current_application";
   
   jresult = SWIG_csharp_string_callback((const char *)result); 
   return jresult;
 }
 
 
-SWIGEXPORT char * SWIGSTDCALL CSharp_SWITCH_READ_RESULT_VARIABLE_get() {
+SWIGEXPORT char * SWIGSTDCALL CSharp_SWITCH_CURRENT_APPLICATION_DATA_VARIABLE_get() {
   char * jresult ;
   char *result = 0 ;
   
-  result = (char *) "read_result";
+  result = (char *) "current_application_data";
   
   jresult = SWIG_csharp_string_callback((const char *)result); 
   return jresult;
 }
 
 
-SWIGEXPORT char * SWIGSTDCALL CSharp_SWITCH_COPY_XML_CDR_VARIABLE_get() {
+SWIGEXPORT char * SWIGSTDCALL CSharp_SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE_get() {
   char * jresult ;
   char *result = 0 ;
   
-  result = (char *) "copy_xml_cdr";
+  result = (char *) "current_application_response";
   
   jresult = SWIG_csharp_string_callback((const char *)result); 
   return jresult;
 }
 
 
-SWIGEXPORT char * SWIGSTDCALL CSharp_SWITCH_CURRENT_APPLICATION_VARIABLE_get() {
+SWIGEXPORT char * SWIGSTDCALL CSharp_SWITCH_ENABLE_HEARTBEAT_EVENTS_VARIABLE_get() {
   char * jresult ;
   char *result = 0 ;
   
-  result = (char *) "current_application";
+  result = (char *) "enable_heartbeat_events";
+  
+  jresult = SWIG_csharp_string_callback((const char *)result); 
+  return jresult;
+}
+
+
+SWIGEXPORT char * SWIGSTDCALL CSharp_SWITCH_BYPASS_MEDIA_AFTER_BRIDGE_VARIABLE_get() {
+  char * jresult ;
+  char *result = 0 ;
+  
+  result = (char *) "bypass_media_after_bridge";
+  
+  jresult = SWIG_csharp_string_callback((const char *)result); 
+  return jresult;
+}
+
+
+SWIGEXPORT char * SWIGSTDCALL CSharp_SWITCH_READ_RESULT_VARIABLE_get() {
+  char * jresult ;
+  char *result = 0 ;
+  
+  result = (char *) "read_result";
+  
+  jresult = SWIG_csharp_string_callback((const char *)result); 
+  return jresult;
+}
+
+
+SWIGEXPORT char * SWIGSTDCALL CSharp_SWITCH_COPY_XML_CDR_VARIABLE_get() {
+  char * jresult ;
+  char *result = 0 ;
+  
+  result = (char *) "copy_xml_cdr";
   
   jresult = SWIG_csharp_string_callback((const char *)result); 
   return jresult;
@@ -1037,6 +1070,17 @@
 }
 
 
+SWIGEXPORT char * SWIGSTDCALL CSharp_SWITCH_SESSION_IN_HANGUP_HOOK_VARIABLE_get() {
+  char * jresult ;
+  char *result = 0 ;
+  
+  result = (char *) "session_in_hangup_hook";
+  
+  jresult = SWIG_csharp_string_callback((const char *)result); 
+  return jresult;
+}
+
+
 SWIGEXPORT char * SWIGSTDCALL CSharp_SWITCH_PROCESS_CDR_VARIABLE_get() {
   char * jresult ;
   char *result = 0 ;
@@ -4811,6 +4855,18 @@
 }
 
 
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_session_read_lock_hangup(void * jarg1) {
+  int jresult ;
+  switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
+  switch_status_t result;
+  
+  arg1 = (switch_core_session_t *)jarg1; 
+  result = (switch_status_t)switch_core_session_read_lock_hangup(arg1);
+  jresult = result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_core_session_write_lock(void * jarg1) {
   switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
   
@@ -7458,6 +7514,162 @@
 }
 
 
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_toupper(int jarg1) {
+  int jresult ;
+  int arg1 ;
+  int result;
+  
+  arg1 = (int)jarg1; 
+  result = (int)switch_toupper(arg1);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_tolower(int jarg1) {
+  int jresult ;
+  int arg1 ;
+  int result;
+  
+  arg1 = (int)jarg1; 
+  result = (int)switch_tolower(arg1);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_isalnum(int jarg1) {
+  int jresult ;
+  int arg1 ;
+  int result;
+  
+  arg1 = (int)jarg1; 
+  result = (int)switch_isalnum(arg1);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_isalpha(int jarg1) {
+  int jresult ;
+  int arg1 ;
+  int result;
+  
+  arg1 = (int)jarg1; 
+  result = (int)switch_isalpha(arg1);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_iscntrl(int jarg1) {
+  int jresult ;
+  int arg1 ;
+  int result;
+  
+  arg1 = (int)jarg1; 
+  result = (int)switch_iscntrl(arg1);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_isdigit(int jarg1) {
+  int jresult ;
+  int arg1 ;
+  int result;
+  
+  arg1 = (int)jarg1; 
+  result = (int)switch_isdigit(arg1);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_isgraph(int jarg1) {
+  int jresult ;
+  int arg1 ;
+  int result;
+  
+  arg1 = (int)jarg1; 
+  result = (int)switch_isgraph(arg1);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_islower(int jarg1) {
+  int jresult ;
+  int arg1 ;
+  int result;
+  
+  arg1 = (int)jarg1; 
+  result = (int)switch_islower(arg1);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_isprint(int jarg1) {
+  int jresult ;
+  int arg1 ;
+  int result;
+  
+  arg1 = (int)jarg1; 
+  result = (int)switch_isprint(arg1);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_ispunct(int jarg1) {
+  int jresult ;
+  int arg1 ;
+  int result;
+  
+  arg1 = (int)jarg1; 
+  result = (int)switch_ispunct(arg1);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_isspace(int jarg1) {
+  int jresult ;
+  int arg1 ;
+  int result;
+  
+  arg1 = (int)jarg1; 
+  result = (int)switch_isspace(arg1);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_isupper(int jarg1) {
+  int jresult ;
+  int arg1 ;
+  int result;
+  
+  arg1 = (int)jarg1; 
+  result = (int)switch_isupper(arg1);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_isxdigit(int jarg1) {
+  int jresult ;
+  int arg1 ;
+  int result;
+  
+  arg1 = (int)jarg1; 
+  result = (int)switch_isxdigit(arg1);
+  jresult = result; 
+  return jresult;
+}
+
+
 SWIGEXPORT int SWIGSTDCALL CSharp_SWITCH_SMAX_get() {
   int jresult ;
   int result;
@@ -10707,6 +10919,29 @@
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_endpoint_interface_reflock_set(void * jarg1, void * jarg2) {
+  switch_endpoint_interface *arg1 = (switch_endpoint_interface *) 0 ;
+  switch_mutex_t *arg2 = (switch_mutex_t *) 0 ;
+  
+  arg1 = (switch_endpoint_interface *)jarg1; 
+  arg2 = (switch_mutex_t *)jarg2; 
+  if (arg1) (arg1)->reflock = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_endpoint_interface_reflock_get(void * jarg1) {
+  void * jresult ;
+  switch_endpoint_interface *arg1 = (switch_endpoint_interface *) 0 ;
+  switch_mutex_t *result = 0 ;
+  
+  arg1 = (switch_endpoint_interface *)jarg1; 
+  result = (switch_mutex_t *) ((arg1)->reflock);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_endpoint_interface_parent_set(void * jarg1, void * jarg2) {
   switch_endpoint_interface *arg1 = (switch_endpoint_interface *) 0 ;
   switch_loadable_module_interface_t *arg2 = (switch_loadable_module_interface_t *) 0 ;
@@ -11223,6 +11458,29 @@
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_timer_interface_reflock_set(void * jarg1, void * jarg2) {
+  switch_timer_interface *arg1 = (switch_timer_interface *) 0 ;
+  switch_mutex_t *arg2 = (switch_mutex_t *) 0 ;
+  
+  arg1 = (switch_timer_interface *)jarg1; 
+  arg2 = (switch_mutex_t *)jarg2; 
+  if (arg1) (arg1)->reflock = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_timer_interface_reflock_get(void * jarg1) {
+  void * jresult ;
+  switch_timer_interface *arg1 = (switch_timer_interface *) 0 ;
+  switch_mutex_t *result = 0 ;
+  
+  arg1 = (switch_timer_interface *)jarg1; 
+  result = (switch_mutex_t *) ((arg1)->reflock);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_timer_interface_parent_set(void * jarg1, void * jarg2) {
   switch_timer_interface *arg1 = (switch_timer_interface *) 0 ;
   switch_loadable_module_interface_t *arg2 = (switch_loadable_module_interface_t *) 0 ;
@@ -11386,6 +11644,29 @@
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_dialplan_interface_reflock_set(void * jarg1, void * jarg2) {
+  switch_dialplan_interface *arg1 = (switch_dialplan_interface *) 0 ;
+  switch_mutex_t *arg2 = (switch_mutex_t *) 0 ;
+  
+  arg1 = (switch_dialplan_interface *)jarg1; 
+  arg2 = (switch_mutex_t *)jarg2; 
+  if (arg1) (arg1)->reflock = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_dialplan_interface_reflock_get(void * jarg1) {
+  void * jresult ;
+  switch_dialplan_interface *arg1 = (switch_dialplan_interface *) 0 ;
+  switch_mutex_t *result = 0 ;
+  
+  arg1 = (switch_dialplan_interface *)jarg1; 
+  result = (switch_mutex_t *) ((arg1)->reflock);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_dialplan_interface_parent_set(void * jarg1, void * jarg2) {
   switch_dialplan_interface *arg1 = (switch_dialplan_interface *) 0 ;
   switch_loadable_module_interface_t *arg2 = (switch_loadable_module_interface_t *) 0 ;
@@ -11710,6 +11991,29 @@
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_file_interface_reflock_set(void * jarg1, void * jarg2) {
+  switch_file_interface *arg1 = (switch_file_interface *) 0 ;
+  switch_mutex_t *arg2 = (switch_mutex_t *) 0 ;
+  
+  arg1 = (switch_file_interface *)jarg1; 
+  arg2 = (switch_mutex_t *)jarg2; 
+  if (arg1) (arg1)->reflock = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_file_interface_reflock_get(void * jarg1) {
+  void * jresult ;
+  switch_file_interface *arg1 = (switch_file_interface *) 0 ;
+  switch_mutex_t *result = 0 ;
+  
+  arg1 = (switch_file_interface *)jarg1; 
+  result = (switch_mutex_t *) ((arg1)->reflock);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_file_interface_parent_set(void * jarg1, void * jarg2) {
   switch_file_interface *arg1 = (switch_file_interface *) 0 ;
   switch_loadable_module_interface_t *arg2 = (switch_loadable_module_interface_t *) 0 ;
@@ -12843,6 +13147,29 @@
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_asr_interface_reflock_set(void * jarg1, void * jarg2) {
+  switch_asr_interface *arg1 = (switch_asr_interface *) 0 ;
+  switch_mutex_t *arg2 = (switch_mutex_t *) 0 ;
+  
+  arg1 = (switch_asr_interface *)jarg1; 
+  arg2 = (switch_mutex_t *)jarg2; 
+  if (arg1) (arg1)->reflock = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_asr_interface_reflock_get(void * jarg1) {
+  void * jresult ;
+  switch_asr_interface *arg1 = (switch_asr_interface *) 0 ;
+  switch_mutex_t *result = 0 ;
+  
+  arg1 = (switch_asr_interface *)jarg1; 
+  result = (switch_mutex_t *) ((arg1)->reflock);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_asr_interface_parent_set(void * jarg1, void * jarg2) {
   switch_asr_interface *arg1 = (switch_asr_interface *) 0 ;
   switch_loadable_module_interface_t *arg2 = (switch_loadable_module_interface_t *) 0 ;
@@ -13421,6 +13748,29 @@
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_speech_interface_reflock_set(void * jarg1, void * jarg2) {
+  switch_speech_interface *arg1 = (switch_speech_interface *) 0 ;
+  switch_mutex_t *arg2 = (switch_mutex_t *) 0 ;
+  
+  arg1 = (switch_speech_interface *)jarg1; 
+  arg2 = (switch_mutex_t *)jarg2; 
+  if (arg1) (arg1)->reflock = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_speech_interface_reflock_get(void * jarg1) {
+  void * jresult ;
+  switch_speech_interface *arg1 = (switch_speech_interface *) 0 ;
+  switch_mutex_t *result = 0 ;
+  
+  arg1 = (switch_speech_interface *)jarg1; 
+  result = (switch_mutex_t *) ((arg1)->reflock);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_speech_interface_parent_set(void * jarg1, void * jarg2) {
   switch_speech_interface *arg1 = (switch_speech_interface *) 0 ;
   switch_loadable_module_interface_t *arg2 = (switch_loadable_module_interface_t *) 0 ;
@@ -13879,6 +14229,29 @@
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_say_interface_reflock_set(void * jarg1, void * jarg2) {
+  switch_say_interface *arg1 = (switch_say_interface *) 0 ;
+  switch_mutex_t *arg2 = (switch_mutex_t *) 0 ;
+  
+  arg1 = (switch_say_interface *)jarg1; 
+  arg2 = (switch_mutex_t *)jarg2; 
+  if (arg1) (arg1)->reflock = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_say_interface_reflock_get(void * jarg1) {
+  void * jresult ;
+  switch_say_interface *arg1 = (switch_say_interface *) 0 ;
+  switch_mutex_t *result = 0 ;
+  
+  arg1 = (switch_say_interface *)jarg1; 
+  result = (switch_mutex_t *) ((arg1)->reflock);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_say_interface_parent_set(void * jarg1, void * jarg2) {
   switch_say_interface *arg1 = (switch_say_interface *) 0 ;
   switch_loadable_module_interface_t *arg2 = (switch_loadable_module_interface_t *) 0 ;
@@ -14042,6 +14415,29 @@
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_chat_interface_reflock_set(void * jarg1, void * jarg2) {
+  switch_chat_interface *arg1 = (switch_chat_interface *) 0 ;
+  switch_mutex_t *arg2 = (switch_mutex_t *) 0 ;
+  
+  arg1 = (switch_chat_interface *)jarg1; 
+  arg2 = (switch_mutex_t *)jarg2; 
+  if (arg1) (arg1)->reflock = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_chat_interface_reflock_get(void * jarg1) {
+  void * jresult ;
+  switch_chat_interface *arg1 = (switch_chat_interface *) 0 ;
+  switch_mutex_t *result = 0 ;
+  
+  arg1 = (switch_chat_interface *)jarg1; 
+  result = (switch_mutex_t *) ((arg1)->reflock);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_chat_interface_parent_set(void * jarg1, void * jarg2) {
   switch_chat_interface *arg1 = (switch_chat_interface *) 0 ;
   switch_loadable_module_interface_t *arg2 = (switch_loadable_module_interface_t *) 0 ;
@@ -14205,6 +14601,29 @@
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_management_interface_reflock_set(void * jarg1, void * jarg2) {
+  switch_management_interface *arg1 = (switch_management_interface *) 0 ;
+  switch_mutex_t *arg2 = (switch_mutex_t *) 0 ;
+  
+  arg1 = (switch_management_interface *)jarg1; 
+  arg2 = (switch_mutex_t *)jarg2; 
+  if (arg1) (arg1)->reflock = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_management_interface_reflock_get(void * jarg1) {
+  void * jresult ;
+  switch_management_interface *arg1 = (switch_management_interface *) 0 ;
+  switch_mutex_t *result = 0 ;
+  
+  arg1 = (switch_management_interface *)jarg1; 
+  result = (switch_mutex_t *) ((arg1)->reflock);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_management_interface_parent_set(void * jarg1, void * jarg2) {
   switch_management_interface *arg1 = (switch_management_interface *) 0 ;
   switch_loadable_module_interface_t *arg2 = (switch_loadable_module_interface_t *) 0 ;
@@ -14460,6 +14879,29 @@
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_directory_interface_reflock_set(void * jarg1, void * jarg2) {
+  switch_directory_interface *arg1 = (switch_directory_interface *) 0 ;
+  switch_mutex_t *arg2 = (switch_mutex_t *) 0 ;
+  
+  arg1 = (switch_directory_interface *)jarg1; 
+  arg2 = (switch_mutex_t *)jarg2; 
+  if (arg1) (arg1)->reflock = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_directory_interface_reflock_get(void * jarg1) {
+  void * jresult ;
+  switch_directory_interface *arg1 = (switch_directory_interface *) 0 ;
+  switch_mutex_t *result = 0 ;
+  
+  arg1 = (switch_directory_interface *)jarg1; 
+  result = (switch_mutex_t *) ((arg1)->reflock);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_directory_interface_parent_set(void * jarg1, void * jarg2) {
   switch_directory_interface *arg1 = (switch_directory_interface *) 0 ;
   switch_loadable_module_interface_t *arg2 = (switch_loadable_module_interface_t *) 0 ;
@@ -15877,6 +16319,29 @@
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_codec_interface_reflock_set(void * jarg1, void * jarg2) {
+  switch_codec_interface *arg1 = (switch_codec_interface *) 0 ;
+  switch_mutex_t *arg2 = (switch_mutex_t *) 0 ;
+  
+  arg1 = (switch_codec_interface *)jarg1; 
+  arg2 = (switch_mutex_t *)jarg2; 
+  if (arg1) (arg1)->reflock = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_codec_interface_reflock_get(void * jarg1) {
+  void * jresult ;
+  switch_codec_interface *arg1 = (switch_codec_interface *) 0 ;
+  switch_mutex_t *result = 0 ;
+  
+  arg1 = (switch_codec_interface *)jarg1; 
+  result = (switch_mutex_t *) ((arg1)->reflock);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_codec_interface_parent_set(void * jarg1, void * jarg2) {
   switch_codec_interface *arg1 = (switch_codec_interface *) 0 ;
   switch_loadable_module_interface_t *arg2 = (switch_loadable_module_interface_t *) 0 ;
@@ -16150,6 +16615,29 @@
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_application_interface_reflock_set(void * jarg1, void * jarg2) {
+  switch_application_interface *arg1 = (switch_application_interface *) 0 ;
+  switch_mutex_t *arg2 = (switch_mutex_t *) 0 ;
+  
+  arg1 = (switch_application_interface *)jarg1; 
+  arg2 = (switch_mutex_t *)jarg2; 
+  if (arg1) (arg1)->reflock = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_application_interface_reflock_get(void * jarg1) {
+  void * jresult ;
+  switch_application_interface *arg1 = (switch_application_interface *) 0 ;
+  switch_mutex_t *result = 0 ;
+  
+  arg1 = (switch_application_interface *)jarg1; 
+  result = (switch_mutex_t *) ((arg1)->reflock);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_application_interface_parent_set(void * jarg1, void * jarg2) {
   switch_application_interface *arg1 = (switch_application_interface *) 0 ;
   switch_loadable_module_interface_t *arg2 = (switch_loadable_module_interface_t *) 0 ;
@@ -16371,6 +16859,29 @@
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_api_interface_reflock_set(void * jarg1, void * jarg2) {
+  switch_api_interface *arg1 = (switch_api_interface *) 0 ;
+  switch_mutex_t *arg2 = (switch_mutex_t *) 0 ;
+  
+  arg1 = (switch_api_interface *)jarg1; 
+  arg2 = (switch_mutex_t *)jarg2; 
+  if (arg1) (arg1)->reflock = arg2;
+  
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_switch_api_interface_reflock_get(void * jarg1) {
+  void * jresult ;
+  switch_api_interface *arg1 = (switch_api_interface *) 0 ;
+  switch_mutex_t *result = 0 ;
+  
+  arg1 = (switch_api_interface *)jarg1; 
+  result = (switch_mutex_t *) ((arg1)->reflock);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_api_interface_parent_set(void * jarg1, void * jarg2) {
   switch_api_interface *arg1 = (switch_api_interface *) 0 ;
   switch_loadable_module_interface_t *arg2 = (switch_loadable_module_interface_t *) 0 ;
@@ -16729,7 +17240,7 @@
 }
 
 
-SWIGEXPORT int SWIGSTDCALL CSharp_switch_channel_wait_for_flag(void * jarg1, unsigned long jarg2, int jarg3, unsigned long jarg4, void * jarg5) {
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_channel_wait_for_flag(void * jarg1, int jarg2, int jarg3, unsigned long jarg4, void * jarg5) {
   int jresult ;
   switch_channel_t *arg1 = (switch_channel_t *) 0 ;
   switch_channel_flag_t arg2 ;
@@ -16875,18 +17386,18 @@
 }
 
 
-SWIGEXPORT int SWIGSTDCALL CSharp_switch_channel_init(void * jarg1, void * jarg2, int jarg3, unsigned long jarg4) {
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_channel_init(void * jarg1, void * jarg2, int jarg3, int jarg4) {
   int jresult ;
   switch_channel_t *arg1 = (switch_channel_t *) 0 ;
   switch_core_session_t *arg2 = (switch_core_session_t *) 0 ;
   switch_channel_state_t arg3 ;
-  uint32_t arg4 ;
+  switch_channel_flag_t arg4 ;
   switch_status_t result;
   
   arg1 = (switch_channel_t *)jarg1; 
   arg2 = (switch_core_session_t *)jarg2; 
   arg3 = (switch_channel_state_t)jarg3; 
-  arg4 = (uint32_t)jarg4; 
+  arg4 = (switch_channel_flag_t)jarg4; 
   result = (switch_status_t)switch_channel_init(arg1,arg2,arg3,arg4);
   jresult = result; 
   return jresult;
@@ -17126,7 +17637,7 @@
 }
 
 
-SWIGEXPORT unsigned long SWIGSTDCALL CSharp_switch_channel_test_flag(void * jarg1, unsigned long jarg2) {
+SWIGEXPORT unsigned long SWIGSTDCALL CSharp_switch_channel_test_flag(void * jarg1, int jarg2) {
   unsigned long jresult ;
   switch_channel_t *arg1 = (switch_channel_t *) 0 ;
   switch_channel_flag_t arg2 ;
@@ -17140,7 +17651,7 @@
 }
 
 
-SWIGEXPORT void SWIGSTDCALL CSharp_switch_channel_set_flag(void * jarg1, unsigned long jarg2) {
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_channel_set_flag(void * jarg1, int jarg2) {
   switch_channel_t *arg1 = (switch_channel_t *) 0 ;
   switch_channel_flag_t arg2 ;
   
@@ -17150,7 +17661,7 @@
 }
 
 
-SWIGEXPORT int SWIGSTDCALL CSharp_switch_channel_set_flag_partner(void * jarg1, unsigned long jarg2) {
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_channel_set_flag_partner(void * jarg1, int jarg2) {
   int jresult ;
   switch_channel_t *arg1 = (switch_channel_t *) 0 ;
   switch_channel_flag_t arg2 ;
@@ -17164,7 +17675,7 @@
 }
 
 
-SWIGEXPORT int SWIGSTDCALL CSharp_switch_channel_clear_flag_partner(void * jarg1, unsigned long jarg2) {
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_channel_clear_flag_partner(void * jarg1, int jarg2) {
   int jresult ;
   switch_channel_t *arg1 = (switch_channel_t *) 0 ;
   switch_channel_flag_t arg2 ;
@@ -17178,7 +17689,7 @@
 }
 
 
-SWIGEXPORT void SWIGSTDCALL CSharp_switch_channel_set_state_flag(void * jarg1, unsigned long jarg2) {
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_channel_set_state_flag(void * jarg1, int jarg2) {
   switch_channel_t *arg1 = (switch_channel_t *) 0 ;
   switch_channel_flag_t arg2 ;
   
@@ -17188,7 +17699,7 @@
 }
 
 
-SWIGEXPORT void SWIGSTDCALL CSharp_switch_channel_clear_flag(void * jarg1, unsigned long jarg2) {
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_channel_clear_flag(void * jarg1, int jarg2) {
   switch_channel_t *arg1 = (switch_channel_t *) 0 ;
   switch_channel_flag_t arg2 ;
   
@@ -17580,6 +18091,48 @@
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_channel_audio_sync(void * jarg1) {
+  switch_channel_t *arg1 = (switch_channel_t *) 0 ;
+  
+  arg1 = (switch_channel_t *)jarg1; 
+  switch_channel_audio_sync(arg1);
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_channel_set_private_flag(void * jarg1, unsigned long jarg2) {
+  switch_channel_t *arg1 = (switch_channel_t *) 0 ;
+  uint32_t arg2 ;
+  
+  arg1 = (switch_channel_t *)jarg1; 
+  arg2 = (uint32_t)jarg2; 
+  switch_channel_set_private_flag(arg1,arg2);
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_channel_clear_private_flag(void * jarg1, unsigned long jarg2) {
+  switch_channel_t *arg1 = (switch_channel_t *) 0 ;
+  uint32_t arg2 ;
+  
+  arg1 = (switch_channel_t *)jarg1; 
+  arg2 = (uint32_t)jarg2; 
+  switch_channel_clear_private_flag(arg1,arg2);
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_channel_test_private_flag(void * jarg1, unsigned long jarg2) {
+  int jresult ;
+  switch_channel_t *arg1 = (switch_channel_t *) 0 ;
+  uint32_t arg2 ;
+  int result;
+  
+  arg1 = (switch_channel_t *)jarg1; 
+  arg2 = (uint32_t)jarg2; 
+  result = (int)switch_channel_test_private_flag(arg1,arg2);
+  jresult = result; 
+  return jresult;
+}
+
+
 SWIGEXPORT int SWIGSTDCALL CSharp_switch_buffer_create(void * jarg1, void * jarg2, void * jarg3) {
   int jresult ;
   switch_memory_pool_t *arg1 = (switch_memory_pool_t *) 0 ;
@@ -19622,17 +20175,19 @@
 }
 
 
-SWIGEXPORT int SWIGSTDCALL CSharp_switch_ivr_sleep(void * jarg1, unsigned long jarg2, void * jarg3) {
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_ivr_sleep(void * jarg1, unsigned long jarg2, int jarg3, void * jarg4) {
   int jresult ;
   switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
   uint32_t arg2 ;
-  switch_input_args_t *arg3 = (switch_input_args_t *) 0 ;
+  switch_bool_t arg3 ;
+  switch_input_args_t *arg4 = (switch_input_args_t *) 0 ;
   switch_status_t result;
   
   arg1 = (switch_core_session_t *)jarg1; 
   arg2 = (uint32_t)jarg2; 
-  arg3 = (switch_input_args_t *)jarg3; 
-  result = (switch_status_t)switch_ivr_sleep(arg1,arg2,arg3);
+  arg3 = (switch_bool_t)jarg3; 
+  arg4 = (switch_input_args_t *)jarg4; 
+  result = (switch_status_t)switch_ivr_sleep(arg1,arg2,arg3,arg4);
   jresult = result; 
   return jresult;
 }
@@ -19950,15 +20505,16 @@
 }
 
 
-SWIGEXPORT int SWIGSTDCALL CSharp_switch_ivr_tone_detect_session(void * jarg1, char * jarg2, char * jarg3, char * jarg4, void * jarg5, char * jarg6, char * jarg7) {
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_ivr_tone_detect_session(void * jarg1, char * jarg2, char * jarg3, char * jarg4, void * jarg5, int jarg6, char * jarg7, char * jarg8) {
   int jresult ;
   switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
   char *arg2 = (char *) 0 ;
   char *arg3 = (char *) 0 ;
   char *arg4 = (char *) 0 ;
   time_t arg5 ;
-  char *arg6 = (char *) 0 ;
+  int arg6 ;
   char *arg7 = (char *) 0 ;
+  char *arg8 = (char *) 0 ;
   switch_status_t result;
   time_t *argp5 ;
   
@@ -19972,9 +20528,10 @@
     return 0;
   }
   arg5 = *argp5; 
-  arg6 = (char *)jarg6; 
+  arg6 = (int)jarg6; 
   arg7 = (char *)jarg7; 
-  result = (switch_status_t)switch_ivr_tone_detect_session(arg1,(char const *)arg2,(char const *)arg3,(char const *)arg4,arg5,(char const *)arg6,(char const *)arg7);
+  arg8 = (char *)jarg8; 
+  result = (switch_status_t)switch_ivr_tone_detect_session(arg1,(char const *)arg2,(char const *)arg3,(char const *)arg4,arg5,arg6,(char const *)arg7,(char const *)arg8);
   jresult = result; 
   return jresult;
 }
@@ -20140,7 +20697,7 @@
 }
 
 
-SWIGEXPORT int SWIGSTDCALL CSharp_switch_ivr_originate(void * jarg1, void * jarg2, void * jarg3, char * jarg4, unsigned long jarg5, void * jarg6, char * jarg7, char * jarg8, void * jarg9, unsigned long jarg10) {
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_ivr_originate(void * jarg1, void * jarg2, void * jarg3, char * jarg4, unsigned long jarg5, void * jarg6, char * jarg7, char * jarg8, void * jarg9, void * jarg10, unsigned long jarg11) {
   int jresult ;
   switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
   switch_core_session_t **arg2 = (switch_core_session_t **) 0 ;
@@ -20151,7 +20708,8 @@
   char *arg7 = (char *) 0 ;
   char *arg8 = (char *) 0 ;
   switch_caller_profile_t *arg9 = (switch_caller_profile_t *) 0 ;
-  switch_originate_flag_t arg10 ;
+  switch_event_t *arg10 = (switch_event_t *) 0 ;
+  switch_originate_flag_t arg11 ;
   switch_status_t result;
   
   arg1 = (switch_core_session_t *)jarg1; 
@@ -20163,8 +20721,9 @@
   arg7 = (char *)jarg7; 
   arg8 = (char *)jarg8; 
   arg9 = (switch_caller_profile_t *)jarg9; 
-  arg10 = (switch_originate_flag_t)jarg10; 
-  result = (switch_status_t)switch_ivr_originate(arg1,arg2,arg3,(char const *)arg4,arg5,(switch_state_handler_table const *)arg6,(char const *)arg7,(char const *)arg8,arg9,arg10);
+  arg10 = (switch_event_t *)jarg10; 
+  arg11 = (switch_originate_flag_t)jarg11; 
+  result = (switch_status_t)switch_ivr_originate(arg1,arg2,arg3,(char const *)arg4,arg5,(switch_state_handler_table const *)arg6,(char const *)arg7,(char const *)arg8,arg9,arg10,arg11);
   jresult = result; 
   return jresult;
 }
@@ -21243,15 +21802,19 @@
 }
 
 
-SWIGEXPORT void SWIGSTDCALL CSharp_switch_rtp_change_interval(void * jarg1, unsigned long jarg2, unsigned long jarg3) {
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_rtp_change_interval(void * jarg1, unsigned long jarg2, unsigned long jarg3) {
+  int jresult ;
   switch_rtp_t *arg1 = (switch_rtp_t *) 0 ;
   uint32_t arg2 ;
   uint32_t arg3 ;
+  switch_status_t result;
   
   arg1 = (switch_rtp_t *)jarg1; 
   arg2 = (uint32_t)jarg2; 
   arg3 = (uint32_t)jarg3; 
-  switch_rtp_change_interval(arg1,arg2,arg3);
+  result = (switch_status_t)switch_rtp_change_interval(arg1,arg2,arg3);
+  jresult = result; 
+  return jresult;
 }
 
 
@@ -21665,6 +22228,14 @@
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_rtp_flush_read_buffer(void * jarg1) {
+  switch_rtp_t *arg1 = (switch_rtp_t *) 0 ;
+  
+  arg1 = (switch_rtp_t *)jarg1; 
+  rtp_flush_read_buffer(arg1);
+}
+
+
 SWIGEXPORT int SWIGSTDCALL CSharp_switch_rtp_enable_vad(void * jarg1, void * jarg2, void * jarg3, unsigned long jarg4) {
   int jresult ;
   switch_rtp_t *arg1 = (switch_rtp_t *) 0 ;
@@ -26292,15 +26863,17 @@
 }
 
 
-SWIGEXPORT int SWIGSTDCALL CSharp_CoreSession_sleep(void * jarg1, int jarg2) {
+SWIGEXPORT int SWIGSTDCALL CSharp_CoreSession_sleep(void * jarg1, int jarg2, int jarg3) {
   int jresult ;
   CoreSession *arg1 = (CoreSession *) 0 ;
   int arg2 ;
+  int arg3 = (int) 0 ;
   int result;
   
   arg1 = (CoreSession *)jarg1; 
   arg2 = (int)jarg2; 
-  result = (int)(arg1)->sleep(arg2);
+  arg3 = (int)jarg3; 
+  result = (int)(arg1)->sleep(arg2,arg3);
   jresult = result; 
   return jresult;
 }
@@ -26511,6 +27084,14 @@
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_msleep(unsigned int jarg1) {
+  unsigned int arg1 ;
+  
+  arg1 = (unsigned int)jarg1; 
+  msleep(arg1);
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_bridge(void * jarg1, void * jarg2) {
   CoreSession *arg1 = 0 ;
   CoreSession *arg2 = 0 ;

Modified: freeswitch/branches/gmaruzz/src/mod/languages/mod_managed/managed/swig.cs
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/languages/mod_managed/managed/swig.cs	(original)
+++ freeswitch/branches/gmaruzz/src/mod/languages/mod_managed/managed/swig.cs	Mon Dec 15 12:56:36 2008
@@ -292,8 +292,8 @@
     return ret;
   }
 
-  public int sleep(int ms) {
-    int ret = freeswitchPINVOKE.CoreSession_sleep(swigCPtr, ms);
+  public int sleep(int ms, int sync) {
+    int ret = freeswitchPINVOKE.CoreSession_sleep(swigCPtr, ms, sync);
     return ret;
   }
 
@@ -984,6 +984,11 @@
     return ret;
   }
 
+  public static switch_status_t switch_core_session_read_lock_hangup(SWIGTYPE_p_switch_core_session session) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_core_session_read_lock_hangup(SWIGTYPE_p_switch_core_session.getCPtr(session));
+    return ret;
+  }
+
   public static void switch_core_session_write_lock(SWIGTYPE_p_switch_core_session session) {
     freeswitchPINVOKE.switch_core_session_write_lock(SWIGTYPE_p_switch_core_session.getCPtr(session));
   }
@@ -1932,6 +1937,71 @@
     return ret;
   }
 
+  public static int switch_toupper(int c) {
+    int ret = freeswitchPINVOKE.switch_toupper(c);
+    return ret;
+  }
+
+  public static int switch_tolower(int c) {
+    int ret = freeswitchPINVOKE.switch_tolower(c);
+    return ret;
+  }
+
+  public static int switch_isalnum(int c) {
+    int ret = freeswitchPINVOKE.switch_isalnum(c);
+    return ret;
+  }
+
+  public static int switch_isalpha(int c) {
+    int ret = freeswitchPINVOKE.switch_isalpha(c);
+    return ret;
+  }
+
+  public static int switch_iscntrl(int c) {
+    int ret = freeswitchPINVOKE.switch_iscntrl(c);
+    return ret;
+  }
+
+  public static int switch_isdigit(int c) {
+    int ret = freeswitchPINVOKE.switch_isdigit(c);
+    return ret;
+  }
+
+  public static int switch_isgraph(int c) {
+    int ret = freeswitchPINVOKE.switch_isgraph(c);
+    return ret;
+  }
+
+  public static int switch_islower(int c) {
+    int ret = freeswitchPINVOKE.switch_islower(c);
+    return ret;
+  }
+
+  public static int switch_isprint(int c) {
+    int ret = freeswitchPINVOKE.switch_isprint(c);
+    return ret;
+  }
+
+  public static int switch_ispunct(int c) {
+    int ret = freeswitchPINVOKE.switch_ispunct(c);
+    return ret;
+  }
+
+  public static int switch_isspace(int c) {
+    int ret = freeswitchPINVOKE.switch_isspace(c);
+    return ret;
+  }
+
+  public static int switch_isupper(int c) {
+    int ret = freeswitchPINVOKE.switch_isupper(c);
+    return ret;
+  }
+
+  public static int switch_isxdigit(int c) {
+    int ret = freeswitchPINVOKE.switch_isxdigit(c);
+    return ret;
+  }
+
   public static switch_bool_t switch_is_moh(string s) {
     switch_bool_t ret = (switch_bool_t)freeswitchPINVOKE.switch_is_moh(s);
     return ret;
@@ -2204,8 +2274,8 @@
     freeswitchPINVOKE.switch_channel_wait_for_state(SWIGTYPE_p_switch_channel.getCPtr(channel), SWIGTYPE_p_switch_channel.getCPtr(other_channel), (int)want_state);
   }
 
-  public static switch_status_t switch_channel_wait_for_flag(SWIGTYPE_p_switch_channel channel, uint want_flag, switch_bool_t pres, uint to, SWIGTYPE_p_switch_channel super_channel) {
-    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_channel_wait_for_flag(SWIGTYPE_p_switch_channel.getCPtr(channel), want_flag, (int)pres, to, SWIGTYPE_p_switch_channel.getCPtr(super_channel));
+  public static switch_status_t switch_channel_wait_for_flag(SWIGTYPE_p_switch_channel channel, switch_channel_flag_t want_flag, switch_bool_t pres, uint to, SWIGTYPE_p_switch_channel super_channel) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_channel_wait_for_flag(SWIGTYPE_p_switch_channel.getCPtr(channel), (int)want_flag, (int)pres, to, SWIGTYPE_p_switch_channel.getCPtr(super_channel));
     return ret;
   }
 
@@ -2255,8 +2325,8 @@
     return ret;
   }
 
-  public static switch_status_t switch_channel_init(SWIGTYPE_p_switch_channel channel, SWIGTYPE_p_switch_core_session session, switch_channel_state_t state, uint flags) {
-    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_channel_init(SWIGTYPE_p_switch_channel.getCPtr(channel), SWIGTYPE_p_switch_core_session.getCPtr(session), (int)state, flags);
+  public static switch_status_t switch_channel_init(SWIGTYPE_p_switch_channel channel, SWIGTYPE_p_switch_core_session session, switch_channel_state_t state, switch_channel_flag_t flag) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_channel_init(SWIGTYPE_p_switch_channel.getCPtr(channel), SWIGTYPE_p_switch_core_session.getCPtr(session), (int)state, (int)flag);
     return ret;
   }
 
@@ -2353,31 +2423,31 @@
     return ret;
   }
 
-  public static uint switch_channel_test_flag(SWIGTYPE_p_switch_channel channel, uint flags) {
-    uint ret = freeswitchPINVOKE.switch_channel_test_flag(SWIGTYPE_p_switch_channel.getCPtr(channel), flags);
+  public static uint switch_channel_test_flag(SWIGTYPE_p_switch_channel channel, switch_channel_flag_t flag) {
+    uint ret = freeswitchPINVOKE.switch_channel_test_flag(SWIGTYPE_p_switch_channel.getCPtr(channel), (int)flag);
     return ret;
   }
 
-  public static void switch_channel_set_flag(SWIGTYPE_p_switch_channel channel, uint flags) {
-    freeswitchPINVOKE.switch_channel_set_flag(SWIGTYPE_p_switch_channel.getCPtr(channel), flags);
+  public static void switch_channel_set_flag(SWIGTYPE_p_switch_channel channel, switch_channel_flag_t flag) {
+    freeswitchPINVOKE.switch_channel_set_flag(SWIGTYPE_p_switch_channel.getCPtr(channel), (int)flag);
   }
 
-  public static switch_bool_t switch_channel_set_flag_partner(SWIGTYPE_p_switch_channel channel, uint flags) {
-    switch_bool_t ret = (switch_bool_t)freeswitchPINVOKE.switch_channel_set_flag_partner(SWIGTYPE_p_switch_channel.getCPtr(channel), flags);
+  public static switch_bool_t switch_channel_set_flag_partner(SWIGTYPE_p_switch_channel channel, switch_channel_flag_t flag) {
+    switch_bool_t ret = (switch_bool_t)freeswitchPINVOKE.switch_channel_set_flag_partner(SWIGTYPE_p_switch_channel.getCPtr(channel), (int)flag);
     return ret;
   }
 
-  public static switch_bool_t switch_channel_clear_flag_partner(SWIGTYPE_p_switch_channel channel, uint flags) {
-    switch_bool_t ret = (switch_bool_t)freeswitchPINVOKE.switch_channel_clear_flag_partner(SWIGTYPE_p_switch_channel.getCPtr(channel), flags);
+  public static switch_bool_t switch_channel_clear_flag_partner(SWIGTYPE_p_switch_channel channel, switch_channel_flag_t flag) {
+    switch_bool_t ret = (switch_bool_t)freeswitchPINVOKE.switch_channel_clear_flag_partner(SWIGTYPE_p_switch_channel.getCPtr(channel), (int)flag);
     return ret;
   }
 
-  public static void switch_channel_set_state_flag(SWIGTYPE_p_switch_channel channel, uint flags) {
-    freeswitchPINVOKE.switch_channel_set_state_flag(SWIGTYPE_p_switch_channel.getCPtr(channel), flags);
+  public static void switch_channel_set_state_flag(SWIGTYPE_p_switch_channel channel, switch_channel_flag_t flag) {
+    freeswitchPINVOKE.switch_channel_set_state_flag(SWIGTYPE_p_switch_channel.getCPtr(channel), (int)flag);
   }
 
-  public static void switch_channel_clear_flag(SWIGTYPE_p_switch_channel channel, uint flags) {
-    freeswitchPINVOKE.switch_channel_clear_flag(SWIGTYPE_p_switch_channel.getCPtr(channel), flags);
+  public static void switch_channel_clear_flag(SWIGTYPE_p_switch_channel channel, switch_channel_flag_t flag) {
+    freeswitchPINVOKE.switch_channel_clear_flag(SWIGTYPE_p_switch_channel.getCPtr(channel), (int)flag);
   }
 
   public static switch_status_t switch_channel_perform_answer(SWIGTYPE_p_switch_channel channel, string file, string func, int line) {
@@ -2510,6 +2580,23 @@
     return ret;
   }
 
+  public static void switch_channel_audio_sync(SWIGTYPE_p_switch_channel channel) {
+    freeswitchPINVOKE.switch_channel_audio_sync(SWIGTYPE_p_switch_channel.getCPtr(channel));
+  }
+
+  public static void switch_channel_set_private_flag(SWIGTYPE_p_switch_channel channel, uint flags) {
+    freeswitchPINVOKE.switch_channel_set_private_flag(SWIGTYPE_p_switch_channel.getCPtr(channel), flags);
+  }
+
+  public static void switch_channel_clear_private_flag(SWIGTYPE_p_switch_channel channel, uint flags) {
+    freeswitchPINVOKE.switch_channel_clear_private_flag(SWIGTYPE_p_switch_channel.getCPtr(channel), flags);
+  }
+
+  public static int switch_channel_test_private_flag(SWIGTYPE_p_switch_channel channel, uint flags) {
+    int ret = freeswitchPINVOKE.switch_channel_test_private_flag(SWIGTYPE_p_switch_channel.getCPtr(channel), flags);
+    return ret;
+  }
+
   public static switch_status_t switch_buffer_create(SWIGTYPE_p_apr_pool_t pool, SWIGTYPE_p_p_switch_buffer buffer, SWIGTYPE_p_switch_size_t max_len) {
     switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_buffer_create(SWIGTYPE_p_apr_pool_t.getCPtr(pool), SWIGTYPE_p_p_switch_buffer.getCPtr(buffer), SWIGTYPE_p_switch_size_t.getCPtr(max_len));
     if (freeswitchPINVOKE.SWIGPendingException.Pending) throw freeswitchPINVOKE.SWIGPendingException.Retrieve();
@@ -2812,8 +2899,8 @@
     return ret;
   }
 
-  public static switch_status_t switch_ivr_sleep(SWIGTYPE_p_switch_core_session session, uint ms, switch_input_args_t args) {
-    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_ivr_sleep(SWIGTYPE_p_switch_core_session.getCPtr(session), ms, switch_input_args_t.getCPtr(args));
+  public static switch_status_t switch_ivr_sleep(SWIGTYPE_p_switch_core_session session, uint ms, switch_bool_t sync, switch_input_args_t args) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_ivr_sleep(SWIGTYPE_p_switch_core_session.getCPtr(session), ms, (int)sync, switch_input_args_t.getCPtr(args));
     return ret;
   }
 
@@ -2917,8 +3004,8 @@
     return ret;
   }
 
-  public static switch_status_t switch_ivr_tone_detect_session(SWIGTYPE_p_switch_core_session session, string key, string tone_spec, string flags, SWIGTYPE_p_time_t timeout, string app, string data) {
-    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_ivr_tone_detect_session(SWIGTYPE_p_switch_core_session.getCPtr(session), key, tone_spec, flags, SWIGTYPE_p_time_t.getCPtr(timeout), app, data);
+  public static switch_status_t switch_ivr_tone_detect_session(SWIGTYPE_p_switch_core_session session, string key, string tone_spec, string flags, SWIGTYPE_p_time_t timeout, int hits, string app, string data) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_ivr_tone_detect_session(SWIGTYPE_p_switch_core_session.getCPtr(session), key, tone_spec, flags, SWIGTYPE_p_time_t.getCPtr(timeout), hits, app, data);
     if (freeswitchPINVOKE.SWIGPendingException.Pending) throw freeswitchPINVOKE.SWIGPendingException.Retrieve();
     return ret;
   }
@@ -2962,8 +3049,8 @@
     return ret;
   }
 
-  public static switch_status_t switch_ivr_originate(SWIGTYPE_p_switch_core_session session, SWIGTYPE_p_p_switch_core_session bleg, SWIGTYPE_p_switch_call_cause_t cause, string bridgeto, uint timelimit_sec, switch_state_handler_table table, string cid_name_override, string cid_num_override, switch_caller_profile caller_profile_override, uint flags) {
-    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_ivr_originate(SWIGTYPE_p_switch_core_session.getCPtr(session), SWIGTYPE_p_p_switch_core_session.getCPtr(bleg), SWIGTYPE_p_switch_call_cause_t.getCPtr(cause), bridgeto, timelimit_sec, switch_state_handler_table.getCPtr(table), cid_name_override, cid_num_override, switch_caller_profile.getCPtr(caller_profile_override), flags);
+  public static switch_status_t switch_ivr_originate(SWIGTYPE_p_switch_core_session session, SWIGTYPE_p_p_switch_core_session bleg, SWIGTYPE_p_switch_call_cause_t cause, string bridgeto, uint timelimit_sec, switch_state_handler_table table, string cid_name_override, string cid_num_override, switch_caller_profile caller_profile_override, switch_event ovars, uint flags) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_ivr_originate(SWIGTYPE_p_switch_core_session.getCPtr(session), SWIGTYPE_p_p_switch_core_session.getCPtr(bleg), SWIGTYPE_p_switch_call_cause_t.getCPtr(cause), bridgeto, timelimit_sec, switch_state_handler_table.getCPtr(table), cid_name_override, cid_num_override, switch_caller_profile.getCPtr(caller_profile_override), switch_event.getCPtr(ovars), flags);
     return ret;
   }
 
@@ -3242,8 +3329,9 @@
     freeswitchPINVOKE.switch_rtp_release_port(ip, port);
   }
 
-  public static void switch_rtp_change_interval(SWIGTYPE_p_switch_rtp rtp_session, uint ms_per_packet, uint samples_per_interval) {
-    freeswitchPINVOKE.switch_rtp_change_interval(SWIGTYPE_p_switch_rtp.getCPtr(rtp_session), ms_per_packet, samples_per_interval);
+  public static switch_status_t switch_rtp_change_interval(SWIGTYPE_p_switch_rtp rtp_session, uint ms_per_packet, uint samples_per_interval) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_rtp_change_interval(SWIGTYPE_p_switch_rtp.getCPtr(rtp_session), ms_per_packet, samples_per_interval);
+    return ret;
   }
 
   public static switch_status_t switch_rtp_create(SWIGTYPE_p_p_switch_rtp new_rtp_session, byte payload, uint samples_per_interval, uint ms_per_packet, uint flags, string timer_name, ref string err, SWIGTYPE_p_apr_pool_t pool) {
@@ -3384,6 +3472,10 @@
     return ret;
   }
 
+  public static void rtp_flush_read_buffer(SWIGTYPE_p_switch_rtp rtp_session) {
+    freeswitchPINVOKE.rtp_flush_read_buffer(SWIGTYPE_p_switch_rtp.getCPtr(rtp_session));
+  }
+
   public static switch_status_t switch_rtp_enable_vad(SWIGTYPE_p_switch_rtp rtp_session, SWIGTYPE_p_switch_core_session session, switch_codec codec, uint flags) {
     switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_rtp_enable_vad(SWIGTYPE_p_switch_rtp.getCPtr(rtp_session), SWIGTYPE_p_switch_core_session.getCPtr(session), switch_codec.getCPtr(codec), flags);
     return ret;
@@ -3850,6 +3942,10 @@
     freeswitchPINVOKE.console_clean_log(msg);
   }
 
+  public static void msleep(uint ms) {
+    freeswitchPINVOKE.msleep(ms);
+  }
+
   public static void bridge(CoreSession session_a, CoreSession session_b) {
     freeswitchPINVOKE.bridge(CoreSession.getCPtr(session_a), CoreSession.getCPtr(session_b));
     if (freeswitchPINVOKE.SWIGPendingException.Pending) throw freeswitchPINVOKE.SWIGPendingException.Retrieve();
@@ -3922,11 +4018,14 @@
   public static readonly int SWITCH_MAX_DTMF_DURATION = freeswitchPINVOKE.SWITCH_MAX_DTMF_DURATION_get();
   public static readonly string SWITCH_PATH_SEPARATOR = freeswitchPINVOKE.SWITCH_PATH_SEPARATOR_get();
   public static readonly string SWITCH_URL_SEPARATOR = freeswitchPINVOKE.SWITCH_URL_SEPARATOR_get();
+  public static readonly string SWITCH_SEND_SILENCE_WHEN_IDLE_VARIABLE = freeswitchPINVOKE.SWITCH_SEND_SILENCE_WHEN_IDLE_VARIABLE_get();
+  public static readonly string SWITCH_CURRENT_APPLICATION_VARIABLE = freeswitchPINVOKE.SWITCH_CURRENT_APPLICATION_VARIABLE_get();
+  public static readonly string SWITCH_CURRENT_APPLICATION_DATA_VARIABLE = freeswitchPINVOKE.SWITCH_CURRENT_APPLICATION_DATA_VARIABLE_get();
+  public static readonly string SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE = freeswitchPINVOKE.SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE_get();
   public static readonly string SWITCH_ENABLE_HEARTBEAT_EVENTS_VARIABLE = freeswitchPINVOKE.SWITCH_ENABLE_HEARTBEAT_EVENTS_VARIABLE_get();
   public static readonly string SWITCH_BYPASS_MEDIA_AFTER_BRIDGE_VARIABLE = freeswitchPINVOKE.SWITCH_BYPASS_MEDIA_AFTER_BRIDGE_VARIABLE_get();
   public static readonly string SWITCH_READ_RESULT_VARIABLE = freeswitchPINVOKE.SWITCH_READ_RESULT_VARIABLE_get();
   public static readonly string SWITCH_COPY_XML_CDR_VARIABLE = freeswitchPINVOKE.SWITCH_COPY_XML_CDR_VARIABLE_get();
-  public static readonly string SWITCH_CURRENT_APPLICATION_VARIABLE = freeswitchPINVOKE.SWITCH_CURRENT_APPLICATION_VARIABLE_get();
   public static readonly string SWITCH_PROTO_SPECIFIC_HANGUP_CAUSE_VARIABLE = freeswitchPINVOKE.SWITCH_PROTO_SPECIFIC_HANGUP_CAUSE_VARIABLE_get();
   public static readonly string SWITCH_CHANNEL_EXECUTE_ON_ANSWER_VARIABLE = freeswitchPINVOKE.SWITCH_CHANNEL_EXECUTE_ON_ANSWER_VARIABLE_get();
   public static readonly string SWITCH_CHANNEL_EXECUTE_ON_RING_VARIABLE = freeswitchPINVOKE.SWITCH_CHANNEL_EXECUTE_ON_RING_VARIABLE_get();
@@ -3934,6 +4033,7 @@
   public static readonly string SWITCH_HOLDING_UUID_VARIABLE = freeswitchPINVOKE.SWITCH_HOLDING_UUID_VARIABLE_get();
   public static readonly string SWITCH_API_BRIDGE_END_VARIABLE = freeswitchPINVOKE.SWITCH_API_BRIDGE_END_VARIABLE_get();
   public static readonly string SWITCH_API_HANGUP_HOOK_VARIABLE = freeswitchPINVOKE.SWITCH_API_HANGUP_HOOK_VARIABLE_get();
+  public static readonly string SWITCH_SESSION_IN_HANGUP_HOOK_VARIABLE = freeswitchPINVOKE.SWITCH_SESSION_IN_HANGUP_HOOK_VARIABLE_get();
   public static readonly string SWITCH_PROCESS_CDR_VARIABLE = freeswitchPINVOKE.SWITCH_PROCESS_CDR_VARIABLE_get();
   public static readonly string SWITCH_BRIDGE_CHANNEL_VARIABLE = freeswitchPINVOKE.SWITCH_BRIDGE_CHANNEL_VARIABLE_get();
   public static readonly string SWITCH_CHANNEL_NAME_VARIABLE = freeswitchPINVOKE.SWITCH_CHANNEL_NAME_VARIABLE_get();
@@ -4389,6 +4489,18 @@
   [DllImport("mod_managed", EntryPoint="CSharp_SWITCH_URL_SEPARATOR_get")]
   public static extern string SWITCH_URL_SEPARATOR_get();
 
+  [DllImport("mod_managed", EntryPoint="CSharp_SWITCH_SEND_SILENCE_WHEN_IDLE_VARIABLE_get")]
+  public static extern string SWITCH_SEND_SILENCE_WHEN_IDLE_VARIABLE_get();
+
+  [DllImport("mod_managed", EntryPoint="CSharp_SWITCH_CURRENT_APPLICATION_VARIABLE_get")]
+  public static extern string SWITCH_CURRENT_APPLICATION_VARIABLE_get();
+
+  [DllImport("mod_managed", EntryPoint="CSharp_SWITCH_CURRENT_APPLICATION_DATA_VARIABLE_get")]
+  public static extern string SWITCH_CURRENT_APPLICATION_DATA_VARIABLE_get();
+
+  [DllImport("mod_managed", EntryPoint="CSharp_SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE_get")]
+  public static extern string SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE_get();
+
   [DllImport("mod_managed", EntryPoint="CSharp_SWITCH_ENABLE_HEARTBEAT_EVENTS_VARIABLE_get")]
   public static extern string SWITCH_ENABLE_HEARTBEAT_EVENTS_VARIABLE_get();
 
@@ -4401,9 +4513,6 @@
   [DllImport("mod_managed", EntryPoint="CSharp_SWITCH_COPY_XML_CDR_VARIABLE_get")]
   public static extern string SWITCH_COPY_XML_CDR_VARIABLE_get();
 
-  [DllImport("mod_managed", EntryPoint="CSharp_SWITCH_CURRENT_APPLICATION_VARIABLE_get")]
-  public static extern string SWITCH_CURRENT_APPLICATION_VARIABLE_get();
-
   [DllImport("mod_managed", EntryPoint="CSharp_SWITCH_PROTO_SPECIFIC_HANGUP_CAUSE_VARIABLE_get")]
   public static extern string SWITCH_PROTO_SPECIFIC_HANGUP_CAUSE_VARIABLE_get();
 
@@ -4425,6 +4534,9 @@
   [DllImport("mod_managed", EntryPoint="CSharp_SWITCH_API_HANGUP_HOOK_VARIABLE_get")]
   public static extern string SWITCH_API_HANGUP_HOOK_VARIABLE_get();
 
+  [DllImport("mod_managed", EntryPoint="CSharp_SWITCH_SESSION_IN_HANGUP_HOOK_VARIABLE_get")]
+  public static extern string SWITCH_SESSION_IN_HANGUP_HOOK_VARIABLE_get();
+
   [DllImport("mod_managed", EntryPoint="CSharp_SWITCH_PROCESS_CDR_VARIABLE_get")]
   public static extern string SWITCH_PROCESS_CDR_VARIABLE_get();
 
@@ -5361,6 +5473,9 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_core_session_read_lock")]
   public static extern int switch_core_session_read_lock(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_core_session_read_lock_hangup")]
+  public static extern int switch_core_session_read_lock_hangup(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_core_session_write_lock")]
   public static extern void switch_core_session_write_lock(HandleRef jarg1);
 
@@ -5937,6 +6052,45 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_console_stream_raw_write")]
   public static extern int switch_console_stream_raw_write(HandleRef jarg1, HandleRef jarg2, HandleRef jarg3);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_toupper")]
+  public static extern int switch_toupper(int jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_tolower")]
+  public static extern int switch_tolower(int jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_isalnum")]
+  public static extern int switch_isalnum(int jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_isalpha")]
+  public static extern int switch_isalpha(int jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_iscntrl")]
+  public static extern int switch_iscntrl(int jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_isdigit")]
+  public static extern int switch_isdigit(int jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_isgraph")]
+  public static extern int switch_isgraph(int jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_islower")]
+  public static extern int switch_islower(int jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_isprint")]
+  public static extern int switch_isprint(int jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_ispunct")]
+  public static extern int switch_ispunct(int jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_isspace")]
+  public static extern int switch_isspace(int jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_isupper")]
+  public static extern int switch_isupper(int jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_isxdigit")]
+  public static extern int switch_isxdigit(int jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_SWITCH_SMAX_get")]
   public static extern int SWITCH_SMAX_get();
 
@@ -6690,6 +6844,12 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_endpoint_interface_refs_get")]
   public static extern int switch_endpoint_interface_refs_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_endpoint_interface_reflock_set")]
+  public static extern void switch_endpoint_interface_reflock_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_endpoint_interface_reflock_get")]
+  public static extern IntPtr switch_endpoint_interface_reflock_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_endpoint_interface_parent_set")]
   public static extern void switch_endpoint_interface_parent_set(HandleRef jarg1, HandleRef jarg2);
 
@@ -6822,6 +6982,12 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_timer_interface_refs_get")]
   public static extern int switch_timer_interface_refs_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_timer_interface_reflock_set")]
+  public static extern void switch_timer_interface_reflock_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_timer_interface_reflock_get")]
+  public static extern IntPtr switch_timer_interface_reflock_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_timer_interface_parent_set")]
   public static extern void switch_timer_interface_parent_set(HandleRef jarg1, HandleRef jarg2);
 
@@ -6864,6 +7030,12 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_dialplan_interface_refs_get")]
   public static extern int switch_dialplan_interface_refs_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_dialplan_interface_reflock_set")]
+  public static extern void switch_dialplan_interface_reflock_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_dialplan_interface_reflock_get")]
+  public static extern IntPtr switch_dialplan_interface_reflock_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_dialplan_interface_parent_set")]
   public static extern void switch_dialplan_interface_parent_set(HandleRef jarg1, HandleRef jarg2);
 
@@ -6948,6 +7120,12 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_file_interface_refs_get")]
   public static extern int switch_file_interface_refs_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_file_interface_reflock_set")]
+  public static extern void switch_file_interface_reflock_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_file_interface_reflock_get")]
+  public static extern IntPtr switch_file_interface_reflock_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_file_interface_parent_set")]
   public static extern void switch_file_interface_parent_set(HandleRef jarg1, HandleRef jarg2);
 
@@ -7236,6 +7414,12 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_asr_interface_refs_get")]
   public static extern int switch_asr_interface_refs_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_asr_interface_reflock_set")]
+  public static extern void switch_asr_interface_reflock_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_asr_interface_reflock_get")]
+  public static extern IntPtr switch_asr_interface_reflock_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_asr_interface_parent_set")]
   public static extern void switch_asr_interface_parent_set(HandleRef jarg1, HandleRef jarg2);
 
@@ -7380,6 +7564,12 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_speech_interface_refs_get")]
   public static extern int switch_speech_interface_refs_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_speech_interface_reflock_set")]
+  public static extern void switch_speech_interface_reflock_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_speech_interface_reflock_get")]
+  public static extern IntPtr switch_speech_interface_reflock_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_speech_interface_parent_set")]
   public static extern void switch_speech_interface_parent_set(HandleRef jarg1, HandleRef jarg2);
 
@@ -7494,6 +7684,12 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_say_interface_refs_get")]
   public static extern int switch_say_interface_refs_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_say_interface_reflock_set")]
+  public static extern void switch_say_interface_reflock_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_say_interface_reflock_get")]
+  public static extern IntPtr switch_say_interface_reflock_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_say_interface_parent_set")]
   public static extern void switch_say_interface_parent_set(HandleRef jarg1, HandleRef jarg2);
 
@@ -7536,6 +7732,12 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_chat_interface_refs_get")]
   public static extern int switch_chat_interface_refs_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_chat_interface_reflock_set")]
+  public static extern void switch_chat_interface_reflock_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_chat_interface_reflock_get")]
+  public static extern IntPtr switch_chat_interface_reflock_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_chat_interface_parent_set")]
   public static extern void switch_chat_interface_parent_set(HandleRef jarg1, HandleRef jarg2);
 
@@ -7578,6 +7780,12 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_management_interface_refs_get")]
   public static extern int switch_management_interface_refs_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_management_interface_reflock_set")]
+  public static extern void switch_management_interface_reflock_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_management_interface_reflock_get")]
+  public static extern IntPtr switch_management_interface_reflock_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_management_interface_parent_set")]
   public static extern void switch_management_interface_parent_set(HandleRef jarg1, HandleRef jarg2);
 
@@ -7644,6 +7852,12 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_directory_interface_refs_get")]
   public static extern int switch_directory_interface_refs_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_directory_interface_reflock_set")]
+  public static extern void switch_directory_interface_reflock_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_directory_interface_reflock_get")]
+  public static extern IntPtr switch_directory_interface_reflock_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_directory_interface_parent_set")]
   public static extern void switch_directory_interface_parent_set(HandleRef jarg1, HandleRef jarg2);
 
@@ -8010,6 +8224,12 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_codec_interface_refs_get")]
   public static extern int switch_codec_interface_refs_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_codec_interface_reflock_set")]
+  public static extern void switch_codec_interface_reflock_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_codec_interface_reflock_get")]
+  public static extern IntPtr switch_codec_interface_reflock_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_codec_interface_parent_set")]
   public static extern void switch_codec_interface_parent_set(HandleRef jarg1, HandleRef jarg2);
 
@@ -8076,6 +8296,12 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_application_interface_refs_get")]
   public static extern int switch_application_interface_refs_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_application_interface_reflock_set")]
+  public static extern void switch_application_interface_reflock_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_application_interface_reflock_get")]
+  public static extern IntPtr switch_application_interface_reflock_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_application_interface_parent_set")]
   public static extern void switch_application_interface_parent_set(HandleRef jarg1, HandleRef jarg2);
 
@@ -8130,6 +8356,12 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_api_interface_refs_get")]
   public static extern int switch_api_interface_refs_get(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_api_interface_reflock_set")]
+  public static extern void switch_api_interface_reflock_set(HandleRef jarg1, HandleRef jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_api_interface_reflock_get")]
+  public static extern IntPtr switch_api_interface_reflock_get(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_api_interface_parent_set")]
   public static extern void switch_api_interface_parent_set(HandleRef jarg1, HandleRef jarg2);
 
@@ -8215,7 +8447,7 @@
   public static extern void switch_channel_wait_for_state(HandleRef jarg1, HandleRef jarg2, int jarg3);
 
   [DllImport("mod_managed", EntryPoint="CSharp_switch_channel_wait_for_flag")]
-  public static extern int switch_channel_wait_for_flag(HandleRef jarg1, uint jarg2, int jarg3, uint jarg4, HandleRef jarg5);
+  public static extern int switch_channel_wait_for_flag(HandleRef jarg1, int jarg2, int jarg3, uint jarg4, HandleRef jarg5);
 
   [DllImport("mod_managed", EntryPoint="CSharp_switch_channel_perform_set_state")]
   public static extern int switch_channel_perform_set_state(HandleRef jarg1, string jarg2, string jarg3, int jarg4, int jarg5);
@@ -8245,7 +8477,7 @@
   public static extern int switch_channel_alloc(HandleRef jarg1, HandleRef jarg2);
 
   [DllImport("mod_managed", EntryPoint="CSharp_switch_channel_init")]
-  public static extern int switch_channel_init(HandleRef jarg1, HandleRef jarg2, int jarg3, uint jarg4);
+  public static extern int switch_channel_init(HandleRef jarg1, HandleRef jarg2, int jarg3, int jarg4);
 
   [DllImport("mod_managed", EntryPoint="CSharp_switch_channel_presence")]
   public static extern void switch_channel_presence(HandleRef jarg1, string jarg2, string jarg3, string jarg4);
@@ -8305,22 +8537,22 @@
   public static extern IntPtr switch_channel_get_caller_extension(HandleRef jarg1);
 
   [DllImport("mod_managed", EntryPoint="CSharp_switch_channel_test_flag")]
-  public static extern uint switch_channel_test_flag(HandleRef jarg1, uint jarg2);
+  public static extern uint switch_channel_test_flag(HandleRef jarg1, int jarg2);
 
   [DllImport("mod_managed", EntryPoint="CSharp_switch_channel_set_flag")]
-  public static extern void switch_channel_set_flag(HandleRef jarg1, uint jarg2);
+  public static extern void switch_channel_set_flag(HandleRef jarg1, int jarg2);
 
   [DllImport("mod_managed", EntryPoint="CSharp_switch_channel_set_flag_partner")]
-  public static extern int switch_channel_set_flag_partner(HandleRef jarg1, uint jarg2);
+  public static extern int switch_channel_set_flag_partner(HandleRef jarg1, int jarg2);
 
   [DllImport("mod_managed", EntryPoint="CSharp_switch_channel_clear_flag_partner")]
-  public static extern int switch_channel_clear_flag_partner(HandleRef jarg1, uint jarg2);
+  public static extern int switch_channel_clear_flag_partner(HandleRef jarg1, int jarg2);
 
   [DllImport("mod_managed", EntryPoint="CSharp_switch_channel_set_state_flag")]
-  public static extern void switch_channel_set_state_flag(HandleRef jarg1, uint jarg2);
+  public static extern void switch_channel_set_state_flag(HandleRef jarg1, int jarg2);
 
   [DllImport("mod_managed", EntryPoint="CSharp_switch_channel_clear_flag")]
-  public static extern void switch_channel_clear_flag(HandleRef jarg1, uint jarg2);
+  public static extern void switch_channel_clear_flag(HandleRef jarg1, int jarg2);
 
   [DllImport("mod_managed", EntryPoint="CSharp_switch_channel_perform_answer")]
   public static extern int switch_channel_perform_answer(HandleRef jarg1, string jarg2, string jarg3, int jarg4);
@@ -8400,6 +8632,18 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_channel_set_timestamps")]
   public static extern int switch_channel_set_timestamps(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_channel_audio_sync")]
+  public static extern void switch_channel_audio_sync(HandleRef jarg1);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_channel_set_private_flag")]
+  public static extern void switch_channel_set_private_flag(HandleRef jarg1, uint jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_channel_clear_private_flag")]
+  public static extern void switch_channel_clear_private_flag(HandleRef jarg1, uint jarg2);
+
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_channel_test_private_flag")]
+  public static extern int switch_channel_test_private_flag(HandleRef jarg1, uint jarg2);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_buffer_create")]
   public static extern int switch_buffer_create(HandleRef jarg1, HandleRef jarg2, HandleRef jarg3);
 
@@ -8860,7 +9104,7 @@
   public static extern int switch_ivr_parse_next_event(HandleRef jarg1);
 
   [DllImport("mod_managed", EntryPoint="CSharp_switch_ivr_sleep")]
-  public static extern int switch_ivr_sleep(HandleRef jarg1, uint jarg2, HandleRef jarg3);
+  public static extern int switch_ivr_sleep(HandleRef jarg1, uint jarg2, int jarg3, HandleRef jarg4);
 
   [DllImport("mod_managed", EntryPoint="CSharp_switch_ivr_park")]
   public static extern int switch_ivr_park(HandleRef jarg1, HandleRef jarg2);
@@ -8923,7 +9167,7 @@
   public static extern int switch_ivr_stop_tone_detect_session(HandleRef jarg1);
 
   [DllImport("mod_managed", EntryPoint="CSharp_switch_ivr_tone_detect_session")]
-  public static extern int switch_ivr_tone_detect_session(HandleRef jarg1, string jarg2, string jarg3, string jarg4, HandleRef jarg5, string jarg6, string jarg7);
+  public static extern int switch_ivr_tone_detect_session(HandleRef jarg1, string jarg2, string jarg3, string jarg4, HandleRef jarg5, int jarg6, string jarg7, string jarg8);
 
   [DllImport("mod_managed", EntryPoint="CSharp_switch_ivr_play_file")]
   public static extern int switch_ivr_play_file(HandleRef jarg1, HandleRef jarg2, string jarg3, HandleRef jarg4);
@@ -8950,7 +9194,7 @@
   public static extern int switch_ivr_speak_text(HandleRef jarg1, string jarg2, string jarg3, string jarg4, HandleRef jarg5);
 
   [DllImport("mod_managed", EntryPoint="CSharp_switch_ivr_originate")]
-  public static extern int switch_ivr_originate(HandleRef jarg1, HandleRef jarg2, HandleRef jarg3, string jarg4, uint jarg5, HandleRef jarg6, string jarg7, string jarg8, HandleRef jarg9, uint jarg10);
+  public static extern int switch_ivr_originate(HandleRef jarg1, HandleRef jarg2, HandleRef jarg3, string jarg4, uint jarg5, HandleRef jarg6, string jarg7, string jarg8, HandleRef jarg9, HandleRef jarg10, uint jarg11);
 
   [DllImport("mod_managed", EntryPoint="CSharp_switch_ivr_multi_threaded_bridge")]
   public static extern int switch_ivr_multi_threaded_bridge(HandleRef jarg1, HandleRef jarg2, HandleRef jarg3, HandleRef jarg4, HandleRef jarg5);
@@ -9169,7 +9413,7 @@
   public static extern void switch_rtp_release_port(string jarg1, ushort jarg2);
 
   [DllImport("mod_managed", EntryPoint="CSharp_switch_rtp_change_interval")]
-  public static extern void switch_rtp_change_interval(HandleRef jarg1, uint jarg2, uint jarg3);
+  public static extern int switch_rtp_change_interval(HandleRef jarg1, uint jarg2, uint jarg3);
 
   [DllImport("mod_managed", EntryPoint="CSharp_switch_rtp_create")]
   public static extern int switch_rtp_create(HandleRef jarg1, byte jarg2, uint jarg3, uint jarg4, uint jarg5, string jarg6, ref string jarg7, HandleRef jarg8);
@@ -9258,6 +9502,9 @@
   [DllImport("mod_managed", EntryPoint="CSharp_switch_rtp_zerocopy_read_frame")]
   public static extern int switch_rtp_zerocopy_read_frame(HandleRef jarg1, HandleRef jarg2, uint jarg3);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_rtp_flush_read_buffer")]
+  public static extern void rtp_flush_read_buffer(HandleRef jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_rtp_enable_vad")]
   public static extern int switch_rtp_enable_vad(HandleRef jarg1, HandleRef jarg2, HandleRef jarg3, uint jarg4);
 
@@ -10360,7 +10607,7 @@
   public static extern int CoreSession_StreamFile(HandleRef jarg1, string jarg2, int jarg3);
 
   [DllImport("mod_managed", EntryPoint="CSharp_CoreSession_sleep")]
-  public static extern int CoreSession_sleep(HandleRef jarg1, int jarg2);
+  public static extern int CoreSession_sleep(HandleRef jarg1, int jarg2, int jarg3);
 
   [DllImport("mod_managed", EntryPoint="CSharp_CoreSession_flushEvents")]
   public static extern int CoreSession_flushEvents(HandleRef jarg1);
@@ -10416,6 +10663,9 @@
   [DllImport("mod_managed", EntryPoint="CSharp_console_clean_log")]
   public static extern void console_clean_log(string jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_msleep")]
+  public static extern void msleep(uint jarg1);
+
   [DllImport("mod_managed", EntryPoint="CSharp_bridge")]
   public static extern void bridge(HandleRef jarg1, HandleRef jarg2);
 
@@ -14949,6 +15199,17 @@
     } 
   }
 
+  public SWIGTYPE_p_switch_mutex_t reflock {
+    set {
+      freeswitchPINVOKE.switch_api_interface_reflock_set(swigCPtr, SWIGTYPE_p_switch_mutex_t.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_api_interface_reflock_get(swigCPtr);
+      SWIGTYPE_p_switch_mutex_t ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_switch_mutex_t(cPtr, false);
+      return ret;
+    } 
+  }
+
   public SWIGTYPE_p_switch_loadable_module_interface parent {
     set {
       freeswitchPINVOKE.switch_api_interface_parent_set(swigCPtr, SWIGTYPE_p_switch_loadable_module_interface.getCPtr(value));
@@ -15116,6 +15377,17 @@
     } 
   }
 
+  public SWIGTYPE_p_switch_mutex_t reflock {
+    set {
+      freeswitchPINVOKE.switch_application_interface_reflock_set(swigCPtr, SWIGTYPE_p_switch_mutex_t.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_application_interface_reflock_get(swigCPtr);
+      SWIGTYPE_p_switch_mutex_t ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_switch_mutex_t(cPtr, false);
+      return ret;
+    } 
+  }
+
   public SWIGTYPE_p_switch_loadable_module_interface parent {
     set {
       freeswitchPINVOKE.switch_application_interface_parent_set(swigCPtr, SWIGTYPE_p_switch_loadable_module_interface.getCPtr(value));
@@ -15553,6 +15825,17 @@
     } 
   }
 
+  public SWIGTYPE_p_switch_mutex_t reflock {
+    set {
+      freeswitchPINVOKE.switch_asr_interface_reflock_set(swigCPtr, SWIGTYPE_p_switch_mutex_t.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_asr_interface_reflock_get(swigCPtr);
+      SWIGTYPE_p_switch_mutex_t ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_switch_mutex_t(cPtr, false);
+      return ret;
+    } 
+  }
+
   public SWIGTYPE_p_switch_loadable_module_interface parent {
     set {
       freeswitchPINVOKE.switch_asr_interface_parent_set(swigCPtr, SWIGTYPE_p_switch_loadable_module_interface.getCPtr(value));
@@ -16653,38 +16936,38 @@
 
 namespace FreeSWITCH.Native {
 
-[System.Flags] public enum switch_channel_flag_enum_t {
-  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_WAIT_FOR_ME = (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_PROXY_MODE = (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_BREAK = (1 << 19),
-  CF_BROADCAST = (1 << 20),
-  CF_UNICAST = (1 << 21),
-  CF_VIDEO = (1 << 22),
-  CF_EVENT_LOCK = (1 << 23),
-  CF_RESET = (1 << 24),
-  CF_ORIGINATING = (1 << 25),
-  CF_STOP_BROADCAST = (1 << 26),
-  CF_PROXY_MEDIA = (1 << 27),
-  CF_INNER_BRIDGE = (1 << 28),
-  CF_REQ_MEDIA = (1 << 29),
-  CF_VERBOSE_EVENTS = (1 << 30)
+public enum switch_channel_flag_t {
+  CF_ANSWERED = 1,
+  CF_OUTBOUND,
+  CF_EARLY_MEDIA,
+  CF_ORIGINATOR,
+  CF_TRANSFER,
+  CF_ACCEPT_CNG,
+  CF_REDIRECT,
+  CF_BRIDGED,
+  CF_HOLD,
+  CF_SERVICE,
+  CF_TAGGED,
+  CF_WINNER,
+  CF_CONTROLLED,
+  CF_PROXY_MODE,
+  CF_SUSPEND,
+  CF_EVENT_PARSE,
+  CF_GEN_RINGBACK,
+  CF_RING_READY,
+  CF_BREAK,
+  CF_BROADCAST,
+  CF_UNICAST,
+  CF_VIDEO,
+  CF_EVENT_LOCK,
+  CF_RESET,
+  CF_ORIGINATING,
+  CF_STOP_BROADCAST,
+  CF_PROXY_MEDIA,
+  CF_INNER_BRIDGE,
+  CF_REQ_MEDIA,
+  CF_VERBOSE_EVENTS,
+  CF_FLAG_MAX
 }
 
 }
@@ -16940,6 +17223,17 @@
     } 
   }
 
+  public SWIGTYPE_p_switch_mutex_t reflock {
+    set {
+      freeswitchPINVOKE.switch_chat_interface_reflock_set(swigCPtr, SWIGTYPE_p_switch_mutex_t.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_chat_interface_reflock_get(swigCPtr);
+      SWIGTYPE_p_switch_mutex_t ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_switch_mutex_t(cPtr, false);
+      return ret;
+    } 
+  }
+
   public SWIGTYPE_p_switch_loadable_module_interface parent {
     set {
       freeswitchPINVOKE.switch_chat_interface_parent_set(swigCPtr, SWIGTYPE_p_switch_loadable_module_interface.getCPtr(value));
@@ -17478,6 +17772,17 @@
     } 
   }
 
+  public SWIGTYPE_p_switch_mutex_t reflock {
+    set {
+      freeswitchPINVOKE.switch_codec_interface_reflock_set(swigCPtr, SWIGTYPE_p_switch_mutex_t.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_codec_interface_reflock_get(swigCPtr);
+      SWIGTYPE_p_switch_mutex_t ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_switch_mutex_t(cPtr, false);
+      return ret;
+    } 
+  }
+
   public SWIGTYPE_p_switch_loadable_module_interface parent {
     set {
       freeswitchPINVOKE.switch_codec_interface_parent_set(swigCPtr, SWIGTYPE_p_switch_loadable_module_interface.getCPtr(value));
@@ -18119,7 +18424,9 @@
 namespace FreeSWITCH.Native {
 
 [System.Flags] public enum switch_core_session_message_flag_enum_t {
-  SCSMF_DYNAMIC = (1 << 0)
+  SCSMF_DYNAMIC = (1 << 0),
+  SCSMF_FREE_STRING_REPLY = (1 << 1),
+  SCSMF_FREE_POINTER_REPLY = (1 << 2)
 }
 
 }
@@ -18154,6 +18461,7 @@
   SWITCH_MESSAGE_INDICATE_VIDEO_REFRESH_REQ,
   SWITCH_MESSAGE_INDICATE_DISPLAY,
   SWITCH_MESSAGE_INDICATE_TRANSCODING_NECESSARY,
+  SWITCH_MESSAGE_INDICATE_AUDIO_SYNC,
   SWITCH_MESSAGE_INVALID
 }
 
@@ -18459,6 +18767,17 @@
     } 
   }
 
+  public SWIGTYPE_p_switch_mutex_t reflock {
+    set {
+      freeswitchPINVOKE.switch_dialplan_interface_reflock_set(swigCPtr, SWIGTYPE_p_switch_mutex_t.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_dialplan_interface_reflock_get(swigCPtr);
+      SWIGTYPE_p_switch_mutex_t ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_switch_mutex_t(cPtr, false);
+      return ret;
+    } 
+  }
+
   public SWIGTYPE_p_switch_loadable_module_interface parent {
     set {
       freeswitchPINVOKE.switch_dialplan_interface_parent_set(swigCPtr, SWIGTYPE_p_switch_loadable_module_interface.getCPtr(value));
@@ -18866,6 +19185,17 @@
     } 
   }
 
+  public SWIGTYPE_p_switch_mutex_t reflock {
+    set {
+      freeswitchPINVOKE.switch_directory_interface_reflock_set(swigCPtr, SWIGTYPE_p_switch_mutex_t.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_directory_interface_reflock_get(swigCPtr);
+      SWIGTYPE_p_switch_mutex_t ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_switch_mutex_t(cPtr, false);
+      return ret;
+    } 
+  }
+
   public SWIGTYPE_p_switch_loadable_module_interface parent {
     set {
       freeswitchPINVOKE.switch_directory_interface_parent_set(swigCPtr, SWIGTYPE_p_switch_loadable_module_interface.getCPtr(value));
@@ -19099,6 +19429,17 @@
     } 
   }
 
+  public SWIGTYPE_p_switch_mutex_t reflock {
+    set {
+      freeswitchPINVOKE.switch_endpoint_interface_reflock_set(swigCPtr, SWIGTYPE_p_switch_mutex_t.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_endpoint_interface_reflock_get(swigCPtr);
+      SWIGTYPE_p_switch_mutex_t ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_switch_mutex_t(cPtr, false);
+      return ret;
+    } 
+  }
+
   public SWIGTYPE_p_switch_loadable_module_interface parent {
     set {
       freeswitchPINVOKE.switch_endpoint_interface_parent_set(swigCPtr, SWIGTYPE_p_switch_loadable_module_interface.getCPtr(value));
@@ -19422,6 +19763,7 @@
   SWITCH_EVENT_DTMF,
   SWITCH_EVENT_MESSAGE,
   SWITCH_EVENT_PRESENCE_IN,
+  SWITCH_EVENT_NOTIFY_IN,
   SWITCH_EVENT_PRESENCE_OUT,
   SWITCH_EVENT_PRESENCE_PROBE,
   SWITCH_EVENT_MESSAGE_WAITING,
@@ -20016,6 +20358,17 @@
     } 
   }
 
+  public SWIGTYPE_p_switch_mutex_t reflock {
+    set {
+      freeswitchPINVOKE.switch_file_interface_reflock_set(swigCPtr, SWIGTYPE_p_switch_mutex_t.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_file_interface_reflock_get(swigCPtr);
+      SWIGTYPE_p_switch_mutex_t ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_switch_mutex_t(cPtr, false);
+      return ret;
+    } 
+  }
+
   public SWIGTYPE_p_switch_loadable_module_interface parent {
     set {
       freeswitchPINVOKE.switch_file_interface_parent_set(swigCPtr, SWIGTYPE_p_switch_loadable_module_interface.getCPtr(value));
@@ -22018,6 +22371,17 @@
     } 
   }
 
+  public SWIGTYPE_p_switch_mutex_t reflock {
+    set {
+      freeswitchPINVOKE.switch_management_interface_reflock_set(swigCPtr, SWIGTYPE_p_switch_mutex_t.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_management_interface_reflock_get(swigCPtr);
+      SWIGTYPE_p_switch_mutex_t ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_switch_mutex_t(cPtr, false);
+      return ret;
+    } 
+  }
+
   public SWIGTYPE_p_switch_loadable_module_interface parent {
     set {
       freeswitchPINVOKE.switch_management_interface_parent_set(swigCPtr, SWIGTYPE_p_switch_loadable_module_interface.getCPtr(value));
@@ -22353,7 +22717,8 @@
   SWITCH_RTP_FLAG_SECURE_SEND_RESET = (1 << 16),
   SWITCH_RTP_FLAG_SECURE_RECV_RESET = (1 << 17),
   SWITCH_RTP_FLAG_PROXY_MEDIA = (1 << 18),
-  SWITCH_RTP_FLAG_SHUTDOWN = (1 << 19)
+  SWITCH_RTP_FLAG_SHUTDOWN = (1 << 19),
+  SWITCH_RTP_FLAG_FLUSH = (1 << 20)
 }
 
 }
@@ -22577,6 +22942,17 @@
     } 
   }
 
+  public SWIGTYPE_p_switch_mutex_t reflock {
+    set {
+      freeswitchPINVOKE.switch_say_interface_reflock_set(swigCPtr, SWIGTYPE_p_switch_mutex_t.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_say_interface_reflock_get(swigCPtr);
+      SWIGTYPE_p_switch_mutex_t ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_switch_mutex_t(cPtr, false);
+      return ret;
+    } 
+  }
+
   public SWIGTYPE_p_switch_loadable_module_interface parent {
     set {
       freeswitchPINVOKE.switch_say_interface_parent_set(swigCPtr, SWIGTYPE_p_switch_loadable_module_interface.getCPtr(value));
@@ -23169,6 +23545,17 @@
     } 
   }
 
+  public SWIGTYPE_p_switch_mutex_t reflock {
+    set {
+      freeswitchPINVOKE.switch_speech_interface_reflock_set(swigCPtr, SWIGTYPE_p_switch_mutex_t.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_speech_interface_reflock_get(swigCPtr);
+      SWIGTYPE_p_switch_mutex_t ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_switch_mutex_t(cPtr, false);
+      return ret;
+    } 
+  }
+
   public SWIGTYPE_p_switch_loadable_module_interface parent {
     set {
       freeswitchPINVOKE.switch_speech_interface_parent_set(swigCPtr, SWIGTYPE_p_switch_loadable_module_interface.getCPtr(value));
@@ -23923,6 +24310,17 @@
     } 
   }
 
+  public SWIGTYPE_p_switch_mutex_t reflock {
+    set {
+      freeswitchPINVOKE.switch_timer_interface_reflock_set(swigCPtr, SWIGTYPE_p_switch_mutex_t.getCPtr(value));
+    } 
+    get {
+      IntPtr cPtr = freeswitchPINVOKE.switch_timer_interface_reflock_get(swigCPtr);
+      SWIGTYPE_p_switch_mutex_t ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_switch_mutex_t(cPtr, false);
+      return ret;
+    } 
+  }
+
   public SWIGTYPE_p_switch_loadable_module_interface parent {
     set {
       freeswitchPINVOKE.switch_timer_interface_parent_set(swigCPtr, SWIGTYPE_p_switch_loadable_module_interface.getCPtr(value));

Modified: freeswitch/branches/gmaruzz/src/mod/languages/mod_perl/freeswitch.pm
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/languages/mod_perl/freeswitch.pm	(original)
+++ freeswitch/branches/gmaruzz/src/mod/languages/mod_perl/freeswitch.pm	Mon Dec 15 12:56:36 2008
@@ -52,6 +52,7 @@
 *consoleCleanLog = *freeswitchc::consoleCleanLog;
 *console_log = *freeswitchc::console_log;
 *console_clean_log = *freeswitchc::console_clean_log;
+*msleep = *freeswitchc::msleep;
 *bridge = *freeswitchc::bridge;
 *hanguphook = *freeswitchc::hanguphook;
 *dtmf_callback = *freeswitchc::dtmf_callback;

Modified: freeswitch/branches/gmaruzz/src/mod/languages/mod_perl/mod_perl_wrap.cpp
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/languages/mod_perl/mod_perl_wrap.cpp	(original)
+++ freeswitch/branches/gmaruzz/src/mod/languages/mod_perl/mod_perl_wrap.cpp	Mon Dec 15 12:56:36 2008
@@ -8146,7 +8146,55 @@
 }
 
 
-XS(_wrap_CoreSession_sleep) {
+XS(_wrap_CoreSession_sleep__SWIG_0) {
+  {
+    CoreSession *arg1 = (CoreSession *) 0 ;
+    int arg2 ;
+    int arg3 ;
+    int result;
+    void *argp1 = 0 ;
+    int res1 = 0 ;
+    int val2 ;
+    int ecode2 = 0 ;
+    int val3 ;
+    int ecode3 = 0 ;
+    int argvi = 0;
+    dXSARGS;
+    
+    if ((items < 3) || (items > 3)) {
+      SWIG_croak("Usage: CoreSession_sleep(self,ms,sync);");
+    }
+    res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_CoreSession, 0 |  0 );
+    if (!SWIG_IsOK(res1)) {
+      SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "CoreSession_sleep" "', argument " "1"" of type '" "CoreSession *""'"); 
+    }
+    arg1 = reinterpret_cast< CoreSession * >(argp1);
+    ecode2 = SWIG_AsVal_int SWIG_PERL_CALL_ARGS_2(ST(1), &val2);
+    if (!SWIG_IsOK(ecode2)) {
+      SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "CoreSession_sleep" "', argument " "2"" of type '" "int""'");
+    } 
+    arg2 = static_cast< int >(val2);
+    ecode3 = SWIG_AsVal_int SWIG_PERL_CALL_ARGS_2(ST(2), &val3);
+    if (!SWIG_IsOK(ecode3)) {
+      SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "CoreSession_sleep" "', argument " "3"" of type '" "int""'");
+    } 
+    arg3 = static_cast< int >(val3);
+    result = (int)(arg1)->sleep(arg2,arg3);
+    ST(argvi) = SWIG_From_int  SWIG_PERL_CALL_ARGS_1(static_cast< int >(result)); argvi++ ;
+    
+    
+    
+    XSRETURN(argvi);
+  fail:
+    
+    
+    
+    SWIG_croak_null();
+  }
+}
+
+
+XS(_wrap_CoreSession_sleep__SWIG_1) {
   {
     CoreSession *arg1 = (CoreSession *) 0 ;
     int arg2 ;
@@ -8184,6 +8232,98 @@
 }
 
 
+XS(_wrap_CoreSession_sleep) {
+  dXSARGS;
+  
+  {
+    unsigned long _index = 0;
+    SWIG_TypeRank _rank = 0; 
+    if (items == 2) {
+      SWIG_TypeRank _ranki = 0;
+      SWIG_TypeRank _rankm = 0;
+      SWIG_TypeRank _pi = 1;
+      int _v = 0;
+      {
+        void *vptr = 0;
+        int res = SWIG_ConvertPtr(ST(0), &vptr, SWIGTYPE_p_CoreSession, 0);
+        _v = SWIG_CheckState(res);
+      }
+      if (!_v) goto check_1;
+      _ranki += _v*_pi;
+      _rankm += _pi;
+      _pi *= SWIG_MAXCASTRANK;
+      {
+        {
+          int res = SWIG_AsVal_int SWIG_PERL_CALL_ARGS_2(ST(1), NULL);
+          _v = SWIG_CheckState(res);
+        }
+      }
+      if (!_v) goto check_1;
+      _ranki += _v*_pi;
+      _rankm += _pi;
+      _pi *= SWIG_MAXCASTRANK;
+      if (!_index || (_ranki < _rank)) {
+        _rank = _ranki; _index = 1;
+        if (_rank == _rankm) goto dispatch;
+      }
+    }
+  check_1:
+    
+    if (items == 3) {
+      SWIG_TypeRank _ranki = 0;
+      SWIG_TypeRank _rankm = 0;
+      SWIG_TypeRank _pi = 1;
+      int _v = 0;
+      {
+        void *vptr = 0;
+        int res = SWIG_ConvertPtr(ST(0), &vptr, SWIGTYPE_p_CoreSession, 0);
+        _v = SWIG_CheckState(res);
+      }
+      if (!_v) goto check_2;
+      _ranki += _v*_pi;
+      _rankm += _pi;
+      _pi *= SWIG_MAXCASTRANK;
+      {
+        {
+          int res = SWIG_AsVal_int SWIG_PERL_CALL_ARGS_2(ST(1), NULL);
+          _v = SWIG_CheckState(res);
+        }
+      }
+      if (!_v) goto check_2;
+      _ranki += _v*_pi;
+      _rankm += _pi;
+      _pi *= SWIG_MAXCASTRANK;
+      {
+        {
+          int res = SWIG_AsVal_int SWIG_PERL_CALL_ARGS_2(ST(2), NULL);
+          _v = SWIG_CheckState(res);
+        }
+      }
+      if (!_v) goto check_2;
+      _ranki += _v*_pi;
+      _rankm += _pi;
+      _pi *= SWIG_MAXCASTRANK;
+      if (!_index || (_ranki < _rank)) {
+        _rank = _ranki; _index = 2;
+        if (_rank == _rankm) goto dispatch;
+      }
+    }
+  check_2:
+    
+  dispatch:
+    switch(_index) {
+    case 1:
+      ++PL_markstack_ptr; SWIG_CALLXS(_wrap_CoreSession_sleep__SWIG_1); return;
+    case 2:
+      ++PL_markstack_ptr; SWIG_CALLXS(_wrap_CoreSession_sleep__SWIG_0); return;
+    }
+  }
+  
+  croak("No matching function for overloaded 'CoreSession_sleep'");
+  XSRETURN(0);
+}
+
+
 XS(_wrap_CoreSession_flushEvents) {
   {
     CoreSession *arg1 = (CoreSession *) 0 ;
@@ -8968,6 +9108,33 @@
 }
 
 
+XS(_wrap_msleep) {
+  {
+    unsigned int arg1 ;
+    unsigned int val1 ;
+    int ecode1 = 0 ;
+    int argvi = 0;
+    dXSARGS;
+    
+    if ((items < 1) || (items > 1)) {
+      SWIG_croak("Usage: msleep(ms);");
+    }
+    ecode1 = SWIG_AsVal_unsigned_SS_int SWIG_PERL_CALL_ARGS_2(ST(0), &val1);
+    if (!SWIG_IsOK(ecode1)) {
+      SWIG_exception_fail(SWIG_ArgError(ecode1), "in method '" "msleep" "', argument " "1"" of type '" "unsigned int""'");
+    } 
+    arg1 = static_cast< unsigned int >(val1);
+    msleep(arg1);
+    
+    
+    XSRETURN(argvi);
+  fail:
+    
+    SWIG_croak_null();
+  }
+}
+
+
 XS(_wrap_bridge) {
   {
     CoreSession *arg1 = 0 ;
@@ -10656,6 +10823,7 @@
 {"freeswitchc::CoreSession_run_dtmf_callback", _wrap_CoreSession_run_dtmf_callback},
 {"freeswitchc::console_log", _wrap_console_log},
 {"freeswitchc::console_clean_log", _wrap_console_clean_log},
+{"freeswitchc::msleep", _wrap_msleep},
 {"freeswitchc::bridge", _wrap_bridge},
 {"freeswitchc::hanguphook", _wrap_hanguphook},
 {"freeswitchc::dtmf_callback", _wrap_dtmf_callback},

Modified: freeswitch/branches/gmaruzz/src/mod/languages/mod_python/freeswitch.py
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/languages/mod_python/freeswitch.py	(original)
+++ freeswitch/branches/gmaruzz/src/mod/languages/mod_python/freeswitch.py	Mon Dec 15 12:56:36 2008
@@ -302,6 +302,7 @@
 
 console_log = _freeswitch.console_log
 console_clean_log = _freeswitch.console_clean_log
+msleep = _freeswitch.msleep
 bridge = _freeswitch.bridge
 hanguphook = _freeswitch.hanguphook
 dtmf_callback = _freeswitch.dtmf_callback

Modified: freeswitch/branches/gmaruzz/src/mod/languages/mod_python/mod_python_wrap.cpp
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/languages/mod_python/mod_python_wrap.cpp	(original)
+++ freeswitch/branches/gmaruzz/src/mod/languages/mod_python/mod_python_wrap.cpp	Mon Dec 15 12:56:36 2008
@@ -8018,7 +8018,47 @@
 }
 
 
-SWIGINTERN PyObject *_wrap_CoreSession_sleep(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
+SWIGINTERN PyObject *_wrap_CoreSession_sleep__SWIG_0(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
+  PyObject *resultobj = 0;
+  CoreSession *arg1 = (CoreSession *) 0 ;
+  int arg2 ;
+  int arg3 ;
+  int result;
+  void *argp1 = 0 ;
+  int res1 = 0 ;
+  int val2 ;
+  int ecode2 = 0 ;
+  int val3 ;
+  int ecode3 = 0 ;
+  PyObject * obj0 = 0 ;
+  PyObject * obj1 = 0 ;
+  PyObject * obj2 = 0 ;
+  
+  if (!PyArg_ParseTuple(args,(char *)"OOO:CoreSession_sleep",&obj0,&obj1,&obj2)) SWIG_fail;
+  res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_CoreSession, 0 |  0 );
+  if (!SWIG_IsOK(res1)) {
+    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "CoreSession_sleep" "', argument " "1"" of type '" "CoreSession *""'"); 
+  }
+  arg1 = reinterpret_cast< CoreSession * >(argp1);
+  ecode2 = SWIG_AsVal_int(obj1, &val2);
+  if (!SWIG_IsOK(ecode2)) {
+    SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "CoreSession_sleep" "', argument " "2"" of type '" "int""'");
+  } 
+  arg2 = static_cast< int >(val2);
+  ecode3 = SWIG_AsVal_int(obj2, &val3);
+  if (!SWIG_IsOK(ecode3)) {
+    SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "CoreSession_sleep" "', argument " "3"" of type '" "int""'");
+  } 
+  arg3 = static_cast< int >(val3);
+  result = (int)(arg1)->sleep(arg2,arg3);
+  resultobj = SWIG_From_int(static_cast< int >(result));
+  return resultobj;
+fail:
+  return NULL;
+}
+
+
+SWIGINTERN PyObject *_wrap_CoreSession_sleep__SWIG_1(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
   PyObject *resultobj = 0;
   CoreSession *arg1 = (CoreSession *) 0 ;
   int arg2 ;
@@ -8049,6 +8089,62 @@
 }
 
 
+SWIGINTERN PyObject *_wrap_CoreSession_sleep(PyObject *self, PyObject *args) {
+  int argc;
+  PyObject *argv[4];
+  int ii;
+  
+  if (!PyTuple_Check(args)) SWIG_fail;
+  argc = (int)PyObject_Length(args);
+  for (ii = 0; (ii < argc) && (ii < 3); ii++) {
+    argv[ii] = PyTuple_GET_ITEM(args,ii);
+  }
+  if (argc == 2) {
+    int _v;
+    void *vptr = 0;
+    int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_CoreSession, 0);
+    _v = SWIG_CheckState(res);
+    if (_v) {
+      {
+        int res = SWIG_AsVal_int(argv[1], NULL);
+        _v = SWIG_CheckState(res);
+      }
+      if (_v) {
+        return _wrap_CoreSession_sleep__SWIG_1(self, args);
+      }
+    }
+  }
+  if (argc == 3) {
+    int _v;
+    void *vptr = 0;
+    int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_CoreSession, 0);
+    _v = SWIG_CheckState(res);
+    if (_v) {
+      {
+        int res = SWIG_AsVal_int(argv[1], NULL);
+        _v = SWIG_CheckState(res);
+      }
+      if (_v) {
+        {
+          int res = SWIG_AsVal_int(argv[2], NULL);
+          _v = SWIG_CheckState(res);
+        }
+        if (_v) {
+          return _wrap_CoreSession_sleep__SWIG_0(self, args);
+        }
+      }
+    }
+  }
+  
+fail:
+  SWIG_SetErrorMsg(PyExc_NotImplementedError,"Wrong number of arguments for overloaded function 'CoreSession_sleep'.\n"
+    "  Possible C/C++ prototypes are:\n"
+    "    sleep(CoreSession *,int,int)\n"
+    "    sleep(CoreSession *,int)\n");
+  return NULL;
+}
+
+
 SWIGINTERN PyObject *_wrap_CoreSession_flushEvents(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
   PyObject *resultobj = 0;
   CoreSession *arg1 = (CoreSession *) 0 ;
@@ -8683,6 +8779,27 @@
 }
 
 
+SWIGINTERN PyObject *_wrap_msleep(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
+  PyObject *resultobj = 0;
+  unsigned int arg1 ;
+  unsigned int val1 ;
+  int ecode1 = 0 ;
+  PyObject * obj0 = 0 ;
+  
+  if (!PyArg_ParseTuple(args,(char *)"O:msleep",&obj0)) SWIG_fail;
+  ecode1 = SWIG_AsVal_unsigned_SS_int(obj0, &val1);
+  if (!SWIG_IsOK(ecode1)) {
+    SWIG_exception_fail(SWIG_ArgError(ecode1), "in method '" "msleep" "', argument " "1"" of type '" "unsigned int""'");
+  } 
+  arg1 = static_cast< unsigned int >(val1);
+  msleep(arg1);
+  resultobj = SWIG_Py_Void();
+  return resultobj;
+fail:
+  return NULL;
+}
+
+
 SWIGINTERN PyObject *_wrap_bridge(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
   PyObject *resultobj = 0;
   CoreSession *arg1 = 0 ;
@@ -9701,6 +9818,7 @@
 	 { (char *)"CoreSession_swigregister", CoreSession_swigregister, METH_VARARGS, NULL},
 	 { (char *)"console_log", _wrap_console_log, METH_VARARGS, NULL},
 	 { (char *)"console_clean_log", _wrap_console_clean_log, METH_VARARGS, NULL},
+	 { (char *)"msleep", _wrap_msleep, METH_VARARGS, NULL},
 	 { (char *)"bridge", _wrap_bridge, METH_VARARGS, NULL},
 	 { (char *)"hanguphook", _wrap_hanguphook, METH_VARARGS, NULL},
 	 { (char *)"dtmf_callback", _wrap_dtmf_callback, METH_VARARGS, NULL},

Modified: freeswitch/branches/gmaruzz/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c	Mon Dec 15 12:56:36 2008
@@ -1723,7 +1723,8 @@
 	switch_input_args_t args = { 0 };
 	int32 ms = 0;
 	jsval ret = JS_TRUE;
-
+	int32 sync = 0;
+	
 	METHOD_SANITY_CHECK();
 	channel = switch_core_session_get_channel(jss->session);
 	CHANNEL_SANITY_CHECK();
@@ -1755,12 +1756,16 @@
 		}
 	}
 
+	if (argc > 2) {
+		JS_ValueToInt32(cx, argv[2], &sync);
+	}
+
 	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_sleep(jss->session, ms, &args);
+	switch_ivr_sleep(jss->session, ms, sync, &args);
 	JS_ResumeRequest(cx, cb_state.saveDepth);
 	check_hangup_hook(jss, &ret);
 	*rval = cb_state.ret;
@@ -1773,7 +1778,6 @@
 	struct js_session *jss = JS_GetPrivate(cx, obj);
 	switch_channel_t *channel;
 
-	METHOD_SANITY_CHECK();
 	channel = switch_core_session_get_channel(jss->session);
 
 	if (argc > 1) {
@@ -2056,8 +2060,6 @@
 	/*Always a pessimist... sheesh! */
 	*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 
-	METHOD_SANITY_CHECK();
-
 	if (switch_ivr_generate_xml_cdr(jss->session, &cdr) == SWITCH_STATUS_SUCCESS) {
 		char *xml_text;
 		if ((xml_text = switch_xml_toxml(cdr, SWITCH_FALSE))) {
@@ -2104,7 +2106,7 @@
 	switch_channel_t *channel;
 	switch_time_t started;
 	unsigned int elapsed;
-	int32 timeout = 60;
+	int32 timeout = 60000;
 	jsrefcount saveDepth;
 	jsval ret = JS_TRUE;
 
@@ -2117,7 +2119,11 @@
 
 	if (argc > 0) {
 		JS_ValueToInt32(cx, argv[0], &timeout);
+		if (timeout < 1000) {
+			timeout = 1000;
+		}
 	}
+
 	if (check_hangup_hook(jss, NULL) != JS_TRUE) {
 		return JS_FALSE;
 	}
@@ -2149,7 +2155,7 @@
 	switch_channel_t *channel;
 	switch_time_t started;
 	unsigned int elapsed;
-	int32 timeout = 60;
+	int32 timeout = 60000;
 	jsrefcount saveDepth;
 	jsval ret = JS_TRUE;
 	
@@ -2160,6 +2166,9 @@
 
 	if (argc > 0) {
 		JS_ValueToInt32(cx, argv[0], &timeout);
+		if (timeout < 1000) {
+			timeout = 1000;
+		}
 	}
 
 	if (check_hangup_hook(jss, NULL) != JS_TRUE) {
@@ -2730,7 +2739,7 @@
 		(*jss)->stack_depth = 0;
 		if ((JS_SetPrivate(cx, session_obj, *jss) &&
 			 JS_DefineProperties(cx, session_obj, session_props) && JS_DefineFunctions(cx, session_obj, session_methods))) {
-			if (switch_core_session_read_lock(session) != SWITCH_STATUS_SUCCESS) {
+			if (switch_core_session_read_lock_hangup(session) != SWITCH_STATUS_SUCCESS) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Read Lock Failure.\n");
 				free(*jss);
 				return NULL;
@@ -2777,7 +2786,7 @@
 				}
 			}
 			if (switch_ivr_originate(old_jss ? old_jss->session : NULL, 
-									 &jss->session, &jss->cause, uuid, 60, NULL, NULL, NULL, NULL, SOF_NONE) == SWITCH_STATUS_SUCCESS) {
+									 &jss->session, &jss->cause, uuid, 60, NULL, NULL, NULL, NULL, NULL, SOF_NONE) == SWITCH_STATUS_SUCCESS) {
 				switch_set_flag(jss, S_HUP);
 				switch_channel_set_state(switch_core_session_get_channel(jss->session), CS_SOFT_EXECUTE);
 				*rval = BOOLEAN_TO_JSVAL(JS_TRUE);
@@ -2917,7 +2926,7 @@
 		caller_profile = switch_caller_profile_new(pool, username, dialplan, cid_name, cid_num, network_addr, ani, aniii, rdnis, modname, context, dest);
 
 		saveDepth = JS_SuspendRequest(cx);
-		status = switch_ivr_originate(session, &peer_session, &jss->cause, dest, to ? atoi(to) : 60, NULL, NULL, NULL, caller_profile, SOF_NONE);
+		status = switch_ivr_originate(session, &peer_session, &jss->cause, dest, to ? atoi(to) : 60, NULL, NULL, NULL, caller_profile, NULL, SOF_NONE);
 		JS_ResumeRequest(cx, saveDepth);
 
 		if (status != SWITCH_STATUS_SUCCESS) {

Modified: freeswitch/branches/gmaruzz/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c	Mon Dec 15 12:56:36 2008
@@ -33,10 +33,13 @@
 #include <sys/stat.h>
 #include <switch.h>
 #include <curl/curl.h>
+#define MAX_URLS 20
 
 static struct {
 	char *cred;
-	char *url;
+	char *urls[MAX_URLS+1];
+	int url_count;
+	int url_index;
 	char *log_dir;
 	char *err_log_dir;
 	uint32_t delay;
@@ -45,7 +48,9 @@
 	uint32_t ignore_cacert_check;
 	int encode;
 	int log_b;
+	int prefix_a;
 	int disable100continue;
+	switch_memory_pool_t *pool;
 } globals;
 
 SWITCH_MODULE_LOAD_FUNCTION(mod_xml_cdr_load);
@@ -77,14 +82,18 @@
 	struct curl_slist *slist = NULL;
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 	switch_status_t status = SWITCH_STATUS_FALSE;
+	int is_b;
+	const char * a_prefix = "";
 
 	if (globals.shutdown) {
 		return SWITCH_STATUS_SUCCESS;
 	}
 
-	if (!globals.log_b && channel && switch_channel_get_originator_caller_profile(channel)) {
+	is_b = channel && switch_channel_get_originator_caller_profile(channel);
+	if (!globals.log_b && is_b) {
 		return SWITCH_STATUS_SUCCESS;
 	}
+	if (!is_b && globals.prefix_a) a_prefix = "a_";
 
 	if (switch_ivr_generate_xml_cdr(session, &cdr) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Generating Data!\n");
@@ -103,7 +112,7 @@
 	}
 
 	if (!switch_strlen_zero(logdir)) {
-		if ((path = switch_mprintf("%s%s%s.cdr.xml", logdir, SWITCH_PATH_SEPARATOR, switch_core_session_get_uuid(session)))) {
+		if ((path = switch_mprintf("%s%s%s%s.cdr.xml", logdir, SWITCH_PATH_SEPARATOR, a_prefix, switch_core_session_get_uuid(session)))) {
 			if ((fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) > -1) {
 				int wrote;
 				wrote = write(fd, xml_text, (unsigned) strlen(xml_text));
@@ -123,7 +132,7 @@
 	}
 
 	/* try to post it to the web server */
-	if (!switch_strlen_zero(globals.url)) {
+	if (globals.url_count) {
 		curl_handle = curl_easy_init();
 
 		if (globals.encode) {
@@ -145,11 +154,6 @@
 			headers = curl_slist_append(headers, "Content-Type: application/x-www-form-plaintext");
 		}
 
-		if (!strncasecmp(globals.url, "https", 5)) {
-			curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0);
-			curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0);
-		}
-
 		if (!(curl_xml_text = switch_mprintf("cdr=%s", xml_text))) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
 			goto error;
@@ -163,7 +167,6 @@
 		curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, headers);
 		curl_easy_setopt(curl_handle, CURLOPT_POST, 1);
 		curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, curl_xml_text);
-		curl_easy_setopt(curl_handle, CURLOPT_URL, globals.url);
 		curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "freeswitch-xml/1.0");
 		curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, httpCallBack);
 
@@ -185,12 +188,27 @@
 			if (cur_try > 0) {
 				switch_yield(globals.delay * 1000000);
 			}
+			
+			curl_easy_setopt(curl_handle, CURLOPT_URL, globals.urls[globals.url_index]);
+
+			if (!strncasecmp(globals.urls[globals.url_index], "https", 5)) {
+				curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0);
+				curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0);
+			}
+
 			curl_easy_perform(curl_handle);
 			curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &httpRes);
 			if (httpRes == 200) {
 				goto success;
 			} else {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Got error [%ld] posting to web server [%s]\n", httpRes, globals.url);
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Got error [%ld] posting to web server [%s]\n", 
+								  httpRes, globals.urls[globals.url_index]);
+				globals.url_index++;
+				switch_assert(globals.url_count <= MAX_URLS);
+				if (globals.url_index >= globals.url_count) {
+					globals.url_index = 0;
+				}
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Retry will be with url [%s]\n", globals.urls[globals.url_index]);
 			}
 		}
 		curl_easy_cleanup(curl_handle);
@@ -203,7 +221,7 @@
 		/* if we are here the web post failed for some reason */
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to post to web server, writing to file\n");
 
-		if ((path = switch_mprintf("%s%s%s.cdr.xml", globals.err_log_dir, SWITCH_PATH_SEPARATOR, switch_core_session_get_uuid(session)))) {
+		if ((path = switch_mprintf("%s%s%s%s.cdr.xml", globals.err_log_dir, SWITCH_PATH_SEPARATOR, a_prefix, switch_core_session_get_uuid(session)))) {
 			if ((fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) > -1) {
 				int wrote;
 				wrote = write(fd, xml_text, (unsigned) strlen(xml_text));
@@ -265,6 +283,7 @@
 	memset(&globals, 0, sizeof(globals));
 	globals.log_b = 1;
 	globals.disable100continue = 0;
+	globals.pool = pool;
 
 	/* parse the config */
 	if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
@@ -278,13 +297,19 @@
 			char *val = (char *) switch_xml_attr_soft(param, "value");
 
 			if (!strcasecmp(var, "cred") && !switch_strlen_zero(val)) {
-				globals.cred = strdup(val);
+				globals.cred = switch_core_strdup(globals.pool, val);
 			} else if (!strcasecmp(var, "url") && !switch_strlen_zero(val)) {
-				globals.url = strdup(val);
+				if (globals.url_count >= MAX_URLS) {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "maximum urls configured!\n");
+				} else {
+					globals.urls[globals.url_count++] = switch_core_strdup(globals.pool, val);
+				}
 			} else if (!strcasecmp(var, "delay") && !switch_strlen_zero(val)) {
 				globals.delay = (uint32_t) atoi(val);
 			} else if (!strcasecmp(var, "log-b-leg")) {
 				globals.log_b = switch_true(val);
+			} else if (!strcasecmp(var, "prefix-a-leg")) {
+				globals.prefix_a = switch_true(val);
 			} else if (!strcasecmp(var, "disable-100-continue") && switch_true(val)) {
 				globals.disable100continue = 1;
 			} else if (!strcasecmp(var, "encode") && !switch_strlen_zero(val)) {
@@ -300,7 +325,7 @@
 					globals.log_dir = switch_mprintf("%s%sxml_cdr", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR);
 				} else {
 					if (switch_is_file_path(val)) {
-						globals.log_dir = strdup(val);
+						globals.log_dir = switch_core_strdup(globals.pool, val);
 					} else {
 						globals.log_dir = switch_mprintf("%s%s%s", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR, val);
 					}
@@ -310,7 +335,7 @@
 					globals.err_log_dir = switch_mprintf("%s%sxml_cdr", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR);
 				} else {
 					if (switch_is_file_path(val)) {
-						globals.err_log_dir = strdup(val);
+						globals.err_log_dir = switch_core_strdup(globals.pool, val);
 					} else {
 						globals.err_log_dir = switch_mprintf("%s%s%s", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR, val);
 					}
@@ -321,9 +346,9 @@
 
 			if (switch_strlen_zero(globals.err_log_dir)) {
 				if (!switch_strlen_zero(globals.log_dir)) {
-					globals.err_log_dir = strdup(globals.log_dir);
+					globals.err_log_dir = switch_core_strdup(globals.pool, globals.log_dir);
 				} else {
-					globals.err_log_dir = switch_mprintf("%s%sxml_cdr", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR);
+					globals.err_log_dir = switch_core_sprintf(globals.pool, "%s%sxml_cdr", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR);
 				}
 			}
 		}

Modified: freeswitch/branches/gmaruzz/src/mod/xml_int/mod_xml_curl/mod_xml_curl.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/xml_int/mod_xml_curl/mod_xml_curl.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/xml_int/mod_xml_curl/mod_xml_curl.c	Mon Dec 15 12:56:36 2008
@@ -37,13 +37,17 @@
 SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_xml_curl_shutdown);
 SWITCH_MODULE_DEFINITION(mod_xml_curl, mod_xml_curl_load, mod_xml_curl_shutdown, NULL);
 
+
 struct xml_binding {
+	char *method;
 	char *url;
 	char *bindings;
 	char *cred;
 	int disable100continue;
+	int use_get_style;
 	uint32_t ignore_cacert_check;
 	switch_hash_t *vars_map;
+	int use_dynamic_url;
 };
 
 static int keep_files_around = 0;
@@ -105,6 +109,9 @@
 	return x;
 }
 
+
+
+
 static switch_xml_t xml_url_fetch(const char *section, const char *tag_name, const char *key_name, const char *key_value, switch_event_t *params,
 								  void *user_data)
 {
@@ -122,7 +129,9 @@
 	struct curl_slist *headers = NULL;
 	char hostname[256] = "";
 	char basic_data[512];
-
+	char *uri = NULL;
+	char *dynamic_url = NULL;
+	
 	gethostname(hostname, sizeof(hostname));
 
 	if (!binding) {
@@ -138,13 +147,31 @@
 
 		return xml;
 	}
-
+	
 	switch_snprintf(basic_data, sizeof(basic_data), "hostname=%s&section=%s&tag_name=%s&key_name=%s&key_value=%s",
 					hostname, section, switch_str_nil(tag_name), switch_str_nil(key_name), switch_str_nil(key_value));
 
 	data = switch_event_build_param_string(params, basic_data, binding->vars_map);
 	switch_assert(data);
 
+	if (binding->use_dynamic_url) {
+		switch_event_add_header_string(params, SWITCH_STACK_TOP, "hostname", hostname);
+		switch_event_add_header_string(params, SWITCH_STACK_TOP, "section", switch_str_nil(section));
+		switch_event_add_header_string(params, SWITCH_STACK_TOP, "tag_name", switch_str_nil(tag_name));
+		switch_event_add_header_string(params, SWITCH_STACK_TOP, "key_name", switch_str_nil(key_name));
+		switch_event_add_header_string(params, SWITCH_STACK_TOP, "key_value", switch_str_nil(key_value));
+		dynamic_url = switch_event_expand_headers(params, binding->url);
+		switch_assert(dynamic_url);
+	} else {
+		dynamic_url = binding->url;
+	}
+
+	if (binding->use_get_style == 1) {
+		uri = malloc(strlen(data) + strlen(dynamic_url) + 16);
+		switch_assert(uri);
+		sprintf(uri, "%s%c%s", dynamic_url, strchr(dynamic_url, '?') != NULL ? '&' : '?', data);
+	} 
+
 	switch_uuid_get(&uuid);
 	switch_uuid_format(uuid_str, &uuid);
 
@@ -164,11 +191,14 @@
 			curl_easy_setopt(curl_handle, CURLOPT_USERPWD, binding->cred);
 		}
 		curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, headers);
-		curl_easy_setopt(curl_handle, CURLOPT_POST, 1);
+		if (binding->method != NULL)
+			curl_easy_setopt(curl_handle, CURLOPT_CUSTOMREQUEST, binding->method);
+		curl_easy_setopt(curl_handle, CURLOPT_POST, !binding->use_get_style);
 		curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1);
 		curl_easy_setopt(curl_handle, CURLOPT_MAXREDIRS, 10);
-		curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, data);
-		curl_easy_setopt(curl_handle, CURLOPT_URL, binding->url);
+		if (!binding->use_get_style)
+			curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, data);
+		curl_easy_setopt(curl_handle, CURLOPT_URL, binding->use_get_style ? uri : dynamic_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_USERAGENT, "freeswitch-xml/1.0");
@@ -211,7 +241,10 @@
 	}
 
 	switch_safe_free(data);
-
+	if (binding->use_get_style == 1)
+		switch_safe_free(uri);
+	if (binding->use_dynamic_url && dynamic_url != binding->url)
+		switch_safe_free(dynamic_url);
 	return xml;
 }
 
@@ -240,7 +273,9 @@
 		char *url = NULL;
 		char *bind_cred = NULL;
 		char *bind_mask = NULL;
+		char *method = NULL;
 		int disable100continue = 0;
+		int use_dynamic_url = 0;
 		uint32_t ignore_cacert_check = 0;
 		hash_node_t* hash_node;
 		need_vars_map = 0;
@@ -258,8 +293,12 @@
 				bind_cred = val;
 			} else if (!strcasecmp(var, "disable-100-continue") && switch_true(val)) {
 				disable100continue = 1;
+			} else if (!strcasecmp(var, "method")) {
+				method = val;
 			} else if (!strcasecmp(var, "ignore-cacert-check") && switch_true(val)) {
 				ignore_cacert_check = 1;
+			} else if (!strcasecmp(var, "use-dynamic-url") && switch_true(val)) {
+				use_dynamic_url = 1;
 			} else if (!strcasecmp(var, "enable-post-var")) {
 				if (!vars_map && need_vars_map == 0) {
 					if (switch_core_hash_init(&vars_map, globals.pool) != SWITCH_STATUS_SUCCESS) {
@@ -292,7 +331,13 @@
 		memset(binding, 0, sizeof(*binding));
 
 		binding->url = strdup(url);
+		switch_assert(binding->url);
 
+		if (method != NULL) {
+			binding->method = strdup(method);
+		} else {
+			binding->method = NULL;
+		}
 		if (bind_mask) {
 			binding->bindings = strdup(bind_mask);
 		}
@@ -302,6 +347,8 @@
 		}
 
 		binding->disable100continue = disable100continue;
+		binding->use_get_style = method != NULL && strcasecmp(method,"post") != 0;
+		binding->use_dynamic_url = use_dynamic_url;
 		binding->ignore_cacert_check = ignore_cacert_check;
 
 		binding->vars_map = vars_map;

Modified: freeswitch/branches/gmaruzz/src/mod/xml_int/mod_xml_ldap/Makefile
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/xml_int/mod_xml_ldap/Makefile	(original)
+++ freeswitch/branches/gmaruzz/src/mod/xml_int/mod_xml_ldap/Makefile	Mon Dec 15 12:56:36 2008
@@ -17,7 +17,7 @@
 include $(switch_srcdir)/build/modmake.rules
 
 $(LDAP_DIR):
-	$(GETLIB) $(LDAP).tgz
+	$(GETLIB) $(LDAP).tar.gz
 	cd $(LDAP_DIR) && CFLAGS="`echo $(CFLAGS) | sed -e 's:-std=c99::'`" ./configure $(DEFAULT_ARGS)
 
 $(LIBLUTILA) $(LDAPLA) $(LIBLBERLA): $(LDAP_DIR)

Modified: freeswitch/branches/gmaruzz/src/switch.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch.c	Mon Dec 15 12:56:36 2008
@@ -253,7 +253,8 @@
 {
 	char pid_path[256] = "";	/* full path to the pid file */
 	char pid_buffer[32] = "";	/* pid string */
-	switch_size_t pid_len;
+	char old_pid_buffer[32] = "";	/* pid string */
+	switch_size_t pid_len, old_pid_len;
 	const char *err = NULL;		/* error value for return from freeswitch initialization */
 #ifndef WIN32
 	int nf = 0;					/* TRUE if we are running in nofork mode */
@@ -603,17 +604,34 @@
 	pid_len = strlen(pid_buffer);
 
 	apr_pool_create(&pool, NULL);
+	
+
 	if (switch_file_open(&fd,
-		pid_path,
-		SWITCH_FOPEN_WRITE | SWITCH_FOPEN_CREATE | SWITCH_FOPEN_TRUNCATE,
-		SWITCH_FPROT_UREAD | SWITCH_FPROT_UWRITE,
-		pool) != SWITCH_STATUS_SUCCESS) {
-			fprintf(stderr, "Cannot open pid file %s.\n", pid_path);
-			return 255;
+						 pid_path,
+						 SWITCH_FOPEN_READ,
+						 SWITCH_FPROT_UREAD | SWITCH_FPROT_UWRITE,
+						 pool) == SWITCH_STATUS_SUCCESS) {
+
+		old_pid_len = sizeof(old_pid_buffer);
+		switch_file_read(fd, old_pid_buffer, &old_pid_len);
+		switch_file_close(fd);
+	}
+
+	if (switch_file_open(&fd,
+						 pid_path,
+						 SWITCH_FOPEN_WRITE | SWITCH_FOPEN_CREATE | SWITCH_FOPEN_TRUNCATE,
+						 SWITCH_FPROT_UREAD | SWITCH_FPROT_UWRITE,
+						 pool) != SWITCH_STATUS_SUCCESS) {
+		fprintf(stderr, "Cannot open pid file %s.\n", pid_path);
+		return 255;
 	}
 
 	if (switch_file_lock(fd, SWITCH_FLOCK_EXCLUSIVE | SWITCH_FLOCK_NONBLOCK) != SWITCH_STATUS_SUCCESS) {
 		fprintf(stderr, "Cannot lock pid file %s.\n", pid_path);
+		old_pid_len = strlen(old_pid_buffer);
+		if (strlen(old_pid_buffer)) {
+			switch_file_write(fd, old_pid_buffer, &old_pid_len);
+		}
 		return 255;
 	}
 

Modified: freeswitch/branches/gmaruzz/src/switch_apr.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_apr.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_apr.c	Mon Dec 15 12:56:36 2008
@@ -754,6 +754,11 @@
 	return sa->family;
 }
 
+SWITCH_DECLARE(switch_status_t) switch_socket_atmark(switch_socket_t *sock, int *atmark)
+{
+	return apr_socket_atmark(sock, atmark);
+}
+
 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;
@@ -799,7 +804,7 @@
 		return SWITCH_STATUS_MEMERR;
 	}
 
-	if (switch_pollset_create(&pollset, 1, pool, flags) != SWITCH_STATUS_SUCCESS) {
+	if (switch_pollset_create(&pollset, 1, pool, 0) != SWITCH_STATUS_SUCCESS) {
 		return SWITCH_STATUS_GENERR;
 	}
 

Modified: freeswitch/branches/gmaruzz/src/switch_channel.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_channel.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_channel.c	Mon Dec 15 12:56:36 2008
@@ -115,8 +115,9 @@
 	switch_core_session_t *session;
 	switch_channel_state_t state;
 	switch_channel_state_t running_state;
-	switch_channel_flag_t flags;
-	switch_channel_flag_t state_flags;
+	uint8_t flags[CF_FLAG_MAX];
+	uint8_t state_flags[CF_FLAG_MAX];
+	uint32_t private_flags;
 	switch_caller_profile_t *caller_profile;
 	const switch_state_handler_table_t *state_handlers[SWITCH_MAX_STATE_HANDLERS];
 	int state_handler_index;
@@ -166,6 +167,19 @@
 	return channel->hangup_cause;
 }
 
+
+SWITCH_DECLARE(void) switch_channel_audio_sync(switch_channel_t *channel) 
+{
+	if (switch_channel_media_ready(channel)) {
+		switch_core_session_message_t msg;
+		msg.message_id = SWITCH_MESSAGE_INDICATE_AUDIO_SYNC;
+		msg.from = channel->name;
+		switch_core_session_receive_message(channel->session, &msg);
+	}
+}
+
+
+
 SWITCH_DECLARE(switch_call_cause_t) switch_channel_cause_q850(switch_call_cause_t cause)
 {
 	if (cause <= SWITCH_CAUSE_INTERWORKING) {
@@ -396,11 +410,11 @@
 }
 
 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_channel_flag_t flag)
 {
 	switch_assert(channel != NULL);
 	channel->state = state;
-	channel->flags = flags;
+	switch_channel_set_flag(channel, flag);
 	channel->session = session;
 	channel->running_state = CS_NONE;
 	return SWITCH_STATUS_SUCCESS;
@@ -629,13 +643,13 @@
 	return SWITCH_STATUS_FALSE;
 }
 
-SWITCH_DECLARE(uint32_t) switch_channel_test_flag(switch_channel_t *channel, switch_channel_flag_t flags)
+SWITCH_DECLARE(uint32_t) switch_channel_test_flag(switch_channel_t *channel, switch_channel_flag_t flag)
 {
 	switch_assert(channel != NULL);
-	return switch_test_flag(channel, flags) ? 1 : 0;
+	return channel->flags[flag] ? 1 : 0;
 }
 
-SWITCH_DECLARE(switch_bool_t) switch_channel_set_flag_partner(switch_channel_t *channel, switch_channel_flag_t flags)
+SWITCH_DECLARE(switch_bool_t) switch_channel_set_flag_partner(switch_channel_t *channel, switch_channel_flag_t flag)
 {
 	const char *uuid;
 
@@ -644,7 +658,7 @@
 	if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))) {
 		switch_core_session_t *session;
 		if ((session = switch_core_session_locate(uuid))) {
-			switch_channel_set_flag(switch_core_session_get_channel(session), flags);
+			switch_channel_set_flag(switch_core_session_get_channel(session), flag);
 			switch_core_session_rwunlock(session);
 			return SWITCH_TRUE;
 		}
@@ -653,7 +667,7 @@
 	return SWITCH_FALSE;
 }
 
-SWITCH_DECLARE(switch_bool_t) switch_channel_clear_flag_partner(switch_channel_t *channel, switch_channel_flag_t flags)
+SWITCH_DECLARE(switch_bool_t) switch_channel_clear_flag_partner(switch_channel_t *channel, switch_channel_flag_t flag)
 {
 	const char *uuid;
 
@@ -662,7 +676,7 @@
 	if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))) {
 		switch_core_session_t *session;
 		if ((session = switch_core_session_locate(uuid))) {
-			switch_channel_clear_flag(switch_core_session_get_channel(session), flags);
+			switch_channel_clear_flag(switch_core_session_get_channel(session), flag);
 			switch_core_session_rwunlock(session);
 			return SWITCH_TRUE;
 		}
@@ -700,11 +714,11 @@
 
 	for (;;) {
 		if (pres) {
-			if (switch_test_flag(channel, want_flag)) {
+			if (switch_channel_test_flag(channel, want_flag)) {
 				break;
 			}
 		} else {
-			if (!switch_test_flag(channel, want_flag)) {
+			if (!switch_channel_test_flag(channel, want_flag)) {
 				break;
 			}
 		}
@@ -727,29 +741,62 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-SWITCH_DECLARE(void) switch_channel_set_flag(switch_channel_t *channel, switch_channel_flag_t flags)
+SWITCH_DECLARE(void) switch_channel_set_flag(switch_channel_t *channel, switch_channel_flag_t flag)
 {
-	switch_assert(channel != NULL);
-	switch_set_flag_locked(channel, flags);
-	if (flags & CF_OUTBOUND) {
+	switch_assert(channel);
+	switch_assert(channel->flag_mutex);
+
+	switch_mutex_lock(channel->flag_mutex);
+	channel->flags[flag] = 1;
+	switch_mutex_unlock(channel->flag_mutex);
+
+	if (flag == CF_OUTBOUND) {
 		switch_channel_set_variable(channel, "is_outbound", "true");
 	}
 }
 
-SWITCH_DECLARE(void) switch_channel_set_state_flag(switch_channel_t *channel, switch_channel_flag_t flags)
+
+SWITCH_DECLARE(void) switch_channel_set_private_flag(switch_channel_t *channel, uint32_t flags)
+{
+	switch_assert(channel != NULL);
+	switch_mutex_lock(channel->flag_mutex);
+	channel->private_flags |= flags;
+	switch_mutex_unlock(channel->flag_mutex);
+}
+
+SWITCH_DECLARE(void) switch_channel_clear_private_flag(switch_channel_t *channel, uint32_t flags)
+{
+	switch_assert(channel != NULL);
+	switch_mutex_lock(channel->flag_mutex);
+	channel->private_flags &= ~flags;
+	switch_mutex_unlock(channel->flag_mutex);
+}
+
+SWITCH_DECLARE(int) switch_channel_test_private_flag(switch_channel_t *channel, uint32_t flags)
+{
+	switch_assert(channel != NULL);
+	return (channel->private_flags & flags);
+}
+
+SWITCH_DECLARE(void) switch_channel_set_state_flag(switch_channel_t *channel, switch_channel_flag_t flag)
 {
 	switch_assert(channel != NULL);
 
 	switch_mutex_lock(channel->flag_mutex);
-	channel->state_flags |= flags;
+	channel->state_flags[0] = 1;
+	channel->state_flags[flag] = 1;
 	switch_mutex_unlock(channel->flag_mutex);
 }
 
-SWITCH_DECLARE(void) switch_channel_clear_flag(switch_channel_t *channel, switch_channel_flag_t flags)
+SWITCH_DECLARE(void) switch_channel_clear_flag(switch_channel_t *channel, switch_channel_flag_t flag)
 {
 	switch_assert(channel != NULL);
-	switch_clear_flag_locked(channel, flags);
-	if (flags & CF_OUTBOUND) {
+	switch_assert(channel->flag_mutex);
+
+	switch_mutex_lock(channel->flag_mutex);
+	channel->flags[flag] = 0;
+	switch_mutex_unlock(channel->flag_mutex);
+	if (flag == CF_OUTBOUND) {
 		switch_channel_set_variable(channel, "is_outbound", NULL);
 	}
 }
@@ -785,7 +832,7 @@
 	switch_assert(channel != NULL);
 
 	if (!channel->hangup_cause && channel->state > CS_ROUTING && channel->state < CS_HANGUP && channel->state != CS_RESET &&
-		!switch_test_flag(channel, CF_TRANSFER)) {
+		!switch_channel_test_flag(channel, CF_TRANSFER)) {
 		ret++;
 	}
 
@@ -829,19 +876,24 @@
 SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_set_running_state(switch_channel_t *channel, switch_channel_state_t state,
 																				const char *file, const char *func, int line)
 {
+	int x;
 	switch_mutex_lock(channel->flag_mutex);
 	switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_DEBUG, "(%s) Running State Change %s\n", channel->name, state_names[state]);
 	channel->running_state = state;
 
-	if (channel->state_flags) {
-		channel->flags |= channel->state_flags;
-		channel->state_flags = 0;
+	if (channel->state_flags[0]) {
+		for(x = 1; x < CF_FLAG_MAX ; x++ ) {
+			if (channel->state_flags[x]) {
+				channel->flags[x] = 1;
+				channel->state_flags[x] = 0;
+			}
+		}
+		channel->state_flags[0] = 0;
 	}
 
-	switch_clear_flag(channel, CF_TAGGED);
+	switch_channel_clear_flag(channel, CF_TAGGED);
 
 	if (channel->state >= CS_ROUTING) {
-		switch_clear_flag(channel, CF_TRANSFER);
 		switch_channel_presence(channel, "unknown", (char *) state_names[state], NULL);
 	}
 
@@ -1148,7 +1200,7 @@
 	}
 
 
-	if (switch_test_flag(channel, CF_VERBOSE_EVENTS) || 
+	if (switch_channel_test_flag(channel, CF_VERBOSE_EVENTS) || 
 		event->event_id == SWITCH_EVENT_CHANNEL_ORIGINATE ||
 		event->event_id == SWITCH_EVENT_CHANNEL_UUID ||
 		event->event_id == SWITCH_EVENT_CHANNEL_ANSWER ||
@@ -1157,6 +1209,7 @@
 		event->event_id == SWITCH_EVENT_CHANNEL_HANGUP ||
 		event->event_id == SWITCH_EVENT_REQUEST_PARAMS ||
 		event->event_id == SWITCH_EVENT_CHANNEL_DATA ||
+		event->event_id == SWITCH_EVENT_CHANNEL_EXECUTE_COMPLETE ||
 		event->event_id == SWITCH_EVENT_SESSION_HEARTBEAT ||
 		event->event_id == SWITCH_EVENT_CUSTOM
 		) {
@@ -1689,6 +1742,9 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s execute on answer: %s(%s)", channel->name, app, switch_str_nil(arg));
 		switch_core_session_execute_application(channel->session, app, arg);
 	}
+
+	switch_channel_audio_sync(channel);
+
 	return SWITCH_STATUS_SUCCESS;
 }
 
@@ -2267,7 +2323,7 @@
 	switch_snprintf(tmp, sizeof(tmp), "%d", progressmsec);
 	switch_channel_set_variable(channel, "progressmsec", tmp);
 
-	switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, progressusec);
+	switch_snprintf(tmp, sizeof(tmp), "%d" , progressmsec);
 	switch_channel_set_variable(channel, "progress_mediamsec", tmp);
 
 	switch_snprintf(tmp, sizeof(tmp), "%d", legbillmsec);

Modified: freeswitch/branches/gmaruzz/src/switch_core.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_core.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_core.c	Mon Dec 15 12:56:36 2008
@@ -781,7 +781,7 @@
 	setrlimit(RLIMIT_CPU, &rlp);
 	setrlimit(RLIMIT_DATA, &rlp);
 	setrlimit(RLIMIT_FSIZE, &rlp);
-#ifndef __OpenBSD__
+#if !defined(__OpenBSD__) && !defined(__NetBSD__)
 	setrlimit(RLIMIT_AS, &rlp);
 #endif
 #endif
@@ -973,7 +973,7 @@
 	runtime.dummy_cng_frame.data = runtime.dummy_data;
 	runtime.dummy_cng_frame.datalen = sizeof(runtime.dummy_data);
 	runtime.dummy_cng_frame.buflen = sizeof(runtime.dummy_data);
-	runtime.dummy_cng_frame.flags = SFF_CNG;
+	switch_set_flag((&runtime.dummy_cng_frame), SFF_CNG);
 
 	switch_set_flag((&runtime), SCF_NO_NEW_SESSIONS);
 	runtime.hard_log_level = SWITCH_LOG_DEBUG;

Modified: freeswitch/branches/gmaruzz/src/switch_core_codec.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_core_codec.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_core_codec.c	Mon Dec 15 12:56:36 2008
@@ -44,16 +44,30 @@
 
 SWITCH_DECLARE(void) switch_core_session_unset_read_codec(switch_core_session_t *session)
 {
+	switch_mutex_t *mutex = NULL;
+
+	switch_mutex_lock(session->codec_read_mutex);
+	if (session->read_codec) mutex = session->read_codec->mutex;
+	if (mutex) switch_mutex_lock(mutex);
 	session->real_read_codec = session->read_codec = NULL;
 	session->raw_read_frame.codec = session->read_codec;
 	session->raw_write_frame.codec = session->read_codec;
 	session->enc_read_frame.codec = session->read_codec;
 	session->enc_write_frame.codec = session->read_codec;
+	if (mutex) switch_mutex_unlock(mutex);
+	switch_mutex_unlock(session->codec_read_mutex);
 }
 
 SWITCH_DECLARE(void) switch_core_session_unset_write_codec(switch_core_session_t *session)
 {	
+	switch_mutex_t *mutex = NULL;
+
+	switch_mutex_lock(session->codec_write_mutex);
+	if (session->write_codec) mutex = session->write_codec->mutex;
+	if (mutex) switch_mutex_lock(mutex);
 	session->real_write_codec = session->write_codec = NULL;
+	if (mutex) switch_mutex_unlock(mutex);
+	switch_mutex_unlock(session->codec_write_mutex);
 }
 
 
@@ -64,6 +78,8 @@
 	char tmp[30];
 	switch_status_t status = SWITCH_STATUS_SUCCESS;
 
+	switch_mutex_lock(session->codec_read_mutex);
+
 	if (codec && !codec->implementation) {
 		codec = NULL;
 	}
@@ -118,6 +134,7 @@
 
  end:
 
+	switch_mutex_unlock(session->codec_read_mutex);
 	return status;
 
 }
@@ -182,6 +199,8 @@
 	char tmp[30];
 	switch_status_t status = SWITCH_STATUS_SUCCESS;
 
+	switch_mutex_lock(session->codec_write_mutex);
+
 	if (!codec || !codec->implementation) {
 		if (session->real_write_codec) {
 			session->write_codec = session->real_write_codec;
@@ -231,6 +250,7 @@
 	}
 
  end:
+	switch_mutex_unlock(session->codec_write_mutex);
 
 	return status;
 }

Modified: freeswitch/branches/gmaruzz/src/switch_core_io.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_core_io.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_core_io.c	Mon Dec 15 12:56:36 2008
@@ -103,17 +103,29 @@
 															   int stream_id)
 {
 	switch_io_event_hook_read_frame_t *ptr;
-	switch_status_t status;
+	switch_status_t status = SWITCH_STATUS_FALSE;
 	int need_codec, perfect, do_bugs = 0, do_resample = 0, is_cng = 0;
 	unsigned int flag = 0;
 
 	switch_assert(session != NULL);
 
+	if (!(session->read_codec && session->read_codec->implementation)) {
+		if (switch_channel_test_flag(session->channel, CF_PROXY_MODE) || switch_channel_get_state(session->channel) == CS_HIBERNATE) {
+			*frame = &runtime.dummy_cng_frame;
+			return SWITCH_STATUS_SUCCESS;
+		}
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s has no read codec.\n", switch_channel_get_name(session->channel));
+		return SWITCH_STATUS_FALSE;
+	}
+
+	switch_mutex_lock(session->codec_read_mutex);
+	switch_mutex_lock(session->read_codec->mutex);
+
   top:
 
 	if (switch_channel_get_state(session->channel) >= CS_HANGUP) {
 		*frame = NULL;
-		return SWITCH_STATUS_FALSE;
+		status = SWITCH_STATUS_FALSE; goto even_more_done;
 	}
 
 
@@ -138,11 +150,14 @@
 
 
 	if (switch_channel_test_flag(session->channel, CF_HOLD)) {
+		switch_yield(session->read_codec->implementation->microseconds_per_packet);
 		status = SWITCH_STATUS_BREAK;
 		goto even_more_done;
 	}
 
 	if (session->endpoint_interface->io_routines->read_frame) {
+		switch_mutex_unlock(session->read_codec->mutex);
+		switch_mutex_unlock(session->codec_read_mutex);
 		if ((status = session->endpoint_interface->io_routines->read_frame(session, frame, flags, stream_id)) == SWITCH_STATUS_SUCCESS) {
 			for (ptr = session->event_hooks.read_frame; ptr; ptr = ptr->next) {
 				if ((status = ptr->read_frame(session, frame, flags, stream_id)) != SWITCH_STATUS_SUCCESS) {
@@ -150,6 +165,14 @@
 				}
 			}
 		}
+		
+		if (!SWITCH_READ_ACCEPTABLE(status) || !session->read_codec || !session->read_codec->mutex) {
+			*frame = NULL;
+			return SWITCH_STATUS_FALSE;
+		}
+		
+		switch_mutex_lock(session->codec_read_mutex);
+		switch_mutex_lock(session->read_codec->mutex);
 	}
 
 	if (status != SWITCH_STATUS_SUCCESS) {
@@ -178,10 +201,6 @@
 
 	switch_assert((*frame)->codec != NULL);
 
-	if (!(session->read_codec && session->read_codec->implementation)) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s has no read codec.\n", switch_channel_get_name(session->channel));
-		return SWITCH_STATUS_FALSE;
-	}
 
 	if (((*frame)->codec && session->read_codec->implementation != (*frame)->codec->implementation)) {
 		need_codec = TRUE;
@@ -318,15 +337,12 @@
 					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->stop_time && bp->stop_time <= switch_timestamp(NULL))) {
-							ok = SWITCH_FALSE;
-						}
+						ok = bp->callback(bp, bp->user_data, SWITCH_ABC_TYPE_READ);
 					}
 					switch_mutex_unlock(bp->read_mutex);
 				}
-
-				if (switch_test_flag(bp, SMBF_READ_REPLACE)) {
+				
+				if (ok && switch_test_flag(bp, SMBF_READ_REPLACE)) {
 					do_bugs = 0;
 					if (bp->callback) {
 						bp->read_replace_frame_in = read_frame;
@@ -336,6 +352,10 @@
 						}
 					}
 				}
+				
+				if (bp->stop_time && bp->stop_time <= switch_timestamp(NULL)) {
+					ok = SWITCH_FALSE;
+				}
 
 				if (ok == SWITCH_FALSE) {
 					bp->ready = 0;
@@ -516,6 +536,9 @@
 		*frame = &runtime.dummy_cng_frame;
 	}
 
+	switch_mutex_unlock(session->read_codec->mutex);
+	switch_mutex_unlock(session->codec_read_mutex);
+
 	return status;
 }
 
@@ -577,21 +600,32 @@
 	switch_assert(frame->codec != NULL);
 	switch_assert(frame->codec->implementation != NULL);
 
+	switch_mutex_lock(session->codec_write_mutex);	
+
+	if (!(session->write_codec && session->write_codec->mutex && frame->codec)) {
+		switch_mutex_unlock(session->codec_write_mutex);	
+		return SWITCH_STATUS_FALSE;
+	}
+
+	switch_mutex_lock(session->write_codec->mutex);
+	switch_mutex_lock(frame->codec->mutex);
+
+
 	if ((session->write_codec && frame->codec && session->write_codec->implementation != frame->codec->implementation)) {
-		need_codec = TRUE;
 		if (session->write_codec->implementation->codec_id == frame->codec->implementation->codec_id) {
 			ptime_mismatch = TRUE;
+			if (switch_test_flag(frame->codec, SWITCH_CODEC_FLAG_PASSTHROUGH) || switch_test_flag(session->read_codec, SWITCH_CODEC_FLAG_PASSTHROUGH)) {
+				status = perform_write(session, frame, flags, stream_id);
+				goto error;
+			}
 		}
+		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 = TRUE;
 		need_codec = TRUE;
@@ -654,7 +688,7 @@
 				write_frame = &session->raw_write_frame;
 				break;
 			case SWITCH_STATUS_BREAK:
-				return SWITCH_STATUS_SUCCESS;
+				status = SWITCH_STATUS_SUCCESS; goto error;
 			case SWITCH_STATUS_NOOP:
 				if (session->write_resampler) {
 					switch_mutex_lock(session->resample_mutex);
@@ -668,15 +702,15 @@
 			default:
 				if (status == SWITCH_STATUS_NOT_INITALIZED) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec init error!\n");
-					return status;
+					goto error;
 				}
 				if (ptime_mismatch) {
 					status = perform_write(session, frame, flags, stream_id);
-					return SWITCH_STATUS_SUCCESS;
+					status = SWITCH_STATUS_SUCCESS; goto error;
 				}
 				
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec %s decoder error!\n", frame->codec->codec_interface->interface_name);
-				return status;
+				goto error;
 			}
 		}
 
@@ -774,13 +808,13 @@
 															   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;
+						goto error;
 					}
 				}
 
 				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;
+					status = SWITCH_STATUS_MEMERR; goto error;
 				}
 			}
 
@@ -826,18 +860,18 @@
 				case SWITCH_STATUS_NOT_INITALIZED:
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec init error!\n");
 					write_frame = NULL;
-                    return status;					
+                    goto error;					
 				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;
+					goto error;
 				}
 				if (flag & SFF_CNG) {
 					switch_set_flag(write_frame, SFF_CNG);
 				}
 				status = perform_write(session, write_frame, flags, stream_id);
-				return status;
+				goto error;
 			} else {
 				switch_size_t used = switch_buffer_inuse(session->raw_write_buffer);
 				uint32_t bytes = session->write_codec->implementation->decoded_bytes_per_packet;
@@ -845,7 +879,7 @@
 
 				status = SWITCH_STATUS_SUCCESS;
 				if (!frames) {
-					return status;
+					goto error;
 				} else {
 					switch_size_t x;
 					for (x = 0; x < frames; x++) {
@@ -917,12 +951,12 @@
 							case SWITCH_STATUS_NOT_INITALIZED:
 								switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec init error!\n");
 								write_frame = NULL;
-								return status;
+								goto error;
 							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;
+								goto error;
 							}
 
 							if (session->read_resampler) {
@@ -951,7 +985,7 @@
 							}
 						}
 					}
-					return status;
+					goto error;
 				}
 			}
 		}
@@ -959,11 +993,18 @@
 		do_write = TRUE;
 	}
 
-  done:
+ done:
 
 	if (do_write) {
-		return perform_write(session, frame, flags, stream_id);
+		status = perform_write(session, frame, flags, stream_id);
 	}
+	
+ error:
+
+	switch_mutex_unlock(session->write_codec->mutex);
+	switch_mutex_unlock(frame->codec->mutex);
+	switch_mutex_unlock(session->codec_write_mutex);
+
 	return status;
 }
 

Modified: freeswitch/branches/gmaruzz/src/switch_core_rwlock.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_core_rwlock.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_core_rwlock.c	Mon Dec 15 12:56:36 2008
@@ -63,6 +63,34 @@
 	return status;
 }
 
+
+#ifdef SWITCH_DEBUG_RWLOCKS
+SWITCH_DECLARE(switch_status_t) switch_core_session_perform_read_lock_hangup(switch_core_session_t *session, const char *file, const char *func, int line)
+#else
+SWITCH_DECLARE(switch_status_t) switch_core_session_read_lock_hangup(switch_core_session_t *session)
+#endif
+{
+	switch_status_t status = SWITCH_STATUS_FALSE;
+
+	if (session->rwlock) {
+		if (switch_test_flag(session, SSF_DESTROYED) || switch_channel_get_state(session->channel) >= CS_DONE) {
+			status = SWITCH_STATUS_FALSE;
+#ifdef SWITCH_DEBUG_RWLOCKS
+			switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, 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, NULL, SWITCH_LOG_ERROR, "%s Read lock ACQUIRED\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)
 {

Modified: freeswitch/branches/gmaruzz/src/switch_core_session.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_core_session.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_core_session.c	Mon Dec 15 12:56:36 2008
@@ -242,7 +242,7 @@
 {
 	switch_io_event_hook_outgoing_channel_t *ptr;
 	switch_status_t status = SWITCH_STATUS_FALSE;
-	const switch_endpoint_interface_t *endpoint_interface;
+	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;
@@ -301,6 +301,7 @@
 
 	if ((cause =
 		 endpoint_interface->io_routines->outgoing_channel(session, var_event, outgoing_profile, new_session, pool, flags)) != SWITCH_CAUSE_SUCCESS) {
+		UNPROTECT_INTERFACE(endpoint_interface);
 		return cause;
 	}
 
@@ -315,6 +316,7 @@
 	if (!*new_session) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Outgoing method for endpoint: [%s] returned: [%s] but there is no new session!\n",
 						  endpoint_name, switch_channel_cause2str(cause));
+		UNPROTECT_INTERFACE(endpoint_interface);
 		return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
 	} else {
 		switch_caller_profile_t *profile = NULL, *peer_profile = NULL, *cloned_profile = NULL;
@@ -344,7 +346,7 @@
 
 			profile = switch_channel_get_caller_profile(channel);
 
-			if (read_codec) {
+			if (read_codec && read_codec->implementation) {
 				char tmp[80];
 				switch_codec2str(read_codec, tmp, sizeof(tmp));
 				switch_channel_set_variable(peer_channel, SWITCH_ORIGINATOR_CODEC_VARIABLE, tmp);
@@ -414,6 +416,7 @@
 		}
 	}
 
+	UNPROTECT_INTERFACE(endpoint_interface);
 	return cause;
 }
 
@@ -438,6 +441,7 @@
 	"SWITCH_MESSAGE_INDICATE_VIDEO_REFRESH_REQ",
 	"SWITCH_MESSAGE_INDICATE_DISPLAY",
 	"SWITCH_MESSAGE_INDICATE_TRANSCODING_NECESSARY",
+	"SWITCH_MESSAGE_INDICATE_AUDIO_SYNC",
 	"SWITCH_MESSAGE_INVALID"
 };
 
@@ -486,7 +490,29 @@
 	message->_line = 0;
 	
 
-	switch_core_session_kill_channel(session, SWITCH_SIG_BREAK);
+	switch (message->message_id) {
+    case SWITCH_MESSAGE_REDIRECT_AUDIO:
+    case SWITCH_MESSAGE_INDICATE_ANSWER:
+    case SWITCH_MESSAGE_INDICATE_PROGRESS:
+    case SWITCH_MESSAGE_INDICATE_BRIDGE:
+    case SWITCH_MESSAGE_INDICATE_UNBRIDGE:
+    case SWITCH_MESSAGE_INDICATE_TRANSFER:
+    case SWITCH_MESSAGE_INDICATE_RINGING:
+    case SWITCH_MESSAGE_INDICATE_MEDIA:
+    case SWITCH_MESSAGE_INDICATE_NOMEDIA:
+    case SWITCH_MESSAGE_INDICATE_HOLD:
+    case SWITCH_MESSAGE_INDICATE_UNHOLD:
+    case SWITCH_MESSAGE_INDICATE_REDIRECT:
+    case SWITCH_MESSAGE_INDICATE_RESPOND:
+    case SWITCH_MESSAGE_INDICATE_BROADCAST:
+    case SWITCH_MESSAGE_INDICATE_MEDIA_REDIRECT:
+    case SWITCH_MESSAGE_INDICATE_DEFLECT:
+		switch_core_session_kill_channel(session, SWITCH_SIG_BREAK);
+		break;
+	default:
+		break;
+	}
+
 	switch_core_session_rwunlock(session);
 
 	return status;
@@ -722,6 +748,7 @@
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 	switch_size_t has;
 
+
 	switch_core_session_set_read_codec(session, NULL);
 
 	/* clear resamplers */
@@ -869,7 +896,7 @@
 {
 	switch_assert(session != NULL);
 
-	if (seconds < 10) {
+	if (!seconds) {
 		seconds = 60;
 	}
 
@@ -1077,6 +1104,8 @@
 
 	switch_mutex_init(&session->mutex, SWITCH_MUTEX_NESTED, session->pool);
 	switch_mutex_init(&session->resample_mutex, SWITCH_MUTEX_NESTED, session->pool);
+	switch_mutex_init(&session->codec_read_mutex, SWITCH_MUTEX_NESTED, session->pool);
+	switch_mutex_init(&session->codec_write_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);
@@ -1111,14 +1140,18 @@
 SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request_by_name(const char *endpoint_name, switch_memory_pool_t **pool)
 {
 	switch_endpoint_interface_t *endpoint_interface;
+	switch_core_session_t *session;
 
 	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);
+	session = switch_core_session_request(endpoint_interface, pool);
+
+	UNPROTECT_INTERFACE(endpoint_interface);
 
+	return session;
 }
 
 #ifndef SWITCH_PREFIX_DIR
@@ -1273,9 +1306,10 @@
 		}
 	}
 	
-	switch_channel_set_variable(channel, "current_application", application_interface->interface_name);
-	switch_channel_set_variable(channel, "current_application_data", arg);
-
+	switch_channel_set_variable(channel, SWITCH_CURRENT_APPLICATION_VARIABLE, application_interface->interface_name);
+	switch_channel_set_variable(channel, SWITCH_CURRENT_APPLICATION_DATA_VARIABLE, arg);
+	switch_channel_set_variable(channel, SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE, NULL);
+	
 	if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_EXECUTE) == SWITCH_STATUS_SUCCESS) {
 		switch_channel_event_set_data(session->channel, event);
 		switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Application", application_interface->interface_name);
@@ -1292,9 +1326,11 @@
 	application_interface->application_function(session, arg);
 	
 	if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_EXECUTE_COMPLETE) == SWITCH_STATUS_SUCCESS) {
+		const char *resp = switch_channel_get_variable(session->channel, SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE);
 		switch_channel_event_set_data(session->channel, event);
 		switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Application", application_interface->interface_name);
 		switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Application-Data", arg);
+		switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Application-Response", resp ? resp : "_none_");
 		switch_event_fire(&event);
 	}
 

Modified: freeswitch/branches/gmaruzz/src/switch_core_state_machine.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_core_state_machine.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_core_state_machine.c	Mon Dec 15 12:56:36 2008
@@ -165,7 +165,7 @@
 	}
 
 	if (switch_channel_get_state(session->channel) == CS_EXECUTE) {
-		switch_channel_hangup(session->channel, SWITCH_CAUSE_NORMAL_CLEARING);
+		switch_channel_hangup(session->channel, SWITCH_CAUSE_NORMAL_CLEARING);		
 	}
 }
 
@@ -185,7 +185,6 @@
 {
 	switch_assert(session != NULL);
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s Standard PARK\n", switch_channel_get_name(session->channel));
-	switch_channel_clear_flag(session->channel, CF_TRANSFER);
 	switch_core_session_reset(session, SWITCH_TRUE);
 	switch_ivr_park(session, NULL);
 }
@@ -361,18 +360,15 @@
 	switch_mutex_lock(session->mutex);
 
 	while ((state = switch_channel_get_state(session->channel)) != CS_DONE) {
-		uint8_t exception = 0;
 		midstate = state;
-		if (switch_channel_test_flag(session->channel, CF_REPEAT_STATE)) {
-			switch_channel_clear_flag(session->channel, CF_REPEAT_STATE);
-			exception = 1;
-		}
-		if (state != switch_channel_get_running_state(session->channel) || state == CS_HANGUP || exception) {
+		if (state != switch_channel_get_running_state(session->channel) || state == CS_HANGUP) {
 			int index = 0;
 			int proceed = 1;
 			int do_extra_handlers = 1;
 
 			switch_channel_set_running_state(session->channel, state);
+			switch_channel_clear_flag(session->channel, CF_TRANSFER);
+			switch_channel_clear_flag(session->channel, CF_REDIRECT);
 
 			switch (state) {
 			case CS_NEW:		/* Just created, Waiting for first instructions */
@@ -385,7 +381,8 @@
 				{
 					const char *var = switch_channel_get_variable(session->channel, SWITCH_PROCESS_CDR_VARIABLE);
 					const char *hook_var;
-
+					switch_core_session_t *use_session = NULL;
+					
 					if (!switch_strlen_zero(var)) {
 						if (!strcasecmp(var, "a_only")) {
 							if (switch_channel_get_originator_caller_profile(session->channel)) {
@@ -401,20 +398,32 @@
 					}
 					
 					STATE_MACRO(hangup, "HANGUP");
-
+					
 					hook_var = switch_channel_get_variable(session->channel, SWITCH_API_HANGUP_HOOK_VARIABLE);
+					if (switch_true(switch_channel_get_variable(session->channel, SWITCH_SESSION_IN_HANGUP_HOOK_VARIABLE))) {
+						use_session = session;
+					}
 
 					if (!switch_strlen_zero(hook_var)) {
 						switch_stream_handle_t stream = { 0 };
 						char *cmd = switch_core_session_strdup(session, hook_var);
 						char *arg = NULL;
+						char *expanded = NULL;
+						
 						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, "Hangup Command %s(%s):\n%s\n", cmd, arg,
+						switch_channel_get_variables(session->channel, &stream.param_event);
+						expanded = switch_channel_expand_variables(session->channel, arg);
+						
+
+						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Hangup Command %s(%s):\n%s\n", cmd, expanded,
 										  switch_str_nil((char *) stream.data));
+						switch_api_execute(cmd, expanded, use_session, &stream);
+						if (expanded != arg) {
+							switch_safe_free(expanded);
+						}
 						switch_safe_free(stream.data);
 					}
 				}

Modified: freeswitch/branches/gmaruzz/src/switch_cpp.cpp
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_cpp.cpp	(original)
+++ freeswitch/branches/gmaruzz/src/switch_cpp.cpp	Mon Dec 15 12:56:36 2008
@@ -467,7 +467,8 @@
 		allocated = 1;
     } else {
 		switch_call_cause_t cause;
-		if (switch_ivr_originate(a_leg ? a_leg->session : NULL, &session, &cause, nuuid, 60, NULL, NULL, NULL, NULL, SOF_NONE) == SWITCH_STATUS_SUCCESS) {
+		if (switch_ivr_originate(a_leg ? a_leg->session : NULL, &session, &cause, nuuid, 60, NULL, NULL, NULL, NULL, NULL, SOF_NONE) 
+			== SWITCH_STATUS_SUCCESS) {
 			channel = switch_core_session_get_channel(session);
 			allocated = 1;
 			switch_set_flag(this, S_HUP);
@@ -832,7 +833,7 @@
 
 }
 
-SWITCH_DECLARE(int) CoreSession::sleep(int ms) {
+SWITCH_DECLARE(int) CoreSession::sleep(int ms, int sync) {
 
     switch_status_t status;
 
@@ -840,7 +841,7 @@
     sanity_check(-1);
 	
     begin_allow_threads();
-    status = switch_ivr_sleep(session, ms, ap);
+    status = switch_ivr_sleep(session, ms, (switch_bool_t) sync, ap);
     end_allow_threads();
 
     return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
@@ -919,6 +920,7 @@
 							 NULL, 
 							 NULL, 
 							 &caller_profile,
+							 NULL,
 							 SOF_NONE) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Error Creating Outgoing Channel! [%s]\n", dest);
 		goto failed;
@@ -1090,6 +1092,12 @@
 }
 
 
+SWITCH_DECLARE(void) msleep(unsigned ms)
+{
+	switch_sleep(ms * 1000);
+	return;
+}
+
 SWITCH_DECLARE(void) bridge(CoreSession &session_a, CoreSession &session_b)
 {
     switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "bridge called, session_a uuid: %s\n", session_a.get_uuid());

Modified: freeswitch/branches/gmaruzz/src/switch_event.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_event.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_event.c	Mon Dec 15 12:56:36 2008
@@ -142,6 +142,7 @@
 	"DTMF",
 	"MESSAGE",
 	"PRESENCE_IN",
+	"NOTIFY_IN",
 	"PRESENCE_OUT",
 	"PRESENCE_PROBE",
 	"MESSAGE_WAITING",

Modified: freeswitch/branches/gmaruzz/src/switch_ivr.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_ivr.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_ivr.c	Mon Dec 15 12:56:36 2008
@@ -38,7 +38,7 @@
 #include <switch_ivr.h>
 #include "stfu.h"
 
-SWITCH_DECLARE(switch_status_t) switch_ivr_sleep(switch_core_session_t *session, uint32_t ms, switch_input_args_t *args)
+SWITCH_DECLARE(switch_status_t) switch_ivr_sleep(switch_core_session_t *session, uint32_t ms, switch_bool_t sync, switch_input_args_t *args)
 {
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 	switch_status_t status = SWITCH_STATUS_SUCCESS;
@@ -47,10 +47,60 @@
 	int32_t left, elapsed;
 	char data[2] = "";
 
+	switch_frame_t write_frame = { 0 };
+	unsigned char *abuf = NULL;
+	switch_codec_implementation_t imp = {0};
+	switch_codec_t codec = { 0 };
+	int sval = 0;
+	const char *var;
+	
+	if ((var = switch_channel_get_variable(channel, SWITCH_SEND_SILENCE_WHEN_IDLE_VARIABLE)) && (sval = atoi(var))) {
+		switch_core_session_get_read_impl(session, &imp);
+	
+		if (switch_core_codec_init(&codec,
+								   "L16",
+								   NULL,
+								   imp.samples_per_second,
+								   imp.microseconds_per_packet / 1000,
+								   imp.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_ERROR, "Codec Error L16@%uhz %u channels %dms\n", 
+							  imp.samples_per_second, imp.number_of_channels, imp.microseconds_per_packet / 1000);
+			return SWITCH_STATUS_FALSE;
+		}
+
+
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Codec Activated L16@%uhz %u channels %dms\n", 
+						  imp.samples_per_second, imp.number_of_channels, imp.microseconds_per_packet / 1000);
+		
+		write_frame.codec = &codec;
+		switch_zmalloc(abuf, SWITCH_RECOMMENDED_BUFFER_SIZE);
+		write_frame.data = abuf;
+		write_frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE;
+		write_frame.datalen = imp.decoded_bytes_per_packet;
+		write_frame.samples = write_frame.datalen / sizeof(int16_t);
+
+		if (!switch_channel_media_ready(channel)) {
+			if ((status = switch_channel_pre_answer(channel)) != SWITCH_STATUS_SUCCESS) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot establish media.\n");
+				return SWITCH_STATUS_FALSE;
+			}
+		}
+	}
+
 	cng_frame.data = data;
 	cng_frame.datalen = 2;
 	cng_frame.buflen = 2;
-	cng_frame.flags = SFF_CNG;
+	switch_set_flag((&cng_frame), SFF_CNG);
+
+	if (sync && !switch_channel_test_flag(channel, CF_PROXY_MODE)) {
+		switch_channel_audio_sync(channel);
+	}
+	
+	if (!ms) {
+		return SWITCH_STATUS_SUCCESS;
+	}
 
 	for (;;) {
 		now = switch_timestamp_now();
@@ -126,10 +176,20 @@
 			}
 		}
 
-		switch_core_session_write_frame(session, &cng_frame, SWITCH_IO_FLAG_NONE, 0);
+		if (sval) {
+			switch_generate_sln_silence((int16_t *) write_frame.data, write_frame.samples, sval);
+			switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0);
+		} else {
+			switch_core_session_write_frame(session, &cng_frame, SWITCH_IO_FLAG_NONE, 0);
+		}
+	}
 
+	if (write_frame.codec) {
+		switch_core_codec_destroy(&codec);
 	}
 
+	switch_safe_free(abuf);
+
 	return status;
 }
 
@@ -741,9 +801,44 @@
 	switch_time_t started = 0, digit_started = 0;
 	uint32_t abs_elapsed = 0, digit_elapsed = 0;
 	uint32_t eff_timeout = 0;
+	switch_frame_t write_frame = { 0 };
+	unsigned char *abuf = NULL;
+	switch_codec_implementation_t imp = {0};
+	switch_codec_t codec = { 0 };
+	int sval = 0;
+	const char *var;
 
-	if (terminator != NULL)
+	if ((var = switch_channel_get_variable(channel, SWITCH_SEND_SILENCE_WHEN_IDLE_VARIABLE)) && (sval = atoi(var))) {
+		switch_core_session_get_read_impl(session, &imp);
+	
+		if (switch_core_codec_init(&codec,
+								   "L16",
+								   NULL,
+								   imp.samples_per_second,
+								   imp.microseconds_per_packet / 1000,
+								   imp.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_ERROR, "Codec Error L16@%uhz %u channels %dms\n", 
+							  imp.samples_per_second, imp.number_of_channels, imp.microseconds_per_packet / 1000);
+			return SWITCH_STATUS_FALSE;
+		}
+
+
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Codec Activated L16@%uhz %u channels %dms\n", 
+						  imp.samples_per_second, imp.number_of_channels, imp.microseconds_per_packet / 1000);
+		
+		write_frame.codec = &codec;
+		switch_zmalloc(abuf, SWITCH_RECOMMENDED_BUFFER_SIZE);
+		write_frame.data = abuf;
+		write_frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE;
+		write_frame.datalen = imp.decoded_bytes_per_packet;
+		write_frame.samples = write_frame.datalen / sizeof(int16_t);
+	}
+
+	if (terminator != NULL) {
 		*terminator = '\0';
+	}
 
 	if (!switch_strlen_zero(terminators)) {
 		for (i = 0; i < x; i++) {
@@ -830,9 +925,21 @@
 			if (!SWITCH_READ_ACCEPTABLE(status)) {
 				break;
 			}
+
+			if (write_frame.data) {
+				switch_generate_sln_silence((int16_t *) write_frame.data, write_frame.samples, sval);
+				switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0);
+			}
+			
 		}
 	}
 
+	if (write_frame.codec) {
+		switch_core_codec_destroy(&codec);
+	}
+
+	switch_safe_free(abuf);
+
 	return status;
 }
 
@@ -1057,7 +1164,8 @@
 	switch_channel_clear_state_handler(channel, NULL);
 
 	if ((profile = switch_channel_get_caller_profile(channel))) {
-
+		const char *var;
+		
 		if (switch_strlen_zero(dialplan)) {
 			dialplan = profile->dialplan;
 		}
@@ -1078,6 +1186,14 @@
 			extension = "service";
 		}
 
+		if ((var = switch_channel_get_variable(channel, "force_transfer_dialplan"))) {
+			dialplan = var;
+		}
+
+		if ((var = switch_channel_get_variable(channel, "force_transfer_context"))) {
+			context = var;
+		}
+		
 		new_profile = switch_caller_profile_clone(session, profile);
 
 		new_profile->dialplan = switch_core_strdup(new_profile->pool, dialplan);

Modified: freeswitch/branches/gmaruzz/src/switch_ivr_async.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_ivr_async.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_ivr_async.c	Mon Dec 15 12:56:36 2008
@@ -1192,6 +1192,10 @@
 	char *key;
 	teletone_tone_map_t map;
 	int up;
+	int total_hits;
+	int hits;
+	int sleep;
+	int expires;
 } switch_tone_detect_t;
 
 typedef struct {
@@ -1213,43 +1217,76 @@
 	case SWITCH_ABC_TYPE_CLOSE:
 		break;
 	case SWITCH_ABC_TYPE_READ_REPLACE:
-		frame = switch_core_media_bug_get_read_replace_frame(bug);
 	case SWITCH_ABC_TYPE_WRITE_REPLACE:
 		{
+			int skip = 0;
 
-			if (!frame) {
+			if (type == SWITCH_ABC_TYPE_READ_REPLACE) {
+				frame = switch_core_media_bug_get_read_replace_frame(bug);
+			} else {
 				frame = switch_core_media_bug_get_write_replace_frame(bug);
 			}
 
-			for (i = 0; i < cont->index; i++) {
-				if (cont->list[i].up && teletone_multi_tone_detect(&cont->list[i].mt, frame->data, frame->samples)) {
-					switch_event_t *event;
 
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "TONE %s DETECTED\n", cont->list[i].key);
-					cont->list[i].up = 0;
 
-					if (cont->list[i].app) {
-						if (switch_event_create(&event, SWITCH_EVENT_COMMAND) == SWITCH_STATUS_SUCCESS) {
-							switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "call-command", "execute");
-							switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "execute-app-name", cont->list[i].app);
-							switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "execute-app-arg", cont->list[i].data);
-							switch_event_add_header(event, SWITCH_STACK_BOTTOM, "lead-frames", "%d", 5);
-							switch_core_session_queue_private_event(cont->session, &event);
-						}
+			for (i = 0; i < cont->index; i++) {
+
+				if (cont->list[i].sleep) {
+					cont->list[i].sleep--;
+					if (cont->list[i].sleep) {
+						skip = 1;
 					}
+				}
 
-					if (switch_event_create(&event, SWITCH_EVENT_DETECTED_TONE) == SWITCH_STATUS_SUCCESS) {
-						switch_event_t *dup;
-						switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Detected-Tone", cont->list[i].key);
+				if (cont->list[i].expires) {
+					cont->list[i].expires--;
+					if (!cont->list[i].expires) {
+						cont->list[i].hits = 0;
+						cont->list[i].sleep = 0;
+						cont->list[i].expires = 0;
+					}
+				}
+				
+				if (!cont->list[i].up) skip = 1;
 
-						if (switch_event_dup(&dup, event) == SWITCH_STATUS_SUCCESS) {
-							switch_event_fire(&dup);
+				if (skip) return SWITCH_TRUE;
+				
+				if (teletone_multi_tone_detect(&cont->list[i].mt, frame->data, frame->samples)) {
+					switch_event_t *event;
+					cont->list[i].hits++;
+					
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "TONE %s HIT %d/%d\n", 
+									  cont->list[i].key, cont->list[i].hits, cont->list[i].total_hits);
+					cont->list[i].sleep = 50;
+					cont->list[i].expires = 250;
+					
+					if (cont->list[i].hits >= cont->list[i].total_hits) {
+						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "TONE %s DETECTED\n", cont->list[i].key);
+						cont->list[i].up = 0;
+					
+						if (cont->list[i].app) {
+							if (switch_event_create(&event, SWITCH_EVENT_COMMAND) == SWITCH_STATUS_SUCCESS) {
+								switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "call-command", "execute");
+								switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "execute-app-name", cont->list[i].app);
+								switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "execute-app-arg", cont->list[i].data);
+								switch_event_add_header(event, SWITCH_STACK_BOTTOM, "lead-frames", "%d", 5);
+								switch_core_session_queue_private_event(cont->session, &event);
+							}
 						}
 
-						if (switch_core_session_queue_event(cont->session, &event) != SWITCH_STATUS_SUCCESS) {
-							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Event queue failed!\n");
-							switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "delivery-failure", "true");
-							switch_event_fire(&event);
+						if (switch_event_create(&event, SWITCH_EVENT_DETECTED_TONE) == SWITCH_STATUS_SUCCESS) {
+							switch_event_t *dup;
+							switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Detected-Tone", cont->list[i].key);
+
+							if (switch_event_dup(&dup, event) == SWITCH_STATUS_SUCCESS) {
+								switch_event_fire(&dup);
+							}
+
+							if (switch_core_session_queue_event(cont->session, &event) != SWITCH_STATUS_SUCCESS) {
+								switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Event queue failed!\n");
+								switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "delivery-failure", "true");
+								switch_event_fire(&event);
+							}
 						}
 					}
 				}
@@ -1278,7 +1315,7 @@
 
 SWITCH_DECLARE(switch_status_t) switch_ivr_tone_detect_session(switch_core_session_t *session,
 															   const char *key, const char *tone_spec,
-															   const char *flags, time_t timeout, const char *app, const char *data)
+															   const char *flags, time_t timeout, int hits, const char *app, const char *data)
 {
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 	switch_codec_t *read_codec = switch_core_session_get_read_codec(session);
@@ -1305,7 +1342,9 @@
 			if (!switch_strlen_zero(cont->list[cont->index].key) && !strcasecmp(key, cont->list[cont->index].key)) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Re-enabling %s\n", key);
 				cont->list[cont->index].up = 1;
-				teletone_multi_tone_init(&cont->list[i].mt, &cont->list[i].map);
+				cont->list[i].hits = 0;
+				cont->list[i].sleep = 0;
+				cont->list[i].expires = 0;
 				return SWITCH_STATUS_SUCCESS;
 			}
 		}
@@ -1320,7 +1359,7 @@
 		return SWITCH_STATUS_MEMERR;
 	}
 
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Adding tone spec %s index %d\n", tone_spec, cont->index);
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Adding tone spec %s index %d hits %d\n", tone_spec, cont->index, hits);
 
 	i = 0;
 	p = (char *) tone_spec;
@@ -1339,7 +1378,7 @@
 		}
 	} while (next);
 	cont->list[cont->index].map.freqs[i++] = 0;
-
+	
 	if (!ok) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid tone spec!\n");
 		return SWITCH_STATUS_FALSE;
@@ -1355,6 +1394,11 @@
 		cont->list[cont->index].data = switch_core_session_strdup(session, data);
 	}
 
+	if (!hits) hits = 1;
+
+	cont->list[cont->index].hits = 0;
+	cont->list[cont->index].total_hits = hits;
+
 	cont->list[cont->index].up = 1;
 	cont->list[cont->index].mt.sample_rate = read_codec->implementation->actual_samples_per_second;
 	teletone_multi_tone_init(&cont->list[cont->index].mt, &cont->list[cont->index].map);
@@ -1371,7 +1415,7 @@
 			bflags |= SMBF_WRITE_REPLACE;
 		}
 	}
-
+	
 	if ((status = switch_core_media_bug_add(session, tone_detect_callback, cont, timeout, bflags, &cont->bug)) != SWITCH_STATUS_SUCCESS) {
 		return status;
 	}

Modified: freeswitch/branches/gmaruzz/src/switch_ivr_bridge.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_ivr_bridge.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_ivr_bridge.c	Mon Dec 15 12:56:36 2008
@@ -140,7 +140,8 @@
 	switch_channel_wait_for_flag(chan_b, CF_BRIDGED, SWITCH_TRUE, 10000, chan_a);
 
 	if (!switch_channel_test_flag(chan_b, CF_BRIDGED)) {
-		if (!(switch_channel_test_flag(chan_b, CF_TRANSFER) || switch_channel_get_state(chan_b) == CS_RESET)) {
+		if (!(switch_channel_test_flag(chan_b, CF_TRANSFER) || switch_channel_test_flag(chan_b, CF_REDIRECT) 
+			  || switch_channel_get_state(chan_b) == CS_RESET)) {
 			switch_channel_hangup(chan_b, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
 		}
 		goto end_of_bridge_loop;
@@ -352,8 +353,6 @@
 				if (switch_core_session_write_frame(session_b, read_frame, SWITCH_IO_FLAG_NONE, stream_id) != SWITCH_STATUS_SUCCESS) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, 
 									  "%s ending bridge by request from write function\n", switch_channel_get_name(chan_b));
-									  
-					
 					goto end_of_bridge_loop;
 				}
 			}
@@ -462,15 +461,16 @@
 	switch_channel_clear_state_handler(channel, &audio_bridge_peer_state_handlers);
 
 	state = switch_channel_get_state(channel);
-
+	
 	if (state < CS_HANGUP && switch_true(switch_channel_get_variable(channel, SWITCH_PARK_AFTER_BRIDGE_VARIABLE))) {
 		switch_ivr_park_session(session);
+	} else {
+		if (!switch_channel_test_flag(channel, CF_TRANSFER) && !switch_channel_test_flag(channel, CF_REDIRECT) && bd && !bd->clean_exit 
+			&& state != CS_PARK && state != CS_ROUTING && !switch_channel_test_flag(channel, CF_INNER_BRIDGE)) {
+			switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
+			}
 	}
-
-	if (!switch_channel_test_flag(channel, CF_TRANSFER) && bd && !bd->clean_exit && state != CS_PARK && 
-		state != CS_ROUTING && !switch_channel_test_flag(channel, CF_INNER_BRIDGE)) {
-		switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
-	}
+	
 
 	if (switch_true(switch_channel_get_variable(channel, SWITCH_COPY_XML_CDR_VARIABLE))) {
 		switch_xml_t cdr;
@@ -485,6 +485,9 @@
 		}
 	}
 
+	if (switch_channel_get_state(channel) == CS_EXCHANGE_MEDIA) {
+		switch_channel_set_state(channel, CS_RESET);
+	}
 
 	return SWITCH_STATUS_FALSE;
 }
@@ -526,7 +529,7 @@
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CUSTOM RESET\n", switch_channel_get_name(channel));
 
-	switch_channel_clear_flag(channel, CF_TRANSFER);
+	switch_channel_clear_flag(channel, CF_ORIGINATING);
 
 	if (switch_channel_test_flag(channel, CF_ORIGINATOR)) {
 		switch_channel_set_state(channel, CS_SOFT_EXECUTE);
@@ -535,21 +538,27 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
+static switch_status_t uuid_bridge_on_hibernate(switch_core_session_t *session)
+{
+	switch_channel_set_state(switch_core_session_get_channel(session), CS_RESET);
+	return SWITCH_STATUS_FALSE;
+}
+
 static switch_status_t uuid_bridge_on_soft_execute(switch_core_session_t *session)
 {
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 	switch_core_session_t *other_session;
 	const char *other_uuid = NULL;
 
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CUSTOM TRANSMIT\n", switch_channel_get_name(channel));
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CUSTOM SOFT_EXECUTE\n", switch_channel_get_name(channel));
 	switch_channel_clear_state_handler(channel, NULL);
 
-	switch_channel_clear_flag(channel, CF_TRANSFER);
-
 	if (!switch_channel_test_flag(channel, CF_ORIGINATOR)) {
 		return SWITCH_STATUS_SUCCESS;
 	}
 
+	switch_channel_clear_flag(channel, CF_ORIGINATOR);
+	
 	if ((other_uuid = switch_channel_get_variable(channel, SWITCH_UUID_BRIDGE)) && (other_session = switch_core_session_locate(other_uuid))) {
 		switch_channel_t *other_channel = switch_core_session_get_channel(other_session);
 		switch_event_t *event;
@@ -572,8 +581,6 @@
 
 		switch_channel_wait_for_state(channel, other_channel, CS_SOFT_EXECUTE);
 
-		switch_channel_clear_flag(channel, CF_TRANSFER);
-		switch_channel_clear_flag(other_channel, CF_TRANSFER);
 		switch_core_session_reset(session, SWITCH_TRUE);
 
 
@@ -613,9 +620,11 @@
 		}
 
 		switch_ivr_multi_threaded_bridge(session, other_session, NULL, NULL, NULL);
-
+		
 		state = switch_channel_get_state(channel);
-		if (!switch_channel_test_flag(channel, CF_TRANSFER) && state < CS_HANGUP && state != CS_ROUTING && state != CS_PARK) {
+		if (!switch_channel_test_flag(channel, CF_TRANSFER) && 
+			!switch_channel_test_flag(channel, CF_REDIRECT) && state < CS_HANGUP 
+			&& state != CS_ROUTING && state != CS_PARK) {
 			switch_channel_set_state(channel, CS_EXECUTE);
 		}
 		switch_core_session_rwunlock(other_session);
@@ -635,8 +644,8 @@
 	/*.on_hangup */ NULL,
 	/*.on_exchange_media */ NULL,
 	/*.on_soft_execute */ uuid_bridge_on_soft_execute,
-	/*.on_consume_media */ NULL,
-	/*.on_hibernate */ NULL,
+	/*.on_consume_media */ uuid_bridge_on_hibernate,
+	/*.on_hibernate */ uuid_bridge_on_hibernate,
 	/*.on_reset */ uuid_bridge_on_reset
 };
 
@@ -646,7 +655,6 @@
 
 	channel = switch_core_session_get_channel(session);
 	switch_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));
 
@@ -782,8 +790,6 @@
 	int inner_bridge = switch_channel_test_flag(caller_channel, CF_INNER_BRIDGE);
 
 	switch_channel_set_flag(caller_channel, CF_ORIGINATOR);
-	switch_channel_clear_flag(caller_channel, CF_TRANSFER);
-	switch_channel_clear_flag(peer_channel, CF_TRANSFER);
 
 	b_leg->session = peer_session;
 	switch_copy_string(b_leg->b_uuid, switch_core_session_get_uuid(session), sizeof(b_leg->b_uuid));
@@ -827,7 +833,8 @@
 				if ((status = switch_ivr_wait_for_answer(session, peer_session)) != SWITCH_STATUS_SUCCESS) {
 					switch_channel_state_t w_state = switch_channel_get_state(caller_channel);
 					switch_channel_hangup(peer_channel, SWITCH_CAUSE_ALLOTTED_TIMEOUT);
-					if (w_state < CS_HANGUP && w_state != CS_ROUTING && w_state != CS_PARK && !switch_channel_test_flag(caller_channel, CF_TRANSFER) &&
+					if (w_state < CS_HANGUP && w_state != CS_ROUTING && w_state != CS_PARK && 
+						!switch_channel_test_flag(caller_channel, CF_REDIRECT) && !switch_channel_test_flag(caller_channel, CF_TRANSFER) &&
 						w_state != CS_EXECUTE) {
 						const char *ext = switch_channel_get_variable(peer_channel, "original_destination_number");
 						if (!ext) {
@@ -908,10 +915,6 @@
 			
 			switch_channel_clear_flag(caller_channel, CF_ORIGINATOR);
 
-			if (!switch_channel_test_flag(peer_channel, CF_TRANSFER) && switch_channel_get_state(peer_channel) == CS_EXCHANGE_MEDIA) {
-				switch_channel_set_state(peer_channel, CS_RESET);
-			}
-
 			while (switch_channel_get_state(peer_channel) == CS_EXCHANGE_MEDIA) {
 				switch_cond_next();
 			}
@@ -940,18 +943,26 @@
 	}
 
 	state = switch_channel_get_state(caller_channel);
-
-	if (!switch_channel_test_flag(caller_channel, CF_TRANSFER) && !a_leg->clean_exit && !inner_bridge) {
+	
+	if (!switch_channel_test_flag(caller_channel, CF_TRANSFER) && !switch_channel_test_flag(caller_channel, CF_REDIRECT) 
+		&& !a_leg->clean_exit && !inner_bridge) {
 		if ((state != CS_EXECUTE && state != CS_SOFT_EXECUTE && state != CS_PARK && state != CS_ROUTING) ||
 			(switch_channel_test_flag(peer_channel, CF_ANSWERED) && state < CS_HANGUP)) {
-			if (switch_true(switch_channel_get_variable(caller_channel, SWITCH_HANGUP_AFTER_BRIDGE_VARIABLE))) {
-				switch_channel_hangup(caller_channel, switch_channel_get_cause(peer_channel));
-			} else if (switch_true(switch_channel_get_variable(caller_channel, SWITCH_PARK_AFTER_BRIDGE_VARIABLE))) {
+			if (switch_true(switch_channel_get_variable(caller_channel, SWITCH_PARK_AFTER_BRIDGE_VARIABLE))) {
 				switch_ivr_park_session(session);
+			} else if (switch_true(switch_channel_get_variable(caller_channel, SWITCH_HANGUP_AFTER_BRIDGE_VARIABLE))) {
+				switch_channel_hangup(caller_channel, switch_channel_get_cause(peer_channel));
 			}
 		}
 	}
 
+	if (switch_channel_test_flag(caller_channel, CF_REDIRECT)) {
+		state = switch_channel_get_state(caller_channel);
+		if (!(state == CS_RESET || state == CS_PARK || state == CS_ROUTING)) {
+			switch_channel_set_state(caller_channel, CS_RESET);
+		}
+	}
+	
 	return status;
 }
 
@@ -989,6 +1000,7 @@
 	switch_status_t status = SWITCH_STATUS_FALSE;
 	switch_caller_profile_t *cp, *originator_cp, *originatee_cp;
 	char *p;
+	switch_channel_state_t state;
 
 	if ((originator_session = switch_core_session_locate(originator_uuid))) {
 		if ((originatee_session = switch_core_session_locate(originatee_uuid))) {
@@ -1030,14 +1042,11 @@
 			 * 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_state_flag(originator_channel, CF_ORIGINATOR);
-			switch_channel_clear_flag(originatee_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_variable(originator_channel, SWITCH_UUID_BRIDGE, switch_core_session_get_uuid(originatee_session));
+			switch_channel_set_flag(originator_channel, CF_REDIRECT);
+			switch_channel_set_flag(originatee_channel, CF_REDIRECT);
+			
 
+			switch_channel_set_variable(originator_channel, SWITCH_UUID_BRIDGE, switch_core_session_get_uuid(originatee_session));
 			switch_channel_set_variable(originator_channel, SWITCH_BRIDGE_CHANNEL_VARIABLE, switch_channel_get_name(originatee_channel));
 			switch_channel_set_variable(originator_channel, SWITCH_BRIDGE_UUID_VARIABLE, switch_core_session_get_uuid(originatee_session));
 			switch_channel_set_variable(originator_channel, SWITCH_SIGNAL_BOND_VARIABLE, switch_core_session_get_uuid(originatee_session));
@@ -1086,13 +1095,23 @@
 			switch_channel_set_flag(originator_channel, CF_TRANSFER);
 			switch_channel_set_flag(originatee_channel, CF_TRANSFER);
 
+
 			switch_channel_clear_flag(originator_channel, CF_ORIGINATING);
 			switch_channel_clear_flag(originatee_channel, CF_ORIGINATING);
 
 			/* change the states and let the chips fall where they may */
-			switch_channel_set_state(originator_channel, CS_RESET);
-			switch_channel_set_state(originatee_channel, CS_RESET);
+			switch_channel_clear_state_handler(originator_channel, NULL);
+			switch_channel_clear_state_handler(originatee_channel, NULL);
+			switch_channel_set_state_flag(originator_channel, CF_ORIGINATOR);
+			switch_channel_clear_flag(originatee_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);
 
+			state = switch_channel_get_state(originator_channel);
+			switch_channel_set_state(originator_channel, state == CS_HIBERNATE ? CS_CONSUME_MEDIA : CS_HIBERNATE);
+			state = switch_channel_get_state(originatee_channel);
+			switch_channel_set_state(originatee_channel, state == CS_HIBERNATE ? CS_CONSUME_MEDIA : CS_HIBERNATE);
+			
 			status = SWITCH_STATUS_SUCCESS;
 
 			/* release the read locks we have on the channels */

Modified: freeswitch/branches/gmaruzz/src/switch_ivr_menu.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_ivr_menu.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_ivr_menu.c	Mon Dec 15 12:56:36 2008
@@ -167,9 +167,17 @@
 
 	menu->inlen = digit_len;
 
-	menu->max_failures = max_failures;
+	if (max_failures > 0) {
+		menu->max_failures = max_failures;
+	} else {
+		menu->max_failures = 3;
+	}
 
-	menu->max_timeouts = max_timeouts;
+	if (max_timeouts > 0) {
+		menu->max_timeouts = max_timeouts;
+	} else {
+		menu->max_timeouts = 3;
+	}
 
 	menu->timeout = timeout;
 
@@ -178,7 +186,7 @@
 	menu->actions = NULL;
 
 	if (newpool) {
-		menu->flags |= SWITCH_IVR_MENU_FLAG_FREEPOOL;
+		switch_set_flag(menu, SWITCH_IVR_MENU_FLAG_FREEPOOL);
 	}
 
 	if (menu->timeout <= 0) {
@@ -188,7 +196,7 @@
 	if (main) {
 		switch_ivr_menu_stack_add(&main, menu);
 	} else {
-		menu->flags |= SWITCH_IVR_MENU_FLAG_STACK;
+		switch_set_flag(menu, SWITCH_IVR_MENU_FLAG_STACK);
 	}
 
 	*new_menu = menu;
@@ -521,7 +529,7 @@
 			}
 			errs++;
 			if (status == SWITCH_STATUS_SUCCESS) {
-				status = switch_ivr_sleep(session, 1000, NULL);
+				status = switch_ivr_sleep(session, 1000, SWITCH_FALSE, NULL);
 			}
 			/* breaks are ok too */
 			if (SWITCH_STATUS_IS_BREAK(status)) {
@@ -736,8 +744,8 @@
 									  atoi(inter_timeout),
 									  atoi(digit_len),
 									  atoi(timeout), 
-									  strlen(max_failures)? atoi(max_failures): 1, 
-									  strlen(max_timeouts)? atoi(max_timeouts): 1, 
+									  strlen(max_failures)? atoi(max_failures): 0, 
+									  strlen(max_timeouts)? atoi(max_timeouts): 0, 
 									  xml_menu_ctx->pool);
 		/* set the menu_stack for the caller */
 		if (status == SWITCH_STATUS_SUCCESS && *menu_stack == NULL) {

Modified: freeswitch/branches/gmaruzz/src/switch_ivr_originate.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_ivr_originate.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_ivr_originate.c	Mon Dec 15 12:56:36 2008
@@ -39,12 +39,6 @@
 {
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 
-	if (!switch_channel_test_flag(channel, CF_PROXY_MODE)) {
-		while (switch_channel_get_state(channel) == CS_CONSUME_MEDIA && !switch_channel_test_flag(channel, CF_TAGGED)) {
-			switch_ivr_sleep(session, 10, NULL);
-		}
-	}
-
 	switch_channel_clear_state_handler(channel, &originate_state_handlers);
 
 	return SWITCH_STATUS_FALSE;
@@ -97,6 +91,8 @@
 		return NULL;
 	}
 	
+	switch_ivr_sleep(collect->session, 0, SWITCH_TRUE, NULL);
+	
 	if (!strcasecmp(collect->key, "exec")) {
 		char *data;
 		switch_application_interface_t *application_interface;
@@ -229,9 +225,15 @@
 			*progress = 1;
 		}
 
+		if (switch_core_session_private_event_count(peer_sessions[i])) {
+			switch_ivr_parse_all_events(peer_sessions[i]);
+		}
+
 		state = switch_channel_get_state(peer_channels[i]);
 		if (state >= CS_HANGUP || state == CS_RESET || switch_channel_test_flag(peer_channels[i], CF_TRANSFER) ||
-			switch_channel_test_flag(peer_channels[i], CF_BRIDGED) || !switch_channel_test_flag(peer_channels[i], CF_ORIGINATING)
+			switch_channel_test_flag(peer_channels[i], CF_REDIRECT) ||
+			switch_channel_test_flag(peer_channels[i], CF_BRIDGED) || 
+			!switch_channel_test_flag(peer_channels[i], CF_ORIGINATING)
 			) {
 			(*hups)++;
 		} else if ((switch_channel_test_flag(peer_channels[i], CF_ANSWERED) ||
@@ -277,6 +279,7 @@
 	teletone_generation_session_t ts;
 	switch_file_handle_t fhb;
 	switch_file_handle_t *fh;
+	int silence;
 	uint8_t asis;
 };
 
@@ -346,9 +349,16 @@
 			ringback_data = switch_channel_get_variable(caller_channel, "ringback");
 		}
 
-
 		if (switch_channel_test_flag(caller_channel, CF_PROXY_MODE) || switch_channel_test_flag(caller_channel, CF_PROXY_MEDIA)) {
 			ringback_data = NULL;
+		} else if (switch_strlen_zero(ringback_data)) {
+			if ((var = switch_channel_get_variable(caller_channel, SWITCH_SEND_SILENCE_WHEN_IDLE_VARIABLE))) {
+				int sval = atoi(var);
+
+				if (sval) {
+					ringback_data = switch_core_session_sprintf(session, "silence:%d", sval);
+				}
+			}
 		}
 	}
 
@@ -376,9 +386,6 @@
 				if (ringback_data) {
 					char *tmp_data = NULL;
 
-					switch_buffer_create_dynamic(&ringback.audio_buffer, 512, 1024, 0);
-					switch_buffer_set_loops(ringback.audio_buffer, -1);
-
 					if (switch_is_file_path(ringback_data)) {
 						char *ext;
 
@@ -407,14 +414,30 @@
 						}
 						ringback.fh = &ringback.fhb;
 					} else {
-						teletone_init_session(&ringback.ts, 0, teletone_handler, &ringback);
-						ringback.ts.rate = read_codec->implementation->actual_samples_per_second;
-						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Play Ringback Tone [%s]\n", ringback_data);
-						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);
-							ringback_data = NULL;
+						if (!strncasecmp(ringback_data, "silence", 7)) {
+							const char *p = ringback_data + 7;
+							if (*p == ':') {
+								p++;
+								if (p) {
+									ringback.silence = atoi(p);
+								}
+							}
+							if (ringback.silence <= 0) {
+								ringback.silence = 400;
+							}
+						} else {
+							switch_buffer_create_dynamic(&ringback.audio_buffer, 512, 1024, 0);
+							switch_buffer_set_loops(ringback.audio_buffer, -1);
+							
+							teletone_init_session(&ringback.ts, 0, teletone_handler, &ringback);
+							ringback.ts.rate = read_codec->implementation->actual_samples_per_second;
+							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Play Ringback Tone [%s]\n", ringback_data);
+							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);
+								ringback_data = NULL;
+							}
 						}
 					}
 					switch_safe_free(tmp_data);
@@ -489,9 +512,12 @@
 																			  write_frame.codec->implementation->decoded_bytes_per_packet)) <= 0) {
 					break;
 				}
+			} else if (ringback.silence) {
+				write_frame.datalen = write_frame.codec->implementation->decoded_bytes_per_packet;
+				switch_generate_sln_silence((int16_t *) write_frame.data, write_frame.datalen / 2, ringback.silence);
 			}
 
-			if ((ringback.fh || ringback.audio_buffer) && write_frame.codec && write_frame.datalen) {
+			if ((ringback.fh || ringback.silence || ringback.audio_buffer) && write_frame.codec && write_frame.datalen) {
 				if (switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0) != SWITCH_STATUS_SUCCESS) {
 					break;
 				}
@@ -554,7 +580,10 @@
 													 const switch_state_handler_table_t *table,
 													 const char *cid_name_override,
 													 const char *cid_num_override,
-													 switch_caller_profile_t *caller_profile_override, switch_originate_flag_t flags)
+													 switch_caller_profile_t *caller_profile_override, 
+													 switch_event_t *ovars,
+													 switch_originate_flag_t flags
+													 )
 {
 	switch_originate_flag_t dftflags = SOF_NONE, myflags = dftflags;
 	char *pipe_names[MAX_PEERS] = { 0 };
@@ -667,8 +696,13 @@
 	   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_GENERAL) != SWITCH_STATUS_SUCCESS) {
-		abort();
+
+	if (ovars) {
+		var_event = ovars;
+	} else {
+		if (switch_event_create(&var_event, SWITCH_EVENT_GENERAL) != SWITCH_STATUS_SUCCESS) {
+			abort();
+		}
 	}
 
 	if (session) {
@@ -759,6 +793,17 @@
 
 		if (switch_channel_test_flag(caller_channel, CF_PROXY_MODE) || switch_channel_test_flag(caller_channel, CF_PROXY_MEDIA)) {
 			ringback_data = NULL;
+		} else if (switch_strlen_zero(ringback_data)) {
+			const char *vvar;
+			
+			if ((vvar = switch_channel_get_variable(caller_channel, SWITCH_SEND_SILENCE_WHEN_IDLE_VARIABLE))) {
+				int sval = atoi(vvar);
+
+				if (sval) {
+					ringback_data = switch_core_session_sprintf(session, "silence:%d", sval);
+				}
+
+			}
 		}
 	}
 
@@ -906,7 +951,7 @@
 			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);
 				if (caller_channel) {
-					switch_ivr_sleep(session, sleep_ms, NULL);
+					switch_ivr_sleep(session, sleep_ms, SWITCH_TRUE, NULL);
 				} else {
 					switch_yield(sleep_ms * 1000);
 				}
@@ -1251,9 +1296,7 @@
 						if (ringback_data) {
 							char *tmp_data = NULL;
 
-							switch_buffer_create_dynamic(&ringback.audio_buffer, 512, 1024, 0);
-							switch_buffer_set_loops(ringback.audio_buffer, -1);
-
+							
 							if (switch_is_file_path(ringback_data)) {
 								char *ext;
 
@@ -1282,8 +1325,21 @@
 								}
 								ringback.fh = &ringback.fhb;
 
-
+							} else if (!strncasecmp(ringback_data, "silence", 7)) {
+								const char *c = ringback_data + 7;
+								if (*c == ':') {
+									c++;
+									if (c) {
+										ringback.silence = atoi(c);
+									}
+								}
+								if (ringback.silence <= 0) {
+									ringback.silence = 400;
+								}
 							} else {
+								switch_buffer_create_dynamic(&ringback.audio_buffer, 512, 1024, 0);
+								switch_buffer_set_loops(ringback.audio_buffer, -1);
+
 								teletone_init_session(&ringback.ts, 0, teletone_handler, &ringback);
 								ringback.ts.rate = read_codec->implementation->actual_samples_per_second;
 								switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Play Ringback Tone [%s]\n", ringback_data);
@@ -1322,6 +1378,10 @@
 				
 				check_per_channel_timeouts(peer_channels, per_channel_timelimit_sec, per_channel_progress_timelimit_sec, and_argc, start);
 
+				if (session && switch_core_session_private_event_count(session)) {
+					switch_ivr_parse_all_events(session);
+				}
+
 				if (!sent_ring && !progress && (progress_timelimit_sec && elapsed > (time_t) progress_timelimit_sec)) {
 					idx = IDX_TIMEOUT;
 					goto notready;
@@ -1377,6 +1437,7 @@
 					 || (switch_channel_test_flag(caller_channel, CF_ANSWERED) || switch_channel_test_flag(caller_channel, CF_EARLY_MEDIA)))) {
 
 					switch_status_t tstatus = SWITCH_STATUS_SUCCESS;
+					int silence = 0;
 
 					if (switch_channel_media_ready(caller_channel)) {
 						tstatus = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
@@ -1422,15 +1483,24 @@
 																						  write_frame.codec->implementation->decoded_bytes_per_packet)) <= 0) {
 								break;
 							}
+						} else if (ringback.silence) {
+							silence = ringback.silence;
 						}
-
-						if ((ringback.fh || ringback.audio_buffer) && write_frame.codec && write_frame.datalen) {
-							if (switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0) != SWITCH_STATUS_SUCCESS) {
-								break;
-							}
+					} else {
+						silence = 400;
+					}
+					
+					if ((ringback.fh || silence || ringback.audio_buffer) && write_frame.codec && write_frame.datalen) {
+						if (silence) {
+							write_frame.datalen = write_frame.codec->implementation->decoded_bytes_per_packet;
+							switch_generate_sln_silence((int16_t *) write_frame.data, write_frame.datalen / 2, silence);
+						}
+						
+						if (switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0) != SWITCH_STATUS_SUCCESS) {
+							break;
 						}
 					}
-
+					
 				} else {
 					switch_yield(100000);
 				}
@@ -1453,8 +1523,11 @@
 					continue;
 				}
 
-				if (switch_channel_test_flag(peer_channels[i], CF_TRANSFER) || switch_channel_test_flag(peer_channels[i], CF_BRIDGED) ||
-					switch_channel_get_state(peer_channels[i]) == CS_RESET || !switch_channel_test_flag(peer_channels[i], CF_ORIGINATING)
+				if (switch_channel_test_flag(peer_channels[i], CF_TRANSFER) 
+					|| switch_channel_test_flag(peer_channels[i], CF_REDIRECT) 
+					|| switch_channel_test_flag(peer_channels[i], CF_BRIDGED) ||
+					switch_channel_get_state(peer_channels[i]) == CS_RESET || 
+					!switch_channel_test_flag(peer_channels[i], CF_ORIGINATING)
 					) {
 					continue;
 				}
@@ -1645,16 +1718,19 @@
 					continue;
 				}
 				
-				switch_channel_clear_flag(peer_channels[i], CF_ORIGINATING);
 				if (status == SWITCH_STATUS_SUCCESS) { 
+					switch_channel_clear_flag(peer_channels[i], CF_ORIGINATING);
 					if (bleg && *bleg && *bleg == peer_sessions[i]) {
 						continue;
 					}
-				} else if ((state=switch_channel_get_state(peer_channels[i])) < CS_HANGUP) {
-					if (!(state == CS_RESET || switch_channel_test_flag(peer_channels[i], CF_TRANSFER))) {
+				} else if ((state=switch_channel_get_state(peer_channels[i])) < CS_HANGUP && switch_channel_test_flag(peer_channels[i], CF_ORIGINATING)) {
+					if (!(state == CS_RESET || switch_channel_test_flag(peer_channels[i], CF_TRANSFER) || 
+						  switch_channel_test_flag(peer_channels[i], CF_REDIRECT) ||
+						  switch_channel_test_flag(peer_channels[i], CF_BRIDGED))) {
 						switch_channel_hangup(peer_channels[i], *cause);
 					}
 				}
+				switch_channel_clear_flag(peer_channels[i], CF_ORIGINATING);
 
 				switch_core_session_rwunlock(peer_sessions[i]);
 			}
@@ -1672,8 +1748,15 @@
 		*bleg = NULL;
 	}
 
+	if (*bleg) {
+		switch_ivr_sleep(*bleg, 0, SWITCH_TRUE, NULL);
+	}
+
+	if (session) {
+		switch_ivr_sleep(session, 0, SWITCH_TRUE, NULL);
+	}
 
-	if (var_event) {
+	if (var_event && var_event != ovars) {
 		switch_event_destroy(&var_event);
 	}
 	switch_safe_free(write_frame.data);

Modified: freeswitch/branches/gmaruzz/src/switch_ivr_play_say.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_ivr_play_say.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_ivr_play_say.c	Mon Dec 15 12:56:36 2008
@@ -327,7 +327,7 @@
 						}
 					}
 
-					switch_ivr_sleep(session, pause, NULL);
+					switch_ivr_sleep(session, pause, SWITCH_FALSE, NULL);
 				}
 			}
 

Modified: freeswitch/branches/gmaruzz/src/switch_loadable_module.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_loadable_module.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_loadable_module.c	Mon Dec 15 12:56:36 2008
@@ -428,7 +428,7 @@
 				if (switch_thread_rwlock_trywrlock_timeout(ptr->rwlock, 10) == SWITCH_STATUS_SUCCESS) {
                     switch_thread_rwlock_unlock(ptr->rwlock);
                 } else {
-                    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Giving up waiting for existing references.\n");
+                    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Giving up on '%s' waiting for existing references.\n", ptr->interface_name);
                 }
 
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Deleting Endpoint '%s'\n", ptr->interface_name);
@@ -513,7 +513,7 @@
 				if (switch_thread_rwlock_trywrlock_timeout(ptr->rwlock, 10) == SWITCH_STATUS_SUCCESS) {
 					switch_thread_rwlock_unlock(ptr->rwlock);
 				} else {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Giving up waiting for existing references.\n");
+                    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Giving up on '%s' waiting for existing references.\n", ptr->interface_name);
 				}
 				
 				if (switch_event_create(&event, SWITCH_EVENT_MODULE_UNLOAD) == SWITCH_STATUS_SUCCESS) {
@@ -540,7 +540,7 @@
 				if (switch_thread_rwlock_trywrlock_timeout(ptr->rwlock, 10) == SWITCH_STATUS_SUCCESS) {
 					switch_thread_rwlock_unlock(ptr->rwlock);
 				} else {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Giving up waiting for existing references.\n");
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Giving up on '%s' waiting for existing references.\n", ptr->interface_name);
 				}
 
 
@@ -568,7 +568,7 @@
 				if (switch_thread_rwlock_trywrlock_timeout(ptr->rwlock, 10) == SWITCH_STATUS_SUCCESS) {
 					switch_thread_rwlock_unlock(ptr->rwlock);
 				} else {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Giving up waiting for existing references.\n");
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Giving up on '%s' waiting for existing references.\n", ptr->interface_name);
 				}
 
 				for (i = 0; ptr->extens[i]; i++) {
@@ -596,7 +596,7 @@
 				if (switch_thread_rwlock_trywrlock_timeout(ptr->rwlock, 10) == SWITCH_STATUS_SUCCESS) {
 					switch_thread_rwlock_unlock(ptr->rwlock);
 				} else {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Giving up waiting for existing references.\n");
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Giving up on '%s' waiting for existing references.\n", ptr->interface_name);
 				}
 
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Deleting Speech interface '%s'\n", ptr->interface_name);
@@ -621,7 +621,7 @@
 				if (switch_thread_rwlock_trywrlock_timeout(ptr->rwlock, 10) == SWITCH_STATUS_SUCCESS) {
 					switch_thread_rwlock_unlock(ptr->rwlock);
 				} else {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Giving up waiting for existing references.\n");
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Giving up on '%s' waiting for existing references.\n", ptr->interface_name);
 				}
 
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Deleting Asr interface '%s'\n", ptr->interface_name);
@@ -646,7 +646,7 @@
 				if (switch_thread_rwlock_trywrlock_timeout(ptr->rwlock, 10) == SWITCH_STATUS_SUCCESS) {
 					switch_thread_rwlock_unlock(ptr->rwlock);
 				} else {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Giving up waiting for existing references.\n");
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Giving up on '%s' waiting for existing references.\n", ptr->interface_name);
 				}
 
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Deleting Directory interface '%s'\n", ptr->interface_name);
@@ -671,7 +671,7 @@
 				if (switch_thread_rwlock_trywrlock_timeout(ptr->rwlock, 10) == SWITCH_STATUS_SUCCESS) {
 					switch_thread_rwlock_unlock(ptr->rwlock);
 				} else {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Giving up waiting for existing references.\n");
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Giving up on '%s' waiting for existing references.\n", ptr->interface_name);
 				}
 
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Deleting Chat interface '%s'\n", ptr->interface_name);
@@ -695,7 +695,7 @@
 				if (switch_thread_rwlock_trywrlock_timeout(ptr->rwlock, 10) == SWITCH_STATUS_SUCCESS) {
 					switch_thread_rwlock_unlock(ptr->rwlock);
 				} else {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Giving up waiting for existing references.\n");
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Giving up on '%s' waiting for existing references.\n", ptr->interface_name);
 				}
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Deleting Say interface '%s'\n", ptr->interface_name);
 				if (switch_event_create(&event, SWITCH_EVENT_MODULE_UNLOAD) == SWITCH_STATUS_SUCCESS) {
@@ -1567,6 +1567,7 @@
 			mod->_TYPE_##_interface = i;								\
 		}																\
 		switch_thread_rwlock_create(&i->rwlock, mod->pool);				\
+		switch_mutex_init(&i->reflock, SWITCH_MUTEX_NESTED, mod->pool);	\
 		i->parent = mod;												\
 		return i; }
 

Modified: freeswitch/branches/gmaruzz/src/switch_odbc.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_odbc.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_odbc.c	Mon Dec 15 12:56:36 2008
@@ -301,7 +301,7 @@
 
 	result = SQLExecute(stmt);
 
-	if (result != SQL_SUCCESS && result != SQL_SUCCESS_WITH_INFO) {
+	if (result != SQL_SUCCESS && result != SQL_SUCCESS_WITH_INFO && result != SQL_NO_DATA) {
 		goto error;
 	}
 
@@ -322,12 +322,14 @@
 	return SWITCH_ODBC_FAIL;
 }
 
-SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_callback_exec(switch_odbc_handle_t *handle,
-																	  char *sql, switch_core_db_callback_func_t callback, void *pdata)
+SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_callback_exec_detailed(const char *file, const char *func, int line,
+																			   switch_odbc_handle_t *handle,
+																			   char *sql, switch_core_db_callback_func_t callback, void *pdata)
 {
 	SQLHSTMT stmt = NULL;
 	SQLSMALLINT c = 0, x = 0;
 	SQLLEN m = 0, t = 0;
+	char *err_str = NULL;
 	int result;
 
 	switch_assert(callback != NULL);
@@ -337,10 +339,12 @@
 	}
 
 	if (SQLAllocHandle(SQL_HANDLE_STMT, handle->con, &stmt) != SQL_SUCCESS) {
+		err_str = "Unable to SQL allocate handle.";
 		goto error;
 	}
 
 	if (SQLPrepare(stmt, (unsigned char *) sql, SQL_NTS) != SQL_SUCCESS) {
+		err_str = "Unable to prepare SQL statement.";
 		goto error;
 	}
 
@@ -407,7 +411,18 @@
 
   error:
 
+	/* err_str is already defined  for some error cases */
+	if (err_str != NULL) {
+		switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, "ERR: [%s]\n[%s]\n", sql, switch_str_nil(err_str));
+		err_str = NULL;
+	}
+	
 	if (stmt) {
+		err_str = switch_odbc_handle_get_error(handle, stmt);
+		if (!switch_strlen_zero(err_str)) {
+			switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, "ERR: [%s]\n[%s]\n", sql, switch_str_nil(err_str));
+		}
+		switch_safe_free(err_str);
 		SQLFreeHandle(SQL_HANDLE_STMT, stmt);
 	}
 

Modified: freeswitch/branches/gmaruzz/src/switch_resample.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_resample.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_resample.c	Mon Dec 15 12:56:36 2008
@@ -203,16 +203,19 @@
 
 SWITCH_DECLARE(void) switch_generate_sln_silence(int16_t *data, uint32_t samples, uint32_t divisor)
 {
-	int16_t rnd, x;
+	int16_t x;
 	uint32_t i;
 	int sum_rnd = 0;
+	int16_t rnd2 = (int16_t) switch_timestamp_now();
 
 	assert(divisor);
 
+
+
 	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;
+		for (x = 0; x < 6; x++) {
+			rnd2 = rnd2 * 31821U + 13849U;
+			sum_rnd += rnd2;
 		}
 		switch_normalize_to_16bit(sum_rnd);
 		*data = (int16_t) ((int16_t) sum_rnd / (int) divisor);

Modified: freeswitch/branches/gmaruzz/src/switch_rtp.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_rtp.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_rtp.c	Mon Dec 15 12:56:36 2008
@@ -158,6 +158,7 @@
 	uint32_t last_write_ts;
 	uint32_t last_write_samplecount;
 	uint32_t next_write_samplecount;
+	switch_time_t last_write_timestamp;
 	uint32_t flags;
 	switch_memory_pool_t *pool;
 	switch_sockaddr_t *from_addr;
@@ -754,20 +755,29 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-SWITCH_DECLARE(void) switch_rtp_change_interval(switch_rtp_t *rtp_session, uint32_t ms_per_packet, uint32_t samples_per_interval)
+SWITCH_DECLARE(switch_status_t) switch_rtp_change_interval(switch_rtp_t *rtp_session, uint32_t ms_per_packet, uint32_t samples_per_interval)
 {
 	rtp_session->ms_per_packet = ms_per_packet;
 	rtp_session->samples_per_interval = rtp_session->conf_samples_per_interval = samples_per_interval;
-	
+	rtp_session->missed_count = 0;
+
 	if (rtp_session->timer_name) {
 		if (rtp_session->timer.timer_interface) {
 			switch_core_timer_destroy(&rtp_session->timer);
 		}
-		switch_core_timer_init(&rtp_session->timer, rtp_session->timer_name, ms_per_packet / 1000, samples_per_interval, rtp_session->pool);
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
-						  "RE-Starting timer [%s] %d bytes per %dms\n", rtp_session->timer_name, samples_per_interval, ms_per_packet);
+		if (switch_core_timer_init(&rtp_session->timer, 
+								   rtp_session->timer_name, ms_per_packet / 1000, samples_per_interval, rtp_session->pool) == SWITCH_STATUS_SUCCESS) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
+							  "RE-Starting timer [%s] %d bytes per %dms\n", rtp_session->timer_name, samples_per_interval, ms_per_packet);
+		} else {
+			memset(&rtp_session->timer, 0, sizeof(rtp_session->timer));
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
+							  "Problem RE-Starting timer [%s] %d bytes per %dms\n", rtp_session->timer_name, samples_per_interval, ms_per_packet / 1000);
+			return SWITCH_STATUS_FALSE;
+		}
 	}
 		
+	return SWITCH_STATUS_SUCCESS;
 }
 
 SWITCH_DECLARE(switch_status_t) switch_rtp_create(switch_rtp_t **new_rtp_session,
@@ -983,7 +993,7 @@
 
 	if (rtp_session->ice_user) {
 		if (ice_out(rtp_session) != SWITCH_STATUS_SUCCESS) {
-			return -1;
+			return SWITCH_STATUS_FALSE;
 		}
 	}
 
@@ -992,15 +1002,22 @@
 
 SWITCH_DECLARE(void) switch_rtp_break(switch_rtp_t *rtp_session)
 {
-	switch_assert(rtp_session != NULL);
+	if (!switch_rtp_ready(rtp_session)) {
+		return;
+	}
+
 	switch_mutex_lock(rtp_session->flag_mutex);
 	switch_set_flag(rtp_session, SWITCH_RTP_FLAG_BREAK);
+	
+	if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_NOBLOCK)) {
+		switch_mutex_unlock(rtp_session->flag_mutex);
+		return;
+	}
 
 	if (rtp_session->sock_input) {
-		char o[4] = "DOH";
+		uint32_t o = UINT_MAX;
 		switch_size_t len = sizeof(o);
-		
-		switch_socket_sendto(rtp_session->sock_input, rtp_session->local_addr, 0, (void *) o, &len);
+		switch_socket_sendto(rtp_session->sock_input, rtp_session->local_addr, 0, (void *) &o, &len);
 	}
 	switch_mutex_unlock(rtp_session->flag_mutex);
 }
@@ -1187,6 +1204,9 @@
 							  rtp_session->dtmf_data.timestamp_dtmf,
 							  rtp_session->dtmf_data.out_digit_sofar,
 							  rtp_session->dtmf_data.out_digit_sub_sofar, rtp_session->dtmf_data.out_digit_dur, rtp_session->seq);
+			if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_BUGGY_2833)) {
+				rtp_session->dtmf_data.timestamp_dtmf = rtp_session->last_write_ts + samples;
+			}
 		}
 
 		if (loops != 1) {
@@ -1251,6 +1271,50 @@
 	}
 }
 
+SWITCH_DECLARE(void) rtp_flush_read_buffer(switch_rtp_t *rtp_session)
+{
+	if (switch_rtp_ready(rtp_session) && !switch_test_flag(rtp_session, SWITCH_RTP_FLAG_PROXY_MEDIA)) {
+		switch_set_flag_locked(rtp_session, SWITCH_RTP_FLAG_FLUSH);
+	}
+}
+
+static void do_flush(switch_rtp_t *rtp_session)
+{
+	int was_blocking = 0;
+	switch_size_t bytes;
+	switch_status_t status;
+
+	if (!switch_rtp_ready(rtp_session) || switch_test_flag(rtp_session, SWITCH_RTP_FLAG_PROXY_MEDIA)) {
+		return;
+	}
+	
+	READ_INC(rtp_session);
+
+	if (switch_rtp_ready(rtp_session)) {
+		if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_NOBLOCK)) {
+			was_blocking = 1;
+			switch_set_flag_locked(rtp_session, SWITCH_RTP_FLAG_NOBLOCK);		
+			switch_socket_opt_set(rtp_session->sock_input, SWITCH_SO_NONBLOCK, TRUE);
+		}
+	
+		do {
+			if (switch_rtp_ready(rtp_session)) {
+				bytes = sizeof(rtp_msg_t);
+				status = switch_socket_recvfrom(rtp_session->from_addr, rtp_session->sock_input, 0, (void *) &rtp_session->recv_msg, &bytes);
+			} else {
+				break;
+			}
+		} while(bytes > 0);
+		
+		if (was_blocking && switch_rtp_ready(rtp_session)) {
+			switch_clear_flag_locked(rtp_session, SWITCH_RTP_FLAG_NOBLOCK);
+			switch_socket_opt_set(rtp_session->sock_input, SWITCH_SO_NONBLOCK, FALSE);
+		}
+	}
+	
+	READ_DEC(rtp_session);
+}
+
 #define return_cng_frame() do_cng = 1; goto timer_check
 
 static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_type, switch_frame_flag_t *flags, switch_io_flag_t io_flags)
@@ -1289,11 +1353,27 @@
 			goto end;
 		}
 		
-		check = !bytes;
+		if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_FLUSH)) {
+			do_flush(rtp_session);
+			switch_clear_flag_locked(rtp_session, SWITCH_RTP_FLAG_FLUSH);
+			bytes = 0;
+		}
 
-		if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_BREAK)) {
+		if (rtp_session->max_missed_packets) {
+			if (bytes) {
+				rtp_session->missed_count = 0;
+			} else if (++rtp_session->missed_count >= rtp_session->max_missed_packets) {
+				ret = -2;
+				goto end;
+			}
+		}
+
+		check = !bytes;
+		
+		if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_BREAK) || (bytes && bytes == 4 && *((int *)&rtp_session->recv_msg) == UINT_MAX)) {
 			switch_clear_flag_locked(rtp_session, SWITCH_RTP_FLAG_BREAK);
 			do_2833(rtp_session);
+			rtp_flush_read_buffer(rtp_session);
 			bytes = 0;
 			return_cng_frame();
 		}
@@ -1302,6 +1382,10 @@
 			continue;
 		}
 
+		if (bytes && rtp_session->recv_msg.header.m && rtp_session->recv_msg.header.pt != rtp_session->te) {
+			rtp_flush_read_buffer(rtp_session);
+		}
+
 		if (bytes && switch_test_flag(rtp_session, SWITCH_RTP_FLAG_AUTOADJ) && switch_sockaddr_get_port(rtp_session->from_addr)) {
 			if (++rtp_session->autoadj_tally >= 10) {
 				const char *tx_host;
@@ -1521,13 +1605,6 @@
 		}
 
 		if (check || (bytes && !rtp_session->timer.interval)) {
-			if (!bytes && rtp_session->max_missed_packets) {
-				if (++rtp_session->missed_count >= rtp_session->max_missed_packets) {
-					ret = -2;
-					goto end;
-				}
-			}
-
 			if (rtp_session->jb && (jb_frame = stfu_n_read_a_frame(rtp_session->jb))) {
 				memcpy(rtp_session->recv_msg.body, jb_frame->data, jb_frame->dlen);
 				if (jb_frame->plc) {
@@ -1620,6 +1697,10 @@
 	}
 	switch_mutex_unlock(rtp_session->dtmf_data.dtmf_mutex);
 
+	if (bytes) {
+		rtp_flush_read_buffer(rtp_session);
+	}
+
 	return bytes;
 }
 
@@ -1716,9 +1797,9 @@
 	frame->packet = &rtp_session->recv_msg;
 	frame->packetlen = bytes;
 	frame->source = __FILE__;
-	frame->flags |= SFF_RAW_RTP;
+	switch_set_flag(frame, SFF_RAW_RTP);
 	if (frame->payload == rtp_session->te) {
-		frame->flags |= SFF_RFC2833;
+		switch_set_flag(frame, SFF_RFC2833);
 	}
 	frame->timestamp = ntohl(rtp_session->recv_msg.header.ts);
 	frame->seq = (uint16_t) ntohs((u_short) rtp_session->recv_msg.header.seq);
@@ -1808,15 +1889,27 @@
 
 		rtp_session->send_msg.header.ts = htonl(rtp_session->ts);
 
+
 		if ((rtp_session->ts > (rtp_session->last_write_ts + (rtp_session->samples_per_interval * 10)))
 			|| rtp_session->ts == rtp_session->samples_per_interval) {
 			m++;
 		}
 
+		if (rtp_session->timer.interval && 
+			(rtp_session->timer.samplecount - rtp_session->last_write_samplecount) > rtp_session->samples_per_interval * 2) {
+			m++;
+		}
+
+		if (!rtp_session->timer.interval && 
+			((unsigned)((switch_timestamp_now() - rtp_session->last_write_timestamp))) > (rtp_session->ms_per_packet *2)) {
+			m++;
+		}
+
 		if (rtp_session->cn && payload != rtp_session->cng_pt) {
 			rtp_session->cn = 0;
 			m++;
 		}
+
 		send_msg->header.m = m ? 1 : 0;
 
 		memcpy(send_msg->body, data, datalen);
@@ -1972,7 +2065,10 @@
 
 		if (rtp_session->timer.interval) {
 			rtp_session->last_write_samplecount = rtp_session->timer.samplecount;
+		} else {
+			rtp_session->last_write_timestamp = (uint32_t) switch_timestamp_now();
 		}
+
 		rtp_session->last_write_ts = this_ts;
 	}
 
@@ -2105,7 +2201,7 @@
 	} else {
 		data = frame->data;
 		len = frame->datalen;
-		ts = (uint32_t) frame->timestamp;
+		ts = switch_test_flag(rtp_session, SWITCH_RTP_FLAG_RAW_WRITE) ? (uint32_t) frame->timestamp : 0;
 	}
 
 	return rtp_common_write(rtp_session, send_msg, data, len, payload, ts, &frame->flags);

Modified: freeswitch/branches/gmaruzz/src/switch_stun.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_stun.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_stun.c	Mon Dec 15 12:56:36 2008
@@ -428,6 +428,16 @@
 	return 1;
 }
 
+SWITCH_DECLARE(char *) switch_stun_host_lookup(const char *host, switch_memory_pool_t *pool)
+{
+	switch_sockaddr_t *addr = NULL;
+	char buf[30];
+	
+	switch_sockaddr_info_get(&addr, host, SWITCH_UNSPEC, 0, 0, pool);
+	return switch_core_strdup(pool, switch_str_nil(switch_get_addr(buf, sizeof(buf), addr)));
+	
+}
+
 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)
 {

Modified: freeswitch/branches/gmaruzz/src/switch_utils.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_utils.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_utils.c	Mon Dec 15 12:56:36 2008
@@ -654,7 +654,7 @@
 
 	for (start = str; *start; start++) {
 		/* find start of pattern in string */
-		for (; ((*start) && (toupper(*start) != toupper(*instr))); start++);
+		for (; ((*start) && (switch_toupper(*start) != switch_toupper(*instr))); start++);
 
 		if (!*start)
 			return NULL;
@@ -662,7 +662,7 @@
 		pptr = instr;
 		sptr = start;
 
-		while (toupper(*sptr) == toupper(*pptr)) {
+		while (switch_toupper(*sptr) == switch_toupper(*pptr)) {
 			sptr++;
 			pptr++;
 
@@ -1138,7 +1138,7 @@
 	char *c;
 	unsigned char counter = 0;
 
-	key = (char) toupper(key);
+	key = (char) switch_toupper(key);
 	for (c = RFC2833_CHARS; *c; c++) {
 		if (*c == key) {
 			return counter;
@@ -1507,6 +1507,251 @@
 	return s;
 }
 
+
+/* Written by Marc Espie, public domain */
+#define SWITCH_CTYPE_NUM_CHARS       256
+
+const short _switch_C_toupper_[1 + SWITCH_CTYPE_NUM_CHARS] = {
+	EOF,
+	0x00,	0x01,	0x02,	0x03,	0x04,	0x05,	0x06,	0x07,
+	0x08,	0x09,	0x0a,	0x0b,	0x0c,	0x0d,	0x0e,	0x0f,
+	0x10,	0x11,	0x12,	0x13,	0x14,	0x15,	0x16,	0x17,
+	0x18,	0x19,	0x1a,	0x1b,	0x1c,	0x1d,	0x1e,	0x1f,
+	0x20,	0x21,	0x22,	0x23,	0x24,	0x25,	0x26,	0x27,
+	0x28,	0x29,	0x2a,	0x2b,	0x2c,	0x2d,	0x2e,	0x2f,
+	0x30,	0x31,	0x32,	0x33,	0x34,	0x35,	0x36,	0x37,
+	0x38,	0x39,	0x3a,	0x3b,	0x3c,	0x3d,	0x3e,	0x3f,
+	0x40,	0x41,	0x42,	0x43,	0x44,	0x45,	0x46,	0x47,
+	0x48,	0x49,	0x4a,	0x4b,	0x4c,	0x4d,	0x4e,	0x4f,
+	0x50,	0x51,	0x52,	0x53,	0x54,	0x55,	0x56,	0x57,
+	0x58,	0x59,	0x5a,	0x5b,	0x5c,	0x5d,	0x5e,	0x5f,
+	0x60,	'A',	'B',	'C',	'D',	'E',	'F',	'G',
+	'H',	'I',	'J',	'K',	'L',	'M',	'N',	'O',
+	'P',	'Q',	'R',	'S',	'T',	'U',	'V',	'W',
+	'X',	'Y',	'Z',	0x7b,	0x7c,	0x7d,	0x7e,	0x7f,
+	0x80,	0x81,	0x82,	0x83,	0x84,	0x85,	0x86,	0x87,
+	0x88,	0x89,	0x8a,	0x8b,	0x8c,	0x8d,	0x8e,	0x8f,
+	0x90,	0x91,	0x92,	0x93,	0x94,	0x95,	0x96,	0x97,
+	0x98,	0x99,	0x9a,	0x9b,	0x9c,	0x9d,	0x9e,	0x9f,
+	0xa0,	0xa1,	0xa2,	0xa3,	0xa4,	0xa5,	0xa6,	0xa7,
+	0xa8,	0xa9,	0xaa,	0xab,	0xac,	0xad,	0xae,	0xaf,
+	0xb0,	0xb1,	0xb2,	0xb3,	0xb4,	0xb5,	0xb6,	0xb7,
+	0xb8,	0xb9,	0xba,	0xbb,	0xbc,	0xbd,	0xbe,	0xbf,
+	0xc0,	0xc1,	0xc2,	0xc3,	0xc4,	0xc5,	0xc6,	0xc7,
+	0xc8,	0xc9,	0xca,	0xcb,	0xcc,	0xcd,	0xce,	0xcf,
+	0xd0,	0xd1,	0xd2,	0xd3,	0xd4,	0xd5,	0xd6,	0xd7,
+	0xd8,	0xd9,	0xda,	0xdb,	0xdc,	0xdd,	0xde,	0xdf,
+	0xe0,	0xe1,	0xe2,	0xe3,	0xe4,	0xe5,	0xe6,	0xe7,
+	0xe8,	0xe9,	0xea,	0xeb,	0xec,	0xed,	0xee,	0xef,
+	0xf0,	0xf1,	0xf2,	0xf3,	0xf4,	0xf5,	0xf6,	0xf7,
+	0xf8,	0xf9,	0xfa,	0xfb,	0xfc,	0xfd,	0xfe,	0xff
+};
+
+const short *_switch_toupper_tab_ = _switch_C_toupper_;
+
+SWITCH_DECLARE(int) switch_toupper(int c)
+{
+	if ((unsigned int)c > 255)
+		return(c);
+	if (c < -1)
+		return EOF;
+	return((_switch_toupper_tab_ + 1)[c]);
+}
+
+const short _switch_C_tolower_[1 + SWITCH_CTYPE_NUM_CHARS] = {
+	EOF,
+	0x00,	0x01,	0x02,	0x03,	0x04,	0x05,	0x06,	0x07,
+	0x08,	0x09,	0x0a,	0x0b,	0x0c,	0x0d,	0x0e,	0x0f,
+	0x10,	0x11,	0x12,	0x13,	0x14,	0x15,	0x16,	0x17,
+	0x18,	0x19,	0x1a,	0x1b,	0x1c,	0x1d,	0x1e,	0x1f,
+	0x20,	0x21,	0x22,	0x23,	0x24,	0x25,	0x26,	0x27,
+	0x28,	0x29,	0x2a,	0x2b,	0x2c,	0x2d,	0x2e,	0x2f,
+	0x30,	0x31,	0x32,	0x33,	0x34,	0x35,	0x36,	0x37,
+	0x38,	0x39,	0x3a,	0x3b,	0x3c,	0x3d,	0x3e,	0x3f,
+	0x40,	'a',	'b',	'c',	'd',	'e',	'f',	'g',
+	'h',	'i',	'j',	'k',	'l',	'm',	'n',	'o',
+	'p',	'q',	'r',	's',	't',	'u',	'v',	'w',
+	'x',	'y',	'z',	0x5b,	0x5c,	0x5d,	0x5e,	0x5f,
+	0x60,	0x61,	0x62,	0x63,	0x64,	0x65,	0x66,	0x67,
+	0x68,	0x69,	0x6a,	0x6b,	0x6c,	0x6d,	0x6e,	0x6f,
+	0x70,	0x71,	0x72,	0x73,	0x74,	0x75,	0x76,	0x77,
+	0x78,	0x79,	0x7a,	0x7b,	0x7c,	0x7d,	0x7e,	0x7f,
+	0x80,	0x81,	0x82,	0x83,	0x84,	0x85,	0x86,	0x87,
+	0x88,	0x89,	0x8a,	0x8b,	0x8c,	0x8d,	0x8e,	0x8f,
+	0x90,	0x91,	0x92,	0x93,	0x94,	0x95,	0x96,	0x97,
+	0x98,	0x99,	0x9a,	0x9b,	0x9c,	0x9d,	0x9e,	0x9f,
+	0xa0,	0xa1,	0xa2,	0xa3,	0xa4,	0xa5,	0xa6,	0xa7,
+	0xa8,	0xa9,	0xaa,	0xab,	0xac,	0xad,	0xae,	0xaf,
+	0xb0,	0xb1,	0xb2,	0xb3,	0xb4,	0xb5,	0xb6,	0xb7,
+	0xb8,	0xb9,	0xba,	0xbb,	0xbc,	0xbd,	0xbe,	0xbf,
+	0xc0,	0xc1,	0xc2,	0xc3,	0xc4,	0xc5,	0xc6,	0xc7,
+	0xc8,	0xc9,	0xca,	0xcb,	0xcc,	0xcd,	0xce,	0xcf,
+	0xd0,	0xd1,	0xd2,	0xd3,	0xd4,	0xd5,	0xd6,	0xd7,
+	0xd8,	0xd9,	0xda,	0xdb,	0xdc,	0xdd,	0xde,	0xdf,
+	0xe0,	0xe1,	0xe2,	0xe3,	0xe4,	0xe5,	0xe6,	0xe7,
+	0xe8,	0xe9,	0xea,	0xeb,	0xec,	0xed,	0xee,	0xef,
+	0xf0,	0xf1,	0xf2,	0xf3,	0xf4,	0xf5,	0xf6,	0xf7,
+	0xf8,	0xf9,	0xfa,	0xfb,	0xfc,	0xfd,	0xfe,	0xff
+};
+
+const short *_switch_tolower_tab_ = _switch_C_tolower_;
+
+SWITCH_DECLARE(int) switch_tolower(int c)
+{
+	if ((unsigned int)c > 255)
+		return(c);
+	if (c < -1)
+		return EOF;
+	return((_switch_tolower_tab_ + 1)[c]);
+}
+
+/*
+ * Copyright (c) 1989 The Regents of the University of California.
+ * All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#undef _U
+#undef _L
+#undef _N
+#undef _S
+#undef _P
+#undef _C
+#undef _X
+#undef _B
+
+#define	_U	0x01
+#define	_L	0x02
+#define	_N	0x04
+#define	_S	0x08
+#define	_P	0x10
+#define	_C	0x20
+#define	_X	0x40
+#define	_B	0x80
+
+const int _switch_C_ctype_[1 + SWITCH_CTYPE_NUM_CHARS] = {
+	0,
+	_C,	_C,	_C,	_C,	_C,	_C,	_C,	_C,
+	_C,	_C|_S,	_C|_S,	_C|_S,	_C|_S,	_C|_S,	_C,	_C,
+	_C,	_C,	_C,	_C,	_C,	_C,	_C,	_C,
+	_C,	_C,	_C,	_C,	_C,	_C,	_C,	_C,
+   _S|_B,	_P,	_P,	_P,	_P,	_P,	_P,	_P,
+	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P,
+	_N,	_N,	_N,	_N,	_N,	_N,	_N,	_N,
+	_N,	_N,	_P,	_P,	_P,	_P,	_P,	_P,
+	_P,	_U|_X,	_U|_X,	_U|_X,	_U|_X,	_U|_X,	_U|_X,	_U,
+	_U,	_U,	_U,	_U,	_U,	_U,	_U,	_U,
+	_U,	_U,	_U,	_U,	_U,	_U,	_U,	_U,
+	_U,	_U,	_U,	_P,	_P,	_P,	_P,	_P,
+	_P,	_L|_X,	_L|_X,	_L|_X,	_L|_X,	_L|_X,	_L|_X,	_L,
+	_L,	_L,	_L,	_L,	_L,	_L,	_L,	_L,
+	_L,	_L,	_L,	_L,	_L,	_L,	_L,	_L,
+/* determine printability based on the IS0 8859 8-bit standard */
+	_L,	_L,	_L,	_P,	_P,	_P,	_P,	_C,
+
+	_C,	_C,	_C,	_C,	_C,	_C,	_C,	_C, /* 80 */
+	_C,	_C,	_C,	_C,	_C,	_C,	_C,	_C, /* 88 */
+	_C,	_C,	_C,	_C,	_C,	_C,	_C,	_C, /* 90 */
+	_C,	_C,	_C,	_C,	_C,	_C,	_C,	_C, /* 98 */
+	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P, /* A0 */
+	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P, /* A8 */
+	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P, /* B0 */
+	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P, /* B8 */
+	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P, /* C0 */
+	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P, /* C8 */
+	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P, /* D0 */
+	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P, /* D8 */
+	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P, /* E0 */
+	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P, /* E8 */
+	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P, /* F0 */
+	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P  /* F8 */
+};
+
+const int *_switch_ctype_ = _switch_C_ctype_;
+
+SWITCH_DECLARE(int) switch_isalnum(int c)
+{
+	return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char)c] & (_U|_L|_N)));
+}
+
+SWITCH_DECLARE(int) switch_isalpha(int c)
+{
+	return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char)c] & (_U|_L)));
+}
+
+SWITCH_DECLARE(int) switch_iscntrl(int c)
+{
+	return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char)c] & _C));
+}
+
+SWITCH_DECLARE(int) switch_isdigit(int c)
+{
+	return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char)c] & _N));
+}
+
+SWITCH_DECLARE(int) switch_isgraph(int c)
+{
+	return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char)c] & (_P|_U|_L|_N)));
+}
+
+SWITCH_DECLARE(int) switch_islower(int c)
+{
+	return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char)c] & _L));
+}
+
+SWITCH_DECLARE(int) switch_isprint(int c)
+{
+	return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char)c] & (_P|_U|_L|_N|_B)));
+}
+
+SWITCH_DECLARE(int) switch_ispunct(int c)
+{
+	return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char)c] & _P));
+}
+
+SWITCH_DECLARE(int) switch_isspace(int c)
+{
+	return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char)c] & _S));
+}
+
+SWITCH_DECLARE(int) switch_isupper(int c)
+{
+	return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char)c] & _U));
+}
+
+SWITCH_DECLARE(int) switch_isxdigit(int c)
+{
+	return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char)c] & (_N|_X)));
+}
+
 /* For Emacs:
  * Local Variables:
  * mode:c

Modified: freeswitch/branches/gmaruzz/src/switch_xml.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_xml.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_xml.c	Mon Dec 15 12:56:36 2008
@@ -1131,7 +1131,7 @@
 		} else { /*  child */
 			close(fds[0]);
 			dup2(fds[1], STDOUT_FILENO);
-			system(command);
+			switch_system(command, SWITCH_TRUE);
 			close(fds[1]);
 			exit(0);
 		}



More information about the Freeswitch-branches mailing list