[Freeswitch-branches] [commit] r2844 - in freeswitch/branches/mishehu: . build conf libs libs/codec/g726 libs/codec/g7xx libs/codec/gsm libs/codec/ilbc libs/codec/lpc10 libs/iax libs/libdingaling libs/libteletone mac/xcode/FreeSWITCH.xcodeproj src src/dotnet src/include src/mod/applications/mod_bridgecall src/mod/applications/mod_commands src/mod/applications/mod_conference src/mod/applications/mod_dptools src/mod/applications/mod_echo src/mod/applications/mod_ivrtest src/mod/applications/mod_playback src/mod/applications/mod_skel src/mod/asr_tts/mod_cepstral src/mod/codecs/mod_g711 src/mod/codecs/mod_gsm src/mod/codecs/mod_ilbc src/mod/codecs/mod_l16 src/mod/dialplans/mod_dialplan_xml src/mod/endpoints/mod_dingaling src/mod/endpoints/mod_exosip src/mod/endpoints/mod_iax src/mod/endpoints/mod_portaudio src/mod/endpoints/mod_sofia src/mod/endpoints/mod_wanpipe src/mod/endpoints/mod_woomera src/mod/event_handlers/mod_cdr src/mod/event_handlers/mod_event_socket src/mod/event_handlers/mod_xmpp_event src/mod/formats/mod_native_file src/mod/formats/mod_sndfile src/mod/languages/mod_mono src/mod/loggers/mod_console src/mod/loggers/mod_syslog src/mod/timers/mod_softtimer

Freeswitch SVN mishehu at freeswitch.org
Wed Sep 27 00:28:58 EDT 2006


Author: mishehu
Date: Wed Sep 27 00:28:54 2006
New Revision: 2844

Added:
   freeswitch/branches/mishehu/src/mod/formats/mod_native_file/
      - copied from r2843, /freeswitch/trunk/src/mod/formats/mod_native_file/
   freeswitch/branches/mishehu/src/mod/formats/mod_native_file/mod_native_file.c
      - copied unchanged from r2843, /freeswitch/trunk/src/mod/formats/mod_native_file/mod_native_file.c
   freeswitch/branches/mishehu/src/mod/formats/mod_native_file/mod_native_file.vcproj
      - copied unchanged from r2843, /freeswitch/trunk/src/mod/formats/mod_native_file/mod_native_file.vcproj
Modified:
   freeswitch/branches/mishehu/   (props changed)
   freeswitch/branches/mishehu/Freeswitch.sln
   freeswitch/branches/mishehu/Makefile.am
   freeswitch/branches/mishehu/Makefile.in
   freeswitch/branches/mishehu/build/buildlib.sh
   freeswitch/branches/mishehu/build/modmake.sh
   freeswitch/branches/mishehu/conf/freeswitch.xml
   freeswitch/branches/mishehu/libs/codec/g726/Makefile.am
   freeswitch/branches/mishehu/libs/codec/g726/Makefile.in
   freeswitch/branches/mishehu/libs/codec/g7xx/Makefile.am
   freeswitch/branches/mishehu/libs/codec/g7xx/Makefile.in
   freeswitch/branches/mishehu/libs/codec/gsm/   (props changed)
   freeswitch/branches/mishehu/libs/codec/gsm/Makefile.am
   freeswitch/branches/mishehu/libs/codec/gsm/Makefile.in
   freeswitch/branches/mishehu/libs/codec/ilbc/   (props changed)
   freeswitch/branches/mishehu/libs/codec/ilbc/Makefile.am
   freeswitch/branches/mishehu/libs/codec/ilbc/Makefile.in
   freeswitch/branches/mishehu/libs/codec/lpc10/Makefile.am
   freeswitch/branches/mishehu/libs/codec/lpc10/Makefile.in
   freeswitch/branches/mishehu/libs/iax/   (props changed)
   freeswitch/branches/mishehu/libs/libdingaling/   (props changed)
   freeswitch/branches/mishehu/libs/libteletone/   (props changed)
   freeswitch/branches/mishehu/libs/portaudio.build.sh
   freeswitch/branches/mishehu/mac/xcode/FreeSWITCH.xcodeproj/   (props changed)
   freeswitch/branches/mishehu/mac/xcode/FreeSWITCH.xcodeproj/project.pbxproj
   freeswitch/branches/mishehu/src/dotnet/FreeSwitch.NET.csproj
   freeswitch/branches/mishehu/src/include/switch_core.h
   freeswitch/branches/mishehu/src/mod/applications/mod_bridgecall/   (props changed)
   freeswitch/branches/mishehu/src/mod/applications/mod_commands/   (props changed)
   freeswitch/branches/mishehu/src/mod/applications/mod_conference/   (props changed)
   freeswitch/branches/mishehu/src/mod/applications/mod_dptools/   (props changed)
   freeswitch/branches/mishehu/src/mod/applications/mod_dptools/mod_dptools.c
   freeswitch/branches/mishehu/src/mod/applications/mod_echo/   (props changed)
   freeswitch/branches/mishehu/src/mod/applications/mod_ivrtest/   (props changed)
   freeswitch/branches/mishehu/src/mod/applications/mod_playback/   (props changed)
   freeswitch/branches/mishehu/src/mod/applications/mod_skel/   (props changed)
   freeswitch/branches/mishehu/src/mod/asr_tts/mod_cepstral/mod_cepstral.c
   freeswitch/branches/mishehu/src/mod/codecs/mod_g711/   (props changed)
   freeswitch/branches/mishehu/src/mod/codecs/mod_gsm/   (props changed)
   freeswitch/branches/mishehu/src/mod/codecs/mod_ilbc/   (props changed)
   freeswitch/branches/mishehu/src/mod/codecs/mod_l16/   (props changed)
   freeswitch/branches/mishehu/src/mod/dialplans/mod_dialplan_xml/   (props changed)
   freeswitch/branches/mishehu/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c
   freeswitch/branches/mishehu/src/mod/endpoints/mod_dingaling/   (props changed)
   freeswitch/branches/mishehu/src/mod/endpoints/mod_dingaling/mod_dingaling.c
   freeswitch/branches/mishehu/src/mod/endpoints/mod_exosip/   (props changed)
   freeswitch/branches/mishehu/src/mod/endpoints/mod_exosip/mod_exosip.c
   freeswitch/branches/mishehu/src/mod/endpoints/mod_iax/   (props changed)
   freeswitch/branches/mishehu/src/mod/endpoints/mod_portaudio/   (props changed)
   freeswitch/branches/mishehu/src/mod/endpoints/mod_sofia/mod_sofia.c
   freeswitch/branches/mishehu/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c
   freeswitch/branches/mishehu/src/mod/endpoints/mod_woomera/   (props changed)
   freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/basecdr.cpp
   freeswitch/branches/mishehu/src/mod/event_handlers/mod_event_socket/mod_event_socket.c
   freeswitch/branches/mishehu/src/mod/event_handlers/mod_xmpp_event/   (props changed)
   freeswitch/branches/mishehu/src/mod/formats/mod_sndfile/   (props changed)
   freeswitch/branches/mishehu/src/mod/languages/mod_mono/mod_mono.c
   freeswitch/branches/mishehu/src/mod/loggers/mod_console/   (props changed)
   freeswitch/branches/mishehu/src/mod/loggers/mod_syslog/   (props changed)
   freeswitch/branches/mishehu/src/mod/timers/mod_softtimer/   (props changed)
   freeswitch/branches/mishehu/src/mod/timers/mod_softtimer/mod_softtimer.c
   freeswitch/branches/mishehu/src/switch_buffer.c
   freeswitch/branches/mishehu/src/switch_core.c
   freeswitch/branches/mishehu/src/switch_ivr.c
   freeswitch/branches/mishehu/src/switch_rtp.c
   freeswitch/branches/mishehu/src/switch_xml.c

Log:
Fixed strncpy's in basecdr.cpp to operate properly and safely as intended.  Should speed up mod_cdr's operation as well, as there are less strlen() calls.

Modified: freeswitch/branches/mishehu/Freeswitch.sln
==============================================================================
--- freeswitch/branches/mishehu/Freeswitch.sln	(original)
+++ freeswitch/branches/mishehu/Freeswitch.sln	Wed Sep 27 00:28:54 2006
@@ -571,6 +571,16 @@
 		{101130D1-3EA6-4ED2-B65D-CEB5243A20ED} = {101130D1-3EA6-4ED2-B65D-CEB5243A20ED}
 	EndProjectSection
 EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_native_file", "src\mod\formats\mod_native_file\mod_native_file.vcproj", "{9254C4B0-6F60-42B6-BB3A-36D63FC001C7}"
+	ProjectSection(ProjectDependencies) = postProject
+		{202D7A4E-760D-4D0E-AFA1-D7459CED30FF} = {202D7A4E-760D-4D0E-AFA1-D7459CED30FF}
+		{F057DA7F-79E5-4B00-845C-EF446EF055E3} = {F057DA7F-79E5-4B00-845C-EF446EF055E3}
+		{F6C55D93-B927-4483-BB69-15AEF3DD2DFF} = {F6C55D93-B927-4483-BB69-15AEF3DD2DFF}
+		{101130D1-3EA6-4ED2-B65D-CEB5243A20ED} = {101130D1-3EA6-4ED2-B65D-CEB5243A20ED}
+	EndProjectSection
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FreeSwitch.NET", "src\dotnet\FreeSwitch.NET.csproj", "{251CAABC-16C3-4593-A491-603B908094E0}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Win32 = Debug|Win32
@@ -943,6 +953,12 @@
 		{FEA1EEF7-876F-48DE-88BF-C0E3E606D758}.Debug|Win32.Build.0 = Debug Passthrough|Win32
 		{FEA1EEF7-876F-48DE-88BF-C0E3E606D758}.Release|Win32.ActiveCfg = Release Passthrough|Win32
 		{FEA1EEF7-876F-48DE-88BF-C0E3E606D758}.Release|Win32.Build.0 = Release Passthrough|Win32
+		{9254C4B0-6F60-42B6-BB3A-36D63FC001C7}.Debug|Win32.ActiveCfg = Debug|Win32
+		{9254C4B0-6F60-42B6-BB3A-36D63FC001C7}.Debug|Win32.Build.0 = Debug|Win32
+		{9254C4B0-6F60-42B6-BB3A-36D63FC001C7}.Release|Win32.ActiveCfg = Release|Win32
+		{9254C4B0-6F60-42B6-BB3A-36D63FC001C7}.Release|Win32.Build.0 = Release|Win32
+		{251CAABC-16C3-4593-A491-603B908094E0}.Debug|Win32.ActiveCfg = Debug|Any CPU
+		{251CAABC-16C3-4593-A491-603B908094E0}.Release|Win32.ActiveCfg = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
@@ -964,6 +980,7 @@
 		{05515420-16DE-4E63-BE73-85BE85BA5142} = {9ADF1E48-2F5C-4ED7-A893-596259FABFE0}
 		{3D1EED36-A510-4EDB-B4D9-4E0F4A5EC2A8} = {9ADF1E48-2F5C-4ED7-A893-596259FABFE0}
 		{AFAC0568-7548-42D5-9F6A-8D3400A1E4F6} = {A5A27244-AD24-46E5-B01B-840CD296C91D}
+		{9254C4B0-6F60-42B6-BB3A-36D63FC001C7} = {A5A27244-AD24-46E5-B01B-840CD296C91D}
 		{78100236-7CEA-4948-96CC-E8ED3160329C} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78}
 		{E1794405-29D4-466D-9BE3-DD2344C2A663} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78}
 		{419AA391-5F3F-4BFE-A869-9D154D62A792} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78}

Modified: freeswitch/branches/mishehu/Makefile.am
==============================================================================
--- freeswitch/branches/mishehu/Makefile.am	(original)
+++ freeswitch/branches/mishehu/Makefile.am	Wed Sep 27 00:28:54 2006
@@ -3,8 +3,6 @@
 EXTRA_DIST =
 SUBDIRS = 
 AUTOMAKE_OPTS = gnu foreign
-AM_MAKE=`which gmake 2>/dev/null || which make 2>/dev/null || echo make`
-MAKE=$(AM_MAKE)
 NAME=freeswitch
 PREFIX=$(prefix)
 APR_CONFIG=$(prefix)/bin/apr-1-config
@@ -191,7 +189,7 @@
 	@./build/addenv.sh build/freeswitch.env CFLAGS "-Werror $(AM_CFLAGS)"
 	@./build/addenv.sh build/freeswitch.env CC "$(CC)"
 	@./build/addenv.sh build/freeswitch.env CFGARGS "$(AM_CFGARGS)"
-	@cd src/mod && for i in `cat ../../modules.conf | grep -v \#` ; do echo making $$i ; $(PWD)/build/modmake.sh $(PWD) $$i || exit 1; done
+	@cd src/mod && for i in `cat ../../modules.conf | grep -v \#` ; do echo making $$i ; $(PWD)/build/modmake.sh $(MAKE) $(PWD) $$i || exit 1; done
 	@rm -f build/freeswitch.env
 
 modclean:
@@ -199,7 +197,7 @@
 	@./build/addenv.sh build/freeswitch.env MAKE "$(MAKE)"
 	@./build/addenv.sh build/freeswitch.env CC "$(CC)"
 	@./build/addenv.sh build/freeswitch.env DYNAMIC_LIB_EXTEN "$(DYNAMIC_LIB_EXTEN)"
-	@cd src/mod && for i in `find . -type d -name mod_\*` ; do echo making clean $$i ; $(PWD)/build/modmake.sh $(PWD) $$i clean || exit 1; done
+	@cd src/mod && for i in `find . -type d -name mod_\*` ; do echo making clean $$i ; $(PWD)/build/modmake.sh $(MAKE) $(PWD) $$i clean || exit 1; done
 	@rm -f build/freeswitch.env
 
 everything: install install_mod
@@ -231,7 +229,7 @@
 	@./build/addenv.sh build/freeswitch.env LDFLAGS "$(AM_LDFLAGS) -lfreeswitch"
 	@./build/addenv.sh build/freeswitch.env CFLAGS "-Werror $(AM_CFLAGS)"
 	@./build/addenv.sh build/freeswitch.env CC "$(CC)"
-	@cd src/mod && for i in `cat ../../modules.conf | grep -v \#` ; do echo making install $$i ; $(PWD)/build/modmake.sh $(PWD) $$i install || exit 1; done
+	@cd src/mod && for i in `cat ../../modules.conf | grep -v \#` ; do echo making install $$i ; $(PWD)/build/modmake.sh $(MAKE) $(PWD) $$i install || exit 1; done
 	@rm -f build/freeswitch.env
 	@echo done
 

Modified: freeswitch/branches/mishehu/Makefile.in
==============================================================================
--- freeswitch/branches/mishehu/Makefile.in	(original)
+++ freeswitch/branches/mishehu/Makefile.in	Wed Sep 27 00:28:54 2006
@@ -243,8 +243,6 @@
 EXTRA_DIST = 
 SUBDIRS = 
 AUTOMAKE_OPTS = gnu foreign
-AM_MAKE = `which gmake 2>/dev/null || which make 2>/dev/null || echo make`
-MAKE = $(AM_MAKE)
 NAME = freeswitch
 PREFIX = $(prefix)
 APR_CONFIG = $(prefix)/bin/apr-1-config
