mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-01-25 02:07:54 +00:00
[Core] Add new switch_channel_get_variable_strdup() and switch_channel_get_variable_buf() APIs that avoid allocating channel variables in a session's memory pool.
This commit is contained in:
@@ -416,6 +416,42 @@ FST_CORE_BEGIN("./conf")
|
||||
fst_requires(hash == NULL);
|
||||
}
|
||||
FST_TEST_END()
|
||||
|
||||
FST_SESSION_BEGIN(test_switch_channel_get_variable_strdup)
|
||||
{
|
||||
const char *val;
|
||||
switch_channel_t *channel = switch_core_session_get_channel(fst_session);
|
||||
|
||||
fst_check(channel);
|
||||
|
||||
switch_channel_set_variable(channel, "test_var", "test_value");
|
||||
|
||||
fst_check(!switch_channel_get_variable_strdup(channel, "test_var_does_not_exist"));
|
||||
|
||||
val = switch_channel_get_variable_strdup(channel, "test_var");
|
||||
|
||||
fst_check(val);
|
||||
fst_check_string_equals(val, "test_value");
|
||||
|
||||
free((char *)val);
|
||||
}
|
||||
FST_SESSION_END()
|
||||
|
||||
FST_SESSION_BEGIN(test_switch_channel_get_variable_buf)
|
||||
{
|
||||
char buf[16] = { 0 };
|
||||
switch_channel_t *channel = switch_core_session_get_channel(fst_session);
|
||||
|
||||
fst_check(channel);
|
||||
|
||||
switch_channel_set_variable(channel, "test_var", "test_value");
|
||||
|
||||
fst_check(switch_channel_get_variable_buf(channel, "test_var", buf, sizeof(buf)) == SWITCH_STATUS_SUCCESS);
|
||||
fst_check_string_equals(buf, "test_value");
|
||||
|
||||
fst_check(switch_channel_get_variable_buf(channel, "test_var_does_not_exist", buf, sizeof(buf)) == SWITCH_STATUS_FALSE);
|
||||
}
|
||||
FST_SESSION_END()
|
||||
}
|
||||
FST_SUITE_END()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user