switch_core.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. /*
  2. * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
  3. * Copyright (C) 2005-2018, Anthony Minessale II <anthm@freeswitch.org>
  4. *
  5. * Version: MPL 1.1
  6. *
  7. * The contents of this file are subject to the Mozilla Public License Version
  8. * 1.1 (the "License"); you may not use this file except in compliance with
  9. * the License. You may obtain a copy of the License at
  10. * http://www.mozilla.org/MPL/
  11. *
  12. * Software distributed under the License is distributed on an "AS IS" basis,
  13. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  14. * for the specific language governing rights and limitations under the
  15. * License.
  16. *
  17. * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
  18. *
  19. * The Initial Developer of the Original Code is
  20. * Anthony Minessale II <anthm@freeswitch.org>
  21. * Portions created by the Initial Developer are Copyright (C)
  22. * the Initial Developer. All Rights Reserved.
  23. *
  24. * Contributor(s):
  25. * Chris Rienzo <chris@signalwire.com>
  26. * Seven Du <dujinfang@gmail.com>
  27. *
  28. *
  29. * switch_core.c -- tests core functions
  30. *
  31. */
  32. #include <switch.h>
  33. #include <test/switch_test.h>
  34. #if defined(HAVE_OPENSSL)
  35. #include <openssl/ssl.h>
  36. #endif
  37. #define ENABLE_SNPRINTFV_TESTS 0 /* Do not turn on for CI as this requires a lot of RAM */
  38. FST_CORE_BEGIN("./conf")
  39. {
  40. FST_SUITE_BEGIN(switch_core)
  41. {
  42. FST_SETUP_BEGIN()
  43. {
  44. switch_core_set_variable("spawn_instead_of_system", "false");
  45. }
  46. FST_SETUP_END()
  47. FST_TEARDOWN_BEGIN()
  48. {
  49. }
  50. FST_TEARDOWN_END()
  51. FST_TEST_BEGIN(test_switch_parse_cidr_v6)
  52. {
  53. ip_t ip, mask;
  54. uint32_t bits;
  55. fst_check(!switch_parse_cidr("fe80::/10", &ip, &mask, &bits));
  56. fst_check_int_equals(bits, 10);
  57. fst_check_int_equals(ip.v6.s6_addr[0], 0xfe);
  58. fst_check_int_equals(ip.v6.s6_addr[1], 0x80);
  59. fst_check_int_equals(ip.v6.s6_addr[2], 0);
  60. fst_check_int_equals(mask.v6.s6_addr[0], 0xff);
  61. fst_check_int_equals(mask.v6.s6_addr[1], 0xc0);
  62. fst_check_int_equals(mask.v6.s6_addr[2], 0);
  63. fst_check(!switch_parse_cidr("::/0", &ip, &mask, &bits));
  64. fst_check_int_equals(bits, 0);
  65. fst_check_int_equals(ip.v6.s6_addr[0], 0);
  66. fst_check_int_equals(ip.v6.s6_addr[1], 0);
  67. fst_check_int_equals(ip.v6.s6_addr[2], 0);
  68. fst_check_int_equals(mask.v6.s6_addr[0], 0);
  69. fst_check_int_equals(mask.v6.s6_addr[1], 0);
  70. fst_check_int_equals(mask.v6.s6_addr[2], 0);
  71. fst_check(!switch_parse_cidr("::1/128", &ip, &mask, &bits));
  72. fst_check_int_equals(bits, 128);
  73. fst_check_int_equals(ip.v6.s6_addr[0], 0);
  74. fst_check_int_equals(ip.v6.s6_addr[1], 0);
  75. fst_check_int_equals(ip.v6.s6_addr[2], 0);
  76. fst_check_int_equals(ip.v6.s6_addr[3], 0);
  77. fst_check_int_equals(ip.v6.s6_addr[4], 0);
  78. fst_check_int_equals(ip.v6.s6_addr[5], 0);
  79. fst_check_int_equals(ip.v6.s6_addr[6], 0);
  80. fst_check_int_equals(ip.v6.s6_addr[7], 0);
  81. fst_check_int_equals(ip.v6.s6_addr[8], 0);
  82. fst_check_int_equals(ip.v6.s6_addr[9], 0);
  83. fst_check_int_equals(ip.v6.s6_addr[10], 0);
  84. fst_check_int_equals(ip.v6.s6_addr[11], 0);
  85. fst_check_int_equals(ip.v6.s6_addr[12], 0);
  86. fst_check_int_equals(ip.v6.s6_addr[13], 0);
  87. fst_check_int_equals(ip.v6.s6_addr[14], 0);
  88. fst_check_int_equals(ip.v6.s6_addr[15], 1);
  89. fst_check_int_equals(mask.v6.s6_addr[0], 0xff);
  90. fst_check_int_equals(mask.v6.s6_addr[1], 0xff);
  91. fst_check_int_equals(mask.v6.s6_addr[2], 0xff);
  92. fst_check_int_equals(mask.v6.s6_addr[3], 0xff);
  93. fst_check_int_equals(mask.v6.s6_addr[4], 0xff);
  94. fst_check_int_equals(mask.v6.s6_addr[5], 0xff);
  95. fst_check_int_equals(mask.v6.s6_addr[6], 0xff);
  96. fst_check_int_equals(mask.v6.s6_addr[7], 0xff);
  97. fst_check_int_equals(mask.v6.s6_addr[8], 0xff);
  98. fst_check_int_equals(mask.v6.s6_addr[9], 0xff);
  99. fst_check_int_equals(mask.v6.s6_addr[10], 0xff);
  100. fst_check_int_equals(mask.v6.s6_addr[11], 0xff);
  101. fst_check_int_equals(mask.v6.s6_addr[12], 0xff);
  102. fst_check_int_equals(mask.v6.s6_addr[13], 0xff);
  103. fst_check_int_equals(mask.v6.s6_addr[14], 0xff);
  104. fst_check_int_equals(mask.v6.s6_addr[15], 0xff);
  105. }
  106. FST_TEST_END()
  107. #if ENABLE_SNPRINTFV_TESTS
  108. FST_TEST_BEGIN(test_snprintfv_1)
  109. {
  110. size_t src_buf_size = 0x100000001;
  111. char* src = calloc(1, src_buf_size);
  112. if (!src) {
  113. printf("bad allocation\n");
  114. return -1;
  115. }
  116. src[0] = '\xc0';
  117. memset(src + 1, '\x80', 0xffffffff);
  118. char dst[256];
  119. switch_snprintfv(dst, 256, "'%!q'", src);
  120. free(src);
  121. }
  122. FST_TEST_END()
  123. FST_TEST_BEGIN(test_snprintfv_2)
  124. {
  125. #define STR_LEN ((0x100000001 - 3) / 2)
  126. char* src = calloc(1, STR_LEN + 1); /* Account for NULL byte. */
  127. if (!src) { return -1; }
  128. memset(src, 'a', STR_LEN);
  129. char* dst = calloc(1, STR_LEN + 3); /* Account for extra quotes and NULL byte */
  130. if (!dst) { return -1; }
  131. switch_snprintfv(dst, 2 * STR_LEN + 3, "'%q'", src);
  132. free(src);
  133. free(dst);
  134. }
  135. FST_TEST_END()
  136. #endif
  137. FST_TEST_BEGIN(test_switch_is_number_in_range)
  138. {
  139. fst_check_int_equals(switch_is_uint_in_range("x5", 0, 10), SWITCH_FALSE);
  140. fst_check_int_equals(switch_is_uint_in_range("0", 1, 10), SWITCH_FALSE);
  141. fst_check_int_equals(switch_is_uint_in_range("-11", -10, 10), SWITCH_FALSE);
  142. fst_check_int_equals(switch_is_uint_in_range("-10", -10, 10), SWITCH_FALSE);
  143. fst_check_int_equals(switch_is_uint_in_range("-5", -10, 10), SWITCH_FALSE);
  144. fst_check_int_equals(switch_is_uint_in_range("-5", -10, 10), SWITCH_FALSE);
  145. fst_check_int_equals(switch_is_uint_in_range("5", -10, 10), SWITCH_FALSE);
  146. fst_check_int_equals(switch_is_uint_in_range("0", 0, 10), SWITCH_TRUE);
  147. fst_check_int_equals(switch_is_uint_in_range("10", 0, 10), SWITCH_TRUE);
  148. fst_check_int_equals(switch_is_uint_in_range("11", 0, 10), SWITCH_FALSE);
  149. }
  150. FST_TEST_END()
  151. FST_TEST_BEGIN(test_md5)
  152. {
  153. char digest[SWITCH_MD5_DIGEST_STRING_SIZE] = { 0 };
  154. char test_string[] = "test";
  155. switch_status_t status;
  156. status = switch_md5_string(digest, (void *)test_string, strlen(test_string));
  157. fst_check_int_equals(status, SWITCH_STATUS_SUCCESS);
  158. fst_check_string_equals(digest, "098f6bcd4621d373cade4e832627b4f6");
  159. }
  160. FST_TEST_END()
  161. FST_TEST_BEGIN(test_switch_event_add_header_leak)
  162. {
  163. switch_event_t* event;
  164. if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_CALLSTATE) == SWITCH_STATUS_SUCCESS) {
  165. switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-Call-State-Number[0]", "1");
  166. switch_event_fire(&event);
  167. }
  168. if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_CALLSTATE) == SWITCH_STATUS_SUCCESS) {
  169. switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-Call-State-Number[5000]", "12");
  170. switch_event_fire(&event);
  171. }
  172. }
  173. FST_TEST_END()
  174. FST_TEST_BEGIN(test_xml_free_attr)
  175. {
  176. switch_xml_t parent_xml = switch_xml_new("xml");
  177. switch_xml_t xml = switch_xml_add_child_d(parent_xml, "test", 1);
  178. switch_xml_set_attr(xml, "a1", "v1");
  179. switch_xml_set_attr_d(xml, "a2", "v2");
  180. switch_xml_free(parent_xml);
  181. }
  182. FST_TEST_END()
  183. FST_TEST_BEGIN(test_xml_set_attr)
  184. {
  185. switch_xml_t parent_xml = switch_xml_new("xml");
  186. switch_xml_t xml = switch_xml_add_child_d(parent_xml, "test", 1);
  187. switch_xml_set_attr_d(xml, "test1", "1");
  188. switch_xml_set_attr(xml, "a1", "v1");
  189. switch_xml_set_attr_d(xml, "a2", "v2");
  190. switch_xml_set_attr(xml, "test1", NULL);
  191. switch_xml_set_attr_d(xml, "test2", "2");
  192. switch_xml_set_attr_d(xml, "a3", "v3");
  193. switch_xml_set_attr(xml, "test2", NULL);
  194. switch_xml_set_attr(xml, "a1", NULL);
  195. switch_xml_set_attr(xml, "a2", NULL);
  196. switch_xml_set_attr(xml, "a3", NULL);
  197. switch_xml_free(parent_xml);
  198. }
  199. FST_TEST_END()
  200. #ifdef HAVE_OPENSSL
  201. FST_TEST_BEGIN(test_md5)
  202. {
  203. char *digest_name = "md5";
  204. char *digest_str = NULL;
  205. const char *str = "test data";
  206. unsigned int outputlen;
  207. switch_status_t status = switch_digest_string(digest_name, &digest_str, str, strlen(str), &outputlen);
  208. fst_check_int_equals(status, SWITCH_STATUS_SUCCESS);
  209. fst_check_string_equals(digest_str, "eb733a00c0c9d336e65691a37ab54293");
  210. switch_safe_free(digest_str);
  211. }
  212. FST_TEST_END()
  213. FST_TEST_BEGIN(test_sha256)
  214. {
  215. char *digest_name = "sha256";
  216. char *digest_str = NULL;
  217. const char *str = "test data";
  218. unsigned int outputlen;
  219. switch_status_t status = switch_digest_string(digest_name, &digest_str, str, strlen(str), &outputlen);
  220. fst_check_int_equals(status, SWITCH_STATUS_SUCCESS);
  221. fst_check_string_equals(digest_str, "916f0027a575074ce72a331777c3478d6513f786a591bd892da1a577bf2335f9");
  222. switch_safe_free(digest_str);
  223. }
  224. FST_TEST_END()
  225. #endif
  226. #if OPENSSL_VERSION_NUMBER >= 0x10101000L
  227. FST_TEST_BEGIN(test_sha512_256)
  228. {
  229. char *digest_name = "sha512-256";
  230. char *digest_str = NULL;
  231. const char *str = "test data";
  232. unsigned int outputlen;
  233. switch_status_t status = switch_digest_string(digest_name, &digest_str, str, strlen(str), &outputlen);
  234. fst_check_int_equals(status, SWITCH_STATUS_SUCCESS);
  235. fst_check_string_equals(digest_str, "9fe875600168548c1954aed4f03974ce06b3e17f03a70980190da2d7ef937a43");
  236. switch_safe_free(digest_str);
  237. }
  238. FST_TEST_END()
  239. #endif
  240. #ifndef WIN32
  241. FST_TEST_BEGIN(test_fork)
  242. {
  243. switch_stream_handle_t exec_result = { 0 };
  244. SWITCH_STANDARD_STREAM(exec_result);
  245. fst_requires(switch_stream_system_fork("ip ad sh", &exec_result) == 0);
  246. fst_requires(!zstr(exec_result.data));
  247. switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s\n", (char *)exec_result.data);
  248. fst_requires(switch_stream_system_fork("ip ad sh | grep link", &exec_result) == 0);
  249. fst_requires(!zstr(exec_result.data));
  250. switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s\n", (char *)exec_result.data);
  251. switch_safe_free(exec_result.data);
  252. }
  253. FST_TEST_END()
  254. #endif
  255. FST_TEST_BEGIN(test_non_fork_exec_set)
  256. {
  257. char *var_test = switch_core_get_variable_dup("test");
  258. char *var_default_password = switch_core_get_variable_dup("default_password");
  259. switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "global_getvar test: %s\n", switch_str_nil(var_test));
  260. switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "global_getvar default_password: %s\n", switch_str_nil(var_default_password));
  261. fst_check_string_not_equals(var_test, "");
  262. fst_check_string_not_equals(var_default_password, "");
  263. fst_check_string_equals(var_test, var_default_password);
  264. switch_safe_free(var_test);
  265. switch_safe_free(var_default_password);
  266. }
  267. FST_TEST_END()
  268. FST_TEST_BEGIN(test_switch_sockaddr_new)
  269. {
  270. int type = SOCK_DGRAM;
  271. switch_port_t port = 12044;
  272. const char *ip = "127.0.0.1";
  273. switch_memory_pool_t *pool = NULL;
  274. switch_sockaddr_t *local_addr = NULL;
  275. switch_socket_t *sock = NULL;
  276. switch_bool_t r = SWITCH_FALSE;
  277. if (switch_core_new_memory_pool(&pool) == SWITCH_STATUS_SUCCESS) {
  278. if (switch_sockaddr_new(&local_addr, ip, port, pool) == SWITCH_STATUS_SUCCESS) {
  279. if (switch_socket_create(&sock, switch_sockaddr_get_family(local_addr), type, 0, pool) == SWITCH_STATUS_SUCCESS) {
  280. if (switch_socket_bind(sock, local_addr) == SWITCH_STATUS_SUCCESS) {
  281. r = SWITCH_TRUE;
  282. }
  283. switch_socket_close(sock);
  284. }
  285. }
  286. switch_core_destroy_memory_pool(&pool);
  287. }
  288. fst_check_int_equals(r, SWITCH_TRUE);
  289. }
  290. FST_TEST_END()
  291. FST_TEST_BEGIN(test_switch_spawn)
  292. {
  293. #ifdef __linux__
  294. int status;
  295. switch_stream_handle_t stream = { 0 };
  296. status = switch_spawn("echo CHECKING_BAD_FILE_DESCRIPTOR", SWITCH_TRUE);
  297. fst_check_int_equals(status, 0);
  298. SWITCH_STANDARD_STREAM(stream);
  299. status = switch_stream_spawn("echo DEADBEEF", SWITCH_FALSE, SWITCH_TRUE, &stream);
  300. fst_check_int_equals(status, 0);
  301. fst_check_string_equals(stream.data, "DEADBEEF\n");
  302. switch_safe_free(stream.data);
  303. SWITCH_STANDARD_STREAM(stream);
  304. status = switch_stream_spawn("echo DEADBEEF", SWITCH_FALSE, SWITCH_FALSE, &stream);
  305. fst_check_int_equals(status, 0);
  306. fst_check_string_equals(stream.data, "DEADBEEF\n");
  307. switch_safe_free(stream.data);
  308. printf("\nExpected warning check ... ");
  309. status = switch_spawn("false", SWITCH_TRUE);
  310. fct_chk_neq_int(status, 0);
  311. status = switch_spawn("false", SWITCH_FALSE);
  312. fct_chk_eq_int(status, 0);
  313. status = switch_spawn("true", SWITCH_TRUE);
  314. fct_chk_eq_int(status, 0);
  315. #endif
  316. }
  317. FST_TEST_END()
  318. FST_TEST_BEGIN(test_switch_spawn_instead_of_system)
  319. {
  320. #ifdef __linux__
  321. int status;
  322. char file_uuid[SWITCH_UUID_FORMATTED_LENGTH + 1] = { 0 };
  323. const char *filename = NULL;
  324. const char *cmd = NULL;
  325. // tell FS core to use posix_spawn() instead of popen() and friends
  326. switch_core_set_variable("spawn_instead_of_system", "true");
  327. // echo text to a file using shell redirection- this will ensure the command was executed in a shell, as expected
  328. switch_uuid_str(file_uuid, sizeof(file_uuid));
  329. filename = switch_core_sprintf(fst_pool, "%s" SWITCH_PATH_SEPARATOR "%s", SWITCH_GLOBAL_dirs.temp_dir, file_uuid);
  330. cmd = switch_core_sprintf(fst_pool, "echo test_switch_spawn_instead_of_system with spaces > %s", filename);
  331. status = switch_system(cmd, SWITCH_TRUE);
  332. fst_check_int_equals(status, 0);
  333. fst_xcheck(status == 0, "Expect switch_system() command to return 0");
  334. fst_xcheck(switch_file_exists(filename, fst_pool) == SWITCH_STATUS_SUCCESS, "Expect switch_system() to use shell to create file via > redirection");
  335. unlink(filename);
  336. // verify exec-set works- see conf/freeswitch.xml for test setup of shell_exec_set_test global variable
  337. fst_check_string_equals(switch_core_get_variable("shell_exec_set_test"), "usr");
  338. #endif
  339. }
  340. FST_TEST_END()
  341. FST_TEST_BEGIN(test_switch_safe_atoXX)
  342. {
  343. fst_check_int_equals(switch_safe_atoi("1", 0), 1);
  344. fst_check_int_equals(switch_safe_atoi("", 2), 0);
  345. fst_check_int_equals(switch_safe_atoi(0, 3), 3);
  346. fst_check_int_equals(switch_safe_atol("9275806", 0), 9275806);
  347. fst_check_int_equals(switch_safe_atol("", 2), 0);
  348. fst_check_int_equals(switch_safe_atol(0, 3), 3);
  349. fst_check_int_equals(switch_safe_atoll("9275806", 0), 9275806);
  350. fst_check_int_equals(switch_safe_atoll("", 2), 0);
  351. fst_check_int_equals(switch_safe_atoll(0, 3), 3);
  352. }
  353. FST_TEST_END()
  354. FST_TEST_BEGIN(test_switch_core_hash_insert_dup)
  355. {
  356. char *magicnumber = malloc(9);
  357. switch_hash_index_t *hi;
  358. switch_hash_t *hash = NULL;
  359. void *hash_val;
  360. switch_core_hash_init(&hash);
  361. fst_requires(hash);
  362. snprintf(magicnumber, 9, "%s", "DEADBEEF");
  363. switch_core_hash_insert_dup(hash, "test", (const char *)magicnumber);
  364. snprintf(magicnumber, 9, "%s", "BAADF00D");
  365. hi = switch_core_hash_first(hash);
  366. switch_core_hash_this(hi, NULL, NULL, &hash_val);
  367. fst_check_string_equals(hash_val, "DEADBEEF");
  368. switch_safe_free(hash_val);
  369. free(magicnumber);
  370. free(hi);
  371. switch_core_hash_destroy(&hash);
  372. fst_requires(hash == NULL);
  373. }
  374. FST_TEST_END()
  375. FST_TEST_BEGIN(test_switch_core_hash_insert_alloc)
  376. {
  377. char *item;
  378. switch_hash_index_t *hi;
  379. switch_hash_t *hash = NULL;
  380. void *hash_val;
  381. switch_core_hash_init(&hash);
  382. fst_requires(hash);
  383. item = switch_core_hash_insert_alloc(hash, "test", 10);
  384. fst_requires(item);
  385. snprintf(item, 9, "%s", "DEADBEEF");
  386. hi = switch_core_hash_first(hash);
  387. switch_core_hash_this(hi, NULL, NULL, &hash_val);
  388. fst_check_string_equals(hash_val, "DEADBEEF");
  389. free(hi);
  390. switch_core_hash_destroy(&hash);
  391. fst_requires(hash == NULL);
  392. free(item);
  393. }
  394. FST_TEST_END()
  395. FST_TEST_BEGIN(test_switch_core_hash_insert_pointer)
  396. {
  397. int i, sum = 0;
  398. switch_hash_index_t *hi;
  399. switch_hash_t *hash = NULL;
  400. switch_core_hash_init(&hash);
  401. fst_requires(hash);
  402. for (i = 0; i < 10; i++) {
  403. int *num = malloc(sizeof(int));
  404. *num = i;
  405. fst_check_int_equals(switch_core_hash_insert_pointer(hash, (void*)num), SWITCH_STATUS_SUCCESS);
  406. }
  407. i = 0;
  408. for (hi = switch_core_hash_first(hash); hi; hi = switch_core_hash_next(&hi)) {
  409. void *hash_val;
  410. switch_core_hash_this(hi, NULL, NULL, &hash_val);
  411. sum += *(int*)hash_val;
  412. free(hash_val);
  413. i++;
  414. }
  415. fst_check_int_equals(i, 10);
  416. fst_check_int_equals(sum, 45);
  417. switch_core_hash_destroy(&hash);
  418. fst_requires(hash == NULL);
  419. }
  420. FST_TEST_END()
  421. FST_SESSION_BEGIN(test_switch_channel_get_variable_strdup)
  422. {
  423. const char *val;
  424. switch_channel_t *channel = switch_core_session_get_channel(fst_session);
  425. fst_check(channel);
  426. switch_channel_set_variable(channel, "test_var", "test_value");
  427. fst_check(!switch_channel_get_variable_strdup(channel, "test_var_does_not_exist"));
  428. val = switch_channel_get_variable_strdup(channel, "test_var");
  429. fst_check(val);
  430. fst_check_string_equals(val, "test_value");
  431. free((char *)val);
  432. }
  433. FST_SESSION_END()
  434. FST_SESSION_BEGIN(test_switch_channel_get_variable_buf)
  435. {
  436. char buf[16] = { 0 };
  437. switch_channel_t *channel = switch_core_session_get_channel(fst_session);
  438. fst_check(channel);
  439. switch_channel_set_variable(channel, "test_var", "test_value");
  440. fst_check(switch_channel_get_variable_buf(channel, "test_var", buf, sizeof(buf)) == SWITCH_STATUS_SUCCESS);
  441. fst_check_string_equals(buf, "test_value");
  442. fst_check(switch_channel_get_variable_buf(channel, "test_var_does_not_exist", buf, sizeof(buf)) == SWITCH_STATUS_FALSE);
  443. }
  444. FST_SESSION_END()
  445. }
  446. FST_SUITE_END()
  447. }
  448. FST_CORE_END()