From 58705374f4896101e74d6a9ca2ef8c322d21e45e Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 19 Feb 2007 22:57:27 +0000 Subject: [PATCH] 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. git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4329 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_channel.h | 9 +++++++++ src/switch_channel.c | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/include/switch_channel.h b/src/include/switch_channel.h index 255516893d..49b563134c 100644 --- a/src/include/switch_channel.h +++ b/src/include/switch_channel.h @@ -210,6 +210,15 @@ SWITCH_DECLARE(char *) switch_channel_get_uuid(switch_channel_t *channel); */ 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 diff --git a/src/switch_channel.c b/src/switch_channel.c index 958cd269b9..77874f7126 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -373,6 +373,23 @@ SWITCH_DECLARE(switch_status_t) switch_channel_set_variable(switch_channel_t *ch 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);