confdb_test_agent.c 18 KB

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