[Freeswitch-svn] [commit] r6674 - in freeswitch/branches/stkn/sofia-exp/trunk: conf/autoload_configs conf/dialplan conf/directory/default conf/sip_profiles scripts src src/include src/mod/applications/mod_conference src/mod/applications/mod_enum src/mod/applications/mod_esf src/mod/endpoints/mod_dingaling src/mod/endpoints/mod_sofia

Freeswitch SVN stkn at freeswitch.org
Tue Dec 11 16:35:05 EST 2007


Author: stkn
Date: Tue Dec 11 16:35:05 2007
New Revision: 6674

Added:
   freeswitch/branches/stkn/sofia-exp/trunk/conf/directory/default/voipuser.org.noload
      - copied unchanged from r6673, /freeswitch/trunk/conf/directory/default/voipuser.org.noload
Modified:
   freeswitch/branches/stkn/sofia-exp/trunk/conf/autoload_configs/conference.conf.xml
   freeswitch/branches/stkn/sofia-exp/trunk/conf/autoload_configs/console.conf.xml
   freeswitch/branches/stkn/sofia-exp/trunk/conf/autoload_configs/local_stream.conf.xml
   freeswitch/branches/stkn/sofia-exp/trunk/conf/dialplan/default.xml
   freeswitch/branches/stkn/sofia-exp/trunk/conf/dialplan/public.xml
   freeswitch/branches/stkn/sofia-exp/trunk/conf/sip_profiles/default.xml
   freeswitch/branches/stkn/sofia-exp/trunk/conf/sip_profiles/nat.xml
   freeswitch/branches/stkn/sofia-exp/trunk/conf/sip_profiles/outbound.xml
   freeswitch/branches/stkn/sofia-exp/trunk/scripts/sipsetup
   freeswitch/branches/stkn/sofia-exp/trunk/src/include/switch_console.h
   freeswitch/branches/stkn/sofia-exp/trunk/src/include/switch_core.h
   freeswitch/branches/stkn/sofia-exp/trunk/src/include/switch_platform.h
   freeswitch/branches/stkn/sofia-exp/trunk/src/include/switch_rtp.h
   freeswitch/branches/stkn/sofia-exp/trunk/src/include/switch_types.h
   freeswitch/branches/stkn/sofia-exp/trunk/src/include/switch_utils.h
   freeswitch/branches/stkn/sofia-exp/trunk/src/mod/applications/mod_conference/mod_conference.c
   freeswitch/branches/stkn/sofia-exp/trunk/src/mod/applications/mod_enum/mod_enum.c
   freeswitch/branches/stkn/sofia-exp/trunk/src/mod/applications/mod_esf/mod_esf.c
   freeswitch/branches/stkn/sofia-exp/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c
   freeswitch/branches/stkn/sofia-exp/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c
   freeswitch/branches/stkn/sofia-exp/trunk/src/switch_buffer.c
   freeswitch/branches/stkn/sofia-exp/trunk/src/switch_caller.c
   freeswitch/branches/stkn/sofia-exp/trunk/src/switch_channel.c
   freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core.c
   freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_asr.c
   freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_codec.c
   freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_file.c
   freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_hash.c
   freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_io.c
   freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_memory.c
   freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_port_allocator.c
   freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_session.c
   freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_speech.c
   freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_sqldb.c
   freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_state_machine.c
   freeswitch/branches/stkn/sofia-exp/trunk/src/switch_event.c
   freeswitch/branches/stkn/sofia-exp/trunk/src/switch_ivr.c
   freeswitch/branches/stkn/sofia-exp/trunk/src/switch_ivr_async.c
   freeswitch/branches/stkn/sofia-exp/trunk/src/switch_ivr_bridge.c
   freeswitch/branches/stkn/sofia-exp/trunk/src/switch_ivr_originate.c
   freeswitch/branches/stkn/sofia-exp/trunk/src/switch_ivr_play_say.c
   freeswitch/branches/stkn/sofia-exp/trunk/src/switch_loadable_module.c
   freeswitch/branches/stkn/sofia-exp/trunk/src/switch_log.c
   freeswitch/branches/stkn/sofia-exp/trunk/src/switch_odbc.c
   freeswitch/branches/stkn/sofia-exp/trunk/src/switch_rtp.c
   freeswitch/branches/stkn/sofia-exp/trunk/src/switch_scheduler.c
   freeswitch/branches/stkn/sofia-exp/trunk/src/switch_utils.c

Log:
Merge changes from trunk

Modified: freeswitch/branches/stkn/sofia-exp/trunk/conf/autoload_configs/conference.conf.xml
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/conf/autoload_configs/conference.conf.xml	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/conf/autoload_configs/conference.conf.xml	Tue Dec 11 16:35:05 2007
@@ -1,3 +1,4 @@
+<!-- http://wiki.freeswitch.org/wiki/Mod_conference --> 
 <!-- None of these paths are real if you want any of these options you need to really set them up -->
 <configuration name="conference.conf" description="Audio Conference">
   <!-- Advertise certain presence on startup . -->

Modified: freeswitch/branches/stkn/sofia-exp/trunk/conf/autoload_configs/console.conf.xml
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/conf/autoload_configs/console.conf.xml	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/conf/autoload_configs/console.conf.xml	Tue Dec 11 16:35:05 2007
@@ -6,7 +6,7 @@
 	 name can be a file name, function name or 'all' 
 	 value is one or more of debug,info,notice,warning,err,crit,alert,all
     -->
-    <map name="all" value="debug,info,notice,warning,err,crit,alert"/>
+    <map name="all" value="info,notice,warning,err,crit,alert"/>
   </mappings>
   <settings>
     <!-- comment or set to false for no color logging -->

Modified: freeswitch/branches/stkn/sofia-exp/trunk/conf/autoload_configs/local_stream.conf.xml
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/conf/autoload_configs/local_stream.conf.xml	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/conf/autoload_configs/local_stream.conf.xml	Tue Dec 11 16:35:05 2007
@@ -1,5 +1,5 @@
 <configuration name="local_stream.conf" description="stream files from local dir">
-<directory name="foo" path="/path/to/moh/files">
+<directory name="demo_moh" path="$${base_dir}/sounds/moh">
   <param name="rate" value="8000"/>
   <param name="channels" value="1"/>
   <param name="interval" value="2"/>

Modified: freeswitch/branches/stkn/sofia-exp/trunk/conf/dialplan/default.xml
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/conf/dialplan/default.xml	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/conf/dialplan/default.xml	Tue Dec 11 16:35:05 2007
@@ -1,3 +1,4 @@
+<!-- http://wiki.freeswitch.org/wiki/Dialplan_XML --> 
 <include>
   <context name="default">
     <extension name="intercept">

Modified: freeswitch/branches/stkn/sofia-exp/trunk/conf/dialplan/public.xml
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/conf/dialplan/public.xml	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/conf/dialplan/public.xml	Tue Dec 11 16:35:05 2007
@@ -1,3 +1,4 @@
+<!-- http://wiki.freeswitch.org/wiki/Dialplan_XML -->
 <include>
   <context name="public">
 

Modified: freeswitch/branches/stkn/sofia-exp/trunk/conf/sip_profiles/default.xml
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/conf/sip_profiles/default.xml	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/conf/sip_profiles/default.xml	Tue Dec 11 16:35:05 2007
@@ -1,3 +1,4 @@
+<!-- http://wiki.freeswitch.org/wiki/Sofia_Configuration_Files -->
 <profile name="default">
   <!--aliases are other names that will work as a valid profile name for this profile-->
   <aliases>
@@ -14,7 +15,7 @@
   </domains>
   
   <settings>
-    <param name="debug" value="1"/>
+    <param name="debug" value="0"/>
     <param name="context" value="public"/>
     <param name="rfc2833-pt" value="101"/>
     <param name="sip-port" value="5060"/>
@@ -25,6 +26,7 @@
     <param name="rtp-timer-name" value="soft"/>
     <param name="rtp-ip" value="$${local_ip_v4}"/>
     <param name="sip-ip" value="$${local_ip_v4}"/>
+    <param name="hold-music" value="local_stream://demo_moh"/>
     <!--enable to use presense and mwi -->
     <param name="manage-presence" value="true"/>
     <!--max number of open dialogs in proceeding -->

Modified: freeswitch/branches/stkn/sofia-exp/trunk/conf/sip_profiles/nat.xml
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/conf/sip_profiles/nat.xml	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/conf/sip_profiles/nat.xml	Tue Dec 11 16:35:05 2007
@@ -1,10 +1,11 @@
+<!-- http://wiki.freeswitch.org/wiki/Sofia_Configuration_Files -->
 <profile name="nat">
   <gateways>
     <X-PRE-PROCESS cmd="include" data="nat/*.xml"/>
   </gateways>
 
   <settings>
-    <param name="debug" value="1"/>
+    <param name="debug" value="0"/>
     <param name="rfc2833-pt" value="101"/>
     <param name="sip-port" value="5070"/>
     <param name="dialplan" value="XML"/>
@@ -12,6 +13,7 @@
     <param name="dtmf-duration" value="100"/>
     <param name="codec-prefs" value="$${global_codec_prefs}"/>
     <param name="use-rtp-timer" value="true"/>
+    <param name="hold-music" value="local_stream://demo_moh"/>
     <param name="rtp-timer-name" value="soft"/>
     <param name="manage-presence" value="true"/>
     <param name="inbound-codec-negotiation" value="generous"/>

Modified: freeswitch/branches/stkn/sofia-exp/trunk/conf/sip_profiles/outbound.xml
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/conf/sip_profiles/outbound.xml	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/conf/sip_profiles/outbound.xml	Tue Dec 11 16:35:05 2007
@@ -1,3 +1,4 @@
+<!-- http://wiki.freeswitch.org/wiki/Sofia_Configuration_Files --> 
 <profile name="outbound">
   <!-- This profile is only for outbound registrations to providers -->
   <gateways>
@@ -9,13 +10,14 @@
   </domains>
 
   <settings>
-    <param name="debug" value="1"/>
+    <param name="debug" value="0"/>
     <param name="rfc2833-pt" value="101"/>
     <param name="sip-port" value="5080"/>
     <param name="dialplan" value="XML"/>
     <param name="context" value="public"/>
     <param name="dtmf-duration" value="100"/>
     <param name="codec-prefs" value="$${global_codec_prefs}"/>
+    <param name="hold-music" value="local_stream://demo_moh"/>
     <param name="use-rtp-timer" value="true"/>
     <param name="rtp-timer-name" value="soft"/>
     <param name="manage-presence" value="true"/>