@@ -1110,7 +1108,7 @@
 	@./build/addenv.sh build/freeswitch.env CFLAGS "-Werror $(AM_CFLAGS)"
 	@./build/addenv.sh build/freeswitch.env CC "$(CC)"
 	@./build/addenv.sh build/freeswitch.env CFGARGS "$(AM_CFGARGS)"
-	@cd src/mod && for i in `cat ../../modules.conf | grep -v \#` ; do echo making $$i ; $(PWD)/build/modmake.sh $(PWD) $$i || exit 1; done
+	@cd src/mod && for i in `cat ../../modules.conf | grep -v \#` ; do echo making $$i ; $(PWD)/build/modmake.sh $(MAKE) $(PWD) $$i || exit 1; done
 	@rm -f build/freeswitch.env
 
 modclean:
@@ -1118,7 +1116,7 @@
 	@./build/addenv.sh build/freeswitch.env MAKE "$(MAKE)"
 	@./build/addenv.sh build/freeswitch.env CC "$(CC)"
 	@./build/addenv.sh build/freeswitch.env DYNAMIC_LIB_EXTEN "$(DYNAMIC_LIB_EXTEN)"
-	@cd src/mod && for i in `find . -type d -name mod_\*` ; do echo making clean $$i ; $(PWD)/build/modmake.sh $(PWD) $$i clean || exit 1; done
+	@cd src/mod && for i in `find . -type d -name mod_\*` ; do echo making clean $$i ; $(PWD)/build/modmake.sh $(MAKE) $(PWD) $$i clean || exit 1; done
 	@rm -f build/freeswitch.env
 
 everything: install install_mod
@@ -1150,7 +1148,7 @@
 	@./build/addenv.sh build/freeswitch.env LDFLAGS "$(AM_LDFLAGS) -lfreeswitch"
 	@./build/addenv.sh build/freeswitch.env CFLAGS "-Werror $(AM_CFLAGS)"
 	@./build/addenv.sh build/freeswitch.env CC "$(CC)"
-	@cd src/mod && for i in `cat ../../modules.conf | grep -v \#` ; do echo making install $$i ; $(PWD)/build/modmake.sh $(PWD) $$i install || exit 1; done
+	@cd src/mod && for i in `cat ../../modules.conf | grep -v \#` ; do echo making install $$i ; $(PWD)/build/modmake.sh $(MAKE) $(PWD) $$i install || exit 1; done
 	@rm -f build/freeswitch.env
 	@echo done
 

Modified: freeswitch/branches/mishehu/build/buildlib.sh
==============================================================================
--- freeswitch/branches/mishehu/build/buildlib.sh	(original)
+++ freeswitch/branches/mishehu/build/buildlib.sh	Wed Sep 27 00:28:54 2006
@@ -13,9 +13,9 @@
     . $root/build/freeswitch.env
 fi
 
-if [ -z $MAKE ] ; then
+if [ -z "$MAKE" ] ; then
     make=`which gmake 2>/dev/null`
-    if [ -z $MAKE ] ; then
+    if [ -z "$MAKE" ] ; then
 	make=make
     fi
 fi
@@ -23,7 +23,7 @@
 install=
 base=http://svn.freeswitch.org/downloads/libs
 
-if [ ! -z $1 ] && [ $1 = install ] ; then
+if [ ! -z "$1" ] && [ "$1" = install ] ; then
     install=1
     shift
 fi
@@ -45,7 +45,7 @@
 
     if [ ! -f $tar ] ; then
 	rm -fr $uncompressed
-	wget $base/$tar
+	wget $base/$tar || ftp $base/$tar
 	if [ ! -f $tar ] ; then
 	    echo cannot find $tar
 	    exit

Modified: freeswitch/branches/mishehu/build/modmake.sh
==============================================================================
--- freeswitch/branches/mishehu/build/modmake.sh	(original)
+++ freeswitch/branches/mishehu/build/modmake.sh	Wed Sep 27 00:28:54 2006
@@ -1,4 +1,7 @@
 #!/bin/sh
+
+make=$1
+shift
 pwd=$1
 shift
 mod=$1
@@ -8,14 +11,8 @@
     . $pwd/build/freeswitch.env
 fi
 
-make=`which gmake`
-
-if [ -z $make ] ; then
-    make=`which make`
-fi
-
 end=`echo $mod | sed "s/^.*\///g"`
-if [ -z $end ] ; then
+if [ -z "$end" ] ; then
     end=$mod
 fi
 

Modified: freeswitch/branches/mishehu/conf/freeswitch.xml
==============================================================================
--- freeswitch/branches/mishehu/conf/freeswitch.xml	(original)
+++ freeswitch/branches/mishehu/conf/freeswitch.xml	Wed Sep 27 00:28:54 2006
@@ -112,7 +112,7 @@
         <param name="codec-prefs" value="PCMU at 20i"/>
         <param name="codec-ms" value="20"/>
         <param name="use-rtp-timer" value="true"/>
-        <param name="rtp-timer-name" value="thread_soft"/>
+        <param name="rtp-timer-name" value="soft"/>
         <param name="rtp-ip" value="192.168.1.20"/>
         <param name="sip-ip" value="192.168.1.20"/>
         <!-- optional ; -->
@@ -476,6 +476,12 @@
   </section>
 
   <section name="directory" description="User Directory">
+    <domain name="mydomain.com">
+      <user id="1000">
+	<param name="password" value="mypass"/>
+	<param name="mypref" value="myval"/>
+	</user>
+    </domain>
   </section>
 
 </document>

Modified: freeswitch/branches/mishehu/libs/codec/g726/Makefile.am
==============================================================================
--- freeswitch/branches/mishehu/libs/codec/g726/Makefile.am	(original)
+++ freeswitch/branches/mishehu/libs/codec/g726/Makefile.am	Wed Sep 27 00:28:54 2006
@@ -1,7 +1,6 @@
 EXTRA_DIST =
 SUBDIRS = 
 AUTOMAKE_OPTS= gnu
-MAKE=gmake
 NAME=libg726
 
 AM_CC=gcc

Modified: freeswitch/branches/mishehu/libs/codec/g726/Makefile.in
==============================================================================
--- freeswitch/branches/mishehu/libs/codec/g726/Makefile.in	(original)
+++ freeswitch/branches/mishehu/libs/codec/g726/Makefile.in	Wed Sep 27 00:28:54 2006
@@ -202,7 +202,6 @@
 EXTRA_DIST = 
 SUBDIRS = 
 AUTOMAKE_OPTS = gnu
-MAKE = gmake
 NAME = libg726
 AM_CC = gcc
 AM_CFLAGS = -Wall -O3 -funroll-loops

Modified: freeswitch/branches/mishehu/libs/codec/g7xx/Makefile.am
==============================================================================
--- freeswitch/branches/mishehu/libs/codec/g7xx/Makefile.am	(original)
+++ freeswitch/branches/mishehu/libs/codec/g7xx/Makefile.am	Wed Sep 27 00:28:54 2006
@@ -1,6 +1,5 @@
 AM_CFLAGS	= -I./src/include -fPIC -O3 -Dsingle -funroll-loops -fomit-frame-pointer
 AUTOMAKE_OPTS	= gnu
-MAKE		= gmake
 NAME		= libg7xx
 lib_LTLIBRARIES		= libg7xx.la
 libg7xx_la_SOURCES	= src/g711.c src/g722_decode.c src/g722_encode.c src/g726.c

Modified: freeswitch/branches/mishehu/libs/codec/g7xx/Makefile.in
==============================================================================
--- freeswitch/branches/mishehu/libs/codec/g7xx/Makefile.in	(original)
+++ freeswitch/branches/mishehu/libs/codec/g7xx/Makefile.in	Wed Sep 27 00:28:54 2006
@@ -193,7 +193,6 @@
 target_alias = @target_alias@
 AM_CFLAGS = -I./src/include -fPIC -O3 -Dsingle -funroll-loops -fomit-frame-pointer
 AUTOMAKE_OPTS = gnu
-MAKE = gmake
 NAME = libg7xx
 lib_LTLIBRARIES = libg7xx.la
 libg7xx_la_SOURCES = src/g711.c src/g722_decode.c src/g722_encode.c src/g726.c

Modified: freeswitch/branches/mishehu/libs/codec/gsm/Makefile.am
==============================================================================
--- freeswitch/branches/mishehu/libs/codec/gsm/Makefile.am	(original)
+++ freeswitch/branches/mishehu/libs/codec/gsm/Makefile.am	Wed Sep 27 00:28:54 2006
@@ -1,7 +1,6 @@
 EXTRA_DIST =
 SUBDIRS = 
 AUTOMAKE_OPTS= gnu
-MAKE=gmake
 NAME=libgsm
 
 AM_CC=gcc

Modified: freeswitch/branches/mishehu/libs/codec/gsm/Makefile.in
==============================================================================
--- freeswitch/branches/mishehu/libs/codec/gsm/Makefile.in	(original)
+++ freeswitch/branches/mishehu/libs/codec/gsm/Makefile.in	Wed Sep 27 00:28:54 2006
@@ -204,7 +204,6 @@
 EXTRA_DIST = 
 SUBDIRS = 
 AUTOMAKE_OPTS = gnu
-MAKE = gmake
 NAME = libgsm
 AM_CC = gcc
 AM_CFLAGS = -I./inc -DNeedFunctionPrototypes=1 -funroll-loops  -fPIC -DSASR -DNDEBUG -DWAV49

Modified: freeswitch/branches/mishehu/libs/codec/ilbc/Makefile.am
==============================================================================
--- freeswitch/branches/mishehu/libs/codec/ilbc/Makefile.am	(original)
+++ freeswitch/branches/mishehu/libs/codec/ilbc/Makefile.am	Wed Sep 27 00:28:54 2006
@@ -1,7 +1,6 @@
 EXTRA_DIST =
 SUBDIRS = 
 AUTOMAKE_OPTS= gnu
-MAKE=gmake
 NAME=libilbc
 
 AM_CC=gcc

Modified: freeswitch/branches/mishehu/libs/codec/ilbc/Makefile.in
==============================================================================
--- freeswitch/branches/mishehu/libs/codec/ilbc/Makefile.in	(original)
+++ freeswitch/branches/mishehu/libs/codec/ilbc/Makefile.in	Wed Sep 27 00:28:54 2006
@@ -209,7 +209,6 @@
 EXTRA_DIST = 
 SUBDIRS = 
 AUTOMAKE_OPTS = gnu
-MAKE = gmake
 NAME = libilbc
 AM_CC = gcc
 AM_CFLAGS = -Wall -O3 -funroll-loops

Modified: freeswitch/branches/mishehu/libs/codec/lpc10/Makefile.am
==============================================================================
--- freeswitch/branches/mishehu/libs/codec/lpc10/Makefile.am	(original)
+++ freeswitch/branches/mishehu/libs/codec/lpc10/Makefile.am	Wed Sep 27 00:28:54 2006
@@ -1,7 +1,6 @@
 EXTRA_DIST =
 SUBDIRS = 
 AUTOMAKE_OPTS= gnu
-MAKE=gmake
 NAME=libg7xx
 
 AM_CC=gcc

Modified: freeswitch/branches/mishehu/libs/codec/lpc10/Makefile.in
==============================================================================
--- freeswitch/branches/mishehu/libs/codec/lpc10/Makefile.in	(original)
+++ freeswitch/branches/mishehu/libs/codec/lpc10/Makefile.in	Wed Sep 27 00:28:54 2006
@@ -216,7 +216,6 @@
 EXTRA_DIST = 
 SUBDIRS = 
 AUTOMAKE_OPTS = gnu
-MAKE = gmake
 NAME = liblpc10
 AM_CC = gcc
 AM_CFLAGS = -Wall -O3 -funroll-loops

Modified: freeswitch/branches/mishehu/libs/portaudio.build.sh
==============================================================================
--- freeswitch/branches/mishehu/libs/portaudio.build.sh	(original)
+++ freeswitch/branches/mishehu/libs/portaudio.build.sh	Wed Sep 27 00:28:54 2006
@@ -1,3 +1,17 @@
+patch <<__EOF__
+--- configure.orig	2006-09-24 23:56:36.000000000 -0700
++++ configure	2006-09-24 23:57:32.000000000 -0700
+@@ -1886,7 +1886,7 @@
+ 	OTHER_OBJS="pa_mac_core/pa_mac_core.o";
+ 	LIBS="-framework CoreAudio -lm";
+ 	PADLL="libportaudio.dylib";
+-	SHARED_FLAGS="-framework CoreAudio -dynamiclib";
++	SHARED_FLAGS="-framework CoreAudio -dynamiclib -install_name \\\$(PREFIX)/lib/\\\$(PADLL)";
+ 	;;
+ 
+   mingw* )
+__EOF__
+
 arch=`uname -m`
 
 opts=""

Modified: freeswitch/branches/mishehu/mac/xcode/FreeSWITCH.xcodeproj/project.pbxproj
==============================================================================
--- freeswitch/branches/mishehu/mac/xcode/FreeSWITCH.xcodeproj/project.pbxproj	(original)
+++ freeswitch/branches/mishehu/mac/xcode/FreeSWITCH.xcodeproj/project.pbxproj	Wed Sep 27 00:28:54 2006
@@ -65,6 +65,8 @@
 /* End PBXAggregateTarget section */
 
 /* Begin PBXBuildFile section */
