[Freeswitch-svn] [commit] r4873 - in freeswitch/branches/mikej/sofiasip-upgrade: . build conf libs/libdingaling/src libs/srtp src src/include src/mod src/mod/applications/mod_conference src/mod/endpoints/mod_dingaling src/mod/endpoints/mod_sofia src/mod/event_handlers/mod_cdr src/mod/languages/mod_spidermonkey src/mod/languages/mod_spidermonkey_odbc src/mod/languages/mod_spidermonkey_teletone w32/Library

Freeswitch SVN mikej at freeswitch.org
Fri Apr 6 19:25:40 EDT 2007


Author: mikej
Date: Fri Apr  6 19:25:38 2007
New Revision: 4873

Added:
   freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_odbc.h
      - copied unchanged from r4872, /freeswitch/trunk/src/include/switch_odbc.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_odbc.c
      - copied unchanged from r4872, /freeswitch/trunk/src/switch_odbc.c
Modified:
   freeswitch/branches/mikej/sofiasip-upgrade/Freeswitch.sln
   freeswitch/branches/mikej/sofiasip-upgrade/Makefile.am
   freeswitch/branches/mikej/sofiasip-upgrade/bootstrap.sh
   freeswitch/branches/mikej/sofiasip-upgrade/build/turbo_build.sh
   freeswitch/branches/mikej/sofiasip-upgrade/conf/dingaling.conf.xml
   freeswitch/branches/mikej/sofiasip-upgrade/conf/freeswitch.xml
   freeswitch/branches/mikej/sofiasip-upgrade/conf/freeswitch_combined.xml
   freeswitch/branches/mikej/sofiasip-upgrade/conf/sofia.conf.xml
   freeswitch/branches/mikej/sofiasip-upgrade/configure.in
   freeswitch/branches/mikej/sofiasip-upgrade/libs/libdingaling/src/libdingaling.c
   freeswitch/branches/mikej/sofiasip-upgrade/libs/libdingaling/src/libdingaling.h
   freeswitch/branches/mikej/sofiasip-upgrade/libs/srtp/Makefile.am
   freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_buffer.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_platform.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_types.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/Makefile.am
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_conference/mod_conference.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_dingaling/Makefile
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_dingaling/mod_dingaling.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/Makefile
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/mod_sofia.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/mod_sofia.h
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/sofia.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/sofia_glue.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/sofia_presence.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/sofia_reg.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/Makefile.am
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey_odbc/Makefile
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey_odbc/mod_spidermonkey_odbc.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey_teletone/mod_spidermonkey_teletone.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_buffer.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_event.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_ivr_originate.c
   freeswitch/branches/mikej/sofiasip-upgrade/src/switch_rtp.c
   freeswitch/branches/mikej/sofiasip-upgrade/w32/Library/FreeSwitchCore.vcproj

Log:
merged changes from trunk revisions 4823-4872.

Modified: freeswitch/branches/mikej/sofiasip-upgrade/Freeswitch.sln
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/Freeswitch.sln	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/Freeswitch.sln	Fri Apr  6 19:25:38 2007
@@ -492,6 +492,7 @@
 		conf\ivr.conf.xml = conf\ivr.conf.xml
 		conf\lang_en.xml = conf\lang_en.xml
 		conf\lang_fr.xml = conf\lang_fr.xml
+		conf\mod_cdr.conf.xml = conf\mod_cdr.conf.xml
 		conf\modules.conf.xml = conf\modules.conf.xml
 		conf\portaudio.conf.xml = conf\portaudio.conf.xml
 		conf\rss.conf.xml = conf\rss.conf.xml
@@ -524,6 +525,7 @@
 		release\conf\ivr.conf.xml = release\conf\ivr.conf.xml
 		release\conf\lang_en.xml = release\conf\lang_en.xml
 		release\conf\lang_fr.xml = release\conf\lang_fr.xml
+		release\conf\mod_cdr.conf.xml = release\conf\mod_cdr.conf.xml
 		release\conf\modules.conf.xml = release\conf\modules.conf.xml
 		release\conf\portaudio.conf.xml = release\conf\portaudio.conf.xml
 		release\conf\rss.conf.xml = release\conf\rss.conf.xml
@@ -556,6 +558,7 @@
 		debug\conf\ivr.conf.xml = debug\conf\ivr.conf.xml
 		debug\conf\lang_en.xml = debug\conf\lang_en.xml
 		debug\conf\lang_fr.xml = debug\conf\lang_fr.xml
+		debug\conf\mod_cdr.conf.xml = debug\conf\mod_cdr.conf.xml
 		debug\conf\modules.conf.xml = debug\conf\modules.conf.xml
 		debug\conf\portaudio.conf.xml = debug\conf\portaudio.conf.xml
 		debug\conf\rss.conf.xml = debug\conf\rss.conf.xml

Modified: freeswitch/branches/mikej/sofiasip-upgrade/Makefile.am
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/Makefile.am	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/Makefile.am	Fri Apr  6 19:25:38 2007
@@ -103,6 +103,11 @@
 CORE_LIBS      = libs/apr/libapr-1.la libs/apr-util/libaprutil-1.la
 CORE_LIBS     += libs/sqlite/libsqlite3.la libs/pcre/libpcre.la
 CORE_LIBS     += libs/srtp/libsrtp.la $(RESAMPLE_LIB)
+if ADD_ODBC
+libfreeswitch_la_SOURCES += src/switch_odbc.c
+library_include_HEADERS += src/include/switch_odbc.h
+CORE_LIBS     += -lodbc
+endif
 
 lib_LTLIBRARIES	          = libfreeswitch.la
 libfreeswitch_la_CFLAGS   = $(CORE_CFLAGS) $(AM_CFLAGS)
@@ -113,7 +118,7 @@
 MOD_LINK       = $(BASE)/libfreeswitch.la
 
 CLEANFILES     = src/include/switch_version.h
-BUILT_SOURCES  = src/include/switch_version.h
+BUILT_SOURCES  = src/include/switch_version.h ./$(DEPDIR)/modules.targets
 
 bin_PROGRAMS = freeswitch
 freeswitch_SOURCES = src/switch.c
@@ -122,7 +127,7 @@
 freeswitch_LDFLAGS = $(AM_LDFLAGS) -rpath $(libdir)
 freeswitch_LDADD = libfreeswitch.la libs/apr/libapr-1.la
 
-$(libfreeswitch_la_SOURCES): $(CORE_LIBS) $(switch_builddir)/quiet_libtool
+$(libfreeswitch_la_SOURCES): $(CORE_LIBS) $(switch_builddir)/quiet_libtool modules.conf
 
 $(switch_builddir)/quiet_libtool: $(switch_builddir)/libtool
 	@cat libtool | sed -e 's|$$show "$$command"|if test -z "$$suppress_output" ; then $$show "Compiling $$srcfile ..." ; fi|' > quiet_libtool
@@ -170,7 +175,7 @@
 	@cd libs/apr && $(MAKE)
 	@$(TOUCH_TARGET)
 
-libs/apr-util/libaprutil-1.la: libs/apr-util libs/apr-util/.update
+libs/apr-util/libaprutil-1.la: libs/apr-util libs/apr-util/.update libs/apr/libapr-1.la
 	@cd libs/apr-util && $(MAKE)
 	@$(TOUCH_TARGET)
 
@@ -239,6 +244,19 @@
 megaclean: eclean modclean
 	rm -f `find ./libs -name \*.la`
 
+ at am__include@ @am__quote at ./$(DEPDIR)/modules.targets at am__quote@
+
+modules.conf:
+	if test -f $@; then touch $@; else cp build/modules.conf.in $@ ;fi
+
+./$(DEPDIR)/modules.targets: modules.conf
+	mods=`cat modules.conf | sed -e 's|^.*/||'`; echo MODULE_TARGETS=\"$$mods\" > ./$(DEPDIR)/modules.targets
+
+$(MODULE_TARGETS):
+	@set fnord $$MAKEFLAGS; amf=$$2; \
+	(cd src/mod && $(MAKE) $(AM_MAKEFLAGS) $@) \
+	   || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
+	test -z "$$fail"
 
 # Special targets
 

Modified: freeswitch/branches/mikej/sofiasip-upgrade/bootstrap.sh
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/bootstrap.sh	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/bootstrap.sh	Fri Apr  6 19:25:38 2007
@@ -4,7 +4,7 @@
 BASEDIR=`pwd`;
 LIBDIR=${BASEDIR}/libs;
 SUBDIRS="codec/g7xx codec/g726 codec/gsm codec/ilbc codec/lpc10 curl iax iksemel  \
-        js js/nsprpub libdingaling libetpan libresample libsndfile libteletone pcre sofia-sip \
+        js js/nsprpub libdingaling libetpan libresample libsndfile pcre sofia-sip \
         speex sqlite srtp xmlrpc-c";
 
 # keep automake from making us magically GPL, and to stop complaining about missing files.

Modified: freeswitch/branches/mikej/sofiasip-upgrade/build/turbo_build.sh
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/build/turbo_build.sh	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/build/turbo_build.sh	Fri Apr  6 19:25:38 2007
@@ -5,7 +5,7 @@
 fi
 
 if [ -z $arg ] ; then
-    $MAKE -j8 core
+    $MAKE -j freeswitch
     MODS=`cat modules.conf | grep -v \#`
     for i in $MODS ; do 
 	MOD_NAME=`echo $i | sed -e 's|^.*/||'`
@@ -21,8 +21,8 @@
 	    fi
 	done
 	if [ $x = 0 ] ; then
-	    sleep 1
-	    echo done
+	    echo Build finished. Making install
+	    $MAKE install
 	    exit;
 	fi
 	sleep 1
@@ -42,9 +42,9 @@
 
 echo "Making module in $MOD_NAME"
 if [ -f $MOD_DIR/Makefile ] ; then 
-    cd $MOD_DIR && BASE=$switch_srcdir $MAKE
+    cd $MOD_DIR && BASE=$switch_srcdir $MAKE -j
 else
-    cd $MOD_DIR && BASE=$switch_srcdir $MAKE -f $switch_srcdir/build/modmake.rules
+    cd $MOD_DIR && BASE=$switch_srcdir $MAKE -j -f $switch_srcdir/build/modmake.rules
 fi
 
 echo "Finished making module in $MOD_NAME"

Modified: freeswitch/branches/mikej/sofiasip-upgrade/conf/dingaling.conf.xml
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/conf/dingaling.conf.xml	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/conf/dingaling.conf.xml	Fri Apr  6 19:25:38 2007
@@ -33,6 +33,7 @@
     <!-- <param name="vad" value="in"/> -->
     <!-- <param name="vad" value="out"/> -->
     <param name="vad" value="both"/>
+    <!--<param name="avatar" value="/path/to/tiny.jpg"/>-->
   </x-profile>
 
   <!-- Component (Server to Server Login) -->
@@ -48,6 +49,10 @@
     <!-- "_auto_" means the extension will be automaticly set to the called jid -->
     <param name="exten" value="_auto_"/>
     <!--<param name="vad" value="both"/>-->
+    <!--<param name="avatar" value="/path/to/tiny.jpg"/>-->
+    <!--If you have ODBC support and a working dsn you can use it instead of SQLite-->
+    <!--<param name="odbc-dsn" value="dsn:user:pass"/>-->
+
   </x-profile>
 
 </configuration>

Modified: freeswitch/branches/mikej/sofiasip-upgrade/conf/freeswitch.xml
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/conf/freeswitch.xml	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/conf/freeswitch.xml	Fri Apr  6 19:25:38 2007
@@ -40,6 +40,7 @@
     <!--#include "conference.conf.xml"-->
     <!--#include "enum.conf.xml"-->
     <!--#include "ivr.conf.xml"-->
+    <!--#include "mod_cdr.conf.xml"-->
   </section>
   
   <section name="dialplan" description="Regex/XML Dialplan">

Modified: freeswitch/branches/mikej/sofiasip-upgrade/conf/freeswitch_combined.xml
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/conf/freeswitch_combined.xml	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/conf/freeswitch_combined.xml	Fri Apr  6 19:25:38 2007
@@ -524,7 +524,32 @@
 	  <entry action="menu-top" digits="*"/>
 	</menu>
       </menus>
-    </configuration> 
+    </configuration>
+    <configuration name="mod_cdr.conf" description="CDR Configuration">
+      <pddcdr>
+        <param name="path" value="/work/temp/pddcdr"/>
+        <!-- <param name="chanvars" value="username,accountcode"/> -->
+        <!-- <param name="chanvars_fixed" value="foo"/> -->
+      </pddcdr>
+      <csvcdr>
+        <param name="path" value="/work/temp/csvcdr"/>
+        <param name="size_limit" value="25"/>
+        <!-- <param name="chanvars_fixed" value="username"/> -->
+        <!-- <param name="chanvars_supp" value="*"/> -->
+        <!-- <param name="repeat_fixed_in_supp" value="0"/> -->
+      </csvcdr>
+      <mysqlcdr>
+        <param name="hostname" value="10.0.0.1"/>
+        <param name="username" value="test"/>
+        <param name="password" value="test"/>
+        <param name="dbname" value="testing"/>
+        <!-- This following line logs username as a varchar, and The_Kow as a tiny -->
+        <!-- <param name="chanvars_fixed" value="username=s,The_Kow=t"/> -->
+        <!-- If you do not want to log any and all chanvars to the chanvar table, comment the next 2 lines out -->
+        <param name="chanvars_supp" value="*"/>
+        <param name="chanvars_supp_repeat_fixed" value="0"/>
+      </mysqlcdr>
+    </configuration>
 
   </section>
   

Modified: freeswitch/branches/mikej/sofiasip-upgrade/conf/sofia.conf.xml
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/conf/sofia.conf.xml	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/conf/sofia.conf.xml	Fri Apr  6 19:25:38 2007
@@ -31,6 +31,12 @@
 	<param name="rtp-ip" value="auto"/>
 	<param name="sip-ip" value="auto"/>
 
+	<!--If you don't want to pass through timestampes from 1 RTP call to another (on a per call basis with rtp_rewrite_timestamps chanvar)-->
+	<!--<param name="rtp-rewrite-timestampes" value="true"/>-->
+
+	<!--If you have ODBC support and a working dsn you can use it instead of SQLite-->
+	<!--<param name="odbc-dsn" value="dsn:user:pass"/>-->
+
 	<!--Uncomment to set all inbound calls to no media mode-->
 	<!--<param name="inbound-no-media" value="true"/>-->
 

Modified: freeswitch/branches/mikej/sofiasip-upgrade/configure.in
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/configure.in	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/configure.in	Fri Apr  6 19:25:38 2007
@@ -32,6 +32,11 @@
 AC_PROG_AWK
 AC_PROG_MAKE_SET
 AC_PROG_INSTALL
+
+#override some default libtool behavior and invoke AC_PROG_LIBTOOL (see http://lists.gnu.org/archive/html/libtool/2007-03/msg00000.html)
+m4_defun([_LT_AC_LANG_F77_CONFIG], [:])
+m4_defun([_LT_AC_LANG_GCJ_CONFIG], [:])
+m4_defun([_LT_AC_LANG_RC_CONFIG], [:])
 AC_PROG_LIBTOOL
 
 #Check for compiler vendor
@@ -309,11 +314,15 @@
 AC_ARG_ENABLE(crash-protection,     
 	[  --enable-crash-protection         Compile with CRASH Protection],,[enable_crash_prot="no"])
 
+AC_ARG_ENABLE(core-odbc-support,     
+	[  --enable-core-odbc-support         Compile with ODBC Support],,[enable_core_odbc_support="no"])
+
 #AX_LIB_MYSQL([MINIMUM-VERSION]) 
 AX_LIB_MYSQL
 
 AM_CONDITIONAL([CRASHPROT],[test "x$enable_crash_prot" != "xno"])
