confdb_test_agent.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. /*
  2. * Copyright (c) 2008, 2009 Red Hat Inc
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Christine Caulfield <ccaulfie@redhat.com>
  7. *
  8. * This software licensed under BSD license, the text of which follows:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. * THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include <config.h>
  35. #include <stdio.h>
  36. #include <stdlib.h>
  37. #include <errno.h>
  38. #include <unistd.h>
  39. #include <string.h>
  40. #include <sys/types.h>
  41. #include <sys/socket.h>
  42. #include <netinet/in.h>
  43. #include <arpa/inet.h>
  44. #include <netdb.h>
  45. #include <sys/un.h>
  46. #include <syslog.h>
  47. #include <corosync/corotypes.h>
  48. #include <corosync/confdb.h>
  49. #include "common_test_agent.h"
  50. #define INCDEC_VALUE 45
  51. confdb_callbacks_t callbacks = {
  52. .confdb_key_change_notify_fn = NULL,
  53. .confdb_object_create_change_notify_fn = NULL,
  54. .confdb_object_delete_change_notify_fn = NULL
  55. };
  56. typedef enum {
  57. NTF_OBJECT_CREATED,
  58. NTF_OBJECT_DELETED,
  59. NTF_KEY_CREATED,
  60. NTF_KEY_REPLACED,
  61. NTF_KEY_DELETED,
  62. NTF_NONE,
  63. } ntf_callback_type_t;
  64. static ntf_callback_type_t callback_type;
  65. static char ntf_object_name[256];
  66. static size_t ntf_object_name_len;
  67. static char ntf_key_name[256];
  68. static size_t ntf_key_name_len;
  69. static char ntf_key_value[256];
  70. static size_t ntf_key_value_len;
  71. static void ta_key_change_notify (
  72. confdb_handle_t handle,
  73. confdb_change_type_t change_type,
  74. hdb_handle_t parent_object_handle,
  75. hdb_handle_t object_handle,
  76. const void *object_name,
  77. size_t object_name_len,
  78. const void *key_name,
  79. size_t key_name_len,
  80. const void *key_value,
  81. size_t key_value_len)
  82. {
  83. switch (change_type) {
  84. case OBJECT_KEY_CREATED:
  85. callback_type = NTF_KEY_CREATED;
  86. break;
  87. case OBJECT_KEY_DELETED:
  88. callback_type = NTF_KEY_DELETED;
  89. break;
  90. case OBJECT_KEY_REPLACED:
  91. callback_type = NTF_KEY_REPLACED;
  92. break;
  93. default:
  94. assert (0);
  95. break;
  96. }
  97. ntf_object_name_len = object_name_len;
  98. memcpy (ntf_object_name, object_name, object_name_len);
  99. ntf_key_name_len = key_name_len;
  100. memcpy (ntf_key_name, key_name, key_name_len);
  101. ntf_key_value_len = key_value_len;
  102. memcpy (ntf_key_value, key_value, key_value_len);
  103. }
  104. static void ta_object_create_notify (
  105. confdb_handle_t handle,
  106. hdb_handle_t parent_object_handle,
  107. hdb_handle_t object_handle,
  108. const void *name_pt,
  109. size_t name_len)
  110. {
  111. callback_type = NTF_OBJECT_CREATED;
  112. ntf_object_name_len = name_len;
  113. memcpy (ntf_object_name, name_pt, name_len);
  114. }
  115. static void ta_object_delete_notify (
  116. confdb_handle_t handle,
  117. hdb_handle_t parent_object_handle,
  118. const void *name_pt,
  119. size_t name_len)
  120. {
  121. callback_type = NTF_OBJECT_DELETED;
  122. ntf_object_name_len = name_len;
  123. memcpy (ntf_object_name, name_pt, name_len);
  124. }
  125. confdb_callbacks_t valid_callbacks = {
  126. .confdb_key_change_notify_fn = ta_key_change_notify,
  127. .confdb_object_create_change_notify_fn = ta_object_create_notify,
  128. .confdb_object_delete_change_notify_fn = ta_object_delete_notify
  129. };
  130. static void set_get_test (int sock)
  131. {
  132. confdb_handle_t handle;
  133. char response[100];
  134. int res;
  135. hdb_handle_t object_handle;
  136. confdb_value_types_t type;
  137. char key_value[256];
  138. char key2_value[256];
  139. size_t value_len;
  140. size_t value2_len;
  141. syslog (LOG_ERR, "%s START", __func__);
  142. snprintf (response, 100, "%s", OK_STR);
  143. res = confdb_initialize (&handle, &callbacks);
  144. if (res != CS_OK) {
  145. syslog (LOG_ERR, "Could not initialize confdb error %d", res);
  146. goto send_response;
  147. }
  148. /* Add a scratch object and put 2 keys into it */
  149. res = confdb_object_create (handle, OBJECT_PARENT_HANDLE,
  150. "testconfdb", strlen("testconfdb"), &object_handle);
  151. if (res != CS_OK) {
  152. syslog (LOG_ERR, "error creating 'testconfdb' object: %d", res);
  153. goto send_response;
  154. }
  155. res = confdb_key_create (handle, object_handle,
  156. "testkey", strlen ("testkey"),
  157. "one", strlen ("one"));
  158. if (res != CS_OK) {
  159. syslog (LOG_ERR, "error creating 'testconfdb' key 1: %d", res);
  160. goto send_response;
  161. }
  162. res = confdb_key_replace (handle, object_handle,
  163. "testkey", strlen ("testkey"),
  164. "one", strlen ("one"),
  165. "newone", strlen ("newone"));
  166. if (res != CS_OK) {
  167. syslog (LOG_ERR, "error replace 'testconfdb' key 2: %d", res);
  168. goto send_response;
  169. }
  170. res = confdb_key_get_typed (handle, object_handle,
  171. "testkey", key_value, &value_len, &type);
  172. if (res != CS_OK) {
  173. syslog (LOG_ERR, "Could not get \"testkey\" key: %d", res);
  174. goto send_response;
  175. }
  176. if (strcmp (key_value, "newone") != 0) {
  177. syslog (LOG_ERR, "Key not set correctly");
  178. goto send_response;
  179. }
  180. if (type != CONFDB_VALUETYPE_ANY) {
  181. syslog (LOG_ERR, "Key type not set correctly");
  182. goto send_response;
  183. }
  184. res = confdb_key_get (handle, object_handle,
  185. "testkey", strlen ("testkey"), key2_value, &value2_len);
  186. if (res != CS_OK) {
  187. syslog (LOG_ERR, "Could not get \"testkey\" key: %d", res);
  188. goto send_response;
  189. }
  190. if (value2_len != value_len) {
  191. syslog (LOG_ERR, "value length from confdb_key_get:%u and confdb_key_get_typed:%u differ.",
  192. (uint32_t)value_len, (uint32_t)value2_len);
  193. goto send_response;
  194. }
  195. res = confdb_key_delete (handle, object_handle,
  196. "testkey", strlen ("testkey"), key2_value, value2_len);
  197. if (res != CS_OK) {
  198. syslog (LOG_ERR, "Could not get \"testkey\" key: %d", res);
  199. goto send_response;
  200. }
  201. /* Remove it.
  202. Check that it doesn't exist when the full tree dump runs next */
  203. res = confdb_object_destroy(handle, object_handle);
  204. if (res != CS_OK) {
  205. syslog (LOG_ERR, "error destroying 'testconfdb' object: %d", res);
  206. goto send_response;
  207. }
  208. snprintf (response, 100, "%s", OK_STR);
  209. send_response:
  210. syslog (LOG_ERR, "%s %s", __func__, response);
  211. send (sock, response, strlen (response) + 1, 0);
  212. confdb_finalize (handle);
  213. }
  214. static void increment_decrement_test (int sock)
  215. {
  216. char response[100];
  217. int res;
  218. uint32_t incdec_value;
  219. hdb_handle_t object_handle;
  220. confdb_handle_t handle;
  221. confdb_handle_t par_handle;
  222. snprintf (response, 100, "%s", FAIL_STR);
  223. res = confdb_initialize (&handle, &callbacks);
  224. if (res != CS_OK) {
  225. syslog (LOG_ERR, "Could not initialize confdb error %d", res);
  226. goto send_response;
  227. }
  228. /* Add a scratch object and put 1 keys into it */
  229. res = confdb_object_create(handle, OBJECT_PARENT_HANDLE,
  230. "testconfdb", strlen("testconfdb"), &object_handle);
  231. if (res != CS_OK) {
  232. syslog (LOG_ERR, "error creating 'testconfdb' object: %d", res);
  233. goto send_response;
  234. }
  235. res = confdb_object_parent_get (handle, object_handle, &par_handle);
  236. if (res != CS_OK) {
  237. syslog (LOG_ERR, "error getting parent of 'testconfdb' object: %d", res);
  238. goto send_response;
  239. }
  240. if (par_handle != OBJECT_PARENT_HANDLE) {
  241. syslog (LOG_ERR, "wrong parent handle");
  242. goto send_response;
  243. }
  244. incdec_value = INCDEC_VALUE;
  245. res = confdb_key_create_typed (handle, object_handle, "incdec",
  246. &incdec_value, sizeof(incdec_value), CONFDB_VALUETYPE_UINT32);
  247. if (res != CS_OK) {
  248. syslog (LOG_ERR, "error creating 'testconfdb' key 4: %d\n", res);
  249. goto send_response;
  250. }
  251. res = confdb_key_increment(handle, object_handle, "incdec", strlen("incdec"), &incdec_value);
  252. if (res != CS_OK) {
  253. syslog (LOG_ERR, "error incrementing 'testconfdb' key 4: %d\n", res);
  254. goto send_response;
  255. }
  256. if (incdec_value == INCDEC_VALUE + 1) {
  257. syslog (LOG_INFO, "incremented value = %d\n", incdec_value);
  258. }
  259. else {
  260. syslog (LOG_ERR, "ERROR: incremented value = %d (should be %d)\n", incdec_value, INCDEC_VALUE+1);
  261. goto send_response;
  262. }
  263. res = confdb_key_decrement(handle, object_handle, "incdec", strlen("incdec"), &incdec_value);
  264. if (res != CS_OK) {
  265. syslog (LOG_ERR, "error decrementing 'testconfdb' key 4: %d\n", res);
  266. goto send_response;
  267. }
  268. if (incdec_value == INCDEC_VALUE) {
  269. syslog (LOG_ERR, "decremented value = %d\n", incdec_value);
  270. }
  271. else {
  272. syslog (LOG_ERR, "ERROR: decremented value = %d (should be %d)\n", incdec_value, INCDEC_VALUE);
  273. goto send_response;
  274. }
  275. /* Remove it.
  276. Check that it doesn't exist when the full tree dump runs next */
  277. res = confdb_object_destroy(handle, object_handle);
  278. if (res != CS_OK) {
  279. syslog (LOG_ERR, "error destroying 'testconfdb' object: %d\n", res);
  280. goto send_response;
  281. }
  282. snprintf (response, 100, "%s", OK_STR);
  283. send_response:
  284. confdb_finalize (handle);
  285. send (sock, response, strlen (response) + 1, 0);
  286. }
  287. static void object_find_test (int sock)
  288. {
  289. char response[100];
  290. confdb_handle_t handle;
  291. int result;
  292. hdb_handle_t totem_handle;
  293. char key_value[256];
  294. size_t value_len;
  295. snprintf (response, 100, "%s", FAIL_STR);
  296. result = confdb_initialize (&handle, &callbacks);
  297. if (result != CS_OK) {
  298. syslog (LOG_ERR, "Could not initialize confdb error %d\n", result);
  299. goto send_response;
  300. }
  301. /* Find "totem" and dump bits of it again, to test the direct APIs */
  302. result = confdb_object_find_start(handle, OBJECT_PARENT_HANDLE);
  303. if (result != CS_OK) {
  304. syslog (LOG_ERR, "Could not start object_find %d\n", result);
  305. goto send_response;
  306. }
  307. result = confdb_object_find(handle, OBJECT_PARENT_HANDLE, "totem", strlen("totem"), &totem_handle);
  308. if (result != CS_OK) {
  309. syslog (LOG_ERR, "Could not object_find \"totem\": %d\n", result);
  310. goto send_response;
  311. }
  312. result = confdb_key_get(handle, totem_handle, "version", strlen("version"), key_value, &value_len);
  313. if (result != CS_OK) {
  314. syslog (LOG_ERR, "Could not get \"version\" key: %d\n", result);
  315. goto send_response;
  316. }
  317. result = confdb_object_find_destroy (handle, OBJECT_PARENT_HANDLE);
  318. if (result != CS_OK) {
  319. syslog (LOG_ERR, "Could not destroy find object %d\n", result);
  320. goto send_response;
  321. }
  322. snprintf (response, 100, "%s", OK_STR);
  323. send_response:
  324. confdb_finalize (handle);
  325. send (sock, response, strlen (response) + 1, 0);
  326. }
  327. static void notification_test (int sock)
  328. {
  329. char response[100];
  330. confdb_handle_t handle;
  331. int res;
  332. hdb_handle_t object_handle;
  333. hdb_handle_t new_object_handle;
  334. uint16_t incdec_value;
  335. uint16_t incdec_value_new;
  336. uint32_t incdec_value_out;
  337. snprintf (response, 100, "%s", FAIL_STR);
  338. res = confdb_initialize (&handle, &valid_callbacks);
  339. if (res != CS_OK) {
  340. syslog (LOG_ERR, "Could not initialize confdb error %d\n", res);
  341. goto send_response;
  342. }
  343. /* Add a base scratch object (we don't want to track the parent object) */
  344. res = confdb_object_create(handle, OBJECT_PARENT_HANDLE,
  345. "testconfdb", strlen("testconfdb"), &object_handle);
  346. if (res != CS_OK) {
  347. syslog (LOG_ERR, "error creating 'testconfdb' object: %d", res);
  348. goto send_response;
  349. }
  350. res = confdb_track_changes (handle, object_handle, 1 /*OBJECT_TRACK_DEPTH_RECURSIVE*/);
  351. if (res != CS_OK) {
  352. syslog (LOG_ERR, "can't track changes on object: %d", res);
  353. goto send_response;
  354. }
  355. /* Test 'object created' notification
  356. */
  357. callback_type = NTF_NONE;
  358. res = confdb_object_create(handle, object_handle,
  359. "duck", strlen("duck"), &new_object_handle);
  360. if (res != CS_OK) {
  361. syslog (LOG_ERR, "error creating 'duck' object: %d", res);
  362. goto send_response;
  363. }
  364. confdb_dispatch (handle, CS_DISPATCH_ALL);
  365. if (callback_type != NTF_OBJECT_CREATED) {
  366. syslog (LOG_ERR, "no notification received for the creation of 'duck'");
  367. goto send_response;
  368. }
  369. if (strcmp ("duck", ntf_object_name) != 0) {
  370. syslog (LOG_ERR, "expected notification for 'duck' but got %s", ntf_object_name);
  371. goto send_response;
  372. }
  373. /* Test 'key created' notification
  374. */
  375. callback_type = NTF_NONE;
  376. incdec_value = INCDEC_VALUE;
  377. res = confdb_key_create_typed (handle, new_object_handle, "incdec",
  378. &incdec_value, sizeof(incdec_value), CONFDB_VALUETYPE_UINT16);
  379. if (res != CS_OK) {
  380. syslog (LOG_ERR, "error creating 'testconfdb' key 4: %d\n", res);
  381. goto send_response;
  382. }
  383. confdb_dispatch (handle, CS_DISPATCH_ALL);
  384. if (callback_type != NTF_KEY_CREATED) {
  385. syslog (LOG_ERR, "no notification received for the creation of key 'incdec'");
  386. goto send_response;
  387. }
  388. if (strcmp ("incdec", ntf_key_name) != 0) {
  389. syslog (LOG_ERR, "expected notification for 'incdec' but got %s", ntf_key_name);
  390. goto send_response;
  391. }
  392. /* Test 'key replaced' notification for key_replace()
  393. */
  394. callback_type = NTF_NONE;
  395. incdec_value_new = 413;
  396. res = confdb_key_replace(handle, new_object_handle, "incdec", strlen("incdec"),
  397. &incdec_value, sizeof(incdec_value),
  398. &incdec_value_new, sizeof(incdec_value_new));
  399. if (res != CS_OK) {
  400. syslog (LOG_ERR, "error replacing 'incdec' key: %d\n", res);
  401. goto send_response;
  402. }
  403. confdb_dispatch (handle, CS_DISPATCH_ALL);
  404. if (callback_type != NTF_KEY_REPLACED) {
  405. syslog (LOG_ERR, "no notification received for the incrementing of key 'incdec'");
  406. goto send_response;
  407. }
  408. if (strcmp ("incdec", ntf_key_name) != 0) {
  409. syslog (LOG_ERR, "expected notification for 'incdec' but got %s", ntf_key_name);
  410. goto send_response;
  411. }
  412. /* Test NO 'key replaced' notification for key_replace() of the same
  413. * value.
  414. */
  415. callback_type = NTF_NONE;
  416. incdec_value = incdec_value_new;
  417. res = confdb_key_replace(handle, new_object_handle, "incdec", strlen("incdec"),
  418. &incdec_value_new, sizeof(incdec_value),
  419. &incdec_value, sizeof(incdec_value_new));
  420. if (res != CS_OK) {
  421. syslog (LOG_ERR, "error replacing 'incdec' key: %d\n", res);
  422. goto send_response;
  423. }
  424. confdb_dispatch (handle, CS_DISPATCH_ALL);
  425. if (callback_type != NTF_NONE) {
  426. syslog (LOG_ERR, "notification received for the replacing the same value of key 'incdec'");
  427. goto send_response;
  428. }
  429. if (strcmp ("incdec", ntf_key_name) != 0) {
  430. syslog (LOG_ERR, "expected notification for 'incdec' but got %s", ntf_key_name);
  431. goto send_response;
  432. }
  433. /* Test 'key replaced' notification for key_increment()
  434. */
  435. callback_type = NTF_NONE;
  436. res = confdb_key_increment(handle, new_object_handle, "incdec", strlen("incdec"), &incdec_value_out);
  437. if (res != CS_OK) {
  438. syslog (LOG_ERR, "error incrementing 'testconfdb' key 4: %d\n", res);
  439. goto send_response;
  440. }
  441. confdb_dispatch (handle, CS_DISPATCH_ALL);
  442. if (callback_type != NTF_KEY_REPLACED) {
  443. syslog (LOG_ERR, "no notification received for the incrementing of key 'incdec'");
  444. goto send_response;
  445. }
  446. if (strcmp ("incdec", ntf_key_name) != 0) {
  447. syslog (LOG_ERR, "expected notification for 'incdec' but got %s", ntf_key_name);
  448. goto send_response;
  449. }
  450. /* Test 'key destroyed' notification
  451. */
  452. callback_type = NTF_NONE;
  453. res = confdb_key_delete (handle, new_object_handle,
  454. "incdec", strlen ("incdec"), ntf_key_value, ntf_key_value_len);
  455. if (res != CS_OK) {
  456. syslog (LOG_ERR, "Could not delete \"incdec\" key: %d", res);
  457. goto send_response;
  458. }
  459. confdb_dispatch (handle, CS_DISPATCH_ALL);
  460. if (callback_type != NTF_KEY_DELETED) {
  461. syslog (LOG_ERR, "no notification received for the deletion of key 'incdec'");
  462. goto send_response;
  463. }
  464. if (strcmp ("incdec", ntf_key_name) != 0) {
  465. syslog (LOG_ERR, "expected notification for 'incdec' but got %s", ntf_key_name);
  466. goto send_response;
  467. }
  468. /* Test 'object destroyed' notification
  469. */
  470. callback_type = NTF_NONE;
  471. res = confdb_object_destroy(handle, new_object_handle);
  472. if (res != CS_OK) {
  473. syslog (LOG_ERR, "error destroying 'testconfdb' object: %d", res);
  474. goto send_response;
  475. }
  476. confdb_dispatch (handle, CS_DISPATCH_ALL);
  477. if (callback_type != NTF_OBJECT_DELETED) {
  478. syslog (LOG_ERR, "no notification received for the deletion of 'duck'");
  479. goto send_response;
  480. }
  481. if (strcmp ("duck", ntf_object_name) != 0) {
  482. syslog (LOG_ERR, "expected notification for 'duck' but got %s", ntf_object_name);
  483. goto send_response;
  484. }
  485. confdb_stop_track_changes (handle);
  486. confdb_object_destroy(handle, object_handle);
  487. snprintf (response, 100, "%s", OK_STR);
  488. send_response:
  489. send (sock, response, strlen (response) + 1, 0);
  490. confdb_finalize (handle);
  491. }
  492. static void context_test (int sock)
  493. {
  494. confdb_handle_t handle;
  495. char response[100];
  496. char *cmp;
  497. int res;
  498. snprintf (response, 100, "%s", OK_STR);
  499. res = confdb_initialize (&handle, &valid_callbacks);
  500. if (res != CS_OK) {
  501. syslog (LOG_ERR, "Could not initialize confdb error %d\n", res);
  502. goto send_response;
  503. }
  504. confdb_context_set (handle, response);
  505. confdb_context_get (handle, (const void**)&cmp);
  506. if (response != cmp) {
  507. snprintf (response, 100, "%s", FAIL_STR);
  508. }
  509. send_response:
  510. send (sock, response, strlen (response) + 1, 0);
  511. confdb_finalize (handle);
  512. }
  513. static void do_command (int sock, char* func, char*args[], int num_args)
  514. {
  515. char response[100];
  516. if (parse_debug)
  517. syslog (LOG_DEBUG,"RPC:%s() called.", func);
  518. if (strcmp ("set_get_test", func) == 0) {
  519. set_get_test (sock);
  520. } else if (strcmp ("increment_decrement_test", func) == 0) {
  521. increment_decrement_test (sock);
  522. } else if (strcmp ("object_find_test", func) == 0) {
  523. object_find_test (sock);
  524. } else if (strcmp ("notification_test", func) == 0) {
  525. notification_test (sock);
  526. } else if (strcmp ("context_test", func) == 0) {
  527. context_test (sock);
  528. } else if (strcmp ("are_you_ok_dude", func) == 0) {
  529. snprintf (response, 100, "%s", OK_STR);
  530. send (sock, response, strlen (response) + 1, 0);
  531. } else {
  532. syslog (LOG_ERR,"%s RPC:%s not supported!", __func__, func);
  533. snprintf (response, 100, "%s", NOT_SUPPORTED_STR);
  534. send (sock, response, strlen (response) + 1, 0);
  535. }
  536. }
  537. int main (int argc, char *argv[])
  538. {
  539. int ret;
  540. openlog (NULL, LOG_CONS|LOG_PID, LOG_DAEMON);
  541. syslog (LOG_ERR, "confdb_test_agent STARTING");
  542. parse_debug = 1;
  543. ret = test_agent_run (9035, do_command);
  544. syslog (LOG_ERR, "confdb_test_agent EXITING");
  545. return ret;
  546. }