+		AE21414E0AC7BEBF00524EAE /* pcre.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D36500F10A76BE9400C47A76 /* pcre.framework */; };
+		AE21414F0AC7BEC100524EAE /* pcre.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D36500F10A76BE9400C47A76 /* pcre.framework */; };
 		D30151710A76EC9F00117F59 /* speex_bits.h in Headers */ = {isa = PBXBuildFile; fileRef = D30151670A76EC9F00117F59 /* speex_bits.h */; settings = {ATTRIBUTES = (Public, ); }; };
 		D30151720A76EC9F00117F59 /* speex_callbacks.h in Headers */ = {isa = PBXBuildFile; fileRef = D30151680A76EC9F00117F59 /* speex_callbacks.h */; settings = {ATTRIBUTES = (Public, ); }; };
 		D30151730A76EC9F00117F59 /* speex_config_types.h in Headers */ = {isa = PBXBuildFile; fileRef = D30151690A76EC9F00117F59 /* speex_config_types.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -1199,7 +1201,7 @@
 			isa = PBXContainerItemProxy;
 			containerPortal = 08FB7793FE84155DC02AAC07 /* Project object */;
 			proxyType = 1;
-			remoteGlobalIDString = D36500F00A76BE9400C47A76 /* pcre */;
+			remoteGlobalIDString = D36500F00A76BE9400C47A76;
 			remoteInfo = pcre;
 		};
 		D36501760A76C28200C47A76 /* PBXContainerItemProxy */ = {
@@ -1937,8 +1939,8 @@
 		D3BC330D0A76A82A00DE971E /* mod_softtimer.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = mod_softtimer.c; path = ../../src/mod/timers/mod_softtimer/mod_softtimer.c; sourceTree = SOURCE_ROOT; };
 		D3BC33110A76A83D00DE971E /* mod_softtimer.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.objfile"; includeInIndex = 0; path = mod_softtimer.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
 		D3BC331E0A76A87E00DE971E /* mod_g711.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.objfile"; includeInIndex = 0; path = mod_g711.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
-		D3BC331F0A76A8B200DE971E /* g711.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = g711.c; path = ../../src/mod/codecs/mod_g711/g711.c; sourceTree = SOURCE_ROOT; };
-		D3BC33200A76A8B200DE971E /* g711.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = g711.h; path = ../../src/mod/codecs/mod_g711/g711.h; sourceTree = SOURCE_ROOT; };
+		D3BC331F0A76A8B200DE971E /* g711.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = g711.c; path = ../../libs/codec/g7xx/src/g711.c; sourceTree = SOURCE_ROOT; };
+		D3BC33200A76A8B200DE971E /* g711.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = g711.h; path = ../../libs/codec/g7xx/src/include/g7xx/g711.h; sourceTree = SOURCE_ROOT; };
 		D3BC33210A76A8B200DE971E /* mod_g711.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = mod_g711.c; path = ../../src/mod/codecs/mod_g711/mod_g711.c; sourceTree = SOURCE_ROOT; };
 		D3BC333E0A76A9CD00DE971E /* mod_conference.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = mod_conference.c; path = ../../src/mod/applications/mod_conference/mod_conference.c; sourceTree = SOURCE_ROOT; };
 		D3BC33420A76A9D900DE971E /* mod_conference.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.objfile"; includeInIndex = 0; path = mod_conference.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -2665,6 +2667,7 @@
 				D36502E30A76CB1000C47A76 /* teletone.framework in Frameworks */,
 				D3BF926D0A77F7FA00BEDBC8 /* System.framework in Frameworks */,
 				D3E3E9CC0A786E4600DBE6EB /* bundle1.o in Frameworks */,
+				AE21414E0AC7BEBF00524EAE /* pcre.framework in Frameworks */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -2790,6 +2793,7 @@
 				D3BC32D30A76A68400DE971E /* libfreeswitch.framework in Frameworks */,
 				D3BF92600A77F7FA00BEDBC8 /* System.framework in Frameworks */,
 				D3E3E9BF0A786E4600DBE6EB /* bundle1.o in Frameworks */,
+				AE21414F0AC7BEC100524EAE /* pcre.framework in Frameworks */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -9209,6 +9213,7 @@
 				GCC_ENABLE_FIX_AND_CONTINUE = NO;
 				GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
 				GCC_MODEL_TUNING = G5;
+				HEADER_SEARCH_PATHS = ../../libs/codec/g7xx/src/include;
 				INSTALL_PATH = "$(FREESWITCH_INSTALL_PREFIX)/freeswitch/mod";
 				KEEP_PRIVATE_EXTERNS = NO;
 				MACH_O_TYPE = mh_bundle;

Modified: freeswitch/branches/mishehu/src/dotnet/FreeSwitch.NET.csproj
==============================================================================
--- freeswitch/branches/mishehu/src/dotnet/FreeSwitch.NET.csproj	(original)
+++ freeswitch/branches/mishehu/src/dotnet/FreeSwitch.NET.csproj	Wed Sep 27 00:28:54 2006
@@ -18,19 +18,23 @@
     <DebugSymbols>true</DebugSymbols>
     <DebugType>full</DebugType>
     <Optimize>false</Optimize>
-    <OutputPath>bin\Debug\</OutputPath>
+    <OutputPath>..\..\debug\</OutputPath>
     <DefineConstants>DEBUG;TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+    <NoWarn>0649,0169</NoWarn>
+    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     <DebugType>pdbonly</DebugType>
     <Optimize>true</Optimize>
-    <OutputPath>bin\Release\</OutputPath>
+    <OutputPath>..\..\release\</OutputPath>
     <DefineConstants>TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
+    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
+    <NoWarn>0649,0169</NoWarn>
   </PropertyGroup>
   <ItemGroup>
     <Reference Include="System" />

Modified: freeswitch/branches/mishehu/src/include/switch_core.h
==============================================================================
--- freeswitch/branches/mishehu/src/include/switch_core.h	(original)
+++ freeswitch/branches/mishehu/src/include/switch_core.h	Wed Sep 27 00:28:54 2006
@@ -283,7 +283,7 @@
   \brief determine if the session's state machine is running
   \param session the session on which to check
 */
-SWITCH_DECLARE(unsigned int) switch_core_session_runing(switch_core_session_t *session);
+SWITCH_DECLARE(unsigned int) switch_core_session_running(switch_core_session_t *session);
 
 /*! 
   \brief Allocate memory from the main pool with no intention of returning it

Modified: freeswitch/branches/mishehu/src/mod/applications/mod_dptools/mod_dptools.c
==============================================================================
--- freeswitch/branches/mishehu/src/mod/applications/mod_dptools/mod_dptools.c	(original)
+++ freeswitch/branches/mishehu/src/mod/applications/mod_dptools/mod_dptools.c	Wed Sep 27 00:28:54 2006
@@ -34,6 +34,21 @@
 static const char modname[] = "mod_dptools";
 
 
+static void transfer_function(switch_core_session_t *session, char *data)
+{
+	int argc;
+	char *argv[4] = {0};
+	char *mydata;
+
+	if ((mydata = switch_core_session_strdup(session, data))) {
+		if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) >= 1) {
+			switch_ivr_session_transfer(session, argv[0], argv[1], argv[2]);
+		} else {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No extension specified.\n");
+		}
+	}
+}
+
 static void sleep_function(switch_core_session_t *session, char *data)
 {
 
@@ -159,13 +174,22 @@
 	/* next */ &strftime_application_interface
 };
 
+static const switch_application_interface_t transfer_application_interface = {
+	/*.interface_name */ "transfer",
+	/*.application_function */ transfer_function,
+	/* long_desc */ "Immediatly transfer the calling channel to a new extension",
+	/* short_desc */ "Transfer a channel",
+	/* syntax */ "<exten> [<dialplan> <context>]",
+	/* next */ &sleep_application_interface
+};
+
 static const switch_loadable_module_interface_t mod_dptools_module_interface = {
 	/*.module_name = */ modname,
 	/*.endpoint_interface = */ NULL,
 	/*.timer_interface = */ NULL,
 	/*.dialplan_interface = */ NULL,
 	/*.codec_interface = */ NULL,
-	/*.application_interface */ &sleep_application_interface,
+	/*.application_interface */ &transfer_application_interface,
 	/*.api_interface */ &dptools_api_interface
 };
 

Modified: freeswitch/branches/mishehu/src/mod/asr_tts/mod_cepstral/mod_cepstral.c
==============================================================================
--- freeswitch/branches/mishehu/src/mod/asr_tts/mod_cepstral/mod_cepstral.c	(original)
+++ freeswitch/branches/mishehu/src/mod/asr_tts/mod_cepstral/mod_cepstral.c	Wed Sep 27 00:28:54 2006
@@ -215,6 +215,14 @@
 	cepstral->done = 0;
 	
 	cepstral->tts_stream = NULL;
+
+	if (cepstral->audio_buffer) {
+		switch_byte_t data[1280];
+		memset(data, 255, sizeof(data));
+		switch_mutex_lock(cepstral->audio_lock);
+		switch_buffer_write(cepstral->audio_buffer, data, sizeof(data));
+		switch_mutex_unlock(cepstral->audio_lock);
+	}
 	
 	if (!strncasecmp(text, fp, len)) {
 		text += len;

Modified: freeswitch/branches/mishehu/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c
==============================================================================
--- freeswitch/branches/mishehu/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c	(original)
+++ freeswitch/branches/mishehu/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c	Wed Sep 27 00:28:54 2006
@@ -274,7 +274,14 @@
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Processing %s->%s!\n", caller_profile->caller_id_name,
 					  caller_profile->destination_number);
 	
-	snprintf(params, sizeof(params), "context=%s&dest=%s", caller_profile->context, caller_profile->destination_number);
+	snprintf(params, sizeof(params), "context=%s&dest=%s&cid_name=%s&cid_num=%s&netaddr=%s&ani=%s&ani2=%s&rdnis=%s&source=%s&chan_name=%s&uuid=%s", 
+			caller_profile->context, caller_profile->destination_number,
+			caller_profile->caller_id_name, caller_profile->caller_id_number,
+			caller_profile->network_addr?caller_profile->network_addr:"", 
+			caller_profile->ani?caller_profile->ani:"", 
+			caller_profile->ani2?caller_profile->ani2:"",
+			caller_profile->rdnis?caller_profile->rdnis:"", 
+			caller_profile->source, caller_profile->chan_name, caller_profile->uuid);
 
 	if (switch_xml_locate("dialplan", NULL, NULL, NULL, &xml, &cfg, params) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of dialplan failed\n");
@@ -286,6 +293,7 @@
 		if (!(xcontext = switch_xml_find_child(cfg, "context", "name", "global"))) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "context %s not found\n", context);
 			switch_channel_hangup(channel, SWITCH_CAUSE_MESSAGE_TYPE_NONEXIST);
+			switch_xml_free(xml);
 			return NULL;
 		}
 	}

Modified: freeswitch/branches/mishehu/src/mod/endpoints/mod_dingaling/mod_dingaling.c
==============================================================================
--- freeswitch/branches/mishehu/src/mod/endpoints/mod_dingaling/mod_dingaling.c	(original)
+++ freeswitch/branches/mishehu/src/mod/endpoints/mod_dingaling/mod_dingaling.c	Wed Sep 27 00:28:54 2006
@@ -177,28 +177,19 @@
 static switch_status_t load_config(void);
 
 
-static void terminate_session(switch_core_session_t **session, switch_call_cause_t cause)
+static void terminate_session(switch_core_session_t **session, int line, switch_call_cause_t cause)
 {
 	if (*session) {
 		switch_channel_t *channel = switch_core_session_get_channel(*session);
 		switch_channel_state_t state = switch_channel_get_state(channel);
 		struct private_object *tech_pvt = NULL;
-			
+		
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Terminate called from line %d state=%s\n", line, switch_channel_state_name(state));
+ 
 		tech_pvt = switch_core_session_get_private(*session);
 
-		if (tech_pvt && tech_pvt->dlsession) {
-			if (!switch_test_flag(tech_pvt, TFLAG_TERM)) {
-				ldl_session_terminate(tech_pvt->dlsession);
-				switch_set_flag_locked(tech_pvt, TFLAG_TERM);
-			}
-			ldl_session_destroy(&tech_pvt->dlsession);
-		}
 
-		if (state > CS_INIT && state < CS_HANGUP) {
-			switch_channel_hangup(channel, cause);
-		}
-		
-		if (!switch_core_session_runing(*session)) {
+		if (state < CS_INIT || !switch_core_session_running(*session)) {
 			if (state > CS_INIT && state < CS_HANGUP) {
 				channel_on_hangup(*session);
 			}
@@ -207,8 +198,28 @@
 				ldl_session_set_private(tech_pvt->dlsession, NULL);
 			}
 			switch_core_session_destroy(session);
+		} else if (tech_pvt){
+			if (switch_test_flag(tech_pvt, TFLAG_TERM)) {
+				/*once is enough*/
+				return;
+			}
+
+			if (tech_pvt->dlsession) {
+				if (!switch_test_flag(tech_pvt, TFLAG_TERM)) {
+					ldl_session_terminate(tech_pvt->dlsession);
+				}
+				ldl_session_destroy(&tech_pvt->dlsession);
+			}
+			switch_set_flag_locked(tech_pvt, TFLAG_TERM);
 		}
+
+		if (state < CS_HANGUP) {
+			switch_channel_hangup(channel, cause);
+		}
+		
+		*session = NULL;
 	}
+
 }
 
 static void dl_logger(char *file, const char *func, int line, int level, char *fmt, ...)
@@ -474,7 +485,7 @@
 	memset(payloads, 0, sizeof(payloads));
 	switch_set_flag_locked(tech_pvt, TFLAG_DO_CAND);
 	if (!get_codecs(tech_pvt)) {
-		terminate_session(&tech_pvt->session, SWITCH_CAUSE_INCOMPATIBLE_DESTINATION);
+		terminate_session(&tech_pvt->session, __LINE__, SWITCH_CAUSE_INCOMPATIBLE_DESTINATION);
 		switch_set_flag_locked(tech_pvt, TFLAG_BYE);
 		switch_clear_flag_locked(tech_pvt, TFLAG_IO);
 		return 0;
@@ -522,6 +533,12 @@
 	switch_time_t now;
 	unsigned int elapsed;
 
+	if (switch_core_session_read_lock(session) != SWITCH_STATUS_SUCCESS) {
+		/* too late */
+		return NULL;
+	}
+
+
 	tech_pvt = switch_core_session_get_private(session);
 	assert(tech_pvt != NULL);
 
@@ -564,13 +581,13 @@
 			}
 		}
 		if (elapsed > 60000) {
-			terminate_session(&tech_pvt->session, SWITCH_CAUSE_NORMAL_CLEARING);
+			terminate_session(&tech_pvt->session,  __LINE__, SWITCH_CAUSE_NORMAL_CLEARING);
 			switch_set_flag_locked(tech_pvt, TFLAG_BYE);
 			switch_clear_flag_locked(tech_pvt, TFLAG_IO);
-			return NULL;
+			goto done;
 		}
 		if (switch_test_flag(tech_pvt, TFLAG_BYE) || ! switch_test_flag(tech_pvt, TFLAG_IO)) {
-			return NULL;
+			goto done;
 		}
 		switch_yield(1000);
 		//printf("WAIT %s %d %d %d %d\n", switch_channel_get_name(channel), switch_test_flag(tech_pvt, TFLAG_TRANSPORT), switch_test_flag(tech_pvt, TFLAG_CODEC_READY), switch_test_flag(tech_pvt, TFLAG_RTP_READY), switch_test_flag(tech_pvt, TFLAG_ANSWER));
@@ -594,10 +611,14 @@
 		switch_core_session_thread_launch(session);
 	}
 	switch_channel_set_state(channel, CS_INIT);
-	return NULL;
+	goto done;
 	
  out:
-	terminate_session(&session, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+	terminate_session(&session,  __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+ done:
+	if (session) {
+		switch_core_session_rwunlock(session);
+	}
 	return NULL;
 }
 
@@ -875,7 +896,7 @@
 	switch_clear_flag_locked(tech_pvt, TFLAG_READING);
 
 	if (switch_test_flag(tech_pvt, TFLAG_BYE)) {
-		terminate_session(&session, SWITCH_CAUSE_NORMAL_CLEARING);
+		terminate_session(&session,  __LINE__, SWITCH_CAUSE_NORMAL_CLEARING);
 		return SWITCH_STATUS_FALSE;
 	}
 
@@ -908,7 +929,7 @@
 
 
 	if (switch_test_flag(tech_pvt, TFLAG_BYE)) {
-		terminate_session(&session, SWITCH_CAUSE_NORMAL_CLEARING);
+		terminate_session(&session,  __LINE__, SWITCH_CAUSE_NORMAL_CLEARING);
 		return SWITCH_STATUS_FALSE;
 	}
 
@@ -1099,7 +1120,7 @@
 			*callto++ = '\0';
 		} else {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Invalid URL!\n");
-			terminate_session(new_session, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+			terminate_session(new_session,  __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
 			return SWITCH_STATUS_GENERR;
 		}
 		
@@ -1110,17 +1131,17 @@
 		if ((mdl_profile = switch_core_hash_find(globals.profile_hash, profile_name))) {
 			if (!ldl_handle_ready(mdl_profile->handle)) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Doh! we are not logged in yet!\n");
-				terminate_session(new_session, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+				terminate_session(new_session,  __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
 				return SWITCH_STATUS_GENERR;
 			}
 			if (!(full_id = ldl_handle_probe(mdl_profile->handle, callto, idbuf, sizeof(idbuf)))) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Unknown Recipient!\n");
-				terminate_session(new_session, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+				terminate_session(new_session,  __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
 				return SWITCH_STATUS_GENERR;
 			}
 		} else {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Unknown Profile!\n");
-			terminate_session(new_session, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+			terminate_session(new_session,  __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
 			return SWITCH_STATUS_GENERR;
 		}
 		
@@ -1140,7 +1161,7 @@
 			tech_pvt->dnis = switch_core_session_strdup(*new_session, dnis);
 		} else {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n");
-			terminate_session(new_session, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+			terminate_session(new_session,  __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
 			return SWITCH_STATUS_GENERR;
 		}
 
@@ -1155,7 +1176,7 @@
 			tech_pvt->caller_profile = caller_profile;
 		} else {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Doh! no caller profile\n");
-			terminate_session(new_session, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+			terminate_session(new_session,  __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
 			return SWITCH_STATUS_GENERR;
 		}
 
@@ -1172,7 +1193,7 @@
 		ldl_session_set_value(dlsession, "caller_id_number", outbound_profile->caller_id_number);
 		tech_pvt->dlsession = dlsession;
 		if (!get_codecs(tech_pvt)) {
-			terminate_session(new_session, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+			terminate_session(new_session,  __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
             return SWITCH_STATUS_GENERR;
 		}
 		//tech_pvt->desc_id = ldl_session_describe(dlsession, NULL, 0, LDL_DESCRIPTION_INITIATE);
@@ -1535,12 +1556,14 @@
 	switch_channel_t *channel = NULL;
     struct private_object *tech_pvt = NULL;
 	switch_event_t *event;
-
+	ldl_status status = LDL_STATUS_SUCCESS;
+	
 	assert(handle != NULL);
 
 	if (!(profile = ldl_handle_get_private(handle))) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ERROR NO PROFILE!\n");
-		return LDL_STATUS_FALSE;
+		status = LDL_STATUS_FALSE;
+		goto done;
 	}
 
 	if (!dlsession) {
@@ -1577,7 +1600,8 @@
 			break;
 			
 		}
-		return LDL_STATUS_SUCCESS;
+		status = LDL_STATUS_SUCCESS;
+		goto done;
 	}
 	
 
@@ -1587,21 +1611,24 @@
 
 		channel = switch_core_session_get_channel(session);
 		assert(channel != NULL);
-
+		
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "using Existing session for %s\n", ldl_session_get_id(dlsession));
 
 		if (switch_channel_get_state(channel) >= CS_HANGUP) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Call %s is already over\n", switch_channel_get_name(channel));
-			return LDL_STATUS_FALSE;
+			status = LDL_STATUS_FALSE;
+			goto done;
 		}
 
 	} else {
 		if (signal != LDL_SIGNAL_INITIATE) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Session is already dead\n");
-			return LDL_STATUS_FALSE;
+			status = LDL_STATUS_FALSE;
+			goto done;
 		}
 		if ((session = switch_core_session_request(&channel_endpoint_interface, NULL)) != 0) {
 			switch_core_session_add_stream(session, NULL);
+			
 			if ((tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object))) != 0) {
 				memset(tech_pvt, 0, sizeof(*tech_pvt));
 				switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
@@ -1618,8 +1645,9 @@
 				switch_set_flag_locked(tech_pvt, TFLAG_TRANSPORT_ACCEPT);
 			} else {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Hey where is my memory pool?\n");
-				terminate_session(&session, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-				return LDL_STATUS_FALSE;
+				terminate_session(&session,  __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+				status = LDL_STATUS_FALSE;
+				goto done;
 			}
 
 
@@ -1627,7 +1655,11 @@
 			ldl_session_set_private(dlsession, session);
 			tech_pvt->dlsession = dlsession;
 			negotiate_thread_launch(session);
+		} else {
+			status = LDL_STATUS_FALSE;
+			goto done;
 		}
+
 	}
 
 	switch(signal) {
@@ -1669,7 +1701,9 @@
 				if (!strcasecmp(msg, "accept")) {
 					switch_set_flag_locked(tech_pvt, TFLAG_ANSWER);
 					if (!do_candidates(tech_pvt, 0)) {
-						terminate_session(&session, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+						terminate_session(&session,  __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+						status = LDL_STATUS_FALSE;
+						goto done;
 					}
 				}
 			}
@@ -1681,8 +1715,9 @@
 
 
 			if (!get_codecs(tech_pvt)) {
-				terminate_session(&session, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-				return LDL_STATUS_FALSE;
+				terminate_session(&session,  __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+				status = LDL_STATUS_FALSE;
+				goto done;
 			}
 
 			
@@ -1713,18 +1748,21 @@
 							tech_pvt->codec_rate = payloads[x].rate;
 							if (!switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) {
 								if (!do_describe(tech_pvt, 0)) {
-									terminate_session(&session, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-									return LDL_STATUS_FALSE;
+									terminate_session(&session,  __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+									status = LDL_STATUS_FALSE;
+									goto done;
 								}
 							}
-							return LDL_STATUS_SUCCESS;
+							status = LDL_STATUS_SUCCESS;
+							goto done;
 						}
 					}
 				}
 				if (!match && !switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) {
 					if (!do_describe(tech_pvt, 0)) {
-						terminate_session(&session, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-						return LDL_STATUS_FALSE;
+						terminate_session(&session,  __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+						status = LDL_STATUS_FALSE;
+						goto done;
 					}
 				}
 			}
@@ -1829,8 +1867,9 @@
 						}
 
 						if (!get_codecs(tech_pvt)) {
-							terminate_session(&session, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-							return LDL_STATUS_FALSE;
+							terminate_session(&session,  __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+							status = LDL_STATUS_FALSE;
+							goto done;
 						}
 
 						
@@ -1842,15 +1881,17 @@
 						
 						if (!switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) {
 							if (!do_candidates(tech_pvt, 0)) {
-								terminate_session(&session, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-								return LDL_STATUS_FALSE;
+								terminate_session(&session,  __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+								status = LDL_STATUS_FALSE;
+								goto done;
 							}
 						}
 				
 						
 						switch_set_flag_locked(tech_pvt, TFLAG_TRANSPORT);
 						
-						return LDL_STATUS_SUCCESS;
+						status = LDL_STATUS_SUCCESS;
+						goto done;
 					}
 				}
 			}
@@ -1866,15 +1907,9 @@
 			switch_set_flag(tech_pvt, TFLAG_BYE);
 			switch_clear_flag(tech_pvt, TFLAG_IO);
 			switch_mutex_unlock(tech_pvt->flag_mutex);
-			terminate_session(&session, SWITCH_CAUSE_NORMAL_CLEARING);
-
-			if (state <= CS_INIT && !switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Destroy unused Session\n");
-				terminate_session(&session, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-			} else {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "End Call\n");
-			}
-
+			terminate_session(&session,  __LINE__, SWITCH_CAUSE_NORMAL_CLEARING);
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "End Call\n");
+			goto done;
 		}
 		break;
 
@@ -1883,7 +1918,9 @@
 		break;
 	}
 
-	return LDL_STATUS_SUCCESS;
+ done:
+	
+	return status;
 }
 
 static ldl_status handle_response(ldl_handle_t *handle, char *id)

Modified: freeswitch/branches/mishehu/src/mod/endpoints/mod_exosip/mod_exosip.c
==============================================================================
--- freeswitch/branches/mishehu/src/mod/endpoints/mod_exosip/mod_exosip.c	(original)
+++ freeswitch/branches/mishehu/src/mod/endpoints/mod_exosip/mod_exosip.c	Wed Sep 27 00:28:54 2006
@@ -551,7 +551,7 @@
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "using Realm %s\n", tech_pvt->realm);
 		}
 	}
-	flags = SWITCH_RTP_FLAG_MINI | SWITCH_RTP_FLAG_RAW_WRITE;
+	flags = SWITCH_RTP_FLAG_RAW_WRITE | SWITCH_RTP_FLAG_AUTOADJ | SWITCH_RTP_FLAG_DATAWAIT;
 	if (switch_test_flag(tech_pvt, TFLAG_TIMER)) {
 		flags |= SWITCH_RTP_FLAG_USE_TIMER;
 	}
@@ -667,9 +667,6 @@
 	size_t bytes = 0, samples = 0, frames = 0, ms = 0;
 	switch_channel_t *channel = NULL;
 	int payload = 0;
-	switch_time_t now, started = switch_time_now(), last_act = switch_time_now();
-	unsigned int elapsed;
-	uint32_t hard_timeout = 60000 * 3;
 
 	channel = switch_core_session_get_channel(session);
 	assert(channel != NULL);
@@ -688,13 +685,6 @@
 		assert(0);
 	}
 	
-	if (tech_pvt->last_read) {
-		elapsed = (unsigned int)((switch_time_now() - tech_pvt->last_read) / 1000);
-		if (elapsed > 60000) {
-			return SWITCH_STATUS_TIMEOUT;
-		}
-	}
-
 	if (switch_test_flag(tech_pvt, TFLAG_IO)) {
 		switch_status_t status;
 
@@ -707,7 +697,6 @@
 
 
 		while (!switch_test_flag(tech_pvt, TFLAG_BYE) && switch_test_flag(tech_pvt, TFLAG_IO) && tech_pvt->read_frame.datalen == 0) {
-			now = switch_time_now();
 			tech_pvt->read_frame.flags = 0;
 
 			status = switch_rtp_zerocopy_read_frame(tech_pvt->rtp_session, &tech_pvt->read_frame);
@@ -718,19 +707,6 @@
 			payload = tech_pvt->read_frame.payload;
 
 
-			elapsed = (unsigned int)((switch_time_now() - started) / 1000);
-
-			if (timeout > -1) {
-				if (elapsed >= (unsigned int)timeout) {
-					return SWITCH_STATUS_BREAK;
-				}
-			}
-			
-			elapsed = (unsigned int)((switch_time_now() - last_act) / 1000);
-			if (elapsed >= hard_timeout) {
-				return SWITCH_STATUS_BREAK;
-			}
-
 			if (switch_rtp_has_dtmf(tech_pvt->rtp_session)) {
 				char dtmf[128];
 				switch_rtp_dequeue_dtmf(tech_pvt->rtp_session, dtmf, sizeof(dtmf));
@@ -753,7 +729,6 @@
 				break;
 			}
 
-			switch_yield(1000);
 		}
 
 	}

Modified: freeswitch/branches/mishehu/src/mod/endpoints/mod_sofia/mod_sofia.c
==============================================================================
--- freeswitch/branches/mishehu/src/mod/endpoints/mod_sofia/mod_sofia.c	(original)
+++ freeswitch/branches/mishehu/src/mod/endpoints/mod_sofia/mod_sofia.c	Wed Sep 27 00:28:54 2006
@@ -53,8 +53,19 @@
 #include <sofia-sip/sip_status.h>
 #include <sofia-sip/sdp.h>
 #include <sofia-sip/sip_protos.h>
-#define DBFILE "sofia"
 
+static char reg_sql[] =
+"CREATE TABLE sip_registrations (\n"
+"   user            VARCHAR(255),\n"
+"   host            VARCHAR(255),\n"
+"   contact         VARCHAR(255),\n"
+"   expires         INTEGER(8)"
+");\n";
+
+
+
+
+
 static const char modname[] = "mod_sofia";
 #define STRLEN 15
 
@@ -97,11 +108,14 @@
 	switch_hash_t *profile_hash;
 	switch_mutex_t *hash_mutex;
 	uint32_t callid;
+	int32_t running;
+	switch_mutex_t *mutex;
 } globals;
 
 struct sofia_profile {
 	int debug;
 	char *name;
+	char *dbname;
 	char *dialplan;
 	char *context;
 	char *extrtpip;
@@ -127,6 +141,8 @@
 	sip_alias_node_t *aliases;
 	switch_payload_t te;
 	uint32_t codec_flags;
+	switch_mutex_t *reg_mutex;
+	switch_core_db_t *db;
 };
 
 
@@ -140,7 +156,6 @@
 	switch_codec_t read_codec;
 	switch_codec_t write_codec;
 	uint32_t codec_index;
-	uint32_t codec_rate;
 	uint32_t codec_ms;
 	switch_caller_profile_t *caller_profile;
 	int32_t timestamp_send;
@@ -235,6 +250,13 @@
                          sip_t const *sip,
                          tagi_t tags[]);
 
+static void sip_i_register(nua_t *nua,
+						   sofia_profile_t *profile,
+						   nua_handle_t *nh,
+						   switch_core_session_t *session,
+						   sip_t const *sip,
+						   tagi_t tags[]);
+
 static void event_callback(nua_event_t   event,
                            int           status,
                            char const   *phrase,
@@ -255,6 +277,83 @@
 
 /* BODY OF THE MODULE */
 /*************************************************************************************************************************************************************/
+struct callback_t {
+	char *val;
+	switch_size_t len;
+	int matches;
+};
+
+static int find_callback(void *pArg, int argc, char **argv, char **columnNames){
+	struct callback_t *cbt = (struct callback_t *) pArg;
+
+	switch_copy_string(cbt->val, argv[0], cbt->len);
+	cbt->matches++;
+	return 0;
+}
+
+static int del_callback(void *pArg, int argc, char **argv, char **columnNames){
+	switch_event_t *s_event;
+
+	if (argc >=3 ) {
+		if (switch_event_create_subclass(&s_event, SWITCH_EVENT_CUSTOM, MY_EVENT_EXPIRE) == SWITCH_STATUS_SUCCESS) {
+			switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "user", "%s", argv[0]);
+			switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "host", "%s", argv[1]);
+			switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "contact", "%s", argv[2]);
+			switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "expires", "%d", argv[3]);
+			switch_event_fire(&s_event);
+		}
+	}
+	return 0;
+}
+
+static void check_expire(sofia_profile_t *profile, time_t now)
+{
+	char sql[1024];
+	char *errmsg;
+
+	switch_mutex_lock(profile->reg_mutex);
+	snprintf(sql, sizeof(sql), "select * from sip_registrations where expires > 0 and expires < %ld", (long) now);	
+	switch_core_db_exec(profile->db, sql, del_callback, NULL, &errmsg);
+
+	if (errmsg) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR [%s][%s]\n", sql, errmsg);
+		switch_core_db_free(errmsg);
+		errmsg = NULL;
+	}
+	
+	snprintf(sql, sizeof(sql), "delete from sip_registrations where expires > 0 and expires < %ld", (long) now);
+	switch_core_db_persistant_execute(profile->db, sql, 1);
+	switch_mutex_unlock(profile->reg_mutex);
+}
+
+static char *find_reg_url(sofia_profile_t *profile, char *user, char *host, char *val, switch_size_t len)
+{
+	char *errmsg;
+	struct callback_t cbt = {0};
+
+
+	cbt.val = val;
+	cbt.len = len;
+	switch_mutex_lock(profile->reg_mutex);
+	if (host) {
+		snprintf(val, len, "select contact from sip_registrations where user='%s' and host='%s'", user, host);	
+	} else {
+		snprintf(val, len, "select contact from sip_registrations where user='%s'", user);	
+	}
+
+	switch_core_db_exec(profile->db, val, find_callback, &cbt, &errmsg);
+
+	if (errmsg) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR [%s][%s]\n", val, errmsg);
+		switch_core_db_free(errmsg);
+		errmsg = NULL;
+	}
+
+	switch_mutex_unlock(profile->reg_mutex);
+	return cbt.matches ? val : NULL;
+}
+
+
 static void set_local_sdp(private_object_t *tech_pvt)
 {
 	char buf[1024];
@@ -690,11 +789,11 @@
 			return SWITCH_STATUS_FALSE;
 		} else {
 			int ms;
-			tech_pvt->read_frame.rate = tech_pvt->codec_rate;
+			tech_pvt->read_frame.rate = tech_pvt->rm_rate;
 			ms = tech_pvt->write_codec.implementation->microseconds_per_frame / 1000;
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set Codec %s %s/%d %d ms\n",
 							  switch_channel_get_name(channel),
-							  tech_pvt->codecs[tech_pvt->codec_index]->iananame, tech_pvt->codec_rate, tech_pvt->codec_ms);
+							  tech_pvt->codecs[tech_pvt->codec_index]->iananame, tech_pvt->rm_rate, tech_pvt->codec_ms);
 			tech_pvt->read_frame.codec = &tech_pvt->read_codec;
 				
 			switch_core_session_set_read_codec(tech_pvt->session, &tech_pvt->read_codec);