-AM_CONDITIONAL([HAVE_MYSQL],[test "$have_mysql" = "yes"])
+AM_CONDITIONAL([ADD_ODBC],[test "x$enable_core_odbc_support" != "xno"])
+AM_CONDITIONAL([HAVE_MYSQL],[test "$found_mysql" = "yes"])
 
 AC_CONFIG_FILES([Makefile
                 src/Makefile

Modified: freeswitch/branches/mikej/sofiasip-upgrade/libs/libdingaling/src/libdingaling.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/libs/libdingaling/src/libdingaling.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/libs/libdingaling/src/libdingaling.c	Fri Apr  6 19:25:38 2007
@@ -31,6 +31,11 @@
 
 #ifndef  _MSC_VER
 #include <config.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
 #endif
 
 #include <string.h>
@@ -38,6 +43,7 @@
 #include <stdlib.h>
 #include <assert.h>
 #include <ctype.h>
+#include <fcntl.h>
 #include <iksemel.h>
 #include <apr.h>
 #include <apr_network_io.h>
@@ -67,13 +73,18 @@
 #include "sha1.h"
 
 #ifdef _MSC_VER
+#include <io.h>
 #pragma warning(disable:4127 4706)
 #endif
 
 #define microsleep(x) apr_sleep(x * 1000)
+#define LDL_CAPS_VER "1.0.0.1"
 
 static int opt_timeout = 30;
 
+static void sha1_hash(char *out, char *in, unsigned int len);
+static int b64encode(unsigned char *in, size_t ilen, unsigned char *out, size_t olen);
+static void ldl_random_string(char *buf, uint16_t len, char *set);
 
 static struct {
 	unsigned int flags;
@@ -82,6 +93,7 @@
 	apr_pool_t *memory_pool;
 	unsigned int id;
 	ldl_logger_t logger;
+	apr_hash_t *avatar_hash;
 	apr_thread_mutex_t *flag_mutex;
 } globals;
 
@@ -152,6 +164,40 @@
 	void *private_data;
 };
 
+static int on_disco_default(void *user_data, ikspak *pak);
+static int on_vcard(void *user_data, ikspak *pak);
+typedef int (*iks_filter_callback_t)(void *user_data, ikspak *pak);
+
+struct ldl_feature {
+	const char *name;
+	iks_filter_callback_t callback;
+};
+typedef struct ldl_feature ldl_feature_t;
+
+#define FEATURE_DISCO "http://jabber.org/protocol/disco"
+#define FEATURE_VERSION "jabber:iq:version"
+#define FEATURE_VCARD "vcard-temp"
+#define FEATURE_VOICE "http://www.google.com/xmpp/protocol/voice/v1"
+#define FEATURE_LAST "jabber:iq:last"
+
+static ldl_feature_t FEATURES[] = { 
+	{ FEATURE_DISCO, on_disco_default },
+	{ FEATURE_VERSION, on_disco_default },
+	{ FEATURE_VCARD, on_vcard},
+	{ FEATURE_VOICE, on_disco_default },
+	{ FEATURE_LAST, on_disco_default },
+	{ NULL, NULL}
+};
+
+
+struct ldl_avatar {
+	char *path;
+	char *base64;
+	char hash[256];
+};
+
+typedef struct ldl_avatar ldl_avatar_t;
+
 
 static void lowercase(char *str) 
 {
@@ -480,19 +526,6 @@
 
 const char *marker = "TRUE";
 
-static int on_vcard(void *user_data, ikspak *pak)
-{
-	ldl_handle_t *handle = user_data;
-	char *from = iks_find_attrib(pak->x, "from");
-	char *to = iks_find_attrib(pak->x, "to");
-
-	if (handle->session_callback) {
-		handle->session_callback(handle, NULL, LDL_SIGNAL_VCARD, to, from, pak->id, NULL); 
-	}
-
-	return IKS_FILTER_EAT;
-}
-
 static int on_disco_info(void *user_data, ikspak *pak)
 {
 	ldl_handle_t *handle = user_data;
@@ -584,89 +617,81 @@
 	return IKS_FILTER_EAT;
 }
 
-static int on_component_disco_info(void *user_data, ikspak *pak)
+
+static int on_vcard(void *user_data, ikspak *pak)
 {
-	char *node = iks_find_attrib(pak->query, "node");
 	ldl_handle_t *handle = user_data;
+	char *from = iks_find_attrib(pak->x, "from");
+	char *to = iks_find_attrib(pak->x, "to");
 
-	if (pak->subtype == IKS_TYPE_RESULT) {
-		globals.logger(DL_LOG_DEBUG, "FixME!!! node=[%s]\n", node?node:"");		
-	} else if (pak->subtype == IKS_TYPE_GET) {
-		//	if (ldl_test_flag(handle, LDL_FLAG_COMPONENT)) {
-		if (node) {
-			
-		} else {
-			iks *iq, *query, *tag;
-			uint8_t send = 0;
+	if (handle->session_callback) {
+		handle->session_callback(handle, NULL, LDL_SIGNAL_VCARD, to, from, pak->id, NULL); 
+	}
 
-			if ((iq = iks_new("iq"))) {
-				do {
-					iks_insert_attrib(iq, "from", handle->login);
-					iks_insert_attrib(iq, "to", pak->from->full);
-					iks_insert_attrib(iq, "id", pak->id);
-					iks_insert_attrib(iq, "type", "result");
+	return IKS_FILTER_EAT;
+}
 
-					if (!(query = iks_insert (iq, "query"))) {
-						break;
-					}
-					iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#info");
-					
-					if (!(tag = iks_insert (query, "identity"))) {
-						break;
-					}
-					iks_insert_attrib(tag, "category", "gateway");
-					iks_insert_attrib(tag, "type", "voice");
-					iks_insert_attrib(tag, "name", "LibDingaLing");
-				
 
-					if (!(tag = iks_insert (query, "feature"))) {
-						break;
-					}
-					iks_insert_attrib(tag, "var", "http://jabber.org/protocol/disco");
+static int on_disco_default(void *user_data, ikspak *pak)
+{
+	char *node = NULL;
+	char *ns;
+	ldl_handle_t *handle = user_data;
+	iks *iq, *query, *tag;
+	uint8_t send = 0;
+	int x;
 
-					if (!(tag = iks_insert (query, "feature"))) {
-						break;
-					}
-					iks_insert_attrib(tag, "var", "jabber:iq:register");
-				
-					/*
-					if (!(tag = iks_insert (query, "feature"))) {
-						break;
-					}
-					iks_insert_attrib(tag, "var", "http://jabber.org/protocol/commands");
-					*/
+	if (pak && pak->query) {
+		ns = iks_find_attrib(pak->query, "xmlns");
+		node = iks_find_attrib(pak->query, "node");
+	}
 
-					if (!(tag = iks_insert (query, "feature"))) {
-						break;
-					}
-					iks_insert_attrib(tag, "var", "jabber:iq:gateway");
+	if (pak->subtype == IKS_TYPE_RESULT) {
+		globals.logger(DL_LOG_DEBUG, "FixME!!! node=[%s]\n", node?node:"");		
+	} else if (pak->subtype == IKS_TYPE_GET) {
+		if ((iq = iks_new("iq"))) {
+			iks_insert_attrib(iq, "from", handle->login);
+			iks_insert_attrib(iq, "to", pak->from->full);
+			iks_insert_attrib(iq, "id", pak->id);
+			iks_insert_attrib(iq, "type", "result");
+					
+			if (!(query = iks_insert (iq, "query"))) {
+				goto fail;
+			}
+			iks_insert_attrib(query, "xmlns", ns);
 
-					if (!(tag = iks_insert (query, "feature"))) {
-						break;
-					}
-					iks_insert_attrib(tag, "var", "jabber:iq:version");
+			if (!strcasecmp(ns, FEATURE_LAST)) {
+				iks_insert_attrib(query, "seconds", "1");
+			}
+			
+			if (!(tag = iks_insert (query, "identity"))) {
+				goto fail;
+			}
 
-					if (!(tag = iks_insert (query, "feature"))) {
-						break;
-					}
-					iks_insert_attrib(tag, "var", "vcard-temp");
+			iks_insert_attrib(tag, "category", "gateway");
+			iks_insert_attrib(tag, "type", "voice");
+			iks_insert_attrib(tag, "name", "LibDingaLing");
 
+			for (x = 0; FEATURES[x].name; x++) {
+				if (!ns || !strcasecmp(ns, FEATURES[x].name)) {
 					if (!(tag = iks_insert (query, "feature"))) {
-						break;
+						goto fail;
 					}
-					iks_insert_attrib(tag, "var", "jabber:iq:search");
-
-					iks_send(handle->parser, iq);
-					send = 1;
-				} while (0);
-
-				iks_delete(iq);
-			}
-
-			if (!send) {
-				globals.logger(DL_LOG_DEBUG, "Memory Error!\n");
+					iks_insert_attrib(tag, "var", FEATURES[x].name);
+				}
 			}
 			
+			iks_send(handle->parser, iq);
+			send = 1;
+		}
+	fail:
+
+		if (iq) {
+			iks_delete(iq);
+		}
+
+		if (!send) {
+			globals.logger(DL_LOG_DEBUG, "Memory Error!\n");
 		}
 	}
 
@@ -750,7 +775,82 @@
 	return IKS_FILTER_EAT;
 }
 
-static void do_presence(ldl_handle_t *handle, char *from, char *to, char *type, char *rpid, char *message) 
+static char *ldl_handle_strdup(ldl_handle_t *handle, char *str)
+{
+	char *dup;
+	apr_size_t len;
+
+	len = strlen(str) + 1;
+	dup = apr_palloc(handle->pool, len);
+	assert(dup != NULL);
+	strncpy(dup, str, len);
+	return dup;
+}
+
+static void ldl_strip_resource(char *in)
+{
+	char *p;
+
+	if ((p = strchr(in, '/'))) {
+		*p = '\0';
+	}
+}
+
+static ldl_avatar_t *ldl_get_avatar(ldl_handle_t *handle, char *path, char *from)
+{
+	ldl_avatar_t *ap;
+	uint8_t image[8192];
+	unsigned char base64[9216] = "";
+	int fd = -1;
+	size_t bytes;
+	char *key;
+	char hash[128] = "";
+
+	if (from && (ap = (ldl_avatar_t *) apr_hash_get(globals.avatar_hash, from, APR_HASH_KEY_STRING))) {
+		return ap;
+	}
+
+	if (path && from) {
+		if ((ap = (ldl_avatar_t *) apr_hash_get(globals.avatar_hash, path, APR_HASH_KEY_STRING))) {
+			key = ldl_handle_strdup(handle, from);
+			ldl_strip_resource(key);
+			apr_hash_set(globals.avatar_hash, key, APR_HASH_KEY_STRING, ap);
+			return ap;
+		}
+	}
+
+	if (!(path && from)) {
+		return NULL;
+	}
+
+	if ((fd = open(path, O_RDONLY, 0)) < 0) {
+		globals.logger(DL_LOG_ERR, "File %s does not exist!\n", path);
+		return NULL;
+	}
+	
+	bytes = read(fd, image, sizeof(image));
+	close(fd);
+	fd = -1;
+
+	ap = malloc(sizeof(*ap));
+	assert(ap != NULL);
+	memset(ap, 0, sizeof(*ap));
+	ldl_random_string(hash, sizeof(hash) -1, NULL);
+	sha1_hash(ap->hash, hash, strlen(hash));
+	ap->path = strdup(path);
+
+	key = ldl_handle_strdup(handle, from);
+	ldl_strip_resource(key);
+
+	b64encode((unsigned char *)image, bytes, base64, sizeof(base64));
+	ap->base64 = strdup((const char *)base64);
+	apr_hash_set(globals.avatar_hash, ap->path, APR_HASH_KEY_STRING, ap);
+	apr_hash_set(globals.avatar_hash, key, APR_HASH_KEY_STRING, ap);
+	return ap;
+}
+
+
+static void do_presence(ldl_handle_t *handle, char *from, char *to, char *type, char *rpid, char *message, char *avatar) 
 {
 	iks *pres;
 	char buf[512];
@@ -791,9 +891,23 @@
 		}
 
 		if (message || rpid) {
+			ldl_avatar_t *ap;
+
+			if (avatar) {
+				if ((ap = ldl_get_avatar(handle, avatar, from))) {
+					if ((tag = iks_insert(pres, "x"))) {
+						iks *hash;
+						iks_insert_attrib(tag, "xmlns", "vcard-temp:x:update");
+						if ((hash = iks_insert(tag, "photo"))) {
+							iks_insert_cdata(hash, ap->hash, 0);
+						}
+					}
+				}
+			}
+
 			if ((tag = iks_insert(pres, "c"))) {
 				iks_insert_attrib(tag, "node", "http://www.freeswitch.org/xmpp/client/caps");
-				iks_insert_attrib(tag, "ver", "1.0.0.1");
+				iks_insert_attrib(tag, "ver", LDL_CAPS_VER);
 				iks_insert_attrib(tag, "ext", "sidebar voice-v1");
 				iks_insert_attrib(tag, "client", "libdingaling");
 				iks_insert_attrib(tag, "xmlns", "http://jabber.org/protocol/caps");
@@ -975,9 +1089,10 @@
 static const char c64[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 #define B64BUFFLEN 1024
 
-static int b64encode(unsigned char *in, uint32_t ilen, unsigned char *out, uint32_t olen) {
+static int b64encode(unsigned char *in, size_t ilen, unsigned char *out, size_t olen) 
+{
 	int y=0,bytes=0;
-	uint32_t x=0;
+	size_t x=0;
 	unsigned int b=0,l=0;
 
 	for(x=0;x<ilen;x++) {
@@ -988,7 +1103,7 @@
 			if(++y!=72) {
 				continue;
 			}
-			out[bytes++] = '\n';
+			//out[bytes++] = '\n';
 			y=0;
 		}
 	}
@@ -1003,7 +1118,7 @@
 	return 0;
 }
 
-static void sha1_hash(char *out, char *in)
+static void sha1_hash(char *out, char *in, unsigned int len)
 {
 	sha_context_t sha;
 	char *p;
@@ -1012,7 +1127,7 @@
 
 	SHA1Init(&sha);
 	
-	SHA1Update(&sha, (unsigned char *) in, (unsigned int)strlen(in));
+	SHA1Update(&sha, (unsigned char *) in, len);
 
 	SHA1Final(digest, &sha);
 
@@ -1039,7 +1154,7 @@
 			char handshake[512] = "";
 
 			snprintf(secret, sizeof(secret), "%s%s", pak->id, handle->password);
-			sha1_hash(hash, secret);
+			sha1_hash(hash, secret, strlen(secret));
 			snprintf(handshake, sizeof(handshake), "<handshake>%s</handshake>", hash);
 			iks_send_raw(handle->parser, handshake);
 			handle->state = CS_START;
@@ -1224,15 +1339,19 @@
 static void on_log(ldl_handle_t *handle, const char *data, size_t size, int is_incoming)
 {
 	if (globals.debug) {
-		globals.logger(DL_LOG_DEBUG, "\n%s%s[%s]\n", 
-			iks_is_secure(handle->parser) ? "Sec" : "",
-			is_incoming ? "RECV" : "SEND",
-			data);
+		if (is_incoming) {
+			globals.logger(DL_LOG_INFO, "+xml:%s%s:%s", iks_is_secure(handle->parser) ? "Sec" : "", is_incoming ? "RECV" : "SEND", data);
+		} else {
+			globals.logger(DL_LOG_NOTICE, "+xml:%s%s:%s", iks_is_secure(handle->parser) ? "Sec" : "", is_incoming ? "RECV" : "SEND", data);
+		}
+						   
 	}
 }
 
 static void j_setup_filter(ldl_handle_t *handle)
 {
+	int x = 0;
+
 	if (handle->filter) {
 		iks_filter_delete(handle->filter);
 	}
@@ -1278,24 +1397,10 @@
 						IKS_RULE_TYPE, IKS_PAK_IQ,
 						IKS_RULE_SUBTYPE, IKS_TYPE_ERROR, IKS_RULE_ID, "auth", IKS_RULE_DONE);
 
-
-
-	if (ldl_test_flag(handle, LDL_FLAG_COMPONENT)) {
-		iks_filter_add_rule(handle->filter, on_component_disco_info, handle, 
-							IKS_RULE_NS, "http://jabber.org/protocol/disco#info", IKS_RULE_DONE);
-		iks_filter_add_rule(handle->filter, on_disco_items, handle,
-							IKS_RULE_NS, "http://jabber.org/protocol/disco#items", IKS_RULE_DONE);
-		iks_filter_add_rule(handle->filter, on_disco_reg_in, handle,
-							IKS_RULE_SUBTYPE, IKS_TYPE_GET, IKS_RULE_NS, "jabber:iq:register", IKS_RULE_DONE);
-		iks_filter_add_rule(handle->filter, on_disco_reg_out, handle,
-							IKS_RULE_SUBTYPE, IKS_TYPE_SET, IKS_RULE_NS, "jabber:iq:register", IKS_RULE_DONE);
-		iks_filter_add_rule(handle->filter, on_vcard, handle,
-							IKS_RULE_SUBTYPE, IKS_TYPE_GET, IKS_RULE_NS, "vcard-temp", IKS_RULE_DONE);
-	} else {
-		iks_filter_add_rule(handle->filter, on_disco_info, handle, 
-							IKS_RULE_NS, "http://jabber.org/protocol/disco#info", IKS_RULE_DONE);
+	for (x = 0; FEATURES[x].name; x++) {
+		iks_filter_add_rule(handle->filter, FEATURES[x].callback, handle, 
+							IKS_RULE_NS, FEATURES[x].name, IKS_RULE_DONE);
 	}
-	
 }
 
 static void ldl_flush_queue(ldl_handle_t *handle, int done)
@@ -1629,15 +1734,65 @@
 	return handle->login;
 }
 
-void ldl_handle_send_presence(ldl_handle_t *handle, char *from, char *to, char *type, char *rpid, char *message)
+void ldl_handle_send_presence(ldl_handle_t *handle, char *from, char *to, char *type, char *rpid, char *message, char *avatar)
 {
-	do_presence(handle, from, to, type, rpid, message);
+	do_presence(handle, from, to, type, rpid, message, avatar);
 }
 
+static void ldl_random_string(char *buf, uint16_t len, char *set)
+{
+    char chars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+    int max;
+    uint16_t x;
+
+    if (!set) {
+        set = chars;
+    }
+
+    max = (int) strlen(set);
+
+    srand((unsigned int) time(NULL));
+
+    for (x = 0; x < len; x++) {
+        int j = (int) (max * 1.0 * rand() / (RAND_MAX + 1.0));
+        buf[x] = set[j];
+    }
+}
+
+
 void ldl_handle_send_vcard(ldl_handle_t *handle, char *from, char *to, char *id, char *vcard)
 {
 	iks *vxml, *iq;
 	int e = 0;
+	ldl_avatar_t *ap;
+
+	ap = ldl_get_avatar(handle, NULL, from);
+
+	if (!vcard) {
+		char text[8192];
+		char *ext;
+		if (!ap) {
+			return;
+		}
+		
+		if ((ext = strrchr(ap->path, '.'))) {
+			ext++;
+		} else {
+			ext = "png";
+		}
+
+		snprintf(text, sizeof(text),
+				 "<vCard xmlns='vcard-temp'><PHOTO><TYPE>image/%s</TYPE><BINVAL>%s</BINVAL></PHOTO></vCard>",
+				 ext,
+				 ap->base64
+				 );
+		vcard = text;
+	} else {
+		if (ap && (strstr(vcard, "photo") || strstr(vcard, "PHOTO"))) {
+			ldl_random_string(ap->hash, sizeof(ap->hash) -1, NULL);
+		}
+	}
+
 
 	if (!(vxml = iks_tree(vcard, 0, &e))) {
 		globals.logger(DL_LOG_ERR, "Parse returned error [%d]\n", e);
@@ -2016,6 +2171,7 @@
 	globals.debug = debug;
 	globals.id = 300;
 	globals.logger = default_logger;
+	globals.avatar_hash = apr_hash_make(globals.memory_pool);
 	ldl_set_flag_locked((&globals), LDL_FLAG_INIT);
 	
 	return LDL_STATUS_SUCCESS;

Modified: freeswitch/branches/mikej/sofiasip-upgrade/libs/libdingaling/src/libdingaling.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/libs/libdingaling/src/libdingaling.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/libs/libdingaling/src/libdingaling.h	Fri Apr  6 19:25:38 2007
@@ -38,8 +38,9 @@
   \{
 */
 /* OMG */
-#ifdef WIN32
+#ifdef _MSC_VER
 #define __LDL_FUNC__ __FUNCTION__
+#define inline __inline
 #else
 #define __LDL_FUNC__ (const char *)__func__
 #endif
@@ -203,7 +204,7 @@
 	}
 
     if (id_a_host && id_b_host) {
-        int id_a_len = 0, id_b_len = 0, len = 0;
+        size_t id_a_len = 0, id_b_len = 0, len = 0;
 
         if ((id_a_r = strchr(id_a_host, '/'))) {
             id_a_len = id_a_r - id_a_host;
@@ -222,7 +223,7 @@
         } else {
             len = id_a_len;
         }
-		printf("[%s][%s][%d]\n", id_a_host, id_b_host, len);
+
         return strncasecmp(id_a_host, id_b_host, len) ? 0 : 1;
     }
     return -1;
@@ -439,8 +440,9 @@
   \param type the type of presence
   \param rpid data for the icon
   \param message a status message
+  \param avatar the path to an avatar image
 */
-void ldl_handle_send_presence(ldl_handle_t *handle, char *from, char *to, char *type, char *rpid, char *message);
+void ldl_handle_send_presence(ldl_handle_t *handle, char *from, char *to, char *type, char *rpid, char *message, char *avatar);
 
 /*!
   \brief Send a vcard

Modified: freeswitch/branches/mikej/sofiasip-upgrade/libs/srtp/Makefile.am
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/libs/srtp/Makefile.am	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/libs/srtp/Makefile.am	Fri Apr  6 19:25:38 2007
@@ -1,5 +1,3 @@
-_DIST =
-SUBDIRS = test
 AUTOMAKE_OPTS= gnu
 NAME=srtp
 
@@ -46,7 +44,7 @@
 
 noinst_PROGRAMS = aes_tables
 aes_tables_SOURCES = tables/aes_tables.c
-aes_tables_LDFLAGS = -lcryptomath
+aes_tables_LDADD = libcryptomath.la
 
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = srtp-1.42.pc

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_buffer.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_buffer.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_buffer.h	Fri Apr  6 19:25:38 2007
@@ -96,6 +96,21 @@
  */
 SWITCH_DECLARE(switch_size_t) switch_buffer_read(switch_buffer_t *buffer, void *data, switch_size_t datalen);
 
+/*! \brief Read data endlessly from a switch_buffer_t 
+ * \param buffer any buffer of type switch_buffer_t
+ * \param data pointer to the read data to be returned
+ * \param datalen amount of data to be returned
+ * \return int ammount of data actually read
+ * \note Once you have read all the data from the buffer it will loop around.
+ */
+SWITCH_DECLARE(switch_size_t) switch_buffer_read_loop(switch_buffer_t *buffer, void *data, switch_size_t datalen);
+
+/*! \brief Assign a number of loops to read
+ * \param buffer any buffer of type switch_buffer_t
+ * \param loops the number of loops (-1 for infinite)
+ */
+SWITCH_DECLARE(void) switch_buffer_set_loops(switch_buffer_t *buffer, int32_t loops);
+
 /*! \brief Write data into a switch_buffer_t up to the length of datalen
  * \param buffer any buffer of type switch_buffer_t
  * \param data pointer to the data to be written

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_platform.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_platform.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_platform.h	Fri Apr  6 19:25:38 2007
@@ -59,6 +59,12 @@
  */
 #pragma warning(disable:4100 4200 4204 4706 4819 4132 4510 4512 4610 4996)
 
+#define SWITCH_HAVE_ODBC 1
+
+#ifdef _MSC_VER
+#  pragma comment(lib, "odbc32.lib")
+#endif
+
 #pragma include_alias(<libteletone.h>,				<../../libs/libteletone/src/libteletone.h>)
 #pragma include_alias(<libteletone_generate.h>,		<../../libs/libteletone/src/libteletone_generate.h>)
 #pragma include_alias(<libteletone_detect.h>,		<../../libs/libteletone/src/libteletone_detect.h>)

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_types.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_types.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_types.h	Fri Apr  6 19:25:38 2007
@@ -796,6 +796,8 @@
 	SWITCH_EVENT_PRESENCE_IN		- Presence in
 	SWITCH_EVENT_PRESENCE_OUT		- Presence out
 	SWITCH_EVENT_PRESENCE_PROBE		- Presence probe
+	SWITCH_EVENT_MESSAGE_WAITING	- A message is waiting
+	SWITCH_EVENT_MESSAGE_QUERY		- A query for MESSAGE_WAITING events
 	SWITCH_EVENT_CODEC				- Codec Change
 	SWITCH_EVENT_BACKGROUND_JOB		- Background Job
 	SWITCH_EVENT_DETECTED_SPEECH	- Detected Speech
@@ -841,6 +843,8 @@
 	SWITCH_EVENT_PRESENCE_IN,
 	SWITCH_EVENT_PRESENCE_OUT,
 	SWITCH_EVENT_PRESENCE_PROBE,
+	SWITCH_EVENT_MESSAGE_WAITING,
+	SWITCH_EVENT_MESSAGE_QUERY,
 	SWITCH_EVENT_ROSTER,
 	SWITCH_EVENT_CODEC,
 	SWITCH_EVENT_BACKGROUND_JOB,

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/Makefile.am
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/Makefile.am	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/Makefile.am	Fri Apr  6 19:25:38 2007
@@ -76,3 +76,15 @@
 	@echo
 	@echo done Uninstalling Modules
 
+
+ at am__include@ @am__quote@$(switch_builddir)/$(DEPDIR)/modules.targets at am__quote@
+
+$(MODULE_TARGETS):
+	@set fnord $$MAKEFLAGS; amf=$$2; \
+	moddir=`grep $@ $(switch_builddir)/modules.conf | sed -e 's|#||'` ; \
+	(if test -f $$moddir/Makefile ; then \
+		cd $$moddir && MODNAME=$(MOD_NAME) BASE=$(switch_builddir) $(MAKE) $(AM_MAKEFLAGS); else\
+		cd $$moddir && MODNAME=$(MOD_NAME) BASE=$(switch_builddir) $(MAKE) $(AM_MAKEFLAGS) -f $(switch_builddir)/build/modmake.rules;\
+	fi;)\
+	   || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
+	test -z "$$fail"

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_conference/mod_conference.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_conference/mod_conference.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_conference/mod_conference.c	Fri Apr  6 19:25:38 2007
@@ -3429,7 +3429,7 @@
 				}
 			} else {
 				stream->write_function(stream, "Conference %s not found\n", argv[0]);
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Conference %s not found\n", argv[0]);
+				//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Conference %s not found\n", argv[0]);
 			}
 		}
 

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_dingaling/Makefile
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_dingaling/Makefile	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_dingaling/Makefile	Fri Apr  6 19:25:38 2007
@@ -2,13 +2,15 @@
 
 LOCAL_CFLAGS     = `$(BASE)/libs/apr/apr-1-config --cflags --cppflags --includes`
 LOCAL_CFLAGS    += `$(BASE)/libs/apr-util/apu-1-config --includes`
+LOCAL_CFLAGS += `if test -f $(BASE)/.libs/libfreeswitch_la-switch_odbc.o ; then echo -DSWITCH_HAVE_ODBC; fi ;`
+LOCAL_CFLAGS += -w
 
 IKS_DIR=$(BASE)/libs/iksemel
 IKS_LA=$(IKS_DIR)/src/libiksemel.la
 DING_DIR=$(BASE)/libs/libdingaling
 LOCAL_CFLAGS += -I$(DING_DIR)/src -I$(BASE)/libs/iksemel/include
 LOCAL_OBJS=$(DING_DIR)/src/libdingaling.o $(DING_DIR)/src/sha1.o $(IKS_LA)
-
+LOCAL_SOURCES=$(DING_DIR)/src/libdingaling.c $(DING_DIR)/src/sha1.c
 include $(BASE)/build/modmake.rules
 
 $(IKS_LA): $(IKS_DIR) $(IKS_DIR)/.update

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_dingaling/mod_dingaling.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_dingaling/mod_dingaling.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_dingaling/mod_dingaling.c	Fri Apr  6 19:25:38 2007
@@ -31,6 +31,9 @@
  */
 #include <switch.h>
 #include <libdingaling.h>
+#ifdef SWITCH_HAVE_ODBC
+#include <switch_odbc.h>
+#endif
 
 #define DL_CAND_WAIT 10000000
 #define DL_CAND_INITIAL_WAIT 2000000
@@ -45,8 +48,11 @@
 static switch_memory_pool_t *module_pool = NULL;
 
 static char sub_sql[] =
-	"CREATE TABLE subscriptions (\n"
-	"   sub_from            VARCHAR(255),\n" "   sub_to          VARCHAR(255),\n" "   show          VARCHAR(255),\n" "   status          VARCHAR(255)\n"
+	"CREATE TABLE jabber_subscriptions (\n"
+	"   sub_from      VARCHAR(255),\n" 
+	"   sub_to        VARCHAR(255),\n" 
+	"   show_pres     VARCHAR(255),\n" 
+	"   status        VARCHAR(255)\n"
 	");\n";
 
 
@@ -112,18 +118,31 @@
 	char *context;
 	char *timer_name;
 	char *dbname;
+	char *avatar;
+#ifdef SWITCH_HAVE_ODBC
+	char *odbc_dsn;
+	char *odbc_user;
+	char *odbc_pass;
+	switch_odbc_handle_t *master_odbc;
+#else
+	void *filler1;
+	void *filler2;
+	void *filler3;
+	void *filler4;
+#endif
 	switch_mutex_t *mutex;
 	ldl_handle_t *handle;
 	uint32_t flags;
 	uint32_t user_flags;
 };
+typedef struct mdl_profile mdl_profile_t;
 
 struct private_object {
 	unsigned int flags;
 	switch_codec_t read_codec;
 	switch_codec_t write_codec;
 	switch_frame_t read_frame;
-	struct mdl_profile *profile;
+	mdl_profile_t *profile;
 	switch_core_session_t *session;
 	switch_caller_profile_t *caller_profile;
 	unsigned short samprate;
@@ -167,32 +186,33 @@
 
 
 SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_dialplan, globals.dialplan)
-	SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_string, globals.codec_string)
-	SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_rates_string, globals.codec_rates_string)
+SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_string, globals.codec_string)
+SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_rates_string, globals.codec_rates_string)
 
-	 static switch_status_t dl_login(char *arg, switch_core_session_t *session, switch_stream_handle_t *stream);
-	 static switch_status_t dl_logout(char *profile_name, switch_core_session_t *session, switch_stream_handle_t *stream);
-	 static switch_status_t channel_on_init(switch_core_session_t *session);
-	 static switch_status_t channel_on_hangup(switch_core_session_t *session);
-	 static switch_status_t channel_on_ring(switch_core_session_t *session);
-	 static switch_status_t channel_on_loopback(switch_core_session_t *session);
-	 static switch_status_t channel_on_transmit(switch_core_session_t *session);
-	 static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session,
-														 switch_caller_profile_t *outbound_profile,
-														 switch_core_session_t **new_session, switch_memory_pool_t **pool);
-	 static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, switch_io_flag_t flags, int stream_id);
-	 static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flags, int stream_id);
-	 static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig);
-
-	 static ldl_status handle_signalling(ldl_handle_t * handle, ldl_session_t * dlsession, ldl_signal_t dl_signal,
-										 char *to, char *from, char *subject, char *msg);
-	 static ldl_status handle_response(ldl_handle_t * handle, char *id);
-	 static switch_status_t load_config(void);
-	 static int sin_callback(void *pArg, int argc, char **argv, char **columnNames);
+static switch_status_t dl_login(char *arg, switch_core_session_t *session, switch_stream_handle_t *stream);
+static switch_status_t dl_logout(char *profile_name, switch_core_session_t *session, switch_stream_handle_t *stream);
+static switch_status_t dl_pres(char *profile_name, switch_core_session_t *session, switch_stream_handle_t *stream);
+static switch_status_t channel_on_init(switch_core_session_t *session);
+static switch_status_t channel_on_hangup(switch_core_session_t *session);
+static switch_status_t channel_on_ring(switch_core_session_t *session);
+static switch_status_t channel_on_loopback(switch_core_session_t *session);
+static switch_status_t channel_on_transmit(switch_core_session_t *session);
+static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session,
+													switch_caller_profile_t *outbound_profile,
+													switch_core_session_t **new_session, switch_memory_pool_t **pool);
+static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, switch_io_flag_t flags, int stream_id);
+static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flags, int stream_id);
+static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig);
+
+static ldl_status handle_signalling(ldl_handle_t * handle, ldl_session_t * dlsession, ldl_signal_t dl_signal,
+									char *to, char *from, char *subject, char *msg);
+static ldl_status handle_response(ldl_handle_t * handle, char *id);
+static switch_status_t load_config(void);
+static int sin_callback(void *pArg, int argc, char **argv, char **columnNames);
 
 #define is_special(s) (s && (strstr(s, "ext+") || strstr(s, "user+")))
 
