[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:
Andrey Volk
2023-06-28 02:51:24 +03:00
parent d91947f587
commit 6b67970bbb
3 changed files with 72 additions and 0 deletions

View File

@@ -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()
}