confdb.c 24 KB

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