-	 static char *translate_rpid(char *in, char *ext)
+static char *translate_rpid(char *in, char *ext)
 {
 	char *r = NULL;
 
@@ -229,9 +249,109 @@
 	return r;
 }
 
+
+
+
+static void mdl_execute_sql(mdl_profile_t *profile, char *sql, switch_mutex_t *mutex)
+{
+	switch_core_db_t *db;
+
+	if (mutex) {
+		switch_mutex_lock(mutex);
+	}
+
+#ifdef SWITCH_HAVE_ODBC
+    if (profile->odbc_dsn) {
+		SQLHSTMT stmt;
+		if (switch_odbc_handle_exec(profile->master_odbc, sql, &stmt) != SWITCH_ODBC_SUCCESS) {
+			char *err_str;
+			err_str = switch_odbc_handle_get_error(profile->master_odbc, stmt);
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ERR: [%s]\n[%s]\n", sql, switch_str_nil(err_str));
+			switch_safe_free(err_str);
+		}
+		SQLFreeHandle(SQL_HANDLE_STMT, stmt);
+	} else {
+#endif
+		if (!(db = switch_core_db_open_file(profile->dbname))) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
+			goto end;
+		}
+
+		switch_core_db_persistant_execute(db, sql, 25);
+		switch_core_db_close(db);
+
+#ifdef SWITCH_HAVE_ODBC
+    }
+#endif
+
+
+ end:
+	if (mutex) {
+		switch_mutex_unlock(mutex);
+	}
+}
+
+
+static switch_bool_t mdl_execute_sql_callback(mdl_profile_t *profile,
+											  switch_mutex_t *mutex,
+											  char *sql,
+											  switch_core_db_callback_func_t callback,
+											  void *pdata)
+{
+	switch_bool_t ret = SWITCH_FALSE;
+	switch_core_db_t *db;
+	char *errmsg = NULL;
+	
+	if (mutex) {
+        switch_mutex_lock(mutex);
+    }
+
+
+#ifdef SWITCH_HAVE_ODBC
+    if (profile->odbc_dsn) {
+		switch_odbc_handle_callback_exec(profile->master_odbc, sql, callback, pdata);
+	} else {
+#endif
+
+
+
+		if (!(db = switch_core_db_open_file(profile->dbname))) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
+			goto end;
+		}
+
+	
+		switch_core_db_exec(db, sql, callback, pdata, &errmsg);
+
+		if (errmsg) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg);
+			free(errmsg);
+		}
+
+		if (db) {
+			switch_core_db_close(db);
+		}
+
+#ifdef SWITCH_HAVE_ODBC
+    }
+#endif
+
+
+ end:
+
+	if (mutex) {
+        switch_mutex_unlock(mutex);
+    }
+	
+
+
+	return ret;
+
+}
+
 static int sub_callback(void *pArg, int argc, char **argv, char **columnNames)
 {
-	struct mdl_profile *profile = (struct mdl_profile *) pArg;
+	mdl_profile_t *profile = (mdl_profile_t *) pArg;
 
 	char *sub_from = argv[0];
 	char *sub_to = argv[1];
@@ -248,7 +368,7 @@
 	rpid = translate_rpid(rpid, status);
 
 	//ldl_handle_send_presence(profile->handle, sub_to, sub_from, "probe", rpid, status);
-	ldl_handle_send_presence(profile->handle, sub_to, sub_from, type, rpid, status);
+	ldl_handle_send_presence(profile->handle, sub_to, sub_from, type, rpid, status, profile->avatar);
 
 
 	return 0;
@@ -256,7 +376,7 @@
 
 static int rost_callback(void *pArg, int argc, char **argv, char **columnNames)
 {
-	struct mdl_profile *profile = (struct mdl_profile *) pArg;
+	mdl_profile_t *profile = (mdl_profile_t *) pArg;
 
 	char *sub_from = argv[0];
 	char *sub_to = argv[1];
@@ -271,14 +391,14 @@
 		}
 	}
 
