[Freeswitch-svn] [commit] r4329 - in freeswitch/trunk/src: . include

Freeswitch SVN mikej at freeswitch.org
Mon Feb 19 17:57:27 EST 2007


Author: mikej
Date: Mon Feb 19 17:57:27 2007
New Revision: 4329

Modified:
   freeswitch/trunk/src/include/switch_channel.h
   freeswitch/trunk/src/switch_channel.c

Log:
switch_channel_set_variable_nodup which does not dup the value from the session pool.  The value MUST already be allocated from the pool for that session, or very bad things could happen.  Use with caution.

Modified: freeswitch/trunk/src/include/switch_channel.h
==============================================================================
--- freeswitch/trunk/src/include/switch_channel.h	(original)
+++ freeswitch/trunk/src/include/switch_channel.h	Mon Feb 19 17:57:27 2007
@@ -211,6 +211,15 @@
 SWITCH_DECLARE(switch_status_t) switch_channel_set_variable(switch_channel_t *channel, const char *varname, const char *value);
 
 /*!
+  \brief Set a variable on a given channel, without duplicating the value from the session pool.
+  \param channel channel to set variable on
+  \param varname the name of the variable
+  \param value the vaule of the variable (MUST BE ALLOCATED FROM THE SESSION POOL ALREADY)
+  \returns SWITCH_STATUS_SUCCESS if successful
+*/
+SWITCH_DECLARE(switch_status_t) switch_channel_set_variable_nodup(switch_channel_t *channel, const char *varname, char *value);
+
+/*!
   \brief Retrieve a variable from a given channel
   \param channel channel to retrieve variable from
   \param varname the name of the variable

Modified: freeswitch/trunk/src/switch_channel.c
==============================================================================
--- freeswitch/trunk/src/switch_channel.c	(original)
+++ freeswitch/trunk/src/switch_channel.c	Mon Feb 19 17:57:27 2007
@@ -373,6 +373,23 @@
 	return SWITCH_STATUS_FALSE;
 }
 
+SWITCH_DECLARE(switch_status_t) switch_channel_set_variable_nodup(switch_channel_t *channel, const char *varname, char *value)
+{
+	assert(channel != NULL);
+
+	if (varname) {
+		switch_core_hash_delete(channel->variables, varname);
+		if (!switch_strlen_zero(value)) {
+			switch_core_hash_insert_dup(channel->variables, varname, value);
+		} else {
+			switch_core_hash_delete(channel->variables, varname);
+		}
+		return SWITCH_STATUS_SUCCESS;
+	}
+
+	return SWITCH_STATUS_FALSE;
+}
+
 SWITCH_DECLARE(int) switch_channel_test_flag(switch_channel_t *channel, switch_channel_flag_t flags)
 {
 	assert(channel != NULL);



More information about the Freeswitch-svn mailing list