@@ -730,7 +829,7 @@
 	bw = tech_pvt->read_codec.implementation->bits_per_second;
 	ms = tech_pvt->read_codec.implementation->microseconds_per_frame;
 
-	flags = (switch_rtp_flag_t) (SWITCH_RTP_FLAG_RAW_WRITE | SWITCH_RTP_FLAG_MINI | SWITCH_RTP_FLAG_AUTOADJ | SWITCH_RTP_FLAG_DATAWAIT);
+	flags = (switch_rtp_flag_t) (SWITCH_RTP_FLAG_RAW_WRITE | SWITCH_RTP_FLAG_AUTOADJ | SWITCH_RTP_FLAG_DATAWAIT);
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "RTP [%s] %s:%d->%s:%d codec: %u ms: %d\n",
 					  switch_channel_get_name(channel),
@@ -1152,6 +1251,7 @@
 	switch_caller_profile_t *caller_profile = NULL;
 	private_object_t *tech_pvt = NULL;
 	switch_channel_t *channel;
+	char *host;
 
 	*new_session = NULL;
 
@@ -1182,10 +1282,18 @@
         terminate_session(&nsession, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __LINE__);
         goto done;
 	}
-	
-	tech_pvt->dest = switch_core_session_alloc(nsession, strlen(dest) + 5);
-	snprintf(tech_pvt->dest, strlen(dest) + 5, "sip:%s", dest);
-	
+
+	if ((host = strchr(dest, '%'))) {
+		char buf[128];
+		*host++ = '\0';
+		find_reg_url(profile, dest, host, buf, sizeof(buf));
+		tech_pvt->dest = switch_core_session_strdup(nsession, buf);
+		dest = tech_pvt->dest + 4;
+	} else {
+		tech_pvt->dest = switch_core_session_alloc(nsession, strlen(dest) + 5);
+		snprintf(tech_pvt->dest, strlen(dest) + 5, "sip:%s", dest);
+	}
+
 	channel = switch_core_session_get_channel(nsession);
 	attach_private(nsession, profile, tech_pvt, dest);	
 	caller_profile = switch_caller_profile_clone(nsession, outbound_profile);
@@ -1554,6 +1662,106 @@
 	}
 }
 
+
+static void sip_i_register(nua_t *nua,
+						   sofia_profile_t *profile,
+						   nua_handle_t *nh,
+						   switch_core_session_t *session,
+						   sip_t const *sip,
+						   tagi_t tags[])
+{
+	sip_from_t const *from = sip->sip_from;
+	sip_expires_t const *expires = sip->sip_expires;
+	//sip_to_t const *to = sip->sip_to;
+	sip_contact_t const *contact = sip->sip_contact;
+	// SIP_407_PROXY_AUTH_REQUIRED
+	switch_xml_t domain, xml, user, param;
+	char params[1024] = "";
+	char *sql;
+	switch_event_t *s_event;
+	char *from_user = (char *) from->a_url->url_user;
+	char *from_host = (char *) from->a_url->url_host;
+	char *contact_user = (char *) contact->m_url->url_user;
+	char *contact_host = (char *) contact->m_url->url_host;
+	char buf[512];
+	
+	snprintf(params, sizeof(params), "from_user=%s&from_host=%s&contact_user=%s&contact_host=%s",
+			 from_user,
+			 from_host,
+			 contact_user,
+			 contact_host 
+			 );
+
+
+	if (switch_xml_locate("directory", "domain", "name", (char *)from->a_url->url_host, &xml, &domain, params) != SWITCH_STATUS_SUCCESS) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of directory failed\n");
+		nua_respond(nh, SIP_401_UNAUTHORIZED, SIPTAG_CONTACT(contact), TAG_END());
+		return;
+	}
+
+	if (!(user = switch_xml_find_child(domain, "user", "id", from_user))) {
+		nua_respond(nh, SIP_401_UNAUTHORIZED, SIPTAG_CONTACT(contact), TAG_END());
+		switch_xml_free(xml);
+		return;
+	}
+	
+
+	for (param = switch_xml_child(user, "param"); param; param = param->next) {
+		char *var = (char *) switch_xml_attr_soft(param, "name");
+		char *val = (char *) switch_xml_attr_soft(param, "value");
+
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "param [%s]=[%s]\n", var, val);
+	}
+
+
+	if (!find_reg_url(profile, from_user, from_host, buf, sizeof(buf))) {
+		sql = switch_core_db_mprintf("insert into sip_registrations values ('%q','%q','sip:%q@%q',%ld)", 
+									 from_user,
+									 from_host,
+									 contact_user,
+									 contact_host,
+									 (long) time(NULL) + (long)expires->ex_delta);
+	} else {
+		sql = switch_core_db_mprintf("update sip_registrations set contact='sip:%q@%q', expires=%ld where user='%q' and host='%q'",
+									 contact_user,
+                                     contact_host,
+									 (long) time(NULL) + (long)expires->ex_delta,
+									 from_user,
+									 from_host);
+		
+	}
+	
+	if (switch_event_create_subclass(&s_event, SWITCH_EVENT_CUSTOM, MY_EVENT_REGISTER) == SWITCH_STATUS_SUCCESS) {
+		switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "from_user", "%s", from_user);
+		switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "from_host", "%s", from_host);
+		switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "contact_user", "%s", contact_user);
+		switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "contact_host", "%s", contact_host);
+		switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "expires", "%ld", (long)expires->ex_delta);
+		switch_event_fire(&s_event);
+	}
+	if (sql) {
+		switch_mutex_lock(profile->reg_mutex);
+		switch_core_db_persistant_execute(profile->db, sql, 25);
+					switch_core_db_free(sql);
+					sql = NULL;
+					switch_mutex_unlock(profile->reg_mutex);
+	}
+	
+	switch_xml_free(xml);
+
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Got a Register from [%s@%s] contact [%s@%s] expires %ld\n", 
+					  from_user, 
+					  from_host,
+					  contact_user,
+					  contact_host,
+					  (long)expires->ex_delta
+					  );
+
+	
+	nua_respond(nh, SIP_200_OK, SIPTAG_CONTACT(contact), TAG_END());
+	//nua_respond(nh, SIP_407_PROXY_AUTH_REQUIRED, TAG_END());
+}
+
 static void event_callback(nua_event_t   event,
 						   int           status,
 						   char const   *phrase,
@@ -1606,6 +1814,10 @@
 		sip_i_invite(nua, profile, nh, session, sip, tags);
 		break;
 
+    case nua_i_register:
+ 		sip_i_register (nua, profile, nh, session, sip, tags);
+        break;
+
 	case nua_i_prack:
 		//sip_i_prack(nua, profile, nh, session, sip, tags);
 		break;
@@ -1696,12 +1908,15 @@
 	}
 }
 
+#define REG_SECONDS 30
 static void *SWITCH_THREAD_FUNC profile_thread_run(switch_thread_t *thread, void *obj)
 {
 	sofia_profile_t *profile = (sofia_profile_t *) obj;
 	switch_memory_pool_t *pool;
 	sip_alias_node_t *node;
+	uint32_t loops = 0;
 
+
 	profile->s_root = su_root_create(NULL);
 	profile->nua = nua_create(profile->s_root, /* Event loop */
 							  event_callback, /* Callback for processing events */
@@ -1713,6 +1928,7 @@
 				   NUTAG_EARLY_MEDIA(1),				   
 				   NUTAG_AUTOANSWER(0),
 				   NUTAG_AUTOALERT(0),
+				   NUTAG_ALLOW("REGISTER"),
 				   SIPTAG_SUPPORTED_STR("100rel, precondition"),
 				   TAG_END());
 				   
@@ -1727,17 +1943,46 @@
 		nua_set_params(node->nua,
 					   NUTAG_EARLY_MEDIA(1),
 					   NUTAG_AUTOANSWER(0),
+					   NUTAG_ALLOW("REGISTER"),
 					   SIPTAG_SUPPORTED_STR("100rel, precondition"),
 					   NUTAG_AUTOALERT(0),
 					   TAG_END());
 		
 	}
 
-	su_root_run(profile->s_root);
+
+	if ((profile->db = switch_core_db_open_file(profile->dbname))) {
+		switch_core_db_test_reactive(profile->db, "select * from sip_registrations", reg_sql);
+	} else {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open SQL Database!\n");
+		return NULL;
+	}
+
+	switch_mutex_init(&profile->reg_mutex, SWITCH_MUTEX_NESTED, profile->pool);
+
+	switch_mutex_lock(globals.mutex);
+	globals.running = 1;
+	switch_mutex_unlock(globals.mutex);
+
+	loops = REG_SECONDS;
+
+	while(globals.running == 1) {
+		if (++loops >= REG_SECONDS) {
+			check_expire(profile, time(NULL));
+			loops = 0;
+		}
+
+		su_root_step(profile->s_root, 1000);
+		//su_root_run(profile->s_root);
+	}
+
 	su_root_destroy(profile->s_root);
 
 	pool = profile->pool;
 	switch_core_destroy_memory_pool(&pool);
+	switch_mutex_lock(globals.mutex);
+	globals.running = 0;
+	switch_mutex_unlock(globals.mutex);
 	
 	return NULL;
 }
@@ -1763,7 +2008,7 @@
 	char *cf = "sofia.conf";
 	switch_xml_t cfg, xml = NULL, xprofile, param;
 	switch_status_t status = SWITCH_STATUS_SUCCESS;
-	
+
 	if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
 		status = SWITCH_STATUS_FALSE;
@@ -1790,10 +2035,15 @@
 		if (!xprofilename) {
 			xprofilename = "unnamed";
 		}
+		
 
+		
+
 		profile->pool = pool;
 
 		profile->name = switch_core_strdup(profile->pool, xprofilename);
+		snprintf(url, sizeof(url), "sofia_reg_%s", xprofilename);
+		profile->dbname = switch_core_strdup(profile->pool, url);
 
 		profile->dtmf_duration = 100;		
 		profile->codec_ms = 20;
@@ -1909,7 +2159,6 @@
 
 }
 
-
 SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
 {
 
@@ -1919,6 +2168,8 @@
 	}
 
 	memset(&globals, 0, sizeof(globals));
+	switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, module_pool);
+	
 	su_init();
 
 
@@ -1938,10 +2189,17 @@
 
 SWITCH_MOD_DECLARE(switch_status_t) switch_module_shutdown(void)
 {
-	/*  Adding Note so we can destroy these properly. Will remind tony.
-	 *  nua_destroy (nua);
-	 *  su_root_destroy (root);
-	 */
+
+	switch_mutex_lock(globals.mutex);
+	if (globals.running == 1) {
+		globals.running = -1;
+	}
+	switch_mutex_unlock(globals.mutex);
+
+	while(globals.running) {
+		switch_yield(1000);
+	}
+
 	su_deinit();
 
 	return SWITCH_STATUS_SUCCESS;

Modified: freeswitch/branches/mishehu/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c
==============================================================================
--- freeswitch/branches/mishehu/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c	(original)
+++ freeswitch/branches/mishehu/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c	Wed Sep 27 00:28:54 2006
@@ -77,6 +77,8 @@
 	int supress_dtmf_tone;
 	int configured_spans;
 	char *dialplan;
+	switch_hash_t *call_hash;
+	switch_mutex_t *hash_mutex;
 } globals;
 
 struct wanpipe_pri_span {
@@ -92,6 +94,15 @@
 	struct sangoma_pri spri;
 };
 
+struct wpsock {
+	int fd;
+	char *name;
+	struct private_object *tech_pvt;
+};
+
+typedef struct wpsock wpsock_t;
+
+
 #define MAX_SPANS 128
 static struct wanpipe_pri_span *SPANS[MAX_SPANS];
 
@@ -106,7 +117,7 @@
 	struct sangoma_pri *spri;
 	sangoma_api_hdr_t hdrframe;
 	switch_caller_profile_t *caller_profile;
-	int socket;
+	wpsock_t *wpsock;
 	int callno;
 	int span;
 	int cause;
@@ -127,7 +138,84 @@
 	switch_core_session_t *map[36];
 };
 