-	ldl_handle_send_presence(profile->handle, sub_to, sub_from, NULL, show, status);
+	ldl_handle_send_presence(profile->handle, sub_to, sub_from, NULL, show, status, profile->avatar);
 
 	return 0;
 }
 
 static void pres_event_handler(switch_event_t *event)
 {
-	struct mdl_profile *profile = NULL;
+	mdl_profile_t *profile = NULL;
 	switch_hash_index_t *hi;
 	void *val;
 	char *proto = switch_event_get_header(event, "proto");
@@ -287,7 +407,7 @@
 	char *rpid = switch_event_get_header(event, "rpid");
 	char *type = switch_event_get_header(event, "event_subtype");
 	char *sql;
-	switch_core_db_t *db;
+
 
 	if (!proto) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Missing 'proto' header\n");
@@ -307,8 +427,6 @@
 	case SWITCH_EVENT_PRESENCE_PROBE:
 		if (proto) {
 			char *sql;
-			switch_core_db_t *db;
-			char *errmsg;
 			char *to = switch_event_get_header(event, "to");
 			char *f_host = NULL;
 			if (to) {
@@ -318,15 +436,8 @@
 			}
 
 			if (f_host && (profile = switch_core_hash_find(globals.profile_hash, f_host))) {
-				if (to && (sql = switch_mprintf("select * from subscriptions where sub_to='%q'", to))) {
-					if (!(db = switch_core_db_open_file(profile->dbname))) {
-						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
-						return;
-					}
-					switch_mutex_lock(profile->mutex);
-					switch_core_db_exec(db, sql, sin_callback, profile, &errmsg);
-					switch_mutex_unlock(profile->mutex);
-					switch_core_db_close(db);
+				if (to && (sql = switch_mprintf("select * from jabber_subscriptions where sub_to='%q'", to))) {
+					mdl_execute_sql_callback(profile, profile->mutex, sql, sin_callback, profile);
 					switch_safe_free(sql);
 				}
 			}
@@ -356,13 +467,12 @@
 	}
 
 
-	sql = switch_mprintf("select sub_from, sub_to,'%q','%q','%q','%q' from subscriptions where sub_to like '%%%q'", type, rpid, status, proto, from);
+	sql = switch_mprintf("select sub_from, sub_to,'%q','%q','%q','%q' from jabber_subscriptions where sub_to like '%%%q'", type, rpid, status, proto, from);
 
 
 	for (hi = switch_hash_first(switch_hash_pool_get(globals.profile_hash), globals.profile_hash); hi; hi = switch_hash_next(hi)) {
-		char *errmsg;
 		switch_hash_this(hi, NULL, NULL, &val);
-		profile = (struct mdl_profile *) val;
+		profile = (mdl_profile_t *) val;
 
 		if (!(profile->user_flags & LDL_FLAG_COMPONENT)) {
 			continue;
@@ -370,14 +480,11 @@
 
 
 		if (sql) {
-			if (!(db = switch_core_db_open_file(profile->dbname))) {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
+			switch_bool_t worked = mdl_execute_sql_callback(profile, profile->mutex, sql, sub_callback, profile);
+			
+			if (!worked) {
 				continue;
 			}
-			switch_mutex_lock(profile->mutex);
-			switch_core_db_exec(db, sql, sub_callback, profile, &errmsg);
-			switch_mutex_unlock(profile->mutex);
-			switch_core_db_close(db);
 		}
 
 
@@ -389,7 +496,7 @@
 static switch_status_t chat_send(char *proto, char *from, char *to, char *subject, char *body, char *hint)
 {
 	char *user, *host, *f_user = NULL, *ffrom = NULL, *f_host = NULL, *f_resource = NULL;
-	struct mdl_profile *profile = NULL;
+	mdl_profile_t *profile = NULL;
 
 	assert(proto != NULL);
 
@@ -438,11 +545,11 @@
 	char *status = switch_event_get_header(event, "status");
 	char *from = switch_event_get_header(event, "from");
 	char *event_type = switch_event_get_header(event, "event_type");
-	struct mdl_profile *profile = NULL;
+	mdl_profile_t *profile = NULL;
 	switch_hash_index_t *hi;
 	void *val;
 	char *sql;
-	switch_core_db_t *db;
+
 
 	if (status && !strcasecmp(status, "n/a")) {
 		status = NULL;
@@ -453,15 +560,14 @@
 	}
 
 	if (from) {
-		sql = switch_mprintf("select *,'%q' from subscriptions where sub_from='%q'", status ? status : "", from);
+		sql = switch_mprintf("select *,'%q' from jabber_subscriptions where sub_from='%q'", status ? status : "", from);
 	} else {
-		sql = switch_mprintf("select *,'%q' from subscriptions", status ? status : "");
+		sql = switch_mprintf("select *,'%q' from jabber_subscriptions", status ? status : "");
 	}
 
 	for (hi = switch_hash_first(switch_hash_pool_get(globals.profile_hash), globals.profile_hash); hi; hi = switch_hash_next(hi)) {
-		char *errmsg;
 		switch_hash_this(hi, NULL, NULL, &val);
-		profile = (struct mdl_profile *) val;
+		profile = (mdl_profile_t *) val;
 
 		if (!(profile->user_flags & LDL_FLAG_COMPONENT)) {
 			continue;
@@ -469,14 +575,10 @@
 
 
 		if (sql) {
-			if (!(db = switch_core_db_open_file(profile->dbname))) {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
+			switch_bool_t worked = mdl_execute_sql_callback(profile, profile->mutex, sql, rost_callback, profile);
+			if (!worked) {
 				continue;
 			}
-			switch_mutex_lock(profile->mutex);
-			switch_core_db_exec(db, sql, rost_callback, profile, &errmsg);
-			switch_mutex_unlock(profile->mutex);
-			switch_core_db_close(db);
 		}
 
 	}
@@ -487,13 +589,13 @@
 
 static int so_callback(void *pArg, int argc, char **argv, char **columnNames)
 {
-	struct mdl_profile *profile = (struct mdl_profile *) pArg;
+	mdl_profile_t *profile = (mdl_profile_t *) pArg;
 
 	char *sub_from = argv[0];
 	char *sub_to = argv[1];
 
 
-	ldl_handle_send_presence(profile->handle, sub_to, sub_from, "unavailable", "dnd", "Bub-Bye");
+	ldl_handle_send_presence(profile->handle, sub_to, sub_from, "unavailable", "dnd", "Bub-Bye", profile->avatar);
 
 	return 0;
 }
@@ -501,7 +603,7 @@
 
 static int sin_callback(void *pArg, int argc, char **argv, char **columnNames)
 {
-	struct mdl_profile *profile = (struct mdl_profile *) pArg;
+	mdl_profile_t *profile = (mdl_profile_t *) pArg;
 	switch_event_t *event;
 
 	//char *sub_from = argv[0];
@@ -523,20 +625,19 @@
 
 static void sign_off(void)
 {
-	struct mdl_profile *profile = NULL;
+	mdl_profile_t *profile = NULL;
 	switch_hash_index_t *hi;
 	void *val;
 	char *sql;
-	switch_core_db_t *db;
 
 
-	sql = switch_mprintf("select * from subscriptions");
+
+	sql = switch_mprintf("select * from jabber_subscriptions");
 
 
 	for (hi = switch_hash_first(switch_hash_pool_get(globals.profile_hash), globals.profile_hash); hi; hi = switch_hash_next(hi)) {
-		char *errmsg;
 		switch_hash_this(hi, NULL, NULL, &val);
-		profile = (struct mdl_profile *) val;
+		profile = (mdl_profile_t *) val;
 
 		if (!(profile->user_flags & LDL_FLAG_COMPONENT)) {
 			continue;
@@ -544,14 +645,10 @@
 
 
 		if (sql) {
-			if (!(db = switch_core_db_open_file(profile->dbname))) {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
+			switch_bool_t worked = mdl_execute_sql_callback(profile, profile->mutex, sql, so_callback, profile);
+			if (!worked) {
 				continue;
 			}
-			switch_mutex_lock(profile->mutex);
-			switch_core_db_exec(db, sql, so_callback, profile, &errmsg);
-			switch_mutex_unlock(profile->mutex);
-			switch_core_db_close(db);
 		}
 
 	}
@@ -561,21 +658,13 @@
 
 }
 
-static void sign_on(struct mdl_profile *profile)
+static void sign_on(mdl_profile_t *profile)
 {
 	char *sql;
-	switch_core_db_t *db;
-	char *errmsg;
 
-	if ((sql = switch_mprintf("select * from subscriptions where sub_to like 'ext+%%' or sub_to like 'user+%%' or sub_to like 'conf+%%'"))) {
-		if (!(db = switch_core_db_open_file(profile->dbname))) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
-			return;
-		}
-		switch_mutex_lock(profile->mutex);
-		switch_core_db_exec(db, sql, sin_callback, profile, &errmsg);
-		switch_mutex_unlock(profile->mutex);
-		switch_core_db_close(db);
+
+	if ((sql = switch_mprintf("select * from jabber_subscriptions where sub_to like 'ext+%%' or sub_to like 'user+%%' or sub_to like 'conf+%%'"))) {
+		mdl_execute_sql_callback(profile, profile->mutex, sql, sin_callback, profile);
 		switch_safe_free(sql);
 	}
 }
@@ -619,13 +708,33 @@
 static void dl_logger(char *file, const char *func, int line, int level, char *fmt, ...)
 {
 	va_list ap;
-	char data[1024];
+	char *data = NULL;
+	int ret;
 
 	va_start(ap, fmt);
-
-	vsnprintf(data, sizeof(data), fmt, ap);
-	switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, SWITCH_LOG_DEBUG, "%s", data);
-
+	if ((ret = switch_vasprintf(&data, fmt, ap)) != -1) {
+		if (!strncasecmp(data, "+xml:", 5)) {
+			switch_xml_t xml;
+			char *form;
+			char *ll = data + 5;
+			char *xmltxt;
+
+			if (ll) {
+				if ((xmltxt = strchr(ll, ':'))) {
+					*xmltxt++ = '\0';
+					xml = switch_xml_parse_str(xmltxt, strlen(xmltxt));
+					form = switch_xml_toxml(xml);
+					switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, level, 
+									  "%s:\n-------------------------------------------------------------------------------\n"
+									  "%s\n", ll, form);
+					switch_xml_free(xml);
+					free(data);
+				}
+			}
+		} else {
+			switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, level, "%s\n", data);
+		}
+	}
 	va_end(ap);
 }
 
@@ -656,7 +765,7 @@
 static void *SWITCH_THREAD_FUNC handle_thread_run(switch_thread_t * thread, void *obj)
 {
 	ldl_handle_t *handle = obj;
-	struct mdl_profile *profile = NULL;
+	mdl_profile_t *profile = NULL;
 
 
 
@@ -741,15 +850,13 @@
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SETUP RTP %s:%d -> %s:%d\n", tech_pvt->profile->ip,
 					  tech_pvt->local_port, tech_pvt->remote_ip, tech_pvt->remote_port);
 
-	flags = SWITCH_RTP_FLAG_GOOGLEHACK | SWITCH_RTP_FLAG_AUTOADJ;
+	flags = SWITCH_RTP_FLAG_GOOGLEHACK | SWITCH_RTP_FLAG_AUTOADJ | SWITCH_RTP_FLAG_RAW_WRITE | SWITCH_RTP_FLAG_AUTO_CNG;
 	//flags = SWITCH_RTP_FLAG_AUTOADJ;
 
 	if (switch_test_flag(tech_pvt->profile, TFLAG_TIMER)) {
 		flags |= SWITCH_RTP_FLAG_USE_TIMER;
 	}
 
-	flags |= SWITCH_RTP_FLAG_AUTO_CNG;
-
 	if (!(tech_pvt->rtp_session = switch_rtp_new(tech_pvt->profile->ip,
 												 tech_pvt->local_port,
 												 tech_pvt->remote_ip,
@@ -1009,9 +1116,9 @@
 
 	goto done;
 
-  out:
+ out:
 	terminate_session(&session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-  done:
+ done:
 
 	return ret;
 }
@@ -1096,9 +1203,9 @@
 	/* Dunno why, but if googletalk calls us for the first time, as soon as the call ends
 	   they think we are offline for no reason so we send this presence packet to stop it from happening
 	   We should find out why.....
-	 */
+	*/
 	if ((tech_pvt->profile->user_flags & LDL_FLAG_COMPONENT) && is_special(tech_pvt->them)) {
-		ldl_handle_send_presence(tech_pvt->profile->handle, tech_pvt->them, tech_pvt->us, NULL, NULL, "Click To Call");
+		ldl_handle_send_presence(tech_pvt->profile->handle, tech_pvt->them, tech_pvt->us, NULL, NULL, "Click To Call", tech_pvt->profile->avatar);
 	}
 	if (tech_pvt->dlsession) {
 		if (!switch_test_flag(tech_pvt, TFLAG_TERM)) {
@@ -1462,13 +1569,20 @@
 };
 
 
+static switch_api_interface_t pres_api_interface = {
+	/*.interface_name */ "dl_pres",
+	/*.desc */ "DingaLing Presence",
+	/*.function */ dl_pres,
+	/*.syntax */ "dl_pres <profile_name>",
+	/*.next */ NULL
+};
 
 static switch_api_interface_t logout_api_interface = {
 	/*.interface_name */ "dl_logout",
 	/*.desc */ "DingaLing Logout",
 	/*.function */ dl_logout,
 	/*.syntax */ "dl_logout <profile_name>",
-	/*.next */ NULL
+	/*.next */ &pres_api_interface
 };
 
 static switch_api_interface_t login_api_interface = {
@@ -1510,7 +1624,7 @@
 		struct private_object *tech_pvt;
 		switch_channel_t *channel;
 		switch_caller_profile_t *caller_profile = NULL;
-		struct mdl_profile *mdl_profile = NULL;
+		mdl_profile_t *mdl_profile = NULL;
 		ldl_session_t *dlsession = NULL;
 		char *profile_name;
 		char *callto;
@@ -1727,7 +1841,7 @@
 	return LDL_STATUS_SUCCESS;
 }
 
-static switch_status_t init_profile(struct mdl_profile *profile, uint8_t login)
+static switch_status_t init_profile(mdl_profile_t *profile, uint8_t login)
 {
 	if (profile && profile->login && profile->password && profile->dialplan && profile->message && profile->ip && profile->name && profile->exten) {
 		ldl_handle_t *handle;
@@ -1792,13 +1906,29 @@
 }
 
 
-static void set_profile_val(struct mdl_profile *profile, char *var, char *val)
+static void set_profile_val(mdl_profile_t *profile, char *var, char *val)
 {
 
 	if (!strcasecmp(var, "login")) {
 		profile->login = switch_core_strdup(module_pool, val);
 	} else if (!strcasecmp(var, "password")) {
 		profile->password = switch_core_strdup(module_pool, val);
+	} else if (!strcasecmp(var, "avatar")) {
+		profile->avatar = switch_core_strdup(module_pool, val);
+	} else if (!strcasecmp(var, "odbc-dsn")) {
+#ifdef SWITCH_HAVE_ODBC
+		profile->odbc_dsn = switch_core_strdup(module_pool, val);
+		if ((profile->odbc_user = strchr(profile->odbc_dsn, ':'))) {
+			*profile->odbc_user++ = '\0';
+		}
+		if ((profile->odbc_pass = strchr(profile->odbc_user, ':'))) {
+			*profile->odbc_pass++ = '\0';
+		}
+		
+		
+#else
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n");
+#endif
 	} else if (!strcasecmp(var, "use-rtp-timer") && switch_true(val)) {
 		switch_set_flag(profile, TFLAG_TIMER);
 	} else if (!strcasecmp(var, "dialplan")) {
@@ -1851,9 +1981,36 @@
 	}
 }
 
+static switch_status_t dl_pres(char *profile_name, switch_core_session_t *session, switch_stream_handle_t *stream)
+{
+	mdl_profile_t *profile;
+
+	if (session) {
+		return SWITCH_STATUS_FALSE;
+	}
+
+	if (!profile_name) {
+		stream->write_function(stream, "USAGE: %s\n", pres_api_interface.syntax);
+		return SWITCH_STATUS_SUCCESS;
+	}
+
+	if ((profile = switch_core_hash_find(globals.profile_hash, profile_name))) {
+		if (profile->user_flags & LDL_FLAG_COMPONENT) {
+			sign_on(profile);
+			stream->write_function(stream, "OK\n");
+		} else {
+			stream->write_function(stream, "NO PROFILE %s NOT A COMPONENT\n", profile_name);
+		}
+	} else {
+		stream->write_function(stream, "NO SUCH PROFILE %s\n", profile_name);
+	}
+
+	return SWITCH_STATUS_SUCCESS;
+}
+
 static switch_status_t dl_logout(char *profile_name, switch_core_session_t *session, switch_stream_handle_t *stream)
 {
-	struct mdl_profile *profile;
+	mdl_profile_t *profile;
 
 	if (session) {
 		return SWITCH_STATUS_FALSE;
@@ -1879,7 +2036,7 @@
 	char *argv[10] = { 0 };
 	int argc = 0;
 	char *var, *val, *myarg;
-	struct mdl_profile *profile = NULL;
+	mdl_profile_t *profile = NULL;
 	int x;
 
 	if (session) {
@@ -1938,7 +2095,7 @@
 static switch_status_t load_config(void)
 {
 	char *cf = "dingaling.conf";
-	struct mdl_profile *profile = NULL;
+	mdl_profile_t *profile = NULL;
 	switch_xml_t cfg, xml, settings, param, xmlint;
 
 	memset(&globals, 0, sizeof(globals));
@@ -2010,13 +2167,34 @@
 			snprintf(dbname, sizeof(dbname), "dingaling_%s", profile->name);
 			profile->dbname = switch_core_strdup(module_pool, dbname);
 
-			if ((db = switch_core_db_open_file(profile->dbname))) {
-				switch_core_db_test_reactive(db, "select * from subscriptions", sub_sql);
+
+#ifdef SWITCH_HAVE_ODBC
+			if (profile->odbc_dsn) {
+				if (!(profile->master_odbc = switch_odbc_handle_new(profile->odbc_dsn, profile->odbc_user, profile->odbc_pass))) {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open ODBC Database!\n");
+					continue;
+					
+				}
+				if (switch_odbc_handle_connect(profile->master_odbc) != SWITCH_ODBC_SUCCESS) {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open ODBC Database!\n");
+					continue;
+				}
+
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Connected ODBC DSN: %s\n", profile->odbc_dsn);
+				switch_odbc_handle_exec(profile->master_odbc, sub_sql, NULL);
+				//mdl_execute_sql(profile, sub_sql, NULL);
 			} else {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open SQL Database!\n");
-				continue;
+#endif
+				if ((db = switch_core_db_open_file(profile->dbname))) {
+					switch_core_db_test_reactive(db, "select * from jabber_subscriptions", sub_sql);
+				} else {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open SQL Database!\n");
+					continue;
+				}
+				switch_core_db_close(db);
+#ifdef SWITCH_HAVE_ODBC
 			}
-			switch_core_db_close(db);
+#endif
 		}
 
 		if (profile) {
@@ -2047,32 +2225,11 @@
 }
 
 
-static void execute_sql(char *dbname, char *sql, switch_mutex_t * mutex)
-{
-	switch_core_db_t *db;
-
-	if (mutex) {
-		switch_mutex_lock(mutex);
-	}
-
-	if (!(db = switch_core_db_open_file(dbname))) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", dbname);
-		goto end;
-	}
-
-	switch_core_db_persistant_execute(db, sql, 25);
-	switch_core_db_close(db);
-
-  end:
-	if (mutex) {
-		switch_mutex_unlock(mutex);
-	}
-}
-
-static void do_vcard(ldl_handle_t * handle, char *to, char *from, char *id)
+static void do_vcard(ldl_handle_t *handle, char *to, char *from, char *id)
 {
 	char *params = NULL, *real_to, *to_user, *xmlstr = NULL, *to_host = NULL;
 	switch_xml_t domain, xml = NULL, user, vcard;
+	int sent = 0;
 
 	if (!strncasecmp(to, "user+", 5)) {
 		real_to = to + 5;
@@ -2102,17 +2259,17 @@
 
 
 	if (switch_xml_locate("directory", "domain", "name", to_host, &xml, &domain, params) != SWITCH_STATUS_SUCCESS) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "can't find domain for [%s@%s]\n", to_user, to_host);
+		//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "can't find domain for [%s@%s]\n", to_user, to_host);
 		goto end;
 	}
 
 	if (!(user = switch_xml_find_child(domain, "user", "id", to_user))) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "can't find user [%s@%s]\n", to_user, to_host);
+		//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "can't find user [%s@%s]\n", to_user, to_host);
 		goto end;
 	}
 
 	if (!(vcard = switch_xml_child(user, "vcard"))) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "can't find <vcard> tag for user [%s@%s]\n", to_user, to_host);
+		//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "can't find <vcard> tag for user [%s@%s]\n", to_user, to_host);
 		goto end;
 	}
 
@@ -2120,11 +2277,17 @@
 
 	if ((xmlstr = switch_xml_toxml(vcard))) {
 		ldl_handle_send_vcard(handle, to, from, id, xmlstr);
+		sent = 1;
 	} else {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
 	}
 
-  end:
+ end:
+
+	if (!sent) {
+		ldl_handle_send_vcard(handle, to, from, id, NULL);
+	}
+
 	if (xml)
 		switch_xml_free(xml);
 	switch_safe_free(to_user);
@@ -2135,7 +2298,7 @@
 static ldl_status handle_signalling(ldl_handle_t * handle, ldl_session_t * dlsession, ldl_signal_t dl_signal, char *to, char *from, char *subject,
 									char *msg)
 {
-	struct mdl_profile *profile = NULL;
+	mdl_profile_t *profile = NULL;
 	switch_core_session_t *session = NULL;
 	switch_channel_t *channel = NULL;
 	struct private_object *tech_pvt = NULL;
@@ -2159,8 +2322,8 @@
 				break;
 			case LDL_SIGNAL_UNSUBSCRIBE:
 
-				if ((sql = switch_mprintf("delete from subscriptions where sub_from='%q' and sub_to='%q';", from, to))) {
-					execute_sql(profile->dbname, sql, profile->mutex);
+				if ((sql = switch_mprintf("delete from jabber_subscriptions where sub_from='%q' and sub_to='%q';", from, to))) {
+					mdl_execute_sql(profile, sql, profile->mutex);
 					switch_core_db_free(sql);
 				}
 
@@ -2170,14 +2333,22 @@
 				if (profile->user_flags & LDL_FLAG_COMPONENT && ldl_jid_domcmp(from, to)) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Attempt to add presence from/to our own domain [%s][%s]\n", from, to);
 				} else {
-					if ((sql = switch_mprintf("delete from subscriptions where sub_from='%q' and sub_to='%q';\n"
-											  "insert into subscriptions values('%q','%q','%q','%q');\n", from, to, from, to, msg, subject))) {
-						execute_sql(profile->dbname, sql, profile->mutex);
+					switch_mutex_lock(profile->mutex);
+					if ((sql = switch_mprintf("delete from jabber_subscriptions where sub_from='%q' and sub_to='%q'", from, to))) {
+						mdl_execute_sql(profile, sql, NULL);
 						switch_core_db_free(sql);
 					}
-
+					if ((sql = switch_mprintf("insert into jabber_subscriptions values('%q','%q','%q','%q');\n", 
+											  switch_str_nil(from),
+											  switch_str_nil(to),
+											  switch_str_nil(msg),
+											  switch_str_nil(subject)))) {
+						mdl_execute_sql(profile, sql, NULL);
+						switch_core_db_free(sql);
+					}
+					switch_mutex_unlock(profile->mutex);
 					if (is_special(to)) {
-						ldl_handle_send_presence(profile->handle, to, from, NULL, NULL, "Click To Call");
+						ldl_handle_send_presence(profile->handle, to, from, NULL, NULL, "Click To Call", profile->avatar);
 					}
 #if 0
 					if (is_special(to)) {
@@ -2202,7 +2373,7 @@
 				break;
 			case LDL_SIGNAL_PRESENCE_PROBE:
 				if (is_special(to)) {
-					ldl_handle_send_presence(profile->handle, to, from, NULL, NULL, "Click To Call");
+					ldl_handle_send_presence(profile->handle, to, from, NULL, NULL, "Click To Call", profile->avatar);
 				} else {
 					if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_PROBE) == SWITCH_STATUS_SUCCESS) {
 						switch_event_add_header(event, SWITCH_STACK_BOTTOM, "proto", MDL_CHAT_PROTO);
@@ -2215,8 +2386,9 @@
 				break;
 			case LDL_SIGNAL_PRESENCE_IN:
 
-				if ((sql = switch_mprintf("update subscriptions set show='%q', status='%q' where sub_from='%q'", msg, subject, from))) {
-					execute_sql(profile->dbname, sql, profile->mutex);
+				if ((sql = switch_mprintf("update jabber_subscriptions set show_pres='%q', status='%q' where sub_from='%q'", 
+										  switch_str_nil(msg), switch_str_nil(subject), switch_str_nil(from)))) {
+					mdl_execute_sql(profile, sql, profile->mutex);
 					switch_core_db_free(sql);
 				}
 
@@ -2231,7 +2403,7 @@
 
 
 				if (is_special(to)) {
-					ldl_handle_send_presence(profile->handle, to, from, NULL, NULL, "Click To Call");
+					ldl_handle_send_presence(profile->handle, to, from, NULL, NULL, "Click To Call", profile->avatar);
 				}
 #if 0
 				if (is_special(to)) {
@@ -2249,8 +2421,9 @@
 
 			case LDL_SIGNAL_PRESENCE_OUT:
 
-				if ((sql = switch_mprintf("update subscriptions set show='%q', status='%q' where sub_from='%q'", msg, subject, from))) {
-					execute_sql(profile->dbname, sql, profile->mutex);
+				if ((sql = switch_mprintf("update jabber_subscriptions set show_pres='%q', status='%q' where sub_from='%q'", 
+										  switch_str_nil(msg), switch_str_nil(subject), switch_str_nil(from)))) {
+					mdl_execute_sql(profile, sql, profile->mutex);
 					switch_core_db_free(sql);
 				}
 				if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_OUT) == SWITCH_STATUS_SUCCESS) {
@@ -2267,44 +2440,44 @@
 
 		switch (dl_signal) {
 		case LDL_SIGNAL_MSG:{
-				switch_chat_interface_t *ci;
-				char *proto = MDL_CHAT_PROTO;
-				char *pproto = NULL, *ffrom = NULL;
-				char *hint;
-
-				if (profile->auto_reply) {
-					ldl_handle_send_msg(handle,
-										(profile->user_flags & LDL_FLAG_COMPONENT) ? to : ldl_handle_get_login(profile->handle), from, "",
-										profile->auto_reply);
-				}
-
-				if (strchr(to, '+')) {
-					pproto = strdup(to);
-					if ((to = strchr(pproto, '+'))) {
-						*to++ = '\0';
-					}
-					proto = pproto;
+			switch_chat_interface_t *ci;
+			char *proto = MDL_CHAT_PROTO;
+			char *pproto = NULL, *ffrom = NULL;
+			char *hint;
+
+			if (profile->auto_reply) {
+				ldl_handle_send_msg(handle,
+									(profile->user_flags & LDL_FLAG_COMPONENT) ? to : ldl_handle_get_login(profile->handle), from, "",
+									profile->auto_reply);
+			}
+
+			if (strchr(to, '+')) {
+				pproto = strdup(to);
+				if ((to = strchr(pproto, '+'))) {
+					*to++ = '\0';
 				}
+				proto = pproto;
+			}
 
-				hint = from;
-
-				if (strchr(from, '/') && (ffrom = strdup(from))) {
-					char *p;
-					if ((p = strchr(ffrom, '/'))) {
-						*p = '\0';
-					}
-					from = ffrom;
-				}
+			hint = from;
 
-				if ((ci = switch_loadable_module_get_chat_interface(proto))) {
-					ci->chat_send(MDL_CHAT_PROTO, from, to, subject, msg, hint);
-				} else {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Chat Interface [%s]!\n", proto);
+			if (strchr(from, '/') && (ffrom = strdup(from))) {
+				char *p;
+				if ((p = strchr(ffrom, '/'))) {
+					*p = '\0';
 				}
+				from = ffrom;
+			}
 
-				switch_safe_free(pproto);
-				switch_safe_free(ffrom);
+			if ((ci = switch_loadable_module_get_chat_interface(proto))) {
+				ci->chat_send(MDL_CHAT_PROTO, from, to, subject, msg, hint);
+			} else {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Chat Interface [%s]!\n", proto);
 			}
+
+			switch_safe_free(pproto);
+			switch_safe_free(ffrom);
+		}
 			break;
 		case LDL_SIGNAL_LOGIN_SUCCESS:
 			if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, DL_EVENT_LOGIN_SUCCESS) == SWITCH_STATUS_SUCCESS) {
@@ -2556,7 +2729,7 @@
 																																															   address,
 																																															   "169.254.",
 																																															   8)
-																																							))) {
+																																															  ))) {
 					ldl_payload_t payloads[5];
 					char *exten;
 					char *context;
@@ -2710,7 +2883,7 @@
 		break;
 	}
 
-  done:
+ done:
 
 	return status;
 }

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/Makefile
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/Makefile	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/Makefile	Fri Apr  6 19:25:38 2007
@@ -12,7 +12,10 @@
 LOCAL_CFLAGS += -I$(SOFIAUA_DIR)/soa -I$(SOFIAUA_DIR)/sresolv
 LOCAL_CFLAGS += -I$(SOFIAUA_DIR)/stun -I$(SOFIAUA_DIR)/su
 LOCAL_CFLAGS += -I$(SOFIAUA_DIR)/tport -I$(SOFIAUA_DIR)/url
+LOCAL_CFLAGS += `if test -f $(BASE)/.libs/libfreeswitch_la-switch_odbc.o ; then echo -DSWITCH_HAVE_ODBC; fi ;`
+
 LOCAL_OBJS=sofia.o sofia_glue.o sofia_presence.o sofia_reg.o
+LOCAL_SOURCES=sofia.c sofia_glue.c sofia_presense.c sofia_reg.c mod_sofia.c
 
 SOFIALA=$(SOFIAUA_DIR)/libsofia-sip-ua.la
 
@@ -25,3 +28,9 @@
 $(SOFIALA): $(SOFIA_DIR) $(SOFIA_DIR)/.update
 	cd $(SOFIA_DIR) && $(MAKE)
 	$(TOUCH_TARGET)
+
+local_depend: $(SOFIALA)
+
+../../../../libs/sofia-sip/libsofia-sip-ua/nua/sofia-sip/nua_tag.h: $(SOFIALA)
+
+$(LOCAL_OBJS) $(LOCAL_SOURCES): ../../../../libs/sofia-sip/libsofia-sip-ua/nua/sofia-sip/nua_tag.h

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/mod_sofia.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/mod_sofia.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/mod_sofia.c	Fri Apr  6 19:25:38 2007
@@ -888,6 +888,7 @@
 		} else {
 			tech_pvt->dest = switch_core_session_sprintf(nsession, "sip:%s", dest);
 		}
+		tech_pvt->invite_contact = switch_core_session_strdup(nsession, gateway_ptr->register_contact);
 	} else {
 		if (!(dest = strchr(profile_name, '/'))) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid URL\n");
@@ -1008,22 +1009,32 @@
 	config_sofia(0);
 
 
-	if (switch_event_bind((char *) modname, SWITCH_EVENT_PRESENCE_IN, SWITCH_EVENT_SUBCLASS_ANY, sofia_presence_event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
+	if (switch_event_bind((char *) modname, SWITCH_EVENT_PRESENCE_IN, SWITCH_EVENT_SUBCLASS_ANY, sofia_presence_event_handler, NULL)
+		!= SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
 		return SWITCH_STATUS_GENERR;
 	}
 
-	if (switch_event_bind((char *) modname, SWITCH_EVENT_PRESENCE_OUT, SWITCH_EVENT_SUBCLASS_ANY, sofia_presence_event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
+	if (switch_event_bind((char *) modname, SWITCH_EVENT_PRESENCE_OUT, SWITCH_EVENT_SUBCLASS_ANY, sofia_presence_event_handler, NULL)
+		!= SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
 		return SWITCH_STATUS_GENERR;
 	}
 
-	if (switch_event_bind((char *) modname, SWITCH_EVENT_PRESENCE_PROBE, SWITCH_EVENT_SUBCLASS_ANY, sofia_presence_event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
+	if (switch_event_bind((char *) modname, SWITCH_EVENT_PRESENCE_PROBE, SWITCH_EVENT_SUBCLASS_ANY, sofia_presence_event_handler, NULL)
+		!= SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
 		return SWITCH_STATUS_GENERR;
 	}
 
-	if (switch_event_bind((char *) modname, SWITCH_EVENT_ROSTER, SWITCH_EVENT_SUBCLASS_ANY, sofia_presence_event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
+	if (switch_event_bind((char *) modname, SWITCH_EVENT_ROSTER, SWITCH_EVENT_SUBCLASS_ANY, sofia_presence_event_handler, NULL)
+		!= SWITCH_STATUS_SUCCESS) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
+		return SWITCH_STATUS_GENERR;
+	}
+
+	if (switch_event_bind((char *) modname, SWITCH_EVENT_MESSAGE_WAITING, SWITCH_EVENT_SUBCLASS_ANY, sofia_presence_mwi_event_handler, NULL)
+		!= SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
 		return SWITCH_STATUS_GENERR;
 	}

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/mod_sofia.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/mod_sofia.h	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/mod_sofia.h	Fri Apr  6 19:25:38 2007
@@ -40,6 +40,9 @@
 
 #define HAVE_APR
 #include <switch.h>
+#ifdef SWITCH_HAVE_ODBC
+#include <switch_odbc.h>
+#endif
 
 static const char modname[] = "mod_sofia";
 static const switch_state_handler_table_t noop_state_handler = { 0 };
@@ -102,7 +105,8 @@
 	PFLAG_FULL_ID = (1 << 3),
 	PFLAG_PRESENCE = (1 << 4),
 	PFLAG_PASS_RFC2833 = (1 << 5),
-	PFLAG_DISABLE_TRANSCODING = (1 << 6)
+	PFLAG_DISABLE_TRANSCODING = (1 << 6),
+	PFLAG_REWRITE_TIMESTAMPS = (1 << 7)
 } PFLAGS;
 
 typedef enum {
@@ -221,6 +225,18 @@
 	su_home_t *home;
 	switch_hash_t *profile_hash;
 	switch_hash_t *chat_hash;
+	switch_core_db_t *master_db;
+#ifdef SWITCH_HAVE_ODBC
+	char *odbc_dsn;
+	char *odbc_user;
+	char *odbc_pass;
+	switch_odbc_handle_t *master_odbc;
+#else
+	void *filler1;
+	void *filler2;
+	void *filler3;
+	void *filler4;
+#endif
 };
 
 
@@ -276,6 +292,7 @@
 	char *chat_to;
 	char *e_dest;
 	char *call_id;
+	char *invite_contact;
 	unsigned long rm_rate;
 	switch_payload_t pt;
 	switch_mutex_t *flag_mutex;
@@ -328,8 +345,6 @@
 
 uint8_t negotiate_sdp(switch_core_session_t *session, sdp_session_t * sdp);
 
-char *sofia_reg_get_auth_data(char *dbname, char *nonce, char *npassword, size_t len, switch_mutex_t * mutex);
-
 void sofia_presence_establish_presence(sofia_profile_t * profile);
 
 void sofia_handle_sip_i_state(int status,
@@ -361,6 +376,7 @@
 char *sofia_reg_find_reg_url(sofia_profile_t * profile, const char *user, const char *host, char *val, switch_size_t len);
 void event_handler(switch_event_t *event);
 void sofia_presence_event_handler(switch_event_t *event);
+void sofia_presence_mwi_event_handler(switch_event_t *event);
 void sofia_presence_cancel(void);
 switch_status_t config_sofia(int reload);
 auth_res_t parse_auth(sofia_profile_t * profile, sip_authorization_t const *authorization, const char *regstr, char *np, size_t nplen);
@@ -386,14 +402,15 @@
 
 sofia_profile_t *sofia_glue_find_profile(char *key);
 void sofia_glue_add_profile(char *key, sofia_profile_t * profile);
-void sofia_glue_execute_sql(char *dbname, char *sql, switch_mutex_t * mutex);
-void sofia_reg_check_expire(switch_core_db_t *db, sofia_profile_t * profile, time_t now);
+void sofia_glue_execute_sql(sofia_profile_t *profile, switch_bool_t master, char *sql, switch_mutex_t *mutex);
+void sofia_reg_check_expire(sofia_profile_t * profile, time_t now);
 void sofia_reg_check_gateway(sofia_profile_t * profile, time_t now);
 void sofia_reg_unregister(sofia_profile_t * profile);
 switch_status_t sofia_glue_ext_address_lookup(char **ip, switch_port_t *port, char *sourceip, switch_memory_pool_t *pool);
 outbound_reg_t *sofia_reg_find_gateway(char *key);
 void sofia_reg_add_gateway(char *key, outbound_reg_t * gateway);
 void sofia_glue_pass_sdp(private_object_t * tech_pvt, char *sdp);
+int sofia_glue_get_user_host(char *in, char **user, char **host);
 switch_call_cause_t sofia_glue_sip_cause_to_freeswitch(int status);
 void sofia_glue_do_xfer_invite(switch_core_session_t *session);
 uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t * profile, nua_handle_t * nh, sip_t const *sip, sofia_regtype_t regtype, char *key, uint32_t keylen);
@@ -401,6 +418,13 @@
 void sofia_presence_set_chat_hash(private_object_t * tech_pvt, sip_t const *sip);
 switch_status_t sofia_on_hangup(switch_core_session_t *session);
 char *sofia_glue_get_url_from_contact(char *buf, uint8_t to_dup);
-int sofia_presence_resub_callback(void *pArg, int argc, char **argv, char **columnNames);
-int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char **columnNames);
 void sofia_presence_set_hash_key(char *hash_key, int32_t len, sip_t const *sip);
+void sofia_glue_sql_close(sofia_profile_t *profile);
+int sofia_glue_init_sql(sofia_profile_t *profile);
+switch_bool_t sofia_glue_execute_sql_callback(sofia_profile_t *profile,
+											  switch_bool_t master,
+											  switch_mutex_t *mutex,
+											  char *sql,
+											  switch_core_db_callback_func_t callback,
+											  void *pdata);
+char *sofia_glue_execute_sql2str(sofia_profile_t *profile, switch_mutex_t *mutex, char *sql, char *resbuf, size_t len);

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/sofia.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/sofia.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/sofia.c	Fri Apr  6 19:25:38 2007
@@ -29,48 +29,13 @@
  * Bret McDanel <trixter AT 0xdecafbad.com>
  *
  *
- * sofia.c -- SOFIA SIP Endpoint
+ * sofia.c -- SOFIA SIP Endpoint (sofia code)
  *
  */
 #include "mod_sofia.h"
 extern su_log_t tport_log[];
 
 
-static char reg_sql[] =
-	"CREATE TABLE sip_registrations (\n"
-	"   user            VARCHAR(255),\n"
-	"   host            VARCHAR(255),\n"
-	"   contact         VARCHAR(1024),\n" 
-	"   status          VARCHAR(255),\n" 
-	"   rpid            VARCHAR(255),\n" 
-	"   expires         INTEGER(8)" ");\n";
-
-
-static char sub_sql[] =
-	"CREATE TABLE sip_subscriptions (\n"
-	"   proto           VARCHAR(255),\n"
-	"   user            VARCHAR(255),\n"
-	"   host            VARCHAR(255),\n"
-	"   sub_to_user     VARCHAR(255),\n"
-	"   sub_to_host     VARCHAR(255),\n"
-	"   event           VARCHAR(255),\n"
-	"   contact         VARCHAR(1024),\n"
-	"   call_id         VARCHAR(255),\n" 
-	"   full_from       VARCHAR(255),\n" 
-	"   full_via        VARCHAR(255),\n" 
-	"   expires         INTEGER(8)" ");\n";
-
-
-static char auth_sql[] =
-	"CREATE TABLE sip_authentication (\n"
-	"   user            VARCHAR(255),\n"
-	"   host            VARCHAR(255),\n" 
-	"   passwd            VARCHAR(255),\n" 
-	"   nonce           VARCHAR(255),\n" 
-	"   expires         INTEGER(8)"
-	");\n";
-
-
 void sofia_event_callback(nua_event_t event,
 						   int status,
 						   char const *phrase,
@@ -253,7 +218,7 @@
 		}
 
 		if (sql) {
-			sofia_glue_execute_sql(profile->dbname, sql, profile->ireg_mutex);
+			sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, profile->ireg_mutex);
 			switch_safe_free(sql);
 			sql = NULL;
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Propagating registration for %s@%s->%s\n", from_user, from_host, contact_str);
@@ -272,7 +237,6 @@
 	sip_alias_node_t *node;
 	uint32_t ireg_loops = 0;
 	uint32_t gateway_loops = 0;
-	switch_core_db_t *db;
 	switch_event_t *s_event;
 
 	profile->s_root = su_root_create(NULL);
@@ -320,11 +284,7 @@
 	}
 
 
-	if ((db = switch_core_db_open_file(profile->dbname))) {
-		switch_core_db_test_reactive(db, "select contact from sip_registrations", reg_sql);
-		switch_core_db_test_reactive(db, "select contact from sip_subscriptions", sub_sql);
-		switch_core_db_test_reactive(db, "select * from sip_authentication", auth_sql);
-	} else {
+	if (!sofia_glue_init_sql(profile)) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open SQL Database!\n");
 		return NULL;
 	}
@@ -362,7 +322,7 @@
 
 	while (mod_sofia_globals.running == 1) {
 		if (++ireg_loops >= IREG_SECONDS) {
-			sofia_reg_check_expire(db, profile, time(NULL));
+			sofia_reg_check_expire(profile, time(NULL));
 			ireg_loops = 0;
 		}
 
@@ -373,8 +333,9 @@
 
 		su_root_step(profile->s_root, 1000);
 	}
+	
+	sofia_glue_sql_close(profile);
 
-	switch_core_db_close(db);
 	sofia_reg_unregister(profile);
 	su_home_unref(profile->home);
 
@@ -496,6 +457,7 @@
 
 				profile->name = switch_core_strdup(profile->pool, xprofilename);
 				snprintf(url, sizeof(url), "sofia_reg_%s", xprofilename);
+				
 				profile->dbname = switch_core_strdup(profile->pool, url);
 				switch_core_hash_init(&profile->chat_hash, profile->pool);
 
@@ -510,6 +472,22 @@
 						profile->debug = atoi(val);
 					} else if (!strcasecmp(var, "use-rtp-timer") && switch_true(val)) {
 						switch_set_flag(profile, TFLAG_TIMER);
+
+					} else if (!strcasecmp(var, "odbc-dsn")) {
+#ifdef SWITCH_HAVE_ODBC
+						profile->odbc_dsn = switch_core_strdup(profile->pool, val);
+						if ((profile->odbc_user = strchr(profile->odbc_dsn, ':'))) {
+							*profile->odbc_user++ = '\0';
+						}
+						if ((profile->odbc_pass = strchr(profile->odbc_user, ':'))) {
+							*profile->odbc_pass++ = '\0';
+						}
+
+				
+#else
+						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n");
+#endif
+						
 					} else if (!strcasecmp(var, "inbound-no-media") && switch_true(val)) {
 						switch_set_flag(profile, TFLAG_INB_NOMEDIA);
 					} else if (!strcasecmp(var, "inbound-late-negotiation") && switch_true(val)) {
@@ -569,6 +547,10 @@
 						if (switch_true(val)) {
 							profile->pflags |= PFLAG_DISABLE_TRANSCODING;
 						}
+					} else if (!strcasecmp(var, "rtp-rewrite-timestamps")) {
+						if (switch_true(val)) {
+							profile->pflags |= PFLAG_REWRITE_TIMESTAMPS;
+						}
 					} else if (!strcasecmp(var, "auth-calls")) {
 						if (switch_true(val)) {
 							profile->pflags |= PFLAG_AUTH_CALLS;
@@ -1004,16 +986,18 @@
 					nua_respond(nh, SIP_488_NOT_ACCEPTABLE, TAG_END());
 				}
 			} else {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Invite with no SDP activating no-media-mode\n");
-				switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "RECEIVED_NOSDP");
-
-				switch_set_flag(tech_pvt, TFLAG_LATE_NEGOTIATION);
-				switch_set_flag_locked(tech_pvt, TFLAG_NOMEDIA);
-				switch_channel_set_flag(channel, CF_NOMEDIA);
-				switch_channel_set_state(channel, CS_INIT);
-				switch_set_flag_locked(tech_pvt, TFLAG_READY);
-				switch_core_session_thread_launch(session);
-				goto done;
+				if (switch_test_flag(tech_pvt, TFLAG_NOMEDIA)) {
+					goto done;
+				} else {
+					switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "RECEIVED_NOSDP");
+					switch_set_flag(tech_pvt, TFLAG_LATE_NEGOTIATION);
+					sofia_glue_set_local_sdp(tech_pvt, NULL, 0, NULL, 0);
+					
+					nua_respond(tech_pvt->nh, SIP_200_OK,
+								SIPTAG_CONTACT_STR(tech_pvt->profile->url),
+								SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str), SOATAG_AUDIO_AUX("cn telephone-event"), NUTAG_INCLUDE_EXTRA_SDP(1), TAG_END());
+					goto done;
+				}
 			}
 		}
 

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/sofia_glue.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/sofia_glue.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/sofia_glue.c	Fri Apr  6 19:25:38 2007
@@ -1,3 +1,37 @@
+/* 
+ * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
+ * Copyright (C) 2005/2006, Anthony Minessale II <anthmct at yahoo.com>
+ *
+ * Version: MPL 1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
+ *
+ * The Initial Developer of the Original Code is
+ * Anthony Minessale II <anthmct at yahoo.com>
+ * Portions created by the Initial Developer are Copyright (C)
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * 
+ * Anthony Minessale II <anthmct at yahoo.com>
+ * Ken Rice, Asteria Solutions Group, Inc <ken at asteriasgi.com>
+ * Paul D. Tinsley <pdt at jackhammer.org>
+ * Bret McDanel <trixter AT 0xdecafbad.com>
+ *
+ *
+ * sofia_glue.c -- SOFIA SIP Endpoint (code to tie sofia to freeswitch)
+ *
+ */
 #include "mod_sofia.h"
 
 
@@ -382,7 +416,10 @@
 		char *url = sofia_glue_get_url_from_contact(tech_pvt->dest, 1);
 		tech_pvt->nh = nua_handle(tech_pvt->profile->nua, NULL,
 								  NUTAG_URL(url),
-								  SIPTAG_TO_STR(tech_pvt->dest_to), SIPTAG_FROM_STR(tech_pvt->from_str), SIPTAG_CONTACT_STR(tech_pvt->profile->url),
+								  SIPTAG_TO_STR(tech_pvt->dest_to),
+								  SIPTAG_FROM_STR(tech_pvt->from_str),
+								  TAG_IF(tech_pvt->invite_contact, SIPTAG_CONTACT_STR(tech_pvt->invite_contact)),
+								  TAG_IF(!tech_pvt->invite_contact, SIPTAG_CONTACT_STR(tech_pvt->profile->url)),
 								  TAG_END());
 		switch_safe_free(url);
 
@@ -438,7 +475,6 @@
 			   TAG_IF(!switch_strlen_zero(alert_info), SIPTAG_HEADER_STR(alert_info)),
 			   TAG_IF(!switch_strlen_zero(extra_headers), SIPTAG_HEADER_STR(extra_headers)),
 			   TAG_IF(!switch_strlen_zero(max_forwards), SIPTAG_MAX_FORWARDS_STR(max_forwards)),
-			   //SIPTAG_CONTACT_STR(tech_pvt->profile->url),
 			   SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
 			   SOATAG_RTP_SORT(SOA_RTP_SORT_REMOTE),
 			   SOATAG_RTP_SELECT(SOA_RTP_SELECT_ALL), TAG_IF(rep, SIPTAG_REPLACES_STR(rep)), SOATAG_HOLD(holdstr), TAG_END());
@@ -646,7 +682,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_AUTOADJ | SWITCH_RTP_FLAG_DATAWAIT);
+	flags = (switch_rtp_flag_t) (SWITCH_RTP_FLAG_AUTOADJ | SWITCH_RTP_FLAG_DATAWAIT);
 
 	if (switch_test_flag(tech_pvt, TFLAG_BUGGY_2833)) {
 		flags |= SWITCH_RTP_FLAG_BUGGY_2833;
@@ -657,6 +693,11 @@
 		flags |= SWITCH_RTP_FLAG_PASS_RFC2833;
 	}
 
+	if (!((tech_pvt->profile->pflags & PFLAG_REWRITE_TIMESTAMPS) || 
+		  ((val = switch_channel_get_variable(channel, "rtp_rewrite_timestamps")) && switch_true(val)))) {
+		flags |= SWITCH_RTP_FLAG_RAW_WRITE;
+	}
+
 	if (tech_pvt->cng_pt) {
 		flags |= SWITCH_RTP_FLAG_AUTO_CNG;
 	}
@@ -1085,7 +1126,91 @@
 	switch_mutex_unlock(mod_sofia_globals.hash_mutex);
 }
 
-void sofia_glue_execute_sql(char *dbname, char *sql, switch_mutex_t * mutex)
+int sofia_glue_init_sql(sofia_profile_t *profile)
+{
+
+	
+	char reg_sql[] =
+		"CREATE TABLE sip_registrations (\n"
+		"   user            VARCHAR(255),\n"
+		"   host            VARCHAR(255),\n"
+		"   contact         VARCHAR(1024),\n" 
+		"   status          VARCHAR(255),\n" 
+		"   rpid            VARCHAR(255),\n" 
+		"   expires         INTEGER(8)" ");\n";
+
+
+	char sub_sql[] =
+		"CREATE TABLE sip_subscriptions (\n"
+		"   proto           VARCHAR(255),\n"
+		"   user            VARCHAR(255),\n"
+		"   host            VARCHAR(255),\n"
+		"   sub_to_user     VARCHAR(255),\n"
+		"   sub_to_host     VARCHAR(255),\n"
+		"   event           VARCHAR(255),\n"
+		"   contact         VARCHAR(1024),\n"
+		"   call_id         VARCHAR(255),\n" 
+		"   full_from       VARCHAR(255),\n" 
+		"   full_via        VARCHAR(255),\n" 
+		"   expires         INTEGER(8)" ");\n";
+
+
+	char auth_sql[] =
+		"CREATE TABLE sip_authentication (\n"
+		"   user            VARCHAR(255),\n"
+		"   host            VARCHAR(255),\n" 
+		"   passwd            VARCHAR(255),\n" 
+		"   nonce           VARCHAR(255),\n" 
+		"   expires         INTEGER(8)"
+		");\n";
+	
+#ifdef SWITCH_HAVE_ODBC
+	if (profile->odbc_dsn) {
+		if (!(profile->master_odbc = switch_odbc_handle_new(profile->odbc_dsn, profile->odbc_user, profile->odbc_pass))) {
+			return 0;
+		}
+		if (switch_odbc_handle_connect(profile->master_odbc) != SWITCH_ODBC_SUCCESS) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Connecting ODBC DSN: %s\n", profile->odbc_dsn);
+			return 0;
+		}
+
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Connected ODBC DSN: %s\n", profile->odbc_dsn);
+			
+		switch_odbc_handle_exec(profile->master_odbc, reg_sql, NULL);
+		switch_odbc_handle_exec(profile->master_odbc, sub_sql, NULL);
+		switch_odbc_handle_exec(profile->master_odbc, auth_sql, NULL);
+	} else {
+#endif
+		if (!(profile->master_db = switch_core_db_open_file(profile->dbname))) {
+			return 0;
+		}
+
+		switch_core_db_test_reactive(profile->master_db, "select contact from sip_registrations", reg_sql);
+		switch_core_db_test_reactive(profile->master_db, "select contact from sip_subscriptions", sub_sql);
+		switch_core_db_test_reactive(profile->master_db, "select * from sip_authentication", auth_sql);
+
+#ifdef SWITCH_HAVE_ODBC
+	}
+#endif
+
+	return 1;
+}
+
+void sofia_glue_sql_close(sofia_profile_t *profile)
+{
+#ifdef SWITCH_HAVE_ODBC
+    if (profile->odbc_dsn) {
+		switch_odbc_handle_destroy(&profile->master_odbc);
+	} else {
+#endif
+		switch_core_db_close(profile->master_db);
+#ifdef SWITCH_HAVE_ODBC
+	}
+#endif
+}
+
+
+void sofia_glue_execute_sql(sofia_profile_t *profile, switch_bool_t master, char *sql, switch_mutex_t *mutex)
 {
 	switch_core_db_t *db;
 
@@ -1093,18 +1218,225 @@
 		switch_mutex_lock(mutex);
 	}
 
-	if (!(db = switch_core_db_open_file(dbname))) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", dbname);
-		goto end;
+#ifdef SWITCH_HAVE_ODBC
+    if (profile->odbc_dsn) {
+		SQLHSTMT stmt;
+		if (switch_odbc_handle_exec(profile->master_odbc, sql, &stmt) != SWITCH_ODBC_SUCCESS) {
+			char *err_str;
+			err_str = switch_odbc_handle_get_error(profile->master_odbc, stmt);
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ERR: [%s]\n[%s]\n", sql, switch_str_nil(err_str));
+			switch_safe_free(err_str);
+		}
+		SQLFreeHandle(SQL_HANDLE_STMT, stmt);
+	} else {
+#endif
+
+
+	if (master) {
+		db = profile->master_db;
+	} else {
+		if (!(db = switch_core_db_open_file(profile->dbname))) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
+			goto end;
+		}
 	}
 	switch_core_db_persistant_execute(db, sql, 25);
+	if (!master) {
+		switch_core_db_close(db);
+	}
+
+
+#ifdef SWITCH_HAVE_ODBC
+    }
+#endif
+
+
+  end:
+	if (mutex) {
+		switch_mutex_unlock(mutex);
+	}
+}
+
+
+switch_bool_t sofia_glue_execute_sql_callback(sofia_profile_t *profile,
+											  switch_bool_t master,
+											  switch_mutex_t *mutex,
+											  char *sql,
+											  switch_core_db_callback_func_t callback,
+											  void *pdata)
+{
+	switch_bool_t ret = SWITCH_FALSE;
+	switch_core_db_t *db;
+	char *errmsg = NULL;
+	
+	if (mutex) {
+        switch_mutex_lock(mutex);
+    }
+
+
+#ifdef SWITCH_HAVE_ODBC
+    if (profile->odbc_dsn) {
+		switch_odbc_handle_callback_exec(profile->master_odbc, sql, callback, pdata);
+	} else {
+#endif
+
+
+	if (master) {
+		db = profile->master_db;
+	} else {
+		if (!(db = switch_core_db_open_file(profile->dbname))) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
+			goto end;
+		}
+	}
+	
+	switch_core_db_exec(db, sql, callback, pdata, &errmsg);
+
+	if (errmsg) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg);
+		free(errmsg);
+	}
+
+	if (!master && db) {
+		switch_core_db_close(db);
+	}
+
+#ifdef SWITCH_HAVE_ODBC
+    }
+#endif
+
+
+ end:
+
+	if (mutex) {
+        switch_mutex_unlock(mutex);
+    }
+	
+
+
+	return ret;
+
+}
+
+#ifdef SWITCH_HAVE_ODBC
+static char *sofia_glue_execute_sql2str_odbc(sofia_profile_t *profile, switch_mutex_t *mutex, char *sql, char *resbuf, size_t len)
+{
+	char *ret = NULL;
+	SQLHSTMT stmt;
+	SQLCHAR name[1024];
+	SQLINTEGER m = 0;
+
+	if (switch_odbc_handle_exec(profile->master_odbc, sql, &stmt) == SWITCH_ODBC_SUCCESS) {
+		SQLSMALLINT NameLength, DataType, DecimalDigits, Nullable;
+		SQLUINTEGER ColumnSize;
+		SQLRowCount(stmt, &m);
+
+		if (m <= 0) {
+			return NULL;
+		}
+
+		if (SQLFetch(stmt) != SQL_SUCCESS) {
+			return NULL;
+		}
+
+		SQLDescribeCol(stmt, 1, name, sizeof(name), &NameLength, &DataType, &ColumnSize, &DecimalDigits, &Nullable);
+		SQLGetData(stmt, 1, SQL_C_CHAR, (SQLCHAR *)resbuf, (SQLINTEGER)len, NULL);
+		SQLFreeHandle(SQL_HANDLE_STMT, stmt);
+		ret = resbuf;
+	}
+
+	return ret;
+}
+
+#endif
+
+char *sofia_glue_execute_sql2str(sofia_profile_t *profile, switch_mutex_t *mutex, char *sql, char *resbuf, size_t len)
+{
+	switch_core_db_t *db;
+	switch_core_db_stmt_t *stmt;
+	char *ret = NULL;
+
+#ifdef SWITCH_HAVE_ODBC
+    if (profile->odbc_dsn) {
+		return sofia_glue_execute_sql2str_odbc(profile, mutex, sql, resbuf, len);
+	}
+#endif
+
+	if (mutex) {
+		switch_mutex_lock(mutex);
+	}
+
+	if (!(db = switch_core_db_open_file(profile->dbname))) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
+		goto end;
+	}
+
+	if (switch_core_db_prepare(db, sql, -1, &stmt, 0)) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Statement Error!\n");
+		goto fail;
+	} else {
+		int running = 1;
+		int colcount;
+
+		while (running < 5000) {
+			int result = switch_core_db_step(stmt);
+
+			if (result == SWITCH_CORE_DB_ROW) {
+				if ((colcount = switch_core_db_column_count(stmt))) {
+					switch_copy_string(resbuf, (char *) switch_core_db_column_text(stmt, 0), len);
+					ret = resbuf;
+				}
+				break;
+			} else if (result == SWITCH_CORE_DB_BUSY) {
+				running++;
+				switch_yield(1000);
+				continue;
+			}
+			break;
+		}
+
+		switch_core_db_finalize(stmt);
+	}
+
+
+  fail:
+
 	switch_core_db_close(db);
 
   end:
 	if (mutex) {
 		switch_mutex_unlock(mutex);
 	}
+
+	return ret;
 }
 