Modified: freeswitch/branches/stkn/sofia-exp/trunk/scripts/sipsetup
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/scripts/sipsetup	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/scripts/sipsetup	Tue Dec 11 16:35:05 2007
@@ -12,159 +12,169 @@
 my $PREFIX = "/usr/local/freeswitch";
 
 my $providers = {
-		 "1" => "FWD",
-		 "2" => "SP",
-		 "3" => "IS",
-		 "4" => "AL",
-		 "5" => "SB"
-		};
+    "1" => "FWD",
+    "2" => "SP",
+    "3" => "IS",
+    "4" => "AL",
+    "5" => "SB",
+    "6" => "VU"
+    };
 
 
 my $FWD = {
-	   "type" => "network",
-	   "register" => "true",
-	   "fields" => [number, password, extension],
-	   "domain" => "pulver.com",
-	   "dialprefix" => "1-393"
-	  };
-
-my $SP = {
-	  "type" => "network",
-	  "register" => "true",
-	  "fields" => [username, password, extension],
-	  "domain" => "sipphone.com",
-	  "dialprefix" => "1-747, 1-222"
-	 };
-
-my $IS = {
-	  "type" => "network",
-	  "register" => "true",
-	  "fields" => [username, password, extension],
-	  "domain" => "ideasip.com",
-	  "dialprefix" => "1-101"
-	 };
-
-my $AL = {
-	  "type" => "pstn",
-	  "register" => "true",
-	  "fields" => [username, password, extension],
-	  "domain" => "asterlink.com",
-	 };
-
-my $SB = {
-	  "type" => "peer",
-	  "domain" => "sipbroker.com",
-	  "dialprefix" => "*XXX"
-	 };
+    "type" => "network",
+    "register" => "true",
+    "fields" => [number, password, extension],
+    "domain" => "pulver.com",
+    "dialprefix" => "1-393"
+    };
+
+my $SIPHONE = {
+    "type" => "network",
+    "register" => "true",
+    "fields" => [username, password, extension],
+    "domain" => "sipphone.com",
+    "dialprefix" => "1-747, 1-222"
+    };
+
+my $IDEASIP = {
+    "type" => "network",
+    "register" => "true",
+    "fields" => [username, password, extension],
+    "domain" => "ideasip.com",
+    "dialprefix" => "1-101"
+    };
+
+my $VOIPUSER = {
+    "type" => "network",
+    "register" => "true",
+    "fields" => [username, password, extension],
+    "domain" => "voipuser.org"
+    };
+
+my $ASTERLINK = {
+    "type" => "pstn",
+    "register" => "true",
+    "fields" => [username, password, extension],
+    "domain" => "asterlink.com",
+};
+
+my $SIPBROKER = {
+    "type" => "peer",
+    "domain" => "sipbroker.com",
+    "dialprefix" => "*XXX"
+    };
 
 my $TEMPLATES = {
-		 "FWD" => $FWD,
-		 "SP" => $SP,
-		 "IS" => $IS,
-		 "AL" => $AL,
-		 "SB" => $SB
-		};
+    "FWD" => $FWD,
+    "SP" => $SIPPHONE,
+    "IS" => $IDEASIP,
+    "AL" => $ASTERLINK,
+    "SB" => $SIPBROKER,
+    "VU" => $VOIPUSER
+    };
 
 print "\n" x 60;
 &welcome;
 
 sub welcome {
-  print <<WELCOME
+    print <<WELCOME
 
-  Welcome to the FreeSWITCH setup assistant.
+	Welcome to the FreeSWITCH setup assistant.
 
-  1. Configure Free World Dialup
-  2. Configure SIPPhone.com
-  3. Configure ideaSIP.com
-  4. Configure Asterlink.com
-  5. Configure SIPBroker.com
+	1. Configure Free World Dialup
+	2. Configure SIPPhone.com
+	3. Configure ideaSIP.com
+	4. Configure Asterlink.com
+	5. Configure SIPBroker.com
+	6. Configure voipuser.org
 
-  X. Exit
+	X. Exit
 
 WELCOME
-    ;
-  print "Which provider do you wish to setup? ";
-  my $i = <STDIN>;
-  chomp($i);
-  if ($i =~ m/X|x/) {
-    print "Thanks you!\n"; exit;
-  } elsif ($i > 5) {
-    print "Invalid Choice\n"; &welcome;
-  } else {
-    if (exists($providers->{$i})) {
-      configure_sip_provider($providers->{$i});
-    }
-  };
-  &welcome;
+;
+    print "Which provider do you wish to setup? ";
+    my $i = <STDIN>;
+    chomp($i);
+    if ($i =~ m/X|x/) {
+	print "Thanks you!\n"; exit;
+    } elsif ($i > 6) {
+	print "Invalid Choice\n"; &welcome;
+    } else {
+	if (exists($providers->{$i})) {
+	    configure_sip_provider($providers->{$i});
+	}
+    };
+    &welcome;
 }
 
 sub configure_sip_provider($) {
-  my $provider = shift;
-  my $template = $TEMPLATES->{$provider};
-  my $config;
-  my $check = 1;
-  foreach $field (@{$template->{fields}}) {
-    print "\nPlease your $template->{domain} $field: ";
-    $tmp = "$provider" . uc($field);
-    $i = <STDIN>;
-    chomp($i);
-    $config->{$tmp} = $i;
-  }
+    my $provider = shift;
+    my $template = $TEMPLATES->{$provider};
+    my $config;
+    my $check = 1;
+    foreach $field (@{$template->{fields}}) {
+	print "\nPlease your $template->{domain} $field: ";
+	$tmp = "$provider" . uc($field);
+	$i = <STDIN>;
+	chomp($i);
+	$config->{$tmp} = $i;
+    }
 
-  while($check) {
-    $check = &are_you_sure;
-  };
-
-  if ($template->{type} eq "network") {
-    do_config($provider, $config);
-  }
-  if ($template->{dialprefix}) {
-    enable_extension($provider, $config);
-  }
-  print "\n\n\nConfiguration Complete!!!\n\n\n\n\n";
-  sleep(2);
-  &welcome;
+    while($check) {
+	$check = &are_you_sure;
+    };
+
+    if ($template->{type} eq "network" || $template->{type} eq "pstn") {
+	do_config($provider, $config);
+    }
+    if ($template->{dialprefix}) {
+	enable_extension($provider, $config);
+    }
+    print "\n\n\nConfiguration Complete!!!\n\n\n\n\n";
+    sleep(2);
+    &welcome;
 }
 
 sub enable_extension($$) {
-  my $provider = shift;
-  my $config = shift;
+    my $provider = shift;
+    my $config = shift;
 
-  my $todo = $TEMPLATES->{$provider};
+    my $todo = $TEMPLATES->{$provider};
 
-  copy("$PREFIX/conf/dialplan/extensions/$todo->{domain}.noload", "$PREFIX/conf/dialplan/extensions/$todo->{domain}.xml");
-  print "\nExtension prefix $todo->{dialprefix} enabled for dialing $todo->{domain}...\n";
+    copy("$PREFIX/conf/dialplan/extensions/$todo->{domain}.noload", "$PREFIX/conf/dialplan/extensions/$todo->{domain}.xml");
+    print "\nExtension prefix $todo->{dialprefix} enabled for dialing $todo->{domain}...\n";
 }
 
 sub do_config($$) {
-  my $provider = shift;
-  my $config = shift;
-  my $todo = $TEMPLATES->{$provider};
-
-  open(TEMPLATE, "<$PREFIX/conf/directory/default/$todo->{domain}.noload");
-  @lines = <TEMPLATE>;
-  close(TEMPLATE);
-  open(CONFIG, ">$PREFIX/conf/directory/default/$todo->{domain}.xml");
-  foreach $line (@lines) {
-    foreach $key (sort keys %{$config}) {
-      $line =~ s/%$key%/$config->{$key}/g;
+    my $provider = shift;
+    my $config = shift;
+    my $todo = $TEMPLATES->{$provider};
+
+    open(TEMPLATE, "<$PREFIX/conf/directory/default/$todo->{domain}.noload");
+    @lines = <TEMPLATE>;
+    close(TEMPLATE);
+    open(CONFIG, ">$PREFIX/conf/directory/default/$todo->{domain}.xml");
+    foreach $line (@lines) {
+	foreach $key (sort keys %{$config}) {
+	    $line =~ s/%$key%/$config->{$key}/g;
+	}
+	print CONFIG $line;
     }
-    print CONFIG $line;
-  }
-  close(CONFIG);
-  print "Config Created...\n";
+    close(CONFIG);
+    print "Config Created...\n";
 }
 
 sub are_you_sure {
-  my $sure = 1;
-  while($sure) {
-    print "Are you sure? (yes/no)";
-    $i = <STDIN>;
-    chomp($i);
-    if($i =~ m/No|no|NO|n/) {
-      &welcome;
-    } elsif ($i =~ m/Yes|yes|YES|y/) {
-      return 0;
+    my $sure = 1;
+    while($sure) {
+	print "Are you sure? (yes/no)";
+	$i = <STDIN>;
+	chomp($i);
+	if($i =~ m/No|no|NO|n/) {
+	    &welcome;
+	} elsif ($i =~ m/Yes|yes|YES|y/) {
+	    return 0;
+	}
     }
-  }
 }

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/include/switch_console.h
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/include/switch_console.h	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/include/switch_console.h	Tue Dec 11 16:35:05 2007
@@ -44,7 +44,7 @@
 SWITCH_BEGIN_EXTERN_C
 #define SWITCH_CMD_CHUNK_LEN 1024
 #define SWITCH_STANDARD_STREAM(s) memset(&s, 0, sizeof(s)); s.data = malloc(SWITCH_CMD_CHUNK_LEN); \
-	assert(s.data);														\
+	switch_assert(s.data);												\
 	memset(s.data, 0, SWITCH_CMD_CHUNK_LEN);							\
 	s.end = s.data;														\
 	s.data_size = SWITCH_CMD_CHUNK_LEN;									\

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/include/switch_core.h
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/include/switch_core.h	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/include/switch_core.h	Tue Dec 11 16:35:05 2007
@@ -216,14 +216,16 @@
   \return SWITCH_STATUS_SUCCESS if the operation was a success
 */
 SWITCH_DECLARE(switch_status_t) switch_core_port_allocator_new(switch_port_t start,
-															   switch_port_t end, uint8_t inc, switch_core_port_allocator_t **new_allocator);
+															   switch_port_t end, switch_port_flag_t flags, switch_core_port_allocator_t **new_allocator);
 
 /*!
   \brief Get a port from the port allocator
   \param alloc the allocator object
-  \return the port
+  \param port a pointer to the port
+  \return SUCCESS
 */
-SWITCH_DECLARE(switch_port_t) switch_core_port_allocator_request_port(switch_core_port_allocator_t *alloc);
+SWITCH_DECLARE(switch_status_t) switch_core_port_allocator_request_port(switch_core_port_allocator_t *alloc, switch_port_t *port_ptr);
+SWITCH_DECLARE(switch_status_t) switch_core_port_allocator_free_port(switch_core_port_allocator_t *alloc, switch_port_t port);
 
 /*!
   \brief destroythe port allocator

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/include/switch_platform.h
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/include/switch_platform.h	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/include/switch_platform.h	Tue Dec 11 16:35:05 2007
@@ -69,6 +69,10 @@
 #pragma include_alias(<libteletone_generate.h>,		<../../libs/libteletone/src/libteletone_generate.h>)
 #pragma include_alias(<libteletone_detect.h>,		<../../libs/libteletone/src/libteletone_detect.h>)
 
+#if (_MSC_VER >= 1500)			// VC9+
+#define switch_assert(expr) assert(expr);__analysis_assume( expr )
+#endif
+
 #if (_MSC_VER >= 1400)			// VC8+
 #ifndef _CRT_SECURE_NO_DEPRECATE
 #define _CRT_SECURE_NO_DEPRECATE
@@ -285,6 +289,9 @@
 #ifndef TRUE
 #define TRUE (!FALSE)
 #endif
+#ifndef switch_assert
+#define switch_assert(expr) assert(expr)
+#endif
 /* For Emacs:
  * Local Variables:
  * mode:c

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/include/switch_rtp.h
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/include/switch_rtp.h	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/include/switch_rtp.h	Tue Dec 11 16:35:05 2007
@@ -53,6 +53,7 @@
   \note Generally called by the core_init
 */
 SWITCH_DECLARE(void) switch_rtp_init(switch_memory_pool_t *pool);
+SWITCH_DECLARE(void) switch_rtp_shutdown(void);
 
 /*!
   \brief Set/Get RTP start port
@@ -70,9 +71,10 @@
 
 /*! 
   \brief Request a new port to be used for media
+  \param ip the ip to request a port from
   \return the new port to use
 */
-SWITCH_DECLARE(switch_port_t) switch_rtp_request_port(void);
+SWITCH_DECLARE(switch_port_t) switch_rtp_request_port(const char *ip);
 
 /*! 
   \brief create a new RTP session handle

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/include/switch_types.h
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/include/switch_types.h	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/include/switch_types.h	Tue Dec 11 16:35:05 2007
@@ -137,6 +137,12 @@
 typedef uint8_t switch_byte_t;
 
 typedef enum {
+	SPF_NONE = 0,
+	SPF_ODD = (1 << 0),
+	SPF_EVEN = (1 << 1)
+} switch_port_flag_t;
+
+typedef enum {
 	ED_MUX_READ = (1 << 0),
 	ED_MUX_WRITE = (1 << 1),
 	ED_DTMF = (1 << 2)

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/include/switch_utils.h
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/include/switch_utils.h	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/include/switch_utils.h	Tue Dec 11 16:35:05 2007
@@ -352,9 +352,14 @@
 #define switch_malloc(ptr, len) (void)( (!!(ptr = malloc(len))) || (fprintf(stderr,"ABORT! Malloc failure at: %s:%s", __FILE__, __LINE__),abort(), 0), ptr )
 #define switch_zmalloc(ptr, len) (void)( (!!(ptr = malloc(len))) || (fprintf(stderr,"ABORT! Malloc failure at: %s:%s", __FILE__, __LINE__),abort(), 0), memset(ptr, 0, len))
 #else
+#if (_MSC_VER >= 1500)			// VC9+
+#define switch_malloc(ptr, len) (void)(assert(((ptr) = malloc((len)))),ptr);__analysis_assume( ptr )
+#define switch_zmalloc(ptr, len) (void)(assert((ptr = malloc(len))),memset(ptr, 0, len));__analysis_assume( ptr )
+#else
 #define switch_malloc(ptr, len) (void)(assert(((ptr) = malloc((len)))),ptr)
 #define switch_zmalloc(ptr, len) (void)(assert((ptr = malloc(len))),memset(ptr, 0, len))
 #endif
+#endif
 
 SWITCH_END_EXTERN_C
 #endif

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/mod/applications/mod_conference/mod_conference.c
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/mod/applications/mod_conference/mod_conference.c	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/mod/applications/mod_conference/mod_conference.c	Tue Dec 11 16:35:05 2007
@@ -422,8 +422,8 @@
 {
 	conference_member_t *member = NULL;
 
-	assert(conference != NULL);
-	assert(id != 0);
+	switch_assert(conference != NULL); 
+	switch_assert(id != 0);
 
 	switch_mutex_lock(conference->member_mutex);
 	for (member = conference->members; member; member = member->next) {
@@ -452,7 +452,7 @@
 	conference_member_t *member = NULL;
 	int count = 0;
 
-	assert(conference != NULL);
+	switch_assert(conference != NULL);
 	switch_mutex_lock(conference->member_mutex);
 	for (member = conference->members; member; member = member->next) {
 		if (switch_test_flag(member, MFLAG_NOCHANNEL) && (!path || !strcmp(path, member->rec_path))) {
@@ -517,8 +517,8 @@
 	call_list_t *call_list = NULL;
 	switch_channel_t *channel;
 
-	assert(conference != NULL);
-	assert(member != NULL);
+	switch_assert(conference != NULL);
+	switch_assert(member != NULL);
 
 	switch_mutex_lock(conference->mutex);
 	switch_mutex_lock(member->audio_in_mutex);
@@ -559,9 +559,9 @@
 		call_list = (call_list_t *) switch_channel_get_private(channel, "_conference_autocall_list_");
 			
 		if (call_list) {
-			char msg[1024];
-			snprintf(msg, sizeof(msg), "Auto Calling %d parties", call_list->itteration);
-			conference_member_say(member, msg, 0);
+			char saymsg[1024];
+			snprintf(saymsg, sizeof(saymsg), "Auto Calling %d parties", call_list->itteration);
+			conference_member_say(member, saymsg, 0);
 		} else {
 			if (switch_strlen_zero(conference->special_announce)) {
 				/* anounce the total number of members in the conference */
@@ -609,8 +609,8 @@
 	conference_member_t *imember, *last = NULL;
 	switch_event_t *event;
 
-	assert(conference != NULL);
-	assert(member != NULL);
+	switch_assert(conference != NULL);
+	switch_assert(member != NULL);
 
 	switch_mutex_lock(conference->mutex);
 	switch_mutex_lock(conference->member_mutex);
@@ -716,8 +716,8 @@
 	uint8_t *file_frame;
 	uint8_t *async_file_frame;
 
-	file_frame = switch_core_alloc(conference->pool, CONF_BUFFER_SIZE);
-	async_file_frame = switch_core_alloc(conference->pool, CONF_BUFFER_SIZE);
+	file_frame = switch_core_alloc(conference->pool, SWITCH_RECOMMENDED_BUFFER_SIZE);
+	async_file_frame = switch_core_alloc(conference->pool, SWITCH_RECOMMENDED_BUFFER_SIZE);
 
 
 	if (switch_core_timer_init(&timer, conference->timer_name, conference->interval, samples, conference->pool) == SWITCH_STATUS_SUCCESS) {
@@ -1335,13 +1335,13 @@
 	uint32_t hangover = 40, hangunder = 15, hangover_hits = 0, hangunder_hits = 0, energy_level = 0, diff_level = 400;
 	uint8_t talking = 0;
 
-	assert(member != NULL);
+	switch_assert(member != NULL);
 
 	channel = switch_core_session_get_channel(member->session);
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	read_codec = switch_core_session_get_read_codec(member->session);
-	assert(read_codec != NULL);
+	switch_assert(read_codec != NULL);
 
 	/* As long as we have a valid read, feed that data into an input buffer where the conference thread will take it 
 	   and mux it with any audio from other channels. */
@@ -1521,8 +1521,8 @@
 
 	channel = switch_core_session_get_channel(member->session);
 
-	assert(channel != NULL);
-	assert(member->conference != NULL);
+	switch_assert(channel != NULL);
+	switch_assert(member->conference != NULL);
 
 
 	tsamples = member->orig_read_codec->implementation->samples_per_frame;
@@ -1586,7 +1586,7 @@
 	while (switch_test_flag(member, MFLAG_RUNNING) && switch_test_flag(member, MFLAG_ITHREAD)
 		   && switch_channel_ready(channel)) {
 		char dtmf[128] = "";
-		uint8_t file_frame[CONF_BUFFER_SIZE] = { 0 };
+		uint8_t file_frame[SWITCH_RECOMMENDED_BUFFER_SIZE] = { 0 };
 		switch_size_t file_data_len = csamples * 2;
 		switch_size_t file_sample_len = csamples;
 		char *digit;
@@ -1955,7 +1955,7 @@
 	uint32_t count = 0;
 	conference_file_node_t *nptr;
 
-	assert(conference != NULL);
+	switch_assert(conference != NULL);
 
 	switch_mutex_lock(conference->mutex);
 
@@ -2022,7 +2022,7 @@
 	uint32_t count;
 	char *dfile = NULL, *expanded = NULL;
 
-	assert(conference != NULL);
+	switch_assert(conference != NULL);
 
 	switch_mutex_lock(conference->mutex);
 	switch_mutex_lock(conference->member_mutex);
@@ -2100,10 +2100,10 @@
 		conference->async_fnode = fnode;
 
 		if (nptr) {
-			switch_memory_pool_t *pool;
+			switch_memory_pool_t *tmppool;
 			switch_core_file_close(&nptr->fh);
-			pool = nptr->pool;
-			switch_core_destroy_memory_pool(&pool);
+			tmppool = nptr->pool;
+			switch_core_destroy_memory_pool(&tmppool);
 		}
 
 	} else {
@@ -2225,7 +2225,7 @@
 		switch_memory_pool_t *pool;
 		switch_speech_flag_t flags = SWITCH_SPEECH_FLAG_NONE;
 
-		assert(conference != NULL);
+		switch_assert(conference != NULL);
 
 		if (!(conference->tts_engine && conference->tts_voice)) {
 			return SWITCH_STATUS_SUCCESS;
@@ -2303,7 +2303,7 @@
 	switch_speech_flag_t flags = SWITCH_SPEECH_FLAG_NONE;
 	uint32_t count;
 
-	assert(conference != NULL);
+	switch_assert(conference != NULL);
 
 	if (switch_strlen_zero(text)) {
 		return SWITCH_STATUS_GENERR;
@@ -2389,9 +2389,9 @@
 {
 	conference_member_t *member = NULL;
 
-	assert(conference != NULL);
-	assert(stream != NULL);
-	assert(pfncallback != NULL);
+	switch_assert(conference != NULL);
+	switch_assert(stream != NULL);
+	switch_assert(pfncallback != NULL);
 
 	switch_mutex_lock(conference->member_mutex);
 	for (member = conference->members; member; member = member->next) {
@@ -2405,8 +2405,8 @@
 {
 	conference_member_t *member = NULL;
 
-	assert(conference != NULL);
-	assert(stream != NULL);
+	switch_assert(conference != NULL);
+	switch_assert(stream != NULL);
 
 	switch_mutex_lock(conference->member_mutex);
 
@@ -2433,9 +2433,9 @@
 {
 	conference_member_t *member = NULL;
 
-	assert(conference != NULL);
-	assert(stream != NULL);
-	assert(delim != NULL);
+	switch_assert(conference != NULL);
+	switch_assert(stream != NULL);
+	switch_assert(delim != NULL);
 
 
 	switch_mutex_lock(conference->member_mutex);
@@ -2813,8 +2813,8 @@
 	switch_event_t *event;
 	uint8_t async = 0;
 
-	assert(conference != NULL);
-	assert(stream != NULL);
+	switch_assert(conference != NULL);
+	switch_assert(stream != NULL);
 
 	if ((argc == 4 && !strcasecmp(argv[3], "async")) || (argc == 5 && !strcasecmp(argv[4], "async"))) {
 		argc--;
@@ -2954,8 +2954,8 @@
 	int ret_status = SWITCH_STATUS_GENERR;
 	uint8_t current = 0, all = 0;
 
-	assert(conference != NULL);
-	assert(stream != NULL);
+	switch_assert(conference != NULL);
+	switch_assert(stream != NULL);
 
 	if (argc > 2) {
 		current = strcasecmp(argv[2], "current") ? 0 : 1;
@@ -2990,8 +2990,8 @@
 {
 	int ret_status = SWITCH_STATUS_GENERR;
 
-	assert(conference != NULL);
-	assert(stream != NULL);
+	switch_assert(conference != NULL);
+	switch_assert(stream != NULL);
 
 	if (argc > 4) {
 		uint8_t nospeak = 0, nohear = 0, clear = 0;
@@ -3059,8 +3059,8 @@
 {
 	switch_event_t *event;
 
-	assert(conference != NULL);
-	assert(stream != NULL);
+	switch_assert(conference != NULL);
+	switch_assert(stream != NULL);
 
 	if (conference->is_locked_sound) {
 		conference_play_file(conference, conference->is_locked_sound, CONF_DEFAULT_LEADIN, NULL, 0);
@@ -3081,8 +3081,8 @@
 {
 	switch_event_t *event;
 
-	assert(conference != NULL);
-	assert(stream != NULL);
+	switch_assert(conference != NULL);
+	switch_assert(stream != NULL);
 
 	if (conference->is_unlocked_sound) {
 		conference_play_file(conference, conference->is_unlocked_sound, CONF_DEFAULT_LEADIN, NULL, 0);
@@ -3104,7 +3104,7 @@
 {
 	switch_status_t ret_status = SWITCH_STATUS_SUCCESS;
 
-	assert(stream != NULL);
+	switch_assert(stream != NULL);
 
 	if (argc > 2) {
 		switch_call_cause_t cause;
@@ -3129,7 +3129,7 @@
 {
 	switch_status_t ret_status = SWITCH_STATUS_SUCCESS;
 
-	assert(stream != NULL);
+	switch_assert(stream != NULL);
 
 	if (argc > 2) {
 		if (conference) {
@@ -3150,8 +3150,8 @@
 {
 	switch_status_t ret_status = SWITCH_STATUS_SUCCESS;
 	char *params = NULL, *chanvars = NULL;
-	assert(conference != NULL);
-	assert(stream != NULL);
+	switch_assert(conference != NULL);
+	switch_assert(stream != NULL);
 
 	if (argc > 3 && !switch_strlen_zero(argv[2])) {
 		int x;
@@ -3274,8 +3274,8 @@
 static switch_status_t conf_api_sub_record(conference_obj_t * conference, switch_stream_handle_t *stream, int argc, char **argv)
 {
 	switch_status_t ret_status = SWITCH_STATUS_SUCCESS;
-	assert(conference != NULL);
-	assert(stream != NULL);
+	switch_assert(conference != NULL);
+	switch_assert(stream != NULL);
 
 	if (argc > 2) {
 		stream->write_function(stream, "Record file %s\n", argv[2]);
@@ -3291,8 +3291,8 @@
 {
 	switch_status_t ret_status = SWITCH_STATUS_SUCCESS;
 
-	assert(conference != NULL);
-	assert(stream != NULL);
+	switch_assert(conference != NULL);
+	switch_assert(stream != NULL);
 
 	if (argc > 2) {
 		int all = (strcasecmp(argv[2], "all") == 0);
@@ -3378,8 +3378,8 @@
 {
 	switch_status_t status = SWITCH_STATUS_FALSE;
 	uint32_t i, found = 0;
-	assert(conference != NULL);
-	assert(stream != NULL);
+	switch_assert(conference != NULL);
+	switch_assert(stream != NULL);
 
 	/* loop through the command table to find a match */
 	for (i = 0; i < CONFFUNCAPISIZE && !found; i++) {
@@ -3535,7 +3535,7 @@
 			}
 			switch_thread_rwlock_unlock(conference->rwlock);
 
-		} else {
+		} else if (argv[0]) {
 			/* special case the list command, because it doesn't require a conference argument */
 			if (strcasecmp(argv[0], "list") == 0) {
 				conf_api_sub_list(NULL, stream, argc, argv);
@@ -3573,7 +3573,7 @@
 	switch_channel_t *channel = NULL;
 
 	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CUSTOM RING\n");
 
@@ -3620,7 +3620,7 @@
 		}
 
 		peer_channel = switch_core_session_get_channel(peer_session);
-		assert(peer_channel != NULL);
+		switch_assert(peer_channel != NULL);
 		rdlock = 1;
 		goto callup;
 	}
@@ -3659,7 +3659,7 @@
 
 	rdlock = 1;
 	peer_channel = switch_core_session_get_channel(peer_session);
-	assert(peer_channel != NULL);
+	switch_assert(peer_channel != NULL);
 
 	/* make sure the conference still exists */
 	if (!switch_test_flag(conference, CFLAG_RUNNING)) {
@@ -3811,7 +3811,7 @@
 	/* generate some space infront of the file to be played */
 	for (x = 0; x < leadin; x++) {
 		switch_frame_t *read_frame;
-		switch_status_t status = switch_core_session_read_frame(session, &read_frame, 1000, 0);
+		status = switch_core_session_read_frame(session, &read_frame, 1000, 0);
 
 		if (!SWITCH_READ_ACCEPTABLE(status)) {
 			break;
@@ -3880,7 +3880,7 @@
 	char *addition = (char *) data;
 
 	channel = switch_core_session_get_channel(session);
-    assert(channel != NULL);
+    switch_assert(channel != NULL);
 
 	call_list = switch_channel_get_private(channel, "_conference_autocall_list_");
 
@@ -3888,7 +3888,7 @@
 		call_list = NULL;
 	} else {
 		np = switch_core_session_alloc(session, sizeof(*np));
-		assert(np != NULL);
+		switch_assert(np != NULL);
 
 		np->string = switch_core_session_strdup(session, addition);
 		if (call_list) {
@@ -3931,7 +3931,7 @@
 	char *params = NULL;
 
 	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	if (!mydata) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Pool Failure\n");
@@ -4297,13 +4297,13 @@
 		switch_xml_free(cxml);
 	}
 
-	if (switch_test_flag(&member, MFLAG_KICKED) && conference->kicked_sound) {
+	if (conference && switch_test_flag(&member, MFLAG_KICKED) && conference->kicked_sound) {
 		char *toplay = NULL;
 		char *dfile = NULL;
 
 		if (conference->sound_prefix) {
 			dfile = switch_mprintf("%s%s%s", conference->sound_prefix, SWITCH_PATH_SEPARATOR,  conference->kicked_sound);
-			assert(dfile);
+			switch_assert(dfile);
 			toplay = dfile;
 		} else {
 			toplay = conference->kicked_sound;
@@ -4353,6 +4353,7 @@
 	if (!(rec = switch_core_alloc(pool, sizeof(*rec)))) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Alloc Failure\n");
 		switch_core_destroy_memory_pool(&pool);
+		return;
 	}
 
 	rec->conference = conference;
@@ -4382,6 +4383,7 @@
 
 	if (!(ci = switch_loadable_module_get_chat_interface(proto))) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Chat Interface [%s]!\n", proto);
+		return SWITCH_STATUS_FALSE;
 	}
 
 
@@ -4432,7 +4434,7 @@
 	uint32_t i;
 	caller_control_action_t *action;
 
-	assert(conference != NULL);
+	switch_assert(conference != NULL);
 
 	for (i = 0, status = SWITCH_STATUS_SUCCESS; status == SWITCH_STATUS_SUCCESS && i < CCFNTBL_QTY; i++) {
 		if (!switch_strlen_zero(ccfntbl[i].digits)) {
@@ -4460,7 +4462,7 @@
 	switch_status_t status = SWITCH_STATUS_FALSE;
 	switch_xml_t xml_kvp;
 
-	assert(conference != NULL);
+	switch_assert(conference != NULL);
 
 	if (!xml_controls) {
 		return status;
@@ -4855,8 +4857,6 @@
 	}
 
 	if ((conference = (conference_obj_t *) switch_core_hash_find(globals.conference_hash, conf_name))) {
-		switch_event_t *event;
-
 		if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
 			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "proto", CONF_CHAT_PROTO);
 			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "login", "%s", conference->name);
@@ -4919,7 +4919,7 @@
 {
 	uint32_t i;
 	size_t nl, ol = 0;
-	char *p = NULL;
+	char *p = NULL, *tmp = NULL;
 	switch_chat_interface_t *chat_interface;
 	switch_api_interface_t *api_interface;
 	switch_application_interface_t *app_interface;
@@ -4937,13 +4937,17 @@
 		if (p != NULL) {
 			ol = strlen(p);
 		}
-		p = realloc(p, ol + nl);
-		if (p != NULL) {
+		tmp = realloc(p, ol + nl);
+		if (tmp != NULL) {
+			p = tmp;
 			strcat(p, "\t\t");
 			strcat(p, conf_api_sub_commands[i].psyntax);
 			if (i < CONFFUNCAPISIZE - 1) {
 				strcat(p, "\n");
 			}
+		} else {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't realloc\n");
+			return SWITCH_STATUS_TERM;
 		}
 
 	}

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/mod/applications/mod_enum/mod_enum.c
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/mod/applications/mod_enum/mod_enum.c	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/mod/applications/mod_enum/mod_enum.c	Tue Dec 11 16:35:05 2007
@@ -55,6 +55,7 @@
 	unsigned char dn[DNS_MAXDN];
 	enum dns_type qtyp;			/* type of the query */
 	enum_record_t *results;
+	int errs;
 };
 typedef struct query enum_query_t;
 
@@ -203,9 +204,10 @@
 
 static void dnserror(enum_query_t * q, int errnum)
 {
-
+	
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "unable to lookup %s record for %s: %s\n",
 					  dns_typename(q->qtyp), dns_dntosp(q->dn), dns_strerror(errnum));
+	q->errs++;
 }
 
 
@@ -501,7 +503,7 @@
 
 		j += i;
 
-		if (j > globals.timeout || query.results) {
+		if (j > globals.timeout || query.results || query.errs) {
 			break;
 		}
 
@@ -509,8 +511,9 @@
 		tv.tv_usec = 0;
 		i = select((int) (fd + 1), &fds, 0, 0, &tv);
 		now = time(NULL);
-		if (i > 0)
+		if (i > 0) {
 			dns_ioevent(nctx, now);
+		}
 	}
 
 	if (!query.results) {

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/mod/applications/mod_esf/mod_esf.c
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/mod/applications/mod_esf/mod_esf.c	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/mod/applications/mod_esf/mod_esf.c	Tue Dec 11 16:35:05 2007
@@ -153,7 +153,10 @@
 	}
 
 	if (ready == SEND_TYPE_RTP) {
-		rtp_port = switch_rtp_request_port();
+		if (!(rtp_port = switch_rtp_request_port(guess_ip))) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "RTP Port Error\n");
+			goto fail;
+		}
 		switch_find_local_ip(guess_ip, sizeof(guess_ip), AF_INET);
 		rtp_session = switch_rtp_new(guess_ip,
 									 rtp_port,

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c	Tue Dec 11 16:35:05 2007
@@ -1697,7 +1697,11 @@
 			switch_core_session_set_private(*new_session, tech_pvt);
 			tech_pvt->session = *new_session;
 			tech_pvt->codec_index = -1;
-			tech_pvt->local_port = switch_rtp_request_port();
+			if (!(tech_pvt->local_port = switch_rtp_request_port(tech_pvt->profile->ip))) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "No RTP port available!\n");
+				terminate_session(new_session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+				return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
+			}
 			tech_pvt->recip = switch_core_session_strdup(*new_session, full_id);
 			tech_pvt->dnis = switch_core_session_strdup(*new_session, dnis);
 		} else {
@@ -2584,7 +2588,12 @@
 				tech_pvt->session = session;
 				tech_pvt->codec_index = -1;
 				tech_pvt->profile = profile;
-				tech_pvt->local_port = switch_rtp_request_port();
+				if (!(tech_pvt->local_port = switch_rtp_request_port(profile->ip))) {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "No RTP port available!\n");
+					terminate_session(&session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+					status = LDL_STATUS_FALSE;
+					goto done;
+				}
 				switch_set_flag_locked(tech_pvt, TFLAG_ANSWER);
 				tech_pvt->recip = switch_core_session_strdup(session, from);
 				if (!(exten = ldl_session_get_value(dlsession, "dnis"))) {

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c	Tue Dec 11 16:35:05 2007
@@ -398,7 +398,10 @@
 	}
 
 	tech_pvt->local_sdp_audio_ip = ip;
-	tech_pvt->local_sdp_audio_port = switch_rtp_request_port();
+	if (!(tech_pvt->local_sdp_audio_port = switch_rtp_request_port(tech_pvt->profile->rtpip))) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "No RTP ports available!\n");
+		return SWITCH_STATUS_FALSE;
+	}
 	sdp_port = tech_pvt->local_sdp_audio_port;
 
 	if (tech_pvt->profile->extrtpip) {
@@ -428,7 +431,10 @@
 		return SWITCH_STATUS_SUCCESS;
 	}
 
-	tech_pvt->local_sdp_video_port = switch_rtp_request_port();
+	if (!(tech_pvt->local_sdp_video_port = switch_rtp_request_port(tech_pvt->profile->rtpip))) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "No RTP ports available!\n");
+		return SWITCH_STATUS_FALSE;
+	}
 	sdp_port = tech_pvt->local_sdp_video_port;
 
 	if (tech_pvt->profile->extrtpip) {

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/switch_buffer.c
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/switch_buffer.c	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/switch_buffer.c	Tue Dec 11 16:35:05 2007
@@ -126,7 +126,7 @@
 SWITCH_DECLARE(switch_size_t) switch_buffer_len(switch_buffer_t *buffer)
 {
 
-	assert(buffer != NULL);
+	switch_assert(buffer != NULL);
 
 	return buffer->datalen;
 
@@ -135,7 +135,7 @@
 
 SWITCH_DECLARE(switch_size_t) switch_buffer_freespace(switch_buffer_t *buffer)
 {
-	assert(buffer != NULL);
+	switch_assert(buffer != NULL);
 
 	if (switch_test_flag(buffer, SWITCH_BUFFER_FLAG_DYNAMIC)) {
 		if (buffer->max_len) {
@@ -150,7 +150,7 @@
 
 SWITCH_DECLARE(switch_size_t) switch_buffer_inuse(switch_buffer_t *buffer)
 {
-	assert(buffer != NULL);
+	switch_assert(buffer != NULL);
 
 	return buffer->used;
 }
@@ -159,7 +159,7 @@
 {
 	switch_size_t reading = 0;
 
-	assert(buffer != NULL);
+	switch_assert(buffer != NULL);
 
 	if (buffer->used < 1) {
 		buffer->used = 0;
@@ -202,8 +202,8 @@
 {
 	switch_size_t reading = 0;
 
-	assert(buffer != NULL);
-	assert(data != NULL);
+	switch_assert(buffer != NULL);
+	switch_assert(data != NULL);
 
 
 	if (buffer->used < 1) {
@@ -227,9 +227,9 @@
 {
 	switch_size_t freespace, actual_freespace;
 
-	assert(buffer != NULL);
-	assert(data != NULL);
-	assert(buffer->data != NULL);
+	switch_assert(buffer != NULL);
+	switch_assert(data != NULL);
+	switch_assert(buffer->data != NULL);
 
 	if (!datalen) {
 		return buffer->used;
@@ -286,8 +286,8 @@
 
 SWITCH_DECLARE(void) switch_buffer_zero(switch_buffer_t *buffer)
 {
-	assert(buffer != NULL);
-	assert(buffer->data != NULL);
+	switch_assert(buffer != NULL);
+	switch_assert(buffer->data != NULL);
 
 	buffer->used = 0;
 	buffer->actually_used = 0;

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/switch_caller.c
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/switch_caller.c	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/switch_caller.c	Tue Dec 11 16:35:05 2007
@@ -54,7 +54,7 @@
 	switch_caller_profile_t *profile = NULL;
 
 	profile = switch_core_alloc(pool, sizeof(*profile));
-	assert(profile != NULL);
+	switch_assert(profile != NULL);
 		
 	if (!context) {
 		context = "default";
@@ -85,7 +85,7 @@
 	switch_caller_profile_t *profile = NULL;
 
 	profile = switch_core_alloc(pool, sizeof(*profile));
-	assert(profile != NULL);
+	switch_assert(profile != NULL);
 
 	profile_dup(tocopy->username, profile->username, pool);
 	profile_dup(tocopy->dialplan, profile->dialplan, pool);
@@ -294,7 +294,7 @@
 {
 	switch_caller_application_t *caller_application = NULL;
 
-	assert(session != NULL);
+	switch_assert(session != NULL);
 
 	if ((caller_application = switch_core_session_alloc(session, sizeof(switch_caller_application_t))) != 0) {
 		caller_application->application_name = switch_core_session_strdup(session, application_name);

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/switch_channel.c
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/switch_channel.c	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/switch_channel.c	Tue Dec 11 16:35:05 2007
@@ -156,7 +156,7 @@
 
 SWITCH_DECLARE(switch_call_cause_t) switch_channel_get_cause(switch_channel_t *channel)
 {
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 	return channel->hangup_cause;
 }
 
@@ -164,7 +164,7 @@
 {
 	switch_channel_timetable_t *times = NULL;
 
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 	if (channel->caller_profile) {
 		switch_mutex_lock(channel->profile_mutex);
 		times = channel->caller_profile->times;
@@ -176,7 +176,7 @@
 
 SWITCH_DECLARE(switch_status_t) switch_channel_alloc(switch_channel_t **channel, switch_memory_pool_t *pool)
 {
-	assert(pool != NULL);
+	switch_assert(pool != NULL);
 
 	if (((*channel) = switch_core_alloc(pool, sizeof(switch_channel_t))) == 0) {
 		return SWITCH_STATUS_MEMERR;
@@ -200,7 +200,7 @@
 {
 	switch_size_t has;
 
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 	switch_mutex_lock(channel->dtmf_mutex);
 	has = switch_buffer_inuse(channel->dtmf_buffer);
 	switch_mutex_unlock(channel->dtmf_mutex);
@@ -215,7 +215,7 @@
 	switch_size_t wr = 0;
 	const char *p;
 
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	switch_mutex_lock(channel->dtmf_mutex);	
 
@@ -254,7 +254,7 @@
 	switch_size_t bytes;
 	switch_event_t *event;
 
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	switch_mutex_lock(channel->dtmf_mutex);
 	if ((bytes = switch_buffer_read(channel->dtmf_buffer, dtmf, len)) > 0) {
@@ -283,7 +283,7 @@
 SWITCH_DECLARE(switch_status_t) switch_channel_init(switch_channel_t *channel, switch_core_session_t *session, switch_channel_state_t state,
 													uint32_t flags)
 {
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 	channel->state = state;
 	channel->flags = flags;
 	channel->session = session;
@@ -325,7 +325,7 @@
 SWITCH_DECLARE(const char *) switch_channel_get_variable(switch_channel_t *channel, const char *varname)
 {
 	const char *v = NULL;
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	switch_mutex_lock(channel->profile_mutex);
 	if (!(v = switch_event_get_header(channel->variables, (char*)varname))) {
@@ -352,7 +352,7 @@
 
 SWITCH_DECLARE(void) switch_channel_variable_last(switch_channel_t *channel)
 {
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 	if (!channel->vi) {
 		return;
 	}
@@ -365,7 +365,7 @@
 {
 	switch_event_header_t *hi = NULL;
 
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 	switch_mutex_lock(channel->profile_mutex);
 	if ((hi = channel->variables->headers)) {
 		channel->vi = 1;
@@ -379,7 +379,7 @@
 
 SWITCH_DECLARE(switch_status_t) switch_channel_set_private(switch_channel_t *channel, const char *key, const void *private_info)
 {
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 	switch_core_hash_insert_locked(channel->private_hash, key, private_info, channel->profile_mutex);
 	return SWITCH_STATUS_SUCCESS;
 }
@@ -387,14 +387,14 @@
 SWITCH_DECLARE(void *) switch_channel_get_private(switch_channel_t *channel, const char *key)
 {
 	void *val;
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 	val = switch_core_hash_find_locked(channel->private_hash, key, channel->profile_mutex);
 	return val;
 }
 
 SWITCH_DECLARE(switch_status_t) switch_channel_set_name(switch_channel_t *channel, const char *name)
 {
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 	channel->name = NULL;
 	if (name) {
 		char *uuid = switch_core_session_get_uuid(channel->session);
@@ -408,13 +408,13 @@
 
 SWITCH_DECLARE(char *) switch_channel_get_name(switch_channel_t *channel)
 {
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 	return channel->name ? channel->name : "N/A";
 }
 
 SWITCH_DECLARE(switch_status_t) switch_channel_set_variable(switch_channel_t *channel, const char *varname, const char *value)
 {
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 	
 	if (!switch_strlen_zero(varname)) {
 		switch_mutex_lock(channel->profile_mutex);
@@ -431,7 +431,7 @@
 
 SWITCH_DECLARE(int) switch_channel_test_flag(switch_channel_t *channel, switch_channel_flag_t flags)
 {
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 	return switch_test_flag(channel, flags) ? 1 : 0;
 }
 
@@ -439,7 +439,7 @@
 {
 	const char *uuid;
 
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))) {
 		switch_core_session_t *session;
@@ -457,7 +457,7 @@
 {
 	const char *uuid;
 
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))) {
 		switch_core_session_t *session;
@@ -489,13 +489,13 @@
 
 SWITCH_DECLARE(void) switch_channel_set_flag(switch_channel_t *channel, switch_channel_flag_t flags)
 {
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 	switch_set_flag_locked(channel, flags);
 }
 
 SWITCH_DECLARE(void) switch_channel_set_state_flag(switch_channel_t *channel, switch_channel_flag_t flags)
 {
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	switch_mutex_lock(channel->flag_mutex);
 	channel->state_flags |= flags;
@@ -504,14 +504,14 @@
 
 SWITCH_DECLARE(void) switch_channel_clear_flag(switch_channel_t *channel, switch_channel_flag_t flags)
 {
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 	switch_clear_flag_locked(channel, flags);
 }
 
 SWITCH_DECLARE(switch_channel_state_t) switch_channel_get_state(switch_channel_t *channel)
 {
 	switch_channel_state_t state;
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	switch_mutex_lock(channel->flag_mutex);
 	state = channel->state;
@@ -523,7 +523,7 @@
 SWITCH_DECLARE(switch_channel_state_t) switch_channel_get_running_state(switch_channel_t *channel)
 {
 	switch_channel_state_t state;
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	switch_mutex_lock(channel->flag_mutex);
 	state = channel->running_state;
@@ -536,7 +536,7 @@
 {
 	uint8_t ret = 0;
 
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 	
 	if (!channel->hangup_cause && channel->state > CS_RING && channel->state < CS_HANGUP && channel->state != CS_RESET && 
 		!switch_test_flag(channel, CF_TRANSFER)) {
@@ -618,7 +618,7 @@
 	int ok = 0;
 
 
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 	switch_mutex_lock(channel->flag_mutex);
 
 	last_state = channel->state;
@@ -800,7 +800,7 @@
 		/* we won't tolerate an invalid state change so we can make sure we are as robust as a nice cup of dark coffee! */
 		if (channel->state < CS_HANGUP) {
 			/* not cool lets crash this bad boy and figure out wtf is going on */
-			assert(0);
+			switch_assert(0);
 		}
 	}
   done:
@@ -869,7 +869,7 @@
 		vval = (char *) hi->value;
 		x++;
 		
-		assert(vvar && vval);
+		switch_assert(vvar && vval);
 		snprintf(buf, sizeof(buf), "variable_%s", vvar);
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, buf, "%s", vval);
 
@@ -882,10 +882,10 @@
 SWITCH_DECLARE(void) switch_channel_set_caller_profile(switch_channel_t *channel, switch_caller_profile_t *caller_profile)
 {
 	char *uuid = NULL;
-	assert(channel != NULL);
-	assert(channel->session != NULL);
+	switch_assert(channel != NULL);
+	switch_assert(channel->session != NULL);
 	switch_mutex_lock(channel->profile_mutex);
-	assert(caller_profile != NULL);
+	switch_assert(caller_profile != NULL);
 	
 	uuid = switch_core_session_get_uuid(channel->session);
 	
@@ -927,7 +927,7 @@
 SWITCH_DECLARE(switch_caller_profile_t *) switch_channel_get_caller_profile(switch_channel_t *channel)
 {
 	switch_caller_profile_t *profile;
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 	switch_mutex_lock(channel->profile_mutex);
 	profile = channel->caller_profile;
 	switch_mutex_unlock(channel->profile_mutex);
@@ -936,26 +936,28 @@
 
 SWITCH_DECLARE(void) switch_channel_set_originator_caller_profile(switch_channel_t *channel, switch_caller_profile_t *caller_profile)
 {
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
+	switch_assert(channel->caller_profile != NULL);
 	switch_mutex_lock(channel->profile_mutex);
 	if (channel->caller_profile) {
 		caller_profile->next = channel->caller_profile->originator_caller_profile;
 		channel->caller_profile->originator_caller_profile = caller_profile;
 	}
-	assert(channel->caller_profile->originator_caller_profile->next != channel->caller_profile->originator_caller_profile);
+	switch_assert(channel->caller_profile->originator_caller_profile->next != channel->caller_profile->originator_caller_profile);
 	switch_mutex_unlock(channel->profile_mutex);
 }
 
 SWITCH_DECLARE(void) switch_channel_set_originatee_caller_profile(switch_channel_t *channel, switch_caller_profile_t *caller_profile)
 {
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
+	switch_assert(channel->caller_profile != NULL);
 
 	switch_mutex_lock(channel->profile_mutex);
 	if (channel->caller_profile) {
 		caller_profile->next = channel->caller_profile->originatee_caller_profile;
 		channel->caller_profile->originatee_caller_profile = caller_profile;
 	}
-	assert(channel->caller_profile->originatee_caller_profile->next != channel->caller_profile->originatee_caller_profile);
+	switch_assert(channel->caller_profile->originatee_caller_profile->next != channel->caller_profile->originatee_caller_profile);
 	switch_mutex_unlock(channel->profile_mutex);
 		
 }
@@ -963,7 +965,7 @@
 SWITCH_DECLARE(switch_caller_profile_t *) switch_channel_get_originator_caller_profile(switch_channel_t *channel)
 {
 	switch_caller_profile_t *profile = NULL;
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	switch_mutex_lock(channel->profile_mutex);
 	if (channel->caller_profile) {
@@ -977,7 +979,7 @@
 SWITCH_DECLARE(switch_caller_profile_t *) switch_channel_get_originatee_caller_profile(switch_channel_t *channel)
 {
 	switch_caller_profile_t *profile = NULL;
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	switch_mutex_lock(channel->profile_mutex);
 	if (channel->caller_profile) {
@@ -990,8 +992,8 @@
 
 SWITCH_DECLARE(char *) switch_channel_get_uuid(switch_channel_t *channel)
 {
-	assert(channel != NULL);
-	assert(channel->session != NULL);
+	switch_assert(channel != NULL);
+	switch_assert(channel->session != NULL);
 	return switch_core_session_get_uuid(channel->session);
 }
 
@@ -999,7 +1001,7 @@
 {
 	int x, index;
 
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 	switch_mutex_lock(channel->flag_mutex);
 	for (x = 0; x < SWITCH_MAX_STATE_HANDLERS; x++) {
 		if (channel->state_handlers[x] == state_handler) {
@@ -1025,7 +1027,7 @@
 {
 	const switch_state_handler_table_t *h = NULL;
 
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	if (index > SWITCH_MAX_STATE_HANDLERS || index > channel->state_handler_index) {
 		return NULL;
@@ -1046,7 +1048,7 @@
 
 	switch_mutex_lock(channel->flag_mutex);
 
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 	channel->state_handler_index = 0;
 
 	if (state_handler) {
@@ -1072,7 +1074,7 @@
 
 SWITCH_DECLARE(void) switch_channel_set_caller_extension(switch_channel_t *channel, switch_caller_extension_t *caller_extension)
 {
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	switch_mutex_lock(channel->profile_mutex);
 	caller_extension->next = channel->caller_profile->caller_extension;
@@ -1085,7 +1087,7 @@
 {
 	switch_caller_extension_t *extension = NULL;
 
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 	switch_mutex_lock(channel->profile_mutex);
 	if (channel->caller_profile) {
 		extension = channel->caller_profile->caller_extension;
@@ -1098,7 +1100,7 @@
 SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_hangup(switch_channel_t *channel,
 																	 const char *file, const char *func, int line, switch_call_cause_t hangup_cause)
 {
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 	switch_mutex_lock(channel->flag_mutex);
 
 	if (channel->caller_profile && channel->caller_profile->times && !channel->caller_profile->times->hungup) {
@@ -1182,7 +1184,7 @@
 	switch_core_session_message_t msg;
 	switch_status_t status;
 
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	if (channel->hangup_cause || channel->state >= CS_HANGUP) {
 		return SWITCH_STATUS_FALSE;
@@ -1212,7 +1214,7 @@
 	switch_core_session_message_t msg;
 	switch_status_t status;
 
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	if (channel->hangup_cause || channel->state >= CS_HANGUP) {
 		return SWITCH_STATUS_FALSE;
@@ -1243,7 +1245,7 @@
 	const char *uuid;
 	switch_core_session_t *other_session;
 
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	if (channel->hangup_cause || channel->state >= CS_HANGUP) {
 		return SWITCH_STATUS_FALSE;
@@ -1286,7 +1288,7 @@
 	switch_core_session_message_t msg;
 	switch_status_t status;
 
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	if (channel->hangup_cause || channel->state >= CS_HANGUP) {
 		return SWITCH_STATUS_FALSE;
@@ -1471,7 +1473,7 @@
 					sub_val = switch_channel_get_variable(channel, vname);
 					if (offset || ooffset) {
 						cloned_sub_val = strdup(sub_val);
-                        assert(cloned_sub_val);
+                        switch_assert(cloned_sub_val);
 						sub_val = cloned_sub_val;
 					}
 
@@ -1583,13 +1585,13 @@
 	}
 
 	encode_buf = malloc(encode_len);
-	assert(encode_buf);
+	switch_assert(encode_buf);
 
 	if (!caller_profile) {
 		caller_profile = switch_channel_get_caller_profile(channel);
 	}
 
-	assert(caller_profile != NULL);
+	switch_assert(caller_profile != NULL);
 	
 	prof[0] = caller_profile->context;
 	prof[1] = caller_profile->destination_number;
@@ -1647,7 +1649,7 @@
 				encode_len = new_len;
 			
 				tmp = realloc(encode_buf, encode_len);
-				assert(tmp);
+				switch_assert(tmp);
 				encode_buf = tmp;
 			}
 

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core.c
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core.c	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core.c	Tue Dec 11 16:35:05 2007
@@ -182,10 +182,10 @@
 	switch_frame_t *read_frame;
 	int stream_id = *stream_id_p;
 
-	assert(thread != NULL);
-	assert(session != NULL);
+	switch_assert(thread != NULL);
+	switch_assert(session != NULL);
 	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	switch_channel_set_flag(channel, CF_SERVICE);
 	while (data->running > 0) {
@@ -536,7 +536,9 @@
 #ifdef WIN32
 		snprintf(path, sizeof(path), "Global\\Freeswitch.%d", getpid());
 		shutdown_event = CreateEvent(NULL, FALSE, FALSE, path);
-		WaitForSingleObject(shutdown_event, INFINITE);
+		if (shutdown_event) {
+			WaitForSingleObject(shutdown_event, INFINITE);
+		}
 #else
 		runtime.running = 1;
 		while (runtime.running) {
@@ -568,8 +570,8 @@
 	const char *check = (const char *) switch_core_hash_find(runtime.mime_types, ext);
 	switch_status_t status = SWITCH_STATUS_FALSE;
 
-	assert(type);
-	assert(ext);
+	switch_assert(type);
+	switch_assert(ext);
 
 	if (!check) {
 		char *ptype = switch_core_permanent_strdup(type);
@@ -578,7 +580,7 @@
 		char *argv[20] = { 0 };
 		int x;
 
-		assert(ext_list);
+		switch_assert(ext_list);
 
 		if ((argc = switch_separate_string(ext_list, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
 
@@ -603,7 +605,7 @@
 	char *mime_path = NULL;
 
 	mime_path = switch_mprintf("%s/%s", SWITCH_GLOBAL_dirs.conf_dir, cf);
-	assert(mime_path);
+	switch_assert(mime_path);
 
 	fd = open(mime_path, O_RDONLY);
 	if (fd <= 0) {
@@ -664,7 +666,7 @@
 		*err = "FATAL ERROR! Could noat allocate memory pool\n";
 		return SWITCH_STATUS_MEMERR;
 	}
-	assert(runtime.memory_pool != NULL);
+	switch_assert(runtime.memory_pool != NULL);
 	switch_mutex_init(&runtime.throttle_mutex, SWITCH_MUTEX_NESTED, runtime.memory_pool);
 	switch_core_set_globals();
 	switch_core_session_init(runtime.memory_pool);
@@ -750,7 +752,7 @@
 		runtime.console = stdout;
 	}
 
-	assert(runtime.memory_pool != NULL);
+	switch_assert(runtime.memory_pool != NULL);
 	switch_log_init(runtime.memory_pool);
 	switch_event_init(runtime.memory_pool);
 
@@ -994,13 +996,12 @@
 	}
 	switch_scheduler_task_thread_stop();
 
+	switch_rtp_shutdown();
 	switch_xml_destroy();
 	switch_core_memory_stop();
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Finalizing Shutdown.\n");
 	switch_log_shutdown();
 
-
-
 	if (runtime.console && runtime.console != stdout && runtime.console != stderr) {
 		fclose(runtime.console);
 		runtime.console = NULL;
@@ -1028,6 +1029,18 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
+SWITCH_DECLARE(switch_status_t) switch_core_management_exec(char *relative_oid, switch_management_action_t action, char *data, switch_size_t datalen)
+{
+	const switch_management_interface_t *ptr;
+	switch_status_t status = SWITCH_STATUS_FALSE;
+
+	if ((ptr = switch_loadable_module_get_management_interface(relative_oid))) {
+		status = ptr->management_function(relative_oid, action, data, datalen);
+	}
+
+	return status;
+}
+
 SWITCH_DECLARE(void) switch_core_memory_reclaim_all(void)
 {
 	switch_core_memory_reclaim_logger();	

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_asr.c
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_asr.c	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_asr.c	Tue Dec 11 16:35:05 2007
@@ -54,7 +54,7 @@
 		}
 	}
 
-	assert(ah != NULL);
+	switch_assert(ah != NULL);
 
 	if ((ah->asr_interface = switch_loadable_module_get_asr_interface(module_name)) == 0) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "invalid asr module [%s]!\n", module_name);
@@ -86,7 +86,7 @@
 	char *epath = NULL;
 	switch_status_t status;
 
-	assert(ah != NULL);
+	switch_assert(ah != NULL);
 
 	if (!switch_is_file_path(path)) {
 		epath = switch_mprintf("%s%s%s", SWITCH_GLOBAL_dirs.grammar_dir, SWITCH_PATH_SEPARATOR, path);
@@ -103,7 +103,7 @@
 {
 	switch_status_t status;
 
-	assert(ah != NULL);
+	switch_assert(ah != NULL);
 	status = ah->asr_interface->asr_unload_grammar(ah, grammar);
 
 	return status;
@@ -111,42 +111,42 @@
 
 SWITCH_DECLARE(switch_status_t) switch_core_asr_pause(switch_asr_handle_t *ah)
 {
-	assert(ah != NULL);
+	switch_assert(ah != NULL);
 
 	return ah->asr_interface->asr_pause(ah);
 }
 
 SWITCH_DECLARE(switch_status_t) switch_core_asr_resume(switch_asr_handle_t *ah)
 {
-	assert(ah != NULL);
+	switch_assert(ah != NULL);
 
 	return ah->asr_interface->asr_resume(ah);
 }
 
 SWITCH_DECLARE(switch_status_t) switch_core_asr_close(switch_asr_handle_t *ah, switch_asr_flag_t *flags)
 {
-	assert(ah != NULL);
+	switch_assert(ah != NULL);
 
 	return ah->asr_interface->asr_close(ah, flags);
 }
 
 SWITCH_DECLARE(switch_status_t) switch_core_asr_feed(switch_asr_handle_t *ah, void *data, unsigned int len, switch_asr_flag_t *flags)
 {
-	assert(ah != NULL);
+	switch_assert(ah != NULL);
 
 	return ah->asr_interface->asr_feed(ah, data, len, flags);
 }
 
 SWITCH_DECLARE(switch_status_t) switch_core_asr_check_results(switch_asr_handle_t *ah, switch_asr_flag_t *flags)
 {
-	assert(ah != NULL);
+	switch_assert(ah != NULL);
 
 	return ah->asr_interface->asr_check_results(ah, flags);
 }
 
 SWITCH_DECLARE(switch_status_t) switch_core_asr_get_results(switch_asr_handle_t *ah, char **xmlstr, switch_asr_flag_t *flags)
 {
-	assert(ah != NULL);
+	switch_assert(ah != NULL);
 
 	return ah->asr_interface->asr_get_results(ah, xmlstr, flags);
 }

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_codec.c
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_codec.c	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_codec.c	Tue Dec 11 16:35:05 2007
@@ -40,7 +40,7 @@
 	switch_channel_t *channel;
 	char tmp[30];
 
-	assert(session != NULL);
+	switch_assert(session != NULL);
 	channel = switch_core_session_get_channel(session);
 
 	if (switch_event_create(&event, SWITCH_EVENT_CODEC) == SWITCH_STATUS_SUCCESS) {
@@ -77,7 +77,7 @@
 	switch_channel_t *channel;
 	char tmp[30];
 
-	assert(session != NULL);
+	switch_assert(session != NULL);
 	channel = switch_core_session_get_channel(session);
 
 
@@ -112,8 +112,8 @@
 	const switch_codec_implementation_t *iptr, *implementation = NULL;
 	char *mode = fmtp;
 
-	assert(codec != NULL);
-	assert(codec_name != NULL);
+	switch_assert(codec != NULL);
+	switch_assert(codec_name != NULL);
 
 	memset(codec, 0, sizeof(*codec));
 
@@ -199,9 +199,9 @@
 														 uint32_t decoded_rate,
 														 void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate, unsigned int *flag)
 {
-	assert(codec != NULL);
-	assert(encoded_data != NULL);
-	assert(decoded_data != NULL);
+	switch_assert(codec != NULL);
+	switch_assert(encoded_data != NULL);
+	switch_assert(decoded_data != NULL);
 
 	if (!codec->implementation) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec is not initilized!\n");
@@ -227,9 +227,9 @@
 														 void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate, unsigned int *flag)
 {
 
-	assert(codec != NULL);
-	assert(encoded_data != NULL);
-	assert(decoded_data != NULL);
+	switch_assert(codec != NULL);
+	switch_assert(encoded_data != NULL);
+	switch_assert(decoded_data != NULL);
 
 
 
@@ -251,7 +251,7 @@
 
 SWITCH_DECLARE(switch_status_t) switch_core_codec_destroy(switch_codec_t *codec)
 {
-	assert(codec != NULL);
+	switch_assert(codec != NULL);
 
 	if (!codec->implementation) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Codec is not initilized!\n");

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_file.c
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_file.c	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_file.c	Tue Dec 11 16:35:05 2007
@@ -94,16 +94,16 @@
 
 SWITCH_DECLARE(switch_status_t) switch_core_file_read(switch_file_handle_t *fh, void *data, switch_size_t *len)
 {
-	assert(fh != NULL);
-	assert(fh->file_interface != NULL);
+	switch_assert(fh != NULL);
+	switch_assert(fh->file_interface != NULL);
 
 	return fh->file_interface->file_read(fh, data, len);
 }
 
 SWITCH_DECLARE(switch_status_t) switch_core_file_write(switch_file_handle_t *fh, void *data, switch_size_t *len)
 {
-	assert(fh != NULL);
-	assert(fh->file_interface != NULL);
+	switch_assert(fh != NULL);
+	switch_assert(fh->file_interface != NULL);
 
 	return fh->file_interface->file_write(fh, data, len);
 }
@@ -112,8 +112,8 @@
 {
 	switch_status_t status;
 
-	assert(fh != NULL);
-	assert(fh->file_interface != NULL);
+	switch_assert(fh != NULL);
+	switch_assert(fh->file_interface != NULL);
 
 	switch_set_flag(fh, SWITCH_FILE_SEEK);
 	status = fh->file_interface->file_seek(fh, cur_pos, samples, whence);
@@ -125,16 +125,16 @@
 
 SWITCH_DECLARE(switch_status_t) switch_core_file_set_string(switch_file_handle_t *fh, switch_audio_col_t col, const char *string)
 {
-	assert(fh != NULL);
-	assert(fh->file_interface != NULL);
+	switch_assert(fh != NULL);
+	switch_assert(fh->file_interface != NULL);
 
 	return fh->file_interface->file_set_string(fh, col, string);
 }
 
 SWITCH_DECLARE(switch_status_t) switch_core_file_get_string(switch_file_handle_t *fh, switch_audio_col_t col, const char **string)
 {
-	assert(fh != NULL);
-	assert(fh->file_interface != NULL);
+	switch_assert(fh != NULL);
+	switch_assert(fh->file_interface != NULL);
 
 	return fh->file_interface->file_get_string(fh, col, string);
 
@@ -143,8 +143,8 @@
 
 SWITCH_DECLARE(switch_status_t) switch_core_file_close(switch_file_handle_t *fh)
 {
-	assert(fh != NULL);
-	assert(fh->file_interface != NULL);
+	switch_assert(fh != NULL);
+	switch_assert(fh->file_interface != NULL);
 
 	switch_clear_flag(fh, SWITCH_FILE_OPEN);
 	return fh->file_interface->file_close(fh);

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_hash.c
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_hash.c	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_hash.c	Tue Dec 11 16:35:05 2007
@@ -47,7 +47,7 @@
 	switch_hash_t *newhash;
 	
 	newhash = switch_core_alloc(pool, sizeof(*newhash));
-	assert(newhash);
+	switch_assert(newhash);
 
 	sqlite3HashInit(&newhash->table, SQLITE_HASH_STRING, 1);
 	*hash = newhash;
@@ -58,7 +58,7 @@
 
 SWITCH_DECLARE(switch_status_t) switch_core_hash_destroy(switch_hash_t **hash)
 {
-	assert(hash != NULL && *hash != NULL);
+	switch_assert(hash != NULL && *hash != NULL);
 	sqlite3HashClear(&(*hash)->table);
 	*hash = NULL;
 	return SWITCH_STATUS_SUCCESS;
@@ -145,9 +145,9 @@
 {
 	if (key) {
 		*key = sqliteHashKey((HashElem *) hi);
-	}
-	if (klen) {
-		*klen = strlen((char *) *key) + 1;
+		if (klen) {
+			*klen = strlen((char *) *key) + 1;
+		}
 	}
 	if (val) {
 		*val = sqliteHashData((HashElem *) hi);

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_io.c
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_io.c	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_io.c	Tue Dec 11 16:35:05 2007
@@ -76,8 +76,8 @@
 		goto done;
 	}
 
-	assert(session != NULL);
-	assert(*frame != NULL);
+	switch_assert(session != NULL);
+	switch_assert(*frame != NULL);
 
 	if (switch_test_flag(*frame, SFF_CNG)) {
 		status = SWITCH_STATUS_SUCCESS;
@@ -101,7 +101,7 @@
 	status = SWITCH_STATUS_FALSE;
 	need_codec = perfect = 0;
 
-	assert(session != NULL);
+	switch_assert(session != NULL);
 	*frame = NULL;
 
 	if (switch_channel_test_flag(session->channel, CF_HOLD)) {
@@ -128,8 +128,8 @@
 		goto done;
 	}
 
-	assert(session != NULL);
-	assert(*frame != NULL);
+	switch_assert(session != NULL);
+	switch_assert(*frame != NULL);
 
 	
 	if (switch_test_flag(*frame, SFF_CNG)) {
@@ -137,7 +137,7 @@
 		goto done;
 	}
 
-	assert((*frame)->codec != NULL);
+	switch_assert((*frame)->codec != NULL);
 	if ((session->read_codec && (*frame)->codec && session->read_codec->implementation != (*frame)->codec->implementation)) {
 		need_codec = TRUE;
 	}
@@ -313,9 +313,9 @@
 				}
 				session->enc_read_frame.datalen = session->enc_read_frame.buflen;
 
-				assert(session->read_codec != NULL);
-				assert(enc_frame != NULL);
-				assert(enc_frame->data != NULL);
+				switch_assert(session->read_codec != NULL);
+				switch_assert(enc_frame != NULL);
+				switch_assert(enc_frame->data != NULL);
 
 				status = switch_core_codec_encode(session->read_codec,
 												  enc_frame->codec,
@@ -433,8 +433,8 @@
 	unsigned int flag = 0, need_codec = 0, perfect = 0, do_bugs = 0, do_write = 0, do_resample = 0;
 	switch_io_flag_t io_flag = SWITCH_IO_FLAG_NOOP;
 
-	assert(session != NULL);
-	assert(frame != NULL);
+	switch_assert(session != NULL);
+	switch_assert(frame != NULL);
 
 
 	if (switch_channel_test_flag(session->channel, CF_HOLD)) {
@@ -450,7 +450,7 @@
 		return SWITCH_STATUS_SUCCESS;
 	}
 
-	assert(frame->codec != NULL);
+	switch_assert(frame->codec != NULL);
 
 	if ((session->write_codec && frame->codec && session->write_codec->implementation != frame->codec->implementation)) {
 		need_codec = TRUE;

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_memory.c
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_memory.c	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_memory.c	Tue Dec 11 16:35:05 2007
@@ -45,8 +45,8 @@
 
 SWITCH_DECLARE(switch_memory_pool_t *) switch_core_session_get_pool(switch_core_session_t *session)
 {
-	assert(session != NULL);
-	assert(session->pool != NULL);
+	switch_assert(session != NULL);
+	switch_assert(session->pool != NULL);
 	return session->pool;
 }
 
@@ -55,8 +55,8 @@
 SWITCH_DECLARE(void *) switch_core_session_alloc(switch_core_session_t *session, switch_size_t memory)
 {
 	void *ptr = NULL;
-	assert(session != NULL);
-	assert(session->pool != NULL);
+	switch_assert(session != NULL);
+	switch_assert(session->pool != NULL);
 
 #ifdef LOCK_MORE
 	switch_mutex_lock(memory_manager.mem_lock);
@@ -67,7 +67,7 @@
 #endif
 
 	ptr = apr_palloc(session->pool, memory);
-	assert(ptr != NULL);
+	switch_assert(ptr != NULL);
 
 	memset(ptr, 0, memory);
 	
@@ -84,7 +84,7 @@
 SWITCH_DECLARE(void *) switch_core_permanent_alloc(switch_size_t memory)
 {
 	void *ptr = NULL;
-	assert(memory_manager.memory_pool != NULL);
+	switch_assert(memory_manager.memory_pool != NULL);
 
 #ifdef LOCK_MORE
 	switch_mutex_lock(memory_manager.mem_lock);
@@ -96,7 +96,7 @@
 
 	ptr = apr_palloc(memory_manager.memory_pool, memory);
 
-	assert(ptr != NULL);
+	switch_assert(ptr != NULL);
 	memset(ptr, 0, memory);
 
 #ifdef LOCK_MORE
@@ -110,7 +110,7 @@
 {
 	char *duped = NULL;
 	switch_size_t len;
-	assert(memory_manager.memory_pool != NULL);
+	switch_assert(memory_manager.memory_pool != NULL);
 
 	if (!todup)
 		return NULL;
@@ -121,7 +121,7 @@
 
 	len = strlen(todup) + 1;
 	duped = apr_pstrmemdup(memory_manager.memory_pool, todup, len);
-	assert(duped != NULL);
+	switch_assert(duped != NULL);
 
 #ifdef DEBUG_ALLOC
 	printf("Perm Allocate %d\n", (int)len);
@@ -143,12 +143,12 @@
 	switch_mutex_lock(memory_manager.mem_lock);
 #endif
 
-	assert(session != NULL);
-	assert(session->pool != NULL);
+	switch_assert(session != NULL);
+	switch_assert(session->pool != NULL);
 	va_start(ap, fmt);
 	
 	result = apr_pvsprintf(session->pool, fmt, ap);
-	assert(result != NULL);
+	switch_assert(result != NULL);
 	va_end(ap);
 
 
@@ -164,7 +164,7 @@
 	va_list ap;
 	char *result = NULL;
 
-	assert(pool != NULL);
+	switch_assert(pool != NULL);
 
 #ifdef LOCK_MORE
 	switch_mutex_lock(memory_manager.mem_lock);
@@ -173,7 +173,7 @@
 	va_start(ap, fmt);
 
 	result = apr_pvsprintf(pool, fmt, ap);
-	assert(result != NULL);
+	switch_assert(result != NULL);
 	va_end(ap);
 
 #ifdef LOCK_MORE
@@ -188,8 +188,8 @@
 {
 	char *duped = NULL;
 	switch_size_t len;
-	assert(session != NULL);
-	assert(session->pool != NULL);
+	switch_assert(session != NULL);
+	switch_assert(session->pool != NULL);
 
 	if (!todup) {
 		return NULL;
@@ -206,7 +206,7 @@
 #endif
 
 	duped = apr_pstrmemdup(session->pool, todup, len);
-	assert(duped != NULL);
+	switch_assert(duped != NULL);
 
 
 #ifdef LOCK_MORE
@@ -221,7 +221,7 @@
 {
 	char *duped = NULL;
 	switch_size_t len;
-	assert(pool != NULL);
+	switch_assert(pool != NULL);
 
 	if (!todup) {
 		return NULL;
@@ -238,7 +238,7 @@
 #endif
 
 	duped = apr_pstrmemdup(pool, todup, len);
-	assert(duped != NULL);
+	switch_assert(duped != NULL);
 
 #ifdef LOCK_MORE
 	switch_mutex_unlock(memory_manager.mem_lock);
@@ -253,13 +253,13 @@
 	void *pop;
 
 	switch_mutex_lock(memory_manager.mem_lock);
-	assert(pool != NULL);
+	switch_assert(pool != NULL);
 
 	if (switch_queue_trypop(memory_manager.pool_recycle_queue, &pop) == SWITCH_STATUS_SUCCESS) {
 		*pool = (switch_memory_pool_t *) pop;
 	} else {
 		apr_pool_create(pool, NULL);
-		assert(*pool != NULL);
+		switch_assert(*pool != NULL);
 	}
 
 #ifdef DEBUG_ALLOC2
@@ -276,7 +276,7 @@
 	//char tmp[128] = "";
 
 
-	assert(pool != NULL);
+	switch_assert(pool != NULL);
 
 #ifdef DEBUG_ALLOC2
 	printf("Free Pool %s %s:%d\n", file, func, line);
@@ -296,7 +296,7 @@
 {
 	void *ptr = NULL;
 
-	assert(pool != NULL);
+	switch_assert(pool != NULL);
 
 #ifdef LOCK_MORE
 	switch_mutex_lock(memory_manager.mem_lock);
@@ -304,11 +304,11 @@
 
 #ifdef DEBUG_ALLOC
 	printf("Allocate %d\n", (int)memory);
-	/*assert(memory < 20000);*/
+	/*switch_assert(memory < 20000);*/
 #endif
 
 	ptr = apr_palloc(pool, memory);
-	assert(ptr != NULL);
+	switch_assert(ptr != NULL);
 	memset(ptr, 0, memory);
 	
 
@@ -413,7 +413,7 @@
 	memset(&memory_manager, 0, sizeof(memory_manager));
 
 	apr_pool_create(&memory_manager.memory_pool, NULL);
-	assert(memory_manager.memory_pool != NULL);
+	switch_assert(memory_manager.memory_pool != NULL);
 	switch_mutex_init(&memory_manager.mem_lock, SWITCH_MUTEX_NESTED, memory_manager.memory_pool);
 	switch_queue_create(&memory_manager.pool_queue, 50000, memory_manager.memory_pool);
 	switch_queue_create(&memory_manager.pool_recycle_queue, 50000, memory_manager.memory_pool);

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_port_allocator.c
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_port_allocator.c	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_port_allocator.c	Tue Dec 11 16:35:05 2007
@@ -38,18 +38,21 @@
 	switch_port_t start;
 	switch_port_t end;
 	switch_port_t next;
-	uint8_t inc;
+	switch_byte_t *track;
+	uint32_t track_len;
+	uint32_t track_used;
+	switch_port_flag_t flags;
 	switch_mutex_t *mutex;
 	switch_memory_pool_t *pool;
 };
 
 SWITCH_DECLARE(switch_status_t) switch_core_port_allocator_new(switch_port_t start,
-															   switch_port_t end, uint8_t inc, switch_core_port_allocator_t **new_allocator)
+															   switch_port_t end, switch_port_flag_t flags, switch_core_port_allocator_t **new_allocator)
 {
 	switch_status_t status;
 	switch_memory_pool_t *pool;
 	switch_core_port_allocator_t *alloc;
-
+	
 	if ((status = switch_core_new_memory_pool(&pool)) != SWITCH_STATUS_SUCCESS) {
 		return status;
 	}
@@ -58,13 +61,21 @@
 		switch_core_destroy_memory_pool(&pool);
 		return SWITCH_STATUS_MEMERR;
 	}
+	
+	alloc->track_len = (end - start) + 2;
+	alloc->flags = flags;
+
+	if (!(switch_test_flag(alloc, SPF_EVEN) && switch_test_flag(alloc, SPF_ODD))) {
+		alloc->track_len /= 2;
+	}
+
+	alloc->track = switch_core_alloc(pool, (alloc->track_len + 2) * sizeof(switch_byte_t));
 
 	alloc->start = start;
 	alloc->next = start;
 	alloc->end = end;
-	if (!(alloc->inc = inc)) {
-		alloc->inc = 2;
-	}
+
+
 	switch_mutex_init(&alloc->mutex, SWITCH_MUTEX_NESTED, pool);
 	alloc->pool = pool;
 	*new_allocator = alloc;
@@ -72,34 +83,89 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-SWITCH_DECLARE(switch_status_t) switch_core_management_exec(char *relative_oid, switch_management_action_t action, char *data, switch_size_t datalen)
+
+SWITCH_DECLARE(switch_status_t) switch_core_port_allocator_request_port(switch_core_port_allocator_t *alloc, switch_port_t *port_ptr)
 {
-	const switch_management_interface_t *ptr;
+	switch_port_t port = 0;
 	switch_status_t status = SWITCH_STATUS_FALSE;
+	int even = switch_test_flag(alloc, SPF_EVEN);
+	int odd = switch_test_flag(alloc, SPF_ODD);
+
+	switch_mutex_lock(alloc->mutex);
+	srand(getpid() + (unsigned)time(NULL));
+	
+	while(alloc->track_used < alloc->track_len) {
+		double r;
+		uint32_t index;
+		int tries = 0;
+
+		do {
+			r = ((double)rand() / ((double)(RAND_MAX)+(double)(1)));
+			index = (int) (r * alloc->track_len);
+			tries++;
+		} while((alloc->track[index] || index >= alloc->track_len) && tries < 10000);
+		
+		while(alloc->track[index]) {
+			if (++index >= alloc->track_len) {
+				index = 0;
+			}
+		}
+
+		if (index < alloc->track_len) {
+			alloc->track[index] = 1;
+			alloc->track_used++;
+			status = SWITCH_STATUS_SUCCESS;
+
+			if ((even && odd)) {
+				port = (switch_port_t)(index + alloc->start);
+			} else {
+				port = (switch_port_t)(index + (alloc->start / 2));
+				port *= 2;
+			} 
+			goto end;
+		}
+	}
+	
+	
+ end:
 
-	if ((ptr = switch_loadable_module_get_management_interface(relative_oid))) {
-		status = ptr->management_function(relative_oid, action, data, datalen);
+	switch_mutex_unlock(alloc->mutex);
+	
+	if (status == SWITCH_STATUS_SUCCESS) {
+		*port_ptr = port;
+	} else {
+		*port_ptr = 0;
 	}
 
+	
 	return status;
+	
 }
 
 
-
-SWITCH_DECLARE(switch_port_t) switch_core_port_allocator_request_port(switch_core_port_allocator_t *alloc)
+SWITCH_DECLARE(switch_status_t) switch_core_port_allocator_free_port(switch_core_port_allocator_t *alloc, switch_port_t port)
 {
-	switch_port_t port;
+	switch_status_t status = SWITCH_STATUS_FALSE;
+	int even = switch_test_flag(alloc, SPF_EVEN);
+	int odd = switch_test_flag(alloc, SPF_ODD);
+	int index = port - alloc->start;
+	
+	if (!(even && odd)) {
+		index /= 2;
+	}
 
 	switch_mutex_lock(alloc->mutex);
-	port = alloc->next;
-	alloc->next = alloc->next + alloc->inc;
-	if (alloc->next > alloc->end) {
-		alloc->next = alloc->start;
+	if (alloc->track[index]) {
+		alloc->track[index] = 0;
+		alloc->track_used--;
+		status = SWITCH_STATUS_SUCCESS;
 	}
 	switch_mutex_unlock(alloc->mutex);
-	return port;
+
+	return status;
 }
 
+
 SWITCH_DECLARE(void) switch_core_port_allocator_destroy(switch_core_port_allocator_t **alloc)
 {
 	switch_memory_pool_t *pool = (*alloc)->pool;

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_session.c
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_session.c	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_session.c	Tue Dec 11 16:35:05 2007
@@ -144,14 +144,14 @@
 
 SWITCH_DECLARE(void *) switch_core_session_get_private(switch_core_session_t *session)
 {
-	assert(session != NULL);
+	switch_assert(session != NULL);
 	return session->private_info;
 }
 
 
 SWITCH_DECLARE(switch_status_t) switch_core_session_set_private(switch_core_session_t *session, void *private_info)
 {
-	assert(session != NULL);
+	switch_assert(session != NULL);
 	session->private_info = private_info;
 	return SWITCH_STATUS_SUCCESS;
 }
@@ -231,7 +231,7 @@
 		return SWITCH_CAUSE_CHAN_NOT_IMPLEMENTED;
 	}
 
-	assert(*new_session != NULL);
+	switch_assert(*new_session != NULL);
 	
 	if (*new_session) {
 		switch_caller_profile_t *profile = NULL, *peer_profile = NULL, *cloned_profile = NULL;
@@ -270,13 +270,13 @@
 					int x;
 
 					for (x = 0; x < argc; x++) {
-						const char *val;
-						if ((val = switch_channel_get_variable(channel, argv[x]))) {
-							char *var = argv[x];
-							if (!strncasecmp(var, "nolocal:", 8)) {
-								var += 8;
+						const char *vval;
+						if ((vval = switch_channel_get_variable(channel, argv[x]))) {
+							char *vvar = argv[x];
+							if (!strncasecmp(vvar, "nolocal:", 8)) {
+								vvar += 8;
 							}
-							switch_channel_set_variable(peer_channel, var, val);
+							switch_channel_set_variable(peer_channel, vvar, vval);
 						}
 					}
 				}
@@ -321,7 +321,7 @@
 	switch_io_event_hook_receive_message_t *ptr;
 	switch_status_t status = SWITCH_STATUS_SUCCESS;
 
-	assert(session != NULL);
+	switch_assert(session != NULL);
 
 	if (session->endpoint_interface->io_routines->receive_message) {
 		status = session->endpoint_interface->io_routines->receive_message(session, message);
@@ -348,10 +348,10 @@
 	switch_channel_t *channel;
 	switch_status_t status = SWITCH_STATUS_SUCCESS;
 
-	assert(session != NULL);
+	switch_assert(session != NULL);
 	
 	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE)) && (other_session = switch_core_session_locate(uuid))) {
 		msg.message_id = indication;
@@ -385,7 +385,7 @@
 {
 	switch_status_t status = SWITCH_STATUS_FALSE;
 
-	assert(session != NULL);
+	switch_assert(session != NULL);
 
 	if (session->message_queue) {
 		if (switch_queue_trypush(session->message_queue, message) == SWITCH_STATUS_SUCCESS) {
@@ -401,7 +401,7 @@
 	switch_status_t status = SWITCH_STATUS_FALSE;
 	void *pop;
 
-	assert(session != NULL);
+	switch_assert(session != NULL);
 
 	if (session->message_queue) {
 		if ((status = (switch_status_t) switch_queue_trypop(session->message_queue, &pop)) == SWITCH_STATUS_SUCCESS) {
@@ -433,7 +433,7 @@
 	switch_io_event_hook_receive_event_t *ptr;
 	switch_status_t status = SWITCH_STATUS_FALSE;
 
-	assert(session != NULL);
+	switch_assert(session != NULL);
 
 	/* Acquire a read lock on the session or forget it the channel is dead */
 	if (switch_core_session_read_lock(session) == SWITCH_STATUS_SUCCESS) {
@@ -470,7 +470,7 @@
 {
 	switch_status_t status = SWITCH_STATUS_FALSE;
 
-	assert(session != NULL);
+	switch_assert(session != NULL);
 
 	if (session->event_queue) {
 		if (switch_queue_trypush(session->event_queue, *event) == SWITCH_STATUS_SUCCESS) {
@@ -496,7 +496,7 @@
 	switch_status_t status = SWITCH_STATUS_FALSE;
 	void *pop;
 
-	assert(session != NULL);
+	switch_assert(session != NULL);
 
 	if (session->event_queue) {
 		if ((status = (switch_status_t) switch_queue_trypop(session->event_queue, &pop)) == SWITCH_STATUS_SUCCESS) {
@@ -511,7 +511,7 @@
 {
 	switch_status_t status = SWITCH_STATUS_FALSE;
 
-	assert(session != NULL);
+	switch_assert(session != NULL);
 
 	if (session->private_event_queue) {
 		(*event)->event_id = SWITCH_EVENT_PRIVATE_COMMAND;
@@ -540,10 +540,10 @@
 	void *pop;
 	switch_channel_t *channel;
 
-	assert(session != NULL);
+	switch_assert(session != NULL);
 
 	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	
 	if (switch_channel_test_flag(channel, CF_EVENT_LOCK)) {
@@ -849,8 +849,8 @@
 
 SWITCH_DECLARE(uint8_t) switch_core_session_compare(switch_core_session_t *a, switch_core_session_t *b)
 {
-	assert(a != NULL);
-	assert(b != NULL);
+	switch_assert(a != NULL);
+	switch_assert(b != NULL);
 
 	return (uint8_t) (a->endpoint_interface == b->endpoint_interface);
 }
@@ -911,7 +911,7 @@
 
 	log = switch_core_session_alloc(session, sizeof(*log));
 
-	assert(log != NULL);
+	switch_assert(log != NULL);
 
 	log->app = switch_core_session_strdup(session, application_interface->interface_name);
 	log->arg = switch_core_session_strdup(session, arg);

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_speech.c
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_speech.c	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_speech.c	Tue Dec 11 16:35:05 2007
@@ -87,14 +87,14 @@
 
 SWITCH_DECLARE(switch_status_t) switch_core_speech_feed_tts(switch_speech_handle_t *sh, char *text, switch_speech_flag_t *flags)
 {
-	assert(sh != NULL);
+	switch_assert(sh != NULL);
 
 	return sh->speech_interface->speech_feed_tts(sh, text, flags);
 }
 
 SWITCH_DECLARE(void) switch_core_speech_flush_tts(switch_speech_handle_t *sh)
 {
-	assert(sh != NULL);
+	switch_assert(sh != NULL);
 
 	if (sh->speech_interface->speech_flush_tts) {
 		sh->speech_interface->speech_flush_tts(sh);
@@ -103,7 +103,7 @@
 
 SWITCH_DECLARE(void) switch_core_speech_text_param_tts(switch_speech_handle_t *sh, char *param, const char *val)
 {
-	assert(sh != NULL);
+	switch_assert(sh != NULL);
 
 	if (sh->speech_interface->speech_text_param_tts) {
 		sh->speech_interface->speech_text_param_tts(sh, param, val);
@@ -112,7 +112,7 @@
 
 SWITCH_DECLARE(void) switch_core_speech_numeric_param_tts(switch_speech_handle_t *sh, char *param, int val)
 {
-	assert(sh != NULL);
+	switch_assert(sh != NULL);
 
 	if (sh->speech_interface->speech_numeric_param_tts) {
 		sh->speech_interface->speech_numeric_param_tts(sh, param, val);
@@ -121,7 +121,7 @@
 
 SWITCH_DECLARE(void) switch_core_speech_float_param_tts(switch_speech_handle_t *sh, char *param, double val)
 {
-	assert(sh != NULL);
+	switch_assert(sh != NULL);
 
 	if (sh->speech_interface->speech_float_param_tts) {
 		sh->speech_interface->speech_float_param_tts(sh, param, val);
@@ -131,7 +131,7 @@
 SWITCH_DECLARE(switch_status_t) switch_core_speech_read_tts(switch_speech_handle_t *sh,
 															void *data, switch_size_t *datalen, uint32_t * rate, switch_speech_flag_t *flags)
 {
-	assert(sh != NULL);
+	switch_assert(sh != NULL);
 
 	return sh->speech_interface->speech_read_tts(sh, data, datalen, rate, flags);
 }

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_sqldb.c
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_sqldb.c	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_sqldb.c	Tue Dec 11 16:35:05 2007
@@ -154,10 +154,12 @@
 	uint8_t trans = 0, nothing_in_queue = 0;
 	uint32_t target = 1000;
 	switch_size_t len = 0, sql_len = SQLLEN;
-	char *sqlbuf = (char *) malloc(sql_len);
+	char *tmp, *sqlbuf = (char *) malloc(sql_len);
 	char *sql;
 	switch_size_t newlen;
 
+	switch_assert(sqlbuf);
+
 	if (!sql_manager.event_db) {
 		sql_manager.event_db = switch_core_db_handle();
 	}
@@ -180,10 +182,12 @@
 					itterations++;
 					if (len + newlen > sql_len) {
 						sql_len = len + SQLLEN;
-						if (!(sqlbuf = realloc(sqlbuf, sql_len))) {
+						if (!(tmp = realloc(sqlbuf, sql_len))) {
 							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "SQL thread ending on mem err\n");
+							abort();
 							break;
 						}
+						sqlbuf = tmp;
 					}
 					sprintf(sqlbuf + len, "%s;\n", sql);
 					len += newlen;

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_state_machine.c
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_state_machine.c	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/switch_core_state_machine.c	Tue Dec 11 16:35:05 2007
@@ -201,19 +201,19 @@
 
 static void switch_core_standard_on_transmit(switch_core_session_t *session)
 {
-	assert(session != NULL);
+	switch_assert(session != NULL);
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Standard TRANSMIT\n");
 }
 
 static void switch_core_standard_on_hold(switch_core_session_t *session)
 {
-	assert(session != NULL);
+	switch_assert(session != NULL);
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Standard HOLD\n");
 }
 
 static void switch_core_standard_on_hibernate(switch_core_session_t *session)
 {
-	assert(session != NULL);
+	switch_assert(session != NULL);
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Standard HIBERNATE\n");
 }
 
@@ -368,14 +368,14 @@
 
 
 	 */
-	assert(session != NULL);
+	switch_assert(session != NULL);
 
 	session->thread_running = 1;
 	endpoint_interface = session->endpoint_interface;
-	assert(endpoint_interface != NULL);
+	switch_assert(endpoint_interface != NULL);
 
 	driver_state_handler = endpoint_interface->state_handler;
-	assert(driver_state_handler != NULL);
+	switch_assert(driver_state_handler != NULL);
 
 	switch_mutex_lock(session->mutex);
 

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/switch_event.c
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/switch_event.c	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/switch_event.c	Tue Dec 11 16:35:05 2007
@@ -89,7 +89,7 @@
 {
     size_t len = strlen (s) + 1;
     void *new = malloc (len);
-	assert(new);
+	switch_assert(new);
 
     return (char *) memcpy (new, s, len);
 }
@@ -207,13 +207,13 @@
 	void *pop;
 	int i, len[3] = { 0, 0, 0 };
 
-	assert(thread != NULL);
-	assert(obj == NULL);
-	assert(POOL_LOCK != NULL);
-	assert(RUNTIME_POOL != NULL);
-	assert(EVENT_QUEUE_MUTEX != NULL);
-	assert(EVENT_QUEUE_HAVEMORE_MUTEX != NULL);
-	assert(EVENT_QUEUE_CONDITIONAL != NULL);
+	switch_assert(thread != NULL);
+	switch_assert(obj == NULL);
+	switch_assert(POOL_LOCK != NULL);
+	switch_assert(RUNTIME_POOL != NULL);
+	switch_assert(EVENT_QUEUE_MUTEX != NULL);
+	switch_assert(EVENT_QUEUE_HAVEMORE_MUTEX != NULL);
+	switch_assert(EVENT_QUEUE_CONDITIONAL != NULL);
 	THREAD_RUNNING = 1;
 
 	queues[0] = EVENT_QUEUE[SWITCH_PRIORITY_HIGH];
@@ -319,8 +319,8 @@
 
 SWITCH_DECLARE(char *) switch_event_name(switch_event_types_t event)
 {
-	assert(BLOCK != NULL);
-	assert(RUNTIME_POOL != NULL);
+	switch_assert(BLOCK != NULL);
+	switch_assert(RUNTIME_POOL != NULL);
 
 	return EVENT_NAMES[event];
 }
@@ -328,8 +328,8 @@
 SWITCH_DECLARE(switch_status_t) switch_name_event(char *name, switch_event_types_t *type)
 {
 	switch_event_types_t x;
-	assert(BLOCK != NULL);
-	assert(RUNTIME_POOL != NULL);
+	switch_assert(BLOCK != NULL);
+	switch_assert(RUNTIME_POOL != NULL);
 
 	for (x = 0; x <= SWITCH_EVENT_ALL; x++) {
 		if ((strlen(name) > 13 && !strcasecmp(name + 13, EVENT_NAMES[x])) || !strcasecmp(name, EVENT_NAMES[x])) {
@@ -347,8 +347,8 @@
 
 	switch_event_subclass_t *subclass;
 
-	assert(RUNTIME_POOL != NULL);
-	assert(CUSTOM_HASH != NULL);
+	switch_assert(RUNTIME_POOL != NULL);
+	switch_assert(CUSTOM_HASH != NULL);
 
 	if (switch_core_hash_find(CUSTOM_HASH, subclass_name)) {
 		return SWITCH_STATUS_INUSE;
@@ -448,7 +448,7 @@
 	switch_find_local_ip(guess_ip_v4, sizeof(guess_ip_v4), AF_INET);
 	switch_find_local_ip(guess_ip_v6, sizeof(guess_ip_v6), AF_INET6);
 
-	assert(pool != NULL);
+	switch_assert(pool != NULL);
 	THRUNTIME_POOL = RUNTIME_POOL = pool;
 
 	/*
@@ -501,7 +501,7 @@
 		*event = (switch_event_t *) pop;
 	} else {
 		*event = ALLOC(sizeof(switch_event_t));
-		assert(*event);
+		switch_assert(*event);
 	}
 
 	memset(*event, 0, sizeof(switch_event_t));
@@ -594,7 +594,7 @@
 			header = (switch_event_header_t *) pop;
 		} else {
 			header = ALLOC(sizeof(*header));
-			assert(header);
+			switch_assert(header);
 		}
 
 		memset(header, 0, sizeof(*header));
@@ -850,6 +850,7 @@
 		ret = vasprintf(&data, fmt, ap);
 #else
 		data = (char *) malloc(2048);
+		switch_assert(data);
 		ret = vsnprintf(data, 2048, fmt, ap);
 #endif
 		va_end(ap);
@@ -899,12 +900,12 @@
 	switch_size_t retsize;
 	switch_time_t ts = switch_timestamp_now();
 
-	assert(BLOCK != NULL);
-	assert(RUNTIME_POOL != NULL);
-	assert(EVENT_QUEUE_HAVEMORE_MUTEX != NULL);
-	assert(EVENT_QUEUE_MUTEX != NULL);
-	assert(EVENT_QUEUE_CONDITIONAL != NULL);
-	assert(RUNTIME_POOL != NULL);
+	switch_assert(BLOCK != NULL);
+	switch_assert(RUNTIME_POOL != NULL);
+	switch_assert(EVENT_QUEUE_HAVEMORE_MUTEX != NULL);
+	switch_assert(EVENT_QUEUE_MUTEX != NULL);
+	switch_assert(EVENT_QUEUE_CONDITIONAL != NULL);
+	switch_assert(RUNTIME_POOL != NULL);
 
 	if (THREAD_RUNNING <= 0) {
 		/* sorry we're closed */
@@ -976,8 +977,8 @@
 	switch_event_node_t *event_node;
 	switch_event_subclass_t *subclass = NULL;
 
-	assert(BLOCK != NULL);
-	assert(RUNTIME_POOL != NULL);
+	switch_assert(BLOCK != NULL);
+	switch_assert(RUNTIME_POOL != NULL);
 
 	if (subclass_name) {
 		if ((subclass = switch_core_hash_find(CUSTOM_HASH, subclass_name)) == 0) {

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/switch_ivr.c
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/switch_ivr.c	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/switch_ivr.c	Tue Dec 11 16:35:05 2007
@@ -45,7 +45,7 @@
 	int32_t left, elapsed;
 
 	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	start = switch_time_now();
 
@@ -125,7 +125,7 @@
 	int sanity = 0;
 	
 	channel = switch_core_session_get_channel(session);
-    assert(channel != NULL);
+    switch_assert(channel != NULL);
 
 	if (!switch_channel_test_flag(channel, CF_UNICAST)) {
 			return SWITCH_STATUS_FALSE;
@@ -163,10 +163,10 @@
 	switch_codec_t *read_codec;
 
 	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	conninfo = switch_core_session_alloc(session, sizeof(*conninfo));
-	assert(conninfo != NULL);
+	switch_assert(conninfo != NULL);
 
 	conninfo->local_ip = switch_core_session_strdup(session, local_ip);
 	conninfo->local_port = local_port;
@@ -269,8 +269,8 @@
 	char *event_lock = switch_event_get_header(event, "event-lock");
 	switch_status_t status = SWITCH_STATUS_FALSE;
 
-	assert(channel != NULL);
-	assert(event != NULL);
+	switch_assert(channel != NULL);
+	switch_assert(event != NULL);
 
 	if (switch_strlen_zero(cmd)) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Command!\n");
@@ -382,7 +382,7 @@
 	switch_channel_t *channel;
 
 	channel = switch_core_session_get_channel(session);
-    assert(channel != NULL);
+    switch_assert(channel != NULL);
 
 	while (switch_core_session_dequeue_private_event(session, &event) == SWITCH_STATUS_SUCCESS) {
 		switch_ivr_parse_event(session, event);
@@ -404,7 +404,7 @@
 	switch_codec_t *read_codec = switch_core_session_get_read_codec(session);
 
 	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	if (!switch_channel_test_flag(channel, CF_ANSWERED)) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Careful, Channel is unaswered. Pre-answering...\n");
@@ -539,7 +539,7 @@
 	uint32_t elapsed;
 
 	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	if (!args->input_callback) {
 		return SWITCH_STATUS_GENERR;
@@ -606,7 +606,7 @@
 	uint32_t elapsed;
 
 	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	if (terminator != NULL)
 		*terminator = '\0';
@@ -680,7 +680,7 @@
 	msg.from = __FILE__;
 
 	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	switch_channel_set_flag(channel, CF_HOLD);
 	switch_channel_set_flag(channel, CF_SUSPEND);
@@ -711,7 +711,7 @@
 	msg.from = __FILE__;
 
 	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	switch_channel_clear_flag(channel, CF_HOLD);
 	switch_channel_clear_flag(channel, CF_SUSPEND);
@@ -747,7 +747,7 @@
 
 	if ((session = switch_core_session_locate(uuid))) {
 		channel = switch_core_session_get_channel(session);
-		assert(channel != NULL);
+		switch_assert(channel != NULL);
 		if ((flags & SMF_REBRIDGE) && !switch_channel_test_flag(channel, CF_ORIGINATOR)) {
 			swap = 1;
 		}
@@ -760,7 +760,7 @@
 				&& (other_uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BRIDGE_VARIABLE))
 				&& (other_session = switch_core_session_locate(other_uuid))) {
 				other_channel = switch_core_session_get_channel(other_session);
-				assert(other_channel != NULL);
+				switch_assert(other_channel != NULL);
 				switch_core_session_receive_message(other_session, &msg);
 				switch_channel_clear_state_handler(other_channel, NULL);
 				switch_core_session_rwunlock(other_session);
@@ -800,7 +800,7 @@
 	if ((session = switch_core_session_locate(uuid))) {
 		status = SWITCH_STATUS_SUCCESS;
 		channel = switch_core_session_get_channel(session);
-		assert(channel != NULL);
+		switch_assert(channel != NULL);
 
 		if ((flags & SMF_REBRIDGE) && !switch_channel_test_flag(channel, CF_ORIGINATOR)) {
 			swap = 1;
@@ -812,7 +812,7 @@
 			if ((flags & SMF_REBRIDGE) && (other_uuid = switch_channel_get_variable(channel, SWITCH_BRIDGE_VARIABLE)) &&
 				(other_session = switch_core_session_locate(other_uuid))) {
 				other_channel = switch_core_session_get_channel(other_session);
-				assert(other_channel != NULL);
+				switch_assert(other_channel != NULL);
 
 				switch_core_session_receive_message(other_session, &msg);
 				switch_channel_clear_state_handler(other_channel, NULL);
@@ -843,11 +843,11 @@
 	switch_channel_t *other_channel = NULL;
 	const char *uuid = NULL;
 
-	assert(session != NULL);
+	switch_assert(session != NULL);
 	switch_core_session_reset(session);
 
 	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	/* clear all state handlers */
 	switch_channel_clear_state_handler(channel, NULL);
@@ -893,7 +893,7 @@
 		
 		if (uuid && (other_session = switch_core_session_locate(uuid))) {
 			other_channel = switch_core_session_get_channel(other_session);
-			assert(other_channel != NULL);
+			switch_assert(other_channel != NULL);
 			switch_channel_set_variable(other_channel, SWITCH_SIGNAL_BOND_VARIABLE, NULL);
 			switch_core_session_rwunlock(other_session);
 		}
@@ -901,7 +901,7 @@
 		if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BRIDGE_VARIABLE))
 			&& (other_session = switch_core_session_locate(uuid))) {
 			other_channel = switch_core_session_get_channel(other_session);
-			assert(other_channel != NULL);
+			switch_assert(other_channel != NULL);
 
 			switch_channel_set_variable(channel, SWITCH_SIGNAL_BRIDGE_VARIABLE, NULL);
 			switch_channel_set_variable(other_channel, SWITCH_SIGNAL_BRIDGE_VARIABLE, NULL);
@@ -1309,7 +1309,7 @@
 	int cdr_off = 0, v_off = 0;
 
 	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	if (!(cdr = switch_xml_new("cdr"))) {
 		return SWITCH_STATUS_SUCCESS;

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/switch_ivr_async.c
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/switch_ivr_async.c	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/switch_ivr_async.c	Tue Dec 11 16:35:05 2007
@@ -174,7 +174,7 @@
 	switch_media_bug_t *bug;
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 	if ((bug = switch_channel_get_private(channel, file))) {
 		switch_channel_set_private(channel, file, NULL);
 		switch_core_media_bug_remove(session, &bug);
@@ -196,7 +196,7 @@
 
 
 	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	if ((bug = switch_channel_get_private(channel, file))) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Only 1 of the same file per channel please!\n");
@@ -210,7 +210,7 @@
 
 
 	read_codec = switch_core_session_get_read_codec(session);
-	assert(read_codec != NULL);
+	switch_assert(read_codec != NULL);
 
 	dh->fh.channels = read_codec->implementation->number_of_channels;
 	dh->fh.samplerate = read_codec->implementation->actual_samples_per_second;
@@ -272,9 +272,9 @@
 			switch_channel_t *channel;
 			
 			session = switch_core_media_bug_get_session(bug);
-			assert(session != NULL);
+			switch_assert(session != NULL);
 			channel = switch_core_session_get_channel(session);
-			assert(channel != NULL);
+			switch_assert(channel != NULL);
 			
 			if (switch_core_media_bug_read(bug, &frame) == SWITCH_STATUS_SUCCESS) {
 				int doit = 1;
@@ -302,7 +302,7 @@
 	switch_media_bug_t *bug;
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 	if ((bug = switch_channel_get_private(channel, file))) {
 		switch_channel_set_private(channel, file, NULL);
 		switch_core_media_bug_remove(session, &bug);
@@ -595,7 +595,7 @@
 	switch_media_bug_flag_t flags = SMBF_READ_STREAM | SMBF_WRITE_STREAM;
 	uint8_t channels;
 	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	if ((bug = switch_channel_get_private(channel, file))) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Only 1 of the same file per channel please!\n");
@@ -609,7 +609,7 @@
 	}
 
 	read_codec = switch_core_session_get_read_codec(session);
-	assert(read_codec != NULL);
+	switch_assert(read_codec != NULL);
 
 	channels = read_codec->implementation->number_of_channels;
 
@@ -703,7 +703,7 @@
 	char digit_str[80];
 	switch_channel_t *channel = switch_core_session_get_channel(pvt->session);
 
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 	frame.data = data;
 	frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE;
 
@@ -735,7 +735,7 @@
 	switch_media_bug_t *bug;
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 	if ((bug = switch_channel_get_private(channel, "dtmf"))) {
 		switch_channel_set_private(channel, "dtmf", NULL);
 		switch_core_media_bug_remove(session, &bug);
@@ -755,10 +755,10 @@
 	switch_inband_dtmf_t *pvt;
 
 	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	read_codec = switch_core_session_get_read_codec(session);
-	assert(read_codec != NULL);
+	switch_assert(read_codec != NULL);
 
 	if (!(pvt = switch_core_session_alloc(session, sizeof(*pvt)))) {
 		return SWITCH_STATUS_MEMERR;
@@ -885,7 +885,7 @@
 	switch_media_bug_t *bug;
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 	if ((bug = switch_channel_get_private(channel, "dtmf_generate"))) {
 		switch_channel_set_private(channel, "dtmf_generate", NULL);
 		switch_core_media_bug_remove(session, &bug);
@@ -905,10 +905,10 @@
 	switch_inband_dtmf_generate_t *pvt;
 
 	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	read_codec = switch_core_session_get_read_codec(session);
-	assert(read_codec != NULL);
+	switch_assert(read_codec != NULL);
 
 	if (!(pvt = switch_core_session_alloc(session, sizeof(*pvt)))) {
 		return SWITCH_STATUS_MEMERR;
@@ -1014,7 +1014,7 @@
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 	switch_tone_container_t *cont;
 	
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 	if ((cont = switch_channel_get_private(channel, "_tone_detect_"))) {
 		switch_channel_set_private(channel, "_tone_detect_", NULL);
 		switch_core_media_bug_remove(session, &cont->bug);
@@ -1040,10 +1040,10 @@
   switch_media_bug_flag_t bflags = 0;
 
   channel = switch_core_session_get_channel(session);
-  assert(channel != NULL);
+  switch_assert(channel != NULL);
 
   read_codec = switch_core_session_get_read_codec(session);
-  assert(read_codec != NULL);
+  switch_assert(read_codec != NULL);
   
   if (switch_strlen_zero(key)) {
 	  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Key Specified!\n");
@@ -1268,7 +1268,7 @@
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 	struct speech_thread_handle *sth;
 
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 	if ((sth = switch_channel_get_private(channel, SWITCH_SPEECH_KEY))) {
 		switch_channel_set_private(channel, SWITCH_SPEECH_KEY, NULL);
 		switch_core_media_bug_remove(session, &sth->bug);
@@ -1286,7 +1286,7 @@
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 	struct speech_thread_handle *sth;
 
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 	if ((sth = switch_channel_get_private(channel, SWITCH_SPEECH_KEY))) {
 		switch_core_asr_pause(sth->ah);
 		return SWITCH_STATUS_SUCCESS;
@@ -1301,7 +1301,7 @@
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 	struct speech_thread_handle *sth;
 
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 	if ((sth = switch_channel_get_private(channel, SWITCH_SPEECH_KEY))) {
 		switch_core_asr_resume(sth->ah);
 		return SWITCH_STATUS_SUCCESS;
@@ -1318,7 +1318,7 @@
 	switch_asr_flag_t flags = SWITCH_ASR_FLAG_NONE;
 	struct speech_thread_handle *sth;
 
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 	if ((sth = switch_channel_get_private(channel, SWITCH_SPEECH_KEY))) {
 		if (switch_core_asr_load_grammar(sth->ah, grammar, path) != SWITCH_STATUS_SUCCESS) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error loading Grammar\n");
@@ -1340,7 +1340,7 @@
 	switch_asr_flag_t flags = SWITCH_ASR_FLAG_NONE;
 	struct speech_thread_handle *sth;
 
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 	if ((sth = switch_channel_get_private(channel, SWITCH_SPEECH_KEY))) {
 		if (switch_core_asr_unload_grammar(sth->ah, grammar) != SWITCH_STATUS_SUCCESS) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error unloading Grammar\n");
@@ -1376,10 +1376,10 @@
 	}
 
 	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	read_codec = switch_core_session_get_read_codec(session);
-	assert(read_codec != NULL);
+	switch_assert(read_codec != NULL);
 
 
 	if ((val = switch_channel_get_variable(channel, "fire_asr_events"))) {
@@ -1443,7 +1443,7 @@
 	switch_core_session_t *session, *other_session;
 	const char *other_uuid;
 
-	assert(task);
+	switch_assert(task);
 
 	helper = (struct hangup_helper *) task->cmd_arg;
 
@@ -1492,7 +1492,7 @@
 	struct transfer_helper *helper;
 	switch_core_session_t *session;
 
-	assert(task);
+	switch_assert(task);
 
 	helper = (struct transfer_helper *) task->cmd_arg;
 
@@ -1558,7 +1558,7 @@
 SWITCH_STANDARD_SCHED_FUNC(sch_broadcast_callback)
 {
 	struct broadcast_helper *helper;
-	assert(task);
+	switch_assert(task);
 
 	helper = (struct broadcast_helper *) task->cmd_arg;
 	switch_ivr_broadcast(helper->uuid_str, helper->path, helper->flags);
@@ -1593,7 +1593,7 @@
 	const char *other_uuid = NULL;
 	char *app = "playback";
 
-	assert(path);
+	switch_assert(path);
 
 	if ((session = switch_core_session_locate(uuid))) {
 		char *cause = NULL;
@@ -1603,7 +1603,7 @@
 		master = session;
 
 		channel = switch_core_session_get_channel(session);
-		assert(channel != NULL);
+		switch_assert(channel != NULL);
 
 		if ((switch_channel_test_flag(channel, CF_EVENT_PARSE))) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Channel [%s] already broadcasting...broadcast aborted\n", 

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/switch_ivr_bridge.c
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/switch_ivr_bridge.c	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/switch_ivr_bridge.c	Tue Dec 11 16:35:05 2007
@@ -233,7 +233,7 @@
 	switch_ivr_bridge_data_t *bd;
 
 	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	if ((bd = (switch_ivr_bridge_data_t *) switch_channel_get_private(channel, "_bridge_"))) {
 		switch_channel_set_private(channel, "_bridge_", NULL);
@@ -260,7 +260,7 @@
 	switch_channel_t *channel = NULL;
 
 	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CUSTOM RING\n", switch_channel_get_name(channel));
 
@@ -274,7 +274,7 @@
 	switch_channel_t *channel = NULL;
 
 	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CUSTOM HOLD\n", switch_channel_get_name(channel));
 
@@ -298,7 +298,7 @@
 	switch_channel_t *channel = NULL;
 
 	channel = switch_core_session_get_channel(session);
-    assert(channel != NULL);
+    switch_assert(channel != NULL);
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CUSTOM RESET\n", switch_channel_get_name(channel));
 
@@ -318,7 +318,7 @@
 	const char *other_uuid = NULL;
 
 	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CUSTOM TRANSMIT\n", switch_channel_get_name(channel));
 	switch_channel_clear_state_handler(channel, NULL);
@@ -407,7 +407,7 @@
 	switch_channel_t *channel = NULL;
 
 	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 	switch_channel_clear_flag(channel, CF_TRANSFER);
 
 	switch_channel_set_variable(channel, SWITCH_BRIDGE_VARIABLE, switch_channel_get_variable(channel, SWITCH_SIGNAL_BRIDGE_VARIABLE));
@@ -423,7 +423,7 @@
 	switch_event_t *event;
 
 	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	if (switch_channel_test_flag(channel, CF_ORIGINATOR)) {
 		switch_channel_clear_flag(channel, CF_ORIGINATOR);
@@ -439,7 +439,7 @@
 		switch_channel_t *other_channel = NULL;
 
 		other_channel = switch_core_session_get_channel(other_session);
-		assert(other_channel != NULL);
+		switch_assert(other_channel != NULL);
 
 		switch_channel_set_variable(channel, SWITCH_SIGNAL_BRIDGE_VARIABLE, NULL);
 		switch_channel_set_variable(other_channel, SWITCH_SIGNAL_BRIDGE_VARIABLE, NULL);
@@ -480,10 +480,10 @@
 	switch_event_t *event;
 
 	caller_channel = switch_core_session_get_channel(session);
-	assert(caller_channel != NULL);
+	switch_assert(caller_channel != NULL);
 
 	peer_channel = switch_core_session_get_channel(peer_session);
-	assert(peer_channel != NULL);
+	switch_assert(peer_channel != NULL);
 
 	if (!switch_channel_ready(peer_channel)) {
 		switch_channel_hangup(caller_channel, switch_channel_get_cause(peer_channel));
@@ -547,21 +547,21 @@
 	int stream_id = 0;
 	switch_status_t status = SWITCH_STATUS_SUCCESS;
 	
-	assert(session != NULL);
-	assert(peer_session != NULL);
+	switch_assert(session != NULL);
+	switch_assert(peer_session != NULL);
 
 	caller_channel = switch_core_session_get_channel(session);
-	assert(caller_channel != NULL);
+	switch_assert(caller_channel != NULL);
 
 	switch_channel_set_flag(caller_channel, CF_ORIGINATOR);
 
 	peer_channel = switch_core_session_get_channel(peer_session);
-	assert(peer_channel != NULL);
+	switch_assert(peer_channel != NULL);
 
 	a_leg = switch_core_session_alloc(session, sizeof(*a_leg));
 	b_leg = switch_core_session_alloc(peer_session, sizeof(*b_leg));
 	
-	assert(a_leg && b_leg);
+	switch_assert(a_leg && b_leg);
 
 	b_leg->session = peer_session;
 	switch_copy_string(b_leg->b_uuid, switch_core_session_get_uuid(session), sizeof(b_leg->b_uuid));

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/switch_ivr_originate.c
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/switch_ivr_originate.c	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/switch_ivr_originate.c	Tue Dec 11 16:35:05 2007
@@ -38,7 +38,7 @@
 	switch_channel_t *channel = NULL;
 
 	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	/* put the channel in a passive state so we can loop audio to it */
 
@@ -323,7 +323,7 @@
 		switch_event_header_t *hi;
 
 		caller_channel = switch_core_session_get_channel(session);
-		assert(caller_channel != NULL);
+		switch_assert(caller_channel != NULL);
 
 		/* Copy all the applicable channel variables into the event */
 		if ((hi = switch_channel_variable_first(caller_channel))) {
@@ -444,7 +444,7 @@
 	for (try = 0; try < retries; try++) {
 		switch_safe_free(loop_data);
 		loop_data = strdup(data);
-		assert(loop_data);
+		switch_assert(loop_data);
 		or_argc = switch_separate_string(loop_data, '|', pipe_names, (sizeof(pipe_names) / sizeof(pipe_names[0])));
 
 		if (caller_channel && or_argc > 1 && !ringback_data) {
@@ -574,7 +574,7 @@
 				caller_profiles[i] = new_profile;
 				peer_sessions[i] = new_session;
 				peer_channels[i] = switch_core_session_get_channel(new_session);
-				assert(peer_channels[i] != NULL);
+				switch_assert(peer_channels[i] != NULL);
 
 
 				if (var_event) {
@@ -585,7 +585,7 @@
 						switch_channel_set_variable(peer_channels[i], header->name, header->value);
 					}
 					switch_event_create(&event, SWITCH_EVENT_CHANNEL_ORIGINATE);
-					assert(event);
+					switch_assert(event);
 					switch_channel_event_set_data(peer_channels[i], event);
 					switch_event_fire(&event);
 				}

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/switch_ivr_play_say.c
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/switch_ivr_play_say.c	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/switch_ivr_play_say.c	Tue Dec 11 16:35:05 2007
@@ -103,7 +103,7 @@
 	int matches = 0;
 
 	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	if (!macro_name) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No phrase macro specified.\n");
@@ -356,10 +356,10 @@
 	}
 
 	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	read_codec = switch_core_session_get_read_codec(session);
-	assert(read_codec != NULL);
+	switch_assert(read_codec != NULL);
 
 	fh->channels = read_codec->implementation->number_of_channels;
 
@@ -602,10 +602,10 @@
 	switch_byte_t data[1024];
 	switch_channel_t *channel;
 
-	assert(session != NULL);
+	switch_assert(session != NULL);
 
 	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	switch_channel_pre_answer(channel);
 	read_codec = switch_core_session_get_read_codec(session);
@@ -711,7 +711,7 @@
 	const char *prebuf;
 
 	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	prefix = switch_channel_get_variable(channel, "sound_prefix");
 	timer_name = switch_channel_get_variable(channel, "timer_name");
@@ -819,7 +819,7 @@
 					  "ARTIST=%s\n" "COMMENT=%s\n" "DATE=%s\n", file, fh->samplerate, fh->channels, title, copyright, software, artist, comment, date);
 #endif
 
-	assert(read_codec != NULL);
+	switch_assert(read_codec != NULL);
 	interval = read_codec->implementation->microseconds_per_frame / 1000;
 
 	if (!fh->audio_buffer) {
@@ -1137,7 +1137,7 @@
 	channel = switch_core_session_get_channel(session);
 
 	//Make sure somebody is home
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	//Answer the channel if it hasn't already been answered
 	switch_channel_answer(channel);
@@ -1254,7 +1254,7 @@
 	switch_size_t starlen, poundlen;
 	
 	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	if (!sh) {
 		return SWITCH_STATUS_FALSE;
@@ -1320,7 +1320,7 @@
 	write_frame.samples = len / 2;
 	write_frame.codec = codec;
 
-	assert(codec->implementation != NULL);
+	switch_assert(codec->implementation != NULL);
 
 	for (x = 0; !done && x < lead_in_out; x++) {
 		switch_yield(codec->implementation->microseconds_per_frame);
@@ -1502,7 +1502,7 @@
 	switch_channel_t *channel;
 
 	channel = switch_core_session_get_channel(session);
-    assert(channel != NULL);
+    switch_assert(channel != NULL);
 
 	if ((cache_obj = switch_channel_get_private(channel, SWITCH_CACHE_SPEECH_HANDLES_OBJ_NAME))) {
 		switch_speech_flag_t flags = SWITCH_SPEECH_FLAG_NONE;
@@ -1539,7 +1539,7 @@
 	int need_create = 1, need_alloc = 1;
 	
 	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
+	switch_assert(channel != NULL);
 
 	sh = &lsh;
 	codec = &lcodec;

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/switch_loadable_module.c
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/switch_loadable_module.c	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/switch_loadable_module.c	Tue Dec 11 16:35:05 2007
@@ -83,8 +83,8 @@
 	switch_loadable_module_t *module = ts->objs[0];
 	int restarts;
 
-	assert(thread != NULL);
-	assert(module != NULL);
+	switch_assert(thread != NULL);
+	switch_assert(module != NULL);
 
 	for (restarts = 0; status != SWITCH_STATUS_TERM; restarts++) {
 		status = module->switch_module_runtime();
@@ -653,7 +653,7 @@
 	char derr[512] = "";
 	switch_memory_pool_t *pool;
 
-	assert(path != NULL);
+	switch_assert(path != NULL);
 
 	switch_core_new_memory_pool(&pool);
 	*new_module = NULL;
@@ -1030,7 +1030,6 @@
 
 		while (apr_dir_read(&finfo, finfo_flags, module_dir_handle) == APR_SUCCESS) {
 			const char *fname = finfo.fname;
-			const char *err;
 
 			if (finfo.filetype != APR_REG) {
 				continue;
@@ -1060,7 +1059,7 @@
 
 static void do_shutdown(switch_loadable_module_t *module)
 {
-	assert(module != NULL);
+	switch_assert(module != NULL);
 
 	switch_loadable_module_unprocess(module);
 	if (module->switch_module_shutdown) {
@@ -1328,9 +1327,9 @@
 	switch_api_interface_t *api;
 	switch_status_t status;
 
-	assert(stream != NULL);
-	assert(stream->data != NULL);
-	assert(stream->write_function != NULL);
+	switch_assert(stream != NULL);
+	switch_assert(stream->data != NULL);
+	switch_assert(stream->write_function != NULL);
 
 	if (!stream->event) {
 		switch_event_create(&stream->event, SWITCH_EVENT_API);
@@ -1366,7 +1365,7 @@
 	switch_loadable_module_interface_t *mod;
 
 	mod = switch_core_alloc(pool, sizeof(switch_loadable_module_interface_t));
-	assert(mod != NULL);
+	switch_assert(mod != NULL);
 
 	mod->pool = pool;
 
@@ -1378,7 +1377,7 @@
 #define ALLOC_INTERFACE(_TYPE_)	{									\
 		switch_##_TYPE_##_interface_t *i, *ptr;							\
 		i = switch_core_alloc(mod->pool, sizeof(switch_##_TYPE_##_interface_t)); \
-		assert(i != NULL);												\
+		switch_assert(i != NULL);												\
 		for (ptr = mod->_TYPE_##_interface; ptr && ptr->next; ptr = ptr->next); \
 		if (ptr) {														\
 			ptr->next = i;												\

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/switch_log.c
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/switch_log.c	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/switch_log.c	Tue Dec 11 16:35:05 2007
@@ -77,10 +77,10 @@
 	char *p = strdup(str);
 	switch_log_level_t level;
 
-	assert(p);
+	switch_assert(p);
 
 	if ((argc = switch_separate_string(p, ',', argv, (sizeof(argv) / sizeof(argv[0]))))) {
-		for (x = 0; x < argc; x++) {
+		for (x = 0; x < argc && argv[x]; x++) {
 			if (!strcasecmp(argv[x], "all")) {
 				mask = 0xFF;
 				break;
@@ -121,7 +121,7 @@
 SWITCH_DECLARE(switch_status_t) switch_log_bind_logger(switch_log_function_t function, switch_log_level_t level)
 {
 	switch_log_binding_t *binding = NULL, *ptr = NULL;
-	assert(function != NULL);
+	switch_assert(function != NULL);
 
 	if (!(binding = switch_core_alloc(LOG_POOL, sizeof(*binding)))) {
 		return SWITCH_STATUS_MEMERR;
@@ -221,6 +221,7 @@
 
 		len = (uint32_t) (strlen(extra_fmt) + strlen(date) + strlen(filep) + 32 + strlen(funcp) + strlen(fmt));
 		new_fmt = malloc(len + 1);
+		switch_assert(new_fmt);
 		snprintf(new_fmt, len, extra_fmt, date, switch_log_level2str(level), filep, line, funcp, 128, fmt);
 		fmt = new_fmt;
 	}
@@ -263,7 +264,7 @@
 					node = (switch_log_node_t *) pop;
 				} else {
 					node = malloc(sizeof(*node));
-					assert(node);			
+					switch_assert(node);			
 				}
 
 				node->data = data;
@@ -292,7 +293,7 @@
 	switch_thread_t *thread;
 	switch_threadattr_t *thd_attr;;
 
-	assert(pool != NULL);
+	switch_assert(pool != NULL);
 
 	LOG_POOL = pool;
 

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/switch_odbc.c
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/switch_odbc.c	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/switch_odbc.c	Tue Dec 11 16:35:05 2007
@@ -320,7 +320,7 @@
 	SQLLEN m = 0, t = 0;
 	int result;
 
-	assert(callback != NULL);
+	switch_assert(callback != NULL);
 
 	if (!db_is_up(handle)) {
 		goto error;
@@ -358,7 +358,7 @@
 			names = calloc(c, sizeof(*names));
 			vals = calloc(c, sizeof(*vals));
 		
-			assert(names && vals);
+			switch_assert(names && vals);
 
 			for (x = 1; x <= c; x++) {
 				SQLSMALLINT NameLength, DataType, DecimalDigits, Nullable;
@@ -407,9 +407,10 @@
 {
 	switch_odbc_handle_t *handle = NULL;
 
-	if (handlep) {
-		handle = *handlep;
+	if (!handlep) {
+		return;
 	}
+	handle = *handlep;
 
 	if (handle) {
 		switch_odbc_handle_disconnect(handle);

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/switch_rtp.c
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/switch_rtp.c	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/switch_rtp.c	Tue Dec 11 16:35:05 2007
@@ -67,7 +67,7 @@
 #pragma pack()
 #endif
 
-
+static switch_hash_t *alloc_hash = NULL;
 
 typedef struct {
 	srtp_hdr_t header;
@@ -147,7 +147,8 @@
 	uint32_t flags;
 	switch_memory_pool_t *pool;
 	switch_sockaddr_t *from_addr;
-
+	char *rx_host;
+	switch_port_t rx_port;
 	char *ice_user;
 	char *user_ice;
 	char *timer_name;
@@ -182,8 +183,8 @@
 	unsigned int elapsed;
 	switch_size_t bytes;
 
-	assert(rtp_session != NULL);
-	assert(rtp_session->ice_user != NULL);
+	switch_assert(rtp_session != NULL);
+	switch_assert(rtp_session->ice_user != NULL);
 
 	if (rtp_session->stuncount != 0) {
 		rtp_session->stuncount--;
@@ -261,12 +262,17 @@
 	if (global_init) {
 		return;
 	}
-
+	switch_core_hash_init(&alloc_hash, pool);
 	srtp_init();
 	switch_mutex_init(&port_lock, SWITCH_MUTEX_NESTED, pool);
 	global_init = 1;
 }
 
+SWITCH_DECLARE(void) switch_rtp_shutdown(void)
+{
+	switch_core_hash_destroy(&alloc_hash);
+}
+
 SWITCH_DECLARE(switch_port_t) switch_rtp_set_start_port(switch_port_t port)
 {
 	if (port) {
@@ -304,16 +310,43 @@
         return END_PORT;
 }
 
-SWITCH_DECLARE(switch_port_t) switch_rtp_request_port(void)
+static void release_port(switch_rtp_t *rtp_session)
 {
-	switch_port_t port;
+	switch_core_port_allocator_t *alloc = NULL;
 
+	if (!rtp_session->rx_host) {
+		return;
+	}
+
+    switch_mutex_lock(port_lock);
+    if ((alloc = switch_core_hash_find(alloc_hash, rtp_session->rx_host))) {
+		switch_core_port_allocator_free_port(alloc, rtp_session->rx_port);
+	}
+	switch_mutex_unlock(port_lock);
+
+}
+
+SWITCH_DECLARE(switch_port_t) switch_rtp_request_port(const char *ip)
+{
+	switch_port_t port = 0;
+	switch_core_port_allocator_t *alloc = NULL;
+	
 	switch_mutex_lock(port_lock);
-	port = NEXT_PORT;
-	NEXT_PORT += 2;
-	if (NEXT_PORT > END_PORT) {
-		NEXT_PORT = START_PORT;
+	alloc = switch_core_hash_find(alloc_hash, ip);
+	if (!alloc) {
+		if (switch_core_port_allocator_new(START_PORT, END_PORT, SPF_EVEN, &alloc) != SWITCH_STATUS_SUCCESS) {
+			port = 0;
+			goto end;
+		}
+
+		switch_core_hash_insert(alloc_hash, ip, alloc);
+	}
+	
+	if (switch_core_port_allocator_request_port(alloc, &port) != SWITCH_STATUS_SUCCESS) {
+		port = 0;
 	}
+
+ end:
 	switch_mutex_unlock(port_lock);
 	return port;
 }
@@ -379,7 +412,8 @@
 		*err = "Send myself a packet failed!";
 		goto done;
 	}
-
+	release_port(rtp_session);
+	
 	old_sock = rtp_session->sock;
 	rtp_session->sock = new_sock;
 	new_sock = NULL;
@@ -395,7 +429,9 @@
 
   done:
 
-	if (status != SWITCH_STATUS_SUCCESS) {
+	if (status == SWITCH_STATUS_SUCCESS) {
+		rtp_session->rx_host = switch_core_strdup(rtp_session->pool, host);
+		rtp_session->rx_port = port;
 		rtp_session->ready = 1;
 	}
 
@@ -632,10 +668,10 @@
 
 SWITCH_DECLARE(void) switch_rtp_kill_socket(switch_rtp_t *rtp_session)
 {
-	assert(rtp_session != NULL);
+	switch_assert(rtp_session != NULL);
 	switch_mutex_lock(rtp_session->flag_mutex);
 	if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_IO)) {
-		assert(rtp_session->sock != NULL);
+		switch_assert(rtp_session->sock != NULL);
 		switch_socket_shutdown(rtp_session->sock, SWITCH_SHUTDOWN_READWRITE);
 		switch_clear_flag(rtp_session, SWITCH_RTP_FLAG_IO);
 	}
@@ -653,6 +689,7 @@
 		return;
 	}
 
+
 	(*rtp_session)->ready = 0;
 
 	switch_mutex_lock((*rtp_session)->flag_mutex);
@@ -683,6 +720,8 @@
 		switch_core_timer_destroy(&(*rtp_session)->timer);
 	}
 
+	release_port(*rtp_session);
+
 	switch_mutex_unlock((*rtp_session)->flag_mutex);
 	return;
 }
@@ -1553,7 +1592,7 @@
 		return -1;
 	}
 
-	assert(frame != NULL);
+	switch_assert(frame != NULL);
 
 	if (switch_test_flag(frame, SFF_CNG)) {
 		payload = rtp_session->cng_pt;

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/switch_scheduler.c
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/switch_scheduler.c	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/switch_scheduler.c	Tue Dec 11 16:35:05 2007
@@ -158,7 +158,7 @@
 
 	switch_mutex_lock(globals.task_mutex);
 	switch_zmalloc(container, sizeof(*container));
-	assert(func);
+	switch_assert(func);
 	container->func = func;
 	container->task.created = time(NULL);
 	container->task.runtime = task_runtime;

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/switch_utils.c
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/switch_utils.c	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/switch_utils.c	Tue Dec 11 16:35:05 2007
@@ -45,7 +45,7 @@
 		s++;
 	}
 
-	if (*s == open) {
+	if (s && *s == open) {
 		depth++;
 		for (e = s + 1; e && *e; e++) {
 			if (*e == open) {
@@ -86,7 +86,7 @@
 {
 	char *p, *q;
 	switch_size_t x = 0;
-	assert(s);
+	switch_assert(s);
 
 	q = buf;
 
@@ -266,11 +266,11 @@
         }
 
         if (file) {
-			const char *filename = switch_cut_path(file);
+			const char *stipped_file = switch_cut_path(file);
 			const char *new_type;
 			char *ext;
 
-			if ((ext = strrchr(filename, '.'))) {
+			if ((ext = strrchr(stipped_file, '.'))) {
 				ext++;
 				if ((new_type = switch_core_mime_ext2type(ext))) {
 					mime_type = new_type;
@@ -283,7 +283,7 @@
 					 "Content-Transfer-Encoding: base64\n"
 					 "Content-Description: Sound attachment.\n"
 					 "Content-Disposition: attachment; filename=\"%s\"\n\n",
-					 bound, mime_type, filename, filename);
+					 bound, mime_type, stipped_file, stipped_file);
             if (!write_buf(fd, buf))
                 return SWITCH_FALSE;
 
@@ -379,6 +379,11 @@
 SWITCH_DECLARE(switch_bool_t) switch_ast2regex(char *pat, char *rbuf, size_t len)
 {
 	char *p = pat;
+
+	if (!pat) {
+		return SWITCH_FALSE;
+	}
+
 	memset(rbuf, 0, len);
 	
 	*(rbuf + strlen(rbuf)) = '^';
@@ -408,7 +413,7 @@
 
 	if (dup) {
 		p = strdup(str);
-		assert(p);
+		switch_assert(p);
 	} else {
 		p = str;
 	}
@@ -926,7 +931,7 @@
 
 SWITCH_DECLARE(char *) get_addr(char *buf, switch_size_t len, struct in_addr *in)
 {
-	assert(buf);
+	switch_assert(buf);
 	*buf = '\0';
 	if (in) {
 		switch_inet_ntop(AF_INET, in, buf, len);
@@ -1098,22 +1103,27 @@
 	size_t replace_len = strlen(replace);
 	size_t i, n;
 	size_t dest_len = 0;
-	char *dest;
+	char *dest, *tmp;
 
 	dest = (char *) malloc(sizeof(char));
+	switch_assert(dest);
 
 	for (i = 0; i < string_len; i++) {
 		if (switch_string_match(string + i, string_len - i, search, search_len) == SWITCH_STATUS_SUCCESS) {
 			for (n = 0; n < replace_len; n++) {
 				dest[dest_len] = replace[n];
 				dest_len++;
-				dest = (char *) realloc(dest, sizeof(char) * (dest_len + 1));
+				tmp = (char *) realloc(dest, sizeof(char) * (dest_len + 1));
+				switch_assert(tmp);
+				dest = tmp;
 			}
 			i += search_len - 1;
 		} else {
 			dest[dest_len] = string[i];
 			dest_len++;
-			dest = (char *) realloc(dest, sizeof(char) * (dest_len + 1));
+			tmp = (char *) realloc(dest, sizeof(char) * (dest_len + 1));
+			switch_assert(tmp);
+			dest = tmp;
 		}
 	}
 



More information about the Freeswitch-svn mailing list