+static int wp_close(struct private_object *tech_pvt)
+{
+	int ret = 0;
 
+	switch_mutex_lock(globals.hash_mutex);
+	if (tech_pvt->wpsock && tech_pvt->wpsock->tech_pvt == tech_pvt) {
+		tech_pvt->wpsock->tech_pvt = NULL;
+		ret = 1;
+	}
+	switch_mutex_unlock(globals.hash_mutex);
+	
+	return ret;
+}
+
+static int wp_open(struct private_object *tech_pvt, int span, int chan)
+{
+	int fd;
+	wpsock_t *sock;
+	char name[25];
+	
+	snprintf(name, sizeof(name), "s%dc%d", span, chan);
+
+	switch_mutex_lock(globals.hash_mutex);
+	if ((sock = switch_core_hash_find(globals.call_hash, name))) {
+		fd = sock->fd;
+	} else {
+		if ((fd = sangoma_open_tdmapi_span_chan(span, chan)) > -1) {
+			if ((sock = malloc(sizeof(*sock)))) {
+				memset(sock, 0, sizeof(*sock));
+				sock->fd = fd;
+				sock->name = strdup(name);
+				switch_core_hash_insert(globals.call_hash, sock->name, sock);
+			}
+		}
+	}
+
+	if (sock) {
+		if (sock->tech_pvt) {
+			if (tech_pvt->session) {
+				switch_channel_t *channel = switch_core_session_get_channel(tech_pvt->session);
+				switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+			}
+		}
+		sock->tech_pvt = tech_pvt;
+		tech_pvt->wpsock = sock;
+	}
+
+	switch_mutex_unlock(globals.hash_mutex);
+
+	return sock ? 1 : 0;
+}
+
+static int wp_restart(int span, int chan)
+{
+	wpsock_t *sock;
+	int fd;
+	char name[25];
+	
+	snprintf(name, sizeof(name), "s%dc%d", span, chan);
+
+	switch_mutex_lock(globals.hash_mutex);
+	if ((sock = switch_core_hash_find(globals.call_hash, name))) {
+		switch_core_hash_delete(globals.call_hash, sock->name);
+		fd = sock->fd;
+	} else {
+		fd = sangoma_open_tdmapi_span_chan(span, chan);
+	}
+	switch_mutex_unlock(globals.hash_mutex);
+
+	if (fd > -1) {
+		close(fd);
+		return 0;
+	}
+	
+	return -1;
+}
+
+
 static void set_global_dialplan(char *dialplan)
 {
 	if (globals.dialplan) {
@@ -226,7 +314,7 @@
 {
 	struct private_object *tech_pvt;
 	switch_channel_t *channel = NULL;
-	wanpipe_tdm_api_t tdm_api = {0};
+	wanpipe_tdm_api_t tdm_api = {{0}};
 	int err = 0;
 	int mtu_mru;
 	unsigned int rate = 8000;
@@ -240,15 +328,15 @@
 
 	tech_pvt->read_frame.data = tech_pvt->databuf;
 
-	err = sangoma_tdm_set_codec(tech_pvt->socket, &tdm_api, WP_SLINEAR);
+	err = sangoma_tdm_set_codec(tech_pvt->wpsock->fd, &tdm_api, WP_SLINEAR);
 	
-	mtu_mru = sangoma_tdm_get_usr_mtu_mru(tech_pvt->socket, &tdm_api);	
+	mtu_mru = sangoma_tdm_get_usr_mtu_mru(tech_pvt->wpsock->fd, &tdm_api);	
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "WANPIPE INIT MTU is %d\n", mtu_mru);
 
 	if (mtu_mru != globals.mtu) {
-		sangoma_tdm_set_usr_period(tech_pvt->socket, &tdm_api, 40);
-		err = sangoma_tdm_set_usr_period(tech_pvt->socket, &tdm_api, new_mtu);
-		mtu_mru = sangoma_tdm_get_usr_mtu_mru(tech_pvt->socket, &tdm_api);
+		sangoma_tdm_set_usr_period(tech_pvt->wpsock->fd, &tdm_api, 40);
+		err = sangoma_tdm_set_usr_period(tech_pvt->wpsock->fd, &tdm_api, new_mtu);
+		mtu_mru = sangoma_tdm_get_usr_mtu_mru(tech_pvt->wpsock->fd, &tdm_api);
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "ADJUSTED MTU AFTER SETTING IT TO %d is %d %d [%s]\n", new_mtu, mtu_mru, err, strerror(err));
 		if (mtu_mru != globals.mtu) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failure to adjust MTU\n");
@@ -344,7 +432,8 @@
 		chanmap = tech_pvt->spri->private_info;
 	}
 
-	sangoma_socket_close(&tech_pvt->socket);
+	//sangoma_socket_close(&tech_pvt->wpsock->fd);
+	wp_close(tech_pvt);
 
 	switch_core_codec_destroy(&tech_pvt->read_codec);
 	switch_core_codec_destroy(&tech_pvt->write_codec);
@@ -434,7 +523,7 @@
 	assert(tech_pvt != NULL);
 
 
-	if (switch_test_flag(tech_pvt, TFLAG_BYE) || tech_pvt->socket < 0) {
+	if (switch_test_flag(tech_pvt, TFLAG_BYE) || tech_pvt->wpsock->fd < 0) {
 		return SWITCH_STATUS_GENERR;
 	}
 
@@ -444,16 +533,16 @@
 	memset(tech_pvt->databuf, 0, sizeof(tech_pvt->databuf));
 	while (bytes < globals.mtu) {
 
-		if (switch_test_flag(tech_pvt, TFLAG_BYE) || tech_pvt->socket < 0) {
+		if (switch_test_flag(tech_pvt, TFLAG_BYE) || tech_pvt->wpsock->fd < 0) {
 			return SWITCH_STATUS_GENERR;
 		}
 
 
-		if (sangoma_socket_waitfor(tech_pvt->socket, 1000, POLLIN | POLLERR | POLLHUP) <= 0) {
+		if (sangoma_socket_waitfor(tech_pvt->wpsock->fd, 1000, POLLIN | POLLERR | POLLHUP) <= 0) {
 			return SWITCH_STATUS_GENERR;
 		}
 
-		if ((res = sangoma_readmsg_socket(tech_pvt->socket,
+		if ((res = sangoma_readmsg_socket(tech_pvt->wpsock->fd,
 										  &tech_pvt->hdrframe,
 										  sizeof(tech_pvt->hdrframe), bp, sizeof(tech_pvt->databuf) - bytes, 0)) < 0) {
 			if (errno == EBUSY) {
@@ -467,7 +556,7 @@
 		bp += bytes;
 	}
 
-	if (!bytes || switch_test_flag(tech_pvt, TFLAG_BYE) || tech_pvt->socket < 0) {
+	if (!bytes || switch_test_flag(tech_pvt, TFLAG_BYE) || tech_pvt->wpsock->fd < 0) {
 		return SWITCH_STATUS_GENERR;
 	}
 
@@ -520,7 +609,7 @@
 
 
 	while (tech_pvt->dtmf_buffer && bwrote < frame->datalen && bytes > 0 && switch_buffer_inuse(tech_pvt->dtmf_buffer) > 0) {
-		if (switch_test_flag(tech_pvt, TFLAG_BYE) || tech_pvt->socket < 0) {
+		if (switch_test_flag(tech_pvt, TFLAG_BYE) || tech_pvt->wpsock->fd < 0) {
 			return SWITCH_STATUS_GENERR;
 		}
 
@@ -530,14 +619,14 @@
 			}
 		}
 
-		if (sangoma_socket_waitfor(tech_pvt->socket, 1000, POLLOUT | POLLERR | POLLHUP) <= 0) {
+		if (sangoma_socket_waitfor(tech_pvt->wpsock->fd, 1000, POLLOUT | POLLERR | POLLHUP) <= 0) {
 			return SWITCH_STATUS_GENERR;
 		}
 
 #ifdef DOTRACE	
 		write(tech_pvt->fd, dtmf, (int) bread);
 #endif
-		result = sangoma_sendmsg_socket(tech_pvt->socket,
+		result = sangoma_sendmsg_socket(tech_pvt->wpsock->fd,
 									 &tech_pvt->hdrframe, sizeof(tech_pvt->hdrframe), dtmf, bread, 0);
 		if (result < 0) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
@@ -557,7 +646,7 @@
 		}
 	}
 
-	if (switch_test_flag(tech_pvt, TFLAG_BYE) || tech_pvt->socket < 0) {
+	if (switch_test_flag(tech_pvt, TFLAG_BYE) || tech_pvt->wpsock->fd < 0) {
 		return SWITCH_STATUS_GENERR;
 	}
 
@@ -570,7 +659,7 @@
 		unsigned int towrite;
 
 #if 1
-		if (sangoma_socket_waitfor(tech_pvt->socket, 1000, POLLOUT | POLLERR | POLLHUP) <= 0) {
+		if (sangoma_socket_waitfor(tech_pvt->wpsock->fd, 1000, POLLOUT | POLLERR | POLLHUP) <= 0) {
 			return SWITCH_STATUS_GENERR;
 		}
 #endif
@@ -586,7 +675,7 @@
 			towrite = globals.mtu;
 		}
 
-		result = sangoma_sendmsg_socket(tech_pvt->socket,
+		result = sangoma_sendmsg_socket(tech_pvt->wpsock->fd,
 									 &tech_pvt->hdrframe, sizeof(tech_pvt->hdrframe), bp, towrite, 0);
 		if (result < 0) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
@@ -664,7 +753,8 @@
 	switch_clear_flag(tech_pvt, TFLAG_MEDIA);
 	switch_mutex_unlock(tech_pvt->flag_mutex);
 
-	sangoma_socket_close(&tech_pvt->socket);
+	//sangoma_socket_close(&tech_pvt->wpsock->fd);
+	//wp_close(tech_pvt);
 
 	return SWITCH_STATUS_SUCCESS;
 
@@ -805,9 +895,9 @@
 
 			if (bchan) {
 				int chan, span;
-				
+
 				if (sangoma_span_chan_fromif(bchan, &span, &chan)) {
-					if ((tech_pvt->socket = sangoma_open_tdmapi_span_chan(span, chan)) < 0) {
+					if (!wp_open(tech_pvt, span, chan)) {
 						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open fd for s%dc%d! [%s]\n", span, chan, strerror(errno));
 						switch_core_session_destroy(new_session);
 						return SWITCH_STATUS_GENERR;
@@ -889,7 +979,7 @@
 						return SWITCH_STATUS_GENERR;
 					}
 
-					if ((tech_pvt->socket = sangoma_open_tdmapi_span_chan(spri->span, channo)) < 0) {
+					if (!wp_open(tech_pvt, spri->span, channo)) {
 						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open fd!\n");
 						switch_core_session_destroy(new_session);
 						pri_sr_free(sr);
@@ -943,6 +1033,10 @@
 		return SWITCH_STATUS_TERM;
 	}
 
+	memset(&globals, 0, sizeof(globals));
+	switch_core_hash_init(&globals.call_hash, module_pool);
+	switch_mutex_init(&globals.hash_mutex, SWITCH_MUTEX_NESTED, module_pool);
+
 	/* start the pri's */
 	if ((status = config_wanpipe(0)) != SWITCH_STATUS_SUCCESS) {
 		return status;
@@ -1117,7 +1211,6 @@
 
 	if ((session = switch_core_session_request(&wanpipe_endpoint_interface, NULL))) {
 		struct private_object *tech_pvt;
-		int fd;
 		char ani2str[4] = "";
 		//wanpipe_tdm_api_t tdm_api;
 
@@ -1166,12 +1259,11 @@
 		tech_pvt->callno = event->ring.channel;
 		tech_pvt->span = spri->span;
 
-		if ((fd = sangoma_open_tdmapi_span_chan(spri->span, event->ring.channel)) < 0) {
+		if (!wp_open(tech_pvt, spri->span, event->ring.channel)) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open fd!\n");
 		}
 		//sangoma_tdm_set_hw_period(fd, &tdm_api, 480);
 
-		tech_pvt->socket = fd;
 		chanmap->map[event->ring.channel] = session;
 
 		switch_channel_set_state(channel, CS_INIT);
@@ -1192,7 +1284,6 @@
 
 static int on_restart(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *event)
 {
-	int fd;
 	switch_core_session_t *session;
 	struct channel_map *chanmap;
 
@@ -1213,11 +1304,8 @@
 		switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
 	}
 	
-	if ((fd = sangoma_open_tdmapi_span_chan(spri->span, event->restart.channel)) < 0) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open fd [%s]!\n", strerror(errno));
-	} else {
-		close(fd);
-	}
+	wp_restart(spri->span, event->restart.channel);
+
 	return 0;
 }
 
@@ -1306,6 +1394,7 @@
 	globals.mtu = DEFAULT_MTU;
 	globals.dtmf_on = 150;
 	globals.dtmf_off = 50;
+
 
 
 	if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {

Modified: freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/basecdr.cpp
==============================================================================
--- freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/basecdr.cpp	(original)
+++ freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/basecdr.cpp	Wed Sep 27 00:28:54 2006
@@ -86,30 +86,30 @@
 		{
 			if(newchannel->callerprofile->caller_id_name != 0)
 			{
-				strncpy(clid,newchannel->callerprofile->caller_id_name,strlen(newchannel->callerprofile->caller_id_name));
+				strncpy(clid,newchannel->callerprofile->caller_id_name,sizeof(clid));
 				strncat(clid," <",2);
 				if(newchannel->callerprofile->caller_id_number != 0 )
-					strncat(clid,newchannel->callerprofile->caller_id_number,strlen(clid)+strlen(newchannel->callerprofile->caller_id_number));
+					strncat(clid,newchannel->callerprofile->caller_id_number,79-(strlen(clid)+strlen(newchannel->callerprofile->caller_id_number)));
 				strncat(clid,">",1);
 			}
 			
 			// Get the ANI information if it's set
 			if(newchannel->callerprofile->ani != 0)
-				strncpy(ani,newchannel->callerprofile->ani,strlen(newchannel->callerprofile->ani));
+				strncpy(ani,newchannel->callerprofile->ani,sizeof(ani)));
 			if(newchannel->callerprofile->ani2 != 0)
-				strncpy(ani2,newchannel->callerprofile->ani2,strlen(newchannel->callerprofile->ani2));
+				strncpy(ani2,newchannel->callerprofile->ani2,sizeof(ani2));
 		
 			if(newchannel->callerprofile->dialplan != 0)
-				strncpy(dialplan,newchannel->callerprofile->dialplan,strlen(newchannel->callerprofile->dialplan));
+				strncpy(dialplan,newchannel->callerprofile->dialplan,sizeof(dialplan));
 		
 			if(newchannel->callerprofile->network_addr != 0)
-				strncpy(network_addr,newchannel->callerprofile->network_addr,strlen(newchannel->callerprofile->network_addr));
+				strncpy(network_addr,newchannel->callerprofile->network_addr,sizeof(network_addr));
 		}
 
 		originated = newchannel->originate;
 	
 		if(newchannel->originateprofile && newchannel->originateprofile->uuid != 0)
-			strncpy(destuuid,newchannel->originateprofile->uuid,strlen(newchannel->originateprofile->uuid));
+			strncpy(destuuid,newchannel->originateprofile->uuid,sizeof(uuid));
 	
 		// We still need to check if this is originated or not
 		if(originated == 0)
@@ -117,27 +117,27 @@
 			if (newchannel->callerprofile) 
 			{
 				if(newchannel->callerprofile->destination_number != 0)
-					strncpy(src,newchannel->callerprofile->destination_number,strlen(newchannel->callerprofile->destination_number));
+					strncpy(src,newchannel->callerprofile->destination_number,sizeof(destination_number));
 				if(newchannel->callerprofile->caller_id_number != 0)
-					strncpy(dst,newchannel->callerprofile->caller_id_number,strlen(newchannel->callerprofile->caller_id_number));
+					strncpy(dst,newchannel->callerprofile->caller_id_number,sizeof(caller_id_number));
 			}
 			if(newchannel->originateprofile && newchannel->originateprofile->chan_name != 0)
-				strncpy(dstchannel,newchannel->originateprofile->chan_name,strlen(newchannel->originateprofile->chan_name));
+				strncpy(dstchannel,newchannel->originateprofile->chan_name,sizeof(chan_name));
 		}
 		else
 		{
 			if (newchannel->callerprofile) {
 				if(newchannel->callerprofile->caller_id_number != 0)
-					strncpy(src,newchannel->callerprofile->caller_id_number,strlen(newchannel->callerprofile->caller_id_number));
+					strncpy(src,newchannel->callerprofile->caller_id_number,sizeof(caller_id_number));
 				if(newchannel->callerprofile->destination_number != 0)
-					strncpy(dst,newchannel->callerprofile->destination_number,strlen(newchannel->callerprofile->destination_number));
+					strncpy(dst,newchannel->callerprofile->destination_number,sizeof(destination_number));
 			}
 			if(newchannel->originateprofile && newchannel->originateprofile->chan_name != 0)
-				strncpy(dstchannel,newchannel->originateprofile->chan_name,strlen(newchannel->originateprofile->chan_name));
+				strncpy(dstchannel,newchannel->originateprofile->chan_name,sizeof(chan_name));
 		}
 		
-		strncpy(myuuid,newchannel->callerprofile->uuid,strlen(newchannel->callerprofile->uuid));
-		strncpy(srcchannel,newchannel->callerprofile->chan_name,strlen(newchannel->callerprofile->chan_name));
+		strncpy(myuuid,newchannel->callerprofile->uuid,sizeof(uuid));
+		strncpy(srcchannel,newchannel->callerprofile->chan_name,sizeof(chan_name));
 		
 		if(switch_channel_test_flag(newchannel->channel,CF_ANSWERED))
 		{
@@ -158,9 +158,9 @@
 			if(newchannel->callerextension->last_application != 0)
 			{
 				if(newchannel->callerextension->last_application->application_name != 0)
-					strncpy(lastapp,newchannel->callerextension->last_application->application_name,strlen(newchannel->callerextension->last_application->application_name));
+					strncpy(lastapp,newchannel->callerextension->last_application->application_name,sizeof(lastapp));
 				if(newchannel->callerextension->last_application->application_data != 0)
-					strncpy(lastdata,newchannel->callerextension->last_application->application_data,strlen(newchannel->callerextension->last_application->application_data));
+					strncpy(lastdata,newchannel->callerextension->last_application->application_data,sizeof(lastdata));
 			}
 		
 		amaflags=0;

Modified: freeswitch/branches/mishehu/src/mod/event_handlers/mod_event_socket/mod_event_socket.c
==============================================================================
--- freeswitch/branches/mishehu/src/mod/event_handlers/mod_event_socket/mod_event_socket.c	(original)
+++ freeswitch/branches/mishehu/src/mod/event_handlers/mod_event_socket/mod_event_socket.c	Wed Sep 27 00:28:54 2006
@@ -228,7 +228,7 @@
 static switch_status_t read_packet(listener_t *listener, switch_event_t **event, uint32_t timeout) 
 {
 	switch_size_t mlen;
-	char mbuf[1024] = "";
+	char mbuf[2048] = "";
 	char buf[1024] = "";
 	switch_size_t len;
 	switch_status_t status = SWITCH_STATUS_SUCCESS;
@@ -238,7 +238,7 @@
 	void *pop;
 	char *ptr;
 	uint8_t crcount = 0;
-
+	uint32_t max_len = sizeof(mbuf);
 	*event = NULL;
 	start = time(NULL);
 	ptr = mbuf;
@@ -253,12 +253,13 @@
 		}
 
 		if (mlen) {
-			bytes++;
+			bytes += mlen;
 			do_sleep = 0;
 
 			if (*mbuf == '\r' || *mbuf == '\n') { /* bah */
 				ptr = mbuf;
 				mbuf[0] = '\0';
+				bytes = 0;
 				continue;
 			}
 
@@ -268,10 +269,15 @@
 				crcount = 0;
 			}
 			ptr++;
+
+			if (bytes >= max_len) {
+				crcount = 2;
+			}
+
 			if (crcount == 2) {
 				char *next;
 				char *cur = mbuf;
-
+				bytes = 0;
 				while(cur) {
 					if ((next = strchr(cur, '\r')) || (next = strchr(cur, '\n'))) {
 						while (*next == '\r' || *next == '\n') {
@@ -486,8 +492,13 @@
 
 		goto done;
 	}
-	
-	if (!strncasecmp(cmd, "sendmsg", 7)) {
+
+
+	if (!strncasecmp(cmd, "sendevent", 9)) {
+		switch_event_fire(&event);
+		snprintf(reply, reply_len, "+OK");
+		goto done;
+	} else if (!strncasecmp(cmd, "sendmsg", 7)) {
 		switch_core_session_t *session;
 		char *uuid = cmd + 8;
 

Modified: freeswitch/branches/mishehu/src/mod/languages/mod_mono/mod_mono.c
==============================================================================
--- freeswitch/branches/mishehu/src/mod/languages/mod_mono/mod_mono.c	(original)
+++ freeswitch/branches/mishehu/src/mod/languages/mod_mono/mod_mono.c	Wed Sep 27 00:28:54 2006
@@ -96,12 +96,12 @@
 	char *assembly_dir  = (char *) switch_core_alloc(mono_pool, assembly_dir_len);
 	char *assembly_file = (char *) switch_core_alloc(mono_pool, assembly_file_len);
 
-	apr_finfo_t *finfo = (apr_finfo_t *) switch_core_alloc(mono_pool, sizeof(*finfo));
+	apr_finfo_t *assembly_finfo = (apr_finfo_t *) switch_core_alloc(mono_pool, sizeof(*assembly_finfo));
 
 	snprintf(assembly_dir, assembly_dir_len, "%s/%s", SWITCH_GLOBAL_dirs.base_dir, SWITCH_MONO_LIBDIR);
 	snprintf(assembly_file, assembly_file_len, "%s/%s%s", SWITCH_GLOBAL_dirs.base_dir, SWITCH_MONO_LIBDIR, SWITCH_MONO_ASSEMBLY);
 
-	if (apr_stat(finfo, assembly_file, 0, mono_pool) != SWITCH_STATUS_SUCCESS) {
+	if (apr_stat(assembly_finfo, assembly_file, 0, mono_pool) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Could not find FreeSwitch.NET assembly\n");
 		return SWITCH_STATUS_FALSE;
 	}
@@ -178,6 +178,13 @@
  */ 
 switch_status_t mod_mono_load_modules(const char *module_dir)
 {
+	apr_finfo_t *module_finfo = (apr_finfo_t *) switch_core_alloc(mono_pool, sizeof(*module_finfo));
+	
+	if (apr_stat(module_finfo, module_dir, 0, mono_pool) != SWITCH_STATUS_SUCCESS) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not access module dir!.\n");
+		return SWITCH_STATUS_FALSE;
+	}
+	
 	apr_dir_t *module_dir_handle;
 	char *file;
 	size_t len;

Modified: freeswitch/branches/mishehu/src/mod/timers/mod_softtimer/mod_softtimer.c
==============================================================================
--- freeswitch/branches/mishehu/src/mod/timers/mod_softtimer/mod_softtimer.c	(original)
+++ freeswitch/branches/mishehu/src/mod/timers/mod_softtimer/mod_softtimer.c	Wed Sep 27 00:28:54 2006
@@ -37,8 +37,6 @@
 static struct {
 	int32_t RUNNING;
 	switch_mutex_t *mutex;
-	uint32_t timer_milliseconds;
-	switch_interval_time_t timer_microseconds;
 } globals;
 
 static const char modname[] = "mod_softtimer";
@@ -60,22 +58,6 @@
 #define IDLE_SPEED 100
 
 
-static inline void set_timer(void)
-{
-	uint32_t index = 0, min = IDLE_SPEED;
-
-	for(index = 0; index < MAX_ELEMENTS; index++) {
-		if (TIMER_MATRIX[index].count) {
-			if (min > index) {
-				min = index;
-			}
-		}
-	}
-
-	globals.timer_milliseconds = min;
-	globals.timer_microseconds = min * 1000;
-}
-
 static inline switch_status_t timer_init(switch_timer_t *timer)
 {
 	timer_private_t *private_info;
@@ -86,8 +68,6 @@
 		switch_mutex_unlock(globals.mutex);
 		timer->private_info = private_info;
 		private_info->reference = TIMER_MATRIX[timer->interval].tick;
-		set_timer();
-
 		return SWITCH_STATUS_SUCCESS;
 	}
 
@@ -113,7 +93,6 @@
 		switch_yield(1000);
 	}
 	timer->samplecount += timer->samples;
-
 	return SWITCH_STATUS_SUCCESS;
 }
 
@@ -139,7 +118,6 @@
 	switch_mutex_lock(globals.mutex);
 	TIMER_MATRIX[timer->interval].count--;
 	switch_mutex_unlock(globals.mutex);
-	set_timer();
 	timer->private_info = NULL;
 	return SWITCH_STATUS_SUCCESS;
 }
@@ -177,8 +155,12 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
+/* I cant resist setting this to 10ms, we dont even run anything smaller than 20ms so this is already 
+   twice the granularity we need, we'll change it if we need anything smaller
+*/
 
-
+#define STEP_MS 10
+#define STEP_MIC 10000
 SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
 {
 	switch_time_t reference = switch_time_now();
@@ -187,21 +169,17 @@
 	
 	memset(&globals, 0, sizeof(globals));
 	switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, module_pool);
-	globals.timer_microseconds = IDLE_SPEED  * 1000;
-	globals.timer_milliseconds = IDLE_SPEED;
 
 	globals.RUNNING = 1;
 
 	while(globals.RUNNING == 1) {
-		reference += globals.timer_microseconds;
+		reference += STEP_MIC;
 
 		while (switch_time_now() < reference) {
-			//switch_yield((reference - now) - 1000);
-			//switch_yield(globals.timer_microseconds >> 1);
-			switch_yield(1000);
+			switch_yield(STEP_MIC);
 		}
 
-		current_ms += globals.timer_milliseconds;
+		current_ms += STEP_MS;
 
 		for (x = 0; x < MAX_ELEMENTS; x++) {
 			int i = x, index;

Modified: freeswitch/branches/mishehu/src/switch_buffer.c
==============================================================================
--- freeswitch/branches/mishehu/src/switch_buffer.c	(original)
+++ freeswitch/branches/mishehu/src/switch_buffer.c	Wed Sep 27 00:28:54 2006
@@ -40,8 +40,9 @@
 
 struct switch_buffer {
 	switch_byte_t *data;
-	switch_byte_t *front;
+	switch_byte_t *head;
 	switch_size_t used;
+	switch_size_t actually_used;
 	switch_size_t datalen;
 	switch_size_t max_len;
 	switch_size_t blocksize;
@@ -57,7 +58,7 @@
 		&& (new_buffer->data = switch_core_alloc(pool, max_len)) != 0) {
 		new_buffer->datalen = max_len;
 		new_buffer->id = buffer_id++;
-		new_buffer->front = new_buffer->data;
+		new_buffer->head = new_buffer->data;
 		*buffer = new_buffer;
 		return SWITCH_STATUS_SUCCESS;
 	}
@@ -86,7 +87,7 @@
 		new_buffer->datalen = start_len;
 		new_buffer->id = buffer_id++;
 		new_buffer->blocksize = blocksize;
-		new_buffer->front = new_buffer->data;
+		new_buffer->head = new_buffer->data;
 		switch_set_flag(new_buffer, SWITCH_BUFFER_FLAG_DYNAMIC);
 		
 		*buffer = new_buffer;
@@ -143,10 +144,11 @@
 		reading = buffer->used;
 	}
 
-	memmove(buffer->data, buffer->data + reading, buffer->datalen - reading);
-	buffer->used -= datalen;
-
-	return buffer->datalen;
+	memmove(buffer->data, buffer->data + reading, reading);
+	buffer->head = buffer->data;
+	buffer->used -= reading;
+	buffer->actually_used = buffer->used;
+	return buffer->used;
 }
 
 SWITCH_DECLARE(switch_size_t) switch_buffer_read(switch_buffer_t *buffer, void *data, switch_size_t datalen)
@@ -166,44 +168,57 @@
 		reading = buffer->used;
 	}
 
-	memcpy(data, buffer->front, reading);
-
-	buffer->front += reading;
+	memcpy(data, buffer->head, reading);
 	buffer->used -= reading;
+	buffer->head += reading;
 
-	//if (buffer->id == 3) printf("%u o %d = %d\n", buffer->id, (uint32_t)reading, (uint32_t)buffer->used);
+	//if (buffer->id == 4) printf("%u o %d = %d\n", buffer->id, (uint32_t)reading, (uint32_t)buffer->used);
 	return reading;
 }
 
 SWITCH_DECLARE(switch_size_t) switch_buffer_write(switch_buffer_t *buffer, void *data, switch_size_t datalen)
 {
-	switch_size_t freespace;
+	switch_size_t freespace, actual_freespace;
 
 	assert(buffer != NULL);
 	assert(data != NULL);
 	assert(buffer->data != NULL);
+	
+	if (!datalen) {
+		return buffer->used;
+	}
 
-	freespace = buffer->datalen - buffer->used;
+	actual_freespace = buffer->datalen - buffer->actually_used;
 
-	if (buffer->used && buffer->data != buffer->front) {
-		memmove(buffer->data, buffer->front, buffer->used);
-		buffer->front = buffer->data;
+	if (actual_freespace < datalen) {
+		memmove(buffer->data, buffer->head, buffer->used);
+		buffer->head = buffer->data;
+		buffer->actually_used = buffer->used;
 	}
 
+	freespace = buffer->datalen - buffer->used;
+
+	/*
+	if (buffer->data != buffer->head) {
+		memmove(buffer->data, buffer->head, buffer->used);
+		buffer->head = buffer->data;
+	}
+	*/
 	if (switch_test_flag(buffer, SWITCH_BUFFER_FLAG_DYNAMIC)) {
 		if (freespace < datalen) {
 			switch_size_t new_size, new_block_size;
+
 			new_size = buffer->datalen + datalen;
 			new_block_size = buffer->datalen + buffer->blocksize;
 
 			if (new_block_size > new_size) {
 				new_size = new_block_size;
 			}
-
+			buffer->head = buffer->data;
 			if (!(buffer->data = realloc(buffer->data, new_size))) {
 				return 0;
 			}
-			buffer->front = buffer->data;
+			buffer->head = buffer->data;
 			buffer->datalen = new_size;
 		}
 	}
@@ -213,10 +228,11 @@
 	if (freespace < datalen) {
 		return 0;
 	} else {
-		memcpy(buffer->data + buffer->used, data, datalen);
+		memcpy(buffer->head + buffer->used, data, datalen);
 		buffer->used += datalen;
+		buffer->actually_used += datalen;
 	}
-	//if (buffer->id == 3) printf("%u i %d = %d\n", buffer->id, (uint32_t)datalen, (uint32_t)buffer->used);
+	//if (buffer->id == 4) printf("%u i %d = %d\n", buffer->id, (uint32_t)datalen, (uint32_t)buffer->used);
 
 	return buffer->used;
 }
@@ -227,7 +243,7 @@
     assert(buffer->data != NULL);
 
 	buffer->used = 0;
-	
+	buffer->head = buffer->data;
 }
 
 SWITCH_DECLARE(void) switch_buffer_destroy(switch_buffer_t **buffer)

Modified: freeswitch/branches/mishehu/src/switch_core.c
==============================================================================
--- freeswitch/branches/mishehu/src/switch_core.c	(original)
+++ freeswitch/branches/mishehu/src/switch_core.c	Wed Sep 27 00:28:54 2006
@@ -52,6 +52,8 @@
 #define SWITCH_EVENT_QUEUE_LEN 256
 #define SWITCH_SQL_QUEUE_LEN 2000
 
+#define SWITCH_BUFFER_BLOCK_FRAMES 25
+#define SWITCH_BUFFER_START_FRAMES 50
 
 struct switch_media_bug {
 	switch_buffer_t *raw_write_buffer;
@@ -253,10 +255,10 @@
 	bug->user_data = user_data;
 	bug->session = session;
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Attaching BUG to %s\n", switch_channel_get_name(session->channel));
-	bytes = session->read_codec->implementation->bytes_per_frame * 2;
-	switch_buffer_create_dynamic(&bug->raw_read_buffer, bytes, bytes, MAX_BUG_BUFFER);
-	bytes = session->write_codec->implementation->bytes_per_frame * 2;
-	switch_buffer_create_dynamic(&bug->raw_write_buffer, bytes, bytes, MAX_BUG_BUFFER);
+	bytes = session->read_codec->implementation->bytes_per_frame;
+	switch_buffer_create_dynamic(&bug->raw_read_buffer, bytes * SWITCH_BUFFER_BLOCK_FRAMES, bytes * SWITCH_BUFFER_START_FRAMES, MAX_BUG_BUFFER);
+	bytes = session->write_codec->implementation->bytes_per_frame;
+	switch_buffer_create_dynamic(&bug->raw_write_buffer, bytes * SWITCH_BUFFER_BLOCK_FRAMES, bytes * SWITCH_BUFFER_START_FRAMES, MAX_BUG_BUFFER);
 	switch_mutex_init(&bug->read_mutex, SWITCH_MUTEX_NESTED, session->pool);
 	switch_mutex_init(&bug->write_mutex, SWITCH_MUTEX_NESTED, session->pool);
 
@@ -1701,9 +1703,9 @@
 				perfect = TRUE;
 			} else {
 				if (!session->raw_read_buffer) {
-					switch_size_t bytes = session->read_codec->implementation->bytes_per_frame * 2;
+					switch_size_t bytes = session->read_codec->implementation->bytes_per_frame;
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Engaging Read Buffer at %u bytes\n", bytes);
-					switch_buffer_create_dynamic(&session->raw_read_buffer, bytes, bytes, 0);
+					switch_buffer_create_dynamic(&session->raw_read_buffer, bytes * SWITCH_BUFFER_BLOCK_FRAMES, bytes * SWITCH_BUFFER_START_FRAMES, 0);
 				}
 				if (!switch_buffer_write(session->raw_read_buffer, read_frame->data, read_frame->datalen)) {
 					status = SWITCH_STATUS_MEMERR;
@@ -1932,13 +1934,15 @@
 				perfect = TRUE;
 			} else {
 				if (!session->raw_write_buffer) {
-					switch_size_t bytes = session->write_codec->implementation->bytes_per_frame * 2;
+					switch_size_t bytes = session->write_codec->implementation->bytes_per_frame;
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
 										  "Engaging Write Buffer at %u bytes to accomodate %u->%u\n",
 										  bytes,
 										  write_frame->datalen, session->write_codec->implementation->bytes_per_frame);
-					if ((status =
-						 switch_buffer_create_dynamic(&session->raw_write_buffer, bytes, bytes, 0)) != SWITCH_STATUS_SUCCESS) {
+					if ((status =switch_buffer_create_dynamic(&session->raw_write_buffer,
+															  bytes * SWITCH_BUFFER_BLOCK_FRAMES,
+															  bytes * SWITCH_BUFFER_START_FRAMES,
+															  0)) != SWITCH_STATUS_SUCCESS) {
 						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Write Buffer Failed!\n");
 						return status;
 					}
@@ -2504,7 +2508,7 @@
 	
 }
 
-SWITCH_DECLARE(unsigned int) switch_core_session_runing(switch_core_session_t *session)
+SWITCH_DECLARE(unsigned int) switch_core_session_running(switch_core_session_t *session)
 {
 	return session->thread_running;
 }

Modified: freeswitch/branches/mishehu/src/switch_ivr.c
==============================================================================
--- freeswitch/branches/mishehu/src/switch_ivr.c	(original)
+++ freeswitch/branches/mishehu/src/switch_ivr.c	Wed Sep 27 00:28:54 2006
@@ -580,8 +580,10 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-#define FILE_STARTSAMPLES 512 * 128
-#define FILE_BLOCKSIZE 1024
+#define FILE_STARTSAMPLES 1024 * 32
+#define FILE_BLOCKSIZE 1024 * 8
+#define FILE_BUFSIZE 1024 * 64
+
 SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *session, 
 												   switch_file_handle_t *fh,
 												   char *file,
@@ -591,9 +593,9 @@
 												   unsigned int buflen)
 {
 	switch_channel_t *channel;
-	int16_t abuf[FILE_STARTSAMPLES+1];
+	int16_t abuf[FILE_STARTSAMPLES];
 	char dtmf[128];
-	uint32_t interval = 0, samples = 0;
+	uint32_t interval = 0, samples = 0, framelen;
 	uint32_t ilen = 0;
 	switch_size_t olen = 0;
 	switch_frame_t write_frame = {0};
@@ -608,7 +610,24 @@
 	switch_codec_t *read_codec = switch_core_session_get_read_codec(session);
 	const char *p;
 	char *title = "", *copyright = "", *software = "", *artist = "", *comment = "", *date = "";
+	uint8_t asis = 0;
+	char *ext;
 	
+	if (file) {
+		if ((ext = strrchr(file, '.'))) {
+			ext++;
+		} else {
+			char *new_file;
+			uint32_t len;
+			ext = read_codec->implementation->iananame;
+			len = (uint32_t)strlen(file) + (uint32_t)strlen(ext) + 2;
+			new_file = switch_core_session_alloc(session, len);
+			snprintf(new_file, len, "%s.%s", file, ext);
+			file = new_file;
+			asis = 1;
+		}
+	}
+
 	if (!fh) {
 		fh = &lfh;
 		memset(fh, 0, sizeof(lfh));
@@ -679,30 +698,43 @@
 	interval = read_codec->implementation->microseconds_per_frame / 1000;
 
 	if (!fh->audio_buffer) {
-		switch_buffer_create_dynamic(&fh->audio_buffer, FILE_BLOCKSIZE, (FILE_STARTSAMPLES * sizeof(int16_t)) + FILE_BLOCKSIZE, 0);
+		switch_buffer_create_dynamic(&fh->audio_buffer, FILE_BLOCKSIZE, FILE_BUFSIZE, 0);
 	} 
 
-	codec_name = "L16";
+	if (asis) {
+		write_frame.codec = read_codec;
+		samples = read_codec->implementation->samples_per_frame;
+		framelen = read_codec->implementation->encoded_bytes_per_frame;
+	} else {
+		codec_name = "L16";
 
-	if (switch_core_codec_init(&codec,
-							   codec_name,
-							   fh->samplerate,
-							   interval,
-							   fh->channels,
-							   SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
-							   NULL, pool) == SWITCH_STATUS_SUCCESS) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activated\n");
+		if (switch_core_codec_init(&codec,
+								   codec_name,
+								   fh->samplerate,
+								   interval,
+								   fh->channels,
+								   SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
+								   NULL, pool) == SWITCH_STATUS_SUCCESS) {
+			switch_log_printf(SWITCH_CHANNEL_LOG,
+							  SWITCH_LOG_DEBUG,
+							  "Codec Activated %s@%uhz %u channels %dms\n",
+							  codec_name,
+							  fh->samplerate,
+							  fh->channels,
+							  interval);
 
-		write_frame.codec = &codec;
-	} else {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activation Failed %s@%uhz %u channels %dms\n",
+			write_frame.codec = &codec;
+		} else {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activation Failed %s@%uhz %u channels %dms\n",
 							  codec_name, fh->samplerate, fh->channels, interval);
-		switch_core_file_close(fh);
-		switch_core_session_reset(session);
-		return SWITCH_STATUS_GENERR;
+			switch_core_file_close(fh);
+			switch_core_session_reset(session);
+			return SWITCH_STATUS_GENERR;
+		}
+		samples = codec.implementation->samples_per_frame;
+		framelen = codec.implementation->bytes_per_frame;
 	}
 
-	samples = codec.implementation->bytes_per_frame / 2;
 
 	if (timer_name) {
 		uint32_t len;
@@ -727,6 +759,7 @@
 	}
 
 	ilen = samples;
+
 	while(switch_channel_ready(channel)) {
 		int done = 0;
 		int do_speed = 1;
@@ -768,36 +801,41 @@
 		}
 		
 		if (switch_test_flag(fh, SWITCH_FILE_PAUSE)) {
-			memset(abuf, 0, ilen * 2);
+			memset(abuf, 0, framelen);
 			olen = ilen;
             do_speed = 0;
-		} else if (fh->audio_buffer && (switch_buffer_inuse(fh->audio_buffer) > (switch_size_t)(ilen * 2))) {
-			switch_buffer_read(fh->audio_buffer, abuf, ilen * 2);
-			olen = ilen;
+		} else if (fh->audio_buffer && (switch_buffer_inuse(fh->audio_buffer) > (switch_size_t)(framelen))) {
+			switch_buffer_read(fh->audio_buffer, abuf, framelen);
+			olen = asis ? framelen : ilen;
 			do_speed = 0;
 		} else {
-			olen = FILE_STARTSAMPLES;
+			olen = 32 * framelen;
 			switch_core_file_read(fh, abuf, &olen);
-			switch_buffer_write(fh->audio_buffer, abuf, olen * 2);
-			olen = switch_buffer_read(fh->audio_buffer, abuf, ilen * 2) / 2;
+			switch_buffer_write(fh->audio_buffer, abuf, asis ? olen : olen * 2);
+			olen = switch_buffer_read(fh->audio_buffer, abuf, framelen);
+			if (!asis) {
+				olen /= 2;
+			} 
 		}
 
 		if (done || olen <= 0) {
 			break;
 		}
 
-		if (fh->speed > 2) {
-			fh->speed = 2;
-		} else if (fh->speed < -2) {
-			fh->speed = -2;
+		if (!asis) {
+			if (fh->speed > 2) {
+				fh->speed = 2;
+			} else if (fh->speed < -2) {
+				fh->speed = -2;
+			}
 		}
 		
-		if (fh->audio_buffer && last_speed > -1 && last_speed != fh->speed) {
+		if (!asis && fh->audio_buffer && last_speed > -1 && last_speed != fh->speed) {
 			switch_buffer_zero(fh->audio_buffer);
 		}
 
 		
-		if (fh->speed && do_speed) {
+		if (!asis && fh->speed && do_speed) {
 			float factor = 0.25f * abs(fh->speed);
 			switch_size_t newlen, supplement, step;
 			short *bp = write_frame.data;
@@ -831,14 +869,17 @@
 			}
 			last_speed = fh->speed;
 			continue;
-		} 
-
-		write_frame.datalen = (uint32_t)(olen * 2);
+		}
+		
+		write_frame.datalen = (uint32_t)(olen * (asis ? 1 : 2));
 		write_frame.samples = (uint32_t)olen;
 
+		
+
+
 #ifndef WIN32
 #if __BYTE_ORDER == __BIG_ENDIAN
-		switch_swap_linear(write_frame.data, (int) write_frame.datalen / 2);
+		if (!asis) {switch_swap_linear(write_frame.data, (int) write_frame.datalen / 2);}
 #endif
 #endif
 		for (stream_id = 0; stream_id < switch_core_session_get_stream_count(session); stream_id++) {
@@ -877,8 +918,9 @@
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "done playing file\n");
 	switch_core_file_close(fh);
 	switch_buffer_destroy(&fh->audio_buffer);
-	switch_core_codec_destroy(&codec);
-
+	if (!asis) {
+		switch_core_codec_destroy(&codec);
+	}
 	if (timer_name) {
 		/* End the audio absorbing thread */
 		switch_core_thread_session_end(&thread_session);
@@ -1827,7 +1869,7 @@
 			switch_channel_add_state_handler(peer_channels[i], table);
 		}
 
-		if (switch_core_session_runing(peer_sessions[i])) {
+		if (switch_core_session_running(peer_sessions[i])) {
 			switch_channel_set_state(peer_channels[i], CS_RING);
 		} else {
 			switch_core_session_thread_launch(peer_sessions[i]);

Modified: freeswitch/branches/mishehu/src/switch_rtp.c
==============================================================================
--- freeswitch/branches/mishehu/src/switch_rtp.c	(original)
+++ freeswitch/branches/mishehu/src/switch_rtp.c	Wed Sep 27 00:28:54 2006
@@ -389,7 +389,7 @@
 
 	switch_mutex_init(&rtp_session->flag_mutex, SWITCH_MUTEX_NESTED, rtp_session->pool);
 	switch_mutex_init(&rtp_session->dtmf_data.dtmf_mutex, SWITCH_MUTEX_NESTED, rtp_session->pool);
-	switch_buffer_create(rtp_session->pool, &rtp_session->dtmf_data.dtmf_buffer, 128);
+	switch_buffer_create_dynamic(&rtp_session->dtmf_data.dtmf_buffer, 128, 128, 0);
 	/* for from address on recvfrom calls */
 	switch_sockaddr_info_get(&rtp_session->from_addr, NULL, SWITCH_UNSPEC, 0, 0, rtp_session->pool);
 	
@@ -475,15 +475,15 @@
 		}
 	}
 
-	if (timer_name) {
+	if (!switch_strlen_zero(timer_name)) {
 		switch_set_flag_locked(rtp_session, SWITCH_RTP_FLAG_USE_TIMER);
 	}
 
-	if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_USE_TIMER) && !timer_name) {
+	if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_USE_TIMER) && switch_strlen_zero(timer_name)) {
 		timer_name = "soft";
 	}
 
-	if (timer_name) {
+	if (!switch_strlen_zero(timer_name)) {
 		if (switch_core_timer_init(&rtp_session->timer, timer_name, ms_per_packet / 1000, packet_size, rtp_session->pool) == SWITCH_STATUS_SUCCESS) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Starting timer [%s] %d bytes per %dms\n", timer_name, packet_size, ms_per_packet);
 		} else {
@@ -588,7 +588,10 @@
 	if ((*rtp_session)->packet_buffer) {
 		switch_buffer_destroy(&(*rtp_session)->packet_buffer);
 	}
-			
+	if ((*rtp_session)->dtmf_data.dtmf_buffer) {
+		switch_buffer_destroy(&(*rtp_session)->dtmf_data.dtmf_buffer);
+	}
+
 	switch_rtp_kill_socket(*rtp_session);
 	switch_socket_close((*rtp_session)->sock);
 	(*rtp_session)->sock = NULL;

Modified: freeswitch/branches/mishehu/src/switch_xml.c
==============================================================================
--- freeswitch/branches/mishehu/src/switch_xml.c	(original)
+++ freeswitch/branches/mishehu/src/switch_xml.c	Wed Sep 27 00:28:54 2006
@@ -168,8 +168,7 @@
 
 	for (p = switch_xml_child(node, childname); p; p = p->next) {
 		const char *aname = switch_xml_attr(p, attrname);
-
-		if (!strcasecmp(aname, value)) {
+		if (aname && value && !strcasecmp(aname, value)) {
 			break;
 		}
 	}



More information about the Freeswitch-branches mailing list