+int sofia_glue_get_user_host(char *in, char **user, char **host)
+{
+	char *p, *h, *u = in;
+
+	*user = NULL;
+	*host = NULL;
+
+	if (!strncasecmp(u, "sip:", 4)) {
+		u += 4;
+	}
+
+	if ((h = strchr(u, '@'))) {
+		*h++ = '\0';
+	} else {
+		return 0;
+	}
 
+	p = h + strlen(h) - 1;
+
+	if (p && (*p == ':' || *p == ';' || *p == ' ')) {
+		*p = '\0';
+	}
 
+	*user = u;
+	*host = h;
+
+	return 1;
+
+}

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/sofia_presence.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/sofia_presence.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/sofia_presence.c	Fri Apr  6 19:25:38 2007
@@ -1,5 +1,43 @@
+/* 
+ * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
+ * Copyright (C) 2005/2006, Anthony Minessale II <anthmct at yahoo.com>
+ *
+ * Version: MPL 1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
+ *
+ * The Initial Developer of the Original Code is
+ * Anthony Minessale II <anthmct at yahoo.com>
+ * Portions created by the Initial Developer are Copyright (C)
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * 
+ * Anthony Minessale II <anthmct at yahoo.com>
+ * Ken Rice, Asteria Solutions Group, Inc <ken at asteriasgi.com>
+ * Paul D. Tinsley <pdt at jackhammer.org>
+ * Bret McDanel <trixter AT 0xdecafbad.com>
+ *
+ *
+ * sofia_presence.c -- SOFIA SIP Endpoint (presence code)
+ *
+ */
 #include "mod_sofia.h"
 
