confdb.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  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 CONTIBUTORS "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 <sys/types.h>
  36. #include <unistd.h>
  37. #include <fcntl.h>
  38. #include <stdlib.h>
  39. #include <errno.h>
  40. #include <unistd.h>
  41. #include <corosync/corotypes.h>
  42. #include <corosync/coroipc_types.h>
  43. #include <corosync/corodefs.h>
  44. #include <corosync/cfg.h>
  45. #include <corosync/list.h>
  46. #include <corosync/queue.h>
  47. #include <corosync/mar_gen.h>
  48. #include <corosync/ipc_confdb.h>
  49. #include <corosync/lcr/lcr_comp.h>
  50. #include <corosync/engine/logsys.h>
  51. #include <corosync/engine/coroapi.h>
  52. LOGSYS_DECLARE_SUBSYS ("CONFDB");
  53. static hdb_handle_t *
  54. m2h (mar_uint64_t *m)
  55. {
  56. /* FIXME enable the following when/if we use gnulib:
  57. (it's a compile-time assertion; i.e., zero run-time cost)
  58. verify (sizeof (*m) == sizeof (hdb_handle_t)); */
  59. return (void *) m;
  60. }
  61. static struct corosync_api_v1 *api;
  62. static int confdb_exec_init_fn (
  63. struct corosync_api_v1 *corosync_api);
  64. static int confdb_lib_init_fn (void *conn);
  65. static int confdb_lib_exit_fn (void *conn);
  66. static void message_handler_req_lib_confdb_object_create (void *conn,
  67. const void *message);
  68. static void message_handler_req_lib_confdb_object_destroy (void *conn,
  69. const void *message);
  70. static void message_handler_req_lib_confdb_object_find_destroy (void *conn,
  71. const void *message);
  72. static void message_handler_req_lib_confdb_key_create (void *conn,
  73. const void *message);
  74. static void message_handler_req_lib_confdb_key_get (void *conn,
  75. const void *message);
  76. static void message_handler_req_lib_confdb_key_replace (void *conn,
  77. const void *message);
  78. static void message_handler_req_lib_confdb_key_delete (void *conn,
  79. const void *message);
  80. static void message_handler_req_lib_confdb_key_iter (void *conn,
  81. const void *message);
  82. static void message_handler_req_lib_confdb_key_increment (void *conn,
  83. const void *message);
  84. static void message_handler_req_lib_confdb_key_decrement (void *conn,
  85. const void *message);
  86. static void message_handler_req_lib_confdb_object_iter (void *conn,
  87. const void *message);
  88. static void message_handler_req_lib_confdb_object_find (void *conn,
  89. const void *message);
  90. static void message_handler_req_lib_confdb_object_parent_get (void *conn,
  91. const void *message);
  92. static void message_handler_req_lib_confdb_write (void *conn,
  93. const void *message);
  94. static void message_handler_req_lib_confdb_reload (void *conn,
  95. const void *message);
  96. static void message_handler_req_lib_confdb_track_start (void *conn,
  97. const void *message);
  98. static void message_handler_req_lib_confdb_track_stop (void *conn,
  99. const void *message);
  100. static void confdb_notify_lib_of_key_change(
  101. object_change_type_t change_type,
  102. hdb_handle_t parent_object_handle,
  103. hdb_handle_t object_handle,
  104. const void *object_name_pt, size_t object_name_len,
  105. const void *key_name_pt, size_t key_name_len,
  106. const void *key_value_pt, size_t key_value_len,
  107. void *priv_data_pt);
  108. static void confdb_notify_lib_of_new_object(
  109. hdb_handle_t parent_object_handle,
  110. hdb_handle_t object_handle,
  111. const uint8_t *name_pt, size_t name_len,
  112. void *priv_data_pt);
  113. static void confdb_notify_lib_of_destroyed_object(
  114. hdb_handle_t parent_object_handle,
  115. const uint8_t *name_pt, size_t name_len,
  116. void *priv_data_pt);
  117. /*
  118. * Library Handler Definition
  119. */
  120. static struct corosync_lib_handler confdb_lib_engine[] =
  121. {
  122. { /* 0 */
  123. .lib_handler_fn = message_handler_req_lib_confdb_object_create,
  124. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  125. },
  126. { /* 1 */
  127. .lib_handler_fn = message_handler_req_lib_confdb_object_destroy,
  128. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  129. },
  130. { /* 2 */
  131. .lib_handler_fn = message_handler_req_lib_confdb_object_find,
  132. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  133. },
  134. { /* 3 */
  135. .lib_handler_fn = message_handler_req_lib_confdb_key_create,
  136. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  137. },
  138. { /* 4 */
  139. .lib_handler_fn = message_handler_req_lib_confdb_key_get,
  140. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  141. },
  142. { /* 5 */
  143. .lib_handler_fn = message_handler_req_lib_confdb_key_replace,
  144. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  145. },
  146. { /* 6 */
  147. .lib_handler_fn = message_handler_req_lib_confdb_key_delete,
  148. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  149. },
  150. { /* 7 */
  151. .lib_handler_fn = message_handler_req_lib_confdb_object_iter,
  152. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  153. },
  154. { /* 8 */
  155. .lib_handler_fn = message_handler_req_lib_confdb_object_parent_get,
  156. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  157. },
  158. { /* 9 */
  159. .lib_handler_fn = message_handler_req_lib_confdb_key_iter,
  160. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  161. },
  162. { /* 10 */
  163. .lib_handler_fn = message_handler_req_lib_confdb_track_start,
  164. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  165. },
  166. { /* 11 */
  167. .lib_handler_fn = message_handler_req_lib_confdb_track_stop,
  168. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  169. },
  170. { /* 12 */
  171. .lib_handler_fn = message_handler_req_lib_confdb_write,
  172. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  173. },
  174. { /* 13 */
  175. .lib_handler_fn = message_handler_req_lib_confdb_reload,
  176. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  177. },
  178. { /* 14 */
  179. .lib_handler_fn = message_handler_req_lib_confdb_object_find_destroy,
  180. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  181. },
  182. { /* 15 */
  183. .lib_handler_fn = message_handler_req_lib_confdb_key_increment,
  184. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  185. },
  186. { /* 16 */
  187. .lib_handler_fn = message_handler_req_lib_confdb_key_decrement,
  188. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  189. },
  190. };
  191. struct corosync_service_engine confdb_service_engine = {
  192. .name = "corosync cluster config database access v1.01",
  193. .id = CONFDB_SERVICE,
  194. .private_data_size = 0,
  195. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED,
  196. .allow_inquorate = CS_LIB_ALLOW_INQUORATE,
  197. .lib_init_fn = confdb_lib_init_fn,
  198. .lib_exit_fn = confdb_lib_exit_fn,
  199. .lib_engine = confdb_lib_engine,
  200. .lib_engine_count = sizeof (confdb_lib_engine) / sizeof (struct corosync_lib_handler),
  201. .exec_init_fn = confdb_exec_init_fn,
  202. };
  203. /*
  204. * Dynamic loader definition
  205. */
  206. static struct corosync_service_engine *confdb_get_service_engine_ver0 (void);
  207. static struct corosync_service_engine_iface_ver0 confdb_service_engine_iface = {
  208. .corosync_get_service_engine_ver0 = confdb_get_service_engine_ver0
  209. };
  210. static struct lcr_iface corosync_confdb_ver0[1] = {
  211. {
  212. .name = "corosync_confdb",
  213. .version = 0,
  214. .versions_replace = 0,
  215. .versions_replace_count = 0,
  216. .dependencies = 0,
  217. .dependency_count = 0,
  218. .constructor = NULL,
  219. .destructor = NULL,
  220. .interfaces = NULL
  221. }
  222. };
  223. static struct lcr_comp confdb_comp_ver0 = {
  224. .iface_count = 1,
  225. .ifaces = corosync_confdb_ver0
  226. };
  227. static struct corosync_service_engine *confdb_get_service_engine_ver0 (void)
  228. {
  229. return (&confdb_service_engine);
  230. }
  231. __attribute__ ((constructor)) static void confdb_comp_register (void) {
  232. lcr_interfaces_set (&corosync_confdb_ver0[0], &confdb_service_engine_iface);
  233. lcr_component_register (&confdb_comp_ver0);
  234. }
  235. static int confdb_exec_init_fn (
  236. struct corosync_api_v1 *corosync_api)
  237. {
  238. api = corosync_api;
  239. return 0;
  240. }
  241. static int confdb_lib_init_fn (void *conn)
  242. {
  243. log_printf(LOGSYS_LEVEL_DEBUG, "lib_init_fn: conn=%p\n", conn);
  244. return (0);
  245. }
  246. static int confdb_lib_exit_fn (void *conn)
  247. {
  248. log_printf(LOGSYS_LEVEL_DEBUG, "exit_fn for conn=%p\n", conn);
  249. /* cleanup the object trackers for this client. */
  250. api->object_track_stop(confdb_notify_lib_of_key_change,
  251. confdb_notify_lib_of_new_object,
  252. confdb_notify_lib_of_destroyed_object,
  253. NULL,
  254. conn);
  255. return (0);
  256. }
  257. static void message_handler_req_lib_confdb_object_create (void *conn,
  258. const void *message)
  259. {
  260. const struct req_lib_confdb_object_create *req_lib_confdb_object_create
  261. = message;
  262. struct res_lib_confdb_object_create res_lib_confdb_object_create;
  263. hdb_handle_t object_handle;
  264. int ret = CS_OK;
  265. if (api->object_create(req_lib_confdb_object_create->parent_object_handle,
  266. &object_handle,
  267. req_lib_confdb_object_create->object_name.value,
  268. req_lib_confdb_object_create->object_name.length))
  269. ret = CS_ERR_ACCESS;
  270. res_lib_confdb_object_create.object_handle = object_handle;
  271. res_lib_confdb_object_create.header.size = sizeof(res_lib_confdb_object_create);
  272. res_lib_confdb_object_create.header.id = MESSAGE_RES_CONFDB_OBJECT_CREATE;
  273. res_lib_confdb_object_create.header.error = ret;
  274. api->ipc_response_send(conn, &res_lib_confdb_object_create, sizeof(res_lib_confdb_object_create));
  275. }
  276. static void message_handler_req_lib_confdb_object_destroy (void *conn,
  277. const void *message)
  278. {
  279. const struct req_lib_confdb_object_destroy *req_lib_confdb_object_destroy
  280. = message;
  281. coroipc_response_header_t res;
  282. int ret = CS_OK;
  283. if (api->object_destroy(req_lib_confdb_object_destroy->object_handle))
  284. ret = CS_ERR_ACCESS;
  285. res.size = sizeof(res);
  286. res.id = MESSAGE_RES_CONFDB_OBJECT_DESTROY;
  287. res.error = ret;
  288. api->ipc_response_send(conn, &res, sizeof(res));
  289. }
  290. static void message_handler_req_lib_confdb_object_find_destroy (void *conn,
  291. const void *message)
  292. {
  293. const struct req_lib_confdb_object_find_destroy
  294. *req_lib_confdb_object_find_destroy = message;
  295. coroipc_response_header_t res;
  296. int ret = CS_OK;
  297. if (api->object_find_destroy(req_lib_confdb_object_find_destroy->find_handle))
  298. ret = CS_ERR_ACCESS;
  299. res.size = sizeof(res);
  300. res.id = MESSAGE_RES_CONFDB_OBJECT_FIND_DESTROY;
  301. res.error = ret;
  302. api->ipc_response_send(conn, &res, sizeof(res));
  303. }
  304. static void message_handler_req_lib_confdb_key_create (void *conn,
  305. const void *message)
  306. {
  307. const struct req_lib_confdb_key_create *req_lib_confdb_key_create
  308. = message;
  309. coroipc_response_header_t res;
  310. int ret = CS_OK;
  311. if (api->object_key_create(req_lib_confdb_key_create->object_handle,
  312. req_lib_confdb_key_create->key_name.value,
  313. req_lib_confdb_key_create->key_name.length,
  314. req_lib_confdb_key_create->value.value,
  315. req_lib_confdb_key_create->value.length))
  316. ret = CS_ERR_ACCESS;
  317. res.size = sizeof(res);
  318. res.id = MESSAGE_RES_CONFDB_KEY_CREATE;
  319. res.error = ret;
  320. api->ipc_response_send(conn, &res, sizeof(res));
  321. }
  322. static void message_handler_req_lib_confdb_key_get (void *conn,
  323. const void *message)
  324. {
  325. const struct req_lib_confdb_key_get *req_lib_confdb_key_get = message;
  326. struct res_lib_confdb_key_get res_lib_confdb_key_get;
  327. size_t value_len;
  328. void *value;
  329. int ret = CS_OK;
  330. if (api->object_key_get(req_lib_confdb_key_get->parent_object_handle,
  331. req_lib_confdb_key_get->key_name.value,
  332. req_lib_confdb_key_get->key_name.length,
  333. &value,
  334. &value_len))
  335. ret = CS_ERR_ACCESS;
  336. else {
  337. memcpy(res_lib_confdb_key_get.value.value, value, value_len);
  338. res_lib_confdb_key_get.value.length = value_len;
  339. }
  340. res_lib_confdb_key_get.header.size = sizeof(res_lib_confdb_key_get);
  341. res_lib_confdb_key_get.header.id = MESSAGE_RES_CONFDB_KEY_GET;
  342. res_lib_confdb_key_get.header.error = ret;
  343. api->ipc_response_send(conn, &res_lib_confdb_key_get, sizeof(res_lib_confdb_key_get));
  344. }
  345. static void message_handler_req_lib_confdb_key_increment (void *conn,
  346. const void *message)
  347. {
  348. const struct req_lib_confdb_key_get *req_lib_confdb_key_get = message;
  349. struct res_lib_confdb_key_incdec res_lib_confdb_key_incdec;
  350. int ret = CS_OK;
  351. if (api->object_key_increment(req_lib_confdb_key_get->parent_object_handle,
  352. req_lib_confdb_key_get->key_name.value,
  353. req_lib_confdb_key_get->key_name.length,
  354. &res_lib_confdb_key_incdec.value))
  355. ret = CS_ERR_ACCESS;
  356. res_lib_confdb_key_incdec.header.size = sizeof(res_lib_confdb_key_incdec);
  357. res_lib_confdb_key_incdec.header.id = MESSAGE_RES_CONFDB_KEY_INCREMENT;
  358. res_lib_confdb_key_incdec.header.error = ret;
  359. api->ipc_response_send(conn, &res_lib_confdb_key_incdec, sizeof(res_lib_confdb_key_incdec));
  360. }
  361. static void message_handler_req_lib_confdb_key_decrement (void *conn,
  362. const void *message)
  363. {
  364. const struct req_lib_confdb_key_get *req_lib_confdb_key_get = message;
  365. struct res_lib_confdb_key_incdec res_lib_confdb_key_incdec;
  366. int ret = CS_OK;
  367. if (api->object_key_decrement(req_lib_confdb_key_get->parent_object_handle,
  368. req_lib_confdb_key_get->key_name.value,
  369. req_lib_confdb_key_get->key_name.length,
  370. &res_lib_confdb_key_incdec.value))
  371. ret = CS_ERR_ACCESS;
  372. res_lib_confdb_key_incdec.header.size = sizeof(res_lib_confdb_key_incdec);
  373. res_lib_confdb_key_incdec.header.id = MESSAGE_RES_CONFDB_KEY_DECREMENT;
  374. res_lib_confdb_key_incdec.header.error = ret;
  375. api->ipc_response_send(conn, &res_lib_confdb_key_incdec, sizeof(res_lib_confdb_key_incdec));
  376. }
  377. static void message_handler_req_lib_confdb_key_replace (void *conn,
  378. const void *message)
  379. {
  380. const struct req_lib_confdb_key_replace *req_lib_confdb_key_replace
  381. = message;
  382. coroipc_response_header_t res;
  383. int ret = CS_OK;
  384. if (api->object_key_replace(req_lib_confdb_key_replace->object_handle,
  385. req_lib_confdb_key_replace->key_name.value,
  386. req_lib_confdb_key_replace->key_name.length,
  387. req_lib_confdb_key_replace->new_value.value,
  388. req_lib_confdb_key_replace->new_value.length))
  389. ret = CS_ERR_ACCESS;
  390. res.size = sizeof(res);
  391. res.id = MESSAGE_RES_CONFDB_KEY_REPLACE;
  392. res.error = ret;
  393. api->ipc_response_send(conn, &res, sizeof(res));
  394. }
  395. static void message_handler_req_lib_confdb_key_delete (void *conn,
  396. const void *message)
  397. {
  398. const struct req_lib_confdb_key_delete *req_lib_confdb_key_delete
  399. = message;
  400. coroipc_response_header_t res;
  401. int ret = CS_OK;
  402. if (api->object_key_delete(req_lib_confdb_key_delete->object_handle,
  403. req_lib_confdb_key_delete->key_name.value,
  404. req_lib_confdb_key_delete->key_name.length))
  405. ret = CS_ERR_ACCESS;
  406. res.size = sizeof(res);
  407. res.id = MESSAGE_RES_CONFDB_KEY_DELETE;
  408. res.error = ret;
  409. api->ipc_response_send(conn, &res, sizeof(res));
  410. }
  411. static void message_handler_req_lib_confdb_object_parent_get (void *conn,
  412. const void *message)
  413. {
  414. const struct req_lib_confdb_object_parent_get
  415. *req_lib_confdb_object_parent_get = message;
  416. struct res_lib_confdb_object_parent_get res_lib_confdb_object_parent_get;
  417. hdb_handle_t object_handle;
  418. int ret = CS_OK;
  419. if (api->object_parent_get(req_lib_confdb_object_parent_get->object_handle,
  420. &object_handle))
  421. ret = CS_ERR_ACCESS;
  422. res_lib_confdb_object_parent_get.parent_object_handle = object_handle;
  423. res_lib_confdb_object_parent_get.header.size = sizeof(res_lib_confdb_object_parent_get);
  424. res_lib_confdb_object_parent_get.header.id = MESSAGE_RES_CONFDB_OBJECT_CREATE;
  425. res_lib_confdb_object_parent_get.header.error = ret;
  426. api->ipc_response_send(conn, &res_lib_confdb_object_parent_get, sizeof(res_lib_confdb_object_parent_get));
  427. }
  428. static void message_handler_req_lib_confdb_key_iter (void *conn,
  429. const void *message)
  430. {
  431. const struct req_lib_confdb_key_iter *req_lib_confdb_key_iter = message;
  432. struct res_lib_confdb_key_iter res_lib_confdb_key_iter;
  433. void *key_name;
  434. size_t key_name_len;
  435. void *value;
  436. size_t value_len;
  437. int ret = CS_OK;
  438. if (api->object_key_iter_from(req_lib_confdb_key_iter->parent_object_handle,
  439. req_lib_confdb_key_iter->next_entry,
  440. &key_name,
  441. &key_name_len,
  442. &value,
  443. &value_len))
  444. ret = CS_ERR_ACCESS;
  445. else {
  446. memcpy(res_lib_confdb_key_iter.key_name.value, key_name, key_name_len);
  447. memcpy(res_lib_confdb_key_iter.value.value, value, value_len);
  448. res_lib_confdb_key_iter.key_name.length = key_name_len;
  449. res_lib_confdb_key_iter.value.length = value_len;
  450. }
  451. res_lib_confdb_key_iter.header.size = sizeof(res_lib_confdb_key_iter);
  452. res_lib_confdb_key_iter.header.id = MESSAGE_RES_CONFDB_KEY_ITER;
  453. res_lib_confdb_key_iter.header.error = ret;
  454. api->ipc_response_send(conn, &res_lib_confdb_key_iter, sizeof(res_lib_confdb_key_iter));
  455. }
  456. static void message_handler_req_lib_confdb_object_iter (void *conn,
  457. const void *message)
  458. {
  459. const struct req_lib_confdb_object_iter *req_lib_confdb_object_iter
  460. = message;
  461. struct res_lib_confdb_object_iter res_lib_confdb_object_iter;
  462. size_t object_name_len;
  463. int ret = CS_OK;
  464. if (!req_lib_confdb_object_iter->find_handle) {
  465. api->object_find_create(req_lib_confdb_object_iter->parent_object_handle,
  466. NULL, 0,
  467. m2h(&res_lib_confdb_object_iter.find_handle));
  468. }
  469. else
  470. res_lib_confdb_object_iter.find_handle = req_lib_confdb_object_iter->find_handle;
  471. if (api->object_find_next(res_lib_confdb_object_iter.find_handle,
  472. m2h(&res_lib_confdb_object_iter.object_handle))) {
  473. ret = CS_ERR_ACCESS;
  474. api->object_find_destroy(res_lib_confdb_object_iter.find_handle);
  475. }
  476. else {
  477. api->object_name_get(res_lib_confdb_object_iter.object_handle,
  478. (char *)res_lib_confdb_object_iter.object_name.value,
  479. &object_name_len);
  480. res_lib_confdb_object_iter.object_name.length = object_name_len;
  481. }
  482. res_lib_confdb_object_iter.header.size = sizeof(res_lib_confdb_object_iter);
  483. res_lib_confdb_object_iter.header.id = MESSAGE_RES_CONFDB_OBJECT_ITER;
  484. res_lib_confdb_object_iter.header.error = ret;
  485. api->ipc_response_send(conn, &res_lib_confdb_object_iter, sizeof(res_lib_confdb_object_iter));
  486. }
  487. static void message_handler_req_lib_confdb_object_find (void *conn,
  488. const void *message)
  489. {
  490. const struct req_lib_confdb_object_find *req_lib_confdb_object_find
  491. = message;
  492. struct res_lib_confdb_object_find res_lib_confdb_object_find;
  493. int ret = CS_OK;
  494. if (!req_lib_confdb_object_find->find_handle) {
  495. api->object_find_create(req_lib_confdb_object_find->parent_object_handle,
  496. req_lib_confdb_object_find->object_name.value,
  497. req_lib_confdb_object_find->object_name.length,
  498. m2h(&res_lib_confdb_object_find.find_handle));
  499. }
  500. else
  501. res_lib_confdb_object_find.find_handle = req_lib_confdb_object_find->find_handle;
  502. if (api->object_find_next(res_lib_confdb_object_find.find_handle,
  503. m2h(&res_lib_confdb_object_find.object_handle))) {
  504. ret = CS_ERR_ACCESS;
  505. api->object_find_destroy(res_lib_confdb_object_find.find_handle);
  506. }
  507. res_lib_confdb_object_find.header.size = sizeof(res_lib_confdb_object_find);
  508. res_lib_confdb_object_find.header.id = MESSAGE_RES_CONFDB_OBJECT_FIND;
  509. res_lib_confdb_object_find.header.error = ret;
  510. api->ipc_response_send(conn, &res_lib_confdb_object_find, sizeof(res_lib_confdb_object_find));
  511. }
  512. static void message_handler_req_lib_confdb_write (void *conn,
  513. const void *message)
  514. {
  515. struct res_lib_confdb_write res_lib_confdb_write;
  516. int ret = CS_OK;
  517. const char *error_string = NULL;
  518. if (api->object_write_config(&error_string))
  519. ret = CS_ERR_ACCESS;
  520. res_lib_confdb_write.header.size = sizeof(res_lib_confdb_write);
  521. res_lib_confdb_write.header.id = MESSAGE_RES_CONFDB_WRITE;
  522. res_lib_confdb_write.header.error = ret;
  523. if (error_string) {
  524. strcpy((char *)res_lib_confdb_write.error.value, error_string);
  525. res_lib_confdb_write.error.length = strlen(error_string) + 1;
  526. } else
  527. res_lib_confdb_write.error.length = 0;
  528. api->ipc_response_send(conn, &res_lib_confdb_write, sizeof(res_lib_confdb_write));
  529. }
  530. static void message_handler_req_lib_confdb_reload (void *conn,
  531. const void *message)
  532. {
  533. const struct req_lib_confdb_reload *req_lib_confdb_reload = message;
  534. struct res_lib_confdb_reload res_lib_confdb_reload;
  535. int ret = CS_OK;
  536. const char *error_string = NULL;
  537. if (api->object_reload_config(req_lib_confdb_reload->flush, &error_string))
  538. ret = CS_ERR_ACCESS;
  539. res_lib_confdb_reload.header.size = sizeof(res_lib_confdb_reload);
  540. res_lib_confdb_reload.header.id = MESSAGE_RES_CONFDB_RELOAD;
  541. res_lib_confdb_reload.header.error = ret;
  542. if(error_string) {
  543. strcpy((char *)res_lib_confdb_reload.error.value, error_string);
  544. res_lib_confdb_reload.error.length = strlen(error_string) + 1;
  545. } else
  546. res_lib_confdb_reload.error.length = 0;
  547. api->ipc_response_send(conn, &res_lib_confdb_reload, sizeof(res_lib_confdb_reload));
  548. }
  549. static void confdb_notify_lib_of_key_change(object_change_type_t change_type,
  550. hdb_handle_t parent_object_handle,
  551. hdb_handle_t object_handle,
  552. const void *object_name_pt, size_t object_name_len,
  553. const void *key_name_pt, size_t key_name_len,
  554. const void *key_value_pt, size_t key_value_len,
  555. void *priv_data_pt)
  556. {
  557. struct res_lib_confdb_key_change_callback res;
  558. res.header.size = sizeof(res);
  559. res.header.id = MESSAGE_RES_CONFDB_KEY_CHANGE_CALLBACK;
  560. res.header.error = CS_OK;
  561. // handle & type
  562. res.change_type = change_type;
  563. res.parent_object_handle = parent_object_handle;
  564. res.object_handle = object_handle;
  565. //object
  566. memcpy(res.object_name.value, object_name_pt, object_name_len);
  567. res.object_name.length = object_name_len;
  568. //key name
  569. memcpy(res.key_name.value, key_name_pt, key_name_len);
  570. res.key_name.length = key_name_len;
  571. //key value
  572. memcpy(res.key_value.value, key_value_pt, key_value_len);
  573. res.key_value.length = key_value_len;
  574. api->ipc_dispatch_send(priv_data_pt, &res, sizeof(res));
  575. }
  576. static void confdb_notify_lib_of_new_object(hdb_handle_t parent_object_handle,
  577. hdb_handle_t object_handle,
  578. const uint8_t *name_pt, size_t name_len,
  579. void *priv_data_pt)
  580. {
  581. struct res_lib_confdb_object_create_callback res;
  582. res.header.size = sizeof(res);
  583. res.header.id = MESSAGE_RES_CONFDB_OBJECT_CREATE_CALLBACK;
  584. res.header.error = CS_OK;
  585. res.parent_object_handle = parent_object_handle;
  586. res.object_handle = object_handle;
  587. memcpy(res.name.value, name_pt, name_len);
  588. res.name.length = name_len;
  589. api->ipc_dispatch_send(priv_data_pt, &res, sizeof(res));
  590. }
  591. static void confdb_notify_lib_of_destroyed_object(
  592. hdb_handle_t parent_object_handle,
  593. const uint8_t *name_pt, size_t name_len,
  594. void *priv_data_pt)
  595. {
  596. struct res_lib_confdb_object_destroy_callback res;
  597. res.header.size = sizeof(res);
  598. res.header.id = MESSAGE_RES_CONFDB_OBJECT_DESTROY_CALLBACK;
  599. res.header.error = CS_OK;
  600. res.parent_object_handle = parent_object_handle;
  601. memcpy(res.name.value, name_pt, name_len);
  602. res.name.length = name_len;
  603. api->ipc_dispatch_send(priv_data_pt, &res, sizeof(res));
  604. }
  605. static void message_handler_req_lib_confdb_track_start (void *conn,
  606. const void *message)
  607. {
  608. const struct req_lib_confdb_object_track_start *req = message;
  609. coroipc_response_header_t res;
  610. api->object_track_start(req->object_handle,
  611. req->flags,
  612. confdb_notify_lib_of_key_change,
  613. confdb_notify_lib_of_new_object,
  614. confdb_notify_lib_of_destroyed_object,
  615. NULL,
  616. conn);
  617. res.size = sizeof(res);
  618. res.id = MESSAGE_RES_CONFDB_TRACK_START;
  619. res.error = CS_OK;
  620. api->ipc_response_send(conn, &res, sizeof(res));
  621. }
  622. static void message_handler_req_lib_confdb_track_stop (void *conn,
  623. const void *message)
  624. {
  625. coroipc_response_header_t res;
  626. api->object_track_stop(confdb_notify_lib_of_key_change,
  627. confdb_notify_lib_of_new_object,
  628. confdb_notify_lib_of_destroyed_object,
  629. NULL,
  630. conn);
  631. res.size = sizeof(res);
  632. res.id = MESSAGE_RES_CONFDB_TRACK_STOP;
  633. res.error = CS_OK;
  634. api->ipc_response_send(conn, &res, sizeof(res));
  635. }