+static int sofia_presence_mwi_callback(void *pArg, int argc, char **argv, char **columnNames);
+static int sofia_presence_sub_reg_callback(void *pArg, int argc, char **argv, char **columnNames);
+static int sofia_presence_resub_callback(void *pArg, int argc, char **argv, char **columnNames);
+static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char **columnNames);
 
 switch_status_t sofia_presence_chat_send(char *proto, char *from, char *to, char *subject, char *body, char *hint)
 {
@@ -67,8 +105,7 @@
 
 void sofia_presence_cancel(void)
 {
-	char *sql, *errmsg = NULL;
-	switch_core_db_t *db;
+	char *sql;
 	sofia_profile_t *profile;
 	switch_hash_index_t *hi;
 	void *val;
@@ -82,47 +119,30 @@
 				continue;
 			}
 
-			if (!(db = switch_core_db_open_file(profile->dbname))) {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
+			if (sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex, sql, sofia_presence_sub_callback, profile) != SWITCH_TRUE) {
 				continue;
 			}
-			switch_mutex_lock(profile->ireg_mutex);
-			switch_core_db_exec(db, sql, sofia_presence_sub_callback, profile, &errmsg);
-			switch_mutex_unlock(profile->ireg_mutex);
-			switch_core_db_close(db);
 		}
 		switch_safe_free(sql);
+		switch_mutex_unlock(mod_sofia_globals.hash_mutex);
 	}
-	switch_mutex_unlock(mod_sofia_globals.hash_mutex);
 }
 
 void sofia_presence_establish_presence(sofia_profile_t * profile)
 {
-	char *sql, *errmsg = NULL;
-	switch_core_db_t *db;
 
-	if (!(db = switch_core_db_open_file(profile->dbname))) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
+	if (sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex, 
+										"select user,host,'Registered','unknown','' from sip_registrations", 
+										sofia_presence_resub_callback, profile) != SWITCH_TRUE) {
 		return;
 	}
 
-	if ((sql = switch_mprintf("select user,host,'Registered','unknown','' from sofia_handle_sip_registrations"))) {
-		switch_mutex_lock(profile->ireg_mutex);
-		switch_core_db_exec(db, sql, sofia_presence_resub_callback, profile, &errmsg);
-		switch_mutex_unlock(profile->ireg_mutex);
-		switch_safe_free(sql);
-	}
-
-	if ((sql = switch_mprintf("select sub_to_user,sub_to_host,'Online','unknown',proto from sip_subscriptions "
-							  "where proto='ext' or proto='user' or proto='conf'"))) {
-		switch_mutex_lock(profile->ireg_mutex);
-		switch_core_db_exec(db, sql, sofia_presence_resub_callback, profile, &errmsg);
-		switch_mutex_unlock(profile->ireg_mutex);
-		switch_safe_free(sql);
+	if (sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex,
+										"select sub_to_user,sub_to_host,'Online','unknown',proto from sip_subscriptions "
+										"where proto='ext' or proto='user' or proto='conf'",
+										sofia_presence_resub_callback, profile) != SWITCH_TRUE) {
+		return;
 	}
-
-	switch_core_db_close(db);
-
 }
 
 
@@ -154,6 +174,64 @@
 	return r;
 }
 
+void sofia_presence_mwi_event_handler(switch_event_t *event)
+{
+	char *account, *dup_account, *yn, *host, *user;
+	char *sql;
+	sofia_profile_t *profile;
+	switch_stream_handle_t stream = { 0 };
+	switch_event_header_t *hp;
+
+	assert(event != NULL);
+
+	if (!(account = switch_event_get_header(event, "mwi-message-account"))) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing required Header 'MWI-Message-Account'\n");
+		return;
+	}
+
+	if (!(yn = switch_event_get_header(event, "mwi-messages-waiting"))) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing required Header 'MWI-Messages-Waiting'\n");
+		return;
+	}
+
+	dup_account = strdup(account);
+	assert(dup_account != NULL);
+	sofia_glue_get_user_host(dup_account, &user, &host);
+
+	if (!host || !(profile = sofia_glue_find_profile(host))) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find profile for host %s\n", switch_str_nil(host));
+		return;
+	}
+	
+	SWITCH_STANDARD_STREAM(stream);
+
+	for (hp = event->headers; hp; hp = hp->next) {
+		if (!strncasecmp(hp->name, "mwi-", 4)) {
+			stream.write_function(&stream, "%s: %s\r\n", hp->name + 4, hp->value);
+		}
+	}
+
+	stream.write_function(&stream, "\r\n");
+	
+	sql = switch_mprintf("select *,'%q' from sip_subscriptions where event='message-summary' and sub_to_user='%q' and sub_to_host='%q'", 
+						 stream.data, user, host);
+	
+	switch_safe_free(stream.data);
+
+	assert (sql != NULL);
+
+	sofia_glue_execute_sql_callback(profile,
+									SWITCH_FALSE,
+									profile->ireg_mutex,
+									sql,
+									sofia_presence_mwi_callback,
+									profile);
+
+
+	switch_safe_free(sql);
+	switch_safe_free(dup_account);
+}
+
 void sofia_presence_event_handler(switch_event_t *event)
 {
 	sofia_profile_t *profile;
@@ -167,8 +245,6 @@
 	//char *event_subtype = switch_event_get_header(event, "event_subtype");
 	char *sql = NULL;
 	char *euser = NULL, *user = NULL, *host = NULL;
-	char *errmsg;
-	switch_core_db_t *db;
 
 
 	if (rpid && !strcasecmp(rpid, "n/a")) {
@@ -208,7 +284,8 @@
 		} else {
 			sql = switch_mprintf("select 1,'%q','%q',* from sip_subscriptions where event='presence'", status, rpid);
 		}
-
+		
+		assert(sql != NULL);
 		switch_mutex_lock(mod_sofia_globals.hash_mutex);
 		for (hi = switch_hash_first(switch_hash_pool_get(mod_sofia_globals.profile_hash), mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) {
 			switch_hash_this(hi, NULL, NULL, &val);
@@ -217,20 +294,18 @@
 				continue;
 			}
 
-			if (sql) {
-				if (!(db = switch_core_db_open_file(profile->dbname))) {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
-					continue;
-				}
-				switch_mutex_lock(profile->ireg_mutex);
-				switch_core_db_exec(db, sql, sofia_presence_sub_callback, profile, &errmsg);
-				switch_mutex_unlock(profile->ireg_mutex);
-				switch_core_db_close(db);
-			}
+		
+			sofia_glue_execute_sql_callback(profile,
+											SWITCH_FALSE,
+											profile->ireg_mutex,
+											sql,
+											sofia_presence_sub_callback,
+											profile);
+		
 
 		}
 		switch_mutex_unlock(mod_sofia_globals.hash_mutex);
-
+		free(sql);
 		return;
 	}
 
@@ -263,7 +338,6 @@
 	switch (event->event_id) {
 	case SWITCH_EVENT_PRESENCE_PROBE:
 		if (proto) {
-			switch_core_db_t *db = NULL;
 			char *to = switch_event_get_header(event, "to");
 			char *user, *euser, *host, *p;
 
@@ -280,23 +354,19 @@
 			}
 
 			if (euser && host &&
-				(sql =
-				 switch_mprintf("select user,host,status,rpid,'' from sofia_handle_sip_registrations where user='%q' and host='%q'",
-								euser, host)) && (profile = sofia_glue_find_profile(host))) {
-				if (!(db = switch_core_db_open_file(profile->dbname))) {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
-					switch_safe_free(user);
-					switch_safe_free(sql);
-					return;
-				}
+				(sql = switch_mprintf("select user,host,status,rpid,'' from sip_registrations where user='%q' and host='%q'",
+									  euser, host)) && (profile = sofia_glue_find_profile(host))) {
+				
+				sofia_glue_execute_sql_callback(profile,
+												SWITCH_FALSE,
+												profile->ireg_mutex,
+												sql,
+												sofia_presence_resub_callback,
+												profile);
 
-				switch_mutex_lock(profile->ireg_mutex);
-				switch_core_db_exec(db, sql, sofia_presence_resub_callback, profile, &errmsg);
-				switch_mutex_unlock(profile->ireg_mutex);
 				switch_safe_free(sql);
 			}
 			switch_safe_free(user);
-			switch_core_db_close(db);
 		}
 		return;
 	case SWITCH_EVENT_PRESENCE_IN:
@@ -324,15 +394,13 @@
 		}
 
 		if (sql) {
-			if (!(db = switch_core_db_open_file(profile->dbname))) {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
-				continue;
-			}
-			switch_mutex_lock(profile->ireg_mutex);
-			switch_core_db_exec(db, sql, sofia_presence_sub_callback, profile, &errmsg);
-			switch_mutex_unlock(profile->ireg_mutex);
+			sofia_glue_execute_sql_callback(profile,
+											SWITCH_FALSE,
+											profile->ireg_mutex,
+											sql,
+											sofia_presence_sub_callback,
+											profile);
 
-			switch_core_db_close(db);
 		}
 	}
 	switch_mutex_unlock(mod_sofia_globals.hash_mutex);
@@ -341,7 +409,7 @@
 	switch_safe_free(user);
 }
 
-int sofia_presence_sub_reg_callback(void *pArg, int argc, char **argv, char **columnNames)
+static int sofia_presence_sub_reg_callback(void *pArg, int argc, char **argv, char **columnNames)
 {
 	sofia_profile_t *profile = (sofia_profile_t *) pArg;
 	//char *proto = argv[0];
@@ -349,6 +417,16 @@
 	char *host = argv[2];
 	switch_event_t *event;
 	char *status = NULL;
+	char *event_name = argv[5];
+
+	if (!strcasecmp(event_name, "message-summary")) {
+		if (switch_event_create(&event, SWITCH_EVENT_MESSAGE_QUERY) == SWITCH_STATUS_SUCCESS) {
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Message-Account", "sip:%s@%s", user, host);
+			switch_event_fire(&event);
+		}
+		return 0;
+	}
+
 	if (switch_strlen_zero(status)) {
 		status = "Available";
 	}
@@ -365,7 +443,7 @@
 	return 0;
 }
 
-int sofia_presence_resub_callback(void *pArg, int argc, char **argv, char **columnNames)
+static int sofia_presence_resub_callback(void *pArg, int argc, char **argv, char **columnNames)
 {
 	sofia_profile_t *profile = (sofia_profile_t *) pArg;
 	char *user = argv[0];
@@ -392,7 +470,7 @@
 	return 0;
 }
 
-int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char **columnNames)
+static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char **columnNames)
 {
 	sofia_profile_t *profile = (sofia_profile_t *) pArg;
 	char *pl;
@@ -476,6 +554,62 @@
 	return 0;
 }
 
+static int sofia_presence_mwi_callback(void *pArg, int argc, char **argv, char **columnNames)
+{
+	//char *proto = argv[0];
+	//char *user = argv[1];
+	char *host = argv[2];
+	char *sub_to_user = argv[3];
+	char *sub_to_host = argv[4];
+	char *event = argv[5];
+	char *contact = argv[6];
+	char *call_id = argv[7];
+	char *full_from = argv[8];
+	char *full_via = argv[9];
+	char *expires = argv[10];
+	char *body = argv[11];
+	char *exp;
+	sofia_profile_t *profile;
+	char *tmp, *id = NULL;
+	nua_handle_t *nh;
+	int expire_sec = atoi(expires);
+
+	if (!(profile = sofia_glue_find_profile(sub_to_host))) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find profile for host %s\n", host);
+		return 0;
+	}
+	
+	nh = nua_handle(profile->nua, NULL, TAG_END());
+	assert(nh != NULL);
+
+	id = switch_mprintf("sip:%s@%s", sub_to_user, sub_to_host);
+	expire_sec = (int)(expire_sec - time(NULL));
+	if (expire_sec < 0) {
+		expire_sec = 3600;
+	}
+	exp = switch_mprintf("active;expires=%ld", expire_sec);
+
+	tmp = contact;
+	contact = sofia_glue_get_url_from_contact(tmp, 0);
+
+	nua_notify(nh,
+			   NUTAG_URL(contact),
+			   SIPTAG_TO_STR(full_from),
+			   SIPTAG_FROM_STR(id),
+			   //SIPTAG_CONTACT_STR(profile->url),
+			   SIPTAG_CONTACT_STR(id),
+			   SIPTAG_CALL_ID_STR(call_id),
+			   SIPTAG_VIA_STR(full_via),
+			   SIPTAG_SUBSCRIPTION_STATE_STR(exp),
+			   SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR("application/simple-message-summary"), SIPTAG_PAYLOAD_STR(body), TAG_END());
+
+
+	switch_safe_free(id);
+	switch_safe_free(exp);
+	return 0;
+}
+
+
 void sofia_presence_handle_sip_i_subscribe(int status,
 							char const *phrase,
 							nua_t * nua, sofia_profile_t * profile, nua_handle_t * nh, sofia_private_t * sofia_private, sip_t const *sip, tagi_t tags[])
@@ -497,8 +631,6 @@
 		char *to_str = NULL;
 		char *full_from = NULL;
 		char *full_via = NULL;
-		switch_core_db_t *db;
-		char *errmsg;
 		char *sstr;
 		const char *display = "\"user\"";
 		switch_event_t *sevent;
@@ -594,17 +726,28 @@
 			from_host = "n/a";
 		}
 
-		if ((sql = switch_mprintf("delete from sip_subscriptions where "
-								  "proto='%q' and user='%q' and host='%q' and sub_to_user='%q' and sub_to_host='%q' and event='%q';\n"
-								  "insert into sip_subscriptions values ('%q','%q','%q','%q','%q','%q','%q','%q','%q','%q',%ld)",
-								  proto,
-								  from_user,
-								  from_host,
-								  to_user,
-								  to_host, event, proto, from_user, from_host, to_user, to_host, event, contact_str, call_id, full_from, full_via, exp))) {
-			sofia_glue_execute_sql(profile->dbname, sql, profile->ireg_mutex);
-			switch_safe_free(sql);
-		}
+		switch_mutex_lock(profile->ireg_mutex);
+
+		sql = switch_mprintf("delete from sip_subscriptions where "
+							 "proto='%q' and user='%q' and host='%q' and sub_to_user='%q' and sub_to_host='%q' and event='%q'",
+							 proto,
+							 from_user,
+							 from_host,
+							 to_user,
+							 to_host, event, proto
+							 );
+
+		assert(sql != NULL);
+		sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, NULL);
+		free(sql);
+		sql = switch_mprintf("insert into sip_subscriptions values ('%q','%q','%q','%q','%q','%q','%q','%q','%q','%q',%ld)",
+							 proto, from_user, from_host, to_user, to_host, event, contact_str, call_id, full_from, full_via, exp);
+
+		assert(sql != NULL);
+		sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, NULL);
+		free(sql);
+
+		switch_mutex_unlock(profile->ireg_mutex);
 
 		sstr = switch_mprintf("active;expires=%ld", exp_raw);
 
@@ -616,18 +759,17 @@
 
 		switch_safe_free(sstr);
 
-		if (!(db = switch_core_db_open_file(profile->dbname))) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
-			goto end;
-		}
 		if ((sql = switch_mprintf("select * from sip_subscriptions where user='%q' and host='%q'", to_user, to_host, to_user, to_host))) {
-			switch_mutex_lock(profile->ireg_mutex);
-			switch_core_db_exec(db, sql, sofia_presence_sub_reg_callback, profile, &errmsg);
-			switch_mutex_unlock(profile->ireg_mutex);
+			sofia_glue_execute_sql_callback(profile,
+											SWITCH_FALSE,
+											profile->ireg_mutex,
+											sql,
+											sofia_presence_sub_reg_callback,
+											profile);
+
 			switch_safe_free(sql);
 		}
-		switch_core_db_close(db);
-	  end:
+	end:
 
 		if (event) {
 			su_free(profile->home, event);
@@ -708,9 +850,9 @@
 				}
 
 				if ((sql =
-					 switch_mprintf("update sofia_handle_sip_registrations set status='%q',rpid='%q' where user='%q' and host='%q'",
+					 switch_mprintf("update sip_registrations set status='%q',rpid='%q' where user='%q' and host='%q'",
 									note_txt, rpid, from_user, from_host))) {
-					sofia_glue_execute_sql(profile->dbname, sql, profile->ireg_mutex);
+					sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, profile->ireg_mutex);
 					switch_safe_free(sql);
 				}
 

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/sofia_reg.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/sofia_reg.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/sofia_reg.c	Fri Apr  6 19:25:38 2007
@@ -1,7 +1,41 @@
+/* 
+ * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
+ * Copyright (C) 2005/2006, Anthony Minessale II <anthmct at yahoo.com>
+ *
+ * Version: MPL 1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
+ *
+ * The Initial Developer of the Original Code is
+ * Anthony Minessale II <anthmct at yahoo.com>
+ * Portions created by the Initial Developer are Copyright (C)
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * 
+ * Anthony Minessale II <anthmct at yahoo.com>
+ * Ken Rice, Asteria Solutions Group, Inc <ken at asteriasgi.com>
+ * Paul D. Tinsley <pdt at jackhammer.org>
+ * Bret McDanel <trixter AT 0xdecafbad.com>
+ *
+ *
+ * sofia_ref.c -- SOFIA SIP Endpoint (registration code)
+ *
+ */
 #include "mod_sofia.h"
 
 
-void sofia_reg_unregister(sofia_profile_t * profile)
+void sofia_reg_unregister(sofia_profile_t *profile)
 {
 	outbound_reg_t *gateway_ptr;
 	for (gateway_ptr = profile->gateways; gateway_ptr; gateway_ptr = gateway_ptr->next) {
@@ -14,7 +48,7 @@
 	}
 }
 
-void sofia_reg_check_gateway(sofia_profile_t * profile, time_t now)
+void sofia_reg_check_gateway(sofia_profile_t *profile, time_t now)
 {
 	outbound_reg_t *gateway_ptr;
 	for (gateway_ptr = profile->gateways; gateway_ptr; gateway_ptr = gateway_ptr->next) {
@@ -99,73 +133,74 @@
 	return 0;
 }
 
-void sofia_reg_check_expire(switch_core_db_t *db, sofia_profile_t * profile, time_t now)
+void sofia_reg_check_expire(sofia_profile_t *profile, time_t now)
 {
 	char sql[1024];
-	char *errmsg;
 
-	if (!db) {
+#ifdef SWITCH_HAVE_ODBC
+    if (profile->odbc_dsn) {
+     	if (!profile->master_odbc) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
+			return;
+		}   
+    } else {
+#endif
+	if (!profile->master_db) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
 		return;
 	}
+#ifdef SWITCH_HAVE_ODBC
+    }
+#endif
 
-	switch_mutex_lock(profile->ireg_mutex);
-	snprintf(sql, sizeof(sql), "select '%s',* from sip_registrations where expires > 0 and expires < %ld", profile->name, (long) now);
-	switch_core_db_exec(db, sql, sofia_reg_del_callback, NULL, &errmsg);
-
-	if (errmsg) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR [%s][%s]\n", sql, errmsg);
-		switch_safe_free(errmsg);
-		errmsg = NULL;
-	}
+	snprintf(sql, sizeof(sql), "select '%s',* from sip_registrations where expires > 0 and expires <= %ld", profile->name, (long) now);
 
-	snprintf(sql, sizeof(sql), "delete from sip_registrations where expires > 0 and expires < %ld", (long) now);
-	switch_core_db_persistant_execute(db, sql, 1000);
-	snprintf(sql, sizeof(sql), "delete from sip_authentication where expires > 0 and expires < %ld", (long) now);
-	switch_core_db_persistant_execute(db, sql, 1000);
-	snprintf(sql, sizeof(sql), "delete from sip_subscriptions where expires > 0 and expires < %ld", (long) now);
-	switch_core_db_persistant_execute(db, sql, 1000);
+	switch_mutex_lock(profile->ireg_mutex);
+	sofia_glue_execute_sql_callback(profile,
+									SWITCH_TRUE,
+									NULL,
+									sql,
+									sofia_reg_del_callback,
+									NULL);
+	
+	snprintf(sql, sizeof(sql), "delete from sip_registrations where expires > 0 and expires <= %ld", (long) now);
+	sofia_glue_execute_sql(profile, SWITCH_TRUE, sql, NULL);
+	snprintf(sql, sizeof(sql), "delete from sip_authentication where expires > 0 and expires <= %ld", (long) now);
+	sofia_glue_execute_sql(profile, SWITCH_TRUE, sql, NULL);
+	snprintf(sql, sizeof(sql), "delete from sip_subscriptions where expires > 0 and expires <= %ld", (long) now);
+	sofia_glue_execute_sql(profile, SWITCH_TRUE, sql, NULL);
 
 	switch_mutex_unlock(profile->ireg_mutex);
 
 }
 
-char *sofia_reg_find_reg_url(sofia_profile_t * profile, const char *user, const char *host, char *val, switch_size_t len)
+char *sofia_reg_find_reg_url(sofia_profile_t *profile, const char *user, const char *host, char *val, switch_size_t len)
 {
-	char *errmsg;
 	struct callback_t cbt = { 0 };
-	switch_core_db_t *db;
 
 	if (!user) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Called with null user!\n");
 		return NULL;
 	}
 
-	if (!(db = switch_core_db_open_file(profile->dbname))) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
-		return NULL;
-	}
-
 	cbt.val = val;
 	cbt.len = len;
-	switch_mutex_lock(profile->ireg_mutex);
+
 	if (host) {
 		snprintf(val, len, "select contact from sip_registrations where user='%s' and host='%s'", user, host);
 	} else {
 		snprintf(val, len, "select contact from sip_registrations where user='%s'", user);
 	}
 
-	switch_core_db_exec(db, val, sofia_reg_find_callback, &cbt, &errmsg);
 
-	if (errmsg) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR [%s][%s]\n", val, errmsg);
-		switch_safe_free(errmsg);
-		errmsg = NULL;
-	}
+	sofia_glue_execute_sql_callback(profile,
+									SWITCH_FALSE,
+									profile->ireg_mutex,
+									val,
+									sofia_reg_find_callback,
+									&cbt);
 
-	switch_mutex_unlock(profile->ireg_mutex);
 
-	switch_core_db_close(db);
 	if (cbt.matches) {
 		return val;
 	} else {
@@ -173,73 +208,20 @@
 	}
 }
 
-char *sofia_reg_get_auth_data(char *dbname, char *nonce, char *npassword, size_t len, switch_mutex_t * mutex)
+static char *sofia_reg_get_auth_data(sofia_profile_t *profile, char *nonce, char *npassword, size_t len, switch_mutex_t *mutex)
 {
-	switch_core_db_t *db;
-	switch_core_db_stmt_t *stmt;
-	char *sql = NULL, *ret = NULL;
-
-	if (mutex) {
-		switch_mutex_lock(mutex);
-	}
-
-	if (!dbname) {
-		goto end;
-	}
-
-	if (!(db = switch_core_db_open_file(dbname))) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", dbname);
-		goto end;
-	}
-
+	char *sql, *ret;
+	
 	sql = switch_mprintf("select passwd from sip_authentication where nonce='%q'", nonce);
-	if (switch_core_db_prepare(db, sql, -1, &stmt, 0)) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Statement Error!\n");
-		goto fail;
-	} else {
-		int running = 1;
-		int colcount;
+	assert(sql != NULL);
 
-		while (running < 5000) {
-			int result = switch_core_db_step(stmt);
-
-			if (result == SWITCH_CORE_DB_ROW) {
-				if ((colcount = switch_core_db_column_count(stmt))) {
-					switch_copy_string(npassword, (char *) switch_core_db_column_text(stmt, 0), len);
-					ret = npassword;
-				}
-				break;
-			} else if (result == SWITCH_CORE_DB_BUSY) {
-				running++;
-				switch_yield(1000);
-				continue;
-			}
-			break;
-		}
-
-		switch_core_db_finalize(stmt);
-	}
-
-
-  fail:
-
-	switch_core_db_close(db);
-
-  end:
-	if (mutex) {
-		switch_mutex_unlock(mutex);
-	}
-
-	if (sql) {
-		switch_safe_free(sql);
-	}
+	ret = sofia_glue_execute_sql2str(profile, mutex, sql, npassword, len);
 
+	free(sql);
 	return ret;
 }
 
-
-
-uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t * profile, nua_handle_t * nh, sip_t const *sip, sofia_regtype_t regtype, char *key,
+uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_handle_t * nh, sip_t const *sip, sofia_regtype_t regtype, char *key,
 							   uint32_t keylen)
 {
 	sip_from_t const *from = NULL;
@@ -399,9 +381,18 @@
 				a1_hash = hexdigest;
 			}
 
-			sql = switch_mprintf("delete from sip_authentication where user='%q' and host='%q';\n"
-								 "insert into sip_authentication values('%q','%q','%q','%q', %ld)",
-								 from_user, from_host, from_user, from_host, a1_hash, uuid_str, time(NULL) + profile->nonce_ttl);
+			switch_mutex_lock(profile->ireg_mutex);
+			sql = switch_mprintf("delete from sip_authentication where user='%q' and host='%q';", from_user, from_host);
+			assert(sql != NULL);
+			sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, NULL);
+			switch_safe_free(sql);
+			sql = switch_mprintf("insert into sip_authentication values('%q','%q','%q','%q', %ld)",
+								 from_user, from_host, a1_hash, uuid_str, time(NULL) + profile->nonce_ttl);
+			assert(sql != NULL);
+			sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, NULL);
+			switch_safe_free(sql);
+			switch_mutex_unlock(profile->ireg_mutex);
+
 			auth_str =
 				switch_mprintf("Digest realm=\"%q\", nonce=\"%q\",%s algorithm=MD5, qop=\"auth\"", from_host, uuid_str, stale ? " stale=\"true\"," : "");
 
@@ -414,8 +405,6 @@
 
 			}
 
-			sofia_glue_execute_sql(profile->dbname, sql, profile->ireg_mutex);
-			switch_safe_free(sql);
 			switch_safe_free(auth_str);
 			ret = 1;
 		} else {
@@ -454,7 +443,7 @@
 		}
 
 		if (sql) {
-			sofia_glue_execute_sql(profile->dbname, sql, profile->ireg_mutex);
+			sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, profile->ireg_mutex);
 			switch_safe_free(sql);
 			sql = NULL;
 		}
@@ -475,7 +464,7 @@
 		}
 	} else {
 		if ((sql = switch_mprintf("delete from sip_subscriptions where user='%q' and host='%q'", from_user, from_host))) {
-			sofia_glue_execute_sql(profile->dbname, sql, profile->ireg_mutex);
+			sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, profile->ireg_mutex);
 			switch_safe_free(sql);
 			sql = NULL;
 		}
@@ -508,7 +497,7 @@
 
 
 
-void sofia_reg_handle_sip_i_register(nua_t * nua, sofia_profile_t * profile, nua_handle_t * nh, sofia_private_t * sofia_private, sip_t const *sip, tagi_t tags[])
+void sofia_reg_handle_sip_i_register(nua_t * nua, sofia_profile_t *profile, nua_handle_t * nh, sofia_private_t * sofia_private, sip_t const *sip, tagi_t tags[])
 {
 	char key[128] = "";
 
@@ -530,7 +519,7 @@
 
 void sofia_reg_handle_sip_r_register(int status,
 						   char const *phrase,
-						   nua_t * nua, sofia_profile_t * profile, nua_handle_t * nh, sofia_private_t * sofia_private, sip_t const *sip, tagi_t tags[])
+						   nua_t * nua, sofia_profile_t *profile, nua_handle_t * nh, sofia_private_t * sofia_private, sip_t const *sip, tagi_t tags[])
 {
 	if (sofia_private && sofia_private->gateway) {
 		switch (status) {
@@ -560,7 +549,7 @@
 
 void sofia_reg_handle_sip_r_challenge(int status,
 							char const *phrase,
-							nua_t * nua, sofia_profile_t * profile, nua_handle_t * nh, switch_core_session_t *session, sip_t const *sip, tagi_t tags[])
+							nua_t * nua, sofia_profile_t *profile, nua_handle_t * nh, switch_core_session_t *session, sip_t const *sip, tagi_t tags[])
 {
 	outbound_reg_t *gateway = NULL;
 	sip_www_authenticate_t const *authenticate = NULL;
@@ -664,7 +653,7 @@
 
 }
 
-auth_res_t parse_auth(sofia_profile_t * profile, sip_authorization_t const *authorization, const char *regstr, char *np, size_t nplen)
+auth_res_t parse_auth(sofia_profile_t *profile, sip_authorization_t const *authorization, const char *regstr, char *np, size_t nplen)
 {
 	int indexnum;
 	const char *cur;
@@ -724,7 +713,7 @@
 	}
 
 	if (switch_strlen_zero(np)) {
-		if (!sofia_reg_get_auth_data(profile->dbname, nonce, np, nplen, profile->ireg_mutex)) {
+		if (!sofia_reg_get_auth_data(profile, nonce, np, nplen, profile->ireg_mutex)) {
 			ret = AUTH_STALE;
 			goto end;
 		}

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/Makefile.am
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/Makefile.am	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/event_handlers/mod_cdr/Makefile.am	Fri Apr  6 19:25:38 2007
@@ -14,13 +14,15 @@
 mod_LTLIBRARIES = mod_cdr.la
 mod_cdr_la_SOURCES = mod_cdr.cpp cdrcontainer.cpp basecdr.cpp baseregistry.cpp pddcdr.cpp csvcdr.cpp xmlcdr.cpp sqlitecdr.cpp
 mod_cdr_la_CFLAGS = $(AM_CFLAGS)
+mod_cdr_la_CPPFLAGS = $(AM_CPPFLAGS)
 mod_cdr_la_LIBADD=$(switch_builddir)/libfreeswitch.la
 mod_cdr_la_LDFLAGS=-module -avoid-version -no-undefined -export-symbols-regex ^switch_module_.*$ -rpath $(PREFIX)/$(libdir)
 
 #Build mysqlcdr if we have mysql client
 if HAVE_MYSQL
-mod_cdr_la_CFLAGS += -DMYSQL
-mod_cdr_la_LDFLAGS += -lmysql-client
+mod_cdr_la_CFLAGS += $(MYSQL_CFLAGS)
+mod_cdr_la_CPPFLAGS += $(MYSQL_CFLAGS)
+mod_cdr_la_LDFLAGS += $(MYSQL_LDFLAGS)
 mod_cdr_la_SOURCES += mysqlcdr.cpp
 endif
 

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c	Fri Apr  6 19:25:38 2007
@@ -128,6 +128,7 @@
 		if ((eo = malloc(sizeof(*eo)))) {
 
 			if (switch_name_event(ename, &etype) != SWITCH_STATUS_SUCCESS) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unknown event %s\n", ename);
 				*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 				return JS_TRUE;
 			}
@@ -146,7 +147,7 @@
 				}
 
 			} else {
-				if (!switch_event_create(&event, etype) != SWITCH_STATUS_SUCCESS) {
+				if (switch_event_create(&event, etype) != SWITCH_STATUS_SUCCESS) {
 					*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 					return JS_TRUE;
 				}
@@ -2650,7 +2651,7 @@
 
 	if ((arg = strchr(script, ' '))) {
 		*arg++ = '\0';
-		argc = switch_separate_string(arg, ':', argv, (sizeof(argv) / sizeof(argv[0])));
+		argc = switch_separate_string(arg, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
 	}
 
 	if (argc) {					/* create a js doppleganger of this argc/argv */
@@ -2662,7 +2663,6 @@
 		for (y = 0; y < argc; y++) {
 			snprintf(buf, sizeof(buf), "~argv[%d] = \"%s\";", x++, argv[y]);
 			eval_some_js(buf, cx, javascript_global_object, &rval);
-
 		}
 	}
 
@@ -2756,6 +2756,28 @@
 	/*.directory_interface */ NULL
 };
 
+static void  message_query_handler(switch_event_t *event)
+{
+	char *account = switch_event_get_header(event, "message-account");
+
+	if (account) {
+		char *path, *cmd;
+
+		path  = switch_mprintf("%s%smwi.js", SWITCH_GLOBAL_dirs.script_dir, SWITCH_PATH_SEPARATOR);
+		assert(path != NULL);
+
+		if (switch_file_exists(path) == SWITCH_STATUS_SUCCESS) {
+			cmd = switch_mprintf("%s %s", path, account);
+			assert(cmd != NULL);
+			js_thread_launch(cmd);
+			switch_safe_free(cmd);
+		}
+
+		switch_safe_free(path);
+	}
+
+}
+
 SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
 {
 	switch_status_t status;
@@ -2764,6 +2786,12 @@
 		return status;
 	}
 
+	if (switch_event_bind((char *) modname, SWITCH_EVENT_MESSAGE_QUERY, SWITCH_EVENT_SUBCLASS_ANY, message_query_handler, NULL)
+		!= SWITCH_STATUS_SUCCESS) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
+		return SWITCH_STATUS_GENERR;
+	}
+
 	/* connect my internal structure to the blank pointer passed to me */
 	*module_interface = &spidermonkey_module_interface;
 

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey_odbc/Makefile
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey_odbc/Makefile	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey_odbc/Makefile	Fri Apr  6 19:25:38 2007
@@ -1,28 +1,4 @@
 switch_srcdir=../../../..
 
-ODBC=unixODBC-2.2.12
-ODBC_DIR=$(switch_srcdir)/libs/$(ODBC)
-ODBCLA=libodbc.la
-
-UNINST_ODBCLA=$(ODBC_DIR)/DriverManager/$(ODBCLA)
-INST_ODBCLA=$(DESTDIR)$(PREFIX)/lib/$(ODBCLA)
-
-LOCAL_CFLAGS=-I$(ODBC_DIR)/include
-LOCAL_LDFLAGS=
-LOCAL_LIBADD=$(UNINST_ODBCLA)
-
 include ../mod_spidermonkey/sm.mak
 
-$(ODBC_DIR):
-	$(GETLIB) $(ODBC).tar.gz
-	cd $(ODBC_DIR) && ./configure --prefix=$(PREFIX) --disable-gui --without-x --with-pic 
-
-$(UNINST_ODBCLA): $(ODBC_DIR)
-	cd $(ODBC_DIR) && $(MAKE)
-	$(TOUCH_TARGET)
-
-depend_install: $(INST_ODBCLA)
-
-$(INST_ODBCLA): $(UNINST_ODBCLA)
-	cd $(ODBC_DIR) && $(MAKE) install
-	@$(TOUCH_TARGET)

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey_odbc/mod_spidermonkey_odbc.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey_odbc/mod_spidermonkey_odbc.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey_odbc/mod_spidermonkey_odbc.c	Fri Apr  6 19:25:38 2007
@@ -30,48 +30,19 @@
  *
  */
 #include "mod_spidermonkey.h"
-
-
-#include <sql.h>
-#ifdef _MSC_VER
-#pragma warning(push)
-#pragma warning(disable:4201)
-#include <sqlext.h>
-#pragma warning(pop)
-#else
-#include <sqlext.h>
-#endif
-#include <sqltypes.h>
+#include <switch_odbc.h>
 
 static const char modname[] = "ODBC";
 
 struct odbc_obj {
-	char *dsn;
-	char *username;
-	char *password;
-	SQLHENV env;
-	SQLHDBC con;
+	switch_odbc_handle_t *handle;
 	SQLHSTMT stmt;
-	uint32_t state;
 	SQLCHAR *colbuf;
 	int32 cblen;
 	SQLCHAR *code;
 	int32 codelen;
 };
-
-typedef enum {
-	ODBC_STATE_INIT,
-	ODBC_STATE_DOWN,
-	ODBC_STATE_CONNECTED,
-	ODBC_STATE_ERROR
-} odbc_state_t;
-typedef struct odbc_obj odbc_obj_t;
-
-typedef enum {
-	ODBC_SUCCESS = 0,
-	ODBC_FAIL = -1
-} odbc_status_t;
-
+typedef struct odbc_obj  odbc_obj_t;
 
 static odbc_obj_t *new_odbc_obj(char *dsn, char *username, char *password)
 {
@@ -81,122 +52,39 @@
 		goto err;
 	}
 
-	if (!(new_obj->dsn = strdup(dsn))) {
+	if (!(new_obj->handle = switch_odbc_handle_new(dsn, username, password))) {
 		goto err;
 	}
-
-	if (!(new_obj->username = strdup(username))) {
-		goto err;
-	}
-
-	if (!(new_obj->password = strdup(password))) {
-		goto err;
-	}
-
-	new_obj->env = SQL_NULL_HANDLE;
-	new_obj->state = ODBC_STATE_INIT;
-
+	
 	return new_obj;
 
   err:
 	if (new_obj) {
-		switch_safe_free(new_obj->dsn);
-		switch_safe_free(new_obj->username);
-		switch_safe_free(new_obj->password);
+		if (new_obj->handle) {
+			switch_odbc_handle_destroy(&new_obj->handle);
+		}
 		switch_safe_free(new_obj);
 	}
 
 	return NULL;
 }
 
-odbc_status_t odbc_obj_disconnect(odbc_obj_t * obj)
+switch_odbc_status_t odbc_obj_connect(odbc_obj_t *obj)
 {
-	int result;
-
-	if (obj->state == ODBC_STATE_CONNECTED) {
-		result = SQLDisconnect(obj->con);
-		if (result == ODBC_SUCCESS) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Disconnected %d from [%s]\n", result, obj->dsn);
-		} else {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Disconnectiong [%s]\n", obj->dsn);
-		}
-	} else {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "[%s] already disconnected\n", obj->dsn);
-	}
-
-	obj->state = ODBC_STATE_DOWN;
-
-	return ODBC_SUCCESS;
-}
-
-odbc_status_t odbc_obj_connect(odbc_obj_t * obj)
-{
-	int result;
-	SQLINTEGER err;
-	int16_t mlen;
-	unsigned char msg[200], stat[10];
-
-	if (obj->env == SQL_NULL_HANDLE) {
-		result = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &obj->env);
-
-		if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error AllocHandle\n");
-			return ODBC_FAIL;
-		}
-
-		result = SQLSetEnvAttr(obj->env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
-
-		if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error SetEnv\n");
-			SQLFreeHandle(SQL_HANDLE_ENV, obj->env);
-			return ODBC_FAIL;
-		}
-
-		result = SQLAllocHandle(SQL_HANDLE_DBC, obj->env, &obj->con);
-
-		if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error AllocHDB %d\n", result);
-			SQLFreeHandle(SQL_HANDLE_ENV, obj->env);
-			return ODBC_FAIL;
-		}
-		SQLSetConnectAttr(obj->con, SQL_LOGIN_TIMEOUT, (SQLPOINTER *) 10, 0);
-	}
-	if (obj->state == ODBC_STATE_CONNECTED) {
-		odbc_obj_disconnect(obj);
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Re-connecting %s\n", obj->dsn);
-	}
-
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connecting %s\n", obj->dsn);
-
-	result = SQLConnect(obj->con, (SQLCHAR *) obj->dsn, SQL_NTS, (SQLCHAR *) obj->username, SQL_NTS, (SQLCHAR *) obj->password, SQL_NTS);
-
-	if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
-		SQLGetDiagRec(SQL_HANDLE_DBC, obj->con, 1, stat, &err, msg, 100, &mlen);
-		SQLFreeHandle(SQL_HANDLE_ENV, obj->env);
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error SQLConnect=%d errno=%d %s\n", result, (int) err, msg);
-		return ODBC_FAIL;
-	} else {
-
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connected to [%s]\n", obj->dsn);
-		obj->state = ODBC_STATE_CONNECTED;
-	}
-
-	return ODBC_SUCCESS;
+	
+	return switch_odbc_handle_connect(obj->handle);
 }
 
 static void destroy_odbc_obj(odbc_obj_t ** objp)
 {
 	odbc_obj_t *obj = *objp;
 
-	odbc_obj_disconnect(obj);
-
-	SQLFreeHandle(SQL_HANDLE_STMT, obj->stmt);
-	SQLFreeHandle(SQL_HANDLE_DBC, obj->con);
-	SQLFreeHandle(SQL_HANDLE_ENV, obj->env);
-
-	switch_safe_free(obj->dsn);
-	switch_safe_free(obj->username);
-	switch_safe_free(obj->password);
+	if (obj->handle) {
+		switch_odbc_handle_destroy(&obj->handle);
+	}
+	if (obj->stmt) {
+		SQLFreeHandle(SQL_HANDLE_STMT, obj->stmt);
+	}
 	switch_safe_free(obj->colbuf);
 	switch_safe_free(obj->code);
 	switch_safe_free(obj);
@@ -205,7 +93,7 @@
 
 /* ODBC Object */
 /*********************************************************************************/
-static JSBool odbc_construct(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
+static JSBool odbc_construct(JSContext * cx, JSObject * obj, uintN argc, jsval *argv, jsval *rval)
 {
 	odbc_obj_t *odbc_obj = NULL;
 	char *dsn, *username, *password;
@@ -228,7 +116,15 @@
 		}
 	}
 
-	if (dsn && username && password) {
+	if (switch_strlen_zero(username)) {
+		username = NULL;
+	}
+
+	if (switch_strlen_zero(password)) {
+		password = NULL;
+	}
+
+	if (dsn) {
 		odbc_obj = new_odbc_obj(dsn, username, password);
 	}
 
@@ -266,13 +162,13 @@
 	}
 }
 
-static JSBool odbc_connect(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
+static JSBool odbc_connect(JSContext * cx, JSObject * obj, uintN argc, jsval *argv, jsval *rval)
 {
 	odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
 	JSBool tf = JS_TRUE;
 
 	if (odbc_obj) {
-		if (odbc_obj_connect(odbc_obj) == ODBC_SUCCESS) {
+		if (odbc_obj_connect(odbc_obj) == SWITCH_ODBC_SUCCESS) {
 			tf = JS_TRUE;
 		} else {
 			tf = JS_FALSE;
@@ -284,18 +180,18 @@
 	return JS_TRUE;
 }
 
-static JSBool odbc_exec(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
+static JSBool odbc_exec(JSContext * cx, JSObject * obj, uintN argc, jsval *argv, jsval *rval)
 {
 	odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
 	char *sql;
 	JSBool tf = JS_FALSE;
-	int result;
 
 	if (argc < 1) {
 		goto done;
 	}
 
-	if (odbc_obj->state != ODBC_STATE_CONNECTED) {
+	if (switch_odbc_handle_get_state(odbc_obj->handle) != SWITCH_ODBC_STATE_CONNECTED) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Database is not connected!\n");
 		goto done;
 	}
 
@@ -306,17 +202,8 @@
 
 	sql = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
 
-	if (SQLAllocHandle(SQL_HANDLE_STMT, odbc_obj->con, &odbc_obj->stmt) != SQL_SUCCESS) {
-		goto done;
-	}
-
-	if (SQLPrepare(odbc_obj->stmt, (unsigned char *) sql, SQL_NTS) != SQL_SUCCESS) {
-		goto done;
-	}
-
-	result = SQLExecute(odbc_obj->stmt);
 
-	if (result != SQL_SUCCESS && result != SQL_SUCCESS_WITH_INFO) {
+	if (switch_odbc_handle_exec(odbc_obj->handle, sql, &odbc_obj->stmt) != SWITCH_ODBC_SUCCESS) {
 		goto done;
 	}
 
@@ -329,13 +216,14 @@
 	return JS_TRUE;
 }
 
-static JSBool odbc_num_rows(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
+static JSBool odbc_num_rows(JSContext * cx, JSObject * obj, uintN argc, jsval *argv, jsval *rval)
 {
 	odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
 
 	SQLSMALLINT rows = 0;
 
-	if (odbc_obj->state != ODBC_STATE_CONNECTED) {
+	if (switch_odbc_handle_get_state(odbc_obj->handle) != SWITCH_ODBC_STATE_CONNECTED) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Database is not connected!\n");
 		goto done;
 	}
 
@@ -352,15 +240,17 @@
 }
 
 
-static JSBool odbc_next_row(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
+static JSBool odbc_next_row(JSContext * cx, JSObject * obj, uintN argc, jsval *argv, jsval *rval)
 {
 	odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
 	int result = 0;
 	JSBool tf = JS_FALSE;
 
-	if (odbc_obj->state != ODBC_STATE_CONNECTED) {
-		goto done;
-	}
+	if (switch_odbc_handle_get_state(odbc_obj->handle) != SWITCH_ODBC_STATE_CONNECTED) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Database is not connected!\n");
+        goto done;
+    }
+
 
 	if (odbc_obj->stmt) {
 		if ((result = SQLFetch(odbc_obj->stmt) == SQL_SUCCESS)) {
@@ -412,19 +302,20 @@
 }
 
 
-static JSBool odbc_get_data(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
+static JSBool odbc_get_data(JSContext * cx, JSObject * obj, uintN argc, jsval *argv, jsval *rval)
 {
 
 	odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
 	JSBool tf = JS_FALSE;
 
-	if (odbc_obj->state != ODBC_STATE_CONNECTED) {
-		goto done;
-	}
+	if (switch_odbc_handle_get_state(odbc_obj->handle) != SWITCH_ODBC_STATE_CONNECTED) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Database is not connected!\n");
+        goto done;
+    }
 
 	if (odbc_obj->stmt) {
 		SQLSMALLINT c = 0, x = 0;
-		int result;
+		SQLINTEGER m = 0;
 		char code[66560];
 
 		snprintf(code, sizeof(code), "~var _oDbC_dB_RoW_DaTa_ = {}");
@@ -433,15 +324,16 @@
 			return JS_TRUE;
 		}
 
-		result = SQLNumResultCols(odbc_obj->stmt, &c);
-		if (result == SQL_SUCCESS || result == SQL_SUCCESS_WITH_INFO) {
+		SQLNumResultCols(odbc_obj->stmt, &c);
+		SQLRowCount(odbc_obj->stmt, &m);
+		if (m > 0) {
 			for (x = 1; x <= c; x++) {
 				SQLSMALLINT NameLength, DataType, DecimalDigits, Nullable;
 				SQLUINTEGER ColumnSize;
 				SQLCHAR name[1024] = "";
 				SQLCHAR *data = odbc_obj->colbuf;
 				SQLCHAR *esc = NULL;
-
+				
 				SQLDescribeCol(odbc_obj->stmt, x, name, sizeof(name), &NameLength, &DataType, &ColumnSize, &DecimalDigits, &Nullable);
 				SQLGetData(odbc_obj->stmt, x, SQL_C_CHAR, odbc_obj->colbuf, odbc_obj->cblen, NULL);
 

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey_teletone/mod_spidermonkey_teletone.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey_teletone/mod_spidermonkey_teletone.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/languages/mod_spidermonkey_teletone/mod_spidermonkey_teletone.c	Fri Apr  6 19:25:38 2007
@@ -46,7 +46,6 @@
 	switch_core_session_t *session;
 	switch_codec_t codec;
 	switch_buffer_t *audio_buffer;
-	switch_buffer_t *loop_buffer;
 	switch_memory_pool_t *pool;
 	switch_timer_t *timer;
 	switch_timer_t timer_base;
@@ -158,7 +157,6 @@
 		}
 		teletone_destroy_session(&tto->ts);
 		switch_buffer_destroy(&tto->audio_buffer);
-		switch_buffer_destroy(&tto->loop_buffer);
 		switch_core_codec_destroy(&tto->codec);
 		pool = tto->pool;
 		tto->pool = NULL;
@@ -221,17 +219,12 @@
 				return JS_FALSE;
 			}
 			loops--;
-			if (!tto->loop_buffer) {
-				switch_buffer_create_dynamic(&tto->loop_buffer, JS_BLOCK_SIZE, JS_BUFFER_SIZE, 0);
-			}
 		}
 
 		if (tto->audio_buffer) {
 			switch_buffer_zero(tto->audio_buffer);
 		}
-		if (tto->loop_buffer) {
-			switch_buffer_zero(tto->loop_buffer);
-		}
+
 		tto->ts.debug = 1;
 		tto->ts.debug_stream = switch_core_get_console();
 
@@ -250,12 +243,16 @@
 			}
 		}
 
+		if (loops) {
+			switch_buffer_set_loops(tto->audio_buffer, loops);
+		}
+
 		for (;;) {
 
 			if (switch_test_flag(tto, TTF_DTMF)) {
 				char dtmf[128];
 				char *ret;
-
+				
 				if (switch_channel_has_dtmf(channel)) {
 					uintN aargc = 0;
 					jsval aargv[4];
@@ -284,23 +281,9 @@
 					break;
 				}
 			}
-			if ((write_frame.datalen = (uint32_t) switch_buffer_read(tto->audio_buffer, fdata, write_frame.codec->implementation->bytes_per_frame)) <= 0) {
-				if (loops) {
-					switch_buffer_t *tmp;
-
-					/* Switcharoo */
-					tmp = tto->audio_buffer;
-					tto->audio_buffer = tto->loop_buffer;
-					tto->loop_buffer = tmp;
-					loops--;
-					/* try again */
-					if ((write_frame.datalen =
-						 (uint32_t) switch_buffer_read(tto->audio_buffer, fdata, write_frame.codec->implementation->bytes_per_frame)) <= 0) {
-						break;
-					}
-				} else {
-					break;
-				}
+			if ((write_frame.datalen = (uint32_t) switch_buffer_read_loop(tto->audio_buffer,
+																		  fdata, write_frame.codec->implementation->bytes_per_frame)) <= 0) {
+				break;
 			}
 
 			write_frame.samples = write_frame.datalen / 2;
@@ -310,9 +293,6 @@
 					break;
 				}
 			}
-			if (tto->loop_buffer && loops) {
-				switch_buffer_write(tto->loop_buffer, write_frame.data, write_frame.datalen);
-			}
 		}
 
 		if (tto->timer) {

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/switch_buffer.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/switch_buffer.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/switch_buffer.c	Fri Apr  6 19:25:38 2007
@@ -48,6 +48,7 @@
 	switch_size_t blocksize;
 	uint32_t flags;
 	uint32_t id;
+	int32_t loops;
 };
 
 SWITCH_DECLARE(switch_status_t) switch_buffer_create(switch_memory_pool_t *pool, switch_buffer_t **buffer, switch_size_t max_len)
@@ -147,6 +148,26 @@
 	return buffer->used;
 }
 
+SWITCH_DECLARE(void) switch_buffer_set_loops(switch_buffer_t *buffer, int32_t loops)
+{
+	buffer->loops = loops;
+}
+
+SWITCH_DECLARE(switch_size_t) switch_buffer_read_loop(switch_buffer_t *buffer, void *data, switch_size_t datalen)
+{
+	switch_size_t len;
+	if ((len = switch_buffer_read(buffer, data, datalen)) == 0) {
+		if (buffer->loops == 0) {
+			return 0;
+		}
+		buffer->head = buffer->data;
+		buffer->used = buffer->actually_used;
+		len = switch_buffer_read(buffer, data, datalen);
+		buffer->loops--;
+	}
+	return len;
+}
+
 SWITCH_DECLARE(switch_size_t) switch_buffer_read(switch_buffer_t *buffer, void *data, switch_size_t datalen)
 {
 	switch_size_t reading = 0;

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/switch_event.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/switch_event.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/switch_event.c	Fri Apr  6 19:25:38 2007
@@ -126,6 +126,8 @@
 	"PRESENCE_IN",
 	"PRESENCE_OUT",
 	"PRESENCE_PROBE",
+	"MESSAGE_WAITING",
+	"MESSAGE_QUERY",
 	"ROSTER",
 	"CODEC",
 	"BACKGROUND_JOB",
@@ -313,7 +315,7 @@
 	assert(RUNTIME_POOL != NULL);
 
 	for (x = 0; x <= SWITCH_EVENT_ALL; x++) {
-		if (!strcasecmp(name, EVENT_NAMES[x])) {
+		if ((strlen(name) > 13 && !strcasecmp(name + 13, EVENT_NAMES[x])) || !strcasecmp(name, EVENT_NAMES[x])) {
 			*type = x;
 			return SWITCH_STATUS_SUCCESS;
 		}

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/switch_ivr_originate.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/switch_ivr_originate.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/switch_ivr_originate.c	Fri Apr  6 19:25:38 2007
@@ -210,7 +210,6 @@
 
 struct ringback {
 	switch_buffer_t *audio_buffer;
-	switch_buffer_t *loop_buffer;
 	teletone_generation_session_t ts;
 	switch_file_handle_t fhb;
 	switch_file_handle_t *fh;
@@ -623,7 +622,7 @@
 							char *tmp_data = NULL;
 
 							switch_buffer_create_dynamic(&ringback.audio_buffer, 512, 1024, 0);
-							switch_buffer_create_dynamic(&ringback.loop_buffer, 512, 1024, 0);
+							switch_buffer_set_loops(ringback.audio_buffer, -1);
 
 							if (*ringback_data == '/') {
 								char *ext;
@@ -665,7 +664,6 @@
 									switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Playing Tone\n");
 									teletone_destroy_session(&ringback.ts);
 									switch_buffer_destroy(&ringback.audio_buffer);
-									switch_buffer_destroy(&ringback.loop_buffer);
 									ringback_data = NULL;
 								}
 							}
@@ -747,27 +745,16 @@
 								break;
 							}
 						} else if (ringback.audio_buffer) {
-							if ((write_frame.datalen = (uint32_t) switch_buffer_read(ringback.audio_buffer,
-																					 write_frame.data,
-																					 write_frame.codec->implementation->bytes_per_frame)) <= 0) {
-								switch_buffer_t *tmp;
-								tmp = ringback.audio_buffer;
-								ringback.audio_buffer = ringback.loop_buffer;
-								ringback.loop_buffer = tmp;
-								if ((write_frame.datalen = (uint32_t) switch_buffer_read(ringback.audio_buffer,
-																						 write_frame.data,
-																						 write_frame.codec->implementation->bytes_per_frame)) <= 0) {
-									break;
-								}
+							if ((write_frame.datalen = (uint32_t) switch_buffer_read_loop(ringback.audio_buffer,
+																						  write_frame.data,
+																						  write_frame.codec->implementation->bytes_per_frame)) <= 0) {
+								break;
 							}
 						}
 
 						if (switch_core_session_write_frame(session, &write_frame, 1000, 0) != SWITCH_STATUS_SUCCESS) {
 							break;
 						}
-						if (ringback.loop_buffer) {
-							switch_buffer_write(ringback.loop_buffer, write_frame.data, write_frame.datalen);
-						}
 					}
 
 				} else {
@@ -908,7 +895,6 @@
 			} else if (ringback.audio_buffer) {
 				teletone_destroy_session(&ringback.ts);
 				switch_buffer_destroy(&ringback.audio_buffer);
-				switch_buffer_destroy(&ringback.loop_buffer);
 			}
 
 			for (i = 0; i < and_argc; i++) {

Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/switch_rtp.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/switch_rtp.c	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/switch_rtp.c	Fri Apr  6 19:25:38 2007
@@ -1307,6 +1307,7 @@
 			switch_core_timer_check(&rtp_session->timer);
 			rtp_session->last_write_samplecount = rtp_session->timer.samplecount;
 		}
+
 		switch_socket_sendto(rtp_session->sock, rtp_session->remote_addr, 0, (void *) send_msg, &bytes);
 	}
 
@@ -1410,7 +1411,6 @@
 SWITCH_DECLARE(int) switch_rtp_write_frame(switch_rtp_t *rtp_session, switch_frame_t *frame, uint32_t ts)
 {
 	uint8_t fwd = 0;
-	uint8_t packetize = 0;
 	void *data;
 	uint32_t len;
 	switch_payload_t payload;
@@ -1421,7 +1421,6 @@
 	}
 
 	fwd = (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_RAW_WRITE) && switch_test_flag(frame, SFF_RAW_RTP)) ? 1 : 0;
-	packetize = (rtp_session->samples_per_interval > frame->datalen && (frame->payload == rtp_session->payload)) ? 1 : 0;
 
 	if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_IO) || !rtp_session->remote_addr) {
 		return -1;
@@ -1435,7 +1434,7 @@
 		payload = rtp_session->payload;
 	}
 
-	if (fwd && !packetize) {
+	if (fwd) {
 		data = frame->packet;
 		len = frame->packetlen;
 	} else {

Modified: freeswitch/branches/mikej/sofiasip-upgrade/w32/Library/FreeSwitchCore.vcproj
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/w32/Library/FreeSwitchCore.vcproj	(original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/w32/Library/FreeSwitchCore.vcproj	Fri Apr  6 19:25:38 2007
@@ -352,6 +352,10 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\src\switch_odbc.c"
+				>
+			</File>
+			<File
 				RelativePath="..\..\src\switch_regex.c"
 				>
 			</File>
@@ -418,11 +422,11 @@
 				>
 			</File>
 			<File
-				RelativePath="..\..\src\include\switch_core.h"
+				RelativePath="..\..\src\include\private\switch_core.h"
 				>
 			</File>
 			<File
-				RelativePath="..\..\src\include\private\switch_core.h"
+				RelativePath="..\..\src\include\switch_core.h"
 				>
 			</File>
 			<File
@@ -458,6 +462,10 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\src\include\switch_odbc.h"
+				>
+			</File>
+			<File
 				RelativePath="..\..\src\include\switch_platform.h"
 				>
 			</File>



More information about the Freeswitch-svn mailing list